Skip to contentSkip to conversation

e2fsprogs-new-opt-shrdblks.patch

PATCH In review Kalpak Shah 1 participant 1 message Oct 6, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 3/15 e2fsprogs-new-opt-shrdblks.patch

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 which
remains
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 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 which remains 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.h +13 -0
Index: e2fsprogs-1.41.1/e2fsck/e2fsck.h
===================================================================
@@ -185,6 +185,17 @@ struct resource_track {
 #define E2F_PASS_5	5
 #define E2F_PASS_1B	6
 
+typedef	enum {
+	E2F_SHARED_PRESERVE = 0,
+	E2F_SHARED_DELETE,
+	E2F_SHARED_LPF
+} shared_opt_t;
+
+typedef enum {
+	E2F_CLONE_DUP = 0,
+	E2F_CLONE_ZERO
+} clone_opt_t;
+
 /*
  * Define the extended attribute refcount structure
  */
@@ -337,6 +348,8 @@ struct e2fsck_struct {
 	time_t now;
 	time_t time_fudge;	/* For working around buggy init scripts */
 	int ext_attr_ver;
+	shared_opt_t shared;
+	clone_opt_t clone;
 	profile_t	profile;
 	int blocks_per_page;
 
e2fsck/unix.c +76 -0

100 lines not on this page · raw message

e2fsck/pass1b.c +36 -10

79 lines not on this page · raw message

e2fsck/problem.h +7 -0
Index: e2fsprogs-1.41.1/e2fsck/problem.h
===================================================================
@@ -576,6 +576,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 2 errors
  */
e2fsck/problem.c +8 -0
Index: e2fsprogs-1.41.1/e2fsck/problem.c
===================================================================
@@ -976,6 +976,14 @@ static struct e2fsck_problem problem_tab
 	{ PR_1D_CLONE_ERROR,
 	  N_("Couldn't clone file: %m\n"), PROMPT_NONE, 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 2 errors */
 
 	/* Pass 2: Checking directory structure */
e2fsck/e2fsck.8.in +13 -0
Index: e2fsprogs-1.41.1/e2fsck/e2fsck.8.in
===================================================================
@@ -184,6 +184,19 @@ separated, and may take an argument usin
 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.
+.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.
+.TP
 .BI ea_ver= extended_attribute_version
 Set the version of the extended attribute blocks which
 .B e2fsck
e2fsck/e2fsck.conf.5.in +14 -0
Index: e2fsprogs-1.41.1/e2fsck/e2fsck.conf.5.in
===================================================================
@@ -106,6 +106,20 @@ This boolean relation controls whether o
 filesystem checks (either based on time or number of mounts) should 
 be doubled if the system is running on battery.  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).
+
 .SH THE [problems] STANZA
 Each tag in the
 .I [problems]