Lines Matching refs:scan
48 ext2_inode_scan scan,
109 ext2_inode_scan scan; in ext2fs_open_inode_scan() local
134 retval = ext2fs_get_mem(sizeof(struct ext2_struct_inode_scan), &scan); in ext2fs_open_inode_scan()
137 memset(scan, 0, sizeof(struct ext2_struct_inode_scan)); in ext2fs_open_inode_scan()
139 scan->magic = EXT2_ET_MAGIC_INODE_SCAN; 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()
142 scan->bytes_left = 0; in ext2fs_open_inode_scan()
143 scan->current_group = 0; in ext2fs_open_inode_scan()
144 scan->groups_left = fs->group_desc_count - 1; in ext2fs_open_inode_scan()
145 scan->inode_buffer_blocks = buffer_blocks ? buffer_blocks : 8; in ext2fs_open_inode_scan()
146 scan->current_block = ext2fs_inode_table_loc(scan->fs, in ext2fs_open_inode_scan()
147 scan->current_group); 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()
152 scan->inodes_left -= in ext2fs_open_inode_scan()
153 ext2fs_bg_itable_unused(fs, scan->current_group); in ext2fs_open_inode_scan()
154 scan->blocks_left = in ext2fs_open_inode_scan()
155 (scan->inodes_left + 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()
160 &scan->inode_buffer); in ext2fs_open_inode_scan()
161 scan->done_group = 0; in ext2fs_open_inode_scan()
162 scan->done_group_data = 0; in ext2fs_open_inode_scan()
163 scan->bad_block_ptr = 0; in ext2fs_open_inode_scan()
165 ext2fs_free_mem(&scan); in ext2fs_open_inode_scan()
168 retval = ext2fs_get_mem(scan->inode_size, &scan->temp_buffer); in ext2fs_open_inode_scan()
170 ext2fs_free_mem(&scan->inode_buffer); in ext2fs_open_inode_scan()
171 ext2fs_free_mem(&scan); in ext2fs_open_inode_scan()
174 if (scan->fs->badblocks && scan->fs->badblocks->num) in ext2fs_open_inode_scan()
175 scan->scan_flags |= EXT2_SF_CHK_BADBLOCKS; in ext2fs_open_inode_scan()
178 scan->scan_flags |= EXT2_SF_DO_LAZY; in ext2fs_open_inode_scan()
179 *ret_scan = scan; in ext2fs_open_inode_scan()
183 void ext2fs_close_inode_scan(ext2_inode_scan scan) in ext2fs_close_inode_scan() argument
185 if (!scan || (scan->magic != EXT2_ET_MAGIC_INODE_SCAN)) in ext2fs_close_inode_scan()
188 ext2fs_free_mem(&scan->inode_buffer); in ext2fs_close_inode_scan()
189 scan->inode_buffer = NULL; in ext2fs_close_inode_scan()
190 ext2fs_free_mem(&scan->temp_buffer); in ext2fs_close_inode_scan()
191 scan->temp_buffer = NULL; in ext2fs_close_inode_scan()
192 ext2fs_free_mem(&scan); in ext2fs_close_inode_scan()
196 void ext2fs_set_inode_callback(ext2_inode_scan scan, in ext2fs_set_inode_callback() argument
198 ext2_inode_scan scan, in ext2fs_set_inode_callback()
203 if (!scan || (scan->magic != EXT2_ET_MAGIC_INODE_SCAN)) in ext2fs_set_inode_callback()
206 scan->done_group = done_group; in ext2fs_set_inode_callback()
207 scan->done_group_data = done_group_data; in ext2fs_set_inode_callback()
210 int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags, in ext2fs_inode_scan_flags() argument
215 if (!scan || (scan->magic != EXT2_ET_MAGIC_INODE_SCAN)) in ext2fs_inode_scan_flags()
218 old_flags = scan->scan_flags; in ext2fs_inode_scan_flags()
219 scan->scan_flags &= ~clear_flags; in ext2fs_inode_scan_flags()
220 scan->scan_flags |= set_flags; in ext2fs_inode_scan_flags()
228 static errcode_t get_next_blockgroup(ext2_inode_scan scan) in get_next_blockgroup() argument
230 ext2_filsys fs = scan->fs; in get_next_blockgroup()
232 scan->current_group++; in get_next_blockgroup()
233 scan->groups_left--; in get_next_blockgroup()
235 scan->current_block = ext2fs_inode_table_loc(scan->fs, in get_next_blockgroup()
236 scan->current_group); in get_next_blockgroup()
237 scan->current_inode = scan->current_group * in get_next_blockgroup()
240 scan->bytes_left = 0; 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()
245 scan->inodes_left -= in get_next_blockgroup()
246 ext2fs_bg_itable_unused(fs, scan->current_group); in get_next_blockgroup()
247 scan->blocks_left = in get_next_blockgroup()
248 (scan->inodes_left + 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()
256 errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan, in ext2fs_inode_scan_goto_blockgroup() argument
259 scan->current_group = group - 1; in ext2fs_inode_scan_goto_blockgroup()
260 scan->groups_left = scan->fs->group_desc_count - group; in ext2fs_inode_scan_goto_blockgroup()
261 return get_next_blockgroup(scan); in ext2fs_inode_scan_goto_blockgroup()
271 static errcode_t check_for_inode_bad_blocks(ext2_inode_scan scan, in check_for_inode_bad_blocks() argument
274 blk64_t blk = scan->current_block; in check_for_inode_bad_blocks()
275 badblocks_list bb = scan->fs->badblocks; in check_for_inode_bad_blocks()
290 while (blk > bb->list[scan->bad_block_ptr]) { in check_for_inode_bad_blocks()
291 if (++scan->bad_block_ptr >= bb->num) { in check_for_inode_bad_blocks()
292 scan->scan_flags &= ~EXT2_SF_CHK_BADBLOCKS; in check_for_inode_bad_blocks()
305 if (blk == bb->list[scan->bad_block_ptr]) { in check_for_inode_bad_blocks()
306 scan->scan_flags |= EXT2_SF_BAD_INODE_BLK; in check_for_inode_bad_blocks()
308 if (++scan->bad_block_ptr >= bb->num) in check_for_inode_bad_blocks()
309 scan->scan_flags &= ~EXT2_SF_CHK_BADBLOCKS; in check_for_inode_bad_blocks()
319 if ((blk + *num_blocks) > bb->list[scan->bad_block_ptr]) in check_for_inode_bad_blocks()
320 *num_blocks = (int) (bb->list[scan->bad_block_ptr] - blk); in check_for_inode_bad_blocks()
329 static errcode_t get_next_blocks(ext2_inode_scan scan) in get_next_blocks() argument
339 num_blocks = scan->inode_buffer_blocks; in get_next_blocks()
340 if (num_blocks > scan->blocks_left) in get_next_blocks()
341 num_blocks = scan->blocks_left; in get_next_blocks()
347 if (scan->scan_flags & EXT2_SF_BAD_INODE_BLK) { in get_next_blocks()
348 if (scan->bytes_left) in get_next_blocks()
349 scan->scan_flags |= EXT2_SF_BAD_EXTRA_BYTES; in get_next_blocks()
350 scan->scan_flags &= ~EXT2_SF_BAD_INODE_BLK; in get_next_blocks()
356 if (scan->scan_flags & EXT2_SF_CHK_BADBLOCKS) { in get_next_blocks()
357 retval = check_for_inode_bad_blocks(scan, &num_blocks); in get_next_blocks()
362 if ((scan->scan_flags & EXT2_SF_BAD_INODE_BLK) || in get_next_blocks()
363 (scan->current_block == 0)) { in get_next_blocks()
364 memset(scan->inode_buffer, 0, in get_next_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()
368 scan->current_block, in get_next_blocks()
370 scan->inode_buffer); in get_next_blocks()
374 scan->ptr = scan->inode_buffer; in get_next_blocks()
375 scan->bytes_left = num_blocks * scan->fs->blocksize; in get_next_blocks()
377 scan->blocks_left -= num_blocks; in get_next_blocks()
378 if (scan->current_block) in get_next_blocks()
379 scan->current_block += num_blocks; in get_next_blocks()
390 static inline int is_empty_scan(ext2_inode_scan scan)
394 if (scan->bytes_left == 0)
397 for (i=0; i < scan->bytes_left; i++)
398 if (scan->ptr[i])
404 errcode_t ext2fs_get_next_inode_full(ext2_inode_scan scan, ext2_ino_t *ino, in ext2fs_get_next_inode_full() argument
410 EXT2_CHECK_MAGIC(scan, EXT2_ET_MAGIC_INODE_SCAN); in ext2fs_get_next_inode_full()
415 if (scan->inodes_left <= 0) { in ext2fs_get_next_inode_full()
417 if (scan->done_group) { in ext2fs_get_next_inode_full()
418 retval = (scan->done_group) in ext2fs_get_next_inode_full()
419 (scan->fs, scan, scan->current_group, in ext2fs_get_next_inode_full()
420 scan->done_group_data); in ext2fs_get_next_inode_full()
424 if (scan->groups_left <= 0) { in ext2fs_get_next_inode_full()
428 retval = get_next_blockgroup(scan); in ext2fs_get_next_inode_full()
436 if ((scan->scan_flags & EXT2_SF_DO_LAZY) && 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()
440 if (scan->inodes_left == 0) in ext2fs_get_next_inode_full()
442 if (scan->current_block == 0) { in ext2fs_get_next_inode_full()
443 if (scan->scan_flags & EXT2_SF_SKIP_MISSING_ITABLE) { in ext2fs_get_next_inode_full()
454 if (scan->bytes_left < scan->inode_size) { in ext2fs_get_next_inode_full()
455 memcpy(scan->temp_buffer, scan->ptr, scan->bytes_left); in ext2fs_get_next_inode_full()
456 extra_bytes = scan->bytes_left; in ext2fs_get_next_inode_full()
458 retval = get_next_blocks(scan); in ext2fs_get_next_inode_full()
466 if (is_empty_scan(scan)) in ext2fs_get_next_inode_full()
473 memcpy(scan->temp_buffer+extra_bytes, scan->ptr, in ext2fs_get_next_inode_full()
474 scan->inode_size - extra_bytes); in ext2fs_get_next_inode_full()
475 scan->ptr += scan->inode_size - extra_bytes; in ext2fs_get_next_inode_full()
476 scan->bytes_left -= scan->inode_size - extra_bytes; in ext2fs_get_next_inode_full()
480 ext2fs_swap_inode_full(scan->fs, in ext2fs_get_next_inode_full()
482 (struct ext2_inode_large *) scan->temp_buffer, in ext2fs_get_next_inode_full()
485 *inode = *((struct ext2_inode *) scan->temp_buffer); in ext2fs_get_next_inode_full()
487 if (scan->scan_flags & EXT2_SF_BAD_EXTRA_BYTES) in ext2fs_get_next_inode_full()
489 scan->scan_flags &= ~EXT2_SF_BAD_EXTRA_BYTES; in ext2fs_get_next_inode_full()
493 ext2fs_swap_inode_full(scan->fs, in ext2fs_get_next_inode_full()
495 (struct ext2_inode_large *) scan->ptr, in ext2fs_get_next_inode_full()
498 memcpy(inode, scan->ptr, bufsize); in ext2fs_get_next_inode_full()
500 scan->ptr += scan->inode_size; in ext2fs_get_next_inode_full()
501 scan->bytes_left -= scan->inode_size; in ext2fs_get_next_inode_full()
502 if (scan->scan_flags & EXT2_SF_BAD_INODE_BLK) in ext2fs_get_next_inode_full()
506 scan->inodes_left--; in ext2fs_get_next_inode_full()
507 scan->current_inode++; in ext2fs_get_next_inode_full()
508 *ino = scan->current_inode; in ext2fs_get_next_inode_full()
512 errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino, in ext2fs_get_next_inode() argument
515 return ext2fs_get_next_inode_full(scan, ino, inode, in ext2fs_get_next_inode()