From: Daniel Abrecht <linux-f2fs-devel@nodmarc.danielabrecht.ch>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [f2fs-dev] [PATCH v2] Add -P option to preserve file owner
Date: Mon, 15 Mar 2021 22:08:53 +0000 [thread overview]
Message-ID: <685cd73aea4daa72236ec53aa9c3a7fe@abrecht.li> (raw)
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.
Signed-off-by: Daniel Abrecht <public@danielabrecht.ch>
---
fsck/main.c | 6 +++++-
fsck/sload.c | 5 +++++
include/f2fs_fs.h | 1 +
man/sload.f2fs.8 | 7 +++++++
4 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/fsck/main.c b/fsck/main.c
index a538c72..be30e00 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -138,6 +138,7 @@ void sload_usage()
MSG(0, " -S sparse_mode\n");
MSG(0, " -t mount point [prefix of target fs path, default:/]\n");
MSG(0, " -T timestamp\n");
+ MSG(0, " -P preserve owner: user and group\n");
MSG(0, " -c enable compression (default allow policy)\n");
MSG(0, " ------------ Compression sub-options
-----------------\n");
MSG(0, " -L <log-of-blocks-per-cluster>, default 2\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;
diff --git a/fsck/sload.c b/fsck/sload.c
index 4dea78b..6929023 100644
--- a/fsck/sload.c
+++ b/fsck/sload.c
@@ -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);
}
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index a51a359..cdcce2c 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -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;
diff --git a/man/sload.f2fs.8 b/man/sload.f2fs.8
index c165b35..ed5ee4b 100644
--- a/man/sload.f2fs.8
+++ b/man/sload.f2fs.8
@@ -18,6 +18,9 @@ sload.f2fs \- load directories and files into the
device directly
.I debugging-level
]
[
+.B \-P
+]
+[
.B \-c
[
.B \-L
@@ -66,6 +69,10 @@ Specify the mount point path in the partition to
load.
Specify the level of debugging options.
The default number is 0, which shows basic debugging messages.
.TP
+.BI \-P
+Preserve owner: user and group.
+The user and group of the source files will be taken into account.
+.TP
.BI \-c
Enable a cluster-based file compression.
The file would be chopped into clusters, and each cluster is compressed
--
2.20.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next reply other threads:[~2021-03-15 22:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-15 22:08 Daniel Abrecht [this message]
2021-03-16 1:06 ` [f2fs-dev] [PATCH v2] Add -P option to preserve file owner Chao Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=685cd73aea4daa72236ec53aa9c3a7fe@abrecht.li \
--to=linux-f2fs-devel@nodmarc.danielabrecht.ch \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).