4 * Copyright (C) 1991, 1992 Linus Torvalds
8 * Some corrections by tytso.
11 /* [Feb 1997 T. Schoebel-Theuer] Complete rewrite of the pathname
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>
21 #include <linux/namei.h>
22 #include <linux/quotaops.h>
23 #include <linux/pagemap.h>
24 #include <linux/fsnotify.h>
25 #include <linux/smp_lock.h>
26 #include <linux/personality.h>
27 #include <linux/security.h>
28 #include <linux/syscalls.h>
29 #include <linux/mount.h>
30 #include <linux/audit.h>
31 #include <linux/capability.h>
32 #include <linux/file.h>
33 #include <linux/fcntl.h>
34 #include <linux/namei.h>
35 #include <linux/proc_fs.h>
36 #include <linux/vserver/inode.h>
37 #include <linux/vs_base.h>
38 #include <linux/vs_tag.h>
39 #include <linux/vs_cowbl.h>
40 #include <asm/namei.h>
41 #include <asm/uaccess.h>
43 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
45 /* [Feb-1997 T. Schoebel-Theuer]
46 * Fundamental changes in the pathname lookup mechanisms (namei)
47 * were necessary because of omirr. The reason is that omirr needs
48 * to know the _real_ pathname, not the user-supplied one, in case
49 * of symlinks (and also when transname replacements occur).
51 * The new code replaces the old recursive symlink resolution with
52 * an iterative one (in case of non-nested symlink chains). It does
53 * this with calls to <fs>_follow_link().
54 * As a side effect, dir_namei(), _namei() and follow_link() are now
55 * replaced with a single function lookup_dentry() that can handle all
56 * the special cases of the former code.
58 * With the new dcache, the pathname is stored at each inode, at least as
59 * long as the refcount of the inode is positive. As a side effect, the
60 * size of the dcache depends on the inode cache and thus is dynamic.
62 * [29-Apr-1998 C. Scott Ananian] Updated above description of symlink
63 * resolution to correspond with current state of the code.
65 * Note that the symlink resolution is not *completely* iterative.
66 * There is still a significant amount of tail- and mid- recursion in
67 * the algorithm. Also, note that <fs>_readlink() is not used in
68 * lookup_dentry(): lookup_dentry() on the result of <fs>_readlink()
69 * may return different results than <fs>_follow_link(). Many virtual
70 * filesystems (including /proc) exhibit this behavior.
73 /* [24-Feb-97 T. Schoebel-Theuer] Side effects caused by new implementation:
74 * New symlink semantics: when open() is called with flags O_CREAT | O_EXCL
75 * and the name already exists in form of a symlink, try to create the new
76 * name indicated by the symlink. The old code always complained that the
77 * name already exists, due to not following the symlink even if its target
78 * is nonexistent. The new semantics affects also mknod() and link() when
79 * the name is a symlink pointing to a non-existant name.
81 * I don't know which semantics is the right one, since I have no access
82 * to standards. But I found by trial that HP-UX 9.0 has the full "new"
83 * semantics implemented, while SunOS 4.1.1 and Solaris (SunOS 5.4) have the
84 * "old" one. Personally, I think the new semantics is much more logical.
85 * Note that "ln old new" where "new" is a symlink pointing to a non-existing
86 * file does succeed in both HP-UX and SunOs, but not in Solaris
87 * and in the old Linux semantics.
90 /* [16-Dec-97 Kevin Buhr] For security reasons, we change some symlink
91 * semantics. See the comments in "open_namei" and "do_link" below.
93 * [10-Sep-98 Alan Modra] Another symlink change.
96 /* [Feb-Apr 2000 AV] Complete rewrite. Rules for symlinks:
97 * inside the path - always follow.
98 * in the last component in creation/removal/renaming - never follow.
99 * if LOOKUP_FOLLOW passed - follow.
100 * if the pathname has trailing slashes - follow.
101 * otherwise - don't follow.
102 * (applied in that order).
104 * [Jun 2000 AV] Inconsistent behaviour of open() in case if flags==O_CREAT
105 * restored for 2.4. This is the last surviving part of old 4.2BSD bug.
106 * During the 2.4 we need to fix the userland stuff depending on it -
107 * hopefully we will be able to get rid of that wart in 2.5. So far only
108 * XEmacs seems to be relying on it...
111 * [Sep 2001 AV] Single-semaphore locking scheme (kudos to David Holland)
112 * implemented. Let's see if raised priority of ->s_vfs_rename_mutex gives
113 * any extra contention...
116 /* In order to reduce some races, while at the same time doing additional
117 * checking and hopefully speeding things up, we copy filenames to the
118 * kernel data space before using them..
120 * POSIX.1 2.4: an empty pathname is invalid (ENOENT).
121 * PATH_MAX includes the nul terminator --RR.
123 static int do_getname(const char __user *filename, char *page)
126 unsigned long len = PATH_MAX;
128 if (!segment_eq(get_fs(), KERNEL_DS)) {
129 if ((unsigned long) filename >= TASK_SIZE)
131 if (TASK_SIZE - (unsigned long) filename < PATH_MAX)
132 len = TASK_SIZE - (unsigned long) filename;
135 retval = strncpy_from_user(page, filename, len);
139 return -ENAMETOOLONG;
145 char * getname(const char __user * filename)
149 result = ERR_PTR(-ENOMEM);
152 int retval = do_getname(filename, tmp);
157 result = ERR_PTR(retval);
160 audit_getname(result);
164 #ifdef CONFIG_AUDITSYSCALL
165 void putname(const char *name)
167 if (unlikely(!audit_dummy_context()))
172 EXPORT_SYMBOL(putname);
177 * generic_permission - check for access rights on a Posix-like filesystem
178 * @inode: inode to check access rights for
179 * @mask: right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC)
180 * @check_acl: optional callback to check for Posix ACLs
182 * Used to check for read/write/execute permissions on a file.
183 * We use "fsuid" for this, letting us set arbitrary permissions
184 * for filesystem access without changing the "normal" uids which
185 * are used for other things..
187 int generic_permission(struct inode *inode, int mask,
188 int (*check_acl)(struct inode *inode, int mask))
190 umode_t mode = inode->i_mode;
192 if (current->fsuid == inode->i_uid)
195 if (IS_POSIXACL(inode) && (mode & S_IRWXG) && check_acl) {
196 int error = check_acl(inode, mask);
197 if (error == -EACCES)
198 goto check_capabilities;
199 else if (error != -EAGAIN)
203 if (in_group_p(inode->i_gid))
208 * If the DACs are ok we don't need any capability check.
210 if (((mode & mask & (MAY_READ|MAY_WRITE|MAY_EXEC)) == mask))
215 * Read/write DACs are always overridable.
216 * Executable DACs are overridable if at least one exec bit is set.
218 if (!(mask & MAY_EXEC) ||
219 (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode))
220 if (capable(CAP_DAC_OVERRIDE))
224 * Searching includes executable on directories, else just read.
226 if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
227 if (capable(CAP_DAC_READ_SEARCH))
233 static inline int dx_barrier(struct inode *inode)
235 if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN)) {
236 vxwprintk(1, "xid=%d did hit the barrier.",
243 static inline int dx_permission(struct inode *inode, int mask, struct nameidata *nd)
245 if (dx_barrier(inode))
247 if (inode->i_tag == 0)
249 #ifdef CONFIG_VSERVER_FILESHARING
250 /* MEF: PlanetLab FS module assumes that any file that can be
251 * named (e.g., via a cross mount) is not hidden from another
252 * context or the admin context.
254 if (!dx_check(inode->i_tag, DX_HOSTID))
257 if (dx_check(inode->i_tag, DX_ADMIN|DX_WATCH|DX_IDENT))
260 vxwprintk(1, "xid=%d denied access to %p[#%d,%lu] »%s«.",
261 vx_current_xid(), inode, inode->i_tag, inode->i_ino,
266 int permission(struct inode *inode, int mask, struct nameidata *nd)
268 umode_t mode = inode->i_mode;
271 if (mask & MAY_WRITE) {
274 * Nobody gets write access to a read-only fs.
276 if ((IS_RDONLY(inode) || (nd && MNT_IS_RDONLY(nd->mnt))) &&
277 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
281 * Nobody gets write access to an immutable file.
283 if (IS_IMMUTABLE(inode) && !IS_COW(inode))
289 * MAY_EXEC on regular files requires special handling: We override
290 * filesystem execute permissions if the mode bits aren't set or
291 * the fs is mounted with the "noexec" flag.
293 if ((mask & MAY_EXEC) && S_ISREG(mode) && (!(mode & S_IXUGO) ||
294 (nd && nd->mnt && (nd->mnt->mnt_flags & MNT_NOEXEC))))
297 /* Ordinary permission routines do not understand MAY_APPEND. */
298 submask = mask & ~MAY_APPEND;
299 if ((retval = dx_permission(inode, mask, nd)))
301 if (inode->i_op && inode->i_op->permission)
302 retval = inode->i_op->permission(inode, submask, nd);
304 retval = generic_permission(inode, submask, NULL);
308 return security_inode_permission(inode, mask, nd);
312 * vfs_permission - check for access rights to a given path
313 * @nd: lookup result that describes the path
314 * @mask: right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC)
316 * Used to check for read/write/execute permissions on a path.
317 * We use "fsuid" for this, letting us set arbitrary permissions
318 * for filesystem access without changing the "normal" uids which
319 * are used for other things.
321 int vfs_permission(struct nameidata *nd, int mask)
323 return permission(nd->dentry->d_inode, mask, nd);
327 * file_permission - check for additional access rights to a given file
328 * @file: file to check access rights for
329 * @mask: right to check for (%MAY_READ, %MAY_WRITE, %MAY_EXEC)
331 * Used to check for read/write/execute permissions on an already opened
335 * Do not use this function in new code. All access checks should
336 * be done using vfs_permission().
338 int file_permission(struct file *file, int mask)
340 return permission(file->f_path.dentry->d_inode, mask, NULL);
344 * get_write_access() gets write permission for a file.
345 * put_write_access() releases this write permission.
346 * This is used for regular files.
347 * We cannot support write (and maybe mmap read-write shared) accesses and
348 * MAP_DENYWRITE mmappings simultaneously. The i_writecount field of an inode
349 * can have the following values:
350 * 0: no writers, no VM_DENYWRITE mappings
351 * < 0: (-i_writecount) vm_area_structs with VM_DENYWRITE set exist
352 * > 0: (i_writecount) users are writing to the file.
354 * Normally we operate on that counter with atomic_{inc,dec} and it's safe
355 * except for the cases where we don't hold i_writecount yet. Then we need to
356 * use {get,deny}_write_access() - these functions check the sign and refuse
357 * to do the change if sign is wrong. Exclusion between them is provided by
358 * the inode->i_lock spinlock.
361 int get_write_access(struct inode * inode)
363 spin_lock(&inode->i_lock);
364 if (atomic_read(&inode->i_writecount) < 0) {
365 spin_unlock(&inode->i_lock);
368 atomic_inc(&inode->i_writecount);
369 spin_unlock(&inode->i_lock);
374 int deny_write_access(struct file * file)
376 struct inode *inode = file->f_path.dentry->d_inode;
378 spin_lock(&inode->i_lock);
379 if (atomic_read(&inode->i_writecount) > 0) {
380 spin_unlock(&inode->i_lock);
383 atomic_dec(&inode->i_writecount);
384 spin_unlock(&inode->i_lock);
389 void path_release(struct nameidata *nd)
396 * umount() mustn't call path_release()/mntput() as that would clear
399 void path_release_on_umount(struct nameidata *nd)
402 mntput_no_expire(nd->mnt);
406 * release_open_intent - free up open intent resources
407 * @nd: pointer to nameidata
409 void release_open_intent(struct nameidata *nd)
411 if (nd->intent.open.file->f_path.dentry == NULL)
412 put_filp(nd->intent.open.file);
414 fput(nd->intent.open.file);
417 static inline struct dentry *
418 do_revalidate(struct dentry *dentry, struct nameidata *nd)
420 int status = dentry->d_op->d_revalidate(dentry, nd);
421 if (unlikely(status <= 0)) {
423 * The dentry failed validation.
424 * If d_revalidate returned 0 attempt to invalidate
425 * the dentry otherwise d_revalidate is asking us
426 * to return a fail status.
429 if (!d_invalidate(dentry)) {
435 dentry = ERR_PTR(status);
442 * Internal lookup() using the new generic dcache.
445 static struct dentry * cached_lookup(struct dentry * parent, struct qstr * name, struct nameidata *nd)
447 struct dentry * dentry = __d_lookup(parent, name);
449 /* lockess __d_lookup may fail due to concurrent d_move()
450 * in some unrelated directory, so try with d_lookup
453 dentry = d_lookup(parent, name);
455 if (dentry && dentry->d_op && dentry->d_op->d_revalidate)
456 dentry = do_revalidate(dentry, nd);
462 * Short-cut version of permission(), for calling by
463 * path_walk(), when dcache lock is held. Combines parts
464 * of permission() and generic_permission(), and tests ONLY for
465 * MAY_EXEC permission.
467 * If appropriate, check DAC only. If not appropriate, or
468 * short-cut DAC fails, then call permission() to do more
469 * complete permission check.
471 static int exec_permission_lite(struct inode *inode,
472 struct nameidata *nd)
474 umode_t mode = inode->i_mode;
476 if (dx_barrier(inode))
478 if (inode->i_op && inode->i_op->permission)
481 if (current->fsuid == inode->i_uid)
483 else if (in_group_p(inode->i_gid))
489 if ((inode->i_mode & S_IXUGO) && capable(CAP_DAC_OVERRIDE))
492 if (S_ISDIR(inode->i_mode) && capable(CAP_DAC_OVERRIDE))
495 if (S_ISDIR(inode->i_mode) && capable(CAP_DAC_READ_SEARCH))
500 return security_inode_permission(inode, MAY_EXEC, nd);
504 * This is called when everything else fails, and we actually have
505 * to go to the low-level filesystem to find out what we should do..
507 * We get the directory semaphore, and after getting that we also
508 * make sure that nobody added the entry to the dcache in the meantime..
511 static struct dentry * real_lookup(struct dentry * parent, struct qstr * name, struct nameidata *nd)
513 struct dentry * result;
514 struct inode *dir = parent->d_inode;
516 mutex_lock(&dir->i_mutex);
518 * First re-do the cached lookup just in case it was created
519 * while we waited for the directory semaphore..
521 * FIXME! This could use version numbering or similar to
522 * avoid unnecessary cache lookups.
524 * The "dcache_lock" is purely to protect the RCU list walker
525 * from concurrent renames at this point (we mustn't get false
526 * negatives from the RCU list walk here, unlike the optimistic
529 * so doing d_lookup() (with seqlock), instead of lockfree __d_lookup
531 result = d_lookup(parent, name);
533 struct dentry * dentry = d_alloc(parent, name);
534 result = ERR_PTR(-ENOMEM);
536 result = dir->i_op->lookup(dir, dentry, nd);
542 mutex_unlock(&dir->i_mutex);
547 * Uhhuh! Nasty case: the cache was re-populated while
548 * we waited on the semaphore. Need to revalidate.
550 mutex_unlock(&dir->i_mutex);
551 if (result->d_op && result->d_op->d_revalidate) {
552 result = do_revalidate(result, nd);
554 result = ERR_PTR(-ENOENT);
559 static int __emul_lookup_dentry(const char *, struct nameidata *);
562 static __always_inline int
563 walk_init_root(const char *name, struct nameidata *nd)
565 struct fs_struct *fs = current->fs;
567 read_lock(&fs->lock);
568 if (fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
569 nd->mnt = mntget(fs->altrootmnt);
570 nd->dentry = dget(fs->altroot);
571 read_unlock(&fs->lock);
572 if (__emul_lookup_dentry(name,nd))
574 read_lock(&fs->lock);
576 nd->mnt = mntget(fs->rootmnt);
577 nd->dentry = dget(fs->root);
578 read_unlock(&fs->lock);
582 static __always_inline int __vfs_follow_link(struct nameidata *nd, const char *link)
591 if (!walk_init_root(link, nd))
592 /* weird __emul_prefix() stuff did it */
595 res = link_path_walk(link, nd);
597 if (nd->depth || res || nd->last_type!=LAST_NORM)
600 * If it is an iterative symlinks resolution in open_namei() we
601 * have to copy the last component. And all that crap because of
602 * bloody create() on broken symlinks. Furrfu...
605 if (unlikely(!name)) {
609 strcpy(name, nd->last.name);
610 nd->last.name = name;
614 return PTR_ERR(link);
617 static inline void dput_path(struct path *path, struct nameidata *nd)
620 if (path->mnt != nd->mnt)
624 static inline void path_to_nameidata(struct path *path, struct nameidata *nd)
627 if (nd->mnt != path->mnt)
630 nd->dentry = path->dentry;
633 static __always_inline int __do_follow_link(struct path *path, struct nameidata *nd)
637 struct dentry *dentry = path->dentry;
639 touch_atime(path->mnt, dentry);
640 nd_set_link(nd, NULL);
642 if (path->mnt != nd->mnt) {
643 path_to_nameidata(path, nd);
647 cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
648 error = PTR_ERR(cookie);
649 if (!IS_ERR(cookie)) {
650 char *s = nd_get_link(nd);
653 error = __vfs_follow_link(nd, s);
654 if (dentry->d_inode->i_op->put_link)
655 dentry->d_inode->i_op->put_link(dentry, nd, cookie);
664 * This limits recursive symlink follows to 8, while
665 * limiting consecutive symlinks to 40.
667 * Without that kind of total limit, nasty chains of consecutive
668 * symlinks can cause almost arbitrarily long lookups.
670 static inline int do_follow_link(struct path *path, struct nameidata *nd)
673 if (current->link_count >= MAX_NESTED_LINKS)
675 if (current->total_link_count >= 40)
677 BUG_ON(nd->depth >= MAX_NESTED_LINKS);
679 err = security_inode_follow_link(path->dentry, nd);
682 current->link_count++;
683 current->total_link_count++;
685 err = __do_follow_link(path, nd);
686 current->link_count--;
695 int follow_up(struct vfsmount **mnt, struct dentry **dentry)
697 struct vfsmount *parent;
698 struct dentry *mountpoint;
699 spin_lock(&vfsmount_lock);
700 parent=(*mnt)->mnt_parent;
701 if (parent == *mnt) {
702 spin_unlock(&vfsmount_lock);
706 mountpoint=dget((*mnt)->mnt_mountpoint);
707 spin_unlock(&vfsmount_lock);
709 *dentry = mountpoint;
715 /* no need for dcache_lock, as serialization is taken care in
718 static int __follow_mount(struct path *path)
721 while (d_mountpoint(path->dentry)) {
722 struct vfsmount *mounted = lookup_mnt(path->mnt, path->dentry);
729 path->dentry = dget(mounted->mnt_root);
735 static void follow_mount(struct vfsmount **mnt, struct dentry **dentry)
737 while (d_mountpoint(*dentry)) {
738 struct vfsmount *mounted = lookup_mnt(*mnt, *dentry);
744 *dentry = dget(mounted->mnt_root);
748 /* no need for dcache_lock, as serialization is taken care in
751 int follow_down(struct vfsmount **mnt, struct dentry **dentry)
753 struct vfsmount *mounted;
755 mounted = lookup_mnt(*mnt, *dentry);
760 *dentry = dget(mounted->mnt_root);
766 static __always_inline void follow_dotdot(struct nameidata *nd)
768 struct fs_struct *fs = current->fs;
771 struct vfsmount *parent;
772 struct dentry *old = nd->dentry;
774 read_lock(&fs->lock);
775 if (nd->dentry == fs->root &&
776 nd->mnt == fs->rootmnt) {
777 read_unlock(&fs->lock);
778 /* for sane '/' avoid follow_mount() */
781 read_unlock(&fs->lock);
782 spin_lock(&dcache_lock);
783 if (nd->dentry != nd->mnt->mnt_root) {
784 nd->dentry = dget(nd->dentry->d_parent);
785 spin_unlock(&dcache_lock);
789 spin_unlock(&dcache_lock);
790 spin_lock(&vfsmount_lock);
791 parent = nd->mnt->mnt_parent;
792 if (parent == nd->mnt) {
793 spin_unlock(&vfsmount_lock);
797 nd->dentry = dget(nd->mnt->mnt_mountpoint);
798 spin_unlock(&vfsmount_lock);
803 follow_mount(&nd->mnt, &nd->dentry);
807 * It's more convoluted than I'd like it to be, but... it's still fairly
808 * small and for now I'd prefer to have fast path as straight as possible.
809 * It _is_ time-critical.
811 static int do_lookup(struct nameidata *nd, struct qstr *name,
814 struct vfsmount *mnt = nd->mnt;
815 struct dentry *dentry = __d_lookup(nd->dentry, name);
820 if (dentry->d_op && dentry->d_op->d_revalidate)
821 goto need_revalidate;
822 inode = dentry->d_inode;
825 if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
826 struct proc_dir_entry *de = PDE(inode);
828 if (de && !vx_hide_check(0, de->vx_flags))
831 #ifdef CONFIG_VSERVER_FILESHARING
832 /* MEF: PlanetLab FS module assumes that any file that can be
833 * named (e.g., via a cross mount) is not hidden from another
834 * context or the admin context.
836 if (!dx_check(inode->i_tag, DX_HOSTID)) {
839 else /* do the following check */
841 if (!dx_check(inode->i_tag, DX_WATCH|DX_ADMIN|DX_HOSTID|DX_IDENT))
845 path->dentry = dentry;
846 __follow_mount(path);
849 vxwprintk(1, "xid=%d did lookup hidden %p[#%d,%lu] »%s«.",
850 vx_current_xid(), inode, inode->i_tag, inode->i_ino,
851 vxd_path(dentry, mnt));
856 dentry = real_lookup(nd->dentry, name, nd);
862 dentry = do_revalidate(dentry, nd);
870 return PTR_ERR(dentry);
875 * This is the basic name resolution function, turning a pathname into
876 * the final dentry. We expect 'base' to be positive and a directory.
878 * Returns 0 and nd will have valid dentry and mnt on success.
879 * Returns error and drops reference to input namei data on failure.
881 static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
886 unsigned int lookup_flags = nd->flags;
893 inode = nd->dentry->d_inode;
895 lookup_flags = LOOKUP_FOLLOW | (nd->flags & LOOKUP_CONTINUE);
897 /* At this point we know we have a real path component. */
903 nd->flags |= LOOKUP_CONTINUE;
904 err = exec_permission_lite(inode, nd);
906 err = vfs_permission(nd, MAY_EXEC);
911 c = *(const unsigned char *)name;
913 hash = init_name_hash();
916 hash = partial_name_hash(c, hash);
917 c = *(const unsigned char *)name;
918 } while (c && (c != '/'));
919 this.len = name - (const char *) this.name;
920 this.hash = end_name_hash(hash);
922 /* remove trailing slashes? */
925 while (*++name == '/');
927 goto last_with_slashes;
930 * "." and ".." are special - ".." especially so because it has
931 * to be able to know about the current root directory and
932 * parent relationships.
934 if (this.name[0] == '.') switch (this.len) {
938 if (this.name[1] != '.')
941 inode = nd->dentry->d_inode;
947 * See if the low-level filesystem might want
948 * to use its own hash..
950 if (nd->dentry->d_op && nd->dentry->d_op->d_hash) {
951 err = nd->dentry->d_op->d_hash(nd->dentry, &this);
955 /* This does the actual lookups.. */
956 err = do_lookup(nd, &this, &next);
961 inode = next.dentry->d_inode;
968 if (inode->i_op->follow_link) {
969 err = do_follow_link(&next, nd);
973 inode = nd->dentry->d_inode;
980 path_to_nameidata(&next, nd);
982 if (!inode->i_op->lookup)
985 /* here ends the main loop */
988 lookup_flags |= LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
990 /* Clear LOOKUP_CONTINUE iff it was previously unset */
991 nd->flags &= lookup_flags | ~LOOKUP_CONTINUE;
992 if (lookup_flags & LOOKUP_PARENT)
994 if (this.name[0] == '.') switch (this.len) {
998 if (this.name[1] != '.')
1001 inode = nd->dentry->d_inode;
1006 if (nd->dentry->d_op && nd->dentry->d_op->d_hash) {
1007 err = nd->dentry->d_op->d_hash(nd->dentry, &this);
1011 err = do_lookup(nd, &this, &next);
1014 inode = next.dentry->d_inode;
1015 if ((lookup_flags & LOOKUP_FOLLOW)
1016 && inode && inode->i_op && inode->i_op->follow_link) {
1017 err = do_follow_link(&next, nd);
1020 inode = nd->dentry->d_inode;
1022 path_to_nameidata(&next, nd);
1026 if (lookup_flags & LOOKUP_DIRECTORY) {
1028 if (!inode->i_op || !inode->i_op->lookup)
1034 nd->last_type = LAST_NORM;
1035 if (this.name[0] != '.')
1038 nd->last_type = LAST_DOT;
1039 else if (this.len == 2 && this.name[1] == '.')
1040 nd->last_type = LAST_DOTDOT;
1045 * We bypassed the ordinary revalidation routines.
1046 * We may need to check the cached dentry for staleness.
1048 if (nd->dentry && nd->dentry->d_sb &&
1049 (nd->dentry->d_sb->s_type->fs_flags & FS_REVAL_DOT)) {
1051 /* Note: we do not d_invalidate() */
1052 if (!nd->dentry->d_op->d_revalidate(nd->dentry, nd))
1058 dput_path(&next, nd);
1067 * Wrapper to retry pathname resolution whenever the underlying
1068 * file system returns an ESTALE.
1070 * Retry the whole path once, forcing real lookup requests
1071 * instead of relying on the dcache.
1073 int fastcall link_path_walk(const char *name, struct nameidata *nd)
1075 struct nameidata save = *nd;
1078 /* make sure the stuff we saved doesn't go away */
1082 result = __link_path_walk(name, nd);
1083 if (result == -ESTALE) {
1087 nd->flags |= LOOKUP_REVAL;
1088 result = __link_path_walk(name, nd);
1097 int fastcall path_walk(const char * name, struct nameidata *nd)
1099 current->total_link_count = 0;
1100 return link_path_walk(name, nd);
1104 * SMP-safe: Returns 1 and nd will have valid dentry and mnt, if
1105 * everything is done. Returns 0 and drops input nd, if lookup failed;
1107 static int __emul_lookup_dentry(const char *name, struct nameidata *nd)
1109 if (path_walk(name, nd))
1110 return 0; /* something went wrong... */
1112 if (!nd->dentry->d_inode || S_ISDIR(nd->dentry->d_inode->i_mode)) {
1113 struct dentry *old_dentry = nd->dentry;
1114 struct vfsmount *old_mnt = nd->mnt;
1115 struct qstr last = nd->last;
1116 int last_type = nd->last_type;
1117 struct fs_struct *fs = current->fs;
1120 * NAME was not found in alternate root or it's a directory.
1121 * Try to find it in the normal root:
1123 nd->last_type = LAST_ROOT;
1124 read_lock(&fs->lock);
1125 nd->mnt = mntget(fs->rootmnt);
1126 nd->dentry = dget(fs->root);
1127 read_unlock(&fs->lock);
1128 if (path_walk(name, nd) == 0) {
1129 if (nd->dentry->d_inode) {
1136 nd->dentry = old_dentry;
1139 nd->last_type = last_type;
1144 void set_fs_altroot(void)
1146 char *emul = __emul_prefix();
1147 struct nameidata nd;
1148 struct vfsmount *mnt = NULL, *oldmnt;
1149 struct dentry *dentry = NULL, *olddentry;
1151 struct fs_struct *fs = current->fs;
1155 err = path_lookup(emul, LOOKUP_FOLLOW|LOOKUP_DIRECTORY|LOOKUP_NOALT, &nd);
1161 write_lock(&fs->lock);
1162 oldmnt = fs->altrootmnt;
1163 olddentry = fs->altroot;
1164 fs->altrootmnt = mnt;
1165 fs->altroot = dentry;
1166 write_unlock(&fs->lock);
1173 /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
1174 static int fastcall do_path_lookup(int dfd, const char *name,
1175 unsigned int flags, struct nameidata *nd)
1180 struct fs_struct *fs = current->fs;
1182 nd->last_type = LAST_ROOT; /* if there are only slashes... */
1187 read_lock(&fs->lock);
1188 if (fs->altroot && !(nd->flags & LOOKUP_NOALT)) {
1189 nd->mnt = mntget(fs->altrootmnt);
1190 nd->dentry = dget(fs->altroot);
1191 read_unlock(&fs->lock);
1192 if (__emul_lookup_dentry(name,nd))
1193 goto out; /* found in altroot */
1194 read_lock(&fs->lock);
1196 nd->mnt = mntget(fs->rootmnt);
1197 nd->dentry = dget(fs->root);
1198 read_unlock(&fs->lock);
1199 } else if (dfd == AT_FDCWD) {
1200 read_lock(&fs->lock);
1201 nd->mnt = mntget(fs->pwdmnt);
1202 nd->dentry = dget(fs->pwd);
1203 read_unlock(&fs->lock);
1205 struct dentry *dentry;
1207 file = fget_light(dfd, &fput_needed);
1212 dentry = file->f_path.dentry;
1215 if (!S_ISDIR(dentry->d_inode->i_mode))
1218 retval = file_permission(file, MAY_EXEC);
1222 nd->mnt = mntget(file->f_path.mnt);
1223 nd->dentry = dget(dentry);
1225 fput_light(file, fput_needed);
1227 current->total_link_count = 0;
1228 retval = link_path_walk(name, nd);
1230 if (likely(retval == 0)) {
1231 if (unlikely(!audit_dummy_context() && nd && nd->dentry &&
1232 nd->dentry->d_inode))
1233 audit_inode(name, nd->dentry->d_inode);
1239 fput_light(file, fput_needed);
1243 int fastcall path_lookup(const char *name, unsigned int flags,
1244 struct nameidata *nd)
1246 return do_path_lookup(AT_FDCWD, name, flags, nd);
1249 static int __path_lookup_intent_open(int dfd, const char *name,
1250 unsigned int lookup_flags, struct nameidata *nd,
1251 int open_flags, int create_mode)
1253 struct file *filp = get_empty_filp();
1258 nd->intent.open.file = filp;
1259 nd->intent.open.flags = open_flags;
1260 nd->intent.open.create_mode = create_mode;
1261 err = do_path_lookup(dfd, name, lookup_flags|LOOKUP_OPEN, nd);
1262 if (IS_ERR(nd->intent.open.file)) {
1264 err = PTR_ERR(nd->intent.open.file);
1267 } else if (err != 0)
1268 release_open_intent(nd);
1273 * path_lookup_open - lookup a file path with open intent
1274 * @dfd: the directory to use as base, or AT_FDCWD
1275 * @name: pointer to file name
1276 * @lookup_flags: lookup intent flags
1277 * @nd: pointer to nameidata
1278 * @open_flags: open intent flags
1280 int path_lookup_open(int dfd, const char *name, unsigned int lookup_flags,
1281 struct nameidata *nd, int open_flags)
1283 return __path_lookup_intent_open(dfd, name, lookup_flags, nd,
1288 * path_lookup_create - lookup a file path with open + create intent
1289 * @dfd: the directory to use as base, or AT_FDCWD
1290 * @name: pointer to file name
1291 * @lookup_flags: lookup intent flags
1292 * @nd: pointer to nameidata
1293 * @open_flags: open intent flags
1294 * @create_mode: create intent flags
1296 static int path_lookup_create(int dfd, const char *name,
1297 unsigned int lookup_flags, struct nameidata *nd,
1298 int open_flags, int create_mode)
1300 return __path_lookup_intent_open(dfd, name, lookup_flags|LOOKUP_CREATE,
1301 nd, open_flags, create_mode);
1304 int __user_path_lookup_open(const char __user *name, unsigned int lookup_flags,
1305 struct nameidata *nd, int open_flags)
1307 char *tmp = getname(name);
1308 int err = PTR_ERR(tmp);
1311 err = __path_lookup_intent_open(AT_FDCWD, tmp, lookup_flags, nd, open_flags, 0);
1318 * Restricted form of lookup. Doesn't follow links, single-component only,
1319 * needs parent already locked. Doesn't follow mounts.
1322 static struct dentry * __lookup_hash(struct qstr *name, struct dentry * base, struct nameidata *nd)
1324 struct dentry * dentry;
1325 struct inode *inode;
1328 inode = base->d_inode;
1329 err = permission(inode, MAY_EXEC, nd);
1330 dentry = ERR_PTR(err);
1335 * See if the low-level filesystem might want
1336 * to use its own hash..
1338 if (base->d_op && base->d_op->d_hash) {
1339 err = base->d_op->d_hash(base, name);
1340 dentry = ERR_PTR(err);
1345 dentry = cached_lookup(base, name, nd);
1347 struct dentry *new = d_alloc(base, name);
1348 dentry = ERR_PTR(-ENOMEM);
1351 dentry = inode->i_op->lookup(inode, new, nd);
1361 static struct dentry *lookup_hash(struct nameidata *nd)
1363 return __lookup_hash(&nd->last, nd->dentry, nd);
1367 struct dentry * lookup_one_len(const char * name, struct dentry * base, int len)
1378 hash = init_name_hash();
1380 c = *(const unsigned char *)name++;
1381 if (c == '/' || c == '\0')
1383 hash = partial_name_hash(c, hash);
1385 this.hash = end_name_hash(hash);
1387 return __lookup_hash(&this, base, NULL);
1389 return ERR_PTR(-EACCES);
1395 * is used by most simple commands to get the inode of a specified name.
1396 * Open, link etc use their own routines, but this is enough for things
1399 * namei exists in two versions: namei/lnamei. The only difference is
1400 * that namei follows links, while lnamei does not.
1403 int fastcall __user_walk_fd(int dfd, const char __user *name, unsigned flags,
1404 struct nameidata *nd)
1406 char *tmp = getname(name);
1407 int err = PTR_ERR(tmp);
1410 err = do_path_lookup(dfd, tmp, flags, nd);
1416 int fastcall __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
1418 return __user_walk_fd(AT_FDCWD, name, flags, nd);
1422 * It's inline, so penalty for filesystems that don't use sticky bit is
1425 static inline int check_sticky(struct inode *dir, struct inode *inode)
1427 if (!(dir->i_mode & S_ISVTX))
1429 if (inode->i_uid == current->fsuid)
1431 if (dir->i_uid == current->fsuid)
1433 return !capable(CAP_FOWNER);
1437 * Check whether we can remove a link victim from directory dir, check
1438 * whether the type of victim is right.
1439 * 1. We can't do it if dir is read-only (done in permission())
1440 * 2. We should have write and exec permissions on dir
1441 * 3. We can't remove anything from append-only dir
1442 * 4. We can't do anything with immutable dir (done in permission())
1443 * 5. If the sticky bit on dir is set we should either
1444 * a. be owner of dir, or
1445 * b. be owner of victim, or
1446 * c. have CAP_FOWNER capability
1447 * 6. If the victim is append-only or immutable we can't do antyhing with
1448 * links pointing to it.
1449 * 7. If we were asked to remove a directory and victim isn't one - ENOTDIR.
1450 * 8. If we were asked to remove a non-directory and victim isn't one - EISDIR.
1451 * 9. We can't remove a root or mountpoint.
1452 * 10. We don't allow removal of NFS sillyrenamed files; it's handled by
1453 * nfs_async_unlink().
1455 static int may_delete(struct inode *dir, struct dentry *victim,
1456 int isdir, struct nameidata *nd)
1460 if (!victim->d_inode)
1463 BUG_ON(victim->d_parent->d_inode != dir);
1464 audit_inode_child(victim->d_name.name, victim->d_inode, dir);
1466 error = permission(dir,MAY_WRITE | MAY_EXEC, nd);
1471 if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
1472 IS_IXORUNLINK(victim->d_inode))
1475 if (!S_ISDIR(victim->d_inode->i_mode))
1477 if (IS_ROOT(victim))
1479 } else if (S_ISDIR(victim->d_inode->i_mode))
1481 if (IS_DEADDIR(dir))
1483 if (victim->d_flags & DCACHE_NFSFS_RENAMED)
1488 /* Check whether we can create an object with dentry child in directory
1490 * 1. We can't do it if child already exists (open has special treatment for
1491 * this case, but since we are inlined it's OK)
1492 * 2. We can't do it if dir is read-only (done in permission())
1493 * 3. We should have write and exec permissions on dir
1494 * 4. We can't do it if dir is immutable (done in permission())
1496 static inline int may_create(struct inode *dir, struct dentry *child,
1497 struct nameidata *nd)
1501 if (IS_DEADDIR(dir))
1503 return permission(dir,MAY_WRITE | MAY_EXEC, nd);
1507 * O_DIRECTORY translates into forcing a directory lookup.
1509 static inline int lookup_flags(unsigned int f)
1511 unsigned long retval = LOOKUP_FOLLOW;
1514 retval &= ~LOOKUP_FOLLOW;
1516 if (f & O_DIRECTORY)
1517 retval |= LOOKUP_DIRECTORY;
1523 * p1 and p2 should be directories on the same fs.
1525 struct dentry *lock_rename(struct dentry *p1, struct dentry *p2)
1530 mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_PARENT);
1534 mutex_lock(&p1->d_inode->i_sb->s_vfs_rename_mutex);
1536 for (p = p1; p->d_parent != p; p = p->d_parent) {
1537 if (p->d_parent == p2) {
1538 mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_PARENT);
1539 mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_CHILD);
1544 for (p = p2; p->d_parent != p; p = p->d_parent) {
1545 if (p->d_parent == p1) {
1546 mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_PARENT);
1547 mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_CHILD);
1552 mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_PARENT);
1553 mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_CHILD);
1557 void unlock_rename(struct dentry *p1, struct dentry *p2)
1559 mutex_unlock(&p1->d_inode->i_mutex);
1561 mutex_unlock(&p2->d_inode->i_mutex);
1562 mutex_unlock(&p1->d_inode->i_sb->s_vfs_rename_mutex);
1566 int vfs_create(struct inode *dir, struct dentry *dentry, int mode,
1567 struct nameidata *nd)
1569 int error = may_create(dir, dentry, nd);
1574 if (!dir->i_op || !dir->i_op->create)
1575 return -EACCES; /* shouldn't it be ENOSYS? */
1578 error = security_inode_create(dir, dentry, mode);
1582 error = dir->i_op->create(dir, dentry, mode, nd);
1584 fsnotify_create(dir, dentry);
1588 int may_open(struct nameidata *nd, int acc_mode, int flag)
1590 struct dentry *dentry = nd->dentry;
1591 struct inode *inode = dentry->d_inode;
1597 if (S_ISLNK(inode->i_mode))
1600 if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE))
1603 #ifdef CONFIG_VSERVER_COWBL
1604 if (IS_COW(inode) && (flag & FMODE_WRITE)) {
1605 if (IS_COW_LINK(inode))
1607 inode->i_flags &= ~(S_IUNLINK|S_IMMUTABLE);
1608 mark_inode_dirty(inode);
1611 error = vfs_permission(nd, acc_mode);
1616 * FIFO's, sockets and device files are special: they don't
1617 * actually live on the filesystem itself, and as such you
1618 * can write to them even if the filesystem is read-only.
1620 if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
1622 } else if (S_ISBLK(inode->i_mode) || S_ISCHR(inode->i_mode)) {
1623 if (nd->mnt->mnt_flags & MNT_NODEV)
1627 } else if ((IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
1628 && (flag & FMODE_WRITE))
1631 * An append-only file must be opened in append mode for writing.
1633 if (IS_APPEND(inode)) {
1634 if ((flag & FMODE_WRITE) && !(flag & O_APPEND))
1640 /* O_NOATIME can only be set by the owner or superuser */
1641 if (flag & O_NOATIME)
1642 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1646 * Ensure there are no outstanding leases on the file.
1648 error = break_lease(inode, flag);
1652 if (flag & O_TRUNC) {
1653 error = get_write_access(inode);
1658 * Refuse to truncate files with mandatory locks held on them.
1660 error = locks_verify_locked(inode);
1664 error = do_truncate(dentry, 0, ATTR_MTIME|ATTR_CTIME, NULL);
1666 put_write_access(inode);
1670 if (flag & FMODE_WRITE)
1676 static int open_namei_create(struct nameidata *nd, struct path *path,
1680 struct dentry *dir = nd->dentry;
1682 if (!IS_POSIXACL(dir->d_inode))
1683 mode &= ~current->fs->umask;
1684 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
1685 mutex_unlock(&dir->d_inode->i_mutex);
1687 nd->dentry = path->dentry;
1690 /* Don't check for write permission, don't truncate */
1691 return may_open(nd, 0, flag & ~O_TRUNC);
1697 * namei for open - this is in fact almost the whole open-routine.
1699 * Note that the low bits of "flag" aren't the same as in the open
1700 * system call - they are 00 - no permissions needed
1701 * 01 - read permission needed
1702 * 10 - write permission needed
1703 * 11 - read/write permissions needed
1704 * which is a lot more logical, and also allows the "no perm" needed
1705 * for symlinks (where the permissions are checked later).
1708 int open_namei(int dfd, const char *pathname, int flag,
1709 int mode, struct nameidata *nd)
1711 int acc_mode, error;
1716 #ifdef CONFIG_VSERVER_COWBL
1721 acc_mode = ACC_MODE(flag);
1723 /* O_TRUNC implies we need access checks for write permissions */
1725 acc_mode |= MAY_WRITE;
1727 /* Allow the LSM permission hook to distinguish append
1728 access from general write access. */
1729 if (flag & O_APPEND)
1730 acc_mode |= MAY_APPEND;
1733 * The simplest case - just a plain lookup.
1735 if (!(flag & O_CREAT)) {
1736 error = path_lookup_open(dfd, pathname, lookup_flags(flag),
1744 * Create - we need to know the parent.
1746 error = path_lookup_create(dfd,pathname,LOOKUP_PARENT,nd,flag,mode);
1751 * We have the parent and last component. First of all, check
1752 * that we are not asked to creat(2) an obvious directory - that
1756 if (nd->last_type != LAST_NORM || nd->last.name[nd->last.len])
1760 nd->flags &= ~LOOKUP_PARENT;
1761 mutex_lock(&dir->d_inode->i_mutex);
1762 path.dentry = lookup_hash(nd);
1766 error = PTR_ERR(path.dentry);
1767 if (IS_ERR(path.dentry)) {
1768 mutex_unlock(&dir->d_inode->i_mutex);
1772 if (IS_ERR(nd->intent.open.file)) {
1773 mutex_unlock(&dir->d_inode->i_mutex);
1774 error = PTR_ERR(nd->intent.open.file);
1778 /* Negative dentry, just create the file */
1779 if (!path.dentry->d_inode) {
1780 error = open_namei_create(nd, &path, flag, mode);
1787 * It already exists.
1789 mutex_unlock(&dir->d_inode->i_mutex);
1790 audit_inode_update(path.dentry->d_inode);
1796 if (__follow_mount(&path)) {
1798 if (flag & O_NOFOLLOW)
1803 if (!path.dentry->d_inode)
1805 if (path.dentry->d_inode->i_op && path.dentry->d_inode->i_op->follow_link)
1808 path_to_nameidata(&path, nd);
1810 if (path.dentry->d_inode && S_ISDIR(path.dentry->d_inode->i_mode))
1813 error = may_open(nd, acc_mode, flag);
1814 #ifdef CONFIG_VSERVER_COWBL
1815 if (error == -EMLINK) {
1816 struct dentry *dentry;
1817 dentry = cow_break_link(pathname);
1818 if (IS_ERR(dentry)) {
1819 error = PTR_ERR(dentry);
1823 release_open_intent(nd);
1835 dput_path(&path, nd);
1837 if (!IS_ERR(nd->intent.open.file))
1838 release_open_intent(nd);
1844 if (flag & O_NOFOLLOW)
1847 * This is subtle. Instead of calling do_follow_link() we do the
1848 * thing by hands. The reason is that this way we have zero link_count
1849 * and path_walk() (called from ->follow_link) honoring LOOKUP_PARENT.
1850 * After that we have the parent and last component, i.e.
1851 * we are in the same situation as after the first path_walk().
1852 * Well, almost - if the last component is normal we get its copy
1853 * stored in nd->last.name and we will have to putname() it when we
1854 * are done. Procfs-like symlinks just set LAST_BIND.
1856 nd->flags |= LOOKUP_PARENT;
1857 error = security_inode_follow_link(path.dentry, nd);
1860 error = __do_follow_link(&path, nd);
1862 /* Does someone understand code flow here? Or it is only
1863 * me so stupid? Anathema to whoever designed this non-sense
1864 * with "intent.open".
1866 release_open_intent(nd);
1869 nd->flags &= ~LOOKUP_PARENT;
1870 if (nd->last_type == LAST_BIND)
1873 if (nd->last_type != LAST_NORM)
1875 if (nd->last.name[nd->last.len]) {
1876 __putname(nd->last.name);
1881 __putname(nd->last.name);
1885 mutex_lock(&dir->d_inode->i_mutex);
1886 path.dentry = lookup_hash(nd);
1888 __putname(nd->last.name);
1893 * lookup_create - lookup a dentry, creating it if it doesn't exist
1894 * @nd: nameidata info
1895 * @is_dir: directory flag
1897 * Simple function to lookup and return a dentry and create it
1898 * if it doesn't exist. Is SMP-safe.
1900 * Returns with nd->dentry->d_inode->i_mutex locked.
1902 struct dentry *lookup_create(struct nameidata *nd, int is_dir)
1904 struct dentry *dentry = ERR_PTR(-EEXIST);
1906 mutex_lock_nested(&nd->dentry->d_inode->i_mutex, I_MUTEX_PARENT);
1908 * Yucky last component or no last component at all?
1909 * (foo/., foo/.., /////)
1911 if (nd->last_type != LAST_NORM)
1913 nd->flags &= ~LOOKUP_PARENT;
1914 nd->flags |= LOOKUP_CREATE;
1915 nd->intent.open.flags = O_EXCL;
1918 * Do the final lookup.
1920 dentry = lookup_hash(nd);
1925 * Special case - lookup gave negative, but... we had foo/bar/
1926 * From the vfs_mknod() POV we just have a negative dentry -
1927 * all is fine. Let's be bastards - you had / on the end, you've
1928 * been asking for (non-existent) directory. -ENOENT for you.
1930 if (!is_dir && nd->last.name[nd->last.len] && !dentry->d_inode)
1935 dentry = ERR_PTR(-ENOENT);
1939 EXPORT_SYMBOL_GPL(lookup_create);
1941 int vfs_mknod(struct inode *dir, struct dentry *dentry,
1942 int mode, dev_t dev, struct nameidata *nd)
1944 int error = may_create(dir, dentry, nd);
1949 if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
1952 if (!dir->i_op || !dir->i_op->mknod)
1955 error = security_inode_mknod(dir, dentry, mode, dev);
1960 error = dir->i_op->mknod(dir, dentry, mode, dev);
1962 fsnotify_create(dir, dentry);
1966 asmlinkage long sys_mknodat(int dfd, const char __user *filename, int mode,
1971 struct dentry * dentry;
1972 struct nameidata nd;
1976 tmp = getname(filename);
1978 return PTR_ERR(tmp);
1980 error = do_path_lookup(dfd, tmp, LOOKUP_PARENT, &nd);
1983 dentry = lookup_create(&nd, 0);
1984 error = PTR_ERR(dentry);
1986 if (!IS_POSIXACL(nd.dentry->d_inode))
1987 mode &= ~current->fs->umask;
1988 if (!IS_ERR(dentry)) {
1989 switch (mode & S_IFMT) {
1990 case 0: case S_IFREG:
1991 error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
1993 case S_IFCHR: case S_IFBLK:
1994 error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
1995 new_decode_dev(dev), &nd);
1997 case S_IFIFO: case S_IFSOCK:
1998 error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
2009 mutex_unlock(&nd.dentry->d_inode->i_mutex);
2017 asmlinkage long sys_mknod(const char __user *filename, int mode, unsigned dev)
2019 return sys_mknodat(AT_FDCWD, filename, mode, dev);
2022 int vfs_mkdir(struct inode *dir, struct dentry *dentry,
2023 int mode, struct nameidata *nd)
2025 int error = may_create(dir, dentry, nd);
2030 if (!dir->i_op || !dir->i_op->mkdir)
2033 mode &= (S_IRWXUGO|S_ISVTX);
2034 error = security_inode_mkdir(dir, dentry, mode);
2039 error = dir->i_op->mkdir(dir, dentry, mode);
2041 fsnotify_mkdir(dir, dentry);
2045 asmlinkage long sys_mkdirat(int dfd, const char __user *pathname, int mode)
2049 struct dentry *dentry;
2050 struct nameidata nd;
2052 tmp = getname(pathname);
2053 error = PTR_ERR(tmp);
2057 error = do_path_lookup(dfd, tmp, LOOKUP_PARENT, &nd);
2060 dentry = lookup_create(&nd, 1);
2061 error = PTR_ERR(dentry);
2065 if (!IS_POSIXACL(nd.dentry->d_inode))
2066 mode &= ~current->fs->umask;
2067 error = vfs_mkdir(nd.dentry->d_inode, dentry, mode, &nd);
2070 mutex_unlock(&nd.dentry->d_inode->i_mutex);
2078 asmlinkage long sys_mkdir(const char __user *pathname, int mode)
2080 return sys_mkdirat(AT_FDCWD, pathname, mode);
2084 * We try to drop the dentry early: we should have
2085 * a usage count of 2 if we're the only user of this
2086 * dentry, and if that is true (possibly after pruning
2087 * the dcache), then we drop the dentry now.
2089 * A low-level filesystem can, if it choses, legally
2092 * if (!d_unhashed(dentry))
2095 * if it cannot handle the case of removing a directory
2096 * that is still in use by something else..
2098 void dentry_unhash(struct dentry *dentry)
2101 shrink_dcache_parent(dentry);
2102 spin_lock(&dcache_lock);
2103 spin_lock(&dentry->d_lock);
2104 if (atomic_read(&dentry->d_count) == 2)
2106 spin_unlock(&dentry->d_lock);
2107 spin_unlock(&dcache_lock);
2110 int vfs_rmdir(struct inode *dir, struct dentry *dentry,
2111 struct nameidata *nd)
2113 int error = may_delete(dir, dentry, 1, nd);
2118 if (!dir->i_op || !dir->i_op->rmdir)
2123 mutex_lock(&dentry->d_inode->i_mutex);
2124 dentry_unhash(dentry);
2125 if (d_mountpoint(dentry))
2128 error = security_inode_rmdir(dir, dentry);
2130 error = dir->i_op->rmdir(dir, dentry);
2132 dentry->d_inode->i_flags |= S_DEAD;
2135 mutex_unlock(&dentry->d_inode->i_mutex);
2144 static long do_rmdir(int dfd, const char __user *pathname)
2148 struct dentry *dentry;
2149 struct nameidata nd;
2151 name = getname(pathname);
2153 return PTR_ERR(name);
2155 error = do_path_lookup(dfd, name, LOOKUP_PARENT, &nd);
2159 switch(nd.last_type) {
2170 mutex_lock_nested(&nd.dentry->d_inode->i_mutex, I_MUTEX_PARENT);
2171 dentry = lookup_hash(&nd);
2172 error = PTR_ERR(dentry);
2175 error = vfs_rmdir(nd.dentry->d_inode, dentry, &nd);
2178 mutex_unlock(&nd.dentry->d_inode->i_mutex);
2186 asmlinkage long sys_rmdir(const char __user *pathname)
2188 return do_rmdir(AT_FDCWD, pathname);
2191 int vfs_unlink(struct inode *dir, struct dentry *dentry,
2192 struct nameidata *nd)
2194 int error = may_delete(dir, dentry, 0, nd);
2199 if (!dir->i_op || !dir->i_op->unlink)
2204 mutex_lock(&dentry->d_inode->i_mutex);
2205 if (d_mountpoint(dentry))
2208 error = security_inode_unlink(dir, dentry);
2210 error = dir->i_op->unlink(dir, dentry);
2212 mutex_unlock(&dentry->d_inode->i_mutex);
2214 /* We don't d_delete() NFS sillyrenamed files--they still exist. */
2215 if (!error && !(dentry->d_flags & DCACHE_NFSFS_RENAMED)) {
2223 * Make sure that the actual truncation of the file will occur outside its
2224 * directory's i_mutex. Truncate can take a long time if there is a lot of
2225 * writeout happening, and we don't want to prevent access to the directory
2226 * while waiting on the I/O.
2228 static long do_unlinkat(int dfd, const char __user *pathname)
2232 struct dentry *dentry;
2233 struct nameidata nd;
2234 struct inode *inode = NULL;
2236 name = getname(pathname);
2238 return PTR_ERR(name);
2240 error = do_path_lookup(dfd, name, LOOKUP_PARENT, &nd);
2244 if (nd.last_type != LAST_NORM)
2246 mutex_lock_nested(&nd.dentry->d_inode->i_mutex, I_MUTEX_PARENT);
2247 dentry = lookup_hash(&nd);
2248 error = PTR_ERR(dentry);
2249 if (!IS_ERR(dentry)) {
2250 /* Why not before? Because we want correct error value */
2251 if (nd.last.name[nd.last.len])
2253 inode = dentry->d_inode;
2255 atomic_inc(&inode->i_count);
2256 error = vfs_unlink(nd.dentry->d_inode, dentry, &nd);
2260 mutex_unlock(&nd.dentry->d_inode->i_mutex);
2262 iput(inode); /* truncate the inode here */
2270 error = !dentry->d_inode ? -ENOENT :
2271 S_ISDIR(dentry->d_inode->i_mode) ? -EISDIR : -ENOTDIR;
2275 asmlinkage long sys_unlinkat(int dfd, const char __user *pathname, int flag)
2277 if ((flag & ~AT_REMOVEDIR) != 0)
2280 if (flag & AT_REMOVEDIR)
2281 return do_rmdir(dfd, pathname);
2283 return do_unlinkat(dfd, pathname);
2286 asmlinkage long sys_unlink(const char __user *pathname)
2288 return do_unlinkat(AT_FDCWD, pathname);
2291 int vfs_symlink(struct inode *dir, struct dentry *dentry,
2292 const char *oldname, int mode, struct nameidata *nd)
2294 int error = may_create(dir, dentry, nd);
2299 if (!dir->i_op || !dir->i_op->symlink)
2302 error = security_inode_symlink(dir, dentry, oldname);
2307 error = dir->i_op->symlink(dir, dentry, oldname);
2309 fsnotify_create(dir, dentry);
2313 asmlinkage long sys_symlinkat(const char __user *oldname,
2314 int newdfd, const char __user *newname)
2319 struct dentry *dentry;
2320 struct nameidata nd;
2322 from = getname(oldname);
2324 return PTR_ERR(from);
2325 to = getname(newname);
2326 error = PTR_ERR(to);
2330 error = do_path_lookup(newdfd, to, LOOKUP_PARENT, &nd);
2333 dentry = lookup_create(&nd, 0);
2334 error = PTR_ERR(dentry);
2338 error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO, &nd);
2341 mutex_unlock(&nd.dentry->d_inode->i_mutex);
2350 asmlinkage long sys_symlink(const char __user *oldname, const char __user *newname)
2352 return sys_symlinkat(oldname, AT_FDCWD, newname);
2355 int vfs_link(struct dentry *old_dentry, struct inode *dir,
2356 struct dentry *new_dentry, struct nameidata *nd)
2358 struct inode *inode = old_dentry->d_inode;
2364 error = may_create(dir, new_dentry, nd);
2368 if (dir->i_sb != inode->i_sb)
2372 * A link to an append-only or immutable file cannot be created.
2374 if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2376 if (!dir->i_op || !dir->i_op->link)
2378 if (S_ISDIR(old_dentry->d_inode->i_mode))
2381 error = security_inode_link(old_dentry, dir, new_dentry);
2385 mutex_lock(&old_dentry->d_inode->i_mutex);
2387 error = dir->i_op->link(old_dentry, dir, new_dentry);
2388 mutex_unlock(&old_dentry->d_inode->i_mutex);
2390 fsnotify_create(dir, new_dentry);
2395 * Hardlinks are often used in delicate situations. We avoid
2396 * security-related surprises by not following symlinks on the
2399 * We don't follow them on the oldname either to be compatible
2400 * with linux 2.0, and to avoid hard-linking to directories
2401 * and other special files. --ADM
2403 asmlinkage long sys_linkat(int olddfd, const char __user *oldname,
2404 int newdfd, const char __user *newname,
2407 struct dentry *new_dentry;
2408 struct nameidata nd, old_nd;
2412 if ((flags & ~AT_SYMLINK_FOLLOW) != 0)
2415 to = getname(newname);
2419 error = __user_walk_fd(olddfd, oldname,
2420 flags & AT_SYMLINK_FOLLOW ? LOOKUP_FOLLOW : 0,
2424 error = do_path_lookup(newdfd, to, LOOKUP_PARENT, &nd);
2428 * We allow hard-links to be created to a bind-mount as long
2429 * as the bind-mount is not read-only. Checking for cross-dev
2430 * links is subsumed by the superblock check in vfs_link().
2433 if (MNT_IS_RDONLY(old_nd.mnt))
2435 new_dentry = lookup_create(&nd, 0);
2436 error = PTR_ERR(new_dentry);
2437 if (IS_ERR(new_dentry))
2439 error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry, &nd);
2442 mutex_unlock(&nd.dentry->d_inode->i_mutex);
2446 path_release(&old_nd);
2453 asmlinkage long sys_link(const char __user *oldname, const char __user *newname)
2455 return sys_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
2459 * The worst of all namespace operations - renaming directory. "Perverted"
2460 * doesn't even start to describe it. Somebody in UCB had a heck of a trip...
2462 * a) we can get into loop creation. Check is done in is_subdir().
2463 * b) race potential - two innocent renames can create a loop together.
2464 * That's where 4.4 screws up. Current fix: serialization on
2465 * sb->s_vfs_rename_mutex. We might be more accurate, but that's another
2467 * c) we have to lock _three_ objects - parents and victim (if it exists).
2468 * And that - after we got ->i_mutex on parents (until then we don't know
2469 * whether the target exists). Solution: try to be smart with locking
2470 * order for inodes. We rely on the fact that tree topology may change
2471 * only under ->s_vfs_rename_mutex _and_ that parent of the object we
2472 * move will be locked. Thus we can rank directories by the tree
2473 * (ancestors first) and rank all non-directories after them.
2474 * That works since everybody except rename does "lock parent, lookup,
2475 * lock child" and rename is under ->s_vfs_rename_mutex.
2476 * HOWEVER, it relies on the assumption that any object with ->lookup()
2477 * has no more than 1 dentry. If "hybrid" objects will ever appear,
2478 * we'd better make sure that there's no link(2) for them.
2479 * d) some filesystems don't support opened-but-unlinked directories,
2480 * either because of layout or because they are not ready to deal with
2481 * all cases correctly. The latter will be fixed (taking this sort of
2482 * stuff into VFS), but the former is not going away. Solution: the same
2483 * trick as in rmdir().
2484 * e) conversion from fhandle to dentry may come in the wrong moment - when
2485 * we are removing the target. Solution: we will have to grab ->i_mutex
2486 * in the fhandle_to_dentry code. [FIXME - current nfsfh.c relies on
2487 * ->i_mutex on parents, which works but leads to some truely excessive
2490 static int vfs_rename_dir(struct inode *old_dir, struct dentry *old_dentry,
2491 struct inode *new_dir, struct dentry *new_dentry)
2494 struct inode *target;
2497 * If we are going to change the parent - check write permissions,
2498 * we'll need to flip '..'.
2500 if (new_dir != old_dir) {
2501 error = permission(old_dentry->d_inode, MAY_WRITE, NULL);
2506 error = security_inode_rename(old_dir, old_dentry, new_dir, new_dentry);
2510 target = new_dentry->d_inode;
2512 mutex_lock(&target->i_mutex);
2513 dentry_unhash(new_dentry);
2515 if (d_mountpoint(old_dentry)||d_mountpoint(new_dentry))
2518 error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry);
2521 target->i_flags |= S_DEAD;
2522 mutex_unlock(&target->i_mutex);
2523 if (d_unhashed(new_dentry))
2524 d_rehash(new_dentry);
2528 if (!(old_dir->i_sb->s_type->fs_flags & FS_RENAME_DOES_D_MOVE))
2529 d_move(old_dentry,new_dentry);
2533 static int vfs_rename_other(struct inode *old_dir, struct dentry *old_dentry,
2534 struct inode *new_dir, struct dentry *new_dentry)
2536 struct inode *target;
2539 error = security_inode_rename(old_dir, old_dentry, new_dir, new_dentry);
2544 target = new_dentry->d_inode;
2546 mutex_lock(&target->i_mutex);
2547 if (d_mountpoint(old_dentry)||d_mountpoint(new_dentry))
2550 error = old_dir->i_op->rename(old_dir, old_dentry, new_dir, new_dentry);
2552 if (!(old_dir->i_sb->s_type->fs_flags & FS_RENAME_DOES_D_MOVE))
2553 d_move(old_dentry, new_dentry);
2556 mutex_unlock(&target->i_mutex);
2561 int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
2562 struct inode *new_dir, struct dentry *new_dentry)
2565 int is_dir = S_ISDIR(old_dentry->d_inode->i_mode);
2566 const char *old_name;
2568 if (old_dentry->d_inode == new_dentry->d_inode)
2571 error = may_delete(old_dir, old_dentry, is_dir, NULL);
2575 if (!new_dentry->d_inode)
2576 error = may_create(new_dir, new_dentry, NULL);
2578 error = may_delete(new_dir, new_dentry, is_dir, NULL);
2582 if (!old_dir->i_op || !old_dir->i_op->rename)
2585 DQUOT_INIT(old_dir);
2586 DQUOT_INIT(new_dir);
2588 old_name = fsnotify_oldname_init(old_dentry->d_name.name);
2591 error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry);
2593 error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
2595 const char *new_name = old_dentry->d_name.name;
2596 fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir,
2597 new_dentry->d_inode, old_dentry->d_inode);
2599 fsnotify_oldname_free(old_name);
2604 static int do_rename(int olddfd, const char *oldname,
2605 int newdfd, const char *newname)
2608 struct dentry * old_dir, * new_dir;
2609 struct dentry * old_dentry, *new_dentry;
2610 struct dentry * trap;
2611 struct nameidata oldnd, newnd;
2613 error = do_path_lookup(olddfd, oldname, LOOKUP_PARENT, &oldnd);
2617 error = do_path_lookup(newdfd, newname, LOOKUP_PARENT, &newnd);
2622 if (oldnd.mnt != newnd.mnt)
2625 old_dir = oldnd.dentry;
2627 if (oldnd.last_type != LAST_NORM)
2630 new_dir = newnd.dentry;
2631 if (newnd.last_type != LAST_NORM)
2634 trap = lock_rename(new_dir, old_dir);
2636 old_dentry = lookup_hash(&oldnd);
2637 error = PTR_ERR(old_dentry);
2638 if (IS_ERR(old_dentry))
2640 /* source must exist */
2642 if (!old_dentry->d_inode)
2644 /* unless the source is a directory trailing slashes give -ENOTDIR */
2645 if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
2647 if (oldnd.last.name[oldnd.last.len])
2649 if (newnd.last.name[newnd.last.len])
2652 /* source should not be ancestor of target */
2654 if (old_dentry == trap)
2657 if (MNT_IS_RDONLY(newnd.mnt))
2659 new_dentry = lookup_hash(&newnd);
2660 error = PTR_ERR(new_dentry);
2661 if (IS_ERR(new_dentry))
2663 /* target should not be an ancestor of source */
2665 if (new_dentry == trap)
2668 error = vfs_rename(old_dir->d_inode, old_dentry,
2669 new_dir->d_inode, new_dentry);
2675 unlock_rename(new_dir, old_dir);
2677 path_release(&newnd);
2679 path_release(&oldnd);
2684 asmlinkage long sys_renameat(int olddfd, const char __user *oldname,
2685 int newdfd, const char __user *newname)
2691 from = getname(oldname);
2693 return PTR_ERR(from);
2694 to = getname(newname);
2695 error = PTR_ERR(to);
2697 error = do_rename(olddfd, from, newdfd, to);
2704 asmlinkage long sys_rename(const char __user *oldname, const char __user *newname)
2706 return sys_renameat(AT_FDCWD, oldname, AT_FDCWD, newname);
2709 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
2713 len = PTR_ERR(link);
2718 if (len > (unsigned) buflen)
2720 if (copy_to_user(buffer, link, len))
2727 * A helper for ->readlink(). This should be used *ONLY* for symlinks that
2728 * have ->follow_link() touching nd only in nd_set_link(). Using (or not
2729 * using) it for any given inode is up to filesystem.
2731 int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)
2733 struct nameidata nd;
2737 cookie = dentry->d_inode->i_op->follow_link(dentry, &nd);
2738 if (!IS_ERR(cookie)) {
2739 int res = vfs_readlink(dentry, buffer, buflen, nd_get_link(&nd));
2740 if (dentry->d_inode->i_op->put_link)
2741 dentry->d_inode->i_op->put_link(dentry, &nd, cookie);
2742 cookie = ERR_PTR(res);
2744 return PTR_ERR(cookie);
2747 int vfs_follow_link(struct nameidata *nd, const char *link)
2749 return __vfs_follow_link(nd, link);
2753 #ifdef CONFIG_VSERVER_COWBL
2755 #include <linux/file.h>
2757 struct dentry *cow_break_link(const char *pathname)
2759 int ret, mode, pathlen;
2760 struct nameidata old_nd, dir_nd;
2761 struct dentry *old_dentry, *new_dentry;
2762 struct dentry *res = ERR_PTR(-EMLINK);
2763 struct vfsmount *old_mnt, *new_mnt;
2764 struct file *old_file;
2765 struct file *new_file;
2766 char *to, *path, pad='\251';
2769 vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
2770 path = kmalloc(PATH_MAX, GFP_KERNEL);
2772 ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
2773 vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
2774 old_dentry = old_nd.dentry;
2775 old_mnt = old_nd.mnt;
2776 mode = old_dentry->d_inode->i_mode;
2778 to = d_path(old_dentry, old_mnt, path, PATH_MAX-2);
2779 pathlen = strlen(to);
2780 vxdprintk(VXD_CBIT(misc, 2), "old path »%s«", to);
2784 to[pathlen] = pad--;
2788 vxdprintk(VXD_CBIT(misc, 1), "temp copy »%s«", to);
2789 ret = path_lookup(to,
2790 LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, &dir_nd);
2792 /* this puppy downs the inode sem */
2793 new_dentry = lookup_create(&dir_nd, 0);
2794 vxdprintk(VXD_CBIT(misc, 2),
2795 "lookup_create(new): %p", new_dentry);
2797 path_release(&dir_nd);
2801 ret = vfs_create(dir_nd.dentry->d_inode, new_dentry, mode, &dir_nd);
2802 vxdprintk(VXD_CBIT(misc, 2),
2803 "vfs_create(new): %d", ret);
2804 if (ret == -EEXIST) {
2805 mutex_unlock(&dir_nd.dentry->d_inode->i_mutex);
2807 path_release(&dir_nd);
2815 new_mnt = dir_nd.mnt;
2819 /* this one cleans up the dentry in case of failure */
2820 old_file = dentry_open(old_dentry, old_mnt, O_RDONLY);
2821 vxdprintk(VXD_CBIT(misc, 2),
2822 "dentry_open(old): %p", old_file);
2828 /* this one cleans up the dentry in case of failure */
2829 new_file = dentry_open(new_dentry, new_mnt, O_WRONLY);
2830 vxdprintk(VXD_CBIT(misc, 2),
2831 "dentry_open(new): %p", new_file);
2835 size = i_size_read(old_file->f_dentry->d_inode);
2836 ret = vfs_sendfile(new_file, old_file, NULL, size, 0);
2837 vxdprintk(VXD_CBIT(misc, 2), "vfs_sendfile: %d", ret);
2842 ret = vfs_rename(dir_nd.dentry->d_inode, new_dentry,
2843 old_nd.dentry->d_parent->d_inode, old_dentry);
2844 vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
2851 vxdprintk(VXD_CBIT(misc, 3),
2852 "fput(new_file=%p[#%d])", new_file,
2853 atomic_read(&new_file->f_count));
2857 vxdprintk(VXD_CBIT(misc, 3),
2858 "fput(old_file=%p[#%d])", old_file,
2859 atomic_read(&old_file->f_count));
2863 mutex_unlock(&dir_nd.dentry->d_inode->i_mutex);
2866 path_release(&dir_nd);
2868 path_release(&old_nd);
2875 /* get the link contents into pagecache */
2876 static char *page_getlink(struct dentry * dentry, struct page **ppage)
2879 struct address_space *mapping = dentry->d_inode->i_mapping;
2880 page = read_mapping_page(mapping, 0, NULL);
2883 wait_on_page_locked(page);
2884 if (!PageUptodate(page))
2890 page_cache_release(page);
2891 return ERR_PTR(-EIO);
2897 int page_readlink(struct dentry *dentry, char __user *buffer, int buflen)
2899 struct page *page = NULL;
2900 char *s = page_getlink(dentry, &page);
2901 int res = vfs_readlink(dentry,buffer,buflen,s);
2904 page_cache_release(page);
2909 void *page_follow_link_light(struct dentry *dentry, struct nameidata *nd)
2911 struct page *page = NULL;
2912 nd_set_link(nd, page_getlink(dentry, &page));
2916 void page_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
2918 struct page *page = cookie;
2922 page_cache_release(page);
2926 int __page_symlink(struct inode *inode, const char *symname, int len,
2929 struct address_space *mapping = inode->i_mapping;
2935 page = find_or_create_page(mapping, 0, gfp_mask);
2938 err = mapping->a_ops->prepare_write(NULL, page, 0, len-1);
2939 if (err == AOP_TRUNCATED_PAGE) {
2940 page_cache_release(page);
2945 kaddr = kmap_atomic(page, KM_USER0);
2946 memcpy(kaddr, symname, len-1);
2947 kunmap_atomic(kaddr, KM_USER0);
2948 err = mapping->a_ops->commit_write(NULL, page, 0, len-1);
2949 if (err == AOP_TRUNCATED_PAGE) {
2950 page_cache_release(page);
2956 * Notice that we are _not_ going to block here - end of page is
2957 * unmapped, so this will only try to map the rest of page, see
2958 * that it is unmapped (typically even will not look into inode -
2959 * ->i_size will be enough for everything) and zero it out.
2960 * OTOH it's obviously correct and should make the page up-to-date.
2962 if (!PageUptodate(page)) {
2963 err = mapping->a_ops->readpage(NULL, page);
2964 if (err != AOP_TRUNCATED_PAGE)
2965 wait_on_page_locked(page);
2969 page_cache_release(page);
2972 mark_inode_dirty(inode);
2976 page_cache_release(page);
2981 int page_symlink(struct inode *inode, const char *symname, int len)
2983 return __page_symlink(inode, symname, len,
2984 mapping_gfp_mask(inode->i_mapping));
2987 struct inode_operations page_symlink_inode_operations = {
2988 .readlink = generic_readlink,
2989 .follow_link = page_follow_link_light,
2990 .put_link = page_put_link,
2993 EXPORT_SYMBOL(__user_walk);
2994 EXPORT_SYMBOL(__user_walk_fd);
2995 EXPORT_SYMBOL(follow_down);
2996 EXPORT_SYMBOL(follow_up);
2997 EXPORT_SYMBOL(get_write_access); /* binfmt_aout */
2998 EXPORT_SYMBOL(getname);
2999 EXPORT_SYMBOL(lock_rename);
3000 EXPORT_SYMBOL(lookup_one_len);
3001 EXPORT_SYMBOL(page_follow_link_light);
3002 EXPORT_SYMBOL(page_put_link);
3003 EXPORT_SYMBOL(page_readlink);
3004 EXPORT_SYMBOL(__page_symlink);
3005 EXPORT_SYMBOL(page_symlink);
3006 EXPORT_SYMBOL(page_symlink_inode_operations);
3007 EXPORT_SYMBOL(path_lookup);
3008 EXPORT_SYMBOL(path_release);
3009 EXPORT_SYMBOL(path_walk);
3010 EXPORT_SYMBOL(permission);
3011 EXPORT_SYMBOL(vfs_permission);
3012 EXPORT_SYMBOL(file_permission);
3013 EXPORT_SYMBOL(unlock_rename);
3014 EXPORT_SYMBOL(vfs_create);
3015 EXPORT_SYMBOL(vfs_follow_link);
3016 EXPORT_SYMBOL(vfs_link);
3017 EXPORT_SYMBOL(vfs_mkdir);
3018 EXPORT_SYMBOL(vfs_mknod);
3019 EXPORT_SYMBOL(generic_permission);
3020 EXPORT_SYMBOL(vfs_readlink);
3021 EXPORT_SYMBOL(vfs_rename);
3022 EXPORT_SYMBOL(vfs_rmdir);
3023 EXPORT_SYMBOL(vfs_symlink);
3024 EXPORT_SYMBOL(vfs_unlink);
3025 EXPORT_SYMBOL(dentry_unhash);
3026 EXPORT_SYMBOL(generic_readlink);