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: linux-2.6.0/fs/exec.c
14 ===================================================================
15 --- linux-2.6.0.orig/fs/exec.c 2004-01-15 02:58:27.000000000 +0300
16 +++ linux-2.6.0/fs/exec.c 2004-01-15 02:58:33.000000000 +0300
21 + intent_init(&nd.intent, IT_OPEN);
23 - nd.intent.open.flags = O_RDONLY;
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);
40 struct file *open_exec(const char *name)
43 - int err = path_lookup(name, LOOKUP_FOLLOW, &nd);
44 - struct file *file = ERR_PTR(err);
48 + intent_init(&nd.intent, IT_OPEN);
49 + nd.intent.it_flags = O_RDONLY;
50 + err = path_lookup(name, LOOKUP_FOLLOW, &nd);
51 + file = ERR_PTR(err);
54 struct inode *inode = nd.dentry->d_inode;
59 - file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
60 + file = dentry_open_it(nd.dentry, nd.mnt, O_RDONLY, &nd.intent);
62 err = deny_write_access(file);
64 Index: linux-2.6.0/fs/namei.c
65 ===================================================================
66 --- linux-2.6.0.orig/fs/namei.c 2003-12-30 08:32:44.000000000 +0300
67 +++ linux-2.6.0/fs/namei.c 2004-01-15 02:58:33.000000000 +0300
72 +void intent_release(struct lookup_intent *it)
76 + if (it->it_magic != INTENT_MAGIC)
78 + if (it->it_op_release)
79 + it->it_op_release(it);
82 void path_release(struct nameidata *nd)
84 + intent_release(&nd->intent);
90 struct dentry * result;
91 struct inode *dir = parent->d_inode;
98 * First re-do the cached lookup just in case it was created
100 if (result->d_op && result->d_op->d_revalidate) {
101 if (!result->d_op->d_revalidate(result, nd) && !d_invalidate(result)) {
103 - result = ERR_PTR(-ENOENT);
105 + result = ERR_PTR(-ESTALE);
106 + if (!IS_ERR(result))
112 return PTR_ERR(dentry);
115 +static int revalidate_special(struct nameidata *nd)
117 + struct dentry *dentry = nd->dentry;
118 + int err, counter = 0;
120 + if (!dentry->d_op || !dentry->d_op->d_revalidate)
123 + if (!dentry->d_op->d_revalidate(dentry, nd)) {
124 + struct dentry *new;
125 + if ((err = permission(dentry->d_parent->d_inode, MAY_EXEC,nd)))
127 + new = real_lookup(dentry->d_parent, &dentry->d_name, nd);
128 + d_invalidate(dentry);
130 + nd->dentry = dentry = new;
133 + goto revalidate_again;
134 + printk("excessive revalidate_it loops\n");
145 if (inode->i_op->follow_link) {
147 + nd->flags |= LOOKUP_LINK_NOTLAST;
148 err = do_follow_link(next.dentry, nd);
149 + nd->flags &= ~LOOKUP_LINK_NOTLAST;
154 inode = nd->dentry->d_inode;
157 + nd->flags |= LOOKUP_LAST;
158 + err = revalidate_special(nd);
159 + nd->flags &= ~LOOKUP_LAST;
164 if (nd->dentry->d_op && nd->dentry->d_op->d_hash) {
169 + nd->flags |= LOOKUP_LAST;
170 err = do_lookup(nd, &this, &next);
171 + nd->flags &= ~LOOKUP_LAST;
174 follow_mount(&next.mnt, &next.dentry);
179 -struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
180 +struct dentry * lookup_one_len_it(const char * name, struct dentry * base, int len, struct nameidata *nd)
184 @@ -948,11 +999,16 @@
186 this.hash = end_name_hash(hash);
188 - return lookup_hash(&this, base);
189 + return __lookup_hash(&this, base, nd);
191 return ERR_PTR(-EACCES);
194 +struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
196 + return lookup_one_len_it(name, base, len, NULL);
202 @@ -964,11 +1020,12 @@
203 * that namei follows links, while lnamei does not.
206 -int __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
207 +int __user_walk_it(const char __user *name, unsigned flags, struct nameidata *nd)
209 char *tmp = getname(name);
210 int err = PTR_ERR(tmp);
214 err = path_lookup(tmp, flags, nd);
216 @@ -976,6 +1033,12 @@
220 +int __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
222 + intent_init(&nd->intent, IT_LOOKUP);
223 + return __user_walk_it(name, flags, nd);
227 * It's inline, so penalty for filesystems that don't use sticky bit is
229 @@ -1248,8 +1311,8 @@
230 acc_mode |= MAY_APPEND;
232 /* Fill in the open() intent data */
233 - nd->intent.open.flags = flag;
234 - nd->intent.open.create_mode = mode;
235 + nd->intent.it_flags = flag;
236 + nd->intent.it_create_mode = mode;
239 * The simplest case - just a plain lookup.
240 @@ -1265,6 +1328,7 @@
242 * Create - we need to know the parent.
244 + nd->intent.it_op |= IT_CREAT;
245 error = path_lookup(pathname, LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, nd);
248 @@ -1281,7 +1345,9 @@
250 nd->flags &= ~LOOKUP_PARENT;
251 down(&dir->d_inode->i_sem);
252 + nd->flags |= LOOKUP_LAST;
253 dentry = __lookup_hash(&nd->last, nd->dentry, nd);
254 + nd->flags &= ~LOOKUP_LAST;
257 error = PTR_ERR(dentry);
258 @@ -1386,7 +1452,9 @@
261 down(&dir->d_inode->i_sem);
262 + nd->flags |= LOOKUP_LAST;
263 dentry = __lookup_hash(&nd->last, nd->dentry, nd);
264 + nd->flags &= ~LOOKUP_LAST;
265 putname(nd->last.name);
268 @@ -2148,7 +2216,9 @@
269 __vfs_follow_link(struct nameidata *nd, const char *link)
272 + struct lookup_intent it = nd->intent;
278 @@ -2158,6 +2228,10 @@
279 /* weird __emul_prefix() stuff did it */
283 + intent_init(&nd->intent, it.it_op);
284 + nd->intent.it_flags = it.it_flags;
285 + nd->intent.it_create_mode = it.it_create_mode;
286 res = link_path_walk(link, nd);
288 if (current->link_count || res || nd->last_type!=LAST_NORM)
289 Index: linux-2.6.0/fs/namespace.c
290 ===================================================================
291 --- linux-2.6.0.orig/fs/namespace.c 2004-01-15 02:58:27.000000000 +0300
292 +++ linux-2.6.0/fs/namespace.c 2004-01-15 02:58:33.000000000 +0300
297 + intent_init(&nd.intent, IT_LOOKUP);
299 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
300 flags &= ~MS_MGC_MSK;
301 Index: linux-2.6.0/fs/open.c
302 ===================================================================
303 --- linux-2.6.0.orig/fs/open.c 2004-01-15 02:58:27.000000000 +0300
304 +++ linux-2.6.0/fs/open.c 2004-01-15 02:58:33.000000000 +0300
307 struct inode * inode;
310 + intent_init(&nd.intent, IT_GETATTR);
312 if (length < 0) /* sorry, but loff_t says... */
315 int old_fsuid, old_fsgid;
316 kernel_cap_t old_cap;
318 + intent_init(&nd.intent, IT_GETATTR);
320 if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
323 if(!res && (mode & S_IWOTH) && IS_RDONLY(nd.dentry->d_inode)
324 && !special_file(nd.dentry->d_inode->i_mode))
334 + intent_init(&nd.intent, IT_GETATTR);
336 error = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd);
342 + intent_init(&nd.intent, IT_GETATTR);
344 error = __user_walk(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd);
348 if (IS_RDONLY(inode))
353 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
356 * for the internal routines (ie open_namei()/follow_link() etc). 00 is
359 -struct file *filp_open(const char * filename, int flags, int mode)
361 - int namei_flags, error;
362 - struct nameidata nd;
364 - namei_flags = flags;
365 - if ((namei_flags+1) & O_ACCMODE)
367 - if (namei_flags & O_TRUNC)
370 - error = open_namei(filename, namei_flags, mode, &nd);
372 - return dentry_open(nd.dentry, nd.mnt, flags);
374 - return ERR_PTR(error);
377 -EXPORT_SYMBOL(filp_open);
379 -struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
380 +struct file *dentry_open_it(struct dentry *dentry, struct vfsmount *mnt, int flags,
381 + struct lookup_intent *it)
388 f->f_mode = (flags+1) & O_ACCMODE;
390 inode = dentry->d_inode;
391 if (f->f_mode & FMODE_WRITE) {
392 error = get_write_access(inode);
394 error = f->f_op->open(inode,f);
397 + intent_release(it);
399 f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
405 + intent_release(it);
408 return ERR_PTR(error);
411 EXPORT_SYMBOL(dentry_open);
413 +struct file *filp_open(const char * filename, int flags, int mode)
415 + int namei_flags, error;
416 + struct file * temp_filp;
417 + struct nameidata nd;
418 + intent_init(&nd.intent, IT_OPEN);
420 + namei_flags = flags;
421 + if ((namei_flags+1) & O_ACCMODE)
423 + if (namei_flags & O_TRUNC)
426 + error = open_namei(filename, namei_flags, mode, &nd);
428 + temp_filp = dentry_open_it(nd.dentry, nd.mnt, flags, &nd.intent);
431 + return ERR_PTR(error);
435 +struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
437 + struct lookup_intent it;
438 + intent_init(&it, IT_LOOKUP);
440 + return dentry_open_it(dentry, mnt, flags, &it);
444 * Find an empty file descriptor entry, and mark it busy.
446 Index: linux-2.6.0/fs/stat.c
447 ===================================================================
448 --- linux-2.6.0.orig/fs/stat.c 2004-01-15 02:58:27.000000000 +0300
449 +++ linux-2.6.0/fs/stat.c 2004-01-15 02:59:34.000000000 +0300
452 EXPORT_SYMBOL(generic_fillattr);
454 -int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
455 +int vfs_getattr_it(struct vfsmount *mnt, struct dentry *dentry, struct lookup_intent *it, struct kstat *stat)
457 struct inode *inode = dentry->d_inode;
463 + if (inode->i_op->getattr_it)
464 + return inode->i_op->getattr_it(mnt, dentry, it, stat);
465 if (inode->i_op->getattr)
466 return inode->i_op->getattr(mnt, dentry, stat);
470 EXPORT_SYMBOL(vfs_getattr);
472 +int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
474 + return vfs_getattr_it(mnt, dentry, NULL, stat);
477 int vfs_stat(char __user *name, struct kstat *stat)
481 + intent_init(&nd.intent, IT_GETATTR);
483 - error = user_path_walk(name, &nd);
484 + error = user_path_walk_it(name, &nd);
486 - error = vfs_getattr(nd.mnt, nd.dentry, stat);
487 + error = vfs_getattr_it(nd.mnt, nd.dentry, &nd.intent, stat);
495 + intent_init(&nd.intent, IT_GETATTR);
497 - error = user_path_walk_link(name, &nd);
498 + error = user_path_walk_link_it(name, &nd);
500 - error = vfs_getattr(nd.mnt, nd.dentry, stat);
501 + error = vfs_getattr_it(nd.mnt, nd.dentry, &nd.intent, stat);
507 struct file *f = fget(fd);
509 + struct nameidata nd;
510 + intent_init(&nd.intent, IT_GETATTR);
513 - error = vfs_getattr(f->f_vfsmnt, f->f_dentry, stat);
514 + error = vfs_getattr_it(f->f_vfsmnt, f->f_dentry, &nd.intent, stat);
515 + intent_release(&nd.intent);
519 Index: linux-2.6.0/fs/nfs/dir.c
520 ===================================================================
521 --- linux-2.6.0.orig/fs/nfs/dir.c 2003-12-30 08:32:44.000000000 +0300
522 +++ linux-2.6.0/fs/nfs/dir.c 2004-01-15 02:58:33.000000000 +0300
525 if (!nd || (nd->flags & LOOKUP_CONTINUE) || !(nd->flags & LOOKUP_CREATE))
527 - return (nd->intent.open.flags & O_EXCL) != 0;
528 + return (nd->intent.it_flags & O_EXCL) != 0;
531 static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
533 attr.ia_valid = ATTR_MODE;
535 if (nd && (nd->flags & LOOKUP_CREATE))
536 - open_flags = nd->intent.open.flags;
537 + open_flags = nd->intent.it_flags;
540 * The 0 argument passed into the create function should one day
541 Index: linux-2.6.0/fs/inode.c
542 ===================================================================
543 --- linux-2.6.0.orig/fs/inode.c 2004-01-15 02:58:27.000000000 +0300
544 +++ linux-2.6.0/fs/inode.c 2004-01-15 02:58:33.000000000 +0300
546 inodes_stat.nr_unused--;
549 +EXPORT_SYMBOL(__iget);
551 * clear_inode - clear an inode
552 * @inode: inode to clear
553 Index: linux-2.6.0/fs/super.c
554 ===================================================================
555 --- linux-2.6.0.orig/fs/super.c 2004-01-15 02:58:27.000000000 +0300
556 +++ linux-2.6.0/fs/super.c 2004-01-15 02:58:33.000000000 +0300
558 return (struct vfsmount *)sb;
561 +EXPORT_SYMBOL(do_kern_mount);
563 struct vfsmount *kern_mount(struct file_system_type *type)
565 return do_kern_mount(type->name, 0, type->name, NULL);
566 Index: linux-2.6.0/include/linux/dcache.h
567 ===================================================================
568 --- linux-2.6.0.orig/include/linux/dcache.h 2003-09-19 18:01:10.000000000 +0400
569 +++ linux-2.6.0/include/linux/dcache.h 2004-01-15 02:58:33.000000000 +0300
573 #include <asm/atomic.h>
574 +#include <linux/string.h>
575 #include <linux/list.h>
576 #include <linux/spinlock.h>
577 #include <linux/cache.h>
582 +#include <linux/namei.h>
584 struct dentry_stat_t {
587 Index: linux-2.6.0/include/linux/fs.h
588 ===================================================================
589 --- linux-2.6.0.orig/include/linux/fs.h 2004-01-15 02:58:27.000000000 +0300
590 +++ linux-2.6.0/include/linux/fs.h 2004-01-15 02:58:33.000000000 +0300
592 #define ATTR_ATTR_FLAG 1024
593 #define ATTR_KILL_SUID 2048
594 #define ATTR_KILL_SGID 4096
595 +#define ATTR_RAW 8192 /* file system, not vfs will massage attrs */
596 +#define ATTR_FROM_OPEN 16384 /* called from open path, ie O_TRUNC */
599 * This is the Inode Attributes structure, used for notify_change(). It
601 struct block_device *i_bdev;
604 + void *i_filterdata;
606 unsigned long i_dnotify_mask; /* Directory notify events */
607 struct dnotify_struct *i_dnotify; /* for directory notifications */
609 spinlock_t f_ep_lock;
610 #endif /* #ifdef CONFIG_EPOLL */
611 struct address_space *f_mapping;
612 + struct lookup_intent *f_it;
614 extern spinlock_t files_lock;
615 #define file_list_lock() spin_lock(&files_lock);
617 void (*truncate) (struct inode *);
618 int (*permission) (struct inode *, int, struct nameidata *);
619 int (*setattr) (struct dentry *, struct iattr *);
620 + int (*setattr_raw) (struct inode *, struct iattr *);
621 int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
622 + int (*getattr_it) (struct vfsmount *, struct dentry *, struct lookup_intent *, struct kstat *);
623 int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);
624 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
625 ssize_t (*listxattr) (struct dentry *, char *, size_t);
626 @@ -1057,6 +1063,7 @@
627 extern int unregister_filesystem(struct file_system_type *);
628 extern struct vfsmount *kern_mount(struct file_system_type *);
629 extern int may_umount(struct vfsmount *);
630 +struct vfsmount *do_kern_mount(const char *type, int flags, const char *name, void *data);
631 extern long do_mount(char *, char *, char *, unsigned long, void *);
633 extern int vfs_statfs(struct super_block *, struct kstatfs *);
634 @@ -1124,6 +1131,7 @@
636 extern struct file *filp_open(const char *, int, int);
637 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
638 +extern struct file * dentry_open_it(struct dentry *, struct vfsmount *, int, struct lookup_intent *);
639 extern int filp_close(struct file *, fl_owner_t id);
640 extern char * getname(const char __user *);
642 Index: linux-2.6.0/include/linux/namei.h
643 ===================================================================
644 --- linux-2.6.0.orig/include/linux/namei.h 2003-07-24 15:52:31.000000000 +0400
645 +++ linux-2.6.0/include/linux/namei.h 2004-01-15 02:58:33.000000000 +0300
647 #define _LINUX_NAMEI_H
649 #include <linux/linkage.h>
650 +#include <linux/string.h>
655 -struct open_intent {
658 +/* intent opcodes */
660 +#define IT_CREAT (1<<1)
661 +#define IT_READDIR (1<<2)
662 +#define IT_GETATTR (1<<3)
663 +#define IT_LOOKUP (1<<4)
664 +#define IT_UNLINK (1<<5)
665 +#define IT_TRUNC (1<<6)
666 +#define IT_GETXATTR (1<<7)
668 +struct lustre_intent_data {
669 + int it_disposition;
671 + __u64 it_lock_handle;
676 +#define INTENT_MAGIC 0x19620323
677 +struct lookup_intent {
679 + void (*it_op_release)(struct lookup_intent *);
682 + int it_create_mode;
684 + struct lustre_intent_data lustre;
688 +static inline void intent_init(struct lookup_intent *it, int op)
690 + memset(it, 0, sizeof(*it));
691 + it->it_magic = INTENT_MAGIC;
696 struct dentry *dentry;
697 struct vfsmount *mnt;
704 - struct open_intent open;
706 + struct lookup_intent intent;
711 #define LOOKUP_CONTINUE 4
712 #define LOOKUP_PARENT 16
713 #define LOOKUP_NOALT 32
714 +#define LOOKUP_LAST (1<<6)
715 +#define LOOKUP_LINK_NOTLAST (1<<7)
721 #define LOOKUP_ACCESS (0x0400)
723 extern int FASTCALL(__user_walk(const char __user *, unsigned, struct nameidata *));
724 +extern int FASTCALL(__user_walk_it(const char __user *name, unsigned flags, struct nameidata *nd));
725 +#define user_path_walk_it(name,nd) \
726 + __user_walk_it(name, LOOKUP_FOLLOW, nd)
727 +#define user_path_walk_link_it(name,nd) \
728 + __user_walk_it(name, 0, nd)
729 +extern void intent_release(struct lookup_intent *);
730 #define user_path_walk(name,nd) \
731 __user_walk(name, LOOKUP_FOLLOW, nd)
732 #define user_path_walk_link(name,nd) \
735 extern struct dentry * lookup_one_len(const char *, struct dentry *, int);
736 extern struct dentry * lookup_hash(struct qstr *, struct dentry *);
738 extern int follow_down(struct vfsmount **, struct dentry **);
739 extern int follow_up(struct vfsmount **, struct dentry **);
741 Index: linux-2.6.0/kernel/exit.c
742 ===================================================================
743 --- linux-2.6.0.orig/kernel/exit.c 2004-01-15 02:58:27.000000000 +0300
744 +++ linux-2.6.0/kernel/exit.c 2004-01-15 02:58:33.000000000 +0300
746 write_unlock_irq(&tasklist_lock);
749 +EXPORT_SYMBOL(reparent_to_init);
751 void __set_special_pids(pid_t session, pid_t pgrp)
753 struct task_struct *curr = current;
758 +EXPORT_SYMBOL(exit_files);
760 static inline void __put_fs_struct(struct fs_struct *fs)
762 /* No need to hold fs->lock if we are killing it */