Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 3 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include "xfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include "xfs_fs.h" |
Dave Chinner | 70a9883 | 2013-10-23 10:36:05 +1100 | [diff] [blame] | 8 | #include "xfs_shared.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 9 | #include "xfs_format.h" |
| 10 | #include "xfs_log_format.h" |
| 11 | #include "xfs_trans_resv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "xfs_mount.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "xfs_inode.h" |
Hannes Eder | 7bf446f | 2009-03-05 15:20:25 +0100 | [diff] [blame] | 14 | #include "xfs_ioctl.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 15 | #include "xfs_alloc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "xfs_rtalloc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include "xfs_itable.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 18 | #include "xfs_error.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include "xfs_attr.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 20 | #include "xfs_bmap.h" |
Dave Chinner | 6898811 | 2013-08-12 20:49:42 +1000 | [diff] [blame] | 21 | #include "xfs_bmap_util.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "xfs_fsops.h" |
Christoph Hellwig | a46db60 | 2011-01-07 13:02:04 +0000 | [diff] [blame] | 23 | #include "xfs_discard.h" |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 24 | #include "xfs_quota.h" |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 25 | #include "xfs_export.h" |
Christoph Hellwig | 0b1b213 | 2009-12-14 23:14:59 +0000 | [diff] [blame] | 26 | #include "xfs_trace.h" |
Brian Foster | 8ca149d | 2012-11-07 12:21:12 -0500 | [diff] [blame] | 27 | #include "xfs_icache.h" |
Dave Chinner | c24b5df | 2013-08-12 20:49:45 +1000 | [diff] [blame] | 28 | #include "xfs_symlink.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 29 | #include "xfs_trans.h" |
Andreas Gruenbacher | 47e1bf6 | 2015-11-03 12:56:17 +1100 | [diff] [blame] | 30 | #include "xfs_acl.h" |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 31 | #include "xfs_btree.h" |
| 32 | #include <linux/fsmap.h> |
| 33 | #include "xfs_fsmap.h" |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 34 | #include "scrub/xfs_scrub.h" |
Darrick J. Wong | c368ebc | 2018-01-08 10:51:27 -0800 | [diff] [blame] | 35 | #include "xfs_sb.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 37 | #include <linux/capability.h> |
Ingo Molnar | 5b825c3 | 2017-02-02 17:54:15 +0100 | [diff] [blame] | 38 | #include <linux/cred.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/dcache.h> |
| 40 | #include <linux/mount.h> |
| 41 | #include <linux/namei.h> |
| 42 | #include <linux/pagemap.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 43 | #include <linux/slab.h> |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 44 | #include <linux/exportfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to |
| 48 | * a file or fs handle. |
| 49 | * |
| 50 | * XFS_IOC_PATH_TO_FSHANDLE |
| 51 | * returns fs handle for a mount point or path within that mount point |
| 52 | * XFS_IOC_FD_TO_HANDLE |
| 53 | * returns full handle for a FD opened in user space |
| 54 | * XFS_IOC_PATH_TO_HANDLE |
| 55 | * returns full handle for a path |
| 56 | */ |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 57 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | xfs_find_handle( |
| 59 | unsigned int cmd, |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 60 | xfs_fsop_handlereq_t *hreq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
| 62 | int hsize; |
| 63 | xfs_handle_t handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | struct inode *inode; |
Dave Chinner | a30b036 | 2013-09-02 20:49:36 +1000 | [diff] [blame] | 65 | struct fd f = {NULL}; |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 66 | struct path path; |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 67 | int error; |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 68 | struct xfs_inode *ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 70 | if (cmd == XFS_IOC_FD_TO_HANDLE) { |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 71 | f = fdget(hreq->fd); |
| 72 | if (!f.file) |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 73 | return -EBADF; |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 74 | inode = file_inode(f.file); |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 75 | } else { |
| 76 | error = user_lpath((const char __user *)hreq->path, &path); |
| 77 | if (error) |
| 78 | return error; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 79 | inode = d_inode(path.dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 81 | ip = XFS_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 83 | /* |
| 84 | * We can only generate handles for inodes residing on a XFS filesystem, |
| 85 | * and only for regular files, directories or symbolic links. |
| 86 | */ |
| 87 | error = -EINVAL; |
| 88 | if (inode->i_sb->s_magic != XFS_SB_MAGIC) |
| 89 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 91 | error = -EBADF; |
| 92 | if (!S_ISREG(inode->i_mode) && |
| 93 | !S_ISDIR(inode->i_mode) && |
| 94 | !S_ISLNK(inode->i_mode)) |
| 95 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 98 | memcpy(&handle.ha_fsid, ip->i_mount->m_fixedfsid, sizeof(xfs_fsid_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 100 | if (cmd == XFS_IOC_PATH_TO_FSHANDLE) { |
| 101 | /* |
| 102 | * This handle only contains an fsid, zero the rest. |
| 103 | */ |
| 104 | memset(&handle.ha_fid, 0, sizeof(handle.ha_fid)); |
| 105 | hsize = sizeof(xfs_fsid_t); |
| 106 | } else { |
Christoph Hellwig | c614391 | 2007-09-14 15:22:37 +1000 | [diff] [blame] | 107 | handle.ha_fid.fid_len = sizeof(xfs_fid_t) - |
| 108 | sizeof(handle.ha_fid.fid_len); |
| 109 | handle.ha_fid.fid_pad = 0; |
Dave Chinner | 9e9a267 | 2016-02-09 16:54:58 +1100 | [diff] [blame] | 110 | handle.ha_fid.fid_gen = inode->i_generation; |
Christoph Hellwig | c614391 | 2007-09-14 15:22:37 +1000 | [diff] [blame] | 111 | handle.ha_fid.fid_ino = ip->i_ino; |
Christoph Hellwig | 3398a40 | 2017-06-14 21:30:44 -0700 | [diff] [blame] | 112 | hsize = sizeof(xfs_handle_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 115 | error = -EFAULT; |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 116 | if (copy_to_user(hreq->ohandle, &handle, hsize) || |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 117 | copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32))) |
| 118 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 120 | error = 0; |
| 121 | |
| 122 | out_put: |
| 123 | if (cmd == XFS_IOC_FD_TO_HANDLE) |
Al Viro | 2903ff0 | 2012-08-28 12:52:22 -0400 | [diff] [blame] | 124 | fdput(f); |
Christoph Hellwig | 4346cdd | 2009-02-08 21:51:14 +0100 | [diff] [blame] | 125 | else |
| 126 | path_put(&path); |
| 127 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | /* |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 131 | * No need to do permission checks on the various pathname components |
| 132 | * as the handle operations are privileged. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | */ |
| 134 | STATIC int |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 135 | xfs_handle_acceptable( |
| 136 | void *context, |
| 137 | struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 139 | return 1; |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | * Convert userspace handle data into a dentry. |
| 144 | */ |
| 145 | struct dentry * |
| 146 | xfs_handle_to_dentry( |
| 147 | struct file *parfilp, |
| 148 | void __user *uhandle, |
| 149 | u32 hlen) |
| 150 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | xfs_handle_t handle; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 152 | struct xfs_fid64 fid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * Only allow handle opens under a directory. |
| 156 | */ |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 157 | if (!S_ISDIR(file_inode(parfilp)->i_mode)) |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 158 | return ERR_PTR(-ENOTDIR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 160 | if (hlen != sizeof(xfs_handle_t)) |
| 161 | return ERR_PTR(-EINVAL); |
| 162 | if (copy_from_user(&handle, uhandle, hlen)) |
| 163 | return ERR_PTR(-EFAULT); |
| 164 | if (handle.ha_fid.fid_len != |
| 165 | sizeof(handle.ha_fid) - sizeof(handle.ha_fid.fid_len)) |
| 166 | return ERR_PTR(-EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 168 | memset(&fid, 0, sizeof(struct fid)); |
| 169 | fid.ino = handle.ha_fid.fid_ino; |
| 170 | fid.gen = handle.ha_fid.fid_gen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 172 | return exportfs_decode_fh(parfilp->f_path.mnt, (struct fid *)&fid, 3, |
| 173 | FILEID_INO32_GEN | XFS_FILEID_TYPE_64FLAG, |
| 174 | xfs_handle_acceptable, NULL); |
| 175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 177 | STATIC struct dentry * |
| 178 | xfs_handlereq_to_dentry( |
| 179 | struct file *parfilp, |
| 180 | xfs_fsop_handlereq_t *hreq) |
| 181 | { |
| 182 | return xfs_handle_to_dentry(parfilp, hreq->ihandle, hreq->ihandlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
| 184 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 185 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | xfs_open_by_handle( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | struct file *parfilp, |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 188 | xfs_fsop_handlereq_t *hreq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
David Howells | 745ca24 | 2008-11-14 10:39:22 +1100 | [diff] [blame] | 190 | const struct cred *cred = current_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | int error; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 192 | int fd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | int permflag; |
| 194 | struct file *filp; |
| 195 | struct inode *inode; |
| 196 | struct dentry *dentry; |
Dave Chinner | 1a1d772 | 2012-03-22 05:15:06 +0000 | [diff] [blame] | 197 | fmode_t fmode; |
Al Viro | 765927b | 2012-06-26 21:58:53 +0400 | [diff] [blame] | 198 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | if (!capable(CAP_SYS_ADMIN)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 201 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 203 | dentry = xfs_handlereq_to_dentry(parfilp, hreq); |
| 204 | if (IS_ERR(dentry)) |
| 205 | return PTR_ERR(dentry); |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 206 | inode = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | /* Restrict xfs_open_by_handle to directories & regular files. */ |
| 209 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) { |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 210 | error = -EPERM; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 211 | goto out_dput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | #if BITS_PER_LONG != 32 |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 215 | hreq->oflags |= O_LARGEFILE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | #endif |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 217 | |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 218 | permflag = hreq->oflags; |
Dave Chinner | 1a1d772 | 2012-03-22 05:15:06 +0000 | [diff] [blame] | 219 | fmode = OPEN_FMODE(permflag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) && |
Dave Chinner | 1a1d772 | 2012-03-22 05:15:06 +0000 | [diff] [blame] | 221 | (fmode & FMODE_WRITE) && IS_APPEND(inode)) { |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 222 | error = -EPERM; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 223 | goto out_dput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Dave Chinner | 1a1d772 | 2012-03-22 05:15:06 +0000 | [diff] [blame] | 226 | if ((fmode & FMODE_WRITE) && IS_IMMUTABLE(inode)) { |
Eryu Guan | 337684a | 2016-08-02 19:58:28 +0800 | [diff] [blame] | 227 | error = -EPERM; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 228 | goto out_dput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /* Can't write directories. */ |
Dave Chinner | 1a1d772 | 2012-03-22 05:15:06 +0000 | [diff] [blame] | 232 | if (S_ISDIR(inode->i_mode) && (fmode & FMODE_WRITE)) { |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 233 | error = -EISDIR; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 234 | goto out_dput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Yann Droneaud | 862a629 | 2013-07-02 18:39:34 +0200 | [diff] [blame] | 237 | fd = get_unused_fd_flags(0); |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 238 | if (fd < 0) { |
| 239 | error = fd; |
| 240 | goto out_dput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Al Viro | 765927b | 2012-06-26 21:58:53 +0400 | [diff] [blame] | 243 | path.mnt = parfilp->f_path.mnt; |
| 244 | path.dentry = dentry; |
| 245 | filp = dentry_open(&path, hreq->oflags, cred); |
| 246 | dput(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | if (IS_ERR(filp)) { |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 248 | put_unused_fd(fd); |
| 249 | return PTR_ERR(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 251 | |
Al Viro | 0320937 | 2011-07-25 20:54:24 -0400 | [diff] [blame] | 252 | if (S_ISREG(inode->i_mode)) { |
Vlad Apostolov | 2e2e7bb | 2006-11-11 18:04:47 +1100 | [diff] [blame] | 253 | filp->f_flags |= O_NOATIME; |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 254 | filp->f_mode |= FMODE_NOCMTIME; |
Vlad Apostolov | 2e2e7bb | 2006-11-11 18:04:47 +1100 | [diff] [blame] | 255 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 257 | fd_install(fd, filp); |
| 258 | return fd; |
| 259 | |
| 260 | out_dput: |
| 261 | dput(dentry); |
| 262 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
| 264 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 265 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | xfs_readlink_by_handle( |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 267 | struct file *parfilp, |
| 268 | xfs_fsop_handlereq_t *hreq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 270 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | __u32 olen; |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 272 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | if (!capable(CAP_SYS_ADMIN)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 275 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 277 | dentry = xfs_handlereq_to_dentry(parfilp, hreq); |
| 278 | if (IS_ERR(dentry)) |
| 279 | return PTR_ERR(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | /* Restrict this handle operation to symlinks only. */ |
Miklos Szeredi | fd4a0edf | 2016-12-09 16:45:04 +0100 | [diff] [blame] | 282 | if (!d_is_symlink(dentry)) { |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 283 | error = -EINVAL; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 284 | goto out_dput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 287 | if (copy_from_user(&olen, hreq->ohandlen, sizeof(__u32))) { |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 288 | error = -EFAULT; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 289 | goto out_dput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Miklos Szeredi | fd4a0edf | 2016-12-09 16:45:04 +0100 | [diff] [blame] | 292 | error = vfs_readlink(dentry, hreq->ohandle, olen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 294 | out_dput: |
| 295 | dput(dentry); |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 296 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Dave Chinner | c24b5df | 2013-08-12 20:49:45 +1000 | [diff] [blame] | 299 | int |
| 300 | xfs_set_dmattrs( |
| 301 | xfs_inode_t *ip, |
Darrick J. Wong | 65a7935 | 2017-11-09 09:34:28 -0800 | [diff] [blame] | 302 | uint evmask, |
| 303 | uint16_t state) |
Dave Chinner | c24b5df | 2013-08-12 20:49:45 +1000 | [diff] [blame] | 304 | { |
| 305 | xfs_mount_t *mp = ip->i_mount; |
| 306 | xfs_trans_t *tp; |
| 307 | int error; |
| 308 | |
| 309 | if (!capable(CAP_SYS_ADMIN)) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 310 | return -EPERM; |
Dave Chinner | c24b5df | 2013-08-12 20:49:45 +1000 | [diff] [blame] | 311 | |
| 312 | if (XFS_FORCED_SHUTDOWN(mp)) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 313 | return -EIO; |
Dave Chinner | c24b5df | 2013-08-12 20:49:45 +1000 | [diff] [blame] | 314 | |
Christoph Hellwig | 253f491 | 2016-04-06 09:19:55 +1000 | [diff] [blame] | 315 | error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp); |
| 316 | if (error) |
Dave Chinner | c24b5df | 2013-08-12 20:49:45 +1000 | [diff] [blame] | 317 | return error; |
Christoph Hellwig | 253f491 | 2016-04-06 09:19:55 +1000 | [diff] [blame] | 318 | |
Dave Chinner | c24b5df | 2013-08-12 20:49:45 +1000 | [diff] [blame] | 319 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 320 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); |
| 321 | |
| 322 | ip->i_d.di_dmevmask = evmask; |
| 323 | ip->i_d.di_dmstate = state; |
| 324 | |
| 325 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
Christoph Hellwig | 7039331 | 2015-06-04 13:48:08 +1000 | [diff] [blame] | 326 | error = xfs_trans_commit(tp); |
Dave Chinner | c24b5df | 2013-08-12 20:49:45 +1000 | [diff] [blame] | 327 | |
| 328 | return error; |
| 329 | } |
| 330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | STATIC int |
| 332 | xfs_fssetdm_by_handle( |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 333 | struct file *parfilp, |
| 334 | void __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
| 336 | int error; |
| 337 | struct fsdmidata fsd; |
| 338 | xfs_fsop_setdm_handlereq_t dmhreq; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 339 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | if (!capable(CAP_MKNOD)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 342 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 344 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 346 | error = mnt_want_write_file(parfilp); |
| 347 | if (error) |
| 348 | return error; |
| 349 | |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 350 | dentry = xfs_handlereq_to_dentry(parfilp, &dmhreq.hreq); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 351 | if (IS_ERR(dentry)) { |
| 352 | mnt_drop_write_file(parfilp); |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 353 | return PTR_ERR(dentry); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 354 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 356 | if (IS_IMMUTABLE(d_inode(dentry)) || IS_APPEND(d_inode(dentry))) { |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 357 | error = -EPERM; |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 358 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) { |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 362 | error = -EFAULT; |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 363 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 366 | error = xfs_set_dmattrs(XFS_I(d_inode(dentry)), fsd.fsd_dmevmask, |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 367 | fsd.fsd_dmstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 369 | out: |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 370 | mnt_drop_write_file(parfilp); |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 371 | dput(dentry); |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 372 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | STATIC int |
| 376 | xfs_attrlist_by_handle( |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 377 | struct file *parfilp, |
| 378 | void __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 380 | int error = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | attrlist_cursor_kern_t *cursor; |
Darrick J. Wong | 0facef7 | 2016-08-03 10:58:53 +1000 | [diff] [blame] | 382 | struct xfs_fsop_attrlist_handlereq __user *p = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | xfs_fsop_attrlist_handlereq_t al_hreq; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 384 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | char *kbuf; |
| 386 | |
| 387 | if (!capable(CAP_SYS_ADMIN)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 388 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 390 | return -EFAULT; |
Dan Carpenter | 071c529 | 2013-10-31 21:00:10 +0300 | [diff] [blame] | 391 | if (al_hreq.buflen < sizeof(struct attrlist) || |
Jan Tulak | 4e24761 | 2015-10-12 16:02:56 +1100 | [diff] [blame] | 392 | al_hreq.buflen > XFS_XATTR_LIST_MAX) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 393 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Christoph Hellwig | 90ad58a | 2008-06-27 13:32:19 +1000 | [diff] [blame] | 395 | /* |
| 396 | * Reject flags, only allow namespaces. |
| 397 | */ |
| 398 | if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 399 | return -EINVAL; |
Christoph Hellwig | 90ad58a | 2008-06-27 13:32:19 +1000 | [diff] [blame] | 400 | |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 401 | dentry = xfs_handlereq_to_dentry(parfilp, &al_hreq.hreq); |
| 402 | if (IS_ERR(dentry)) |
| 403 | return PTR_ERR(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
Dave Chinner | fdd3cce | 2013-09-02 20:53:00 +1000 | [diff] [blame] | 405 | kbuf = kmem_zalloc_large(al_hreq.buflen, KM_SLEEP); |
| 406 | if (!kbuf) |
| 407 | goto out_dput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 409 | cursor = (attrlist_cursor_kern_t *)&al_hreq.pos; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 410 | error = xfs_attr_list(XFS_I(d_inode(dentry)), kbuf, al_hreq.buflen, |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 411 | al_hreq.flags, cursor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | if (error) |
| 413 | goto out_kfree; |
| 414 | |
Darrick J. Wong | 0facef7 | 2016-08-03 10:58:53 +1000 | [diff] [blame] | 415 | if (copy_to_user(&p->pos, cursor, sizeof(attrlist_cursor_kern_t))) { |
| 416 | error = -EFAULT; |
| 417 | goto out_kfree; |
| 418 | } |
| 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen)) |
| 421 | error = -EFAULT; |
| 422 | |
Dave Chinner | fdd3cce | 2013-09-02 20:53:00 +1000 | [diff] [blame] | 423 | out_kfree: |
| 424 | kmem_free(kbuf); |
| 425 | out_dput: |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 426 | dput(dentry); |
| 427 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
| 429 | |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 430 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | xfs_attrmulti_attr_get( |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 432 | struct inode *inode, |
Dave Chinner | a9273ca | 2010-01-20 10:47:48 +1100 | [diff] [blame] | 433 | unsigned char *name, |
| 434 | unsigned char __user *ubuf, |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 435 | uint32_t *len, |
| 436 | uint32_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | { |
Dave Chinner | a9273ca | 2010-01-20 10:47:48 +1100 | [diff] [blame] | 438 | unsigned char *kbuf; |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 439 | int error = -EFAULT; |
Barry Naujok | e8b0eba | 2008-04-22 17:34:31 +1000 | [diff] [blame] | 440 | |
Jan Tulak | 51fcbfe | 2015-10-12 16:03:59 +1100 | [diff] [blame] | 441 | if (*len > XFS_XATTR_SIZE_MAX) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 442 | return -EINVAL; |
Dave Chinner | fdd3cce | 2013-09-02 20:53:00 +1000 | [diff] [blame] | 443 | kbuf = kmem_zalloc_large(*len, KM_SLEEP); |
| 444 | if (!kbuf) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 445 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Barry Naujok | e8b0eba | 2008-04-22 17:34:31 +1000 | [diff] [blame] | 447 | error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | if (error) |
| 449 | goto out_kfree; |
| 450 | |
| 451 | if (copy_to_user(ubuf, kbuf, *len)) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 452 | error = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
Dave Chinner | fdd3cce | 2013-09-02 20:53:00 +1000 | [diff] [blame] | 454 | out_kfree: |
| 455 | kmem_free(kbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | return error; |
| 457 | } |
| 458 | |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 459 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | xfs_attrmulti_attr_set( |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 461 | struct inode *inode, |
Dave Chinner | a9273ca | 2010-01-20 10:47:48 +1100 | [diff] [blame] | 462 | unsigned char *name, |
| 463 | const unsigned char __user *ubuf, |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 464 | uint32_t len, |
| 465 | uint32_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | { |
Dave Chinner | a9273ca | 2010-01-20 10:47:48 +1100 | [diff] [blame] | 467 | unsigned char *kbuf; |
Andreas Gruenbacher | 09cb22d | 2015-11-03 12:53:54 +1100 | [diff] [blame] | 468 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 470 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 471 | return -EPERM; |
Jan Tulak | 51fcbfe | 2015-10-12 16:03:59 +1100 | [diff] [blame] | 472 | if (len > XFS_XATTR_SIZE_MAX) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 473 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Li Zefan | 0e639bd | 2009-04-08 15:08:04 +0800 | [diff] [blame] | 475 | kbuf = memdup_user(ubuf, len); |
| 476 | if (IS_ERR(kbuf)) |
| 477 | return PTR_ERR(kbuf); |
Barry Naujok | e8b0eba | 2008-04-22 17:34:31 +1000 | [diff] [blame] | 478 | |
Andreas Gruenbacher | 09cb22d | 2015-11-03 12:53:54 +1100 | [diff] [blame] | 479 | error = xfs_attr_set(XFS_I(inode), name, kbuf, len, flags); |
Andreas Gruenbacher | 47e1bf6 | 2015-11-03 12:56:17 +1100 | [diff] [blame] | 480 | if (!error) |
| 481 | xfs_forget_acl(inode, name, flags); |
Andreas Gruenbacher | 09cb22d | 2015-11-03 12:53:54 +1100 | [diff] [blame] | 482 | kfree(kbuf); |
| 483 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | } |
| 485 | |
sandeen@sandeen.net | 2875097 | 2008-11-25 21:20:15 -0600 | [diff] [blame] | 486 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | xfs_attrmulti_attr_remove( |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 488 | struct inode *inode, |
Dave Chinner | a9273ca | 2010-01-20 10:47:48 +1100 | [diff] [blame] | 489 | unsigned char *name, |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 490 | uint32_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | { |
Andreas Gruenbacher | 47e1bf6 | 2015-11-03 12:56:17 +1100 | [diff] [blame] | 492 | int error; |
| 493 | |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 494 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 495 | return -EPERM; |
Andreas Gruenbacher | 47e1bf6 | 2015-11-03 12:56:17 +1100 | [diff] [blame] | 496 | error = xfs_attr_remove(XFS_I(inode), name, flags); |
| 497 | if (!error) |
| 498 | xfs_forget_acl(inode, name, flags); |
| 499 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | STATIC int |
| 503 | xfs_attrmulti_by_handle( |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 504 | struct file *parfilp, |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 505 | void __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | { |
| 507 | int error; |
| 508 | xfs_attr_multiop_t *ops; |
| 509 | xfs_fsop_attrmulti_handlereq_t am_hreq; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 510 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | unsigned int i, size; |
Dave Chinner | a9273ca | 2010-01-20 10:47:48 +1100 | [diff] [blame] | 512 | unsigned char *attr_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
| 514 | if (!capable(CAP_SYS_ADMIN)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 515 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 517 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
Zhitong Wang | fda168c | 2010-03-23 09:51:22 +1100 | [diff] [blame] | 519 | /* overflow check */ |
| 520 | if (am_hreq.opcount >= INT_MAX / sizeof(xfs_attr_multiop_t)) |
| 521 | return -E2BIG; |
| 522 | |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 523 | dentry = xfs_handlereq_to_dentry(parfilp, &am_hreq.hreq); |
| 524 | if (IS_ERR(dentry)) |
| 525 | return PTR_ERR(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 527 | error = -E2BIG; |
Christoph Hellwig | e182f57 | 2008-06-27 13:32:31 +1000 | [diff] [blame] | 528 | size = am_hreq.opcount * sizeof(xfs_attr_multiop_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | if (!size || size > 16 * PAGE_SIZE) |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 530 | goto out_dput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Li Zefan | 0e639bd | 2009-04-08 15:08:04 +0800 | [diff] [blame] | 532 | ops = memdup_user(am_hreq.ops, size); |
| 533 | if (IS_ERR(ops)) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 534 | error = PTR_ERR(ops); |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 535 | goto out_dput; |
Li Zefan | 0e639bd | 2009-04-08 15:08:04 +0800 | [diff] [blame] | 536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 538 | error = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL); |
| 540 | if (!attr_name) |
| 541 | goto out_kfree_ops; |
| 542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | error = 0; |
| 544 | for (i = 0; i < am_hreq.opcount; i++) { |
Dave Chinner | a9273ca | 2010-01-20 10:47:48 +1100 | [diff] [blame] | 545 | ops[i].am_error = strncpy_from_user((char *)attr_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | ops[i].am_attrname, MAXNAMELEN); |
| 547 | if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 548 | error = -ERANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | if (ops[i].am_error < 0) |
| 550 | break; |
| 551 | |
| 552 | switch (ops[i].am_opcode) { |
| 553 | case ATTR_OP_GET: |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 554 | ops[i].am_error = xfs_attrmulti_attr_get( |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 555 | d_inode(dentry), attr_name, |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 556 | ops[i].am_attrvalue, &ops[i].am_length, |
| 557 | ops[i].am_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | break; |
| 559 | case ATTR_OP_SET: |
Al Viro | a561be7 | 2011-11-23 11:57:51 -0500 | [diff] [blame] | 560 | ops[i].am_error = mnt_want_write_file(parfilp); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 561 | if (ops[i].am_error) |
| 562 | break; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 563 | ops[i].am_error = xfs_attrmulti_attr_set( |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 564 | d_inode(dentry), attr_name, |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 565 | ops[i].am_attrvalue, ops[i].am_length, |
| 566 | ops[i].am_flags); |
Al Viro | 2a79f17 | 2011-12-09 08:06:57 -0500 | [diff] [blame] | 567 | mnt_drop_write_file(parfilp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | break; |
| 569 | case ATTR_OP_REMOVE: |
Al Viro | a561be7 | 2011-11-23 11:57:51 -0500 | [diff] [blame] | 570 | ops[i].am_error = mnt_want_write_file(parfilp); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 571 | if (ops[i].am_error) |
| 572 | break; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 573 | ops[i].am_error = xfs_attrmulti_attr_remove( |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 574 | d_inode(dentry), attr_name, |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 575 | ops[i].am_flags); |
Al Viro | 2a79f17 | 2011-12-09 08:06:57 -0500 | [diff] [blame] | 576 | mnt_drop_write_file(parfilp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | break; |
| 578 | default: |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 579 | ops[i].am_error = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
| 583 | if (copy_to_user(am_hreq.ops, ops, size)) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 584 | error = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
| 586 | kfree(attr_name); |
| 587 | out_kfree_ops: |
| 588 | kfree(ops); |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 589 | out_dput: |
| 590 | dput(dentry); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 591 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | } |
| 593 | |
sandeen@sandeen.net | d5547f9 | 2008-11-25 21:20:08 -0600 | [diff] [blame] | 594 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | xfs_ioc_space( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | unsigned int cmd, |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 598 | xfs_flock64_t *bf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | { |
Christoph Hellwig | 8f3e205 | 2016-07-20 11:29:35 +1000 | [diff] [blame] | 600 | struct inode *inode = file_inode(filp); |
| 601 | struct xfs_inode *ip = XFS_I(inode); |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 602 | struct iattr iattr; |
Christoph Hellwig | 8add71c | 2015-02-02 09:53:56 +1100 | [diff] [blame] | 603 | enum xfs_prealloc_flags flags = 0; |
Dan Williams | c63a8ea | 2018-03-12 14:12:29 -0700 | [diff] [blame] | 604 | uint iolock = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | int error; |
| 606 | |
Alexey Dobriyan | f37ea14 | 2006-09-28 10:52:04 +1000 | [diff] [blame] | 607 | if (inode->i_flags & (S_IMMUTABLE|S_APPEND)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 608 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
Eric Sandeen | ad4a8ac | 2005-09-02 16:41:16 +1000 | [diff] [blame] | 610 | if (!(filp->f_mode & FMODE_WRITE)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 611 | return -EBADF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
Alexey Dobriyan | f37ea14 | 2006-09-28 10:52:04 +1000 | [diff] [blame] | 613 | if (!S_ISREG(inode->i_mode)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 614 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
Christoph Hellwig | 8add71c | 2015-02-02 09:53:56 +1100 | [diff] [blame] | 616 | if (filp->f_flags & O_DSYNC) |
| 617 | flags |= XFS_PREALLOC_SYNC; |
Christoph Hellwig | 8f3e205 | 2016-07-20 11:29:35 +1000 | [diff] [blame] | 618 | if (filp->f_mode & FMODE_NOCMTIME) |
Christoph Hellwig | 8add71c | 2015-02-02 09:53:56 +1100 | [diff] [blame] | 619 | flags |= XFS_PREALLOC_INVISIBLE; |
| 620 | |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 621 | error = mnt_want_write_file(filp); |
| 622 | if (error) |
| 623 | return error; |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 624 | |
Christoph Hellwig | 781355c | 2015-02-16 11:59:50 +1100 | [diff] [blame] | 625 | xfs_ilock(ip, iolock); |
Dan Williams | 69eb5fa | 2018-03-20 14:42:38 -0700 | [diff] [blame] | 626 | error = xfs_break_layouts(inode, &iolock, BREAK_UNMAP); |
Christoph Hellwig | 781355c | 2015-02-16 11:59:50 +1100 | [diff] [blame] | 627 | if (error) |
| 628 | goto out_unlock; |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 629 | |
| 630 | switch (bf->l_whence) { |
| 631 | case 0: /*SEEK_SET*/ |
| 632 | break; |
| 633 | case 1: /*SEEK_CUR*/ |
| 634 | bf->l_start += filp->f_pos; |
| 635 | break; |
| 636 | case 2: /*SEEK_END*/ |
| 637 | bf->l_start += XFS_ISIZE(ip); |
| 638 | break; |
| 639 | default: |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 640 | error = -EINVAL; |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 641 | goto out_unlock; |
| 642 | } |
| 643 | |
| 644 | /* |
| 645 | * length of <= 0 for resv/unresv/zero is invalid. length for |
| 646 | * alloc/free is ignored completely and we have no idea what userspace |
| 647 | * might have set it to, so set it to zero to allow range |
| 648 | * checks to pass. |
| 649 | */ |
| 650 | switch (cmd) { |
| 651 | case XFS_IOC_ZERO_RANGE: |
| 652 | case XFS_IOC_RESVSP: |
| 653 | case XFS_IOC_RESVSP64: |
| 654 | case XFS_IOC_UNRESVSP: |
| 655 | case XFS_IOC_UNRESVSP64: |
| 656 | if (bf->l_len <= 0) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 657 | error = -EINVAL; |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 658 | goto out_unlock; |
| 659 | } |
| 660 | break; |
| 661 | default: |
| 662 | bf->l_len = 0; |
| 663 | break; |
| 664 | } |
| 665 | |
| 666 | if (bf->l_start < 0 || |
Christoph Hellwig | 8add71c | 2015-02-02 09:53:56 +1100 | [diff] [blame] | 667 | bf->l_start > inode->i_sb->s_maxbytes || |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 668 | bf->l_start + bf->l_len < 0 || |
Christoph Hellwig | 8add71c | 2015-02-02 09:53:56 +1100 | [diff] [blame] | 669 | bf->l_start + bf->l_len >= inode->i_sb->s_maxbytes) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 670 | error = -EINVAL; |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 671 | goto out_unlock; |
| 672 | } |
| 673 | |
| 674 | switch (cmd) { |
| 675 | case XFS_IOC_ZERO_RANGE: |
Christoph Hellwig | 8add71c | 2015-02-02 09:53:56 +1100 | [diff] [blame] | 676 | flags |= XFS_PREALLOC_SET; |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 677 | error = xfs_zero_file_space(ip, bf->l_start, bf->l_len); |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 678 | break; |
| 679 | case XFS_IOC_RESVSP: |
| 680 | case XFS_IOC_RESVSP64: |
Christoph Hellwig | 8add71c | 2015-02-02 09:53:56 +1100 | [diff] [blame] | 681 | flags |= XFS_PREALLOC_SET; |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 682 | error = xfs_alloc_file_space(ip, bf->l_start, bf->l_len, |
| 683 | XFS_BMAPI_PREALLOC); |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 684 | break; |
| 685 | case XFS_IOC_UNRESVSP: |
| 686 | case XFS_IOC_UNRESVSP64: |
| 687 | error = xfs_free_file_space(ip, bf->l_start, bf->l_len); |
| 688 | break; |
| 689 | case XFS_IOC_ALLOCSP: |
| 690 | case XFS_IOC_ALLOCSP64: |
| 691 | case XFS_IOC_FREESP: |
| 692 | case XFS_IOC_FREESP64: |
Christoph Hellwig | 8add71c | 2015-02-02 09:53:56 +1100 | [diff] [blame] | 693 | flags |= XFS_PREALLOC_CLEAR; |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 694 | if (bf->l_start > XFS_ISIZE(ip)) { |
| 695 | error = xfs_alloc_file_space(ip, XFS_ISIZE(ip), |
| 696 | bf->l_start - XFS_ISIZE(ip), 0); |
| 697 | if (error) |
| 698 | goto out_unlock; |
| 699 | } |
| 700 | |
| 701 | iattr.ia_valid = ATTR_SIZE; |
| 702 | iattr.ia_size = bf->l_start; |
| 703 | |
Jan Kara | 69bca80 | 2016-05-26 14:46:43 +0200 | [diff] [blame] | 704 | error = xfs_vn_setattr_size(file_dentry(filp), &iattr); |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 705 | break; |
| 706 | default: |
| 707 | ASSERT(0); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 708 | error = -EINVAL; |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | if (error) |
| 712 | goto out_unlock; |
| 713 | |
Christoph Hellwig | 8add71c | 2015-02-02 09:53:56 +1100 | [diff] [blame] | 714 | error = xfs_update_prealloc_flags(ip, flags); |
Christoph Hellwig | 865e944 | 2013-10-12 00:55:08 -0700 | [diff] [blame] | 715 | |
| 716 | out_unlock: |
Christoph Hellwig | 781355c | 2015-02-16 11:59:50 +1100 | [diff] [blame] | 717 | xfs_iunlock(ip, iolock); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 718 | mnt_drop_write_file(filp); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 719 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | STATIC int |
| 723 | xfs_ioc_bulkstat( |
| 724 | xfs_mount_t *mp, |
| 725 | unsigned int cmd, |
| 726 | void __user *arg) |
| 727 | { |
| 728 | xfs_fsop_bulkreq_t bulkreq; |
| 729 | int count; /* # of records returned */ |
| 730 | xfs_ino_t inlast; /* last inode number */ |
| 731 | int done; |
| 732 | int error; |
| 733 | |
| 734 | /* done = 1 if there are more stats to get and if bulkstat */ |
| 735 | /* should be called again (unused here, but used in dmapi) */ |
| 736 | |
| 737 | if (!capable(CAP_SYS_ADMIN)) |
| 738 | return -EPERM; |
| 739 | |
| 740 | if (XFS_FORCED_SHUTDOWN(mp)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 741 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
| 743 | if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 744 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | |
| 746 | if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 747 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
| 749 | if ((count = bulkreq.icount) <= 0) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 750 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 752 | if (bulkreq.ubuffer == NULL) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 753 | return -EINVAL; |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 754 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | if (cmd == XFS_IOC_FSINUMBERS) |
| 756 | error = xfs_inumbers(mp, &inlast, &count, |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 757 | bulkreq.ubuffer, xfs_inumbers_fmt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE) |
Christoph Hellwig | d716f8e | 2014-07-24 12:07:15 +1000 | [diff] [blame] | 759 | error = xfs_bulkstat_one(mp, inlast, bulkreq.ubuffer, |
| 760 | sizeof(xfs_bstat_t), NULL, &done); |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 761 | else /* XFS_IOC_FSBULKSTAT */ |
Christoph Hellwig | 7dce11d | 2010-06-23 18:11:11 +1000 | [diff] [blame] | 762 | error = xfs_bulkstat(mp, &inlast, &count, xfs_bulkstat_one, |
| 763 | sizeof(xfs_bstat_t), bulkreq.ubuffer, |
| 764 | &done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
| 766 | if (error) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 767 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
| 769 | if (bulkreq.ocount != NULL) { |
| 770 | if (copy_to_user(bulkreq.lastip, &inlast, |
| 771 | sizeof(xfs_ino_t))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 772 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
| 774 | if (copy_to_user(bulkreq.ocount, &count, sizeof(count))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 775 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | STATIC int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | xfs_ioc_fsgeometry( |
Dave Chinner | 1b6d968 | 2019-04-12 07:41:16 -0700 | [diff] [blame^] | 783 | struct xfs_mount *mp, |
| 784 | void __user *arg, |
| 785 | int struct_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | { |
Dave Chinner | 1b6d968 | 2019-04-12 07:41:16 -0700 | [diff] [blame^] | 787 | struct xfs_fsop_geom fsgeo; |
| 788 | size_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | int error; |
| 790 | |
Dave Chinner | 1b6d968 | 2019-04-12 07:41:16 -0700 | [diff] [blame^] | 791 | error = xfs_fs_geometry(&mp->m_sb, &fsgeo, struct_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | if (error) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 793 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
Dave Chinner | 1b6d968 | 2019-04-12 07:41:16 -0700 | [diff] [blame^] | 795 | if (struct_version <= 3) |
| 796 | len = sizeof(struct xfs_fsop_geom_v1); |
| 797 | else if (struct_version == 4) |
| 798 | len = sizeof(struct xfs_fsop_geom_v4); |
| 799 | else |
| 800 | len = sizeof(fsgeo); |
| 801 | |
| 802 | if (copy_to_user(arg, &fsgeo, len)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 803 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * Linux extended inode flags interface. |
| 809 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
| 811 | STATIC unsigned int |
| 812 | xfs_merge_ioc_xflags( |
| 813 | unsigned int flags, |
| 814 | unsigned int start) |
| 815 | { |
| 816 | unsigned int xflags = start; |
| 817 | |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 818 | if (flags & FS_IMMUTABLE_FL) |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 819 | xflags |= FS_XFLAG_IMMUTABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | else |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 821 | xflags &= ~FS_XFLAG_IMMUTABLE; |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 822 | if (flags & FS_APPEND_FL) |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 823 | xflags |= FS_XFLAG_APPEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | else |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 825 | xflags &= ~FS_XFLAG_APPEND; |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 826 | if (flags & FS_SYNC_FL) |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 827 | xflags |= FS_XFLAG_SYNC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | else |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 829 | xflags &= ~FS_XFLAG_SYNC; |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 830 | if (flags & FS_NOATIME_FL) |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 831 | xflags |= FS_XFLAG_NOATIME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | else |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 833 | xflags &= ~FS_XFLAG_NOATIME; |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 834 | if (flags & FS_NODUMP_FL) |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 835 | xflags |= FS_XFLAG_NODUMP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | else |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 837 | xflags &= ~FS_XFLAG_NODUMP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
| 839 | return xflags; |
| 840 | } |
| 841 | |
| 842 | STATIC unsigned int |
| 843 | xfs_di2lxflags( |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 844 | uint16_t di_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | { |
| 846 | unsigned int flags = 0; |
| 847 | |
| 848 | if (di_flags & XFS_DIFLAG_IMMUTABLE) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 849 | flags |= FS_IMMUTABLE_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | if (di_flags & XFS_DIFLAG_APPEND) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 851 | flags |= FS_APPEND_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | if (di_flags & XFS_DIFLAG_SYNC) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 853 | flags |= FS_SYNC_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | if (di_flags & XFS_DIFLAG_NOATIME) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 855 | flags |= FS_NOATIME_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | if (di_flags & XFS_DIFLAG_NODUMP) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 857 | flags |= FS_NODUMP_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | return flags; |
| 859 | } |
| 860 | |
| 861 | STATIC int |
Christoph Hellwig | c83bfab | 2007-10-11 17:47:00 +1000 | [diff] [blame] | 862 | xfs_ioc_fsgetxattr( |
| 863 | xfs_inode_t *ip, |
| 864 | int attr, |
| 865 | void __user *arg) |
| 866 | { |
| 867 | struct fsxattr fa; |
| 868 | |
Dan Rosenberg | a122eb2 | 2010-09-06 18:24:57 -0400 | [diff] [blame] | 869 | memset(&fa, 0, sizeof(struct fsxattr)); |
| 870 | |
Christoph Hellwig | c83bfab | 2007-10-11 17:47:00 +1000 | [diff] [blame] | 871 | xfs_ilock(ip, XFS_ILOCK_SHARED); |
| 872 | fa.fsx_xflags = xfs_ip2xflags(ip); |
| 873 | fa.fsx_extsize = ip->i_d.di_extsize << ip->i_mount->m_sb.sb_blocklog; |
Darrick J. Wong | f7ca352 | 2016-10-03 09:11:43 -0700 | [diff] [blame] | 874 | fa.fsx_cowextsize = ip->i_d.di_cowextsize << |
| 875 | ip->i_mount->m_sb.sb_blocklog; |
Arkadiusz Mi?kiewicz | 6743099 | 2010-09-26 06:10:18 +0000 | [diff] [blame] | 876 | fa.fsx_projid = xfs_get_projid(ip); |
Christoph Hellwig | c83bfab | 2007-10-11 17:47:00 +1000 | [diff] [blame] | 877 | |
| 878 | if (attr) { |
| 879 | if (ip->i_afp) { |
| 880 | if (ip->i_afp->if_flags & XFS_IFEXTENTS) |
Eric Sandeen | 5d82930 | 2016-11-08 12:59:42 +1100 | [diff] [blame] | 881 | fa.fsx_nextents = xfs_iext_count(ip->i_afp); |
Christoph Hellwig | c83bfab | 2007-10-11 17:47:00 +1000 | [diff] [blame] | 882 | else |
| 883 | fa.fsx_nextents = ip->i_d.di_anextents; |
| 884 | } else |
| 885 | fa.fsx_nextents = 0; |
| 886 | } else { |
| 887 | if (ip->i_df.if_flags & XFS_IFEXTENTS) |
Eric Sandeen | 5d82930 | 2016-11-08 12:59:42 +1100 | [diff] [blame] | 888 | fa.fsx_nextents = xfs_iext_count(&ip->i_df); |
Christoph Hellwig | c83bfab | 2007-10-11 17:47:00 +1000 | [diff] [blame] | 889 | else |
| 890 | fa.fsx_nextents = ip->i_d.di_nextents; |
| 891 | } |
| 892 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
| 893 | |
| 894 | if (copy_to_user(arg, &fa, sizeof(fa))) |
| 895 | return -EFAULT; |
| 896 | return 0; |
| 897 | } |
| 898 | |
Christoph Hellwig | dd60687 | 2017-09-02 08:21:20 -0700 | [diff] [blame] | 899 | STATIC uint16_t |
| 900 | xfs_flags2diflags( |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 901 | struct xfs_inode *ip, |
| 902 | unsigned int xflags) |
| 903 | { |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 904 | /* can't set PREALLOC this way, just preserve it */ |
Christoph Hellwig | dd60687 | 2017-09-02 08:21:20 -0700 | [diff] [blame] | 905 | uint16_t di_flags = |
| 906 | (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC); |
| 907 | |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 908 | if (xflags & FS_XFLAG_IMMUTABLE) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 909 | di_flags |= XFS_DIFLAG_IMMUTABLE; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 910 | if (xflags & FS_XFLAG_APPEND) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 911 | di_flags |= XFS_DIFLAG_APPEND; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 912 | if (xflags & FS_XFLAG_SYNC) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 913 | di_flags |= XFS_DIFLAG_SYNC; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 914 | if (xflags & FS_XFLAG_NOATIME) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 915 | di_flags |= XFS_DIFLAG_NOATIME; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 916 | if (xflags & FS_XFLAG_NODUMP) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 917 | di_flags |= XFS_DIFLAG_NODUMP; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 918 | if (xflags & FS_XFLAG_NODEFRAG) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 919 | di_flags |= XFS_DIFLAG_NODEFRAG; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 920 | if (xflags & FS_XFLAG_FILESTREAM) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 921 | di_flags |= XFS_DIFLAG_FILESTREAM; |
Dave Chinner | c19b3b05 | 2016-02-09 16:54:58 +1100 | [diff] [blame] | 922 | if (S_ISDIR(VFS_I(ip)->i_mode)) { |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 923 | if (xflags & FS_XFLAG_RTINHERIT) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 924 | di_flags |= XFS_DIFLAG_RTINHERIT; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 925 | if (xflags & FS_XFLAG_NOSYMLINKS) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 926 | di_flags |= XFS_DIFLAG_NOSYMLINKS; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 927 | if (xflags & FS_XFLAG_EXTSZINHERIT) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 928 | di_flags |= XFS_DIFLAG_EXTSZINHERIT; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 929 | if (xflags & FS_XFLAG_PROJINHERIT) |
Dave Chinner | 9336e3a | 2014-10-02 09:18:40 +1000 | [diff] [blame] | 930 | di_flags |= XFS_DIFLAG_PROJINHERIT; |
Dave Chinner | c19b3b05 | 2016-02-09 16:54:58 +1100 | [diff] [blame] | 931 | } else if (S_ISREG(VFS_I(ip)->i_mode)) { |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 932 | if (xflags & FS_XFLAG_REALTIME) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 933 | di_flags |= XFS_DIFLAG_REALTIME; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 934 | if (xflags & FS_XFLAG_EXTSIZE) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 935 | di_flags |= XFS_DIFLAG_EXTSIZE; |
| 936 | } |
Dave Chinner | 58f88ca | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 937 | |
Christoph Hellwig | dd60687 | 2017-09-02 08:21:20 -0700 | [diff] [blame] | 938 | return di_flags; |
| 939 | } |
Dave Chinner | 58f88ca | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 940 | |
Christoph Hellwig | dd60687 | 2017-09-02 08:21:20 -0700 | [diff] [blame] | 941 | STATIC uint64_t |
| 942 | xfs_flags2diflags2( |
| 943 | struct xfs_inode *ip, |
| 944 | unsigned int xflags) |
| 945 | { |
| 946 | uint64_t di_flags2 = |
| 947 | (ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK); |
| 948 | |
Dave Chinner | 58f88ca | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 949 | if (xflags & FS_XFLAG_DAX) |
| 950 | di_flags2 |= XFS_DIFLAG2_DAX; |
Darrick J. Wong | f7ca352 | 2016-10-03 09:11:43 -0700 | [diff] [blame] | 951 | if (xflags & FS_XFLAG_COWEXTSIZE) |
| 952 | di_flags2 |= XFS_DIFLAG2_COWEXTSIZE; |
Dave Chinner | 58f88ca | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 953 | |
Christoph Hellwig | dd60687 | 2017-09-02 08:21:20 -0700 | [diff] [blame] | 954 | return di_flags2; |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 955 | } |
| 956 | |
Christoph Hellwig | f13fae2 | 2008-07-21 16:16:15 +1000 | [diff] [blame] | 957 | STATIC void |
| 958 | xfs_diflags_to_linux( |
| 959 | struct xfs_inode *ip) |
| 960 | { |
David Chinner | e4f7529 | 2008-08-13 16:00:45 +1000 | [diff] [blame] | 961 | struct inode *inode = VFS_I(ip); |
Christoph Hellwig | f13fae2 | 2008-07-21 16:16:15 +1000 | [diff] [blame] | 962 | unsigned int xflags = xfs_ip2xflags(ip); |
| 963 | |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 964 | if (xflags & FS_XFLAG_IMMUTABLE) |
Christoph Hellwig | f13fae2 | 2008-07-21 16:16:15 +1000 | [diff] [blame] | 965 | inode->i_flags |= S_IMMUTABLE; |
| 966 | else |
| 967 | inode->i_flags &= ~S_IMMUTABLE; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 968 | if (xflags & FS_XFLAG_APPEND) |
Christoph Hellwig | f13fae2 | 2008-07-21 16:16:15 +1000 | [diff] [blame] | 969 | inode->i_flags |= S_APPEND; |
| 970 | else |
| 971 | inode->i_flags &= ~S_APPEND; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 972 | if (xflags & FS_XFLAG_SYNC) |
Christoph Hellwig | f13fae2 | 2008-07-21 16:16:15 +1000 | [diff] [blame] | 973 | inode->i_flags |= S_SYNC; |
| 974 | else |
| 975 | inode->i_flags &= ~S_SYNC; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 976 | if (xflags & FS_XFLAG_NOATIME) |
Christoph Hellwig | f13fae2 | 2008-07-21 16:16:15 +1000 | [diff] [blame] | 977 | inode->i_flags |= S_NOATIME; |
| 978 | else |
| 979 | inode->i_flags &= ~S_NOATIME; |
Christoph Hellwig | 742d842 | 2017-08-30 09:23:01 -0700 | [diff] [blame] | 980 | #if 0 /* disabled until the flag switching races are sorted out */ |
Dave Chinner | 58f88ca | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 981 | if (xflags & FS_XFLAG_DAX) |
| 982 | inode->i_flags |= S_DAX; |
| 983 | else |
| 984 | inode->i_flags &= ~S_DAX; |
Christoph Hellwig | 742d842 | 2017-08-30 09:23:01 -0700 | [diff] [blame] | 985 | #endif |
Christoph Hellwig | f13fae2 | 2008-07-21 16:16:15 +1000 | [diff] [blame] | 986 | } |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 987 | |
Dave Chinner | 29a17c0 | 2015-02-02 10:14:25 +1100 | [diff] [blame] | 988 | static int |
| 989 | xfs_ioctl_setattr_xflags( |
| 990 | struct xfs_trans *tp, |
| 991 | struct xfs_inode *ip, |
| 992 | struct fsxattr *fa) |
| 993 | { |
| 994 | struct xfs_mount *mp = ip->i_mount; |
Christoph Hellwig | dd60687 | 2017-09-02 08:21:20 -0700 | [diff] [blame] | 995 | uint64_t di_flags2; |
Dave Chinner | 29a17c0 | 2015-02-02 10:14:25 +1100 | [diff] [blame] | 996 | |
| 997 | /* Can't change realtime flag if any extents are allocated. */ |
| 998 | if ((ip->i_d.di_nextents || ip->i_delayed_blks) && |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 999 | XFS_IS_REALTIME_INODE(ip) != (fa->fsx_xflags & FS_XFLAG_REALTIME)) |
Dave Chinner | 29a17c0 | 2015-02-02 10:14:25 +1100 | [diff] [blame] | 1000 | return -EINVAL; |
| 1001 | |
| 1002 | /* If realtime flag is set then must have realtime device */ |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 1003 | if (fa->fsx_xflags & FS_XFLAG_REALTIME) { |
Dave Chinner | 29a17c0 | 2015-02-02 10:14:25 +1100 | [diff] [blame] | 1004 | if (mp->m_sb.sb_rblocks == 0 || mp->m_sb.sb_rextsize == 0 || |
| 1005 | (ip->i_d.di_extsize % mp->m_sb.sb_rextsize)) |
| 1006 | return -EINVAL; |
| 1007 | } |
| 1008 | |
Darrick J. Wong | 1987fd7 | 2016-10-10 16:49:29 +1100 | [diff] [blame] | 1009 | /* Clear reflink if we are actually able to set the rt flag. */ |
Darrick J. Wong | c8e156a | 2016-10-03 09:11:50 -0700 | [diff] [blame] | 1010 | if ((fa->fsx_xflags & FS_XFLAG_REALTIME) && xfs_is_reflink_inode(ip)) |
Darrick J. Wong | 1987fd7 | 2016-10-10 16:49:29 +1100 | [diff] [blame] | 1011 | ip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK; |
Darrick J. Wong | c8e156a | 2016-10-03 09:11:50 -0700 | [diff] [blame] | 1012 | |
Darrick J. Wong | 4f435eb | 2016-10-03 09:11:50 -0700 | [diff] [blame] | 1013 | /* Don't allow us to set DAX mode for a reflinked file for now. */ |
| 1014 | if ((fa->fsx_xflags & FS_XFLAG_DAX) && xfs_is_reflink_inode(ip)) |
| 1015 | return -EINVAL; |
| 1016 | |
Dave Chinner | 29a17c0 | 2015-02-02 10:14:25 +1100 | [diff] [blame] | 1017 | /* |
| 1018 | * Can't modify an immutable/append-only file unless |
| 1019 | * we have appropriate permission. |
| 1020 | */ |
| 1021 | if (((ip->i_d.di_flags & (XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND)) || |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 1022 | (fa->fsx_xflags & (FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND))) && |
Dave Chinner | 29a17c0 | 2015-02-02 10:14:25 +1100 | [diff] [blame] | 1023 | !capable(CAP_LINUX_IMMUTABLE)) |
| 1024 | return -EPERM; |
| 1025 | |
Christoph Hellwig | dd60687 | 2017-09-02 08:21:20 -0700 | [diff] [blame] | 1026 | /* diflags2 only valid for v3 inodes. */ |
| 1027 | di_flags2 = xfs_flags2diflags2(ip, fa->fsx_xflags); |
| 1028 | if (di_flags2 && ip->i_d.di_version < 3) |
| 1029 | return -EINVAL; |
| 1030 | |
| 1031 | ip->i_d.di_flags = xfs_flags2diflags(ip, fa->fsx_xflags); |
| 1032 | ip->i_d.di_flags2 = di_flags2; |
| 1033 | |
Dave Chinner | 29a17c0 | 2015-02-02 10:14:25 +1100 | [diff] [blame] | 1034 | xfs_diflags_to_linux(ip); |
| 1035 | xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG); |
| 1036 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
Bill O'Donnell | ff6d6af | 2015-10-12 18:21:22 +1100 | [diff] [blame] | 1037 | XFS_STATS_INC(mp, xs_ig_attrchg); |
Dave Chinner | 29a17c0 | 2015-02-02 10:14:25 +1100 | [diff] [blame] | 1038 | return 0; |
| 1039 | } |
| 1040 | |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1041 | /* |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1042 | * If we are changing DAX flags, we have to ensure the file is clean and any |
| 1043 | * cached objects in the address space are invalidated and removed. This |
| 1044 | * requires us to lock out other IO and page faults similar to a truncate |
| 1045 | * operation. The locks need to be held until the transaction has been committed |
| 1046 | * so that the cache invalidation is atomic with respect to the DAX flag |
| 1047 | * manipulation. |
| 1048 | */ |
| 1049 | static int |
| 1050 | xfs_ioctl_setattr_dax_invalidate( |
| 1051 | struct xfs_inode *ip, |
| 1052 | struct fsxattr *fa, |
| 1053 | int *join_flags) |
| 1054 | { |
| 1055 | struct inode *inode = VFS_I(ip); |
Ross Zwisler | 6851a3d | 2017-09-18 14:46:03 -0700 | [diff] [blame] | 1056 | struct super_block *sb = inode->i_sb; |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1057 | int error; |
| 1058 | |
| 1059 | *join_flags = 0; |
| 1060 | |
| 1061 | /* |
| 1062 | * It is only valid to set the DAX flag on regular files and |
Dave Chinner | 6448543 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1063 | * directories on filesystems where the block size is equal to the page |
Darrick J. Wong | aaacdd2 | 2018-05-31 15:07:47 -0700 | [diff] [blame] | 1064 | * size. On directories it serves as an inherited hint so we don't |
| 1065 | * have to check the device for dax support or flush pagecache. |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1066 | */ |
Dave Chinner | 6448543 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1067 | if (fa->fsx_xflags & FS_XFLAG_DAX) { |
| 1068 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) |
| 1069 | return -EINVAL; |
Darrick J. Wong | aaacdd2 | 2018-05-31 15:07:47 -0700 | [diff] [blame] | 1070 | if (S_ISREG(inode->i_mode) && |
| 1071 | !bdev_dax_supported(xfs_find_bdev_for_inode(VFS_I(ip)), |
Dave Jiang | 80660f2 | 2018-05-30 13:03:46 -0700 | [diff] [blame] | 1072 | sb->s_blocksize)) |
Dave Chinner | 6448543 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1073 | return -EINVAL; |
| 1074 | } |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1075 | |
| 1076 | /* If the DAX state is not changing, we have nothing to do here. */ |
| 1077 | if ((fa->fsx_xflags & FS_XFLAG_DAX) && IS_DAX(inode)) |
| 1078 | return 0; |
| 1079 | if (!(fa->fsx_xflags & FS_XFLAG_DAX) && !IS_DAX(inode)) |
| 1080 | return 0; |
| 1081 | |
Darrick J. Wong | aaacdd2 | 2018-05-31 15:07:47 -0700 | [diff] [blame] | 1082 | if (S_ISDIR(inode->i_mode)) |
| 1083 | return 0; |
| 1084 | |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1085 | /* lock, flush and invalidate mapping in preparation for flag change */ |
| 1086 | xfs_ilock(ip, XFS_MMAPLOCK_EXCL | XFS_IOLOCK_EXCL); |
| 1087 | error = filemap_write_and_wait(inode->i_mapping); |
| 1088 | if (error) |
| 1089 | goto out_unlock; |
| 1090 | error = invalidate_inode_pages2(inode->i_mapping); |
| 1091 | if (error) |
| 1092 | goto out_unlock; |
| 1093 | |
| 1094 | *join_flags = XFS_MMAPLOCK_EXCL | XFS_IOLOCK_EXCL; |
| 1095 | return 0; |
| 1096 | |
| 1097 | out_unlock: |
| 1098 | xfs_iunlock(ip, XFS_MMAPLOCK_EXCL | XFS_IOLOCK_EXCL); |
| 1099 | return error; |
| 1100 | |
| 1101 | } |
| 1102 | |
| 1103 | /* |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1104 | * Set up the transaction structure for the setattr operation, checking that we |
| 1105 | * have permission to do so. On success, return a clean transaction and the |
| 1106 | * inode locked exclusively ready for further operation specific checks. On |
| 1107 | * failure, return an error without modifying or locking the inode. |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1108 | * |
| 1109 | * The inode might already be IO locked on call. If this is the case, it is |
| 1110 | * indicated in @join_flags and we take full responsibility for ensuring they |
| 1111 | * are unlocked from now on. Hence if we have an error here, we still have to |
| 1112 | * unlock them. Otherwise, once they are joined to the transaction, they will |
| 1113 | * be unlocked on commit/cancel. |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1114 | */ |
| 1115 | static struct xfs_trans * |
| 1116 | xfs_ioctl_setattr_get_trans( |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1117 | struct xfs_inode *ip, |
| 1118 | int join_flags) |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1119 | { |
| 1120 | struct xfs_mount *mp = ip->i_mount; |
| 1121 | struct xfs_trans *tp; |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1122 | int error = -EROFS; |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1123 | |
| 1124 | if (mp->m_flags & XFS_MOUNT_RDONLY) |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1125 | goto out_unlock; |
| 1126 | error = -EIO; |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1127 | if (XFS_FORCED_SHUTDOWN(mp)) |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1128 | goto out_unlock; |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1129 | |
Christoph Hellwig | 253f491 | 2016-04-06 09:19:55 +1000 | [diff] [blame] | 1130 | error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp); |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1131 | if (error) |
Christoph Hellwig | 253f491 | 2016-04-06 09:19:55 +1000 | [diff] [blame] | 1132 | return ERR_PTR(error); |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1133 | |
| 1134 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1135 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | join_flags); |
| 1136 | join_flags = 0; |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1137 | |
| 1138 | /* |
| 1139 | * CAP_FOWNER overrides the following restrictions: |
| 1140 | * |
| 1141 | * The user ID of the calling process must be equal to the file owner |
| 1142 | * ID, except in cases where the CAP_FSETID capability is applicable. |
| 1143 | */ |
| 1144 | if (!inode_owner_or_capable(VFS_I(ip))) { |
| 1145 | error = -EPERM; |
| 1146 | goto out_cancel; |
| 1147 | } |
| 1148 | |
| 1149 | if (mp->m_flags & XFS_MOUNT_WSYNC) |
| 1150 | xfs_trans_set_sync(tp); |
| 1151 | |
| 1152 | return tp; |
| 1153 | |
| 1154 | out_cancel: |
Christoph Hellwig | 4906e21 | 2015-06-04 13:47:56 +1000 | [diff] [blame] | 1155 | xfs_trans_cancel(tp); |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1156 | out_unlock: |
| 1157 | if (join_flags) |
| 1158 | xfs_iunlock(ip, join_flags); |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1159 | return ERR_PTR(error); |
| 1160 | } |
| 1161 | |
Iustin Pop | 9b94fcc | 2015-02-02 10:26:26 +1100 | [diff] [blame] | 1162 | /* |
| 1163 | * extent size hint validation is somewhat cumbersome. Rules are: |
| 1164 | * |
| 1165 | * 1. extent size hint is only valid for directories and regular files |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 1166 | * 2. FS_XFLAG_EXTSIZE is only valid for regular files |
| 1167 | * 3. FS_XFLAG_EXTSZINHERIT is only valid for directories. |
Iustin Pop | 9b94fcc | 2015-02-02 10:26:26 +1100 | [diff] [blame] | 1168 | * 4. can only be changed on regular files if no extents are allocated |
| 1169 | * 5. can be changed on directories at any time |
| 1170 | * 6. extsize hint of 0 turns off hints, clears inode flags. |
| 1171 | * 7. Extent size must be a multiple of the appropriate block size. |
| 1172 | * 8. for non-realtime files, the extent size hint must be limited |
| 1173 | * to half the AG size to avoid alignment extending the extent beyond the |
| 1174 | * limits of the AG. |
Darrick J. Wong | 80e4e12 | 2017-10-17 21:37:42 -0700 | [diff] [blame] | 1175 | * |
| 1176 | * Please keep this function in sync with xfs_scrub_inode_extsize. |
Iustin Pop | 9b94fcc | 2015-02-02 10:26:26 +1100 | [diff] [blame] | 1177 | */ |
kbuild test robot | f92090e | 2015-02-05 11:13:21 +1100 | [diff] [blame] | 1178 | static int |
Dave Chinner | d4388d3c | 2015-02-02 10:22:20 +1100 | [diff] [blame] | 1179 | xfs_ioctl_setattr_check_extsize( |
| 1180 | struct xfs_inode *ip, |
| 1181 | struct fsxattr *fa) |
| 1182 | { |
| 1183 | struct xfs_mount *mp = ip->i_mount; |
| 1184 | |
Dave Chinner | c19b3b05 | 2016-02-09 16:54:58 +1100 | [diff] [blame] | 1185 | if ((fa->fsx_xflags & FS_XFLAG_EXTSIZE) && !S_ISREG(VFS_I(ip)->i_mode)) |
Iustin Pop | 9b94fcc | 2015-02-02 10:26:26 +1100 | [diff] [blame] | 1186 | return -EINVAL; |
| 1187 | |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 1188 | if ((fa->fsx_xflags & FS_XFLAG_EXTSZINHERIT) && |
Dave Chinner | c19b3b05 | 2016-02-09 16:54:58 +1100 | [diff] [blame] | 1189 | !S_ISDIR(VFS_I(ip)->i_mode)) |
Iustin Pop | 9b94fcc | 2015-02-02 10:26:26 +1100 | [diff] [blame] | 1190 | return -EINVAL; |
| 1191 | |
Dave Chinner | c19b3b05 | 2016-02-09 16:54:58 +1100 | [diff] [blame] | 1192 | if (S_ISREG(VFS_I(ip)->i_mode) && ip->i_d.di_nextents && |
Dave Chinner | d4388d3c | 2015-02-02 10:22:20 +1100 | [diff] [blame] | 1193 | ((ip->i_d.di_extsize << mp->m_sb.sb_blocklog) != fa->fsx_extsize)) |
| 1194 | return -EINVAL; |
| 1195 | |
Dave Chinner | d4388d3c | 2015-02-02 10:22:20 +1100 | [diff] [blame] | 1196 | if (fa->fsx_extsize != 0) { |
| 1197 | xfs_extlen_t size; |
| 1198 | xfs_fsblock_t extsize_fsb; |
| 1199 | |
| 1200 | extsize_fsb = XFS_B_TO_FSB(mp, fa->fsx_extsize); |
| 1201 | if (extsize_fsb > MAXEXTLEN) |
| 1202 | return -EINVAL; |
| 1203 | |
| 1204 | if (XFS_IS_REALTIME_INODE(ip) || |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 1205 | (fa->fsx_xflags & FS_XFLAG_REALTIME)) { |
Dave Chinner | d4388d3c | 2015-02-02 10:22:20 +1100 | [diff] [blame] | 1206 | size = mp->m_sb.sb_rextsize << mp->m_sb.sb_blocklog; |
| 1207 | } else { |
| 1208 | size = mp->m_sb.sb_blocksize; |
| 1209 | if (extsize_fsb > mp->m_sb.sb_agblocks / 2) |
| 1210 | return -EINVAL; |
| 1211 | } |
| 1212 | |
| 1213 | if (fa->fsx_extsize % size) |
| 1214 | return -EINVAL; |
Iustin Pop | 9b94fcc | 2015-02-02 10:26:26 +1100 | [diff] [blame] | 1215 | } else |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 1216 | fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT); |
Iustin Pop | 9b94fcc | 2015-02-02 10:26:26 +1100 | [diff] [blame] | 1217 | |
Dave Chinner | d4388d3c | 2015-02-02 10:22:20 +1100 | [diff] [blame] | 1218 | return 0; |
| 1219 | } |
| 1220 | |
Darrick J. Wong | f7ca352 | 2016-10-03 09:11:43 -0700 | [diff] [blame] | 1221 | /* |
| 1222 | * CoW extent size hint validation rules are: |
| 1223 | * |
| 1224 | * 1. CoW extent size hint can only be set if reflink is enabled on the fs. |
| 1225 | * The inode does not have to have any shared blocks, but it must be a v3. |
| 1226 | * 2. FS_XFLAG_COWEXTSIZE is only valid for directories and regular files; |
| 1227 | * for a directory, the hint is propagated to new files. |
| 1228 | * 3. Can be changed on files & directories at any time. |
| 1229 | * 4. CoW extsize hint of 0 turns off hints, clears inode flags. |
| 1230 | * 5. Extent size must be a multiple of the appropriate block size. |
| 1231 | * 6. The extent size hint must be limited to half the AG size to avoid |
| 1232 | * alignment extending the extent beyond the limits of the AG. |
Darrick J. Wong | 80e4e12 | 2017-10-17 21:37:42 -0700 | [diff] [blame] | 1233 | * |
| 1234 | * Please keep this function in sync with xfs_scrub_inode_cowextsize. |
Darrick J. Wong | f7ca352 | 2016-10-03 09:11:43 -0700 | [diff] [blame] | 1235 | */ |
| 1236 | static int |
| 1237 | xfs_ioctl_setattr_check_cowextsize( |
| 1238 | struct xfs_inode *ip, |
| 1239 | struct fsxattr *fa) |
| 1240 | { |
| 1241 | struct xfs_mount *mp = ip->i_mount; |
| 1242 | |
| 1243 | if (!(fa->fsx_xflags & FS_XFLAG_COWEXTSIZE)) |
| 1244 | return 0; |
| 1245 | |
| 1246 | if (!xfs_sb_version_hasreflink(&ip->i_mount->m_sb) || |
| 1247 | ip->i_d.di_version != 3) |
| 1248 | return -EINVAL; |
| 1249 | |
| 1250 | if (!S_ISREG(VFS_I(ip)->i_mode) && !S_ISDIR(VFS_I(ip)->i_mode)) |
| 1251 | return -EINVAL; |
| 1252 | |
| 1253 | if (fa->fsx_cowextsize != 0) { |
| 1254 | xfs_extlen_t size; |
| 1255 | xfs_fsblock_t cowextsize_fsb; |
| 1256 | |
| 1257 | cowextsize_fsb = XFS_B_TO_FSB(mp, fa->fsx_cowextsize); |
| 1258 | if (cowextsize_fsb > MAXEXTLEN) |
| 1259 | return -EINVAL; |
| 1260 | |
| 1261 | size = mp->m_sb.sb_blocksize; |
| 1262 | if (cowextsize_fsb > mp->m_sb.sb_agblocks / 2) |
| 1263 | return -EINVAL; |
| 1264 | |
| 1265 | if (fa->fsx_cowextsize % size) |
| 1266 | return -EINVAL; |
| 1267 | } else |
| 1268 | fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE; |
| 1269 | |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
kbuild test robot | f92090e | 2015-02-05 11:13:21 +1100 | [diff] [blame] | 1273 | static int |
Dave Chinner | 23bd073 | 2015-02-02 10:22:53 +1100 | [diff] [blame] | 1274 | xfs_ioctl_setattr_check_projid( |
| 1275 | struct xfs_inode *ip, |
| 1276 | struct fsxattr *fa) |
| 1277 | { |
| 1278 | /* Disallow 32bit project ids if projid32bit feature is not enabled. */ |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 1279 | if (fa->fsx_projid > (uint16_t)-1 && |
Dave Chinner | 23bd073 | 2015-02-02 10:22:53 +1100 | [diff] [blame] | 1280 | !xfs_sb_version_hasprojid32bit(&ip->i_mount->m_sb)) |
| 1281 | return -EINVAL; |
| 1282 | |
| 1283 | /* |
| 1284 | * Project Quota ID state is only allowed to change from within the init |
| 1285 | * namespace. Enforce that restriction only if we are trying to change |
| 1286 | * the quota ID state. Everything else is allowed in user namespaces. |
| 1287 | */ |
| 1288 | if (current_user_ns() == &init_user_ns) |
| 1289 | return 0; |
| 1290 | |
| 1291 | if (xfs_get_projid(ip) != fa->fsx_projid) |
| 1292 | return -EINVAL; |
Dave Chinner | e7b8948 | 2016-01-04 16:44:15 +1100 | [diff] [blame] | 1293 | if ((fa->fsx_xflags & FS_XFLAG_PROJINHERIT) != |
Dave Chinner | 23bd073 | 2015-02-02 10:22:53 +1100 | [diff] [blame] | 1294 | (ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)) |
| 1295 | return -EINVAL; |
| 1296 | |
| 1297 | return 0; |
| 1298 | } |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1299 | |
| 1300 | STATIC int |
| 1301 | xfs_ioctl_setattr( |
| 1302 | xfs_inode_t *ip, |
Dave Chinner | fd179b9 | 2015-02-02 10:16:25 +1100 | [diff] [blame] | 1303 | struct fsxattr *fa) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1304 | { |
| 1305 | struct xfs_mount *mp = ip->i_mount; |
| 1306 | struct xfs_trans *tp; |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 1307 | struct xfs_dquot *udqp = NULL; |
Chandra Seetharaman | 92f8ff7 | 2013-07-11 00:00:40 -0500 | [diff] [blame] | 1308 | struct xfs_dquot *pdqp = NULL; |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1309 | struct xfs_dquot *olddquot = NULL; |
| 1310 | int code; |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1311 | int join_flags = 0; |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1312 | |
Christoph Hellwig | cca28fb | 2010-06-24 11:57:09 +1000 | [diff] [blame] | 1313 | trace_xfs_ioctl_setattr(ip); |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1314 | |
Dave Chinner | 23bd073 | 2015-02-02 10:22:53 +1100 | [diff] [blame] | 1315 | code = xfs_ioctl_setattr_check_projid(ip, fa); |
| 1316 | if (code) |
| 1317 | return code; |
Arkadiusz Mi?kiewicz | 23963e54 | 2010-08-26 10:19:43 +0000 | [diff] [blame] | 1318 | |
| 1319 | /* |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1320 | * If disk quotas is on, we make sure that the dquots do exist on disk, |
| 1321 | * before we start any other transactions. Trying to do this later |
| 1322 | * is messy. We don't care to take a readlock to look at the ids |
| 1323 | * in inode here, because we can't hold it across the trans_reserve. |
| 1324 | * If the IDs do change before we take the ilock, we're covered |
| 1325 | * because the i_*dquot fields will get updated anyway. |
| 1326 | */ |
Dave Chinner | fd179b9 | 2015-02-02 10:16:25 +1100 | [diff] [blame] | 1327 | if (XFS_IS_QUOTA_ON(mp)) { |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 1328 | code = xfs_qm_vop_dqalloc(ip, ip->i_d.di_uid, |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1329 | ip->i_d.di_gid, fa->fsx_projid, |
Chandra Seetharaman | 92f8ff7 | 2013-07-11 00:00:40 -0500 | [diff] [blame] | 1330 | XFS_QMOPT_PQUOTA, &udqp, NULL, &pdqp); |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1331 | if (code) |
| 1332 | return code; |
| 1333 | } |
| 1334 | |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1335 | /* |
| 1336 | * Changing DAX config may require inode locking for mapping |
| 1337 | * invalidation. These need to be held all the way to transaction commit |
| 1338 | * or cancel time, so need to be passed through to |
| 1339 | * xfs_ioctl_setattr_get_trans() so it can apply them to the join call |
| 1340 | * appropriately. |
| 1341 | */ |
| 1342 | code = xfs_ioctl_setattr_dax_invalidate(ip, fa, &join_flags); |
| 1343 | if (code) |
| 1344 | goto error_free_dquots; |
| 1345 | |
| 1346 | tp = xfs_ioctl_setattr_get_trans(ip, join_flags); |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1347 | if (IS_ERR(tp)) { |
| 1348 | code = PTR_ERR(tp); |
| 1349 | goto error_free_dquots; |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1350 | } |
| 1351 | |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1352 | |
Dave Chinner | fd179b9 | 2015-02-02 10:16:25 +1100 | [diff] [blame] | 1353 | if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp) && |
| 1354 | xfs_get_projid(ip) != fa->fsx_projid) { |
| 1355 | code = xfs_qm_vop_chown_reserve(tp, ip, udqp, NULL, pdqp, |
| 1356 | capable(CAP_FOWNER) ? XFS_QMOPT_FORCE_RES : 0); |
| 1357 | if (code) /* out of quota */ |
Dave Chinner | d4388d3c | 2015-02-02 10:22:20 +1100 | [diff] [blame] | 1358 | goto error_trans_cancel; |
Dave Chinner | fd179b9 | 2015-02-02 10:16:25 +1100 | [diff] [blame] | 1359 | } |
| 1360 | |
Dave Chinner | d4388d3c | 2015-02-02 10:22:20 +1100 | [diff] [blame] | 1361 | code = xfs_ioctl_setattr_check_extsize(ip, fa); |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1362 | if (code) |
Dave Chinner | d4388d3c | 2015-02-02 10:22:20 +1100 | [diff] [blame] | 1363 | goto error_trans_cancel; |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1364 | |
Darrick J. Wong | f7ca352 | 2016-10-03 09:11:43 -0700 | [diff] [blame] | 1365 | code = xfs_ioctl_setattr_check_cowextsize(ip, fa); |
| 1366 | if (code) |
| 1367 | goto error_trans_cancel; |
| 1368 | |
Dave Chinner | 29a17c0 | 2015-02-02 10:14:25 +1100 | [diff] [blame] | 1369 | code = xfs_ioctl_setattr_xflags(tp, ip, fa); |
| 1370 | if (code) |
Dave Chinner | d4388d3c | 2015-02-02 10:22:20 +1100 | [diff] [blame] | 1371 | goto error_trans_cancel; |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1372 | |
| 1373 | /* |
Dave Chinner | fd179b9 | 2015-02-02 10:16:25 +1100 | [diff] [blame] | 1374 | * Change file ownership. Must be the owner or privileged. CAP_FSETID |
| 1375 | * overrides the following restrictions: |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1376 | * |
Dave Chinner | fd179b9 | 2015-02-02 10:16:25 +1100 | [diff] [blame] | 1377 | * The set-user-ID and set-group-ID bits of a file will be cleared upon |
| 1378 | * successful return from chown() |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1379 | */ |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1380 | |
Dave Chinner | c19b3b05 | 2016-02-09 16:54:58 +1100 | [diff] [blame] | 1381 | if ((VFS_I(ip)->i_mode & (S_ISUID|S_ISGID)) && |
Dave Chinner | fd179b9 | 2015-02-02 10:16:25 +1100 | [diff] [blame] | 1382 | !capable_wrt_inode_uidgid(VFS_I(ip), CAP_FSETID)) |
Dave Chinner | c19b3b05 | 2016-02-09 16:54:58 +1100 | [diff] [blame] | 1383 | VFS_I(ip)->i_mode &= ~(S_ISUID|S_ISGID); |
Dave Chinner | fd179b9 | 2015-02-02 10:16:25 +1100 | [diff] [blame] | 1384 | |
| 1385 | /* Change the ownerships and register project quota modifications */ |
| 1386 | if (xfs_get_projid(ip) != fa->fsx_projid) { |
| 1387 | if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp)) { |
| 1388 | olddquot = xfs_qm_vop_chown(tp, ip, |
| 1389 | &ip->i_pdquot, pdqp); |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1390 | } |
Dave Chinner | fd179b9 | 2015-02-02 10:16:25 +1100 | [diff] [blame] | 1391 | ASSERT(ip->i_d.di_version > 1); |
| 1392 | xfs_set_projid(ip, fa->fsx_projid); |
Christoph Hellwig | f13fae2 | 2008-07-21 16:16:15 +1000 | [diff] [blame] | 1393 | } |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1394 | |
Dave Chinner | a872703 | 2014-10-02 09:20:30 +1000 | [diff] [blame] | 1395 | /* |
| 1396 | * Only set the extent size hint if we've already determined that the |
| 1397 | * extent size hint should be set on the inode. If no extent size flags |
| 1398 | * are set on the inode then unconditionally clear the extent size hint. |
| 1399 | */ |
Dave Chinner | fd179b9 | 2015-02-02 10:16:25 +1100 | [diff] [blame] | 1400 | if (ip->i_d.di_flags & (XFS_DIFLAG_EXTSIZE | XFS_DIFLAG_EXTSZINHERIT)) |
| 1401 | ip->i_d.di_extsize = fa->fsx_extsize >> mp->m_sb.sb_blocklog; |
| 1402 | else |
| 1403 | ip->i_d.di_extsize = 0; |
Darrick J. Wong | f7ca352 | 2016-10-03 09:11:43 -0700 | [diff] [blame] | 1404 | if (ip->i_d.di_version == 3 && |
| 1405 | (ip->i_d.di_flags2 & XFS_DIFLAG2_COWEXTSIZE)) |
| 1406 | ip->i_d.di_cowextsize = fa->fsx_cowextsize >> |
| 1407 | mp->m_sb.sb_blocklog; |
| 1408 | else |
| 1409 | ip->i_d.di_cowextsize = 0; |
Dave Chinner | a872703 | 2014-10-02 09:20:30 +1000 | [diff] [blame] | 1410 | |
Christoph Hellwig | 7039331 | 2015-06-04 13:48:08 +1000 | [diff] [blame] | 1411 | code = xfs_trans_commit(tp); |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1412 | |
| 1413 | /* |
| 1414 | * Release any dquot(s) the inode had kept before chown. |
| 1415 | */ |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 1416 | xfs_qm_dqrele(olddquot); |
| 1417 | xfs_qm_dqrele(udqp); |
Chandra Seetharaman | 92f8ff7 | 2013-07-11 00:00:40 -0500 | [diff] [blame] | 1418 | xfs_qm_dqrele(pdqp); |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1419 | |
Christoph Hellwig | 288699f | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 1420 | return code; |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1421 | |
Dave Chinner | d4388d3c | 2015-02-02 10:22:20 +1100 | [diff] [blame] | 1422 | error_trans_cancel: |
Christoph Hellwig | 4906e21 | 2015-06-04 13:47:56 +1000 | [diff] [blame] | 1423 | xfs_trans_cancel(tp); |
Dave Chinner | 8f3d17a | 2015-02-02 10:15:35 +1100 | [diff] [blame] | 1424 | error_free_dquots: |
Christoph Hellwig | 7d09525 | 2009-06-08 15:33:32 +0200 | [diff] [blame] | 1425 | xfs_qm_dqrele(udqp); |
Chandra Seetharaman | 92f8ff7 | 2013-07-11 00:00:40 -0500 | [diff] [blame] | 1426 | xfs_qm_dqrele(pdqp); |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1427 | return code; |
| 1428 | } |
| 1429 | |
Christoph Hellwig | c83bfab | 2007-10-11 17:47:00 +1000 | [diff] [blame] | 1430 | STATIC int |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1431 | xfs_ioc_fssetxattr( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | xfs_inode_t *ip, |
| 1433 | struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | void __user *arg) |
| 1435 | { |
| 1436 | struct fsxattr fa; |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 1437 | int error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1438 | |
| 1439 | if (copy_from_user(&fa, arg, sizeof(fa))) |
| 1440 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 1442 | error = mnt_want_write_file(filp); |
| 1443 | if (error) |
| 1444 | return error; |
Dave Chinner | fd179b9 | 2015-02-02 10:16:25 +1100 | [diff] [blame] | 1445 | error = xfs_ioctl_setattr(ip, &fa); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 1446 | mnt_drop_write_file(filp); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1447 | return error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1450 | STATIC int |
| 1451 | xfs_ioc_getxflags( |
| 1452 | xfs_inode_t *ip, |
| 1453 | void __user *arg) |
| 1454 | { |
| 1455 | unsigned int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1457 | flags = xfs_di2lxflags(ip->i_d.di_flags); |
| 1458 | if (copy_to_user(arg, &flags, sizeof(flags))) |
| 1459 | return -EFAULT; |
| 1460 | return 0; |
| 1461 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1463 | STATIC int |
| 1464 | xfs_ioc_setxflags( |
Dave Chinner | f96291f | 2015-02-02 10:15:56 +1100 | [diff] [blame] | 1465 | struct xfs_inode *ip, |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1466 | struct file *filp, |
| 1467 | void __user *arg) |
| 1468 | { |
Dave Chinner | f96291f | 2015-02-02 10:15:56 +1100 | [diff] [blame] | 1469 | struct xfs_trans *tp; |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1470 | struct fsxattr fa; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1471 | unsigned int flags; |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1472 | int join_flags = 0; |
Dave Chinner | f96291f | 2015-02-02 10:15:56 +1100 | [diff] [blame] | 1473 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1475 | if (copy_from_user(&flags, arg, sizeof(flags))) |
| 1476 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1478 | if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \ |
| 1479 | FS_NOATIME_FL | FS_NODUMP_FL | \ |
| 1480 | FS_SYNC_FL)) |
| 1481 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1483 | fa.fsx_xflags = xfs_merge_ioc_xflags(flags, xfs_ip2xflags(ip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 1485 | error = mnt_want_write_file(filp); |
| 1486 | if (error) |
| 1487 | return error; |
Dave Chinner | f96291f | 2015-02-02 10:15:56 +1100 | [diff] [blame] | 1488 | |
Dave Chinner | 3a6a854 | 2016-03-01 09:41:33 +1100 | [diff] [blame] | 1489 | /* |
| 1490 | * Changing DAX config may require inode locking for mapping |
| 1491 | * invalidation. These need to be held all the way to transaction commit |
| 1492 | * or cancel time, so need to be passed through to |
| 1493 | * xfs_ioctl_setattr_get_trans() so it can apply them to the join call |
| 1494 | * appropriately. |
| 1495 | */ |
| 1496 | error = xfs_ioctl_setattr_dax_invalidate(ip, &fa, &join_flags); |
| 1497 | if (error) |
| 1498 | goto out_drop_write; |
| 1499 | |
| 1500 | tp = xfs_ioctl_setattr_get_trans(ip, join_flags); |
Dave Chinner | f96291f | 2015-02-02 10:15:56 +1100 | [diff] [blame] | 1501 | if (IS_ERR(tp)) { |
| 1502 | error = PTR_ERR(tp); |
| 1503 | goto out_drop_write; |
| 1504 | } |
| 1505 | |
| 1506 | error = xfs_ioctl_setattr_xflags(tp, ip, &fa); |
| 1507 | if (error) { |
Christoph Hellwig | 4906e21 | 2015-06-04 13:47:56 +1000 | [diff] [blame] | 1508 | xfs_trans_cancel(tp); |
Dave Chinner | f96291f | 2015-02-02 10:15:56 +1100 | [diff] [blame] | 1509 | goto out_drop_write; |
| 1510 | } |
| 1511 | |
Christoph Hellwig | 7039331 | 2015-06-04 13:48:08 +1000 | [diff] [blame] | 1512 | error = xfs_trans_commit(tp); |
Dave Chinner | f96291f | 2015-02-02 10:15:56 +1100 | [diff] [blame] | 1513 | out_drop_write: |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 1514 | mnt_drop_write_file(filp); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1515 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Christoph Hellwig | 232b5194 | 2017-10-17 14:16:19 -0700 | [diff] [blame] | 1518 | static bool |
| 1519 | xfs_getbmap_format( |
| 1520 | struct kgetbmap *p, |
| 1521 | struct getbmapx __user *u, |
| 1522 | size_t recsize) |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame] | 1523 | { |
Christoph Hellwig | 232b5194 | 2017-10-17 14:16:19 -0700 | [diff] [blame] | 1524 | if (put_user(p->bmv_offset, &u->bmv_offset) || |
| 1525 | put_user(p->bmv_block, &u->bmv_block) || |
| 1526 | put_user(p->bmv_length, &u->bmv_length) || |
| 1527 | put_user(0, &u->bmv_count) || |
| 1528 | put_user(0, &u->bmv_entries)) |
| 1529 | return false; |
| 1530 | if (recsize < sizeof(struct getbmapx)) |
| 1531 | return true; |
| 1532 | if (put_user(0, &u->bmv_iflags) || |
| 1533 | put_user(p->bmv_oflags, &u->bmv_oflags) || |
| 1534 | put_user(0, &u->bmv_unused1) || |
| 1535 | put_user(0, &u->bmv_unused2)) |
| 1536 | return false; |
| 1537 | return true; |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | STATIC int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | xfs_ioc_getbmap( |
Christoph Hellwig | 8f3e205 | 2016-07-20 11:29:35 +1000 | [diff] [blame] | 1542 | struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | unsigned int cmd, |
| 1544 | void __user *arg) |
| 1545 | { |
Darrick J. Wong | be6324c | 2017-04-03 15:17:57 -0700 | [diff] [blame] | 1546 | struct getbmapx bmx = { 0 }; |
Christoph Hellwig | 232b5194 | 2017-10-17 14:16:19 -0700 | [diff] [blame] | 1547 | struct kgetbmap *buf; |
| 1548 | size_t recsize; |
| 1549 | int error, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | |
Christoph Hellwig | 232b5194 | 2017-10-17 14:16:19 -0700 | [diff] [blame] | 1551 | switch (cmd) { |
| 1552 | case XFS_IOC_GETBMAPA: |
| 1553 | bmx.bmv_iflags = BMV_IF_ATTRFORK; |
| 1554 | /*FALLTHRU*/ |
| 1555 | case XFS_IOC_GETBMAP: |
| 1556 | if (file->f_mode & FMODE_NOCMTIME) |
| 1557 | bmx.bmv_iflags |= BMV_IF_NO_DMAPI_READ; |
| 1558 | /* struct getbmap is a strict subset of struct getbmapx. */ |
| 1559 | recsize = sizeof(struct getbmap); |
| 1560 | break; |
| 1561 | case XFS_IOC_GETBMAPX: |
| 1562 | recsize = sizeof(struct getbmapx); |
| 1563 | break; |
| 1564 | default: |
| 1565 | return -EINVAL; |
| 1566 | } |
| 1567 | |
| 1568 | if (copy_from_user(&bmx, arg, recsize)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 1569 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame] | 1571 | if (bmx.bmv_count < 2) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 1572 | return -EINVAL; |
Christoph Hellwig | 232b5194 | 2017-10-17 14:16:19 -0700 | [diff] [blame] | 1573 | if (bmx.bmv_count > ULONG_MAX / recsize) |
| 1574 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | |
Christoph Hellwig | 232b5194 | 2017-10-17 14:16:19 -0700 | [diff] [blame] | 1576 | buf = kmem_zalloc_large(bmx.bmv_count * sizeof(*buf), 0); |
| 1577 | if (!buf) |
| 1578 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | |
Christoph Hellwig | 232b5194 | 2017-10-17 14:16:19 -0700 | [diff] [blame] | 1580 | error = xfs_getbmap(XFS_I(file_inode(file)), &bmx, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | if (error) |
Christoph Hellwig | 232b5194 | 2017-10-17 14:16:19 -0700 | [diff] [blame] | 1582 | goto out_free_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | |
Christoph Hellwig | 232b5194 | 2017-10-17 14:16:19 -0700 | [diff] [blame] | 1584 | error = -EFAULT; |
| 1585 | if (copy_to_user(arg, &bmx, recsize)) |
| 1586 | goto out_free_buf; |
| 1587 | arg += recsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | |
Christoph Hellwig | 232b5194 | 2017-10-17 14:16:19 -0700 | [diff] [blame] | 1589 | for (i = 0; i < bmx.bmv_entries; i++) { |
| 1590 | if (!xfs_getbmap_format(buf + i, arg, recsize)) |
| 1591 | goto out_free_buf; |
| 1592 | arg += recsize; |
| 1593 | } |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame] | 1594 | |
Christoph Hellwig | 232b5194 | 2017-10-17 14:16:19 -0700 | [diff] [blame] | 1595 | error = 0; |
| 1596 | out_free_buf: |
| 1597 | kmem_free(buf); |
Christophe JAILLET | 132bf67 | 2018-11-06 07:50:50 -0800 | [diff] [blame] | 1598 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | } |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1600 | |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 1601 | struct getfsmap_info { |
| 1602 | struct xfs_mount *mp; |
Christoph Hellwig | 9d17e14 | 2017-04-21 11:24:41 -0700 | [diff] [blame] | 1603 | struct fsmap_head __user *data; |
| 1604 | unsigned int idx; |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 1605 | __u32 last_flags; |
| 1606 | }; |
| 1607 | |
| 1608 | STATIC int |
| 1609 | xfs_getfsmap_format(struct xfs_fsmap *xfm, void *priv) |
| 1610 | { |
| 1611 | struct getfsmap_info *info = priv; |
| 1612 | struct fsmap fm; |
| 1613 | |
| 1614 | trace_xfs_getfsmap_mapping(info->mp, xfm); |
| 1615 | |
| 1616 | info->last_flags = xfm->fmr_flags; |
| 1617 | xfs_fsmap_from_internal(&fm, xfm); |
Christoph Hellwig | 9d17e14 | 2017-04-21 11:24:41 -0700 | [diff] [blame] | 1618 | if (copy_to_user(&info->data->fmh_recs[info->idx++], &fm, |
| 1619 | sizeof(struct fsmap))) |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 1620 | return -EFAULT; |
| 1621 | |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 1622 | return 0; |
| 1623 | } |
| 1624 | |
| 1625 | STATIC int |
| 1626 | xfs_ioc_getfsmap( |
| 1627 | struct xfs_inode *ip, |
Christoph Hellwig | 9d17e14 | 2017-04-21 11:24:41 -0700 | [diff] [blame] | 1628 | struct fsmap_head __user *arg) |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 1629 | { |
Christoph Hellwig | ef2b67e | 2017-04-21 11:24:40 -0700 | [diff] [blame] | 1630 | struct getfsmap_info info = { NULL }; |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 1631 | struct xfs_fsmap_head xhead = {0}; |
| 1632 | struct fsmap_head head; |
| 1633 | bool aborted = false; |
| 1634 | int error; |
| 1635 | |
| 1636 | if (copy_from_user(&head, arg, sizeof(struct fsmap_head))) |
| 1637 | return -EFAULT; |
| 1638 | if (memchr_inv(head.fmh_reserved, 0, sizeof(head.fmh_reserved)) || |
| 1639 | memchr_inv(head.fmh_keys[0].fmr_reserved, 0, |
| 1640 | sizeof(head.fmh_keys[0].fmr_reserved)) || |
| 1641 | memchr_inv(head.fmh_keys[1].fmr_reserved, 0, |
| 1642 | sizeof(head.fmh_keys[1].fmr_reserved))) |
| 1643 | return -EINVAL; |
| 1644 | |
| 1645 | xhead.fmh_iflags = head.fmh_iflags; |
| 1646 | xhead.fmh_count = head.fmh_count; |
| 1647 | xfs_fsmap_to_internal(&xhead.fmh_keys[0], &head.fmh_keys[0]); |
| 1648 | xfs_fsmap_to_internal(&xhead.fmh_keys[1], &head.fmh_keys[1]); |
| 1649 | |
| 1650 | trace_xfs_getfsmap_low_key(ip->i_mount, &xhead.fmh_keys[0]); |
| 1651 | trace_xfs_getfsmap_high_key(ip->i_mount, &xhead.fmh_keys[1]); |
| 1652 | |
| 1653 | info.mp = ip->i_mount; |
Christoph Hellwig | 9d17e14 | 2017-04-21 11:24:41 -0700 | [diff] [blame] | 1654 | info.data = arg; |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 1655 | error = xfs_getfsmap(ip->i_mount, &xhead, xfs_getfsmap_format, &info); |
| 1656 | if (error == XFS_BTREE_QUERY_RANGE_ABORT) { |
| 1657 | error = 0; |
| 1658 | aborted = true; |
| 1659 | } else if (error) |
| 1660 | return error; |
| 1661 | |
| 1662 | /* If we didn't abort, set the "last" flag in the last fmx */ |
Darrick J. Wong | 12e4a38 | 2017-04-23 10:45:21 -0700 | [diff] [blame] | 1663 | if (!aborted && info.idx) { |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 1664 | info.last_flags |= FMR_OF_LAST; |
Christoph Hellwig | 9d17e14 | 2017-04-21 11:24:41 -0700 | [diff] [blame] | 1665 | if (copy_to_user(&info.data->fmh_recs[info.idx - 1].fmr_flags, |
| 1666 | &info.last_flags, sizeof(info.last_flags))) |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 1667 | return -EFAULT; |
| 1668 | } |
| 1669 | |
| 1670 | /* copy back header */ |
| 1671 | head.fmh_entries = xhead.fmh_entries; |
| 1672 | head.fmh_oflags = xhead.fmh_oflags; |
| 1673 | if (copy_to_user(arg, &head, sizeof(struct fsmap_head))) |
| 1674 | return -EFAULT; |
| 1675 | |
| 1676 | return 0; |
| 1677 | } |
| 1678 | |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 1679 | STATIC int |
| 1680 | xfs_ioc_scrub_metadata( |
| 1681 | struct xfs_inode *ip, |
| 1682 | void __user *arg) |
| 1683 | { |
| 1684 | struct xfs_scrub_metadata scrub; |
| 1685 | int error; |
| 1686 | |
| 1687 | if (!capable(CAP_SYS_ADMIN)) |
| 1688 | return -EPERM; |
| 1689 | |
| 1690 | if (copy_from_user(&scrub, arg, sizeof(scrub))) |
| 1691 | return -EFAULT; |
| 1692 | |
| 1693 | error = xfs_scrub_metadata(ip, &scrub); |
| 1694 | if (error) |
| 1695 | return error; |
| 1696 | |
| 1697 | if (copy_to_user(arg, &scrub, sizeof(scrub))) |
| 1698 | return -EFAULT; |
| 1699 | |
| 1700 | return 0; |
| 1701 | } |
| 1702 | |
Dave Chinner | a133d95 | 2013-08-12 20:49:48 +1000 | [diff] [blame] | 1703 | int |
| 1704 | xfs_ioc_swapext( |
| 1705 | xfs_swapext_t *sxp) |
| 1706 | { |
| 1707 | xfs_inode_t *ip, *tip; |
| 1708 | struct fd f, tmp; |
| 1709 | int error = 0; |
| 1710 | |
| 1711 | /* Pull information for the target fd */ |
| 1712 | f = fdget((int)sxp->sx_fdtarget); |
| 1713 | if (!f.file) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1714 | error = -EINVAL; |
Dave Chinner | a133d95 | 2013-08-12 20:49:48 +1000 | [diff] [blame] | 1715 | goto out; |
| 1716 | } |
| 1717 | |
| 1718 | if (!(f.file->f_mode & FMODE_WRITE) || |
| 1719 | !(f.file->f_mode & FMODE_READ) || |
| 1720 | (f.file->f_flags & O_APPEND)) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1721 | error = -EBADF; |
Dave Chinner | a133d95 | 2013-08-12 20:49:48 +1000 | [diff] [blame] | 1722 | goto out_put_file; |
| 1723 | } |
| 1724 | |
| 1725 | tmp = fdget((int)sxp->sx_fdtmp); |
| 1726 | if (!tmp.file) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1727 | error = -EINVAL; |
Dave Chinner | a133d95 | 2013-08-12 20:49:48 +1000 | [diff] [blame] | 1728 | goto out_put_file; |
| 1729 | } |
| 1730 | |
| 1731 | if (!(tmp.file->f_mode & FMODE_WRITE) || |
| 1732 | !(tmp.file->f_mode & FMODE_READ) || |
| 1733 | (tmp.file->f_flags & O_APPEND)) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1734 | error = -EBADF; |
Dave Chinner | a133d95 | 2013-08-12 20:49:48 +1000 | [diff] [blame] | 1735 | goto out_put_tmp_file; |
| 1736 | } |
| 1737 | |
| 1738 | if (IS_SWAPFILE(file_inode(f.file)) || |
| 1739 | IS_SWAPFILE(file_inode(tmp.file))) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1740 | error = -EINVAL; |
Dave Chinner | a133d95 | 2013-08-12 20:49:48 +1000 | [diff] [blame] | 1741 | goto out_put_tmp_file; |
| 1742 | } |
| 1743 | |
Jann Horn | 7f1b624 | 2016-07-20 10:30:30 +1000 | [diff] [blame] | 1744 | /* |
| 1745 | * We need to ensure that the fds passed in point to XFS inodes |
| 1746 | * before we cast and access them as XFS structures as we have no |
| 1747 | * control over what the user passes us here. |
| 1748 | */ |
| 1749 | if (f.file->f_op != &xfs_file_operations || |
| 1750 | tmp.file->f_op != &xfs_file_operations) { |
| 1751 | error = -EINVAL; |
| 1752 | goto out_put_tmp_file; |
| 1753 | } |
| 1754 | |
Dave Chinner | a133d95 | 2013-08-12 20:49:48 +1000 | [diff] [blame] | 1755 | ip = XFS_I(file_inode(f.file)); |
| 1756 | tip = XFS_I(file_inode(tmp.file)); |
| 1757 | |
| 1758 | if (ip->i_mount != tip->i_mount) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1759 | error = -EINVAL; |
Dave Chinner | a133d95 | 2013-08-12 20:49:48 +1000 | [diff] [blame] | 1760 | goto out_put_tmp_file; |
| 1761 | } |
| 1762 | |
| 1763 | if (ip->i_ino == tip->i_ino) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1764 | error = -EINVAL; |
Dave Chinner | a133d95 | 2013-08-12 20:49:48 +1000 | [diff] [blame] | 1765 | goto out_put_tmp_file; |
| 1766 | } |
| 1767 | |
| 1768 | if (XFS_FORCED_SHUTDOWN(ip->i_mount)) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1769 | error = -EIO; |
Dave Chinner | a133d95 | 2013-08-12 20:49:48 +1000 | [diff] [blame] | 1770 | goto out_put_tmp_file; |
| 1771 | } |
| 1772 | |
| 1773 | error = xfs_swap_extents(ip, tip, sxp); |
| 1774 | |
| 1775 | out_put_tmp_file: |
| 1776 | fdput(tmp); |
| 1777 | out_put_file: |
| 1778 | fdput(f); |
| 1779 | out: |
| 1780 | return error; |
| 1781 | } |
| 1782 | |
Eric Sandeen | f7664b3 | 2018-05-15 13:21:48 -0700 | [diff] [blame] | 1783 | static int |
| 1784 | xfs_ioc_getlabel( |
| 1785 | struct xfs_mount *mp, |
| 1786 | char __user *user_label) |
| 1787 | { |
| 1788 | struct xfs_sb *sbp = &mp->m_sb; |
| 1789 | char label[XFSLABEL_MAX + 1]; |
| 1790 | |
| 1791 | /* Paranoia */ |
| 1792 | BUILD_BUG_ON(sizeof(sbp->sb_fname) > FSLABEL_MAX); |
| 1793 | |
Arnd Bergmann | 4bb8b65 | 2018-06-05 19:42:45 -0700 | [diff] [blame] | 1794 | /* 1 larger than sb_fname, so this ensures a trailing NUL char */ |
| 1795 | memset(label, 0, sizeof(label)); |
Eric Sandeen | f7664b3 | 2018-05-15 13:21:48 -0700 | [diff] [blame] | 1796 | spin_lock(&mp->m_sb_lock); |
Arnd Bergmann | 4bb8b65 | 2018-06-05 19:42:45 -0700 | [diff] [blame] | 1797 | strncpy(label, sbp->sb_fname, XFSLABEL_MAX); |
Eric Sandeen | f7664b3 | 2018-05-15 13:21:48 -0700 | [diff] [blame] | 1798 | spin_unlock(&mp->m_sb_lock); |
| 1799 | |
Arnd Bergmann | 4bb8b65 | 2018-06-05 19:42:45 -0700 | [diff] [blame] | 1800 | if (copy_to_user(user_label, label, sizeof(label))) |
Eric Sandeen | f7664b3 | 2018-05-15 13:21:48 -0700 | [diff] [blame] | 1801 | return -EFAULT; |
| 1802 | return 0; |
| 1803 | } |
| 1804 | |
| 1805 | static int |
| 1806 | xfs_ioc_setlabel( |
| 1807 | struct file *filp, |
| 1808 | struct xfs_mount *mp, |
| 1809 | char __user *newlabel) |
| 1810 | { |
| 1811 | struct xfs_sb *sbp = &mp->m_sb; |
| 1812 | char label[XFSLABEL_MAX + 1]; |
| 1813 | size_t len; |
| 1814 | int error; |
| 1815 | |
| 1816 | if (!capable(CAP_SYS_ADMIN)) |
| 1817 | return -EPERM; |
| 1818 | /* |
| 1819 | * The generic ioctl allows up to FSLABEL_MAX chars, but XFS is much |
| 1820 | * smaller, at 12 bytes. We copy one more to be sure we find the |
| 1821 | * (required) NULL character to test the incoming label length. |
| 1822 | * NB: The on disk label doesn't need to be null terminated. |
| 1823 | */ |
| 1824 | if (copy_from_user(label, newlabel, XFSLABEL_MAX + 1)) |
| 1825 | return -EFAULT; |
| 1826 | len = strnlen(label, XFSLABEL_MAX + 1); |
| 1827 | if (len > sizeof(sbp->sb_fname)) |
| 1828 | return -EINVAL; |
| 1829 | |
| 1830 | error = mnt_want_write_file(filp); |
| 1831 | if (error) |
| 1832 | return error; |
| 1833 | |
| 1834 | spin_lock(&mp->m_sb_lock); |
| 1835 | memset(sbp->sb_fname, 0, sizeof(sbp->sb_fname)); |
Arnd Bergmann | 4bb8b65 | 2018-06-05 19:42:45 -0700 | [diff] [blame] | 1836 | memcpy(sbp->sb_fname, label, len); |
Eric Sandeen | f7664b3 | 2018-05-15 13:21:48 -0700 | [diff] [blame] | 1837 | spin_unlock(&mp->m_sb_lock); |
| 1838 | |
| 1839 | /* |
| 1840 | * Now we do several things to satisfy userspace. |
| 1841 | * In addition to normal logging of the primary superblock, we also |
| 1842 | * immediately write these changes to sector zero for the primary, then |
| 1843 | * update all backup supers (as xfs_db does for a label change), then |
| 1844 | * invalidate the block device page cache. This is so that any prior |
| 1845 | * buffered reads from userspace (i.e. from blkid) are invalidated, |
| 1846 | * and userspace will see the newly-written label. |
| 1847 | */ |
| 1848 | error = xfs_sync_sb_buf(mp); |
| 1849 | if (error) |
| 1850 | goto out; |
| 1851 | /* |
| 1852 | * growfs also updates backup supers so lock against that. |
| 1853 | */ |
| 1854 | mutex_lock(&mp->m_growlock); |
| 1855 | error = xfs_update_secondary_sbs(mp); |
| 1856 | mutex_unlock(&mp->m_growlock); |
| 1857 | |
| 1858 | invalidate_bdev(mp->m_ddev_targp->bt_bdev); |
| 1859 | |
| 1860 | out: |
| 1861 | mnt_drop_write_file(filp); |
| 1862 | return error; |
| 1863 | } |
| 1864 | |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 1865 | /* |
| 1866 | * Note: some of the ioctl's return positive numbers as a |
| 1867 | * byte count indicating success, such as readlink_by_handle. |
| 1868 | * So we don't "sign flip" like most other routines. This means |
| 1869 | * true errors need to be returned as a negative value. |
| 1870 | */ |
| 1871 | long |
| 1872 | xfs_file_ioctl( |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1873 | struct file *filp, |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1874 | unsigned int cmd, |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 1875 | unsigned long p) |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1876 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 1877 | struct inode *inode = file_inode(filp); |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 1878 | struct xfs_inode *ip = XFS_I(inode); |
| 1879 | struct xfs_mount *mp = ip->i_mount; |
| 1880 | void __user *arg = (void __user *)p; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1881 | int error; |
| 1882 | |
Christoph Hellwig | cca28fb | 2010-06-24 11:57:09 +1000 | [diff] [blame] | 1883 | trace_xfs_file_ioctl(ip); |
Christoph Hellwig | 4d4be48 | 2008-12-09 04:47:33 -0500 | [diff] [blame] | 1884 | |
| 1885 | switch (cmd) { |
Christoph Hellwig | a46db60 | 2011-01-07 13:02:04 +0000 | [diff] [blame] | 1886 | case FITRIM: |
| 1887 | return xfs_ioc_trim(mp, arg); |
Eric Sandeen | f7664b3 | 2018-05-15 13:21:48 -0700 | [diff] [blame] | 1888 | case FS_IOC_GETFSLABEL: |
| 1889 | return xfs_ioc_getlabel(mp, arg); |
| 1890 | case FS_IOC_SETFSLABEL: |
| 1891 | return xfs_ioc_setlabel(filp, mp, arg); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1892 | case XFS_IOC_ALLOCSP: |
| 1893 | case XFS_IOC_FREESP: |
| 1894 | case XFS_IOC_RESVSP: |
| 1895 | case XFS_IOC_UNRESVSP: |
| 1896 | case XFS_IOC_ALLOCSP64: |
| 1897 | case XFS_IOC_FREESP64: |
| 1898 | case XFS_IOC_RESVSP64: |
Dave Chinner | 4472235 | 2010-08-24 12:02:11 +1000 | [diff] [blame] | 1899 | case XFS_IOC_UNRESVSP64: |
| 1900 | case XFS_IOC_ZERO_RANGE: { |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 1901 | xfs_flock64_t bf; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1902 | |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 1903 | if (copy_from_user(&bf, arg, sizeof(bf))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 1904 | return -EFAULT; |
Christoph Hellwig | 8f3e205 | 2016-07-20 11:29:35 +1000 | [diff] [blame] | 1905 | return xfs_ioc_space(filp, cmd, &bf); |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 1906 | } |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1907 | case XFS_IOC_DIOINFO: { |
| 1908 | struct dioattr da; |
| 1909 | xfs_buftarg_t *target = |
| 1910 | XFS_IS_REALTIME_INODE(ip) ? |
| 1911 | mp->m_rtdev_targp : mp->m_ddev_targp; |
| 1912 | |
Eric Sandeen | 7c71ee7 | 2014-01-21 16:46:23 -0600 | [diff] [blame] | 1913 | da.d_mem = da.d_miniosz = target->bt_logical_sectorsize; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1914 | da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1); |
| 1915 | |
| 1916 | if (copy_to_user(arg, &da, sizeof(da))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 1917 | return -EFAULT; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1918 | return 0; |
| 1919 | } |
| 1920 | |
| 1921 | case XFS_IOC_FSBULKSTAT_SINGLE: |
| 1922 | case XFS_IOC_FSBULKSTAT: |
| 1923 | case XFS_IOC_FSINUMBERS: |
| 1924 | return xfs_ioc_bulkstat(mp, cmd, arg); |
| 1925 | |
| 1926 | case XFS_IOC_FSGEOMETRY_V1: |
Dave Chinner | 1b6d968 | 2019-04-12 07:41:16 -0700 | [diff] [blame^] | 1927 | return xfs_ioc_fsgeometry(mp, arg, 3); |
| 1928 | case XFS_IOC_FSGEOMETRY_V4: |
| 1929 | return xfs_ioc_fsgeometry(mp, arg, 4); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1930 | case XFS_IOC_FSGEOMETRY: |
Dave Chinner | 1b6d968 | 2019-04-12 07:41:16 -0700 | [diff] [blame^] | 1931 | return xfs_ioc_fsgeometry(mp, arg, 5); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1932 | |
| 1933 | case XFS_IOC_GETVERSION: |
| 1934 | return put_user(inode->i_generation, (int __user *)arg); |
| 1935 | |
| 1936 | case XFS_IOC_FSGETXATTR: |
| 1937 | return xfs_ioc_fsgetxattr(ip, 0, arg); |
| 1938 | case XFS_IOC_FSGETXATTRA: |
| 1939 | return xfs_ioc_fsgetxattr(ip, 1, arg); |
Lachlan McIlroy | 3b2816b | 2008-04-18 12:43:35 +1000 | [diff] [blame] | 1940 | case XFS_IOC_FSSETXATTR: |
Lachlan McIlroy | 65e67f5 | 2008-04-18 12:59:45 +1000 | [diff] [blame] | 1941 | return xfs_ioc_fssetxattr(ip, filp, arg); |
| 1942 | case XFS_IOC_GETXFLAGS: |
| 1943 | return xfs_ioc_getxflags(ip, arg); |
| 1944 | case XFS_IOC_SETXFLAGS: |
| 1945 | return xfs_ioc_setxflags(ip, filp, arg); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1946 | |
| 1947 | case XFS_IOC_FSSETDM: { |
| 1948 | struct fsdmidata dmi; |
| 1949 | |
| 1950 | if (copy_from_user(&dmi, arg, sizeof(dmi))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 1951 | return -EFAULT; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1952 | |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 1953 | error = mnt_want_write_file(filp); |
| 1954 | if (error) |
| 1955 | return error; |
| 1956 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1957 | error = xfs_set_dmattrs(ip, dmi.fsd_dmevmask, |
| 1958 | dmi.fsd_dmstate); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 1959 | mnt_drop_write_file(filp); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 1960 | return error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | case XFS_IOC_GETBMAP: |
| 1964 | case XFS_IOC_GETBMAPA: |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1965 | case XFS_IOC_GETBMAPX: |
Christoph Hellwig | 232b5194 | 2017-10-17 14:16:19 -0700 | [diff] [blame] | 1966 | return xfs_ioc_getbmap(filp, cmd, arg); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1967 | |
Darrick J. Wong | e89c041 | 2017-03-28 14:56:37 -0700 | [diff] [blame] | 1968 | case FS_IOC_GETFSMAP: |
| 1969 | return xfs_ioc_getfsmap(ip, arg); |
| 1970 | |
Darrick J. Wong | 36fd6e8 | 2017-10-17 21:37:34 -0700 | [diff] [blame] | 1971 | case XFS_IOC_SCRUB_METADATA: |
| 1972 | return xfs_ioc_scrub_metadata(ip, arg); |
| 1973 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1974 | case XFS_IOC_FD_TO_HANDLE: |
| 1975 | case XFS_IOC_PATH_TO_HANDLE: |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 1976 | case XFS_IOC_PATH_TO_FSHANDLE: { |
| 1977 | xfs_fsop_handlereq_t hreq; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1978 | |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 1979 | if (copy_from_user(&hreq, arg, sizeof(hreq))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 1980 | return -EFAULT; |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 1981 | return xfs_find_handle(cmd, &hreq); |
| 1982 | } |
| 1983 | case XFS_IOC_OPEN_BY_HANDLE: { |
| 1984 | xfs_fsop_handlereq_t hreq; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1985 | |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 1986 | if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 1987 | return -EFAULT; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 1988 | return xfs_open_by_handle(filp, &hreq); |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 1989 | } |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1990 | case XFS_IOC_FSSETDM_BY_HANDLE: |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 1991 | return xfs_fssetdm_by_handle(filp, arg); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1992 | |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 1993 | case XFS_IOC_READLINK_BY_HANDLE: { |
| 1994 | xfs_fsop_handlereq_t hreq; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1995 | |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 1996 | if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 1997 | return -EFAULT; |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 1998 | return xfs_readlink_by_handle(filp, &hreq); |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 1999 | } |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2000 | case XFS_IOC_ATTRLIST_BY_HANDLE: |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 2001 | return xfs_attrlist_by_handle(filp, arg); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2002 | |
| 2003 | case XFS_IOC_ATTRMULTI_BY_HANDLE: |
Christoph Hellwig | d296d30 | 2009-01-19 02:02:57 +0100 | [diff] [blame] | 2004 | return xfs_attrmulti_by_handle(filp, arg); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2005 | |
| 2006 | case XFS_IOC_SWAPEXT: { |
sandeen@sandeen.net | 743bb465 | 2008-11-25 21:20:06 -0600 | [diff] [blame] | 2007 | struct xfs_swapext sxp; |
| 2008 | |
| 2009 | if (copy_from_user(&sxp, arg, sizeof(xfs_swapext_t))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2010 | return -EFAULT; |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 2011 | error = mnt_want_write_file(filp); |
| 2012 | if (error) |
| 2013 | return error; |
Dave Chinner | a133d95 | 2013-08-12 20:49:48 +1000 | [diff] [blame] | 2014 | error = xfs_ioc_swapext(&sxp); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 2015 | mnt_drop_write_file(filp); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 2016 | return error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | case XFS_IOC_FSCOUNTS: { |
| 2020 | xfs_fsop_counts_t out; |
| 2021 | |
| 2022 | error = xfs_fs_counts(mp, &out); |
| 2023 | if (error) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 2024 | return error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2025 | |
| 2026 | if (copy_to_user(arg, &out, sizeof(out))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2027 | return -EFAULT; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2028 | return 0; |
| 2029 | } |
| 2030 | |
| 2031 | case XFS_IOC_SET_RESBLKS: { |
| 2032 | xfs_fsop_resblks_t inout; |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 2033 | uint64_t in; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2034 | |
| 2035 | if (!capable(CAP_SYS_ADMIN)) |
| 2036 | return -EPERM; |
| 2037 | |
Eric Sandeen | d5db0f9 | 2010-02-05 22:59:53 +0000 | [diff] [blame] | 2038 | if (mp->m_flags & XFS_MOUNT_RDONLY) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2039 | return -EROFS; |
Eric Sandeen | d5db0f9 | 2010-02-05 22:59:53 +0000 | [diff] [blame] | 2040 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2041 | if (copy_from_user(&inout, arg, sizeof(inout))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2042 | return -EFAULT; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2043 | |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 2044 | error = mnt_want_write_file(filp); |
| 2045 | if (error) |
| 2046 | return error; |
| 2047 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2048 | /* input parameter is passed in resblks field of structure */ |
| 2049 | in = inout.resblks; |
| 2050 | error = xfs_reserve_blocks(mp, &in, &inout); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 2051 | mnt_drop_write_file(filp); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2052 | if (error) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 2053 | return error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2054 | |
| 2055 | if (copy_to_user(arg, &inout, sizeof(inout))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2056 | return -EFAULT; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2057 | return 0; |
| 2058 | } |
| 2059 | |
| 2060 | case XFS_IOC_GET_RESBLKS: { |
| 2061 | xfs_fsop_resblks_t out; |
| 2062 | |
| 2063 | if (!capable(CAP_SYS_ADMIN)) |
| 2064 | return -EPERM; |
| 2065 | |
| 2066 | error = xfs_reserve_blocks(mp, NULL, &out); |
| 2067 | if (error) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 2068 | return error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2069 | |
| 2070 | if (copy_to_user(arg, &out, sizeof(out))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2071 | return -EFAULT; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2072 | |
| 2073 | return 0; |
| 2074 | } |
| 2075 | |
| 2076 | case XFS_IOC_FSGROWFSDATA: { |
| 2077 | xfs_growfs_data_t in; |
| 2078 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2079 | if (copy_from_user(&in, arg, sizeof(in))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2080 | return -EFAULT; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2081 | |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 2082 | error = mnt_want_write_file(filp); |
| 2083 | if (error) |
| 2084 | return error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2085 | error = xfs_growfs_data(mp, &in); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 2086 | mnt_drop_write_file(filp); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 2087 | return error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | case XFS_IOC_FSGROWFSLOG: { |
| 2091 | xfs_growfs_log_t in; |
| 2092 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2093 | if (copy_from_user(&in, arg, sizeof(in))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2094 | return -EFAULT; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2095 | |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 2096 | error = mnt_want_write_file(filp); |
| 2097 | if (error) |
| 2098 | return error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2099 | error = xfs_growfs_log(mp, &in); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 2100 | mnt_drop_write_file(filp); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 2101 | return error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | case XFS_IOC_FSGROWFSRT: { |
| 2105 | xfs_growfs_rt_t in; |
| 2106 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2107 | if (copy_from_user(&in, arg, sizeof(in))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2108 | return -EFAULT; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2109 | |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 2110 | error = mnt_want_write_file(filp); |
| 2111 | if (error) |
| 2112 | return error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2113 | error = xfs_growfs_rt(mp, &in); |
Jan Kara | d9457dc | 2012-06-12 16:20:39 +0200 | [diff] [blame] | 2114 | mnt_drop_write_file(filp); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 2115 | return error; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2116 | } |
| 2117 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2118 | case XFS_IOC_GOINGDOWN: { |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 2119 | uint32_t in; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2120 | |
| 2121 | if (!capable(CAP_SYS_ADMIN)) |
| 2122 | return -EPERM; |
| 2123 | |
Darrick J. Wong | c8ce540 | 2017-06-16 11:00:05 -0700 | [diff] [blame] | 2124 | if (get_user(in, (uint32_t __user *)arg)) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2125 | return -EFAULT; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2126 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 2127 | return xfs_fs_goingdown(mp, in); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | case XFS_IOC_ERROR_INJECTION: { |
| 2131 | xfs_error_injection_t in; |
| 2132 | |
| 2133 | if (!capable(CAP_SYS_ADMIN)) |
| 2134 | return -EPERM; |
| 2135 | |
| 2136 | if (copy_from_user(&in, arg, sizeof(in))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2137 | return -EFAULT; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2138 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 2139 | return xfs_errortag_add(mp, in.errtag); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | case XFS_IOC_ERROR_CLEARALL: |
| 2143 | if (!capable(CAP_SYS_ADMIN)) |
| 2144 | return -EPERM; |
| 2145 | |
Darrick J. Wong | 31965ef | 2017-06-20 17:54:46 -0700 | [diff] [blame] | 2146 | return xfs_errortag_clearall(mp); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2147 | |
Brian Foster | 8ca149d | 2012-11-07 12:21:12 -0500 | [diff] [blame] | 2148 | case XFS_IOC_FREE_EOFBLOCKS: { |
Dwight Engen | b9fe505 | 2013-08-15 14:08:02 -0400 | [diff] [blame] | 2149 | struct xfs_fs_eofblocks eofb; |
| 2150 | struct xfs_eofblocks keofb; |
Brian Foster | 8ca149d | 2012-11-07 12:21:12 -0500 | [diff] [blame] | 2151 | |
Dwight Engen | 8c567a7 | 2013-08-15 14:08:03 -0400 | [diff] [blame] | 2152 | if (!capable(CAP_SYS_ADMIN)) |
| 2153 | return -EPERM; |
| 2154 | |
| 2155 | if (mp->m_flags & XFS_MOUNT_RDONLY) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2156 | return -EROFS; |
Dwight Engen | 8c567a7 | 2013-08-15 14:08:03 -0400 | [diff] [blame] | 2157 | |
Brian Foster | 8ca149d | 2012-11-07 12:21:12 -0500 | [diff] [blame] | 2158 | if (copy_from_user(&eofb, arg, sizeof(eofb))) |
Eric Sandeen | b474c7a | 2014-06-22 15:04:54 +1000 | [diff] [blame] | 2159 | return -EFAULT; |
Brian Foster | 8ca149d | 2012-11-07 12:21:12 -0500 | [diff] [blame] | 2160 | |
Dwight Engen | b9fe505 | 2013-08-15 14:08:02 -0400 | [diff] [blame] | 2161 | error = xfs_fs_eofblocks_from_user(&eofb, &keofb); |
| 2162 | if (error) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 2163 | return error; |
Brian Foster | 8ca149d | 2012-11-07 12:21:12 -0500 | [diff] [blame] | 2164 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 2165 | return xfs_icache_free_eofblocks(mp, &keofb); |
Brian Foster | 8ca149d | 2012-11-07 12:21:12 -0500 | [diff] [blame] | 2166 | } |
| 2167 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 2168 | default: |
| 2169 | return -ENOTTY; |
| 2170 | } |
| 2171 | } |