From: Mike Waychison <michael.waychison@sun.com>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: raven@themaw.net
Subject: [PATCH 18/28] VFS: Mountpoint file descriptor read properties
Date: Mon, 25 Oct 2004 10:47:39 -0400 [thread overview]
Message-ID: <1098715659264@sun.com> (raw)
In-Reply-To: <10987156292985@sun.com>
This patch allows userspace to query a mountpoint file descriptor for
information using the ioctl interface.
The properties exported in this patch are for _example only_ to demonstrate
what the interface might look like. This patch allows mountfds to show the
following information:
MOUNTFD_IOC_GETDEV - Get the associated block device (if any)
MOUNTFD_IOC_GETFSTYPE - Get the fstype of the mountpoint.
MOUNTFD_IOC_GETVFSOPTIONS - Get the vfs specific options of the
mountpoint/superblock
MOUNTFD_IOC_GETFSOPTIONS - Get the fstype-specific options (if any)
Signed-off-by: Mike Waychison <michael.waychison@sun.com>
---
fs/mountfd.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
include/linux/fs.h | 6 ++
2 files changed, 119 insertions(+), 1 deletion(-)
Index: linux-2.6.9-quilt/fs/mountfd.c
===================================================================
--- linux-2.6.9-quilt.orig/fs/mountfd.c 2004-10-22 17:17:42.625984008 -0400
+++ linux-2.6.9-quilt/fs/mountfd.c 2004-10-22 17:17:43.230892048 -0400
@@ -160,6 +160,72 @@ static struct dentry *get_mfd_dentry(str
return dget(dentry);
}
+static int mfd_read_fstype(struct vfsmount *mnt, char *buf)
+{
+ return scnprintf(buf, MOUNTFD_READSIZE-1, "%s", mnt->mnt_sb->s_type->name) + 1;
+}
+
+static int mfd_read_dev(struct vfsmount *mnt, char *buf)
+{
+ return scnprintf(buf, MOUNTFD_READSIZE-1, "%s", mnt->mnt_sb->s_id) + 1;
+}
+
+static int mfd_read_vfsoptions(struct vfsmount *mnt, char *buf)
+{
+ static struct vfs_info {
+ int flag;
+ char *str;
+ } vfs_info[] = {
+ { MS_RDONLY, "ro" },
+ { MS_DIRSYNC, "dirsync" },
+ { MS_MANDLOCK, "mand" },
+ { MS_NOATIME, "noatime" },
+ { MS_NODIRATIME, "nodiratime" },
+ { 0, NULL }
+ };
+ struct vfs_info *vfs_infop;
+ static struct mnt_info {
+ int flag;
+ char *str;
+ } mnt_info[] = {
+ { MNT_NOSUID, "nosuid" },
+ { MNT_NODEV, "nodev" },
+ { MNT_NOEXEC, "noexec" },
+ { 0, NULL }
+ };
+ struct mnt_info *mnt_infop;
+
+ char *p = buf;
+
+ int sb_flags = mnt->mnt_sb->s_flags;
+ int mnt_flags = mnt->mnt_flags;
+ int first = 0;
+
+ /*
+ * Note: we skip length checks below because we assume we can't overrun
+ * MOUNTFD_READSIZE.
+ */
+
+ for (vfs_infop = vfs_info; vfs_infop->flag; vfs_infop++) {
+ if (sb_flags & vfs_infop->flag) {
+ if (first++)
+ *p++ = ',';
+ strcpy(p, vfs_infop->str);
+ p += strlen(vfs_infop->str);
+ }
+ }
+
+ for (mnt_infop = mnt_info; mnt_infop->flag; mnt_infop++) {
+ if (mnt_flags & mnt_infop->flag) {
+ if (first++)
+ *p++ = ',';
+ strcpy(p, mnt_infop->str);
+ p += strlen(mnt_infop->str);
+ }
+ }
+ return p - buf + 1;
+}
+
static long open_mfd(struct vfsmount *mnt)
{
struct file *file;
@@ -176,6 +242,7 @@ static long open_mfd(struct vfsmount *mn
if (fd < 0)
goto out_putfilp;
+ error = -ENOMEM;
file->private_data = mnt;
file->f_dentry = get_mfd_dentry(mnt);
if (IS_ERR(file->f_dentry)) {
@@ -326,9 +393,53 @@ static long mfd_nextchild(struct file *m
return ret;
}
+static int mfd_ioctl_reads(struct inode *inode, struct file *filp,
+ unsigned int cmd, unsigned long arg)
+{
+ char __user *user_buf = (char __user *)arg;
+ struct vfsmount *mnt;
+ char *buf;
+ int ret;
+
+ mnt = VFSMOUNT(filp);
+
+ buf = (char *)get_zeroed_page(GFP_KERNEL);
+ if (buf)
+ return -ENOMEM;
+ switch (cmd) {
+ /*
+ * The following calls are expected to return the total number of bytes to write out, including '\0'.
+ */
+ case MOUNTFD_IOC_GETDEV:
+ ret = mfd_read_dev(mnt, buf);
+ break;
+ case MOUNTFD_IOC_GETFSTYPE:
+ ret = mfd_read_fstype(mnt, buf);
+ break;
+ case MOUNTFD_IOC_GETVFSOPTIONS:
+ ret = mfd_read_vfsoptions(mnt, buf);
+ break;
+ case MOUNTFD_IOC_GETFSOPTIONS:
+ /* TODO: need super_block op that doesn't take a seq_file */
+ ret = -ENOSYS;
+ break;
+ default:
+ ret = -ENOTTY;
+ }
+
+ if (ret >= 0) {
+ if (copy_to_user(user_buf, buf, ret))
+ ret = -EFAULT;
+ }
+
+ free_page((unsigned long)buf);
+ return ret;
+}
+
static int mfd_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
+ int ret;
switch (cmd) {
case MOUNTFD_IOC_GETDIRFD:
return mfd_getdirfd(filp);
@@ -345,7 +456,8 @@ static int mfd_ioctl(struct inode *inode
case MOUNTFD_IOC_GETNEXTCHILD:
return mfd_nextchild(filp);
}
- return -ENOTTY;
+ ret = mfd_ioctl_reads(inode, filp, cmd, arg);
+ return ret;
}
asmlinkage long sys_mountfd(int dirfd)
Index: linux-2.6.9-quilt/include/linux/fs.h
===================================================================
--- linux-2.6.9-quilt.orig/include/linux/fs.h 2004-10-22 17:17:42.625984008 -0400
+++ linux-2.6.9-quilt/include/linux/fs.h 2004-10-22 17:17:43.232891744 -0400
@@ -223,6 +223,12 @@ extern int leases_enable, dir_notify_ena
/* TODO: change this interface to require the parent mfd as well */
#define MOUNTFD_IOC_GETNEXTCHILD _IO('p', 0xa6)
+#define MOUNTFD_READSIZE PAGE_SIZE
+#define MOUNTFD_IOC_GETDEV _IOR('p', 0xa7, char [MOUNTFD_READSIZE])
+#define MOUNTFD_IOC_GETFSTYPE _IOR('p', 0xa8, char [MOUNTFD_READSIZE])
+#define MOUNTFD_IOC_GETVFSOPTIONS _IOR('p', 0xa9, char [MOUNTFD_READSIZE])
+#define MOUNTFD_IOC_GETFSOPTIONS _IOR('p', 0xaa, char [MOUNTFD_READSIZE])
+
#ifdef __KERNEL__
#include <linux/list.h>
next prev parent reply other threads:[~2004-10-26 0:28 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <10987155332448@sun.com>
2004-10-25 14:46 ` [PATCH 15/28] VFS: Mountpoint file descriptor umount support Mike Waychison
2004-10-25 14:46 ` [PATCH 16/28] VFS: Mountpoint file descriptor attach support Mike Waychison
2004-10-25 14:47 ` [PATCH 17/28] VFS: Mountpoint file descriptor walking Mike Waychison
2004-10-25 14:47 ` Mike Waychison [this message]
2004-10-25 14:48 ` [PATCH 19/28] VFS: Mountpoint file descriptor expiry support Mike Waychison
2004-10-25 14:48 ` [PATCH 20/28] HOTPLUG: call_usermodehelper callback support Mike Waychison
2004-10-25 14:49 ` [PATCH 21/28] HOTPLUG: Hack to allow for call to execve Mike Waychison
2004-10-25 14:49 ` [PATCH 22/28] VFS: Export put_namespace Mike Waychison
2004-10-25 14:50 ` [PATCH 23/28] VFS: Export get_sb_pseudo Mike Waychison
2004-10-25 14:50 ` [PATCH 24/28] VFS: Fixup for ->follow_link on root of filesystem Mike Waychison
2004-10-25 14:51 ` [PATCH 25/28] VFS: statfs(64) shouldn't follow last component symlink Mike Waychison
2004-10-25 14:51 ` [PATCH 26/28] VFS: Introduce MNT_NOFOLLOW Mike Waychison
2004-10-25 14:52 ` [PATCH 27/28] Testing syscall for expiry Mike Waychison
2004-10-25 15:01 ` Christoph Hellwig
2004-10-25 15:37 ` [PATCH 28/28] AUTOFSNG: New autofs filesystem (resend) Mike Waychison
2004-10-25 15:14 ` [PATCH 25/28] VFS: statfs(64) shouldn't follow last component symlink Christoph Hellwig
2004-10-25 15:21 ` Mike Waychison
2004-10-25 15:18 ` [PATCH 20/28] HOTPLUG: call_usermodehelper callback support Christoph Hellwig
2004-10-25 15:29 ` Mike Waychison
2004-10-26 10:28 ` [PATCH 15/28] VFS: Mountpoint file descriptor umount support Christoph Hellwig
2004-10-26 14:16 ` Mike Waychison
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=1098715659264@sun.com \
--to=michael.waychison@sun.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=raven@themaw.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.