Lines Matching refs:path

100  *	inside the path - always follow.
192 /* The empty path is special. */
542 * path_get - get a reference to a path
543 * @path: path to get the reference to
545 * Given a path increment the reference count to the dentry and the vfsmount.
547 void path_get(const struct path *path)
549 mntget(path->mnt);
550 dget(path->dentry);
555 * path_put - put a reference to a path
556 * @path: path to put the reference to
558 * Given a path decrement the reference count to the dentry and the vfsmount.
560 void path_put(const struct path *path)
562 dput(path->dentry);
563 mntput(path->mnt);
569 struct path path;
571 struct path root;
572 struct inode *inode; /* path.dentry.d_inode */
579 struct path link;
603 p->path.mnt = NULL;
604 p->path.dentry = NULL;
611 const struct path *root)
686 path_put(&nd->path);
697 nd->path.mnt = NULL;
698 nd->path.dentry = NULL;
702 static bool __legitimize_path(struct path *path, unsigned seq, unsigned mseq)
704 int res = __legitimize_mnt(path->mnt, mseq);
707 path->mnt = NULL;
708 path->dentry = NULL;
711 if (unlikely(!lockref_get_not_dead(&path->dentry->d_lockref))) {
712 path->dentry = NULL;
715 return !read_seqcount_retry(&path->dentry->d_seq, seq);
719 struct path *path, unsigned seq)
721 return __legitimize_path(path, seq, nd->m_seq);
754 * Documentation/filesystems/path-lookup.txt). In situations when we can't
760 * to restart the path walk from the beginning in ref-walk mode.
768 * try_to_unlazy attempts to legitimize the current nd->path and nd->root
776 struct dentry *parent = nd->path.dentry;
782 if (unlikely(!legitimize_path(nd, &nd->path, nd->seq)))
791 nd->path.mnt = NULL;
792 nd->path.dentry = NULL;
806 * nd->path and nd->root for ref-walk mode. Must be called from rcu-walk context.
817 res = __legitimize_mnt(nd->path.mnt, nd->m_seq);
823 if (unlikely(!lockref_get_not_dead(&nd->path.dentry->d_lockref)))
847 nd->path.mnt = NULL;
849 nd->path.dentry = NULL;
868 * complete_walk - successful completion of path walk
871 * If we had been in RCU mode, drop out of it and legitimize nd->path.
873 * the path walk or the filesystem doesn't ask for it. Return 0 on
875 * need to drop nd->path.
879 struct dentry *dentry = nd->path.dentry;
900 * BUG resulting in userspace being given a path that was not
908 * Userspace could move the path outside the root after this
912 if (!path_is_under(&nd->path, &nd->root))
964 /* Absolute path arguments to path_init() are allowed. */
965 if (nd->path.mnt != NULL && nd->path.mnt != nd->root.mnt)
975 nd->path = nd->root;
976 d = nd->path.dentry;
982 path_put(&nd->path);
983 nd->path = nd->root;
984 path_get(&nd->path);
985 nd->inode = nd->path.dentry->d_inode;
992 * Helper to directly jump to a known parsed path from ->get_link,
993 * caller must have taken a reference to path beforehand.
995 int nd_jump_link(const struct path *path)
1005 if (nd->path.mnt != path->mnt)
1012 path_put(&nd->path);
1013 nd->path = *path;
1014 nd->inode = nd->path.dentry->d_inode;
1019 path_put(path);
1094 * processes from failing races against path names that may change out
1110 idmap = mnt_idmap(nd->path.mnt);
1188 int may_linkat(struct mnt_idmap *idmap, const struct path *link)
1265 * follow_up - Find the mountpoint of path's vfsmount
1267 * Given a path, find the mountpoint of its source file system.
1268 * Replace @path with the path of the mountpoint in the parent mount.
1274 int follow_up(struct path *path)
1276 struct mount *mnt = real_mount(path->mnt);
1289 dput(path->dentry);
1290 path->dentry = mountpoint;
1291 mntput(path->mnt);
1292 path->mnt = &parent->mnt;
1297 static bool choose_mountpoint_rcu(struct mount *m, const struct path *root,
1298 struct path *path, unsigned *seqp)
1308 path->mnt = &m->mnt;
1309 path->dentry = mountpoint;
1317 static bool choose_mountpoint(struct mount *m, const struct path *root,
1318 struct path *path)
1326 found = choose_mountpoint_rcu(m, root, path, &seq);
1331 if (likely(__legitimize_path(path, seq, mseq)))
1334 path_put(path);
1344 * - return -EISDIR to tell follow_managed() to stop and return the path we
1347 static int follow_automount(struct path *path, int *count, unsigned lookup_flags)
1349 struct dentry *dentry = path->dentry;
1370 return finish_automount(dentry->d_op->d_automount(path), path);
1379 static int __traverse_mounts(struct path *path, unsigned flags, bool *jumped,
1382 struct vfsmount *mnt = path->mnt;
1390 ret = path->dentry->d_op->d_manage(path, false);
1391 flags = smp_load_acquire(&path->dentry->d_flags);
1397 struct vfsmount *mounted = lookup_mnt(path);
1399 dput(path->dentry);
1401 mntput(path->mnt);
1402 path->mnt = mounted;
1403 path->dentry = dget(mounted->mnt_root);
1405 flags = path->dentry->d_flags;
1415 ret = follow_automount(path, count, lookup_flags);
1416 flags = smp_load_acquire(&path->dentry->d_flags);
1424 if (need_mntput && path->mnt == mnt)
1425 mntput(path->mnt);
1432 static inline int traverse_mounts(struct path *path, bool *jumped,
1435 unsigned flags = smp_load_acquire(&path->dentry->d_flags);
1444 return __traverse_mounts(path, flags, jumped, count, lookup_flags);
1447 int follow_down_one(struct path *path)
1451 mounted = lookup_mnt(path);
1453 dput(path->dentry);
1454 mntput(path->mnt);
1455 path->mnt = mounted;
1456 path->dentry = dget(mounted->mnt_root);
1468 int follow_down(struct path *path, unsigned int flags)
1470 struct vfsmount *mnt = path->mnt;
1472 int ret = traverse_mounts(path, &jumped, NULL, flags);
1474 if (path->mnt != mnt)
1484 static bool __follow_mount_rcu(struct nameidata *nd, struct path *path)
1486 struct dentry *dentry = path->dentry;
1501 int res = dentry->d_op->d_manage(path, true);
1508 struct mount *mounted = __lookup_mnt(path->mnt, dentry);
1510 path->mnt = &mounted->mnt;
1511 dentry = path->dentry = mounted->mnt.mnt_root;
1529 struct path *path)
1534 path->mnt = nd->path.mnt;
1535 path->dentry = dentry;
1538 if (likely(__follow_mount_rcu(nd, path)))
1540 // *path and nd->next_seq might've been clobbered
1541 path->mnt = nd->path.mnt;
1542 path->dentry = dentry;
1547 ret = traverse_mounts(path, &jumped, &nd->total_link_count, nd->flags);
1555 dput(path->dentry);
1556 if (path->mnt != nd->path.mnt)
1557 mntput(path->mnt);
1620 struct dentry *dentry, *parent = nd->path.dentry;
1727 static int reserve_stack(struct nameidata *nd, struct path *link)
1755 static const char *pick_link(struct nameidata *nd, struct path *link,
1838 struct path path;
1840 int err = handle_mounts(nd, dentry, &path);
1844 inode = path.dentry->d_inode;
1845 if (likely(!d_is_symlink(path.dentry)) ||
1850 if (read_seqcount_retry(&path.dentry->d_seq, nd->next_seq))
1855 dput(nd->path.dentry);
1856 if (nd->path.mnt != path.mnt)
1857 mntput(nd->path.mnt);
1859 nd->path = path;
1866 if (read_seqcount_retry(&path.dentry->d_seq, nd->next_seq))
1869 if (path.mnt == nd->path.mnt)
1870 mntget(path.mnt);
1872 return pick_link(nd, &path, inode, flags);
1879 if (path_equal(&nd->path, &nd->root))
1881 if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) {
1882 struct path path;
1884 if (!choose_mountpoint_rcu(real_mount(nd->path.mnt),
1885 &nd->root, &path, &seq))
1889 nd->path = path;
1890 nd->inode = path.dentry->d_inode;
1897 old = nd->path.dentry;
1903 if (unlikely(!path_connected(nd->path.mnt, parent)))
1912 return nd->path.dentry;
1919 if (path_equal(&nd->path, &nd->root))
1921 if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) {
1922 struct path path;
1924 if (!choose_mountpoint(real_mount(nd->path.mnt),
1925 &nd->root, &path))
1927 path_put(&nd->path);
1928 nd->path = path;
1929 nd->inode = path.dentry->d_inode;
1934 parent = dget_parent(nd->path.dentry);
1935 if (unlikely(!path_connected(nd->path.mnt, parent))) {
1944 return dget(nd->path.dentry);
1971 * path, then we can't be sure that ".." hasn't jumped
2002 dentry = lookup_slow(&nd->last, nd->path.dentry, nd->flags);
2163 * Calculate the length and hash of the path component, and
2220 * We know there's a real path component here of at least
2263 /* At this point we know we have a real path component. */
2270 idmap = mnt_idmap(nd->path.mnt);
2275 hash_len = hash_name(nd->path.dentry, name);
2289 struct dentry *parent = nd->path.dentry;
2339 if (unlikely(!d_can_lookup(nd->path.dentry))) {
2378 nd->path = nd->root;
2381 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
2384 path_get(&nd->path);
2407 nd->path = fs->pwd;
2408 nd->inode = nd->path.dentry->d_inode;
2409 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq);
2412 get_fs_pwd(current->fs, &nd->path);
2413 nd->inode = nd->path.dentry->d_inode;
2416 /* Caller must check execute permissions on the starting path component */
2430 nd->path = f.file->f_path;
2432 nd->inode = nd->path.dentry->d_inode;
2433 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
2435 path_get(&nd->path);
2436 nd->inode = nd->path.dentry->d_inode;
2443 nd->root = nd->path;
2465 dget(nd->path.dentry);
2467 return PTR_ERR(step_into(nd, WALK_NOFOLLOW, nd->path.dentry));
2471 static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path)
2493 if (!d_can_lookup(nd->path.dentry))
2496 *path = nd->path;
2497 nd->path.mnt = NULL;
2498 nd->path.dentry = NULL;
2505 struct path *path, struct path *root)
2512 retval = path_lookupat(&nd, flags | LOOKUP_RCU, path);
2514 retval = path_lookupat(&nd, flags, path);
2516 retval = path_lookupat(&nd, flags | LOOKUP_REVAL, path);
2519 audit_inode(name, path->dentry,
2527 struct path *parent)
2534 *parent = nd->path;
2535 nd->path.mnt = NULL;
2536 nd->path.dentry = NULL;
2544 unsigned int flags, struct path *parent,
2546 const struct path *root)
2569 unsigned int flags, struct path *parent,
2576 static struct dentry *__kern_path_locked(struct filename *name, struct path *path)
2582 error = filename_parentat(AT_FDCWD, name, 0, path, &last, &type);
2586 path_put(path);
2589 inode_lock_nested(path->dentry->d_inode, I_MUTEX_PARENT);
2590 d = lookup_one_qstr_excl(&last, path->dentry, 0);
2592 inode_unlock(path->dentry->d_inode);
2593 path_put(path);
2598 struct dentry *kern_path_locked(const char *name, struct path *path)
2601 struct dentry *res = __kern_path_locked(filename, path);
2607 int kern_path(const char *name, unsigned int flags, struct path *path)
2610 int ret = filename_lookup(AT_FDCWD, filename, flags, path, NULL);
2619 * vfs_path_parent_lookup - lookup a parent path relative to a dentry-vfsmount pair
2622 * @parent: pointer to struct path to fill
2625 * @root: pointer to struct path of the base directory
2628 struct path *parent, struct qstr *last, int *type,
2629 const struct path *root)
2637 * vfs_path_lookup - lookup a file path relative to a dentry-vfsmount pair
2642 * @path: pointer to struct path to fill
2646 struct path *path)
2649 struct path root = {.mnt = mnt, .dentry = dentry};
2654 ret = filename_lookup(AT_FDCWD, filename, flags, path, &root);
2881 int path_pts(struct path *path)
2884 * the input path.
2886 struct dentry *parent = dget_parent(path->dentry);
2890 if (unlikely(!path_connected(path->mnt, parent))) {
2894 dput(path->dentry);
2895 path->dentry = parent;
2900 path->dentry = child;
2902 follow_down(path, 0);
2908 struct path *path, int *empty)
2911 int ret = filename_lookup(dfd, filename, flags, path, NULL);
3220 bool may_open_dev(const struct path *path)
3222 return !(path->mnt->mnt_flags & MNT_NODEV) &&
3223 !(path->mnt->mnt_sb->s_iflags & SB_I_NODEV);
3226 static int may_open(struct mnt_idmap *idmap, const struct path *path,
3229 struct dentry *dentry = path->dentry;
3247 if (!may_open_dev(path))
3257 if ((acc_mode & MAY_EXEC) && path_noexec(path))
3285 const struct path *path = &filp->f_path;
3286 struct inode *inode = path->dentry->d_inode;
3293 error = do_truncate(idmap, path->dentry, 0,
3309 const struct path *dir, struct dentry *dentry,
3335 * be set. The caller will need to perform the open themselves. @path will
3345 struct inode *dir = nd->path.dentry->d_inode;
3352 file->f_path.mnt = nd->path.mnt;
3390 * In the latter case dentry returned in @path might be negative if O_CREAT
3400 struct dentry *dir = nd->path.dentry;
3447 idmap = mnt_idmap(nd->path.mnt);
3453 create_error = may_o_create(idmap, &nd->path,
3509 struct dentry *dir = nd->path.dentry;
3547 got_write = !mnt_want_write(nd->path.mnt);
3567 mnt_drop_write(nd->path.mnt);
3573 dput(nd->path.dentry);
3574 nd->path.dentry = dentry;
3605 audit_inode(nd->name, nd->path.dentry, 0);
3606 idmap = mnt_idmap(nd->path.mnt);
3610 if (d_is_dir(nd->path.dentry))
3613 d_backing_inode(nd->path.dentry));
3617 if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry))
3626 } else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) {
3627 error = mnt_want_write(nd->path.mnt);
3632 error = may_open(idmap, &nd->path, acc_mode, open_flag);
3634 error = vfs_open(&nd->path, file);
3644 mnt_drop_write(nd->path.mnt);
3651 * @parentpath: pointer to the path of the base directory
3664 const struct path *parentpath,
3706 * @parentpath: path of the base directory
3716 const struct path *parentpath,
3740 struct path path;
3741 int error = path_lookupat(nd, flags | LOOKUP_DIRECTORY, &path);
3745 error = mnt_want_write(path.mnt);
3748 error = vfs_tmpfile(mnt_idmap(path.mnt), &path, file, op->mode);
3753 mnt_drop_write(path.mnt);
3755 path_put(&path);
3761 struct path path;
3762 int error = path_lookupat(nd, flags, &path);
3764 audit_inode(nd->name, path.dentry, 0);
3765 error = vfs_open(&path, file);
3766 path_put(&path);
3827 struct file *do_file_open_root(const struct path *root,
3854 struct path *path, unsigned int lookup_flags)
3865 error = filename_parentat(dfd, name, reval_flag, path, &last, &type);
3877 err2 = mnt_want_write(path->mnt);
3884 inode_lock_nested(path->dentry->d_inode, I_MUTEX_PARENT);
3885 dentry = lookup_one_qstr_excl(&last, path->dentry,
3913 inode_unlock(path->dentry->d_inode);
3915 mnt_drop_write(path->mnt);
3917 path_put(path);
3922 struct path *path, unsigned int lookup_flags)
3925 struct dentry *res = filename_create(dfd, filename, path, lookup_flags);
3932 void done_path_create(struct path *path, struct dentry *dentry)
3935 inode_unlock(path->dentry->d_inode);
3936 mnt_drop_write(path->mnt);
3937 path_put(path);
3942 struct path *path, unsigned int lookup_flags)
3945 struct dentry *res = filename_create(dfd, filename, path, lookup_flags);
4022 struct path path;
4030 dentry = filename_create(dfd, name, &path, lookup_flags);
4035 error = security_path_mknod(&path, dentry,
4036 mode_strip_umask(path.dentry->d_inode, mode), dev);
4040 idmap = mnt_idmap(path.mnt);
4043 error = vfs_create(idmap, path.dentry->d_inode,
4049 error = vfs_mknod(idmap, path.dentry->d_inode,
4053 error = vfs_mknod(idmap, path.dentry->d_inode,
4058 done_path_create(&path, dentry);
4125 struct path path;
4130 dentry = filename_create(dfd, name, &path, lookup_flags);
4135 error = security_path_mkdir(&path, dentry,
4136 mode_strip_umask(path.dentry->d_inode, mode));
4138 error = vfs_mkdir(mnt_idmap(path.mnt), path.dentry->d_inode,
4141 done_path_create(&path, dentry);
4220 struct path path;
4225 error = filename_parentat(dfd, name, lookup_flags, &path, &last, &type);
4241 error = mnt_want_write(path.mnt);
4245 inode_lock_nested(path.dentry->d_inode, I_MUTEX_PARENT);
4246 dentry = lookup_one_qstr_excl(&last, path.dentry, lookup_flags);
4254 error = security_path_rmdir(&path, dentry);
4257 error = vfs_rmdir(mnt_idmap(path.mnt), path.dentry->d_inode, dentry);
4261 inode_unlock(path.dentry->d_inode);
4262 mnt_drop_write(path.mnt);
4264 path_put(&path);
4359 struct path path;
4366 error = filename_parentat(dfd, name, lookup_flags, &path, &last, &type);
4374 error = mnt_want_write(path.mnt);
4378 inode_lock_nested(path.dentry->d_inode, I_MUTEX_PARENT);
4379 dentry = lookup_one_qstr_excl(&last, path.dentry, lookup_flags);
4390 error = security_path_unlink(&path, dentry);
4393 error = vfs_unlink(mnt_idmap(path.mnt), path.dentry->d_inode,
4398 inode_unlock(path.dentry->d_inode);
4407 mnt_drop_write(path.mnt);
4409 path_put(&path);
4486 struct path path;
4494 dentry = filename_create(newdfd, to, &path, lookup_flags);
4499 error = security_path_symlink(&path, dentry, from->name);
4501 error = vfs_symlink(mnt_idmap(path.mnt), path.dentry->d_inode,
4503 done_path_create(&path, dentry);
4628 struct path old_path, new_path;
4919 struct path old_path, new_path;