1 fs/exec.c | 18 +++++++---
2 fs/namei.c | 86 +++++++++++++++++++++++++++++++++++++++++++++----
5 fs/open.c | 62 +++++++++++++++++++++++------------
6 fs/stat.c | 24 ++++++++++---
7 include/linux/dcache.h | 3 +
8 include/linux/fs.h | 8 ++++
9 include/linux/namei.h | 56 ++++++++++++++++++++++++++-----
10 kernel/ksyms.c | 8 ++++
11 10 files changed, 222 insertions(+), 49 deletions(-)
13 Index: uml-2.6.3/fs/exec.c
14 ===================================================================
15 --- uml-2.6.3.orig/fs/exec.c 2004-02-20 15:00:48.000000000 +0800
16 +++ uml-2.6.3/fs/exec.c 2004-02-21 00:15:14.154506296 +0800
21 + intent_init(&nd.intent, IT_OPEN);
23 - nd.intent.open.flags = FMODE_READ;
24 + error = user_path_walk_it(library, &nd);
26 + nd.intent.it_flags = O_RDONLY;
27 error = __user_walk(library, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd);
34 - file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
35 + file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &nd.intent);
36 error = PTR_ERR(file);
43 - nd.intent.open.flags = FMODE_READ;
44 - err = path_lookup(name, LOOKUP_FOLLOW|LOOKUP_OPEN, &nd);
45 + intent_init(&nd.intent, IT_OPEN);
46 + nd.intent.it_flags = O_RDONLY;
47 + err = path_lookup(name, LOOKUP_FOLLOW, &nd);
55 - file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
56 + file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &nd.intent);
58 err = deny_write_access(file);
60 Index: uml-2.6.3/fs/namei.c
61 ===================================================================
62 --- uml-2.6.3.orig/fs/namei.c 2004-02-20 15:01:27.000000000 +0800
63 +++ uml-2.6.3/fs/namei.c 2004-02-20 23:59:00.678497144 +0800
68 +void intent_release(struct lookup_intent *it)
72 + if (it->it_magic != INTENT_MAGIC)
74 + if (it->it_op_release)
75 + it->it_op_release(it);
78 void path_release(struct nameidata *nd)
80 + intent_release(&nd->intent);
86 struct dentry * result;
87 struct inode *dir = parent->d_inode;
94 * First re-do the cached lookup just in case it was created
96 if (result->d_op && result->d_op->d_revalidate) {
97 if (!result->d_op->d_revalidate(result, nd) && !d_invalidate(result)) {
99 - result = ERR_PTR(-ENOENT);
101 + result = ERR_PTR(-ESTALE);
102 + if (!IS_ERR(result))
108 return PTR_ERR(dentry);
111 +static int revalidate_special(struct nameidata *nd)
113 + struct dentry *dentry = nd->dentry;
114 + int err, counter = 0;
116 + if (!dentry->d_op || !dentry->d_op->d_revalidate)
119 + if (!dentry->d_op->d_revalidate(dentry, nd)) {
120 + struct dentry *new;
121 + if ((err = permission(dentry->d_parent->d_inode, MAY_EXEC,nd)))
123 + new = real_lookup(dentry->d_parent, &dentry->d_name, nd);
124 + d_invalidate(dentry);
126 + nd->dentry = dentry = new;
129 + goto revalidate_again;
130 + printk("excessive revalidate_it loops\n");
141 if (inode->i_op->follow_link) {
143 + nd->flags |= LOOKUP_LINK_NOTLAST;
144 err = do_follow_link(next.dentry, nd);
145 + nd->flags &= ~LOOKUP_LINK_NOTLAST;
150 inode = nd->dentry->d_inode;
153 + nd->flags |= LOOKUP_LAST;
154 + err = revalidate_special(nd);
155 + nd->flags &= ~LOOKUP_LAST;
160 if (nd->dentry->d_op && nd->dentry->d_op->d_hash) {
165 + nd->flags |= LOOKUP_LAST;
166 err = do_lookup(nd, &this, &next);
167 + nd->flags &= ~LOOKUP_LAST;
170 follow_mount(&next.mnt, &next.dentry);
175 -struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
176 +struct dentry * lookup_one_len_it(const char * name, struct dentry * base, int len, struct nameidata *nd)
180 @@ -954,11 +1005,16 @@
182 this.hash = end_name_hash(hash);
184 - return lookup_hash(&this, base);
185 + return __lookup_hash(&this, base, nd);
187 return ERR_PTR(-EACCES);
190 +struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
192 + return lookup_one_len_it(name, base, len, NULL);
198 @@ -970,11 +1026,12 @@
199 * that namei follows links, while lnamei does not.
202 -int __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
203 +int __user_walk_it(const char __user *name, unsigned flags, struct nameidata *nd)
205 char *tmp = getname(name);
206 int err = PTR_ERR(tmp);
210 err = path_lookup(tmp, flags, nd);
212 @@ -982,6 +1039,12 @@
216 +int __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
218 + intent_init(&nd->intent, IT_LOOKUP);
219 + return __user_walk_it(name, flags, nd);
223 * It's inline, so penalty for filesystems that don't use sticky bit is
225 @@ -1254,8 +1317,8 @@
226 acc_mode |= MAY_APPEND;
228 /* Fill in the open() intent data */
229 - nd->intent.open.flags = flag;
230 - nd->intent.open.create_mode = mode;
231 + nd->intent.it_flags = flag;
232 + nd->intent.it_create_mode = mode;
235 * The simplest case - just a plain lookup.
236 @@ -1270,6 +1333,7 @@
238 * Create - we need to know the parent.
240 + nd->intent.it_op |= IT_CREAT;
241 error = path_lookup(pathname, LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, nd);
244 @@ -1286,7 +1350,9 @@
246 nd->flags &= ~LOOKUP_PARENT;
247 down(&dir->d_inode->i_sem);
248 + nd->flags |= LOOKUP_LAST;
249 dentry = __lookup_hash(&nd->last, nd->dentry, nd);
250 + nd->flags &= ~LOOKUP_LAST;
253 error = PTR_ERR(dentry);
254 @@ -1391,7 +1457,9 @@
257 down(&dir->d_inode->i_sem);
258 + nd->flags |= LOOKUP_LAST;
259 dentry = __lookup_hash(&nd->last, nd->dentry, nd);
260 + nd->flags &= ~LOOKUP_LAST;
261 putname(nd->last.name);
264 @@ -2153,7 +2221,9 @@
265 __vfs_follow_link(struct nameidata *nd, const char *link)
268 + struct lookup_intent it = nd->intent;
274 @@ -2163,6 +2233,10 @@
275 /* weird __emul_prefix() stuff did it */
279 + intent_init(&nd->intent, it.it_op);
280 + nd->intent.it_flags = it.it_flags;
281 + nd->intent.it_create_mode = it.it_create_mode;
282 res = link_path_walk(link, nd);
284 if (current->link_count || res || nd->last_type!=LAST_NORM)
285 Index: uml-2.6.3/fs/namespace.c
286 ===================================================================
287 --- uml-2.6.3.orig/fs/namespace.c 2004-02-20 15:01:27.000000000 +0800
288 +++ uml-2.6.3/fs/namespace.c 2004-02-20 23:59:00.745486960 +0800
293 + intent_init(&nd.intent, IT_LOOKUP);
295 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
296 flags &= ~MS_MGC_MSK;
297 Index: uml-2.6.3/fs/open.c
298 ===================================================================
299 --- uml-2.6.3.orig/fs/open.c 2004-02-20 15:00:48.000000000 +0800
300 +++ uml-2.6.3/fs/open.c 2004-02-20 23:59:00.812476776 +0800
303 struct inode * inode;
306 + intent_init(&nd.intent, IT_GETATTR);
308 if (length < 0) /* sorry, but loff_t says... */
311 int old_fsuid, old_fsgid;
312 kernel_cap_t old_cap;
314 + intent_init(&nd.intent, IT_GETATTR);
316 if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
319 if(!res && (mode & S_IWOTH) && IS_RDONLY(nd.dentry->d_inode)
320 && !special_file(nd.dentry->d_inode->i_mode))
330 + intent_init(&nd.intent, IT_GETATTR);
332 error = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd);
338 + intent_init(&nd.intent, IT_GETATTR);
340 error = __user_walk(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd);
344 if (IS_RDONLY(inode))
349 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
352 * for the internal routines (ie open_namei()/follow_link() etc). 00 is
355 -struct file *filp_open(const char * filename, int flags, int mode)
357 - int namei_flags, error;
358 - struct nameidata nd;
360 - namei_flags = flags;
361 - if ((namei_flags+1) & O_ACCMODE)
363 - if (namei_flags & O_TRUNC)
366 - error = open_namei(filename, namei_flags, mode, &nd);
368 - return dentry_open(nd.dentry, nd.mnt, flags);
370 - return ERR_PTR(error);
373 -EXPORT_SYMBOL(filp_open);
375 -struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
376 +struct file *dentry_open_it(struct dentry *dentry, struct vfsmount *mnt, int flags,
377 + struct lookup_intent *it)
384 f->f_mode = (flags+1) & O_ACCMODE;
386 inode = dentry->d_inode;
387 if (f->f_mode & FMODE_WRITE) {
388 error = get_write_access(inode);
390 error = f->f_op->open(inode,f);
393 + intent_release(it);
395 f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
401 + intent_release(it);
404 return ERR_PTR(error);
407 EXPORT_SYMBOL(dentry_open);
409 +struct file *filp_open(const char * filename, int flags, int mode)
411 + int namei_flags, error;
412 + struct file * temp_filp;
413 + struct nameidata nd;
414 + intent_init(&nd.intent, IT_OPEN);
416 + namei_flags = flags;
417 + if ((namei_flags+1) & O_ACCMODE)
419 + if (namei_flags & O_TRUNC)
422 + error = open_namei(filename, namei_flags, mode, &nd);
424 + temp_filp = dentry_open_it(nd.dentry, nd.mnt, flags, &nd.intent);
427 + return ERR_PTR(error);
431 +struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
433 + struct lookup_intent it;
434 + intent_init(&it, IT_LOOKUP);
436 + return dentry_open_it(dentry, mnt, flags, &it);
440 * Find an empty file descriptor entry, and mark it busy.
442 Index: uml-2.6.3/fs/stat.c
443 ===================================================================
444 --- uml-2.6.3.orig/fs/stat.c 2004-02-20 15:00:48.000000000 +0800
445 +++ uml-2.6.3/fs/stat.c 2004-02-20 23:59:00.878466744 +0800
448 EXPORT_SYMBOL(generic_fillattr);
450 -int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
451 +int vfs_getattr_it(struct vfsmount *mnt, struct dentry *dentry, struct lookup_intent *it, struct kstat *stat)
453 struct inode *inode = dentry->d_inode;
459 + if (inode->i_op->getattr_it)
460 + return inode->i_op->getattr_it(mnt, dentry, it, stat);
461 if (inode->i_op->getattr)
462 return inode->i_op->getattr(mnt, dentry, stat);
466 EXPORT_SYMBOL(vfs_getattr);
468 +int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
470 + return vfs_getattr_it(mnt, dentry, NULL, stat);
473 int vfs_stat(char __user *name, struct kstat *stat)
477 + intent_init(&nd.intent, IT_GETATTR);
479 - error = user_path_walk(name, &nd);
480 + error = user_path_walk_it(name, &nd);
482 - error = vfs_getattr(nd.mnt, nd.dentry, stat);
483 + error = vfs_getattr_it(nd.mnt, nd.dentry, &nd.intent, stat);
491 + intent_init(&nd.intent, IT_GETATTR);
493 - error = user_path_walk_link(name, &nd);
494 + error = user_path_walk_link_it(name, &nd);
496 - error = vfs_getattr(nd.mnt, nd.dentry, stat);
497 + error = vfs_getattr_it(nd.mnt, nd.dentry, &nd.intent, stat);
503 struct file *f = fget(fd);
505 + struct nameidata nd;
506 + intent_init(&nd.intent, IT_GETATTR);
509 - error = vfs_getattr(f->f_vfsmnt, f->f_dentry, stat);
510 + error = vfs_getattr_it(f->f_vfsmnt, f->f_dentry, &nd.intent, stat);
511 + intent_release(&nd.intent);
515 Index: uml-2.6.3/fs/nfs/dir.c
516 ===================================================================
517 --- uml-2.6.3.orig/fs/nfs/dir.c 2004-02-20 15:01:27.000000000 +0800
518 +++ uml-2.6.3/fs/nfs/dir.c 2004-02-20 23:59:00.880466440 +0800
521 if (!nd || (nd->flags & LOOKUP_CONTINUE) || !(nd->flags & LOOKUP_CREATE))
523 - return (nd->intent.open.flags & O_EXCL) != 0;
524 + return (nd->intent.it_flags & O_EXCL) != 0;
527 static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
529 attr.ia_valid = ATTR_MODE;
531 if (nd && (nd->flags & LOOKUP_CREATE))
532 - open_flags = nd->intent.open.flags;
533 + open_flags = nd->intent.it_flags;
536 * The 0 argument passed into the create function should one day
537 Index: uml-2.6.3/fs/inode.c
538 ===================================================================
539 --- uml-2.6.3.orig/fs/inode.c 2004-01-09 15:00:12.000000000 +0800
540 +++ uml-2.6.3/fs/inode.c 2004-02-20 23:59:00.951455648 +0800
542 inodes_stat.nr_unused--;
545 +EXPORT_SYMBOL(__iget);
547 * clear_inode - clear an inode
548 * @inode: inode to clear
549 Index: uml-2.6.3/fs/super.c
550 ===================================================================
551 --- uml-2.6.3.orig/fs/super.c 2004-02-20 15:01:27.000000000 +0800
552 +++ uml-2.6.3/fs/super.c 2004-02-20 23:59:01.024444552 +0800
554 return (struct vfsmount *)sb;
557 +EXPORT_SYMBOL(do_kern_mount);
559 struct vfsmount *kern_mount(struct file_system_type *type)
561 return do_kern_mount(type->name, 0, type->name, NULL);
562 Index: uml-2.6.3/include/linux/dcache.h
563 ===================================================================
564 --- uml-2.6.3.orig/include/linux/dcache.h 2004-02-20 15:00:57.000000000 +0800
565 +++ uml-2.6.3/include/linux/dcache.h 2004-02-20 23:59:01.025444400 +0800
569 #include <asm/atomic.h>
570 +#include <linux/string.h>
571 #include <linux/list.h>
572 #include <linux/spinlock.h>
573 #include <linux/cache.h>
578 +#include <linux/namei.h>
580 struct dentry_stat_t {
583 Index: uml-2.6.3/include/linux/fs.h
584 ===================================================================
585 --- uml-2.6.3.orig/include/linux/fs.h 2004-02-20 15:01:28.000000000 +0800
586 +++ uml-2.6.3/include/linux/fs.h 2004-02-20 23:59:01.100433000 +0800
588 #define ATTR_ATTR_FLAG 1024
589 #define ATTR_KILL_SUID 2048
590 #define ATTR_KILL_SGID 4096
591 +#define ATTR_RAW 8192 /* file system, not vfs will massage attrs */
592 +#define ATTR_FROM_OPEN 16384 /* called from open path, ie O_TRUNC */
595 * This is the Inode Attributes structure, used for notify_change(). It
597 struct block_device *i_bdev;
600 + void *i_filterdata;
602 unsigned long i_dnotify_mask; /* Directory notify events */
603 struct dnotify_struct *i_dnotify; /* for directory notifications */
605 spinlock_t f_ep_lock;
606 #endif /* #ifdef CONFIG_EPOLL */
607 struct address_space *f_mapping;
608 + struct lookup_intent *f_it;
610 extern spinlock_t files_lock;
611 #define file_list_lock() spin_lock(&files_lock);
613 void (*truncate) (struct inode *);
614 int (*permission) (struct inode *, int, struct nameidata *);
615 int (*setattr) (struct dentry *, struct iattr *);
616 + int (*setattr_raw) (struct inode *, struct iattr *);
617 int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
618 + int (*getattr_it) (struct vfsmount *, struct dentry *, struct lookup_intent *, struct kstat *);
619 int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);
620 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
621 ssize_t (*listxattr) (struct dentry *, char *, size_t);
622 @@ -1056,6 +1062,7 @@
623 extern int unregister_filesystem(struct file_system_type *);
624 extern struct vfsmount *kern_mount(struct file_system_type *);
625 extern int may_umount(struct vfsmount *);
626 +struct vfsmount *do_kern_mount(const char *type, int flags, const char *name, void *data);
627 extern long do_mount(char *, char *, char *, unsigned long, void *);
629 extern int vfs_statfs(struct super_block *, struct kstatfs *);
630 @@ -1123,6 +1130,7 @@
632 extern struct file *filp_open(const char *, int, int);
633 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
634 +extern struct file * dentry_open_it(struct dentry *, struct vfsmount *, int, struct lookup_intent *);
635 extern int filp_close(struct file *, fl_owner_t id);
636 extern char * getname(const char __user *);
638 Index: uml-2.6.3/include/linux/namei.h
639 ===================================================================
640 --- uml-2.6.3.orig/include/linux/namei.h 2004-01-09 14:59:19.000000000 +0800
641 +++ uml-2.6.3/include/linux/namei.h 2004-02-20 23:59:01.174421752 +0800
643 #define _LINUX_NAMEI_H
645 #include <linux/linkage.h>
646 +#include <linux/string.h>
651 -struct open_intent {
654 +/* intent opcodes */
656 +#define IT_CREAT (1<<1)
657 +#define IT_READDIR (1<<2)
658 +#define IT_GETATTR (1<<3)
659 +#define IT_LOOKUP (1<<4)
660 +#define IT_UNLINK (1<<5)
661 +#define IT_TRUNC (1<<6)
662 +#define IT_GETXATTR (1<<7)
664 +struct lustre_intent_data {
665 + int it_disposition;
667 + __u64 it_lock_handle;
672 +#define INTENT_MAGIC 0x19620323
673 +struct lookup_intent {
675 + void (*it_op_release)(struct lookup_intent *);
678 + int it_create_mode;
680 + struct lustre_intent_data lustre;
684 +static inline void intent_init(struct lookup_intent *it, int op)
686 + memset(it, 0, sizeof(*it));
687 + it->it_magic = INTENT_MAGIC;
692 struct dentry *dentry;
693 struct vfsmount *mnt;
700 - struct open_intent open;
702 + struct lookup_intent intent;
707 #define LOOKUP_CONTINUE 4
708 #define LOOKUP_PARENT 16
709 #define LOOKUP_NOALT 32
710 +#define LOOKUP_LAST (1<<6)
711 +#define LOOKUP_LINK_NOTLAST (1<<7)
717 #define LOOKUP_ACCESS (0x0400)
719 extern int FASTCALL(__user_walk(const char __user *, unsigned, struct nameidata *));
720 +extern int FASTCALL(__user_walk_it(const char __user *name, unsigned flags, struct nameidata *nd));
721 +#define user_path_walk_it(name,nd) \
722 + __user_walk_it(name, LOOKUP_FOLLOW, nd)
723 +#define user_path_walk_link_it(name,nd) \
724 + __user_walk_it(name, 0, nd)
725 +extern void intent_release(struct lookup_intent *);
726 #define user_path_walk(name,nd) \
727 __user_walk(name, LOOKUP_FOLLOW, nd)
728 #define user_path_walk_link(name,nd) \
731 extern struct dentry * lookup_one_len(const char *, struct dentry *, int);
732 extern struct dentry * lookup_hash(struct qstr *, struct dentry *);
734 extern int follow_down(struct vfsmount **, struct dentry **);
735 extern int follow_up(struct vfsmount **, struct dentry **);
737 Index: uml-2.6.3/kernel/exit.c
738 ===================================================================
739 --- uml-2.6.3.orig/kernel/exit.c 2004-02-20 15:00:58.000000000 +0800
740 +++ uml-2.6.3/kernel/exit.c 2004-02-20 23:59:01.176421448 +0800
742 write_unlock_irq(&tasklist_lock);
745 +EXPORT_SYMBOL(reparent_to_init);
747 void __set_special_pids(pid_t session, pid_t pgrp)
749 struct task_struct *curr = current;
754 +EXPORT_SYMBOL(exit_files);
756 static inline void __put_fs_struct(struct fs_struct *fs)
758 /* No need to hold fs->lock if we are killing it */