2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-09-05 08:45:22 +00:00
Files
apparmor/kernel-patches/for-mainline/d_namespace_path.diff

87 lines
2.8 KiB
Diff
Raw Normal View History

2007-04-05 10:04:00 +00:00
From: Andreas Gruenbacher <agruen@suse.de>
2007-04-18 14:56:47 +00:00
Subject: Add d_namespace_path() to compute namespace relative pathnames
2007-04-18 14:56:47 +00:00
In AppArmor, we are interested in pathnames relative to the namespace root.
This is the same as d_path() except for the root where the search ends. Add
a function for computing the namespace-relative path.
2007-04-03 13:26:33 +00:00
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
2007-06-26 22:14:37 +00:00
Signed-off-by: John Johansen <jjohansen@suse.de>
2007-04-05 10:04:00 +00:00
---
fs/dcache.c | 6 +++---
2007-04-18 14:56:47 +00:00
fs/namespace.c | 27 +++++++++++++++++++++++++++
2007-04-05 10:04:00 +00:00
include/linux/dcache.h | 2 ++
include/linux/mount.h | 2 ++
2007-04-18 14:56:47 +00:00
4 files changed, 34 insertions(+), 3 deletions(-)
2007-04-05 10:04:00 +00:00
--- a/fs/dcache.c
+++ b/fs/dcache.c
2007-11-19 23:18:48 +00:00
@@ -1782,9 +1782,9 @@ shouldnt_be_hashed:
2007-02-06 18:57:06 +00:00
*
* Returns the buffer or an error code.
*/
-static char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
- struct dentry *root, struct vfsmount *rootmnt,
- char *buffer, int buflen, int fail_deleted)
+char *__d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
+ struct dentry *root, struct vfsmount *rootmnt,
+ char *buffer, int buflen, int fail_deleted)
{
int namelen, is_slash, vfsmount_locked = 0;
2007-02-15 11:03:05 +00:00
2007-04-05 10:04:00 +00:00
--- a/fs/namespace.c
+++ b/fs/namespace.c
2007-11-19 23:18:48 +00:00
@@ -1883,3 +1883,30 @@ void __put_mnt_ns(struct mnt_namespace *
2007-02-06 18:57:06 +00:00
release_mounts(&umount_list);
kfree(ns);
}
+
+char *d_namespace_path(struct dentry *dentry, struct vfsmount *vfsmnt,
+ char *buf, int buflen)
2007-02-06 18:57:06 +00:00
+{
2007-04-18 14:56:47 +00:00
+ struct vfsmount *rootmnt, *nsrootmnt = NULL;
+ struct dentry *root = NULL;
2007-02-06 18:57:06 +00:00
+ char *res;
+
+ read_lock(&current->fs->lock);
+ rootmnt = mntget(current->fs->rootmnt);
+ read_unlock(&current->fs->lock);
+ spin_lock(&vfsmount_lock);
2007-04-18 14:56:47 +00:00
+ if (rootmnt->mnt_ns)
+ nsrootmnt = mntget(rootmnt->mnt_ns->root);
2007-02-06 18:57:06 +00:00
+ spin_unlock(&vfsmount_lock);
+ mntput(rootmnt);
2007-04-18 14:56:47 +00:00
+ if (nsrootmnt)
+ root = dget(nsrootmnt->mnt_root);
+ res = __d_path(dentry, vfsmnt, root, nsrootmnt, buf, buflen, 1);
2007-02-06 18:57:06 +00:00
+ dput(root);
+ mntput(nsrootmnt);
2007-04-18 14:56:47 +00:00
+ /* Prevent empty path for lazily unmounted filesystems. */
+ if (!IS_ERR(res) && *res == '\0')
+ *--res = '.';
2007-02-06 18:57:06 +00:00
+ return res;
+}
+EXPORT_SYMBOL(d_namespace_path);
2007-04-05 10:04:00 +00:00
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
2007-11-19 23:18:48 +00:00
@@ -300,6 +300,8 @@ extern int d_validate(struct dentry *, s
2007-05-09 12:51:20 +00:00
*/
extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
2007-04-05 10:04:00 +00:00
+extern char *__d_path(struct dentry *, struct vfsmount *, struct dentry *,
+ struct vfsmount *, char *, int, int);
extern char * d_path(struct dentry *, struct vfsmount *, char *, int);
/* Allocation counts.. */
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -103,5 +103,7 @@ extern void shrink_submounts(struct vfsm
2007-02-06 18:57:06 +00:00
extern spinlock_t vfsmount_lock;
extern dev_t name_to_dev_t(char *name);
+extern char *d_namespace_path(struct dentry *, struct vfsmount *, char *, int);
2007-02-06 18:57:06 +00:00
+
#endif
#endif /* _LINUX_MOUNT_H */