Lines Matching +full:- +full:fs
2 * inode.c --- utility routines to read and write inodes
6 * %Begin-Header%
9 * %End-Header%
35 #define SCAN_BLOCK_STATUS(scan) ((scan)->temp_buffer + (scan)->inode_size)
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()
86 if (--icache->refcount) in ext2fs_free_inode_cache()
88 if (icache->buffer) in ext2fs_free_inode_cache()
89 ext2fs_free_mem(&icache->buffer); in ext2fs_free_inode_cache()
90 for (i = 0; i < icache->cache_size; i++) in ext2fs_free_inode_cache()
91 ext2fs_free_mem(&icache->cache[i].inode); in ext2fs_free_inode_cache()
92 if (icache->cache) in ext2fs_free_inode_cache()
93 ext2fs_free_mem(&icache->cache); in ext2fs_free_inode_cache()
94 icache->buffer_blk = 0; in ext2fs_free_inode_cache()
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()
149 * If fs->badblocks isn't set, then set it --- since the inode in ext2fs_open_inode_scan()
152 if (fs->badblocks == 0) { in ext2fs_open_inode_scan()
154 * Temporarily save fs->get_blocks and set it to zero, 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()
172 scan->magic = EXT2_ET_MAGIC_INODE_SCAN; 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()
175 scan->bytes_left = 0; in ext2fs_open_inode_scan()
176 scan->current_group = 0; in ext2fs_open_inode_scan()
177 scan->groups_left = fs->group_desc_count - 1; in ext2fs_open_inode_scan()
178 scan->inode_buffer_blocks = buffer_blocks ? buffer_blocks : in ext2fs_open_inode_scan()
180 scan->current_block = ext2fs_inode_table_loc(scan->fs, in ext2fs_open_inode_scan()
181 scan->current_group); 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()
186 if (scan->inodes_left > unused) in ext2fs_open_inode_scan()
187 scan->inodes_left -= unused; in ext2fs_open_inode_scan()
189 scan->inodes_left = 0; in ext2fs_open_inode_scan()
190 scan->blocks_left = in ext2fs_open_inode_scan()
191 (scan->inodes_left + 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()
196 &scan->inode_buffer); in ext2fs_open_inode_scan()
197 scan->done_group = 0; in ext2fs_open_inode_scan()
198 scan->done_group_data = 0; in ext2fs_open_inode_scan()
199 scan->bad_block_ptr = 0; in ext2fs_open_inode_scan()
204 retval = ext2fs_get_mem(scan->inode_size + scan->inode_buffer_blocks, in ext2fs_open_inode_scan()
205 &scan->temp_buffer); in ext2fs_open_inode_scan()
207 ext2fs_free_mem(&scan->inode_buffer); in ext2fs_open_inode_scan()
211 memset(SCAN_BLOCK_STATUS(scan), 0, scan->inode_buffer_blocks); in ext2fs_open_inode_scan()
212 if (scan->fs->badblocks && scan->fs->badblocks->num) in ext2fs_open_inode_scan()
213 scan->scan_flags |= EXT2_SF_CHK_BADBLOCKS; in ext2fs_open_inode_scan()
214 if (ext2fs_has_group_desc_csum(fs)) in ext2fs_open_inode_scan()
215 scan->scan_flags |= EXT2_SF_DO_LAZY; in ext2fs_open_inode_scan()
222 if (!scan || (scan->magic != EXT2_ET_MAGIC_INODE_SCAN)) in ext2fs_close_inode_scan()
225 ext2fs_free_mem(&scan->inode_buffer); in ext2fs_close_inode_scan()
226 scan->inode_buffer = NULL; in ext2fs_close_inode_scan()
227 ext2fs_free_mem(&scan->temp_buffer); in ext2fs_close_inode_scan()
228 scan->temp_buffer = NULL; in ext2fs_close_inode_scan()
234 errcode_t (*done_group)(ext2_filsys fs, in ext2fs_set_inode_callback() argument
240 if (!scan || (scan->magic != EXT2_ET_MAGIC_INODE_SCAN)) in ext2fs_set_inode_callback()
243 scan->done_group = done_group; in ext2fs_set_inode_callback()
244 scan->done_group_data = done_group_data; in ext2fs_set_inode_callback()
252 if (!scan || (scan->magic != EXT2_ET_MAGIC_INODE_SCAN)) in ext2fs_inode_scan_flags()
255 old_flags = scan->scan_flags; in ext2fs_inode_scan_flags()
256 scan->scan_flags &= ~clear_flags; in ext2fs_inode_scan_flags()
257 scan->scan_flags |= set_flags; in ext2fs_inode_scan_flags()
267 ext2_filsys fs = scan->fs; in get_next_blockgroup() local
269 scan->current_group++; in get_next_blockgroup()
270 scan->groups_left--; in get_next_blockgroup()
272 scan->current_block = ext2fs_inode_table_loc(scan->fs, in get_next_blockgroup()
273 scan->current_group); in get_next_blockgroup()
274 scan->current_inode = scan->current_group * in get_next_blockgroup()
275 EXT2_INODES_PER_GROUP(fs->super); in get_next_blockgroup()
277 scan->bytes_left = 0; 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()
282 if (scan->inodes_left > unused) in get_next_blockgroup()
283 scan->inodes_left -= unused; in get_next_blockgroup()
285 scan->inodes_left = 0; in get_next_blockgroup()
286 scan->blocks_left = in get_next_blockgroup()
287 (scan->inodes_left + 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()
298 scan->current_group = group - 1; in ext2fs_inode_scan_goto_blockgroup()
299 scan->groups_left = scan->fs->group_desc_count - group; in ext2fs_inode_scan_goto_blockgroup()
307 * This function assumes that badblocks_list->list is sorted in
313 blk64_t blk = scan->current_block; in check_for_inode_bad_blocks()
314 badblocks_list bb = scan->fs->badblocks; in check_for_inode_bad_blocks()
318 * bad blocks. :-) in check_for_inode_bad_blocks()
329 while (blk > bb->list[scan->bad_block_ptr]) { in check_for_inode_bad_blocks()
330 if (++scan->bad_block_ptr >= bb->num) { in check_for_inode_bad_blocks()
331 scan->scan_flags &= ~EXT2_SF_CHK_BADBLOCKS; in check_for_inode_bad_blocks()
344 if (blk == bb->list[scan->bad_block_ptr]) { in check_for_inode_bad_blocks()
345 scan->scan_flags |= EXT2_SF_BAD_INODE_BLK; in check_for_inode_bad_blocks()
347 if (++scan->bad_block_ptr >= bb->num) in check_for_inode_bad_blocks()
348 scan->scan_flags &= ~EXT2_SF_CHK_BADBLOCKS; in check_for_inode_bad_blocks()
358 if ((blk + *num_blocks) > bb->list[scan->bad_block_ptr]) in check_for_inode_bad_blocks()
359 *num_blocks = (int) (bb->list[scan->bad_block_ptr] - blk); in check_for_inode_bad_blocks()
364 static int block_map_looks_insane(ext2_filsys fs, in block_map_looks_insane() argument
370 if ((inode->i_flags & EXT4_INLINE_DATA_FL) || in block_map_looks_insane()
371 (inode->i_flags & EXT4_EXTENTS_FL)) in block_map_looks_insane()
373 if (!LINUX_S_ISREG(inode->i_mode) && in block_map_looks_insane()
374 !LINUX_S_ISLNK(inode->i_mode) && in block_map_looks_insane()
375 !LINUX_S_ISDIR(inode->i_mode)) in block_map_looks_insane()
377 if (LINUX_S_ISLNK(inode->i_mode) && in block_map_looks_insane()
378 EXT2_I_SIZE(inode) <= sizeof(inode->i_block)) in block_map_looks_insane()
382 if (inode->i_links_count == 0) in block_map_looks_insane()
387 if (inode->i_block[i] != 0 && in block_map_looks_insane()
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()
396 if (!(inode->i_flags & EXT4_EXTENTS_FL) || in extent_head_looks_insane()
397 ext2fs_extent_header_verify(inode->i_block, in extent_head_looks_insane()
398 sizeof(inode->i_block)) == 0) in extent_head_looks_insane()
405 * find here -- currently, we can observe that all checksums are ok; more
418 if (!(scan->scan_flags & EXT2_SF_WARN_GARBAGE_INODES)) in check_inode_block_sanity()
421 inodes_to_scan = scan->inodes_left; in check_inode_block_sanity()
422 inodes_in_buf = num_blocks * scan->fs->blocksize / scan->inode_size; in check_inode_block_sanity()
426 p = (char *) scan->inode_buffer; in check_inode_block_sanity()
427 ino = scan->current_inode + 1; in check_inode_block_sanity()
430 memset(block_status, 0, scan->inode_buffer_blocks); 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()
468 ino_adj = inodes_per_block - in check_inode_block_sanity()
469 ((ino - 1) % inodes_per_block); in check_inode_block_sanity()
472 inodes_to_scan -= ino_adj; in check_inode_block_sanity()
473 p += scan->inode_size * ino_adj; in check_inode_block_sanity()
484 inodes_to_scan--; in check_inode_block_sanity()
485 p += scan->inode_size; in check_inode_block_sanity()
508 num_blocks = scan->inode_buffer_blocks; in get_next_blocks()
509 if (num_blocks > scan->blocks_left) in get_next_blocks()
510 num_blocks = scan->blocks_left; in get_next_blocks()
514 * left-over extra bytes as also being bad. in get_next_blocks()
516 if (scan->scan_flags & EXT2_SF_BAD_INODE_BLK) { in get_next_blocks()
517 if (scan->bytes_left) in get_next_blocks()
518 scan->scan_flags |= EXT2_SF_BAD_EXTRA_BYTES; in get_next_blocks()
519 scan->scan_flags &= ~EXT2_SF_BAD_INODE_BLK; in get_next_blocks()
525 if (scan->scan_flags & EXT2_SF_CHK_BADBLOCKS) { in get_next_blocks()
531 if ((scan->scan_flags & EXT2_SF_BAD_INODE_BLK) || in get_next_blocks()
532 (scan->current_block == 0)) { in get_next_blocks()
533 memset(scan->inode_buffer, 0, in get_next_blocks()
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()
537 scan->current_block, in get_next_blocks()
539 scan->inode_buffer); in get_next_blocks()
545 scan->ptr = scan->inode_buffer; in get_next_blocks()
546 scan->bytes_left = num_blocks * scan->fs->blocksize; in get_next_blocks()
548 scan->blocks_left -= num_blocks; in get_next_blocks()
549 if (scan->current_block) in get_next_blocks()
550 scan->current_block += num_blocks; in get_next_blocks()
557 * Returns 1 if the entire inode_buffer has a non-zero size and
566 if (scan->bytes_left == 0)
569 for (i=0; i < scan->bytes_left; i++)
570 if (scan->ptr[i])
587 length = EXT2_INODE_SIZE(scan->fs->super); in ext2fs_get_next_inode_full()
593 if (scan->inodes_left <= 0) { in ext2fs_get_next_inode_full()
595 if (scan->done_group) { in ext2fs_get_next_inode_full()
596 retval = (scan->done_group) in ext2fs_get_next_inode_full()
597 (scan->fs, scan, scan->current_group, in ext2fs_get_next_inode_full()
598 scan->done_group_data); in ext2fs_get_next_inode_full()
602 if (scan->groups_left <= 0) { in ext2fs_get_next_inode_full()
614 if ((scan->scan_flags & EXT2_SF_DO_LAZY) && 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()
618 if (scan->inodes_left == 0) in ext2fs_get_next_inode_full()
620 if (scan->current_block == 0) { in ext2fs_get_next_inode_full()
621 if (scan->scan_flags & EXT2_SF_SKIP_MISSING_ITABLE) { in ext2fs_get_next_inode_full()
632 if (scan->bytes_left < scan->inode_size) { in ext2fs_get_next_inode_full()
633 if (scan->bytes_left) in ext2fs_get_next_inode_full()
634 memcpy(scan->temp_buffer, scan->ptr, scan->bytes_left); in ext2fs_get_next_inode_full()
635 extra_bytes = scan->bytes_left; 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()
659 scan->inode_buffer_blocks; in ext2fs_get_next_inode_full()
661 memcpy(scan->temp_buffer+extra_bytes, scan->ptr, in ext2fs_get_next_inode_full()
662 scan->inode_size - extra_bytes); in ext2fs_get_next_inode_full()
663 scan->ptr += scan->inode_size - extra_bytes; in ext2fs_get_next_inode_full()
664 scan->bytes_left -= scan->inode_size - extra_bytes; 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()
670 (struct ext2_inode_large *)scan->temp_buffer)) in ext2fs_get_next_inode_full()
675 ext2fs_swap_inode_full(scan->fs, in ext2fs_get_next_inode_full()
677 (struct ext2_inode_large *) scan->temp_buffer, in ext2fs_get_next_inode_full()
680 memcpy(iptr, scan->temp_buffer, length); in ext2fs_get_next_inode_full()
682 if (scan->scan_flags & EXT2_SF_BAD_EXTRA_BYTES) in ext2fs_get_next_inode_full()
684 scan->scan_flags &= ~EXT2_SF_BAD_EXTRA_BYTES; 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()
690 (struct ext2_inode_large *)scan->ptr)) in ext2fs_get_next_inode_full()
695 ext2fs_swap_inode_full(scan->fs, in ext2fs_get_next_inode_full()
697 (struct ext2_inode_large *) scan->ptr, in ext2fs_get_next_inode_full()
700 memcpy(iptr, scan->ptr, length); in ext2fs_get_next_inode_full()
702 scan->ptr += scan->inode_size; in ext2fs_get_next_inode_full()
703 scan->bytes_left -= scan->inode_size; in ext2fs_get_next_inode_full()
704 if (scan->scan_flags & EXT2_SF_BAD_INODE_BLK) in ext2fs_get_next_inode_full()
711 scan->inodes_left--; in ext2fs_get_next_inode_full()
712 scan->current_inode++; in ext2fs_get_next_inode_full()
713 *ino = scan->current_inode; 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()
774 block_nr += (ino - 1) / inodes_per_block; in ext2fs_read_inode_full()
775 offset = ((ino - 1) % inodes_per_block) * 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()
814 length -= clen; 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()
957 length -= clen; 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()
987 if (!inode->i_ctime) in ext2fs_write_new_inode()
988 inode->i_ctime = t; in ext2fs_write_new_inode()
989 if (!inode->i_mtime) in ext2fs_write_new_inode()
990 inode->i_mtime = t; in ext2fs_write_new_inode()
991 if (!inode->i_atime) in ext2fs_write_new_inode()
992 inode->i_atime = t; in ext2fs_write_new_inode()
995 return ext2fs_write_inode_full(fs, ino, inode, in ext2fs_write_new_inode()
1006 large_inode->i_extra_isize = sizeof(struct ext2_inode_large) - in ext2fs_write_new_inode()
1008 if (!large_inode->i_crtime) in ext2fs_write_new_inode()
1009 large_inode->i_crtime = t; 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()