Skip to content

Commit d1d58b9

Browse files
committed
Add MKE2FS_POPULATE_UID MKE2FS_POPULATE_GID ...
- Add MKE2FS_POPULATE_UID and MKE2FS_POPULATE_GID env vars for use with -d option - To implement mksquashfs -all-root option equivalent: the env vars will come in handy when creating a file system without root privileges
1 parent c2b1ec5 commit d1d58b9

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

misc/create_inode.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,13 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
967967
goto out;
968968
}
969969

970+
if (fs_callbacks && fs_callbacks->new_inode_extra) {
971+
retval = fs_callbacks->new_inode_extra(fs, target->path,
972+
name, parent_ino, root, &st);
973+
if (retval)
974+
goto out;
975+
}
976+
970977
retval = set_inode_extra(fs, ino, &st);
971978
if (retval) {
972979
com_err(__func__, retval,

misc/create_inode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ struct fs_ops_callbacks {
3131
errcode_t (* end_create_new_inode)(ext2_filsys fs,
3232
const char *target_path, const char *name,
3333
ext2_ino_t parent_ino, ext2_ino_t root, mode_t mode);
34+
errcode_t (* new_inode_extra)(ext2_filsys fs, const char *target_path,
35+
const char *name, ext2_ino_t parent_ino, ext2_ino_t root,
36+
struct stat *st);
3437
};
3538

3639
extern int no_copy_xattrs; /* this should eventually be a flag

misc/mke2fs.8.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,10 @@ sector size of the
842842
.B MKE2FS_SKIP_CHECK_MSG
843843
If set, do not show the message of filesystem automatic check caused by
844844
mount count or check interval.
845+
.TP
846+
.B MKE2FS_POPULATE_UID MKE2FS_POPULATE_GID
847+
With \fB-d\fR option, set UID and GID of the copied files in the newly created
848+
file system.
845849
.SH AUTHOR
846850
This version of
847851
.B mke2fs

misc/mke2fs.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ static int sync_kludge; /* Set using the MKE2FS_SYNC env. option */
116116
char **fs_types;
117117
const char *src_root_dir; /* Copy files from the specified directory */
118118
static char *undo_file;
119+
static int use_populate_id;
120+
static uid_t populate_uid;
121+
static gid_t populate_gid;
119122

120123
static int android_sparse_file; /* -E android_sparse */
121124

@@ -1665,6 +1668,16 @@ static void PRS(int argc, char *argv[])
16651668
break;
16661669
case 'd':
16671670
src_root_dir = optarg;
1671+
tmp = getenv("MKE2FS_POPULATE_UID");
1672+
if (tmp) {
1673+
populate_uid = atoi(tmp);
1674+
use_populate_id = 1;
1675+
}
1676+
tmp = getenv("MKE2FS_POPULATE_GID");
1677+
if (tmp) {
1678+
populate_gid = atoi(tmp);
1679+
use_populate_id = 1;
1680+
}
16681681
break;
16691682
case 'D':
16701683
direct_io = 1;
@@ -2907,6 +2920,16 @@ static errcode_t set_error_behavior(ext2_filsys fs)
29072920
return 0;
29082921
}
29092922

2923+
errcode_t cb_populate_new_inode_extra (ext2_filsys fs, const char *target_path,
2924+
const char *name, ext2_ino_t parent_ino, ext2_ino_t root,
2925+
struct stat *st)
2926+
{
2927+
st->st_uid = populate_uid;
2928+
st->st_gid = populate_gid;
2929+
2930+
return 0;
2931+
}
2932+
29102933
int main (int argc, char *argv[])
29112934
{
29122935
errcode_t retval = 0;
@@ -3369,11 +3392,18 @@ int main (int argc, char *argv[])
33693392
com_err(program_name, retval, "while creating huge files");
33703393
/* Copy files from the specified directory */
33713394
if (src_root_dir) {
3395+
struct fs_ops_callbacks fs_ops_callbacks;
3396+
3397+
memset(&fs_ops_callbacks, 0, sizeof(fs_ops_callbacks));
3398+
if (use_populate_id)
3399+
fs_ops_callbacks.new_inode_extra =
3400+
cb_populate_new_inode_extra;
3401+
33723402
if (!quiet)
33733403
printf("%s", _("Copying files into the device: "));
33743404

3375-
retval = populate_fs(fs, EXT2_ROOT_INO, src_root_dir,
3376-
EXT2_ROOT_INO);
3405+
retval = populate_fs2(fs, EXT2_ROOT_INO, src_root_dir,
3406+
EXT2_ROOT_INO, &fs_ops_callbacks);
33773407
if (retval) {
33783408
com_err(program_name, retval, "%s",
33793409
_("while populating file system"));

0 commit comments

Comments
 (0)