diff --git a/SOURCES/e2fsprogs-1.42.11-e2fsck-free-ctx-fs-not-fs-at-the-end-of-fsck.patch b/SOURCES/e2fsprogs-1.42.11-e2fsck-free-ctx-fs-not-fs-at-the-end-of-fsck.patch new file mode 100644 index 0000000..7edaf7e --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.11-e2fsck-free-ctx-fs-not-fs-at-the-end-of-fsck.patch @@ -0,0 +1,33 @@ +From a82d88ea99d3c5c21bf538b886da0482bf143fd5 Mon Sep 17 00:00:00 2001 +From: "Darrick J. Wong" +Date: Thu, 24 Jul 2014 21:03:54 -0400 +Subject: [PATCH] e2fsck: free ctx->fs, not fs, at the end of fsck + +When we call ext2fs_close_free at the end of main(), we need to supply +the address of ctx->fs, because the subsequent e2fsck_free_context +call will try to access ctx->fs (which is now set to a freed block) to +see if it should free the directory block list. This is clearly not +desirable, so fix the problem. + +Signed-off-by: Darrick J. Wong +Signed-off-by: Theodore Ts'o +--- + e2fsck/unix.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/e2fsck/unix.c b/e2fsck/unix.c +index 8d1bdf3e..fc05bdee 100644 +--- a/e2fsck/unix.c ++++ b/e2fsck/unix.c +@@ -1774,7 +1774,7 @@ no_journal: + io_channel_flush(ctx->fs->io); + print_resource_track(ctx, NULL, &ctx->global_rtrack, ctx->fs->io); + +- ext2fs_close_free(&fs); ++ ext2fs_close_free(&ctx->fs); + free(ctx->journal_name); + + e2fsck_free_context(ctx); +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-Clarify-how-the-description-of-the-dir_nlink-feature.patch b/SOURCES/e2fsprogs-1.42.9-14-Clarify-how-the-description-of-the-dir_nlink-feature.patch new file mode 100644 index 0000000..24b359a --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-Clarify-how-the-description-of-the-dir_nlink-feature.patch @@ -0,0 +1,34 @@ +From 72f9ce9c2e6b7b41963c36096d3955e010df9033 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Sun, 23 Jul 2017 18:51:22 -0400 +Subject: [PATCH 1/2] Clarify how the description of the dir_nlink feature in + the ext4 man page + +commit 7d8f358cdce948df57b1001b9c278f33519afa86 + +Signed-off-by: Theodore Ts'o +--- + misc/ext4.5.in | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/misc/ext4.5.in b/misc/ext4.5.in +index dcef6c08..366916d8 100644 +--- a/misc/ext4.5.in ++++ b/misc/ext4.5.in +@@ -68,7 +68,12 @@ ext2 file systems. + .TP + .B dir_nlink + .br +-This ext4 feature allows more than 65000 subdirectories per directory. ++Normally ext4 allows an inode to have no more than 65,000 hard links. ++This applies to files as well as directories, which means that there can ++be no more than 64,998 subdirectories in a directory (because each of ++the '..' entries counts as a hard link). This feature lifts this limit ++by causing ext4 to use a links count of 1 to indicate that the number of ++hard links to a directory is not known. + .TP + .B extent + .br +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-fd-leak-in-reserve_stdio_fds.patch b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-fd-leak-in-reserve_stdio_fds.patch new file mode 100644 index 0000000..0b8fee0 --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-fd-leak-in-reserve_stdio_fds.patch @@ -0,0 +1,32 @@ +From a2a3247ba03bcb37f80b04b473112079968b9513 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Sat, 11 Aug 2018 20:47:08 -0400 +Subject: [PATCH 10/16] e2fsck: fix fd leak in reserve_stdio_fds + +commit ac5936d78d520b9edac15994728bb8b0364814e6 + +Signed-off-by: Theodore Ts'o +Reviewed-by: Lukas Czerner +--- + e2fsck/unix.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/e2fsck/unix.c b/e2fsck/unix.c +index 5fcc9d99..a434f1e6 100644 +--- a/e2fsck/unix.c ++++ b/e2fsck/unix.c +@@ -604,9 +604,10 @@ static void reserve_stdio_fds(void) + fprintf(stderr, _("ERROR: Couldn't open " + "/dev/null (%s)\n"), + strerror(errno)); +- break; ++ return; + } + } ++ (void) close(fd); + } + + #ifdef HAVE_SIGNAL_H +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-free-pointer-dereferences.patch b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-free-pointer-dereferences.patch new file mode 100644 index 0000000..1f14d27 --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-free-pointer-dereferences.patch @@ -0,0 +1,51 @@ +From 6efb6613deeca55b8e5673c77644890e7f5e4738 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Wed, 8 Oct 2014 11:18:41 -0400 +Subject: [PATCH 13/16] e2fsck: fix free pointer dereferences + +commit ebdf895b43a1ce499e4d2556a201e2a753fc422f + +Commit 47fee2ef6a23a introduces some free pointer dereference bugs by +not clearing ctx->fs after calling ext2fs_close_free(). + +Reported-by: Matthias Andree +Cc: Lukas Czerner +Signed-off-by: Theodore Ts'o +--- + e2fsck/unix.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/e2fsck/unix.c b/e2fsck/unix.c +index 84b9a454..bbf65d90 100644 +--- a/e2fsck/unix.c ++++ b/e2fsck/unix.c +@@ -458,7 +458,7 @@ static void check_if_skip(e2fsck_t ctx) + } + log_out(ctx, "\n"); + skip: +- ext2fs_close_free(&fs); ++ ext2fs_close_free(&ctx->fs); + e2fsck_free_context(ctx); + exit(FSCK_OK); + } +@@ -1461,7 +1461,7 @@ failure: + /* + * Restart in order to reopen fs but this time start mmp. + */ +- ext2fs_close_free(&fs); ++ ext2fs_close_free(&ctx->fs); + flags &= ~EXT2_FLAG_SKIP_MMP; + goto restart; + } +@@ -1690,7 +1690,7 @@ no_journal: + _("while resetting context")); + fatal_error(ctx, 0); + } +- ext2fs_close_free(&fs); ++ ext2fs_close_free(&ctx->fs); + goto restart; + } + if (run_result & E2F_FLAG_CANCEL) { +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-last-mount-time-and-last-write-time-in-pr.patch b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-last-mount-time-and-last-write-time-in-pr.patch new file mode 100644 index 0000000..d7a24af --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-last-mount-time-and-last-write-time-in-pr.patch @@ -0,0 +1,45 @@ +From 0d70bb1ca641ac31c84130e2d701ea296bc059fb Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Fri, 4 Jul 2014 16:24:18 -0400 +Subject: [PATCH 15/16] e2fsck: fix last mount time and last write time in + preen mode + +commit 87aca2ad028b9841d3ec32edd858ccc91d96ab4c + +Fixing last mount time and last write time is safe - there's no risk of +loosing any important information or making corruption significantly +worse even if we get it wrong. So let's just fix these times in preen +mode. This allows initrd to automatically check and mount root +filesystem in case system clock is wrong without having to manually set +broken_system_clock variable (openSUSE uses broken_system_clock by default +to avoid these problems during boot but this disables time-based checks +even on systems where clock is fine so that's not ideal either). + +Signed-off-by: Jan Kara +Signed-off-by: Theodore Ts'o +--- + e2fsck/problem.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/e2fsck/problem.c b/e2fsck/problem.c +index a01b2560..1aac7851 100644 +--- a/e2fsck/problem.c ++++ b/e2fsck/problem.c +@@ -336,12 +336,12 @@ static struct e2fsck_problem problem_table[] = { + /* Last mount time is in the future */ + { PR_0_FUTURE_SB_LAST_MOUNT, + N_("@S last mount time (%t,\n\tnow = %T) is in the future.\n"), +- PROMPT_FIX, PR_NO_OK }, ++ PROMPT_FIX, PR_PREEN_OK | PR_NO_OK }, + + /* Last write time is in the future */ + { PR_0_FUTURE_SB_LAST_WRITE, + N_("@S last write time (%t,\n\tnow = %T) is in the future.\n"), +- PROMPT_FIX, PR_NO_OK }, ++ PROMPT_FIX, PR_PREEN_OK | PR_NO_OK }, + + { PR_0_EXTERNAL_JOURNAL_HINT, + N_("@S hint for external superblock @s %X. "), +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-off-by-one-bounds-check-on-group-number.patch b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-off-by-one-bounds-check-on-group-number.patch new file mode 100644 index 0000000..68aa5a1 --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-off-by-one-bounds-check-on-group-number.patch @@ -0,0 +1,39 @@ +From 2ab3543e3b3330317769adcbe4bdb2f3c0b855e9 Mon Sep 17 00:00:00 2001 +From: "Darrick J. Wong" +Date: Thu, 24 Jul 2014 22:19:27 -0400 +Subject: [PATCH 14/16] e2fsck: fix off-by-one bounds check on group number + +commit b4f724c8a90987d4785fd1accfe69c125567be39 + +Since fs->group_desc_count is the number of block groups, the number +of the last group is always one less than this count. Fix the bounds +check to reflect that. + +This flaw shouldn't have any user-visible side effects, since the +block bitmap test based on last_grp later on can handle overbig block +numbers. + +Signed-off-by: Darrick J. Wong +Signed-off-by: Theodore Ts'o +--- + e2fsck/pass1.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c +index 71b3000a..b58a0ca7 100644 +--- a/e2fsck/pass1.c ++++ b/e2fsck/pass1.c +@@ -2599,8 +2599,8 @@ static void new_table_block(e2fsck_t ctx, blk64_t first_block, dgrp_t group, + first_block = ext2fs_group_first_block2(fs, + flexbg_size * flexbg); + last_grp = group | (flexbg_size - 1); +- if (last_grp > fs->group_desc_count) +- last_grp = fs->group_desc_count; ++ if (last_grp >= fs->group_desc_count) ++ last_grp = fs->group_desc_count - 1; + last_block = ext2fs_group_last_block2(fs, last_grp); + } else + last_block = ext2fs_group_last_block2(fs, group); +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-potential-Floating-Point-Exception-in-sho.patch b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-potential-Floating-Point-Exception-in-sho.patch new file mode 100644 index 0000000..40447ab --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-fix-potential-Floating-Point-Exception-in-sho.patch @@ -0,0 +1,66 @@ +From 63eafe15eb224f1130d7e359db088fd620187ba6 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Tue, 12 Dec 2017 21:46:36 -0500 +Subject: [PATCH 11/16] e2fsck: fix potential Floating Point Exception in + show_stats() + +commit 53600d306dbb0eb901a04d76a4a97f45777d39c8 + +If the free inodes count in the superblock is equal to the inodes +count in the superblock (which is not possible with a valid file +system and will be fixed by e2fsck unless it is prevented by, for +example, e2fsck -n), it is possible for e2fsck to crash due to a +divide by zero error. + +Fix this potential bug. + +Addresses-Debian-Bug: #879220 + +Signed-off-by: Theodore Ts'o +--- + e2fsck/unix.c | 20 +++++++++++--------- + 1 file changed, 11 insertions(+), 9 deletions(-) + +diff --git a/e2fsck/unix.c b/e2fsck/unix.c +index a434f1e6..84b9a454 100644 +--- a/e2fsck/unix.c ++++ b/e2fsck/unix.c +@@ -103,7 +103,7 @@ static void show_stats(e2fsck_t ctx) + unsigned int dir_links; + unsigned int num_files, num_links; + __u32 *mask, m; +- int frag_percent_file, frag_percent_dir, frag_percent_total; ++ int frag_percent_file = 0, frag_percent_dir = 0, frag_percent_total = 0; + int i, j, printed = 0; + + dir_links = 2 * ctx->fs_directory_count - 1; +@@ -116,16 +116,18 @@ static void show_stats(e2fsck_t ctx) + blocks_used = (ext2fs_blocks_count(fs->super) - + ext2fs_free_blocks_count(fs->super)); + +- frag_percent_file = (10000 * ctx->fs_fragmented) / inodes_used; +- frag_percent_file = (frag_percent_file + 5) / 10; ++ if (inodes_used > 0) { ++ frag_percent_file = (10000 * ctx->fs_fragmented) / inodes_used; ++ frag_percent_file = (frag_percent_file + 5) / 10; + +- frag_percent_dir = (10000 * ctx->fs_fragmented_dir) / inodes_used; +- frag_percent_dir = (frag_percent_dir + 5) / 10; ++ frag_percent_dir = (10000 * ctx->fs_fragmented_dir) / inodes_used; ++ frag_percent_dir = (frag_percent_dir + 5) / 10; + +- frag_percent_total = ((10000 * (ctx->fs_fragmented + +- ctx->fs_fragmented_dir)) +- / inodes_used); +- frag_percent_total = (frag_percent_total + 5) / 10; ++ frag_percent_total = ((10000 * (ctx->fs_fragmented + ++ ctx->fs_fragmented_dir)) ++ / inodes_used); ++ frag_percent_total = (frag_percent_total + 5) / 10; ++ } + + if (!verbose) { + log_out(ctx, _("%s: %u/%u files (%0d.%d%% non-contiguous), " +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-e2fsck-if-any-problems-are-fixed-in-pass-0-check-the.patch b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-if-any-problems-are-fixed-in-pass-0-check-the.patch new file mode 100644 index 0000000..b9b8598 --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-if-any-problems-are-fixed-in-pass-0-check-the.patch @@ -0,0 +1,64 @@ +From 775ecc1dd6624fe9bb4c4769cbd4d2cf7f49ca64 Mon Sep 17 00:00:00 2001 +From: Theodore Ts'o +Date: Sat, 26 Apr 2014 23:14:47 -0400 +Subject: [PATCH 16/16] e2fsck: if any problems are fixed in pass 0, check the + whole file system + +commit 7664c7538a11ca03d569008e6c999d525b6ea8ed + +If there are any PREEN_OK problems fixed in check_super_block(), don't +skip checking the full file system. + +Signed-off-by: "Theodore Ts'o" +--- + e2fsck/e2fsck.h | 3 ++- + e2fsck/problem.c | 3 +++ + e2fsck/unix.c | 3 +++ + 3 files changed, 8 insertions(+), 1 deletion(-) + +diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h +index 913a596a..8fc99932 100644 +--- a/e2fsck/e2fsck.h ++++ b/e2fsck/e2fsck.h +@@ -189,8 +189,9 @@ struct resource_track { + #define E2F_FLAG_GOT_DEVSIZE 0x0800 /* Device size has been fetched */ + #define E2F_FLAG_EXITING 0x1000 /* E2fsck exiting due to errors */ + #define E2F_FLAG_TIME_INSANE 0x2000 /* Time is insane */ ++#define E2F_FLAG_PROBLEMS_FIXED 0x4000 /* At least one problem was fixed */ + +-#define E2F_RESET_FLAGS (E2F_FLAG_TIME_INSANE) ++#define E2F_RESET_FLAGS (E2F_FLAG_TIME_INSANE | E2F_FLAG_PROBLEMS_FIXED) + + /* + * Defines for indicating the e2fsck pass number +diff --git a/e2fsck/problem.c b/e2fsck/problem.c +index 1aac7851..c3ba631b 100644 +--- a/e2fsck/problem.c ++++ b/e2fsck/problem.c +@@ -1976,6 +1976,9 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx) + if (ptr->flags & PR_AFTER_CODE) + answer = fix_problem(ctx, ptr->second_code, pctx); + ++ if (answer && (ptr->prompt != PROMPT_NONE)) ++ ctx->flags |= E2F_FLAG_PROBLEMS_FIXED; ++ + return answer; + } + +diff --git a/e2fsck/unix.c b/e2fsck/unix.c +index bbf65d90..813fb8c5 100644 +--- a/e2fsck/unix.c ++++ b/e2fsck/unix.c +@@ -339,6 +339,9 @@ static void check_if_skip(e2fsck_t ctx) + int broken_system_clock; + time_t lastcheck; + ++ if (ctx->flags & E2F_FLAG_PROBLEMS_FIXED) ++ return; ++ + profile_get_boolean(ctx->profile, "options", "broken_system_clock", + 0, 0, &broken_system_clock); + if (ctx->flags & E2F_FLAG_TIME_INSANE) +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-e2fsck-remove-resize-inode-if-both-resize_inode-and-.patch b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-remove-resize-inode-if-both-resize_inode-and-.patch new file mode 100644 index 0000000..cb49677 --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-remove-resize-inode-if-both-resize_inode-and-.patch @@ -0,0 +1,81 @@ +From e9d972c483d98b6b6fc9251166a1f5c2ca37ac5e Mon Sep 17 00:00:00 2001 +From: Lukas Czerner +Date: Wed, 8 Aug 2018 13:52:56 +0200 +Subject: [PATCH 06/16] e2fsck: remove resize inode if both resize_inode and + meta_bg are enabled + +commit 74848259f0dd42bd478f0541c94f31ccd68eac3c + +Previous e2fsprogs versions allowed to create a file system with both +resize_inode and meta_bg enabled. This was fixed by upstream commit +42e77d5d ("libext2fs: don't create filesystems with meta_bg and resize_inode") + +However e2fsck still does not recognize the conflict and will attempt to +clear and recreate resize_inode if it's corrupted due to this incompatible +feature combination, though it will create it in the same wrong layout. + +Fix it by teaching e2fsck to recognize resize_inode and meta_bg +conflict and fixing it by disabling and clearing resize inode. + +Signed-off-by: Lukas Czerner +Reviewed-by: Andreas Dilger +Signed-off-by: Theodore Ts'o +--- + e2fsck/problem.c | 6 ++++++ + e2fsck/problem.h | 3 +++ + e2fsck/super.c | 8 ++++++++ + 3 files changed, 17 insertions(+) + +diff --git a/e2fsck/problem.c b/e2fsck/problem.c +index 83584a08..a01b2560 100644 +--- a/e2fsck/problem.c ++++ b/e2fsck/problem.c +@@ -438,6 +438,12 @@ static struct e2fsck_problem problem_table[] = { + N_("@S 64bit filesystems needs extents to access the whole disk. "), + PROMPT_FIX, PR_PREEN_OK | PR_NO_OK}, + ++ /* Meta_bg and resize_inode are not compatible, disable resize_inode*/ ++ { PR_0_DISABLE_RESIZE_INODE, ++ N_("Resize_@i and meta_bg features are enabled. Those features are\n" ++ "not compatible. Resize @i should be disabled. "), ++ PROMPT_FIX, 0 }, ++ + /* Pass 1 errors */ + + /* Pass 1: Checking inodes, blocks, and sizes */ +diff --git a/e2fsck/problem.h b/e2fsck/problem.h +index 6cb09cfb..cf2df8ce 100644 +--- a/e2fsck/problem.h ++++ b/e2fsck/problem.h +@@ -252,6 +252,9 @@ struct problem_context { + /* 64bit is set but extents are not set. */ + #define PR_0_64BIT_WITHOUT_EXTENTS 0x000048 + ++/* Meta_bg and resize_inode are not compatible, remove resize_inode*/ ++#define PR_0_DISABLE_RESIZE_INODE 0x000051 ++ + /* + * Pass 1 errors + */ +diff --git a/e2fsck/super.c b/e2fsck/super.c +index a6be3c69..7e2c2e4f 100644 +--- a/e2fsck/super.c ++++ b/e2fsck/super.c +@@ -326,6 +326,14 @@ void check_resize_inode(e2fsck_t ctx) + + clear_problem_context(&pctx); + ++ if (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE && ++ fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG && ++ fix_problem(ctx, PR_0_DISABLE_RESIZE_INODE, &pctx)) { ++ fs->super->s_feature_compat &= ~EXT2_FEATURE_COMPAT_RESIZE_INODE; ++ fs->super->s_reserved_gdt_blocks = 0; ++ ext2fs_mark_super_dirty(fs); ++ } ++ + /* + * If the resize inode feature isn't set, then + * s_reserved_gdt_blocks must be zero. +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-e2fsck-set-dir_nlink-feature-if-large-dir-exists.patch b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-set-dir_nlink-feature-if-large-dir-exists.patch new file mode 100644 index 0000000..353925e --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-e2fsck-set-dir_nlink-feature-if-large-dir-exists.patch @@ -0,0 +1,101 @@ +From 458939e5d9441448f87d3a6d45c84e041ee14786 Mon Sep 17 00:00:00 2001 +From: Andreas Dilger +Date: Fri, 22 Jun 2018 18:08:54 -0400 +Subject: [PATCH 2/2] e2fsck: set dir_nlink feature if large dir exists + +commit 1a8015773a9316ee90f713c275fb3a38731735e4 + +If there is a directory with more than EXT2_LINK_MAX (65000) +subdirectories, but the DIR_NLINK feature is not set in the +superblock, the feature should be set before continuing on +to change the on-disk directory link count to 1. + +While most filesystems should have DIR_NLINK set (it was set +by default for all ext4 filesystems, and all kernels between +2.6.23 and 4.12 automatically set it if the directory link +count grew too large), it is possible that this flag is lost +due to disk corruption or for an upgraded filesystem. We no +longer want kernels to automatically enable features. + +Addresses: https://bugzilla.kernel.org/show_bug.cgi?id=196405 +Signed-off-by: Andreas Dilger +Signed-off-by: Theodore Ts'o +--- + e2fsck/pass4.c | 14 +++++++++++++- + e2fsck/problem.c | 5 +++++ + e2fsck/problem.h | 3 +++ + 3 files changed, 21 insertions(+), 1 deletion(-) + +diff --git a/e2fsck/pass4.c b/e2fsck/pass4.c +index 21d93f0c..ad95227c 100644 +--- a/e2fsck/pass4.c ++++ b/e2fsck/pass4.c +@@ -98,6 +98,7 @@ void e2fsck_pass4(e2fsck_t ctx) + #endif + struct problem_context pctx; + __u16 link_count, link_counted; ++ int dir_nlink_fs; + char *buf = 0; + dgrp_t group, maxgroup; + +@@ -112,6 +113,9 @@ void e2fsck_pass4(e2fsck_t ctx) + if (!(ctx->options & E2F_OPT_PREEN)) + fix_problem(ctx, PR_4_PASS_HEADER, &pctx); + ++ dir_nlink_fs = EXT2_HAS_RO_COMPAT_FEATURE(fs->super, ++ EXT4_FEATURE_RO_COMPAT_DIR_NLINK); ++ + group = 0; + maxgroup = fs->group_desc_count; + if (ctx->progress) +@@ -158,8 +162,16 @@ void e2fsck_pass4(e2fsck_t ctx) + &link_counted); + } + isdir = ext2fs_test_inode_bitmap2(ctx->inode_dir_map, i); +- if (isdir && (link_counted > EXT2_LINK_MAX)) ++ if (isdir && (link_counted > EXT2_LINK_MAX)) { ++ if (!dir_nlink_fs && ++ fix_problem(ctx, PR_4_DIR_NLINK_FEATURE, &pctx)) { ++ fs->super->s_feature_ro_compat |= ++ EXT4_FEATURE_RO_COMPAT_DIR_NLINK; ++ ext2fs_mark_super_dirty(fs); ++ dir_nlink_fs = 1; ++ } + link_counted = 1; ++ } + if (link_counted != link_count) { + e2fsck_read_inode(ctx, i, inode, "pass4"); + pctx.ino = i; +diff --git a/e2fsck/problem.c b/e2fsck/problem.c +index c3ba631b..0210ff8f 100644 +--- a/e2fsck/problem.c ++++ b/e2fsck/problem.c +@@ -1576,6 +1576,11 @@ static struct e2fsck_problem problem_table[] = { + "They @s the same!\n"), + PROMPT_NONE, 0 }, + ++ /* directory exceeds max links, but no DIR_NLINK feature in superblock*/ ++ { PR_4_DIR_NLINK_FEATURE, ++ N_("@d exceeds max links, but no DIR_NLINK feature in @S.\n"), ++ PROMPT_FIX, 0 }, ++ + /* Pass 5 errors */ + + /* Pass 5: Checking group summary information */ +diff --git a/e2fsck/problem.h b/e2fsck/problem.h +index cf2df8ce..5712de59 100644 +--- a/e2fsck/problem.h ++++ b/e2fsck/problem.h +@@ -1040,6 +1040,9 @@ struct problem_context { + /* Update quota information if it is inconsistent */ + #define PR_6_UPDATE_QUOTAS 0x060002 + ++/* directory exceeds max links, but no DIR_NLINK feature in superblock */ ++#define PR_4_DIR_NLINK_FEATURE 0x040006 ++ + /* + * Function declarations + */ +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-e2fsprogs-introduce-ext2fs_close_free-helper.patch b/SOURCES/e2fsprogs-1.42.9-14-e2fsprogs-introduce-ext2fs_close_free-helper.patch new file mode 100644 index 0000000..8845c13 --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-e2fsprogs-introduce-ext2fs_close_free-helper.patch @@ -0,0 +1,439 @@ +From 868d26ab9b54545a67150ba59a5aa9d47cb4e2d8 Mon Sep 17 00:00:00 2001 +From: Lukas Czerner +Date: Thu, 20 Feb 2014 16:02:29 +0100 +Subject: [PATCH 01/16] e2fsprogs: introduce ext2fs_close_free() helper + +commit 47fee2ef6a23ae06f680336ffde57caa64604a4c + +Currently there are many uses of ext2fs_close() which might be wrong. +First of all ext2fs_close() does not set the ext2_filsys pointer to NULL +so the caller is responsible for clearing it, however there are some +cases there we do not do it. + +Second of all very small number of users of ext2fs_close() actually +check the return value. If there is a problem in ext2fs_close() it will +not even free the ext2_filsys structure, but majority of users expect it +to do so. + +To fix both problems this commit introduces a new helper +ext2fs_close_free() which will not only check for the return value and +free the ext2_filsys structure if the call to ext2fs_close2() failed, +but it will also set the ext2_filsys pointer to NULL. + +Replace every use of ext2fs_close() in e2fsprogs tools with +ext2fs_close_free() - there is no real reason to keep using +ext2fs_close(). + +Signed-off-by: Lukas Czerner +--- + debugfs/debugfs.c | 6 ++---- + e2fsck/scantest.c | 2 +- + e2fsck/unix.c | 20 ++++++++------------ + e2fsck/util.c | 2 +- + lib/ext2fs/closefs.c | 12 ++++++++++++ + lib/ext2fs/ext2fs.h | 1 + + lib/ext2fs/mkjournal.c | 2 +- + lib/ext2fs/tst_bitmaps.c | 12 ++++-------- + misc/dumpe2fs.c | 6 +++--- + misc/e2freefrag.c | 2 +- + misc/e2image.c | 4 ++-- + misc/e4defrag.c | 2 +- + misc/mke2fs.c | 8 ++++---- + misc/tune2fs.c | 6 +++--- + resize/main.c | 2 +- + resize/resize2fs.c | 2 +- + 16 files changed, 46 insertions(+), 43 deletions(-) + +diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c +index cf7670bc..2082309b 100644 +--- a/debugfs/debugfs.c ++++ b/debugfs/debugfs.c +@@ -131,10 +131,9 @@ static void open_filesystem(char *device, int open_flags, blk64_t superblock, + return; + + errout: +- retval = ext2fs_close(current_fs); ++ retval = ext2fs_close_free(¤t_fs); + if (retval) + com_err(device, retval, "while trying to close filesystem"); +- current_fs = NULL; + } + + void do_open_filesys(int argc, char **argv) +@@ -237,10 +236,9 @@ static void close_filesystem(NOARGS) + if (retval) + com_err("ext2fs_write_block_bitmap", retval, 0); + } +- retval = ext2fs_close(current_fs); ++ retval = ext2fs_close_free(¤t_fs); + if (retval) + com_err("ext2fs_close", retval, 0); +- current_fs = NULL; + return; + } + +diff --git a/e2fsck/scantest.c b/e2fsck/scantest.c +index 16380b31..61311410 100644 +--- a/e2fsck/scantest.c ++++ b/e2fsck/scantest.c +@@ -133,7 +133,7 @@ int main (int argc, char *argv[]) + } + + +- ext2fs_close(fs); ++ ext2fs_close_free(&fs); + + print_resource_track(&global_rtrack); + +diff --git a/e2fsck/unix.c b/e2fsck/unix.c +index d94d5dcd..5fcc9d99 100644 +--- a/e2fsck/unix.c ++++ b/e2fsck/unix.c +@@ -456,8 +456,7 @@ static void check_if_skip(e2fsck_t ctx) + } + log_out(ctx, "\n"); + skip: +- ext2fs_close(fs); +- ctx->fs = NULL; ++ ext2fs_close_free(&fs); + e2fsck_free_context(ctx); + exit(FSCK_OK); + } +@@ -1303,12 +1302,12 @@ restart: + orig_superblock = ctx->superblock; + get_backup_sb(ctx, fs, ctx->filesystem_name, io_ptr); + if (fs) +- ext2fs_close(fs); ++ ext2fs_close_free(&fs); + orig_retval = retval; + retval = try_open_fs(ctx, flags, io_ptr, &fs); + if ((orig_retval == 0) && retval != 0) { + if (fs) +- ext2fs_close(fs); ++ ext2fs_close_free(&fs); + log_out(ctx, _("%s: %s while using the " + "backup blocks"), + ctx->program_name, +@@ -1402,7 +1401,7 @@ failure: + * reopen the filesystem after we get the device size. + */ + if (pctx.errcode == EBUSY) { +- ext2fs_close(fs); ++ ext2fs_close_free(&fs); + need_restart++; + pctx.errcode = + ext2fs_get_device_size2(ctx->filesystem_name, +@@ -1459,8 +1458,7 @@ failure: + /* + * Restart in order to reopen fs but this time start mmp. + */ +- ext2fs_close(fs); +- ctx->fs = NULL; ++ ext2fs_close_free(&fs); + flags &= ~EXT2_FLAG_SKIP_MMP; + goto restart; + } +@@ -1510,8 +1508,7 @@ failure: + ctx->device_name); + fatal_error(ctx, 0); + } +- ext2fs_close(ctx->fs); +- ctx->fs = 0; ++ ext2fs_close_free(&ctx->fs); + ctx->flags |= E2F_FLAG_RESTARTED; + goto restart; + } +@@ -1690,7 +1687,7 @@ no_journal: + _("while resetting context")); + fatal_error(ctx, 0); + } +- ext2fs_close(fs); ++ ext2fs_close_free(&fs); + goto restart; + } + if (run_result & E2F_FLAG_CANCEL) { +@@ -1772,8 +1769,7 @@ no_journal: + io_channel_flush(ctx->fs->io); + print_resource_track(ctx, NULL, &ctx->global_rtrack, ctx->fs->io); + +- ext2fs_close(fs); +- ctx->fs = NULL; ++ ext2fs_close_free(&fs); + free(ctx->journal_name); + + e2fsck_free_context(ctx); +diff --git a/e2fsck/util.c b/e2fsck/util.c +index 9f920b2c..14c9ad48 100644 +--- a/e2fsck/util.c ++++ b/e2fsck/util.c +@@ -319,7 +319,7 @@ void preenhalt(e2fsck_t ctx) + if (fs != NULL) { + fs->super->s_state |= EXT2_ERROR_FS; + ext2fs_mark_super_dirty(fs); +- ext2fs_close(fs); ++ ext2fs_close_free(&fs); + } + exit(FSCK_UNCORRECTED); + } +diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c +index 000ebd87..4db9e194 100644 +--- a/lib/ext2fs/closefs.c ++++ b/lib/ext2fs/closefs.c +@@ -437,6 +437,18 @@ errout: + return retval; + } + ++errcode_t ext2fs_close_free(ext2_filsys *fs_ptr) ++{ ++ errcode_t ret; ++ ext2_filsys fs = *fs_ptr; ++ ++ ret = ext2fs_close2(fs, 0); ++ if (ret) ++ ext2fs_free(fs); ++ *fs_ptr = NULL; ++ return ret; ++} ++ + errcode_t ext2fs_close(ext2_filsys fs) + { + return ext2fs_close2(fs, 0); +diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h +index 380608b2..643b66c0 100644 +--- a/lib/ext2fs/ext2fs.h ++++ b/lib/ext2fs/ext2fs.h +@@ -925,6 +925,7 @@ extern errcode_t ext2fs_check_desc(ext2_filsys fs); + /* closefs.c */ + extern errcode_t ext2fs_close(ext2_filsys fs); + extern errcode_t ext2fs_close2(ext2_filsys fs, int flags); ++extern errcode_t ext2fs_close_free(ext2_filsys *fs); + extern errcode_t ext2fs_flush(ext2_filsys fs); + extern errcode_t ext2fs_flush2(ext2_filsys fs, int flags); + extern int ext2fs_bg_has_super(ext2_filsys fs, dgrp_t group_block); +diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c +index d09c4589..52dc99be 100644 +--- a/lib/ext2fs/mkjournal.c ++++ b/lib/ext2fs/mkjournal.c +@@ -630,7 +630,7 @@ main(int argc, char **argv) + if (retval) { + printf("Warning, had trouble writing out superblocks.\n"); + } +- ext2fs_close(fs); ++ ext2fs_close_free(&fs); + exit(0); + + } +diff --git a/lib/ext2fs/tst_bitmaps.c b/lib/ext2fs/tst_bitmaps.c +index 57bfd6c8..3a6d1bdc 100644 +--- a/lib/ext2fs/tst_bitmaps.c ++++ b/lib/ext2fs/tst_bitmaps.c +@@ -187,8 +187,7 @@ static void setup_filesystem(const char *name, + return; + + errout: +- ext2fs_close(test_fs); +- test_fs = 0; ++ ext2fs_close_free(&test_fs); + } + + void setup_cmd(int argc, char **argv) +@@ -199,10 +198,8 @@ void setup_cmd(int argc, char **argv) + unsigned int type = EXT2FS_BMAP64_BITARRAY; + int flags = EXT2_FLAG_64BITS; + +- if (test_fs) { +- ext2fs_close(test_fs); +- test_fs = 0; +- } ++ if (test_fs) ++ ext2fs_close_free(&test_fs); + + reset_getopt(); + while ((c = getopt(argc, argv, "b:i:lt:")) != EOF) { +@@ -242,8 +239,7 @@ void close_cmd(int argc, char **argv) + if (check_fs_open(argv[0])) + return; + +- ext2fs_close(test_fs); +- test_fs = 0; ++ ext2fs_close_free(&test_fs); + } + + +diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c +index d4bde8e5..cc18ad83 100644 +--- a/misc/dumpe2fs.c ++++ b/misc/dumpe2fs.c +@@ -614,7 +614,7 @@ int main (int argc, char ** argv) + if (fs->super->s_feature_incompat & + EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { + print_journal_information(fs); +- ext2fs_close(fs); ++ ext2fs_close_free(&fs); + exit(0); + } + if ((fs->super->s_feature_compat & +@@ -623,7 +623,7 @@ int main (int argc, char ** argv) + print_inline_journal_information(fs); + list_bad_blocks(fs, 0); + if (header_only) { +- ext2fs_close (fs); ++ ext2fs_close_free(&fs); + exit (0); + } + retval = ext2fs_read_bitmaps (fs); +@@ -634,7 +634,7 @@ int main (int argc, char ** argv) + error_message(retval)); + } + } +- ext2fs_close (fs); ++ ext2fs_close_free(&fs); + remove_error_table(&et_ext2_error_table); + exit (0); + } +diff --git a/misc/e2freefrag.c b/misc/e2freefrag.c +index 612ca445..bb72c70d 100644 +--- a/misc/e2freefrag.c ++++ b/misc/e2freefrag.c +@@ -215,7 +215,7 @@ static errcode_t get_chunk_info(ext2_filsys fs, struct chunk_info *info, + + static void close_device(char *device_name, ext2_filsys fs) + { +- int retval = ext2fs_close(fs); ++ int retval = ext2fs_close_free(&fs); + + if (retval) + com_err(device_name, retval, "while closing the filesystem.\n"); +diff --git a/misc/e2image.c b/misc/e2image.c +index 0537b0d8..98dafa3d 100644 +--- a/misc/e2image.c ++++ b/misc/e2image.c +@@ -1415,7 +1415,7 @@ static void install_image(char *device, char *image_fn, int type) + } + + close(fd); +- ext2fs_close (fs); ++ ext2fs_close_free(&fs); + } + + static struct ext2_qcow2_hdr *check_qcow2_image(int *fd, char *name) +@@ -1648,7 +1648,7 @@ skip_device: + else + write_image_file(fs, fd); + +- ext2fs_close (fs); ++ ext2fs_close_free(&fs); + if (check) + printf(_("%d blocks already contained the data to be copied.\n"), + skipped_blocks); +diff --git a/misc/e4defrag.c b/misc/e4defrag.c +index 1ba3c53a..2c2034cf 100644 +--- a/misc/e4defrag.c ++++ b/misc/e4defrag.c +@@ -1863,7 +1863,7 @@ int main(int argc, char *argv[]) + feature_incompat = fs->super->s_feature_incompat; + log_groups_per_flex = fs->super->s_log_groups_per_flex; + +- ext2fs_close(fs); ++ ext2fs_close_free(&fs); + } + + switch (arg_type) { +diff --git a/misc/mke2fs.c b/misc/mke2fs.c +index 8952a5fe..2787a127 100644 +--- a/misc/mke2fs.c ++++ b/misc/mke2fs.c +@@ -1662,7 +1662,7 @@ profile_error: + printf(_("Using journal device's blocksize: %d\n"), blocksize); + fs_param.s_log_block_size = + int_log2(blocksize >> EXT2_MIN_BLOCK_LOG_SIZE); +- ext2fs_close(jfs); ++ ext2fs_close_free(&jfs); + } + + if (optind < argc) { +@@ -2585,7 +2585,7 @@ int main (int argc, char *argv[]) + if (fs->super->s_feature_incompat & + EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) { + create_journal_dev(fs); +- exit(ext2fs_close(fs) ? 1 : 0); ++ exit(ext2fs_close_free(&fs) ? 1 : 0); + } + + if (bad_blocks_filename) +@@ -2702,7 +2702,7 @@ int main (int argc, char *argv[]) + } + if (!quiet) + printf("%s", _("done\n")); +- ext2fs_close(jfs); ++ ext2fs_close_free(&jfs); + free(journal_device); + } else if ((journal_size) || + (fs_param.s_feature_compat & +@@ -2761,7 +2761,7 @@ no_journal: + "filesystem accounting information: ")); + checkinterval = fs->super->s_checkinterval; + max_mnt_count = fs->super->s_max_mnt_count; +- retval = ext2fs_close(fs); ++ retval = ext2fs_close_free(&fs); + if (retval) { + fprintf(stderr, "%s", + _("\nWarning, had trouble writing out superblocks.\n")); +diff --git a/misc/tune2fs.c b/misc/tune2fs.c +index d2aa125d..1bedca20 100644 +--- a/misc/tune2fs.c ++++ b/misc/tune2fs.c +@@ -682,7 +682,7 @@ static int add_journal(ext2_filsys fs) + fflush(stdout); + + retval = ext2fs_add_journal_device(fs, jfs); +- ext2fs_close(jfs); ++ ext2fs_close_free(&jfs); + if (retval) { + com_err(program_name, retval, + _("while adding filesystem to journal on %s"), +@@ -1987,7 +1987,7 @@ retry_open: + goto closefs; + } + if (io_ptr != io_ptr_orig) { +- ext2fs_close(fs); ++ ext2fs_close_free(&fs); + goto retry_open; + } + } +@@ -2267,5 +2267,5 @@ closefs: + exit(1); + } + +- return (ext2fs_close(fs) ? 1 : 0); ++ return (ext2fs_close_free(&fs) ? 1 : 0); + } +diff --git a/resize/main.c b/resize/main.c +index 80903b22..3951b091 100644 +--- a/resize/main.c ++++ b/resize/main.c +@@ -484,7 +484,7 @@ int main (int argc, char ** argv) + _("Please run 'e2fsck -fy %s' to fix the filesystem\n" + "after the aborted resize operation.\n"), + device_name); +- ext2fs_close(fs); ++ ext2fs_close_free(&fs); + exit(1); + } + printf(_("The filesystem on %s is now %llu blocks long.\n\n"), +diff --git a/resize/resize2fs.c b/resize/resize2fs.c +index d6fc5337..a73390de 100644 +--- a/resize/resize2fs.c ++++ b/resize/resize2fs.c +@@ -195,7 +195,7 @@ errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags, + rfs->new_fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY; + + print_resource_track(rfs, &overall_track, fs->io); +- retval = ext2fs_close(rfs->new_fs); ++ retval = ext2fs_close_free(&rfs->new_fs); + if (retval) + goto errout; + +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-filefrag-don-t-ignore-fsync-errors.patch b/SOURCES/e2fsprogs-1.42.9-14-filefrag-don-t-ignore-fsync-errors.patch new file mode 100644 index 0000000..c2a6efb --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-filefrag-don-t-ignore-fsync-errors.patch @@ -0,0 +1,31 @@ +From c7dcdc70473f524caa4d758233155df79bb1195d Mon Sep 17 00:00:00 2001 +From: Lukas Czerner +Date: Thu, 21 Jun 2018 15:19:56 +0200 +Subject: [PATCH 08/16] filefrag: don't ignore fsync errors + +commit a691f8d844faca28524b7c55780873244a070be7 + +Signed-off-by: Lukas Czerner +Signed-off-by: Theodore Ts'o +--- + misc/filefrag.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/misc/filefrag.c b/misc/filefrag.c +index a050a226..1c16a2ef 100644 +--- a/misc/filefrag.c ++++ b/misc/filefrag.c +@@ -274,8 +274,8 @@ static int filefrag_fibmap(int fd, int blk_shift, int *num_extents, + fm_ext.fe_flags = FIEMAP_EXTENT_MERGED; + } + +- if (sync_file) +- fsync(fd); ++ if (sync_file && fsync(fd) != 0) ++ return -errno; + + for (i = 0, logical = 0, *num_extents = 0, count = last_block = 0; + i < numblocks; +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-libext2fs-automatically-enable-meta_bg-to-avoid-fill.patch b/SOURCES/e2fsprogs-1.42.9-14-libext2fs-automatically-enable-meta_bg-to-avoid-fill.patch new file mode 100644 index 0000000..8e38ded --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-libext2fs-automatically-enable-meta_bg-to-avoid-fill.patch @@ -0,0 +1,37 @@ +From 4198ce4de86d2144ce127bba0d263a005926acf2 Mon Sep 17 00:00:00 2001 +From: "Darrick J. Wong" +Date: Sat, 24 Oct 2015 00:30:02 -0400 +Subject: [PATCH 03/16] libext2fs: automatically enable meta_bg to avoid + filling up BG 0 + +commit 03940aac5492879ef365b07e69105a98f4dbabf9 + +If during formatting we'd lose more than 75% a block group to group +descriptors and other metadata, enable the meta_bg feature. This +enables us to create >500T filesystems with default options. + +Signed-off-by: Darrick J. Wong +Signed-off-by: Theodore Ts'o +--- + lib/ext2fs/initialize.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c +index 3548c56c..0b8355d8 100644 +--- a/lib/ext2fs/initialize.c ++++ b/lib/ext2fs/initialize.c +@@ -379,6 +379,11 @@ ipg_retry: + overhead = (int) (3 + fs->inode_blocks_per_group + + super->s_reserved_gdt_blocks); + ++ /* Enable meta_bg if we'd lose more than 3/4 of a BG to GDT blocks. */ ++ if (super->s_reserved_gdt_blocks + fs->desc_blocks > ++ super->s_blocks_per_group * 3 / 4) ++ fs->super->s_feature_incompat |= EXT2_FEATURE_INCOMPAT_META_BG; ++ + if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) + overhead++; + else +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-libext2fs-don-t-create-filesystems-with-meta_bg-and-.patch b/SOURCES/e2fsprogs-1.42.9-14-libext2fs-don-t-create-filesystems-with-meta_bg-and-.patch new file mode 100644 index 0000000..36d32c0 --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-libext2fs-don-t-create-filesystems-with-meta_bg-and-.patch @@ -0,0 +1,52 @@ +From 1654b25737d2a4538964b290a75e251131fbf3c0 Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Tue, 19 Jun 2018 10:45:16 -0400 +Subject: [PATCH 04/16] libext2fs: don't create filesystems with meta_bg and + resize_inode + +commit 42e77d5db53e3ec09b5dc507169d15de219799e3 + +ext2fs_initialize() may end up enabling meta_bg feature for filesystem +which have resize_inode. Such combination is invalid to make sure we +disable resize_inode when enabling meta_bg. + +Reviewed-by: Andreas Dilger +Signed-off-by: Jan Kara +Signed-off-by: Theodore Ts'o +--- + lib/ext2fs/initialize.c | 12 +++++++----- + 1 file changed, 7 insertions(+), 5 deletions(-) + +diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c +index 0b8355d8..8f0af1fb 100644 +--- a/lib/ext2fs/initialize.c ++++ b/lib/ext2fs/initialize.c +@@ -369,6 +369,13 @@ ipg_retry: + retval = EXT2_ET_RES_GDT_BLOCKS; + goto cleanup; + } ++ /* Enable meta_bg if we'd lose more than 3/4 of a BG to GDT blocks. */ ++ if (super->s_reserved_gdt_blocks + fs->desc_blocks > ++ super->s_blocks_per_group * 3 / 4) { ++ fs->super->s_feature_incompat |= EXT2_FEATURE_INCOMPAT_META_BG; ++ fs->super->s_feature_compat &= ~EXT2_FEATURE_COMPAT_RESIZE_INODE; ++ set_field(s_reserved_gdt_blocks, 0); ++ } + + /* + * Calculate the maximum number of bookkeeping blocks per +@@ -379,11 +386,6 @@ ipg_retry: + overhead = (int) (3 + fs->inode_blocks_per_group + + super->s_reserved_gdt_blocks); + +- /* Enable meta_bg if we'd lose more than 3/4 of a BG to GDT blocks. */ +- if (super->s_reserved_gdt_blocks + fs->desc_blocks > +- super->s_blocks_per_group * 3 / 4) +- fs->super->s_feature_incompat |= EXT2_FEATURE_INCOMPAT_META_BG; +- + if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) + overhead++; + else +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-libext2fs-fix-ext2fs_open2-error-for-meta_bg-image-f.patch b/SOURCES/e2fsprogs-1.42.9-14-libext2fs-fix-ext2fs_open2-error-for-meta_bg-image-f.patch new file mode 100644 index 0000000..d8ea3bf --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-libext2fs-fix-ext2fs_open2-error-for-meta_bg-image-f.patch @@ -0,0 +1,44 @@ +From fc9ed72f64b0e6689eaed1faa33e3a333b995bf7 Mon Sep 17 00:00:00 2001 +From: Kazuya Mio +Date: Sat, 17 Mar 2018 14:56:15 -0400 +Subject: [PATCH 05/16] libext2fs: fix ext2fs_open2() error for meta_bg image + file + +commit 8b061a641dff1a0becf645f8e6002de79b997b95 + +dumpe2fs/debugfs can examine the image file by using the -i option. +However, if meta_bg feature is enabled, dumpe2fs/debugfs cannot open +the image file. + +$ dumpe2fs -i test.img +dumpe2fs: Attempt to read block from filesystem resulted in short read while trying to open test.img +Couldn't find valid filesystem superblock. + +In case of specifying an image file, the location of block group descriptors +is the same as the case of default filesystem regardless of meta_bg feature. +So if EXT2_FLAG_IMAGE_FILE flag is set in ext2fs_open2(), +don't use the meta_bg handling. + +Signed-off-by: Kazuya Mio +Signed-off-by: Theodore Ts'o +--- + lib/ext2fs/openfs.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c +index ba501e6a..200f7815 100644 +--- a/lib/ext2fs/openfs.c ++++ b/lib/ext2fs/openfs.c +@@ -378,7 +378,8 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, + #ifdef WORDS_BIGENDIAN + groups_per_block = EXT2_DESC_PER_BLOCK(fs->super); + #endif +- if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) { ++ if ((fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) && ++ !(flags & EXT2_FLAG_IMAGE_FILE)) { + first_meta_bg = fs->super->s_first_meta_bg; + if (first_meta_bg > fs->desc_blocks) + first_meta_bg = fs->desc_blocks; +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-libext2fs-fix-maximum-bg-overhead-calculation-with-m.patch b/SOURCES/e2fsprogs-1.42.9-14-libext2fs-fix-maximum-bg-overhead-calculation-with-m.patch new file mode 100644 index 0000000..b54e121 --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-libext2fs-fix-maximum-bg-overhead-calculation-with-m.patch @@ -0,0 +1,42 @@ +From 80f665e8365607a9885ca6a136cdeffacf9860d6 Mon Sep 17 00:00:00 2001 +From: "Darrick J. Wong" +Date: Sat, 24 Oct 2015 00:24:57 -0400 +Subject: [PATCH 02/16] libext2fs: fix maximum bg overhead calculation with + meta_bg enabled + +commit 1abdd04eb1d19488493022f81c03f5b80aa7fcc7 + +When meta_bg is enabled at mkfs time, we put at most one group +descriptor block in each blockgroup. Unfortunately, the calculation +of max overhead per bg doesn't know this, so mkfs fails when it isn't +strictly necessary. Fix it, since Dave reported that he couldn't +create a 500TB ext4 filesystem. + +Reported-by: Dave Chinner +Signed-off-by: Darrick J. Wong +Signed-off-by: Theodore Ts'o +--- + lib/ext2fs/initialize.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c +index 2db8b3c2..3548c56c 100644 +--- a/lib/ext2fs/initialize.c ++++ b/lib/ext2fs/initialize.c +@@ -377,7 +377,12 @@ ipg_retry: + * table, and the reserved gdt blocks. + */ + overhead = (int) (3 + fs->inode_blocks_per_group + +- fs->desc_blocks + super->s_reserved_gdt_blocks); ++ super->s_reserved_gdt_blocks); ++ ++ if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) ++ overhead++; ++ else ++ overhead += fs->desc_blocks; + + /* This can only happen if the user requested too many inodes */ + if (overhead > super->s_blocks_per_group) { +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-misc-fix-Coverity-bugs.patch b/SOURCES/e2fsprogs-1.42.9-14-misc-fix-Coverity-bugs.patch new file mode 100644 index 0000000..aaed55d --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-misc-fix-Coverity-bugs.patch @@ -0,0 +1,100 @@ +From df9c49cb287a9cd79ee2589ddfa3db0bc1a9d97b Mon Sep 17 00:00:00 2001 +From: "Darrick J. Wong" +Date: Sat, 16 May 2015 18:32:33 -0400 +Subject: [PATCH 12/16] misc: fix Coverity bugs + +commit 63cd76d6ac3bb7f90c583f240fc75e657610f2ea + +Fix Coverity bugs 1297093, 1297096, 1297489, 1297491, 1297493, +1297506, 1297507, 1297514, 1297516, and 1297517. + +Signed-off-by: Darrick J. Wong +Signed-off-by: Theodore Ts'o +--- + debugfs/util.c | 2 +- + lib/e2p/feature.c | 4 ++-- + lib/e2p/mntopts.c | 2 +- + misc/e4defrag.c | 4 +++- + misc/logsave.c | 2 +- + 5 files changed, 8 insertions(+), 6 deletions(-) + +diff --git a/debugfs/util.c b/debugfs/util.c +index aafbc567..b355e5cd 100644 +--- a/debugfs/util.c ++++ b/debugfs/util.c +@@ -373,7 +373,7 @@ int common_block_args_process(int argc, char *argv[], + return 1; + if (*block == 0) { + com_err(argv[0], 0, "Invalid block number 0"); +- err = 1; ++ return 1; + } + + if (argc > 2) { +diff --git a/lib/e2p/feature.c b/lib/e2p/feature.c +index 96912638..d4f1bf1a 100644 +--- a/lib/e2p/feature.c ++++ b/lib/e2p/feature.c +@@ -177,7 +177,7 @@ int e2p_string2feature(char *string, int *compat_type, unsigned int *mask) + if (string[9] == 0) + return 1; + num = strtol(string+9, &eptr, 10); +- if (num > 32 || num < 0) ++ if (num > 31 || num < 0) + return 1; + if (*eptr) + return 1; +@@ -251,7 +251,7 @@ int e2p_jrnl_string2feature(char *string, int *compat_type, unsigned int *mask) + if (string[9] == 0) + return 1; + num = strtol(string+9, &eptr, 10); +- if (num > 32 || num < 0) ++ if (num > 31 || num < 0) + return 1; + if (*eptr) + return 1; +diff --git a/lib/e2p/mntopts.c b/lib/e2p/mntopts.c +index d56cc527..ff2e5de9 100644 +--- a/lib/e2p/mntopts.c ++++ b/lib/e2p/mntopts.c +@@ -72,7 +72,7 @@ int e2p_string2mntopt(char *string, unsigned int *mask) + if (string[8] == 0) + return 1; + num = strtol(string+8, &eptr, 10); +- if (num > 32 || num < 0) ++ if (num > 31 || num < 0) + return 1; + if (*eptr) + return 1; +diff --git a/misc/e4defrag.c b/misc/e4defrag.c +index 2c2034cf..99baeb7b 100644 +--- a/misc/e4defrag.c ++++ b/misc/e4defrag.c +@@ -440,8 +440,10 @@ static int page_in_core(int fd, struct move_extent defrag_data, + *page_num = 0; + *page_num = (length + pagesize - 1) / pagesize; + *vec = (unsigned char *)calloc(*page_num, 1); +- if (*vec == NULL) ++ if (*vec == NULL) { ++ munmap(page, length); + return -1; ++ } + + /* Get information on whether pages are in core */ + if (mincore(page, (size_t)length, *vec) == -1 || +diff --git a/misc/logsave.c b/misc/logsave.c +index 8612edfb..cd6037dd 100644 +--- a/misc/logsave.c ++++ b/misc/logsave.c +@@ -219,7 +219,7 @@ static int run_program(char **argv) + sprintf(buffer, "died with signal %d\n", + WTERMSIG(status)); + send_output(buffer, 0, SEND_BOTH); +- rc = 1; ++ return 1; + } + rc = 0; + } +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-mke2fs-Avoid-crashes-infinite-loops-for-absurdly-lar.patch b/SOURCES/e2fsprogs-1.42.9-14-mke2fs-Avoid-crashes-infinite-loops-for-absurdly-lar.patch new file mode 100644 index 0000000..8a5a269 --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-mke2fs-Avoid-crashes-infinite-loops-for-absurdly-lar.patch @@ -0,0 +1,44 @@ +From f7da56758e5d15416339d640f79d6eee875d22a9 Mon Sep 17 00:00:00 2001 +From: Jan Kara +Date: Tue, 25 Oct 2016 14:08:59 -0400 +Subject: [PATCH 09/16] mke2fs: Avoid crashes / infinite loops for absurdly + large devices + +commit 101ef2e93c253ae62320628e8958067d2d2a4e2a + +When a device reports absurdly high size, some arithmetics in mke2fs can +overflow (e.g. number of block descriptors) and we end in an infinite +loop. Fix that by checking and refusing insanely large devices. + +Signed-off-by: Jan Kara +Signed-off-by: Theodore Ts'o +--- + misc/mke2fs.c | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/misc/mke2fs.c b/misc/mke2fs.c +index 2787a127..7cea0330 100644 +--- a/misc/mke2fs.c ++++ b/misc/mke2fs.c +@@ -1858,6 +1858,18 @@ profile_error: + EXT2_BLOCK_SIZE(&fs_param)); + exit(1); + } ++ /* ++ * Guard against group descriptor count overflowing... Mostly to avoid ++ * strange results for absurdly large devices. ++ */ ++ if (fs_blocks_count > ((1ULL << (fs_param.s_log_block_size + 3 + 32)) - 1)) { ++ fprintf(stderr, _("%s: Size of device (0x%llx blocks) %s " ++ "too big to create\n\t" ++ "a filesystem using a blocksize of %d.\n"), ++ program_name, fs_blocks_count, device_name, ++ EXT2_BLOCK_SIZE(&fs_param)); ++ exit(1); ++ } + + ext2fs_blocks_count_set(&fs_param, fs_blocks_count); + +-- +2.20.1 + diff --git a/SOURCES/e2fsprogs-1.42.9-14-resize2fs-Remove-the-real-kilobytes-rant-from-man-pa.patch b/SOURCES/e2fsprogs-1.42.9-14-resize2fs-Remove-the-real-kilobytes-rant-from-man-pa.patch new file mode 100644 index 0000000..fba1d91 --- /dev/null +++ b/SOURCES/e2fsprogs-1.42.9-14-resize2fs-Remove-the-real-kilobytes-rant-from-man-pa.patch @@ -0,0 +1,53 @@ +From e8e0b3e9e8318064e38e4be108bc625f9258fb45 Mon Sep 17 00:00:00 2001 +From: Lukas Czerner +Date: Thu, 19 Jul 2018 10:39:38 +0200 +Subject: [PATCH 07/16] resize2fs: Remove the real kilobytes rant from man page + +commit 94f20cd51522dd718bc4a459ea65d72a722d1874 + +Remove the rant about the "real" kilobytes from the man page and just +make it more clear that the suffixed units are representing power-of-two +units as we do in mke2fs man page. Also add terabytes to the list. + +Signed-off-by: Lukas Czerner +Signed-off-by: Theodore Ts'o +--- + resize/resize2fs.8.in | 16 ++++------------ + 1 file changed, 4 insertions(+), 12 deletions(-) + +diff --git a/resize/resize2fs.8.in b/resize/resize2fs.8.in +index a1f3099b..78cb1212 100644 +--- a/resize/resize2fs.8.in ++++ b/resize/resize2fs.8.in +@@ -41,24 +41,16 @@ If no units are specified, the units of the + parameter shall be the filesystem blocksize of the filesystem. + Optionally, the + .I size +-parameter may be suffixed by one of the following the units +-designators: 's', 'K', 'M', or 'G', +-for 512 byte sectors, kilobytes, megabytes, or gigabytes, respectively. +-The ++parameter may be suffixed by one of the following units ++designators: 'K', 'M', 'G', 'T' (either upper-case or lower-case) or 's' ++for power-of-two kilobytes, megabytes, gigabytes, terabytes or 512 byte ++sectors respectively. The + .I size + of the filesystem may never be larger than the size of the partition. + If + .I size + parameter is not specified, it will default to the size of the partition. + .PP +-Note: when kilobytes is used above, I mean +-.IR real , +-power-of-2 kilobytes, (i.e., 1024 bytes), which some politically correct +-folks insist should be the stupid-sounding ``kibibytes''. The same +-holds true for megabytes, also sometimes known as ``mebibytes'', or +-gigabytes, as the amazingly silly ``gibibytes''. Makes you want to +-gibber, doesn't it? +-.PP + The + .B resize2fs + program does not manipulate the size of partitions. If you wish to enlarge +-- +2.20.1 + diff --git a/SPECS/e2fsprogs.spec b/SPECS/e2fsprogs.spec index 6c823d3..b0dcbe2 100644 --- a/SPECS/e2fsprogs.spec +++ b/SPECS/e2fsprogs.spec @@ -1,7 +1,7 @@ Summary: Utilities for managing ext2, ext3, and ext4 filesystems Name: e2fsprogs Version: 1.42.9 -Release: 13%{?dist} +Release: 16%{?dist} # License tags based on COPYING file distinctions for various components License: GPLv2 @@ -40,6 +40,25 @@ Patch27: e2fsprogs-1.42.11-Fix-32-64-bit-overflow-when-multiplying-by-blocks-cl. Patch28: e2fsprogs-1.44.1-e2fsck-warn-if-checkinterval-and-broken_system_clock.patch Patch29: e2fsprogs-1.42.9-libext2fs-detect-correct-superblock-adjustments-when.patch Patch30: e2fsprogs-1.42.9-libext2fs-don-t-always-read-backup-group-descriptors.patch +Patch31: e2fsprogs-1.42.9-14-e2fsprogs-introduce-ext2fs_close_free-helper.patch +Patch32: e2fsprogs-1.42.9-14-libext2fs-fix-maximum-bg-overhead-calculation-with-m.patch +Patch33: e2fsprogs-1.42.9-14-libext2fs-automatically-enable-meta_bg-to-avoid-fill.patch +Patch34: e2fsprogs-1.42.9-14-libext2fs-don-t-create-filesystems-with-meta_bg-and-.patch +Patch35: e2fsprogs-1.42.9-14-libext2fs-fix-ext2fs_open2-error-for-meta_bg-image-f.patch +Patch36: e2fsprogs-1.42.9-14-e2fsck-remove-resize-inode-if-both-resize_inode-and-.patch +Patch37: e2fsprogs-1.42.9-14-resize2fs-Remove-the-real-kilobytes-rant-from-man-pa.patch +Patch38: e2fsprogs-1.42.9-14-filefrag-don-t-ignore-fsync-errors.patch +Patch39: e2fsprogs-1.42.9-14-mke2fs-Avoid-crashes-infinite-loops-for-absurdly-lar.patch +Patch40: e2fsprogs-1.42.9-14-e2fsck-fix-fd-leak-in-reserve_stdio_fds.patch +Patch41: e2fsprogs-1.42.9-14-e2fsck-fix-potential-Floating-Point-Exception-in-sho.patch +Patch42: e2fsprogs-1.42.9-14-misc-fix-Coverity-bugs.patch +Patch43: e2fsprogs-1.42.9-14-e2fsck-fix-free-pointer-dereferences.patch +Patch44: e2fsprogs-1.42.9-14-e2fsck-fix-off-by-one-bounds-check-on-group-number.patch +Patch45: e2fsprogs-1.42.9-14-e2fsck-fix-last-mount-time-and-last-write-time-in-pr.patch +Patch46: e2fsprogs-1.42.9-14-e2fsck-if-any-problems-are-fixed-in-pass-0-check-the.patch +Patch47: e2fsprogs-1.42.9-14-Clarify-how-the-description-of-the-dir_nlink-feature.patch +Patch48: e2fsprogs-1.42.9-14-e2fsck-set-dir_nlink-feature-if-large-dir-exists.patch +Patch49: e2fsprogs-1.42.11-e2fsck-free-ctx-fs-not-fs-at-the-end-of-fsck.patch Url: http://e2fsprogs.sourceforge.net/ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) @@ -219,6 +238,25 @@ It was originally inspired by the Multics SubSystem library. %patch28 -p1 %patch29 -p1 %patch30 -p1 +%patch31 -p1 +%patch32 -p1 +%patch33 -p1 +%patch34 -p1 +%patch35 -p1 +%patch36 -p1 +%patch37 -p1 +%patch38 -p1 +%patch39 -p1 +%patch40 -p1 +%patch41 -p1 +%patch42 -p1 +%patch43 -p1 +%patch44 -p1 +%patch45 -p1 +%patch46 -p1 +%patch47 -p1 +%patch48 -p1 +%patch49 -p1 %build %configure --enable-elf-shlibs --enable-nls --disable-uuidd --disable-fsck \ @@ -411,6 +449,17 @@ exit 0 %{_libdir}/pkgconfig/ss.pc %changelog +* Mon Jun 17 2019 Lukas Czerner 1.42.9-16 +- Fix NULL pointer dereference when releasing memory (#1720903) + +* Wed Feb 27 2019 Lukas Czerner 1.42.9-15 +- set dir_nlink feature if large dir exists (#1683694) + +* Mon Feb 25 2019 Lukas Czerner 1.42.9-14 +- Various fixes and improvements (#1682935) +- Automatically enable meta_bg to avoid failure when creating huge fs with small bs (#1608635) +- don't ignore fsync errors in filefrag (#1451185) + * Tue Jun 13 2018 Lukas Czerner 1.42.9-13 - e2fsck: warn if checkinterval and broken_system_clock both set (#1365594) - e2fsprogs: fail to open 1k block size ext4 with bigalloc,meta_bg,^resize_inode (#1448019)