Lines Matching refs:fs
39 ext2_filsys fs; member
52 errcode_t (*done_group)(ext2_filsys fs,
65 errcode_t ext2fs_flush_icache(ext2_filsys fs) in ext2fs_flush_icache() argument
69 if (!fs->icache) in ext2fs_flush_icache()
72 for (i=0; i < fs->icache->cache_size; i++) in ext2fs_flush_icache()
73 fs->icache->cache[i].ino = 0; in ext2fs_flush_icache()
75 fs->icache->buffer_blk = 0; in ext2fs_flush_icache()
98 errcode_t ext2fs_create_inode_cache(ext2_filsys fs, unsigned int cache_size) in ext2fs_create_inode_cache() argument
103 if (fs->icache) in ext2fs_create_inode_cache()
105 retval = ext2fs_get_mem(sizeof(struct ext2_inode_cache), &fs->icache); in ext2fs_create_inode_cache()
109 memset(fs->icache, 0, sizeof(struct ext2_inode_cache)); in ext2fs_create_inode_cache()
110 retval = ext2fs_get_mem(fs->blocksize, &fs->icache->buffer); in ext2fs_create_inode_cache()
114 fs->icache->buffer_blk = 0; in ext2fs_create_inode_cache()
115 fs->icache->cache_last = -1; in ext2fs_create_inode_cache()
116 fs->icache->cache_size = cache_size; in ext2fs_create_inode_cache()
117 fs->icache->refcount = 1; in ext2fs_create_inode_cache()
118 retval = ext2fs_get_array(fs->icache->cache_size, in ext2fs_create_inode_cache()
120 &fs->icache->cache); in ext2fs_create_inode_cache()
124 for (i = 0; i < fs->icache->cache_size; i++) { in ext2fs_create_inode_cache()
125 retval = ext2fs_get_mem(EXT2_INODE_SIZE(fs->super), in ext2fs_create_inode_cache()
126 &fs->icache->cache[i].inode); in ext2fs_create_inode_cache()
131 ext2fs_flush_icache(fs); in ext2fs_create_inode_cache()
134 ext2fs_free_inode_cache(fs->icache); in ext2fs_create_inode_cache()
135 fs->icache = 0; in ext2fs_create_inode_cache()
139 errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks, in ext2fs_open_inode_scan() argument
146 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); in ext2fs_open_inode_scan()
152 if (fs->badblocks == 0) { in ext2fs_open_inode_scan()
157 save_get_blocks = fs->get_blocks; in ext2fs_open_inode_scan()
158 fs->get_blocks = 0; in ext2fs_open_inode_scan()
159 retval = ext2fs_read_bb_inode(fs, &fs->badblocks); in ext2fs_open_inode_scan()
160 if (retval && fs->badblocks) { in ext2fs_open_inode_scan()
161 ext2fs_badblocks_list_free(fs->badblocks); in ext2fs_open_inode_scan()
162 fs->badblocks = 0; in ext2fs_open_inode_scan()
164 fs->get_blocks = save_get_blocks; in ext2fs_open_inode_scan()
173 scan->fs = fs; in ext2fs_open_inode_scan()
174 scan->inode_size = EXT2_INODE_SIZE(fs->super); in ext2fs_open_inode_scan()
177 scan->groups_left = fs->group_desc_count - 1; in ext2fs_open_inode_scan()
180 scan->current_block = ext2fs_inode_table_loc(scan->fs, in ext2fs_open_inode_scan()
182 scan->inodes_left = EXT2_INODES_PER_GROUP(scan->fs->super); in ext2fs_open_inode_scan()
183 scan->blocks_left = scan->fs->inode_blocks_per_group; in ext2fs_open_inode_scan()
184 if (ext2fs_has_group_desc_csum(fs)) { in ext2fs_open_inode_scan()
185 __u32 unused = ext2fs_bg_itable_unused(fs, scan->current_group); in ext2fs_open_inode_scan()
192 (fs->blocksize / scan->inode_size - 1)) * in ext2fs_open_inode_scan()
193 scan->inode_size / fs->blocksize; in ext2fs_open_inode_scan()
195 retval = io_channel_alloc_buf(fs->io, scan->inode_buffer_blocks, in ext2fs_open_inode_scan()
212 if (scan->fs->badblocks && scan->fs->badblocks->num) in ext2fs_open_inode_scan()
214 if (ext2fs_has_group_desc_csum(fs)) in ext2fs_open_inode_scan()
234 errcode_t (*done_group)(ext2_filsys fs, in ext2fs_set_inode_callback() argument
267 ext2_filsys fs = scan->fs; in get_next_blockgroup() local
272 scan->current_block = ext2fs_inode_table_loc(scan->fs, in get_next_blockgroup()
275 EXT2_INODES_PER_GROUP(fs->super); in get_next_blockgroup()
278 scan->inodes_left = EXT2_INODES_PER_GROUP(fs->super); in get_next_blockgroup()
279 scan->blocks_left = fs->inode_blocks_per_group; in get_next_blockgroup()
280 if (ext2fs_has_group_desc_csum(fs)) { in get_next_blockgroup()
281 __u32 unused = ext2fs_bg_itable_unused(fs, scan->current_group); in get_next_blockgroup()
288 (fs->blocksize / scan->inode_size - 1)) * in get_next_blockgroup()
289 scan->inode_size / fs->blocksize; in get_next_blockgroup()
299 scan->groups_left = scan->fs->group_desc_count - group; in ext2fs_inode_scan_goto_blockgroup()
314 badblocks_list bb = scan->fs->badblocks; in check_for_inode_bad_blocks()
364 static int block_map_looks_insane(ext2_filsys fs, in block_map_looks_insane() argument
388 (inode->i_block[i] < fs->super->s_first_data_block || in block_map_looks_insane()
389 inode->i_block[i] >= ext2fs_blocks_count(fs->super))) in block_map_looks_insane()
422 inodes_in_buf = num_blocks * scan->fs->blocksize / scan->inode_size; in check_inode_block_sanity()
431 inodes_per_block = EXT2_INODES_PER_BLOCK(scan->fs->super); in check_inode_block_sanity()
437 if (ext2fs_get_mem(EXT2_INODE_SIZE(scan->fs->super), &inode)) in check_inode_block_sanity()
442 blk = (p - (char *)scan->inode_buffer) / scan->fs->blocksize; in check_inode_block_sanity()
443 bad_csum = ext2fs_inode_csum_verify(scan->fs, ino, in check_inode_block_sanity()
447 ext2fs_swap_inode_full(scan->fs, in check_inode_block_sanity()
450 0, EXT2_INODE_SIZE(scan->fs->super)); in check_inode_block_sanity()
460 block_map_looks_insane(scan->fs, inode)) in check_inode_block_sanity()
534 (size_t) num_blocks * scan->fs->blocksize); in get_next_blocks()
536 retval = io_channel_read_blk64(scan->fs->io, in get_next_blocks()
546 scan->bytes_left = num_blocks * scan->fs->blocksize; in get_next_blocks()
587 length = EXT2_INODE_SIZE(scan->fs->super); in ext2fs_get_next_inode_full()
597 (scan->fs, scan, scan->current_group, in ext2fs_get_next_inode_full()
615 (ext2fs_bg_flags_test(scan->fs, scan->current_group, EXT2_BG_INODE_UNINIT) in ext2fs_get_next_inode_full()
657 iblk = scan->current_inode % EXT2_INODES_PER_GROUP(scan->fs->super) / in ext2fs_get_next_inode_full()
658 EXT2_INODES_PER_BLOCK(scan->fs->super) % in ext2fs_get_next_inode_full()
668 !(scan->fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) && in ext2fs_get_next_inode_full()
669 !ext2fs_inode_csum_verify(scan->fs, scan->current_inode + 1, in ext2fs_get_next_inode_full()
675 ext2fs_swap_inode_full(scan->fs, in ext2fs_get_next_inode_full()
688 !(scan->fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) && in ext2fs_get_next_inode_full()
689 !ext2fs_inode_csum_verify(scan->fs, scan->current_inode + 1, in ext2fs_get_next_inode_full()
695 ext2fs_swap_inode_full(scan->fs, in ext2fs_get_next_inode_full()
731 errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, in ext2fs_read_inode_full() argument
741 int length = EXT2_INODE_SIZE(fs->super); in ext2fs_read_inode_full()
745 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); in ext2fs_read_inode_full()
748 if (fs->read_inode && in ext2fs_read_inode_full()
750 (EXT2_INODE_SIZE(fs->super) == sizeof(struct ext2_inode)))) { in ext2fs_read_inode_full()
751 retval = (fs->read_inode)(fs, ino, inode); in ext2fs_read_inode_full()
755 if ((ino == 0) || (ino > fs->super->s_inodes_count)) in ext2fs_read_inode_full()
758 if (!fs->icache) { in ext2fs_read_inode_full()
759 retval = ext2fs_create_inode_cache(fs, 4); in ext2fs_read_inode_full()
764 for (i = 0; i < fs->icache->cache_size; i++) { in ext2fs_read_inode_full()
765 if (fs->icache->cache[i].ino == ino) { in ext2fs_read_inode_full()
766 memcpy(inode, fs->icache->cache[i].inode, in ext2fs_read_inode_full()
771 if (fs->flags & EXT2_FLAG_IMAGE_FILE) { in ext2fs_read_inode_full()
772 inodes_per_block = fs->blocksize / EXT2_INODE_SIZE(fs->super); in ext2fs_read_inode_full()
773 block_nr = ext2fs_le32_to_cpu(fs->image_header->offset_inode) / fs->blocksize; in ext2fs_read_inode_full()
776 EXT2_INODE_SIZE(fs->super); in ext2fs_read_inode_full()
777 io = fs->image_io; in ext2fs_read_inode_full()
779 group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super); in ext2fs_read_inode_full()
780 if (group > fs->group_desc_count) in ext2fs_read_inode_full()
782 offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) * in ext2fs_read_inode_full()
783 EXT2_INODE_SIZE(fs->super); in ext2fs_read_inode_full()
784 block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super); in ext2fs_read_inode_full()
785 if (!ext2fs_inode_table_loc(fs, (unsigned) group)) in ext2fs_read_inode_full()
787 block_nr = ext2fs_inode_table_loc(fs, group) + in ext2fs_read_inode_full()
789 io = fs->io; in ext2fs_read_inode_full()
791 offset &= (EXT2_BLOCK_SIZE(fs->super) - 1); in ext2fs_read_inode_full()
793 cache_slot = (fs->icache->cache_last + 1) % fs->icache->cache_size; in ext2fs_read_inode_full()
794 iptr = (struct ext2_inode_large *)fs->icache->cache[cache_slot].inode; in ext2fs_read_inode_full()
799 if ((offset + length) > fs->blocksize) in ext2fs_read_inode_full()
800 clen = fs->blocksize - offset; in ext2fs_read_inode_full()
802 if (block_nr != fs->icache->buffer_blk) { in ext2fs_read_inode_full()
804 fs->icache->buffer); in ext2fs_read_inode_full()
807 fs->icache->buffer_blk = block_nr; in ext2fs_read_inode_full()
810 memcpy(ptr, ((char *) fs->icache->buffer) + (unsigned) offset, in ext2fs_read_inode_full()
818 length = EXT2_INODE_SIZE(fs->super); in ext2fs_read_inode_full()
821 fail_csum = !ext2fs_inode_csum_verify(fs, ino, iptr); in ext2fs_read_inode_full()
824 ext2fs_swap_inode_full(fs, (struct ext2_inode_large *) iptr, in ext2fs_read_inode_full()
831 fs->icache->cache_last = cache_slot; in ext2fs_read_inode_full()
832 fs->icache->cache[cache_slot].ino = ino; in ext2fs_read_inode_full()
836 if (!(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) && fail_csum) in ext2fs_read_inode_full()
842 errcode_t ext2fs_read_inode(ext2_filsys fs, ext2_ino_t ino, in ext2fs_read_inode() argument
845 return ext2fs_read_inode_full(fs, ino, inode, in ext2fs_read_inode()
849 errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, in ext2fs_write_inode_full() argument
859 int length = EXT2_INODE_SIZE(fs->super); in ext2fs_write_inode_full()
861 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); in ext2fs_write_inode_full()
864 if (fs->write_inode) { in ext2fs_write_inode_full()
865 retval = (fs->write_inode)(fs, ino, inode); in ext2fs_write_inode_full()
870 if ((ino == 0) || (ino > fs->super->s_inodes_count)) in ext2fs_write_inode_full()
879 int old_flags = fs->flags; in ext2fs_write_inode_full()
880 fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS; in ext2fs_write_inode_full()
881 retval = ext2fs_read_inode_full(fs, ino, in ext2fs_write_inode_full()
884 fs->flags = (old_flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) | in ext2fs_write_inode_full()
885 (fs->flags & ~EXT2_FLAG_IGNORE_CSUM_ERRORS); in ext2fs_write_inode_full()
891 if (fs->icache) { in ext2fs_write_inode_full()
892 for (i=0; i < fs->icache->cache_size; i++) { in ext2fs_write_inode_full()
893 if (fs->icache->cache[i].ino == ino) { in ext2fs_write_inode_full()
894 memcpy(fs->icache->cache[i].inode, inode, in ext2fs_write_inode_full()
900 retval = ext2fs_create_inode_cache(fs, 4); in ext2fs_write_inode_full()
906 if (!(fs->flags & EXT2_FLAG_RW)) { in ext2fs_write_inode_full()
912 ext2fs_swap_inode_full(fs, w_inode, w_inode, 1, length); in ext2fs_write_inode_full()
915 retval = ext2fs_inode_csum_set(fs, ino, w_inode); in ext2fs_write_inode_full()
919 group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super); in ext2fs_write_inode_full()
920 offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) * in ext2fs_write_inode_full()
921 EXT2_INODE_SIZE(fs->super); in ext2fs_write_inode_full()
922 block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super); in ext2fs_write_inode_full()
923 if (!ext2fs_inode_table_loc(fs, (unsigned) group)) { in ext2fs_write_inode_full()
927 block_nr = ext2fs_inode_table_loc(fs, (unsigned) group) + block; in ext2fs_write_inode_full()
929 offset &= (EXT2_BLOCK_SIZE(fs->super) - 1); in ext2fs_write_inode_full()
935 if ((offset + length) > fs->blocksize) in ext2fs_write_inode_full()
936 clen = fs->blocksize - offset; in ext2fs_write_inode_full()
938 if (fs->icache->buffer_blk != block_nr) { in ext2fs_write_inode_full()
939 retval = io_channel_read_blk64(fs->io, block_nr, 1, in ext2fs_write_inode_full()
940 fs->icache->buffer); in ext2fs_write_inode_full()
943 fs->icache->buffer_blk = block_nr; in ext2fs_write_inode_full()
947 memcpy((char *) fs->icache->buffer + (unsigned) offset, in ext2fs_write_inode_full()
950 retval = io_channel_write_blk64(fs->io, block_nr, 1, in ext2fs_write_inode_full()
951 fs->icache->buffer); in ext2fs_write_inode_full()
961 fs->flags |= EXT2_FLAG_CHANGED; in ext2fs_write_inode_full()
967 errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino, in ext2fs_write_inode() argument
970 return ext2fs_write_inode_full(fs, ino, inode, in ext2fs_write_inode()
978 errcode_t ext2fs_write_new_inode(ext2_filsys fs, ext2_ino_t ino, in ext2fs_write_new_inode() argument
982 int size = EXT2_INODE_SIZE(fs->super); in ext2fs_write_new_inode()
985 __u32 t = fs->now ? fs->now : time(NULL); in ext2fs_write_new_inode()
995 return ext2fs_write_inode_full(fs, ino, inode, in ext2fs_write_new_inode()
1011 retval = ext2fs_write_inode_full(fs, ino, buf, size); in ext2fs_write_new_inode()
1017 errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks) in ext2fs_get_blocks() argument
1023 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); in ext2fs_get_blocks()
1025 if (ino > fs->super->s_inodes_count) in ext2fs_get_blocks()
1028 if (fs->get_blocks) { in ext2fs_get_blocks()
1029 if (!(*fs->get_blocks)(fs, ino, blocks)) in ext2fs_get_blocks()
1032 retval = ext2fs_read_inode(fs, ino, &inode); in ext2fs_get_blocks()
1040 errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino) in ext2fs_check_directory() argument
1045 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); in ext2fs_check_directory()
1047 if (ino > fs->super->s_inodes_count) in ext2fs_check_directory()
1050 if (fs->check_directory) { in ext2fs_check_directory()
1051 retval = (fs->check_directory)(fs, ino); in ext2fs_check_directory()
1055 retval = ext2fs_read_inode(fs, ino, &inode); in ext2fs_check_directory()