2 * pass1b.c --- Pass #1b of e2fsck
4 * This file contains pass1B, pass1C, and pass1D of e2fsck. They are
5 * only invoked if pass 1 discovered blocks which are in use by more
8 * Pass1B scans the data blocks of all the inodes again, generating a
9 * complete list of duplicate blocks and which inodes have claimed
12 * Pass1C does a tree-traversal of the filesystem, to determine the
13 * parent directories of these inodes. This step is necessary so that
14 * e2fsck can print out the pathnames of affected inodes.
16 * Pass1D is a reconciliation pass. For each inode with duplicate
17 * blocks, the user is prompted if s/he would like to clone the file
18 * (so that the file gets a fresh copy of the duplicated blocks) or
19 * simply to delete the file.
21 * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
24 * This file may be redistributed under the terms of the GNU Public
35 #ifdef HAVE_INTTYPES_H
40 typedef long intptr_t;
43 /* Needed for architectures where sizeof(int) != sizeof(void *) */
44 #define INT_TO_VOIDPTR(val) ((void *)(intptr_t)(val))
45 #define VOIDPTR_TO_INT(ptr) ((int)(intptr_t)(ptr))
47 #include <et/com_err.h>
53 /* Define an extension to the ext2 library's block count information */
54 #define BLOCK_COUNT_EXTATTR (-5)
58 struct cluster_el *next;
63 struct inode_el *next;
68 struct inode_el *inode_list;
72 * This structure stores information about a particular inode which
73 * is sharing blocks with other inodes. This information is collected
74 * to display to the user, so that the user knows what files he or she
75 * is dealing with, when trying to decide how to resolve the conflict
76 * of multiply-claimed blocks.
81 struct ext2_inode inode;
82 struct cluster_el *cluster_list;
85 static int process_pass1b_block(ext2_filsys fs, blk64_t *blocknr,
86 e2_blkcnt_t blockcnt, blk64_t ref_blk,
87 int ref_offset, void *priv_data);
88 static void delete_file(e2fsck_t ctx, ext2_ino_t ino,
89 struct dup_inode *dp, char *block_buf);
90 static errcode_t clone_file(e2fsck_t ctx, ext2_ino_t ino,
91 struct dup_inode *dp, char* block_buf);
92 static int check_if_fs_block(e2fsck_t ctx, blk64_t test_block);
93 static int check_if_fs_cluster(e2fsck_t ctx, blk64_t cluster);
95 static void pass1b(e2fsck_t ctx, char *block_buf);
96 static void pass1c(e2fsck_t ctx, char *block_buf);
97 static void pass1d(e2fsck_t ctx, char *block_buf);
99 static int dup_inode_count = 0;
100 static int dup_inode_founddir = 0;
102 static dict_t clstr_dict, ino_dict;
104 static ext2fs_inode_bitmap inode_dup_map;
106 static int dict_int_cmp(const void *a, const void *b)
117 * Add a duplicate block record
119 static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk64_t cluster,
120 struct ext2_inode *inode)
123 struct dup_cluster *db;
124 struct dup_inode *di;
125 struct cluster_el *cluster_el;
126 struct inode_el *ino_el;
128 n = dict_lookup(&clstr_dict, INT_TO_VOIDPTR(cluster));
130 db = (struct dup_cluster *) dnode_get(n);
132 db = (struct dup_cluster *) e2fsck_allocate_memory(ctx,
133 sizeof(struct dup_cluster), "duplicate cluster header");
136 dict_alloc_insert(&clstr_dict, INT_TO_VOIDPTR(cluster), db);
138 ino_el = (struct inode_el *) e2fsck_allocate_memory(ctx,
139 sizeof(struct inode_el), "inode element");
141 ino_el->next = db->inode_list;
142 db->inode_list = ino_el;
145 n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(ino));
147 di = (struct dup_inode *) dnode_get(n);
149 di = (struct dup_inode *) e2fsck_allocate_memory(ctx,
150 sizeof(struct dup_inode), "duplicate inode header");
151 if (ino == EXT2_ROOT_INO) {
152 di->dir = EXT2_ROOT_INO;
153 dup_inode_founddir++;
157 di->num_dupblocks = 0;
158 di->cluster_list = 0;
160 dict_alloc_insert(&ino_dict, INT_TO_VOIDPTR(ino), di);
162 cluster_el = (struct cluster_el *) e2fsck_allocate_memory(ctx,
163 sizeof(struct cluster_el), "cluster element");
164 cluster_el->cluster = cluster;
165 cluster_el->next = di->cluster_list;
166 di->cluster_list = cluster_el;
171 * Free a duplicate inode record
173 static void inode_dnode_free(dnode_t *node,
174 void *context EXT2FS_ATTR((unused)))
176 struct dup_inode *di;
177 struct cluster_el *p, *next;
179 di = (struct dup_inode *) dnode_get(node);
180 for (p = di->cluster_list; p; p = next) {
189 * Free a duplicate cluster record
191 static void cluster_dnode_free(dnode_t *node,
192 void *context EXT2FS_ATTR((unused)))
194 struct dup_cluster *dc;
195 struct inode_el *p, *next;
197 dc = (struct dup_cluster *) dnode_get(node);
198 for (p = dc->inode_list; p; p = next) {
208 * Main procedure for handling duplicate blocks
210 void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf)
212 ext2_filsys fs = ctx->fs;
213 struct problem_context pctx;
214 #ifdef RESOURCE_TRACK
215 struct resource_track rtrack;
218 clear_problem_context(&pctx);
220 pctx.errcode = e2fsck_allocate_inode_bitmap(fs,
221 _("multiply claimed inode map"),
222 EXT2FS_BMAP64_RBTREE, "inode_dup_map",
225 fix_problem(ctx, PR_1B_ALLOCATE_IBITMAP_ERROR, &pctx);
226 ctx->flags |= E2F_FLAG_ABORT;
230 dict_init(&ino_dict, DICTCOUNT_T_MAX, dict_int_cmp);
231 dict_init(&clstr_dict, DICTCOUNT_T_MAX, dict_int_cmp);
232 dict_set_allocator(&ino_dict, NULL, inode_dnode_free, NULL);
233 dict_set_allocator(&clstr_dict, NULL, cluster_dnode_free, NULL);
235 init_resource_track(&rtrack, ctx->fs->io);
236 pass1b(ctx, block_buf);
237 print_resource_track(ctx, "Pass 1b", &rtrack, ctx->fs->io);
239 init_resource_track(&rtrack, ctx->fs->io);
240 pass1c(ctx, block_buf);
241 print_resource_track(ctx, "Pass 1c", &rtrack, ctx->fs->io);
243 init_resource_track(&rtrack, ctx->fs->io);
244 pass1d(ctx, block_buf);
245 print_resource_track(ctx, "Pass 1d", &rtrack, ctx->fs->io);
248 * Time to free all of the accumulated data structures that we
249 * don't need anymore.
251 dict_free_nodes(&ino_dict);
252 dict_free_nodes(&clstr_dict);
253 ext2fs_free_inode_bitmap(inode_dup_map);
257 * Scan the inodes looking for inodes that contain duplicate blocks.
259 struct process_block_struct {
264 struct ext2_inode *inode;
265 struct problem_context *pctx;
268 static void pass1b(e2fsck_t ctx, char *block_buf)
270 ext2_filsys fs = ctx->fs;
272 struct ext2_inode inode;
273 ext2_inode_scan scan;
274 struct process_block_struct pb;
275 struct problem_context pctx;
277 clear_problem_context(&pctx);
279 if (!(ctx->options & E2F_OPT_PREEN))
280 fix_problem(ctx, PR_1B_PASS_HEADER, &pctx);
281 pctx.errcode = ext2fs_open_inode_scan(fs, ctx->inode_buffer_blocks,
284 fix_problem(ctx, PR_1B_ISCAN_ERROR, &pctx);
285 ctx->flags |= E2F_FLAG_ABORT;
288 ctx->stashed_inode = &inode;
293 if (ino % (fs->super->s_inodes_per_group * 4) == 1) {
294 if (e2fsck_mmp_update(fs))
297 pctx.errcode = ext2fs_get_next_inode(scan, &ino, &inode);
298 if (pctx.errcode == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE)
301 fix_problem(ctx, PR_1B_ISCAN_ERROR, &pctx);
302 ctx->flags |= E2F_FLAG_ABORT;
307 pctx.ino = ctx->stashed_ino = ino;
308 if ((ino != EXT2_BAD_INO) &&
309 !ext2fs_test_inode_bitmap2(ctx->inode_used_map, ino))
317 if (ext2fs_inode_has_valid_blocks2(fs, &inode) ||
318 (ino == EXT2_BAD_INO))
319 pctx.errcode = ext2fs_block_iterate3(fs, ino,
320 BLOCK_FLAG_READ_ONLY, block_buf,
321 process_pass1b_block, &pb);
322 /* If the feature is not set, attrs will be cleared later anyway */
323 if ((fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR) &&
324 ext2fs_file_acl_block(fs, &inode)) {
325 blk64_t blk = ext2fs_file_acl_block(fs, &inode);
326 process_pass1b_block(fs, &blk,
327 BLOCK_COUNT_EXTATTR, 0, 0, &pb);
328 ext2fs_file_acl_block_set(fs, &inode, blk);
331 end_problem_latch(ctx, PR_LATCH_DBLOCK);
332 if (ino >= EXT2_FIRST_INODE(fs->super) ||
333 ino == EXT2_ROOT_INO)
337 fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
339 ext2fs_close_inode_scan(scan);
340 e2fsck_use_inode_shortcuts(ctx, 0);
343 static int process_pass1b_block(ext2_filsys fs EXT2FS_ATTR((unused)),
345 e2_blkcnt_t blockcnt,
346 blk64_t ref_blk EXT2FS_ATTR((unused)),
347 int ref_offset EXT2FS_ATTR((unused)),
350 struct process_block_struct *p;
354 if (HOLE_BLKADDR(*block_nr))
356 p = (struct process_block_struct *) priv_data;
358 lc = EXT2FS_B2C(fs, blockcnt);
360 if (!ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr))
363 /* OK, this is a duplicate block */
364 if (p->ino != EXT2_BAD_INO) {
365 p->pctx->blk = *block_nr;
366 fix_problem(ctx, PR_1B_DUP_BLOCK, p->pctx);
369 ext2fs_mark_inode_bitmap2(inode_dup_map, p->ino);
371 if (lc != p->cur_cluster)
372 add_dupe(ctx, p->ino, EXT2FS_B2C(fs, *block_nr), p->inode);
380 * Pass 1c: Scan directories for inodes with duplicate blocks. This
381 * is used so that we can print pathnames when prompting the user for
384 struct search_dir_struct {
386 ext2_ino_t first_inode;
387 ext2_ino_t max_inode;
390 static int search_dirent_proc(ext2_ino_t dir, int entry,
391 struct ext2_dir_entry *dirent,
392 int offset EXT2FS_ATTR((unused)),
393 int blocksize EXT2FS_ATTR((unused)),
394 char *buf EXT2FS_ATTR((unused)),
397 struct search_dir_struct *sd;
401 sd = (struct search_dir_struct *) priv_data;
403 if (dirent->inode > sd->max_inode)
404 /* Should abort this inode, but not everything */
407 if ((dirent->inode < sd->first_inode) || (entry < DIRENT_OTHER_FILE) ||
408 !ext2fs_test_inode_bitmap2(inode_dup_map, dirent->inode))
411 n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(dirent->inode));
414 p = (struct dup_inode *) dnode_get(n);
420 return(sd->count ? 0 : DIRENT_ABORT);
424 static void pass1c(e2fsck_t ctx, char *block_buf)
426 ext2_filsys fs = ctx->fs;
427 struct search_dir_struct sd;
428 struct problem_context pctx;
430 clear_problem_context(&pctx);
432 if (!(ctx->options & E2F_OPT_PREEN))
433 fix_problem(ctx, PR_1C_PASS_HEADER, &pctx);
436 * Search through all directories to translate inodes to names
437 * (by searching for the containing directory for that inode.)
439 sd.count = dup_inode_count - dup_inode_founddir;
440 sd.first_inode = EXT2_FIRST_INODE(fs->super);
441 sd.max_inode = fs->super->s_inodes_count;
442 ext2fs_dblist_dir_iterate(fs->dblist, 0, block_buf,
443 search_dirent_proc, &sd);
446 static void pass1d(e2fsck_t ctx, char *block_buf)
448 ext2_filsys fs = ctx->fs;
449 struct dup_inode *p, *t;
450 struct dup_cluster *q;
451 ext2_ino_t *shared, ino;
456 struct problem_context pctx;
458 struct cluster_el *s;
461 clear_problem_context(&pctx);
463 if (!(ctx->options & E2F_OPT_PREEN))
464 fix_problem(ctx, PR_1D_PASS_HEADER, &pctx);
465 e2fsck_read_bitmaps(ctx);
467 pctx.num = dup_inode_count; /* dict_count(&ino_dict); */
468 fix_problem(ctx, PR_1D_NUM_DUP_INODES, &pctx);
469 shared = (ext2_ino_t *) e2fsck_allocate_memory(ctx,
470 sizeof(ext2_ino_t) * dict_count(&ino_dict),
471 "Shared inode list");
472 for (n = dict_first(&ino_dict); n; n = dict_next(&ino_dict, n)) {
473 p = (struct dup_inode *) dnode_get(n);
476 ino = (ext2_ino_t)VOIDPTR_TO_INT(dnode_getkey(n));
477 if (ino == EXT2_BAD_INO || ino == EXT2_RESIZE_INO)
481 * Find all of the inodes which share blocks with this
482 * one. First we find all of the duplicate blocks
483 * belonging to this inode, and then search each block
484 * get the list of inodes, and merge them together.
486 for (s = p->cluster_list; s; s = s->next) {
487 m = dict_lookup(&clstr_dict,
488 INT_TO_VOIDPTR(s->cluster));
490 continue; /* Should never happen... */
491 q = (struct dup_cluster *) dnode_get(m);
494 if (check_if_fs_cluster(ctx, s->cluster)) {
500 * Add all inodes used by this block to the
501 * shared[] --- which is a unique list, so
502 * if an inode is already in shared[], don't
505 for (r = q->inode_list; r; r = r->next) {
508 for (i = 0; i < shared_len; i++)
509 if (shared[i] == r->inode)
511 if (i == shared_len) {
512 shared[shared_len++] = r->inode;
518 * Report the inode that we are working on
520 pctx.inode = &p->inode;
523 pctx.blkcount = p->num_dupblocks;
524 pctx.num = meta_data ? shared_len+1 : shared_len;
525 fix_problem(ctx, PR_1D_DUP_FILE, &pctx);
530 fix_problem(ctx, PR_1D_SHARE_METADATA, &pctx);
532 for (i = 0; i < shared_len; i++) {
533 m = dict_lookup(&ino_dict, INT_TO_VOIDPTR(shared[i]));
535 continue; /* should never happen */
536 t = (struct dup_inode *) dnode_get(m);
538 * Report the inode that we are sharing with
540 pctx.inode = &t->inode;
541 pctx.ino = shared[i];
543 fix_problem(ctx, PR_1D_DUP_FILE_LIST, &pctx);
546 fix_problem(ctx, PR_1D_DUP_BLOCKS_DEALT, &pctx);
549 if (fix_problem(ctx, PR_1D_CLONE_QUESTION, &pctx)) {
550 pctx.errcode = clone_file(ctx, ino, p, block_buf);
552 fix_problem(ctx, PR_1D_CLONE_ERROR, &pctx);
556 if (fix_problem(ctx, PR_1D_DELETE_QUESTION, &pctx))
557 delete_file(ctx, ino, p, block_buf);
559 ext2fs_unmark_valid(fs);
561 ext2fs_free_mem(&shared);
565 * Drop the refcount on the dup_block structure, and clear the entry
566 * in the block_dup_map if appropriate.
568 static void decrement_badcount(e2fsck_t ctx, blk64_t block,
569 struct dup_cluster *p)
572 if (p->num_bad <= 0 ||
573 (p->num_bad == 1 && !check_if_fs_block(ctx, block))) {
574 if (check_if_fs_cluster(ctx, EXT2FS_B2C(ctx->fs, block)))
576 ext2fs_unmark_block_bitmap2(ctx->block_dup_map, block);
580 static int delete_file_block(ext2_filsys fs,
582 e2_blkcnt_t blockcnt,
583 blk64_t ref_block EXT2FS_ATTR((unused)),
584 int ref_offset EXT2FS_ATTR((unused)),
587 struct process_block_struct *pb;
588 struct dup_cluster *p;
593 pb = (struct process_block_struct *) priv_data;
596 if (HOLE_BLKADDR(*block_nr))
599 c = EXT2FS_B2C(fs, *block_nr);
600 lc = EXT2FS_B2C(fs, blockcnt);
601 if (ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr)) {
602 n = dict_lookup(&clstr_dict, INT_TO_VOIDPTR(c));
604 p = (struct dup_cluster *) dnode_get(n);
605 if (lc != pb->cur_cluster)
606 decrement_badcount(ctx, *block_nr, p);
608 com_err("delete_file_block", 0,
609 _("internal error: can't find dup_blk for %llu\n"),
612 ext2fs_unmark_block_bitmap2(ctx->block_found_map, *block_nr);
613 ext2fs_block_alloc_stats2(fs, *block_nr, -1);
616 pb->cur_cluster = lc;
621 static void delete_file(e2fsck_t ctx, ext2_ino_t ino,
622 struct dup_inode *dp, char* block_buf)
624 ext2_filsys fs = ctx->fs;
625 struct process_block_struct pb;
626 struct problem_context pctx;
629 clear_problem_context(&pctx);
630 pctx.ino = pb.ino = ino;
633 pctx.str = "delete_file";
636 if (ext2fs_inode_has_valid_blocks2(fs, &dp->inode))
637 pctx.errcode = ext2fs_block_iterate3(fs, ino,
638 BLOCK_FLAG_READ_ONLY,
640 delete_file_block, &pb);
642 fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
643 if (ctx->inode_bad_map)
644 ext2fs_unmark_inode_bitmap2(ctx->inode_bad_map, ino);
645 ext2fs_inode_alloc_stats2(fs, ino, -1, LINUX_S_ISDIR(dp->inode.i_mode));
646 quota_data_sub(ctx->qctx, &dp->inode, ino,
647 pb.dup_blocks * fs->blocksize);
648 quota_data_inodes(ctx->qctx, &dp->inode, ino, -1);
650 /* Inode may have changed by block_iterate, so reread it */
651 e2fsck_read_inode(ctx, ino, &dp->inode, "delete_file");
652 e2fsck_clear_inode(ctx, ino, &dp->inode, 0, "delete_file");
653 if (ext2fs_file_acl_block(fs, &dp->inode) &&
654 (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) {
656 pctx.errcode = ext2fs_adjust_ea_refcount2(fs,
657 ext2fs_file_acl_block(fs, &dp->inode),
658 block_buf, -1, &count);
659 if (pctx.errcode == EXT2_ET_BAD_EA_BLOCK_NUM) {
664 pctx.blk = ext2fs_file_acl_block(fs, &dp->inode);
665 fix_problem(ctx, PR_1B_ADJ_EA_REFCOUNT, &pctx);
668 * If the count is zero, then arrange to have the
669 * block deleted. If the block is in the block_dup_map,
670 * also call delete_file_block since it will take care
671 * of keeping the accounting straight.
674 ext2fs_test_block_bitmap2(ctx->block_dup_map,
675 ext2fs_file_acl_block(fs, &dp->inode))) {
676 blk64_t blk = ext2fs_file_acl_block(fs, &dp->inode);
677 delete_file_block(fs, &blk,
678 BLOCK_COUNT_EXTATTR, 0, 0, &pb);
679 ext2fs_file_acl_block_set(fs, &dp->inode, blk);
680 quota_data_sub(ctx->qctx, &dp->inode, ino, fs->blocksize);
685 struct clone_struct {
694 static int clone_file_block(ext2_filsys fs,
696 e2_blkcnt_t blockcnt,
697 blk64_t ref_block EXT2FS_ATTR((unused)),
698 int ref_offset EXT2FS_ATTR((unused)),
701 struct dup_cluster *p;
704 struct clone_struct *cs = (struct clone_struct *) priv_data;
712 if (HOLE_BLKADDR(*block_nr))
715 c = EXT2FS_B2C(fs, blockcnt);
716 if (check_if_fs_cluster(ctx, EXT2FS_B2C(fs, *block_nr)))
719 if (c == cs->dup_cluster && cs->alloc_block) {
720 new_block = cs->alloc_block;
724 if (ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr)) {
725 n = dict_lookup(&clstr_dict,
726 INT_TO_VOIDPTR(EXT2FS_B2C(fs, *block_nr)));
728 com_err("clone_file_block", 0,
729 _("internal error: can't find dup_blk for %llu\n"),
734 p = (struct dup_cluster *) dnode_get(n);
736 decrement_badcount(ctx, *block_nr, p);
740 retval = ext2fs_new_block2(fs, 0, ctx->block_found_map,
743 cs->errcode = retval;
746 cs->alloc_block = new_block;
749 new_block &= ~EXT2FS_CLUSTER_MASK(fs);
750 new_block += EXT2FS_CLUSTER_MASK(fs) & blockcnt;
751 if (cs->dir && (blockcnt >= 0)) {
752 retval = ext2fs_set_dir_block2(fs->dblist,
753 cs->dir, new_block, blockcnt);
755 cs->errcode = retval;
760 printf("Cloning block #%lld from %llu to %llu\n",
761 blockcnt, *block_nr, new_block);
763 retval = io_channel_read_blk64(fs->io, *block_nr, 1, cs->buf);
765 cs->errcode = retval;
768 retval = io_channel_write_blk64(fs->io, new_block, 1, cs->buf);
770 cs->errcode = retval;
773 *block_nr = new_block;
774 ext2fs_mark_block_bitmap2(ctx->block_found_map, new_block);
775 ext2fs_mark_block_bitmap2(fs->block_map, new_block);
776 return BLOCK_CHANGED;
781 static errcode_t clone_file(e2fsck_t ctx, ext2_ino_t ino,
782 struct dup_inode *dp, char* block_buf)
784 ext2_filsys fs = ctx->fs;
786 struct clone_struct cs;
787 struct problem_context pctx;
788 blk64_t blk, new_blk;
790 struct inode_el *ino_el;
791 struct dup_cluster *dc;
792 struct dup_inode *di;
794 clear_problem_context(&pctx);
800 retval = ext2fs_get_mem(fs->blocksize, &cs.buf);
804 if (ext2fs_test_inode_bitmap2(ctx->inode_dir_map, ino))
808 pctx.str = "clone_file";
809 if (ext2fs_inode_has_valid_blocks2(fs, &dp->inode))
810 pctx.errcode = ext2fs_block_iterate3(fs, ino, 0, block_buf,
811 clone_file_block, &cs);
812 ext2fs_mark_bb_dirty(fs);
814 fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
815 retval = pctx.errcode;
819 com_err("clone_file", cs.errcode, "%s",
820 _("returned from clone_file_block"));
824 /* The inode may have changed on disk, so we have to re-read it */
825 e2fsck_read_inode(ctx, ino, &dp->inode, "clone file EA");
826 blk = ext2fs_file_acl_block(fs, &dp->inode);
828 if (blk && (clone_file_block(fs, &new_blk,
829 BLOCK_COUNT_EXTATTR, 0, 0, &cs) ==
831 ext2fs_file_acl_block_set(fs, &dp->inode, new_blk);
832 e2fsck_write_inode(ctx, ino, &dp->inode, "clone file EA");
834 * If we cloned the EA block, find all other inodes
835 * which refered to that EA block, and modify
836 * them to point to the new EA block.
838 n = dict_lookup(&clstr_dict,
839 INT_TO_VOIDPTR(EXT2FS_B2C(fs, blk)));
841 com_err("clone_file", 0,
842 _("internal error: couldn't lookup EA "
843 "block record for %llu"), blk);
844 retval = 0; /* OK to stumble on... */
847 dc = (struct dup_cluster *) dnode_get(n);
848 for (ino_el = dc->inode_list; ino_el; ino_el = ino_el->next) {
849 if (ino_el->inode == ino)
851 n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(ino_el->inode));
853 com_err("clone_file", 0,
854 _("internal error: couldn't lookup EA "
855 "inode record for %u"),
857 retval = 0; /* OK to stumble on... */
860 di = (struct dup_inode *) dnode_get(n);
861 if (ext2fs_file_acl_block(fs, &di->inode) == blk) {
862 ext2fs_file_acl_block_set(fs, &di->inode,
863 ext2fs_file_acl_block(fs, &dp->inode));
864 e2fsck_write_inode(ctx, ino_el->inode,
865 &di->inode, "clone file EA");
866 decrement_badcount(ctx, blk, dc);
872 ext2fs_free_mem(&cs.buf);
877 * This routine returns 1 if a block overlaps with one of the superblocks,
878 * group descriptors, inode bitmaps, or block bitmaps.
880 static int check_if_fs_block(e2fsck_t ctx, blk64_t test_block)
882 ext2_filsys fs = ctx->fs;
886 first_block = fs->super->s_first_data_block;
887 for (i = 0; i < fs->group_desc_count; i++) {
889 /* Check superblocks/block group descriptors */
890 if (ext2fs_bg_has_super(fs, i)) {
891 if (test_block >= first_block &&
892 (test_block <= first_block + fs->desc_blocks))
896 /* Check the inode table */
897 if ((ext2fs_inode_table_loc(fs, i)) &&
898 (test_block >= ext2fs_inode_table_loc(fs, i)) &&
899 (test_block < (ext2fs_inode_table_loc(fs, i) +
900 fs->inode_blocks_per_group)))
903 /* Check the bitmap blocks */
904 if ((test_block == ext2fs_block_bitmap_loc(fs, i)) ||
905 (test_block == ext2fs_inode_bitmap_loc(fs, i)))
908 first_block += fs->super->s_blocks_per_group;
914 * This routine returns 1 if a cluster overlaps with one of the superblocks,
915 * group descriptors, inode bitmaps, or block bitmaps.
917 static int check_if_fs_cluster(e2fsck_t ctx, blk64_t cluster)
919 ext2_filsys fs = ctx->fs;
923 first_block = fs->super->s_first_data_block;
924 for (i = 0; i < fs->group_desc_count; i++) {
926 /* Check superblocks/block group descriptors */
927 if (ext2fs_bg_has_super(fs, i)) {
928 if (cluster >= EXT2FS_B2C(fs, first_block) &&
929 (cluster <= EXT2FS_B2C(fs, first_block +
934 /* Check the inode table */
935 if ((ext2fs_inode_table_loc(fs, i)) &&
936 (cluster >= EXT2FS_B2C(fs,
937 ext2fs_inode_table_loc(fs, i))) &&
938 (cluster <= EXT2FS_B2C(fs,
939 ext2fs_inode_table_loc(fs, i) +
940 fs->inode_blocks_per_group - 1)))
943 /* Check the bitmap blocks */
944 if ((cluster == EXT2FS_B2C(fs,
945 ext2fs_block_bitmap_loc(fs, i))) ||
946 (cluster == EXT2FS_B2C(fs,
947 ext2fs_inode_bitmap_loc(fs, i))))
950 first_block += fs->super->s_blocks_per_group;