diff options
author | Jaegeuk Kim <jaegeuk@kernel.org> | 2018-07-27 17:12:32 +0900 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2018-08-27 23:49:26 -0700 |
commit | bdd39ce73bd485fd56091646a80b79d5a7374991 (patch) | |
tree | d4909a2eb0be64bea2cd6f30cb908d602ee4c7c2 | |
parent | e52f0a82f9d3eb9248f0f2cfb861e69d79823f9a (diff) | |
download | f2fs-tools-bdd39ce73bd485fd56091646a80b79d5a7374991.tar.gz |
mkfs.f2fs: add root_owner to give uid/gid
This patch adds an option to mkfs.f2fs in order for user to assign uid/gid
to the target partition.
This requires when vold in android formats a sdcard partition.
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r-- | include/f2fs_fs.h | 22 | ||||
-rw-r--r-- | lib/libf2fs.c | 4 | ||||
-rw-r--r-- | man/mkfs.f2fs.8 | 8 | ||||
-rw-r--r-- | mkfs/f2fs_format.c | 12 | ||||
-rw-r--r-- | mkfs/f2fs_format_main.c | 7 |
5 files changed, 46 insertions, 7 deletions
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index 36f3c62..ef13bf0 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -384,6 +384,8 @@ struct f2fs_configuration { u_int32_t lpf_inum; u_int32_t lpf_dnum; u_int32_t lpf_ino; + u_int32_t root_uid; + u_int32_t root_gid; /* defragmentation parameters */ int defrag_shrink; @@ -1379,4 +1381,24 @@ static inline int parse_feature(struct feature *table, const char *features) free(buf); return 0; } + +static inline int parse_root_owner(char *ids, + u_int32_t *root_uid, u_int32_t *root_gid) +{ + char *uid = ids; + char *gid = NULL; + int i; + + /* uid:gid */ + for (i = 0; i < strlen(ids) - 1; i++) + if (*(ids + i) == ':') + gid = ids + i + 1; + if (!gid) + return -1; + + *root_uid = atoi(uid); + *root_gid = atoi(gid); + return 0; +} + #endif /*__F2FS_FS_H */ diff --git a/lib/libf2fs.c b/lib/libf2fs.c index 5625cff..a1f8beb 100644 --- a/lib/libf2fs.c +++ b/lib/libf2fs.c @@ -615,6 +615,10 @@ void f2fs_init_configuration(void) c.trim = 1; c.kd = -1; c.fixed_time = -1; + + /* default root owner */ + c.root_uid = getuid(); + c.root_gid = getgid(); } #ifdef HAVE_SETMNTENT diff --git a/man/mkfs.f2fs.8 b/man/mkfs.f2fs.8 index 29dd68f..f9484eb 100644 --- a/man/mkfs.f2fs.8 +++ b/man/mkfs.f2fs.8 @@ -45,6 +45,10 @@ mkfs.f2fs \- create an F2FS file system .B \-q ] [ +.B \-R +.I root_owner +] +[ .B \-s .I #-of-segments-per-section ] @@ -120,6 +124,10 @@ e.g "encrypt" and so on. Quiet mode. With it, mkfs.f2fs does not show any messages include the basic messages. .TP +.BI \-R +Give root_owner option for initial uid/gid assignment. +Default is set by getuid()/getgid(), and assigned by "-R $uid:$gid". +.TP .BI \-s " #-of-segments-per-section" Specify the number of segments per section. A section consists of multiple consecutive segments, and is the unit of garbage collection. diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c index d039434..f2880eb 100644 --- a/mkfs/f2fs_format.c +++ b/mkfs/f2fs_format.c @@ -1078,8 +1078,8 @@ static int f2fs_write_root_inode(void) raw_node->i.i_links = cpu_to_le32(3); else raw_node->i.i_links = cpu_to_le32(2); - raw_node->i.i_uid = cpu_to_le32(getuid()); - raw_node->i.i_gid = cpu_to_le32(getgid()); + raw_node->i.i_uid = cpu_to_le32(c.root_uid); + raw_node->i.i_gid = cpu_to_le32(c.root_gid); blk_size_bytes = 1 << get_sb(log_blocksize); raw_node->i.i_size = cpu_to_le64(1 * blk_size_bytes); /* dentry */ @@ -1236,8 +1236,8 @@ static int f2fs_write_qf_inode(int qtype) raw_node->i.i_mode = cpu_to_le16(0x8180); raw_node->i.i_links = cpu_to_le32(1); - raw_node->i.i_uid = cpu_to_le32(getuid()); - raw_node->i.i_gid = cpu_to_le32(getgid()); + raw_node->i.i_uid = cpu_to_le32(c.root_uid); + raw_node->i.i_gid = cpu_to_le32(c.root_gid); raw_node->i.i_size = cpu_to_le64(1024 * 6); /* Hard coded */ raw_node->i.i_blocks = cpu_to_le64(1 + QUOTA_DATA(qtype)); @@ -1435,8 +1435,8 @@ static int f2fs_write_lpf_inode(void) raw_node->i.i_mode = cpu_to_le16(0x41c0); /* 0700 */ raw_node->i.i_links = cpu_to_le32(2); - raw_node->i.i_uid = cpu_to_le32(getuid()); - raw_node->i.i_gid = cpu_to_le32(getgid()); + raw_node->i.i_uid = cpu_to_le32(c.root_uid); + raw_node->i.i_gid = cpu_to_le32(c.root_gid); blk_size_bytes = 1 << get_sb(log_blocksize); raw_node->i.i_size = cpu_to_le64(1 * blk_size_bytes); diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c index 8af70a2..6bcfbb0 100644 --- a/mkfs/f2fs_format_main.c +++ b/mkfs/f2fs_format_main.c @@ -56,6 +56,7 @@ static void mkfs_usage() MSG(0, " -o overprovision ratio [default:5]\n"); MSG(0, " -O feature1[feature2,feature3,...] e.g. \"encrypt\"\n"); MSG(0, " -q quiet mode\n"); + MSG(0, " -R root_owner [default: 0:0]\n"); MSG(0, " -s # of segments per section [default:1]\n"); MSG(0, " -S sparse mode\n"); MSG(0, " -t 0: nodiscard, 1: discard [default:1]\n"); @@ -104,7 +105,7 @@ static void add_default_options(void) static void f2fs_parse_options(int argc, char *argv[]) { - static const char *option_string = "qa:c:d:e:E:g:il:mo:O:s:S:z:t:fw:V"; + static const char *option_string = "qa:c:d:e:E:g:il:mo:O:R:s:S:z:t:fw:V"; int32_t option=0; while ((option = getopt(argc,argv,option_string)) != EOF) { @@ -162,6 +163,10 @@ static void f2fs_parse_options(int argc, char *argv[]) if (parse_feature(feature_table, optarg)) mkfs_usage(); break; + case 'R': + if (parse_root_owner(optarg, &c.root_uid, &c.root_gid)) + mkfs_usage(); + break; case 's': c.segs_per_sec = atoi(optarg); break; |