2008-01-24 19:37:53

by Miklos Szeredi

[permalink] [raw]
Subject: [patch 10/26] mount options: fix devpts

From: Miklos Szeredi <[email protected]>

Add a .show_options super operation to devpts.

Also add minor fix: when parsing the "mode" option, mask with
S_IALLUGO instead of ~S_IFMT, which could leave unsed bits in the
mask.

Signed-off-by: Miklos Szeredi <[email protected]>
---

Index: linux/fs/devpts/inode.c
===================================================================
--- linux.orig/fs/devpts/inode.c 2008-01-22 23:43:12.000000000 +0100
+++ linux/fs/devpts/inode.c 2008-01-23 13:01:05.000000000 +0100
@@ -20,9 +20,12 @@
#include <linux/devpts_fs.h>
#include <linux/parser.h>
#include <linux/fsnotify.h>
+#include <linux/seq_file.h>

#define DEVPTS_SUPER_MAGIC 0x1cd1

+#define DEVPTS_DEFAULT_MODE 0600
+
static struct vfsmount *devpts_mnt;
static struct dentry *devpts_root;

@@ -32,7 +35,7 @@ static struct {
uid_t uid;
gid_t gid;
umode_t mode;
-} config = {.mode = 0600};
+} config = {.mode = DEVPTS_DEFAULT_MODE};

enum {
Opt_uid, Opt_gid, Opt_mode,
@@ -54,7 +57,7 @@ static int devpts_remount(struct super_b
config.setgid = 0;
config.uid = 0;
config.gid = 0;
- config.mode = 0600;
+ config.mode = DEVPTS_DEFAULT_MODE;

while ((p = strsep(&data, ",")) != NULL) {
substring_t args[MAX_OPT_ARGS];
@@ -81,7 +84,7 @@ static int devpts_remount(struct super_b
case Opt_mode:
if (match_octal(&args[0], &option))
return -EINVAL;
- config.mode = option & ~S_IFMT;
+ config.mode = option & S_IALLUGO;
break;
default:
printk(KERN_ERR "devpts: called with bogus options\n");
@@ -92,9 +95,22 @@ static int devpts_remount(struct super_b
return 0;
}

+static int devpts_show_options(struct seq_file *seq, struct vfsmount *vfs)
+{
+ if (config.setuid)
+ seq_printf(seq, ",uid=%u", config.uid);
+ if (config.setgid)
+ seq_printf(seq, ",gid=%u", config.gid);
+ if (config.mode != DEVPTS_DEFAULT_MODE)
+ seq_printf(seq, ",mode=%03o", config.mode);
+
+ return 0;
+}
+
static const struct super_operations devpts_sops = {
.statfs = simple_statfs,
.remount_fs = devpts_remount,
+ .show_options = devpts_show_options,
};

static int

--


2008-01-24 19:46:40

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [patch 10/26] mount options: fix devpts

Miklos Szeredi wrote:
> Also add minor fix: when parsing the "mode" option, mask with
> S_IALLUGO instead of ~S_IFMT, which could leave unsed bits in the
> mask.

umode_t is 16 bits, so it doesn't. The change is still good, of course.

> + if (config.mode != DEVPTS_DEFAULT_MODE)
> + seq_printf(seq, ",mode=%03o", config.mode);

I would rather this be unconditional, than that it be conditional on
something other than the user having specified it in the first place.

Other than that,

Acked-by: H. Peter Anvin <[email protected]>

-hpa

2008-01-25 09:24:47

by Miklos Szeredi

[permalink] [raw]
Subject: Re: [patch 10/26] mount options: fix devpts

> > Also add minor fix: when parsing the "mode" option, mask with
> > S_IALLUGO instead of ~S_IFMT, which could leave unsed bits in the
> > mask.
>
> umode_t is 16 bits, so it doesn't. The change is still good, of course.

We still use 16 bit types? Strange ;)

>
> > + if (config.mode != DEVPTS_DEFAULT_MODE)
> > + seq_printf(seq, ",mode=%03o", config.mode);
>
> I would rather this be unconditional, than that it be conditional on
> something other than the user having specified it in the first place.

Yeah, it's a matter of taste. I'll update the patch.

Actually, a lot of filesystems share the options 'uid=X', 'gid=X',
'mode=X' (or 'umask=X'). This could be handled by the VFS, saving
some code, and making things more consistent. One day maybe...

Thanks,
Miklos