* [PATCH 1/2] erofs-utils: mkfs: improvement for unprivileged container support
@ 2022-08-14 2:29 Naoto Yamaguchi
2022-08-14 2:29 ` [PATCH 2/2] erofs-utils: mkfs: updating man to use uid/gid offsetting support Naoto Yamaguchi
2022-08-14 6:21 ` [PATCH 1/2] erofs-utils: mkfs: improvement for unprivileged container support Gao Xiang
0 siblings, 2 replies; 4+ messages in thread
From: Naoto Yamaguchi @ 2022-08-14 2:29 UTC (permalink / raw)
To: linux-erofs; +Cc: Naoto Yamaguchi
When developer want to use erofs at guest container rootfs, it require
to uid/gid offsetting for each files.
This patch add uid/gid offsetting feature to mkfs.erofs.
Example of how to use uid/gid offset:
In case of lxc guest image.
Image creation:
mkafs.erofs --uid-offset=100000 --gid-offset=100000 file dir
Set lxc config:
lxc.idmap = u 0 100000 65536
lxc.idmap = g 0 100000 65536
Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
---
include/erofs/config.h | 1 +
lib/inode.c | 2 ++
mkfs/main.c | 18 ++++++++++++++++++
3 files changed, 21 insertions(+)
diff --git a/include/erofs/config.h b/include/erofs/config.h
index 0d0916c..19b7a67 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -67,6 +67,7 @@ struct erofs_configure {
u32 c_dict_size;
u64 c_unix_timestamp;
u32 c_uid, c_gid;
+ u32 c_uid_offset, c_gid_offset;
#ifdef WITH_ANDROID
char *mount_point;
char *target_out_path;
diff --git a/lib/inode.c b/lib/inode.c
index f192510..cc72c01 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -836,6 +836,8 @@ static int erofs_fill_inode(struct erofs_inode *inode,
inode->i_mode = st->st_mode;
inode->i_uid = cfg.c_uid == -1 ? st->st_uid : cfg.c_uid;
inode->i_gid = cfg.c_gid == -1 ? st->st_gid : cfg.c_gid;
+ inode->i_uid += cfg.c_uid_offset;
+ inode->i_gid += cfg.c_gid_offset;
inode->i_mtime = st->st_mtime;
inode->i_mtime_nsec = ST_MTIM_NSEC(st);
diff --git a/mkfs/main.c b/mkfs/main.c
index d2c9830..819b1f0 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -51,6 +51,8 @@ static struct option long_options[] = {
{"blobdev", required_argument, NULL, 13},
{"ignore-mtime", no_argument, NULL, 14},
{"preserve-mtime", no_argument, NULL, 15},
+ {"uid-offset", required_argument, NULL, 16},
+ {"gid-offset", required_argument, NULL, 17},
#ifdef WITH_ANDROID
{"mount-point", required_argument, NULL, 512},
{"product-out", required_argument, NULL, 513},
@@ -97,6 +99,8 @@ static void usage(void)
#endif
" --force-uid=# set all file uids to # (# = UID)\n"
" --force-gid=# set all file gids to # (# = GID)\n"
+ " --uid-offset=# add offset # to all file uids (# = id offset)\n"
+ " --gid-offset=# add offset # to all file gids (# = id offset)\n"
" --help display this help and exit\n"
" --ignore-mtime use build time instead of strict per-file modification time\n"
" --max-extent-bytes=# set maximum decompressed extent size # in bytes\n"
@@ -323,6 +327,20 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
case 10:
cfg.c_compress_hints_file = optarg;
break;
+ case 16:
+ cfg.c_uid_offset = strtoul(optarg, &endptr, 0);
+ if (cfg.c_uid_offset == -1 || *endptr != '\0') {
+ erofs_err("invalid uid offset %s", optarg);
+ return -EINVAL;
+ }
+ break;
+ case 17:
+ cfg.c_gid_offset = strtoul(optarg, &endptr, 0);
+ if (cfg.c_gid_offset == -1 || *endptr != '\0') {
+ erofs_err("invalid gid offset %s", optarg);
+ return -EINVAL;
+ }
+ break;
#ifdef WITH_ANDROID
case 512:
cfg.mount_point = optarg;
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] erofs-utils: mkfs: updating man to use uid/gid offsetting support
2022-08-14 2:29 [PATCH 1/2] erofs-utils: mkfs: improvement for unprivileged container support Naoto Yamaguchi
@ 2022-08-14 2:29 ` Naoto Yamaguchi
2022-08-14 6:18 ` Gao Xiang
2022-08-14 6:21 ` [PATCH 1/2] erofs-utils: mkfs: improvement for unprivileged container support Gao Xiang
1 sibling, 1 reply; 4+ messages in thread
From: Naoto Yamaguchi @ 2022-08-14 2:29 UTC (permalink / raw)
To: linux-erofs; +Cc: Naoto Yamaguchi
Previous commit add support uid/gid offsetting.
This patch add information of these option to man/mkfs.erofs.1.
Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
---
man/mkfs.erofs.1 | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/man/mkfs.erofs.1 b/man/mkfs.erofs.1
index d811f20..cbc4ae2 100644
--- a/man/mkfs.erofs.1
+++ b/man/mkfs.erofs.1
@@ -108,11 +108,21 @@ You may give multiple `--exclude-regex` options.
Specify a \fIfile_contexts\fR file to setup / override selinux labels.
.TP
.BI "\-\-force-uid=" UID
-Set all file uids to \fIUID\fR.
+Set all file uids to \fIUID\fR.
.TP
.BI "\-\-force-gid=" GID
Set all file gids to \fIGID\fR.
.TP
+.BI "\-\-uid-offset=" UIDOFFSET
+Add \fIUIDOFFSET\fR to all file uids.
+When this option used combine with force-uid, the final file uids sets
+\fIUID\fR + \fIUIDOFFSET\fR.
+.TP
+.BI "\-\-id-offset=" GIDOFFSET
+Add \fIGIDOFFSET\fR to all file gids.
+When this option used combine with force-gid, the final file gids sets
+\fIGID\fR + \fIGID-OFFSET\fR.
+.TP
.B \-\-help
Display this help and exit.
.TP
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] erofs-utils: mkfs: updating man to use uid/gid offsetting support
2022-08-14 2:29 ` [PATCH 2/2] erofs-utils: mkfs: updating man to use uid/gid offsetting support Naoto Yamaguchi
@ 2022-08-14 6:18 ` Gao Xiang
0 siblings, 0 replies; 4+ messages in thread
From: Gao Xiang @ 2022-08-14 6:18 UTC (permalink / raw)
To: Naoto Yamaguchi; +Cc: Naoto Yamaguchi, linux-erofs
On Sun, Aug 14, 2022 at 11:29:15AM +0900, Naoto Yamaguchi wrote:
> Previous commit add support uid/gid offsetting.
> This patch add information of these option to man/mkfs.erofs.1.
>
> Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
> ---
> man/mkfs.erofs.1 | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/man/mkfs.erofs.1 b/man/mkfs.erofs.1
> index d811f20..cbc4ae2 100644
> --- a/man/mkfs.erofs.1
> +++ b/man/mkfs.erofs.1
> @@ -108,11 +108,21 @@ You may give multiple `--exclude-regex` options.
> Specify a \fIfile_contexts\fR file to setup / override selinux labels.
> .TP
> .BI "\-\-force-uid=" UID
> -Set all file uids to \fIUID\fR.
> +Set all file uids to \fIUID\fR.
> .TP
> .BI "\-\-force-gid=" GID
> Set all file gids to \fIGID\fR.
> .TP
> +.BI "\-\-uid-offset=" UIDOFFSET
> +Add \fIUIDOFFSET\fR to all file uids.
> +When this option used combine with force-uid, the final file uids sets
> +\fIUID\fR + \fIUIDOFFSET\fR.
> +.TP
> +.BI "\-\-id-offset=" GIDOFFSET
This should be --gid-offset. Also these would be better to be
in alphabet order.
I will update these by hand.
Thanks,
Gao Xiang
> +Add \fIGIDOFFSET\fR to all file gids.
> +When this option used combine with force-gid, the final file gids sets
> +\fIGID\fR + \fIGID-OFFSET\fR.
> +.TP
> .B \-\-help
> Display this help and exit.
> .TP
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] erofs-utils: mkfs: improvement for unprivileged container support
2022-08-14 2:29 [PATCH 1/2] erofs-utils: mkfs: improvement for unprivileged container support Naoto Yamaguchi
2022-08-14 2:29 ` [PATCH 2/2] erofs-utils: mkfs: updating man to use uid/gid offsetting support Naoto Yamaguchi
@ 2022-08-14 6:21 ` Gao Xiang
1 sibling, 0 replies; 4+ messages in thread
From: Gao Xiang @ 2022-08-14 6:21 UTC (permalink / raw)
To: Naoto Yamaguchi; +Cc: Naoto Yamaguchi, linux-erofs
On Sun, Aug 14, 2022 at 11:29:14AM +0900, Naoto Yamaguchi wrote:
> When developer want to use erofs at guest container rootfs, it require
> to uid/gid offsetting for each files.
> This patch add uid/gid offsetting feature to mkfs.erofs.
>
> Example of how to use uid/gid offset:
> In case of lxc guest image.
>
> Image creation:
> mkafs.erofs --uid-offset=100000 --gid-offset=100000 file dir
>
> Set lxc config:
> lxc.idmap = u 0 100000 65536
> lxc.idmap = g 0 100000 65536
>
> Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
> ---
> include/erofs/config.h | 1 +
> lib/inode.c | 2 ++
> mkfs/main.c | 18 ++++++++++++++++++
> 3 files changed, 21 insertions(+)
>
> diff --git a/include/erofs/config.h b/include/erofs/config.h
> index 0d0916c..19b7a67 100644
> --- a/include/erofs/config.h
> +++ b/include/erofs/config.h
> @@ -67,6 +67,7 @@ struct erofs_configure {
> u32 c_dict_size;
> u64 c_unix_timestamp;
> u32 c_uid, c_gid;
> + u32 c_uid_offset, c_gid_offset;
> #ifdef WITH_ANDROID
> char *mount_point;
> char *target_out_path;
> diff --git a/lib/inode.c b/lib/inode.c
> index f192510..cc72c01 100644
> --- a/lib/inode.c
> +++ b/lib/inode.c
> @@ -836,6 +836,8 @@ static int erofs_fill_inode(struct erofs_inode *inode,
> inode->i_mode = st->st_mode;
> inode->i_uid = cfg.c_uid == -1 ? st->st_uid : cfg.c_uid;
> inode->i_gid = cfg.c_gid == -1 ? st->st_gid : cfg.c_gid;
> + inode->i_uid += cfg.c_uid_offset;
> + inode->i_gid += cfg.c_gid_offset;
> inode->i_mtime = st->st_mtime;
> inode->i_mtime_nsec = ST_MTIM_NSEC(st);
>
> diff --git a/mkfs/main.c b/mkfs/main.c
> index d2c9830..819b1f0 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -51,6 +51,8 @@ static struct option long_options[] = {
> {"blobdev", required_argument, NULL, 13},
> {"ignore-mtime", no_argument, NULL, 14},
> {"preserve-mtime", no_argument, NULL, 15},
> + {"uid-offset", required_argument, NULL, 16},
> + {"gid-offset", required_argument, NULL, 17},
> #ifdef WITH_ANDROID
> {"mount-point", required_argument, NULL, 512},
> {"product-out", required_argument, NULL, 513},
> @@ -97,6 +99,8 @@ static void usage(void)
> #endif
> " --force-uid=# set all file uids to # (# = UID)\n"
> " --force-gid=# set all file gids to # (# = GID)\n"
> + " --uid-offset=# add offset # to all file uids (# = id offset)\n"
> + " --gid-offset=# add offset # to all file gids (# = id offset)\n"
I will update this here to follow alphabet order as well.
Thanks,
Gao Xiang
> " --help display this help and exit\n"
> " --ignore-mtime use build time instead of strict per-file modification time\n"
> " --max-extent-bytes=# set maximum decompressed extent size # in bytes\n"
> @@ -323,6 +327,20 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
> case 10:
> cfg.c_compress_hints_file = optarg;
> break;
> + case 16:
> + cfg.c_uid_offset = strtoul(optarg, &endptr, 0);
> + if (cfg.c_uid_offset == -1 || *endptr != '\0') {
> + erofs_err("invalid uid offset %s", optarg);
> + return -EINVAL;
> + }
> + break;
> + case 17:
> + cfg.c_gid_offset = strtoul(optarg, &endptr, 0);
> + if (cfg.c_gid_offset == -1 || *endptr != '\0') {
> + erofs_err("invalid gid offset %s", optarg);
> + return -EINVAL;
> + }
> + break;
> #ifdef WITH_ANDROID
> case 512:
> cfg.mount_point = optarg;
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-14 6:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-14 2:29 [PATCH 1/2] erofs-utils: mkfs: improvement for unprivileged container support Naoto Yamaguchi
2022-08-14 2:29 ` [PATCH 2/2] erofs-utils: mkfs: updating man to use uid/gid offsetting support Naoto Yamaguchi
2022-08-14 6:18 ` Gao Xiang
2022-08-14 6:21 ` [PATCH 1/2] erofs-utils: mkfs: improvement for unprivileged container support Gao Xiang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.