e2fsck: allow deleting or zeroing shared blocks
PATCH 1/1 e2fsck: allow deleting or zeroing shared blocks
From: Jim Garlick <[email protected]>
E2fsck fixes files that are found to be sharing blocks by cloning the shared blocks and giving each file a private copy in pass 1D.
Allowing all files claiming the shared blocks to have copies can inadvertantly bypass access restrictions. Deleting all the files, zeroing the cloned blocks, or placing the files in the /lost+found directory after cloning may be preferable in some secure environments.
The following patches implement config file and command line options in e2fsck that allow pass 1D behavior to be tuned according to site policy. It adds two extended options and config file counterparts. On the command line:
-E clone=dup|zero
Select the block cloning method. "dup" is old behavior, and is the default. "zero" is a new method that substitutes zero-filled blocks for the shared blocks in all the files that claim them.
-E shared=preserve|lost+found|delete
Select the disposition of files containing shared blocks. "preserve" is the old behavior which remains the default. "lost+found" causes files to be unlinked after cloning so they will be reconnected to /lost+found in pass 3. "delete" skips cloning entirely and simply deletes the files.
In the config file:
[options]
clone=dup|zero
shared=preserve|lost+found|delete
--- e2fsck/e2fsck.8.in | 15 +++++++ e2fsck/e2fsck.conf.5.in | 13 +++++++ e2fsck/e2fsck.h | 13 +++++++ e2fsck/pass1b.c | 48 ++++++++++++++++++----- e2fsck/problem.c | 8 ++++ e2fsck/problem.h | 7 ++++ e2fsck/unix.c | 86 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 181 insertions(+), 9 deletions(-)
e2fsck/e2fsck.8.in +15 -0
@@ -198,6 +198,21 @@ separated, and may take an argument using the equals ('=') sign. The following options are supported: .RS 1.2i .TP +.BI clone= dup|zero +Resolve files with shared blocks in pass 1D by giving each file a private +copy of the blocks (dup); +or replacing the shared blocks with private, zero-filled blocks (zero). +The default is dup. zero option is incompatible with -E unshare_blocks +option. +.TP +.BI shared= preserve|lost+found|delete +Files with shared blocks discovered in pass 1D are cloned and then left +in place (preserve); +cloned and then disconnected from their parent directory, +then reconnected to /lost+found in pass 3 (lost+found); +or simply deleted (delete). The default is preserve. +lost+found and delete are incompatible with -E unshare_blocks option. +.TP .BI ea_ver= extended_attribute_version Set the version of the extended attribute blocks which .B e2fsck
e2fsck/e2fsck.conf.5.in +13 -0
@@ -147,6 +147,19 @@ will offer to clear the test_fs flag if the ext4 filesystem is available on the system. It defaults to true. .TP +.I clone +This string relation controls the default handling of shared blocks in pass 1D. +It can be set to dup or zero. See the +.I "-E clone" +option description in e2fsck(8). +.TP +.I shared +This string relation controls the default disposition of files discovered to +have shared blocks in pass 1D. It can be set to preserve, lost+found, +or delete. See the +.I "-E shared" +option description in e2fsck(8). +.TP .I defer_check_on_battery This boolean relation controls whether or not the interval between filesystem checks (either based on time or number of mounts) should
e2fsck/e2fsck.h +13 -0
@@ -211,6 +211,17 @@ struct resource_track {#define E2F_PASS_5 5#define E2F_PASS_1B 6 +enum shared_opt { +E2F_SHARED_PRESERVE =0 , +E2F_SHARED_DELETE , +E2F_SHARED_LPF +}; + +enum clone_opt { +E2F_CLONE_DUP =0 , +E2F_CLONE_ZERO +}; +/* * Define the extended attribute refcount structure */
@@ -387,6 +398,8 @@ struct e2fsck_struct {time_t now;time_t time_fudge;/* For working around buggy init scripts */ int ext_attr_ver; +enum shared_opt shared; +enum clone_opt clone;profile_t profile;int blocks_per_page;ext2_u32_list encrypted_dirs;
e2fsck/pass1b.c +39 -9
81 lines not on this page · raw message
e2fsck/problem.c +8 -0
@@ -1281,6 +1281,14 @@ static struct e2fsck_problem problem_table[] = { {PR_1D_CLONE_ERROR , N_("Couldn't clone file: %m\n"), PROMPT_NONE, 0, 0, 0, 0 }, +/* File with shared blocks found */ + { PR_1D_DISCONNECT_QUESTION, + N_("File with shared blocks found\n"), PROMPT_CONNECT, 0 }, + +/* Couldn't unlink file (error) */ + { PR_1D_DISCONNECT_ERROR, + N_("Couldn't unlink file: %m\n"), PROMPT_NONE, 0 }, +/* Pass 1E Extent tree optimization */ /* Pass 1E: Optimizing extent trees */
e2fsck/problem.h +7 -0
@@ -756,6 +756,13 @@ struct problem_context {/* Couldn't clone file (error) */ #define PR_1D_CLONE_ERROR 0x013008 +/* File with shared blocks found */ +#define PR_1D_DISCONNECT_QUESTION 0x013009 + +/* Couldn't unlink file (error) */ +#define PR_1D_DISCONNECT_ERROR 0x01300A + +/* * Pass 1e --- rebuilding extent trees */
e2fsck/unix.c +86 -0
116 lines not on this page · raw message
Signature · 1 line
2.22.0