Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 9 | * This program is distributed in the hope that it would be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "xfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include "xfs_fs.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 20 | #include "xfs_bit.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include "xfs_log.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 22 | #include "xfs_inum.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "xfs_trans.h" |
| 24 | #include "xfs_sb.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 25 | #include "xfs_ag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "xfs_dir2.h" |
| 27 | #include "xfs_alloc.h" |
| 28 | #include "xfs_dmapi.h" |
| 29 | #include "xfs_mount.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "xfs_bmap_btree.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 31 | #include "xfs_alloc_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "xfs_ialloc_btree.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 33 | #include "xfs_attr_sf.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include "xfs_dir2_sf.h" |
| 35 | #include "xfs_dinode.h" |
| 36 | #include "xfs_inode.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 37 | #include "xfs_btree.h" |
| 38 | #include "xfs_ialloc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "xfs_rtalloc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include "xfs_itable.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 41 | #include "xfs_error.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include "xfs_rw.h" |
| 43 | #include "xfs_acl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include "xfs_attr.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 45 | #include "xfs_bmap.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include "xfs_buf_item.h" |
| 47 | #include "xfs_utils.h" |
| 48 | #include "xfs_dfrag.h" |
| 49 | #include "xfs_fsops.h" |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 50 | #include "xfs_vnodeops.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 52 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <linux/dcache.h> |
| 54 | #include <linux/mount.h> |
| 55 | #include <linux/namei.h> |
| 56 | #include <linux/pagemap.h> |
| 57 | |
| 58 | /* |
| 59 | * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to |
| 60 | * a file or fs handle. |
| 61 | * |
| 62 | * XFS_IOC_PATH_TO_FSHANDLE |
| 63 | * returns fs handle for a mount point or path within that mount point |
| 64 | * XFS_IOC_FD_TO_HANDLE |
| 65 | * returns full handle for a FD opened in user space |
| 66 | * XFS_IOC_PATH_TO_HANDLE |
| 67 | * returns full handle for a path |
| 68 | */ |
| 69 | STATIC int |
| 70 | xfs_find_handle( |
| 71 | unsigned int cmd, |
| 72 | void __user *arg) |
| 73 | { |
| 74 | int hsize; |
| 75 | xfs_handle_t handle; |
| 76 | xfs_fsop_handlereq_t hreq; |
| 77 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | if (copy_from_user(&hreq, arg, sizeof(hreq))) |
| 80 | return -XFS_ERROR(EFAULT); |
| 81 | |
| 82 | memset((char *)&handle, 0, sizeof(handle)); |
| 83 | |
| 84 | switch (cmd) { |
| 85 | case XFS_IOC_PATH_TO_FSHANDLE: |
| 86 | case XFS_IOC_PATH_TO_HANDLE: { |
| 87 | struct nameidata nd; |
| 88 | int error; |
| 89 | |
| 90 | error = user_path_walk_link((const char __user *)hreq.path, &nd); |
| 91 | if (error) |
| 92 | return error; |
| 93 | |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 94 | ASSERT(nd.path.dentry); |
| 95 | ASSERT(nd.path.dentry->d_inode); |
| 96 | inode = igrab(nd.path.dentry->d_inode); |
Jan Blunck | 1d957f9 | 2008-02-14 19:34:35 -0800 | [diff] [blame] | 97 | path_put(&nd.path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | break; |
| 99 | } |
| 100 | |
| 101 | case XFS_IOC_FD_TO_HANDLE: { |
| 102 | struct file *file; |
| 103 | |
| 104 | file = fget(hreq.fd); |
| 105 | if (!file) |
| 106 | return -EBADF; |
| 107 | |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 108 | ASSERT(file->f_path.dentry); |
| 109 | ASSERT(file->f_path.dentry->d_inode); |
| 110 | inode = igrab(file->f_path.dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | fput(file); |
| 112 | break; |
| 113 | } |
| 114 | |
| 115 | default: |
| 116 | ASSERT(0); |
| 117 | return -XFS_ERROR(EINVAL); |
| 118 | } |
| 119 | |
| 120 | if (inode->i_sb->s_magic != XFS_SB_MAGIC) { |
| 121 | /* we're not in XFS anymore, Toto */ |
| 122 | iput(inode); |
| 123 | return -XFS_ERROR(EINVAL); |
| 124 | } |
| 125 | |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 126 | switch (inode->i_mode & S_IFMT) { |
| 127 | case S_IFREG: |
| 128 | case S_IFDIR: |
| 129 | case S_IFLNK: |
| 130 | break; |
| 131 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | iput(inode); |
| 133 | return -XFS_ERROR(EBADF); |
| 134 | } |
| 135 | |
| 136 | /* now we can grab the fsid */ |
Christoph Hellwig | 0ce4cfd | 2007-08-30 17:20:53 +1000 | [diff] [blame] | 137 | memcpy(&handle.ha_fsid, XFS_I(inode)->i_mount->m_fixedfsid, |
Christoph Hellwig | 2f6f7b3 | 2007-08-29 11:44:18 +1000 | [diff] [blame] | 138 | sizeof(xfs_fsid_t)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | hsize = sizeof(xfs_fsid_t); |
| 140 | |
| 141 | if (cmd != XFS_IOC_PATH_TO_FSHANDLE) { |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 142 | xfs_inode_t *ip = XFS_I(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | int lock_mode; |
| 144 | |
| 145 | /* need to get access to the xfs_inode to read the generation */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | lock_mode = xfs_ilock_map_shared(ip); |
| 147 | |
| 148 | /* fill in fid section of handle from inode */ |
Christoph Hellwig | c614391 | 2007-09-14 15:22:37 +1000 | [diff] [blame] | 149 | handle.ha_fid.fid_len = sizeof(xfs_fid_t) - |
| 150 | sizeof(handle.ha_fid.fid_len); |
| 151 | handle.ha_fid.fid_pad = 0; |
| 152 | handle.ha_fid.fid_gen = ip->i_d.di_gen; |
| 153 | handle.ha_fid.fid_ino = ip->i_ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | xfs_iunlock_map_shared(ip, lock_mode); |
| 156 | |
| 157 | hsize = XFS_HSIZE(handle); |
| 158 | } |
| 159 | |
| 160 | /* now copy our handle into the user buffer & write out the size */ |
| 161 | if (copy_to_user(hreq.ohandle, &handle, hsize) || |
| 162 | copy_to_user(hreq.ohandlen, &hsize, sizeof(__s32))) { |
| 163 | iput(inode); |
| 164 | return -XFS_ERROR(EFAULT); |
| 165 | } |
| 166 | |
| 167 | iput(inode); |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | |
| 172 | /* |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 173 | * Convert userspace handle data into inode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | * |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 175 | * We use the fact that all the fsop_handlereq ioctl calls have a data |
| 176 | * structure argument whose first component is always a xfs_fsop_handlereq_t, |
| 177 | * so we can pass that sub structure into this handy, shared routine. |
| 178 | * |
| 179 | * If no error, caller must always iput the returned inode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | */ |
| 181 | STATIC int |
| 182 | xfs_vget_fsop_handlereq( |
| 183 | xfs_mount_t *mp, |
| 184 | struct inode *parinode, /* parent inode pointer */ |
| 185 | xfs_fsop_handlereq_t *hreq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | struct inode **inode) |
| 187 | { |
| 188 | void __user *hanp; |
| 189 | size_t hlen; |
| 190 | xfs_fid_t *xfid; |
| 191 | xfs_handle_t *handlep; |
| 192 | xfs_handle_t handle; |
| 193 | xfs_inode_t *ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | xfs_ino_t ino; |
| 195 | __u32 igen; |
| 196 | int error; |
| 197 | |
| 198 | /* |
| 199 | * Only allow handle opens under a directory. |
| 200 | */ |
| 201 | if (!S_ISDIR(parinode->i_mode)) |
| 202 | return XFS_ERROR(ENOTDIR); |
| 203 | |
| 204 | hanp = hreq->ihandle; |
| 205 | hlen = hreq->ihandlen; |
| 206 | handlep = &handle; |
| 207 | |
| 208 | if (hlen < sizeof(handlep->ha_fsid) || hlen > sizeof(*handlep)) |
| 209 | return XFS_ERROR(EINVAL); |
| 210 | if (copy_from_user(handlep, hanp, hlen)) |
| 211 | return XFS_ERROR(EFAULT); |
| 212 | if (hlen < sizeof(*handlep)) |
| 213 | memset(((char *)handlep) + hlen, 0, sizeof(*handlep) - hlen); |
| 214 | if (hlen > sizeof(handlep->ha_fsid)) { |
Christoph Hellwig | c614391 | 2007-09-14 15:22:37 +1000 | [diff] [blame] | 215 | if (handlep->ha_fid.fid_len != |
| 216 | (hlen - sizeof(handlep->ha_fsid) - |
| 217 | sizeof(handlep->ha_fid.fid_len)) || |
| 218 | handlep->ha_fid.fid_pad) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | return XFS_ERROR(EINVAL); |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | * Crack the handle, obtain the inode # & generation # |
| 224 | */ |
| 225 | xfid = (struct xfs_fid *)&handlep->ha_fid; |
Christoph Hellwig | c614391 | 2007-09-14 15:22:37 +1000 | [diff] [blame] | 226 | if (xfid->fid_len == sizeof(*xfid) - sizeof(xfid->fid_len)) { |
| 227 | ino = xfid->fid_ino; |
| 228 | igen = xfid->fid_gen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } else { |
| 230 | return XFS_ERROR(EINVAL); |
| 231 | } |
| 232 | |
| 233 | /* |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 234 | * Get the XFS inode, building a Linux inode to go with it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | */ |
| 236 | error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0); |
| 237 | if (error) |
| 238 | return error; |
| 239 | if (ip == NULL) |
| 240 | return XFS_ERROR(EIO); |
| 241 | if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) { |
| 242 | xfs_iput_new(ip, XFS_ILOCK_SHARED); |
| 243 | return XFS_ERROR(ENOENT); |
| 244 | } |
| 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
| 247 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 248 | *inode = XFS_ITOV(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | STATIC int |
| 253 | xfs_open_by_handle( |
| 254 | xfs_mount_t *mp, |
| 255 | void __user *arg, |
| 256 | struct file *parfilp, |
| 257 | struct inode *parinode) |
| 258 | { |
| 259 | int error; |
| 260 | int new_fd; |
| 261 | int permflag; |
| 262 | struct file *filp; |
| 263 | struct inode *inode; |
| 264 | struct dentry *dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | xfs_fsop_handlereq_t hreq; |
| 266 | |
| 267 | if (!capable(CAP_SYS_ADMIN)) |
| 268 | return -XFS_ERROR(EPERM); |
| 269 | if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t))) |
| 270 | return -XFS_ERROR(EFAULT); |
| 271 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 272 | error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | if (error) |
| 274 | return -error; |
| 275 | |
| 276 | /* Restrict xfs_open_by_handle to directories & regular files. */ |
| 277 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) { |
| 278 | iput(inode); |
| 279 | return -XFS_ERROR(EINVAL); |
| 280 | } |
| 281 | |
| 282 | #if BITS_PER_LONG != 32 |
| 283 | hreq.oflags |= O_LARGEFILE; |
| 284 | #endif |
| 285 | /* Put open permission in namei format. */ |
| 286 | permflag = hreq.oflags; |
| 287 | if ((permflag+1) & O_ACCMODE) |
| 288 | permflag++; |
| 289 | if (permflag & O_TRUNC) |
| 290 | permflag |= 2; |
| 291 | |
| 292 | if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) && |
| 293 | (permflag & FMODE_WRITE) && IS_APPEND(inode)) { |
| 294 | iput(inode); |
| 295 | return -XFS_ERROR(EPERM); |
| 296 | } |
| 297 | |
| 298 | if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) { |
| 299 | iput(inode); |
| 300 | return -XFS_ERROR(EACCES); |
| 301 | } |
| 302 | |
| 303 | /* Can't write directories. */ |
| 304 | if ( S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) { |
| 305 | iput(inode); |
| 306 | return -XFS_ERROR(EISDIR); |
| 307 | } |
| 308 | |
| 309 | if ((new_fd = get_unused_fd()) < 0) { |
| 310 | iput(inode); |
| 311 | return new_fd; |
| 312 | } |
| 313 | |
| 314 | dentry = d_alloc_anon(inode); |
| 315 | if (dentry == NULL) { |
| 316 | iput(inode); |
| 317 | put_unused_fd(new_fd); |
| 318 | return -XFS_ERROR(ENOMEM); |
| 319 | } |
| 320 | |
| 321 | /* Ensure umount returns EBUSY on umounts while this file is open. */ |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 322 | mntget(parfilp->f_path.mnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | /* Create file pointer. */ |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 325 | filp = dentry_open(dentry, parfilp->f_path.mnt, hreq.oflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | if (IS_ERR(filp)) { |
| 327 | put_unused_fd(new_fd); |
| 328 | return -XFS_ERROR(-PTR_ERR(filp)); |
| 329 | } |
Vlad Apostolov | 2e2e7bb | 2006-11-11 18:04:47 +1100 | [diff] [blame] | 330 | if (inode->i_mode & S_IFREG) { |
| 331 | /* invisible operation should not change atime */ |
| 332 | filp->f_flags |= O_NOATIME; |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 333 | filp->f_op = &xfs_invis_file_operations; |
Vlad Apostolov | 2e2e7bb | 2006-11-11 18:04:47 +1100 | [diff] [blame] | 334 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | fd_install(new_fd, filp); |
| 337 | return new_fd; |
| 338 | } |
| 339 | |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 340 | /* |
| 341 | * This is a copy from fs/namei.c:vfs_readlink(), except for removing it's |
| 342 | * unused first argument. |
| 343 | */ |
| 344 | STATIC int |
| 345 | do_readlink( |
| 346 | char __user *buffer, |
| 347 | int buflen, |
| 348 | const char *link) |
| 349 | { |
| 350 | int len; |
| 351 | |
| 352 | len = PTR_ERR(link); |
| 353 | if (IS_ERR(link)) |
| 354 | goto out; |
| 355 | |
| 356 | len = strlen(link); |
| 357 | if (len > (unsigned) buflen) |
| 358 | len = buflen; |
| 359 | if (copy_to_user(buffer, link, len)) |
| 360 | len = -EFAULT; |
| 361 | out: |
| 362 | return len; |
| 363 | } |
| 364 | |
| 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | STATIC int |
| 367 | xfs_readlink_by_handle( |
| 368 | xfs_mount_t *mp, |
| 369 | void __user *arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | struct inode *parinode) |
| 371 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | struct inode *inode; |
| 373 | xfs_fsop_handlereq_t hreq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | __u32 olen; |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 375 | void *link; |
| 376 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
| 378 | if (!capable(CAP_SYS_ADMIN)) |
| 379 | return -XFS_ERROR(EPERM); |
| 380 | if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t))) |
| 381 | return -XFS_ERROR(EFAULT); |
| 382 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 383 | error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | if (error) |
| 385 | return -error; |
| 386 | |
| 387 | /* Restrict this handle operation to symlinks only. */ |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 388 | if (!S_ISLNK(inode->i_mode)) { |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 389 | error = -XFS_ERROR(EINVAL); |
| 390 | goto out_iput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | if (copy_from_user(&olen, hreq.ohandlen, sizeof(__u32))) { |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 394 | error = -XFS_ERROR(EFAULT); |
| 395 | goto out_iput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 398 | link = kmalloc(MAXPATHLEN+1, GFP_KERNEL); |
| 399 | if (!link) |
| 400 | goto out_iput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 402 | error = -xfs_readlink(XFS_I(inode), link); |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 403 | if (error) |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 404 | goto out_kfree; |
| 405 | error = do_readlink(hreq.ohandle, olen, link); |
| 406 | if (error) |
| 407 | goto out_kfree; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 408 | |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 409 | out_kfree: |
| 410 | kfree(link); |
| 411 | out_iput: |
| 412 | iput(inode); |
| 413 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | STATIC int |
| 417 | xfs_fssetdm_by_handle( |
| 418 | xfs_mount_t *mp, |
| 419 | void __user *arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | struct inode *parinode) |
| 421 | { |
| 422 | int error; |
| 423 | struct fsdmidata fsd; |
| 424 | xfs_fsop_setdm_handlereq_t dmhreq; |
| 425 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
| 427 | if (!capable(CAP_MKNOD)) |
| 428 | return -XFS_ERROR(EPERM); |
| 429 | if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t))) |
| 430 | return -XFS_ERROR(EFAULT); |
| 431 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 432 | error = xfs_vget_fsop_handlereq(mp, parinode, &dmhreq.hreq, &inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | if (error) |
| 434 | return -error; |
| 435 | |
| 436 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) { |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 437 | error = -XFS_ERROR(EPERM); |
| 438 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) { |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 442 | error = -XFS_ERROR(EFAULT); |
| 443 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 446 | error = -xfs_set_dmattrs(XFS_I(inode), fsd.fsd_dmevmask, |
| 447 | fsd.fsd_dmstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 449 | out: |
| 450 | iput(inode); |
| 451 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | STATIC int |
| 455 | xfs_attrlist_by_handle( |
| 456 | xfs_mount_t *mp, |
| 457 | void __user *arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | struct inode *parinode) |
| 459 | { |
| 460 | int error; |
| 461 | attrlist_cursor_kern_t *cursor; |
| 462 | xfs_fsop_attrlist_handlereq_t al_hreq; |
| 463 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | char *kbuf; |
| 465 | |
| 466 | if (!capable(CAP_SYS_ADMIN)) |
| 467 | return -XFS_ERROR(EPERM); |
| 468 | if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t))) |
| 469 | return -XFS_ERROR(EFAULT); |
| 470 | if (al_hreq.buflen > XATTR_LIST_MAX) |
| 471 | return -XFS_ERROR(EINVAL); |
| 472 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 473 | error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq, &inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | if (error) |
| 475 | goto out; |
| 476 | |
| 477 | kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL); |
| 478 | if (!kbuf) |
| 479 | goto out_vn_rele; |
| 480 | |
| 481 | cursor = (attrlist_cursor_kern_t *)&al_hreq.pos; |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 482 | error = xfs_attr_list(XFS_I(inode), kbuf, al_hreq.buflen, |
| 483 | al_hreq.flags, cursor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | if (error) |
| 485 | goto out_kfree; |
| 486 | |
| 487 | if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen)) |
| 488 | error = -EFAULT; |
| 489 | |
| 490 | out_kfree: |
| 491 | kfree(kbuf); |
| 492 | out_vn_rele: |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 493 | iput(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | out: |
| 495 | return -error; |
| 496 | } |
| 497 | |
| 498 | STATIC int |
| 499 | xfs_attrmulti_attr_get( |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 500 | struct inode *inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | char *name, |
| 502 | char __user *ubuf, |
| 503 | __uint32_t *len, |
| 504 | __uint32_t flags) |
| 505 | { |
| 506 | char *kbuf; |
| 507 | int error = EFAULT; |
| 508 | |
| 509 | if (*len > XATTR_SIZE_MAX) |
| 510 | return EINVAL; |
| 511 | kbuf = kmalloc(*len, GFP_KERNEL); |
| 512 | if (!kbuf) |
| 513 | return ENOMEM; |
| 514 | |
David Chinner | a8272ce | 2007-11-23 16:28:09 +1100 | [diff] [blame] | 515 | error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | if (error) |
| 517 | goto out_kfree; |
| 518 | |
| 519 | if (copy_to_user(ubuf, kbuf, *len)) |
| 520 | error = EFAULT; |
| 521 | |
| 522 | out_kfree: |
| 523 | kfree(kbuf); |
| 524 | return error; |
| 525 | } |
| 526 | |
| 527 | STATIC int |
| 528 | xfs_attrmulti_attr_set( |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 529 | struct inode *inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | char *name, |
| 531 | const char __user *ubuf, |
| 532 | __uint32_t len, |
| 533 | __uint32_t flags) |
| 534 | { |
| 535 | char *kbuf; |
| 536 | int error = EFAULT; |
| 537 | |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 538 | if (IS_RDONLY(inode)) |
Christoph Hellwig | 3542c6e | 2006-01-09 20:52:00 -0800 | [diff] [blame] | 539 | return -EROFS; |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 540 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | return EPERM; |
| 542 | if (len > XATTR_SIZE_MAX) |
| 543 | return EINVAL; |
| 544 | |
| 545 | kbuf = kmalloc(len, GFP_KERNEL); |
| 546 | if (!kbuf) |
| 547 | return ENOMEM; |
| 548 | |
| 549 | if (copy_from_user(kbuf, ubuf, len)) |
| 550 | goto out_kfree; |
| 551 | |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 552 | error = xfs_attr_set(XFS_I(inode), name, kbuf, len, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
| 554 | out_kfree: |
| 555 | kfree(kbuf); |
| 556 | return error; |
| 557 | } |
| 558 | |
| 559 | STATIC int |
| 560 | xfs_attrmulti_attr_remove( |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 561 | struct inode *inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | char *name, |
| 563 | __uint32_t flags) |
| 564 | { |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 565 | if (IS_RDONLY(inode)) |
Christoph Hellwig | 3542c6e | 2006-01-09 20:52:00 -0800 | [diff] [blame] | 566 | return -EROFS; |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 567 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | return EPERM; |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 569 | return xfs_attr_remove(XFS_I(inode), name, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | STATIC int |
| 573 | xfs_attrmulti_by_handle( |
| 574 | xfs_mount_t *mp, |
| 575 | void __user *arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | struct inode *parinode) |
| 577 | { |
| 578 | int error; |
| 579 | xfs_attr_multiop_t *ops; |
| 580 | xfs_fsop_attrmulti_handlereq_t am_hreq; |
| 581 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | unsigned int i, size; |
| 583 | char *attr_name; |
| 584 | |
| 585 | if (!capable(CAP_SYS_ADMIN)) |
| 586 | return -XFS_ERROR(EPERM); |
| 587 | if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t))) |
| 588 | return -XFS_ERROR(EFAULT); |
| 589 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 590 | error = xfs_vget_fsop_handlereq(mp, parinode, &am_hreq.hreq, &inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | if (error) |
| 592 | goto out; |
| 593 | |
| 594 | error = E2BIG; |
| 595 | size = am_hreq.opcount * sizeof(attr_multiop_t); |
| 596 | if (!size || size > 16 * PAGE_SIZE) |
| 597 | goto out_vn_rele; |
| 598 | |
| 599 | error = ENOMEM; |
| 600 | ops = kmalloc(size, GFP_KERNEL); |
| 601 | if (!ops) |
| 602 | goto out_vn_rele; |
| 603 | |
| 604 | error = EFAULT; |
| 605 | if (copy_from_user(ops, am_hreq.ops, size)) |
| 606 | goto out_kfree_ops; |
| 607 | |
| 608 | attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL); |
| 609 | if (!attr_name) |
| 610 | goto out_kfree_ops; |
| 611 | |
| 612 | |
| 613 | error = 0; |
| 614 | for (i = 0; i < am_hreq.opcount; i++) { |
| 615 | ops[i].am_error = strncpy_from_user(attr_name, |
| 616 | ops[i].am_attrname, MAXNAMELEN); |
| 617 | if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN) |
| 618 | error = -ERANGE; |
| 619 | if (ops[i].am_error < 0) |
| 620 | break; |
| 621 | |
| 622 | switch (ops[i].am_opcode) { |
| 623 | case ATTR_OP_GET: |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 624 | ops[i].am_error = xfs_attrmulti_attr_get(inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | attr_name, ops[i].am_attrvalue, |
| 626 | &ops[i].am_length, ops[i].am_flags); |
| 627 | break; |
| 628 | case ATTR_OP_SET: |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 629 | ops[i].am_error = xfs_attrmulti_attr_set(inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | attr_name, ops[i].am_attrvalue, |
| 631 | ops[i].am_length, ops[i].am_flags); |
| 632 | break; |
| 633 | case ATTR_OP_REMOVE: |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 634 | ops[i].am_error = xfs_attrmulti_attr_remove(inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | attr_name, ops[i].am_flags); |
| 636 | break; |
| 637 | default: |
| 638 | ops[i].am_error = EINVAL; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | if (copy_to_user(am_hreq.ops, ops, size)) |
| 643 | error = XFS_ERROR(EFAULT); |
| 644 | |
| 645 | kfree(attr_name); |
| 646 | out_kfree_ops: |
| 647 | kfree(ops); |
| 648 | out_vn_rele: |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 649 | iput(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | out: |
| 651 | return -error; |
| 652 | } |
| 653 | |
| 654 | /* prototypes for a few of the stack-hungry cases that have |
| 655 | * their own functions. Functions are defined after their use |
| 656 | * so gcc doesn't get fancy and inline them with -03 */ |
| 657 | |
| 658 | STATIC int |
| 659 | xfs_ioc_space( |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 660 | struct xfs_inode *ip, |
Alexey Dobriyan | f37ea14 | 2006-09-28 10:52:04 +1000 | [diff] [blame] | 661 | struct inode *inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | struct file *filp, |
| 663 | int flags, |
| 664 | unsigned int cmd, |
| 665 | void __user *arg); |
| 666 | |
| 667 | STATIC int |
| 668 | xfs_ioc_bulkstat( |
| 669 | xfs_mount_t *mp, |
| 670 | unsigned int cmd, |
| 671 | void __user *arg); |
| 672 | |
| 673 | STATIC int |
| 674 | xfs_ioc_fsgeometry_v1( |
| 675 | xfs_mount_t *mp, |
| 676 | void __user *arg); |
| 677 | |
| 678 | STATIC int |
| 679 | xfs_ioc_fsgeometry( |
| 680 | xfs_mount_t *mp, |
| 681 | void __user *arg); |
| 682 | |
| 683 | STATIC int |
| 684 | xfs_ioc_xattr( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | xfs_inode_t *ip, |
| 686 | struct file *filp, |
| 687 | unsigned int cmd, |
| 688 | void __user *arg); |
| 689 | |
| 690 | STATIC int |
Christoph Hellwig | c83bfab | 2007-10-11 17:47:00 +1000 | [diff] [blame] | 691 | xfs_ioc_fsgetxattr( |
| 692 | xfs_inode_t *ip, |
| 693 | int attr, |
| 694 | void __user *arg); |
| 695 | |
| 696 | STATIC int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | xfs_ioc_getbmap( |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 698 | struct xfs_inode *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | int flags, |
| 700 | unsigned int cmd, |
| 701 | void __user *arg); |
| 702 | |
| 703 | STATIC int |
| 704 | xfs_ioc_getbmapx( |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 705 | struct xfs_inode *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | void __user *arg); |
| 707 | |
| 708 | int |
| 709 | xfs_ioctl( |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 710 | xfs_inode_t *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | struct file *filp, |
| 712 | int ioflags, |
| 713 | unsigned int cmd, |
| 714 | void __user *arg) |
| 715 | { |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 716 | struct inode *inode = filp->f_path.dentry->d_inode; |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 717 | xfs_mount_t *mp = ip->i_mount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
Lachlan McIlroy | cf441ee | 2008-02-07 16:42:19 +1100 | [diff] [blame] | 720 | xfs_itrace_entry(XFS_I(inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | switch (cmd) { |
| 722 | |
| 723 | case XFS_IOC_ALLOCSP: |
| 724 | case XFS_IOC_FREESP: |
| 725 | case XFS_IOC_RESVSP: |
| 726 | case XFS_IOC_UNRESVSP: |
| 727 | case XFS_IOC_ALLOCSP64: |
| 728 | case XFS_IOC_FREESP64: |
| 729 | case XFS_IOC_RESVSP64: |
| 730 | case XFS_IOC_UNRESVSP64: |
| 731 | /* |
| 732 | * Only allow the sys admin to reserve space unless |
| 733 | * unwritten extents are enabled. |
| 734 | */ |
Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 735 | if (!xfs_sb_version_hasextflgbit(&mp->m_sb) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | !capable(CAP_SYS_ADMIN)) |
| 737 | return -EPERM; |
| 738 | |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 739 | return xfs_ioc_space(ip, inode, filp, ioflags, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
| 741 | case XFS_IOC_DIOINFO: { |
| 742 | struct dioattr da; |
| 743 | xfs_buftarg_t *target = |
Eric Sandeen | 71ddabb | 2007-11-23 16:29:42 +1100 | [diff] [blame] | 744 | XFS_IS_REALTIME_INODE(ip) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | mp->m_rtdev_targp : mp->m_ddev_targp; |
| 746 | |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 747 | da.d_mem = da.d_miniosz = 1 << target->bt_sshift; |
Nathan Scott | 0d14824 | 2006-01-11 15:33:51 +1100 | [diff] [blame] | 748 | da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
| 750 | if (copy_to_user(arg, &da, sizeof(da))) |
| 751 | return -XFS_ERROR(EFAULT); |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | case XFS_IOC_FSBULKSTAT_SINGLE: |
| 756 | case XFS_IOC_FSBULKSTAT: |
| 757 | case XFS_IOC_FSINUMBERS: |
| 758 | return xfs_ioc_bulkstat(mp, cmd, arg); |
| 759 | |
| 760 | case XFS_IOC_FSGEOMETRY_V1: |
| 761 | return xfs_ioc_fsgeometry_v1(mp, arg); |
| 762 | |
| 763 | case XFS_IOC_FSGEOMETRY: |
| 764 | return xfs_ioc_fsgeometry(mp, arg); |
| 765 | |
| 766 | case XFS_IOC_GETVERSION: |
Alexey Dobriyan | 87395de | 2006-09-28 10:56:01 +1000 | [diff] [blame] | 767 | return put_user(inode->i_generation, (int __user *)arg); |
| 768 | |
Christoph Hellwig | c83bfab | 2007-10-11 17:47:00 +1000 | [diff] [blame] | 769 | case XFS_IOC_FSGETXATTR: |
| 770 | return xfs_ioc_fsgetxattr(ip, 0, arg); |
| 771 | case XFS_IOC_FSGETXATTRA: |
| 772 | return xfs_ioc_fsgetxattr(ip, 1, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | case XFS_IOC_GETXFLAGS: |
| 774 | case XFS_IOC_SETXFLAGS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | case XFS_IOC_FSSETXATTR: |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 776 | return xfs_ioc_xattr(ip, filp, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
| 778 | case XFS_IOC_FSSETDM: { |
| 779 | struct fsdmidata dmi; |
| 780 | |
| 781 | if (copy_from_user(&dmi, arg, sizeof(dmi))) |
| 782 | return -XFS_ERROR(EFAULT); |
| 783 | |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 784 | error = xfs_set_dmattrs(ip, dmi.fsd_dmevmask, |
| 785 | dmi.fsd_dmstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | return -error; |
| 787 | } |
| 788 | |
| 789 | case XFS_IOC_GETBMAP: |
| 790 | case XFS_IOC_GETBMAPA: |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 791 | return xfs_ioc_getbmap(ip, ioflags, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
| 793 | case XFS_IOC_GETBMAPX: |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 794 | return xfs_ioc_getbmapx(ip, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | case XFS_IOC_FD_TO_HANDLE: |
| 797 | case XFS_IOC_PATH_TO_HANDLE: |
| 798 | case XFS_IOC_PATH_TO_FSHANDLE: |
| 799 | return xfs_find_handle(cmd, arg); |
| 800 | |
| 801 | case XFS_IOC_OPEN_BY_HANDLE: |
| 802 | return xfs_open_by_handle(mp, arg, filp, inode); |
| 803 | |
| 804 | case XFS_IOC_FSSETDM_BY_HANDLE: |
Lachlan McIlroy | 5180602 | 2007-02-10 18:35:46 +1100 | [diff] [blame] | 805 | return xfs_fssetdm_by_handle(mp, arg, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
| 807 | case XFS_IOC_READLINK_BY_HANDLE: |
Lachlan McIlroy | 5180602 | 2007-02-10 18:35:46 +1100 | [diff] [blame] | 808 | return xfs_readlink_by_handle(mp, arg, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
| 810 | case XFS_IOC_ATTRLIST_BY_HANDLE: |
Lachlan McIlroy | 5180602 | 2007-02-10 18:35:46 +1100 | [diff] [blame] | 811 | return xfs_attrlist_by_handle(mp, arg, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
| 813 | case XFS_IOC_ATTRMULTI_BY_HANDLE: |
Lachlan McIlroy | 5180602 | 2007-02-10 18:35:46 +1100 | [diff] [blame] | 814 | return xfs_attrmulti_by_handle(mp, arg, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
| 816 | case XFS_IOC_SWAPEXT: { |
| 817 | error = xfs_swapext((struct xfs_swapext __user *)arg); |
| 818 | return -error; |
| 819 | } |
| 820 | |
| 821 | case XFS_IOC_FSCOUNTS: { |
| 822 | xfs_fsop_counts_t out; |
| 823 | |
| 824 | error = xfs_fs_counts(mp, &out); |
| 825 | if (error) |
| 826 | return -error; |
| 827 | |
| 828 | if (copy_to_user(arg, &out, sizeof(out))) |
| 829 | return -XFS_ERROR(EFAULT); |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | case XFS_IOC_SET_RESBLKS: { |
| 834 | xfs_fsop_resblks_t inout; |
| 835 | __uint64_t in; |
| 836 | |
| 837 | if (!capable(CAP_SYS_ADMIN)) |
| 838 | return -EPERM; |
| 839 | |
| 840 | if (copy_from_user(&inout, arg, sizeof(inout))) |
| 841 | return -XFS_ERROR(EFAULT); |
| 842 | |
| 843 | /* input parameter is passed in resblks field of structure */ |
| 844 | in = inout.resblks; |
| 845 | error = xfs_reserve_blocks(mp, &in, &inout); |
| 846 | if (error) |
| 847 | return -error; |
| 848 | |
| 849 | if (copy_to_user(arg, &inout, sizeof(inout))) |
| 850 | return -XFS_ERROR(EFAULT); |
| 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | case XFS_IOC_GET_RESBLKS: { |
| 855 | xfs_fsop_resblks_t out; |
| 856 | |
| 857 | if (!capable(CAP_SYS_ADMIN)) |
| 858 | return -EPERM; |
| 859 | |
| 860 | error = xfs_reserve_blocks(mp, NULL, &out); |
| 861 | if (error) |
| 862 | return -error; |
| 863 | |
| 864 | if (copy_to_user(arg, &out, sizeof(out))) |
| 865 | return -XFS_ERROR(EFAULT); |
| 866 | |
| 867 | return 0; |
| 868 | } |
| 869 | |
| 870 | case XFS_IOC_FSGROWFSDATA: { |
| 871 | xfs_growfs_data_t in; |
| 872 | |
| 873 | if (!capable(CAP_SYS_ADMIN)) |
| 874 | return -EPERM; |
| 875 | |
| 876 | if (copy_from_user(&in, arg, sizeof(in))) |
| 877 | return -XFS_ERROR(EFAULT); |
| 878 | |
| 879 | error = xfs_growfs_data(mp, &in); |
| 880 | return -error; |
| 881 | } |
| 882 | |
| 883 | case XFS_IOC_FSGROWFSLOG: { |
| 884 | xfs_growfs_log_t in; |
| 885 | |
| 886 | if (!capable(CAP_SYS_ADMIN)) |
| 887 | return -EPERM; |
| 888 | |
| 889 | if (copy_from_user(&in, arg, sizeof(in))) |
| 890 | return -XFS_ERROR(EFAULT); |
| 891 | |
| 892 | error = xfs_growfs_log(mp, &in); |
| 893 | return -error; |
| 894 | } |
| 895 | |
| 896 | case XFS_IOC_FSGROWFSRT: { |
| 897 | xfs_growfs_rt_t in; |
| 898 | |
| 899 | if (!capable(CAP_SYS_ADMIN)) |
| 900 | return -EPERM; |
| 901 | |
| 902 | if (copy_from_user(&in, arg, sizeof(in))) |
| 903 | return -XFS_ERROR(EFAULT); |
| 904 | |
| 905 | error = xfs_growfs_rt(mp, &in); |
| 906 | return -error; |
| 907 | } |
| 908 | |
| 909 | case XFS_IOC_FREEZE: |
| 910 | if (!capable(CAP_SYS_ADMIN)) |
| 911 | return -EPERM; |
| 912 | |
| 913 | if (inode->i_sb->s_frozen == SB_UNFROZEN) |
| 914 | freeze_bdev(inode->i_sb->s_bdev); |
| 915 | return 0; |
| 916 | |
| 917 | case XFS_IOC_THAW: |
| 918 | if (!capable(CAP_SYS_ADMIN)) |
| 919 | return -EPERM; |
| 920 | if (inode->i_sb->s_frozen != SB_UNFROZEN) |
| 921 | thaw_bdev(inode->i_sb->s_bdev, inode->i_sb); |
| 922 | return 0; |
| 923 | |
| 924 | case XFS_IOC_GOINGDOWN: { |
| 925 | __uint32_t in; |
| 926 | |
| 927 | if (!capable(CAP_SYS_ADMIN)) |
| 928 | return -EPERM; |
| 929 | |
| 930 | if (get_user(in, (__uint32_t __user *)arg)) |
| 931 | return -XFS_ERROR(EFAULT); |
| 932 | |
| 933 | error = xfs_fs_goingdown(mp, in); |
| 934 | return -error; |
| 935 | } |
| 936 | |
| 937 | case XFS_IOC_ERROR_INJECTION: { |
| 938 | xfs_error_injection_t in; |
| 939 | |
| 940 | if (!capable(CAP_SYS_ADMIN)) |
| 941 | return -EPERM; |
| 942 | |
| 943 | if (copy_from_user(&in, arg, sizeof(in))) |
| 944 | return -XFS_ERROR(EFAULT); |
| 945 | |
| 946 | error = xfs_errortag_add(in.errtag, mp); |
| 947 | return -error; |
| 948 | } |
| 949 | |
| 950 | case XFS_IOC_ERROR_CLEARALL: |
| 951 | if (!capable(CAP_SYS_ADMIN)) |
| 952 | return -EPERM; |
| 953 | |
Christoph Hellwig | 0ce4cfd | 2007-08-30 17:20:53 +1000 | [diff] [blame] | 954 | error = xfs_errortag_clearall(mp, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | return -error; |
| 956 | |
| 957 | default: |
| 958 | return -ENOTTY; |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | STATIC int |
| 963 | xfs_ioc_space( |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 964 | struct xfs_inode *ip, |
Alexey Dobriyan | f37ea14 | 2006-09-28 10:52:04 +1000 | [diff] [blame] | 965 | struct inode *inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | struct file *filp, |
| 967 | int ioflags, |
| 968 | unsigned int cmd, |
| 969 | void __user *arg) |
| 970 | { |
| 971 | xfs_flock64_t bf; |
| 972 | int attr_flags = 0; |
| 973 | int error; |
| 974 | |
Alexey Dobriyan | f37ea14 | 2006-09-28 10:52:04 +1000 | [diff] [blame] | 975 | if (inode->i_flags & (S_IMMUTABLE|S_APPEND)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | return -XFS_ERROR(EPERM); |
| 977 | |
Eric Sandeen | ad4a8ac | 2005-09-02 16:41:16 +1000 | [diff] [blame] | 978 | if (!(filp->f_mode & FMODE_WRITE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | return -XFS_ERROR(EBADF); |
| 980 | |
Alexey Dobriyan | f37ea14 | 2006-09-28 10:52:04 +1000 | [diff] [blame] | 981 | if (!S_ISREG(inode->i_mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | return -XFS_ERROR(EINVAL); |
| 983 | |
| 984 | if (copy_from_user(&bf, arg, sizeof(bf))) |
| 985 | return -XFS_ERROR(EFAULT); |
| 986 | |
| 987 | if (filp->f_flags & (O_NDELAY|O_NONBLOCK)) |
| 988 | attr_flags |= ATTR_NONBLOCK; |
| 989 | if (ioflags & IO_INVIS) |
| 990 | attr_flags |= ATTR_DMI; |
| 991 | |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 992 | error = xfs_change_file_space(ip, cmd, &bf, filp->f_pos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | NULL, attr_flags); |
| 994 | return -error; |
| 995 | } |
| 996 | |
| 997 | STATIC int |
| 998 | xfs_ioc_bulkstat( |
| 999 | xfs_mount_t *mp, |
| 1000 | unsigned int cmd, |
| 1001 | void __user *arg) |
| 1002 | { |
| 1003 | xfs_fsop_bulkreq_t bulkreq; |
| 1004 | int count; /* # of records returned */ |
| 1005 | xfs_ino_t inlast; /* last inode number */ |
| 1006 | int done; |
| 1007 | int error; |
| 1008 | |
| 1009 | /* done = 1 if there are more stats to get and if bulkstat */ |
| 1010 | /* should be called again (unused here, but used in dmapi) */ |
| 1011 | |
| 1012 | if (!capable(CAP_SYS_ADMIN)) |
| 1013 | return -EPERM; |
| 1014 | |
| 1015 | if (XFS_FORCED_SHUTDOWN(mp)) |
| 1016 | return -XFS_ERROR(EIO); |
| 1017 | |
| 1018 | if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t))) |
| 1019 | return -XFS_ERROR(EFAULT); |
| 1020 | |
| 1021 | if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64))) |
| 1022 | return -XFS_ERROR(EFAULT); |
| 1023 | |
| 1024 | if ((count = bulkreq.icount) <= 0) |
| 1025 | return -XFS_ERROR(EINVAL); |
| 1026 | |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 1027 | if (bulkreq.ubuffer == NULL) |
| 1028 | return -XFS_ERROR(EINVAL); |
| 1029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | if (cmd == XFS_IOC_FSINUMBERS) |
| 1031 | error = xfs_inumbers(mp, &inlast, &count, |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 1032 | bulkreq.ubuffer, xfs_inumbers_fmt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE) |
| 1034 | error = xfs_bulkstat_single(mp, &inlast, |
| 1035 | bulkreq.ubuffer, &done); |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 1036 | else /* XFS_IOC_FSBULKSTAT */ |
| 1037 | error = xfs_bulkstat(mp, &inlast, &count, |
| 1038 | (bulkstat_one_pf)xfs_bulkstat_one, NULL, |
| 1039 | sizeof(xfs_bstat_t), bulkreq.ubuffer, |
| 1040 | BULKSTAT_FG_QUICK, &done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
| 1042 | if (error) |
| 1043 | return -error; |
| 1044 | |
| 1045 | if (bulkreq.ocount != NULL) { |
| 1046 | if (copy_to_user(bulkreq.lastip, &inlast, |
| 1047 | sizeof(xfs_ino_t))) |
| 1048 | return -XFS_ERROR(EFAULT); |
| 1049 | |
| 1050 | if (copy_to_user(bulkreq.ocount, &count, sizeof(count))) |
| 1051 | return -XFS_ERROR(EFAULT); |
| 1052 | } |
| 1053 | |
| 1054 | return 0; |
| 1055 | } |
| 1056 | |
| 1057 | STATIC int |
| 1058 | xfs_ioc_fsgeometry_v1( |
| 1059 | xfs_mount_t *mp, |
| 1060 | void __user *arg) |
| 1061 | { |
| 1062 | xfs_fsop_geom_v1_t fsgeo; |
| 1063 | int error; |
| 1064 | |
| 1065 | error = xfs_fs_geometry(mp, (xfs_fsop_geom_t *)&fsgeo, 3); |
| 1066 | if (error) |
| 1067 | return -error; |
| 1068 | |
| 1069 | if (copy_to_user(arg, &fsgeo, sizeof(fsgeo))) |
| 1070 | return -XFS_ERROR(EFAULT); |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
| 1074 | STATIC int |
| 1075 | xfs_ioc_fsgeometry( |
| 1076 | xfs_mount_t *mp, |
| 1077 | void __user *arg) |
| 1078 | { |
| 1079 | xfs_fsop_geom_t fsgeo; |
| 1080 | int error; |
| 1081 | |
| 1082 | error = xfs_fs_geometry(mp, &fsgeo, 4); |
| 1083 | if (error) |
| 1084 | return -error; |
| 1085 | |
| 1086 | if (copy_to_user(arg, &fsgeo, sizeof(fsgeo))) |
| 1087 | return -XFS_ERROR(EFAULT); |
| 1088 | return 0; |
| 1089 | } |
| 1090 | |
| 1091 | /* |
| 1092 | * Linux extended inode flags interface. |
| 1093 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
| 1095 | STATIC unsigned int |
| 1096 | xfs_merge_ioc_xflags( |
| 1097 | unsigned int flags, |
| 1098 | unsigned int start) |
| 1099 | { |
| 1100 | unsigned int xflags = start; |
| 1101 | |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 1102 | if (flags & FS_IMMUTABLE_FL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | xflags |= XFS_XFLAG_IMMUTABLE; |
| 1104 | else |
| 1105 | xflags &= ~XFS_XFLAG_IMMUTABLE; |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 1106 | if (flags & FS_APPEND_FL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | xflags |= XFS_XFLAG_APPEND; |
| 1108 | else |
| 1109 | xflags &= ~XFS_XFLAG_APPEND; |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 1110 | if (flags & FS_SYNC_FL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | xflags |= XFS_XFLAG_SYNC; |
| 1112 | else |
| 1113 | xflags &= ~XFS_XFLAG_SYNC; |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 1114 | if (flags & FS_NOATIME_FL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | xflags |= XFS_XFLAG_NOATIME; |
| 1116 | else |
| 1117 | xflags &= ~XFS_XFLAG_NOATIME; |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 1118 | if (flags & FS_NODUMP_FL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | xflags |= XFS_XFLAG_NODUMP; |
| 1120 | else |
| 1121 | xflags &= ~XFS_XFLAG_NODUMP; |
| 1122 | |
| 1123 | return xflags; |
| 1124 | } |
| 1125 | |
| 1126 | STATIC unsigned int |
| 1127 | xfs_di2lxflags( |
| 1128 | __uint16_t di_flags) |
| 1129 | { |
| 1130 | unsigned int flags = 0; |
| 1131 | |
| 1132 | if (di_flags & XFS_DIFLAG_IMMUTABLE) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 1133 | flags |= FS_IMMUTABLE_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | if (di_flags & XFS_DIFLAG_APPEND) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 1135 | flags |= FS_APPEND_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | if (di_flags & XFS_DIFLAG_SYNC) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 1137 | flags |= FS_SYNC_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | if (di_flags & XFS_DIFLAG_NOATIME) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 1139 | flags |= FS_NOATIME_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | if (di_flags & XFS_DIFLAG_NODUMP) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 1141 | flags |= FS_NODUMP_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | return flags; |
| 1143 | } |
| 1144 | |
| 1145 | STATIC int |
Christoph Hellwig | c83bfab | 2007-10-11 17:47:00 +1000 | [diff] [blame] | 1146 | xfs_ioc_fsgetxattr( |
| 1147 | xfs_inode_t *ip, |
| 1148 | int attr, |
| 1149 | void __user *arg) |
| 1150 | { |
| 1151 | struct fsxattr fa; |
| 1152 | |
| 1153 | xfs_ilock(ip, XFS_ILOCK_SHARED); |
| 1154 | fa.fsx_xflags = xfs_ip2xflags(ip); |
| 1155 | fa.fsx_extsize = ip->i_d.di_extsize << ip->i_mount->m_sb.sb_blocklog; |
| 1156 | fa.fsx_projid = ip->i_d.di_projid; |
| 1157 | |
| 1158 | if (attr) { |
| 1159 | if (ip->i_afp) { |
| 1160 | if (ip->i_afp->if_flags & XFS_IFEXTENTS) |
| 1161 | fa.fsx_nextents = ip->i_afp->if_bytes / |
| 1162 | sizeof(xfs_bmbt_rec_t); |
| 1163 | else |
| 1164 | fa.fsx_nextents = ip->i_d.di_anextents; |
| 1165 | } else |
| 1166 | fa.fsx_nextents = 0; |
| 1167 | } else { |
| 1168 | if (ip->i_df.if_flags & XFS_IFEXTENTS) |
| 1169 | fa.fsx_nextents = ip->i_df.if_bytes / |
| 1170 | sizeof(xfs_bmbt_rec_t); |
| 1171 | else |
| 1172 | fa.fsx_nextents = ip->i_d.di_nextents; |
| 1173 | } |
| 1174 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
| 1175 | |
| 1176 | if (copy_to_user(arg, &fa, sizeof(fa))) |
| 1177 | return -EFAULT; |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
| 1181 | STATIC int |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1182 | xfs_ioc_fssetxattr( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | xfs_inode_t *ip, |
| 1184 | struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | void __user *arg) |
| 1186 | { |
| 1187 | struct fsxattr fa; |
Nathan Scott | 8285fb5 | 2006-06-09 17:07:12 +1000 | [diff] [blame] | 1188 | struct bhv_vattr *vattr; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1189 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | int attr_flags; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1191 | |
| 1192 | if (copy_from_user(&fa, arg, sizeof(fa))) |
| 1193 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 1195 | vattr = kmalloc(sizeof(*vattr), GFP_KERNEL); |
| 1196 | if (unlikely(!vattr)) |
| 1197 | return -ENOMEM; |
| 1198 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1199 | attr_flags = 0; |
| 1200 | if (filp->f_flags & (O_NDELAY|O_NONBLOCK)) |
| 1201 | attr_flags |= ATTR_NONBLOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1203 | vattr->va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | XFS_AT_PROJID; |
| 1204 | vattr->va_xflags = fa.fsx_xflags; |
| 1205 | vattr->va_extsize = fa.fsx_extsize; |
| 1206 | vattr->va_projid = fa.fsx_projid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1208 | error = -xfs_setattr(ip, vattr, attr_flags, NULL); |
| 1209 | if (!error) |
| 1210 | vn_revalidate(XFS_ITOV(ip)); /* update flags */ |
| 1211 | kfree(vattr); |
| 1212 | return 0; |
| 1213 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1215 | STATIC int |
| 1216 | xfs_ioc_getxflags( |
| 1217 | xfs_inode_t *ip, |
| 1218 | void __user *arg) |
| 1219 | { |
| 1220 | unsigned int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1222 | flags = xfs_di2lxflags(ip->i_d.di_flags); |
| 1223 | if (copy_to_user(arg, &flags, sizeof(flags))) |
| 1224 | return -EFAULT; |
| 1225 | return 0; |
| 1226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1228 | STATIC int |
| 1229 | xfs_ioc_setxflags( |
| 1230 | xfs_inode_t *ip, |
| 1231 | struct file *filp, |
| 1232 | void __user *arg) |
| 1233 | { |
| 1234 | struct bhv_vattr *vattr; |
| 1235 | unsigned int flags; |
| 1236 | int attr_flags; |
| 1237 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1239 | if (copy_from_user(&flags, arg, sizeof(flags))) |
| 1240 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1242 | if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \ |
| 1243 | FS_NOATIME_FL | FS_NODUMP_FL | \ |
| 1244 | FS_SYNC_FL)) |
| 1245 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1247 | vattr = kmalloc(sizeof(*vattr), GFP_KERNEL); |
| 1248 | if (unlikely(!vattr)) |
| 1249 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1251 | attr_flags = 0; |
| 1252 | if (filp->f_flags & (O_NDELAY|O_NONBLOCK)) |
| 1253 | attr_flags |= ATTR_NONBLOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1255 | vattr->va_mask = XFS_AT_XFLAGS; |
| 1256 | vattr->va_xflags = xfs_merge_ioc_xflags(flags, xfs_ip2xflags(ip)); |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 1257 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1258 | error = -xfs_setattr(ip, vattr, attr_flags, NULL); |
| 1259 | if (likely(!error)) |
| 1260 | vn_revalidate(XFS_ITOV(ip)); /* update flags */ |
Nathan Scott | 220b528 | 2006-03-14 13:33:36 +1100 | [diff] [blame] | 1261 | kfree(vattr); |
| 1262 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | STATIC int |
| 1266 | xfs_ioc_getbmap( |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 1267 | struct xfs_inode *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | int ioflags, |
| 1269 | unsigned int cmd, |
| 1270 | void __user *arg) |
| 1271 | { |
| 1272 | struct getbmap bm; |
| 1273 | int iflags; |
| 1274 | int error; |
| 1275 | |
| 1276 | if (copy_from_user(&bm, arg, sizeof(bm))) |
| 1277 | return -XFS_ERROR(EFAULT); |
| 1278 | |
| 1279 | if (bm.bmv_count < 2) |
| 1280 | return -XFS_ERROR(EINVAL); |
| 1281 | |
| 1282 | iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0); |
| 1283 | if (ioflags & IO_INVIS) |
| 1284 | iflags |= BMV_IF_NO_DMAPI_READ; |
| 1285 | |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 1286 | error = xfs_getbmap(ip, &bm, (struct getbmap __user *)arg+1, iflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | if (error) |
| 1288 | return -error; |
| 1289 | |
| 1290 | if (copy_to_user(arg, &bm, sizeof(bm))) |
| 1291 | return -XFS_ERROR(EFAULT); |
| 1292 | return 0; |
| 1293 | } |
| 1294 | |
| 1295 | STATIC int |
| 1296 | xfs_ioc_getbmapx( |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 1297 | struct xfs_inode *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | void __user *arg) |
| 1299 | { |
| 1300 | struct getbmapx bmx; |
| 1301 | struct getbmap bm; |
| 1302 | int iflags; |
| 1303 | int error; |
| 1304 | |
| 1305 | if (copy_from_user(&bmx, arg, sizeof(bmx))) |
| 1306 | return -XFS_ERROR(EFAULT); |
| 1307 | |
| 1308 | if (bmx.bmv_count < 2) |
| 1309 | return -XFS_ERROR(EINVAL); |
| 1310 | |
| 1311 | /* |
| 1312 | * Map input getbmapx structure to a getbmap |
| 1313 | * structure for xfs_getbmap. |
| 1314 | */ |
| 1315 | GETBMAP_CONVERT(bmx, bm); |
| 1316 | |
| 1317 | iflags = bmx.bmv_iflags; |
| 1318 | |
| 1319 | if (iflags & (~BMV_IF_VALID)) |
| 1320 | return -XFS_ERROR(EINVAL); |
| 1321 | |
| 1322 | iflags |= BMV_IF_EXTENDED; |
| 1323 | |
Christoph Hellwig | 993386c1 | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 1324 | error = xfs_getbmap(ip, &bm, (struct getbmapx __user *)arg+1, iflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | if (error) |
| 1326 | return -error; |
| 1327 | |
| 1328 | GETBMAP_CONVERT(bm, bmx); |
| 1329 | |
| 1330 | if (copy_to_user(arg, &bmx, sizeof(bmx))) |
| 1331 | return -XFS_ERROR(EFAULT); |
| 1332 | |
| 1333 | return 0; |
| 1334 | } |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame^] | 1335 | |
| 1336 | int |
| 1337 | xfs_ioctl( |
| 1338 | xfs_inode_t *ip, |
| 1339 | struct file *filp, |
| 1340 | int ioflags, |
| 1341 | unsigned int cmd, |
| 1342 | void __user *arg) |
| 1343 | { |
| 1344 | struct inode *inode = filp->f_path.dentry->d_inode; |
| 1345 | xfs_mount_t *mp = ip->i_mount; |
| 1346 | int error; |
| 1347 | |
| 1348 | xfs_itrace_entry(XFS_I(inode)); |
| 1349 | switch (cmd) { |
| 1350 | |
| 1351 | case XFS_IOC_ALLOCSP: |
| 1352 | case XFS_IOC_FREESP: |
| 1353 | case XFS_IOC_RESVSP: |
| 1354 | case XFS_IOC_UNRESVSP: |
| 1355 | case XFS_IOC_ALLOCSP64: |
| 1356 | case XFS_IOC_FREESP64: |
| 1357 | case XFS_IOC_RESVSP64: |
| 1358 | case XFS_IOC_UNRESVSP64: |
| 1359 | /* |
| 1360 | * Only allow the sys admin to reserve space unless |
| 1361 | * unwritten extents are enabled. |
| 1362 | */ |
| 1363 | if (!xfs_sb_version_hasextflgbit(&mp->m_sb) && |
| 1364 | !capable(CAP_SYS_ADMIN)) |
| 1365 | return -EPERM; |
| 1366 | |
| 1367 | return xfs_ioc_space(ip, inode, filp, ioflags, cmd, arg); |
| 1368 | |
| 1369 | case XFS_IOC_DIOINFO: { |
| 1370 | struct dioattr da; |
| 1371 | xfs_buftarg_t *target = |
| 1372 | XFS_IS_REALTIME_INODE(ip) ? |
| 1373 | mp->m_rtdev_targp : mp->m_ddev_targp; |
| 1374 | |
| 1375 | da.d_mem = da.d_miniosz = 1 << target->bt_sshift; |
| 1376 | da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1); |
| 1377 | |
| 1378 | if (copy_to_user(arg, &da, sizeof(da))) |
| 1379 | return -XFS_ERROR(EFAULT); |
| 1380 | return 0; |
| 1381 | } |
| 1382 | |
| 1383 | case XFS_IOC_FSBULKSTAT_SINGLE: |
| 1384 | case XFS_IOC_FSBULKSTAT: |
| 1385 | case XFS_IOC_FSINUMBERS: |
| 1386 | return xfs_ioc_bulkstat(mp, cmd, arg); |
| 1387 | |
| 1388 | case XFS_IOC_FSGEOMETRY_V1: |
| 1389 | return xfs_ioc_fsgeometry_v1(mp, arg); |
| 1390 | |
| 1391 | case XFS_IOC_FSGEOMETRY: |
| 1392 | return xfs_ioc_fsgeometry(mp, arg); |
| 1393 | |
| 1394 | case XFS_IOC_GETVERSION: |
| 1395 | return put_user(inode->i_generation, (int __user *)arg); |
| 1396 | |
| 1397 | case XFS_IOC_FSGETXATTR: |
| 1398 | return xfs_ioc_fsgetxattr(ip, 0, arg); |
| 1399 | case XFS_IOC_FSGETXATTRA: |
| 1400 | return xfs_ioc_fsgetxattr(ip, 1, arg); |
| 1401 | case XFS_IOC_FSSETXATTR: |
| 1402 | return xfs_ioc_fssetxattr(ip, filp, arg); |
| 1403 | case XFS_IOC_GETXFLAGS: |
| 1404 | return xfs_ioc_getxflags(ip, arg); |
| 1405 | case XFS_IOC_SETXFLAGS: |
| 1406 | return xfs_ioc_setxflags(ip, filp, arg); |
| 1407 | |
| 1408 | case XFS_IOC_FSSETDM: { |
| 1409 | struct fsdmidata dmi; |
| 1410 | |
| 1411 | if (copy_from_user(&dmi, arg, sizeof(dmi))) |
| 1412 | return -XFS_ERROR(EFAULT); |
| 1413 | |
| 1414 | error = xfs_set_dmattrs(ip, dmi.fsd_dmevmask, |
| 1415 | dmi.fsd_dmstate); |
| 1416 | return -error; |
| 1417 | } |
| 1418 | |
| 1419 | case XFS_IOC_GETBMAP: |
| 1420 | case XFS_IOC_GETBMAPA: |
| 1421 | return xfs_ioc_getbmap(ip, ioflags, cmd, arg); |
| 1422 | |
| 1423 | case XFS_IOC_GETBMAPX: |
| 1424 | return xfs_ioc_getbmapx(ip, arg); |
| 1425 | |
| 1426 | case XFS_IOC_FD_TO_HANDLE: |
| 1427 | case XFS_IOC_PATH_TO_HANDLE: |
| 1428 | case XFS_IOC_PATH_TO_FSHANDLE: |
| 1429 | return xfs_find_handle(cmd, arg); |
| 1430 | |
| 1431 | case XFS_IOC_OPEN_BY_HANDLE: |
| 1432 | return xfs_open_by_handle(mp, arg, filp, inode); |
| 1433 | |
| 1434 | case XFS_IOC_FSSETDM_BY_HANDLE: |
| 1435 | return xfs_fssetdm_by_handle(mp, arg, inode); |
| 1436 | |
| 1437 | case XFS_IOC_READLINK_BY_HANDLE: |
| 1438 | return xfs_readlink_by_handle(mp, arg, inode); |
| 1439 | |
| 1440 | case XFS_IOC_ATTRLIST_BY_HANDLE: |
| 1441 | return xfs_attrlist_by_handle(mp, arg, inode); |
| 1442 | |
| 1443 | case XFS_IOC_ATTRMULTI_BY_HANDLE: |
| 1444 | return xfs_attrmulti_by_handle(mp, arg, inode); |
| 1445 | |
| 1446 | case XFS_IOC_SWAPEXT: { |
| 1447 | error = xfs_swapext((struct xfs_swapext __user *)arg); |
| 1448 | return -error; |
| 1449 | } |
| 1450 | |
| 1451 | case XFS_IOC_FSCOUNTS: { |
| 1452 | xfs_fsop_counts_t out; |
| 1453 | |
| 1454 | error = xfs_fs_counts(mp, &out); |
| 1455 | if (error) |
| 1456 | return -error; |
| 1457 | |
| 1458 | if (copy_to_user(arg, &out, sizeof(out))) |
| 1459 | return -XFS_ERROR(EFAULT); |
| 1460 | return 0; |
| 1461 | } |
| 1462 | |
| 1463 | case XFS_IOC_SET_RESBLKS: { |
| 1464 | xfs_fsop_resblks_t inout; |
| 1465 | __uint64_t in; |
| 1466 | |
| 1467 | if (!capable(CAP_SYS_ADMIN)) |
| 1468 | return -EPERM; |
| 1469 | |
| 1470 | if (copy_from_user(&inout, arg, sizeof(inout))) |
| 1471 | return -XFS_ERROR(EFAULT); |
| 1472 | |
| 1473 | /* input parameter is passed in resblks field of structure */ |
| 1474 | in = inout.resblks; |
| 1475 | error = xfs_reserve_blocks(mp, &in, &inout); |
| 1476 | if (error) |
| 1477 | return -error; |
| 1478 | |
| 1479 | if (copy_to_user(arg, &inout, sizeof(inout))) |
| 1480 | return -XFS_ERROR(EFAULT); |
| 1481 | return 0; |
| 1482 | } |
| 1483 | |
| 1484 | case XFS_IOC_GET_RESBLKS: { |
| 1485 | xfs_fsop_resblks_t out; |
| 1486 | |
| 1487 | if (!capable(CAP_SYS_ADMIN)) |
| 1488 | return -EPERM; |
| 1489 | |
| 1490 | error = xfs_reserve_blocks(mp, NULL, &out); |
| 1491 | if (error) |
| 1492 | return -error; |
| 1493 | |
| 1494 | if (copy_to_user(arg, &out, sizeof(out))) |
| 1495 | return -XFS_ERROR(EFAULT); |
| 1496 | |
| 1497 | return 0; |
| 1498 | } |
| 1499 | |
| 1500 | case XFS_IOC_FSGROWFSDATA: { |
| 1501 | xfs_growfs_data_t in; |
| 1502 | |
| 1503 | if (!capable(CAP_SYS_ADMIN)) |
| 1504 | return -EPERM; |
| 1505 | |
| 1506 | if (copy_from_user(&in, arg, sizeof(in))) |
| 1507 | return -XFS_ERROR(EFAULT); |
| 1508 | |
| 1509 | error = xfs_growfs_data(mp, &in); |
| 1510 | return -error; |
| 1511 | } |
| 1512 | |
| 1513 | case XFS_IOC_FSGROWFSLOG: { |
| 1514 | xfs_growfs_log_t in; |
| 1515 | |
| 1516 | if (!capable(CAP_SYS_ADMIN)) |
| 1517 | return -EPERM; |
| 1518 | |
| 1519 | if (copy_from_user(&in, arg, sizeof(in))) |
| 1520 | return -XFS_ERROR(EFAULT); |
| 1521 | |
| 1522 | error = xfs_growfs_log(mp, &in); |
| 1523 | return -error; |
| 1524 | } |
| 1525 | |
| 1526 | case XFS_IOC_FSGROWFSRT: { |
| 1527 | xfs_growfs_rt_t in; |
| 1528 | |
| 1529 | if (!capable(CAP_SYS_ADMIN)) |
| 1530 | return -EPERM; |
| 1531 | |
| 1532 | if (copy_from_user(&in, arg, sizeof(in))) |
| 1533 | return -XFS_ERROR(EFAULT); |
| 1534 | |
| 1535 | error = xfs_growfs_rt(mp, &in); |
| 1536 | return -error; |
| 1537 | } |
| 1538 | |
| 1539 | case XFS_IOC_FREEZE: |
| 1540 | if (!capable(CAP_SYS_ADMIN)) |
| 1541 | return -EPERM; |
| 1542 | |
| 1543 | if (inode->i_sb->s_frozen == SB_UNFROZEN) |
| 1544 | freeze_bdev(inode->i_sb->s_bdev); |
| 1545 | return 0; |
| 1546 | |
| 1547 | case XFS_IOC_THAW: |
| 1548 | if (!capable(CAP_SYS_ADMIN)) |
| 1549 | return -EPERM; |
| 1550 | if (inode->i_sb->s_frozen != SB_UNFROZEN) |
| 1551 | thaw_bdev(inode->i_sb->s_bdev, inode->i_sb); |
| 1552 | return 0; |
| 1553 | |
| 1554 | case XFS_IOC_GOINGDOWN: { |
| 1555 | __uint32_t in; |
| 1556 | |
| 1557 | if (!capable(CAP_SYS_ADMIN)) |
| 1558 | return -EPERM; |
| 1559 | |
| 1560 | if (get_user(in, (__uint32_t __user *)arg)) |
| 1561 | return -XFS_ERROR(EFAULT); |
| 1562 | |
| 1563 | error = xfs_fs_goingdown(mp, in); |
| 1564 | return -error; |
| 1565 | } |
| 1566 | |
| 1567 | case XFS_IOC_ERROR_INJECTION: { |
| 1568 | xfs_error_injection_t in; |
| 1569 | |
| 1570 | if (!capable(CAP_SYS_ADMIN)) |
| 1571 | return -EPERM; |
| 1572 | |
| 1573 | if (copy_from_user(&in, arg, sizeof(in))) |
| 1574 | return -XFS_ERROR(EFAULT); |
| 1575 | |
| 1576 | error = xfs_errortag_add(in.errtag, mp); |
| 1577 | return -error; |
| 1578 | } |
| 1579 | |
| 1580 | case XFS_IOC_ERROR_CLEARALL: |
| 1581 | if (!capable(CAP_SYS_ADMIN)) |
| 1582 | return -EPERM; |
| 1583 | |
| 1584 | error = xfs_errortag_clearall(mp, 1); |
| 1585 | return -error; |
| 1586 | |
| 1587 | default: |
| 1588 | return -ENOTTY; |
| 1589 | } |
| 1590 | } |