Home | History | Annotate | Download | only in ext2fs

Lines Matching refs:fs

34 	ext2_filsys		fs;
47 errcode_t (*done_group)(ext2_filsys fs,
60 errcode_t ext2fs_flush_icache(ext2_filsys fs)
64 if (!fs->icache)
67 for (i=0; i < fs->icache->cache_size; i++)
68 fs->icache->cache[i].ino = 0;
70 fs->icache->buffer_blk = 0;
74 static errcode_t create_icache(ext2_filsys fs)
78 if (fs->icache)
80 retval = ext2fs_get_mem(sizeof(struct ext2_inode_cache), &fs->icache);
84 memset(fs->icache, 0, sizeof(struct ext2_inode_cache));
85 retval = ext2fs_get_mem(fs->blocksize, &fs->icache->buffer);
87 ext2fs_free_mem(&fs->icache);
90 fs->icache->buffer_blk = 0;
91 fs->icache->cache_last = -1;
92 fs->icache->cache_size = 4;
93 fs->icache->refcount = 1;
94 retval = ext2fs_get_array(fs->icache->cache_size,
96 &fs->icache->cache);
98 ext2fs_free_mem(&fs->icache->buffer);
99 ext2fs_free_mem(&fs->icache);
102 ext2fs_flush_icache(fs);
106 errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
113 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
116 * If fs->badblocks isn't set, then set it --- since the inode
119 if (fs->badblocks == 0) {
121 * Temporarly save fs->get_blocks and set it to zero,
124 save_get_blocks = fs->get_blocks;
125 fs->get_blocks = 0;
126 retval = ext2fs_read_bb_inode(fs, &fs->badblocks);
127 if (retval && fs->badblocks) {
128 ext2fs_badblocks_list_free(fs->badblocks);
129 fs->badblocks = 0;
131 fs->get_blocks = save_get_blocks;
140 scan->fs = fs;
141 scan->inode_size = EXT2_INODE_SIZE(fs->super);
144 scan->groups_left = fs->group_desc_count - 1;
146 scan->current_block = scan->fs->
148 scan->inodes_left = EXT2_INODES_PER_GROUP(scan->fs->super);
149 scan->blocks_left = scan->fs->inode_blocks_per_group;
150 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
153 fs->group_desc[scan->current_group].bg_itable_unused;
156 (fs->blocksize / scan->inode_size - 1)) *
157 scan->inode_size / fs->blocksize;
160 fs->blocksize,
175 if (scan->fs->badblocks && scan->fs->badblocks->num)
177 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
198 errcode_t (*done_group)(ext2_filsys fs,
231 ext2_filsys fs = scan->fs;
236 scan->current_block =fs->group_desc[scan->current_group].bg_inode_table;
239 EXT2_INODES_PER_GROUP(fs->super);
242 scan->inodes_left = EXT2_INODES_PER_GROUP(fs->super);
243 scan->blocks_left = fs->inode_blocks_per_group;
244 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
247 fs->group_desc[scan->current_group].bg_itable_unused;
250 (fs->blocksize / scan->inode_size - 1)) *
251 scan->inode_size / fs->blocksize;
261 scan->groups_left = scan->fs->group_desc_count - group;
276 badblocks_list bb = scan->fs->badblocks;
366 (size_t) num_blocks * scan->fs->blocksize);
368 retval = io_channel_read_blk(scan->fs->io,
376 scan->bytes_left = num_blocks * scan->fs->blocksize;
420 (scan->fs, scan, scan->current_group,
438 (scan->fs->group_desc[scan->current_group].bg_flags &
481 ext2fs_swap_inode_full(scan->fs,
494 ext2fs_swap_inode_full(scan->fs,
523 errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
532 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
535 if (fs->read_inode) {
536 retval = (fs->read_inode)(fs, ino, inode);
540 if ((ino == 0) || (ino > fs->super->s_inodes_count))
543 if (!fs->icache) {
544 retval = create_icache(fs);
551 for (i=0; i < fs->icache->cache_size; i++) {
552 if (fs->icache->cache[i].ino == ino) {
553 *inode = fs->icache->cache[i].inode;
558 if (fs->flags & EXT2_FLAG_IMAGE_FILE) {
559 inodes_per_block = fs->blocksize / EXT2_INODE_SIZE(fs->super);
560 block_nr = fs->image_header->offset_inode / fs->blocksize;
563 EXT2_INODE_SIZE(fs->super);
564 io = fs->image_io;
566 group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super);
567 if (group > fs->group_desc_count)
569 offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) *
570 EXT2_INODE_SIZE(fs->super);
571 block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super);
572 if (!fs->group_desc[(unsigned)group].bg_inode_table)
574 block_nr = fs->group_desc[(unsigned)group].bg_inode_table +
576 io = fs->io;
578 offset &= (EXT2_BLOCK_SIZE(fs->super) - 1);
580 length = EXT2_INODE_SIZE(fs->super);
587 if ((offset + length) > fs->blocksize)
588 clen = fs->blocksize - offset;
590 if (block_nr != fs->icache->buffer_blk) {
592 fs->icache->buffer);
595 fs->icache->buffer_blk = block_nr;
598 memcpy(ptr, ((char *) fs->icache->buffer) + (unsigned) offset,
608 ext2fs_swap_inode_full(fs, (struct ext2_inode_large *) inode,
614 fs->icache->cache_last = (fs->icache->cache_last + 1) %
615 fs->icache->cache_size;
616 fs->icache->cache[fs->icache->cache_last].ino = ino;
617 fs->icache->cache[fs->icache->cache_last].inode = *inode;
622 errcode_t ext2fs_read_inode(ext2_filsys fs, ext2_ino_t ino,
625 return ext2fs_read_inode_full(fs, ino, inode,
629 fs, ext2_ino_t ino,
638 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
641 if (fs->write_inode) {
642 retval = (fs->write_inode)(fs, ino, inode);
648 if (fs->icache) {
649 for (i=0; i < fs->icache->cache_size; i++) {
650 if (fs->icache->cache[i].ino == ino) {
651 fs->icache->cache[i].inode = *inode;
656 retval = create_icache(fs);
661 if (!(fs->flags & EXT2_FLAG_RW))
664 if ((ino == 0) || (ino > fs->super->s_inodes_count))
668 if (length < EXT2_INODE_SIZE(fs->super))
669 length = EXT2_INODE_SIZE(fs->super);
680 ext2fs_swap_inode_full(fs, w_inode,
687 group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super);
688 offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) *
689 EXT2_INODE_SIZE(fs->super);
690 block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super);
691 if (!fs->group_desc[(unsigned) group].bg_inode_table) {
695 block_nr = fs->group_desc[(unsigned) group].bg_inode_table + block;
697 offset &= (EXT2_BLOCK_SIZE(fs->super) - 1);
699 length = EXT2_INODE_SIZE(fs->super);
707 if ((offset + length) > fs->blocksize)
708 clen = fs->blocksize - offset;
710 if (fs->icache->buffer_blk != block_nr) {
711 retval = io_channel_read_blk(fs->io, block_nr, 1,
712 fs->icache->buffer);
715 fs->icache->buffer_blk = block_nr;
719 memcpy((char *) fs->icache->buffer + (unsigned) offset,
722 retval = io_channel_write_blk(fs->io, block_nr, 1,
723 fs->icache->buffer);
733 fs->flags |= EXT2_FLAG_CHANGED;
740 errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
743 return ext2fs_write_inode_full(fs, ino, inode,
751 errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino,
755 int size = EXT2_INODE_SIZE(fs->super);
758 __u32 t = fs->now ? fs->now : time(NULL);
768 return ext2fs_write_inode_full(fs, ino, inode,
784 retval = ext2fs_write_inode_full(fs, ino, buf, size);
790 errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks)
796 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
798 if (ino > fs->super->s_inodes_count)
801 if (fs->get_blocks) {
802 if (!(*fs->get_blocks)(fs, ino, blocks))
805 retval = ext2fs_read_inode(fs, ino, &inode);
813 errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino)
818 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
820 if (ino > fs->super->s_inodes_count)
823 if (fs->check_directory) {
824 retval = (fs->check_directory)(fs, ino);
828 retval = ext2fs_read_inode(fs, ino, &inode);