[PATCH 16/28] VFS: Mountpoint file descriptor attach support

From: Mike Waychison
Date: Mon Oct 25 2004 - 17:26:39 EST


This patch allows an unattached mountfd to be attached to a directory given a
direct fd.

NOTE: Probably requires CAP_SYSADMIN.. depends on what we want the security
model to be.

Signed-off-by: Mike Waychison <michael.waychison@xxxxxxx>
---

fs/mountfd.c | 35 +++++++++++++++++++++++++++++++++++
include/linux/fs.h | 1 +
2 files changed, 36 insertions(+)

Index: linux-2.6.9-quilt/fs/mountfd.c
===================================================================
--- linux-2.6.9-quilt.orig/fs/mountfd.c 2004-10-22 17:17:41.367175376 -0400
+++ linux-2.6.9-quilt/fs/mountfd.c 2004-10-22 17:17:42.011077488 -0400
@@ -5,6 +5,7 @@
#include <linux/stat.h>
#include <linux/init.h>
#include <linux/security.h>
+#include <linux/namei.h>

#define MFDFS_MAGIC 0x4A9F2E43
#define MFDFS_ROOT_INO 1
@@ -251,6 +252,38 @@ out_filp:
return error;
}

+static long mfd_attach(struct file *mountfilp, int dirfd)
+{
+ struct file *dir;
+ struct vfsmount *mnt;
+ struct nameidata nd;
+ int ret;
+
+ mnt = mntget(VFSMOUNT(mountfilp));
+
+ ret = -EBADF;
+ dir = fget(dirfd);
+ if (!dir)
+ goto out;
+
+ ret = -ENOTDIR;
+ if (!S_ISDIR(dir->f_dentry->d_inode->i_mode))
+ goto out2;
+
+ memset(&nd, 0, sizeof(nd));
+ nd.dentry = dget(dir->f_dentry);
+ nd.mnt = mntget(dir->f_vfsmnt);
+
+ ret = do_graft_mount(mnt, &nd);
+
+ path_release(&nd);
+out2:
+ put_filp(dir);
+out:
+ mntput(mnt);
+ return ret;
+}
+
static int mfd_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
@@ -263,6 +296,8 @@ static int mfd_ioctl(struct inode *inode
return mfd_umount(filp, 0);
case MOUNTFD_IOC_FORCEDUNMOUNT:
return mfd_umount(filp, MNT_FORCE);
+ case MOUNTFD_IOC_ATTACH:
+ return mfd_attach(filp, arg);
}
return -ENOTTY;
}
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:41.369175072 -0400
+++ linux-2.6.9-quilt/include/linux/fs.h 2004-10-22 17:17:42.012077336 -0400
@@ -218,6 +218,7 @@ extern int leases_enable, dir_notify_ena
#define MOUNTFD_IOC_UNMOUNT _IO('p', 0xa1)
#define MOUNTFD_IOC_DETACH _IO('p', 0xa2)
#define MOUNTFD_IOC_FORCEDUNMOUNT _IO('p', 0xa3)
+#define MOUNTFD_IOC_ATTACH _IOW('p', 0xa4, int)

#ifdef __KERNEL__


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/