linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ludwig Nussel <ludwig.nussel@suse.de>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Ludwig Nussel <ludwig.nussel@suse.de>
Subject: [PATCH 1/2] implement uid and gid mount options for ext2
Date: Tue, 28 Jul 2009 13:01:42 +0200	[thread overview]
Message-ID: <1248778903-3596-2-git-send-email-ludwig.nussel@suse.de> (raw)
In-Reply-To: <1248778903-3596-1-git-send-email-ludwig.nussel@suse.de>

Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
---
 Documentation/filesystems/ext2.txt |    6 ++++++
 fs/ext2/inode.c                    |   12 ++++++++++++
 fs/ext2/super.c                    |   35 ++++++++++++++++++++++++++++++++++-
 include/linux/ext2_fs_sb.h         |    4 ++++
 4 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/Documentation/filesystems/ext2.txt b/Documentation/filesystems/ext2.txt
index 67639f9..5501ae0 100644
--- a/Documentation/filesystems/ext2.txt
+++ b/Documentation/filesystems/ext2.txt
@@ -42,6 +42,12 @@ orlov			(*)	Use the Orlov block allocator.
 resuid=n			The user ID which may use the reserved blocks.
 resgid=n			The group ID which may use the reserved blocks.
 
+uid=n[:m]			make all files appear to belong to this is uid.
+				The optional second uid is actually written do disk.
+
+gid=n[:m]			make all files appear to belong to this is gid.
+				The optional second gid is actually written do disk.
+
 sb=n				Use alternate superblock at this location.
 
 user_xattr			Enable "user." POSIX Extended Attributes
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index e271303..7ceb73c 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -1239,6 +1239,12 @@ 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 = EXT2_SB(sb)->s_uid;
+	}
+	if (EXT2_SB(sb)->s_gid) {
+		inode->i_gid = EXT2_SB(sb)->s_gid;
+	}
 	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);
@@ -1353,6 +1359,12 @@ int ext2_write_inode(struct inode *inode, int do_sync)
 
 	ext2_get_inode_flags(ei);
 	raw_inode->i_mode = cpu_to_le16(inode->i_mode);
+	if (EXT2_SB(sb)->s_uid) {
+		uid = EXT2_SB(sb)->s_diskuid;
+	}
+	if (EXT2_SB(sb)->s_gid) {
+		gid = EXT2_SB(sb)->s_diskgid;
+	}
 	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 1a9ffee..f89b407 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -382,7 +382,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, Opt_diskuid, Opt_gid, Opt_diskgid
 };
 
 static const match_table_t tokens = {
@@ -416,6 +417,10 @@ static const match_table_t tokens = {
 	{Opt_usrquota, "usrquota"},
 	{Opt_reservation, "reservation"},
 	{Opt_noreservation, "noreservation"},
+	{Opt_uid, "uid=%u"},
+	{Opt_diskuid, "uid=%u:%u"},
+	{Opt_gid, "gid=%u"},
+	{Opt_diskgid, "gid=%u:%u"},
 	{Opt_err, NULL}
 };
 
@@ -556,6 +561,34 @@ 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 = sbi->s_diskuid = option;
+			break;
+		case Opt_diskuid:
+			if (match_int(&args[0], &option))
+				return 0;
+			sbi->s_uid = option;
+
+			if (match_int(&args[1], &option))
+				return 0;
+			sbi->s_diskuid = option;
+			break;
+		case Opt_gid:
+			if (match_int(&args[0], &option))
+				return 0;
+			sbi->s_gid = sbi->s_diskgid = option;
+			break;
+		case Opt_diskgid:
+			if (match_int(&args[0], &option))
+				return 0;
+			sbi->s_gid = option;
+
+			if (match_int(&args[1], &option))
+				return 0;
+			sbi->s_diskgid = 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..062e8a9 100644
--- a/include/linux/ext2_fs_sb.h
+++ b/include/linux/ext2_fs_sb.h
@@ -88,6 +88,10 @@ struct ext2_sb_info {
 	unsigned long s_sb_block;
 	uid_t s_resuid;
 	gid_t s_resgid;
+	uid_t s_uid;                    /* make all files appear to belong to this uid */
+	uid_t s_diskuid;                /* write this uid to disk (if s_uid != 0) */
+	gid_t s_gid;                    /* make all files appear to belong to this gid */
+	gid_t s_diskgid;                /* write this gid to disk (if s_gid != 0) */
 	unsigned short s_mount_state;
 	unsigned short s_pad;
 	int s_addr_per_block_bits;
-- 
1.6.2.1


  reply	other threads:[~2009-07-28 11:01 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-23 14:37 ` [PATCH 0/2] implement uid mount option for ext2 and ext3 Randy Dunlap
2009-07-23 21:23 ` Valdis.Kletnieks
2009-07-24 10:23   ` Ludwig Nussel
2009-07-30  9:07     ` Pavel Machek
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
2009-07-24 16:52     ` [PATCH 1/2] implement uid mount option for ext2 Andreas Dilger
2009-07-24 18:58       ` John Stoffel
2009-07-24 23:16         ` Jamie Lokier
2009-07-27 14:56           ` John Stoffel
2009-07-25 15:44       ` Ludwig Nussel
2009-07-27 19:14         ` Andreas Dilger
2009-07-28  7:50           ` Ludwig Nussel
2009-07-28 11:01 ` [PATCH 0/2] implement uid mount option for ext2 and ext3, try 3 Ludwig Nussel
2009-07-28 11:01   ` Ludwig Nussel [this message]
2009-07-28 11:01     ` [PATCH 2/2] implement uid and gid mount options for ext3 Ludwig Nussel
2009-07-28 18:11   ` [PATCH 0/2] implement uid mount option for ext2 and ext3, try 3 Andreas Dilger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1248778903-3596-2-git-send-email-ludwig.nussel@suse.de \
    --to=ludwig.nussel@suse.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).