-#ifdef HAVE_KERN_PATH_LOCKED
-/* Based on do_unlinkat() from linux/fs/namei.c */
-int
-vn_remove(const char *path, uio_seg_t seg, int flags)
-{
- struct dentry *dentry;
- struct path parent;
- struct inode *inode = NULL;
- int rc = 0;
- SENTRY;
-
- ASSERT(seg == UIO_SYSSPACE);
- ASSERT(flags == RMFILE);
-
- dentry = spl_kern_path_locked(path, &parent);
- rc = PTR_ERR(dentry);
- if (!IS_ERR(dentry)) {
- if (parent.dentry->d_name.name[parent.dentry->d_name.len])
- SGOTO(slashes, rc = 0);
-
- inode = dentry->d_inode;
- if (!inode)
- SGOTO(slashes, rc = 0);
-
- if (inode)
- ihold(inode);
-
- rc = vfs_unlink(parent.dentry->d_inode, dentry);
-exit1:
- dput(dentry);
- } else {
- return (-rc);
- }
-
- spl_inode_unlock(parent.dentry->d_inode);
- if (inode)
- iput(inode); /* truncate the inode here */
-
- path_put(&parent);
- SRETURN(-rc);
-
-slashes:
- rc = !dentry->d_inode ? -ENOENT :
- S_ISDIR(dentry->d_inode->i_mode) ? -EISDIR : -ENOTDIR;
- SGOTO(exit1, rc);
-} /* vn_remove() */
-EXPORT_SYMBOL(vn_remove);
-
-/* Based on do_rename() from linux/fs/namei.c */
-int
-vn_rename(const char *oldname, const char *newname, int x1)
-{
- struct dentry *old_dir, *new_dir;
- struct dentry *old_dentry, *new_dentry;
- struct dentry *trap;
- struct path old_parent, new_parent;
- int rc = 0;
- SENTRY;
-
- old_dentry = spl_kern_path_locked(oldname, &old_parent);
- if (IS_ERR(old_dentry))
- SGOTO(exit, rc = PTR_ERR(old_dentry));
-
- spl_inode_unlock(old_parent.dentry->d_inode);
-
- new_dentry = spl_kern_path_locked(newname, &new_parent);
- if (IS_ERR(new_dentry))
- SGOTO(exit2, rc = PTR_ERR(new_dentry));
-
- spl_inode_unlock(new_parent.dentry->d_inode);
-
- rc = -EXDEV;
- if (old_parent.mnt != new_parent.mnt)
- SGOTO(exit3, rc);
-
- old_dir = old_parent.dentry;
- new_dir = new_parent.dentry;
- trap = lock_rename(new_dir, old_dir);
-
- /* source should not be ancestor of target */
- rc = -EINVAL;
- if (old_dentry == trap)
- SGOTO(exit4, rc);
-
- /* target should not be an ancestor of source */
- rc = -ENOTEMPTY;
- if (new_dentry == trap)
- SGOTO(exit4, rc);
-
- /* source must exist */
- rc = -ENOENT;
- if (!old_dentry->d_inode)
- SGOTO(exit4, rc);
-
- /* unless the source is a directory trailing slashes give -ENOTDIR */
- if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
- rc = -ENOTDIR;
- if (old_dentry->d_name.name[old_dentry->d_name.len])
- SGOTO(exit4, rc);
- if (new_dentry->d_name.name[new_dentry->d_name.len])
- SGOTO(exit4, rc);
- }
-
-#ifdef HAVE_4ARGS_VFS_RENAME
- rc = vfs_rename(old_dir->d_inode, old_dentry,
- new_dir->d_inode, new_dentry);
-#else
- rc = vfs_rename(old_dir->d_inode, old_dentry, oldnd.nd_mnt,
- new_dir->d_inode, new_dentry, newnd.nd_mnt);
-#endif /* HAVE_4ARGS_VFS_RENAME */
-exit4:
- unlock_rename(new_dir, old_dir);
-exit3:
- dput(new_dentry);
- path_put(&new_parent);
-exit2:
- dput(old_dentry);
- path_put(&old_parent);
-exit:
- SRETURN(-rc);
-}
-EXPORT_SYMBOL(vn_rename);
-
-#else
-static struct dentry *
-vn_lookup_hash(struct nameidata *nd)
-{
- return lookup_one_len((const char *)nd->last.name,
- nd->nd_dentry, nd->last.len);
-} /* lookup_hash() */
-
-static void
-vn_path_release(struct nameidata *nd)
-{
- dput(nd->nd_dentry);
- mntput(nd->nd_mnt);
-}
-
-/* Modified do_unlinkat() from linux/fs/namei.c, only uses exported symbols */
-int
-vn_remove(const char *path, uio_seg_t seg, int flags)
-{
- struct dentry *dentry;
- struct nameidata nd;
- struct inode *inode = NULL;
- int rc = 0;
- SENTRY;
-
- ASSERT(seg == UIO_SYSSPACE);
- ASSERT(flags == RMFILE);
-
- rc = spl_kern_path_parent(path, &nd);
- if (rc)
- SGOTO(exit, rc);
-
- rc = -EISDIR;
- if (nd.last_type != LAST_NORM)
- SGOTO(exit1, rc);
-
- spl_inode_lock_nested(nd.nd_dentry->d_inode, I_MUTEX_PARENT);
- dentry = vn_lookup_hash(&nd);
- rc = PTR_ERR(dentry);
- if (!IS_ERR(dentry)) {
- /* Why not before? Because we want correct rc value */
- if (nd.last.name[nd.last.len])
- SGOTO(slashes, rc);
-
- inode = dentry->d_inode;
- if (inode)
- atomic_inc(&inode->i_count);
-#ifdef HAVE_2ARGS_VFS_UNLINK
- rc = vfs_unlink(nd.nd_dentry->d_inode, dentry);
-#else
- rc = vfs_unlink(nd.nd_dentry->d_inode, dentry, nd.nd_mnt);
-#endif /* HAVE_2ARGS_VFS_UNLINK */
-exit2:
- dput(dentry);
- }
-
- spl_inode_unlock(nd.nd_dentry->d_inode);
- if (inode)
- iput(inode); /* truncate the inode here */
-exit1:
- vn_path_release(&nd);
-exit:
- SRETURN(-rc);
-
-slashes:
- rc = !dentry->d_inode ? -ENOENT :
- S_ISDIR(dentry->d_inode->i_mode) ? -EISDIR : -ENOTDIR;
- SGOTO(exit2, rc);
-} /* vn_remove() */
-EXPORT_SYMBOL(vn_remove);
-
-/* Modified do_rename() from linux/fs/namei.c, only uses exported symbols */
-int
-vn_rename(const char *oldname, const char *newname, int x1)
-{
- struct dentry *old_dir, *new_dir;
- struct dentry *old_dentry, *new_dentry;
- struct dentry *trap;
- struct nameidata oldnd, newnd;
- int rc = 0;
- SENTRY;
-
- rc = spl_kern_path_parent(oldname, &oldnd);
- if (rc)
- SGOTO(exit, rc);
-
- rc = spl_kern_path_parent(newname, &newnd);
- if (rc)
- SGOTO(exit1, rc);
-
- rc = -EXDEV;
- if (oldnd.nd_mnt != newnd.nd_mnt)
- SGOTO(exit2, rc);
-
- old_dir = oldnd.nd_dentry;
- rc = -EBUSY;
- if (oldnd.last_type != LAST_NORM)
- SGOTO(exit2, rc);
-
- new_dir = newnd.nd_dentry;
- if (newnd.last_type != LAST_NORM)
- SGOTO(exit2, rc);
-
- trap = lock_rename(new_dir, old_dir);
-
- old_dentry = vn_lookup_hash(&oldnd);
-
- rc = PTR_ERR(old_dentry);
- if (IS_ERR(old_dentry))
- SGOTO(exit3, rc);
-
- /* source must exist */
- rc = -ENOENT;
- if (!old_dentry->d_inode)
- SGOTO(exit4, rc);
-
- /* unless the source is a directory trailing slashes give -ENOTDIR */
- if (!S_ISDIR(old_dentry->d_inode->i_mode)) {
- rc = -ENOTDIR;
- if (oldnd.last.name[oldnd.last.len])
- SGOTO(exit4, rc);
- if (newnd.last.name[newnd.last.len])
- SGOTO(exit4, rc);
- }
-
- /* source should not be ancestor of target */
- rc = -EINVAL;
- if (old_dentry == trap)
- SGOTO(exit4, rc);
-
- new_dentry = vn_lookup_hash(&newnd);
- rc = PTR_ERR(new_dentry);
- if (IS_ERR(new_dentry))
- SGOTO(exit4, rc);
-
- /* target should not be an ancestor of source */
- rc = -ENOTEMPTY;
- if (new_dentry == trap)
- SGOTO(exit5, rc);
-
-#ifdef HAVE_4ARGS_VFS_RENAME
- rc = vfs_rename(old_dir->d_inode, old_dentry,
- new_dir->d_inode, new_dentry);
-#else
- rc = vfs_rename(old_dir->d_inode, old_dentry, oldnd.nd_mnt,
- new_dir->d_inode, new_dentry, newnd.nd_mnt);
-#endif /* HAVE_4ARGS_VFS_RENAME */
-exit5:
- dput(new_dentry);
-exit4:
- dput(old_dentry);
-exit3:
- unlock_rename(new_dir, old_dir);
-exit2:
- vn_path_release(&newnd);
-exit1:
- vn_path_release(&oldnd);
-exit:
- SRETURN(-rc);
-}
-EXPORT_SYMBOL(vn_rename);
-#endif /* HAVE_KERN_PATH_LOCKED */
-