Skip to contentSkip to conversation

Add -P option to preserve file owner

PATCH Superseded Daniel Abrecht 2 participants 2 messages Mar 14, 2021 – Mar 15, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add -P option to preserve file owner

I use user namespaces & debootstrap to bootstrap a system, and then copy that into an image using sload.f2fs. However, without an option to preserve the owner user & group of files, some files end up being owned by the wrong user / group (0:0), which causes all kinds of other issues

This patch adds an option -P to preserve the user and group of files.

---
 fsck/main.c       | 6 +++++-
 fsck/sload.c      | 5 +++++
 include/f2fs_fs.h | 1 +
 3 files changed, 11 insertions(+), 1 deletion(-)
fsck/main.c +5 -1
index a538c72..8438b45 100644
@@ -132,6 +132,7 @@ void sload_usage()
 	MSG(0, "\nUsage: sload.f2fs [options] device\n");
 	MSG(0, "[options]:\n");
 	MSG(0, "  -C fs_config\n");
+	MSG(0, "  -P preserve owner user and group\n");
 	MSG(0, "  -f source directory [path of the source directory]\n");
 	MSG(0, "  -p product out directory\n");
 	MSG(0, "  -s file_contexts\n");
@@ -549,7 +550,7 @@ void f2fs_parse_options(int argc, char *argv[])
 #endif
 	} else if (!strcmp("sload.f2fs", prog)) {
 #ifdef WITH_SLOAD
-		const char *option_string = "cL:a:i:x:m:rC:d:f:p:s:St:T:V";
+		const char *option_string = "cL:a:i:x:m:rC:d:f:p:s:St:T:VP";
 #ifdef HAVE_LIBSELINUX
 		int max_nr_opt = (int)sizeof(c.seopt_file) /
 			sizeof(c.seopt_file[0]);
@@ -685,6 +686,9 @@ void f2fs_parse_options(int argc, char *argv[])
 			case 'V':
 				show_version(prog);
 				exit(0);
+			case 'P':
+				c.preserve_perms = 1;
+				break;
 			default:
 				err = EUNKNOWN_OPT;
 				break;
fsck/sload.c +5 -0
index 4dea78b..6929023 100644
@@ -187,6 +187,11 @@ static void set_inode_metadata(struct dentry *de)
 	else
 		de->mtime = c.fixed_time;
 
+	if (c.preserve_perms) {
+		de->uid = stat.st_uid;
+		de->gid = stat.st_gid;
+	}
+
 	set_perms_and_caps(de);
 }
 
include/f2fs_fs.h +1 -0
index a51a359..cdcce2c 100644
@@ -505,6 +505,7 @@ struct f2fs_configuration {
 	struct selinux_opt seopt_file[8];
 	int nr_opt;
 #endif
+	int preserve_perms;
 
 	/* resize parameters */
 	int safe_resize;
Signature · 8 lines
2.20.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw
Quoted 17 lines · Daniel Abrecht

I use user namespaces & debootstrap to bootstrap a system, and then copy that into an image using sload.f2fs. However, without an option to preserve the owner user & group of files, some files end up being owned by the wrong user / group (0:0), which causes all kinds of other issues

This patch adds an option -P to preserve the user and group of files.

---
   fsck/main.c       | 6 +++++-
   fsck/sload.c      | 5 +++++
   include/f2fs_fs.h | 1 +
   3 files changed, 11 insertions(+), 1 deletion(-)
fsck/main.c +0 -0
index a538c72..8438b45 100644

fsck/main.c void sload_usage() · line 135

Quoted 4 lines
fsck/main.c +1 -0
@@ -132,6 +132,7 @@ void sload_usage()
   	MSG(0, "\nUsage: sload.f2fs [options] device\n");
   	MSG(0, "[options]:\n");
   	MSG(0, "  -C fs_config\n");
+	MSG(0, "  -P preserve owner user and group\n");

preserve owner: user and group

How about adding an entry to describe this new option in manual of sload.f2fs?

Thanks,

Quoted 44 lines
fsck/main.c +4 -1
   	MSG(0, "  -f source directory [path of the source directory]\n");
   	MSG(0, "  -p product out directory\n");
   	MSG(0, "  -s file_contexts\n");
@@ -549,7 +550,7 @@ void f2fs_parse_options(int argc, char *argv[])
   #endif
   	} else if (!strcmp("sload.f2fs", prog)) {
   #ifdef WITH_SLOAD
-		const char *option_string = "cL:a:i:x:m:rC:d:f:p:s:St:T:V";
+		const char *option_string = "cL:a:i:x:m:rC:d:f:p:s:St:T:VP";
   #ifdef HAVE_LIBSELINUX
   		int max_nr_opt = (int)sizeof(c.seopt_file) /
   			sizeof(c.seopt_file[0]);
@@ -685,6 +686,9 @@ void f2fs_parse_options(int argc, char *argv[])
   			case 'V':
   				show_version(prog);
   				exit(0);
+			case 'P':
+				c.preserve_perms = 1;
+				break;
   			default:
   				err = EUNKNOWN_OPT;
   				break;
fsck/sload.c +5 -0
index 4dea78b..6929023 100644
@@ -187,6 +187,11 @@ static void set_inode_metadata(struct dentry *de)
   	else
   		de->mtime = c.fixed_time;
 
+	if (c.preserve_perms) {
+		de->uid = stat.st_uid;
+		de->gid = stat.st_gid;
+	}
+
   	set_perms_and_caps(de);
   }
 
include/f2fs_fs.h +0 -0
index a51a359..cdcce2c 100644

include/f2fs_fs.h struct f2fs_configuration { · line 511

Quoted 7 lines
include/f2fs_fs.h +1 -0
@@ -505,6 +505,7 @@ struct f2fs_configuration {
   	struct selinux_opt seopt_file[8];
   	int nr_opt;
   #endif
+	int preserve_perms;
 
   	/* resize parameters */
   	int safe_resize;

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel