MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / fs / namei.c
blob6f6f1dd85a61190d493c1886f76ee8be5b275aef
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 #ifdef CONFIG_MMU
119 if ((unsigned long) filename >= TASK_SIZE) {
120 if (!segment_eq(get_fs(), KERNEL_DS))
121 return -EFAULT;
122 } else if (TASK_SIZE - (unsigned long) filename < PATH_MAX)
123 len = TASK_SIZE - (unsigned long) filename;
124 #endif
126 retval = strncpy_from_user((char *)page, filename, len);
127 if (retval > 0) {
128 if (retval < len)
129 return 0;
130 return -ENAMETOOLONG;
131 } else if (!retval)
132 retval = -ENOENT;
133 return retval;
136 char * getname(const char __user * filename)
138 char *tmp, *result;
140 result = ERR_PTR(-ENOMEM);
141 tmp = __getname();
142 if (tmp) {
143 int retval = do_getname(filename, tmp);
145 result = tmp;
146 if (retval < 0) {
147 __putname(tmp);
148 result = ERR_PTR(retval);
151 if (unlikely(current->audit_context) && !IS_ERR(result) && result)
152 audit_getname(result);
153 return result;
157 * vfs_permission()
159 * is used to check for read/write/execute permissions on a file.
160 * We use "fsuid" for this, letting us set arbitrary permissions
161 * for filesystem access without changing the "normal" uids which
162 * are used for other things..
164 int vfs_permission(struct inode * inode, int mask)
166 umode_t mode = inode->i_mode;
168 if (mask & MAY_WRITE) {
170 * Nobody gets write access to a read-only fs.
172 if (IS_RDONLY(inode) &&
173 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
174 return -EROFS;
177 * Nobody gets write access to an immutable file.
179 if (IS_IMMUTABLE(inode))
180 return -EACCES;
183 if (current->fsuid == inode->i_uid)
184 mode >>= 6;
185 else if (in_group_p(inode->i_gid))
186 mode >>= 3;
189 * If the DACs are ok we don't need any capability check.
191 if (((mode & mask & (MAY_READ|MAY_WRITE|MAY_EXEC)) == mask))
192 return 0;
195 * Read/write DACs are always overridable.
196 * Executable DACs are overridable if at least one exec bit is set.
198 if (!(mask & MAY_EXEC) ||
199 (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode))
200 if (capable(CAP_DAC_OVERRIDE))
201 return 0;
204 * Searching includes executable on directories, else just read.
206 if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
207 if (capable(CAP_DAC_READ_SEARCH))
208 return 0;
210 return -EACCES;
213 int permission(struct inode * inode,int mask, struct nameidata *nd)
215 int retval;
216 int submask;
218 /* Ordinary permission routines do not understand MAY_APPEND. */
219 submask = mask & ~MAY_APPEND;
221 if (inode->i_op && inode->i_op->permission)
222 retval = inode->i_op->permission(inode, submask, nd);
223 else
224 retval = vfs_permission(inode, submask);
225 if (retval)
226 return retval;
228 return security_inode_permission(inode, mask, nd);
232 * get_write_access() gets write permission for a file.
233 * put_write_access() releases this write permission.
234 * This is used for regular files.
235 * We cannot support write (and maybe mmap read-write shared) accesses and
236 * MAP_DENYWRITE mmappings simultaneously. The i_writecount field of an inode
237 * can have the following values:
238 * 0: no writers, no VM_DENYWRITE mappings
239 * < 0: (-i_writecount) vm_area_structs with VM_DENYWRITE set exist
240 * > 0: (i_writecount) users are writing to the file.
242 * Normally we operate on that counter with atomic_{inc,dec} and it's safe
243 * except for the cases where we don't hold i_writecount yet. Then we need to
244 * use {get,deny}_write_access() - these functions check the sign and refuse
245 * to do the change if sign is wrong. Exclusion between them is provided by
246 * the inode->i_lock spinlock.
249 int get_write_access(struct inode * inode)
251 spin_lock(&inode->i_lock);
252 if (atomic_read(&inode->i_writecount) < 0) {
253 spin_unlock(&inode->i_lock);
254 return -ETXTBSY;
256 atomic_inc(&inode->i_writecount);
257 spin_unlock(&inode->i_lock);
259 return 0;
262 int deny_write_access(struct file * file)
264 struct inode *inode = file->f_dentry->d_inode;
266 spin_lock(&inode->i_lock);
267 if (atomic_read(&inode->i_writecount) > 0) {
268 spin_unlock(&inode->i_lock);
269 return -ETXTBSY;
271 atomic_dec(&inode->i_writecount);
272 spin_unlock(&inode->i_lock);
274 return 0;
277 void path_release(struct nameidata *nd)
279 dput(nd->dentry);
280 mntput(nd->mnt);
284 * umount() mustn't call path_release()/mntput() as that would clear
285 * mnt_expiry_mark
287 void path_release_on_umount(struct nameidata *nd)
289 dput(nd->dentry);
290 _mntput(nd->mnt);
294 * Internal lookup() using the new generic dcache.
295 * SMP-safe
297 static struct dentry * cached_lookup(struct dentry * parent, struct qstr * name, struct nameidata *nd)
299 struct dentry * dentry = __d_lookup(parent, name);
301 /* lockess __d_lookup may fail due to concurrent d_move()
302 * in some unrelated directory, so try with d_lookup
304 if (!dentry)
305 dentry = d_lookup(parent, name);
307 if (dentry && dentry->d_op && dentry->d_op->d_revalidate) {
308 if (!dentry->d_op->d_revalidate(dentry, nd) && !d_invalidate(dentry)) {
309 dput(dentry);
310 dentry = NULL;
313 return dentry;
317 * Short-cut version of permission(), for calling by
318 * path_walk(), when dcache lock is held. Combines parts
319 * of permission() and vfs_permission(), and tests ONLY for
320 * MAY_EXEC permission.
322 * If appropriate, check DAC only. If not appropriate, or
323 * short-cut DAC fails, then call permission() to do more
324 * complete permission check.
326 static inline int exec_permission_lite(struct inode *inode,
327 struct nameidata *nd)
329 umode_t mode = inode->i_mode;
331 if (inode->i_op && inode->i_op->permission)
332 return -EAGAIN;
334 if (current->fsuid == inode->i_uid)
335 mode >>= 6;
336 else if (in_group_p(inode->i_gid))
337 mode >>= 3;
339 if (mode & MAY_EXEC)
340 goto ok;
342 if ((inode->i_mode & S_IXUGO) && capable(CAP_DAC_OVERRIDE))
343 goto ok;
345 if (S_ISDIR(inode->i_mode) && capable(CAP_DAC_OVERRIDE))
346 goto ok;
348 if (S_ISDIR(inode->i_mode) && capable(CAP_DAC_READ_SEARCH))
349 goto ok;
351 return -EACCES;
353 return security_inode_permission(inode, MAY_EXEC, nd);
357 * This is called when everything else fails, and we actually have
358 * to go to the low-level filesystem to find out what we should do..
360 * We get the directory semaphore, and after getting that we also
361 * make sure that nobody added the entry to the dcache in the meantime..
362 * SMP-safe
364 static struct dentry * real_lookup(struct dentry * parent, struct qstr * name, struct nameidata *nd)
366 struct dentry * result;
367 struct inode *dir = parent->d_inode;
369 down(&dir->i_sem);
371 * First re-do the cached lookup just in case it was created
372 * while we waited for the directory semaphore..
374 * FIXME! This could use version numbering or similar to
375 * avoid unnecessary cache lookups.
377 * The "dcache_lock" is purely to protect the RCU list walker
378 * from concurrent renames at this point (we mustn't get false
379 * negatives from the RCU list walk here, unlike the optimistic
380 * fast walk).
382 * so doing d_lookup() (with seqlock), instead of lockfree __d_lookup
384 result = d_lookup(parent, name);
385 if (!result) {
386 struct dentry * dentry = d_alloc(parent, name);
387 result = ERR_PTR(-ENOMEM);
388 if (dentry) {
389 result = dir->i_op->lookup(dir, dentry, nd);
390 if (result)
391 dput(dentry);
392 else
393 result = dentry;
395 up(&dir->i_sem);
396 return result;
400 * Uhhuh! Nasty case: the cache was re-populated while
401 * we waited on the semaphore. Need to revalidate.
403 up(&dir->i_sem);
404 if (result->d_op && result->d_op->d_revalidate) {
405 if (!result->d_op->d_revalidate(result, nd) && !d_invalidate(result)) {
406 dput(result);
407 result = ERR_PTR(-ENOENT);
410 return result;
413 static int __emul_lookup_dentry(const char *, struct nameidata *);
415 /* SMP-safe */
416 static inline int
417 walk_init_root(const char *name, struct nameidata *nd)
419 read_lock(&current->fs->lock);
420 if (current->fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
421 nd->mnt = mntget(current->fs->altrootmnt);
422 nd->dentry = dget(current->fs->altroot);
423 read_unlock(&current->fs->lock);
424 if (__emul_lookup_dentry(name,nd))
425 return 0;
426 read_lock(&current->fs->lock);
428 nd->mnt = mntget(current->fs->rootmnt);
429 nd->dentry = dget(current->fs->root);
430 read_unlock(&current->fs->lock);
431 return 1;
434 static inline int __vfs_follow_link(struct nameidata *nd, const char *link)
436 int res = 0;
437 char *name;
438 if (IS_ERR(link))
439 goto fail;
441 if (*link == '/') {
442 path_release(nd);
443 if (!walk_init_root(link, nd))
444 /* weird __emul_prefix() stuff did it */
445 goto out;
447 res = link_path_walk(link, nd);
448 out:
449 if (nd->depth || res || nd->last_type!=LAST_NORM)
450 return res;
452 * If it is an iterative symlinks resolution in open_namei() we
453 * have to copy the last component. And all that crap because of
454 * bloody create() on broken symlinks. Furrfu...
456 name = __getname();
457 if (unlikely(!name)) {
458 path_release(nd);
459 return -ENOMEM;
461 strcpy(name, nd->last.name);
462 nd->last.name = name;
463 return 0;
464 fail:
465 path_release(nd);
466 return PTR_ERR(link);
470 * This limits recursive symlink follows to 8, while
471 * limiting consecutive symlinks to 40.
473 * Without that kind of total limit, nasty chains of consecutive
474 * symlinks can cause almost arbitrarily long lookups.
476 static inline int do_follow_link(struct dentry *dentry, struct nameidata *nd)
478 int err = -ELOOP;
479 if (current->link_count >= MAX_NESTED_LINKS)
480 goto loop;
481 if (current->total_link_count >= 40)
482 goto loop;
483 BUG_ON(nd->depth >= MAX_NESTED_LINKS);
484 cond_resched();
485 err = security_inode_follow_link(dentry, nd);
486 if (err)
487 goto loop;
488 current->link_count++;
489 current->total_link_count++;
490 nd->depth++;
491 touch_atime(nd->mnt, dentry);
492 nd_set_link(nd, NULL);
493 err = dentry->d_inode->i_op->follow_link(dentry, nd);
494 if (!err) {
495 char *s = nd_get_link(nd);
496 if (s)
497 err = __vfs_follow_link(nd, s);
498 if (dentry->d_inode->i_op->put_link)
499 dentry->d_inode->i_op->put_link(dentry, nd);
501 current->link_count--;
502 nd->depth--;
503 return err;
504 loop:
505 path_release(nd);
506 return err;
509 int follow_up(struct vfsmount **mnt, struct dentry **dentry)
511 struct vfsmount *parent;
512 struct dentry *mountpoint;
513 spin_lock(&vfsmount_lock);
514 parent=(*mnt)->mnt_parent;
515 if (parent == *mnt) {
516 spin_unlock(&vfsmount_lock);
517 return 0;
519 mntget(parent);
520 mountpoint=dget((*mnt)->mnt_mountpoint);
521 spin_unlock(&vfsmount_lock);
522 dput(*dentry);
523 *dentry = mountpoint;
524 mntput(*mnt);
525 *mnt = parent;
526 return 1;
529 /* no need for dcache_lock, as serialization is taken care in
530 * namespace.c
532 static int follow_mount(struct vfsmount **mnt, struct dentry **dentry)
534 int res = 0;
535 while (d_mountpoint(*dentry)) {
536 struct vfsmount *mounted = lookup_mnt(*mnt, *dentry);
537 if (!mounted)
538 break;
539 mntput(*mnt);
540 *mnt = mounted;
541 dput(*dentry);
542 *dentry = dget(mounted->mnt_root);
543 res = 1;
545 return res;
548 /* no need for dcache_lock, as serialization is taken care in
549 * namespace.c
551 static inline int __follow_down(struct vfsmount **mnt, struct dentry **dentry)
553 struct vfsmount *mounted;
555 mounted = lookup_mnt(*mnt, *dentry);
556 if (mounted) {
557 mntput(*mnt);
558 *mnt = mounted;
559 dput(*dentry);
560 *dentry = dget(mounted->mnt_root);
561 return 1;
563 return 0;
566 int follow_down(struct vfsmount **mnt, struct dentry **dentry)
568 return __follow_down(mnt,dentry);
571 static inline void follow_dotdot(struct vfsmount **mnt, struct dentry **dentry)
573 while(1) {
574 struct vfsmount *parent;
575 struct dentry *old = *dentry;
577 read_lock(&current->fs->lock);
578 if (*dentry == current->fs->root &&
579 *mnt == current->fs->rootmnt) {
580 read_unlock(&current->fs->lock);
581 break;
583 read_unlock(&current->fs->lock);
584 spin_lock(&dcache_lock);
585 if (*dentry != (*mnt)->mnt_root) {
586 *dentry = dget((*dentry)->d_parent);
587 spin_unlock(&dcache_lock);
588 dput(old);
589 break;
591 spin_unlock(&dcache_lock);
592 spin_lock(&vfsmount_lock);
593 parent = (*mnt)->mnt_parent;
594 if (parent == *mnt) {
595 spin_unlock(&vfsmount_lock);
596 break;
598 mntget(parent);
599 *dentry = dget((*mnt)->mnt_mountpoint);
600 spin_unlock(&vfsmount_lock);
601 dput(old);
602 mntput(*mnt);
603 *mnt = parent;
605 follow_mount(mnt, dentry);
608 struct path {
609 struct vfsmount *mnt;
610 struct dentry *dentry;
614 * It's more convoluted than I'd like it to be, but... it's still fairly
615 * small and for now I'd prefer to have fast path as straight as possible.
616 * It _is_ time-critical.
618 static int do_lookup(struct nameidata *nd, struct qstr *name,
619 struct path *path)
621 struct vfsmount *mnt = nd->mnt;
622 struct dentry *dentry = __d_lookup(nd->dentry, name);
624 if (!dentry)
625 goto need_lookup;
626 if (dentry->d_op && dentry->d_op->d_revalidate)
627 goto need_revalidate;
628 done:
629 path->mnt = mnt;
630 path->dentry = dentry;
631 return 0;
633 need_lookup:
634 dentry = real_lookup(nd->dentry, name, nd);
635 if (IS_ERR(dentry))
636 goto fail;
637 goto done;
639 need_revalidate:
640 if (dentry->d_op->d_revalidate(dentry, nd))
641 goto done;
642 if (d_invalidate(dentry))
643 goto done;
644 dput(dentry);
645 goto need_lookup;
647 fail:
648 return PTR_ERR(dentry);
652 * Name resolution.
654 * This is the basic name resolution function, turning a pathname
655 * into the final dentry.
657 * We expect 'base' to be positive and a directory.
659 int fastcall link_path_walk(const char * name, struct nameidata *nd)
661 struct path next;
662 struct inode *inode;
663 int err;
664 unsigned int lookup_flags = nd->flags;
666 while (*name=='/')
667 name++;
668 if (!*name)
669 goto return_reval;
671 inode = nd->dentry->d_inode;
672 if (nd->depth)
673 lookup_flags = LOOKUP_FOLLOW;
675 /* At this point we know we have a real path component. */
676 for(;;) {
677 unsigned long hash;
678 struct qstr this;
679 unsigned int c;
681 err = exec_permission_lite(inode, nd);
682 if (err == -EAGAIN) {
683 err = permission(inode, MAY_EXEC, nd);
685 if (err)
686 break;
688 this.name = name;
689 c = *(const unsigned char *)name;
691 hash = init_name_hash();
692 do {
693 name++;
694 hash = partial_name_hash(c, hash);
695 c = *(const unsigned char *)name;
696 } while (c && (c != '/'));
697 this.len = name - (const char *) this.name;
698 this.hash = end_name_hash(hash);
700 /* remove trailing slashes? */
701 if (!c)
702 goto last_component;
703 while (*++name == '/');
704 if (!*name)
705 goto last_with_slashes;
708 * "." and ".." are special - ".." especially so because it has
709 * to be able to know about the current root directory and
710 * parent relationships.
712 if (this.name[0] == '.') switch (this.len) {
713 default:
714 break;
715 case 2:
716 if (this.name[1] != '.')
717 break;
718 follow_dotdot(&nd->mnt, &nd->dentry);
719 inode = nd->dentry->d_inode;
720 /* fallthrough */
721 case 1:
722 continue;
725 * See if the low-level filesystem might want
726 * to use its own hash..
728 if (nd->dentry->d_op && nd->dentry->d_op->d_hash) {
729 err = nd->dentry->d_op->d_hash(nd->dentry, &this);
730 if (err < 0)
731 break;
733 nd->flags |= LOOKUP_CONTINUE;
734 /* This does the actual lookups.. */
735 err = do_lookup(nd, &this, &next);
736 if (err)
737 break;
738 /* Check mountpoints.. */
739 follow_mount(&next.mnt, &next.dentry);
741 err = -ENOENT;
742 inode = next.dentry->d_inode;
743 if (!inode)
744 goto out_dput;
745 err = -ENOTDIR;
746 if (!inode->i_op)
747 goto out_dput;
749 if (inode->i_op->follow_link) {
750 mntget(next.mnt);
751 err = do_follow_link(next.dentry, nd);
752 dput(next.dentry);
753 mntput(next.mnt);
754 if (err)
755 goto return_err;
756 err = -ENOENT;
757 inode = nd->dentry->d_inode;
758 if (!inode)
759 break;
760 err = -ENOTDIR;
761 if (!inode->i_op)
762 break;
763 } else {
764 dput(nd->dentry);
765 nd->mnt = next.mnt;
766 nd->dentry = next.dentry;
768 err = -ENOTDIR;
769 if (!inode->i_op->lookup)
770 break;
771 continue;
772 /* here ends the main loop */
774 last_with_slashes:
775 lookup_flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
776 last_component:
777 nd->flags &= ~LOOKUP_CONTINUE;
778 if (lookup_flags & LOOKUP_PARENT)
779 goto lookup_parent;
780 if (this.name[0] == '.') switch (this.len) {
781 default:
782 break;
783 case 2:
784 if (this.name[1] != '.')
785 break;
786 follow_dotdot(&nd->mnt, &nd->dentry);
787 inode = nd->dentry->d_inode;
788 /* fallthrough */
789 case 1:
790 goto return_reval;
792 if (nd->dentry->d_op && nd->dentry->d_op->d_hash) {
793 err = nd->dentry->d_op->d_hash(nd->dentry, &this);
794 if (err < 0)
795 break;
797 err = do_lookup(nd, &this, &next);
798 if (err)
799 break;
800 follow_mount(&next.mnt, &next.dentry);
801 inode = next.dentry->d_inode;
802 if ((lookup_flags & LOOKUP_FOLLOW)
803 && inode && inode->i_op && inode->i_op->follow_link) {
804 mntget(next.mnt);
805 err = do_follow_link(next.dentry, nd);
806 dput(next.dentry);
807 mntput(next.mnt);
808 if (err)
809 goto return_err;
810 inode = nd->dentry->d_inode;
811 } else {
812 dput(nd->dentry);
813 nd->mnt = next.mnt;
814 nd->dentry = next.dentry;
816 err = -ENOENT;
817 if (!inode)
818 break;
819 if (lookup_flags & LOOKUP_DIRECTORY) {
820 err = -ENOTDIR;
821 if (!inode->i_op || !inode->i_op->lookup)
822 break;
824 goto return_base;
825 lookup_parent:
826 nd->last = this;
827 nd->last_type = LAST_NORM;
828 if (this.name[0] != '.')
829 goto return_base;
830 if (this.len == 1)
831 nd->last_type = LAST_DOT;
832 else if (this.len == 2 && this.name[1] == '.')
833 nd->last_type = LAST_DOTDOT;
834 else
835 goto return_base;
836 return_reval:
838 * We bypassed the ordinary revalidation routines.
839 * We may need to check the cached dentry for staleness.
841 if (nd->dentry && nd->dentry->d_sb &&
842 (nd->dentry->d_sb->s_type->fs_flags & FS_REVAL_DOT)) {
843 err = -ESTALE;
844 /* Note: we do not d_invalidate() */
845 if (!nd->dentry->d_op->d_revalidate(nd->dentry, nd))
846 break;
848 return_base:
849 return 0;
850 out_dput:
851 dput(next.dentry);
852 break;
854 path_release(nd);
855 return_err:
856 return err;
859 int fastcall path_walk(const char * name, struct nameidata *nd)
861 current->total_link_count = 0;
862 return link_path_walk(name, nd);
865 /* SMP-safe */
866 /* returns 1 if everything is done */
867 static int __emul_lookup_dentry(const char *name, struct nameidata *nd)
869 if (path_walk(name, nd))
870 return 0; /* something went wrong... */
872 if (!nd->dentry->d_inode || S_ISDIR(nd->dentry->d_inode->i_mode)) {
873 struct dentry *old_dentry = nd->dentry;
874 struct vfsmount *old_mnt = nd->mnt;
875 struct qstr last = nd->last;
876 int last_type = nd->last_type;
878 * NAME was not found in alternate root or it's a directory. Try to find
879 * it in the normal root:
881 nd->last_type = LAST_ROOT;
882 read_lock(&current->fs->lock);
883 nd->mnt = mntget(current->fs->rootmnt);
884 nd->dentry = dget(current->fs->root);
885 read_unlock(&current->fs->lock);
886 if (path_walk(name, nd) == 0) {
887 if (nd->dentry->d_inode) {
888 dput(old_dentry);
889 mntput(old_mnt);
890 return 1;
892 path_release(nd);
894 nd->dentry = old_dentry;
895 nd->mnt = old_mnt;
896 nd->last = last;
897 nd->last_type = last_type;
899 return 1;
902 void set_fs_altroot(void)
904 char *emul = __emul_prefix();
905 struct nameidata nd;
906 struct vfsmount *mnt = NULL, *oldmnt;
907 struct dentry *dentry = NULL, *olddentry;
908 int err;
910 if (!emul)
911 goto set_it;
912 err = path_lookup(emul, LOOKUP_FOLLOW|LOOKUP_DIRECTORY|LOOKUP_NOALT, &nd);
913 if (!err) {
914 mnt = nd.mnt;
915 dentry = nd.dentry;
917 set_it:
918 write_lock(&current->fs->lock);
919 oldmnt = current->fs->altrootmnt;
920 olddentry = current->fs->altroot;
921 current->fs->altrootmnt = mnt;
922 current->fs->altroot = dentry;
923 write_unlock(&current->fs->lock);
924 if (olddentry) {
925 dput(olddentry);
926 mntput(oldmnt);
930 int fastcall path_lookup(const char *name, unsigned int flags, struct nameidata *nd)
932 int retval;
934 nd->last_type = LAST_ROOT; /* if there are only slashes... */
935 nd->flags = flags;
936 nd->depth = 0;
938 read_lock(&current->fs->lock);
939 if (*name=='/') {
940 if (current->fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
941 nd->mnt = mntget(current->fs->altrootmnt);
942 nd->dentry = dget(current->fs->altroot);
943 read_unlock(&current->fs->lock);
944 if (__emul_lookup_dentry(name,nd))
945 return 0;
946 read_lock(&current->fs->lock);
948 nd->mnt = mntget(current->fs->rootmnt);
949 nd->dentry = dget(current->fs->root);
950 } else {
951 nd->mnt = mntget(current->fs->pwdmnt);
952 nd->dentry = dget(current->fs->pwd);
954 read_unlock(&current->fs->lock);
955 current->total_link_count = 0;
956 retval = link_path_walk(name, nd);
957 if (unlikely(current->audit_context
958 && nd && nd->dentry && nd->dentry->d_inode))
959 audit_inode(name,
960 nd->dentry->d_inode->i_ino,
961 nd->dentry->d_inode->i_rdev);
962 return retval;
966 * Restricted form of lookup. Doesn't follow links, single-component only,
967 * needs parent already locked. Doesn't follow mounts.
968 * SMP-safe.
970 static struct dentry * __lookup_hash(struct qstr *name, struct dentry * base, struct nameidata *nd)
972 struct dentry * dentry;
973 struct inode *inode;
974 int err;
976 inode = base->d_inode;
977 err = permission(inode, MAY_EXEC, nd);
978 dentry = ERR_PTR(err);
979 if (err)
980 goto out;
983 * See if the low-level filesystem might want
984 * to use its own hash..
986 if (base->d_op && base->d_op->d_hash) {
987 err = base->d_op->d_hash(base, name);
988 dentry = ERR_PTR(err);
989 if (err < 0)
990 goto out;
993 dentry = cached_lookup(base, name, nd);
994 if (!dentry) {
995 struct dentry *new = d_alloc(base, name);
996 dentry = ERR_PTR(-ENOMEM);
997 if (!new)
998 goto out;
999 dentry = inode->i_op->lookup(inode, new, nd);
1000 if (!dentry)
1001 dentry = new;
1002 else
1003 dput(new);
1005 out:
1006 return dentry;
1009 struct dentry * lookup_hash(struct qstr *name, struct dentry * base)
1011 return __lookup_hash(name, base, NULL);
1014 /* SMP-safe */
1015 struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
1017 unsigned long hash;
1018 struct qstr this;
1019 unsigned int c;
1021 this.name = name;
1022 this.len = len;
1023 if (!len)
1024 goto access;
1026 hash = init_name_hash();
1027 while (len--) {
1028 c = *(const unsigned char *)name++;
1029 if (c == '/' || c == '\0')
1030 goto access;
1031 hash = partial_name_hash(c, hash);
1033 this.hash = end_name_hash(hash);
1035 return lookup_hash(&this, base);
1036 access:
1037 return ERR_PTR(-EACCES);
1041 * namei()
1043 * is used by most simple commands to get the inode of a specified name.
1044 * Open, link etc use their own routines, but this is enough for things
1045 * like 'chmod' etc.
1047 * namei exists in two versions: namei/lnamei. The only difference is
1048 * that namei follows links, while lnamei does not.
1049 * SMP-safe
1051 int fastcall __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
1053 char *tmp = getname(name);
1054 int err = PTR_ERR(tmp);
1056 if (!IS_ERR(tmp)) {
1057 err = path_lookup(tmp, flags, nd);
1058 putname(tmp);
1060 return err;
1064 * It's inline, so penalty for filesystems that don't use sticky bit is
1065 * minimal.
1067 static inline int check_sticky(struct inode *dir, struct inode *inode)
1069 if (!(dir->i_mode & S_ISVTX))
1070 return 0;
1071 if (inode->i_uid == current->fsuid)
1072 return 0;
1073 if (dir->i_uid == current->fsuid)
1074 return 0;
1075 return !capable(CAP_FOWNER);
1079 * Check whether we can remove a link victim from directory dir, check
1080 * whether the type of victim is right.
1081 * 1. We can't do it if dir is read-only (done in permission())
1082 * 2. We should have write and exec permissions on dir
1083 * 3. We can't remove anything from append-only dir
1084 * 4. We can't do anything with immutable dir (done in permission())
1085 * 5. If the sticky bit on dir is set we should either
1086 * a. be owner of dir, or
1087 * b. be owner of victim, or
1088 * c. have CAP_FOWNER capability
1089 * 6. If the victim is append-only or immutable we can't do antyhing with
1090 * links pointing to it.
1091 * 7. If we were asked to remove a directory and victim isn't one - ENOTDIR.
1092 * 8. If we were asked to remove a non-directory and victim isn't one - EISDIR.
1093 * 9. We can't remove a root or mountpoint.
1094 * 10. We don't allow removal of NFS sillyrenamed files; it's handled by
1095 * nfs_async_unlink().
1097 static inline int may_delete(struct inode *dir,struct dentry *victim,int isdir)
1099 int error;
1101 if (!victim->d_inode)
1102 return -ENOENT;
1104 BUG_ON(victim->d_parent->d_inode != dir);
1106 error = permission(dir,MAY_WRITE | MAY_EXEC, NULL);
1107 if (error)
1108 return error;
1109 if (IS_APPEND(dir))
1110 return -EPERM;
1111 if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
1112 IS_IMMUTABLE(victim->d_inode))
1113 return -EPERM;
1114 if (isdir) {
1115 if (!S_ISDIR(victim->d_inode->i_mode))
1116 return -ENOTDIR;
1117 if (IS_ROOT(victim))
1118 return -EBUSY;
1119 } else if (S_ISDIR(victim->d_inode->i_mode))
1120 return -EISDIR;
1121 if (IS_DEADDIR(dir))
1122 return -ENOENT;
1123 if (victim->d_flags & DCACHE_NFSFS_RENAMED)
1124 return -EBUSY;
1125 return 0;
1128 /* Check whether we can create an object with dentry child in directory
1129 * dir.
1130 * 1. We can't do it if child already exists (open has special treatment for
1131 * this case, but since we are inlined it's OK)
1132 * 2. We can't do it if dir is read-only (done in permission())
1133 * 3. We should have write and exec permissions on dir
1134 * 4. We can't do it if dir is immutable (done in permission())
1136 static inline int may_create(struct inode *dir, struct dentry *child,
1137 struct nameidata *nd)
1139 if (child->d_inode)
1140 return -EEXIST;
1141 if (IS_DEADDIR(dir))
1142 return -ENOENT;
1143 return permission(dir,MAY_WRITE | MAY_EXEC, nd);
1147 * Special case: O_CREAT|O_EXCL implies O_NOFOLLOW for security
1148 * reasons.
1150 * O_DIRECTORY translates into forcing a directory lookup.
1152 static inline int lookup_flags(unsigned int f)
1154 unsigned long retval = LOOKUP_FOLLOW;
1156 if (f & O_NOFOLLOW)
1157 retval &= ~LOOKUP_FOLLOW;
1159 if ((f & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL))
1160 retval &= ~LOOKUP_FOLLOW;
1162 if (f & O_DIRECTORY)
1163 retval |= LOOKUP_DIRECTORY;
1165 return retval;
1169 * p1 and p2 should be directories on the same fs.
1171 struct dentry *lock_rename(struct dentry *p1, struct dentry *p2)
1173 struct dentry *p;
1175 if (p1 == p2) {
1176 down(&p1->d_inode->i_sem);
1177 return NULL;
1180 down(&p1->d_inode->i_sb->s_vfs_rename_sem);
1182 for (p = p1; p->d_parent != p; p = p->d_parent) {
1183 if (p->d_parent == p2) {
1184 down(&p2->d_inode->i_sem);
1185 down(&p1->d_inode->i_sem);
1186 return p;
1190 for (p = p2; p->d_parent != p; p = p->d_parent) {
1191 if (p->d_parent == p1) {
1192 down(&p1->d_inode->i_sem);
1193 down(&p2->d_inode->i_sem);
1194 return p;
1198 down(&p1->d_inode->i_sem);
1199 down(&p2->d_inode->i_sem);
1200 return NULL;
1203 void unlock_rename(struct dentry *p1, struct dentry *p2)
1205 up(&p1->d_inode->i_sem);
1206 if (p1 != p2) {
1207 up(&p2->d_inode->i_sem);
1208 up(&p1->d_inode->i_sb->s_vfs_rename_sem);
1212 int vfs_create(struct inode *dir, struct dentry *dentry, int mode,
1213 struct nameidata *nd)
1215 int error = may_create(dir, dentry, nd);
1217 if (error)
1218 return error;
1220 if (!dir->i_op || !dir->i_op->create)
1221 return -EACCES; /* shouldn't it be ENOSYS? */
1222 mode &= S_IALLUGO;
1223 mode |= S_IFREG;
1224 error = security_inode_create(dir, dentry, mode);
1225 if (error)
1226 return error;
1227 DQUOT_INIT(dir);
1228 error = dir->i_op->create(dir, dentry, mode, nd);
1229 if (!error) {
1230 inode_dir_notify(dir, DN_CREATE);
1231 security_inode_post_create(dir, dentry, mode);
1233 return error;
1236 int may_open(struct nameidata *nd, int acc_mode, int flag)
1238 struct dentry *dentry = nd->dentry;
1239 struct inode *inode = dentry->d_inode;
1240 int error;
1242 if (!inode)
1243 return -ENOENT;
1245 if (S_ISLNK(inode->i_mode))
1246 return -ELOOP;
1248 if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE))
1249 return -EISDIR;
1251 error = permission(inode, acc_mode, nd);
1252 if (error)
1253 return error;
1256 * FIFO's, sockets and device files are special: they don't
1257 * actually live on the filesystem itself, and as such you
1258 * can write to them even if the filesystem is read-only.
1260 if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
1261 flag &= ~O_TRUNC;
1262 } else if (S_ISBLK(inode->i_mode) || S_ISCHR(inode->i_mode)) {
1263 if (nd->mnt->mnt_flags & MNT_NODEV)
1264 return -EACCES;
1266 flag &= ~O_TRUNC;
1267 } else if (IS_RDONLY(inode) && (flag & FMODE_WRITE))
1268 return -EROFS;
1270 * An append-only file must be opened in append mode for writing.
1272 if (IS_APPEND(inode)) {
1273 if ((flag & FMODE_WRITE) && !(flag & O_APPEND))
1274 return -EPERM;
1275 if (flag & O_TRUNC)
1276 return -EPERM;
1279 /* O_NOATIME can only be set by the owner or superuser */
1280 if (flag & O_NOATIME)
1281 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1282 return -EPERM;
1285 * Ensure there are no outstanding leases on the file.
1287 error = break_lease(inode, flag);
1288 if (error)
1289 return error;
1291 if (flag & O_TRUNC) {
1292 error = get_write_access(inode);
1293 if (error)
1294 return error;
1297 * Refuse to truncate files with mandatory locks held on them.
1299 error = locks_verify_locked(inode);
1300 if (!error) {
1301 DQUOT_INIT(inode);
1303 error = do_truncate(dentry, 0);
1305 put_write_access(inode);
1306 if (error)
1307 return error;
1308 } else
1309 if (flag & FMODE_WRITE)
1310 DQUOT_INIT(inode);
1312 return 0;
1316 * open_namei()
1318 * namei for open - this is in fact almost the whole open-routine.
1320 * Note that the low bits of "flag" aren't the same as in the open
1321 * system call - they are 00 - no permissions needed
1322 * 01 - read permission needed
1323 * 10 - write permission needed
1324 * 11 - read/write permissions needed
1325 * which is a lot more logical, and also allows the "no perm" needed
1326 * for symlinks (where the permissions are checked later).
1327 * SMP-safe
1329 int open_namei(const char * pathname, int flag, int mode, struct nameidata *nd)
1331 int acc_mode, error = 0;
1332 struct dentry *dentry;
1333 struct dentry *dir;
1334 int count = 0;
1336 acc_mode = ACC_MODE(flag);
1338 /* Allow the LSM permission hook to distinguish append
1339 access from general write access. */
1340 if (flag & O_APPEND)
1341 acc_mode |= MAY_APPEND;
1343 /* Fill in the open() intent data */
1344 nd->intent.open.flags = flag;
1345 nd->intent.open.create_mode = mode;
1348 * The simplest case - just a plain lookup.
1350 if (!(flag & O_CREAT)) {
1351 error = path_lookup(pathname, lookup_flags(flag)|LOOKUP_OPEN, nd);
1352 if (error)
1353 return error;
1354 goto ok;
1358 * Create - we need to know the parent.
1360 error = path_lookup(pathname, LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, nd);
1361 if (error)
1362 return error;
1365 * We have the parent and last component. First of all, check
1366 * that we are not asked to creat(2) an obvious directory - that
1367 * will not do.
1369 error = -EISDIR;
1370 if (nd->last_type != LAST_NORM || nd->last.name[nd->last.len])
1371 goto exit;
1373 dir = nd->dentry;
1374 nd->flags &= ~LOOKUP_PARENT;
1375 down(&dir->d_inode->i_sem);
1376 dentry = __lookup_hash(&nd->last, nd->dentry, nd);
1378 do_last:
1379 error = PTR_ERR(dentry);
1380 if (IS_ERR(dentry)) {
1381 up(&dir->d_inode->i_sem);
1382 goto exit;
1385 /* Negative dentry, just create the file */
1386 if (!dentry->d_inode) {
1387 if (!IS_POSIXACL(dir->d_inode))
1388 mode &= ~current->fs->umask;
1389 error = vfs_create(dir->d_inode, dentry, mode, nd);
1390 up(&dir->d_inode->i_sem);
1391 dput(nd->dentry);
1392 nd->dentry = dentry;
1393 if (error)
1394 goto exit;
1395 /* Don't check for write permission, don't truncate */
1396 acc_mode = 0;
1397 flag &= ~O_TRUNC;
1398 goto ok;
1402 * It already exists.
1404 up(&dir->d_inode->i_sem);
1406 error = -EEXIST;
1407 if (flag & O_EXCL)
1408 goto exit_dput;
1410 if (d_mountpoint(dentry)) {
1411 error = -ELOOP;
1412 if (flag & O_NOFOLLOW)
1413 goto exit_dput;
1414 while (__follow_down(&nd->mnt,&dentry) && d_mountpoint(dentry));
1416 error = -ENOENT;
1417 if (!dentry->d_inode)
1418 goto exit_dput;
1419 if (dentry->d_inode->i_op && dentry->d_inode->i_op->follow_link)
1420 goto do_link;
1422 dput(nd->dentry);
1423 nd->dentry = dentry;
1424 error = -EISDIR;
1425 if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))
1426 goto exit;
1428 error = may_open(nd, acc_mode, flag);
1429 if (error)
1430 goto exit;
1431 return 0;
1433 exit_dput:
1434 dput(dentry);
1435 exit:
1436 path_release(nd);
1437 return error;
1439 do_link:
1440 error = -ELOOP;
1441 if (flag & O_NOFOLLOW)
1442 goto exit_dput;
1444 * This is subtle. Instead of calling do_follow_link() we do the
1445 * thing by hands. The reason is that this way we have zero link_count
1446 * and path_walk() (called from ->follow_link) honoring LOOKUP_PARENT.
1447 * After that we have the parent and last component, i.e.
1448 * we are in the same situation as after the first path_walk().
1449 * Well, almost - if the last component is normal we get its copy
1450 * stored in nd->last.name and we will have to putname() it when we
1451 * are done. Procfs-like symlinks just set LAST_BIND.
1453 nd->flags |= LOOKUP_PARENT;
1454 error = security_inode_follow_link(dentry, nd);
1455 if (error)
1456 goto exit_dput;
1457 touch_atime(nd->mnt, dentry);
1458 nd_set_link(nd, NULL);
1459 error = dentry->d_inode->i_op->follow_link(dentry, nd);
1460 if (!error) {
1461 char *s = nd_get_link(nd);
1462 if (s)
1463 error = __vfs_follow_link(nd, s);
1464 if (dentry->d_inode->i_op->put_link)
1465 dentry->d_inode->i_op->put_link(dentry, nd);
1467 dput(dentry);
1468 if (error)
1469 return error;
1470 nd->flags &= ~LOOKUP_PARENT;
1471 if (nd->last_type == LAST_BIND) {
1472 dentry = nd->dentry;
1473 goto ok;
1475 error = -EISDIR;
1476 if (nd->last_type != LAST_NORM)
1477 goto exit;
1478 if (nd->last.name[nd->last.len]) {
1479 putname(nd->last.name);
1480 goto exit;
1482 error = -ELOOP;
1483 if (count++==32) {
1484 putname(nd->last.name);
1485 goto exit;
1487 dir = nd->dentry;
1488 down(&dir->d_inode->i_sem);
1489 dentry = __lookup_hash(&nd->last, nd->dentry, nd);
1490 putname(nd->last.name);
1491 goto do_last;
1495 * lookup_create - lookup a dentry, creating it if it doesn't exist
1496 * @nd: nameidata info
1497 * @is_dir: directory flag
1499 * Simple function to lookup and return a dentry and create it
1500 * if it doesn't exist. Is SMP-safe.
1502 struct dentry *lookup_create(struct nameidata *nd, int is_dir)
1504 struct dentry *dentry;
1506 down(&nd->dentry->d_inode->i_sem);
1507 dentry = ERR_PTR(-EEXIST);
1508 if (nd->last_type != LAST_NORM)
1509 goto fail;
1510 nd->flags &= ~LOOKUP_PARENT;
1511 dentry = lookup_hash(&nd->last, nd->dentry);
1512 if (IS_ERR(dentry))
1513 goto fail;
1514 if (!is_dir && nd->last.name[nd->last.len] && !dentry->d_inode)
1515 goto enoent;
1516 return dentry;
1517 enoent:
1518 dput(dentry);
1519 dentry = ERR_PTR(-ENOENT);
1520 fail:
1521 return dentry;
1524 int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
1526 int error = may_create(dir, dentry, NULL);
1528 if (error)
1529 return error;
1531 if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
1532 return -EPERM;
1534 if (!dir->i_op || !dir->i_op->mknod)
1535 return -EPERM;
1537 error = security_inode_mknod(dir, dentry, mode, dev);
1538 if (error)
1539 return error;
1541 DQUOT_INIT(dir);
1542 error = dir->i_op->mknod(dir, dentry, mode, dev);
1543 if (!error) {
1544 inode_dir_notify(dir, DN_CREATE);
1545 security_inode_post_mknod(dir, dentry, mode, dev);
1547 return error;
1550 asmlinkage long sys_mknod(const char __user * filename, int mode, unsigned dev)
1552 int error = 0;
1553 char * tmp;
1554 struct dentry * dentry;
1555 struct nameidata nd;
1557 if (S_ISDIR(mode))
1558 return -EPERM;
1559 tmp = getname(filename);
1560 if (IS_ERR(tmp))
1561 return PTR_ERR(tmp);
1563 error = path_lookup(tmp, LOOKUP_PARENT, &nd);
1564 if (error)
1565 goto out;
1566 dentry = lookup_create(&nd, 0);
1567 error = PTR_ERR(dentry);
1569 if (!IS_POSIXACL(nd.dentry->d_inode))
1570 mode &= ~current->fs->umask;
1571 if (!IS_ERR(dentry)) {
1572 switch (mode & S_IFMT) {
1573 case 0: case S_IFREG:
1574 error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
1575 break;
1576 case S_IFCHR: case S_IFBLK:
1577 error = vfs_mknod(nd.dentry->d_inode,dentry,mode,
1578 new_decode_dev(dev));
1579 break;
1580 case S_IFIFO: case S_IFSOCK:
1581 error = vfs_mknod(nd.dentry->d_inode,dentry,mode,0);
1582 break;
1583 case S_IFDIR:
1584 error = -EPERM;
1585 break;
1586 default:
1587 error = -EINVAL;
1589 dput(dentry);
1591 up(&nd.dentry->d_inode->i_sem);
1592 path_release(&nd);
1593 out:
1594 putname(tmp);
1596 return error;
1599 int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1601 int error = may_create(dir, dentry, NULL);
1603 if (error)
1604 return error;
1606 if (!dir->i_op || !dir->i_op->mkdir)
1607 return -EPERM;
1609 mode &= (S_IRWXUGO|S_ISVTX);
1610 error = security_inode_mkdir(dir, dentry, mode);
1611 if (error)
1612 return error;
1614 DQUOT_INIT(dir);
1615 error = dir->i_op->mkdir(dir, dentry, mode);
1616 if (!error) {
1617 inode_dir_notify(dir, DN_CREATE);
1618 security_inode_post_mkdir(dir,dentry, mode);
1620 return error;
1623 asmlinkage long sys_mkdir(const char __user * pathname, int mode)
1625 int error = 0;
1626 char * tmp;
1628 tmp = getname(pathname);
1629 error = PTR_ERR(tmp);
1630 if (!IS_ERR(tmp)) {
1631 struct dentry *dentry;
1632 struct nameidata nd;
1634 error = path_lookup(tmp, LOOKUP_PARENT, &nd);
1635 if (error)
1636 goto out;
1637 dentry = lookup_create(&nd, 1);
1638 error = PTR_ERR(dentry);
1639 if (!IS_ERR(dentry)) {
1640 if (!IS_POSIXACL(nd.dentry->d_inode))
1641 mode &= ~current->fs->umask;
1642 error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
1643 dput(dentry);
1645 up(&nd.dentry->d_inode->i_sem);
1646 path_release(&nd);
1647 out:
1648 putname(tmp);
1651 return error;
1655 * We try to drop the dentry early: we should have
1656 * a usage count of 2 if we're the only user of this
1657 * dentry, and if that is true (possibly after pruning
1658 * the dcache), then we drop the dentry now.
1660 * A low-level filesystem can, if it choses, legally
1661 * do a
1663 * if (!d_unhashed(dentry))
1664 * return -EBUSY;
1666 * if it cannot handle the case of removing a directory
1667 * that is still in use by something else..
1669 void dentry_unhash(struct dentry *dentry)
1671 dget(dentry);
1672 spin_lock(&dcache_lock);
1673 switch (atomic_read(&dentry->d_count)) {
1674 default:
1675 spin_unlock(&dcache_lock);
1676 shrink_dcache_parent(dentry);
1677 spin_lock(&dcache_lock);
1678 if (atomic_read(&dentry->d_count) != 2)
1679 break;
1680 case 2:
1681 __d_drop(dentry);
1683 spin_unlock(&dcache_lock);
1686 int vfs_rmdir(struct inode *dir, struct dentry *dentry)
1688 int error = may_delete(dir, dentry, 1);
1690 if (error)
1691 return error;
1693 if (!dir->i_op || !dir->i_op->rmdir)
1694 return -EPERM;
1696 DQUOT_INIT(dir);
1698 down(&dentry->d_inode->i_sem);
1699 dentry_unhash(dentry);
1700 if (d_mountpoint(dentry))
1701 error = -EBUSY;
1702 else {
1703 error = security_inode_rmdir(dir, dentry);
1704 if (!error) {
1705 error = dir->i_op->rmdir(dir, dentry);
1706 if (!error)
1707 dentry->d_inode->i_flags |= S_DEAD;
1710 up(&dentry->d_inode->i_sem);
1711 if (!error) {
1712 inode_dir_notify(dir, DN_DELETE);
1713 d_delete(dentry);
1715 dput(dentry);
1717 return error;
1720 asmlinkage long sys_rmdir(const char __user * pathname)
1722 int error = 0;
1723 char * name;
1724 struct dentry *dentry;
1725 struct nameidata nd;
1727 name = getname(pathname);
1728 if(IS_ERR(name))
1729 return PTR_ERR(name);
1731 error = path_lookup(name, LOOKUP_PARENT, &nd);
1732 if (error)
1733 goto exit;
1735 switch(nd.last_type) {
1736 case LAST_DOTDOT:
1737 error = -ENOTEMPTY;
1738 goto exit1;
1739 case LAST_DOT:
1740 error = -EINVAL;
1741 goto exit1;
1742 case LAST_ROOT:
1743 error = -EBUSY;
1744 goto exit1;
1746 down(&nd.dentry->d_inode->i_sem);
1747 dentry = lookup_hash(&nd.last, nd.dentry);
1748 error = PTR_ERR(dentry);
1749 if (!IS_ERR(dentry)) {
1750 error = vfs_rmdir(nd.dentry->d_inode, dentry);
1751 dput(dentry);
1753 up(&nd.dentry->d_inode->i_sem);
1754 exit1:
1755 path_release(&nd);
1756 exit:
1757 putname(name);
1758 return error;
1761 int vfs_unlink(struct inode *dir, struct dentry *dentry)
1763 int error = may_delete(dir, dentry, 0);
1765 if (error)
1766 return error;
1768 if (!dir->i_op || !dir->i_op->unlink)
1769 return -EPERM;
1771 DQUOT_INIT(dir);
1773 down(&dentry->d_inode->i_sem);
1774 if (d_mountpoint(dentry))
1775 error = -EBUSY;
1776 else {
1777 error = security_inode_unlink(dir, dentry);
1778 if (!error)
1779 error = dir->i_op->unlink(dir, dentry);
1781 up(&dentry->d_inode->i_sem);
1783 /* We don't d_delete() NFS sillyrenamed files--they still exist. */
1784 if (!error && !(dentry->d_flags & DCACHE_NFSFS_RENAMED)) {
1785 d_delete(dentry);
1786 inode_dir_notify(dir, DN_DELETE);
1788 return error;
1792 * Make sure that the actual truncation of the file will occur outside its
1793 * directory's i_sem. Truncate can take a long time if there is a lot of
1794 * writeout happening, and we don't want to prevent access to the directory
1795 * while waiting on the I/O.
1797 asmlinkage long sys_unlink(const char __user * pathname)
1799 int error = 0;
1800 char * name;
1801 struct dentry *dentry;
1802 struct nameidata nd;
1803 struct inode *inode = NULL;
1805 name = getname(pathname);
1806 if(IS_ERR(name))
1807 return PTR_ERR(name);
1809 error = path_lookup(name, LOOKUP_PARENT, &nd);
1810 if (error)
1811 goto exit;
1812 error = -EISDIR;
1813 if (nd.last_type != LAST_NORM)
1814 goto exit1;
1815 down(&nd.dentry->d_inode->i_sem);
1816 dentry = lookup_hash(&nd.last, nd.dentry);
1817 error = PTR_ERR(dentry);
1818 if (!IS_ERR(dentry)) {
1819 /* Why not before? Because we want correct error value */
1820 if (nd.last.name[nd.last.len])
1821 goto slashes;
1822 inode = dentry->d_inode;
1823 if (inode)
1824 atomic_inc(&inode->i_count);
1825 error = vfs_unlink(nd.dentry->d_inode, dentry);
1826 exit2:
1827 dput(dentry);
1829 up(&nd.dentry->d_inode->i_sem);
1830 if (inode)
1831 iput(inode); /* truncate the inode here */
1832 exit1:
1833 path_release(&nd);
1834 exit:
1835 putname(name);
1836 return error;
1838 slashes:
1839 error = !dentry->d_inode ? -ENOENT :
1840 S_ISDIR(dentry->d_inode->i_mode) ? -EISDIR : -ENOTDIR;
1841 goto exit2;
1844 int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname, int mode)
1846 int error = may_create(dir, dentry, NULL);
1848 if (error)
1849 return error;
1851 if (!dir->i_op || !dir->i_op->symlink)
1852 return -EPERM;
1854 error = security_inode_symlink(dir, dentry, oldname);
1855 if (error)
1856 return error;
1858 DQUOT_INIT(dir);
1859 error = dir->i_op->symlink(dir, dentry, oldname);
1860 if (!error) {
1861 inode_dir_notify(dir, DN_CREATE);
1862 security_inode_post_symlink(dir, dentry, oldname);
1864 return error;
1867 asmlinkage long sys_symlink(const char __user * oldname, const char __user * newname)
1869 int error = 0;
1870 char * from;
1871 char * to;
1873 from = getname(oldname);
1874 if(IS_ERR(from))
1875 return PTR_ERR(from);
1876 to = getname(newname);
1877 error = PTR_ERR(to);
1878 if (!IS_ERR(to)) {
1879 struct dentry *dentry;
1880 struct nameidata nd;
1882 error = path_lookup(to, LOOKUP_PARENT, &nd);
1883 if (error)
1884 goto out;
1885 dentry = lookup_create(&nd, 0);
1886 error = PTR_ERR(dentry);
1887 if (!IS_ERR(dentry)) {
1888 error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
1889 dput(dentry);
1891 up(&nd.dentry->d_inode->i_sem);
1892 path_release(&nd);
1893 out:
1894 putname(to);
1896 putname(from);
1897 return error;
1900 int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
1902 struct inode *inode = old_dentry->d_inode;
1903 int error;
1905 if (!inode)
1906 return -ENOENT;
1908 error = may_create(dir, new_dentry, NULL);
1909 if (error)
1910 return error;
1912 if (dir->i_sb != inode->i_sb)
1913 return -EXDEV;
1916 * A link to an append-only or immutable file cannot be created.
1918 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1919 return -EPERM;
1920 if (!dir->i_op || !dir->i_op->link)
1921 return -EPERM;
1922 if (S_ISDIR(old_dentry->d_inode->i_mode))
1923 return -EPERM;
1925 error = security_inode_link(old_dentry, dir, new_dentry);
1926 if (error)
1927 return error;
1929 down(&old_dentry->d_inode->i_sem);
1930 DQUOT_INIT(dir);
1931 error = dir->i_op->link(old_dentry, dir, new_dentry);
1932 up(&old_dentry->d_inode->i_sem);
1933 if (!error) {
1934 inode_dir_notify(dir, DN_CREATE);
1935 security_inode_post_link(old_dentry, dir, new_dentry);
1937 return error;
1941 * Hardlinks are often used in delicate situations. We avoid
1942 * security-related surprises by not following symlinks on the
1943 * newname. --KAB
1945 * We don't follow them on the oldname either to be compatible
1946 * with linux 2.0, and to avoid hard-linking to directories
1947 * and other special files. --ADM
1949 asmlinkage long sys_link(const char __user * oldname, const char __user * newname)
1951 struct dentry *new_dentry;
1952 struct nameidata nd, old_nd;
1953 int error;
1954 char * to;
1956 to = getname(newname);
1957 if (IS_ERR(to))
1958 return PTR_ERR(to);
1960 error = __user_walk(oldname, 0, &old_nd);
1961 if (error)
1962 goto exit;
1963 error = path_lookup(to, LOOKUP_PARENT, &nd);
1964 if (error)
1965 goto out;
1966 error = -EXDEV;
1967 if (old_nd.mnt != nd.mnt)
1968 goto out_release;
1969 new_dentry = lookup_create(&nd, 0);
1970 error = PTR_ERR(new_dentry);
1971 if (!IS_ERR(new_dentry)) {
1972 error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
1973 dput(new_dentry);
1975 up(&nd.dentry->d_inode->i_sem);
1976 out_release:
1977 path_release(&nd);
1978 out:
1979 path_release(&old_nd);
1980 exit:
1981 putname(to);
1983 return error;
1987 * The worst of all namespace operations - renaming directory. "Perverted"
1988 * doesn't even start to describe it. Somebody in UCB had a heck of a trip...
1989 * Problems:
1990 * a) we can get into loop creation. Check is done in is_subdir().
1991 * b) race potential - two innocent renames can create a loop together.
1992 * That's where 4.4 screws up. Current fix: serialization on
1993 * sb->s_vfs_rename_sem. We might be more accurate, but that's another
1994 * story.
1995 * c) we have to lock _three_ objects - parents and victim (if it exists).
1996 * And that - after we got ->i_sem on parents (until then we don't know
1997 * whether the target exists). Solution: try to be smart with locking
1998 * order for inodes. We rely on the fact that tree topology may change
1999 * only under ->s_vfs_rename_sem _and_ that parent of the object we
2000 * move will be locked. Thus we can rank directories by the tree
2001 * (ancestors first) and rank all non-directories after them.
2002 * That works since everybody except rename does "lock parent, lookup,
2003 * lock child" and rename is under ->s_vfs_rename_sem.
2004 * HOWEVER, it relies on the assumption that any object with ->lookup()
2005 * has no more than 1 dentry. If "hybrid" objects will ever appear,
2006 * we'd better make sure that there's no link(2) for them.
2007 * d) some filesystems don't support opened-but-unlinked directories,
2008 * either because of layout or because they are not ready to deal with
2009 * all cases correctly. The latter will be fixed (taking this sort of
2010 * stuff into VFS), but the former is not going away. Solution: the same
2011 * trick as in rmdir().
2012 * e) conversion from fhandle to dentry may come in the wrong moment - when
2013 * we are removing the target. Solution: we will have to grab ->i_sem
2014 * in the fhandle_to_dentry code. [FIXME - current nfsfh.c relies on
2015 * ->i_sem on parents, which works but leads to some truely excessive
2016 * locking].
2018 int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
2019 struct inode *new_dir, struct dentry *new_dentry)
2021 int error = 0;
2022 struct inode *target;
2025 * If we are going to change the parent - check write permissions,
2026 * we'll need to flip '..'.
2028 if (new_dir != old_dir) {
2029 error = permission(old_dentry->d_inode, MAY_WRITE, NULL);
2030 if (error)
2031 return error;
2034 error = security_inode_rename(old_dir, old_dentry, new_dir, new_dentry);
2035 if (error)
2036 return error;
2038 target = new_dentry->d_inode;
2039 if (target) {
2040 down(&target->i_sem);
2041 dentry_unhash(new_dentry);
2043 if (d_mountpoint(old_dentry)||d_mountpoint(new_dentry))
2044 error = -EBUSY;
2045 else
2046 error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry);
2047 if (target) {
2048 if (!error)
2049 target->i_flags |= S_DEAD;
2050 up(&target->i_sem);
2051 if (d_unhashed(new_dentry))
2052 d_rehash(new_dentry);
2053 dput(new_dentry);
2055 if (!error) {
2056 d_move(old_dentry,new_dentry);
2057 security_inode_post_rename(old_dir, old_dentry,
2058 new_dir, new_dentry);
2060 return error;
2063 int vfs_rename_other(struct inode *old_dir, struct dentry *old_dentry,
2064 struct inode *new_dir, struct dentry *new_dentry)
2066 struct inode *target;
2067 int error;
2069 error = security_inode_rename(old_dir, old_dentry, new_dir, new_dentry);
2070 if (error)
2071 return error;
2073 dget(new_dentry);
2074 target = new_dentry->d_inode;
2075 if (target)
2076 down(&target->i_sem);
2077 if (d_mountpoint(old_dentry)||d_mountpoint(new_dentry))
2078 error = -EBUSY;
2079 else
2080 error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry);
2081 if (!error) {
2082 /* The following d_move() should become unconditional */
2083 if (!(old_dir->i_sb->s_type->fs_flags & FS_ODD_RENAME))
2084 d_move(old_dentry, new_dentry);
2085 security_inode_post_rename(old_dir, old_dentry, new_dir, new_dentry);
2087 if (target)
2088 up(&target->i_sem);
2089 dput(new_dentry);
2090 return error;
2093 int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
2094 struct inode *new_dir, struct dentry *new_dentry)
2096 int error;
2097 int is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
2099 if (old_dentry->d_inode == new_dentry->d_inode)
2100 return 0;
2102 error = may_delete(old_dir, old_dentry, is_dir);
2103 if (error)
2104 return error;
2106 if (!new_dentry->d_inode)
2107 error = may_create(new_dir, new_dentry, NULL);
2108 else
2109 error = may_delete(new_dir, new_dentry, is_dir);
2110 if (error)
2111 return error;
2113 if (!old_dir->i_op || !old_dir->i_op->rename)
2114 return -EPERM;
2116 DQUOT_INIT(old_dir);
2117 DQUOT_INIT(new_dir);
2119 if (is_dir)
2120 error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry);
2121 else
2122 error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
2123 if (!error) {
2124 if (old_dir == new_dir)
2125 inode_dir_notify(old_dir, DN_RENAME);
2126 else {
2127 inode_dir_notify(old_dir, DN_DELETE);
2128 inode_dir_notify(new_dir, DN_CREATE);
2131 return error;
2134 static inline int do_rename(const char * oldname, const char * newname)
2136 int error = 0;
2137 struct dentry * old_dir, * new_dir;
2138 struct dentry * old_dentry, *new_dentry;
2139 struct dentry * trap;
2140 struct nameidata oldnd, newnd;
2142 error = path_lookup(oldname, LOOKUP_PARENT, &oldnd);
2143 if (error)
2144 goto exit;
2146 error = path_lookup(newname, LOOKUP_PARENT, &newnd);
2147 if (error)
2148 goto exit1;
2150 error = -EXDEV;
2151 if (oldnd.mnt != newnd.mnt)
2152 goto exit2;
2154 old_dir = oldnd.dentry;
2155 error = -EBUSY;
2156 if (oldnd.last_type != LAST_NORM)
2157 goto exit2;
2159 new_dir = newnd.dentry;
2160 if (newnd.last_type != LAST_NORM)
2161 goto exit2;
2163 trap = lock_rename(new_dir, old_dir);
2165 old_dentry = lookup_hash(&oldnd.last, old_dir);
2166 error = PTR_ERR(old_dentry);
2167 if (IS_ERR(old_dentry))
2168 goto exit3;
2169 /* source must exist */
2170 error = -ENOENT;
2171 if (!old_dentry->d_inode)
2172 goto exit4;
2173 /* unless the source is a directory trailing slashes give -ENOTDIR */
2174 if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
2175 error = -ENOTDIR;
2176 if (oldnd.last.name[oldnd.last.len])
2177 goto exit4;
2178 if (newnd.last.name[newnd.last.len])
2179 goto exit4;
2181 /* source should not be ancestor of target */
2182 error = -EINVAL;
2183 if (old_dentry == trap)
2184 goto exit4;
2185 new_dentry = lookup_hash(&newnd.last, new_dir);
2186 error = PTR_ERR(new_dentry);
2187 if (IS_ERR(new_dentry))
2188 goto exit4;
2189 /* target should not be an ancestor of source */
2190 error = -ENOTEMPTY;
2191 if (new_dentry == trap)
2192 goto exit5;
2194 error = vfs_rename(old_dir->d_inode, old_dentry,
2195 new_dir->d_inode, new_dentry);
2196 exit5:
2197 dput(new_dentry);
2198 exit4:
2199 dput(old_dentry);
2200 exit3:
2201 unlock_rename(new_dir, old_dir);
2202 exit2:
2203 path_release(&newnd);
2204 exit1:
2205 path_release(&oldnd);
2206 exit:
2207 return error;
2210 asmlinkage long sys_rename(const char __user * oldname, const char __user * newname)
2212 int error;
2213 char * from;
2214 char * to;
2216 from = getname(oldname);
2217 if(IS_ERR(from))
2218 return PTR_ERR(from);
2219 to = getname(newname);
2220 error = PTR_ERR(to);
2221 if (!IS_ERR(to)) {
2222 error = do_rename(from,to);
2223 putname(to);
2225 putname(from);
2226 return error;
2229 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
2231 int len;
2233 len = PTR_ERR(link);
2234 if (IS_ERR(link))
2235 goto out;
2237 len = strlen(link);
2238 if (len > (unsigned) buflen)
2239 len = buflen;
2240 if (copy_to_user(buffer, link, len))
2241 len = -EFAULT;
2242 out:
2243 return len;
2247 * A helper for ->readlink(). This should be used *ONLY* for symlinks that
2248 * have ->follow_link() touching nd only in nd_set_link(). Using (or not
2249 * using) it for any given inode is up to filesystem.
2251 int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)
2253 struct nameidata nd;
2254 int res;
2255 nd.depth = 0;
2256 res = dentry->d_inode->i_op->follow_link(dentry, &nd);
2257 if (!res) {
2258 res = vfs_readlink(dentry, buffer, buflen, nd_get_link(&nd));
2259 if (dentry->d_inode->i_op->put_link)
2260 dentry->d_inode->i_op->put_link(dentry, &nd);
2262 return res;
2265 int vfs_follow_link(struct nameidata *nd, const char *link)
2267 return __vfs_follow_link(nd, link);
2270 /* get the link contents into pagecache */
2271 static char *page_getlink(struct dentry * dentry, struct page **ppage)
2273 struct page * page;
2274 struct address_space *mapping = dentry->d_inode->i_mapping;
2275 page = read_cache_page(mapping, 0, (filler_t *)mapping->a_ops->readpage,
2276 NULL);
2277 if (IS_ERR(page))
2278 goto sync_fail;
2279 wait_on_page_locked(page);
2280 if (!PageUptodate(page))
2281 goto async_fail;
2282 *ppage = page;
2283 return kmap(page);
2285 async_fail:
2286 page_cache_release(page);
2287 return ERR_PTR(-EIO);
2289 sync_fail:
2290 return (char*)page;
2293 int page_readlink(struct dentry *dentry, char __user *buffer, int buflen)
2295 struct page *page = NULL;
2296 char *s = page_getlink(dentry, &page);
2297 int res = vfs_readlink(dentry,buffer,buflen,s);
2298 if (page) {
2299 kunmap(page);
2300 page_cache_release(page);
2302 return res;
2305 int page_follow_link_light(struct dentry *dentry, struct nameidata *nd)
2307 struct page *page;
2308 nd_set_link(nd, page_getlink(dentry, &page));
2309 return 0;
2312 void page_put_link(struct dentry *dentry, struct nameidata *nd)
2314 if (!IS_ERR(nd_get_link(nd))) {
2315 struct page *page;
2316 page = find_get_page(dentry->d_inode->i_mapping, 0);
2317 if (!page)
2318 BUG();
2319 kunmap(page);
2320 page_cache_release(page);
2321 page_cache_release(page);
2325 int page_follow_link(struct dentry *dentry, struct nameidata *nd)
2327 struct page *page = NULL;
2328 char *s = page_getlink(dentry, &page);
2329 int res = __vfs_follow_link(nd, s);
2330 if (page) {
2331 kunmap(page);
2332 page_cache_release(page);
2334 return res;
2337 int page_symlink(struct inode *inode, const char *symname, int len)
2339 struct address_space *mapping = inode->i_mapping;
2340 struct page *page = grab_cache_page(mapping, 0);
2341 int err = -ENOMEM;
2342 char *kaddr;
2344 if (!page)
2345 goto fail;
2346 err = mapping->a_ops->prepare_write(NULL, page, 0, len-1);
2347 if (err)
2348 goto fail_map;
2349 kaddr = kmap_atomic(page, KM_USER0);
2350 memcpy(kaddr, symname, len-1);
2351 kunmap_atomic(kaddr, KM_USER0);
2352 mapping->a_ops->commit_write(NULL, page, 0, len-1);
2354 * Notice that we are _not_ going to block here - end of page is
2355 * unmapped, so this will only try to map the rest of page, see
2356 * that it is unmapped (typically even will not look into inode -
2357 * ->i_size will be enough for everything) and zero it out.
2358 * OTOH it's obviously correct and should make the page up-to-date.
2360 if (!PageUptodate(page)) {
2361 err = mapping->a_ops->readpage(NULL, page);
2362 wait_on_page_locked(page);
2363 } else {
2364 unlock_page(page);
2366 page_cache_release(page);
2367 if (err < 0)
2368 goto fail;
2369 mark_inode_dirty(inode);
2370 return 0;
2371 fail_map:
2372 unlock_page(page);
2373 page_cache_release(page);
2374 fail:
2375 return err;
2378 struct inode_operations page_symlink_inode_operations = {
2379 .readlink = generic_readlink,
2380 .follow_link = page_follow_link_light,
2381 .put_link = page_put_link,
2384 EXPORT_SYMBOL(__user_walk);
2385 EXPORT_SYMBOL(follow_down);
2386 EXPORT_SYMBOL(follow_up);
2387 EXPORT_SYMBOL(get_write_access); /* binfmt_aout */
2388 EXPORT_SYMBOL(getname);
2389 EXPORT_SYMBOL(lock_rename);
2390 EXPORT_SYMBOL(lookup_create);
2391 EXPORT_SYMBOL(lookup_hash);
2392 EXPORT_SYMBOL(lookup_one_len);
2393 EXPORT_SYMBOL(page_follow_link);
2394 EXPORT_SYMBOL(page_follow_link_light);
2395 EXPORT_SYMBOL(page_put_link);
2396 EXPORT_SYMBOL(page_readlink);
2397 EXPORT_SYMBOL(page_symlink);
2398 EXPORT_SYMBOL(page_symlink_inode_operations);
2399 EXPORT_SYMBOL(path_lookup);
2400 EXPORT_SYMBOL(path_release);
2401 EXPORT_SYMBOL(path_walk);
2402 EXPORT_SYMBOL(permission);
2403 EXPORT_SYMBOL(unlock_rename);
2404 EXPORT_SYMBOL(vfs_create);
2405 EXPORT_SYMBOL(vfs_follow_link);
2406 EXPORT_SYMBOL(vfs_link);
2407 EXPORT_SYMBOL(vfs_mkdir);
2408 EXPORT_SYMBOL(vfs_mknod);
2409 EXPORT_SYMBOL(vfs_permission);
2410 EXPORT_SYMBOL(vfs_readlink);
2411 EXPORT_SYMBOL(vfs_rename);
2412 EXPORT_SYMBOL(vfs_rmdir);
2413 EXPORT_SYMBOL(vfs_symlink);
2414 EXPORT_SYMBOL(vfs_unlink);
2415 EXPORT_SYMBOL(dentry_unhash);
2416 EXPORT_SYMBOL(generic_readlink);