Add -P option to preserve file owner

commit 80dba0f975
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

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>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
This commit is contained in:
Daniel Abrecht 2021-03-15 22:08:53 +00:00 committed by dongsenhao
parent ce1c9b8e99
commit ea01d23fa6
4 changed files with 18 additions and 1 deletions

View File

@ -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;

View File

@ -189,6 +189,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);
}

View File

@ -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;

View File

@ -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