e2fsprogs: Add option `-0' to set default uid/gid to 0

Signed-off-by: hmz007 <hmz007@gmail.com>
master
hmz007 3 years ago
parent 22e12842f0
commit 1f1fd2b232

@ -42,6 +42,8 @@
/* 64KiB is the minimum blksize to best minimize system call overhead. */
#define COPY_FILE_BUFLEN 65536
int uses_default_owner = 0;
static int ext2_file_type(unsigned int mode)
{
if (LINUX_S_ISREG(mode))
@ -120,10 +122,17 @@ static errcode_t set_inode_extra(ext2_filsys fs, ext2_ino_t ino,
return retval;
}
inode.i_uid = st->st_uid;
ext2fs_set_i_uid_high(inode, st->st_uid >> 16);
inode.i_gid = st->st_gid;
ext2fs_set_i_gid_high(inode, st->st_gid >> 16);
if (uses_default_owner) {
inode.i_uid = 0;
ext2fs_set_i_uid_high(inode, 0);
inode.i_gid = 0;
ext2fs_set_i_gid_high(inode, 0);
} else {
inode.i_uid = st->st_uid;
ext2fs_set_i_uid_high(inode, st->st_uid >> 16);
inode.i_gid = st->st_gid;
ext2fs_set_i_gid_high(inode, st->st_gid >> 16);
}
inode.i_mode = (LINUX_S_IFMT & inode.i_mode) | (~S_IFMT & st->st_mode);
inode.i_atime = st->st_atime;
inode.i_mtime = st->st_mtime;

@ -91,6 +91,7 @@ static int noaction;
static int num_backups = 2; /* number of backup bg's for sparse_super2 */
static uid_t root_uid;
static gid_t root_gid;
extern int uses_default_owner;
int journal_size;
int journal_flags;
int journal_fc_size;
@ -139,7 +140,7 @@ static void usage(void)
"[-r fs-revision] [-E extended-option[,...]]\n"
"\t[-t fs-type] [-T usage-type ] [-U UUID] [-e errors_behavior]"
"[-z undo_file]\n"
"\t[-jnqvDFSV] device [blocks-count]\n"),
"\t[-jnqvDFSV0] device [blocks-count]\n"),
program_name);
exit(1);
}
@ -1652,7 +1653,7 @@ profile_error:
}
while ((c = getopt (argc, argv,
"b:cd:e:g:i:jl:m:no:qr:s:t:vC:DE:FG:I:J:KL:M:N:O:R:ST:U:Vz:")) != EOF) {
"b:cd:e:g:i:jl:m:no:qr:s:t:vC:DE:FG:I:J:KL:M:N:O:R:ST:U:Vz:0")) != EOF) {
switch (c) {
case 'b':
blocksize = parse_num_blocks2(optarg, -1);
@ -1897,6 +1898,10 @@ profile_error:
case 'z':
undo_file = optarg;
break;
case '0':
/* Set default owner/group id to 0 */
uses_default_owner = 1;
break;
default:
usage();
}

Loading…
Cancel
Save