Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mke2fs: uid and gid of the copied inodes when using -d option #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions misc/create_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,13 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
goto out;
}

if (fs_callbacks && fs_callbacks->new_inode_extra) {
retval = fs_callbacks->new_inode_extra(fs, target->path,
name, parent_ino, root, &st);
if (retval)
goto out;
}

retval = set_inode_extra(fs, ino, &st);
if (retval) {
com_err(__func__, retval,
Expand Down
3 changes: 3 additions & 0 deletions misc/create_inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ struct fs_ops_callbacks {
errcode_t (* end_create_new_inode)(ext2_filsys fs,
const char *target_path, const char *name,
ext2_ino_t parent_ino, ext2_ino_t root, mode_t mode);
errcode_t (* new_inode_extra)(ext2_filsys fs, const char *target_path,
const char *name, ext2_ino_t parent_ino, ext2_ino_t root,
struct stat *st);
};

extern int no_copy_xattrs; /* this should eventually be a flag
Expand Down
4 changes: 4 additions & 0 deletions misc/mke2fs.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,10 @@ sector size of the
.B MKE2FS_SKIP_CHECK_MSG
If set, do not show the message of filesystem automatic check caused by
mount count or check interval.
.TP
.B MKE2FS_POPULATE_UID MKE2FS_POPULATE_GID
With \fB-d\fR option, set UID and GID of the copied files in the newly created
file system.
.SH AUTHOR
This version of
.B mke2fs
Expand Down
34 changes: 32 additions & 2 deletions misc/mke2fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ static int sync_kludge; /* Set using the MKE2FS_SYNC env. option */
char **fs_types;
const char *src_root_dir; /* Copy files from the specified directory */
static char *undo_file;
static int use_populate_id;
static uid_t populate_uid;
static gid_t populate_gid;

static int android_sparse_file; /* -E android_sparse */

Expand Down Expand Up @@ -1665,6 +1668,16 @@ static void PRS(int argc, char *argv[])
break;
case 'd':
src_root_dir = optarg;
tmp = getenv("MKE2FS_POPULATE_UID");
if (tmp) {
populate_uid = atoi(tmp);
use_populate_id = 1;
}
tmp = getenv("MKE2FS_POPULATE_GID");
if (tmp) {
populate_gid = atoi(tmp);
use_populate_id = 1;
}
break;
case 'D':
direct_io = 1;
Expand Down Expand Up @@ -2907,6 +2920,16 @@ static errcode_t set_error_behavior(ext2_filsys fs)
return 0;
}

errcode_t cb_populate_new_inode_extra (ext2_filsys fs, const char *target_path,
const char *name, ext2_ino_t parent_ino, ext2_ino_t root,
struct stat *st)
{
st->st_uid = populate_uid;
st->st_gid = populate_gid;

return 0;
}

int main (int argc, char *argv[])
{
errcode_t retval = 0;
Expand Down Expand Up @@ -3369,11 +3392,18 @@ int main (int argc, char *argv[])
com_err(program_name, retval, "while creating huge files");
/* Copy files from the specified directory */
if (src_root_dir) {
struct fs_ops_callbacks fs_ops_callbacks;

memset(&fs_ops_callbacks, 0, sizeof(fs_ops_callbacks));
if (use_populate_id)
fs_ops_callbacks.new_inode_extra =
cb_populate_new_inode_extra;

if (!quiet)
printf("%s", _("Copying files into the device: "));

retval = populate_fs(fs, EXT2_ROOT_INO, src_root_dir,
EXT2_ROOT_INO);
retval = populate_fs2(fs, EXT2_ROOT_INO, src_root_dir,
EXT2_ROOT_INO, &fs_ops_callbacks);
if (retval) {
com_err(program_name, retval, "%s",
_("while populating file system"));
Expand Down