initial commit with v2.6.9
[linux-2.6.9-moxart.git] / fs / namei.c
blob0a7647e41d9e6060fefd1876c59eac417135355c
1 /*
2 * linux/fs/namei.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
7 /*
8 * Some corrections by tytso.
9 */
11 /* [Feb 1997 T. Schoebel-Theuer] Complete rewrite of the pathname
12 * lookup logic.
14 /* [Feb-Apr 2000, AV] Rewrite to the new namespace architecture.
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/dnotify.h>
25 #include <linux/smp_lock.h>
26 #include <linux/personality.h>
27 #include <linux/security.h>
28 #include <linux/mount.h>
29 #include <linux/audit.h>
30 #include <asm/namei.h>
31 #include <asm/uaccess.h>
33 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
35 /* [Feb-1997 T. Schoebel-Theuer]
36 * Fundamental changes in the pathname lookup mechanisms (namei)
37 * were necessary because of omirr. The reason is that omirr needs
38 * to know the _real_ pathname, not the user-supplied one, in case
39 * of symlinks (and also when transname replacements occur).
41 * The new code replaces the old recursive symlink resolution with
42 * an iterative one (in case of non-nested symlink chains). It does
43 * this with calls to <fs>_follow_link().
44 * As a side effect, dir_namei(), _namei() and follow_link() are now
45 * replaced with a single function lookup_dentry() that can handle all
46 * the special cases of the former code.
48 * With the new dcache, the pathname is stored at each inode, at least as
49 * long as the refcount of the inode is positive. As a side effect, the
50 * size of the dcache depends on the inode cache and thus is dynamic.
52 * [29-Apr-1998 C. Scott Ananian] Updated above description of symlink
53 * resolution to correspond with current state of the code.
55 * Note that the symlink resolution is not *completely* iterative.
56 * There is still a significant amount of tail- and mid- recursion in
57 * the algorithm. Also, note that <fs>_readlink() is not used in
58 * lookup_dentry(): lookup_dentry() on the result of <fs>_readlink()
59 * may return different results than <fs>_follow_link(). Many virtual
60 * filesystems (including /proc) exhibit this behavior.
63 /* [24-Feb-97 T. Schoebel-Theuer] Side effects caused by new implementation:
64 * New symlink semantics: when open() is called with flags O_CREAT | O_EXCL
65 * and the name already exists in form of a symlink, try to create the new
66 * name indicated by the symlink. The old code always complained that the
67 * name already exists, due to not following the symlink even if its target
68 * is nonexistent. The new semantics affects also mknod() and link() when
69 * the name is a symlink pointing to a non-existant name.
71 * I don't know which semantics is the right one, since I have no access
72 * to standards. But I found by trial that HP-UX 9.0 has the full "new"
73 * semantics implemented, while SunOS 4.1.1 and Solaris (SunOS 5.4) have the
74 * "old" one. Personally, I think the new semantics is much more logical.
75 * Note that "ln old new" where "new" is a symlink pointing to a non-existing
76 * file does succeed in both HP-UX and SunOs, but not in Solaris
77 * and in the old Linux semantics.
80 /* [16-Dec-97 Kevin Buhr] For security reasons, we change some symlink
81 * semantics. See the comments in "open_namei" and "do_link" below.
83 * [10-Sep-98 Alan Modra] Another symlink change.
86 /* [Feb-Apr 2000 AV] Complete rewrite. Rules for symlinks:
87 * inside the path - always follow.
88 * in the last component in creation/removal/renaming - never follow.
89 * if LOOKUP_FOLLOW passed - follow.
90 * if the pathname has trailing slashes - follow.
91 * otherwise - don't follow.
92 * (applied in that order).
94 * [Jun 2000 AV] Inconsistent behaviour of open() in case if flags==O_CREAT
95 * restored for 2.4. This is the last surviving part of old 4.2BSD bug.
96 * During the 2.4 we need to fix the userland stuff depending on it -
97 * hopefully we will be able to get rid of that wart in 2.5. So far only
98 * XEmacs seems to be relying on it...
101 * [Sep 2001 AV] Single-semaphore locking scheme (kudos to David Holland)
102 * implemented. Let's see if raised priority of ->s_vfs_rename_sem gives
103 * any extra contention...
106 /* In order to reduce some races, while at the same time doing additional
107 * checking and hopefully speeding things up, we copy filenames to the
108 * kernel data space before using them..
110 * POSIX.1 2.4: an empty pathname is invalid (ENOENT).
111 * PATH_MAX includes the nul terminator --RR.
113 static inline int do_getname(const char __user *filename, char *page)
115 int retval;
116 unsigned long len = PATH_MAX;
118 if ((unsigned long) filename >= TASK_SIZE) {
119 if (!segment_eq(get_fs(), KERNEL_DS))
120 return -EFAULT;
121 } else if (TASK_SIZE - (unsigned long) filename < PATH_MAX)
122 len = TASK_SIZE - (unsigned long) filename;
124 retval = strncpy_from_user((char *)page, filename, len);
125 if (retval > 0) {
126 if (retval < len)
127 return 0;
128 return -ENAMETOOLONG;
129 } else if (!retval)
130 retval = -ENOENT;
131 return retval;
134 char * getname(const char __user * filename)
136 char *tmp, *result;
138 result = ERR_PTR(-ENOMEM);
139 tmp = __getname();
140 if (tmp) {
141 int retval = do_getname(filename, tmp);
143 result = tmp;
144 if (retval < 0) {
145 __putname(tmp);
146 result = ERR_PTR(retval);
149 if (unlikely(current->audit_context) && !IS_ERR(result) && result)
150 audit_getname(result);
151 return result;
155 * vfs_permission()
157 * is used to check for read/write/execute permissions on a file.
158 * We use "fsuid" for this, letting us set arbitrary permissions
159 * for filesystem access without changing the "normal" uids which
160 * are used for other things..
162 int vfs_permission(struct inode * inode, int mask)
164 umode_t mode = inode->i_mode;
166 if (mask & MAY_WRITE) {
168 * Nobody gets write access to a read-only fs.
170 if (IS_RDONLY(inode) &&
171 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
172 return -EROFS;
175 * Nobody gets write access to an immutable file.
177 if (IS_IMMUTABLE(inode))
178 return -EACCES;
181 if (current->fsuid == inode->i_uid)
182 mode >>= 6;
183 else if (in_group_p(inode->i_gid))
184 mode >>= 3;
187 * If the DACs are ok we don't need any capability check.
189 if (((mode & mask & (MAY_READ|MAY_WRITE|MAY_EXEC)) == mask))
190 return 0;
193 * Read/write DACs are always overridable.
194 * Executable DACs are overridable if at least one exec bit is set.
196 if (!(mask & MAY_EXEC) ||
197 (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode))
198 if (capable(CAP_DAC_OVERRIDE))
199 return 0;
202 * Searching includes executable on directories, else just read.
204 if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
205 if (capable(CAP_DAC_READ_SEARCH))
206 return 0;
208 return -EACCES;
211 int permission(struct inode * inode,int mask, struct nameidata *nd)
213 int retval;
214 int submask;
216 /* Ordinary permission routines do not understand MAY_APPEND. */
217 submask = mask & ~MAY_APPEND;
219 if (inode->i_op && inode->i_op->permission)
220 retval = inode->i_op->permission(inode, submask, nd);
221 else
222 retval = vfs_permission(inode, submask);
223 if (retval)
224 return retval;
226 return security_inode_permission(inode, mask, nd);
230 * get_write_access() gets write permission for a file.
231 * put_write_access() releases this write permission.
232 * This is used for regular files.
233 * We cannot support write (and maybe mmap read-write shared) accesses and
234 * MAP_DENYWRITE mmappings simultaneously. The i_writecount field of an inode
235 * can have the following values:
236 * 0: no writers, no VM_DENYWRITE mappings
237 * < 0: (-i_writecount) vm_area_structs with VM_DENYWRITE set exist
238 * > 0: (i_writecount) users are writing to the file.
240 * Normally we operate on that counter with atomic_{inc,dec} and it's safe
241 * except for the cases where we don't hold i_writecount yet. Then we need to
242 * use {get,deny}_write_access() - these functions check the sign and refuse
243 * to do the change if sign is wrong. Exclusion between them is provided by
244 * the inode->i_lock spinlock.
247 int get_write_access(struct inode * inode)
249 spin_lock(&inode->i_lock);
250 if (atomic_read(&inode->i_writecount) < 0) {
251 spin_unlock(&inode->i_lock);
252 return -ETXTBSY;
254 atomic_inc(&inode->i_writecount);
255 spin_unlock(&inode->i_lock);
257 return 0;
260 int deny_write_access(struct file * file)
262 struct inode *inode = file->f_dentry->d_inode;
264 spin_lock(&inode->i_lock);
265 if (atomic_read(&inode->i_writecount) > 0) {
266 spin_unlock(&inode->i_lock);
267 return -ETXTBSY;
269 atomic_dec(&inode->i_writecount);
270 spin_unlock(&inode->i_lock);
272 return 0;
275 void path_release(struct nameidata *nd)
277 dput(nd->dentry);
278 mntput(nd->mnt);
282 * umount() mustn't call path_release()/mntput() as that would clear
283 * mnt_expiry_mark
285 void path_release_on_umount(struct nameidata *nd)
287 dput(nd->dentry);
288 _mntput(nd->mnt);
292 * Internal lookup() using the new generic dcache.
293 * SMP-safe
295 static struct dentry * cached_lookup(struct dentry * parent, struct qstr * name, struct nameidata *nd)
297 struct dentry * dentry = __d_lookup(parent, name);
299 /* lockess __d_lookup may fail due to concurrent d_move()
300 * in some unrelated directory, so try with d_lookup
302 if (!dentry)
303 dentry = d_lookup(parent, name);
305 if (dentry && dentry->d_op && dentry->d_op->d_revalidate) {
306 if (!dentry->d_op->d_revalidate(dentry, nd) && !d_invalidate(dentry)) {
307 dput(dentry);
308 dentry = NULL;
311 return dentry;
315 * Short-cut version of permission(), for calling by
316 * path_walk(), when dcache lock is held. Combines parts
317 * of permission() and vfs_permission(), and tests ONLY for
318 * MAY_EXEC permission.
320 * If appropriate, check DAC only. If not appropriate, or
321 * short-cut DAC fails, then call permission() to do more
322 * complete permission check.
324 static inline int exec_permission_lite(struct inode *inode,
325 struct nameidata *nd)
327 umode_t mode = inode->i_mode;
329 if (inode->i_op && inode->i_op->permission)
330 return -EAGAIN;
332 if (current->fsuid == inode->i_uid)
333 mode >>= 6;
334 else if (in_group_p(inode->i_gid))
335 mode >>= 3;
337 if (mode & MAY_EXEC)
338 goto ok;
340 if ((inode->i_mode & S_IXUGO) && capable(CAP_DAC_OVERRIDE))
341 goto ok;
343 if (S_ISDIR(inode->i_mode) && capable(CAP_DAC_OVERRIDE))
344 goto ok;
346 if (S_ISDIR(inode->i_mode) && capable(CAP_DAC_READ_SEARCH))
347 goto ok;
349 return -EACCES;
351 return security_inode_permission(inode, MAY_EXEC, nd);
355 * This is called when everything else fails, and we actually have
356 * to go to the low-level filesystem to find out what we should do..
358 * We get the directory semaphore, and after getting that we also
359 * make sure that nobody added the entry to the dcache in the meantime..
360 * SMP-safe
362 static struct dentry * real_lookup(struct dentry * parent, struct qstr * name, struct nameidata *nd)
364 struct dentry * result;
365 struct inode *dir = parent->d_inode;
367 down(&dir->i_sem);
369 * First re-do the cached lookup just in case it was created
370 * while we waited for the directory semaphore..
372 * FIXME! This could use version numbering or similar to
373 * avoid unnecessary cache lookups.
375 * The "dcache_lock" is purely to protect the RCU list walker
376 * from concurrent renames at this point (we mustn't get false
377 * negatives from the RCU list walk here, unlike the optimistic
378 * fast walk).
380 * so doing d_lookup() (with seqlock), instead of lockfree __d_lookup
382 result = d_lookup(parent, name);
383 if (!result) {
384 struct dentry * dentry = d_alloc(parent, name);
385 result = ERR_PTR(-ENOMEM);
386 if (dentry) {
387 result = dir->i_op->lookup(dir, dentry, nd);
388 if (result)
389 dput(dentry);
390 else
391 result = dentry;
393 up(&dir->i_sem);
394 return result;
398 * Uhhuh! Nasty case: the cache was re-populated while
399 * we waited on the semaphore. Need to revalidate.
401 up(&dir->i_sem);
402 if (result->d_op && result->d_op->d_revalidate) {
403 if (!result->d_op->d_revalidate(result, nd) && !d_invalidate(result)) {
404 dput(result);
405 result = ERR_PTR(-ENOENT);
408 return result;
411 static int __emul_lookup_dentry(const char *, struct nameidata *);
413 /* SMP-safe */
414 static inline int
415 walk_init_root(const char *name, struct nameidata *nd)
417 read_lock(&current->fs->lock);
418 if (current->fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
419 nd->mnt = mntget(current->fs->altrootmnt);
420 nd->dentry = dget(current->fs->altroot);
421 read_unlock(&current->fs->lock);
422 if (__emul_lookup_dentry(name,nd))
423 return 0;
424 read_lock(&current->fs->lock);
426 nd->mnt = mntget(current->fs->rootmnt);
427 nd->dentry = dget(current->fs->root);
428 read_unlock(&current->fs->lock);
429 return 1;
432 static inline int __vfs_follow_link(struct nameidata *nd, const char *link)
434 int res = 0;
435 char *name;
436 if (IS_ERR(link))
437 goto fail;
439 if (*link == '/') {
440 path_release(nd);
441 if (!walk_init_root(link, nd))
442 /* weird __emul_prefix() stuff did it */
443 goto out;
445 res = link_path_walk(link, nd);
446 out:
447 if (nd->depth || res || nd->last_type!=LAST_NORM)
448 return res;
450 * If it is an iterative symlinks resolution in open_namei() we
451 * have to copy the last component. And all that crap because of
452 * bloody create() on broken symlinks. Furrfu...
454 name = __getname();
455 if (unlikely(!name)) {
456 path_release(nd);
457 return -ENOMEM;
459 strcpy(name, nd->last.name);
460 nd->last.name = name;
461 return 0;
462 fail:
463 path_release(nd);
464 return PTR_ERR(link);
468 * This limits recursive symlink follows to 8, while
469 * limiting consecutive symlinks to 40.
471 * Without that kind of total limit, nasty chains of consecutive
472 * symlinks can cause almost arbitrarily long lookups.
474 static inline int do_follow_link(struct dentry *dentry, struct nameidata *nd)
476 int err = -ELOOP;
477 if (current->link_count >= MAX_NESTED_LINKS)
478 goto loop;
479 if (current->total_link_count >= 40)
480 goto loop;
481 BUG_ON(nd->depth >= MAX_NESTED_LINKS);
482 cond_resched();
483 err = security_inode_follow_link(dentry, nd);
484 if (err)
485 goto loop;
486 current->link_count++;
487 current->total_link_count++;
488 nd->depth++;
489 touch_atime(nd->mnt, dentry);
490 nd_set_link(nd, NULL);
491 err = dentry->d_inode->i_op->follow_link(dentry, nd);
492 if (!err) {
493 char *s = nd_get_link(nd);
494 if (s)
495 err = __vfs_follow_link(nd, s);
496 if (dentry->d_inode->i_op->put_link)
497 dentry->d_inode->i_op->put_link(dentry, nd);
499 current->link_count--;
500 nd->depth--;
501 return err;
502 loop:
503 path_release(nd);
504 return err;
507 int follow_up(struct vfsmount **mnt, struct dentry **dentry)
509 struct vfsmount *parent;
510 struct dentry *mountpoint;
511 spin_lock(&vfsmount_lock);
512 parent=(*mnt)->mnt_parent;
513 if (parent == *mnt) {
514 spin_unlock(&vfsmount_lock);
515 return 0;
517 mntget(parent);
518 mountpoint=dget((*mnt)->mnt_mountpoint);
519 spin_unlock(&vfsmount_lock);
520 dput(*dentry);
521 *dentry = mountpoint;
522 mntput(*mnt);
523 *mnt = parent;
524 return 1;
527 /* no need for dcache_lock, as serialization is taken care in
528 * namespace.c
530 static int follow_mount(struct vfsmount **mnt, struct dentry **dentry)
532 int res = 0;
533 while (d_mountpoint(*dentry)) {
534 struct vfsmount *mounted = lookup_mnt(*mnt, *dentry);
535 if (!mounted)
536 break;
537 mntput(*mnt);
538 *mnt = mounted;
539 dput(*dentry);
540 *dentry = dget(mounted->mnt_root);
541 res = 1;
543 return res;
546 /* no need for dcache_lock, as serialization is taken care in
547 * namespace.c
549 static inline int __follow_down(struct vfsmount **mnt, struct dentry **dentry)
551 struct vfsmount *mounted;
553 mounted = lookup_mnt(*mnt, *dentry);
554 if (mounted) {
555 mntput(*mnt);
556 *mnt = mounted;
557 dput(*dentry);
558 *dentry = dget(mounted->mnt_root);
559 return 1;
561 return 0;
564 int follow_down(struct vfsmount **mnt, struct dentry **dentry)
566 return __follow_down(mnt,dentry);
569 static inline void follow_dotdot(struct vfsmount **mnt, struct dentry **dentry)
571 while(1) {
572 struct vfsmount *parent;
573 struct dentry *old = *dentry;
575 read_lock(&current->fs->lock);
576 if (*dentry == current->fs->root &&
577 *mnt == current->fs->rootmnt) {
578 read_unlock(&current->fs->lock);
579 break;
581 read_unlock(&current->fs->lock);
582 spin_lock(&dcache_lock);
583 if (*dentry != (*mnt)->mnt_root) {
584 *dentry = dget((*dentry)->d_parent);
585 spin_unlock(&dcache_lock);
586 dput(old);
587 break;
589 spin_unlock(&dcache_lock);
590 spin_lock(&vfsmount_lock);
591 parent = (*mnt)->mnt_parent;
592 if (parent == *mnt) {
593 spin_unlock(&vfsmount_lock);
594 break;
596 mntget(parent);
597 *dentry = dget((*mnt)->mnt_mountpoint);
598 spin_unlock(&vfsmount_lock);
599 dput(old);
600 mntput(*mnt);
601 *mnt = parent;
603 follow_mount(mnt, dentry);
606 struct path {
607 struct vfsmount *mnt;
608 struct dentry *dentry;
612 * It's more convoluted than I'd like it to be, but... it's still fairly
613 * small and for now I'd prefer to have fast path as straight as possible.
614 * It _is_ time-critical.
616 static int do_lookup(struct nameidata *nd, struct qstr *name,
617 struct path *path)
619 struct vfsmount *mnt = nd->mnt;
620 struct dentry *dentry = __d_lookup(nd->dentry, name);
622 if (!dentry)
623 goto need_lookup;
624 if (dentry->d_op && dentry->d_op->d_revalidate)
625 goto need_revalidate;
626 done:
627 path->mnt = mnt;
628 path->dentry = dentry;
629 return 0;
631 need_lookup:
632 dentry = real_lookup(nd->dentry, name, nd);
633 if (IS_ERR(dentry))
634 goto fail;
635 goto done;
637 need_revalidate:
638 if (dentry->d_op->d_revalidate(dentry, nd))
639 goto done;
640 if (d_invalidate(dentry))
641 goto done;
642 dput(dentry);
643 goto need_lookup;
645 fail:
646 return PTR_ERR(dentry);
650 * Name resolution.
652 * This is the basic name resolution function, turning a pathname
653 * into the final dentry.
655 * We expect 'base' to be positive and a directory.
657 int fastcall link_path_walk(const char * name, struct nameidata *nd)
659 struct path next;
660 struct inode *inode;
661 int err;
662 unsigned int lookup_flags = nd->flags;
664 while (*name=='/')
665 name++;
666 if (!*name)
667 goto return_reval;
669 inode = nd->dentry->d_inode;
670 if (nd->depth)
671 lookup_flags = LOOKUP_FOLLOW;
673 /* At this point we know we have a real path component. */
674 for(;;) {
675 unsigned long hash;
676 struct qstr this;
677 unsigned int c;
679 err = exec_permission_lite(inode, nd);
680 if (err == -EAGAIN) {
681 err = permission(inode, MAY_EXEC, nd);
683 if (err)
684 break;
686 this.name = name;
687 c = *(const unsigned char *)name;
689 hash = init_name_hash();
690 do {
691 name++;
692 hash = partial_name_hash(c, hash);
693 c = *(const unsigned char *)name;
694 } while (c && (c != '/'));
695 this.len = name - (const char *) this.name;
696 this.hash = end_name_hash(hash);
698 /* remove trailing slashes? */
699 if (!c)
700 goto last_component;
701 while (*++name == '/');
702 if (!*name)
703 goto last_with_slashes;
706 * "." and ".." are special - ".." especially so because it has
707 * to be able to know about the current root directory and
708 * parent relationships.
710 if (this.name[0] == '.') switch (this.len) {
711 default:
712 break;
713 case 2:
714 if (this.name[1] != '.')
715 break;
716 follow_dotdot(&nd->mnt, &nd->dentry);
717 inode = nd->dentry->d_inode;
718 /* fallthrough */
719 case 1:
720 continue;
723 * See if the low-level filesystem might want
724 * to use its own hash..
726 if (nd->dentry->d_op && nd->dentry->d_op->d_hash) {
727 err = nd->dentry->d_op->d_hash(nd->dentry, &this);
728 if (err < 0)
729 break;
731 nd->flags |= LOOKUP_CONTINUE;
732 /* This does the actual lookups.. */
733 err = do_lookup(nd, &this, &next);
734 if (err)
735 break;
736 /* Check mountpoints.. */
737 follow_mount(&next.mnt, &next.dentry);
739 err = -ENOENT;
740 inode = next.dentry->d_inode;
741 if (!inode)
742 goto out_dput;
743 err = -ENOTDIR;
744 if (!inode->i_op)
745 goto out_dput;
747 if (inode->i_op->follow_link) {
748 mntget(next.mnt);
749 err = do_follow_link(next.dentry, nd);
750 dput(next.dentry);
751 mntput(next.mnt);
752 if (err)
753 goto return_err;
754 err = -ENOENT;
755 inode = nd->dentry->d_inode;
756 if (!inode)
757 break;
758 err = -ENOTDIR;
759 if (!inode->i_op)
760 break;
761 } else {
762 dput(nd->dentry);
763 nd->mnt = next.mnt;
764 nd->dentry = next.dentry;
766 err = -ENOTDIR;
767 if (!inode->i_op->lookup)
768 break;
769 continue;
770 /* here ends the main loop */
772 last_with_slashes:
773 lookup_flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
774 last_component:
775 nd->flags &= ~LOOKUP_CONTINUE;
776 if (lookup_flags & LOOKUP_PARENT)
777 goto lookup_parent;
778 if (this.name[0] == '.') switch (this.len) {
779 default:
780 break;
781 case 2:
782 if (this.name[1] != '.')
783 break;
784 follow_dotdot(&nd->mnt, &nd->dentry);
785 inode = nd->dentry->d_inode;
786 /* fallthrough */
787 case 1:
788 goto return_reval;
790 if (nd->dentry->d_op && nd->dentry->d_op->d_hash) {
791 err = nd->dentry->d_op->d_hash(nd->dentry, &this);
792 if (err < 0)
793 break;
795 err = do_lookup(nd, &this, &next);
796 if (err)
797 break;
798 follow_mount(&next.mnt, &next.dentry);
799 inode = next.dentry->d_inode;
800 if ((lookup_flags & LOOKUP_FOLLOW)
801 && inode && inode->i_op && inode->i_op->follow_link) {
802 mntget(next.mnt);
803 err = do_follow_link(next.dentry, nd);
804 dput(next.dentry);
805 mntput(next.mnt);
806 if (err)
807 goto return_err;
808 inode = nd->dentry->d_inode;
809 } else {
810 dput(nd->dentry);
811 nd->mnt = next.mnt;
812 nd->dentry = next.dentry;
814 err = -ENOENT;
815 if (!inode)
816 break;
817 if (lookup_flags & LOOKUP_DIRECTORY) {
818 err = -ENOTDIR;
819 if (!inode->i_op || !inode->i_op->lookup)
820 break;
822 goto return_base;
823 lookup_parent:
824 nd->last = this;
825 nd->last_type = LAST_NORM;
826 if (this.name[0] != '.')
827 goto return_base;
828 if (this.len == 1)
829 nd->last_type = LAST_DOT;
830 else if (this.len == 2 && this.name[1] == '.')
831 nd->last_type = LAST_DOTDOT;
832 else
833 goto return_base;
834 return_reval:
836 * We bypassed the ordinary revalidation routines.
837 * We may need to check the cached dentry for staleness.
839 if (nd->dentry && nd->dentry->d_sb &&
840 (nd->dentry->d_sb->s_type->fs_flags & FS_REVAL_DOT)) {
841 err = -ESTALE;
842 /* Note: we do not d_invalidate() */
843 if (!nd->dentry->d_op->d_revalidate(nd->dentry, nd))
844 break;
846 return_base:
847 return 0;
848 out_dput:
849 dput(next.dentry);
850 break;
852 path_release(nd);
853 return_err:
854 return err;
857 int fastcall path_walk(const char * name, struct nameidata *nd)
859 current->total_link_count = 0;
860 return link_path_walk(name, nd);
863 /* SMP-safe */
864 /* returns 1 if everything is done */
865 static int __emul_lookup_dentry(const char *name, struct nameidata *nd)
867 if (path_walk(name, nd))
868 return 0; /* something went wrong... */
870 if (!nd->dentry->d_inode || S_ISDIR(nd->dentry->d_inode->i_mode)) {
871 struct dentry *old_dentry = nd->dentry;
872 struct vfsmount *old_mnt = nd->mnt;
873 struct qstr last = nd->last;
874 int last_type = nd->last_type;
876 * NAME was not found in alternate root or it's a directory. Try to find
877 * it in the normal root:
879 nd->last_type = LAST_ROOT;
880 read_lock(&current->fs->lock);
881 nd->mnt = mntget(current->fs->rootmnt);
882 nd->dentry = dget(current->fs->root);
883 read_unlock(&current->fs->lock);
884 if (path_walk(name, nd) == 0) {
885 if (nd->dentry->d_inode) {
886 dput(old_dentry);
887 mntput(old_mnt);
888 return 1;
890 path_release(nd);
892 nd->dentry = old_dentry;
893 nd->mnt = old_mnt;
894 nd->last = last;
895 nd->last_type = last_type;
897 return 1;
900 void set_fs_altroot(void)
902 char *emul = __emul_prefix();
903 struct nameidata nd;
904 struct vfsmount *mnt = NULL, *oldmnt;
905 struct dentry *dentry = NULL, *olddentry;
906 int err;
908 if (!emul)
909 goto set_it;
910 err = path_lookup(emul, LOOKUP_FOLLOW|LOOKUP_DIRECTORY|LOOKUP_NOALT, &nd);
911 if (!err) {
912 mnt = nd.mnt;
913 dentry = nd.dentry;
915 set_it:
916 write_lock(&current->fs->lock);
917 oldmnt = current->fs->altrootmnt;
918 olddentry = current->fs->altroot;
919 current->fs->altrootmnt = mnt;
920 current->fs->altroot = dentry;
921 write_unlock(&current->fs->lock);
922 if (olddentry) {
923 dput(olddentry);
924 mntput(oldmnt);
928 int fastcall path_lookup(const char *name, unsigned int flags, struct nameidata *nd)
930 int retval;
932 nd->last_type = LAST_ROOT; /* if there are only slashes... */
933 nd->flags = flags;
934 nd->depth = 0;
936 read_lock(&current->fs->lock);
937 if (*name=='/') {
938 if (current->fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
939 nd->mnt = mntget(current->fs->altrootmnt);
940 nd->dentry = dget(current->fs->altroot);
941 read_unlock(&current->fs->lock);
942 if (__emul_lookup_dentry(name,nd))
943 return 0;
944 read_lock(&current->fs->lock);
946 nd->mnt = mntget(current->fs->rootmnt);
947 nd->dentry = dget(current->fs->root);
948 } else {
949 nd->mnt = mntget(current->fs->pwdmnt);
950 nd->dentry = dget(current->fs->pwd);
952 read_unlock(&current->fs->lock);
953 current->total_link_count = 0;
954 retval = link_path_walk(name, nd);
955 if (unlikely(current->audit_context
956 && nd && nd->dentry && nd->dentry->d_inode))
957 audit_inode(name,
958 nd->dentry->d_inode->i_ino,
959 nd->dentry->d_inode->i_rdev);
960 return retval;
964 * Restricted form of lookup. Doesn't follow links, single-component only,
965 * needs parent already locked. Doesn't follow mounts.
966 * SMP-safe.
968 static struct dentry * __lookup_hash(struct qstr *name, struct dentry * base, struct nameidata *nd)
970 struct dentry * dentry;
971 struct inode *inode;
972 int err;
974 inode = base->d_inode;
975 err = permission(inode, MAY_EXEC, nd);
976 dentry = ERR_PTR(err);
977 if (err)
978 goto out;
981 * See if the low-level filesystem might want
982 * to use its own hash..
984 if (base->d_op && base->d_op->d_hash) {
985 err = base->d_op->d_hash(base, name);
986 dentry = ERR_PTR(err);
987 if (err < 0)
988 goto out;
991 dentry = cached_lookup(base, name, nd);
992 if (!dentry) {
993 struct dentry *new = d_alloc(base, name);
994 dentry = ERR_PTR(-ENOMEM);
995 if (!new)
996 goto out;
997 dentry = inode->i_op->lookup(inode, new, nd);
998 if (!dentry)
999 dentry = new;
1000 else
1001 dput(new);
1003 out:
1004 return dentry;
1007 struct dentry * lookup_hash(struct qstr *name, struct dentry * base)
1009 return __lookup_hash(name, base, NULL);
1012 /* SMP-safe */
1013 struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
1015 unsigned long hash;
1016 struct qstr this;
1017 unsigned int c;
1019 this.name = name;
1020 this.len = len;
1021 if (!len)
1022 goto access;
1024 hash = init_name_hash();
1025 while (len--) {
1026 c = *(const unsigned char *)name++;
1027 if (c == '/' || c == '\0')
1028 goto access;
1029 hash = partial_name_hash(c, hash);
1031 this.hash = end_name_hash(hash);
1033 return lookup_hash(&this, base);
1034 access:
1035 return ERR_PTR(-EACCES);
1039 * namei()
1041 * is used by most simple commands to get the inode of a specified name.
1042 * Open, link etc use their own routines, but this is enough for things
1043 * like 'chmod' etc.
1045 * namei exists in two versions: namei/lnamei. The only difference is
1046 * that namei follows links, while lnamei does not.
1047 * SMP-safe
1049 int fastcall __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
1051 char *tmp = getname(name);
1052 int err = PTR_ERR(tmp);
1054 if (!IS_ERR(tmp)) {
1055 err = path_lookup(tmp, flags, nd);
1056 putname(tmp);
1058 return err;
1062 * It's inline, so penalty for filesystems that don't use sticky bit is
1063 * minimal.
1065 static inline int check_sticky(struct inode *dir, struct inode *inode)
1067 if (!(dir->i_mode & S_ISVTX))
1068 return 0;
1069 if (inode->i_uid == current->fsuid)
1070 return 0;
1071 if (dir->i_uid == current->fsuid)
1072 return 0;
1073 return !capable(CAP_FOWNER);
1077 * Check whether we can remove a link victim from directory dir, check
1078 * whether the type of victim is right.
1079 * 1. We can't do it if dir is read-only (done in permission())
1080 * 2. We should have write and exec permissions on dir
1081 * 3. We can't remove anything from append-only dir
1082 * 4. We can't do anything with immutable dir (done in permission())
1083 * 5. If the sticky bit on dir is set we should either
1084 * a. be owner of dir, or
1085 * b. be owner of victim, or
1086 * c. have CAP_FOWNER capability
1087 * 6. If the victim is append-only or immutable we can't do antyhing with
1088 * links pointing to it.
1089 * 7. If we were asked to remove a directory and victim isn't one - ENOTDIR.
1090 * 8. If we were asked to remove a non-directory and victim isn't one - EISDIR.
1091 * 9. We can't remove a root or mountpoint.
1092 * 10. We don't allow removal of NFS sillyrenamed files; it's handled by
1093 * nfs_async_unlink().
1095 static inline int may_delete(struct inode *dir,struct dentry *victim,int isdir)
1097 int error;
1099 if (!victim->d_inode)
1100 return -ENOENT;
1102 BUG_ON(victim->d_parent->d_inode != dir);
1104 error = permission(dir,MAY_WRITE | MAY_EXEC, NULL);
1105 if (error)
1106 return error;
1107 if (IS_APPEND(dir))
1108 return -EPERM;
1109 if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
1110 IS_IMMUTABLE(victim->d_inode))
1111 return -EPERM;
1112 if (isdir) {
1113 if (!S_ISDIR(victim->d_inode->i_mode))
1114 return -ENOTDIR;
1115 if (IS_ROOT(victim))
1116 return -EBUSY;
1117 } else if (S_ISDIR(victim->d_inode->i_mode))
1118 return -EISDIR;
1119 if (IS_DEADDIR(dir))
1120 return -ENOENT;
1121 if (victim->d_flags & DCACHE_NFSFS_RENAMED)
1122 return -EBUSY;
1123 return 0;
1126 /* Check whether we can create an object with dentry child in directory
1127 * dir.
1128 * 1. We can't do it if child already exists (open has special treatment for
1129 * this case, but since we are inlined it's OK)
1130 * 2. We can't do it if dir is read-only (done in permission())
1131 * 3. We should have write and exec permissions on dir
1132 * 4. We can't do it if dir is immutable (done in permission())
1134 static inline int may_create(struct inode *dir, struct dentry *child,
1135 struct nameidata *nd)
1137 if (child->d_inode)
1138 return -EEXIST;
1139 if (IS_DEADDIR(dir))
1140 return -ENOENT;
1141 return permission(dir,MAY_WRITE | MAY_EXEC, nd);
1145 * Special case: O_CREAT|O_EXCL implies O_NOFOLLOW for security
1146 * reasons.
1148 * O_DIRECTORY translates into forcing a directory lookup.
1150 static inline int lookup_flags(unsigned int f)
1152 unsigned long retval = LOOKUP_FOLLOW;
1154 if (f & O_NOFOLLOW)
1155 retval &= ~LOOKUP_FOLLOW;
1157 if ((f & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL))
1158 retval &= ~LOOKUP_FOLLOW;
1160 if (f & O_DIRECTORY)
1161 retval |= LOOKUP_DIRECTORY;
1163 return retval;
1167 * p1 and p2 should be directories on the same fs.
1169 struct dentry *lock_rename(struct dentry *p1, struct dentry *p2)
1171 struct dentry *p;
1173 if (p1 == p2) {
1174 down(&p1->d_inode->i_sem);
1175 return NULL;
1178 down(&p1->d_inode->i_sb->s_vfs_rename_sem);
1180 for (p = p1; p->d_parent != p; p = p->d_parent) {
1181 if (p->d_parent == p2) {
1182 down(&p2->d_inode->i_sem);
1183 down(&p1->d_inode->i_sem);
1184 return p;
1188 for (p = p2; p->d_parent != p; p = p->d_parent) {
1189 if (p->d_parent == p1) {
1190 down(&p1->d_inode->i_sem);
1191 down(&p2->d_inode->i_sem);
1192 return p;
1196 down(&p1->d_inode->i_sem);
1197 down(&p2->d_inode->i_sem);
1198 return NULL;
1201 void unlock_rename(struct dentry *p1, struct dentry *p2)
1203 up(&p1->d_inode->i_sem);
1204 if (p1 != p2) {
1205 up(&p2->d_inode->i_sem);
1206 up(&p1->d_inode->i_sb->s_vfs_rename_sem);
1210 int vfs_create(struct inode *dir, struct dentry *dentry, int mode,
1211 struct nameidata *nd)
1213 int error = may_create(dir, dentry, nd);
1215 if (error)
1216 return error;
1218 if (!dir->i_op || !dir->i_op->create)
1219 return -EACCES; /* shouldn't it be ENOSYS? */
1220 mode &= S_IALLUGO;
1221 mode |= S_IFREG;
1222 error = security_inode_create(dir, dentry, mode);
1223 if (error)
1224 return error;
1225 DQUOT_INIT(dir);
1226 error = dir->i_op->create(dir, dentry, mode, nd);
1227 if (!error) {
1228 inode_dir_notify(dir, DN_CREATE);
1229 security_inode_post_create(dir, dentry, mode);
1231 return error;
1234 int may_open(struct nameidata *nd, int acc_mode, int flag)
1236 struct dentry *dentry = nd->dentry;
1237 struct inode *inode = dentry->d_inode;
1238 int error;
1240 if (!inode)
1241 return -ENOENT;
1243 if (S_ISLNK(inode->i_mode))
1244 return -ELOOP;
1246 if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE))
1247 return -EISDIR;
1249 error = permission(inode, acc_mode, nd);
1250 if (error)
1251 return error;
1254 * FIFO's, sockets and device files are special: they don't
1255 * actually live on the filesystem itself, and as such you
1256 * can write to them even if the filesystem is read-only.
1258 if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
1259 flag &= ~O_TRUNC;
1260 } else if (S_ISBLK(inode->i_mode) || S_ISCHR(inode->i_mode)) {
1261 if (nd->mnt->mnt_flags & MNT_NODEV)
1262 return -EACCES;
1264 flag &= ~O_TRUNC;
1265 } else if (IS_RDONLY(inode) && (flag & FMODE_WRITE))
1266 return -EROFS;
1268 * An append-only file must be opened in append mode for writing.
1270 if (IS_APPEND(inode)) {
1271 if ((flag & FMODE_WRITE) && !(flag & O_APPEND))
1272 return -EPERM;
1273 if (flag & O_TRUNC)
1274 return -EPERM;
1277 /* O_NOATIME can only be set by the owner or superuser */
1278 if (flag & O_NOATIME)
1279 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1280 return -EPERM;
1283 * Ensure there are no outstanding leases on the file.
1285 error = break_lease(inode, flag);
1286 if (error)
1287 return error;
1289 if (flag & O_TRUNC) {
1290 error = get_write_access(inode);
1291 if (error)
1292 return error;
1295 * Refuse to truncate files with mandatory locks held on them.
1297 error = locks_verify_locked(inode);
1298 if (!error) {
1299 DQUOT_INIT(inode);
1301 error = do_truncate(dentry, 0);
1303 put_write_access(inode);
1304 if (error)
1305 return error;
1306 } else
1307 if (flag & FMODE_WRITE)
1308 DQUOT_INIT(inode);
1310 return 0;
1314 * open_namei()
1316 * namei for open - this is in fact almost the whole open-routine.
1318 * Note that the low bits of "flag" aren't the same as in the open
1319 * system call - they are 00 - no permissions needed
1320 * 01 - read permission needed
1321 * 10 - write permission needed
1322 * 11 - read/write permissions needed
1323 * which is a lot more logical, and also allows the "no perm" needed
1324 * for symlinks (where the permissions are checked later).
1325 * SMP-safe
1327 int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd)
1329 int acc_mode, error = 0;
1330 struct dentry *dentry;
1331 struct dentry *dir;
1332 int count = 0;
1334 acc_mode = ACC_MODE(flag);
1336 /* Allow the LSM permission hook to distinguish append
1337 access from general write access. */
1338 if (flag & O_APPEND)
1339 acc_mode |= MAY_APPEND;
1341 /* Fill in the open() intent data */
1342 nd->intent.open.flags = flag;
1343 nd->intent.open.create_mode = mode;
1346 * The simplest case - just a plain lookup.
1348 if (!(flag & O_CREAT)) {
1349 error = path_lookup(pathname, lookup_flags(flag)|LOOKUP_OPEN, nd);
1350 if (error)
1351 return error;
1352 goto ok;
1356 * Create - we need to know the parent.
1358 error = path_lookup(pathname, LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, nd);
1359 if (error)
1360 return error;
1363 * We have the parent and last component. First of all, check
1364 * that we are not asked to creat(2) an obvious directory - that
1365 * will not do.
1367 error = -EISDIR;
1368 if (nd->last_type != LAST_NORM || nd->last.name[nd->last.len])
1369 goto exit;
1371 dir = nd->dentry;
1372 nd->flags &= ~LOOKUP_PARENT;
1373 down(&dir->d_inode->i_sem);
1374 dentry = __lookup_hash(&nd->last, nd->dentry, nd);
1376 do_last:
1377 error = PTR_ERR(dentry);
1378 if (IS_ERR(dentry)) {
1379 up(&dir->d_inode->i_sem);
1380 goto exit;
1383 /* Negative dentry, just create the file */
1384 if (!dentry->d_inode) {
1385 if (!IS_POSIXACL(dir->d_inode))
1386 mode &= ~current->fs->umask;
1387 error = vfs_create(dir->d_inode, dentry, mode, nd);
1388 up(&dir->d_inode->i_sem);
1389 dput(nd->dentry);
1390 nd->dentry = dentry;
1391 if (error)
1392 goto exit;
1393 /* Don't check for write permission, don't truncate */
1394 acc_mode = 0;
1395 flag &= ~O_TRUNC;
1396 goto ok;
1400 * It already exists.
1402 up(&dir->d_inode->i_sem);
1404 error = -EEXIST;
1405 if (flag & O_EXCL)
1406 goto exit_dput;
1408 if (d_mountpoint(dentry)) {
1409 error = -ELOOP;
1410 if (flag & O_NOFOLLOW)
1411 goto exit_dput;
1412 while (__follow_down(&nd->mnt,&dentry) && d_mountpoint(dentry));
1414 error = -ENOENT;
1415 if (!dentry->d_inode)
1416 goto exit_dput;
1417 if (dentry->d_inode->i_op && dentry->d_inode->i_op->follow_link)
1418 goto do_link;
1420 dput(nd->dentry);
1421 nd->dentry = dentry;
1422 error = -EISDIR;
1423 if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))
1424 goto exit;
1426 error = may_open(nd, acc_mode, flag);
1427 if (error)
1428 goto exit;
1429 return 0;
1431 exit_dput:
1432 dput(dentry);
1433 exit:
1434 path_release(nd);
1435 return error;
1437 do_link:
1438 error = -ELOOP;
1439 if (flag & O_NOFOLLOW)
1440 goto exit_dput;
1442 * This is subtle. Instead of calling do_follow_link() we do the
1443 * thing by hands. The reason is that this way we have zero link_count
1444 * and path_walk() (called from ->follow_link) honoring LOOKUP_PARENT.
1445 * After that we have the parent and last component, i.e.
1446 * we are in the same situation as after the first path_walk().
1447 * Well, almost - if the last component is normal we get its copy
1448 * stored in nd->last.name and we will have to putname() it when we
1449 * are done. Procfs-like symlinks just set LAST_BIND.
1451 nd->flags |= LOOKUP_PARENT;
1452 error = security_inode_follow_link(dentry, nd);
1453 if (error)
1454 goto exit_dput;
1455 touch_atime(nd->mnt, dentry);
1456 nd_set_link(nd, NULL);
1457 error = dentry->d_inode->i_op->follow_link(dentry, nd);
1458 if (!error) {
1459 char *s = nd_get_link(nd);
1460 if (s)
1461 error = __vfs_follow_link(nd, s);
1462 if (dentry->d_inode->i_op->put_link)
1463 dentry->d_inode->i_op->put_link(dentry, nd);
1465 dput(dentry);
1466 if (error)
1467 return error;
1468 nd->flags &= ~LOOKUP_PARENT;
1469 if (nd->last_type == LAST_BIND) {
1470 dentry = nd->dentry;
1471 goto ok;
1473 error = -EISDIR;
1474 if (nd->last_type != LAST_NORM)
1475 goto exit;
1476 if (nd->last.name[nd->last.len]) {
1477 putname(nd->last.name);
1478 goto exit;
1480 error = -ELOOP;
1481 if (count++==32) {
1482 putname(nd->last.name);
1483 goto exit;
1485 dir = nd->dentry;
1486 down(&dir->d_inode->i_sem);
1487 dentry = __lookup_hash(&nd->last, nd->dentry, nd);
1488 putname(nd->last.name);
1489 goto do_last;
1493 * lookup_create - lookup a dentry, creating it if it doesn't exist
1494 * @nd: nameidata info
1495 * @is_dir: directory flag
1497 * Simple function to lookup and return a dentry and create it
1498 * if it doesn't exist. Is SMP-safe.
1500 struct dentry *lookup_create(struct nameidata *nd, int is_dir)
1502 struct dentry *dentry;
1504 down(&nd->dentry->d_inode->i_sem);
1505 dentry = ERR_PTR(-EEXIST);
1506 if (nd->last_type != LAST_NORM)
1507 goto fail;
1508 nd->flags &= ~LOOKUP_PARENT;
1509 dentry = lookup_hash(&nd->last, nd->dentry);
1510 if (IS_ERR(dentry))
1511 goto fail;
1512 if (!is_dir && nd->last.name[nd->last.len] && !dentry->d_inode)
1513 goto enoent;
1514 return dentry;
1515 enoent:
1516 dput(dentry);
1517 dentry = ERR_PTR(-ENOENT);
1518 fail:
1519 return dentry;
1522 int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
1524 int error = may_create(dir, dentry, NULL);
1526 if (error)
1527 return error;
1529 if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
1530 return -EPERM;
1532 if (!dir->i_op || !dir->i_op->mknod)
1533 return -EPERM;
1535 error = security_inode_mknod(dir, dentry, mode, dev);
1536 if (error)
1537 return error;
1539 DQUOT_INIT(dir);
1540 error = dir->i_op->mknod(dir, dentry, mode, dev);
1541 if (!error) {
1542 inode_dir_notify(dir, DN_CREATE);
1543 security_inode_post_mknod(dir, dentry, mode, dev);
1545 return error;
1548 asmlinkage long sys_mknod(const char __user * filename, int mode, unsigned dev)
1550 int error = 0;
1551 char * tmp;
1552 struct dentry * dentry;
1553 struct nameidata nd;
1555 if (S_ISDIR(mode))
1556 return -EPERM;
1557 tmp = getname(filename);
1558 if (IS_ERR(tmp))
1559 return PTR_ERR(tmp);
1561 error = path_lookup(tmp, LOOKUP_PARENT, &nd);
1562 if (error)
1563 goto out;
1564 dentry = lookup_create(&nd, 0);
1565 error = PTR_ERR(dentry);
1567 if (!IS_POSIXACL(nd.dentry->d_inode))
1568 mode &= ~current->fs->umask;
1569 if (!IS_ERR(dentry)) {
1570 switch (mode & S_IFMT) {
1571 case 0: case S_IFREG:
1572 error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
1573 break;
1574 case S_IFCHR: case S_IFBLK:
1575 error = vfs_mknod(nd.dentry->d_inode,dentry,mode,
1576 new_decode_dev(dev));
1577 break;
1578 case S_IFIFO: case S_IFSOCK:
1579 error = vfs_mknod(nd.dentry->d_inode,dentry,mode,0);
1580 break;
1581 case S_IFDIR:
1582 error = -EPERM;
1583 break;
1584 default:
1585 error = -EINVAL;
1587 dput(dentry);
1589 up(&nd.dentry->d_inode->i_sem);
1590 path_release(&nd);
1591 out:
1592 putname(tmp);
1594 return error;
1597 int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1599 int error = may_create(dir, dentry, NULL);
1601 if (error)
1602 return error;
1604 if (!dir->i_op || !dir->i_op->mkdir)
1605 return -EPERM;
1607 mode &= (S_IRWXUGO|S_ISVTX);
1608 error = security_inode_mkdir(dir, dentry, mode);
1609 if (error)
1610 return error;
1612 DQUOT_INIT(dir);
1613 error = dir->i_op->mkdir(dir, dentry, mode);
1614 if (!error) {
1615 inode_dir_notify(dir, DN_CREATE);
1616 security_inode_post_mkdir(dir,dentry, mode);
1618 return error;
1621 asmlinkage long sys_mkdir(const char __user * pathname, int mode)
1623 int error = 0;
1624 char * tmp;
1626 tmp = getname(pathname);
1627 error = PTR_ERR(tmp);
1628 if (!IS_ERR(tmp)) {
1629 struct dentry *dentry;
1630 struct nameidata nd;
1632 error = path_lookup(tmp, LOOKUP_PARENT, &nd);
1633 if (error)
1634 goto out;
1635 dentry = lookup_create(&nd, 1);
1636 error = PTR_ERR(dentry);
1637 if (!IS_ERR(dentry)) {
1638 if (!IS_POSIXACL(nd.dentry->d_inode))
1639 mode &= ~current->fs->umask;
1640 error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
1641 dput(dentry);
1643 up(&nd.dentry->d_inode->i_sem);
1644 path_release(&nd);
1645 out:
1646 putname(tmp);
1649 return error;
1653 * We try to drop the dentry early: we should have
1654 * a usage count of 2 if we're the only user of this
1655 * dentry, and if that is true (possibly after pruning
1656 * the dcache), then we drop the dentry now.
1658 * A low-level filesystem can, if it choses, legally
1659 * do a
1661 * if (!d_unhashed(dentry))
1662 * return -EBUSY;
1664 * if it cannot handle the case of removing a directory
1665 * that is still in use by something else..
1667 void dentry_unhash(struct dentry *dentry)
1669 dget(dentry);
1670 spin_lock(&dcache_lock);
1671 switch (atomic_read(&dentry->d_count)) {
1672 default:
1673 spin_unlock(&dcache_lock);
1674 shrink_dcache_parent(dentry);
1675 spin_lock(&dcache_lock);
1676 if (atomic_read(&dentry->d_count) != 2)
1677 break;
1678 case 2:
1679 __d_drop(dentry);
1681 spin_unlock(&dcache_lock);
1684 int vfs_rmdir(struct inode *dir, struct dentry *dentry)
1686 int error = may_delete(dir, dentry, 1);
1688 if (error)
1689 return error;
1691 if (!dir->i_op || !dir->i_op->rmdir)
1692 return -EPERM;
1694 DQUOT_INIT(dir);
1696 down(&dentry->d_inode->i_sem);
1697 dentry_unhash(dentry);
1698 if (d_mountpoint(dentry))
1699 error = -EBUSY;
1700 else {
1701 error = security_inode_rmdir(dir, dentry);
1702 if (!error) {
1703 error = dir->i_op->rmdir(dir, dentry);
1704 if (!error)
1705 dentry->d_inode->i_flags |= S_DEAD;
1708 up(&dentry->d_inode->i_sem);
1709 if (!error) {
1710 inode_dir_notify(dir, DN_DELETE);
1711 d_delete(dentry);
1713 dput(dentry);
1715 return error;
1718 asmlinkage long sys_rmdir(const char __user * pathname)
1720 int error = 0;
1721 char * name;
1722 struct dentry *dentry;
1723 struct nameidata nd;
1725 name = getname(pathname);
1726 if(IS_ERR(name))
1727 return PTR_ERR(name);
1729 error = path_lookup(name, LOOKUP_PARENT, &nd);
1730 if (error)
1731 goto exit;
1733 switch(nd.last_type) {
1734 case LAST_DOTDOT:
1735 error = -ENOTEMPTY;
1736 goto exit1;
1737 case LAST_DOT:
1738 error = -EINVAL;
1739 goto exit1;
1740 case LAST_ROOT:
1741 error = -EBUSY;
1742 goto exit1;
1744 down(&nd.dentry->d_inode->i_sem);
1745 dentry = lookup_hash(&nd.last, nd.dentry);
1746 error = PTR_ERR(dentry);
1747 if (!IS_ERR(dentry)) {
1748 error = vfs_rmdir(nd.dentry->d_inode, dentry);
1749 dput(dentry);
1751 up(&nd.dentry->d_inode->i_sem);
1752 exit1:
1753 path_release(&nd);
1754 exit:
1755 putname(name);
1756 return error;
1759 int vfs_unlink(struct inode *dir, struct dentry *dentry)
1761 int error = may_delete(dir, dentry, 0);
1763 if (error)
1764 return error;
1766 if (!dir->i_op || !dir->i_op->unlink)
1767 return -EPERM;
1769 DQUOT_INIT(dir);
1771 down(&dentry->d_inode->i_sem);
1772 if (d_mountpoint(dentry))
1773 error = -EBUSY;
1774 else {
1775 error = security_inode_unlink(dir, dentry);
1776 if (!error)
1777 error = dir->i_op->unlink(dir, dentry);
1779 up(&dentry->d_inode->i_sem);
1781 /* We don't d_delete() NFS sillyrenamed files--they still exist. */
1782 if (!error && !(dentry->d_flags & DCACHE_NFSFS_RENAMED)) {
1783 d_delete(dentry);
1784 inode_dir_notify(dir, DN_DELETE);
1786 return error;
1790 * Make sure that the actual truncation of the file will occur outside its
1791 * directory's i_sem. Truncate can take a long time if there is a lot of
1792 * writeout happening, and we don't want to prevent access to the directory
1793 * while waiting on the I/O.
1795 asmlinkage long sys_unlink(const char __user * pathname)
1797 int error = 0;
1798 char * name;
1799 struct dentry *dentry;
1800 struct nameidata nd;
1801 struct inode *inode = NULL;
1803 name = getname(pathname);
1804 if(IS_ERR(name))
1805 return PTR_ERR(name);
1807 error = path_lookup(name, LOOKUP_PARENT, &nd);
1808 if (error)
1809 goto exit;
1810 error = -EISDIR;
1811 if (nd.last_type != LAST_NORM)
1812 goto exit1;
1813 down(&nd.dentry->d_inode->i_sem);
1814 dentry = lookup_hash(&nd.last, nd.dentry);
1815 error = PTR_ERR(dentry);
1816 if (!IS_ERR(dentry)) {
1817 /* Why not before? Because we want correct error value */
1818 if (nd.last.name[nd.last.len])
1819 goto slashes;
1820 inode = dentry->d_inode;
1821 if (inode)
1822 atomic_inc(&inode->i_count);
1823 error = vfs_unlink(nd.dentry->d_inode, dentry);
1824 exit2:
1825 dput(dentry);
1827 up(&nd.dentry->d_inode->i_sem);
1828 if (inode)
1829 iput(inode); /* truncate the inode here */
1830 exit1:
1831 path_release(&nd);
1832 exit:
1833 putname(name);
1834 return error;
1836 slashes:
1837 error = !dentry->d_inode ? -ENOENT :
1838 S_ISDIR(dentry->d_inode->i_mode) ? -EISDIR : -ENOTDIR;
1839 goto exit2;
1842 int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname, int mode)
1844 int error = may_create(dir, dentry, NULL);
1846 if (error)
1847 return error;
1849 if (!dir->i_op || !dir->i_op->symlink)
1850 return -EPERM;
1852 error = security_inode_symlink(dir, dentry, oldname);
1853 if (error)
1854 return error;
1856 DQUOT_INIT(dir);
1857 error = dir->i_op->symlink(dir, dentry, oldname);
1858 if (!error) {
1859 inode_dir_notify(dir, DN_CREATE);
1860 security_inode_post_symlink(dir, dentry, oldname);
1862 return error;
1865 asmlinkage long sys_symlink(const char __user * oldname, const char __user * newname)
1867 int error = 0;
1868 char * from;
1869 char * to;
1871 from = getname(oldname);
1872 if(IS_ERR(from))
1873 return PTR_ERR(from);
1874 to = getname(newname);
1875 error = PTR_ERR(to);
1876 if (!IS_ERR(to)) {
1877 struct dentry *dentry;
1878 struct nameidata nd;
1880 error = path_lookup(to, LOOKUP_PARENT, &nd);
1881 if (error)
1882 goto out;
1883 dentry = lookup_create(&nd, 0);
1884 error = PTR_ERR(dentry);
1885 if (!IS_ERR(dentry)) {
1886 error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
1887 dput(dentry);
1889 up(&nd.dentry->d_inode->i_sem);
1890 path_release(&nd);
1891 out:
1892 putname(to);
1894 putname(from);
1895 return error;
1898 int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
1900 struct inode *inode = old_dentry->d_inode;
1901 int error;
1903 if (!inode)
1904 return -ENOENT;
1906 error = may_create(dir, new_dentry, NULL);
1907 if (error)
1908 return error;
1910 if (dir->i_sb != inode->i_sb)
1911 return -EXDEV;
1914 * A link to an append-only or immutable file cannot be created.
1916 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1917 return -EPERM;
1918 if (!dir->i_op || !dir->i_op->link)
1919 return -EPERM;
1920 if (S_ISDIR(old_dentry->d_inode->i_mode))
1921 return -EPERM;
1923 error = security_inode_link(old_dentry, dir, new_dentry);
1924 if (error)
1925 return error;
1927 down(&old_dentry->d_inode->i_sem);
1928 DQUOT_INIT(dir);
1929 error = dir->i_op->link(old_dentry, dir, new_dentry);
1930 up(&old_dentry->d_inode->i_sem);
1931 if (!error) {
1932 inode_dir_notify(dir, DN_CREATE);
1933 security_inode_post_link(old_dentry, dir, new_dentry);
1935 return error;
1939 * Hardlinks are often used in delicate situations. We avoid
1940 * security-related surprises by not following symlinks on the
1941 * newname. --KAB
1943 * We don't follow them on the oldname either to be compatible
1944 * with linux 2.0, and to avoid hard-linking to directories
1945 * and other special files. --ADM
1947 asmlinkage long sys_link(const char __user * oldname, const char __user * newname)
1949 struct dentry *new_dentry;
1950 struct nameidata nd, old_nd;
1951 int error;
1952 char * to;
1954 to = getname(newname);
1955 if (IS_ERR(to))
1956 return PTR_ERR(to);
1958 error = __user_walk(oldname, 0, &old_nd);
1959 if (error)
1960 goto exit;
1961 error = path_lookup(to, LOOKUP_PARENT, &nd);
1962 if (error)
1963 goto out;
1964 error = -EXDEV;
1965 if (old_nd.mnt != nd.mnt)
1966 goto out_release;
1967 new_dentry = lookup_create(&nd, 0);
1968 error = PTR_ERR(new_dentry);
1969 if (!IS_ERR(new_dentry)) {
1970 error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
1971 dput(new_dentry);
1973 up(&nd.dentry->d_inode->i_sem);
1974 out_release:
1975 path_release(&nd);
1976 out:
1977 path_release(&old_nd);
1978 exit:
1979 putname(to);
1981 return error;
1985 * The worst of all namespace operations - renaming directory. "Perverted"
1986 * doesn't even start to describe it. Somebody in UCB had a heck of a trip...
1987 * Problems:
1988 * a) we can get into loop creation. Check is done in is_subdir().
1989 * b) race potential - two innocent renames can create a loop together.
1990 * That's where 4.4 screws up. Current fix: serialization on
1991 * sb->s_vfs_rename_sem. We might be more accurate, but that's another
1992 * story.
1993 * c) we have to lock _three_ objects - parents and victim (if it exists).
1994 * And that - after we got ->i_sem on parents (until then we don't know
1995 * whether the target exists). Solution: try to be smart with locking
1996 * order for inodes. We rely on the fact that tree topology may change
1997 * only under ->s_vfs_rename_sem _and_ that parent of the object we
1998 * move will be locked. Thus we can rank directories by the tree
1999 * (ancestors first) and rank all non-directories after them.
2000 * That works since everybody except rename does "lock parent, lookup,
2001 * lock child" and rename is under ->s_vfs_rename_sem.
2002 * HOWEVER, it relies on the assumption that any object with ->lookup()
2003 * has no more than 1 dentry. If "hybrid" objects will ever appear,
2004 * we'd better make sure that there's no link(2) for them.
2005 * d) some filesystems don't support opened-but-unlinked directories,
2006 * either because of layout or because they are not ready to deal with
2007 * all cases correctly. The latter will be fixed (taking this sort of
2008 * stuff into VFS), but the former is not going away. Solution: the same
2009 * trick as in rmdir().
2010 * e) conversion from fhandle to dentry may come in the wrong moment - when
2011 * we are removing the target. Solution: we will have to grab ->i_sem
2012 * in the fhandle_to_dentry code. [FIXME - current nfsfh.c relies on
2013 * ->i_sem on parents, which works but leads to some truely excessive
2014 * locking].
2016 int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
2017 struct inode *new_dir, struct dentry *new_dentry)
2019 int error = 0;
2020 struct inode *target;
2023 * If we are going to change the parent - check write permissions,
2024 * we'll need to flip '..'.
2026 if (new_dir != old_dir) {
2027 error = permission(old_dentry->d_inode, MAY_WRITE, NULL);
2028 if (error)
2029 return error;
2032 error = security_inode_rename(old_dir, old_dentry, new_dir, new_dentry);
2033 if (error)
2034 return error;
2036 target = new_dentry->d_inode;
2037 if (target) {
2038 down(&target->i_sem);
2039 dentry_unhash(new_dentry);
2041 if (d_mountpoint(old_dentry)||d_mountpoint(new_dentry))
2042 error = -EBUSY;
2043 else
2044 error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry);
2045 if (target) {
2046 if (!error)
2047 target->i_flags |= S_DEAD;
2048 up(&target->i_sem);
2049 if (d_unhashed(new_dentry))
2050 d_rehash(new_dentry);
2051 dput(new_dentry);
2053 if (!error) {
2054 d_move(old_dentry,new_dentry);
2055 security_inode_post_rename(old_dir, old_dentry,
2056 new_dir, new_dentry);
2058 return error;
2061 int vfs_rename_other(struct inode *old_dir, struct dentry *old_dentry,
2062 struct inode *new_dir, struct dentry *new_dentry)
2064 struct inode *target;
2065 int error;
2067 error = security_inode_rename(old_dir, old_dentry, new_dir, new_dentry);
2068 if (error)
2069 return error;
2071 dget(new_dentry);
2072 target = new_dentry->d_inode;
2073 if (target)
2074 down(&target->i_sem);
2075 if (d_mountpoint(old_dentry)||d_mountpoint(new_dentry))
2076 error = -EBUSY;
2077 else
2078 error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry);
2079 if (!error) {
2080 /* The following d_move() should become unconditional */
2081 if (!(old_dir->i_sb->s_type->fs_flags & FS_ODD_RENAME))
2082 d_move(old_dentry, new_dentry);
2083 security_inode_post_rename(old_dir, old_dentry, new_dir, new_dentry);
2085 if (target)
2086 up(&target->i_sem);
2087 dput(new_dentry);
2088 return error;
2091 int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
2092 struct inode *new_dir, struct dentry *new_dentry)
2094 int error;
2095 int is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
2097 if (old_dentry->d_inode == new_dentry->d_inode)
2098 return 0;
2100 error = may_delete(old_dir, old_dentry, is_dir);
2101 if (error)
2102 return error;
2104 if (!new_dentry->d_inode)
2105 error = may_create(new_dir, new_dentry, NULL);
2106 else
2107 error = may_delete(new_dir, new_dentry, is_dir);
2108 if (error)
2109 return error;
2111 if (!old_dir->i_op || !old_dir->i_op->rename)
2112 return -EPERM;
2114 DQUOT_INIT(old_dir);
2115 DQUOT_INIT(new_dir);
2117 if (is_dir)
2118 error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry);
2119 else
2120 error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
2121 if (!error) {
2122 if (old_dir == new_dir)
2123 inode_dir_notify(old_dir, DN_RENAME);
2124 else {
2125 inode_dir_notify(old_dir, DN_DELETE);
2126 inode_dir_notify(new_dir, DN_CREATE);
2129 return error;
2132 static inline int do_rename(const char * oldname, const char * newname)
2134 int error = 0;
2135 struct dentry * old_dir, * new_dir;
2136 struct dentry * old_dentry, *new_dentry;
2137 struct dentry * trap;
2138 struct nameidata oldnd, newnd;
2140 error = path_lookup(oldname, LOOKUP_PARENT, &oldnd);
2141 if (error)
2142 goto exit;
2144 error = path_lookup(newname, LOOKUP_PARENT, &newnd);
2145 if (error)
2146 goto exit1;
2148 error = -EXDEV;
2149 if (oldnd.mnt != newnd.mnt)
2150 goto exit2;
2152 old_dir = oldnd.dentry;
2153 error = -EBUSY;
2154 if (oldnd.last_type != LAST_NORM)
2155 goto exit2;
2157 new_dir = newnd.dentry;
2158 if (newnd.last_type != LAST_NORM)
2159 goto exit2;
2161 trap = lock_rename(new_dir, old_dir);
2163 old_dentry = lookup_hash(&oldnd.last, old_dir);
2164 error = PTR_ERR(old_dentry);
2165 if (IS_ERR(old_dentry))
2166 goto exit3;
2167 /* source must exist */
2168 error = -ENOENT;
2169 if (!old_dentry->d_inode)
2170 goto exit4;
2171 /* unless the source is a directory trailing slashes give -ENOTDIR */
2172 if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
2173 error = -ENOTDIR;
2174 if (oldnd.last.name[oldnd.last.len])
2175 goto exit4;
2176 if (newnd.last.name[newnd.last.len])
2177 goto exit4;
2179 /* source should not be ancestor of target */
2180 error = -EINVAL;
2181 if (old_dentry == trap)
2182 goto exit4;
2183 new_dentry = lookup_hash(&newnd.last, new_dir);
2184 error = PTR_ERR(new_dentry);
2185 if (IS_ERR(new_dentry))
2186 goto exit4;
2187 /* target should not be an ancestor of source */
2188 error = -ENOTEMPTY;
2189 if (new_dentry == trap)
2190 goto exit5;
2192 error = vfs_rename(old_dir->d_inode, old_dentry,
2193 new_dir->d_inode, new_dentry);
2194 exit5:
2195 dput(new_dentry);
2196 exit4:
2197 dput(old_dentry);
2198 exit3:
2199 unlock_rename(new_dir, old_dir);
2200 exit2:
2201 path_release(&newnd);
2202 exit1:
2203 path_release(&oldnd);
2204 exit:
2205 return error;
2208 asmlinkage long sys_rename(const char __user * oldname, const char __user * newname)
2210 int error;
2211 char * from;
2212 char * to;
2214 from = getname(oldname);
2215 if(IS_ERR(from))
2216 return PTR_ERR(from);
2217 to = getname(newname);
2218 error = PTR_ERR(to);
2219 if (!IS_ERR(to)) {
2220 error = do_rename(from,to);
2221 putname(to);
2223 putname(from);
2224 return error;
2227 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
2229 int len;
2231 len = PTR_ERR(link);
2232 if (IS_ERR(link))
2233 goto out;
2235 len = strlen(link);
2236 if (len > (unsigned) buflen)
2237 len = buflen;
2238 if (copy_to_user(buffer, link, len))
2239 len = -EFAULT;
2240 out:
2241 return len;
2245 * A helper for ->readlink(). This should be used *ONLY* for symlinks that
2246 * have ->follow_link() touching nd only in nd_set_link(). Using (or not
2247 * using) it for any given inode is up to filesystem.
2249 int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)
2251 struct nameidata nd;
2252 int res;
2253 nd.depth = 0;
2254 res = dentry->d_inode->i_op->follow_link(dentry, &nd);
2255 if (!res) {
2256 res = vfs_readlink(dentry, buffer, buflen, nd_get_link(&nd));
2257 if (dentry->d_inode->i_op->put_link)
2258 dentry->d_inode->i_op->put_link(dentry, &nd);
2260 return res;
2263 int vfs_follow_link(struct nameidata *nd, const char *link)
2265 return __vfs_follow_link(nd, link);
2268 /* get the link contents into pagecache */
2269 static char *page_getlink(struct dentry * dentry, struct page **ppage)
2271 struct page * page;
2272 struct address_space *mapping = dentry->d_inode->i_mapping;
2273 page = read_cache_page(mapping, 0, (filler_t *)mapping->a_ops->readpage,
2274 NULL);
2275 if (IS_ERR(page))
2276 goto sync_fail;
2277 wait_on_page_locked(page);
2278 if (!PageUptodate(page))
2279 goto async_fail;
2280 *ppage = page;
2281 return kmap(page);
2283 async_fail:
2284 page_cache_release(page);
2285 return ERR_PTR(-EIO);
2287 sync_fail:
2288 return (char*)page;
2291 int page_readlink(struct dentry *dentry, char __user *buffer, int buflen)
2293 struct page *page = NULL;
2294 char *s = page_getlink(dentry, &page);
2295 int res = vfs_readlink(dentry,buffer,buflen,s);
2296 if (page) {
2297 kunmap(page);
2298 page_cache_release(page);
2300 return res;
2303 int page_follow_link_light(struct dentry *dentry, struct nameidata *nd)
2305 struct page *page;
2306 nd_set_link(nd, page_getlink(dentry, &page));
2307 return 0;
2310 void page_put_link(struct dentry *dentry, struct nameidata *nd)
2312 if (!IS_ERR(nd_get_link(nd))) {
2313 struct page *page;
2314 page = find_get_page(dentry->d_inode->i_mapping, 0);
2315 if (!page)
2316 BUG();
2317 kunmap(page);
2318 page_cache_release(page);
2319 page_cache_release(page);
2323 int page_follow_link(struct dentry *dentry, struct nameidata *nd)
2325 struct page *page = NULL;
2326 char *s = page_getlink(dentry, &page);
2327 int res = __vfs_follow_link(nd, s);
2328 if (page) {
2329 kunmap(page);
2330 page_cache_release(page);
2332 return res;
2335 int page_symlink(struct inode *inode, const char *symname, int len)
2337 struct address_space *mapping = inode->i_mapping;
2338 struct page *page = grab_cache_page(mapping, 0);
2339 int err = -ENOMEM;
2340 char *kaddr;
2342 if (!page)
2343 goto fail;
2344 err = mapping->a_ops->prepare_write(NULL, page, 0, len-1);
2345 if (err)
2346 goto fail_map;
2347 kaddr = kmap_atomic(page, KM_USER0);
2348 memcpy(kaddr, symname, len-1);
2349 kunmap_atomic(kaddr, KM_USER0);
2350 mapping->a_ops->commit_write(NULL, page, 0, len-1);
2352 * Notice that we are _not_ going to block here - end of page is
2353 * unmapped, so this will only try to map the rest of page, see
2354 * that it is unmapped (typically even will not look into inode -
2355 * ->i_size will be enough for everything) and zero it out.
2356 * OTOH it's obviously correct and should make the page up-to-date.
2358 if (!PageUptodate(page)) {
2359 err = mapping->a_ops->readpage(NULL, page);
2360 wait_on_page_locked(page);
2361 } else {
2362 unlock_page(page);
2364 page_cache_release(page);
2365 if (err < 0)
2366 goto fail;
2367 mark_inode_dirty(inode);
2368 return 0;
2369 fail_map:
2370 unlock_page(page);
2371 page_cache_release(page);
2372 fail:
2373 return err;
2376 struct inode_operations page_symlink_inode_operations = {
2377 .readlink = generic_readlink,
2378 .follow_link = page_follow_link_light,
2379 .put_link = page_put_link,
2382 EXPORT_SYMBOL(__user_walk);
2383 EXPORT_SYMBOL(follow_down);
2384 EXPORT_SYMBOL(follow_up);
2385 EXPORT_SYMBOL(get_write_access); /* binfmt_aout */
2386 EXPORT_SYMBOL(getname);
2387 EXPORT_SYMBOL(lock_rename);
2388 EXPORT_SYMBOL(lookup_create);
2389 EXPORT_SYMBOL(lookup_hash);
2390 EXPORT_SYMBOL(lookup_one_len);
2391 EXPORT_SYMBOL(page_follow_link);
2392 EXPORT_SYMBOL(page_follow_link_light);
2393 EXPORT_SYMBOL(page_put_link);
2394 EXPORT_SYMBOL(page_readlink);
2395 EXPORT_SYMBOL(page_symlink);
2396 EXPORT_SYMBOL(page_symlink_inode_operations);
2397 EXPORT_SYMBOL(path_lookup);
2398 EXPORT_SYMBOL(path_release);
2399 EXPORT_SYMBOL(path_walk);
2400 EXPORT_SYMBOL(permission);
2401 EXPORT_SYMBOL(unlock_rename);
2402 EXPORT_SYMBOL(vfs_create);
2403 EXPORT_SYMBOL(vfs_follow_link);
2404 EXPORT_SYMBOL(vfs_link);
2405 EXPORT_SYMBOL(vfs_mkdir);
2406 EXPORT_SYMBOL(vfs_mknod);
2407 EXPORT_SYMBOL(vfs_permission);
2408 EXPORT_SYMBOL(vfs_readlink);
2409 EXPORT_SYMBOL(vfs_rename);
2410 EXPORT_SYMBOL(vfs_rmdir);
2411 EXPORT_SYMBOL(vfs_symlink);
2412 EXPORT_SYMBOL(vfs_unlink);
2413 EXPORT_SYMBOL(dentry_unhash);
2414 EXPORT_SYMBOL(generic_readlink);