This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / fs / namei.c
1 /*
2  *  linux/fs/namei.c
3  *
4  *  Copyright (C) 1991, 1992  Linus Torvalds
5  */
6
7 /*
8  * Some corrections by tytso.
9  */
10
11 /* [Feb 1997 T. Schoebel-Theuer] Complete rewrite of the pathname
12  * lookup logic.
13  */
14 /* [Feb-Apr 2000, AV] Rewrite to the new namespace architecture.
15  */
16
17 #include <linux/init.h>
18 #include <linux/module.h>
19 #include <linux/slab.h>
20 #include <linux/fs.h>
21 #include <linux/namei.h>
22 #include <linux/quotaops.h>
23 #include <linux/pagemap.h>
24 #include <linux/fsnotify.h>
25 #include <linux/smp_lock.h>
26 #include <linux/personality.h>
27 #include <linux/security.h>
28 #include <linux/syscalls.h>
29 #include <linux/mount.h>
30 #include <linux/audit.h>
31 #include <linux/capability.h>
32 #include <linux/file.h>
33 #include <linux/fcntl.h>
34 #include <linux/namei.h>
35 #include <linux/proc_fs.h>
36 #include <linux/vserver/inode.h>
37 #include <linux/vserver/debug.h>
38 #include <asm/namei.h>
39 #include <asm/uaccess.h>
40
41 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
42
43 /* [Feb-1997 T. Schoebel-Theuer]
44  * Fundamental changes in the pathname lookup mechanisms (namei)
45  * were necessary because of omirr.  The reason is that omirr needs
46  * to know the _real_ pathname, not the user-supplied one, in case
47  * of symlinks (and also when transname replacements occur).
48  *
49  * The new code replaces the old recursive symlink resolution with
50  * an iterative one (in case of non-nested symlink chains).  It does
51  * this with calls to <fs>_follow_link().
52  * As a side effect, dir_namei(), _namei() and follow_link() are now 
53  * replaced with a single function lookup_dentry() that can handle all 
54  * the special cases of the former code.
55  *
56  * With the new dcache, the pathname is stored at each inode, at least as
57  * long as the refcount of the inode is positive.  As a side effect, the
58  * size of the dcache depends on the inode cache and thus is dynamic.
59  *
60  * [29-Apr-1998 C. Scott Ananian] Updated above description of symlink
61  * resolution to correspond with current state of the code.
62  *
63  * Note that the symlink resolution is not *completely* iterative.
64  * There is still a significant amount of tail- and mid- recursion in
65  * the algorithm.  Also, note that <fs>_readlink() is not used in
66  * lookup_dentry(): lookup_dentry() on the result of <fs>_readlink()
67  * may return different results than <fs>_follow_link().  Many virtual
68  * filesystems (including /proc) exhibit this behavior.
69  */
70
71 /* [24-Feb-97 T. Schoebel-Theuer] Side effects caused by new implementation:
72  * New symlink semantics: when open() is called with flags O_CREAT | O_EXCL
73  * and the name already exists in form of a symlink, try to create the new
74  * name indicated by the symlink. The old code always complained that the
75  * name already exists, due to not following the symlink even if its target
76  * is nonexistent.  The new semantics affects also mknod() and link() when
77  * the name is a symlink pointing to a non-existant name.
78  *
79  * I don't know which semantics is the right one, since I have no access
80  * to standards. But I found by trial that HP-UX 9.0 has the full "new"
81  * semantics implemented, while SunOS 4.1.1 and Solaris (SunOS 5.4) have the
82  * "old" one. Personally, I think the new semantics is much more logical.
83  * Note that "ln old new" where "new" is a symlink pointing to a non-existing
84  * file does succeed in both HP-UX and SunOs, but not in Solaris
85  * and in the old Linux semantics.
86  */
87
88 /* [16-Dec-97 Kevin Buhr] For security reasons, we change some symlink
89  * semantics.  See the comments in "open_namei" and "do_link" below.
90  *
91  * [10-Sep-98 Alan Modra] Another symlink change.
92  */
93
94 /* [Feb-Apr 2000 AV] Complete rewrite. Rules for symlinks:
95  *      inside the path - always follow.
96  *      in the last component in creation/removal/renaming - never follow.
97  *      if LOOKUP_FOLLOW passed - follow.
98  *      if the pathname has trailing slashes - follow.
99  *      otherwise - don't follow.
100  * (applied in that order).
101  *
102  * [Jun 2000 AV] Inconsistent behaviour of open() in case if flags==O_CREAT
103  * restored for 2.4. This is the last surviving part of old 4.2BSD bug.
104  * During the 2.4 we need to fix the userland stuff depending on it -
105  * hopefully we will be able to get rid of that wart in 2.5. So far only
106  * XEmacs seems to be relying on it...
107  */
108 /*
109  * [Sep 2001 AV] Single-semaphore locking scheme (kudos to David Holland)
110  * implemented.  Let's see if raised priority of ->s_vfs_rename_mutex gives
111  * any extra contention...
112  */
113
114 /* In order to reduce some races, while at the same time doing additional
115  * checking and hopefully speeding things up, we copy filenames to the
116  * kernel data space before using them..
117  *
118  * POSIX.1 2.4: an empty pathname is invalid (ENOENT).
119  * PATH_MAX includes the nul terminator --RR.
120  */
121 static int do_getname(const char __user *filename, char *page)
122 {
123         int retval;
124         unsigned long len = PATH_MAX;
125
126         if (!segment_eq(get_fs(), KERNEL_DS)) {
127                 if ((unsigned long) filename >= TASK_SIZE)
128                         return -EFAULT;
129                 if (TASK_SIZE - (unsigned long) filename < PATH_MAX)
130                         len = TASK_SIZE - (unsigned long) filename;
131         }
132
133         retval = strncpy_from_user(page, filename, len);
134         if (retval > 0) {
135                 if (retval < len)
136                         return 0;
137                 return -ENAMETOOLONG;
138         } else if (!retval)
139                 retval = -ENOENT;
140         return retval;
141 }
142
143 char * getname(const char __user * filename)
144 {
145         char *tmp, *result;
146
147         result = ERR_PTR(-ENOMEM);
148         tmp = __getname();
149         if (tmp)  {
150                 int retval = do_getname(filename, tmp);
151
152                 result = tmp;
153                 if (retval < 0) {
154                         __putname(tmp);
155                         result = ERR_PTR(retval);
156                 }
157         }
158         audit_getname(result);
159         return result;
160 }
161
162 #ifdef CONFIG_AUDITSYSCALL
163 void putname(const char *name)
164 {
165         if (unlikely(current->audit_context))
166                 audit_putname(name);
167         else
168                 __putname(name);
169 }
170 EXPORT_SYMBOL(putname);
171 #endif
172
173
174 /**
175  * generic_permission  -  check for access rights on a Posix-like filesystem
176  * @inode:      inode to check access rights for
177  * @mask:       right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC)
178  * @check_acl:  optional callback to check for Posix ACLs
179  *
180  * Used to check for read/write/execute permissions on a file.
181  * We use "fsuid" for this, letting us set arbitrary permissions
182  * for filesystem access without changing the "normal" uids which
183  * are used for other things..
184  */
185 int generic_permission(struct inode *inode, int mask,
186                 int (*check_acl)(struct inode *inode, int mask))
187 {
188         umode_t                 mode = inode->i_mode;
189
190         if (current->fsuid == inode->i_uid)
191                 mode >>= 6;
192         else {
193                 if (IS_POSIXACL(inode) && (mode & S_IRWXG) && check_acl) {
194                         int error = check_acl(inode, mask);
195                         if (error == -EACCES)
196                                 goto check_capabilities;
197                         else if (error != -EAGAIN)
198                                 return error;
199                 }
200
201                 if (in_group_p(inode->i_gid))
202                         mode >>= 3;
203         }
204
205         /*
206          * If the DACs are ok we don't need any capability check.
207          */
208         if (((mode & mask & (MAY_READ|MAY_WRITE|MAY_EXEC)) == mask))
209                 return 0;
210
211  check_capabilities:
212         /*
213          * Read/write DACs are always overridable.
214          * Executable DACs are overridable if at least one exec bit is set.
215          */
216         if (!(mask & MAY_EXEC) ||
217             (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode))
218                 if (capable(CAP_DAC_OVERRIDE))
219                         return 0;
220
221         /*
222          * Searching includes executable on directories, else just read.
223          */
224         if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
225                 if (capable(CAP_DAC_READ_SEARCH))
226                         return 0;
227
228         return -EACCES;
229 }
230
231 static inline int vx_barrier(struct inode *inode)
232 {
233         if (IS_BARRIER(inode) && !vx_check(0, VX_ADMIN)) {
234                 vxwprintk(1, "xid=%d did hit the barrier.",
235                         vx_current_xid());
236                 return 1;
237         }
238         return 0;
239 }
240
241 static inline int xid_permission(struct inode *inode, int mask, struct nameidata *nd)
242 {
243         if (vx_barrier(inode))
244                 return -EACCES;
245         if (inode->i_xid == 0)
246                 return 0;
247 #ifdef CONFIG_VSERVER_FILESHARING
248         /* MEF: PlanetLab FS module assumes that any file that can be
249          * named (e.g., via a cross mount) is not hidden from another
250          * context or the admin context.
251          */
252         if (vx_check(inode->i_xid,VX_STATIC|VX_DYNAMIC))
253                 return 0;
254 #endif
255         if (vx_check(inode->i_xid, VX_ADMIN|VX_WATCH|VX_IDENT))
256                 return 0;
257
258         vxwprintk(1, "xid=%d denied access to %p[#%d,%lu] Â»%s«.",
259                 vx_current_xid(), inode, inode->i_xid, inode->i_ino,
260                 vxd_cond_path(nd));
261         return -EACCES;
262 }
263
264 int permission(struct inode *inode, int mask, struct nameidata *nd)
265 {
266         int retval, submask;
267
268         if (mask & MAY_WRITE) {
269                 umode_t mode = inode->i_mode;
270
271                 /*
272                  * Nobody gets write access to a read-only fs.
273                  */
274                 if ((IS_RDONLY(inode) || (nd && MNT_IS_RDONLY(nd->mnt))) &&
275                     (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
276                         return -EROFS;
277
278                 /*
279                  * Nobody gets write access to an immutable file.
280                  */
281                 if (IS_IMMUTABLE(inode))
282                         return -EACCES;
283         }
284
285
286         /* Ordinary permission routines do not understand MAY_APPEND. */
287         submask = mask & ~MAY_APPEND;
288         if ((retval = xid_permission(inode, mask, nd)))
289                 return retval;
290         if (inode->i_op && inode->i_op->permission)
291                 retval = inode->i_op->permission(inode, submask, nd);
292         else
293                 retval = generic_permission(inode, submask, NULL);
294         if (retval)
295                 return retval;
296
297         return security_inode_permission(inode, mask, nd);
298 }
299
300 /**
301  * vfs_permission  -  check for access rights to a given path
302  * @nd:         lookup result that describes the path
303  * @mask:       right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC)
304  *
305  * Used to check for read/write/execute permissions on a path.
306  * We use "fsuid" for this, letting us set arbitrary permissions
307  * for filesystem access without changing the "normal" uids which
308  * are used for other things.
309  */
310 int vfs_permission(struct nameidata *nd, int mask)
311 {
312         return permission(nd->dentry->d_inode, mask, nd);
313 }
314
315 /**
316  * file_permission  -  check for additional access rights to a given file
317  * @file:       file to check access rights for
318  * @mask:       right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC)
319  *
320  * Used to check for read/write/execute permissions on an already opened
321  * file.
322  *
323  * Note:
324  *      Do not use this function in new code.  All access checks should
325  *      be done using vfs_permission().
326  */
327 int file_permission(struct file *file, int mask)
328 {
329         return permission(file->f_dentry->d_inode, mask, NULL);
330 }
331
332 /*
333  * get_write_access() gets write permission for a file.
334  * put_write_access() releases this write permission.
335  * This is used for regular files.
336  * We cannot support write (and maybe mmap read-write shared) accesses and
337  * MAP_DENYWRITE mmappings simultaneously. The i_writecount field of an inode
338  * can have the following values:
339  * 0: no writers, no VM_DENYWRITE mappings
340  * < 0: (-i_writecount) vm_area_structs with VM_DENYWRITE set exist
341  * > 0: (i_writecount) users are writing to the file.
342  *
343  * Normally we operate on that counter with atomic_{inc,dec} and it's safe
344  * except for the cases where we don't hold i_writecount yet. Then we need to
345  * use {get,deny}_write_access() - these functions check the sign and refuse
346  * to do the change if sign is wrong. Exclusion between them is provided by
347  * the inode->i_lock spinlock.
348  */
349
350 int get_write_access(struct inode * inode)
351 {
352         spin_lock(&inode->i_lock);
353         if (atomic_read(&inode->i_writecount) < 0) {
354                 spin_unlock(&inode->i_lock);
355                 return -ETXTBSY;
356         }
357         atomic_inc(&inode->i_writecount);
358         spin_unlock(&inode->i_lock);
359
360         return 0;
361 }
362
363 int deny_write_access(struct file * file)
364 {
365         struct inode *inode = file->f_dentry->d_inode;
366
367         spin_lock(&inode->i_lock);
368         if (atomic_read(&inode->i_writecount) > 0) {
369                 spin_unlock(&inode->i_lock);
370                 return -ETXTBSY;
371         }
372         atomic_dec(&inode->i_writecount);
373         spin_unlock(&inode->i_lock);
374
375         return 0;
376 }
377
378 void path_release(struct nameidata *nd)
379 {
380         dput(nd->dentry);
381         mntput(nd->mnt);
382 }
383
384 /*
385  * umount() mustn't call path_release()/mntput() as that would clear
386  * mnt_expiry_mark
387  */
388 void path_release_on_umount(struct nameidata *nd)
389 {
390         dput(nd->dentry);
391         mntput_no_expire(nd->mnt);
392 }
393
394 /**
395  * release_open_intent - free up open intent resources
396  * @nd: pointer to nameidata
397  */
398 void release_open_intent(struct nameidata *nd)
399 {
400         if (nd->intent.open.file->f_dentry == NULL)
401                 put_filp(nd->intent.open.file);
402         else
403                 fput(nd->intent.open.file);
404 }
405
406 /*
407  * Internal lookup() using the new generic dcache.
408  * SMP-safe
409  */
410 static struct dentry * cached_lookup(struct dentry * parent, struct qstr * name, struct nameidata *nd)
411 {
412         struct dentry * dentry = __d_lookup(parent, name);
413
414         /* lockess __d_lookup may fail due to concurrent d_move() 
415          * in some unrelated directory, so try with d_lookup
416          */
417         if (!dentry)
418                 dentry = d_lookup(parent, name);
419
420         if (dentry && dentry->d_op && dentry->d_op->d_revalidate) {
421                 if (!dentry->d_op->d_revalidate(dentry, nd) && !d_invalidate(dentry)) {
422                         dput(dentry);
423                         dentry = NULL;
424                 }
425         }
426         return dentry;
427 }
428
429 /*
430  * Short-cut version of permission(), for calling by
431  * path_walk(), when dcache lock is held.  Combines parts
432  * of permission() and generic_permission(), and tests ONLY for
433  * MAY_EXEC permission.
434  *
435  * If appropriate, check DAC only.  If not appropriate, or
436  * short-cut DAC fails, then call permission() to do more
437  * complete permission check.
438  */
439 static int exec_permission_lite(struct inode *inode,
440                                        struct nameidata *nd)
441 {
442         umode_t mode = inode->i_mode;
443
444         if (vx_barrier(inode))
445                 return -EACCES;
446         if (inode->i_op && inode->i_op->permission)
447                 return -EAGAIN;
448
449         if (current->fsuid == inode->i_uid)
450                 mode >>= 6;
451         else if (in_group_p(inode->i_gid))
452                 mode >>= 3;
453
454         if (mode & MAY_EXEC)
455                 goto ok;
456
457         if ((inode->i_mode & S_IXUGO) && capable(CAP_DAC_OVERRIDE))
458                 goto ok;
459
460         if (S_ISDIR(inode->i_mode) && capable(CAP_DAC_OVERRIDE))
461                 goto ok;
462
463         if (S_ISDIR(inode->i_mode) && capable(CAP_DAC_READ_SEARCH))
464                 goto ok;
465
466         return -EACCES;
467 ok:
468         return security_inode_permission(inode, MAY_EXEC, nd);
469 }
470
471 /*
472  * This is called when everything else fails, and we actually have
473  * to go to the low-level filesystem to find out what we should do..
474  *
475  * We get the directory semaphore, and after getting that we also
476  * make sure that nobody added the entry to the dcache in the meantime..
477  * SMP-safe
478  */
479 static struct dentry * real_lookup(struct dentry * parent, struct qstr * name, struct nameidata *nd)
480 {
481         struct dentry * result;
482         struct inode *dir = parent->d_inode;
483
484         mutex_lock(&dir->i_mutex);
485         /*
486          * First re-do the cached lookup just in case it was created
487          * while we waited for the directory semaphore..
488          *
489          * FIXME! This could use version numbering or similar to
490          * avoid unnecessary cache lookups.
491          *
492          * The "dcache_lock" is purely to protect the RCU list walker
493          * from concurrent renames at this point (we mustn't get false
494          * negatives from the RCU list walk here, unlike the optimistic
495          * fast walk).
496          *
497          * so doing d_lookup() (with seqlock), instead of lockfree __d_lookup
498          */
499         result = d_lookup(parent, name);
500         if (!result) {
501                 struct dentry * dentry = d_alloc(parent, name);
502                 result = ERR_PTR(-ENOMEM);
503                 if (dentry) {
504                         result = dir->i_op->lookup(dir, dentry, nd);
505                         if (result)
506                                 dput(dentry);
507                         else
508                                 result = dentry;
509                 }
510                 mutex_unlock(&dir->i_mutex);
511                 return result;
512         }
513
514         /*
515          * Uhhuh! Nasty case: the cache was re-populated while
516          * we waited on the semaphore. Need to revalidate.
517          */
518         mutex_unlock(&dir->i_mutex);
519         if (result->d_op && result->d_op->d_revalidate) {
520                 if (!result->d_op->d_revalidate(result, nd) && !d_invalidate(result)) {
521                         dput(result);
522                         result = ERR_PTR(-ENOENT);
523                 }
524         }
525         return result;
526 }
527
528 static int __emul_lookup_dentry(const char *, struct nameidata *);
529
530 /* SMP-safe */
531 static __always_inline int
532 walk_init_root(const char *name, struct nameidata *nd)
533 {
534         read_lock(&current->fs->lock);
535         if (current->fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
536                 nd->mnt = mntget(current->fs->altrootmnt);
537                 nd->dentry = dget(current->fs->altroot);
538                 read_unlock(&current->fs->lock);
539                 if (__emul_lookup_dentry(name,nd))
540                         return 0;
541                 read_lock(&current->fs->lock);
542         }
543         nd->mnt = mntget(current->fs->rootmnt);
544         nd->dentry = dget(current->fs->root);
545         read_unlock(&current->fs->lock);
546         return 1;
547 }
548
549 static __always_inline int __vfs_follow_link(struct nameidata *nd, const char *link)
550 {
551         int res = 0;
552         char *name;
553         if (IS_ERR(link))
554                 goto fail;
555
556         if (*link == '/') {
557                 path_release(nd);
558                 if (!walk_init_root(link, nd))
559                         /* weird __emul_prefix() stuff did it */
560                         goto out;
561         }
562         res = link_path_walk(link, nd);
563 out:
564         if (nd->depth || res || nd->last_type!=LAST_NORM)
565                 return res;
566         /*
567          * If it is an iterative symlinks resolution in open_namei() we
568          * have to copy the last component. And all that crap because of
569          * bloody create() on broken symlinks. Furrfu...
570          */
571         name = __getname();
572         if (unlikely(!name)) {
573                 path_release(nd);
574                 return -ENOMEM;
575         }
576         strcpy(name, nd->last.name);
577         nd->last.name = name;
578         return 0;
579 fail:
580         path_release(nd);
581         return PTR_ERR(link);
582 }
583
584 struct path {
585         struct vfsmount *mnt;
586         struct dentry *dentry;
587 };
588
589 static inline void dput_path(struct path *path, struct nameidata *nd)
590 {
591         dput(path->dentry);
592         if (path->mnt != nd->mnt)
593                 mntput(path->mnt);
594 }
595
596 static inline void path_to_nameidata(struct path *path, struct nameidata *nd)
597 {
598         dput(nd->dentry);
599         if (nd->mnt != path->mnt)
600                 mntput(nd->mnt);
601         nd->mnt = path->mnt;
602         nd->dentry = path->dentry;
603 }
604
605 static __always_inline int __do_follow_link(struct path *path, struct nameidata *nd)
606 {
607         int error;
608         void *cookie;
609         struct dentry *dentry = path->dentry;
610
611         touch_atime(path->mnt, dentry);
612         nd_set_link(nd, NULL);
613
614         if (path->mnt != nd->mnt) {
615                 path_to_nameidata(path, nd);
616                 dget(dentry);
617         }
618         mntget(path->mnt);
619         cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
620         error = PTR_ERR(cookie);
621         if (!IS_ERR(cookie)) {
622                 char *s = nd_get_link(nd);
623                 error = 0;
624                 if (s)
625                         error = __vfs_follow_link(nd, s);
626                 if (dentry->d_inode->i_op->put_link)
627                         dentry->d_inode->i_op->put_link(dentry, nd, cookie);
628         }
629         dput(dentry);
630         mntput(path->mnt);
631
632         return error;
633 }
634
635 /*
636  * This limits recursive symlink follows to 8, while
637  * limiting consecutive symlinks to 40.
638  *
639  * Without that kind of total limit, nasty chains of consecutive
640  * symlinks can cause almost arbitrarily long lookups. 
641  */
642 static inline int do_follow_link(struct path *path, struct nameidata *nd)
643 {
644         int err = -ELOOP;
645         if (current->link_count >= MAX_NESTED_LINKS)
646                 goto loop;
647         if (current->total_link_count >= 40)
648                 goto loop;
649         BUG_ON(nd->depth >= MAX_NESTED_LINKS);
650         cond_resched();
651         err = security_inode_follow_link(path->dentry, nd);
652         if (err)
653                 goto loop;
654         current->link_count++;
655         current->total_link_count++;
656         nd->depth++;
657         err = __do_follow_link(path, nd);
658         current->link_count--;
659         nd->depth--;
660         return err;
661 loop:
662         dput_path(path, nd);
663         path_release(nd);
664         return err;
665 }
666
667 int follow_up(struct vfsmount **mnt, struct dentry **dentry)
668 {
669         struct vfsmount *parent;
670         struct dentry *mountpoint;
671         spin_lock(&vfsmount_lock);
672         parent=(*mnt)->mnt_parent;
673         if (parent == *mnt) {
674                 spin_unlock(&vfsmount_lock);
675                 return 0;
676         }
677         mntget(parent);
678         mountpoint=dget((*mnt)->mnt_mountpoint);
679         spin_unlock(&vfsmount_lock);
680         dput(*dentry);
681         *dentry = mountpoint;
682         mntput(*mnt);
683         *mnt = parent;
684         return 1;
685 }
686
687 /* no need for dcache_lock, as serialization is taken care in
688  * namespace.c
689  */
690 static int __follow_mount(struct path *path)
691 {
692         int res = 0;
693         while (d_mountpoint(path->dentry)) {
694                 struct vfsmount *mounted = lookup_mnt(path->mnt, path->dentry);
695                 if (!mounted)
696                         break;
697                 dput(path->dentry);
698                 if (res)
699                         mntput(path->mnt);
700                 path->mnt = mounted;
701                 path->dentry = dget(mounted->mnt_root);
702                 res = 1;
703         }
704         return res;
705 }
706
707 static void follow_mount(struct vfsmount **mnt, struct dentry **dentry)
708 {
709         while (d_mountpoint(*dentry)) {
710                 struct vfsmount *mounted = lookup_mnt(*mnt, *dentry);
711                 if (!mounted)
712                         break;
713                 dput(*dentry);
714                 mntput(*mnt);
715                 *mnt = mounted;
716                 *dentry = dget(mounted->mnt_root);
717         }
718 }
719
720 /* no need for dcache_lock, as serialization is taken care in
721  * namespace.c
722  */
723 int follow_down(struct vfsmount **mnt, struct dentry **dentry)
724 {
725         struct vfsmount *mounted;
726
727         mounted = lookup_mnt(*mnt, *dentry);
728         if (mounted) {
729                 dput(*dentry);
730                 mntput(*mnt);
731                 *mnt = mounted;
732                 *dentry = dget(mounted->mnt_root);
733                 return 1;
734         }
735         return 0;
736 }
737
738 static __always_inline void follow_dotdot(struct nameidata *nd)
739 {
740         while(1) {
741                 struct vfsmount *parent;
742                 struct dentry *old = nd->dentry;
743
744                 read_lock(&current->fs->lock);
745                 if (nd->dentry == current->fs->root &&
746                     nd->mnt == current->fs->rootmnt) {
747                         read_unlock(&current->fs->lock);
748                         /* for sane '/' avoid follow_mount() */
749                         return;
750                 }
751                 read_unlock(&current->fs->lock);
752                 spin_lock(&dcache_lock);
753                 if (nd->dentry != nd->mnt->mnt_root) {
754                         nd->dentry = dget(nd->dentry->d_parent);
755                         spin_unlock(&dcache_lock);
756                         dput(old);
757                         break;
758                 }
759                 spin_unlock(&dcache_lock);
760                 spin_lock(&vfsmount_lock);
761                 parent = nd->mnt->mnt_parent;
762                 if (parent == nd->mnt) {
763                         spin_unlock(&vfsmount_lock);
764                         break;
765                 }
766                 mntget(parent);
767                 nd->dentry = dget(nd->mnt->mnt_mountpoint);
768                 spin_unlock(&vfsmount_lock);
769                 dput(old);
770                 mntput(nd->mnt);
771                 nd->mnt = parent;
772         }
773         follow_mount(&nd->mnt, &nd->dentry);
774 }
775
776 /*
777  *  It's more convoluted than I'd like it to be, but... it's still fairly
778  *  small and for now I'd prefer to have fast path as straight as possible.
779  *  It _is_ time-critical.
780  */
781 static int do_lookup(struct nameidata *nd, struct qstr *name,
782                      struct path *path, int atomic)
783 {
784         struct vfsmount *mnt = nd->mnt;
785         struct dentry *dentry = __d_lookup(nd->dentry, name);
786         struct inode *inode;
787
788         if (!dentry)
789                 goto need_lookup;
790         if (dentry->d_op && dentry->d_op->d_revalidate)
791                 goto need_revalidate;
792         inode = dentry->d_inode;
793         if (!inode)
794                 goto done;
795 #ifdef CONFIG_VSERVER_FILESHARING
796         /* MEF: PlanetLab FS module assumes that any file that can be
797          * named (e.g., via a cross mount) is not hidden from another
798          * context or the admin context.
799          */
800         if (vx_check(inode->i_xid,VX_STATIC|VX_DYNAMIC|VX_ADMIN)) {
801                 /* do nothing */
802         }
803         else /* do the following check */
804 #endif
805         if (!vx_check(inode->i_xid, VX_WATCH|VX_ADMIN|VX_HOSTID|VX_IDENT))
806                 goto hidden;
807         if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
808                 struct proc_dir_entry *de = PDE(inode);
809
810                 if (de && !vx_hide_check(0, de->vx_flags))
811                         goto hidden;
812         }
813 done:
814         path->mnt = mnt;
815         path->dentry = dentry;
816         __follow_mount(path);
817         return 0;
818 hidden:
819         vxwprintk(1, "xid=%d did lookup hidden %p[#%d,%lu] Â»%s«.",
820                 vx_current_xid(), inode, inode->i_xid, inode->i_ino,
821                 vxd_path(dentry, mnt));
822         dput(dentry);
823         return -ENOENT;
824
825 need_lookup:
826         if (atomic)
827                 return -EWOULDBLOCKIO;
828         dentry = real_lookup(nd->dentry, name, nd);
829         if (IS_ERR(dentry))
830                 goto fail;
831         goto done;
832
833 need_revalidate:
834         if (atomic)
835                 return -EWOULDBLOCKIO;
836         if (dentry->d_op->d_revalidate(dentry, nd))
837                 goto done;
838         if (d_invalidate(dentry))
839                 goto done;
840         dput(dentry);
841         goto need_lookup;
842
843 fail:
844         return PTR_ERR(dentry);
845 }
846
847 /*
848  * Name resolution.
849  * This is the basic name resolution function, turning a pathname into
850  * the final dentry. We expect 'base' to be positive and a directory.
851  *
852  * Returns 0 and nd will have valid dentry and mnt on success.
853  * Returns error and drops reference to input namei data on failure.
854  */
855 static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
856 {
857         struct path next;
858         struct inode *inode;
859         int err, atomic;
860         unsigned int lookup_flags = nd->flags;
861
862         atomic = (lookup_flags & LOOKUP_ATOMIC);
863
864         while (*name=='/')
865                 name++;
866         if (!*name)
867                 goto return_reval;
868
869         inode = nd->dentry->d_inode;
870         if (nd->depth)
871                 lookup_flags = LOOKUP_FOLLOW | (nd->flags & LOOKUP_CONTINUE);
872
873         /* At this point we know we have a real path component. */
874         for(;;) {
875                 unsigned long hash;
876                 struct qstr this;
877                 unsigned int c;
878
879                 nd->flags |= LOOKUP_CONTINUE;
880                 err = exec_permission_lite(inode, nd);
881                 if (err == -EAGAIN)
882                         err = vfs_permission(nd, MAY_EXEC);
883                 if (err)
884                         break;
885
886                 this.name = name;
887                 c = *(const unsigned char *)name;
888
889                 hash = init_name_hash();
890                 do {
891                         name++;
892                         hash = partial_name_hash(c, hash);
893                         c = *(const unsigned char *)name;
894                 } while (c && (c != '/'));
895                 this.len = name - (const char *) this.name;
896                 this.hash = end_name_hash(hash);
897
898                 /* remove trailing slashes? */
899                 if (!c)
900                         goto last_component;
901                 while (*++name == '/');
902                 if (!*name)
903                         goto last_with_slashes;
904
905                 /*
906                  * "." and ".." are special - ".." especially so because it has
907                  * to be able to know about the current root directory and
908                  * parent relationships.
909                  */
910                 if (this.name[0] == '.') switch (this.len) {
911                         default:
912                                 break;
913                         case 2: 
914                                 if (this.name[1] != '.')
915                                         break;
916                                 follow_dotdot(nd);
917                                 inode = nd->dentry->d_inode;
918                                 /* fallthrough */
919                         case 1:
920                                 continue;
921                 }
922                 /*
923                  * See if the low-level filesystem might want
924                  * to use its own hash..
925                  */
926                 if (nd->dentry->d_op && nd->dentry->d_op->d_hash) {
927                         err = nd->dentry->d_op->d_hash(nd->dentry, &this);
928                         if (err < 0)
929                                 break;
930                 }
931                 /* This does the actual lookups.. */
932                 err = do_lookup(nd, &this, &next, atomic);
933                 if (err)
934                         break;
935
936                 err = -ENOENT;
937                 inode = next.dentry->d_inode;
938                 if (!inode)
939                         goto out_dput;
940                 err = -ENOTDIR; 
941                 if (!inode->i_op)
942                         goto out_dput;
943
944                 if (inode->i_op->follow_link) {
945                         err = do_follow_link(&next, nd);
946                         if (err)
947                                 goto return_err;
948                         err = -ENOENT;
949                         inode = nd->dentry->d_inode;
950                         if (!inode)
951                                 break;
952                         err = -ENOTDIR; 
953                         if (!inode->i_op)
954                                 break;
955                 } else
956                         path_to_nameidata(&next, nd);
957                 err = -ENOTDIR; 
958                 if (!inode->i_op->lookup)
959                         break;
960                 continue;
961                 /* here ends the main loop */
962
963 last_with_slashes:
964                 lookup_flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
965 last_component:
966                 /* Clear LOOKUP_CONTINUE iff it was previously unset */
967                 nd->flags &= lookup_flags | ~LOOKUP_CONTINUE;
968                 if (lookup_flags & LOOKUP_PARENT)
969                         goto lookup_parent;
970                 if (this.name[0] == '.') switch (this.len) {
971                         default:
972                                 break;
973                         case 2: 
974                                 if (this.name[1] != '.')
975                                         break;
976                                 follow_dotdot(nd);
977                                 inode = nd->dentry->d_inode;
978                                 /* fallthrough */
979                         case 1:
980                                 goto return_reval;
981                 }
982                 if (nd->dentry->d_op && nd->dentry->d_op->d_hash) {
983                         err = nd->dentry->d_op->d_hash(nd->dentry, &this);
984                         if (err < 0)
985                                 break;
986                 }
987                 err = do_lookup(nd, &this, &next, atomic);
988                 if (err)
989                         break;
990                 inode = next.dentry->d_inode;
991                 if ((lookup_flags & LOOKUP_FOLLOW)
992                     && inode && inode->i_op && inode->i_op->follow_link) {
993                         err = do_follow_link(&next, nd);
994                         if (err)
995                                 goto return_err;
996                         inode = nd->dentry->d_inode;
997                 } else
998                         path_to_nameidata(&next, nd);
999                 err = -ENOENT;
1000                 if (!inode)
1001                         break;
1002                 if (lookup_flags & LOOKUP_DIRECTORY) {
1003                         err = -ENOTDIR; 
1004                         if (!inode->i_op || !inode->i_op->lookup)
1005                                 break;
1006                 }
1007                 goto return_base;
1008 lookup_parent:
1009                 nd->last = this;
1010                 nd->last_type = LAST_NORM;
1011                 if (this.name[0] != '.')
1012                         goto return_base;
1013                 if (this.len == 1)
1014                         nd->last_type = LAST_DOT;
1015                 else if (this.len == 2 && this.name[1] == '.')
1016                         nd->last_type = LAST_DOTDOT;
1017                 else
1018                         goto return_base;
1019 return_reval:
1020                 /*
1021                  * We bypassed the ordinary revalidation routines.
1022                  * We may need to check the cached dentry for staleness.
1023                  */
1024                 if (nd->dentry && nd->dentry->d_sb &&
1025                     (nd->dentry->d_sb->s_type->fs_flags & FS_REVAL_DOT)) {
1026                         err = -ESTALE;
1027                         /* Note: we do not d_invalidate() */
1028                         if (!nd->dentry->d_op->d_revalidate(nd->dentry, nd))
1029                                 break;
1030                 }
1031 return_base:
1032                 return 0;
1033 out_dput:
1034                 dput_path(&next, nd);
1035                 break;
1036         }
1037         path_release(nd);
1038 return_err:
1039         return err;
1040 }
1041
1042 /*
1043  * Wrapper to retry pathname resolution whenever the underlying
1044  * file system returns an ESTALE.
1045  *
1046  * Retry the whole path once, forcing real lookup requests
1047  * instead of relying on the dcache.
1048  */
1049 int fastcall link_path_walk(const char *name, struct nameidata *nd)
1050 {
1051         struct nameidata save = *nd;
1052         int result;
1053
1054         /* make sure the stuff we saved doesn't go away */
1055         dget(save.dentry);
1056         mntget(save.mnt);
1057
1058         result = __link_path_walk(name, nd);
1059         if (result == -ESTALE) {
1060                 *nd = save;
1061                 dget(nd->dentry);
1062                 mntget(nd->mnt);
1063                 nd->flags |= LOOKUP_REVAL;
1064                 result = __link_path_walk(name, nd);
1065         }
1066
1067         dput(save.dentry);
1068         mntput(save.mnt);
1069
1070         return result;
1071 }
1072
1073 int fastcall path_walk(const char * name, struct nameidata *nd)
1074 {
1075         current->total_link_count = 0;
1076         return link_path_walk(name, nd);
1077 }
1078
1079 /* 
1080  * SMP-safe: Returns 1 and nd will have valid dentry and mnt, if
1081  * everything is done. Returns 0 and drops input nd, if lookup failed;
1082  */
1083 static int __emul_lookup_dentry(const char *name, struct nameidata *nd)
1084 {
1085         if (path_walk(name, nd))
1086                 return 0;               /* something went wrong... */
1087
1088         if (!nd->dentry->d_inode || S_ISDIR(nd->dentry->d_inode->i_mode)) {
1089                 struct dentry *old_dentry = nd->dentry;
1090                 struct vfsmount *old_mnt = nd->mnt;
1091                 struct qstr last = nd->last;
1092                 int last_type = nd->last_type;
1093                 /*
1094                  * NAME was not found in alternate root or it's a directory.  Try to find
1095                  * it in the normal root:
1096                  */
1097                 nd->last_type = LAST_ROOT;
1098                 read_lock(&current->fs->lock);
1099                 nd->mnt = mntget(current->fs->rootmnt);
1100                 nd->dentry = dget(current->fs->root);
1101                 read_unlock(&current->fs->lock);
1102                 if (path_walk(name, nd) == 0) {
1103                         if (nd->dentry->d_inode) {
1104                                 dput(old_dentry);
1105                                 mntput(old_mnt);
1106                                 return 1;
1107                         }
1108                         path_release(nd);
1109                 }
1110                 nd->dentry = old_dentry;
1111                 nd->mnt = old_mnt;
1112                 nd->last = last;
1113                 nd->last_type = last_type;
1114         }
1115         return 1;
1116 }
1117
1118 void set_fs_altroot(void)
1119 {
1120         char *emul = __emul_prefix();
1121         struct nameidata nd;
1122         struct vfsmount *mnt = NULL, *oldmnt;
1123         struct dentry *dentry = NULL, *olddentry;
1124         int err;
1125
1126         if (!emul)
1127                 goto set_it;
1128         err = path_lookup(emul, LOOKUP_FOLLOW|LOOKUP_DIRECTORY|LOOKUP_NOALT, &nd);
1129         if (!err) {
1130                 mnt = nd.mnt;
1131                 dentry = nd.dentry;
1132         }
1133 set_it:
1134         write_lock(&current->fs->lock);
1135         oldmnt = current->fs->altrootmnt;
1136         olddentry = current->fs->altroot;
1137         current->fs->altrootmnt = mnt;
1138         current->fs->altroot = dentry;
1139         write_unlock(&current->fs->lock);
1140         if (olddentry) {
1141                 dput(olddentry);
1142                 mntput(oldmnt);
1143         }
1144 }
1145
1146 /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
1147 static int fastcall do_path_lookup(int dfd, const char *name,
1148                                 unsigned int flags, struct nameidata *nd)
1149 {
1150         int retval = 0;
1151         int fput_needed;
1152         struct file *file;
1153
1154         nd->last_type = LAST_ROOT; /* if there are only slashes... */
1155         nd->flags = flags;
1156         nd->depth = 0;
1157
1158         if (*name=='/') {
1159                 read_lock(&current->fs->lock);
1160                 if (current->fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
1161                         nd->mnt = mntget(current->fs->altrootmnt);
1162                         nd->dentry = dget(current->fs->altroot);
1163                         read_unlock(&current->fs->lock);
1164                         if (__emul_lookup_dentry(name,nd))
1165                                 goto out; /* found in altroot */
1166                         read_lock(&current->fs->lock);
1167                 }
1168                 nd->mnt = mntget(current->fs->rootmnt);
1169                 nd->dentry = dget(current->fs->root);
1170                 read_unlock(&current->fs->lock);
1171         } else if (dfd == AT_FDCWD) {
1172                 read_lock(&current->fs->lock);
1173                 nd->mnt = mntget(current->fs->pwdmnt);
1174                 nd->dentry = dget(current->fs->pwd);
1175                 read_unlock(&current->fs->lock);
1176         } else {
1177                 struct dentry *dentry;
1178
1179                 file = fget_light(dfd, &fput_needed);
1180                 retval = -EBADF;
1181                 if (!file)
1182                         goto out_fail;
1183
1184                 dentry = file->f_dentry;
1185
1186                 retval = -ENOTDIR;
1187                 if (!S_ISDIR(dentry->d_inode->i_mode))
1188                         goto fput_fail;
1189
1190                 retval = file_permission(file, MAY_EXEC);
1191                 if (retval)
1192                         goto fput_fail;
1193
1194                 nd->mnt = mntget(file->f_vfsmnt);
1195                 nd->dentry = dget(dentry);
1196
1197                 fput_light(file, fput_needed);
1198         }
1199         current->total_link_count = 0;
1200         retval = link_path_walk(name, nd);
1201 out:
1202         if (likely(retval == 0)) {
1203                 if (unlikely(current->audit_context && nd && nd->dentry &&
1204                                 nd->dentry->d_inode))
1205                 audit_inode(name, nd->dentry->d_inode, flags);
1206         }
1207 out_fail:
1208         return retval;
1209
1210 fput_fail:
1211         fput_light(file, fput_needed);
1212         goto out_fail;
1213 }
1214
1215 int fastcall path_lookup(const char *name, unsigned int flags,
1216                         struct nameidata *nd)
1217 {
1218         return do_path_lookup(AT_FDCWD, name, flags, nd);
1219 }
1220
1221 static int __path_lookup_intent_open(int dfd, const char *name,
1222                 unsigned int lookup_flags, struct nameidata *nd,
1223                 int open_flags, int create_mode)
1224 {
1225         struct file *filp = get_empty_filp();
1226         int err;
1227
1228         if (filp == NULL)
1229                 return -ENFILE;
1230         nd->intent.open.file = filp;
1231         nd->intent.open.flags = open_flags;
1232         nd->intent.open.create_mode = create_mode;
1233         err = do_path_lookup(dfd, name, lookup_flags|LOOKUP_OPEN, nd);
1234         if (IS_ERR(nd->intent.open.file)) {
1235                 if (err == 0) {
1236                         err = PTR_ERR(nd->intent.open.file);
1237                         path_release(nd);
1238                 }
1239         } else if (err != 0)
1240                 release_open_intent(nd);
1241         return err;
1242 }
1243
1244 /**
1245  * path_lookup_open - lookup a file path with open intent
1246  * @dfd: the directory to use as base, or AT_FDCWD
1247  * @name: pointer to file name
1248  * @lookup_flags: lookup intent flags
1249  * @nd: pointer to nameidata
1250  * @open_flags: open intent flags
1251  */
1252 int path_lookup_open(int dfd, const char *name, unsigned int lookup_flags,
1253                 struct nameidata *nd, int open_flags)
1254 {
1255         return __path_lookup_intent_open(dfd, name, lookup_flags, nd,
1256                         open_flags, 0);
1257 }
1258
1259 /**
1260  * path_lookup_create - lookup a file path with open + create intent
1261  * @dfd: the directory to use as base, or AT_FDCWD
1262  * @name: pointer to file name
1263  * @lookup_flags: lookup intent flags
1264  * @nd: pointer to nameidata
1265  * @open_flags: open intent flags
1266  * @create_mode: create intent flags
1267  */
1268 static int path_lookup_create(int dfd, const char *name,
1269                               unsigned int lookup_flags, struct nameidata *nd,
1270                               int open_flags, int create_mode)
1271 {
1272         return __path_lookup_intent_open(dfd, name, lookup_flags|LOOKUP_CREATE,
1273                         nd, open_flags, create_mode);
1274 }
1275
1276 int __user_path_lookup_open(const char __user *name, unsigned int lookup_flags,
1277                 struct nameidata *nd, int open_flags)
1278 {
1279         char *tmp = getname(name);
1280         int err = PTR_ERR(tmp);
1281
1282         if (!IS_ERR(tmp)) {
1283                 err = __path_lookup_intent_open(AT_FDCWD, tmp, lookup_flags, nd, open_flags, 0);
1284                 putname(tmp);
1285         }
1286         return err;
1287 }
1288
1289 /*
1290  * Restricted form of lookup. Doesn't follow links, single-component only,
1291  * needs parent already locked. Doesn't follow mounts.
1292  * SMP-safe.
1293  */
1294 static struct dentry * __lookup_hash(struct qstr *name, struct dentry * base, struct nameidata *nd)
1295 {
1296         struct dentry * dentry;
1297         struct inode *inode;
1298         int err;
1299
1300         inode = base->d_inode;
1301         err = permission(inode, MAY_EXEC, nd);
1302         dentry = ERR_PTR(err);
1303         if (err)
1304                 goto out;
1305
1306         /*
1307          * See if the low-level filesystem might want
1308          * to use its own hash..
1309          */
1310         if (base->d_op && base->d_op->d_hash) {
1311                 err = base->d_op->d_hash(base, name);
1312                 dentry = ERR_PTR(err);
1313                 if (err < 0)
1314                         goto out;
1315         }
1316
1317         dentry = cached_lookup(base, name, nd);
1318         if (!dentry) {
1319                 struct dentry *new = d_alloc(base, name);
1320                 dentry = ERR_PTR(-ENOMEM);
1321                 if (!new)
1322                         goto out;
1323                 dentry = inode->i_op->lookup(inode, new, nd);
1324                 if (!dentry)
1325                         dentry = new;
1326                 else
1327                         dput(new);
1328         }
1329 out:
1330         return dentry;
1331 }
1332
1333 static struct dentry *lookup_hash(struct nameidata *nd)
1334 {
1335         return __lookup_hash(&nd->last, nd->dentry, nd);
1336 }
1337
1338 /* SMP-safe */
1339 struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
1340 {
1341         unsigned long hash;
1342         struct qstr this;
1343         unsigned int c;
1344
1345         this.name = name;
1346         this.len = len;
1347         if (!len)
1348                 goto access;
1349
1350         hash = init_name_hash();
1351         while (len--) {
1352                 c = *(const unsigned char *)name++;
1353                 if (c == '/' || c == '\0')
1354                         goto access;
1355                 hash = partial_name_hash(c, hash);
1356         }
1357         this.hash = end_name_hash(hash);
1358
1359         return __lookup_hash(&this, base, NULL);
1360 access:
1361         return ERR_PTR(-EACCES);
1362 }
1363
1364 /*
1365  *      namei()
1366  *
1367  * is used by most simple commands to get the inode of a specified name.
1368  * Open, link etc use their own routines, but this is enough for things
1369  * like 'chmod' etc.
1370  *
1371  * namei exists in two versions: namei/lnamei. The only difference is
1372  * that namei follows links, while lnamei does not.
1373  * SMP-safe
1374  */
1375 int fastcall __user_walk_fd(int dfd, const char __user *name, unsigned flags,
1376                             struct nameidata *nd)
1377 {
1378         char *tmp = getname(name);
1379         int err = PTR_ERR(tmp);
1380
1381         if (!IS_ERR(tmp)) {
1382                 err = do_path_lookup(dfd, tmp, flags, nd);
1383                 putname(tmp);
1384         }
1385         return err;
1386 }
1387
1388 int fastcall __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
1389 {
1390         return __user_walk_fd(AT_FDCWD, name, flags, nd);
1391 }
1392
1393 /*
1394  * It's inline, so penalty for filesystems that don't use sticky bit is
1395  * minimal.
1396  */
1397 static inline int check_sticky(struct inode *dir, struct inode *inode)
1398 {
1399         if (!(dir->i_mode & S_ISVTX))
1400                 return 0;
1401         if (inode->i_uid == current->fsuid)
1402                 return 0;
1403         if (dir->i_uid == current->fsuid)
1404                 return 0;
1405         return !capable(CAP_FOWNER);
1406 }
1407
1408 /*
1409  *      Check whether we can remove a link victim from directory dir, check
1410  *  whether the type of victim is right.
1411  *  1. We can't do it if dir is read-only (done in permission())
1412  *  2. We should have write and exec permissions on dir
1413  *  3. We can't remove anything from append-only dir
1414  *  4. We can't do anything with immutable dir (done in permission())
1415  *  5. If the sticky bit on dir is set we should either
1416  *      a. be owner of dir, or
1417  *      b. be owner of victim, or
1418  *      c. have CAP_FOWNER capability
1419  *  6. If the victim is append-only or immutable we can't do antyhing with
1420  *     links pointing to it.
1421  *  7. If we were asked to remove a directory and victim isn't one - ENOTDIR.
1422  *  8. If we were asked to remove a non-directory and victim isn't one - EISDIR.
1423  *  9. We can't remove a root or mountpoint.
1424  * 10. We don't allow removal of NFS sillyrenamed files; it's handled by
1425  *     nfs_async_unlink().
1426  */
1427 static int may_delete(struct inode *dir, struct dentry *victim,
1428         int isdir, struct nameidata *nd)
1429 {
1430         int error;
1431
1432         if (!victim->d_inode)
1433                 return -ENOENT;
1434
1435         BUG_ON(victim->d_parent->d_inode != dir);
1436         audit_inode_child(victim->d_name.name, victim->d_inode, dir->i_ino);
1437
1438         error = permission(dir,MAY_WRITE | MAY_EXEC, nd);
1439         if (error)
1440                 return error;
1441         if (IS_APPEND(dir))
1442                 return -EPERM;
1443         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
1444                 IS_IXORUNLINK(victim->d_inode))
1445                 return -EPERM;
1446         if (isdir) {
1447                 if (!S_ISDIR(victim->d_inode->i_mode))
1448                         return -ENOTDIR;
1449                 if (IS_ROOT(victim))
1450                         return -EBUSY;
1451         } else if (S_ISDIR(victim->d_inode->i_mode))
1452                 return -EISDIR;
1453         if (IS_DEADDIR(dir))
1454                 return -ENOENT;
1455         if (victim->d_flags & DCACHE_NFSFS_RENAMED)
1456                 return -EBUSY;
1457         return 0;
1458 }
1459
1460 /*      Check whether we can create an object with dentry child in directory
1461  *  dir.
1462  *  1. We can't do it if child already exists (open has special treatment for
1463  *     this case, but since we are inlined it's OK)
1464  *  2. We can't do it if dir is read-only (done in permission())
1465  *  3. We should have write and exec permissions on dir
1466  *  4. We can't do it if dir is immutable (done in permission())
1467  */
1468 static inline int may_create(struct inode *dir, struct dentry *child,
1469                              struct nameidata *nd)
1470 {
1471         if (child->d_inode)
1472                 return -EEXIST;
1473         if (IS_DEADDIR(dir))
1474                 return -ENOENT;
1475         return permission(dir,MAY_WRITE | MAY_EXEC, nd);
1476 }
1477
1478 /* 
1479  * O_DIRECTORY translates into forcing a directory lookup.
1480  */
1481 static inline int lookup_flags(unsigned int f)
1482 {
1483         unsigned long retval = LOOKUP_FOLLOW;
1484
1485         if (f & O_NOFOLLOW)
1486                 retval &= ~LOOKUP_FOLLOW;
1487         
1488         if (f & O_DIRECTORY)
1489                 retval |= LOOKUP_DIRECTORY;
1490         if (f & O_ATOMICLOOKUP)
1491                 retval |= LOOKUP_ATOMIC;
1492
1493         return retval;
1494 }
1495
1496 /*
1497  * p1 and p2 should be directories on the same fs.
1498  */
1499 struct dentry *lock_rename(struct dentry *p1, struct dentry *p2)
1500 {
1501         struct dentry *p;
1502
1503         if (p1 == p2) {
1504                 mutex_lock(&p1->d_inode->i_mutex);
1505                 return NULL;
1506         }
1507
1508         mutex_lock(&p1->d_inode->i_sb->s_vfs_rename_mutex);
1509
1510         for (p = p1; p->d_parent != p; p = p->d_parent) {
1511                 if (p->d_parent == p2) {
1512                         mutex_lock(&p2->d_inode->i_mutex);
1513                         mutex_lock(&p1->d_inode->i_mutex);
1514                         return p;
1515                 }
1516         }
1517
1518         for (p = p2; p->d_parent != p; p = p->d_parent) {
1519                 if (p->d_parent == p1) {
1520                         mutex_lock(&p1->d_inode->i_mutex);
1521                         mutex_lock(&p2->d_inode->i_mutex);
1522                         return p;
1523                 }
1524         }
1525
1526         mutex_lock(&p1->d_inode->i_mutex);
1527         mutex_lock(&p2->d_inode->i_mutex);
1528         return NULL;
1529 }
1530
1531 void unlock_rename(struct dentry *p1, struct dentry *p2)
1532 {
1533         mutex_unlock(&p1->d_inode->i_mutex);
1534         if (p1 != p2) {
1535                 mutex_unlock(&p2->d_inode->i_mutex);
1536                 mutex_unlock(&p1->d_inode->i_sb->s_vfs_rename_mutex);
1537         }
1538 }
1539
1540 int vfs_create(struct inode *dir, struct dentry *dentry, int mode,
1541                 struct nameidata *nd)
1542 {
1543         int error = may_create(dir, dentry, nd);
1544
1545         if (error)
1546                 return error;
1547
1548         if (!dir->i_op || !dir->i_op->create)
1549                 return -EACCES; /* shouldn't it be ENOSYS? */
1550         mode &= S_IALLUGO;
1551         mode |= S_IFREG;
1552         error = security_inode_create(dir, dentry, mode);
1553         if (error)
1554                 return error;
1555         DQUOT_INIT(dir);
1556         error = dir->i_op->create(dir, dentry, mode, nd);
1557         if (!error)
1558                 fsnotify_create(dir, dentry);
1559         return error;
1560 }
1561
1562 int may_open(struct nameidata *nd, int acc_mode, int flag)
1563 {
1564         struct dentry *dentry = nd->dentry;
1565         struct inode *inode = dentry->d_inode;
1566         int error;
1567
1568         if (!inode)
1569                 return -ENOENT;
1570
1571         if (S_ISLNK(inode->i_mode))
1572                 return -ELOOP;
1573         
1574         if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE))
1575                 return -EISDIR;
1576
1577         error = vfs_permission(nd, acc_mode);
1578         if (error)
1579                 return error;
1580
1581         /*
1582          * FIFO's, sockets and device files are special: they don't
1583          * actually live on the filesystem itself, and as such you
1584          * can write to them even if the filesystem is read-only.
1585          */
1586         if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
1587                 flag &= ~O_TRUNC;
1588         } else if (S_ISBLK(inode->i_mode) || S_ISCHR(inode->i_mode)) {
1589                 if (nd->mnt->mnt_flags & MNT_NODEV)
1590                         return -EACCES;
1591
1592                 flag &= ~O_TRUNC;
1593         } else if ((IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
1594                 && (flag & FMODE_WRITE))
1595                 return -EROFS;
1596         /*
1597          * An append-only file must be opened in append mode for writing.
1598          */
1599         if (IS_APPEND(inode)) {
1600                 if  ((flag & FMODE_WRITE) && !(flag & O_APPEND))
1601                         return -EPERM;
1602                 if (flag & O_TRUNC)
1603                         return -EPERM;
1604         }
1605
1606         /* O_NOATIME can only be set by the owner or superuser */
1607         if (flag & O_NOATIME)
1608                 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1609                         return -EPERM;
1610
1611         /*
1612          * Ensure there are no outstanding leases on the file.
1613          */
1614         error = break_lease(inode, flag);
1615         if (error)
1616                 return error;
1617
1618         if (flag & O_TRUNC) {
1619                 error = get_write_access(inode);
1620                 if (error)
1621                         return error;
1622
1623                 /*
1624                  * Refuse to truncate files with mandatory locks held on them.
1625                  */
1626                 error = locks_verify_locked(inode);
1627                 if (!error) {
1628                         DQUOT_INIT(inode);
1629                         
1630                         error = do_truncate(dentry, 0, ATTR_MTIME|ATTR_CTIME, NULL);
1631                 }
1632                 put_write_access(inode);
1633                 if (error)
1634                         return error;
1635         } else
1636                 if (flag & FMODE_WRITE)
1637                         DQUOT_INIT(inode);
1638
1639         return 0;
1640 }
1641
1642 /*
1643  *      open_namei()
1644  *
1645  * namei for open - this is in fact almost the whole open-routine.
1646  *
1647  * Note that the low bits of "flag" aren't the same as in the open
1648  * system call - they are 00 - no permissions needed
1649  *                        01 - read permission needed
1650  *                        10 - write permission needed
1651  *                        11 - read/write permissions needed
1652  * which is a lot more logical, and also allows the "no perm" needed
1653  * for symlinks (where the permissions are checked later).
1654  * SMP-safe
1655  */
1656 int open_namei(int dfd, const char *pathname, int flag,
1657                 int mode, struct nameidata *nd)
1658 {
1659         int acc_mode, error;
1660         struct path path;
1661         struct dentry *dir;
1662         int count = 0;
1663
1664         acc_mode = ACC_MODE(flag);
1665
1666         /* O_TRUNC implies we need access checks for write permissions */
1667         if (flag & O_TRUNC)
1668                 acc_mode |= MAY_WRITE;
1669
1670         /* Allow the LSM permission hook to distinguish append 
1671            access from general write access. */
1672         if (flag & O_APPEND)
1673                 acc_mode |= MAY_APPEND;
1674
1675         /*
1676          * The simplest case - just a plain lookup.
1677          */
1678         if (!(flag & O_CREAT)) {
1679                 error = path_lookup_open(dfd, pathname, lookup_flags(flag),
1680                                          nd, flag);
1681                 if (error)
1682                         return error;
1683                 goto ok;
1684         }
1685
1686         /*
1687          * Create - we need to know the parent.
1688          */
1689         error = path_lookup_create(dfd,pathname,LOOKUP_PARENT,nd,flag,mode);
1690         if (error)
1691                 return error;
1692
1693         /*
1694          * We have the parent and last component. First of all, check
1695          * that we are not asked to creat(2) an obvious directory - that
1696          * will not do.
1697          */
1698         error = -EISDIR;
1699         if (nd->last_type != LAST_NORM || nd->last.name[nd->last.len])
1700                 goto exit;
1701
1702         dir = nd->dentry;
1703         nd->flags &= ~LOOKUP_PARENT;
1704         mutex_lock(&dir->d_inode->i_mutex);
1705         path.dentry = lookup_hash(nd);
1706         path.mnt = nd->mnt;
1707
1708 do_last:
1709         error = PTR_ERR(path.dentry);
1710         if (IS_ERR(path.dentry)) {
1711                 mutex_unlock(&dir->d_inode->i_mutex);
1712                 goto exit;
1713         }
1714
1715         if (IS_ERR(nd->intent.open.file)) {
1716                 mutex_unlock(&dir->d_inode->i_mutex);
1717                 error = PTR_ERR(nd->intent.open.file);
1718                 goto exit_dput;
1719         }
1720
1721         /* Negative dentry, just create the file */
1722         if (!path.dentry->d_inode) {
1723                 if (!IS_POSIXACL(dir->d_inode))
1724                         mode &= ~current->fs->umask;
1725                 error = vfs_create(dir->d_inode, path.dentry, mode, nd);
1726                 mutex_unlock(&dir->d_inode->i_mutex);
1727                 dput(nd->dentry);
1728                 nd->dentry = path.dentry;
1729                 if (error)
1730                         goto exit;
1731                 /* Don't check for write permission, don't truncate */
1732                 acc_mode = 0;
1733                 flag &= ~O_TRUNC;
1734                 goto ok;
1735         }
1736
1737         /*
1738          * It already exists.
1739          */
1740         mutex_unlock(&dir->d_inode->i_mutex);
1741
1742         error = -EEXIST;
1743         if (flag & O_EXCL)
1744                 goto exit_dput;
1745
1746         if (__follow_mount(&path)) {
1747                 error = -ELOOP;
1748                 if (flag & O_NOFOLLOW)
1749                         goto exit_dput;
1750         }
1751         error = -ENOENT;
1752         if (!path.dentry->d_inode)
1753                 goto exit_dput;
1754         if (path.dentry->d_inode->i_op && path.dentry->d_inode->i_op->follow_link)
1755                 goto do_link;
1756
1757         path_to_nameidata(&path, nd);
1758         error = -EISDIR;
1759         if (path.dentry->d_inode && S_ISDIR(path.dentry->d_inode->i_mode))
1760                 goto exit;
1761 ok:
1762         error = may_open(nd, acc_mode, flag);
1763         if (error)
1764                 goto exit;
1765         return 0;
1766
1767 exit_dput:
1768         dput_path(&path, nd);
1769 exit:
1770         if (!IS_ERR(nd->intent.open.file))
1771                 release_open_intent(nd);
1772         path_release(nd);
1773         return error;
1774
1775 do_link:
1776         error = -ELOOP;
1777         if (flag & O_NOFOLLOW)
1778                 goto exit_dput;
1779         /*
1780          * This is subtle. Instead of calling do_follow_link() we do the
1781          * thing by hands. The reason is that this way we have zero link_count
1782          * and path_walk() (called from ->follow_link) honoring LOOKUP_PARENT.
1783          * After that we have the parent and last component, i.e.
1784          * we are in the same situation as after the first path_walk().
1785          * Well, almost - if the last component is normal we get its copy
1786          * stored in nd->last.name and we will have to putname() it when we
1787          * are done. Procfs-like symlinks just set LAST_BIND.
1788          */
1789         nd->flags |= LOOKUP_PARENT;
1790         error = security_inode_follow_link(path.dentry, nd);
1791         if (error)
1792                 goto exit_dput;
1793         error = __do_follow_link(&path, nd);
1794         if (error) {
1795                 /* Does someone understand code flow here? Or it is only
1796                  * me so stupid? Anathema to whoever designed this non-sense
1797                  * with "intent.open".
1798                  */
1799                 release_open_intent(nd);
1800                 return error;
1801         }
1802         nd->flags &= ~LOOKUP_PARENT;
1803         if (nd->last_type == LAST_BIND)
1804                 goto ok;
1805         error = -EISDIR;
1806         if (nd->last_type != LAST_NORM)
1807                 goto exit;
1808         if (nd->last.name[nd->last.len]) {
1809                 __putname(nd->last.name);
1810                 goto exit;
1811         }
1812         error = -ELOOP;
1813         if (count++==32) {
1814                 __putname(nd->last.name);
1815                 goto exit;
1816         }
1817         dir = nd->dentry;
1818         mutex_lock(&dir->d_inode->i_mutex);
1819         path.dentry = lookup_hash(nd);
1820         path.mnt = nd->mnt;
1821         __putname(nd->last.name);
1822         goto do_last;
1823 }
1824
1825 /**
1826  * lookup_create - lookup a dentry, creating it if it doesn't exist
1827  * @nd: nameidata info
1828  * @is_dir: directory flag
1829  *
1830  * Simple function to lookup and return a dentry and create it
1831  * if it doesn't exist.  Is SMP-safe.
1832  *
1833  * Returns with nd->dentry->d_inode->i_mutex locked.
1834  */
1835 struct dentry *lookup_create(struct nameidata *nd, int is_dir)
1836 {
1837         struct dentry *dentry = ERR_PTR(-EEXIST);
1838
1839         mutex_lock(&nd->dentry->d_inode->i_mutex);
1840         /*
1841          * Yucky last component or no last component at all?
1842          * (foo/., foo/.., /////)
1843          */
1844         if (nd->last_type != LAST_NORM)
1845                 goto fail;
1846         nd->flags &= ~LOOKUP_PARENT;
1847
1848         /*
1849          * Do the final lookup.
1850          */
1851         dentry = lookup_hash(nd);
1852         if (IS_ERR(dentry))
1853                 goto fail;
1854
1855         /*
1856          * Special case - lookup gave negative, but... we had foo/bar/
1857          * From the vfs_mknod() POV we just have a negative dentry -
1858          * all is fine. Let's be bastards - you had / on the end, you've
1859          * been asking for (non-existent) directory. -ENOENT for you.
1860          */
1861         if (!is_dir && nd->last.name[nd->last.len] && !dentry->d_inode)
1862                 goto enoent;
1863         return dentry;
1864 enoent:
1865         dput(dentry);
1866         dentry = ERR_PTR(-ENOENT);
1867 fail:
1868         return dentry;
1869 }
1870 EXPORT_SYMBOL_GPL(lookup_create);
1871
1872 int vfs_mknod(struct inode *dir, struct dentry *dentry,
1873         int mode, dev_t dev, struct nameidata *nd)
1874 {
1875         int error = may_create(dir, dentry, nd);
1876
1877         if (error)
1878                 return error;
1879
1880         if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
1881                 return -EPERM;
1882
1883         if (!dir->i_op || !dir->i_op->mknod)
1884                 return -EPERM;
1885
1886         error = security_inode_mknod(dir, dentry, mode, dev);
1887         if (error)
1888                 return error;
1889
1890         DQUOT_INIT(dir);
1891         error = dir->i_op->mknod(dir, dentry, mode, dev);
1892         if (!error)
1893                 fsnotify_create(dir, dentry);
1894         return error;
1895 }
1896
1897 asmlinkage long sys_mknodat(int dfd, const char __user *filename, int mode,
1898                                 unsigned dev)
1899 {
1900         int error = 0;
1901         char * tmp;
1902         struct dentry * dentry;
1903         struct nameidata nd;
1904
1905         if (S_ISDIR(mode))
1906                 return -EPERM;
1907         tmp = getname(filename);
1908         if (IS_ERR(tmp))
1909                 return PTR_ERR(tmp);
1910
1911         error = do_path_lookup(dfd, tmp, LOOKUP_PARENT, &nd);
1912         if (error)
1913                 goto out;
1914         dentry = lookup_create(&nd, 0);
1915         error = PTR_ERR(dentry);
1916
1917         if (!IS_POSIXACL(nd.dentry->d_inode))
1918                 mode &= ~current->fs->umask;
1919         if (!IS_ERR(dentry)) {
1920                 switch (mode & S_IFMT) {
1921                 case 0: case S_IFREG:
1922                         error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
1923                         break;
1924                 case S_IFCHR: case S_IFBLK:
1925                         error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
1926                                         new_decode_dev(dev), &nd);
1927                         break;
1928                 case S_IFIFO: case S_IFSOCK:
1929                         error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
1930                                         0, &nd);
1931                         break;
1932                 case S_IFDIR:
1933                         error = -EPERM;
1934                         break;
1935                 default:
1936                         error = -EINVAL;
1937                 }
1938                 dput(dentry);
1939         }
1940         mutex_unlock(&nd.dentry->d_inode->i_mutex);
1941         path_release(&nd);
1942 out:
1943         putname(tmp);
1944
1945         return error;
1946 }
1947
1948 asmlinkage long sys_mknod(const char __user *filename, int mode, unsigned dev)
1949 {
1950         return sys_mknodat(AT_FDCWD, filename, mode, dev);
1951 }
1952
1953 int vfs_mkdir(struct inode *dir, struct dentry *dentry,
1954         int mode, struct nameidata *nd)
1955 {
1956         int error = may_create(dir, dentry, nd);
1957
1958         if (error)
1959                 return error;
1960
1961         if (!dir->i_op || !dir->i_op->mkdir)
1962                 return -EPERM;
1963
1964         mode &= (S_IRWXUGO|S_ISVTX);
1965         error = security_inode_mkdir(dir, dentry, mode);
1966         if (error)
1967                 return error;
1968
1969         DQUOT_INIT(dir);
1970         error = dir->i_op->mkdir(dir, dentry, mode);
1971         if (!error)
1972                 fsnotify_mkdir(dir, dentry);
1973         return error;
1974 }
1975
1976 asmlinkage long sys_mkdirat(int dfd, const char __user *pathname, int mode)
1977 {
1978         int error = 0;
1979         char * tmp;
1980
1981         tmp = getname(pathname);
1982         error = PTR_ERR(tmp);
1983         if (!IS_ERR(tmp)) {
1984                 struct dentry *dentry;
1985                 struct nameidata nd;
1986
1987                 error = do_path_lookup(dfd, tmp, LOOKUP_PARENT, &nd);
1988                 if (error)
1989                         goto out;
1990                 dentry = lookup_create(&nd, 1);
1991                 error = PTR_ERR(dentry);
1992                 if (!IS_ERR(dentry)) {
1993                         if (!IS_POSIXACL(nd.dentry->d_inode))
1994                                 mode &= ~current->fs->umask;
1995                         error = vfs_mkdir(nd.dentry->d_inode, dentry,
1996                                 mode, &nd);
1997                         dput(dentry);
1998                 }
1999                 mutex_unlock(&nd.dentry->d_inode->i_mutex);
2000                 path_release(&nd);
2001 out:
2002                 putname(tmp);
2003         }
2004
2005         return error;
2006 }
2007
2008 asmlinkage long sys_mkdir(const char __user *pathname, int mode)
2009 {
2010         return sys_mkdirat(AT_FDCWD, pathname, mode);
2011 }
2012
2013 /*
2014  * We try to drop the dentry early: we should have
2015  * a usage count of 2 if we're the only user of this
2016  * dentry, and if that is true (possibly after pruning
2017  * the dcache), then we drop the dentry now.
2018  *
2019  * A low-level filesystem can, if it choses, legally
2020  * do a
2021  *
2022  *      if (!d_unhashed(dentry))
2023  *              return -EBUSY;
2024  *
2025  * if it cannot handle the case of removing a directory
2026  * that is still in use by something else..
2027  */
2028 void dentry_unhash(struct dentry *dentry)
2029 {
2030         dget(dentry);
2031         if (atomic_read(&dentry->d_count))
2032                 shrink_dcache_parent(dentry);
2033         spin_lock(&dcache_lock);
2034         spin_lock(&dentry->d_lock);
2035         if (atomic_read(&dentry->d_count) == 2)
2036                 __d_drop(dentry);
2037         spin_unlock(&dentry->d_lock);
2038         spin_unlock(&dcache_lock);
2039 }
2040
2041 int vfs_rmdir(struct inode *dir, struct dentry *dentry,
2042         struct nameidata *nd)
2043 {
2044         int error = may_delete(dir, dentry, 1, nd);
2045
2046         if (error)
2047                 return error;
2048
2049         if (!dir->i_op || !dir->i_op->rmdir)
2050                 return -EPERM;
2051
2052         DQUOT_INIT(dir);
2053
2054         mutex_lock(&dentry->d_inode->i_mutex);
2055         dentry_unhash(dentry);
2056         if (d_mountpoint(dentry))
2057                 error = -EBUSY;
2058         else {
2059                 error = security_inode_rmdir(dir, dentry);
2060                 if (!error) {
2061                         error = dir->i_op->rmdir(dir, dentry);
2062                         if (!error)
2063                                 dentry->d_inode->i_flags |= S_DEAD;
2064                 }
2065         }
2066         mutex_unlock(&dentry->d_inode->i_mutex);
2067         if (!error) {
2068                 d_delete(dentry);
2069         }
2070         dput(dentry);
2071
2072         return error;
2073 }
2074
2075 static long do_rmdir(int dfd, const char __user *pathname)
2076 {
2077         int error = 0;
2078         char * name;
2079         struct dentry *dentry;
2080         struct nameidata nd;
2081
2082         name = getname(pathname);
2083         if(IS_ERR(name))
2084                 return PTR_ERR(name);
2085
2086         error = do_path_lookup(dfd, name, LOOKUP_PARENT, &nd);
2087         if (error)
2088                 goto exit;
2089
2090         switch(nd.last_type) {
2091                 case LAST_DOTDOT:
2092                         error = -ENOTEMPTY;
2093                         goto exit1;
2094                 case LAST_DOT:
2095                         error = -EINVAL;
2096                         goto exit1;
2097                 case LAST_ROOT:
2098                         error = -EBUSY;
2099                         goto exit1;
2100         }
2101         mutex_lock(&nd.dentry->d_inode->i_mutex);
2102         dentry = lookup_hash(&nd);
2103         error = PTR_ERR(dentry);
2104         if (!IS_ERR(dentry)) {
2105                 error = vfs_rmdir(nd.dentry->d_inode, dentry, &nd);
2106                 dput(dentry);
2107         }
2108         mutex_unlock(&nd.dentry->d_inode->i_mutex);
2109 exit1:
2110         path_release(&nd);
2111 exit:
2112         putname(name);
2113         return error;
2114 }
2115
2116 asmlinkage long sys_rmdir(const char __user *pathname)
2117 {
2118         return do_rmdir(AT_FDCWD, pathname);
2119 }
2120
2121 int vfs_unlink(struct inode *dir, struct dentry *dentry,
2122         struct nameidata *nd)
2123 {
2124         int error = may_delete(dir, dentry, 0, nd);
2125
2126         if (error)
2127                 return error;
2128
2129         if (!dir->i_op || !dir->i_op->unlink)
2130                 return -EPERM;
2131
2132         DQUOT_INIT(dir);
2133
2134         mutex_lock(&dentry->d_inode->i_mutex);
2135         if (d_mountpoint(dentry))
2136                 error = -EBUSY;
2137         else {
2138                 error = security_inode_unlink(dir, dentry);
2139                 if (!error)
2140                         error = dir->i_op->unlink(dir, dentry);
2141         }
2142         mutex_unlock(&dentry->d_inode->i_mutex);
2143
2144         /* We don't d_delete() NFS sillyrenamed files--they still exist. */
2145         if (!error && !(dentry->d_flags & DCACHE_NFSFS_RENAMED)) {
2146                 d_delete(dentry);
2147         }
2148
2149         return error;
2150 }
2151
2152 /*
2153  * Make sure that the actual truncation of the file will occur outside its
2154  * directory's i_mutex.  Truncate can take a long time if there is a lot of
2155  * writeout happening, and we don't want to prevent access to the directory
2156  * while waiting on the I/O.
2157  */
2158 static long do_unlinkat(int dfd, const char __user *pathname)
2159 {
2160         int error = 0;
2161         char * name;
2162         struct dentry *dentry;
2163         struct nameidata nd;
2164         struct inode *inode = NULL;
2165
2166         name = getname(pathname);
2167         if(IS_ERR(name))
2168                 return PTR_ERR(name);
2169
2170         error = do_path_lookup(dfd, name, LOOKUP_PARENT, &nd);
2171         if (error)
2172                 goto exit;
2173         error = -EISDIR;
2174         if (nd.last_type != LAST_NORM)
2175                 goto exit1;
2176         mutex_lock(&nd.dentry->d_inode->i_mutex);
2177         dentry = lookup_hash(&nd);
2178         error = PTR_ERR(dentry);
2179         if (!IS_ERR(dentry)) {
2180                 /* Why not before? Because we want correct error value */
2181                 if (nd.last.name[nd.last.len])
2182                         goto slashes;
2183                 inode = dentry->d_inode;
2184                 if (inode)
2185                         atomic_inc(&inode->i_count);
2186                 error = vfs_unlink(nd.dentry->d_inode, dentry, &nd);
2187         exit2:
2188                 dput(dentry);
2189         }
2190         mutex_unlock(&nd.dentry->d_inode->i_mutex);
2191         if (inode)
2192                 iput(inode);    /* truncate the inode here */
2193 exit1:
2194         path_release(&nd);
2195 exit:
2196         putname(name);
2197         return error;
2198
2199 slashes:
2200         error = !dentry->d_inode ? -ENOENT :
2201                 S_ISDIR(dentry->d_inode->i_mode) ? -EISDIR : -ENOTDIR;
2202         goto exit2;
2203 }
2204
2205 asmlinkage long sys_unlinkat(int dfd, const char __user *pathname, int flag)
2206 {
2207         if ((flag & ~AT_REMOVEDIR) != 0)
2208                 return -EINVAL;
2209
2210         if (flag & AT_REMOVEDIR)
2211                 return do_rmdir(dfd, pathname);
2212
2213         return do_unlinkat(dfd, pathname);
2214 }
2215
2216 asmlinkage long sys_unlink(const char __user *pathname)
2217 {
2218         return do_unlinkat(AT_FDCWD, pathname);
2219 }
2220
2221 int vfs_symlink(struct inode *dir, struct dentry *dentry,
2222         const char *oldname, int mode, struct nameidata *nd)
2223 {
2224         int error = may_create(dir, dentry, nd);
2225
2226         if (error)
2227                 return error;
2228
2229         if (!dir->i_op || !dir->i_op->symlink)
2230                 return -EPERM;
2231
2232         error = security_inode_symlink(dir, dentry, oldname);
2233         if (error)
2234                 return error;
2235
2236         DQUOT_INIT(dir);
2237         error = dir->i_op->symlink(dir, dentry, oldname);
2238         if (!error)
2239                 fsnotify_create(dir, dentry);
2240         return error;
2241 }
2242
2243 asmlinkage long sys_symlinkat(const char __user *oldname,
2244                               int newdfd, const char __user *newname)
2245 {
2246         int error = 0;
2247         char * from;
2248         char * to;
2249
2250         from = getname(oldname);
2251         if(IS_ERR(from))
2252                 return PTR_ERR(from);
2253         to = getname(newname);
2254         error = PTR_ERR(to);
2255         if (!IS_ERR(to)) {
2256                 struct dentry *dentry;
2257                 struct nameidata nd;
2258
2259                 error = do_path_lookup(newdfd, to, LOOKUP_PARENT, &nd);
2260                 if (error)
2261                         goto out;
2262                 dentry = lookup_create(&nd, 0);
2263                 error = PTR_ERR(dentry);
2264                 if (!IS_ERR(dentry)) {
2265                         error = vfs_symlink(nd.dentry->d_inode, dentry,
2266                                 from, S_IALLUGO, &nd);
2267                         dput(dentry);
2268                 }
2269                 mutex_unlock(&nd.dentry->d_inode->i_mutex);
2270                 path_release(&nd);
2271 out:
2272                 putname(to);
2273         }
2274         putname(from);
2275         return error;
2276 }
2277
2278 asmlinkage long sys_symlink(const char __user *oldname, const char __user *newname)
2279 {
2280         return sys_symlinkat(oldname, AT_FDCWD, newname);
2281 }
2282
2283 int vfs_link(struct dentry *old_dentry, struct inode *dir,
2284         struct dentry *new_dentry, struct nameidata *nd)
2285 {
2286         struct inode *inode = old_dentry->d_inode;
2287         int error;
2288
2289         if (!inode)
2290                 return -ENOENT;
2291
2292         error = may_create(dir, new_dentry, nd);
2293         if (error)
2294                 return error;
2295
2296         if (dir->i_sb != inode->i_sb)
2297                 return -EXDEV;
2298
2299         /*
2300          * A link to an append-only or immutable file cannot be created.
2301          */
2302         if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2303                 return -EPERM;
2304         if (!dir->i_op || !dir->i_op->link)
2305                 return -EPERM;
2306         if (S_ISDIR(old_dentry->d_inode->i_mode))
2307                 return -EPERM;
2308
2309         error = security_inode_link(old_dentry, dir, new_dentry);
2310         if (error)
2311                 return error;
2312
2313         mutex_lock(&old_dentry->d_inode->i_mutex);
2314         DQUOT_INIT(dir);
2315         error = dir->i_op->link(old_dentry, dir, new_dentry);
2316         mutex_unlock(&old_dentry->d_inode->i_mutex);
2317         if (!error)
2318                 fsnotify_create(dir, new_dentry);
2319         return error;
2320 }
2321
2322 /*
2323  * Hardlinks are often used in delicate situations.  We avoid
2324  * security-related surprises by not following symlinks on the
2325  * newname.  --KAB
2326  *
2327  * We don't follow them on the oldname either to be compatible
2328  * with linux 2.0, and to avoid hard-linking to directories
2329  * and other special files.  --ADM
2330  */
2331 asmlinkage long sys_linkat(int olddfd, const char __user *oldname,
2332                            int newdfd, const char __user *newname,
2333                            int flags)
2334 {
2335         struct dentry *new_dentry;
2336         struct nameidata nd, old_nd;
2337         int error;
2338         char * to;
2339
2340         if (flags != 0)
2341                 return -EINVAL;
2342
2343         to = getname(newname);
2344         if (IS_ERR(to))
2345                 return PTR_ERR(to);
2346
2347         error = __user_walk_fd(olddfd, oldname, 0, &old_nd);
2348         if (error)
2349                 goto exit;
2350         error = do_path_lookup(newdfd, to, LOOKUP_PARENT, &nd);
2351         if (error)
2352                 goto out;
2353         /*
2354          * We allow hard-links to be created to a bind-mount as long
2355          * as the bind-mount is not read-only.  Checking for cross-dev
2356          * links is subsumed by the superblock check in vfs_link().
2357          */
2358         error = -EROFS;
2359         if (MNT_IS_RDONLY(old_nd.mnt))
2360                 goto out_release;
2361         new_dentry = lookup_create(&nd, 0);
2362         error = PTR_ERR(new_dentry);
2363         if (!IS_ERR(new_dentry)) {
2364                 error = vfs_link(old_nd.dentry, nd.dentry->d_inode,
2365                         new_dentry, &nd);
2366                 dput(new_dentry);
2367         }
2368         mutex_unlock(&nd.dentry->d_inode->i_mutex);
2369 out_release:
2370         path_release(&nd);
2371 out:
2372         path_release(&old_nd);
2373 exit:
2374         putname(to);
2375
2376         return error;
2377 }
2378
2379 asmlinkage long sys_link(const char __user *oldname, const char __user *newname)
2380 {
2381         return sys_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
2382 }
2383
2384 /*
2385  * The worst of all namespace operations - renaming directory. "Perverted"
2386  * doesn't even start to describe it. Somebody in UCB had a heck of a trip...
2387  * Problems:
2388  *      a) we can get into loop creation. Check is done in is_subdir().
2389  *      b) race potential - two innocent renames can create a loop together.
2390  *         That's where 4.4 screws up. Current fix: serialization on
2391  *         sb->s_vfs_rename_mutex. We might be more accurate, but that's another
2392  *         story.
2393  *      c) we have to lock _three_ objects - parents and victim (if it exists).
2394  *         And that - after we got ->i_mutex on parents (until then we don't know
2395  *         whether the target exists).  Solution: try to be smart with locking
2396  *         order for inodes.  We rely on the fact that tree topology may change
2397  *         only under ->s_vfs_rename_mutex _and_ that parent of the object we
2398  *         move will be locked.  Thus we can rank directories by the tree
2399  *         (ancestors first) and rank all non-directories after them.
2400  *         That works since everybody except rename does "lock parent, lookup,
2401  *         lock child" and rename is under ->s_vfs_rename_mutex.
2402  *         HOWEVER, it relies on the assumption that any object with ->lookup()
2403  *         has no more than 1 dentry.  If "hybrid" objects will ever appear,
2404  *         we'd better make sure that there's no link(2) for them.
2405  *      d) some filesystems don't support opened-but-unlinked directories,
2406  *         either because of layout or because they are not ready to deal with
2407  *         all cases correctly. The latter will be fixed (taking this sort of
2408  *         stuff into VFS), but the former is not going away. Solution: the same
2409  *         trick as in rmdir().
2410  *      e) conversion from fhandle to dentry may come in the wrong moment - when
2411  *         we are removing the target. Solution: we will have to grab ->i_mutex
2412  *         in the fhandle_to_dentry code. [FIXME - current nfsfh.c relies on
2413  *         ->i_mutex on parents, which works but leads to some truely excessive
2414  *         locking].
2415  */
2416 static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
2417                           struct inode *new_dir, struct dentry *new_dentry)
2418 {
2419         int error = 0;
2420         struct inode *target;
2421
2422         /*
2423          * If we are going to change the parent - check write permissions,
2424          * we'll need to flip '..'.
2425          */
2426         if (new_dir != old_dir) {
2427                 error = permission(old_dentry->d_inode, MAY_WRITE, NULL);
2428                 if (error)
2429                         return error;
2430         }
2431
2432         error = security_inode_rename(old_dir, old_dentry, new_dir, new_dentry);
2433         if (error)
2434                 return error;
2435
2436         target = new_dentry->d_inode;
2437         if (target) {
2438                 mutex_lock(&target->i_mutex);
2439                 dentry_unhash(new_dentry);
2440         }
2441         if (d_mountpoint(old_dentry)||d_mountpoint(new_dentry))
2442                 error = -EBUSY;
2443         else 
2444                 error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry);
2445         if (target) {
2446                 if (!error)
2447                         target->i_flags |= S_DEAD;
2448                 mutex_unlock(&target->i_mutex);
2449                 if (d_unhashed(new_dentry))
2450                         d_rehash(new_dentry);
2451                 dput(new_dentry);
2452         }
2453         if (!error)
2454                 d_move(old_dentry,new_dentry);
2455         return error;
2456 }
2457
2458 static int vfs_rename_other(struct inode *old_dir, struct dentry *old_dentry,
2459                             struct inode *new_dir, struct dentry *new_dentry)
2460 {
2461         struct inode *target;
2462         int error;
2463
2464         error = security_inode_rename(old_dir, old_dentry, new_dir, new_dentry);
2465         if (error)
2466                 return error;
2467
2468         dget(new_dentry);
2469         target = new_dentry->d_inode;
2470         if (target)
2471                 mutex_lock(&target->i_mutex);
2472         if (d_mountpoint(old_dentry)||d_mountpoint(new_dentry))
2473                 error = -EBUSY;
2474         else
2475                 error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry);
2476         if (!error) {
2477                 /* The following d_move() should become unconditional */
2478                 if (!(old_dir->i_sb->s_type->fs_flags & FS_ODD_RENAME))
2479                         d_move(old_dentry, new_dentry);
2480         }
2481         if (target)
2482                 mutex_unlock(&target->i_mutex);
2483         dput(new_dentry);
2484         return error;
2485 }
2486
2487 int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
2488                struct inode *new_dir, struct dentry *new_dentry)
2489 {
2490         int error;
2491         int is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
2492         const char *old_name;
2493
2494         if (old_dentry->d_inode == new_dentry->d_inode)
2495                 return 0;
2496  
2497         error = may_delete(old_dir, old_dentry, is_dir, NULL);
2498         if (error)
2499                 return error;
2500
2501         if (!new_dentry->d_inode)
2502                 error = may_create(new_dir, new_dentry, NULL);
2503         else
2504                 error = may_delete(new_dir, new_dentry, is_dir, NULL);
2505         if (error)
2506                 return error;
2507
2508         if (!old_dir->i_op || !old_dir->i_op->rename)
2509                 return -EPERM;
2510
2511         DQUOT_INIT(old_dir);
2512         DQUOT_INIT(new_dir);
2513
2514         old_name = fsnotify_oldname_init(old_dentry->d_name.name);
2515
2516         if (is_dir)
2517                 error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry);
2518         else
2519                 error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
2520         if (!error) {
2521                 const char *new_name = old_dentry->d_name.name;
2522                 fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir,
2523                               new_dentry->d_inode, old_dentry->d_inode);
2524         }
2525         fsnotify_oldname_free(old_name);
2526
2527         return error;
2528 }
2529
2530 static int do_rename(int olddfd, const char *oldname,
2531                         int newdfd, const char *newname)
2532 {
2533         int error = 0;
2534         struct dentry * old_dir, * new_dir;
2535         struct dentry * old_dentry, *new_dentry;
2536         struct dentry * trap;
2537         struct nameidata oldnd, newnd;
2538
2539         error = do_path_lookup(olddfd, oldname, LOOKUP_PARENT, &oldnd);
2540         if (error)
2541                 goto exit;
2542
2543         error = do_path_lookup(newdfd, newname, LOOKUP_PARENT, &newnd);
2544         if (error)
2545                 goto exit1;
2546
2547         error = -EXDEV;
2548         if (oldnd.mnt != newnd.mnt)
2549                 goto exit2;
2550
2551         old_dir = oldnd.dentry;
2552         error = -EBUSY;
2553         if (oldnd.last_type != LAST_NORM)
2554                 goto exit2;
2555
2556         new_dir = newnd.dentry;
2557         if (newnd.last_type != LAST_NORM)
2558                 goto exit2;
2559
2560         trap = lock_rename(new_dir, old_dir);
2561
2562         old_dentry = lookup_hash(&oldnd);
2563         error = PTR_ERR(old_dentry);
2564         if (IS_ERR(old_dentry))
2565                 goto exit3;
2566         /* source must exist */
2567         error = -ENOENT;
2568         if (!old_dentry->d_inode)
2569                 goto exit4;
2570         /* unless the source is a directory trailing slashes give -ENOTDIR */
2571         if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
2572                 error = -ENOTDIR;
2573                 if (oldnd.last.name[oldnd.last.len])
2574                         goto exit4;
2575                 if (newnd.last.name[newnd.last.len])
2576                         goto exit4;
2577         }
2578         /* source should not be ancestor of target */
2579         error = -EINVAL;
2580         if (old_dentry == trap)
2581                 goto exit4;
2582         error = -EROFS;
2583         if (MNT_IS_RDONLY(newnd.mnt))
2584                 goto exit4;
2585         new_dentry = lookup_hash(&newnd);
2586         error = PTR_ERR(new_dentry);
2587         if (IS_ERR(new_dentry))
2588                 goto exit4;
2589         /* target should not be an ancestor of source */
2590         error = -ENOTEMPTY;
2591         if (new_dentry == trap)
2592                 goto exit5;
2593
2594         error = vfs_rename(old_dir->d_inode, old_dentry,
2595                                    new_dir->d_inode, new_dentry);
2596 exit5:
2597         dput(new_dentry);
2598 exit4:
2599         dput(old_dentry);
2600 exit3:
2601         unlock_rename(new_dir, old_dir);
2602 exit2:
2603         path_release(&newnd);
2604 exit1:
2605         path_release(&oldnd);
2606 exit:
2607         return error;
2608 }
2609
2610 asmlinkage long sys_renameat(int olddfd, const char __user *oldname,
2611                              int newdfd, const char __user *newname)
2612 {
2613         int error;
2614         char * from;
2615         char * to;
2616
2617         from = getname(oldname);
2618         if(IS_ERR(from))
2619                 return PTR_ERR(from);
2620         to = getname(newname);
2621         error = PTR_ERR(to);
2622         if (!IS_ERR(to)) {
2623                 error = do_rename(olddfd, from, newdfd, to);
2624                 putname(to);
2625         }
2626         putname(from);
2627         return error;
2628 }
2629
2630 asmlinkage long sys_rename(const char __user *oldname, const char __user *newname)
2631 {
2632         return sys_renameat(AT_FDCWD, oldname, AT_FDCWD, newname);
2633 }
2634
2635 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
2636 {
2637         int len;
2638
2639         len = PTR_ERR(link);
2640         if (IS_ERR(link))
2641                 goto out;
2642
2643         len = strlen(link);
2644         if (len > (unsigned) buflen)
2645                 len = buflen;
2646         if (copy_to_user(buffer, link, len))
2647                 len = -EFAULT;
2648 out:
2649         return len;
2650 }
2651
2652 /*
2653  * A helper for ->readlink().  This should be used *ONLY* for symlinks that
2654  * have ->follow_link() touching nd only in nd_set_link().  Using (or not
2655  * using) it for any given inode is up to filesystem.
2656  */
2657 int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)
2658 {
2659         struct nameidata nd;
2660         void *cookie;
2661
2662         nd.depth = 0;
2663         cookie = dentry->d_inode->i_op->follow_link(dentry, &nd);
2664         if (!IS_ERR(cookie)) {
2665                 int res = vfs_readlink(dentry, buffer, buflen, nd_get_link(&nd));
2666                 if (dentry->d_inode->i_op->put_link)
2667                         dentry->d_inode->i_op->put_link(dentry, &nd, cookie);
2668                 cookie = ERR_PTR(res);
2669         }
2670         return PTR_ERR(cookie);
2671 }
2672
2673 int vfs_follow_link(struct nameidata *nd, const char *link)
2674 {
2675         return __vfs_follow_link(nd, link);
2676 }
2677
2678 /* get the link contents into pagecache */
2679 static char *page_getlink(struct dentry * dentry, struct page **ppage)
2680 {
2681         struct page * page;
2682         struct address_space *mapping = dentry->d_inode->i_mapping;
2683         page = read_cache_page(mapping, 0, (filler_t *)mapping->a_ops->readpage,
2684                                 NULL);
2685         if (IS_ERR(page))
2686                 goto sync_fail;
2687         wait_on_page_locked(page);
2688         if (!PageUptodate(page))
2689                 goto async_fail;
2690         *ppage = page;
2691         return kmap(page);
2692
2693 async_fail:
2694         page_cache_release(page);
2695         return ERR_PTR(-EIO);
2696
2697 sync_fail:
2698         return (char*)page;
2699 }
2700
2701 int page_readlink(struct dentry *dentry, char __user *buffer, int buflen)
2702 {
2703         struct page *page = NULL;
2704         char *s = page_getlink(dentry, &page);
2705         int res = vfs_readlink(dentry,buffer,buflen,s);
2706         if (page) {
2707                 kunmap(page);
2708                 page_cache_release(page);
2709         }
2710         return res;
2711 }
2712
2713 void *page_follow_link_light(struct dentry *dentry, struct nameidata *nd)
2714 {
2715         struct page *page = NULL;
2716         nd_set_link(nd, page_getlink(dentry, &page));
2717         return page;
2718 }
2719
2720 void page_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
2721 {
2722         struct page *page = cookie;
2723
2724         if (page) {
2725                 kunmap(page);
2726                 page_cache_release(page);
2727         }
2728 }
2729
2730 int __page_symlink(struct inode *inode, const char *symname, int len,
2731                 gfp_t gfp_mask)
2732 {
2733         struct address_space *mapping = inode->i_mapping;
2734         struct page *page;
2735         int err = -ENOMEM;
2736         char *kaddr;
2737
2738 retry:
2739         page = find_or_create_page(mapping, 0, gfp_mask);
2740         if (!page)
2741                 goto fail;
2742         err = mapping->a_ops->prepare_write(NULL, page, 0, len-1);
2743         if (err == AOP_TRUNCATED_PAGE) {
2744                 page_cache_release(page);
2745                 goto retry;
2746         }
2747         if (err)
2748                 goto fail_map;
2749         kaddr = kmap_atomic(page, KM_USER0);
2750         memcpy(kaddr, symname, len-1);
2751         kunmap_atomic(kaddr, KM_USER0);
2752         err = mapping->a_ops->commit_write(NULL, page, 0, len-1);
2753         if (err == AOP_TRUNCATED_PAGE) {
2754                 page_cache_release(page);
2755                 goto retry;
2756         }
2757         if (err)
2758                 goto fail_map;
2759         /*
2760          * Notice that we are _not_ going to block here - end of page is
2761          * unmapped, so this will only try to map the rest of page, see
2762          * that it is unmapped (typically even will not look into inode -
2763          * ->i_size will be enough for everything) and zero it out.
2764          * OTOH it's obviously correct and should make the page up-to-date.
2765          */
2766         if (!PageUptodate(page)) {
2767                 err = mapping->a_ops->readpage(NULL, page);
2768                 if (err != AOP_TRUNCATED_PAGE)
2769                         wait_on_page_locked(page);
2770         } else {
2771                 unlock_page(page);
2772         }
2773         page_cache_release(page);
2774         if (err < 0)
2775                 goto fail;
2776         mark_inode_dirty(inode);
2777         return 0;
2778 fail_map:
2779         unlock_page(page);
2780         page_cache_release(page);
2781 fail:
2782         return err;
2783 }
2784
2785 int page_symlink(struct inode *inode, const char *symname, int len)
2786 {
2787         return __page_symlink(inode, symname, len,
2788                         mapping_gfp_mask(inode->i_mapping));
2789 }
2790
2791 struct inode_operations page_symlink_inode_operations = {
2792         .readlink       = generic_readlink,
2793         .follow_link    = page_follow_link_light,
2794         .put_link       = page_put_link,
2795 };
2796
2797 EXPORT_SYMBOL(__user_walk);
2798 EXPORT_SYMBOL(__user_walk_fd);
2799 EXPORT_SYMBOL(follow_down);
2800 EXPORT_SYMBOL(follow_up);
2801 EXPORT_SYMBOL(get_write_access); /* binfmt_aout */
2802 EXPORT_SYMBOL(getname);
2803 EXPORT_SYMBOL(lock_rename);
2804 EXPORT_SYMBOL(lookup_one_len);
2805 EXPORT_SYMBOL(page_follow_link_light);
2806 EXPORT_SYMBOL(page_put_link);
2807 EXPORT_SYMBOL(page_readlink);
2808 EXPORT_SYMBOL(__page_symlink);
2809 EXPORT_SYMBOL(page_symlink);
2810 EXPORT_SYMBOL(page_symlink_inode_operations);
2811 EXPORT_SYMBOL(path_lookup);
2812 EXPORT_SYMBOL(path_release);
2813 EXPORT_SYMBOL(path_walk);
2814 EXPORT_SYMBOL(permission);
2815 EXPORT_SYMBOL(vfs_permission);
2816 EXPORT_SYMBOL(file_permission);
2817 EXPORT_SYMBOL(unlock_rename);
2818 EXPORT_SYMBOL(vfs_create);
2819 EXPORT_SYMBOL(vfs_follow_link);
2820 EXPORT_SYMBOL(vfs_link);
2821 EXPORT_SYMBOL(vfs_mkdir);
2822 EXPORT_SYMBOL(vfs_mknod);
2823 EXPORT_SYMBOL(generic_permission);
2824 EXPORT_SYMBOL(vfs_readlink);
2825 EXPORT_SYMBOL(vfs_rename);
2826 EXPORT_SYMBOL(vfs_rmdir);
2827 EXPORT_SYMBOL(vfs_symlink);
2828 EXPORT_SYMBOL(vfs_unlink);
2829 EXPORT_SYMBOL(dentry_unhash);
2830 EXPORT_SYMBOL(generic_readlink);