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