Lines Matching refs:fs
34 ext2_filsys fs; member
47 errcode_t (*done_group)(ext2_filsys fs,
60 errcode_t ext2fs_flush_icache(ext2_filsys fs) in ext2fs_flush_icache() argument
64 if (!fs->icache) in ext2fs_flush_icache()
67 for (i=0; i < fs->icache->cache_size; i++) in ext2fs_flush_icache()
68 fs->icache->cache[i].ino = 0; in ext2fs_flush_icache()
70 fs->icache->buffer_blk = 0; in ext2fs_flush_icache()
74 static errcode_t create_icache(ext2_filsys fs) in create_icache() argument
78 if (fs->icache) in create_icache()
80 retval = ext2fs_get_mem(sizeof(struct ext2_inode_cache), &fs->icache); in create_icache()
84 memset(fs->icache, 0, sizeof(struct ext2_inode_cache)); in create_icache()
85 retval = ext2fs_get_mem(fs->blocksize, &fs->icache->buffer); in create_icache()
87 ext2fs_free_mem(&fs->icache); in create_icache()
90 fs->icache->buffer_blk = 0; in create_icache()
91 fs->icache->cache_last = -1; in create_icache()
92 fs->icache->cache_size = 4; in create_icache()
93 fs->icache->refcount = 1; in create_icache()
94 retval = ext2fs_get_array(fs->icache->cache_size, in create_icache()
96 &fs->icache->cache); in create_icache()
98 ext2fs_free_mem(&fs->icache->buffer); in create_icache()
99 ext2fs_free_mem(&fs->icache); in create_icache()
102 ext2fs_flush_icache(fs); in create_icache()
106 errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks, in ext2fs_open_inode_scan() argument
113 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); in ext2fs_open_inode_scan()
119 if (fs->badblocks == 0) { in ext2fs_open_inode_scan()
124 save_get_blocks = fs->get_blocks; in ext2fs_open_inode_scan()
125 fs->get_blocks = 0; in ext2fs_open_inode_scan()
126 retval = ext2fs_read_bb_inode(fs, &fs->badblocks); in ext2fs_open_inode_scan()
127 if (retval && fs->badblocks) { in ext2fs_open_inode_scan()
128 ext2fs_badblocks_list_free(fs->badblocks); in ext2fs_open_inode_scan()
129 fs->badblocks = 0; in ext2fs_open_inode_scan()
131 fs->get_blocks = save_get_blocks; in ext2fs_open_inode_scan()
140 scan->fs = fs; in ext2fs_open_inode_scan()
141 scan->inode_size = EXT2_INODE_SIZE(fs->super); in ext2fs_open_inode_scan()
144 scan->groups_left = fs->group_desc_count - 1; in ext2fs_open_inode_scan()
146 scan->current_block = ext2fs_inode_table_loc(scan->fs, in ext2fs_open_inode_scan()
148 scan->inodes_left = EXT2_INODES_PER_GROUP(scan->fs->super); in ext2fs_open_inode_scan()
149 scan->blocks_left = scan->fs->inode_blocks_per_group; in ext2fs_open_inode_scan()
150 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, in ext2fs_open_inode_scan()
153 ext2fs_bg_itable_unused(fs, scan->current_group); in ext2fs_open_inode_scan()
156 (fs->blocksize / scan->inode_size - 1)) * in ext2fs_open_inode_scan()
157 scan->inode_size / fs->blocksize; in ext2fs_open_inode_scan()
159 retval = io_channel_alloc_buf(fs->io, scan->inode_buffer_blocks, in ext2fs_open_inode_scan()
174 if (scan->fs->badblocks && scan->fs->badblocks->num) in ext2fs_open_inode_scan()
176 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, in ext2fs_open_inode_scan()
197 errcode_t (*done_group)(ext2_filsys fs, in ext2fs_set_inode_callback() argument
230 ext2_filsys fs = scan->fs; in get_next_blockgroup() local
235 scan->current_block = ext2fs_inode_table_loc(scan->fs, in get_next_blockgroup()
238 EXT2_INODES_PER_GROUP(fs->super); in get_next_blockgroup()
241 scan->inodes_left = EXT2_INODES_PER_GROUP(fs->super); in get_next_blockgroup()
242 scan->blocks_left = fs->inode_blocks_per_group; in get_next_blockgroup()
243 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, in get_next_blockgroup()
246 ext2fs_bg_itable_unused(fs, scan->current_group); in get_next_blockgroup()
249 (fs->blocksize / scan->inode_size - 1)) * in get_next_blockgroup()
250 scan->inode_size / fs->blocksize; in get_next_blockgroup()
260 scan->groups_left = scan->fs->group_desc_count - group; in ext2fs_inode_scan_goto_blockgroup()
275 badblocks_list bb = scan->fs->badblocks; in check_for_inode_bad_blocks()
365 (size_t) num_blocks * scan->fs->blocksize); in get_next_blocks()
367 retval = io_channel_read_blk64(scan->fs->io, in get_next_blocks()
375 scan->bytes_left = num_blocks * scan->fs->blocksize; in get_next_blocks()
419 (scan->fs, scan, scan->current_group, in ext2fs_get_next_inode_full()
437 (ext2fs_bg_flags_test(scan->fs, scan->current_group, EXT2_BG_INODE_UNINIT) in ext2fs_get_next_inode_full()
480 ext2fs_swap_inode_full(scan->fs, in ext2fs_get_next_inode_full()
493 ext2fs_swap_inode_full(scan->fs, in ext2fs_get_next_inode_full()
522 errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, in ext2fs_read_inode_full() argument
532 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); in ext2fs_read_inode_full()
535 if (fs->read_inode && in ext2fs_read_inode_full()
537 (EXT2_INODE_SIZE(fs->super) == sizeof(struct ext2_inode)))) { in ext2fs_read_inode_full()
538 retval = (fs->read_inode)(fs, ino, inode); in ext2fs_read_inode_full()
542 if ((ino == 0) || (ino > fs->super->s_inodes_count)) in ext2fs_read_inode_full()
545 if (!fs->icache) { in ext2fs_read_inode_full()
546 retval = create_icache(fs); in ext2fs_read_inode_full()
553 for (i=0; i < fs->icache->cache_size; i++) { in ext2fs_read_inode_full()
554 if (fs->icache->cache[i].ino == ino) { in ext2fs_read_inode_full()
555 *inode = fs->icache->cache[i].inode; in ext2fs_read_inode_full()
560 if (fs->flags & EXT2_FLAG_IMAGE_FILE) { in ext2fs_read_inode_full()
561 inodes_per_block = fs->blocksize / EXT2_INODE_SIZE(fs->super); in ext2fs_read_inode_full()
562 block_nr = fs->image_header->offset_inode / fs->blocksize; in ext2fs_read_inode_full()
565 EXT2_INODE_SIZE(fs->super); in ext2fs_read_inode_full()
566 io = fs->image_io; in ext2fs_read_inode_full()
568 group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super); in ext2fs_read_inode_full()
569 if (group > fs->group_desc_count) in ext2fs_read_inode_full()
571 offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) * in ext2fs_read_inode_full()
572 EXT2_INODE_SIZE(fs->super); in ext2fs_read_inode_full()
573 block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super); in ext2fs_read_inode_full()
574 if (!ext2fs_inode_table_loc(fs, (unsigned) group)) in ext2fs_read_inode_full()
576 block_nr = ext2fs_inode_table_loc(fs, group) + in ext2fs_read_inode_full()
578 io = fs->io; in ext2fs_read_inode_full()
580 offset &= (EXT2_BLOCK_SIZE(fs->super) - 1); in ext2fs_read_inode_full()
582 length = EXT2_INODE_SIZE(fs->super); in ext2fs_read_inode_full()
589 if ((offset + length) > fs->blocksize) in ext2fs_read_inode_full()
590 clen = fs->blocksize - offset; in ext2fs_read_inode_full()
592 if (block_nr != fs->icache->buffer_blk) { in ext2fs_read_inode_full()
594 fs->icache->buffer); in ext2fs_read_inode_full()
597 fs->icache->buffer_blk = block_nr; in ext2fs_read_inode_full()
600 memcpy(ptr, ((char *) fs->icache->buffer) + (unsigned) offset, in ext2fs_read_inode_full()
610 ext2fs_swap_inode_full(fs, (struct ext2_inode_large *) inode, in ext2fs_read_inode_full()
616 fs->icache->cache_last = (fs->icache->cache_last + 1) % in ext2fs_read_inode_full()
617 fs->icache->cache_size; in ext2fs_read_inode_full()
618 fs->icache->cache[fs->icache->cache_last].ino = ino; in ext2fs_read_inode_full()
619 fs->icache->cache[fs->icache->cache_last].inode = *inode; in ext2fs_read_inode_full()
624 errcode_t ext2fs_read_inode(ext2_filsys fs, ext2_ino_t ino, in ext2fs_read_inode() argument
627 return ext2fs_read_inode_full(fs, ino, inode, in ext2fs_read_inode()
631 errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, in ext2fs_write_inode_full() argument
641 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); in ext2fs_write_inode_full()
644 if (fs->write_inode) { in ext2fs_write_inode_full()
645 retval = (fs->write_inode)(fs, ino, inode); in ext2fs_write_inode_full()
651 if (fs->icache) { in ext2fs_write_inode_full()
652 for (i=0; i < fs->icache->cache_size; i++) { in ext2fs_write_inode_full()
653 if (fs->icache->cache[i].ino == ino) { in ext2fs_write_inode_full()
654 fs->icache->cache[i].inode = *inode; in ext2fs_write_inode_full()
659 retval = create_icache(fs); in ext2fs_write_inode_full()
664 if (!(fs->flags & EXT2_FLAG_RW)) in ext2fs_write_inode_full()
667 if ((ino == 0) || (ino > fs->super->s_inodes_count)) in ext2fs_write_inode_full()
671 if (length < EXT2_INODE_SIZE(fs->super)) in ext2fs_write_inode_full()
672 length = EXT2_INODE_SIZE(fs->super); in ext2fs_write_inode_full()
685 ext2fs_swap_inode_full(fs, w_inode, in ext2fs_write_inode_full()
692 group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super); in ext2fs_write_inode_full()
693 offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) * in ext2fs_write_inode_full()
694 EXT2_INODE_SIZE(fs->super); in ext2fs_write_inode_full()
695 block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super); in ext2fs_write_inode_full()
696 if (!ext2fs_inode_table_loc(fs, (unsigned) group)) { in ext2fs_write_inode_full()
700 block_nr = ext2fs_inode_table_loc(fs, (unsigned) group) + block; in ext2fs_write_inode_full()
702 offset &= (EXT2_BLOCK_SIZE(fs->super) - 1); in ext2fs_write_inode_full()
704 length = EXT2_INODE_SIZE(fs->super); in ext2fs_write_inode_full()
712 if ((offset + length) > fs->blocksize) in ext2fs_write_inode_full()
713 clen = fs->blocksize - offset; in ext2fs_write_inode_full()
715 if (fs->icache->buffer_blk != block_nr) { in ext2fs_write_inode_full()
716 retval = io_channel_read_blk64(fs->io, block_nr, 1, in ext2fs_write_inode_full()
717 fs->icache->buffer); in ext2fs_write_inode_full()
720 fs->icache->buffer_blk = block_nr; in ext2fs_write_inode_full()
724 memcpy((char *) fs->icache->buffer + (unsigned) offset, in ext2fs_write_inode_full()
727 retval = io_channel_write_blk64(fs->io, block_nr, 1, in ext2fs_write_inode_full()
728 fs->icache->buffer); in ext2fs_write_inode_full()
738 fs->flags |= EXT2_FLAG_CHANGED; in ext2fs_write_inode_full()
745 errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino, in ext2fs_write_inode() argument
748 return ext2fs_write_inode_full(fs, ino, inode, in ext2fs_write_inode()
756 errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino, in ext2fs_write_new_inode() argument
760 int size = EXT2_INODE_SIZE(fs->super); in ext2fs_write_new_inode()
763 __u32 t = fs->now ? fs->now : time(NULL); in ext2fs_write_new_inode()
773 return ext2fs_write_inode_full(fs, ino, inode, in ext2fs_write_new_inode()
789 retval = ext2fs_write_inode_full(fs, ino, buf, size); in ext2fs_write_new_inode()
795 errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks) in ext2fs_get_blocks() argument
801 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); in ext2fs_get_blocks()
803 if (ino > fs->super->s_inodes_count) in ext2fs_get_blocks()
806 if (fs->get_blocks) { in ext2fs_get_blocks()
807 if (!(*fs->get_blocks)(fs, ino, blocks)) in ext2fs_get_blocks()
810 retval = ext2fs_read_inode(fs, ino, &inode); in ext2fs_get_blocks()
818 errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino) in ext2fs_check_directory() argument
823 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); in ext2fs_check_directory()
825 if (ino > fs->super->s_inodes_count) in ext2fs_check_directory()
828 if (fs->check_directory) { in ext2fs_check_directory()
829 retval = (fs->check_directory)(fs, ino); in ext2fs_check_directory()
833 retval = ext2fs_read_inode(fs, ino, &inode); in ext2fs_check_directory()