Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * pass2.c --- check directory structure |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 3 | * |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 4 | * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o |
| 5 | * |
| 6 | * %Begin-Header% |
| 7 | * This file may be redistributed under the terms of the GNU Public |
| 8 | * License. |
| 9 | * %End-Header% |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 10 | * |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 11 | * Pass 2 of e2fsck iterates through all active directory inodes, and |
| 12 | * applies to following tests to each directory entry in the directory |
| 13 | * blocks in the inodes: |
| 14 | * |
| 15 | * - The length of the directory entry (rec_len) should be at |
| 16 | * least 8 bytes, and no more than the remaining space |
| 17 | * left in the directory block. |
| 18 | * - The length of the name in the directory entry (name_len) |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 19 | * should be less than (rec_len - 8). |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 20 | * - The inode number in the directory entry should be within |
| 21 | * legal bounds. |
| 22 | * - The inode number should refer to a in-use inode. |
| 23 | * - The first entry should be '.', and its inode should be |
| 24 | * the inode of the directory. |
| 25 | * - The second entry should be '..'. |
| 26 | * |
| 27 | * To minimize disk seek time, the directory blocks are processed in |
| 28 | * sorted order of block numbers. |
| 29 | * |
| 30 | * Pass 2 also collects the following information: |
| 31 | * - The inode numbers of the subdirectories for each directory. |
| 32 | * |
| 33 | * Pass 2 relies on the following information from previous passes: |
| 34 | * - The directory information collected in pass 1. |
| 35 | * - The inode_used_map bitmap |
| 36 | * - The inode_bad_map bitmap |
| 37 | * - The inode_dir_map bitmap |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 38 | * |
| 39 | * Pass 2 frees the following data structures |
| 40 | * - The inode_bad_map bitmap |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 41 | * - The inode_reg_map bitmap |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 42 | */ |
| 43 | |
Matthias Andree | b969b1b | 2003-12-28 13:04:35 +0100 | [diff] [blame] | 44 | #define _GNU_SOURCE 1 /* get strnlen() */ |
Theodore Ts'o | 48e6e81 | 2003-07-06 00:36:48 -0400 | [diff] [blame] | 45 | #include <string.h> |
| 46 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 47 | #include "e2fsck.h" |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 48 | #include "problem.h" |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 49 | #include "dict.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 50 | |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 51 | #ifdef NO_INLINE_FUNCS |
| 52 | #define _INLINE_ |
| 53 | #else |
| 54 | #define _INLINE_ inline |
| 55 | #endif |
| 56 | |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 57 | /* #define DX_DEBUG */ |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 58 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 59 | /* |
| 60 | * Keeps track of how many times an inode is referenced. |
| 61 | */ |
Theodore Ts'o | 4035f40 | 2001-01-12 20:25:50 +0000 | [diff] [blame] | 62 | static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 63 | static int check_dir_block(ext2_filsys fs, |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 64 | struct ext2_db_entry2 *dir_blocks_info, |
Theodore Ts'o | 54dc7ca | 1998-01-19 14:50:49 +0000 | [diff] [blame] | 65 | void *priv_data); |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 66 | static int allocate_dir_block(e2fsck_t ctx, |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 67 | struct ext2_db_entry2 *dir_blocks_info, |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 68 | char *buf, struct problem_context *pctx); |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 69 | static void clear_htree(e2fsck_t ctx, ext2_ino_t ino); |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 70 | static int htree_depth(struct dx_dir_info *dx_dir, |
| 71 | struct dx_dirblock_info *dx_db); |
Theodore Ts'o | ea1959f | 2002-08-31 02:32:41 -0400 | [diff] [blame] | 72 | static EXT2_QSORT_TYPE special_dir_block_cmp(const void *a, const void *b); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 73 | |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 74 | struct check_dir_struct { |
| 75 | char *buf; |
| 76 | struct problem_context pctx; |
Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 77 | int count, max; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 78 | e2fsck_t ctx; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 79 | }; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 80 | |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 81 | void e2fsck_pass2(e2fsck_t ctx) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 82 | { |
Theodore Ts'o | a474269 | 2001-08-09 04:14:04 -0400 | [diff] [blame] | 83 | struct ext2_super_block *sb = ctx->fs->super; |
| 84 | struct problem_context pctx; |
| 85 | ext2_filsys fs = ctx->fs; |
| 86 | char *buf; |
Theodore Ts'o | 8bf191e | 1997-10-20 01:38:32 +0000 | [diff] [blame] | 87 | #ifdef RESOURCE_TRACK |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 88 | struct resource_track rtrack; |
Theodore Ts'o | 8bf191e | 1997-10-20 01:38:32 +0000 | [diff] [blame] | 89 | #endif |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 90 | struct check_dir_struct cd; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 91 | struct dx_dir_info *dx_dir; |
| 92 | struct dx_dirblock_info *dx_db, *dx_parent; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 93 | unsigned int save_type; |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 94 | int b; |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 95 | int i, depth; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 96 | problem_t code; |
| 97 | int bad_dir; |
| 98 | |
Theodore Ts'o | 6d96b00 | 2007-08-03 20:07:09 -0400 | [diff] [blame] | 99 | init_resource_track(&rtrack, ctx->fs->io); |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 100 | clear_problem_context(&cd.pctx); |
| 101 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 102 | #ifdef MTRACE |
| 103 | mtrace_print("Pass 2"); |
| 104 | #endif |
| 105 | |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 106 | if (!(ctx->options & E2F_OPT_PREEN)) |
| 107 | fix_problem(ctx, PR_2_PASS_HEADER, &cd.pctx); |
| 108 | |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 109 | e2fsck_setup_tdb_icount(ctx, EXT2_ICOUNT_OPT_INCREMENT, |
Theodore Ts'o | 34b9f79 | 2007-04-06 18:43:11 -0400 | [diff] [blame] | 110 | &ctx->inode_count); |
| 111 | if (ctx->inode_count) |
| 112 | cd.pctx.errcode = 0; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 113 | else { |
| 114 | e2fsck_set_bitmap_type(fs, EXT2FS_BMAP64_RBTREE, |
| 115 | "inode_count", &save_type); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 116 | cd.pctx.errcode = ext2fs_create_icount2(fs, |
Theodore Ts'o | 34b9f79 | 2007-04-06 18:43:11 -0400 | [diff] [blame] | 117 | EXT2_ICOUNT_OPT_INCREMENT, |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 118 | 0, ctx->inode_link_info, |
| 119 | &ctx->inode_count); |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 120 | fs->default_bitmap_type = save_type; |
| 121 | } |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 122 | if (cd.pctx.errcode) { |
| 123 | fix_problem(ctx, PR_2_ALLOCATE_ICOUNT, &cd.pctx); |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 124 | ctx->flags |= E2F_FLAG_ABORT; |
| 125 | return; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 126 | } |
Theodore Ts'o | bcf9c5d | 2002-05-21 09:14:17 -0400 | [diff] [blame] | 127 | buf = (char *) e2fsck_allocate_memory(ctx, 2*fs->blocksize, |
Theodore Ts'o | 54dc7ca | 1998-01-19 14:50:49 +0000 | [diff] [blame] | 128 | "directory scan buffer"); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 129 | |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 130 | /* |
| 131 | * Set up the parent pointer for the root directory, if |
| 132 | * present. (If the root directory is not present, we will |
| 133 | * create it in pass 3.) |
| 134 | */ |
Theodore Ts'o | 28db82a | 2007-04-04 22:33:31 -0400 | [diff] [blame] | 135 | (void) e2fsck_dir_info_set_parent(ctx, EXT2_ROOT_INO, EXT2_ROOT_INO); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 136 | |
| 137 | cd.buf = buf; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 138 | cd.ctx = ctx; |
Theodore Ts'o | f75c28d | 1998-08-01 04:18:06 +0000 | [diff] [blame] | 139 | cd.count = 1; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 140 | cd.max = ext2fs_dblist_count2(fs->dblist); |
Theodore Ts'o | f75c28d | 1998-08-01 04:18:06 +0000 | [diff] [blame] | 141 | |
| 142 | if (ctx->progress) |
| 143 | (void) (ctx->progress)(ctx, 2, 0, cd.max); |
Theodore Ts'o | ea1959f | 2002-08-31 02:32:41 -0400 | [diff] [blame] | 144 | |
| 145 | if (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_DIR_INDEX) |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 146 | ext2fs_dblist_sort2(fs->dblist, special_dir_block_cmp); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 147 | |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 148 | cd.pctx.errcode = ext2fs_dblist_iterate2(fs->dblist, check_dir_block, |
| 149 | &cd); |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 150 | if (ctx->flags & E2F_FLAG_SIGNAL_MASK || ctx->flags & E2F_FLAG_RESTART) |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 151 | return; |
Andreas Dilger | 6267ee4 | 2009-05-28 00:39:49 -0600 | [diff] [blame] | 152 | |
| 153 | if (ctx->flags & E2F_FLAG_RESTART_LATER) { |
| 154 | ctx->flags |= E2F_FLAG_RESTART; |
| 155 | return; |
| 156 | } |
| 157 | |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 158 | if (cd.pctx.errcode) { |
| 159 | fix_problem(ctx, PR_2_DBLIST_ITERATE, &cd.pctx); |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 160 | ctx->flags |= E2F_FLAG_ABORT; |
| 161 | return; |
Theodore Ts'o | 7ac02a5 | 1997-06-11 18:32:35 +0000 | [diff] [blame] | 162 | } |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 163 | |
| 164 | #ifdef ENABLE_HTREE |
| 165 | for (i=0; (dx_dir = e2fsck_dx_dir_info_iter(ctx, &i)) != 0;) { |
Theodore Ts'o | 4cae045 | 2002-07-21 14:14:03 -0400 | [diff] [blame] | 166 | if (ctx->flags & E2F_FLAG_SIGNAL_MASK) |
| 167 | return; |
Theodore Ts'o | 62acaa1 | 2002-07-15 16:54:42 -0400 | [diff] [blame] | 168 | if (dx_dir->numblocks == 0) |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 169 | continue; |
| 170 | clear_problem_context(&pctx); |
| 171 | bad_dir = 0; |
| 172 | pctx.dir = dx_dir->ino; |
| 173 | dx_db = dx_dir->dx_block; |
| 174 | if (dx_db->flags & DX_FLAG_REFERENCED) |
| 175 | dx_db->flags |= DX_FLAG_DUP_REF; |
| 176 | else |
| 177 | dx_db->flags |= DX_FLAG_REFERENCED; |
| 178 | /* |
| 179 | * Find all of the first and last leaf blocks, and |
| 180 | * update their parent's min and max hash values |
| 181 | */ |
| 182 | for (b=0, dx_db = dx_dir->dx_block; |
| 183 | b < dx_dir->numblocks; |
| 184 | b++, dx_db++) { |
| 185 | if ((dx_db->type != DX_DIRBLOCK_LEAF) || |
| 186 | !(dx_db->flags & (DX_FLAG_FIRST | DX_FLAG_LAST))) |
| 187 | continue; |
| 188 | dx_parent = &dx_dir->dx_block[dx_db->parent]; |
| 189 | /* |
| 190 | * XXX Make sure dx_parent->min_hash > dx_db->min_hash |
| 191 | */ |
| 192 | if (dx_db->flags & DX_FLAG_FIRST) |
| 193 | dx_parent->min_hash = dx_db->min_hash; |
| 194 | /* |
| 195 | * XXX Make sure dx_parent->max_hash < dx_db->max_hash |
| 196 | */ |
| 197 | if (dx_db->flags & DX_FLAG_LAST) |
| 198 | dx_parent->max_hash = dx_db->max_hash; |
| 199 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 200 | |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 201 | for (b=0, dx_db = dx_dir->dx_block; |
| 202 | b < dx_dir->numblocks; |
| 203 | b++, dx_db++) { |
| 204 | pctx.blkcount = b; |
| 205 | pctx.group = dx_db->parent; |
| 206 | code = 0; |
| 207 | if (!(dx_db->flags & DX_FLAG_FIRST) && |
| 208 | (dx_db->min_hash < dx_db->node_min_hash)) { |
| 209 | pctx.blk = dx_db->min_hash; |
| 210 | pctx.blk2 = dx_db->node_min_hash; |
| 211 | code = PR_2_HTREE_MIN_HASH; |
| 212 | fix_problem(ctx, code, &pctx); |
| 213 | bad_dir++; |
| 214 | } |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 215 | if (dx_db->type == DX_DIRBLOCK_LEAF) { |
| 216 | depth = htree_depth(dx_dir, dx_db); |
| 217 | if (depth != dx_dir->depth) { |
Andreas Dilger | e5e12db | 2008-08-23 21:45:11 -0600 | [diff] [blame] | 218 | pctx.num = dx_dir->depth; |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 219 | code = PR_2_HTREE_BAD_DEPTH; |
| 220 | fix_problem(ctx, code, &pctx); |
| 221 | bad_dir++; |
| 222 | } |
| 223 | } |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 224 | /* |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 225 | * This test doesn't apply for the root block |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 226 | * at block #0 |
| 227 | */ |
| 228 | if (b && |
| 229 | (dx_db->max_hash > dx_db->node_max_hash)) { |
| 230 | pctx.blk = dx_db->max_hash; |
| 231 | pctx.blk2 = dx_db->node_max_hash; |
| 232 | code = PR_2_HTREE_MAX_HASH; |
| 233 | fix_problem(ctx, code, &pctx); |
Theodore Ts'o | 503f9e7 | 2002-06-26 16:52:10 -0400 | [diff] [blame] | 234 | bad_dir++; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 235 | } |
| 236 | if (!(dx_db->flags & DX_FLAG_REFERENCED)) { |
| 237 | code = PR_2_HTREE_NOTREF; |
| 238 | fix_problem(ctx, code, &pctx); |
| 239 | bad_dir++; |
| 240 | } else if (dx_db->flags & DX_FLAG_DUP_REF) { |
| 241 | code = PR_2_HTREE_DUPREF; |
| 242 | fix_problem(ctx, code, &pctx); |
| 243 | bad_dir++; |
| 244 | } |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 245 | } |
| 246 | if (bad_dir && fix_problem(ctx, PR_2_HTREE_CLEAR, &pctx)) { |
| 247 | clear_htree(ctx, dx_dir->ino); |
Theodore Ts'o | 62acaa1 | 2002-07-15 16:54:42 -0400 | [diff] [blame] | 248 | dx_dir->numblocks = 0; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 249 | } |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 250 | } |
Theodore Ts'o | 23f75f6 | 2009-06-15 03:50:07 -0400 | [diff] [blame] | 251 | e2fsck_free_dx_dir_info(ctx); |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 252 | #endif |
Theodore Ts'o | c4e3d3f | 2003-08-01 09:41:07 -0400 | [diff] [blame] | 253 | ext2fs_free_mem(&buf); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 254 | ext2fs_free_dblist(fs->dblist); |
| 255 | |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 256 | if (ctx->inode_bad_map) { |
| 257 | ext2fs_free_inode_bitmap(ctx->inode_bad_map); |
| 258 | ctx->inode_bad_map = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 259 | } |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 260 | if (ctx->inode_reg_map) { |
| 261 | ext2fs_free_inode_bitmap(ctx->inode_reg_map); |
| 262 | ctx->inode_reg_map = 0; |
| 263 | } |
Theodore Ts'o | 890a2f9 | 2015-07-14 22:50:51 -0400 | [diff] [blame] | 264 | if (ctx->encrypted_dirs) { |
| 265 | ext2fs_u32_list_free(ctx->encrypted_dirs); |
| 266 | ctx->encrypted_dirs = 0; |
| 267 | } |
Theodore Ts'o | a474269 | 2001-08-09 04:14:04 -0400 | [diff] [blame] | 268 | |
| 269 | clear_problem_context(&pctx); |
| 270 | if (ctx->large_files) { |
| 271 | if (!(sb->s_feature_ro_compat & |
| 272 | EXT2_FEATURE_RO_COMPAT_LARGE_FILE) && |
| 273 | fix_problem(ctx, PR_2_FEATURE_LARGE_FILES, &pctx)) { |
| 274 | sb->s_feature_ro_compat |= |
| 275 | EXT2_FEATURE_RO_COMPAT_LARGE_FILE; |
Theodore Ts'o | 0cfce7f | 2007-10-06 12:37:08 -0400 | [diff] [blame] | 276 | fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY; |
Theodore Ts'o | a474269 | 2001-08-09 04:14:04 -0400 | [diff] [blame] | 277 | ext2fs_mark_super_dirty(fs); |
| 278 | } |
| 279 | if (sb->s_rev_level == EXT2_GOOD_OLD_REV && |
| 280 | fix_problem(ctx, PR_1_FS_REV_LEVEL, &pctx)) { |
| 281 | ext2fs_update_dynamic_rev(fs); |
| 282 | ext2fs_mark_super_dirty(fs); |
| 283 | } |
Theodore Ts'o | a474269 | 2001-08-09 04:14:04 -0400 | [diff] [blame] | 284 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 285 | |
Ken Chen | 9facd07 | 2009-05-28 09:55:10 -0400 | [diff] [blame] | 286 | print_resource_track(ctx, _("Pass 2"), &rtrack, fs->io); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 289 | #define MAX_DEPTH 32000 |
| 290 | static int htree_depth(struct dx_dir_info *dx_dir, |
| 291 | struct dx_dirblock_info *dx_db) |
| 292 | { |
| 293 | int depth = 0; |
| 294 | |
| 295 | while (dx_db->type != DX_DIRBLOCK_ROOT && depth < MAX_DEPTH) { |
| 296 | dx_db = &dx_dir->dx_block[dx_db->parent]; |
| 297 | depth++; |
| 298 | } |
| 299 | return depth; |
| 300 | } |
| 301 | |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 302 | static int dict_de_cmp(const void *a, const void *b) |
| 303 | { |
Theodore Ts'o | 520ead3 | 2003-04-19 13:48:27 -0400 | [diff] [blame] | 304 | const struct ext2_dir_entry *de_a, *de_b; |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 305 | int a_len, b_len; |
| 306 | |
Theodore Ts'o | 520ead3 | 2003-04-19 13:48:27 -0400 | [diff] [blame] | 307 | de_a = (const struct ext2_dir_entry *) a; |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 308 | a_len = de_a->name_len & 0xFF; |
Theodore Ts'o | 520ead3 | 2003-04-19 13:48:27 -0400 | [diff] [blame] | 309 | de_b = (const struct ext2_dir_entry *) b; |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 310 | b_len = de_b->name_len & 0xFF; |
| 311 | |
| 312 | if (a_len != b_len) |
| 313 | return (a_len - b_len); |
| 314 | |
Theodore Ts'o | 890a2f9 | 2015-07-14 22:50:51 -0400 | [diff] [blame] | 315 | return memcmp(de_a->name, de_b->name, a_len); |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 316 | } |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 317 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 318 | /* |
Theodore Ts'o | ea1959f | 2002-08-31 02:32:41 -0400 | [diff] [blame] | 319 | * This is special sort function that makes sure that directory blocks |
| 320 | * with a dirblock of zero are sorted to the beginning of the list. |
| 321 | * This guarantees that the root node of the htree directories are |
| 322 | * processed first, so we know what hash version to use. |
| 323 | */ |
| 324 | static EXT2_QSORT_TYPE special_dir_block_cmp(const void *a, const void *b) |
| 325 | { |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 326 | const struct ext2_db_entry2 *db_a = |
| 327 | (const struct ext2_db_entry2 *) a; |
| 328 | const struct ext2_db_entry2 *db_b = |
| 329 | (const struct ext2_db_entry2 *) b; |
Theodore Ts'o | ea1959f | 2002-08-31 02:32:41 -0400 | [diff] [blame] | 330 | |
| 331 | if (db_a->blockcnt && !db_b->blockcnt) |
| 332 | return 1; |
| 333 | |
| 334 | if (!db_a->blockcnt && db_b->blockcnt) |
| 335 | return -1; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 336 | |
Theodore Ts'o | ea1959f | 2002-08-31 02:32:41 -0400 | [diff] [blame] | 337 | if (db_a->blk != db_b->blk) |
| 338 | return (int) (db_a->blk - db_b->blk); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 339 | |
Theodore Ts'o | ea1959f | 2002-08-31 02:32:41 -0400 | [diff] [blame] | 340 | if (db_a->ino != db_b->ino) |
| 341 | return (int) (db_a->ino - db_b->ino); |
| 342 | |
| 343 | return (int) (db_a->blockcnt - db_b->blockcnt); |
| 344 | } |
| 345 | |
| 346 | |
| 347 | /* |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 348 | * Make sure the first entry in the directory is '.', and that the |
| 349 | * directory entry is sane. |
| 350 | */ |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 351 | static int check_dot(e2fsck_t ctx, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 352 | struct ext2_dir_entry *dirent, |
Theodore Ts'o | 86c627e | 2001-01-11 15:12:14 +0000 | [diff] [blame] | 353 | ext2_ino_t ino, struct problem_context *pctx) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 354 | { |
| 355 | struct ext2_dir_entry *nextdir; |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 356 | unsigned int rec_len, new_len; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 357 | int status = 0; |
| 358 | int created = 0; |
| 359 | problem_t problem = 0; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 360 | |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 361 | if (!dirent->inode) |
| 362 | problem = PR_2_MISSING_DOT; |
Theodore Ts'o | b6f7983 | 1998-03-09 13:10:37 +0000 | [diff] [blame] | 363 | else if (((dirent->name_len & 0xFF) != 1) || |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 364 | (dirent->name[0] != '.')) |
| 365 | problem = PR_2_1ST_NOT_DOT; |
| 366 | else if (dirent->name[1] != '\0') |
| 367 | problem = PR_2_DOT_NULL_TERM; |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 368 | |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 369 | (void) ext2fs_get_rec_len(ctx->fs, dirent, &rec_len); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 370 | if (problem) { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 371 | if (fix_problem(ctx, problem, pctx)) { |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 372 | if (rec_len < 12) |
| 373 | rec_len = dirent->rec_len = 12; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 374 | dirent->inode = ino; |
| 375 | dirent->name_len = 1; |
| 376 | dirent->name[0] = '.'; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 377 | dirent->name[1] = '\0'; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 378 | status = 1; |
| 379 | created = 1; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 380 | } |
| 381 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 382 | if (dirent->inode != ino) { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 383 | if (fix_problem(ctx, PR_2_BAD_INODE_DOT, pctx)) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 384 | dirent->inode = ino; |
| 385 | status = 1; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 386 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 387 | } |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 388 | if (rec_len > 12) { |
| 389 | new_len = rec_len - 12; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 390 | if (new_len > 12) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 391 | if (created || |
Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 392 | fix_problem(ctx, PR_2_SPLIT_DOT, pctx)) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 393 | nextdir = (struct ext2_dir_entry *) |
| 394 | ((char *) dirent + 12); |
| 395 | dirent->rec_len = 12; |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 396 | (void) ext2fs_set_rec_len(ctx->fs, new_len, |
| 397 | nextdir); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 398 | nextdir->inode = 0; |
| 399 | nextdir->name_len = 0; |
| 400 | status = 1; |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | return status; |
| 405 | } |
| 406 | |
| 407 | /* |
| 408 | * Make sure the second entry in the directory is '..', and that the |
| 409 | * directory entry is sane. We do not check the inode number of '..' |
| 410 | * here; this gets done in pass 3. |
| 411 | */ |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 412 | static int check_dotdot(e2fsck_t ctx, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 413 | struct ext2_dir_entry *dirent, |
Theodore Ts'o | 28db82a | 2007-04-04 22:33:31 -0400 | [diff] [blame] | 414 | ext2_ino_t ino, struct problem_context *pctx) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 415 | { |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 416 | problem_t problem = 0; |
| 417 | unsigned int rec_len; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 418 | |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 419 | if (!dirent->inode) |
| 420 | problem = PR_2_MISSING_DOT_DOT; |
Theodore Ts'o | b6f7983 | 1998-03-09 13:10:37 +0000 | [diff] [blame] | 421 | else if (((dirent->name_len & 0xFF) != 2) || |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 422 | (dirent->name[0] != '.') || |
| 423 | (dirent->name[1] != '.')) |
| 424 | problem = PR_2_2ND_NOT_DOT_DOT; |
| 425 | else if (dirent->name[2] != '\0') |
| 426 | problem = PR_2_DOT_DOT_NULL_TERM; |
| 427 | |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 428 | (void) ext2fs_get_rec_len(ctx->fs, dirent, &rec_len); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 429 | if (problem) { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 430 | if (fix_problem(ctx, problem, pctx)) { |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 431 | if (rec_len < 12) |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 432 | dirent->rec_len = 12; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 433 | /* |
| 434 | * Note: we don't have the parent inode just |
| 435 | * yet, so we will fill it in with the root |
| 436 | * inode. This will get fixed in pass 3. |
| 437 | */ |
| 438 | dirent->inode = EXT2_ROOT_INO; |
| 439 | dirent->name_len = 2; |
| 440 | dirent->name[0] = '.'; |
| 441 | dirent->name[1] = '.'; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 442 | dirent->name[2] = '\0'; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 443 | return 1; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 444 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 445 | return 0; |
| 446 | } |
Theodore Ts'o | 28db82a | 2007-04-04 22:33:31 -0400 | [diff] [blame] | 447 | if (e2fsck_dir_info_set_dotdot(ctx, ino, dirent->inode)) { |
| 448 | fix_problem(ctx, PR_2_NO_DIRINFO, pctx); |
| 449 | return -1; |
| 450 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | /* |
| 455 | * Check to make sure a directory entry doesn't contain any illegal |
| 456 | * characters. |
| 457 | */ |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 458 | static int check_name(e2fsck_t ctx, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 459 | struct ext2_dir_entry *dirent, |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 460 | struct problem_context *pctx) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 461 | { |
| 462 | int i; |
| 463 | int fixup = -1; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 464 | int ret = 0; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 465 | |
Theodore Ts'o | b6f7983 | 1998-03-09 13:10:37 +0000 | [diff] [blame] | 466 | for ( i = 0; i < (dirent->name_len & 0xFF); i++) { |
Theodore Ts'o | 638c15d | 2015-10-25 22:19:04 -0400 | [diff] [blame] | 467 | if (dirent->name[i] != '/' && dirent->name[i] != '\0') |
| 468 | continue; |
| 469 | if (fixup < 0) |
| 470 | fixup = fix_problem(ctx, PR_2_BAD_NAME, pctx); |
| 471 | if (fixup == 0) |
| 472 | return 0; |
| 473 | dirent->name[i] = '.'; |
| 474 | ret = 1; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 475 | } |
| 476 | return ret; |
| 477 | } |
| 478 | |
Theodore Ts'o | 638c15d | 2015-10-25 22:19:04 -0400 | [diff] [blame] | 479 | static int encrypted_check_name(e2fsck_t ctx, |
| 480 | struct ext2_dir_entry *dirent, |
| 481 | struct problem_context *pctx) |
| 482 | { |
| 483 | if ((dirent->name_len & 0xff) < EXT4_CRYPTO_BLOCK_SIZE) { |
| 484 | if (fix_problem(ctx, PR_2_BAD_ENCRYPTED_NAME, pctx)) { |
| 485 | dirent->inode = 0; |
| 486 | return 1; |
| 487 | } |
| 488 | ext2fs_unmark_valid(ctx->fs); |
| 489 | } |
| 490 | return 0; |
| 491 | } |
| 492 | |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 493 | /* |
| 494 | * Check the directory filetype (if present) |
| 495 | */ |
| 496 | static _INLINE_ int check_filetype(e2fsck_t ctx, |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 497 | struct ext2_dir_entry *dirent, |
| 498 | ext2_ino_t dir_ino EXT2FS_ATTR((unused)), |
| 499 | struct problem_context *pctx) |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 500 | { |
| 501 | int filetype = dirent->name_len >> 8; |
| 502 | int should_be = EXT2_FT_UNKNOWN; |
| 503 | struct ext2_inode inode; |
| 504 | |
| 505 | if (!(ctx->fs->super->s_feature_incompat & |
Theodore Ts'o | 7847c1d | 1999-10-22 15:11:42 +0000 | [diff] [blame] | 506 | EXT2_FEATURE_INCOMPAT_FILETYPE)) { |
| 507 | if (filetype == 0 || |
| 508 | !fix_problem(ctx, PR_2_CLEAR_FILETYPE, pctx)) |
| 509 | return 0; |
| 510 | dirent->name_len = dirent->name_len & 0xFF; |
| 511 | return 1; |
| 512 | } |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 513 | |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 514 | if (ext2fs_test_inode_bitmap2(ctx->inode_dir_map, dirent->inode)) { |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 515 | should_be = EXT2_FT_DIR; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 516 | } else if (ext2fs_test_inode_bitmap2(ctx->inode_reg_map, |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 517 | dirent->inode)) { |
| 518 | should_be = EXT2_FT_REG_FILE; |
| 519 | } else if (ctx->inode_bad_map && |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 520 | ext2fs_test_inode_bitmap2(ctx->inode_bad_map, |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 521 | dirent->inode)) |
| 522 | should_be = 0; |
| 523 | else { |
| 524 | e2fsck_read_inode(ctx, dirent->inode, &inode, |
| 525 | "check_filetype"); |
Theodore Ts'o | 6fdc7a3 | 1999-11-10 13:34:40 +0000 | [diff] [blame] | 526 | should_be = ext2_file_type(inode.i_mode); |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 527 | } |
| 528 | if (filetype == should_be) |
| 529 | return 0; |
| 530 | pctx->num = should_be; |
| 531 | |
| 532 | if (fix_problem(ctx, filetype ? PR_2_BAD_FILETYPE : PR_2_SET_FILETYPE, |
| 533 | pctx) == 0) |
| 534 | return 0; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 535 | |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 536 | dirent->name_len = (dirent->name_len & 0xFF) | should_be << 8; |
| 537 | return 1; |
| 538 | } |
| 539 | |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 540 | #ifdef ENABLE_HTREE |
| 541 | static void parse_int_node(ext2_filsys fs, |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 542 | struct ext2_db_entry2 *db, |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 543 | struct check_dir_struct *cd, |
| 544 | struct dx_dir_info *dx_dir, |
| 545 | char *block_buf) |
| 546 | { |
| 547 | struct ext2_dx_root_info *root; |
| 548 | struct ext2_dx_entry *ent; |
| 549 | struct ext2_dx_countlimit *limit; |
| 550 | struct dx_dirblock_info *dx_db; |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 551 | int i, expect_limit, count; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 552 | blk_t blk; |
| 553 | ext2_dirhash_t min_hash = 0xffffffff; |
| 554 | ext2_dirhash_t max_hash = 0; |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 555 | ext2_dirhash_t hash = 0, prev_hash; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 556 | |
| 557 | if (db->blockcnt == 0) { |
| 558 | root = (struct ext2_dx_root_info *) (block_buf + 24); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 559 | |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 560 | #ifdef DX_DEBUG |
| 561 | printf("Root node dump:\n"); |
Takashi Sato | 8deb80a | 2006-03-18 21:43:46 -0500 | [diff] [blame] | 562 | printf("\t Reserved zero: %u\n", root->reserved_zero); |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 563 | printf("\t Hash Version: %d\n", root->hash_version); |
| 564 | printf("\t Info length: %d\n", root->info_length); |
| 565 | printf("\t Indirect levels: %d\n", root->indirect_levels); |
| 566 | printf("\t Flags: %d\n", root->unused_flags); |
| 567 | #endif |
| 568 | |
| 569 | ent = (struct ext2_dx_entry *) (block_buf + 24 + root->info_length); |
| 570 | } else { |
| 571 | ent = (struct ext2_dx_entry *) (block_buf+8); |
| 572 | } |
| 573 | limit = (struct ext2_dx_countlimit *) ent; |
| 574 | |
| 575 | #ifdef DX_DEBUG |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 576 | printf("Number of entries (count): %d\n", |
Theodore Ts'o | 8132d84 | 2002-10-02 22:07:17 -0400 | [diff] [blame] | 577 | ext2fs_le16_to_cpu(limit->count)); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 578 | printf("Number of entries (limit): %d\n", |
Theodore Ts'o | 8132d84 | 2002-10-02 22:07:17 -0400 | [diff] [blame] | 579 | ext2fs_le16_to_cpu(limit->limit)); |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 580 | #endif |
| 581 | |
Theodore Ts'o | 8132d84 | 2002-10-02 22:07:17 -0400 | [diff] [blame] | 582 | count = ext2fs_le16_to_cpu(limit->count); |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 583 | expect_limit = (fs->blocksize - ((char *) ent - block_buf)) / |
| 584 | sizeof(struct ext2_dx_entry); |
Theodore Ts'o | 8132d84 | 2002-10-02 22:07:17 -0400 | [diff] [blame] | 585 | if (ext2fs_le16_to_cpu(limit->limit) != expect_limit) { |
| 586 | cd->pctx.num = ext2fs_le16_to_cpu(limit->limit); |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 587 | if (fix_problem(cd->ctx, PR_2_HTREE_BAD_LIMIT, &cd->pctx)) |
| 588 | goto clear_and_exit; |
| 589 | } |
Theodore Ts'o | 8132d84 | 2002-10-02 22:07:17 -0400 | [diff] [blame] | 590 | if (count > expect_limit) { |
| 591 | cd->pctx.num = count; |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 592 | if (fix_problem(cd->ctx, PR_2_HTREE_BAD_COUNT, &cd->pctx)) |
| 593 | goto clear_and_exit; |
| 594 | count = expect_limit; |
| 595 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 596 | |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 597 | for (i=0; i < count; i++) { |
| 598 | prev_hash = hash; |
Theodore Ts'o | 8132d84 | 2002-10-02 22:07:17 -0400 | [diff] [blame] | 599 | hash = i ? (ext2fs_le32_to_cpu(ent[i].hash) & ~1) : 0; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 600 | #ifdef DX_DEBUG |
Takashi Sato | 8deb80a | 2006-03-18 21:43:46 -0500 | [diff] [blame] | 601 | printf("Entry #%d: Hash 0x%08x, block %u\n", i, |
Theodore Ts'o | 8132d84 | 2002-10-02 22:07:17 -0400 | [diff] [blame] | 602 | hash, ext2fs_le32_to_cpu(ent[i].block)); |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 603 | #endif |
Theodore Ts'o | 8132d84 | 2002-10-02 22:07:17 -0400 | [diff] [blame] | 604 | blk = ext2fs_le32_to_cpu(ent[i].block) & 0x0ffffff; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 605 | /* Check to make sure the block is valid */ |
Theodore Ts'o | 977ac87 | 2006-10-21 23:27:03 -0400 | [diff] [blame] | 606 | if (blk >= (blk_t) dx_dir->numblocks) { |
Theodore Ts'o | b7a0056 | 2002-07-20 00:28:07 -0400 | [diff] [blame] | 607 | cd->pctx.blk = blk; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 608 | if (fix_problem(cd->ctx, PR_2_HTREE_BADBLK, |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 609 | &cd->pctx)) |
| 610 | goto clear_and_exit; |
Theodore Ts'o | 977ac87 | 2006-10-21 23:27:03 -0400 | [diff] [blame] | 611 | continue; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 612 | } |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 613 | if (hash < prev_hash && |
| 614 | fix_problem(cd->ctx, PR_2_HTREE_HASH_ORDER, &cd->pctx)) |
| 615 | goto clear_and_exit; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 616 | dx_db = &dx_dir->dx_block[blk]; |
| 617 | if (dx_db->flags & DX_FLAG_REFERENCED) { |
| 618 | dx_db->flags |= DX_FLAG_DUP_REF; |
| 619 | } else { |
| 620 | dx_db->flags |= DX_FLAG_REFERENCED; |
| 621 | dx_db->parent = db->blockcnt; |
| 622 | } |
| 623 | if (hash < min_hash) |
| 624 | min_hash = hash; |
| 625 | if (hash > max_hash) |
| 626 | max_hash = hash; |
| 627 | dx_db->node_min_hash = hash; |
Theodore Ts'o | 8132d84 | 2002-10-02 22:07:17 -0400 | [diff] [blame] | 628 | if ((i+1) < count) |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 629 | dx_db->node_max_hash = |
Theodore Ts'o | 8132d84 | 2002-10-02 22:07:17 -0400 | [diff] [blame] | 630 | ext2fs_le32_to_cpu(ent[i+1].hash) & ~1; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 631 | else { |
| 632 | dx_db->node_max_hash = 0xfffffffe; |
| 633 | dx_db->flags |= DX_FLAG_LAST; |
| 634 | } |
| 635 | if (i == 0) |
| 636 | dx_db->flags |= DX_FLAG_FIRST; |
| 637 | } |
| 638 | #ifdef DX_DEBUG |
| 639 | printf("Blockcnt = %d, min hash 0x%08x, max hash 0x%08x\n", |
| 640 | db->blockcnt, min_hash, max_hash); |
| 641 | #endif |
| 642 | dx_db = &dx_dir->dx_block[db->blockcnt]; |
| 643 | dx_db->min_hash = min_hash; |
| 644 | dx_db->max_hash = max_hash; |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 645 | return; |
| 646 | |
| 647 | clear_and_exit: |
| 648 | clear_htree(cd->ctx, cd->pctx.ino); |
| 649 | dx_dir->numblocks = 0; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 650 | } |
| 651 | #endif /* ENABLE_HTREE */ |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 652 | |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 653 | /* |
| 654 | * Given a busted directory, try to salvage it somehow. |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 655 | * |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 656 | */ |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 657 | static void salvage_directory(ext2_filsys fs, |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 658 | struct ext2_dir_entry *dirent, |
| 659 | struct ext2_dir_entry *prev, |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 660 | unsigned int *offset) |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 661 | { |
| 662 | char *cp = (char *) dirent; |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 663 | int left; |
| 664 | unsigned int rec_len, prev_rec_len; |
Theodore Ts'o | 642935c | 2006-11-14 23:38:17 -0500 | [diff] [blame] | 665 | unsigned int name_len = dirent->name_len & 0xFF; |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 666 | |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 667 | (void) ext2fs_get_rec_len(fs, dirent, &rec_len); |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 668 | left = fs->blocksize - *offset - rec_len; |
| 669 | |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 670 | /* |
| 671 | * Special case of directory entry of size 8: copy what's left |
| 672 | * of the directory block up to cover up the invalid hole. |
| 673 | */ |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 674 | if ((left >= 12) && (rec_len == 8)) { |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 675 | memmove(cp, cp+8, left); |
| 676 | memset(cp + left, 0, 8); |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 677 | return; |
| 678 | } |
| 679 | /* |
| 680 | * If the directory entry overruns the end of the directory |
| 681 | * block, and the name is small enough to fit, then adjust the |
| 682 | * record length. |
| 683 | */ |
| 684 | if ((left < 0) && |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 685 | ((int) rec_len + left > 8) && |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 686 | ((int) name_len + 8 <= (int) rec_len + left) && |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 687 | dirent->inode <= fs->super->s_inodes_count && |
| 688 | strnlen(dirent->name, name_len) == name_len) { |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 689 | (void) ext2fs_set_rec_len(fs, (int) rec_len + left, dirent); |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 690 | return; |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 691 | } |
| 692 | /* |
Kalpak Shah | 575307c | 2007-07-09 13:05:45 -0400 | [diff] [blame] | 693 | * If the record length of the directory entry is a multiple |
| 694 | * of four, and not too big, such that it is valid, let the |
| 695 | * previous directory entry absorb the invalid one. |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 696 | */ |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 697 | if (prev && rec_len && (rec_len % 4) == 0 && |
| 698 | (*offset + rec_len <= fs->blocksize)) { |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 699 | (void) ext2fs_get_rec_len(fs, prev, &prev_rec_len); |
| 700 | prev_rec_len += rec_len; |
| 701 | (void) ext2fs_set_rec_len(fs, prev_rec_len, prev); |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 702 | *offset += rec_len; |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 703 | return; |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 704 | } |
| 705 | /* |
| 706 | * Default salvage method --- kill all of the directory |
| 707 | * entries for the rest of the block. We will either try to |
| 708 | * absorb it into the previous directory entry, or create a |
| 709 | * new empty directory entry the rest of the directory block. |
| 710 | */ |
| 711 | if (prev) { |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 712 | (void) ext2fs_get_rec_len(fs, prev, &prev_rec_len); |
| 713 | prev_rec_len += fs->blocksize - *offset; |
| 714 | (void) ext2fs_set_rec_len(fs, prev_rec_len, prev); |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 715 | *offset = fs->blocksize; |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 716 | } else { |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 717 | rec_len = fs->blocksize - *offset; |
| 718 | (void) ext2fs_set_rec_len(fs, rec_len, dirent); |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 719 | dirent->name_len = 0; |
| 720 | dirent->inode = 0; |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 721 | } |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 722 | } |
| 723 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 724 | static int check_dir_block(ext2_filsys fs, |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 725 | struct ext2_db_entry2 *db, |
Theodore Ts'o | 54dc7ca | 1998-01-19 14:50:49 +0000 | [diff] [blame] | 726 | void *priv_data) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 727 | { |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 728 | struct dx_dir_info *dx_dir; |
| 729 | #ifdef ENABLE_HTREE |
| 730 | struct dx_dirblock_info *dx_db = 0; |
| 731 | #endif /* ENABLE_HTREE */ |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 732 | struct ext2_dir_entry *dirent, *prev; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 733 | ext2_dirhash_t hash; |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 734 | unsigned int offset = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 735 | int dir_modified = 0; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 736 | int dot_state; |
Theodore Ts'o | 03fa6f8 | 2008-11-16 10:03:00 -0500 | [diff] [blame] | 737 | unsigned int rec_len; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 738 | blk64_t block_nr = db->blk; |
Theodore Ts'o | 86c627e | 2001-01-11 15:12:14 +0000 | [diff] [blame] | 739 | ext2_ino_t ino = db->ino; |
Theodore Ts'o | 28db82a | 2007-04-04 22:33:31 -0400 | [diff] [blame] | 740 | ext2_ino_t subdir_parent; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 741 | __u16 links; |
Theodore Ts'o | 54dc7ca | 1998-01-19 14:50:49 +0000 | [diff] [blame] | 742 | struct check_dir_struct *cd; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 743 | char *buf; |
| 744 | e2fsck_t ctx; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 745 | problem_t problem; |
Theodore Ts'o | ea1959f | 2002-08-31 02:32:41 -0400 | [diff] [blame] | 746 | struct ext2_dx_root_info *root; |
Theodore Ts'o | e8254bf | 2002-09-29 19:30:28 -0400 | [diff] [blame] | 747 | struct ext2_dx_countlimit *limit; |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 748 | static dict_t de_dict; |
| 749 | struct problem_context pctx; |
| 750 | int dups_found = 0; |
Theodore Ts'o | 890a2f9 | 2015-07-14 22:50:51 -0400 | [diff] [blame] | 751 | int encrypted = 0; |
Theodore Ts'o | 28db82a | 2007-04-04 22:33:31 -0400 | [diff] [blame] | 752 | int ret; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 753 | |
Theodore Ts'o | 54dc7ca | 1998-01-19 14:50:49 +0000 | [diff] [blame] | 754 | cd = (struct check_dir_struct *) priv_data; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 755 | buf = cd->buf; |
| 756 | ctx = cd->ctx; |
Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 757 | |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 758 | if (ctx->flags & E2F_FLAG_SIGNAL_MASK || ctx->flags & E2F_FLAG_RESTART) |
Theodore Ts'o | 4cae045 | 2002-07-21 14:14:03 -0400 | [diff] [blame] | 759 | return DIRENT_ABORT; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 760 | |
Theodore Ts'o | 4cae045 | 2002-07-21 14:14:03 -0400 | [diff] [blame] | 761 | if (ctx->progress && (ctx->progress)(ctx, 2, cd->count++, cd->max)) |
| 762 | return DIRENT_ABORT; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 763 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 764 | /* |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 765 | * Make sure the inode is still in use (could have been |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 766 | * deleted in the duplicate/bad blocks pass. |
| 767 | */ |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 768 | if (!(ext2fs_test_inode_bitmap2(ctx->inode_used_map, ino))) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 769 | return 0; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 770 | |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 771 | cd->pctx.ino = ino; |
| 772 | cd->pctx.blk = block_nr; |
| 773 | cd->pctx.blkcount = db->blockcnt; |
| 774 | cd->pctx.ino2 = 0; |
| 775 | cd->pctx.dirent = 0; |
| 776 | cd->pctx.num = 0; |
| 777 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 778 | if (db->blk == 0) { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 779 | if (allocate_dir_block(ctx, db, buf, &cd->pctx)) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 780 | return 0; |
| 781 | block_nr = db->blk; |
| 782 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 783 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 784 | if (db->blockcnt) |
| 785 | dot_state = 2; |
| 786 | else |
| 787 | dot_state = 0; |
| 788 | |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 789 | if (ctx->dirs_to_hash && |
| 790 | ext2fs_u32_list_test(ctx->dirs_to_hash, ino)) |
| 791 | dups_found++; |
| 792 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 793 | #if 0 |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 794 | printf("In process_dir_block block %lu, #%d, inode %lu\n", block_nr, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 795 | db->blockcnt, ino); |
| 796 | #endif |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 797 | |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 798 | ehandler_operation(_("reading directory block")); |
| 799 | cd->pctx.errcode = ext2fs_read_dir_block3(fs, block_nr, buf, 0); |
Theodore Ts'o | e94bc63 | 2007-04-14 09:29:02 -0400 | [diff] [blame] | 800 | ehandler_operation(0); |
Theodore Ts'o | b9852cd | 2001-05-05 05:14:59 +0000 | [diff] [blame] | 801 | if (cd->pctx.errcode == EXT2_ET_DIR_CORRUPTED) |
| 802 | cd->pctx.errcode = 0; /* We'll handle this ourselves */ |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 803 | if (cd->pctx.errcode) { |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 804 | if (!fix_problem(ctx, PR_2_READ_DIRBLOCK, &cd->pctx)) { |
| 805 | ctx->flags |= E2F_FLAG_ABORT; |
| 806 | return DIRENT_ABORT; |
| 807 | } |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 808 | memset(buf, 0, fs->blocksize); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 809 | } |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 810 | #ifdef ENABLE_HTREE |
| 811 | dx_dir = e2fsck_get_dx_dir_info(ctx, ino); |
Theodore Ts'o | 62acaa1 | 2002-07-15 16:54:42 -0400 | [diff] [blame] | 812 | if (dx_dir && dx_dir->numblocks) { |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 813 | if (db->blockcnt >= dx_dir->numblocks) { |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 814 | if (fix_problem(ctx, PR_2_UNEXPECTED_HTREE_BLOCK, |
Theodore Ts'o | d45edec | 2008-03-12 16:10:48 -0400 | [diff] [blame] | 815 | &pctx)) { |
| 816 | clear_htree(ctx, ino); |
| 817 | dx_dir->numblocks = 0; |
| 818 | dx_db = 0; |
| 819 | goto out_htree; |
| 820 | } |
| 821 | fatal_error(ctx, _("Can not continue.")); |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 822 | } |
| 823 | dx_db = &dx_dir->dx_block[db->blockcnt]; |
| 824 | dx_db->type = DX_DIRBLOCK_LEAF; |
| 825 | dx_db->phys = block_nr; |
| 826 | dx_db->min_hash = ~0; |
| 827 | dx_db->max_hash = 0; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 828 | |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 829 | dirent = (struct ext2_dir_entry *) buf; |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 830 | (void) ext2fs_get_rec_len(fs, dirent, &rec_len); |
Theodore Ts'o | e8254bf | 2002-09-29 19:30:28 -0400 | [diff] [blame] | 831 | limit = (struct ext2_dx_countlimit *) (buf+8); |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 832 | if (db->blockcnt == 0) { |
Theodore Ts'o | ea1959f | 2002-08-31 02:32:41 -0400 | [diff] [blame] | 833 | root = (struct ext2_dx_root_info *) (buf + 24); |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 834 | dx_db->type = DX_DIRBLOCK_ROOT; |
| 835 | dx_db->flags |= DX_FLAG_FIRST | DX_FLAG_LAST; |
Theodore Ts'o | ea1959f | 2002-08-31 02:32:41 -0400 | [diff] [blame] | 836 | if ((root->reserved_zero || |
| 837 | root->info_length < 8 || |
| 838 | root->indirect_levels > 1) && |
| 839 | fix_problem(ctx, PR_2_HTREE_BAD_ROOT, &cd->pctx)) { |
| 840 | clear_htree(ctx, ino); |
| 841 | dx_dir->numblocks = 0; |
| 842 | dx_db = 0; |
Theodore Ts'o | f77704e | 2006-11-11 22:32:35 -0500 | [diff] [blame] | 843 | } |
Theodore Ts'o | ea1959f | 2002-08-31 02:32:41 -0400 | [diff] [blame] | 844 | dx_dir->hashversion = root->hash_version; |
Theodore Ts'o | f77704e | 2006-11-11 22:32:35 -0500 | [diff] [blame] | 845 | if ((dx_dir->hashversion <= EXT2_HASH_TEA) && |
| 846 | (fs->super->s_flags & EXT2_FLAGS_UNSIGNED_HASH)) |
| 847 | dx_dir->hashversion += 3; |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 848 | dx_dir->depth = root->indirect_levels + 1; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 849 | } else if ((dirent->inode == 0) && |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 850 | (rec_len == fs->blocksize) && |
Theodore Ts'o | e8254bf | 2002-09-29 19:30:28 -0400 | [diff] [blame] | 851 | (dirent->name_len == 0) && |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 852 | (ext2fs_le16_to_cpu(limit->limit) == |
| 853 | ((fs->blocksize-8) / |
Theodore Ts'o | 8132d84 | 2002-10-02 22:07:17 -0400 | [diff] [blame] | 854 | sizeof(struct ext2_dx_entry)))) |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 855 | dx_db->type = DX_DIRBLOCK_NODE; |
| 856 | } |
Theodore Ts'o | d45edec | 2008-03-12 16:10:48 -0400 | [diff] [blame] | 857 | out_htree: |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 858 | #endif /* ENABLE_HTREE */ |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 859 | |
Theodore Ts'o | 890a2f9 | 2015-07-14 22:50:51 -0400 | [diff] [blame] | 860 | if (ctx->encrypted_dirs) |
| 861 | encrypted = ext2fs_u32_list_test(ctx->encrypted_dirs, ino); |
| 862 | |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 863 | dict_init(&de_dict, DICTCOUNT_T_MAX, dict_de_cmp); |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 864 | prev = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 865 | do { |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 866 | dgrp_t group; |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 867 | ext2_ino_t first_unused_inode; |
| 868 | |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 869 | problem = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 870 | dirent = (struct ext2_dir_entry *) (buf + offset); |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 871 | (void) ext2fs_get_rec_len(fs, dirent, &rec_len); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 872 | cd->pctx.dirent = dirent; |
| 873 | cd->pctx.num = offset; |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 874 | if (((offset + rec_len) > fs->blocksize) || |
| 875 | (rec_len < 12) || |
| 876 | ((rec_len % 4) != 0) || |
Theodore Ts'o | 03fa6f8 | 2008-11-16 10:03:00 -0500 | [diff] [blame] | 877 | (((dirent->name_len & (unsigned) 0xFF)+8) > rec_len)) { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 878 | if (fix_problem(ctx, PR_2_DIR_CORRUPTED, &cd->pctx)) { |
Theodore Ts'o | ad4fa46 | 2002-09-30 11:19:19 -0400 | [diff] [blame] | 879 | salvage_directory(fs, dirent, prev, &offset); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 880 | dir_modified++; |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 881 | continue; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 882 | } else |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 883 | goto abort_free_dict; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 884 | } |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 885 | |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 886 | if (dot_state == 0) { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 887 | if (check_dot(ctx, dirent, ino, &cd->pctx)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 888 | dir_modified++; |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 889 | } else if (dot_state == 1) { |
Theodore Ts'o | 28db82a | 2007-04-04 22:33:31 -0400 | [diff] [blame] | 890 | ret = check_dotdot(ctx, dirent, ino, &cd->pctx); |
| 891 | if (ret < 0) |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 892 | goto abort_free_dict; |
Theodore Ts'o | 28db82a | 2007-04-04 22:33:31 -0400 | [diff] [blame] | 893 | if (ret) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 894 | dir_modified++; |
| 895 | } else if (dirent->inode == ino) { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 896 | problem = PR_2_LINK_DOT; |
| 897 | if (fix_problem(ctx, PR_2_LINK_DOT, &cd->pctx)) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 898 | dirent->inode = 0; |
| 899 | dir_modified++; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 900 | goto next; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 901 | } |
| 902 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 903 | if (!dirent->inode) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 904 | goto next; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 905 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 906 | /* |
| 907 | * Make sure the inode listed is a legal one. |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 908 | */ |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 909 | if (((dirent->inode != EXT2_ROOT_INO) && |
Theodore Ts'o | 7f88b04 | 1997-04-26 14:48:50 +0000 | [diff] [blame] | 910 | (dirent->inode < EXT2_FIRST_INODE(fs->super))) || |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 911 | (dirent->inode > fs->super->s_inodes_count)) { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 912 | problem = PR_2_BAD_INO; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 913 | } else if (ctx->inode_bb_map && |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 914 | (ext2fs_test_inode_bitmap2(ctx->inode_bb_map, |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 915 | dirent->inode))) { |
| 916 | /* |
| 917 | * If the inode is in a bad block, offer to |
| 918 | * clear it. |
| 919 | */ |
| 920 | problem = PR_2_BB_INODE; |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 921 | } else if ((dot_state > 1) && |
Theodore Ts'o | b6f7983 | 1998-03-09 13:10:37 +0000 | [diff] [blame] | 922 | ((dirent->name_len & 0xFF) == 1) && |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 923 | (dirent->name[0] == '.')) { |
| 924 | /* |
| 925 | * If there's a '.' entry in anything other |
| 926 | * than the first directory entry, it's a |
| 927 | * duplicate entry that should be removed. |
| 928 | */ |
| 929 | problem = PR_2_DUP_DOT; |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 930 | } else if ((dot_state > 1) && |
Theodore Ts'o | b6f7983 | 1998-03-09 13:10:37 +0000 | [diff] [blame] | 931 | ((dirent->name_len & 0xFF) == 2) && |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 932 | (dirent->name[0] == '.') && |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 933 | (dirent->name[1] == '.')) { |
| 934 | /* |
| 935 | * If there's a '..' entry in anything other |
| 936 | * than the second directory entry, it's a |
| 937 | * duplicate entry that should be removed. |
| 938 | */ |
| 939 | problem = PR_2_DUP_DOT_DOT; |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 940 | } else if ((dot_state > 1) && |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 941 | (dirent->inode == EXT2_ROOT_INO)) { |
| 942 | /* |
| 943 | * Don't allow links to the root directory. |
| 944 | * We check this specially to make sure we |
| 945 | * catch this error case even if the root |
| 946 | * directory hasn't been created yet. |
| 947 | */ |
| 948 | problem = PR_2_LINK_ROOT; |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 949 | } else if ((dot_state > 1) && |
Theodore Ts'o | c40db6d | 1999-10-25 21:03:34 +0000 | [diff] [blame] | 950 | (dirent->name_len & 0xFF) == 0) { |
| 951 | /* |
| 952 | * Don't allow zero-length directory names. |
| 953 | */ |
| 954 | problem = PR_2_NULL_NAME; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 957 | if (problem) { |
| 958 | if (fix_problem(ctx, problem, &cd->pctx)) { |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 959 | dirent->inode = 0; |
| 960 | dir_modified++; |
| 961 | goto next; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 962 | } else { |
| 963 | ext2fs_unmark_valid(fs); |
| 964 | if (problem == PR_2_BAD_INO) |
| 965 | goto next; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 966 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | /* |
| 970 | * If the inode was marked as having bad fields in |
| 971 | * pass1, process it and offer to fix/clear it. |
| 972 | * (We wait until now so that we can display the |
| 973 | * pathname to the user.) |
| 974 | */ |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 975 | if (ctx->inode_bad_map && |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 976 | ext2fs_test_inode_bitmap2(ctx->inode_bad_map, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 977 | dirent->inode)) { |
Theodore Ts'o | e72a9ba | 1999-06-25 15:40:18 +0000 | [diff] [blame] | 978 | if (e2fsck_process_bad_inode(ctx, ino, |
Theodore Ts'o | bcf9c5d | 2002-05-21 09:14:17 -0400 | [diff] [blame] | 979 | dirent->inode, |
| 980 | buf + fs->blocksize)) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 981 | dirent->inode = 0; |
| 982 | dir_modified++; |
| 983 | goto next; |
| 984 | } |
Theodore Ts'o | a02ce9d | 1998-02-24 20:22:23 +0000 | [diff] [blame] | 985 | if (ctx->flags & E2F_FLAG_SIGNAL_MASK) |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 986 | return DIRENT_ABORT; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 987 | } |
| 988 | |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 989 | group = ext2fs_group_of_ino(fs, dirent->inode); |
| 990 | first_unused_inode = group * fs->super->s_inodes_per_group + |
| 991 | 1 + fs->super->s_inodes_per_group - |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 992 | ext2fs_bg_itable_unused(fs, group); |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 993 | cd->pctx.group = group; |
| 994 | |
| 995 | /* |
Theodore Ts'o | 42e89ce | 2008-11-26 20:41:26 -0500 | [diff] [blame] | 996 | * Check if the inode was missed out because |
| 997 | * _INODE_UNINIT flag was set or bg_itable_unused was |
| 998 | * incorrect. If so, clear the _INODE_UNINIT flag and |
| 999 | * restart e2fsck. In the future it would be nice if |
| 1000 | * we could call a function in pass1.c that checks the |
| 1001 | * newly visible inodes. |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 1002 | */ |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1003 | if (ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT)) { |
Andreas Dilger | 6267ee4 | 2009-05-28 00:39:49 -0600 | [diff] [blame] | 1004 | pctx.num = dirent->inode; |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 1005 | if (fix_problem(ctx, PR_2_INOREF_BG_INO_UNINIT, |
| 1006 | &cd->pctx)){ |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1007 | ext2fs_bg_flags_clear(fs, group, |
| 1008 | EXT2_BG_INODE_UNINIT); |
Theodore Ts'o | 42e89ce | 2008-11-26 20:41:26 -0500 | [diff] [blame] | 1009 | ext2fs_mark_super_dirty(fs); |
Andreas Dilger | 6267ee4 | 2009-05-28 00:39:49 -0600 | [diff] [blame] | 1010 | ctx->flags |= E2F_FLAG_RESTART_LATER; |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 1011 | } else { |
| 1012 | ext2fs_unmark_valid(fs); |
| 1013 | if (problem == PR_2_BAD_INO) |
| 1014 | goto next; |
| 1015 | } |
| 1016 | } else if (dirent->inode >= first_unused_inode) { |
Andreas Dilger | 6267ee4 | 2009-05-28 00:39:49 -0600 | [diff] [blame] | 1017 | pctx.num = dirent->inode; |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 1018 | if (fix_problem(ctx, PR_2_INOREF_IN_UNUSED, &cd->pctx)){ |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1019 | ext2fs_bg_itable_unused_set(fs, group, 0); |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 1020 | ext2fs_mark_super_dirty(fs); |
Andreas Dilger | 6267ee4 | 2009-05-28 00:39:49 -0600 | [diff] [blame] | 1021 | ctx->flags |= E2F_FLAG_RESTART_LATER; |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 1022 | } else { |
| 1023 | ext2fs_unmark_valid(fs); |
| 1024 | if (problem == PR_2_BAD_INO) |
| 1025 | goto next; |
| 1026 | } |
| 1027 | } |
| 1028 | |
Theodore Ts'o | 0433c1f | 2010-05-11 15:12:52 -0400 | [diff] [blame] | 1029 | /* |
| 1030 | * Offer to clear unused inodes; if we are going to be |
| 1031 | * restarting the scan due to bg_itable_unused being |
| 1032 | * wrong, then don't clear any inodes to avoid zapping |
| 1033 | * inodes that were skipped during pass1 due to an |
| 1034 | * incorrect bg_itable_unused; we'll get any real |
| 1035 | * problems after we restart. |
| 1036 | */ |
| 1037 | if (!(ctx->flags & E2F_FLAG_RESTART_LATER) && |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1038 | !(ext2fs_test_inode_bitmap2(ctx->inode_used_map, |
| 1039 | dirent->inode))) |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 1040 | problem = PR_2_UNUSED_INODE; |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 1041 | |
| 1042 | if (problem) { |
| 1043 | if (fix_problem(ctx, problem, &cd->pctx)) { |
| 1044 | dirent->inode = 0; |
| 1045 | dir_modified++; |
| 1046 | goto next; |
| 1047 | } else { |
| 1048 | ext2fs_unmark_valid(fs); |
| 1049 | if (problem == PR_2_BAD_INO) |
| 1050 | goto next; |
| 1051 | } |
| 1052 | } |
| 1053 | |
Theodore Ts'o | 890a2f9 | 2015-07-14 22:50:51 -0400 | [diff] [blame] | 1054 | if (!encrypted && check_name(ctx, dirent, &cd->pctx)) |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1055 | dir_modified++; |
| 1056 | |
Theodore Ts'o | 638c15d | 2015-10-25 22:19:04 -0400 | [diff] [blame] | 1057 | if (encrypted && (dot_state) > 1 && |
| 1058 | encrypted_check_name(ctx, dirent, &cd->pctx)) { |
| 1059 | dir_modified++; |
| 1060 | goto next; |
| 1061 | } |
| 1062 | |
Theodore Ts'o | aa4115a | 1999-10-21 19:33:18 +0000 | [diff] [blame] | 1063 | if (check_filetype(ctx, dirent, ino, &cd->pctx)) |
| 1064 | dir_modified++; |
| 1065 | |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 1066 | #ifdef ENABLE_HTREE |
| 1067 | if (dx_db) { |
| 1068 | ext2fs_dirhash(dx_dir->hashversion, dirent->name, |
Theodore Ts'o | 503f9e7 | 2002-06-26 16:52:10 -0400 | [diff] [blame] | 1069 | (dirent->name_len & 0xFF), |
| 1070 | fs->super->s_hash_seed, &hash, 0); |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 1071 | if (hash < dx_db->min_hash) |
| 1072 | dx_db->min_hash = hash; |
| 1073 | if (hash > dx_db->max_hash) |
| 1074 | dx_db->max_hash = hash; |
| 1075 | } |
| 1076 | #endif |
| 1077 | |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1078 | /* |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1079 | * If this is a directory, then mark its parent in its |
| 1080 | * dir_info structure. If the parent field is already |
| 1081 | * filled in, then this directory has more than one |
| 1082 | * hard link. We assume the first link is correct, |
| 1083 | * and ask the user if he/she wants to clear this one. |
| 1084 | */ |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 1085 | if ((dot_state > 1) && |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1086 | (ext2fs_test_inode_bitmap2(ctx->inode_dir_map, |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1087 | dirent->inode))) { |
Theodore Ts'o | 28db82a | 2007-04-04 22:33:31 -0400 | [diff] [blame] | 1088 | if (e2fsck_dir_info_get_parent(ctx, dirent->inode, |
| 1089 | &subdir_parent)) { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1090 | cd->pctx.ino = dirent->inode; |
| 1091 | fix_problem(ctx, PR_2_NO_DIRINFO, &cd->pctx); |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 1092 | goto abort_free_dict; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1093 | } |
Theodore Ts'o | 28db82a | 2007-04-04 22:33:31 -0400 | [diff] [blame] | 1094 | if (subdir_parent) { |
| 1095 | cd->pctx.ino2 = subdir_parent; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1096 | if (fix_problem(ctx, PR_2_LINK_DIR, |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1097 | &cd->pctx)) { |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1098 | dirent->inode = 0; |
| 1099 | dir_modified++; |
| 1100 | goto next; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1101 | } |
| 1102 | cd->pctx.ino2 = 0; |
Theodore Ts'o | 28db82a | 2007-04-04 22:33:31 -0400 | [diff] [blame] | 1103 | } else { |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1104 | (void) e2fsck_dir_info_set_parent(ctx, |
Theodore Ts'o | 28db82a | 2007-04-04 22:33:31 -0400 | [diff] [blame] | 1105 | dirent->inode, ino); |
| 1106 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1107 | } |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 1108 | |
| 1109 | if (dups_found) { |
| 1110 | ; |
| 1111 | } else if (dict_lookup(&de_dict, dirent)) { |
| 1112 | clear_problem_context(&pctx); |
| 1113 | pctx.ino = ino; |
| 1114 | pctx.dirent = dirent; |
| 1115 | fix_problem(ctx, PR_2_REPORT_DUP_DIRENT, &pctx); |
| 1116 | if (!ctx->dirs_to_hash) |
| 1117 | ext2fs_u32_list_create(&ctx->dirs_to_hash, 50); |
| 1118 | if (ctx->dirs_to_hash) |
| 1119 | ext2fs_u32_list_add(ctx->dirs_to_hash, ino); |
| 1120 | dups_found++; |
| 1121 | } else |
| 1122 | dict_alloc_insert(&de_dict, dirent, dirent); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1123 | |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1124 | ext2fs_icount_increment(ctx->inode_count, dirent->inode, |
| 1125 | &links); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1126 | if (links > 1) |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1127 | ctx->fs_links_count++; |
| 1128 | ctx->fs_total_count++; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1129 | next: |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 1130 | prev = dirent; |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 1131 | if (dir_modified) |
Theodore Ts'o | 8a48035 | 2009-06-21 21:07:38 -0400 | [diff] [blame] | 1132 | (void) ext2fs_get_rec_len(fs, dirent, &rec_len); |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 1133 | offset += rec_len; |
Theodore Ts'o | e70ae99 | 2002-09-28 09:16:28 -0400 | [diff] [blame] | 1134 | dot_state++; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1135 | } while (offset < fs->blocksize); |
| 1136 | #if 0 |
| 1137 | printf("\n"); |
| 1138 | #endif |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 1139 | #ifdef ENABLE_HTREE |
| 1140 | if (dx_db) { |
| 1141 | #ifdef DX_DEBUG |
| 1142 | printf("db_block %d, type %d, min_hash 0x%0x, max_hash 0x%0x\n", |
| 1143 | db->blockcnt, dx_db->type, |
| 1144 | dx_db->min_hash, dx_db->max_hash); |
| 1145 | #endif |
Theodore Ts'o | b7a0056 | 2002-07-20 00:28:07 -0400 | [diff] [blame] | 1146 | cd->pctx.dir = cd->pctx.ino; |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 1147 | if ((dx_db->type == DX_DIRBLOCK_ROOT) || |
| 1148 | (dx_db->type == DX_DIRBLOCK_NODE)) |
| 1149 | parse_int_node(fs, db, cd, dx_dir, buf); |
| 1150 | } |
| 1151 | #endif /* ENABLE_HTREE */ |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1152 | if (offset != fs->blocksize) { |
Theodore Ts'o | 5dd77db | 2008-08-25 21:08:19 -0400 | [diff] [blame] | 1153 | cd->pctx.num = rec_len - fs->blocksize + offset; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1154 | if (fix_problem(ctx, PR_2_FINAL_RECLEN, &cd->pctx)) { |
| 1155 | dirent->rec_len = cd->pctx.num; |
| 1156 | dir_modified++; |
| 1157 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1158 | } |
| 1159 | if (dir_modified) { |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1160 | cd->pctx.errcode = ext2fs_write_dir_block3(fs, block_nr, buf, 0); |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1161 | if (cd->pctx.errcode) { |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1162 | if (!fix_problem(ctx, PR_2_WRITE_DIRBLOCK, |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 1163 | &cd->pctx)) |
| 1164 | goto abort_free_dict; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1165 | } |
| 1166 | ext2fs_mark_changed(fs); |
| 1167 | } |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 1168 | dict_free_nodes(&de_dict); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1169 | return 0; |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 1170 | abort_free_dict: |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 1171 | ctx->flags |= E2F_FLAG_ABORT; |
Jose R. Santos | 49a7360 | 2007-10-21 21:04:03 -0500 | [diff] [blame] | 1172 | dict_free_nodes(&de_dict); |
Theodore Ts'o | 0926668 | 2003-03-14 22:19:10 -0500 | [diff] [blame] | 1173 | return DIRENT_ABORT; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1176 | struct del_block { |
| 1177 | e2fsck_t ctx; |
| 1178 | e2_blkcnt_t num; |
| 1179 | }; |
| 1180 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1181 | /* |
| 1182 | * This function is called to deallocate a block, and is an interator |
| 1183 | * functioned called by deallocate inode via ext2fs_iterate_block(). |
| 1184 | */ |
| 1185 | static int deallocate_inode_block(ext2_filsys fs, |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1186 | blk64_t *block_nr, |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 1187 | e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)), |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1188 | blk64_t ref_block EXT2FS_ATTR((unused)), |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 1189 | int ref_offset EXT2FS_ATTR((unused)), |
Theodore Ts'o | 133a56d | 2000-11-17 05:40:49 +0000 | [diff] [blame] | 1190 | void *priv_data) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1191 | { |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1192 | struct del_block *p = priv_data; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1193 | |
Theodore Ts'o | 1917875 | 2000-02-11 15:55:07 +0000 | [diff] [blame] | 1194 | if (HOLE_BLKADDR(*block_nr)) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1195 | return 0; |
Theodore Ts'o | 1ba7a2f | 2004-01-30 01:48:06 -0500 | [diff] [blame] | 1196 | if ((*block_nr < fs->super->s_first_data_block) || |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1197 | (*block_nr >= ext2fs_blocks_count(fs->super))) |
Theodore Ts'o | 1ba7a2f | 2004-01-30 01:48:06 -0500 | [diff] [blame] | 1198 | return 0; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1199 | ext2fs_unmark_block_bitmap2(p->ctx->block_found_map, *block_nr); |
| 1200 | ext2fs_block_alloc_stats2(fs, *block_nr, -1); |
| 1201 | p->num++; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1202 | return 0; |
| 1203 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1204 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1205 | /* |
| 1206 | * This fuction deallocates an inode |
| 1207 | */ |
Theodore Ts'o | 4035f40 | 2001-01-12 20:25:50 +0000 | [diff] [blame] | 1208 | static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1209 | { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1210 | ext2_filsys fs = ctx->fs; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1211 | struct ext2_inode inode; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1212 | struct problem_context pctx; |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1213 | __u32 count; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1214 | struct del_block del_block; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1215 | |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1216 | e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode"); |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1217 | clear_problem_context(&pctx); |
| 1218 | pctx.ino = ino; |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1219 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1220 | /* |
| 1221 | * Fix up the bitmaps... |
| 1222 | */ |
Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 1223 | e2fsck_read_bitmaps(ctx); |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1224 | ext2fs_inode_alloc_stats2(fs, ino, -1, LINUX_S_ISDIR(inode.i_mode)); |
| 1225 | |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1226 | if (ext2fs_file_acl_block(fs, &inode) && |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1227 | (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) { |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1228 | pctx.errcode = ext2fs_adjust_ea_refcount2(fs, |
| 1229 | ext2fs_file_acl_block(fs, &inode), |
| 1230 | block_buf, -1, &count); |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1231 | if (pctx.errcode == EXT2_ET_BAD_EA_BLOCK_NUM) { |
| 1232 | pctx.errcode = 0; |
| 1233 | count = 1; |
| 1234 | } |
| 1235 | if (pctx.errcode) { |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1236 | pctx.blk = ext2fs_file_acl_block(fs, &inode); |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1237 | fix_problem(ctx, PR_2_ADJ_EA_REFCOUNT, &pctx); |
| 1238 | ctx->flags |= E2F_FLAG_ABORT; |
| 1239 | return; |
| 1240 | } |
| 1241 | if (count == 0) { |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1242 | ext2fs_unmark_block_bitmap2(ctx->block_found_map, |
| 1243 | ext2fs_file_acl_block(fs, &inode)); |
| 1244 | ext2fs_block_alloc_stats2(fs, |
| 1245 | ext2fs_file_acl_block(fs, &inode), -1); |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1246 | } |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1247 | ext2fs_file_acl_block_set(fs, &inode, 0); |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1248 | } |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1249 | |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1250 | if (!ext2fs_inode_has_valid_blocks2(fs, &inode)) |
| 1251 | goto clear_inode; |
Theodore Ts'o | a474269 | 2001-08-09 04:14:04 -0400 | [diff] [blame] | 1252 | |
Darrick J. Wong | 3b6c093 | 2013-12-10 17:18:27 -0800 | [diff] [blame] | 1253 | if (LINUX_S_ISREG(inode.i_mode) && |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1254 | ext2fs_needs_large_file_feature(EXT2_I_SIZE(&inode))) |
Theodore Ts'o | a474269 | 2001-08-09 04:14:04 -0400 | [diff] [blame] | 1255 | ctx->large_files--; |
| 1256 | |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1257 | del_block.ctx = ctx; |
| 1258 | del_block.num = 0; |
| 1259 | pctx.errcode = ext2fs_block_iterate3(fs, ino, 0, block_buf, |
| 1260 | deallocate_inode_block, |
| 1261 | &del_block); |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1262 | if (pctx.errcode) { |
| 1263 | fix_problem(ctx, PR_2_DEALLOC_INODE, &pctx); |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1264 | ctx->flags |= E2F_FLAG_ABORT; |
| 1265 | return; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1266 | } |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1267 | clear_inode: |
| 1268 | /* Inode may have changed by block_iterate, so reread it */ |
| 1269 | e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode"); |
| 1270 | e2fsck_clear_inode(ctx, ino, &inode, 0, "deallocate_inode"); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 1273 | /* |
| 1274 | * This fuction clears the htree flag on an inode |
| 1275 | */ |
| 1276 | static void clear_htree(e2fsck_t ctx, ext2_ino_t ino) |
| 1277 | { |
| 1278 | struct ext2_inode inode; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1279 | |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 1280 | e2fsck_read_inode(ctx, ino, &inode, "clear_htree"); |
| 1281 | inode.i_flags = inode.i_flags & ~EXT2_INDEX_FL; |
| 1282 | e2fsck_write_inode(ctx, ino, &inode, "clear_htree"); |
Theodore Ts'o | b7a0056 | 2002-07-20 00:28:07 -0400 | [diff] [blame] | 1283 | if (ctx->dirs_to_hash) |
| 1284 | ext2fs_u32_list_add(ctx->dirs_to_hash, ino); |
Theodore Ts'o | 8fdc998 | 2002-06-25 23:26:34 -0400 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1288 | int e2fsck_process_bad_inode(e2fsck_t ctx, ext2_ino_t dir, |
| 1289 | ext2_ino_t ino, char *buf) |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1290 | { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1291 | ext2_filsys fs = ctx->fs; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1292 | struct ext2_inode inode; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1293 | int inode_modified = 0; |
Theodore Ts'o | 6c313fd | 2005-01-27 14:28:41 -0500 | [diff] [blame] | 1294 | int not_fixed = 0; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1295 | unsigned char *frag, *fsize; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1296 | struct problem_context pctx; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1297 | problem_t problem = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1298 | |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1299 | e2fsck_read_inode(ctx, ino, &inode, "process_bad_inode"); |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1300 | |
| 1301 | clear_problem_context(&pctx); |
| 1302 | pctx.ino = ino; |
| 1303 | pctx.dir = dir; |
| 1304 | pctx.inode = &inode; |
| 1305 | |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1306 | if (ext2fs_file_acl_block(fs, &inode) && |
Theodore Ts'o | f76344f | 2005-07-04 12:53:36 -0500 | [diff] [blame] | 1307 | !(fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) { |
| 1308 | if (fix_problem(ctx, PR_2_FILE_ACL_ZERO, &pctx)) { |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1309 | ext2fs_file_acl_block_set(fs, &inode, 0); |
Theodore Ts'o | f76344f | 2005-07-04 12:53:36 -0500 | [diff] [blame] | 1310 | inode_modified++; |
| 1311 | } else |
| 1312 | not_fixed++; |
| 1313 | } |
Theodore Ts'o | 6c313fd | 2005-01-27 14:28:41 -0500 | [diff] [blame] | 1314 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1315 | if (!LINUX_S_ISDIR(inode.i_mode) && !LINUX_S_ISREG(inode.i_mode) && |
| 1316 | !LINUX_S_ISCHR(inode.i_mode) && !LINUX_S_ISBLK(inode.i_mode) && |
| 1317 | !LINUX_S_ISLNK(inode.i_mode) && !LINUX_S_ISFIFO(inode.i_mode) && |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1318 | !(LINUX_S_ISSOCK(inode.i_mode))) |
| 1319 | problem = PR_2_BAD_MODE; |
Theodore Ts'o | fdbdea0 | 2001-06-02 04:26:26 +0000 | [diff] [blame] | 1320 | else if (LINUX_S_ISCHR(inode.i_mode) |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1321 | && !e2fsck_pass1_check_device_inode(fs, &inode)) |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1322 | problem = PR_2_BAD_CHAR_DEV; |
Theodore Ts'o | fdbdea0 | 2001-06-02 04:26:26 +0000 | [diff] [blame] | 1323 | else if (LINUX_S_ISBLK(inode.i_mode) |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1324 | && !e2fsck_pass1_check_device_inode(fs, &inode)) |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1325 | problem = PR_2_BAD_BLOCK_DEV; |
Theodore Ts'o | fdbdea0 | 2001-06-02 04:26:26 +0000 | [diff] [blame] | 1326 | else if (LINUX_S_ISFIFO(inode.i_mode) |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1327 | && !e2fsck_pass1_check_device_inode(fs, &inode)) |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 1328 | problem = PR_2_BAD_FIFO; |
Theodore Ts'o | fdbdea0 | 2001-06-02 04:26:26 +0000 | [diff] [blame] | 1329 | else if (LINUX_S_ISSOCK(inode.i_mode) |
Theodore Ts'o | 0684a4f | 2002-08-17 10:19:44 -0400 | [diff] [blame] | 1330 | && !e2fsck_pass1_check_device_inode(fs, &inode)) |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 1331 | problem = PR_2_BAD_SOCKET; |
Theodore Ts'o | fdbdea0 | 2001-06-02 04:26:26 +0000 | [diff] [blame] | 1332 | else if (LINUX_S_ISLNK(inode.i_mode) |
Theodore Ts'o | 7cadc57 | 2008-03-13 23:05:00 -0400 | [diff] [blame] | 1333 | && !e2fsck_pass1_check_symlink(fs, ino, &inode, buf)) { |
Theodore Ts'o | bcf9c5d | 2002-05-21 09:14:17 -0400 | [diff] [blame] | 1334 | problem = PR_2_INVALID_SYMLINK; |
Andreas Dilger | 67052a8 | 2001-08-04 00:51:18 -0600 | [diff] [blame] | 1335 | } |
Theodore Ts'o | 1dde43f | 1998-11-14 04:18:28 +0000 | [diff] [blame] | 1336 | |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1337 | if (problem) { |
| 1338 | if (fix_problem(ctx, problem, &pctx)) { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1339 | deallocate_inode(ctx, ino, 0); |
Theodore Ts'o | a02ce9d | 1998-02-24 20:22:23 +0000 | [diff] [blame] | 1340 | if (ctx->flags & E2F_FLAG_SIGNAL_MASK) |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1341 | return 0; |
Theodore Ts'o | 7cf73dc | 1997-08-14 17:17:16 +0000 | [diff] [blame] | 1342 | return 1; |
Theodore Ts'o | 6c313fd | 2005-01-27 14:28:41 -0500 | [diff] [blame] | 1343 | } else |
| 1344 | not_fixed++; |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1345 | problem = 0; |
Theodore Ts'o | 7cf73dc | 1997-08-14 17:17:16 +0000 | [diff] [blame] | 1346 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1347 | |
Theodore Ts'o | 6c313fd | 2005-01-27 14:28:41 -0500 | [diff] [blame] | 1348 | if (inode.i_faddr) { |
| 1349 | if (fix_problem(ctx, PR_2_FADDR_ZERO, &pctx)) { |
| 1350 | inode.i_faddr = 0; |
| 1351 | inode_modified++; |
| 1352 | } else |
| 1353 | not_fixed++; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1354 | } |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1355 | |
| 1356 | switch (fs->super->s_creator_os) { |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1357 | case EXT2_OS_HURD: |
| 1358 | frag = &inode.osd2.hurd2.h_i_frag; |
| 1359 | fsize = &inode.osd2.hurd2.h_i_fsize; |
| 1360 | break; |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1361 | default: |
| 1362 | frag = fsize = 0; |
| 1363 | } |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1364 | if (frag && *frag) { |
| 1365 | pctx.num = *frag; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1366 | if (fix_problem(ctx, PR_2_FRAG_ZERO, &pctx)) { |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1367 | *frag = 0; |
| 1368 | inode_modified++; |
Theodore Ts'o | 7e0282c | 2005-01-27 21:40:53 -0500 | [diff] [blame] | 1369 | } else |
| 1370 | not_fixed++; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1371 | pctx.num = 0; |
| 1372 | } |
| 1373 | if (fsize && *fsize) { |
| 1374 | pctx.num = *fsize; |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1375 | if (fix_problem(ctx, PR_2_FSIZE_ZERO, &pctx)) { |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1376 | *fsize = 0; |
| 1377 | inode_modified++; |
Theodore Ts'o | 6c313fd | 2005-01-27 14:28:41 -0500 | [diff] [blame] | 1378 | } else |
| 1379 | not_fixed++; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1380 | pctx.num = 0; |
| 1381 | } |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1382 | |
Theodore Ts'o | 5d17119 | 2006-11-11 06:32:03 -0500 | [diff] [blame] | 1383 | if ((fs->super->s_creator_os == EXT2_OS_LINUX) && |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1384 | !(fs->super->s_feature_ro_compat & |
Theodore Ts'o | 5d17119 | 2006-11-11 06:32:03 -0500 | [diff] [blame] | 1385 | EXT4_FEATURE_RO_COMPAT_HUGE_FILE) && |
| 1386 | (inode.osd2.linux2.l_i_blocks_hi != 0)) { |
| 1387 | pctx.num = inode.osd2.linux2.l_i_blocks_hi; |
| 1388 | if (fix_problem(ctx, PR_2_BLOCKS_HI_ZERO, &pctx)) { |
| 1389 | inode.osd2.linux2.l_i_blocks_hi = 0; |
| 1390 | inode_modified++; |
| 1391 | } |
| 1392 | } |
| 1393 | |
Theodore Ts'o | 911ec62 | 2009-04-23 21:31:16 -0400 | [diff] [blame] | 1394 | if (!(fs->super->s_feature_incompat & |
| 1395 | EXT4_FEATURE_INCOMPAT_64BIT) && |
| 1396 | inode.osd2.linux2.l_i_file_acl_high != 0) { |
| 1397 | pctx.num = inode.osd2.linux2.l_i_file_acl_high; |
| 1398 | if (fix_problem(ctx, PR_2_I_FILE_ACL_HI_ZERO, &pctx)) { |
| 1399 | inode.osd2.linux2.l_i_file_acl_high = 0; |
| 1400 | inode_modified++; |
| 1401 | } else |
| 1402 | not_fixed++; |
| 1403 | } |
| 1404 | |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1405 | if (ext2fs_file_acl_block(fs, &inode) && |
| 1406 | ((ext2fs_file_acl_block(fs, &inode) < fs->super->s_first_data_block) || |
| 1407 | (ext2fs_file_acl_block(fs, &inode) >= ext2fs_blocks_count(fs->super)))) { |
Theodore Ts'o | 6c313fd | 2005-01-27 14:28:41 -0500 | [diff] [blame] | 1408 | if (fix_problem(ctx, PR_2_FILE_ACL_BAD, &pctx)) { |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1409 | ext2fs_file_acl_block_set(fs, &inode, 0); |
Theodore Ts'o | 6c313fd | 2005-01-27 14:28:41 -0500 | [diff] [blame] | 1410 | inode_modified++; |
| 1411 | } else |
| 1412 | not_fixed++; |
Theodore Ts'o | 342d847 | 2001-07-02 11:54:09 -0400 | [diff] [blame] | 1413 | } |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1414 | if (inode.i_dir_acl && |
Theodore Ts'o | 6c313fd | 2005-01-27 14:28:41 -0500 | [diff] [blame] | 1415 | LINUX_S_ISDIR(inode.i_mode)) { |
| 1416 | if (fix_problem(ctx, PR_2_DIR_ACL_ZERO, &pctx)) { |
| 1417 | inode.i_dir_acl = 0; |
| 1418 | inode_modified++; |
| 1419 | } else |
| 1420 | not_fixed++; |
Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 1421 | } |
Theodore Ts'o | 6c313fd | 2005-01-27 14:28:41 -0500 | [diff] [blame] | 1422 | |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1423 | if (inode_modified) |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1424 | e2fsck_write_inode(ctx, ino, &inode, "process_bad_inode"); |
Theodore Ts'o | f76344f | 2005-07-04 12:53:36 -0500 | [diff] [blame] | 1425 | if (!not_fixed && ctx->inode_bad_map) |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1426 | ext2fs_unmark_inode_bitmap2(ctx->inode_bad_map, ino); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1427 | return 0; |
| 1428 | } |
| 1429 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1430 | |
| 1431 | /* |
| 1432 | * allocate_dir_block --- this function allocates a new directory |
| 1433 | * block for a particular inode; this is done if a directory has |
| 1434 | * a "hole" in it, or if a directory has a illegal block number |
| 1435 | * that was zeroed out and now needs to be replaced. |
| 1436 | */ |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1437 | static int allocate_dir_block(e2fsck_t ctx, |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1438 | struct ext2_db_entry2 *db, |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1439 | char *buf EXT2FS_ATTR((unused)), |
Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame] | 1440 | struct problem_context *pctx) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1441 | { |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1442 | ext2_filsys fs = ctx->fs; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1443 | blk64_t blk; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1444 | char *block; |
| 1445 | struct ext2_inode inode; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1446 | |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1447 | if (fix_problem(ctx, PR_2_DIRECTORY_HOLE, pctx) == 0) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1448 | return 1; |
| 1449 | |
| 1450 | /* |
| 1451 | * Read the inode and block bitmaps in; we'll be messing with |
| 1452 | * them. |
| 1453 | */ |
Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 1454 | e2fsck_read_bitmaps(ctx); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 1455 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1456 | /* |
| 1457 | * First, find a free block |
| 1458 | */ |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1459 | pctx->errcode = ext2fs_new_block2(fs, 0, ctx->block_found_map, &blk); |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1460 | if (pctx->errcode) { |
| 1461 | pctx->str = "ext2fs_new_block"; |
| 1462 | fix_problem(ctx, PR_2_ALLOC_DIRBOCK, pctx); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1463 | return 1; |
| 1464 | } |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1465 | ext2fs_mark_block_bitmap2(ctx->block_found_map, blk); |
| 1466 | ext2fs_mark_block_bitmap2(fs->block_map, blk); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1467 | ext2fs_mark_bb_dirty(fs); |
| 1468 | |
| 1469 | /* |
| 1470 | * Now let's create the actual data block for the inode |
| 1471 | */ |
| 1472 | if (db->blockcnt) |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1473 | pctx->errcode = ext2fs_new_dir_block(fs, 0, 0, &block); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1474 | else |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1475 | pctx->errcode = ext2fs_new_dir_block(fs, db->ino, |
| 1476 | EXT2_ROOT_INO, &block); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1477 | |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1478 | if (pctx->errcode) { |
| 1479 | pctx->str = "ext2fs_new_dir_block"; |
| 1480 | fix_problem(ctx, PR_2_ALLOC_DIRBOCK, pctx); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1481 | return 1; |
| 1482 | } |
| 1483 | |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1484 | pctx->errcode = ext2fs_write_dir_block3(fs, blk, block, 0); |
Theodore Ts'o | c4e3d3f | 2003-08-01 09:41:07 -0400 | [diff] [blame] | 1485 | ext2fs_free_mem(&block); |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1486 | if (pctx->errcode) { |
| 1487 | pctx->str = "ext2fs_write_dir_block"; |
| 1488 | fix_problem(ctx, PR_2_ALLOC_DIRBOCK, pctx); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1489 | return 1; |
| 1490 | } |
| 1491 | |
| 1492 | /* |
| 1493 | * Update the inode block count |
| 1494 | */ |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1495 | e2fsck_read_inode(ctx, db->ino, &inode, "allocate_dir_block"); |
Theodore Ts'o | 1ca1059 | 2008-04-09 11:39:11 -0400 | [diff] [blame] | 1496 | ext2fs_iblk_add_blocks(fs, &inode, 1); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1497 | if (inode.i_size < (db->blockcnt+1) * fs->blocksize) |
| 1498 | inode.i_size = (db->blockcnt+1) * fs->blocksize; |
Theodore Ts'o | 08b2130 | 1997-11-03 19:42:40 +0000 | [diff] [blame] | 1499 | e2fsck_write_inode(ctx, db->ino, &inode, "allocate_dir_block"); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1500 | |
| 1501 | /* |
| 1502 | * Finally, update the block pointers for the inode |
| 1503 | */ |
| 1504 | db->blk = blk; |
JP Abgrall | e0ed740 | 2014-03-19 19:08:39 -0700 | [diff] [blame] | 1505 | pctx->errcode = ext2fs_bmap2(fs, db->ino, &inode, 0, BMAP_SET, |
| 1506 | db->blockcnt, 0, &blk); |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 1507 | if (pctx->errcode) { |
| 1508 | pctx->str = "ext2fs_block_iterate"; |
| 1509 | fix_problem(ctx, PR_2_ALLOC_DIRBOCK, pctx); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 1510 | return 1; |
| 1511 | } |
| 1512 | |
| 1513 | return 0; |
| 1514 | } |