Lines Matching refs:dentry

700  * Given a path increment the reference count to the dentry and the vfsmount.
705 dget(path->dentry);
713 * Given a path decrement the reference count to the dentry and the vfsmount.
717 dput(path->dentry);
727 struct inode *inode; /* path.dentry.d_inode */
761 p->path.dentry = NULL;
803 * path_connected - Verify that a dentry is below mnt.mnt_root
805 * @dentry: The dentry to check.
810 static bool path_connected(struct vfsmount *mnt, struct dentry *dentry)
818 return is_subdir(dentry, mnt->mnt_root);
856 nd->path.dentry = NULL;
866 path->dentry = NULL;
869 if (unlikely(!lockref_get_not_dead(&path->dentry->d_lockref))) {
870 path->dentry = NULL;
873 return !read_seqcount_retry(&path->dentry->d_seq, seq);
932 struct dentry *parent = nd->path.dentry;
953 nd->path.dentry = NULL;
962 * @dentry: next dentry to step into
965 * Similar to try_to_unlazy(), but here we have the next dentry already
971 static bool try_to_unlazy_next(struct nameidata *nd, struct dentry *dentry)
990 if (unlikely(!lockref_get_not_dead(&nd->path.dentry->d_lockref)))
994 * We need to move both the parent and the dentry from the RCU domain
995 * to be properly refcounted. And the sequence number in the dentry
996 * validates *both* dentry counters, since we checked the sequence
1000 if (unlikely(!lockref_get_not_dead(&dentry->d_lockref)))
1002 if (read_seqcount_retry(&dentry->d_seq, nd->next_seq))
1016 nd->path.dentry = NULL;
1022 dput(dentry);
1027 struct dentry *dentry, unsigned int flags)
1029 if (unlikely(dentry->d_flags & DCACHE_OP_REVALIDATE))
1030 return dentry->d_op->d_revalidate(dir, name, dentry, flags);
1047 struct dentry *dentry = nd->path.dentry;
1087 if (likely(!(dentry->d_flags & DCACHE_OP_WEAK_REVALIDATE)))
1090 status = dentry->d_op->d_weak_revalidate(dentry, nd->flags);
1118 nd->root_seq = __read_seqcount_begin(&nd->root.dentry->d_seq);
1142 struct dentry *d;
1144 d = nd->path.dentry;
1153 nd->inode = nd->path.dentry->d_inode;
1182 nd->inode = nd->path.dentry->d_inode;
1294 audit_inode(nd->name, nd->stack[0].link.dentry, 0);
1357 struct inode *inode = link->dentry->d_inode;
1464 struct dentry *mountpoint;
1475 dput(path->dentry);
1476 path->dentry = mountpoint;
1487 struct dentry *mountpoint = m->mnt_mountpoint;
1490 if (unlikely(root->dentry == mountpoint &&
1495 path->dentry = mountpoint;
1535 struct dentry *dentry = path->dentry;
1550 dentry->d_inode)
1560 return finish_automount(dentry->d_op->d_automount(path), path);
1565 * dentries are pinned but not locked here, so negative dentry can go
1584 ret = path->dentry->d_op->d_manage(path, false);
1585 flags = smp_load_acquire(&path->dentry->d_flags);
1593 dput(path->dentry);
1597 path->dentry = dget(mounted->mnt_root);
1599 flags = path->dentry->d_flags;
1614 flags = smp_load_acquire(&path->dentry->d_flags);
1633 unsigned flags = smp_load_acquire(&path->dentry->d_flags);
1651 dput(path->dentry);
1654 path->dentry = dget(mounted->mnt_root);
1663 * point, the filesystem owning that dentry may be queried as to whether the
1680 * we meet a managed dentry that would need blocking.
1684 struct dentry *dentry = path->dentry;
1685 unsigned int flags = dentry->d_flags;
1692 * Don't forget we might have a non-mountpoint managed dentry
1696 int res = dentry->d_op->d_manage(path, true);
1699 flags = dentry->d_flags;
1703 struct mount *mounted = __lookup_mnt(path->mnt, dentry);
1706 dentry = path->dentry = mounted->mnt.mnt_root;
1708 nd->next_seq = read_seqcount_begin(&dentry->d_seq);
1709 flags = dentry->d_flags;
1723 static inline int handle_mounts(struct nameidata *nd, struct dentry *dentry,
1730 path->dentry = dentry;
1733 if (likely(!d_managed(dentry)))
1739 path->dentry = dentry;
1741 if (unlikely(!try_to_unlazy_next(nd, dentry)))
1748 dput(path->dentry);
1756 * This looks up the name in dcache and possibly revalidates the found dentry.
1757 * NULL is returned if the dentry does not exist in the cache.
1759 static struct dentry *lookup_dcache(const struct qstr *name,
1760 struct dentry *dir,
1763 struct dentry *dentry = d_lookup(dir, name);
1764 if (dentry) {
1765 int error = d_revalidate(dir->d_inode, name, dentry, flags);
1768 d_invalidate(dentry);
1769 dput(dentry);
1773 return dentry;
1785 struct dentry *lookup_one_qstr_excl(const struct qstr *name,
1786 struct dentry *base, unsigned int flags)
1788 struct dentry *dentry;
1789 struct dentry *old;
1792 dentry = lookup_dcache(name, base, flags);
1793 if (dentry)
1796 /* Don't create child dentry for a dead directory. */
1801 dentry = d_alloc(base, name);
1802 if (unlikely(!dentry))
1805 old = dir->i_op->lookup(dir, dentry, flags);
1807 dput(dentry);
1808 dentry = old;
1811 if (IS_ERR(dentry))
1812 return dentry;
1813 if (d_is_negative(dentry) && !(flags & LOOKUP_CREATE)) {
1814 dput(dentry);
1817 if (d_is_positive(dentry) && (flags & LOOKUP_EXCL)) {
1818 dput(dentry);
1821 return dentry;
1826 * lookup_fast - do fast lockless (but racy) lookup of a dentry
1829 * Do a fast, but racy lookup in the dcache for the given dentry, and
1830 * revalidate it. Returns a valid dentry pointer or NULL if one wasn't
1833 * If this function returns a valid dentry and the walk is no longer
1834 * lazy, the dentry will carry a reference that must later be put. If
1835 * RCU mode is still in force, then this is not the case and the dentry
1839 static struct dentry *lookup_fast(struct nameidata *nd)
1841 struct dentry *dentry, *parent = nd->path.dentry;
1850 dentry = __d_lookup_rcu(parent, &nd->last, &nd->next_seq);
1851 if (unlikely(!dentry)) {
1859 * changes while we did the lookup of the dentry above.
1864 status = d_revalidate(nd->inode, &nd->last, dentry, nd->flags);
1866 return dentry;
1867 if (!try_to_unlazy_next(nd, dentry))
1872 dentry, nd->flags);
1874 dentry = __d_lookup(parent, &nd->last);
1875 if (unlikely(!dentry))
1877 status = d_revalidate(nd->inode, &nd->last, dentry, nd->flags);
1881 d_invalidate(dentry);
1882 dput(dentry);
1885 return dentry;
1889 static struct dentry *__lookup_slow(const struct qstr *name,
1890 struct dentry *dir,
1893 struct dentry *dentry, *old;
1901 dentry = d_alloc_parallel(dir, name, &wq);
1902 if (IS_ERR(dentry))
1903 return dentry;
1904 if (unlikely(!d_in_lookup(dentry))) {
1905 int error = d_revalidate(inode, name, dentry, flags);
1908 d_invalidate(dentry);
1909 dput(dentry);
1912 dput(dentry);
1913 dentry = ERR_PTR(error);
1916 old = inode->i_op->lookup(inode, dentry, flags);
1917 d_lookup_done(dentry);
1919 dput(dentry);
1920 dentry = old;
1923 return dentry;
1926 static noinline struct dentry *lookup_slow(const struct qstr *name,
1927 struct dentry *dir,
1931 struct dentry *res;
1938 static struct dentry *lookup_slow_killable(const struct qstr *name,
1939 struct dentry *dir,
1943 struct dentry *res;
2013 if (read_seqcount_retry(&link->dentry->d_seq, nd->next_seq))
2050 error = security_inode_follow_link(link->dentry, inode,
2057 const char * (*get)(struct dentry *, struct inode *,
2063 res = get(link->dentry, inode, &last->done);
2065 res = get(link->dentry, inode, &last->done);
2092 * NOTE: dentry must be what nd->next_seq had been sampled from.
2095 struct dentry *dentry)
2101 err = handle_mounts(nd, dentry, &path);
2104 inode = path.dentry->d_inode;
2105 if (likely(!d_is_symlink(path.dentry)) ||
2110 if (read_seqcount_retry(&path.dentry->d_seq, nd->next_seq))
2115 dput(nd->path.dentry);
2128 struct dentry *dentry)
2137 !d_managed(dentry) && !d_is_symlink(dentry))) {
2138 struct inode *inode = dentry->d_inode;
2139 if (read_seqcount_retry(&dentry->d_seq, nd->next_seq))
2143 nd->path.dentry = dentry;
2149 return step_into_slowpath(nd, flags, dentry);
2152 static struct dentry *follow_dotdot_rcu(struct nameidata *nd)
2154 struct dentry *parent, *old;
2158 if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) {
2167 nd->inode = path.dentry->d_inode;
2174 old = nd->path.dentry;
2189 return nd->path.dentry;
2192 static struct dentry *follow_dotdot(struct nameidata *nd)
2194 struct dentry *parent;
2198 if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) {
2206 nd->inode = path.dentry->d_inode;
2211 parent = dget_parent(nd->path.dentry);
2221 return dget(nd->path.dentry);
2228 struct dentry *parent;
2264 struct dentry *dentry;
2275 dentry = lookup_fast(nd);
2276 if (IS_ERR(dentry))
2277 return ERR_CAST(dentry);
2278 if (unlikely(!dentry)) {
2279 dentry = lookup_slow(&nd->last, nd->path.dentry, nd->flags);
2280 if (IS_ERR(dentry))
2281 return ERR_CAST(dentry);
2285 return step_into(nd, flags, dentry);
2289 * We can do the critical dentry name comparison and hashing
2453 unsigned long a, b, x, y = (unsigned long)nd->path.dentry;
2540 unsigned long hash = init_name_hash(nd->path.dentry);
2570 * the final dentry. We expect 'base' to be positive and a directory.
2572 * Returns 0 and nd will have valid dentry and mnt on success.
2622 struct dentry *parent = nd->path.dentry;
2663 if (unlikely(!d_can_lookup(nd->path.dentry))) {
2698 struct dentry *root = nd->root.dentry;
2705 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
2732 nd->inode = nd->path.dentry->d_inode;
2733 nd->seq = __read_seqcount_begin(&nd->path.dentry->d_seq);
2737 nd->inode = nd->path.dentry->d_inode;
2742 struct dentry *dentry;
2753 dentry = fd_file(f)->f_path.dentry;
2755 if (*s && unlikely(!d_can_lookup(dentry)))
2760 nd->inode = nd->path.dentry->d_inode;
2761 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
2764 nd->inode = nd->path.dentry->d_inode;
2792 dget(nd->path.dentry);
2794 return PTR_ERR(step_into(nd, WALK_NOFOLLOW, nd->path.dentry));
2820 if (!d_can_lookup(nd->path.dentry))
2825 nd->path.dentry = NULL;
2846 audit_inode(name, path->dentry,
2863 nd->path.dentry = NULL;
2889 audit_inode(name, parent->dentry, AUDIT_INODE_PARENT);
2904 * @parent: the dentry of the parent in which the operation will occur
2910 * the returned dentry can be operated on safely.
2913 * Returns: a locked dentry, or an error.
2916 static struct dentry *__start_dirop(struct dentry *parent, struct qstr *name,
2920 struct dentry *dentry;
2931 dentry = lookup_one_qstr_excl(name, parent, lookup_flags);
2932 if (IS_ERR(dentry))
2934 return dentry;
2937 struct dentry *start_dirop(struct dentry *parent, struct qstr *name,
2945 * @de: the dentry which was returned by start_dirop or similar.
2948 * protect the dentry is dropped and the dentry itself is release (dput()).
2950 void end_dirop(struct dentry *de)
2960 static struct dentry *__start_removing_path(int dfd, struct filename *name,
2964 struct dentry *d;
2975 d = start_dirop(parent_path.dentry, &last, 0);
2980 path->dentry = no_free_ptr(parent_path.dentry);
3000 * is store in @parent and the dentry is returned.
3002 * The dentry maybe negative, the parent will be positive.
3004 * Returns: dentry or error.
3006 struct dentry *kern_path_parent(const char *name, struct path *path)
3010 struct dentry *d;
3020 d = lookup_noperm_unlocked(&last, parent_path.dentry);
3023 path->dentry = no_free_ptr(parent_path.dentry);
3028 struct dentry *start_removing_path(const char *name, struct path *path)
3034 struct dentry *start_removing_user_path_at(int dfd,
3051 * vfs_path_parent_lookup - lookup a parent path relative to a dentry-vfsmount pair
3069 * vfs_path_lookup - lookup a file path relative to a dentry-vfsmount pair
3070 * @dentry: pointer to dentry of the base directory
3076 int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
3081 struct path root = {.mnt = mnt, .dentry = dentry};
3088 int lookup_noperm_common(struct qstr *qname, struct dentry *base)
3118 struct qstr *qname, struct dentry *base)
3132 * Look up a dentry by name in the dcache, returning NULL if it does not
3133 * currently exist. The function does not try to create a dentry and if one
3142 struct dentry *try_lookup_noperm(struct qstr *name, struct dentry *base)
3164 struct dentry *lookup_noperm(struct qstr *name, struct dentry *base)
3166 struct dentry *dentry;
3175 dentry = lookup_dcache(name, base, 0);
3176 return dentry ? dentry : __lookup_slow(name, base, 0);
3190 struct dentry *lookup_one(struct mnt_idmap *idmap, struct qstr *name,
3191 struct dentry *base)
3193 struct dentry *dentry;
3202 dentry = lookup_dcache(name, base, 0);
3203 return dentry ? dentry : __lookup_slow(name, base, 0);
3218 struct dentry *lookup_one_unlocked(struct mnt_idmap *idmap, struct qstr *name,
3219 struct dentry *base)
3222 struct dentry *ret;
3254 struct dentry *lookup_one_positive_killable(struct mnt_idmap *idmap,
3256 struct dentry *base)
3259 struct dentry *ret;
3293 struct dentry *lookup_one_positive_unlocked(struct mnt_idmap *idmap,
3295 struct dentry *base)
3297 struct dentry *ret = lookup_one_unlocked(idmap, name, base);
3318 * Unlike try_lookup_noperm() it *does* revalidate the dentry if it already
3321 struct dentry *lookup_noperm_unlocked(struct qstr *name, struct dentry *base)
3323 struct dentry *ret;
3345 struct dentry *lookup_noperm_positive_unlocked(struct qstr *name,
3346 struct dentry *base)
3348 struct dentry *ret;
3369 * If the name already exists, a positive dentry is returned, so
3373 * Returns: a negative or positive dentry, or an error.
3375 struct dentry *start_creating(struct mnt_idmap *idmap, struct dentry *parent,
3400 * Returns: a positive dentry, or an error.
3402 struct dentry *start_removing(struct mnt_idmap *idmap, struct dentry *parent,
3423 * If the name already exists, a positive dentry is returned.
3428 * Returns: a negative or positive dentry, or an error.
3430 struct dentry *start_creating_killable(struct mnt_idmap *idmap,
3431 struct dentry *parent,
3459 * Returns: a positive dentry, or an error.
3461 struct dentry *start_removing_killable(struct mnt_idmap *idmap,
3462 struct dentry *parent,
3481 * If the name already exists, a positive dentry is returned.
3483 * Returns: a negative or positive dentry, or an error.
3485 struct dentry *start_creating_noperm(struct dentry *parent,
3508 * Returns: a positive dentry, or an error.
3510 struct dentry *start_removing_noperm(struct dentry *parent,
3522 * start_creating_dentry - prepare to create a given dentry
3523 * @parent: directory from which dentry should be removed
3524 * @child: the dentry to be removed
3526 * A lock is taken to protect the dentry again other dirops and
3527 * the validity of the dentry is checked: correct parent and still hashed.
3529 * If the dentry is valid and negative a reference is taken and
3534 * Returns: the valid dentry, or an error.
3536 struct dentry *start_creating_dentry(struct dentry *parent,
3537 struct dentry *child)
3555 * start_removing_dentry - prepare to remove a given dentry
3556 * @parent: directory from which dentry should be removed
3557 * @child: the dentry to be removed
3559 * A lock is taken to protect the dentry again other dirops and
3560 * the validity of the dentry is checked: correct parent and still hashed.
3562 * If the dentry is valid and positive, a reference is taken and
3567 * Returns: the valid dentry, or an error.
3569 struct dentry *start_removing_dentry(struct dentry *parent,
3570 struct dentry *child)
3593 struct dentry *parent = dget_parent(path->dentry);
3594 struct dentry *child;
3601 dput(path->dentry);
3602 path->dentry = parent;
3607 path->dentry = child;
3656 struct dentry *victim, bool isdir)
3699 /* Check whether we can create an object with dentry child in directory
3709 struct inode *dir, struct dentry *child)
3724 static struct dentry *lock_two_directories(struct dentry *p1, struct dentry *p2)
3726 struct dentry *p = p1, *q = p2, *r;
3759 struct dentry *lock_rename(struct dentry *p1, struct dentry *p2)
3774 struct dentry *lock_rename_child(struct dentry *c1, struct dentry *p2)
3813 void unlock_rename(struct dentry *p1, struct dentry *p2)
3848 struct dentry *trap;
3849 struct dentry *d1, *d2;
3941 struct dentry *old_dentry, struct qstr *new_last)
3943 struct dentry *trap;
3944 struct dentry *d2;
3953 /* Already have the dentry - need to be sure to lock the correct parent */
3959 /* dentry was removed, or moved and explicit parent requested */
4003 * @old_dentry: dentry of name to move
4009 * On success the found dentry is stored in @rd.new_dentry and
4022 struct dentry *old_dentry, struct qstr *new_last)
4036 * @old_dentry: dentry of name to move
4037 * @new_dentry: dentry to move to
4051 struct dentry *old_dentry, struct dentry *new_dentry)
4053 struct dentry *trap;
4056 /* Already have the dentry - need to be sure to lock the correct parent */
4150 * @dentry: dentry of the child file
4162 int vfs_create(struct mnt_idmap *idmap, struct dentry *dentry, umode_t mode,
4165 struct inode *dir = d_inode(dentry->d_parent);
4168 error = may_create_dentry(idmap, dir, dentry);
4176 error = security_inode_create(dir, dentry, mode);
4182 error = dir->i_op->create(idmap, dir, dentry, mode, true);
4184 fsnotify_create(dir, dentry);
4189 int vfs_mkobj(struct dentry *dentry, umode_t mode,
4190 int (*f)(struct dentry *, umode_t, void *),
4193 struct inode *dir = dentry->d_parent->d_inode;
4194 int error = may_create_dentry(&nop_mnt_idmap, dir, dentry);
4200 error = security_inode_create(dir, dentry, mode);
4203 error = f(dentry, mode, arg);
4205 fsnotify_create(dir, dentry);
4219 struct dentry *dentry = path->dentry;
4220 struct inode *inode = dentry->d_inode;
4278 struct inode *inode = path->dentry->d_inode;
4285 error = do_truncate(idmap, path->dentry, 0,
4301 const struct path *dir, struct dentry *dentry,
4304 int error = security_path_mknod(dir, dentry, mode, 0);
4308 if (!fsuidgid_has_mapping(dir->dentry->d_sb, idmap))
4311 error = inode_permission(idmap, dir->dentry->d_inode,
4316 return security_inode_create(dir->dentry->d_inode, dentry, mode);
4321 * dentry.
4328 * have been updated to point to the new dentry. This may be negative.
4332 static struct dentry *atomic_open(const struct path *path, struct dentry *dentry,
4336 struct dentry *const DENTRY_NOT_SET = (void *) -1UL;
4337 struct inode *dir = path->dentry->d_inode;
4340 file->__f_path.dentry = DENTRY_NOT_SET;
4342 error = dir->i_op->atomic_open(dir, dentry, file,
4344 d_lookup_done(dentry);
4347 if (unlikely(dentry != file->f_path.dentry)) {
4348 dput(dentry);
4349 dentry = dget(file->f_path.dentry);
4351 } else if (WARN_ON(file->f_path.dentry == DENTRY_NOT_SET)) {
4354 if (file->f_path.dentry) {
4355 dput(dentry);
4356 dentry = file->f_path.dentry;
4358 if (unlikely(d_is_negative(dentry)))
4363 dput(dentry);
4364 dentry = ERR_PTR(error);
4366 return dentry;
4379 * In the latter case dentry returned in @path might be negative if O_CREAT
4384 static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
4389 struct dentry *dir = nd->path.dentry;
4392 struct dentry *dentry;
4401 dentry = d_lookup(dir, &nd->last);
4403 if (!dentry) {
4404 dentry = d_alloc_parallel(dir, &nd->last, &wq);
4405 if (IS_ERR(dentry))
4406 return dentry;
4408 if (d_in_lookup(dentry))
4411 error = d_revalidate(dir_inode, &nd->last, dentry, nd->flags);
4416 d_invalidate(dentry);
4417 dput(dentry);
4418 dentry = NULL;
4420 if (dentry->d_inode) {
4421 /* Cached positive dentry: will open in f_op->open */
4422 return dentry;
4446 dentry, mode);
4455 dentry = atomic_open(&nd->path, dentry, file, open_flag, mode);
4456 if (unlikely(create_error) && dentry == ERR_PTR(-ENOENT))
4457 dentry = ERR_PTR(create_error);
4458 return dentry;
4461 if (d_in_lookup(dentry)) {
4462 struct dentry *res = dir_inode->i_op->lookup(dir_inode, dentry,
4464 d_lookup_done(dentry);
4470 dput(dentry);
4471 dentry = res;
4475 /* Negative dentry, just create the file */
4476 if (!dentry->d_inode && (open_flag & O_CREAT)) {
4483 audit_inode_child(dir_inode, dentry, AUDIT_TYPE_CHILD_CREATE);
4489 error = dir_inode->i_op->create(idmap, dir_inode, dentry,
4494 if (unlikely(create_error) && !dentry->d_inode) {
4498 return dentry;
4501 dput(dentry);
4510 static struct dentry *lookup_fast_for_open(struct nameidata *nd, int open_flag)
4512 struct dentry *dentry;
4526 dentry = lookup_fast(nd);
4527 if (IS_ERR_OR_NULL(dentry))
4528 return dentry;
4532 if (!dentry->d_inode) {
4534 dput(dentry);
4535 dentry = NULL;
4538 return dentry;
4545 struct dentry *dir = nd->path.dentry;
4548 struct dentry *dentry;
4560 dentry = lookup_fast_for_open(nd, open_flag);
4561 if (IS_ERR(dentry))
4562 return ERR_CAST(dentry);
4564 if (likely(dentry))
4589 dentry = lookup_open(nd, file, op, got_write, &delegated_inode);
4590 if (!IS_ERR(dentry)) {
4592 fsnotify_create(dir->d_inode, dentry);
4604 if (IS_ERR(dentry)) {
4612 return ERR_CAST(dentry);
4616 dput(nd->path.dentry);
4617 nd->path.dentry = dentry;
4624 res = step_into(nd, WALK_TRAILING, dentry);
4648 audit_inode(nd->name, nd->path.dentry, 0);
4653 if (d_is_dir(nd->path.dentry))
4656 d_backing_inode(nd->path.dentry));
4660 if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry))
4669 } else if (d_is_reg(nd->path.dentry) && open_flag & O_TRUNC) {
4710 struct dentry *child;
4711 struct inode *dir = d_inode(parentpath->dentry);
4722 child = d_alloc(parentpath->dentry, &slash_name);
4726 file->__f_path.dentry = child;
4796 audit_inode(nd->name, file->f_path.dentry, 0);
4809 audit_inode(nd->name, path.dentry, 0);
4881 if (d_is_symlink(root->dentry) && op->intent & LOOKUP_OPEN)
4898 static struct dentry *filename_create(int dfd, struct filename *name,
4901 struct dentry *dentry = ERR_PTR(-EEXIST);
4928 dentry = start_dirop(path->dentry, &last, reval_flag | create_flags);
4929 if (IS_ERR(dentry))
4935 return dentry;
4937 end_dirop(dentry);
4938 dentry = ERR_PTR(error);
4944 return dentry;
4947 struct dentry *start_creating_path(int dfd, const char *pathname,
4958 * @dentry: the dentry returned by start_creating_path()
4966 void end_creating_path(const struct path *path, struct dentry *dentry)
4968 end_creating(dentry);
4974 inline struct dentry *start_creating_user_path(
4991 * a negative dentry, placed in @path->dentry, for the new file.
4995 * negative dentry must reside on the same filesystem instance.
5004 struct dentry *dentry = path->dentry;
5005 struct dentry *dir = dentry->d_parent;
5017 path->dentry = dir;
5020 create_error = may_o_create(idmap, path, dentry, mode);
5024 dentry = atomic_open(path, dentry, file, flags, mode);
5025 error = PTR_ERR_OR_ZERO(dentry);
5032 fsnotify_create(dir->d_inode, dentry);
5037 path->dentry = dentry;
5040 error = vfs_create(mnt_idmap(path->mnt), path->dentry, mode, NULL);
5055 * @dentry: dentry of the child device node
5069 struct dentry *dentry, umode_t mode, dev_t dev,
5073 int error = may_create_dentry(idmap, dir, dentry);
5090 error = security_inode_mknod(dir, dentry, mode, dev);
5098 error = dir->i_op->mknod(idmap, dir, dentry, mode, dev);
5100 fsnotify_create(dir, dentry);
5127 struct dentry *dentry;
5136 dentry = filename_create(dfd, name, &path, lookup_flags);
5137 if (IS_ERR(dentry))
5138 return PTR_ERR(dentry);
5140 error = security_path_mknod(&path, dentry,
5141 mode_strip_umask(path.dentry->d_inode, mode), dev);
5148 error = vfs_create(idmap, dentry, mode, &di);
5150 security_path_post_mknod(idmap, dentry);
5153 error = vfs_mknod(idmap, path.dentry->d_inode,
5154 dentry, mode, new_decode_dev(dev), &di);
5157 error = vfs_mknod(idmap, path.dentry->d_inode,
5158 dentry, mode, 0, &di);
5162 end_creating_path(&path, dentry);
5189 * vfs_mkdir - create directory returning correct dentry if possible
5192 * @dentry: dentry of the child directory
5204 * In the event that the filesystem does not use the *@dentry but leaves it
5206 * the original dentry is dput() and the alternate is returned.
5208 * In case of an error the dentry is dput() and an ERR_PTR() is returned.
5210 struct dentry *vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
5211 struct dentry *dentry, umode_t mode,
5216 struct dentry *de;
5218 error = may_create_dentry(idmap, dir, dentry);
5227 error = security_inode_mkdir(dir, dentry, mode);
5239 de = dir->i_op->mkdir(idmap, dir, dentry, mode);
5244 dput(dentry);
5245 dentry = de;
5247 fsnotify_mkdir(dir, dentry);
5248 return dentry;
5251 end_creating(dentry);
5258 struct dentry *dentry;
5265 dentry = filename_create(dfd, name, &path, lookup_flags);
5266 if (IS_ERR(dentry))
5267 return PTR_ERR(dentry);
5269 error = security_path_mkdir(&path, dentry,
5270 mode_strip_umask(path.dentry->d_inode, mode));
5272 dentry = vfs_mkdir(mnt_idmap(path.mnt), path.dentry->d_inode,
5273 dentry, mode, &delegated_inode);
5274 if (IS_ERR(dentry))
5275 error = PTR_ERR(dentry);
5277 end_creating_path(&path, dentry);
5306 * @dentry: dentry of the child directory
5318 struct dentry *dentry, struct delegated_inode *delegated_inode)
5320 int error = may_delete_dentry(idmap, dir, dentry, true);
5328 dget(dentry);
5329 inode_lock(dentry->d_inode);
5332 if (is_local_mountpoint(dentry) ||
5333 (dentry->d_inode->i_flags & S_KERNEL_FILE))
5336 error = security_inode_rmdir(dir, dentry);
5344 error = dir->i_op->rmdir(dir, dentry);
5348 shrink_dcache_parent(dentry);
5349 dentry->d_inode->i_flags |= S_DEAD;
5350 dont_mount(dentry);
5351 detach_mounts(dentry);
5354 inode_unlock(dentry->d_inode);
5355 dput(dentry);
5357 d_delete_notify(dir, dentry);
5365 struct dentry *dentry;
5392 dentry = start_dirop(path.dentry, &last, lookup_flags);
5393 error = PTR_ERR(dentry);
5394 if (IS_ERR(dentry))
5396 error = security_path_rmdir(&path, dentry);
5399 error = vfs_rmdir(mnt_idmap(path.mnt), path.dentry->d_inode,
5400 dentry, &delegated_inode);
5402 end_dirop(dentry);
5429 * @dentry: victim
5451 struct dentry *dentry, struct delegated_inode *delegated_inode)
5453 struct inode *target = dentry->d_inode;
5454 int error = may_delete_dentry(idmap, dir, dentry, false);
5465 else if (is_local_mountpoint(dentry))
5468 error = security_inode_unlink(dir, dentry);
5476 error = dir->i_op->unlink(dir, dentry);
5478 dont_mount(dentry);
5479 detach_mounts(dentry);
5487 if (!error && dentry->d_flags & DCACHE_NFSFS_RENAMED) {
5488 fsnotify_unlink(dir, dentry);
5491 d_delete_notify(dir, dentry);
5507 struct dentry *dentry;
5527 dentry = start_dirop(path.dentry, &last, lookup_flags);
5528 error = PTR_ERR(dentry);
5529 if (IS_ERR(dentry))
5534 if (d_is_dir(dentry))
5538 end_dirop(dentry);
5541 inode = dentry->d_inode;
5543 error = security_path_unlink(&path, dentry);
5546 error = vfs_unlink(mnt_idmap(path.mnt), path.dentry->d_inode,
5547 dentry, &delegated_inode);
5549 end_dirop(dentry);
5588 * @dentry: dentry of the child symlink file
5601 struct dentry *dentry, const char *oldname,
5606 error = may_create_dentry(idmap, dir, dentry);
5613 error = security_inode_symlink(dir, dentry, oldname);
5621 error = dir->i_op->symlink(idmap, dir, dentry, oldname);
5623 fsnotify_create(dir, dentry);
5631 struct dentry *dentry;
5640 dentry = filename_create(newdfd, to, &path, lookup_flags);
5641 if (IS_ERR(dentry))
5642 return PTR_ERR(dentry);
5644 error = security_path_symlink(&path, dentry, from->name);
5646 error = vfs_symlink(mnt_idmap(path.mnt), path.dentry->d_inode,
5647 dentry, from->name, &delegated_inode);
5648 end_creating_path(&path, dentry);
5702 int vfs_link(struct dentry *old_dentry, struct mnt_idmap *idmap,
5703 struct inode *dir, struct dentry *new_dentry,
5780 struct dentry *new_dentry;
5817 error = security_path_link(old_path.dentry, &new_path, new_dentry);
5820 error = vfs_link(old_path.dentry, idmap, new_path.dentry->d_inode,
5894 * has no more than 1 dentry. If "hybrid" objects will ever appear,
5896 * d) conversion from fhandle to dentry may come in the wrong moment - when
5907 struct dentry *old_dentry = rd->old_dentry;
5908 struct dentry *new_dentry = rd->new_dentry;
6119 rd.old_parent = old_path.dentry;
6121 rd.new_parent = new_path.dentry;
6211 * @dentry: dentry on which to get symbolic link
6219 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen)
6221 struct inode *inode = d_inode(dentry);
6231 return inode->i_op->readlink(dentry, buffer, buflen);
6233 if (!d_is_symlink(dentry))
6243 link = inode->i_op->get_link(dentry, inode, &done);
6255 * @dentry: dentry on which to get symbolic link
6264 const char *vfs_get_link(struct dentry *dentry, struct delayed_call *done)
6267 struct inode *inode = d_inode(dentry);
6269 if (d_is_symlink(dentry)) {
6270 res = ERR_PTR(security_inode_readlink(dentry));
6272 res = inode->i_op->get_link(dentry, inode, done);
6279 static char *__page_get_link(struct dentry *dentry, struct inode *inode,
6285 if (!dentry) {
6303 const char *page_get_link_raw(struct dentry *dentry, struct inode *inode,
6306 return __page_get_link(dentry, inode, callback);
6312 * @dentry: The directory entry which is the symlink.
6321 const char *page_get_link(struct dentry *dentry, struct inode *inode,
6324 char *kaddr = __page_get_link(dentry, inode, callback);
6352 int page_readlink(struct dentry *dentry, char __user *buffer, int buflen)
6358 link = page_get_link(dentry, d_inode(dentry), &done);