]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blob - e2fsck/super.c
eb7ab0d1bb5f01bdfabfad03fa292cb683e39261
[thirdparty/e2fsprogs.git] / e2fsck / super.c
1 /*
2 * e2fsck.c - superblock checks
3 *
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%
10 */
11
12 #include "config.h"
13 #ifdef HAVE_ERRNO_H
14 #include <errno.h>
15 #endif
16
17 #ifndef EXT2_SKIP_UUID
18 #include "uuid/uuid.h"
19 #endif
20 #include "e2fsck.h"
21 #include "problem.h"
22
23 #define MIN_CHECK 1
24 #define MAX_CHECK 2
25 #define LOG2_CHECK 4
26
27 static int check_super_value(e2fsck_t ctx, const char *descr,
28 unsigned long value, int flags,
29 unsigned long min_val, unsigned long max_val)
30 {
31 struct problem_context pctx;
32
33 if ((flags & MIN_CHECK && value < min_val) ||
34 (flags & MAX_CHECK && value > max_val) ||
35 (flags & LOG2_CHECK && (value & (value - 1)) != 0)) {
36 clear_problem_context(&pctx);
37 pctx.num = value;
38 pctx.str = descr;
39 fix_problem(ctx, PR_0_MISC_CORRUPT_SUPER, &pctx);
40 ctx->flags |= E2F_FLAG_ABORT;
41 return 0;
42 }
43 return 1;
44 }
45
46 static int check_super_value64(e2fsck_t ctx, const char *descr,
47 __u64 value, int flags,
48 __u64 min_val, __u64 max_val)
49 {
50 struct problem_context pctx;
51
52 if ((flags & MIN_CHECK && value < min_val) ||
53 (flags & MAX_CHECK && value > max_val) ||
54 (flags & LOG2_CHECK && (value & (value - 1)) != 0)) {
55 clear_problem_context(&pctx);
56 pctx.num = value;
57 pctx.str = descr;
58 fix_problem(ctx, PR_0_MISC_CORRUPT_SUPER, &pctx);
59 ctx->flags |= E2F_FLAG_ABORT;
60 return 0;
61 }
62 return 1;
63 }
64
65 /*
66 * helper function to release an inode
67 */
68 struct process_block_struct {
69 e2fsck_t ctx;
70 char *buf;
71 struct problem_context *pctx;
72 int truncating;
73 int truncate_offset;
74 e2_blkcnt_t truncate_block;
75 int truncated_blocks;
76 int abort;
77 errcode_t errcode;
78 blk64_t last_cluster;
79 struct ext2_inode_large *inode;
80 };
81
82 static int release_inode_block(ext2_filsys fs,
83 blk64_t *block_nr,
84 e2_blkcnt_t blockcnt,
85 blk64_t ref_blk EXT2FS_ATTR((unused)),
86 int ref_offset EXT2FS_ATTR((unused)),
87 void *priv_data)
88 {
89 struct process_block_struct *pb;
90 e2fsck_t ctx;
91 struct problem_context *pctx;
92 blk64_t blk = *block_nr;
93 blk64_t cluster = EXT2FS_B2C(fs, *block_nr);
94 int retval = 0;
95
96 pb = (struct process_block_struct *) priv_data;
97 ctx = pb->ctx;
98 pctx = pb->pctx;
99
100 pctx->blk = blk;
101 pctx->blkcount = blockcnt;
102
103 if (blk == 0)
104 return 0;
105
106 if (pb->last_cluster == cluster)
107 return 0;
108
109 pb->last_cluster = cluster;
110
111 if ((blk < fs->super->s_first_data_block) ||
112 (blk >= ext2fs_blocks_count(fs->super))) {
113 fix_problem(ctx, PR_0_ORPHAN_ILLEGAL_BLOCK_NUM, pctx);
114 return_abort:
115 pb->abort = 1;
116 return BLOCK_ABORT;
117 }
118
119 if (!ext2fs_test_block_bitmap2(fs->block_map, blk)) {
120 fix_problem(ctx, PR_0_ORPHAN_ALREADY_CLEARED_BLOCK, pctx);
121 goto return_abort;
122 }
123
124 /*
125 * If we are deleting an orphan, then we leave the fields alone.
126 * If we are truncating an orphan, then update the inode fields
127 * and clean up any partial block data.
128 */
129 if (pb->truncating) {
130 /*
131 * We only remove indirect blocks if they are
132 * completely empty.
133 */
134 if (blockcnt < 0) {
135 int i, limit;
136 blk_t *bp;
137
138 pb->errcode = io_channel_read_blk64(fs->io, blk, 1,
139 pb->buf);
140 if (pb->errcode)
141 goto return_abort;
142
143 limit = fs->blocksize >> 2;
144 for (i = 0, bp = (blk_t *) pb->buf;
145 i < limit; i++, bp++)
146 if (*bp)
147 return 0;
148 }
149 /*
150 * We don't remove direct blocks until we've reached
151 * the truncation block.
152 */
153 if (blockcnt >= 0 && blockcnt < pb->truncate_block)
154 return 0;
155 /*
156 * If part of the last block needs truncating, we do
157 * it here.
158 */
159 if ((blockcnt == pb->truncate_block) && pb->truncate_offset) {
160 pb->errcode = io_channel_read_blk64(fs->io, blk, 1,
161 pb->buf);
162 if (pb->errcode)
163 goto return_abort;
164 memset(pb->buf + pb->truncate_offset, 0,
165 fs->blocksize - pb->truncate_offset);
166 pb->errcode = io_channel_write_blk64(fs->io, blk, 1,
167 pb->buf);
168 if (pb->errcode)
169 goto return_abort;
170 }
171 pb->truncated_blocks++;
172 *block_nr = 0;
173 retval |= BLOCK_CHANGED;
174 }
175
176 if (ctx->qctx)
177 quota_data_sub(ctx->qctx, pb->inode, 0, ctx->fs->blocksize);
178 ext2fs_block_alloc_stats2(fs, blk, -1);
179 ctx->free_blocks++;
180 return retval;
181 }
182
183 /*
184 * This function releases an inode. Returns 1 if an inconsistency was
185 * found. If the inode has a link count, then it is being truncated and
186 * not deleted.
187 */
188 static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino,
189 struct ext2_inode_large *inode, char *block_buf,
190 struct problem_context *pctx)
191 {
192 struct process_block_struct pb;
193 ext2_filsys fs = ctx->fs;
194 blk64_t blk;
195 errcode_t retval;
196 __u32 count;
197
198 if (!ext2fs_inode_has_valid_blocks2(fs, EXT2_INODE(inode)))
199 return 0;
200
201 pb.buf = block_buf + 3 * ctx->fs->blocksize;
202 pb.ctx = ctx;
203 pb.abort = 0;
204 pb.errcode = 0;
205 pb.pctx = pctx;
206 pb.last_cluster = 0;
207 pb.inode = inode;
208 if (inode->i_links_count) {
209 pb.truncating = 1;
210 pb.truncate_block = (e2_blkcnt_t)
211 ((EXT2_I_SIZE(inode) + fs->blocksize - 1) /
212 fs->blocksize);
213 pb.truncate_offset = inode->i_size % fs->blocksize;
214 } else {
215 pb.truncating = 0;
216 pb.truncate_block = 0;
217 pb.truncate_offset = 0;
218 }
219 pb.truncated_blocks = 0;
220 retval = ext2fs_block_iterate3(fs, ino, BLOCK_FLAG_DEPTH_TRAVERSE,
221 block_buf, release_inode_block, &pb);
222 if (retval) {
223 com_err("release_inode_blocks", retval,
224 _("while calling ext2fs_block_iterate for inode %u"),
225 ino);
226 return 1;
227 }
228 if (pb.abort)
229 return 1;
230
231 /* Refresh the inode since ext2fs_block_iterate may have changed it */
232 e2fsck_read_inode_full(ctx, ino, EXT2_INODE(inode), sizeof(*inode),
233 "release_inode_blocks");
234
235 if (pb.truncated_blocks)
236 ext2fs_iblk_sub_blocks(fs, EXT2_INODE(inode),
237 pb.truncated_blocks);
238
239 blk = ext2fs_file_acl_block(fs, EXT2_INODE(inode));
240 if (blk) {
241 retval = ext2fs_adjust_ea_refcount3(fs, blk, block_buf, -1,
242 &count, ino);
243 if (retval == EXT2_ET_BAD_EA_BLOCK_NUM) {
244 retval = 0;
245 count = 1;
246 }
247 if (retval) {
248 com_err("release_inode_blocks", retval,
249 _("while calling ext2fs_adjust_ea_refcount2 for inode %u"),
250 ino);
251 return 1;
252 }
253 if (count == 0) {
254 if (ctx->qctx)
255 quota_data_sub(ctx->qctx, inode, 0,
256 ctx->fs->blocksize);
257 ext2fs_block_alloc_stats2(fs, blk, -1);
258 ctx->free_blocks++;
259 }
260 ext2fs_file_acl_block_set(fs, EXT2_INODE(inode), 0);
261 }
262 return 0;
263 }
264
265 /* Load all quota data in preparation for orphan clearing. */
266 static errcode_t e2fsck_read_all_quotas(e2fsck_t ctx)
267 {
268 ext2_ino_t qf_ino;
269 enum quota_type qtype;
270 errcode_t retval = 0;
271
272 if (!ext2fs_has_feature_quota(ctx->fs->super))
273 return retval;
274
275 retval = quota_init_context(&ctx->qctx, ctx->fs, 0);
276 if (retval)
277 return retval;
278
279 for (qtype = 0 ; qtype < MAXQUOTAS; qtype++) {
280 qf_ino = *quota_sb_inump(ctx->fs->super, qtype);
281 if (qf_ino == 0)
282 continue;
283
284 retval = quota_update_limits(ctx->qctx, qf_ino, qtype);
285 if (retval)
286 break;
287 }
288 if (retval)
289 quota_release_context(&ctx->qctx);
290 return retval;
291 }
292
293 /* Write all the quota info to disk. */
294 static errcode_t e2fsck_write_all_quotas(e2fsck_t ctx)
295 {
296 struct problem_context pctx;
297 enum quota_type qtype;
298
299 if (!ext2fs_has_feature_quota(ctx->fs->super))
300 return 0;
301
302 clear_problem_context(&pctx);
303 for (qtype = 0 ; qtype < MAXQUOTAS; qtype++) {
304 pctx.num = qtype;
305 pctx.errcode = quota_write_inode(ctx->qctx, 1 << qtype);
306 if (pctx.errcode) {
307 fix_problem(ctx, PR_6_WRITE_QUOTAS, &pctx);
308 break;
309 }
310 }
311
312 quota_release_context(&ctx->qctx);
313 return pctx.errcode;
314 }
315
316 /*
317 * This function releases all of the orphan inodes. It returns 1 if
318 * it hit some error, and 0 on success.
319 */
320 static int release_orphan_inodes(e2fsck_t ctx)
321 {
322 ext2_filsys fs = ctx->fs;
323 ext2_ino_t ino, next_ino;
324 struct ext2_inode_large inode;
325 struct problem_context pctx;
326 char *block_buf;
327
328 if ((ino = fs->super->s_last_orphan) == 0)
329 return 0;
330
331 clear_problem_context(&pctx);
332 pctx.errcode = e2fsck_read_all_quotas(ctx);
333 if (pctx.errcode) {
334 fix_problem(ctx, PR_0_QUOTA_INIT_CTX, &pctx);
335 return 1;
336 }
337
338 /*
339 * Win or lose, we won't be using the head of the orphan inode
340 * list again.
341 */
342 fs->super->s_last_orphan = 0;
343 ext2fs_mark_super_dirty(fs);
344
345 /*
346 * If the filesystem contains errors, don't run the orphan
347 * list, since the orphan list can't be trusted; and we're
348 * going to be running a full e2fsck run anyway...
349 */
350 if (fs->super->s_state & EXT2_ERROR_FS) {
351 if (ctx->qctx)
352 quota_release_context(&ctx->qctx);
353 return 0;
354 }
355
356 if ((ino < EXT2_FIRST_INODE(fs->super)) ||
357 (ino > fs->super->s_inodes_count)) {
358 clear_problem_context(&pctx);
359 pctx.ino = ino;
360 fix_problem(ctx, PR_0_ORPHAN_ILLEGAL_HEAD_INODE, &pctx);
361 goto err_qctx;
362 }
363
364 block_buf = (char *) e2fsck_allocate_memory(ctx, fs->blocksize * 4,
365 "block iterate buffer");
366 e2fsck_read_bitmaps(ctx);
367
368 while (ino) {
369 e2fsck_read_inode_full(ctx, ino, EXT2_INODE(&inode),
370 sizeof(inode), "release_orphan_inodes");
371 clear_problem_context(&pctx);
372 pctx.ino = ino;
373 pctx.inode = EXT2_INODE(&inode);
374 pctx.str = inode.i_links_count ? _("Truncating") :
375 _("Clearing");
376
377 fix_problem(ctx, PR_0_ORPHAN_CLEAR_INODE, &pctx);
378
379 next_ino = inode.i_dtime;
380 if (next_ino &&
381 ((next_ino < EXT2_FIRST_INODE(fs->super)) ||
382 (next_ino > fs->super->s_inodes_count))) {
383 pctx.ino = next_ino;
384 fix_problem(ctx, PR_0_ORPHAN_ILLEGAL_INODE, &pctx);
385 goto err_buf;
386 }
387
388 if (release_inode_blocks(ctx, ino, &inode, block_buf, &pctx))
389 goto err_buf;
390
391 if (!inode.i_links_count) {
392 if (ctx->qctx)
393 quota_data_inodes(ctx->qctx, &inode, ino, -1);
394 ext2fs_inode_alloc_stats2(fs, ino, -1,
395 LINUX_S_ISDIR(inode.i_mode));
396 ctx->free_inodes++;
397 inode.i_dtime = ctx->now;
398 } else {
399 inode.i_dtime = 0;
400 }
401 e2fsck_write_inode_full(ctx, ino, EXT2_INODE(&inode),
402 sizeof(inode), "delete_file");
403 ino = next_ino;
404 }
405 ext2fs_free_mem(&block_buf);
406 pctx.errcode = e2fsck_write_all_quotas(ctx);
407 if (pctx.errcode)
408 goto err;
409 return 0;
410 err_buf:
411 ext2fs_free_mem(&block_buf);
412 err_qctx:
413 if (ctx->qctx)
414 quota_release_context(&ctx->qctx);
415 err:
416 return 1;
417 }
418
419 /*
420 * Check the resize inode to make sure it is sane. We check both for
421 * the case where on-line resizing is not enabled (in which case the
422 * resize inode should be cleared) as well as the case where on-line
423 * resizing is enabled.
424 */
425 void check_resize_inode(e2fsck_t ctx)
426 {
427 ext2_filsys fs = ctx->fs;
428 struct ext2_inode inode;
429 struct problem_context pctx;
430 int i, gdt_off, ind_off;
431 dgrp_t j;
432 blk_t blk, pblk;
433 blk_t expect; /* for resize inode, which is 32-bit only */
434 __u32 *dind_buf = 0, *ind_buf;
435 errcode_t retval;
436
437 clear_problem_context(&pctx);
438
439 /*
440 * If the resize inode feature isn't set, then
441 * s_reserved_gdt_blocks must be zero.
442 */
443 if (!ext2fs_has_feature_resize_inode(fs->super)) {
444 if (fs->super->s_reserved_gdt_blocks) {
445 pctx.num = fs->super->s_reserved_gdt_blocks;
446 if (fix_problem(ctx, PR_0_NONZERO_RESERVED_GDT_BLOCKS,
447 &pctx)) {
448 fs->super->s_reserved_gdt_blocks = 0;
449 ext2fs_mark_super_dirty(fs);
450 }
451 }
452 }
453
454 /* Read the resize inode */
455 pctx.ino = EXT2_RESIZE_INO;
456 retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode);
457 if (retval) {
458 if (ext2fs_has_feature_resize_inode(fs->super))
459 ctx->flags |= E2F_FLAG_RESIZE_INODE;
460 return;
461 }
462
463 /*
464 * If the resize inode feature isn't set, check to make sure
465 * the resize inode is cleared; then we're done.
466 */
467 if (!ext2fs_has_feature_resize_inode(fs->super)) {
468 for (i=0; i < EXT2_N_BLOCKS; i++) {
469 if (inode.i_block[i])
470 break;
471 }
472 if ((i < EXT2_N_BLOCKS) &&
473 fix_problem(ctx, PR_0_CLEAR_RESIZE_INODE, &pctx)) {
474 memset(&inode, 0, sizeof(inode));
475 e2fsck_write_inode(ctx, EXT2_RESIZE_INO, &inode,
476 "clear_resize");
477 }
478 return;
479 }
480
481 /*
482 * The resize inode feature is enabled; check to make sure the
483 * only block in use is the double indirect block
484 */
485 blk = inode.i_block[EXT2_DIND_BLOCK];
486 for (i=0; i < EXT2_N_BLOCKS; i++) {
487 if (i != EXT2_DIND_BLOCK && inode.i_block[i])
488 break;
489 }
490 if ((i < EXT2_N_BLOCKS) || !blk || !inode.i_links_count ||
491 !(inode.i_mode & LINUX_S_IFREG) ||
492 (blk < fs->super->s_first_data_block ||
493 blk >= ext2fs_blocks_count(fs->super))) {
494 resize_inode_invalid:
495 if (fix_problem(ctx, PR_0_RESIZE_INODE_INVALID, &pctx)) {
496 memset(&inode, 0, sizeof(inode));
497 e2fsck_write_inode(ctx, EXT2_RESIZE_INO, &inode,
498 "clear_resize");
499 ctx->flags |= E2F_FLAG_RESIZE_INODE;
500 }
501 if (!(ctx->options & E2F_OPT_READONLY)) {
502 fs->super->s_state &= ~EXT2_VALID_FS;
503 ext2fs_mark_super_dirty(fs);
504 }
505 goto cleanup;
506 }
507 dind_buf = (__u32 *) e2fsck_allocate_memory(ctx, fs->blocksize * 2,
508 "resize dind buffer");
509 ind_buf = (__u32 *) ((char *) dind_buf + fs->blocksize);
510
511 retval = ext2fs_read_ind_block(fs, blk, dind_buf);
512 if (retval)
513 goto resize_inode_invalid;
514
515 gdt_off = fs->desc_blocks;
516 pblk = fs->super->s_first_data_block + 1 + fs->desc_blocks;
517 if (fs->blocksize == 1024 && fs->super->s_first_data_block == 0)
518 pblk++; /* Deal with 1024 blocksize bigalloc fs */
519 for (i = 0; i < fs->super->s_reserved_gdt_blocks / 4;
520 i++, gdt_off++, pblk++) {
521 gdt_off %= fs->blocksize/4;
522 if (dind_buf[gdt_off] != pblk)
523 goto resize_inode_invalid;
524 retval = ext2fs_read_ind_block(fs, pblk, ind_buf);
525 if (retval)
526 goto resize_inode_invalid;
527 ind_off = 0;
528 for (j = 1; j < fs->group_desc_count; j++) {
529 if (!ext2fs_bg_has_super(fs, j))
530 continue;
531 expect = pblk + EXT2_GROUPS_TO_BLOCKS(fs->super, j);
532 if (ind_buf[ind_off] != expect)
533 goto resize_inode_invalid;
534 ind_off++;
535 }
536 }
537
538 cleanup:
539 if (dind_buf)
540 ext2fs_free_mem(&dind_buf);
541
542 }
543
544 /*
545 * This function checks the dirhash signed/unsigned hint if necessary.
546 */
547 static void e2fsck_fix_dirhash_hint(e2fsck_t ctx)
548 {
549 struct ext2_super_block *sb = ctx->fs->super;
550 struct problem_context pctx;
551 char c;
552
553 if ((ctx->options & E2F_OPT_READONLY) ||
554 !ext2fs_has_feature_dir_index(sb) ||
555 (sb->s_flags & (EXT2_FLAGS_SIGNED_HASH|EXT2_FLAGS_UNSIGNED_HASH)))
556 return;
557
558 c = (char) 255;
559
560 clear_problem_context(&pctx);
561 if (fix_problem(ctx, PR_0_DIRHASH_HINT, &pctx)) {
562 if (((int) c) == -1) {
563 sb->s_flags |= EXT2_FLAGS_SIGNED_HASH;
564 } else {
565 sb->s_flags |= EXT2_FLAGS_UNSIGNED_HASH;
566 }
567 ext2fs_mark_super_dirty(ctx->fs);
568 }
569 }
570
571
572 void check_super_block(e2fsck_t ctx)
573 {
574 ext2_filsys fs = ctx->fs;
575 blk64_t first_block, last_block;
576 struct ext2_super_block *sb = fs->super;
577 unsigned int ipg_max;
578 problem_t problem;
579 blk64_t blocks_per_group = fs->super->s_blocks_per_group;
580 __u32 bpg_max, cpg_max;
581 __u64 blks_max;
582 int inodes_per_block;
583 int inode_size;
584 int accept_time_fudge;
585 int broken_system_clock;
586 dgrp_t i;
587 blk64_t should_be;
588 struct problem_context pctx;
589 blk64_t free_blocks = 0;
590 ino_t free_inodes = 0;
591 int csum_flag, clear_test_fs_flag;
592
593 inodes_per_block = EXT2_INODES_PER_BLOCK(fs->super);
594 ipg_max = inodes_per_block * (blocks_per_group - 4);
595 if (ipg_max > EXT2_MAX_INODES_PER_GROUP(sb))
596 ipg_max = EXT2_MAX_INODES_PER_GROUP(sb);
597 cpg_max = 8 * EXT2_BLOCK_SIZE(sb);
598 if (cpg_max > EXT2_MAX_CLUSTERS_PER_GROUP(sb))
599 cpg_max = EXT2_MAX_CLUSTERS_PER_GROUP(sb);
600 bpg_max = 8 * EXT2_BLOCK_SIZE(sb) * EXT2FS_CLUSTER_RATIO(fs);
601 if (bpg_max > EXT2_MAX_BLOCKS_PER_GROUP(sb))
602 bpg_max = EXT2_MAX_BLOCKS_PER_GROUP(sb);
603
604 ctx->invalid_inode_bitmap_flag = (int *) e2fsck_allocate_memory(ctx,
605 sizeof(int) * fs->group_desc_count, "invalid_inode_bitmap");
606 ctx->invalid_block_bitmap_flag = (int *) e2fsck_allocate_memory(ctx,
607 sizeof(int) * fs->group_desc_count, "invalid_block_bitmap");
608 ctx->invalid_inode_table_flag = (int *) e2fsck_allocate_memory(ctx,
609 sizeof(int) * fs->group_desc_count, "invalid_inode_table");
610
611 blks_max = (1ULL << 32) * EXT2_MAX_BLOCKS_PER_GROUP(fs->super);
612 if (ext2fs_has_feature_64bit(fs->super)) {
613 if (blks_max > ((1ULL << 48) - 1))
614 blks_max = (1ULL << 48) - 1;
615 } else {
616 if (blks_max > ((1ULL << 32) - 1))
617 blks_max = (1ULL << 32) - 1;
618 }
619
620 clear_problem_context(&pctx);
621
622 /*
623 * Verify the super block constants...
624 */
625 if (!check_super_value(ctx, "inodes_count", sb->s_inodes_count,
626 MIN_CHECK, 1, 0))
627 return;
628 if (!check_super_value64(ctx, "blocks_count", ext2fs_blocks_count(sb),
629 MIN_CHECK | MAX_CHECK, 1, blks_max))
630 return;
631 if (!check_super_value(ctx, "first_data_block", sb->s_first_data_block,
632 MAX_CHECK, 0, ext2fs_blocks_count(sb)))
633 return;
634 if (!check_super_value(ctx, "log_block_size", sb->s_log_block_size,
635 MIN_CHECK | MAX_CHECK, 0,
636 EXT2_MAX_BLOCK_LOG_SIZE - EXT2_MIN_BLOCK_LOG_SIZE))
637 return;
638 if (!check_super_value(ctx, "log_cluster_size",
639 sb->s_log_cluster_size,
640 MIN_CHECK | MAX_CHECK, sb->s_log_block_size,
641 (EXT2_MAX_CLUSTER_LOG_SIZE -
642 EXT2_MIN_CLUSTER_LOG_SIZE)))
643 return;
644 if (!check_super_value(ctx, "clusters_per_group",
645 sb->s_clusters_per_group,
646 MIN_CHECK | MAX_CHECK, 8, cpg_max))
647 return;
648 if (!check_super_value(ctx, "blocks_per_group", sb->s_blocks_per_group,
649 MIN_CHECK | MAX_CHECK, 8, bpg_max))
650 return;
651 if (!check_super_value(ctx, "inodes_per_group", sb->s_inodes_per_group,
652 MIN_CHECK | MAX_CHECK, inodes_per_block, ipg_max))
653 return;
654 if (!check_super_value(ctx, "r_blocks_count", ext2fs_r_blocks_count(sb),
655 MAX_CHECK, 0, ext2fs_blocks_count(sb) / 2))
656 return;
657 if (!check_super_value(ctx, "reserved_gdt_blocks",
658 sb->s_reserved_gdt_blocks, MAX_CHECK, 0,
659 fs->blocksize / sizeof(__u32)))
660 return;
661 if (!check_super_value(ctx, "desc_size",
662 sb->s_desc_size, MAX_CHECK | LOG2_CHECK, 0,
663 EXT2_MAX_DESC_SIZE))
664 return;
665
666 should_be = (__u64)sb->s_inodes_per_group * fs->group_desc_count;
667 if (should_be > ~0U) {
668 pctx.num = should_be;
669 fix_problem(ctx, PR_0_INODE_COUNT_BIG, &pctx);
670 ctx->flags |= E2F_FLAG_ABORT;
671 return;
672 }
673 if (sb->s_inodes_count != should_be) {
674 pctx.ino = sb->s_inodes_count;
675 pctx.ino2 = should_be;
676 if (fix_problem(ctx, PR_0_INODE_COUNT_WRONG, &pctx)) {
677 sb->s_inodes_count = should_be;
678 ext2fs_mark_super_dirty(fs);
679 } else {
680 pctx.num = sb->s_inodes_count;
681 pctx.str = "inodes_count";
682 fix_problem(ctx, PR_0_MISC_CORRUPT_SUPER, &pctx);
683 ctx->flags |= E2F_FLAG_ABORT;
684 return;
685 }
686 }
687 if (sb->s_rev_level > EXT2_GOOD_OLD_REV &&
688 !check_super_value(ctx, "first_ino", sb->s_first_ino,
689 MIN_CHECK | MAX_CHECK,
690 EXT2_GOOD_OLD_FIRST_INO, sb->s_inodes_count))
691 return;
692 inode_size = EXT2_INODE_SIZE(sb);
693 if (!check_super_value(ctx, "inode_size",
694 inode_size, MIN_CHECK | MAX_CHECK | LOG2_CHECK,
695 EXT2_GOOD_OLD_INODE_SIZE, fs->blocksize))
696 return;
697 if (sb->s_blocks_per_group != (sb->s_clusters_per_group *
698 EXT2FS_CLUSTER_RATIO(fs))) {
699 pctx.num = sb->s_clusters_per_group * EXT2FS_CLUSTER_RATIO(fs);
700 pctx.str = "block_size";
701 fix_problem(ctx, PR_0_MISC_CORRUPT_SUPER, &pctx);
702 ctx->flags |= E2F_FLAG_ABORT;
703 return;
704 }
705
706 if ((ctx->flags & E2F_FLAG_GOT_DEVSIZE) &&
707 (ctx->num_blocks < ext2fs_blocks_count(sb))) {
708 pctx.blk = ext2fs_blocks_count(sb);
709 pctx.blk2 = ctx->num_blocks;
710 if (fix_problem(ctx, PR_0_FS_SIZE_WRONG, &pctx)) {
711 ctx->flags |= E2F_FLAG_ABORT;
712 return;
713 }
714 }
715
716 should_be = (sb->s_log_block_size == 0 &&
717 EXT2FS_CLUSTER_RATIO(fs) == 1) ? 1 : 0;
718 if (sb->s_first_data_block != should_be) {
719 pctx.blk = sb->s_first_data_block;
720 pctx.blk2 = should_be;
721 fix_problem(ctx, PR_0_FIRST_DATA_BLOCK, &pctx);
722 ctx->flags |= E2F_FLAG_ABORT;
723 return;
724 }
725
726 if (EXT2_INODE_SIZE(sb) > EXT2_GOOD_OLD_INODE_SIZE) {
727 unsigned min =
728 sizeof(((struct ext2_inode_large *) 0)->i_extra_isize) +
729 sizeof(((struct ext2_inode_large *) 0)->i_checksum_hi);
730 unsigned max = EXT2_INODE_SIZE(sb) - EXT2_GOOD_OLD_INODE_SIZE;
731 pctx.num = sb->s_min_extra_isize;
732 if (sb->s_min_extra_isize &&
733 (sb->s_min_extra_isize < min ||
734 sb->s_min_extra_isize > max ||
735 sb->s_min_extra_isize & 3) &&
736 fix_problem(ctx, PR_0_BAD_MIN_EXTRA_ISIZE, &pctx)) {
737 sb->s_min_extra_isize =
738 (sizeof(struct ext2_inode_large) -
739 EXT2_GOOD_OLD_INODE_SIZE);
740 ext2fs_mark_super_dirty(fs);
741 }
742 pctx.num = sb->s_want_extra_isize;
743 if (sb->s_want_extra_isize &&
744 (sb->s_want_extra_isize < min ||
745 sb->s_want_extra_isize > max ||
746 sb->s_want_extra_isize & 3) &&
747 fix_problem(ctx, PR_0_BAD_WANT_EXTRA_ISIZE, &pctx)) {
748 sb->s_want_extra_isize =
749 (sizeof(struct ext2_inode_large) -
750 EXT2_GOOD_OLD_INODE_SIZE);
751 ext2fs_mark_super_dirty(fs);
752 }
753 }
754
755 /* Are metadata_csum and uninit_bg both set? */
756 if (ext2fs_has_feature_metadata_csum(fs->super) &&
757 ext2fs_has_feature_gdt_csum(fs->super) &&
758 fix_problem(ctx, PR_0_META_AND_GDT_CSUM_SET, &pctx)) {
759 ext2fs_clear_feature_gdt_csum(fs->super);
760 ext2fs_mark_super_dirty(fs);
761 for (i = 0; i < fs->group_desc_count; i++)
762 ext2fs_group_desc_csum_set(fs, i);
763 }
764
765 /* We can't have ^metadata_csum,metadata_csum_seed */
766 if (!ext2fs_has_feature_metadata_csum(fs->super) &&
767 ext2fs_has_feature_csum_seed(fs->super) &&
768 fix_problem(ctx, PR_0_CSUM_SEED_WITHOUT_META_CSUM, &pctx)) {
769 ext2fs_clear_feature_csum_seed(fs->super);
770 fs->super->s_checksum_seed = 0;
771 ext2fs_mark_super_dirty(fs);
772 }
773
774 /* Is 64bit set and extents unset? */
775 if (ext2fs_has_feature_64bit(fs->super) &&
776 !ext2fs_has_feature_extents(fs->super) &&
777 fix_problem(ctx, PR_0_64BIT_WITHOUT_EXTENTS, &pctx)) {
778 ext2fs_set_feature_extents(fs->super);
779 ext2fs_mark_super_dirty(fs);
780 }
781
782 /* Did user ask us to convert files to extents? */
783 if (ctx->options & E2F_OPT_CONVERT_BMAP) {
784 ext2fs_set_feature_extents(fs->super);
785 ext2fs_mark_super_dirty(fs);
786 }
787
788 if (ext2fs_has_feature_meta_bg(fs->super) &&
789 (fs->super->s_first_meta_bg > fs->desc_blocks)) {
790 pctx.group = fs->desc_blocks;
791 pctx.num = fs->super->s_first_meta_bg;
792 if (fix_problem(ctx, PR_0_FIRST_META_BG_TOO_BIG, &pctx)) {
793 ext2fs_clear_feature_meta_bg(fs->super);
794 fs->super->s_first_meta_bg = 0;
795 ext2fs_mark_super_dirty(fs);
796 }
797 }
798
799 /*
800 * Verify the group descriptors....
801 */
802 first_block = sb->s_first_data_block;
803 last_block = ext2fs_blocks_count(sb)-1;
804
805 csum_flag = ext2fs_has_group_desc_csum(fs);
806 for (i = 0; i < fs->group_desc_count; i++) {
807 pctx.group = i;
808
809 if (!ext2fs_has_feature_flex_bg(fs->super)) {
810 first_block = ext2fs_group_first_block2(fs, i);
811 last_block = ext2fs_group_last_block2(fs, i);
812 }
813
814 if ((ext2fs_block_bitmap_loc(fs, i) < first_block) ||
815 (ext2fs_block_bitmap_loc(fs, i) > last_block)) {
816 pctx.blk = ext2fs_block_bitmap_loc(fs, i);
817 if (fix_problem(ctx, PR_0_BB_NOT_GROUP, &pctx))
818 ext2fs_block_bitmap_loc_set(fs, i, 0);
819 }
820 if (ext2fs_block_bitmap_loc(fs, i) == 0) {
821 ctx->invalid_block_bitmap_flag[i]++;
822 ctx->invalid_bitmaps++;
823 }
824 if ((ext2fs_inode_bitmap_loc(fs, i) < first_block) ||
825 (ext2fs_inode_bitmap_loc(fs, i) > last_block)) {
826 pctx.blk = ext2fs_inode_bitmap_loc(fs, i);
827 if (fix_problem(ctx, PR_0_IB_NOT_GROUP, &pctx))
828 ext2fs_inode_bitmap_loc_set(fs, i, 0);
829 }
830 if (ext2fs_inode_bitmap_loc(fs, i) == 0) {
831 ctx->invalid_inode_bitmap_flag[i]++;
832 ctx->invalid_bitmaps++;
833 }
834 if ((ext2fs_inode_table_loc(fs, i) < first_block) ||
835 ((ext2fs_inode_table_loc(fs, i) +
836 fs->inode_blocks_per_group - 1) > last_block)) {
837 pctx.blk = ext2fs_inode_table_loc(fs, i);
838 if (fix_problem(ctx, PR_0_ITABLE_NOT_GROUP, &pctx))
839 ext2fs_inode_table_loc_set(fs, i, 0);
840 }
841 if (ext2fs_inode_table_loc(fs, i) == 0) {
842 ctx->invalid_inode_table_flag[i]++;
843 ctx->invalid_bitmaps++;
844 }
845 free_blocks += ext2fs_bg_free_blocks_count(fs, i);
846 free_inodes += ext2fs_bg_free_inodes_count(fs, i);
847
848 if ((ext2fs_bg_free_blocks_count(fs, i) > sb->s_blocks_per_group) ||
849 (ext2fs_bg_free_inodes_count(fs, i) > sb->s_inodes_per_group) ||
850 (ext2fs_bg_used_dirs_count(fs, i) > sb->s_inodes_per_group))
851 ext2fs_unmark_valid(fs);
852
853 should_be = 0;
854 if (!ext2fs_group_desc_csum_verify(fs, i)) {
855 pctx.csum1 = ext2fs_bg_checksum(fs, i);
856 pctx.csum2 = ext2fs_group_desc_csum(fs, i);
857 if (fix_problem(ctx, PR_0_GDT_CSUM, &pctx)) {
858 ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
859 ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT);
860 ext2fs_bg_itable_unused_set(fs, i, 0);
861 should_be = 1;
862 }
863 ext2fs_unmark_valid(fs);
864 }
865
866 if (!csum_flag &&
867 (ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) ||
868 ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT) ||
869 ext2fs_bg_itable_unused(fs, i) != 0)) {
870 if (fix_problem(ctx, PR_0_GDT_UNINIT, &pctx)) {
871 ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
872 ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT);
873 ext2fs_bg_itable_unused_set(fs, i, 0);
874 should_be = 1;
875 }
876 ext2fs_unmark_valid(fs);
877 }
878
879 if (i == fs->group_desc_count - 1 &&
880 ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT)) {
881 if (fix_problem(ctx, PR_0_BB_UNINIT_LAST, &pctx)) {
882 ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
883 should_be = 1;
884 }
885 ext2fs_unmark_valid(fs);
886 }
887
888 if (csum_flag &&
889 (ext2fs_bg_itable_unused(fs, i) > ext2fs_bg_free_inodes_count(fs, i) ||
890 ext2fs_bg_itable_unused(fs, i) > sb->s_inodes_per_group)) {
891 pctx.blk = ext2fs_bg_itable_unused(fs, i);
892 if (fix_problem(ctx, PR_0_GDT_ITABLE_UNUSED, &pctx)) {
893 ext2fs_bg_itable_unused_set(fs, i, 0);
894 should_be = 1;
895 }
896 ext2fs_unmark_valid(fs);
897 }
898
899 if (should_be)
900 ext2fs_group_desc_csum_set(fs, i);
901 /* If the user aborts e2fsck by typing ^C, stop right away */
902 if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
903 return;
904 }
905
906 ctx->free_blocks = EXT2FS_C2B(fs, free_blocks);
907 ctx->free_inodes = free_inodes;
908
909 if ((ext2fs_free_blocks_count(sb) > ext2fs_blocks_count(sb)) ||
910 (sb->s_free_inodes_count > sb->s_inodes_count))
911 ext2fs_unmark_valid(fs);
912
913
914 /*
915 * If we have invalid bitmaps, set the error state of the
916 * filesystem.
917 */
918 if (ctx->invalid_bitmaps && !(ctx->options & E2F_OPT_READONLY)) {
919 sb->s_state &= ~EXT2_VALID_FS;
920 ext2fs_mark_super_dirty(fs);
921 }
922
923 clear_problem_context(&pctx);
924
925 #ifndef EXT2_SKIP_UUID
926 /*
927 * If the UUID field isn't assigned, assign it.
928 * Skip if checksums are enabled and the filesystem is mounted,
929 * if the id changes under the kernel remounting rw may fail.
930 */
931 if (!(ctx->options & E2F_OPT_READONLY) && uuid_is_null(sb->s_uuid) &&
932 !ext2fs_has_feature_metadata_csum(ctx->fs->super) &&
933 (!csum_flag || !(ctx->mount_flags & EXT2_MF_MOUNTED))) {
934 if (fix_problem(ctx, PR_0_ADD_UUID, &pctx)) {
935 uuid_generate(sb->s_uuid);
936 ext2fs_init_csum_seed(fs);
937 fs->flags |= EXT2_FLAG_DIRTY;
938 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
939 }
940 }
941 #endif
942
943 /*
944 * Check to see if we should disable the test_fs flag
945 */
946 profile_get_boolean(ctx->profile, "options",
947 "clear_test_fs_flag", 0, 1,
948 &clear_test_fs_flag);
949 if (!(ctx->options & E2F_OPT_READONLY) &&
950 clear_test_fs_flag &&
951 (fs->super->s_flags & EXT2_FLAGS_TEST_FILESYS) &&
952 (fs_proc_check("ext4") || check_for_modules("ext4"))) {
953 if (fix_problem(ctx, PR_0_CLEAR_TESTFS_FLAG, &pctx)) {
954 fs->super->s_flags &= ~EXT2_FLAGS_TEST_FILESYS;
955 fs->flags |= EXT2_FLAG_DIRTY;
956 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
957 }
958 }
959
960 /*
961 * For the Hurd, check to see if the filetype option is set,
962 * since it doesn't support it.
963 */
964 if (!(ctx->options & E2F_OPT_READONLY) &&
965 fs->super->s_creator_os == EXT2_OS_HURD &&
966 ext2fs_has_feature_filetype(fs->super)) {
967 if (fix_problem(ctx, PR_0_HURD_CLEAR_FILETYPE, &pctx)) {
968 ext2fs_clear_feature_filetype(fs->super);
969 ext2fs_mark_super_dirty(fs);
970 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
971 }
972 }
973
974 /*
975 * If we have any of the compatibility flags set, we need to have a
976 * revision 1 filesystem. Most kernels will not check the flags on
977 * a rev 0 filesystem and we may have corruption issues because of
978 * the incompatible changes to the filesystem.
979 */
980 if (!(ctx->options & E2F_OPT_READONLY) &&
981 fs->super->s_rev_level == EXT2_GOOD_OLD_REV &&
982 (fs->super->s_feature_compat ||
983 fs->super->s_feature_ro_compat ||
984 fs->super->s_feature_incompat) &&
985 fix_problem(ctx, PR_0_FS_REV_LEVEL, &pctx)) {
986 ext2fs_update_dynamic_rev(fs);
987 ext2fs_mark_super_dirty(fs);
988 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
989 }
990
991 /*
992 * Clean up any orphan inodes, if present.
993 */
994 if (!(ctx->options & E2F_OPT_READONLY) && release_orphan_inodes(ctx)) {
995 fs->super->s_state &= ~EXT2_VALID_FS;
996 ext2fs_mark_super_dirty(fs);
997 }
998
999 /*
1000 * Unfortunately, due to Windows' unfortunate design decision
1001 * to configure the hardware clock to tick localtime, instead
1002 * of the more proper and less error-prone UTC time, many
1003 * users end up in the situation where the system clock is
1004 * incorrectly set at the time when e2fsck is run.
1005 *
1006 * Historically this was usually due to some distributions
1007 * having buggy init scripts and/or installers that didn't
1008 * correctly detect this case and take appropriate
1009 * countermeasures. However, it's still possible, despite the
1010 * best efforts of init script and installer authors to not be
1011 * able to detect this misconfiguration, usually due to a
1012 * buggy or misconfigured virtualization manager or the
1013 * installer not having access to a network time server during
1014 * the installation process. So by default, we allow the
1015 * superblock times to be fudged by up to 24 hours. This can
1016 * be disabled by setting options.accept_time_fudge to the
1017 * boolean value of false in e2fsck.conf. We also support
1018 * options.buggy_init_scripts for backwards compatibility.
1019 */
1020 profile_get_boolean(ctx->profile, "options", "accept_time_fudge",
1021 0, 1, &accept_time_fudge);
1022 profile_get_boolean(ctx->profile, "options", "buggy_init_scripts",
1023 0, accept_time_fudge, &accept_time_fudge);
1024 ctx->time_fudge = accept_time_fudge ? 86400 : 0;
1025
1026 profile_get_boolean(ctx->profile, "options", "broken_system_clock",
1027 0, 0, &broken_system_clock);
1028
1029 /*
1030 * Check to see if the superblock last mount time or last
1031 * write time is in the future.
1032 */
1033 if (!broken_system_clock &&
1034 !(ctx->flags & E2F_FLAG_TIME_INSANE) &&
1035 fs->super->s_mtime > (__u32) ctx->now) {
1036 pctx.num = fs->super->s_mtime;
1037 problem = PR_0_FUTURE_SB_LAST_MOUNT;
1038 if (fs->super->s_mtime <= (__u32) ctx->now + ctx->time_fudge)
1039 problem = PR_0_FUTURE_SB_LAST_MOUNT_FUDGED;
1040 if (fix_problem(ctx, problem, &pctx)) {
1041 fs->super->s_mtime = ctx->now;
1042 fs->flags |= EXT2_FLAG_DIRTY;
1043 }
1044 }
1045 if (!broken_system_clock &&
1046 !(ctx->flags & E2F_FLAG_TIME_INSANE) &&
1047 fs->super->s_wtime > (__u32) ctx->now) {
1048 pctx.num = fs->super->s_wtime;
1049 problem = PR_0_FUTURE_SB_LAST_WRITE;
1050 if (fs->super->s_wtime <= (__u32) ctx->now + ctx->time_fudge)
1051 problem = PR_0_FUTURE_SB_LAST_WRITE_FUDGED;
1052 if (fix_problem(ctx, problem, &pctx)) {
1053 fs->super->s_wtime = ctx->now;
1054 fs->flags |= EXT2_FLAG_DIRTY;
1055 }
1056 }
1057
1058 e2fsck_validate_quota_inodes(ctx);
1059
1060 /*
1061 * Move the ext3 journal file, if necessary.
1062 */
1063 e2fsck_move_ext3_journal(ctx);
1064
1065 /*
1066 * Fix journal hint, if necessary
1067 */
1068 e2fsck_fix_ext3_journal_hint(ctx);
1069
1070 /*
1071 * Add dirhash hint if necessary
1072 */
1073 e2fsck_fix_dirhash_hint(ctx);
1074
1075 /*
1076 * Hide quota inodes if necessary.
1077 */
1078 e2fsck_hide_quota(ctx);
1079
1080 return;
1081 }
1082
1083 /*
1084 * Check to see if we should backup the master sb to the backup super
1085 * blocks. Returns non-zero if the sb should be backed up.
1086 */
1087
1088 /*
1089 * A few flags are set on the fly by the kernel, but only in the
1090 * primary superblock. This is actually a bad thing, and we should
1091 * try to discourage it in the future. In particular, for the newer
1092 * ext4 files, especially EXT4_FEATURE_RO_COMPAT_DIR_NLINK and
1093 * EXT3_FEATURE_INCOMPAT_EXTENTS. So some of these may go away in the
1094 * future. EXT3_FEATURE_INCOMPAT_RECOVER may also get set when
1095 * copying the primary superblock during online resize.
1096 *
1097 * The kernel will set EXT2_FEATURE_COMPAT_EXT_ATTR, but
1098 * unfortunately, we shouldn't ignore it since if it's not set in the
1099 * backup, the extended attributes in the filesystem will be stripped
1100 * away.
1101 */
1102 #define FEATURE_RO_COMPAT_IGNORE (EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
1103 EXT4_FEATURE_RO_COMPAT_DIR_NLINK)
1104 #define FEATURE_INCOMPAT_IGNORE (EXT3_FEATURE_INCOMPAT_EXTENTS| \
1105 EXT3_FEATURE_INCOMPAT_RECOVER)
1106
1107 int check_backup_super_block(e2fsck_t ctx)
1108 {
1109 ext2_filsys fs = ctx->fs;
1110 errcode_t retval;
1111 dgrp_t g;
1112 blk64_t sb;
1113 int ret = 0;
1114 char buf[SUPERBLOCK_SIZE];
1115 struct ext2_super_block *backup_sb;
1116
1117 /*
1118 * If we are already writing out the backup blocks, then we
1119 * don't need to test. Also, if the filesystem is invalid, or
1120 * the check was aborted or cancelled, we also don't want to
1121 * do the backup. If the filesystem was opened read-only then
1122 * we can't do the backup.
1123 */
1124 if (((fs->flags & EXT2_FLAG_MASTER_SB_ONLY) == 0) ||
1125 !ext2fs_test_valid(fs) ||
1126 (fs->super->s_state & EXT2_ERROR_FS) ||
1127 (ctx->flags & (E2F_FLAG_ABORT | E2F_FLAG_CANCEL)) ||
1128 (ctx->options & E2F_OPT_READONLY))
1129 return 0;
1130
1131 for (g = 1; g < fs->group_desc_count; g++) {
1132 if (!ext2fs_bg_has_super(fs, g))
1133 continue;
1134
1135 sb = ext2fs_group_first_block2(fs, g);
1136
1137 retval = io_channel_read_blk(fs->io, sb, -SUPERBLOCK_SIZE,
1138 buf);
1139 if (retval)
1140 continue;
1141 backup_sb = (struct ext2_super_block *) buf;
1142 #ifdef WORDS_BIGENDIAN
1143 ext2fs_swap_super(backup_sb);
1144 #endif
1145 if ((backup_sb->s_magic != EXT2_SUPER_MAGIC) ||
1146 (backup_sb->s_rev_level > EXT2_LIB_CURRENT_REV) ||
1147 ((backup_sb->s_log_block_size + EXT2_MIN_BLOCK_LOG_SIZE) >
1148 EXT2_MAX_BLOCK_LOG_SIZE) ||
1149 (EXT2_INODE_SIZE(backup_sb) < EXT2_GOOD_OLD_INODE_SIZE))
1150 continue;
1151
1152 #define SUPER_INCOMPAT_DIFFERENT(x) \
1153 ((fs->super->x & ~FEATURE_INCOMPAT_IGNORE) != \
1154 (backup_sb->x & ~FEATURE_INCOMPAT_IGNORE))
1155 #define SUPER_RO_COMPAT_DIFFERENT(x) \
1156 ((fs->super->x & ~FEATURE_RO_COMPAT_IGNORE) != \
1157 (backup_sb->x & ~FEATURE_RO_COMPAT_IGNORE))
1158 #define SUPER_DIFFERENT(x) \
1159 (fs->super->x != backup_sb->x)
1160
1161 if (SUPER_DIFFERENT(s_feature_compat) ||
1162 SUPER_INCOMPAT_DIFFERENT(s_feature_incompat) ||
1163 SUPER_RO_COMPAT_DIFFERENT(s_feature_ro_compat) ||
1164 SUPER_DIFFERENT(s_blocks_count) ||
1165 SUPER_DIFFERENT(s_blocks_count_hi) ||
1166 SUPER_DIFFERENT(s_inodes_count) ||
1167 memcmp(fs->super->s_uuid, backup_sb->s_uuid,
1168 sizeof(fs->super->s_uuid)))
1169 ret = 1;
1170 break;
1171 }
1172 return ret;
1173 }