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 int 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 = ext2fs_allocate_inode_bitmap(fs,
221 _("multiply claimed inode map"), &inode_dup_map);
223 fix_problem(ctx, PR_1B_ALLOCATE_IBITMAP_ERROR, &pctx);
224 ctx->flags |= E2F_FLAG_ABORT;
228 dict_init(&ino_dict, DICTCOUNT_T_MAX, dict_int_cmp);
229 dict_init(&clstr_dict, DICTCOUNT_T_MAX, dict_int_cmp);
230 dict_set_allocator(&ino_dict, NULL, inode_dnode_free, NULL);
231 dict_set_allocator(&clstr_dict, NULL, cluster_dnode_free, NULL);
233 init_resource_track(&rtrack, ctx->fs->io);
234 pass1b(ctx, block_buf);
235 print_resource_track(ctx, "Pass 1b", &rtrack, ctx->fs->io);
237 init_resource_track(&rtrack, ctx->fs->io);
238 pass1c(ctx, block_buf);
239 print_resource_track(ctx, "Pass 1c", &rtrack, ctx->fs->io);
241 init_resource_track(&rtrack, ctx->fs->io);
242 pass1d(ctx, block_buf);
243 print_resource_track(ctx, "Pass 1d", &rtrack, ctx->fs->io);
246 * Time to free all of the accumulated data structures that we
247 * don't need anymore.
249 dict_free_nodes(&ino_dict);
250 dict_free_nodes(&clstr_dict);
251 ext2fs_free_inode_bitmap(inode_dup_map);
255 * Scan the inodes looking for inodes that contain duplicate blocks.
257 struct process_block_struct {
261 struct ext2_inode *inode;
262 struct problem_context *pctx;
265 static void pass1b(e2fsck_t ctx, char *block_buf)
267 ext2_filsys fs = ctx->fs;
269 struct ext2_inode inode;
270 ext2_inode_scan scan;
271 struct process_block_struct pb;
272 struct problem_context pctx;
274 clear_problem_context(&pctx);
276 if (!(ctx->options & E2F_OPT_PREEN))
277 fix_problem(ctx, PR_1B_PASS_HEADER, &pctx);
278 pctx.errcode = ext2fs_open_inode_scan(fs, ctx->inode_buffer_blocks,
281 fix_problem(ctx, PR_1B_ISCAN_ERROR, &pctx);
282 ctx->flags |= E2F_FLAG_ABORT;
285 ctx->stashed_inode = &inode;
290 pctx.errcode = ext2fs_get_next_inode(scan, &ino, &inode);
291 if (pctx.errcode == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE)
294 fix_problem(ctx, PR_1B_ISCAN_ERROR, &pctx);
295 ctx->flags |= E2F_FLAG_ABORT;
300 pctx.ino = ctx->stashed_ino = ino;
301 if ((ino != EXT2_BAD_INO) &&
302 !ext2fs_test_inode_bitmap2(ctx->inode_used_map, ino))
309 if (ext2fs_inode_has_valid_blocks(&inode) ||
310 (ino == EXT2_BAD_INO))
311 pctx.errcode = ext2fs_block_iterate3(fs, ino,
312 BLOCK_FLAG_READ_ONLY, block_buf,
313 process_pass1b_block, &pb);
314 /* If the feature is not set, attrs will be cleared later anyway */
315 if ((fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR) &&
316 ext2fs_file_acl_block(&inode)) {
317 blk64_t blk = ext2fs_file_acl_block(&inode);
318 process_pass1b_block(fs, &blk,
319 BLOCK_COUNT_EXTATTR, 0, 0, &pb);
320 ext2fs_file_acl_block_set(&inode, blk);
323 end_problem_latch(ctx, PR_LATCH_DBLOCK);
324 if (ino >= EXT2_FIRST_INODE(fs->super) ||
325 ino == EXT2_ROOT_INO)
329 fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
331 ext2fs_close_inode_scan(scan);
332 e2fsck_use_inode_shortcuts(ctx, 0);
335 static int process_pass1b_block(ext2_filsys fs EXT2FS_ATTR((unused)),
337 e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
338 blk64_t ref_blk EXT2FS_ATTR((unused)),
339 int ref_offset EXT2FS_ATTR((unused)),
342 struct process_block_struct *p;
345 if (HOLE_BLKADDR(*block_nr))
347 p = (struct process_block_struct *) priv_data;
350 if (!ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr))
353 /* OK, this is a duplicate block */
354 if (p->ino != EXT2_BAD_INO) {
355 p->pctx->blk = *block_nr;
356 fix_problem(ctx, PR_1B_DUP_BLOCK, p->pctx);
359 ext2fs_mark_inode_bitmap2(inode_dup_map, p->ino);
361 add_dupe(ctx, p->ino, EXT2FS_B2C(fs, *block_nr), p->inode);
367 * Pass 1c: Scan directories for inodes with duplicate blocks. This
368 * is used so that we can print pathnames when prompting the user for
371 struct search_dir_struct {
373 ext2_ino_t first_inode;
374 ext2_ino_t max_inode;
377 static int search_dirent_proc(ext2_ino_t dir, int entry,
378 struct ext2_dir_entry *dirent,
379 int offset EXT2FS_ATTR((unused)),
380 int blocksize EXT2FS_ATTR((unused)),
381 char *buf EXT2FS_ATTR((unused)),
384 struct search_dir_struct *sd;
388 sd = (struct search_dir_struct *) priv_data;
390 if (dirent->inode > sd->max_inode)
391 /* Should abort this inode, but not everything */
394 if ((dirent->inode < sd->first_inode) || (entry < DIRENT_OTHER_FILE) ||
395 !ext2fs_test_inode_bitmap2(inode_dup_map, dirent->inode))
398 n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(dirent->inode));
401 p = (struct dup_inode *) dnode_get(n);
407 return(sd->count ? 0 : DIRENT_ABORT);
411 static void pass1c(e2fsck_t ctx, char *block_buf)
413 ext2_filsys fs = ctx->fs;
414 struct search_dir_struct sd;
415 struct problem_context pctx;
417 clear_problem_context(&pctx);
419 if (!(ctx->options & E2F_OPT_PREEN))
420 fix_problem(ctx, PR_1C_PASS_HEADER, &pctx);
423 * Search through all directories to translate inodes to names
424 * (by searching for the containing directory for that inode.)
426 sd.count = dup_inode_count - dup_inode_founddir;
427 sd.first_inode = EXT2_FIRST_INODE(fs->super);
428 sd.max_inode = fs->super->s_inodes_count;
429 ext2fs_dblist_dir_iterate(fs->dblist, 0, block_buf,
430 search_dirent_proc, &sd);
433 static void pass1d(e2fsck_t ctx, char *block_buf)
435 ext2_filsys fs = ctx->fs;
436 struct dup_inode *p, *t;
437 struct dup_cluster *q;
438 ext2_ino_t *shared, ino;
443 struct problem_context pctx;
445 struct cluster_el *s;
448 clear_problem_context(&pctx);
450 if (!(ctx->options & E2F_OPT_PREEN))
451 fix_problem(ctx, PR_1D_PASS_HEADER, &pctx);
452 e2fsck_read_bitmaps(ctx);
454 pctx.num = dup_inode_count; /* dict_count(&ino_dict); */
455 fix_problem(ctx, PR_1D_NUM_DUP_INODES, &pctx);
456 shared = (ext2_ino_t *) e2fsck_allocate_memory(ctx,
457 sizeof(ext2_ino_t) * dict_count(&ino_dict),
458 "Shared inode list");
459 for (n = dict_first(&ino_dict); n; n = dict_next(&ino_dict, n)) {
460 p = (struct dup_inode *) dnode_get(n);
463 ino = (ext2_ino_t)VOIDPTR_TO_INT(dnode_getkey(n));
464 if (ino == EXT2_BAD_INO || ino == EXT2_RESIZE_INO)
468 * Find all of the inodes which share blocks with this
469 * one. First we find all of the duplicate blocks
470 * belonging to this inode, and then search each block
471 * get the list of inodes, and merge them together.
473 for (s = p->cluster_list; s; s = s->next) {
474 m = dict_lookup(&clstr_dict,
475 INT_TO_VOIDPTR(s->cluster));
477 continue; /* Should never happen... */
478 q = (struct dup_cluster *) dnode_get(m);
481 if (check_if_fs_cluster(ctx, s->cluster)) {
487 * Add all inodes used by this block to the
488 * shared[] --- which is a unique list, so
489 * if an inode is already in shared[], don't
492 for (r = q->inode_list; r; r = r->next) {
495 for (i = 0; i < shared_len; i++)
496 if (shared[i] == r->inode)
498 if (i == shared_len) {
499 shared[shared_len++] = r->inode;
505 * Report the inode that we are working on
507 pctx.inode = &p->inode;
510 pctx.blkcount = p->num_dupblocks;
511 pctx.num = meta_data ? shared_len+1 : shared_len;
512 fix_problem(ctx, PR_1D_DUP_FILE, &pctx);
517 fix_problem(ctx, PR_1D_SHARE_METADATA, &pctx);
519 for (i = 0; i < shared_len; i++) {
520 m = dict_lookup(&ino_dict, INT_TO_VOIDPTR(shared[i]));
522 continue; /* should never happen */
523 t = (struct dup_inode *) dnode_get(m);
525 * Report the inode that we are sharing with
527 pctx.inode = &t->inode;
528 pctx.ino = shared[i];
530 fix_problem(ctx, PR_1D_DUP_FILE_LIST, &pctx);
533 fix_problem(ctx, PR_1D_DUP_BLOCKS_DEALT, &pctx);
536 if (fix_problem(ctx, PR_1D_CLONE_QUESTION, &pctx)) {
537 pctx.errcode = clone_file(ctx, ino, p, block_buf);
539 fix_problem(ctx, PR_1D_CLONE_ERROR, &pctx);
543 if (fix_problem(ctx, PR_1D_DELETE_QUESTION, &pctx))
544 delete_file(ctx, ino, p, block_buf);
546 ext2fs_unmark_valid(fs);
548 ext2fs_free_mem(&shared);
552 * Drop the refcount on the dup_block structure, and clear the entry
553 * in the block_dup_map if appropriate.
555 static void decrement_badcount(e2fsck_t ctx, blk64_t block,
556 struct dup_cluster *p)
559 if (p->num_bad <= 0 ||
560 (p->num_bad == 1 && !check_if_fs_block(ctx, block))) {
561 if (check_if_fs_cluster(ctx, EXT2FS_B2C(ctx->fs, block)))
563 ext2fs_unmark_block_bitmap2(ctx->block_dup_map, block);
567 static int delete_file_block(ext2_filsys fs,
569 e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
570 blk64_t ref_block EXT2FS_ATTR((unused)),
571 int ref_offset EXT2FS_ATTR((unused)),
574 struct process_block_struct *pb;
575 struct dup_cluster *p;
580 pb = (struct process_block_struct *) priv_data;
583 if (HOLE_BLKADDR(*block_nr))
586 c = EXT2FS_B2C(fs, *block_nr);
587 if (ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr)) {
588 n = dict_lookup(&clstr_dict, INT_TO_VOIDPTR(c));
590 p = (struct dup_cluster *) dnode_get(n);
591 decrement_badcount(ctx, *block_nr, p);
593 com_err("delete_file_block", 0,
594 _("internal error: can't find dup_blk for %llu\n"),
597 ext2fs_unmark_block_bitmap2(ctx->block_found_map, *block_nr);
598 ext2fs_block_alloc_stats2(fs, *block_nr, -1);
604 static void delete_file(e2fsck_t ctx, ext2_ino_t ino,
605 struct dup_inode *dp, char* block_buf)
607 ext2_filsys fs = ctx->fs;
608 struct process_block_struct pb;
609 struct ext2_inode inode;
610 struct problem_context pctx;
613 clear_problem_context(&pctx);
614 pctx.ino = pb.ino = ino;
615 pb.dup_blocks = dp->num_dupblocks;
617 pctx.str = "delete_file";
619 e2fsck_read_inode(ctx, ino, &inode, "delete_file");
620 if (ext2fs_inode_has_valid_blocks(&inode))
621 pctx.errcode = ext2fs_block_iterate3(fs, ino, BLOCK_FLAG_READ_ONLY,
622 block_buf, delete_file_block, &pb);
624 fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
625 if (ctx->inode_bad_map)
626 ext2fs_unmark_inode_bitmap2(ctx->inode_bad_map, ino);
627 ext2fs_inode_alloc_stats2(fs, ino, -1, LINUX_S_ISDIR(inode.i_mode));
629 /* Inode may have changed by block_iterate, so reread it */
630 e2fsck_read_inode(ctx, ino, &inode, "delete_file");
631 e2fsck_clear_inode(ctx, ino, &inode, 0, "delete_file");
632 if (ext2fs_file_acl_block(&inode) &&
633 (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) {
635 pctx.errcode = ext2fs_adjust_ea_refcount2(fs,
636 ext2fs_file_acl_block(&inode),
637 block_buf, -1, &count);
638 if (pctx.errcode == EXT2_ET_BAD_EA_BLOCK_NUM) {
643 pctx.blk = ext2fs_file_acl_block(&inode);
644 fix_problem(ctx, PR_1B_ADJ_EA_REFCOUNT, &pctx);
647 * If the count is zero, then arrange to have the
648 * block deleted. If the block is in the block_dup_map,
649 * also call delete_file_block since it will take care
650 * of keeping the accounting straight.
653 ext2fs_test_block_bitmap2(ctx->block_dup_map,
654 ext2fs_file_acl_block(&inode))) {
655 blk64_t blk = ext2fs_file_acl_block(&inode);
656 delete_file_block(fs, &blk,
657 BLOCK_COUNT_EXTATTR, 0, 0, &pb);
658 ext2fs_file_acl_block_set(&inode, blk);
663 struct clone_struct {
672 static int clone_file_block(ext2_filsys fs,
674 e2_blkcnt_t blockcnt,
675 blk64_t ref_block EXT2FS_ATTR((unused)),
676 int ref_offset EXT2FS_ATTR((unused)),
679 struct dup_cluster *p;
682 struct clone_struct *cs = (struct clone_struct *) priv_data;
690 if (HOLE_BLKADDR(*block_nr))
693 c = EXT2FS_B2C(fs, blockcnt);
694 if (check_if_fs_cluster(ctx, EXT2FS_B2C(fs, *block_nr)))
697 if (((blockcnt > 0) && c == cs->dup_cluster) ||
698 ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr)) {
699 n = dict_lookup(&clstr_dict,
700 INT_TO_VOIDPTR(EXT2FS_B2C(fs, *block_nr)));
702 com_err("clone_file_block", 0,
703 _("internal error: can't find dup_blk for %llu\n"),
708 p = (struct dup_cluster *) dnode_get(n);
710 decrement_badcount(ctx, *block_nr, p);
712 if (p->num_bad == 0 && !is_meta) {
714 * Normally num_bad never gets to zero; but in
715 * the case of bigalloc file systems, we don't
716 * how many blocks might be in use by a
717 * particular inode. So we may end up
718 * relocating the cluster even though this
719 * inode is the last user of the cluster. In
720 * that case, since we've already moved some
721 * of the blocks of that cluster, we'll
722 * complete the relocation and free the
723 * original cluster here.
725 ext2fs_unmark_block_bitmap2(ctx->block_found_map,
727 ext2fs_block_alloc_stats2(fs, *block_nr, -1);
730 if ((blockcnt > 0) && c == cs->dup_cluster) {
731 new_block = cs->alloc_block;
736 retval = ext2fs_new_block2(fs, 0, ctx->block_found_map,
739 cs->errcode = retval;
742 cs->alloc_block = new_block;
745 new_block &= ~EXT2FS_CLUSTER_MASK(fs);
746 new_block += EXT2FS_CLUSTER_MASK(fs) & blockcnt;
747 if (cs->dir && (blockcnt >= 0)) {
748 retval = ext2fs_set_dir_block2(fs->dblist,
749 cs->dir, new_block, blockcnt);
751 cs->errcode = retval;
756 printf("Cloning block #%lld from %llu to %llu\n",
757 blockcnt, *block_nr, new_block);
759 retval = io_channel_read_blk64(fs->io, *block_nr, 1, cs->buf);
761 cs->errcode = retval;
764 retval = io_channel_write_blk64(fs->io, new_block, 1, cs->buf);
766 cs->errcode = retval;
769 *block_nr = new_block;
770 ext2fs_mark_block_bitmap2(ctx->block_found_map, new_block);
771 ext2fs_mark_block_bitmap2(fs->block_map, new_block);
772 return BLOCK_CHANGED;
777 static int clone_file(e2fsck_t ctx, ext2_ino_t ino,
778 struct dup_inode *dp, char* block_buf)
780 ext2_filsys fs = ctx->fs;
782 struct clone_struct cs;
783 struct problem_context pctx;
784 blk64_t blk, new_blk;
786 struct inode_el *ino_el;
787 struct dup_cluster *dc;
788 struct dup_inode *di;
790 clear_problem_context(&pctx);
796 retval = ext2fs_get_mem(fs->blocksize, &cs.buf);
800 if (ext2fs_test_inode_bitmap2(ctx->inode_dir_map, ino))
804 pctx.str = "clone_file";
805 if (ext2fs_inode_has_valid_blocks(&dp->inode))
806 pctx.errcode = ext2fs_block_iterate3(fs, ino, 0, block_buf,
807 clone_file_block, &cs);
808 ext2fs_mark_bb_dirty(fs);
810 fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
811 retval = pctx.errcode;
815 com_err("clone_file", cs.errcode,
816 _("returned from clone_file_block"));
820 /* The inode may have changed on disk, so we have to re-read it */
821 e2fsck_read_inode(ctx, ino, &dp->inode, "clone file EA");
822 blk = ext2fs_file_acl_block(&dp->inode);
824 if (blk && (clone_file_block(fs, &new_blk,
825 BLOCK_COUNT_EXTATTR, 0, 0, &cs) ==
827 ext2fs_file_acl_block_set(&dp->inode, new_blk);
828 e2fsck_write_inode(ctx, ino, &dp->inode, "clone file EA");
830 * If we cloned the EA block, find all other inodes
831 * which refered to that EA block, and modify
832 * them to point to the new EA block.
834 n = dict_lookup(&clstr_dict,
835 INT_TO_VOIDPTR(EXT2FS_B2C(fs, blk)));
837 com_err("clone_file", 0,
838 _("internal error: couldn't lookup EA "
839 "block record for %llu"), blk);
840 retval = 0; /* OK to stumble on... */
843 dc = (struct dup_cluster *) dnode_get(n);
844 for (ino_el = dc->inode_list; ino_el; ino_el = ino_el->next) {
845 if (ino_el->inode == ino)
847 n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(ino_el->inode));
849 com_err("clone_file", 0,
850 _("internal error: couldn't lookup EA "
851 "inode record for %u"),
853 retval = 0; /* OK to stumble on... */
856 di = (struct dup_inode *) dnode_get(n);
857 if (ext2fs_file_acl_block(&di->inode) == blk) {
858 ext2fs_file_acl_block_set(&di->inode,
859 ext2fs_file_acl_block(&dp->inode));
860 e2fsck_write_inode(ctx, ino_el->inode,
861 &di->inode, "clone file EA");
862 decrement_badcount(ctx, blk, dc);
868 ext2fs_free_mem(&cs.buf);
873 * This routine returns 1 if a block overlaps with one of the superblocks,
874 * group descriptors, inode bitmaps, or block bitmaps.
876 static int check_if_fs_block(e2fsck_t ctx, blk64_t test_block)
878 ext2_filsys fs = ctx->fs;
882 first_block = fs->super->s_first_data_block;
883 for (i = 0; i < fs->group_desc_count; i++) {
885 /* Check superblocks/block group descriptors */
886 if (ext2fs_bg_has_super(fs, i)) {
887 if (test_block >= first_block &&
888 (test_block <= first_block + fs->desc_blocks))
892 /* Check the inode table */
893 if ((ext2fs_inode_table_loc(fs, i)) &&
894 (test_block >= ext2fs_inode_table_loc(fs, i)) &&
895 (test_block < (ext2fs_inode_table_loc(fs, i) +
896 fs->inode_blocks_per_group)))
899 /* Check the bitmap blocks */
900 if ((test_block == ext2fs_block_bitmap_loc(fs, i)) ||
901 (test_block == ext2fs_inode_bitmap_loc(fs, i)))
904 first_block += fs->super->s_blocks_per_group;
910 * This routine returns 1 if a cluster overlaps with one of the superblocks,
911 * group descriptors, inode bitmaps, or block bitmaps.
913 static int check_if_fs_cluster(e2fsck_t ctx, blk64_t cluster)
915 ext2_filsys fs = ctx->fs;
919 first_block = fs->super->s_first_data_block;
920 for (i = 0; i < fs->group_desc_count; i++) {
922 /* Check superblocks/block group descriptors */
923 if (ext2fs_bg_has_super(fs, i)) {
924 if (cluster >= EXT2FS_B2C(fs, first_block) &&
925 (cluster <= EXT2FS_B2C(fs, first_block +
930 /* Check the inode table */
931 if ((ext2fs_inode_table_loc(fs, i)) &&
932 (cluster >= EXT2FS_B2C(fs,
933 ext2fs_inode_table_loc(fs, i))) &&
934 (cluster <= EXT2FS_B2C(fs,
935 ext2fs_inode_table_loc(fs, i) +
936 fs->inode_blocks_per_group - 1)))
939 /* Check the bitmap blocks */
940 if ((cluster == EXT2FS_B2C(fs,
941 ext2fs_block_bitmap_loc(fs, i))) ||
942 (cluster == EXT2FS_B2C(fs,
943 ext2fs_inode_bitmap_loc(fs, i))))
946 first_block += fs->super->s_blocks_per_group;