fs/exec.c | 10 ++++--- fs/namei.c | 69 ++++++++++++++++++++++++++++++++++++++++++++------ fs/namespace.c | 1 fs/open.c | 28 +++++++++++++++----- fs/stat.c | 10 +++++-- fs/xattr.c | 12 +++++--- include/linux/fs.h | 2 + include/linux/namei.h | 27 +++++++++++++++++++ 8 files changed, 134 insertions(+), 25 deletions(-) Index: linux-2.6.6/include/linux/namei.h =================================================================== --- linux-2.6.6.orig/include/linux/namei.h 2004-05-30 19:46:50.238958768 +0300 +++ linux-2.6.6/include/linux/namei.h 2004-05-30 20:05:26.849208208 +0300 @@ -2,17 +2,36 @@ #define _LINUX_NAMEI_H #include +#include struct vfsmount; +/* intent opcodes */ +#define IT_OPEN (1) +#define IT_CREAT (1<<1) +#define IT_READDIR (1<<2) +#define IT_GETATTR (1<<3) +#define IT_LOOKUP (1<<4) +#define IT_UNLINK (1<<5) +#define IT_TRUNC (1<<6) +#define IT_GETXATTR (1<<7) + #define INTENT_MAGIC 0x19620323 struct lookup_intent { int it_magic; int it_op; + void (*it_op_release)(struct lookup_intent *); int it_flags; int it_create_mode; }; +static inline void intent_init(struct lookup_intent *it, int op) +{ + memset(it, 0, sizeof(*it)); + it->it_magic = INTENT_MAGIC; + it->it_op = op; +} + struct nameidata { struct dentry *dentry; struct vfsmount *mnt; @@ -48,14 +67,22 @@ #define LOOKUP_ACCESS (0x0400) extern int FASTCALL(__user_walk(const char __user *, unsigned, struct nameidata *)); +extern int FASTCALL(__user_walk_it(const char __user *, unsigned, struct nameidata *)); #define user_path_walk(name,nd) \ __user_walk(name, LOOKUP_FOLLOW, nd) +#define user_path_walk_it(name,nd) \ + __user_walk_it(name, LOOKUP_FOLLOW, nd) #define user_path_walk_link(name,nd) \ __user_walk(name, 0, nd) +#define user_path_walk_link_it(name,nd) \ + __user_walk_it(name, 0, nd) extern int FASTCALL(path_lookup(const char *, unsigned, struct nameidata *)); +extern int FASTCALL(path_lookup_it(const char *, unsigned, struct nameidata *)); extern int FASTCALL(path_walk(const char *, struct nameidata *)); +extern int FASTCALL(path_walk_it(const char *, struct nameidata *)); extern int FASTCALL(link_path_walk(const char *, struct nameidata *)); extern void path_release(struct nameidata *); +extern void intent_release(struct lookup_intent *); extern struct dentry * lookup_one_len(const char *, struct dentry *, int); extern struct dentry * lookup_hash(struct qstr *, struct dentry *); Index: linux-2.6.6/include/linux/fs.h =================================================================== --- linux-2.6.6.orig/include/linux/fs.h 2004-05-26 20:26:11.000000000 +0300 +++ linux-2.6.6/include/linux/fs.h 2004-05-30 20:05:26.852207752 +0300 @@ -576,6 +576,7 @@ spinlock_t f_ep_lock; #endif /* #ifdef CONFIG_EPOLL */ struct address_space *f_mapping; + struct lookup_intent *f_it; }; extern spinlock_t files_lock; #define file_list_lock() spin_lock(&files_lock); @@ -1190,6 +1191,7 @@ extern int do_truncate(struct dentry *, loff_t start); extern struct file *filp_open(const char *, int, int); extern struct file * dentry_open(struct dentry *, struct vfsmount *, int); +extern struct file * dentry_open_it(struct dentry *, struct vfsmount *, int, struct lookup_intent *); extern int filp_close(struct file *, fl_owner_t id); extern char * getname(const char __user *); Index: linux-2.6.6/fs/namei.c =================================================================== --- linux-2.6.6.orig/fs/namei.c 2004-05-30 19:46:50.185966824 +0300 +++ linux-2.6.6/fs/namei.c 2004-05-30 20:05:26.855207296 +0300 @@ -272,8 +272,19 @@ return 0; } +void intent_release(struct lookup_intent *it) +{ + if (!it) + return; + if (it->it_magic != INTENT_MAGIC) + return; + if (it->it_op_release) + it->it_op_release(it); +} + void path_release(struct nameidata *nd) { + intent_release(&nd->intent); dput(nd->dentry); mntput(nd->mnt); } @@ -774,8 +785,14 @@ return err; } +int fastcall path_walk_it(const char * name, struct nameidata *nd) +{ + current->total_link_count = 0; + return link_path_walk(name, nd); +} int fastcall path_walk(const char * name, struct nameidata *nd) { + intent_init(&nd->intent, IT_LOOKUP); current->total_link_count = 0; return link_path_walk(name, nd); } @@ -784,7 +801,7 @@ /* returns 1 if everything is done */ static int __emul_lookup_dentry(const char *name, struct nameidata *nd) { - if (path_walk(name, nd)) + if (path_walk_it(name, nd)) return 0; /* something went wrong... */ if (!nd->dentry->d_inode || S_ISDIR(nd->dentry->d_inode->i_mode)) { @@ -861,7 +878,18 @@ return 1; } -int fastcall path_lookup(const char *name, unsigned int flags, struct nameidata *nd) +static inline int it_mode_from_lookup_flags(int flags) +{ + int mode = IT_LOOKUP; + + if (flags & LOOKUP_OPEN) + mode = IT_OPEN; + if (flags & LOOKUP_CREATE) + mode |= IT_CREAT; + return mode; +} + +int fastcall path_lookup_it(const char *name, unsigned int flags, struct nameidata *nd) { int retval; @@ -896,6 +924,12 @@ return retval; } +int fastcall path_lookup(const char *name, unsigned int flags, struct nameidata *nd) +{ + intent_init(&nd->intent, it_mode_from_lookup_flags(flags)); + return path_lookup_it(name, flags, nd); +} + /* * Restricted form of lookup. Doesn't follow links, single-component only, * needs parent already locked. Doesn't follow mounts. @@ -946,7 +980,7 @@ } /* SMP-safe */ -struct dentry * lookup_one_len(const char * name, struct dentry * base, int len) +struct dentry * lookup_one_len_it(const char * name, struct dentry * base, int len, struct nameidata *nd) { unsigned long hash; struct qstr this; @@ -966,11 +1000,16 @@ } this.hash = end_name_hash(hash); - return lookup_hash(&this, base); + return __lookup_hash(&this, base, nd); access: return ERR_PTR(-EACCES); } +struct dentry * lookup_one_len(const char * name, struct dentry * base, int len) +{ + return lookup_one_len_it(name, base, len, NULL); +} + /* * namei() * @@ -982,18 +1021,24 @@ * that namei follows links, while lnamei does not. * SMP-safe */ -int fastcall __user_walk(const char __user *name, unsigned flags, struct nameidata *nd) +int fastcall __user_walk_it(const char __user *name, unsigned flags, struct nameidata *nd) { char *tmp = getname(name); int err = PTR_ERR(tmp); if (!IS_ERR(tmp)) { - err = path_lookup(tmp, flags, nd); + err = path_lookup_it(tmp, flags, nd); putname(tmp); } return err; } +int fastcall __user_walk(const char __user *name, unsigned flags, struct nameidata *nd) +{ + intent_init(&nd->intent, it_mode_from_lookup_flags(flags)); + return __user_walk_it(name, flags, nd); +} + /* * It's inline, so penalty for filesystems that don't use sticky bit is * minimal. @@ -1273,7 +1318,7 @@ * The simplest case - just a plain lookup. */ if (!(flag & O_CREAT)) { - error = path_lookup(pathname, lookup_flags(flag)|LOOKUP_OPEN, nd); + error = path_lookup_it(pathname, lookup_flags(flag), nd); if (error) return error; goto ok; @@ -1282,7 +1327,8 @@ /* * Create - we need to know the parent. */ - error = path_lookup(pathname, LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, nd); + nd->intent.it_op |= IT_CREAT; + error = path_lookup_it(pathname, LOOKUP_PARENT, nd); if (error) return error; @@ -2165,6 +2211,7 @@ __vfs_follow_link(struct nameidata *nd, const char *link) { int res = 0; + struct lookup_intent it = nd->intent; char *name; if (IS_ERR(link)) goto fail; @@ -2175,6 +2222,9 @@ /* weird __emul_prefix() stuff did it */ goto out; } + intent_init(&nd->intent, it.it_op); + nd->intent.it_flags = it.it_flags; + nd->intent.it_create_mode = it.it_create_mode; res = link_path_walk(link, nd); out: if (current->link_count || res || nd->last_type!=LAST_NORM) @@ -2249,6 +2299,7 @@ return res; } + int page_symlink(struct inode *inode, const char *symname, int len) { struct address_space *mapping = inode->i_mapping; @@ -2309,8 +2360,10 @@ EXPORT_SYMBOL(page_symlink); EXPORT_SYMBOL(page_symlink_inode_operations); EXPORT_SYMBOL(path_lookup); +EXPORT_SYMBOL(path_lookup_it); EXPORT_SYMBOL(path_release); EXPORT_SYMBOL(path_walk); +EXPORT_SYMBOL(path_walk_it); EXPORT_SYMBOL(permission); EXPORT_SYMBOL(unlock_rename); EXPORT_SYMBOL(vfs_create); Index: linux-2.6.6/fs/open.c =================================================================== --- linux-2.6.6.orig/fs/open.c 2004-05-26 20:25:43.000000000 +0300 +++ linux-2.6.6/fs/open.c 2004-05-30 20:05:26.857206992 +0300 @@ -214,11 +214,12 @@ struct inode * inode; int error; + intent_init(&nd.intent, IT_GETATTR); error = -EINVAL; if (length < 0) /* sorry, but loff_t says... */ goto out; - error = user_path_walk(path, &nd); + error = user_path_walk_it(path, &nd); if (error) goto out; inode = nd.dentry->d_inode; @@ -473,6 +474,7 @@ kernel_cap_t old_cap; int res; + intent_init(&nd.intent, IT_GETATTR); if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */ return -EINVAL; @@ -496,7 +498,7 @@ else current->cap_effective = current->cap_permitted; - res = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_ACCESS, &nd); + res = __user_walk_it(filename, LOOKUP_FOLLOW|LOOKUP_ACCESS, &nd); if (!res) { res = permission(nd.dentry->d_inode, mode, &nd); /* SuS v2 requires we report a read only fs too */ @@ -518,7 +520,8 @@ struct nameidata nd; int error; - error = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd); + intent_init(&nd.intent, IT_GETATTR); + error = __user_walk_it(filename, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd); if (error) goto out; @@ -569,7 +572,8 @@ struct nameidata nd; int error; - error = __user_walk(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd); + intent_init(&nd.intent, IT_GETATTR); + error = __user_walk_it(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd); if (error) goto out; @@ -752,6 +756,7 @@ { int namei_flags, error; struct nameidata nd; + intent_init(&nd.intent, IT_OPEN); namei_flags = flags; if ((namei_flags+1) & O_ACCMODE) @@ -761,14 +766,14 @@ error = open_namei(filename, namei_flags, mode, &nd); if (!error) - return dentry_open(nd.dentry, nd.mnt, flags); + return dentry_open_it(nd.dentry, nd.mnt, flags, &nd.intent); return ERR_PTR(error); } EXPORT_SYMBOL(filp_open); -struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags) +struct file *dentry_open_it(struct dentry *dentry, struct vfsmount *mnt, int flags, struct lookup_intent *it) { struct file * f; struct inode *inode; @@ -780,6 +785,7 @@ goto cleanup_dentry; f->f_flags = flags; f->f_mode = (flags+1) & O_ACCMODE; + f->f_it = it; inode = dentry->d_inode; if (f->f_mode & FMODE_WRITE) { error = get_write_access(inode); @@ -799,6 +805,7 @@ error = f->f_op->open(inode,f); if (error) goto cleanup_all; + intent_release(it); } f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); @@ -823,11 +830,20 @@ cleanup_file: put_filp(f); cleanup_dentry: + intent_release(it); dput(dentry); mntput(mnt); return ERR_PTR(error); } +struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags) +{ + struct lookup_intent it; + intent_init(&it, IT_LOOKUP); + + return dentry_open_it(dentry, mnt, flags, &it); +} + EXPORT_SYMBOL(dentry_open); /* Index: linux-2.6.6/fs/stat.c =================================================================== --- linux-2.6.6.orig/fs/stat.c 2004-05-26 20:25:43.000000000 +0300 +++ linux-2.6.6/fs/stat.c 2004-05-30 23:46:08.545164440 +0300 @@ -58,15 +58,15 @@ } return 0; } - EXPORT_SYMBOL(vfs_getattr); int vfs_stat(char __user *name, struct kstat *stat) { struct nameidata nd; int error; + intent_init(&nd.intent, IT_GETATTR); - error = user_path_walk(name, &nd); + error = user_path_walk_it(name, &nd); if (!error) { error = vfs_getattr(nd.mnt, nd.dentry, stat); path_release(&nd); @@ -80,8 +80,9 @@ { struct nameidata nd; int error; + intent_init(&nd.intent, IT_GETATTR); - error = user_path_walk_link(name, &nd); + error = user_path_walk_link_it(name, &nd); if (!error) { error = vfs_getattr(nd.mnt, nd.dentry, stat); path_release(&nd); @@ -95,9 +96,12 @@ { struct file *f = fget(fd); int error = -EBADF; + struct nameidata nd; + intent_init(&nd.intent, IT_GETATTR); if (f) { error = vfs_getattr(f->f_vfsmnt, f->f_dentry, stat); + intent_release(&nd.intent); fput(f); } return error; Index: linux-2.6.6/fs/namespace.c =================================================================== --- linux-2.6.6.orig/fs/namespace.c 2004-05-26 20:25:43.000000000 +0300 +++ linux-2.6.6/fs/namespace.c 2004-05-30 20:05:26.860206536 +0300 @@ -115,6 +115,7 @@ static void detach_mnt(struct vfsmount *mnt, struct nameidata *old_nd) { + memset(old_nd, 0, sizeof(*old_nd)); old_nd->dentry = mnt->mnt_mountpoint; old_nd->mnt = mnt->mnt_parent; mnt->mnt_parent = mnt; Index: linux-2.6.6/fs/exec.c =================================================================== --- linux-2.6.6.orig/fs/exec.c 2004-05-30 19:46:50.182967280 +0300 +++ linux-2.6.6/fs/exec.c 2004-05-30 20:05:26.862206232 +0300 @@ -122,8 +122,9 @@ struct nameidata nd; int error; + intent_init(&nd.intent, IT_OPEN); nd.intent.it_flags = FMODE_READ; - error = __user_walk(library, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd); + error = user_path_walk_it(library, &nd); if (error) goto out; @@ -135,7 +136,7 @@ if (error) goto exit; - file = dentry_open(nd.dentry, nd.mnt, O_RDONLY); + file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &nd.intent); error = PTR_ERR(file); if (IS_ERR(file)) goto out; @@ -483,8 +484,9 @@ int err; struct file *file; + intent_init(&nd.intent, IT_OPEN); nd.intent.it_flags = FMODE_READ; - err = path_lookup(name, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd); + err = path_lookup_it(name, LOOKUP_FOLLOW, &nd); file = ERR_PTR(err); if (!err) { @@ -497,7 +499,7 @@ err = -EACCES; file = ERR_PTR(err); if (!err) { - file = dentry_open(nd.dentry, nd.mnt, O_RDONLY); + file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &nd.intent); if (!IS_ERR(file)) { err = deny_write_access(file); if (err) { Index: linux-2.6.6/fs/xattr.c =================================================================== --- linux-2.6.6.orig/fs/xattr.c 2004-05-26 20:25:43.000000000 +0300 +++ linux-2.6.6/fs/xattr.c 2004-05-30 20:05:26.863206080 +0300 @@ -161,7 +161,8 @@ struct nameidata nd; ssize_t error; - error = user_path_walk(path, &nd); + intent_init(&nd.intent, IT_GETXATTR); + error = user_path_walk_it(path, &nd); if (error) return error; error = getxattr(nd.dentry, name, value, size); @@ -176,7 +177,8 @@ struct nameidata nd; ssize_t error; - error = user_path_walk_link(path, &nd); + intent_init(&nd.intent, IT_GETXATTR); + error = user_path_walk_link_it(path, &nd); if (error) return error; error = getxattr(nd.dentry, name, value, size); @@ -242,7 +244,8 @@ struct nameidata nd; ssize_t error; - error = user_path_walk(path, &nd); + intent_init(&nd.intent, IT_GETXATTR); + error = user_path_walk_it(path, &nd); if (error) return error; error = listxattr(nd.dentry, list, size); @@ -256,7 +259,8 @@ struct nameidata nd; ssize_t error; - error = user_path_walk_link(path, &nd); + intent_init(&nd.intent, IT_GETXATTR); + error = user_path_walk_link_it(path, &nd); if (error) return error; error = listxattr(nd.dentry, list, size);