X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=e2fsck%2Fpass1b.c;h=155fcba4ad920559a65fa26e8339d224149b51b7;hb=829d9994880394e48c883510799b1536812d6efb;hp=c5ad8ba989b5f60ab6ba252c515846af0d77be67;hpb=c4e3d3f374b409500e3dd05c0b0eca6ac98a6b4e;p=tools%2Fe2fsprogs.git diff --git a/e2fsck/pass1b.c b/e2fsck/pass1b.c index c5ad8ba..155fcba 100644 --- a/e2fsck/pass1b.c +++ b/e2fsck/pass1b.c @@ -4,7 +4,7 @@ * This file contains pass1B, pass1C, and pass1D of e2fsck. They are * only invoked if pass 1 discovered blocks which are in use by more * than one inode. - * + * * Pass1B scans the data blocks of all the inodes again, generating a * complete list of duplicate blocks and which inodes have claimed * them. @@ -17,14 +17,14 @@ * blocks, the user is prompted if s/he would like to clone the file * (so that the file gets a fresh copy of the duplicated blocks) or * simply to delete the file. - * + * * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o. * * %Begin-Header% * This file may be redistributed under the terms of the GNU Public * License. * %End-Header% - * + * */ #include @@ -32,6 +32,18 @@ #include #endif +#ifdef HAVE_INTTYPES_H +#include +#endif + +#ifndef HAVE_INTPTR_T +typedef long intptr_t; +#endif + +/* Needed for architectures where sizeof(int) != sizeof(void *) */ +#define INT_TO_VOIDPTR(val) ((void *)(intptr_t)(val)) +#define VOIDPTR_TO_INT(ptr) ((int)(intptr_t)(ptr)) + #include #include "e2fsck.h" @@ -42,7 +54,7 @@ #define BLOCK_COUNT_EXTATTR (-5) struct block_el { - blk_t block; + blk64_t block; struct block_el *next; }; @@ -70,20 +82,21 @@ struct dup_inode { struct block_el *block_list; }; -static int process_pass1b_block(ext2_filsys fs, blk_t *blocknr, - e2_blkcnt_t blockcnt, blk_t ref_blk, +static int process_pass1b_block(ext2_filsys fs, blk64_t *blocknr, + e2_blkcnt_t blockcnt, blk64_t ref_blk, int ref_offset, void *priv_data); static void delete_file(e2fsck_t ctx, ext2_ino_t ino, struct dup_inode *dp, char *block_buf); static int clone_file(e2fsck_t ctx, ext2_ino_t ino, struct dup_inode *dp, char* block_buf); -static int check_if_fs_block(e2fsck_t ctx, blk_t test_blk); +static int check_if_fs_block(e2fsck_t ctx, blk64_t test_blk); static void pass1b(e2fsck_t ctx, char *block_buf); static void pass1c(e2fsck_t ctx, char *block_buf); static void pass1d(e2fsck_t ctx, char *block_buf); static int dup_inode_count = 0; +static int dup_inode_founddir = 0; static dict_t blk_dict, ino_dict; @@ -91,10 +104,10 @@ static ext2fs_inode_bitmap inode_dup_map; static int dict_int_cmp(const void *a, const void *b) { - int ia, ib; + intptr_t ia, ib; - ia = (int) a; - ib = (int) b; + ia = (intptr_t)a; + ib = (intptr_t)b; return (ia-ib); } @@ -102,7 +115,7 @@ static int dict_int_cmp(const void *a, const void *b) /* * Add a duplicate block record */ -static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk_t blk, +static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk64_t blk, struct ext2_inode *inode) { dnode_t *n; @@ -111,7 +124,7 @@ static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk_t blk, struct block_el *blk_el; struct inode_el *ino_el; - n = dict_lookup(&blk_dict, (void *) blk); + n = dict_lookup(&blk_dict, INT_TO_VOIDPTR(blk)); if (n) db = (struct dup_block *) dnode_get(n); else { @@ -119,7 +132,7 @@ static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk_t blk, sizeof(struct dup_block), "duplicate block header"); db->num_bad = 0; db->inode_list = 0; - dict_alloc_insert(&blk_dict, (void *) blk, db); + dict_alloc_insert(&blk_dict, INT_TO_VOIDPTR(blk), db); } ino_el = (struct inode_el *) e2fsck_allocate_memory(ctx, sizeof(struct inode_el), "inode element"); @@ -128,17 +141,22 @@ static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk_t blk, db->inode_list = ino_el; db->num_bad++; - n = dict_lookup(&ino_dict, (void *) ino); + n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(ino)); if (n) di = (struct dup_inode *) dnode_get(n); else { di = (struct dup_inode *) e2fsck_allocate_memory(ctx, sizeof(struct dup_inode), "duplicate inode header"); - di->dir = (ino == EXT2_ROOT_INO) ? EXT2_ROOT_INO : 0 ; + if (ino == EXT2_ROOT_INO) { + di->dir = EXT2_ROOT_INO; + dup_inode_founddir++; + } else + di->dir = 0; + di->num_dupblocks = 0; di->block_list = 0; di->inode = *inode; - dict_alloc_insert(&ino_dict, (void *) ino, di); + dict_alloc_insert(&ino_dict, INT_TO_VOIDPTR(ino), di); } blk_el = (struct block_el *) e2fsck_allocate_memory(ctx, sizeof(struct block_el), "block element"); @@ -151,7 +169,8 @@ static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk_t blk, /* * Free a duplicate inode record */ -static void inode_dnode_free(dnode_t *node, void *context) +static void inode_dnode_free(dnode_t *node, + void *context EXT2FS_ATTR((unused))) { struct dup_inode *di; struct block_el *p, *next; @@ -161,13 +180,15 @@ static void inode_dnode_free(dnode_t *node, void *context) next = p->next; free(p); } + free(di); free(node); } /* * Free a duplicate block record */ -static void block_dnode_free(dnode_t *node, void *context) +static void block_dnode_free(dnode_t *node, + void *context EXT2FS_ATTR((unused))) { struct dup_block *db; struct inode_el *p, *next; @@ -177,6 +198,7 @@ static void block_dnode_free(dnode_t *node, void *context) next = p->next; free(p); } + free(db); free(node); } @@ -188,9 +210,12 @@ void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf) { ext2_filsys fs = ctx->fs; struct problem_context pctx; +#ifdef RESOURCE_TRACK + struct resource_track rtrack; +#endif clear_problem_context(&pctx); - + pctx.errcode = ext2fs_allocate_inode_bitmap(fs, _("multiply claimed inode map"), &inode_dup_map); if (pctx.errcode) { @@ -203,10 +228,18 @@ void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf) dict_init(&blk_dict, DICTCOUNT_T_MAX, dict_int_cmp); dict_set_allocator(&ino_dict, NULL, inode_dnode_free, NULL); dict_set_allocator(&blk_dict, NULL, block_dnode_free, NULL); - + + init_resource_track(&rtrack, ctx->fs->io); pass1b(ctx, block_buf); + print_resource_track(ctx, "Pass 1b", &rtrack, ctx->fs->io); + + init_resource_track(&rtrack, ctx->fs->io); pass1c(ctx, block_buf); + print_resource_track(ctx, "Pass 1c", &rtrack, ctx->fs->io); + + init_resource_track(&rtrack, ctx->fs->io); pass1d(ctx, block_buf); + print_resource_track(ctx, "Pass 1d", &rtrack, ctx->fs->io); /* * Time to free all of the accumulated data structures that we @@ -214,6 +247,7 @@ void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf) */ dict_free_nodes(&ino_dict); dict_free_nodes(&blk_dict); + ext2fs_free_inode_bitmap(inode_dup_map); } /* @@ -235,10 +269,11 @@ static void pass1b(e2fsck_t ctx, char *block_buf) ext2_inode_scan scan; struct process_block_struct pb; struct problem_context pctx; - + clear_problem_context(&pctx); - - fix_problem(ctx, PR_1B_PASS_HEADER, &pctx); + + if (!(ctx->options & E2F_OPT_PREEN)) + fix_problem(ctx, PR_1B_PASS_HEADER, &pctx); pctx.errcode = ext2fs_open_inode_scan(fs, ctx->inode_buffer_blocks, &scan); if (pctx.errcode) { @@ -263,7 +298,7 @@ static void pass1b(e2fsck_t ctx, char *block_buf) break; pctx.ino = ctx->stashed_ino = ino; if ((ino != EXT2_BAD_INO) && - !ext2fs_test_inode_bitmap(ctx->inode_used_map, ino)) + !ext2fs_test_inode_bitmap2(ctx->inode_used_map, ino)) continue; pb.ino = ino; @@ -272,11 +307,15 @@ static void pass1b(e2fsck_t ctx, char *block_buf) if (ext2fs_inode_has_valid_blocks(&inode) || (ino == EXT2_BAD_INO)) - pctx.errcode = ext2fs_block_iterate2(fs, ino, - 0, block_buf, process_pass1b_block, &pb); - if (inode.i_file_acl) - process_pass1b_block(fs, &inode.i_file_acl, + pctx.errcode = ext2fs_block_iterate3(fs, ino, + BLOCK_FLAG_READ_ONLY, block_buf, + process_pass1b_block, &pb); + if (ext2fs_file_acl_block(&inode)) { + blk64_t blk = ext2fs_file_acl_block(&inode); + process_pass1b_block(fs, &blk, BLOCK_COUNT_EXTATTR, 0, 0, &pb); + ext2fs_file_acl_block_set(&inode, blk); + } if (pb.dup_blocks) { end_problem_latch(ctx, PR_LATCH_DBLOCK); if (ino >= EXT2_FIRST_INODE(fs->super) || @@ -290,11 +329,11 @@ static void pass1b(e2fsck_t ctx, char *block_buf) e2fsck_use_inode_shortcuts(ctx, 0); } -static int process_pass1b_block(ext2_filsys fs, - blk_t *block_nr, - e2_blkcnt_t blockcnt, - blk_t ref_blk, - int ref_offset, +static int process_pass1b_block(ext2_filsys fs EXT2FS_ATTR((unused)), + blk64_t *block_nr, + e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)), + blk64_t ref_blk EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), void *priv_data) { struct process_block_struct *p; @@ -304,20 +343,20 @@ static int process_pass1b_block(ext2_filsys fs, return 0; p = (struct process_block_struct *) priv_data; ctx = p->ctx; - - if (!ext2fs_test_block_bitmap(ctx->block_dup_map, *block_nr)) + + if (!ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr)) return 0; - + /* OK, this is a duplicate block */ if (p->ino != EXT2_BAD_INO) { p->pctx->blk = *block_nr; fix_problem(ctx, PR_1B_DUP_BLOCK, p->pctx); } p->dup_blocks++; - ext2fs_mark_inode_bitmap(inode_dup_map, p->ino); + ext2fs_mark_inode_bitmap2(inode_dup_map, p->ino); add_dupe(ctx, p->ino, *block_nr, p->inode); - + return 0; } @@ -334,8 +373,10 @@ struct search_dir_struct { static int search_dirent_proc(ext2_ino_t dir, int entry, struct ext2_dir_entry *dirent, - int offset, int blocksize, - char *buf, void *priv_data) + int offset EXT2FS_ATTR((unused)), + int blocksize EXT2FS_ATTR((unused)), + char *buf EXT2FS_ATTR((unused)), + void *priv_data) { struct search_dir_struct *sd; struct dup_inode *p; @@ -345,18 +386,20 @@ static int search_dirent_proc(ext2_ino_t dir, int entry, if (dirent->inode > sd->max_inode) /* Should abort this inode, but not everything */ - return 0; + return 0; if ((dirent->inode < sd->first_inode) || (entry < DIRENT_OTHER_FILE) || - !ext2fs_test_inode_bitmap(inode_dup_map, dirent->inode)) + !ext2fs_test_inode_bitmap2(inode_dup_map, dirent->inode)) return 0; - n = dict_lookup(&ino_dict, (void *) dirent->inode); + n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(dirent->inode)); if (!n) return 0; p = (struct dup_inode *) dnode_get(n); - p->dir = dir; - sd->count--; + if (!p->dir) { + p->dir = dir; + sd->count--; + } return(sd->count ? 0 : DIRENT_ABORT); } @@ -370,18 +413,19 @@ static void pass1c(e2fsck_t ctx, char *block_buf) clear_problem_context(&pctx); - fix_problem(ctx, PR_1C_PASS_HEADER, &pctx); + if (!(ctx->options & E2F_OPT_PREEN)) + fix_problem(ctx, PR_1C_PASS_HEADER, &pctx); /* * Search through all directories to translate inodes to names * (by searching for the containing directory for that inode.) */ - sd.count = dup_inode_count; + sd.count = dup_inode_count - dup_inode_founddir; sd.first_inode = EXT2_FIRST_INODE(fs->super); sd.max_inode = fs->super->s_inodes_count; ext2fs_dblist_dir_iterate(fs->dblist, 0, block_buf, search_dirent_proc, &sd); -} +} static void pass1d(e2fsck_t ctx, char *block_buf) { @@ -397,10 +441,11 @@ static void pass1d(e2fsck_t ctx, char *block_buf) dnode_t *n, *m; struct block_el *s; struct inode_el *r; - + clear_problem_context(&pctx); - - fix_problem(ctx, PR_1D_PASS_HEADER, &pctx); + + if (!(ctx->options & E2F_OPT_PREEN)) + fix_problem(ctx, PR_1D_PASS_HEADER, &pctx); e2fsck_read_bitmaps(ctx); pctx.num = dup_inode_count; /* dict_count(&ino_dict); */ @@ -412,8 +457,8 @@ static void pass1d(e2fsck_t ctx, char *block_buf) p = (struct dup_inode *) dnode_get(n); shared_len = 0; file_ok = 1; - ino = (ext2_ino_t) dnode_getkey(n); - if (ino == EXT2_BAD_INO) + ino = (ext2_ino_t)VOIDPTR_TO_INT(dnode_getkey(n)); + if (ino == EXT2_BAD_INO || ino == EXT2_RESIZE_INO) continue; /* @@ -423,7 +468,7 @@ static void pass1d(e2fsck_t ctx, char *block_buf) * get the list of inodes, and merge them together. */ for (s = p->block_list; s; s = s->next) { - m = dict_lookup(&blk_dict, (void *) s->block); + m = dict_lookup(&blk_dict, INT_TO_VOIDPTR(s->block)); if (!m) continue; /* Should never happen... */ q = (struct dup_block *) dnode_get(m); @@ -433,7 +478,7 @@ static void pass1d(e2fsck_t ctx, char *block_buf) file_ok = 0; meta_data = 1; } - + /* * Add all inodes used by this block to the * shared[] --- which is a unique list, so @@ -463,12 +508,12 @@ static void pass1d(e2fsck_t ctx, char *block_buf) fix_problem(ctx, PR_1D_DUP_FILE, &pctx); pctx.blkcount = 0; pctx.num = 0; - + if (meta_data) fix_problem(ctx, PR_1D_SHARE_METADATA, &pctx); - + for (i = 0; i < shared_len; i++) { - m = dict_lookup(&ino_dict, (void *) shared[i]); + m = dict_lookup(&ino_dict, INT_TO_VOIDPTR(shared[i])); if (!m) continue; /* should never happen */ t = (struct dup_inode *) dnode_get(m); @@ -503,19 +548,19 @@ static void pass1d(e2fsck_t ctx, char *block_buf) * Drop the refcount on the dup_block structure, and clear the entry * in the block_dup_map if appropriate. */ -static void decrement_badcount(e2fsck_t ctx, blk_t block, struct dup_block *p) +static void decrement_badcount(e2fsck_t ctx, blk64_t block, struct dup_block *p) { p->num_bad--; if (p->num_bad <= 0 || (p->num_bad == 1 && !check_if_fs_block(ctx, block))) - ext2fs_unmark_block_bitmap(ctx->block_dup_map, block); + ext2fs_unmark_block_bitmap2(ctx->block_dup_map, block); } static int delete_file_block(ext2_filsys fs, - blk_t *block_nr, - e2_blkcnt_t blockcnt, - blk_t ref_block, - int ref_offset, + blk64_t *block_nr, + e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)), + blk64_t ref_block EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), void *priv_data) { struct process_block_struct *pb; @@ -529,23 +574,23 @@ static int delete_file_block(ext2_filsys fs, if (HOLE_BLKADDR(*block_nr)) return 0; - if (ext2fs_test_block_bitmap(ctx->block_dup_map, *block_nr)) { - n = dict_lookup(&blk_dict, (void *) *block_nr); + if (ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr)) { + n = dict_lookup(&blk_dict, INT_TO_VOIDPTR(*block_nr)); if (n) { p = (struct dup_block *) dnode_get(n); decrement_badcount(ctx, *block_nr, p); } else com_err("delete_file_block", 0, - _("internal error; can't find dup_blk for %d\n"), + _("internal error: can't find dup_blk for %llu\n"), *block_nr); } else { - ext2fs_unmark_block_bitmap(ctx->block_found_map, *block_nr); - ext2fs_block_alloc_stats(fs, *block_nr, -1); + ext2fs_unmark_block_bitmap2(ctx->block_found_map, *block_nr); + ext2fs_block_alloc_stats2(fs, *block_nr, -1); } - + return 0; } - + static void delete_file(e2fsck_t ctx, ext2_ino_t ino, struct dup_inode *dp, char* block_buf) { @@ -563,31 +608,29 @@ static void delete_file(e2fsck_t ctx, ext2_ino_t ino, e2fsck_read_inode(ctx, ino, &inode, "delete_file"); if (ext2fs_inode_has_valid_blocks(&inode)) - pctx.errcode = ext2fs_block_iterate2(fs, ino, 0, block_buf, - delete_file_block, &pb); + pctx.errcode = ext2fs_block_iterate3(fs, ino, BLOCK_FLAG_READ_ONLY, + block_buf, delete_file_block, &pb); if (pctx.errcode) fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx); - ext2fs_unmark_inode_bitmap(ctx->inode_used_map, ino); - ext2fs_unmark_inode_bitmap(ctx->inode_dir_map, ino); if (ctx->inode_bad_map) - ext2fs_unmark_inode_bitmap(ctx->inode_bad_map, ino); + ext2fs_unmark_inode_bitmap2(ctx->inode_bad_map, ino); ext2fs_inode_alloc_stats2(fs, ino, -1, LINUX_S_ISDIR(inode.i_mode)); /* Inode may have changed by block_iterate, so reread it */ e2fsck_read_inode(ctx, ino, &inode, "delete_file"); - inode.i_links_count = 0; - inode.i_dtime = time(0); - if (inode.i_file_acl && + e2fsck_clear_inode(ctx, ino, &inode, 0, "delete_file"); + if (ext2fs_file_acl_block(&inode) && (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) { count = 1; - pctx.errcode = ext2fs_adjust_ea_refcount(fs, inode.i_file_acl, + pctx.errcode = ext2fs_adjust_ea_refcount2(fs, + ext2fs_file_acl_block(&inode), block_buf, -1, &count); if (pctx.errcode == EXT2_ET_BAD_EA_BLOCK_NUM) { pctx.errcode = 0; count = 1; } if (pctx.errcode) { - pctx.blk = inode.i_file_acl; + pctx.blk = ext2fs_file_acl_block(&inode); fix_problem(ctx, PR_1B_ADJ_EA_REFCOUNT, &pctx); } /* @@ -597,12 +640,14 @@ static void delete_file(e2fsck_t ctx, ext2_ino_t ino, * of keeping the accounting straight. */ if ((count == 0) || - ext2fs_test_block_bitmap(ctx->block_dup_map, - inode.i_file_acl)) - delete_file_block(fs, &inode.i_file_acl, + ext2fs_test_block_bitmap2(ctx->block_dup_map, + ext2fs_file_acl_block(&inode))) { + blk64_t blk = ext2fs_file_acl_block(&inode); + delete_file_block(fs, &blk, BLOCK_COUNT_EXTATTR, 0, 0, &pb); + ext2fs_file_acl_block_set(&inode, blk); + } } - e2fsck_write_inode(ctx, ino, &inode, "delete_file"); } struct clone_struct { @@ -613,36 +658,36 @@ struct clone_struct { }; static int clone_file_block(ext2_filsys fs, - blk_t *block_nr, + blk64_t *block_nr, e2_blkcnt_t blockcnt, - blk_t ref_block, - int ref_offset, + blk64_t ref_block EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), void *priv_data) { struct dup_block *p; - blk_t new_block; + blk64_t new_block; errcode_t retval; struct clone_struct *cs = (struct clone_struct *) priv_data; dnode_t *n; e2fsck_t ctx; ctx = cs->ctx; - + if (HOLE_BLKADDR(*block_nr)) return 0; - if (ext2fs_test_block_bitmap(ctx->block_dup_map, *block_nr)) { - n = dict_lookup(&blk_dict, (void *) *block_nr); + if (ext2fs_test_block_bitmap2(ctx->block_dup_map, *block_nr)) { + n = dict_lookup(&blk_dict, INT_TO_VOIDPTR(*block_nr)); if (n) { p = (struct dup_block *) dnode_get(n); - retval = ext2fs_new_block(fs, 0, ctx->block_found_map, + retval = ext2fs_new_block2(fs, 0, ctx->block_found_map, &new_block); if (retval) { cs->errcode = retval; return BLOCK_ABORT; } if (cs->dir && (blockcnt >= 0)) { - retval = ext2fs_set_dir_block(fs->dblist, + retval = ext2fs_set_dir_block2(fs->dblist, cs->dir, new_block, blockcnt); if (retval) { cs->errcode = retval; @@ -653,13 +698,13 @@ static int clone_file_block(ext2_filsys fs, printf("Cloning block %u to %u\n", *block_nr, new_block); #endif - retval = io_channel_read_blk(fs->io, *block_nr, 1, + retval = io_channel_read_blk64(fs->io, *block_nr, 1, cs->buf); if (retval) { cs->errcode = retval; return BLOCK_ABORT; } - retval = io_channel_write_blk(fs->io, new_block, 1, + retval = io_channel_write_blk64(fs->io, new_block, 1, cs->buf); if (retval) { cs->errcode = retval; @@ -667,18 +712,18 @@ static int clone_file_block(ext2_filsys fs, } decrement_badcount(ctx, *block_nr, p); *block_nr = new_block; - ext2fs_mark_block_bitmap(ctx->block_found_map, + ext2fs_mark_block_bitmap2(ctx->block_found_map, new_block); - ext2fs_mark_block_bitmap(fs->block_map, new_block); + ext2fs_mark_block_bitmap2(fs->block_map, new_block); return BLOCK_CHANGED; } else com_err("clone_file_block", 0, - _("internal error; can't find dup_blk for %d\n"), + _("internal error: can't find dup_blk for %llu\n"), *block_nr); } return 0; } - + static int clone_file(e2fsck_t ctx, ext2_ino_t ino, struct dup_inode *dp, char* block_buf) { @@ -686,7 +731,7 @@ static int clone_file(e2fsck_t ctx, ext2_ino_t ino, errcode_t retval; struct clone_struct cs; struct problem_context pctx; - blk_t blk; + blk64_t blk, new_blk; dnode_t *n; struct inode_el *ino_el; struct dup_block *db; @@ -700,13 +745,13 @@ static int clone_file(e2fsck_t ctx, ext2_ino_t ino, if (retval) return retval; - if (ext2fs_test_inode_bitmap(ctx->inode_dir_map, ino)) + if (ext2fs_test_inode_bitmap2(ctx->inode_dir_map, ino)) cs.dir = ino; pctx.ino = ino; pctx.str = "clone_file"; if (ext2fs_inode_has_valid_blocks(&dp->inode)) - pctx.errcode = ext2fs_block_iterate2(fs, ino, 0, block_buf, + pctx.errcode = ext2fs_block_iterate3(fs, ino, 0, block_buf, clone_file_block, &cs); ext2fs_mark_bb_dirty(fs); if (pctx.errcode) { @@ -722,25 +767,43 @@ static int clone_file(e2fsck_t ctx, ext2_ino_t ino, } /* The inode may have changed on disk, so we have to re-read it */ e2fsck_read_inode(ctx, ino, &dp->inode, "clone file EA"); - blk = dp->inode.i_file_acl; - if (blk && (clone_file_block(fs, &dp->inode.i_file_acl, + blk = ext2fs_file_acl_block(&dp->inode); + new_blk = blk; + if (blk && (clone_file_block(fs, &new_blk, BLOCK_COUNT_EXTATTR, 0, 0, &cs) == BLOCK_CHANGED)) { + ext2fs_file_acl_block_set(&dp->inode, new_blk); e2fsck_write_inode(ctx, ino, &dp->inode, "clone file EA"); /* * If we cloned the EA block, find all other inodes * which refered to that EA block, and modify * them to point to the new EA block. */ - n = dict_lookup(&blk_dict, (void *) blk); + n = dict_lookup(&blk_dict, INT_TO_VOIDPTR(blk)); + if (!n) { + com_err("clone_file", 0, + _("internal error: couldn't lookup EA " + "block record for %llu"), blk); + retval = 0; /* OK to stumble on... */ + goto errout; + } db = (struct dup_block *) dnode_get(n); for (ino_el = db->inode_list; ino_el; ino_el = ino_el->next) { if (ino_el->inode == ino) continue; - n = dict_lookup(&ino_dict, (void *) ino_el->inode); + n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(ino_el->inode)); + if (!n) { + com_err("clone_file", 0, + _("internal error: couldn't lookup EA " + "inode record for %u"), + ino_el->inode); + retval = 0; /* OK to stumble on... */ + goto errout; + } di = (struct dup_inode *) dnode_get(n); - if (di->inode.i_file_acl == blk) { - di->inode.i_file_acl = dp->inode.i_file_acl; + if (ext2fs_file_acl_block(&di->inode) == blk) { + ext2fs_file_acl_block_set(&di->inode, + ext2fs_file_acl_block(&dp->inode)); e2fsck_write_inode(ctx, ino_el->inode, &di->inode, "clone file EA"); decrement_badcount(ctx, blk, db); @@ -757,35 +820,35 @@ errout: * This routine returns 1 if a block overlaps with one of the superblocks, * group descriptors, inode bitmaps, or block bitmaps. */ -static int check_if_fs_block(e2fsck_t ctx, blk_t test_block) +static int check_if_fs_block(e2fsck_t ctx, blk64_t test_block) { ext2_filsys fs = ctx->fs; - blk_t block; - int i; - - block = fs->super->s_first_data_block; + blk64_t first_block; + dgrp_t i; + + first_block = fs->super->s_first_data_block; for (i = 0; i < fs->group_desc_count; i++) { - /* Check superblocks/block group descriptros */ + /* Check superblocks/block group descriptors */ if (ext2fs_bg_has_super(fs, i)) { - if (test_block >= block && - (test_block <= block + fs->desc_blocks)) + if (test_block >= first_block && + (test_block <= first_block + fs->desc_blocks)) return 1; } - + /* Check the inode table */ - if ((fs->group_desc[i].bg_inode_table) && - (test_block >= fs->group_desc[i].bg_inode_table) && - (test_block < (fs->group_desc[i].bg_inode_table + + if ((ext2fs_inode_table_loc(fs, i)) && + (test_block >= ext2fs_inode_table_loc(fs, i)) && + (test_block < (ext2fs_inode_table_loc(fs, i) + fs->inode_blocks_per_group))) return 1; /* Check the bitmap blocks */ - if ((test_block == fs->group_desc[i].bg_block_bitmap) || - (test_block == fs->group_desc[i].bg_inode_bitmap)) + if ((test_block == ext2fs_block_bitmap_loc(fs, i)) || + (test_block == ext2fs_inode_bitmap_loc(fs, i))) return 1; - - block += fs->super->s_blocks_per_group; + + first_block += fs->super->s_blocks_per_group; } return 0; }