linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] [PATCH 0/2] implement uid mount option for ext2 and ext3
@ 2009-04-08 13:21 Ludwig Nussel
  2009-04-08 13:21 ` [PATCH 1/2] implement uid mount option for ext2 Ludwig Nussel
  2009-04-08 13:21 ` [PATCH 2/2] implement uid mount option for ext3 Ludwig Nussel
  0 siblings, 2 replies; 5+ messages in thread
From: Ludwig Nussel @ 2009-04-08 13:21 UTC (permalink / raw)
  To: linux-fsdevel

Hi,

When using 'real' file systems on removable storage devices such as
hard disks or usb sticks people quickly face the problem that their
Linux users have different uids on different machines. Therefore one
cannot modify or even read files created on a different machine
without running chown as root or storing everything with mode 777.
Simple file systems such as vfat don't have that problem as they
don't store file ownership information and one can pass the uid
files should belong to as mount option.

The following two patches (for 2.6.29) therefore implement the uid
mount option for ext2 and ext3 to make them actually useful on
removable media. My implementation just writes uid 0 to disk for
files that are owned by the specified user. In read direction files
with uid 0 appear as being owned by the specified user.

In an ideal world this would probably be implemented as vfs feature
rather than having it in every single file system.

Anyways, AFAICT the method works just fine for ext2. I'm not sure
about the ext3 patch though as ext3 has that ext3_setattr() function
for journaling. I don't know if the uid should better be mangled
there instead.

cu
Ludwig

-- 
 (o_   Ludwig Nussel
 //\   
 V_/_  http://www.suse.de/
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] implement uid mount option for ext2
  2009-04-08 13:21 [RFC] [PATCH 0/2] implement uid mount option for ext2 and ext3 Ludwig Nussel
@ 2009-04-08 13:21 ` Ludwig Nussel
  2009-04-08 13:21 ` [PATCH 2/2] implement uid mount option for ext3 Ludwig Nussel
  1 sibling, 0 replies; 5+ messages in thread
From: Ludwig Nussel @ 2009-04-08 13:21 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Ludwig Nussel

Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
---
 fs/ext2/inode.c            |   11 ++++++++++-
 fs/ext2/super.c            |    9 ++++++++-
 include/linux/ext2_fs_sb.h |    1 +
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 23fff2f..e631b16 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -1223,6 +1223,9 @@ struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
 		inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
 		inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
 	}
+	if (EXT2_SB(sb)->s_uid && inode->i_uid == 0) {
+		inode->i_uid = EXT2_SB(sb)->s_uid;
+	}
 	inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
 	inode->i_size = le32_to_cpu(raw_inode->i_size);
 	inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
@@ -1337,7 +1340,13 @@ static int ext2_update_inode(struct inode * inode, int do_sync)
 
 	ext2_get_inode_flags(ei);
 	raw_inode->i_mode = cpu_to_le16(inode->i_mode);
-	if (!(test_opt(sb, NO_UID32))) {
+	if (EXT2_SB(sb)->s_uid &&
+	    inode->i_uid == EXT2_SB(sb)->s_uid) {
+		raw_inode->i_uid_high = 0;
+		raw_inode->i_uid_low  = 0;
+		raw_inode->i_gid_high = 0;
+		raw_inode->i_gid_low  = 0;
+	} else if (!(test_opt(sb, NO_UID32))) {
 		raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
 		raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
 /*
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 7c6e360..bb95dee 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -391,7 +391,8 @@ enum {
 	Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
 	Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
 	Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
-	Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
+	Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
+	Opt_uid
 };
 
 static const match_table_t tokens = {
@@ -425,6 +426,7 @@ static const match_table_t tokens = {
 	{Opt_usrquota, "usrquota"},
 	{Opt_reservation, "reservation"},
 	{Opt_noreservation, "noreservation"},
+	{Opt_uid, "uid=%u"},
 	{Opt_err, NULL}
 };
 
@@ -565,6 +567,11 @@ static int parse_options (char * options,
 			clear_opt(sbi->s_mount_opt, RESERVATION);
 			printk("reservations OFF\n");
 			break;
+		case Opt_uid:
+			if (match_int(&args[0], &option))
+				return 0;
+			sbi->s_uid = option;
+			break;
 		case Opt_ignore:
 			break;
 		default:
diff --git a/include/linux/ext2_fs_sb.h b/include/linux/ext2_fs_sb.h
index 1cdb663..a4b0b79 100644
--- a/include/linux/ext2_fs_sb.h
+++ b/include/linux/ext2_fs_sb.h
@@ -88,6 +88,7 @@ struct ext2_sb_info {
 	unsigned long s_sb_block;
 	uid_t s_resuid;
 	gid_t s_resgid;
+	uid_t s_uid;                    /* map root owned files to this uid */
 	unsigned short s_mount_state;
 	unsigned short s_pad;
 	int s_addr_per_block_bits;
-- 
1.6.0.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] implement uid mount option for ext3
  2009-04-08 13:21 [RFC] [PATCH 0/2] implement uid mount option for ext2 and ext3 Ludwig Nussel
  2009-04-08 13:21 ` [PATCH 1/2] implement uid mount option for ext2 Ludwig Nussel
@ 2009-04-08 13:21 ` Ludwig Nussel
  1 sibling, 0 replies; 5+ messages in thread
From: Ludwig Nussel @ 2009-04-08 13:21 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Ludwig Nussel

Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
---
 fs/ext3/inode.c            |   11 ++++++++++-
 fs/ext3/super.c            |    8 +++++++-
 include/linux/ext3_fs_sb.h |    1 +
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 5fa453b..d4c8525 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -2729,6 +2729,9 @@ struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
 		inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
 		inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
 	}
+	if (EXT3_SB(sb)->s_uid && inode->i_uid == 0) {
+		inode->i_uid = EXT3_SB(sb)->s_uid;
+	}
 	inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
 	inode->i_size = le32_to_cpu(raw_inode->i_size);
 	inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
@@ -2868,7 +2871,13 @@ static int ext3_do_update_inode(handle_t *handle,
 
 	ext3_get_inode_flags(ei);
 	raw_inode->i_mode = cpu_to_le16(inode->i_mode);
-	if(!(test_opt(inode->i_sb, NO_UID32))) {
+	if (EXT3_SB(inode->i_sb)->s_uid &&
+	    inode->i_uid == EXT3_SB(inode->i_sb)->s_uid) {
+		raw_inode->i_uid_high = 0;
+		raw_inode->i_uid_low  = 0;
+		raw_inode->i_gid_high = 0;
+		raw_inode->i_gid_low  = 0;
+	} else if(!(test_opt(inode->i_sb, NO_UID32))) {
 		raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
 		raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
 /*
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 4a97041..5122213 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -790,7 +790,7 @@ enum {
 	Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
 	Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
 	Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
-	Opt_grpquota
+	Opt_grpquota, Opt_uid
 };
 
 static const match_table_t tokens = {
@@ -843,6 +843,7 @@ static const match_table_t tokens = {
 	{Opt_usrquota, "usrquota"},
 	{Opt_barrier, "barrier=%u"},
 	{Opt_resize, "resize"},
+	{Opt_uid, "uid=%u"},
 	{Opt_err, NULL},
 };
 
@@ -1194,6 +1195,11 @@ set_qf_format:
 		case Opt_bh:
 			clear_opt(sbi->s_mount_opt, NOBH);
 			break;
+		case Opt_uid:
+			if (match_int(&args[0], &option))
+				return 0;
+			sbi->s_uid = option;
+			break;
 		default:
 			printk (KERN_ERR
 				"EXT3-fs: Unrecognized mount option \"%s\" "
diff --git a/include/linux/ext3_fs_sb.h b/include/linux/ext3_fs_sb.h
index f07f34d..751058a 100644
--- a/include/linux/ext3_fs_sb.h
+++ b/include/linux/ext3_fs_sb.h
@@ -47,6 +47,7 @@ struct ext3_sb_info {
 	ext3_fsblk_t s_sb_block;
 	uid_t s_resuid;
 	gid_t s_resgid;
+	uid_t s_uid;                    /* map root owned files to this uid */
 	unsigned short s_mount_state;
 	unsigned short s_pad;
 	int s_addr_per_block_bits;
-- 
1.6.0.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] implement uid mount option for ext3
  2009-07-23 11:36 ` [PATCH 1/2] implement uid mount option for ext2 Ludwig Nussel
@ 2009-07-23 11:36   ` Ludwig Nussel
  0 siblings, 0 replies; 5+ messages in thread
From: Ludwig Nussel @ 2009-07-23 11:36 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-kernel, Ludwig Nussel

Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
---
 fs/ext3/inode.c            |   11 ++++++++++-
 fs/ext3/super.c            |    8 +++++++-
 include/linux/ext3_fs_sb.h |    1 +
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 5f51fed..148a4d3 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -2766,6 +2766,9 @@ struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
 		inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
 		inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
 	}
+	if (EXT3_SB(sb)->s_uid && inode->i_uid == 0) {
+		inode->i_uid = EXT3_SB(sb)->s_uid;
+	}
 	inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
 	inode->i_size = le32_to_cpu(raw_inode->i_size);
 	inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
@@ -2905,7 +2908,13 @@ static int ext3_do_update_inode(handle_t *handle,
 
 	ext3_get_inode_flags(ei);
 	raw_inode->i_mode = cpu_to_le16(inode->i_mode);
-	if(!(test_opt(inode->i_sb, NO_UID32))) {
+	if (EXT3_SB(inode->i_sb)->s_uid &&
+	    inode->i_uid == EXT3_SB(inode->i_sb)->s_uid) {
+		raw_inode->i_uid_high = 0;
+		raw_inode->i_uid_low  = 0;
+		raw_inode->i_gid_high = 0;
+		raw_inode->i_gid_low  = 0;
+	} else if(!(test_opt(inode->i_sb, NO_UID32))) {
 		raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
 		raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
 /*
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 524b349..b610242 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -779,7 +779,7 @@ enum {
 	Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
 	Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
 	Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
-	Opt_grpquota
+	Opt_grpquota, Opt_uid
 };
 
 static const match_table_t tokens = {
@@ -832,6 +832,7 @@ static const match_table_t tokens = {
 	{Opt_usrquota, "usrquota"},
 	{Opt_barrier, "barrier=%u"},
 	{Opt_resize, "resize"},
+	{Opt_uid, "uid=%u"},
 	{Opt_err, NULL},
 };
 
@@ -1183,6 +1184,11 @@ set_qf_format:
 		case Opt_bh:
 			clear_opt(sbi->s_mount_opt, NOBH);
 			break;
+		case Opt_uid:
+			if (match_int(&args[0], &option))
+				return 0;
+			sbi->s_uid = option;
+			break;
 		default:
 			printk (KERN_ERR
 				"EXT3-fs: Unrecognized mount option \"%s\" "
diff --git a/include/linux/ext3_fs_sb.h b/include/linux/ext3_fs_sb.h
index f07f34d..751058a 100644
--- a/include/linux/ext3_fs_sb.h
+++ b/include/linux/ext3_fs_sb.h
@@ -47,6 +47,7 @@ struct ext3_sb_info {
 	ext3_fsblk_t s_sb_block;
 	uid_t s_resuid;
 	gid_t s_resgid;
+	uid_t s_uid;                    /* map root owned files to this uid */
 	unsigned short s_mount_state;
 	unsigned short s_pad;
 	int s_addr_per_block_bits;
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] implement uid mount option for ext3
  2009-07-24 10:30   ` [PATCH 1/2] implement uid mount option for ext2 Ludwig Nussel
@ 2009-07-24 10:30     ` Ludwig Nussel
  0 siblings, 0 replies; 5+ messages in thread
From: Ludwig Nussel @ 2009-07-24 10:30 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-kernel, Ludwig Nussel

Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
---
 Documentation/filesystems/ext3.txt |    2 ++
 fs/ext3/inode.c                    |   11 ++++++++++-
 fs/ext3/super.c                    |    8 +++++++-
 include/linux/ext3_fs_sb.h         |    1 +
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/Documentation/filesystems/ext3.txt b/Documentation/filesystems/ext3.txt
index 570f9bd..abdb2f6 100644
--- a/Documentation/filesystems/ext3.txt
+++ b/Documentation/filesystems/ext3.txt
@@ -121,6 +121,8 @@ resgid=n		The group ID which may use the reserved blocks.
 
 resuid=n		The user ID which may use the reserved blocks.
 
+uid=n			Map root owned files to this uid.
+
 sb=n			Use alternate superblock at this location.
 
 quota
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 5f51fed..148a4d3 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -2766,6 +2766,9 @@ struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
 		inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
 		inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
 	}
+	if (EXT3_SB(sb)->s_uid && inode->i_uid == 0) {
+		inode->i_uid = EXT3_SB(sb)->s_uid;
+	}
 	inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
 	inode->i_size = le32_to_cpu(raw_inode->i_size);
 	inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
@@ -2905,7 +2908,13 @@ static int ext3_do_update_inode(handle_t *handle,
 
 	ext3_get_inode_flags(ei);
 	raw_inode->i_mode = cpu_to_le16(inode->i_mode);
-	if(!(test_opt(inode->i_sb, NO_UID32))) {
+	if (EXT3_SB(inode->i_sb)->s_uid &&
+	    inode->i_uid == EXT3_SB(inode->i_sb)->s_uid) {
+		raw_inode->i_uid_high = 0;
+		raw_inode->i_uid_low  = 0;
+		raw_inode->i_gid_high = 0;
+		raw_inode->i_gid_low  = 0;
+	} else if(!(test_opt(inode->i_sb, NO_UID32))) {
 		raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
 		raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
 /*
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 524b349..b610242 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -779,7 +779,7 @@ enum {
 	Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
 	Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
 	Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
-	Opt_grpquota
+	Opt_grpquota, Opt_uid
 };
 
 static const match_table_t tokens = {
@@ -832,6 +832,7 @@ static const match_table_t tokens = {
 	{Opt_usrquota, "usrquota"},
 	{Opt_barrier, "barrier=%u"},
 	{Opt_resize, "resize"},
+	{Opt_uid, "uid=%u"},
 	{Opt_err, NULL},
 };
 
@@ -1183,6 +1184,11 @@ set_qf_format:
 		case Opt_bh:
 			clear_opt(sbi->s_mount_opt, NOBH);
 			break;
+		case Opt_uid:
+			if (match_int(&args[0], &option))
+				return 0;
+			sbi->s_uid = option;
+			break;
 		default:
 			printk (KERN_ERR
 				"EXT3-fs: Unrecognized mount option \"%s\" "
diff --git a/include/linux/ext3_fs_sb.h b/include/linux/ext3_fs_sb.h
index f07f34d..751058a 100644
--- a/include/linux/ext3_fs_sb.h
+++ b/include/linux/ext3_fs_sb.h
@@ -47,6 +47,7 @@ struct ext3_sb_info {
 	ext3_fsblk_t s_sb_block;
 	uid_t s_resuid;
 	gid_t s_resgid;
+	uid_t s_uid;                    /* map root owned files to this uid */
 	unsigned short s_mount_state;
 	unsigned short s_pad;
 	int s_addr_per_block_bits;
-- 
1.6.2.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-07-24 10:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-08 13:21 [RFC] [PATCH 0/2] implement uid mount option for ext2 and ext3 Ludwig Nussel
2009-04-08 13:21 ` [PATCH 1/2] implement uid mount option for ext2 Ludwig Nussel
2009-04-08 13:21 ` [PATCH 2/2] implement uid mount option for ext3 Ludwig Nussel
  -- strict thread matches above, loose matches on Subject: below --
2009-07-23 11:36 [PATCH 0/2] implement uid mount option for ext2 and ext3 Ludwig Nussel
2009-07-23 11:36 ` [PATCH 1/2] implement uid mount option for ext2 Ludwig Nussel
2009-07-23 11:36   ` [PATCH 2/2] implement uid mount option for ext3 Ludwig Nussel
2009-07-24 10:30 ` [PATCH 0/2] implement uid mount option for ext2 and ext3, try 2 Ludwig Nussel
2009-07-24 10:30   ` [PATCH 1/2] implement uid mount option for ext2 Ludwig Nussel
2009-07-24 10:30     ` [PATCH 2/2] implement uid mount option for ext3 Ludwig Nussel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).