]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsck: Fix check to see if an extent-based file is fragmented
authorTheodore Ts'o <tytso@mit.edu>
Mon, 11 Aug 2008 02:43:24 +0000 (22:43 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 11 Aug 2008 02:43:24 +0000 (22:43 -0400)
Also added support for "e2fsck -E fragcheck" which issues a
comprehensive report of discontiguous file extents.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
20 files changed:
e2fsck/e2fsck.8.in
e2fsck/e2fsck.h
e2fsck/pass1.c
e2fsck/unix.c
tests/d_loaddump/expect
tests/f_badjour_indblks/expect.1
tests/f_badjour_indblks/expect.2
tests/f_dup_resize/expect.2
tests/f_extents2/expect.1
tests/f_extents2/expect.2
tests/f_full_bg/expect.1
tests/f_full_bg/expect.2
tests/f_uninit_last_uninit/expect.1
tests/f_uninit_last_uninit/expect.2
tests/f_zero_inode_size/expect.1
tests/f_zero_inode_size/expect.2
tests/m_dasd_bs/expect.1
tests/m_large_file/expect.1
tests/m_std/expect.1
tests/m_uninit/expect.1

index d176fb78f83b18e8a5a66e0d585d1b7b84a75a8b..9707a4c30ed3acebf5fcbfb057c6d75729d2494a 100644 (file)
@@ -185,9 +185,14 @@ following options are supported:
 .RS 1.2i
 .TP
 .BI ea_ver= extended_attribute_version
-Assume the format of the extended attribute blocks in the filesystem is
-the specified version number.  The version number may be 1 or 2.  The
-default extended attribute version format is 2.
+Set the version of the extended attribute blocks which
+.B e2fsck
+will require while checking the filesystem.  The version number may 
+be 1 or 2.  The default extended attribute version format is 2.
+.TP
+.BI fragcheck
+During pass 1, print a detailed report of any discontiguous blocks for
+files in the filesystem.
 .RE
 .TP
 .B \-f
index 5523ed69721c5422392fbdd2794e1172731e1d78..1d76f3771218486048c457c25c5a000d1c1a45b5 100644 (file)
@@ -154,6 +154,7 @@ struct resource_track {
 #define E2F_OPT_FORCE          0x0100
 #define E2F_OPT_WRITECHECK     0x0200
 #define E2F_OPT_COMPRESS_DIRS  0x0400
+#define E2F_OPT_FRAGCHECK      0x0800
 
 /*
  * E2fsck flags
index c240195f9aa121010cb97652d5f45baf361f5e5a..c2f7b3b7356b7759c5b44ca6b1158a62139c541b 100644 (file)
@@ -1694,6 +1694,18 @@ static void scan_extent_node(e2fsck_t ctx, struct problem_context *pctx,
                        goto next;
                }
 
+               if ((pb->previous_block != 0) &&
+                   (pb->previous_block+1 != extent.e_pblk)) {
+                       if (ctx->options & E2F_OPT_FRAGCHECK)
+                               printf(("%6lu: expecting %6lu actual extent "
+                                       "phys %6lu log %lu len %lu\n"),
+                                      (unsigned long) pctx->ino,
+                                      (unsigned long) pb->previous_block+1,
+                                      (unsigned long) extent.e_pblk,
+                                      (unsigned long) extent.e_lblk,
+                                      (unsigned long) extent.e_len);
+                       pb->fragmented = 1;
+               }
                for (blk = extent.e_pblk, blockcnt = extent.e_lblk, i = 0;
                     i < extent.e_len;
                     blk++, blockcnt++, i++) {
@@ -1712,6 +1724,7 @@ static void scan_extent_node(e2fsck_t ctx, struct problem_context *pctx,
                        }
                }
                pb->num_blocks += extent.e_len;
+               pb->previous_block = extent.e_pblk + extent.e_len - 1;
                start_block = pb->last_block = extent.e_lblk + extent.e_len - 1;
        next:
                pctx->errcode = ext2fs_extent_get(ehandle,
@@ -1740,6 +1753,9 @@ static void check_blocks_extents(e2fsck_t ctx, struct problem_context *pctx,
 
        scan_extent_node(ctx, pctx, pb, 0, ehandle);
 
+       if (pb->fragmented && pb->num_blocks < fs->super->s_blocks_per_group)
+               ctx->fs_fragmented++;
+
        ext2fs_extent_free(ehandle);
 }
 
@@ -2066,9 +2082,16 @@ static int process_block(ext2_filsys fs,
         * file be contiguous.  (Which can never be true for really
         * big files that are greater than a block group.)
         */
-       if (!HOLE_BLKADDR(p->previous_block)) {
-               if (p->previous_block+1 != blk)
+       if (!HOLE_BLKADDR(p->previous_block) && p->ino != EXT2_RESIZE_INO) {
+               if (p->previous_block+1 != blk) {
+                       if (ctx->options & E2F_OPT_FRAGCHECK)
+                               printf(_("%6lu: expecting %6lu got %6lu (%lu)\n"),
+                                      (unsigned long) pctx->ino,
+                                      (unsigned long) p->previous_block+1,
+                                      (unsigned long) blk,
+                                      (unsigned long) blockcnt);
                        p->fragmented = 1;
+               }
        }
        p->previous_block = blk;
 
index 4262906df12d3e7e9b0a4e5de37bae98a48e1be1..379f19aa4b5a54041bc97a4fcdea8523355808d0 100644 (file)
@@ -553,6 +553,9 @@ static void parse_extended_opts(e2fsck_t ctx, const char *opts)
                                continue;
                        }
                        ctx->ext_attr_ver = ea_ver;
+               } else if (strcmp(token, "fragcheck") == 0) {
+                       ctx->options |= E2F_OPT_FRAGCHECK;
+                       continue;
                } else {
                        fprintf(stderr, _("Unknown extended option: %s\n"),
                                token);
@@ -565,8 +568,10 @@ static void parse_extended_opts(e2fsck_t ctx, const char *opts)
                fputs(("\nExtended options are separated by commas, "
                       "and may take an argument which\n"
                       "is set off by an equals ('=') sign.  "
-                       "Valid extended options are:\n"
-                      "\tea_ver=<ea_version (1 or 2)>\n\n"), stderr);
+                      "Valid extended options are:\n"), stderr);
+               fputs(("\tea_ver=<ea_version (1 or 2)>\n"), stderr);
+               fputs(("\tfragcheck\n"), stderr);
+               fputc('\n', stderr);
                exit(1);
        }
 }
index 1fc45618aabe82573980a8f65659f683fd90d188..f66e2183693a05e82997f4b4118a38daf80bd5bd 100644 (file)
@@ -10,7 +10,7 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 12/64 files (8.3% non-contiguous), 158/512 blocks
+test_filesys: 12/64 files (0.0% non-contiguous), 158/512 blocks
 Exit status is 0
 debugfs -R ''dump test_data test.verify'' ./test.img
 Exit status is 0
index c0de516d38d644e4c661715dcdc82a8f840c2c66..0190bf2abdbb6f18b8578aac54e3a910b714436d 100644 (file)
@@ -29,5 +29,5 @@ Creating journal (1024 blocks):  Done.
 *** journal has been re-created - filesystem is now ext3 again ***
 
 test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
-test_filesys: 11/256 files (9.1% non-contiguous), 1112/8192 blocks
+test_filesys: 11/256 files (0.0% non-contiguous), 1112/8192 blocks
 Exit status is 1
index 74153ad2c1e71b944022ed4322fa38ab6ab371d1..35365fad4887987f89841e2d2f8bd4ea2ed76a8a 100644 (file)
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/256 files (9.1% non-contiguous), 1112/8192 blocks
+test_filesys: 11/256 files (0.0% non-contiguous), 1112/8192 blocks
 Exit status is 0
index ed116f46f0c28b60f2009d54fcd329b805aab493..198acb958f5cc6665a92ddb4c79091945139c00f 100644 (file)
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 12/2560 files (16.7% non-contiguous), 485/10240 blocks
+test_filesys: 12/2560 files (8.3% non-contiguous), 485/10240 blocks
 Exit status is 0
index 62ce0ab632389161727f2525c4c92db22fe837b3..094021d58c004899b8334418292c7ff549110039 100644 (file)
@@ -66,5 +66,5 @@ Fix? yes
 
 
 test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
-test_filesys: 18/32 files (0.0% non-contiguous), 145/200 blocks
+test_filesys: 18/32 files (44.4% non-contiguous), 145/200 blocks
 Exit status is 1
index a81164ee293f03d716db472e9926a4c8dae51789..54f781a0b7c69dc48bda0e36d64691770fb59644 100644 (file)
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 18/32 files (0.0% non-contiguous), 145/200 blocks
+test_filesys: 18/32 files (44.4% non-contiguous), 145/200 blocks
 Exit status is 0
index 00819bf6f93c6472eabc66a575706a62e50924bf..3d5453f1714b3532782dde2c89042e5a17d7bbb9 100644 (file)
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/3744 files (9.1% non-contiguous), 685/769 blocks
+test_filesys: 11/3744 files (0.0% non-contiguous), 685/769 blocks
 Exit status is 0
index 00819bf6f93c6472eabc66a575706a62e50924bf..3d5453f1714b3532782dde2c89042e5a17d7bbb9 100644 (file)
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/3744 files (9.1% non-contiguous), 685/769 blocks
+test_filesys: 11/3744 files (0.0% non-contiguous), 685/769 blocks
 Exit status is 0
index 85f05ee2efd700e3e7056c3b6ec42bae792b83d0..248bd290edc401b261ca7679b8d32474c56bf957 100644 (file)
@@ -5,5 +5,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/32 files (9.1% non-contiguous), 105/10000 blocks
+test_filesys: 11/32 files (0.0% non-contiguous), 105/10000 blocks
 Exit status is 0
index 435a8a7bf00fe59be5e3034c613824a8c9ff0a1e..e95e5edef0af269b66079f5d45c9ff49ccff5b2a 100644 (file)
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/32 files (9.1% non-contiguous), 105/10000 blocks
+test_filesys: 11/32 files (0.0% non-contiguous), 105/10000 blocks
 Exit status is 0
index 3e541705ef01981cff82a673f515c2896336502d..9202131f8387b0f6affd6ad338fc7c59ed53b2af 100644 (file)
@@ -6,5 +6,5 @@ Pass 4: Checking reference counts
 Pass 5: Checking group summary information
 
 test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
-test_filesys: 11/2512 files (9.1% non-contiguous), 415/10000 blocks
+test_filesys: 11/2512 files (0.0% non-contiguous), 415/10000 blocks
 Exit status is 1
index a6f1434e4dbd26c2a62603b8bcaf197ddc1d99e4..da948061d315e16817ad7cae39bb775e732a9fa6 100644 (file)
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/2512 files (9.1% non-contiguous), 415/10000 blocks
+test_filesys: 11/2512 files (0.0% non-contiguous), 415/10000 blocks
 Exit status is 0
index 6ad145e4d0e5c4377e12e298f967d52185ed80cc..59fc457b652c4c474b76ce05b63ad66a3700ff4f 100644 (file)
@@ -22,7 +22,7 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/16384 files (9.1% non-contiguous), 1104/32768 blocks
+test_filesys: 11/16384 files (0.0% non-contiguous), 1104/32768 blocks
 Exit status is 0
 
 Filesystem volume name:   <none>
index 212ed60770248ff6939eb7d718ae20fa3d02eecc..ae27f02192a2096ba39e57cda1e5ed324d9c7d32 100644 (file)
@@ -20,7 +20,7 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/64 files (9.1% non-contiguous), 17/16384 blocks
+test_filesys: 11/64 files (0.0% non-contiguous), 17/16384 blocks
 Exit status is 0
 
 Filesystem volume name:   <none>
index 1139dab9f258cde94d5b8d7973f8956bc599644f..9f5e66e6462c618e0d028761fba8591b4d86eea7 100644 (file)
@@ -22,7 +22,7 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/16384 files (9.1% non-contiguous), 3364/65536 blocks
+test_filesys: 11/16384 files (0.0% non-contiguous), 3364/65536 blocks
 Exit status is 0
 
 Filesystem volume name:   <none>
index ed57e42b66492d5a8d00e79d4808c94674916ba1..02649d88a32bb072f056d134265df8fd2e23e2cf 100644 (file)
@@ -22,7 +22,7 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/32768 files (9.1% non-contiguous), 5691/131072 blocks
+test_filesys: 11/32768 files (0.0% non-contiguous), 5691/131072 blocks
 Exit status is 0
 
 Filesystem volume name:   <none>