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 | 993386c | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 50 | #include "xfs_vnodeops.h" |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 51 | #include "xfs_quota.h" |
| 52 | #include "xfs_inode_item.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 54 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include <linux/dcache.h> |
| 56 | #include <linux/mount.h> |
| 57 | #include <linux/namei.h> |
| 58 | #include <linux/pagemap.h> |
| 59 | |
| 60 | /* |
| 61 | * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to |
| 62 | * a file or fs handle. |
| 63 | * |
| 64 | * XFS_IOC_PATH_TO_FSHANDLE |
| 65 | * returns fs handle for a mount point or path within that mount point |
| 66 | * XFS_IOC_FD_TO_HANDLE |
| 67 | * returns full handle for a FD opened in user space |
| 68 | * XFS_IOC_PATH_TO_HANDLE |
| 69 | * returns full handle for a path |
| 70 | */ |
| 71 | STATIC int |
| 72 | xfs_find_handle( |
| 73 | unsigned int cmd, |
| 74 | void __user *arg) |
| 75 | { |
| 76 | int hsize; |
| 77 | xfs_handle_t handle; |
| 78 | xfs_fsop_handlereq_t hreq; |
| 79 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | if (copy_from_user(&hreq, arg, sizeof(hreq))) |
| 82 | return -XFS_ERROR(EFAULT); |
| 83 | |
| 84 | memset((char *)&handle, 0, sizeof(handle)); |
| 85 | |
| 86 | switch (cmd) { |
| 87 | case XFS_IOC_PATH_TO_FSHANDLE: |
| 88 | case XFS_IOC_PATH_TO_HANDLE: { |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 89 | struct path path; |
| 90 | int error = user_lpath((const char __user *)hreq.path, &path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | if (error) |
| 92 | return error; |
| 93 | |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 94 | ASSERT(path.dentry); |
| 95 | ASSERT(path.dentry->d_inode); |
| 96 | inode = igrab(path.dentry->d_inode); |
| 97 | path_put(&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); |
Christoph Hellwig | 6a7f422 | 2008-04-22 17:33:40 +1000 | [diff] [blame] | 241 | if (ip->i_d.di_gen != igen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
David Chinner | e4f7529 | 2008-08-13 16:00:45 +1000 | [diff] [blame] | 248 | *inode = VFS_I(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 | |
Christoph Hellwig | 4400372 | 2008-08-11 15:49:04 +0200 | [diff] [blame] | 314 | dentry = d_obtain_alias(inode); |
| 315 | if (IS_ERR(dentry)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | put_unused_fd(new_fd); |
Christoph Hellwig | 4400372 | 2008-08-11 15:49:04 +0200 | [diff] [blame] | 317 | return PTR_ERR(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /* Ensure umount returns EBUSY on umounts while this file is open. */ |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 321 | mntget(parfilp->f_path.mnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | /* Create file pointer. */ |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 324 | filp = dentry_open(dentry, parfilp->f_path.mnt, hreq.oflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | if (IS_ERR(filp)) { |
| 326 | put_unused_fd(new_fd); |
| 327 | return -XFS_ERROR(-PTR_ERR(filp)); |
| 328 | } |
Vlad Apostolov | 2e2e7bb | 2006-11-11 18:04:47 +1100 | [diff] [blame] | 329 | if (inode->i_mode & S_IFREG) { |
| 330 | /* invisible operation should not change atime */ |
| 331 | filp->f_flags |= O_NOATIME; |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 332 | filp->f_op = &xfs_invis_file_operations; |
Vlad Apostolov | 2e2e7bb | 2006-11-11 18:04:47 +1100 | [diff] [blame] | 333 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
| 335 | fd_install(new_fd, filp); |
| 336 | return new_fd; |
| 337 | } |
| 338 | |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 339 | /* |
| 340 | * This is a copy from fs/namei.c:vfs_readlink(), except for removing it's |
| 341 | * unused first argument. |
| 342 | */ |
| 343 | STATIC int |
| 344 | do_readlink( |
| 345 | char __user *buffer, |
| 346 | int buflen, |
| 347 | const char *link) |
| 348 | { |
| 349 | int len; |
| 350 | |
| 351 | len = PTR_ERR(link); |
| 352 | if (IS_ERR(link)) |
| 353 | goto out; |
| 354 | |
| 355 | len = strlen(link); |
| 356 | if (len > (unsigned) buflen) |
| 357 | len = buflen; |
| 358 | if (copy_to_user(buffer, link, len)) |
| 359 | len = -EFAULT; |
| 360 | out: |
| 361 | return len; |
| 362 | } |
| 363 | |
| 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | STATIC int |
| 366 | xfs_readlink_by_handle( |
| 367 | xfs_mount_t *mp, |
| 368 | void __user *arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | struct inode *parinode) |
| 370 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | struct inode *inode; |
| 372 | xfs_fsop_handlereq_t hreq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | __u32 olen; |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 374 | void *link; |
| 375 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
| 377 | if (!capable(CAP_SYS_ADMIN)) |
| 378 | return -XFS_ERROR(EPERM); |
| 379 | if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t))) |
| 380 | return -XFS_ERROR(EFAULT); |
| 381 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 382 | error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | if (error) |
| 384 | return -error; |
| 385 | |
| 386 | /* Restrict this handle operation to symlinks only. */ |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 387 | if (!S_ISLNK(inode->i_mode)) { |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 388 | error = -XFS_ERROR(EINVAL); |
| 389 | goto out_iput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | if (copy_from_user(&olen, hreq.ohandlen, sizeof(__u32))) { |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 393 | error = -XFS_ERROR(EFAULT); |
| 394 | goto out_iput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 397 | link = kmalloc(MAXPATHLEN+1, GFP_KERNEL); |
| 398 | if (!link) |
| 399 | goto out_iput; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 401 | error = -xfs_readlink(XFS_I(inode), link); |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 402 | if (error) |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 403 | goto out_kfree; |
| 404 | error = do_readlink(hreq.ohandle, olen, link); |
| 405 | if (error) |
| 406 | goto out_kfree; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 407 | |
Christoph Hellwig | 804c83c | 2007-08-28 13:59:03 +1000 | [diff] [blame] | 408 | out_kfree: |
| 409 | kfree(link); |
| 410 | out_iput: |
| 411 | iput(inode); |
| 412 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | STATIC int |
| 416 | xfs_fssetdm_by_handle( |
| 417 | xfs_mount_t *mp, |
| 418 | void __user *arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | struct inode *parinode) |
| 420 | { |
| 421 | int error; |
| 422 | struct fsdmidata fsd; |
| 423 | xfs_fsop_setdm_handlereq_t dmhreq; |
| 424 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
| 426 | if (!capable(CAP_MKNOD)) |
| 427 | return -XFS_ERROR(EPERM); |
| 428 | if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t))) |
| 429 | return -XFS_ERROR(EFAULT); |
| 430 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 431 | error = xfs_vget_fsop_handlereq(mp, parinode, &dmhreq.hreq, &inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | if (error) |
| 433 | return -error; |
| 434 | |
| 435 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) { |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 436 | error = -XFS_ERROR(EPERM); |
| 437 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) { |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 441 | error = -XFS_ERROR(EFAULT); |
| 442 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 445 | error = -xfs_set_dmattrs(XFS_I(inode), fsd.fsd_dmevmask, |
| 446 | fsd.fsd_dmstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 448 | out: |
| 449 | iput(inode); |
| 450 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | STATIC int |
| 454 | xfs_attrlist_by_handle( |
| 455 | xfs_mount_t *mp, |
| 456 | void __user *arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | struct inode *parinode) |
| 458 | { |
| 459 | int error; |
| 460 | attrlist_cursor_kern_t *cursor; |
| 461 | xfs_fsop_attrlist_handlereq_t al_hreq; |
| 462 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | char *kbuf; |
| 464 | |
| 465 | if (!capable(CAP_SYS_ADMIN)) |
| 466 | return -XFS_ERROR(EPERM); |
| 467 | if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t))) |
| 468 | return -XFS_ERROR(EFAULT); |
| 469 | if (al_hreq.buflen > XATTR_LIST_MAX) |
| 470 | return -XFS_ERROR(EINVAL); |
| 471 | |
Christoph Hellwig | 90ad58a | 2008-06-27 13:32:19 +1000 | [diff] [blame] | 472 | /* |
| 473 | * Reject flags, only allow namespaces. |
| 474 | */ |
| 475 | if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE)) |
| 476 | return -XFS_ERROR(EINVAL); |
| 477 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 478 | error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq, &inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | if (error) |
| 480 | goto out; |
| 481 | |
| 482 | kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL); |
| 483 | if (!kbuf) |
| 484 | goto out_vn_rele; |
| 485 | |
| 486 | cursor = (attrlist_cursor_kern_t *)&al_hreq.pos; |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 487 | error = xfs_attr_list(XFS_I(inode), kbuf, al_hreq.buflen, |
| 488 | al_hreq.flags, cursor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | if (error) |
| 490 | goto out_kfree; |
| 491 | |
| 492 | if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen)) |
| 493 | error = -EFAULT; |
| 494 | |
| 495 | out_kfree: |
| 496 | kfree(kbuf); |
| 497 | out_vn_rele: |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 498 | iput(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | out: |
| 500 | return -error; |
| 501 | } |
| 502 | |
| 503 | STATIC int |
| 504 | xfs_attrmulti_attr_get( |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 505 | struct inode *inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | char *name, |
| 507 | char __user *ubuf, |
| 508 | __uint32_t *len, |
| 509 | __uint32_t flags) |
| 510 | { |
| 511 | char *kbuf; |
| 512 | int error = EFAULT; |
Barry Naujok | e8b0eba | 2008-04-22 17:34:31 +1000 | [diff] [blame] | 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | if (*len > XATTR_SIZE_MAX) |
| 515 | return EINVAL; |
| 516 | kbuf = kmalloc(*len, GFP_KERNEL); |
| 517 | if (!kbuf) |
| 518 | return ENOMEM; |
| 519 | |
Barry Naujok | e8b0eba | 2008-04-22 17:34:31 +1000 | [diff] [blame] | 520 | error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | if (error) |
| 522 | goto out_kfree; |
| 523 | |
| 524 | if (copy_to_user(ubuf, kbuf, *len)) |
| 525 | error = EFAULT; |
| 526 | |
| 527 | out_kfree: |
| 528 | kfree(kbuf); |
| 529 | return error; |
| 530 | } |
| 531 | |
| 532 | STATIC int |
| 533 | xfs_attrmulti_attr_set( |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 534 | struct inode *inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | char *name, |
| 536 | const char __user *ubuf, |
| 537 | __uint32_t len, |
| 538 | __uint32_t flags) |
| 539 | { |
| 540 | char *kbuf; |
| 541 | int error = EFAULT; |
| 542 | |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 543 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | return EPERM; |
| 545 | if (len > XATTR_SIZE_MAX) |
| 546 | return EINVAL; |
| 547 | |
| 548 | kbuf = kmalloc(len, GFP_KERNEL); |
| 549 | if (!kbuf) |
| 550 | return ENOMEM; |
| 551 | |
| 552 | if (copy_from_user(kbuf, ubuf, len)) |
| 553 | goto out_kfree; |
Barry Naujok | e8b0eba | 2008-04-22 17:34:31 +1000 | [diff] [blame] | 554 | |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 555 | error = xfs_attr_set(XFS_I(inode), name, kbuf, len, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| 557 | out_kfree: |
| 558 | kfree(kbuf); |
| 559 | return error; |
| 560 | } |
| 561 | |
| 562 | STATIC int |
| 563 | xfs_attrmulti_attr_remove( |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 564 | struct inode *inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | char *name, |
| 566 | __uint32_t flags) |
| 567 | { |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 568 | if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | return EPERM; |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 570 | return xfs_attr_remove(XFS_I(inode), name, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | STATIC int |
| 574 | xfs_attrmulti_by_handle( |
| 575 | xfs_mount_t *mp, |
| 576 | void __user *arg, |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 577 | struct file *parfilp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | struct inode *parinode) |
| 579 | { |
| 580 | int error; |
| 581 | xfs_attr_multiop_t *ops; |
| 582 | xfs_fsop_attrmulti_handlereq_t am_hreq; |
| 583 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | unsigned int i, size; |
| 585 | char *attr_name; |
| 586 | |
| 587 | if (!capable(CAP_SYS_ADMIN)) |
| 588 | return -XFS_ERROR(EPERM); |
| 589 | if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t))) |
| 590 | return -XFS_ERROR(EFAULT); |
| 591 | |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 592 | error = xfs_vget_fsop_handlereq(mp, parinode, &am_hreq.hreq, &inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | if (error) |
| 594 | goto out; |
| 595 | |
| 596 | error = E2BIG; |
Christoph Hellwig | e182f57 | 2008-06-27 13:32:31 +1000 | [diff] [blame] | 597 | size = am_hreq.opcount * sizeof(xfs_attr_multiop_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | if (!size || size > 16 * PAGE_SIZE) |
| 599 | goto out_vn_rele; |
| 600 | |
| 601 | error = ENOMEM; |
| 602 | ops = kmalloc(size, GFP_KERNEL); |
| 603 | if (!ops) |
| 604 | goto out_vn_rele; |
| 605 | |
| 606 | error = EFAULT; |
| 607 | if (copy_from_user(ops, am_hreq.ops, size)) |
| 608 | goto out_kfree_ops; |
| 609 | |
| 610 | attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL); |
| 611 | if (!attr_name) |
| 612 | goto out_kfree_ops; |
| 613 | |
| 614 | |
| 615 | error = 0; |
| 616 | for (i = 0; i < am_hreq.opcount; i++) { |
| 617 | ops[i].am_error = strncpy_from_user(attr_name, |
| 618 | ops[i].am_attrname, MAXNAMELEN); |
| 619 | if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN) |
| 620 | error = -ERANGE; |
| 621 | if (ops[i].am_error < 0) |
| 622 | break; |
| 623 | |
| 624 | switch (ops[i].am_opcode) { |
| 625 | case ATTR_OP_GET: |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 626 | ops[i].am_error = xfs_attrmulti_attr_get(inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | attr_name, ops[i].am_attrvalue, |
| 628 | &ops[i].am_length, ops[i].am_flags); |
| 629 | break; |
| 630 | case ATTR_OP_SET: |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 631 | ops[i].am_error = mnt_want_write(parfilp->f_path.mnt); |
| 632 | if (ops[i].am_error) |
| 633 | break; |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 634 | ops[i].am_error = xfs_attrmulti_attr_set(inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | attr_name, ops[i].am_attrvalue, |
| 636 | ops[i].am_length, ops[i].am_flags); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 637 | mnt_drop_write(parfilp->f_path.mnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | break; |
| 639 | case ATTR_OP_REMOVE: |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 640 | ops[i].am_error = mnt_want_write(parfilp->f_path.mnt); |
| 641 | if (ops[i].am_error) |
| 642 | break; |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 643 | ops[i].am_error = xfs_attrmulti_attr_remove(inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | attr_name, ops[i].am_flags); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 645 | mnt_drop_write(parfilp->f_path.mnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | break; |
| 647 | default: |
| 648 | ops[i].am_error = EINVAL; |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | if (copy_to_user(am_hreq.ops, ops, size)) |
| 653 | error = XFS_ERROR(EFAULT); |
| 654 | |
| 655 | kfree(attr_name); |
| 656 | out_kfree_ops: |
| 657 | kfree(ops); |
| 658 | out_vn_rele: |
Christoph Hellwig | 6e7f75e | 2007-10-11 18:09:50 +1000 | [diff] [blame] | 659 | iput(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | out: |
| 661 | return -error; |
| 662 | } |
| 663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | STATIC int |
| 665 | xfs_ioc_space( |
Christoph Hellwig | 993386c | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 666 | struct xfs_inode *ip, |
Alexey Dobriyan | f37ea14 | 2006-09-28 10:52:04 +1000 | [diff] [blame] | 667 | struct inode *inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | struct file *filp, |
| 669 | int ioflags, |
| 670 | unsigned int cmd, |
| 671 | void __user *arg) |
| 672 | { |
| 673 | xfs_flock64_t bf; |
| 674 | int attr_flags = 0; |
| 675 | int error; |
| 676 | |
Alexey Dobriyan | f37ea14 | 2006-09-28 10:52:04 +1000 | [diff] [blame] | 677 | if (inode->i_flags & (S_IMMUTABLE|S_APPEND)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | return -XFS_ERROR(EPERM); |
| 679 | |
Eric Sandeen | ad4a8ac | 2005-09-02 16:41:16 +1000 | [diff] [blame] | 680 | if (!(filp->f_mode & FMODE_WRITE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | return -XFS_ERROR(EBADF); |
| 682 | |
Alexey Dobriyan | f37ea14 | 2006-09-28 10:52:04 +1000 | [diff] [blame] | 683 | if (!S_ISREG(inode->i_mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | return -XFS_ERROR(EINVAL); |
| 685 | |
| 686 | if (copy_from_user(&bf, arg, sizeof(bf))) |
| 687 | return -XFS_ERROR(EFAULT); |
| 688 | |
| 689 | if (filp->f_flags & (O_NDELAY|O_NONBLOCK)) |
Christoph Hellwig | 0f285c8 | 2008-07-18 17:13:28 +1000 | [diff] [blame] | 690 | attr_flags |= XFS_ATTR_NONBLOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | if (ioflags & IO_INVIS) |
Christoph Hellwig | 0f285c8 | 2008-07-18 17:13:28 +1000 | [diff] [blame] | 692 | attr_flags |= XFS_ATTR_DMI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Christoph Hellwig | ea5a3dc8 | 2008-10-30 18:27:48 +1100 | [diff] [blame] | 694 | error = xfs_change_file_space(ip, cmd, &bf, filp->f_pos, attr_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | return -error; |
| 696 | } |
| 697 | |
| 698 | STATIC int |
| 699 | xfs_ioc_bulkstat( |
| 700 | xfs_mount_t *mp, |
| 701 | unsigned int cmd, |
| 702 | void __user *arg) |
| 703 | { |
| 704 | xfs_fsop_bulkreq_t bulkreq; |
| 705 | int count; /* # of records returned */ |
| 706 | xfs_ino_t inlast; /* last inode number */ |
| 707 | int done; |
| 708 | int error; |
| 709 | |
| 710 | /* done = 1 if there are more stats to get and if bulkstat */ |
| 711 | /* should be called again (unused here, but used in dmapi) */ |
| 712 | |
| 713 | if (!capable(CAP_SYS_ADMIN)) |
| 714 | return -EPERM; |
| 715 | |
| 716 | if (XFS_FORCED_SHUTDOWN(mp)) |
| 717 | return -XFS_ERROR(EIO); |
| 718 | |
| 719 | if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t))) |
| 720 | return -XFS_ERROR(EFAULT); |
| 721 | |
| 722 | if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64))) |
| 723 | return -XFS_ERROR(EFAULT); |
| 724 | |
| 725 | if ((count = bulkreq.icount) <= 0) |
| 726 | return -XFS_ERROR(EINVAL); |
| 727 | |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 728 | if (bulkreq.ubuffer == NULL) |
| 729 | return -XFS_ERROR(EINVAL); |
| 730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | if (cmd == XFS_IOC_FSINUMBERS) |
| 732 | error = xfs_inumbers(mp, &inlast, &count, |
Michal Marek | faa63e9 | 2007-07-11 11:10:19 +1000 | [diff] [blame] | 733 | bulkreq.ubuffer, xfs_inumbers_fmt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE) |
| 735 | error = xfs_bulkstat_single(mp, &inlast, |
| 736 | bulkreq.ubuffer, &done); |
Lachlan McIlroy | cd57e59 | 2007-11-23 16:30:32 +1100 | [diff] [blame] | 737 | else /* XFS_IOC_FSBULKSTAT */ |
| 738 | error = xfs_bulkstat(mp, &inlast, &count, |
| 739 | (bulkstat_one_pf)xfs_bulkstat_one, NULL, |
| 740 | sizeof(xfs_bstat_t), bulkreq.ubuffer, |
| 741 | BULKSTAT_FG_QUICK, &done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
| 743 | if (error) |
| 744 | return -error; |
| 745 | |
| 746 | if (bulkreq.ocount != NULL) { |
| 747 | if (copy_to_user(bulkreq.lastip, &inlast, |
| 748 | sizeof(xfs_ino_t))) |
| 749 | return -XFS_ERROR(EFAULT); |
| 750 | |
| 751 | if (copy_to_user(bulkreq.ocount, &count, sizeof(count))) |
| 752 | return -XFS_ERROR(EFAULT); |
| 753 | } |
| 754 | |
| 755 | return 0; |
| 756 | } |
| 757 | |
| 758 | STATIC int |
| 759 | xfs_ioc_fsgeometry_v1( |
| 760 | xfs_mount_t *mp, |
| 761 | void __user *arg) |
| 762 | { |
| 763 | xfs_fsop_geom_v1_t fsgeo; |
| 764 | int error; |
| 765 | |
| 766 | error = xfs_fs_geometry(mp, (xfs_fsop_geom_t *)&fsgeo, 3); |
| 767 | if (error) |
| 768 | return -error; |
| 769 | |
| 770 | if (copy_to_user(arg, &fsgeo, sizeof(fsgeo))) |
| 771 | return -XFS_ERROR(EFAULT); |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | STATIC int |
| 776 | xfs_ioc_fsgeometry( |
| 777 | xfs_mount_t *mp, |
| 778 | void __user *arg) |
| 779 | { |
| 780 | xfs_fsop_geom_t fsgeo; |
| 781 | int error; |
| 782 | |
| 783 | error = xfs_fs_geometry(mp, &fsgeo, 4); |
| 784 | if (error) |
| 785 | return -error; |
| 786 | |
| 787 | if (copy_to_user(arg, &fsgeo, sizeof(fsgeo))) |
| 788 | return -XFS_ERROR(EFAULT); |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | /* |
| 793 | * Linux extended inode flags interface. |
| 794 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | STATIC unsigned int |
| 797 | xfs_merge_ioc_xflags( |
| 798 | unsigned int flags, |
| 799 | unsigned int start) |
| 800 | { |
| 801 | unsigned int xflags = start; |
| 802 | |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 803 | if (flags & FS_IMMUTABLE_FL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | xflags |= XFS_XFLAG_IMMUTABLE; |
| 805 | else |
| 806 | xflags &= ~XFS_XFLAG_IMMUTABLE; |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 807 | if (flags & FS_APPEND_FL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | xflags |= XFS_XFLAG_APPEND; |
| 809 | else |
| 810 | xflags &= ~XFS_XFLAG_APPEND; |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 811 | if (flags & FS_SYNC_FL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | xflags |= XFS_XFLAG_SYNC; |
| 813 | else |
| 814 | xflags &= ~XFS_XFLAG_SYNC; |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 815 | if (flags & FS_NOATIME_FL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | xflags |= XFS_XFLAG_NOATIME; |
| 817 | else |
| 818 | xflags &= ~XFS_XFLAG_NOATIME; |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 819 | if (flags & FS_NODUMP_FL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | xflags |= XFS_XFLAG_NODUMP; |
| 821 | else |
| 822 | xflags &= ~XFS_XFLAG_NODUMP; |
| 823 | |
| 824 | return xflags; |
| 825 | } |
| 826 | |
| 827 | STATIC unsigned int |
| 828 | xfs_di2lxflags( |
| 829 | __uint16_t di_flags) |
| 830 | { |
| 831 | unsigned int flags = 0; |
| 832 | |
| 833 | if (di_flags & XFS_DIFLAG_IMMUTABLE) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 834 | flags |= FS_IMMUTABLE_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | if (di_flags & XFS_DIFLAG_APPEND) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 836 | flags |= FS_APPEND_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | if (di_flags & XFS_DIFLAG_SYNC) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 838 | flags |= FS_SYNC_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | if (di_flags & XFS_DIFLAG_NOATIME) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 840 | flags |= FS_NOATIME_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | if (di_flags & XFS_DIFLAG_NODUMP) |
Eric Sandeen | 39058a0 | 2007-02-10 18:37:10 +1100 | [diff] [blame] | 842 | flags |= FS_NODUMP_FL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | return flags; |
| 844 | } |
| 845 | |
| 846 | STATIC int |
Christoph Hellwig | c83bfab | 2007-10-11 17:47:00 +1000 | [diff] [blame] | 847 | xfs_ioc_fsgetxattr( |
| 848 | xfs_inode_t *ip, |
| 849 | int attr, |
| 850 | void __user *arg) |
| 851 | { |
| 852 | struct fsxattr fa; |
| 853 | |
| 854 | xfs_ilock(ip, XFS_ILOCK_SHARED); |
| 855 | fa.fsx_xflags = xfs_ip2xflags(ip); |
| 856 | fa.fsx_extsize = ip->i_d.di_extsize << ip->i_mount->m_sb.sb_blocklog; |
| 857 | fa.fsx_projid = ip->i_d.di_projid; |
| 858 | |
| 859 | if (attr) { |
| 860 | if (ip->i_afp) { |
| 861 | if (ip->i_afp->if_flags & XFS_IFEXTENTS) |
| 862 | fa.fsx_nextents = ip->i_afp->if_bytes / |
| 863 | sizeof(xfs_bmbt_rec_t); |
| 864 | else |
| 865 | fa.fsx_nextents = ip->i_d.di_anextents; |
| 866 | } else |
| 867 | fa.fsx_nextents = 0; |
| 868 | } else { |
| 869 | if (ip->i_df.if_flags & XFS_IFEXTENTS) |
| 870 | fa.fsx_nextents = ip->i_df.if_bytes / |
| 871 | sizeof(xfs_bmbt_rec_t); |
| 872 | else |
| 873 | fa.fsx_nextents = ip->i_d.di_nextents; |
| 874 | } |
| 875 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
| 876 | |
| 877 | if (copy_to_user(arg, &fa, sizeof(fa))) |
| 878 | return -EFAULT; |
| 879 | return 0; |
| 880 | } |
| 881 | |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 882 | STATIC void |
| 883 | xfs_set_diflags( |
| 884 | struct xfs_inode *ip, |
| 885 | unsigned int xflags) |
| 886 | { |
| 887 | unsigned int di_flags; |
| 888 | |
| 889 | /* can't set PREALLOC this way, just preserve it */ |
| 890 | di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC); |
| 891 | if (xflags & XFS_XFLAG_IMMUTABLE) |
| 892 | di_flags |= XFS_DIFLAG_IMMUTABLE; |
| 893 | if (xflags & XFS_XFLAG_APPEND) |
| 894 | di_flags |= XFS_DIFLAG_APPEND; |
| 895 | if (xflags & XFS_XFLAG_SYNC) |
| 896 | di_flags |= XFS_DIFLAG_SYNC; |
| 897 | if (xflags & XFS_XFLAG_NOATIME) |
| 898 | di_flags |= XFS_DIFLAG_NOATIME; |
| 899 | if (xflags & XFS_XFLAG_NODUMP) |
| 900 | di_flags |= XFS_DIFLAG_NODUMP; |
| 901 | if (xflags & XFS_XFLAG_PROJINHERIT) |
| 902 | di_flags |= XFS_DIFLAG_PROJINHERIT; |
| 903 | if (xflags & XFS_XFLAG_NODEFRAG) |
| 904 | di_flags |= XFS_DIFLAG_NODEFRAG; |
| 905 | if (xflags & XFS_XFLAG_FILESTREAM) |
| 906 | di_flags |= XFS_DIFLAG_FILESTREAM; |
| 907 | if ((ip->i_d.di_mode & S_IFMT) == S_IFDIR) { |
| 908 | if (xflags & XFS_XFLAG_RTINHERIT) |
| 909 | di_flags |= XFS_DIFLAG_RTINHERIT; |
| 910 | if (xflags & XFS_XFLAG_NOSYMLINKS) |
| 911 | di_flags |= XFS_DIFLAG_NOSYMLINKS; |
| 912 | if (xflags & XFS_XFLAG_EXTSZINHERIT) |
| 913 | di_flags |= XFS_DIFLAG_EXTSZINHERIT; |
| 914 | } else if ((ip->i_d.di_mode & S_IFMT) == S_IFREG) { |
| 915 | if (xflags & XFS_XFLAG_REALTIME) |
| 916 | di_flags |= XFS_DIFLAG_REALTIME; |
| 917 | if (xflags & XFS_XFLAG_EXTSIZE) |
| 918 | di_flags |= XFS_DIFLAG_EXTSIZE; |
| 919 | } |
| 920 | |
| 921 | ip->i_d.di_flags = di_flags; |
| 922 | } |
| 923 | |
Christoph Hellwig | f13fae2 | 2008-07-21 16:16:15 +1000 | [diff] [blame] | 924 | STATIC void |
| 925 | xfs_diflags_to_linux( |
| 926 | struct xfs_inode *ip) |
| 927 | { |
David Chinner | e4f7529 | 2008-08-13 16:00:45 +1000 | [diff] [blame] | 928 | struct inode *inode = VFS_I(ip); |
Christoph Hellwig | f13fae2 | 2008-07-21 16:16:15 +1000 | [diff] [blame] | 929 | unsigned int xflags = xfs_ip2xflags(ip); |
| 930 | |
| 931 | if (xflags & XFS_XFLAG_IMMUTABLE) |
| 932 | inode->i_flags |= S_IMMUTABLE; |
| 933 | else |
| 934 | inode->i_flags &= ~S_IMMUTABLE; |
| 935 | if (xflags & XFS_XFLAG_APPEND) |
| 936 | inode->i_flags |= S_APPEND; |
| 937 | else |
| 938 | inode->i_flags &= ~S_APPEND; |
| 939 | if (xflags & XFS_XFLAG_SYNC) |
| 940 | inode->i_flags |= S_SYNC; |
| 941 | else |
| 942 | inode->i_flags &= ~S_SYNC; |
| 943 | if (xflags & XFS_XFLAG_NOATIME) |
| 944 | inode->i_flags |= S_NOATIME; |
| 945 | else |
| 946 | inode->i_flags &= ~S_NOATIME; |
| 947 | } |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 948 | |
| 949 | #define FSX_PROJID 1 |
| 950 | #define FSX_EXTSIZE 2 |
| 951 | #define FSX_XFLAGS 4 |
| 952 | #define FSX_NONBLOCK 8 |
| 953 | |
| 954 | STATIC int |
| 955 | xfs_ioctl_setattr( |
| 956 | xfs_inode_t *ip, |
| 957 | struct fsxattr *fa, |
| 958 | int mask) |
| 959 | { |
| 960 | struct xfs_mount *mp = ip->i_mount; |
| 961 | struct xfs_trans *tp; |
| 962 | unsigned int lock_flags = 0; |
| 963 | struct xfs_dquot *udqp = NULL, *gdqp = NULL; |
| 964 | struct xfs_dquot *olddquot = NULL; |
| 965 | int code; |
| 966 | |
| 967 | xfs_itrace_entry(ip); |
| 968 | |
| 969 | if (mp->m_flags & XFS_MOUNT_RDONLY) |
| 970 | return XFS_ERROR(EROFS); |
| 971 | if (XFS_FORCED_SHUTDOWN(mp)) |
| 972 | return XFS_ERROR(EIO); |
| 973 | |
| 974 | /* |
| 975 | * If disk quotas is on, we make sure that the dquots do exist on disk, |
| 976 | * before we start any other transactions. Trying to do this later |
| 977 | * is messy. We don't care to take a readlock to look at the ids |
| 978 | * in inode here, because we can't hold it across the trans_reserve. |
| 979 | * If the IDs do change before we take the ilock, we're covered |
| 980 | * because the i_*dquot fields will get updated anyway. |
| 981 | */ |
| 982 | if (XFS_IS_QUOTA_ON(mp) && (mask & FSX_PROJID)) { |
| 983 | code = XFS_QM_DQVOPALLOC(mp, ip, ip->i_d.di_uid, |
| 984 | ip->i_d.di_gid, fa->fsx_projid, |
| 985 | XFS_QMOPT_PQUOTA, &udqp, &gdqp); |
| 986 | if (code) |
| 987 | return code; |
| 988 | } |
| 989 | |
| 990 | /* |
| 991 | * For the other attributes, we acquire the inode lock and |
| 992 | * first do an error checking pass. |
| 993 | */ |
| 994 | tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE); |
| 995 | code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0); |
| 996 | if (code) |
| 997 | goto error_return; |
| 998 | |
| 999 | lock_flags = XFS_ILOCK_EXCL; |
| 1000 | xfs_ilock(ip, lock_flags); |
| 1001 | |
| 1002 | /* |
| 1003 | * CAP_FOWNER overrides the following restrictions: |
| 1004 | * |
| 1005 | * The user ID of the calling process must be equal |
| 1006 | * to the file owner ID, except in cases where the |
| 1007 | * CAP_FSETID capability is applicable. |
| 1008 | */ |
David Howells | 91b777125 | 2008-10-31 15:50:04 +1100 | [diff] [blame] | 1009 | if (current_fsuid() != ip->i_d.di_uid && !capable(CAP_FOWNER)) { |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1010 | code = XFS_ERROR(EPERM); |
| 1011 | goto error_return; |
| 1012 | } |
| 1013 | |
| 1014 | /* |
| 1015 | * Do a quota reservation only if projid is actually going to change. |
| 1016 | */ |
| 1017 | if (mask & FSX_PROJID) { |
| 1018 | if (XFS_IS_PQUOTA_ON(mp) && |
| 1019 | ip->i_d.di_projid != fa->fsx_projid) { |
| 1020 | ASSERT(tp); |
| 1021 | code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp, |
| 1022 | capable(CAP_FOWNER) ? |
| 1023 | XFS_QMOPT_FORCE_RES : 0); |
| 1024 | if (code) /* out of quota */ |
| 1025 | goto error_return; |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | if (mask & FSX_EXTSIZE) { |
| 1030 | /* |
| 1031 | * Can't change extent size if any extents are allocated. |
| 1032 | */ |
| 1033 | if (ip->i_d.di_nextents && |
| 1034 | ((ip->i_d.di_extsize << mp->m_sb.sb_blocklog) != |
| 1035 | fa->fsx_extsize)) { |
| 1036 | code = XFS_ERROR(EINVAL); /* EFBIG? */ |
| 1037 | goto error_return; |
| 1038 | } |
| 1039 | |
| 1040 | /* |
| 1041 | * Extent size must be a multiple of the appropriate block |
| 1042 | * size, if set at all. |
| 1043 | */ |
| 1044 | if (fa->fsx_extsize != 0) { |
| 1045 | xfs_extlen_t size; |
| 1046 | |
| 1047 | if (XFS_IS_REALTIME_INODE(ip) || |
| 1048 | ((mask & FSX_XFLAGS) && |
| 1049 | (fa->fsx_xflags & XFS_XFLAG_REALTIME))) { |
| 1050 | size = mp->m_sb.sb_rextsize << |
| 1051 | mp->m_sb.sb_blocklog; |
| 1052 | } else { |
| 1053 | size = mp->m_sb.sb_blocksize; |
| 1054 | } |
| 1055 | |
| 1056 | if (fa->fsx_extsize % size) { |
| 1057 | code = XFS_ERROR(EINVAL); |
| 1058 | goto error_return; |
| 1059 | } |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | |
| 1064 | if (mask & FSX_XFLAGS) { |
| 1065 | /* |
| 1066 | * Can't change realtime flag if any extents are allocated. |
| 1067 | */ |
| 1068 | if ((ip->i_d.di_nextents || ip->i_delayed_blks) && |
| 1069 | (XFS_IS_REALTIME_INODE(ip)) != |
| 1070 | (fa->fsx_xflags & XFS_XFLAG_REALTIME)) { |
| 1071 | code = XFS_ERROR(EINVAL); /* EFBIG? */ |
| 1072 | goto error_return; |
| 1073 | } |
| 1074 | |
| 1075 | /* |
| 1076 | * If realtime flag is set then must have realtime data. |
| 1077 | */ |
| 1078 | if ((fa->fsx_xflags & XFS_XFLAG_REALTIME)) { |
| 1079 | if ((mp->m_sb.sb_rblocks == 0) || |
| 1080 | (mp->m_sb.sb_rextsize == 0) || |
| 1081 | (ip->i_d.di_extsize % mp->m_sb.sb_rextsize)) { |
| 1082 | code = XFS_ERROR(EINVAL); |
| 1083 | goto error_return; |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | /* |
| 1088 | * Can't modify an immutable/append-only file unless |
| 1089 | * we have appropriate permission. |
| 1090 | */ |
| 1091 | if ((ip->i_d.di_flags & |
| 1092 | (XFS_DIFLAG_IMMUTABLE|XFS_DIFLAG_APPEND) || |
| 1093 | (fa->fsx_xflags & |
| 1094 | (XFS_XFLAG_IMMUTABLE | XFS_XFLAG_APPEND))) && |
| 1095 | !capable(CAP_LINUX_IMMUTABLE)) { |
| 1096 | code = XFS_ERROR(EPERM); |
| 1097 | goto error_return; |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | xfs_trans_ijoin(tp, ip, lock_flags); |
| 1102 | xfs_trans_ihold(tp, ip); |
| 1103 | |
| 1104 | /* |
| 1105 | * Change file ownership. Must be the owner or privileged. |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1106 | */ |
| 1107 | if (mask & FSX_PROJID) { |
| 1108 | /* |
| 1109 | * CAP_FSETID overrides the following restrictions: |
| 1110 | * |
| 1111 | * The set-user-ID and set-group-ID bits of a file will be |
| 1112 | * cleared upon successful return from chown() |
| 1113 | */ |
| 1114 | if ((ip->i_d.di_mode & (S_ISUID|S_ISGID)) && |
| 1115 | !capable(CAP_FSETID)) |
| 1116 | ip->i_d.di_mode &= ~(S_ISUID|S_ISGID); |
| 1117 | |
| 1118 | /* |
| 1119 | * Change the ownerships and register quota modifications |
| 1120 | * in the transaction. |
| 1121 | */ |
| 1122 | if (ip->i_d.di_projid != fa->fsx_projid) { |
| 1123 | if (XFS_IS_PQUOTA_ON(mp)) { |
| 1124 | olddquot = XFS_QM_DQVOPCHOWN(mp, tp, ip, |
| 1125 | &ip->i_gdquot, gdqp); |
| 1126 | } |
| 1127 | ip->i_d.di_projid = fa->fsx_projid; |
| 1128 | |
| 1129 | /* |
| 1130 | * We may have to rev the inode as well as |
| 1131 | * the superblock version number since projids didn't |
| 1132 | * exist before DINODE_VERSION_2 and SB_VERSION_NLINK. |
| 1133 | */ |
| 1134 | if (ip->i_d.di_version == XFS_DINODE_VERSION_1) |
| 1135 | xfs_bump_ino_vers2(tp, ip); |
| 1136 | } |
| 1137 | |
| 1138 | } |
| 1139 | |
| 1140 | if (mask & FSX_EXTSIZE) |
| 1141 | ip->i_d.di_extsize = fa->fsx_extsize >> mp->m_sb.sb_blocklog; |
Christoph Hellwig | f13fae2 | 2008-07-21 16:16:15 +1000 | [diff] [blame] | 1142 | if (mask & FSX_XFLAGS) { |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1143 | xfs_set_diflags(ip, fa->fsx_xflags); |
Christoph Hellwig | f13fae2 | 2008-07-21 16:16:15 +1000 | [diff] [blame] | 1144 | xfs_diflags_to_linux(ip); |
| 1145 | } |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1146 | |
| 1147 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
| 1148 | xfs_ichgtime(ip, XFS_ICHGTIME_CHG); |
| 1149 | |
| 1150 | XFS_STATS_INC(xs_ig_attrchg); |
| 1151 | |
| 1152 | /* |
| 1153 | * If this is a synchronous mount, make sure that the |
| 1154 | * transaction goes to disk before returning to the user. |
| 1155 | * This is slightly sub-optimal in that truncates require |
| 1156 | * two sync transactions instead of one for wsync filesystems. |
| 1157 | * One for the truncate and one for the timestamps since we |
| 1158 | * don't want to change the timestamps unless we're sure the |
| 1159 | * truncate worked. Truncates are less than 1% of the laddis |
| 1160 | * mix so this probably isn't worth the trouble to optimize. |
| 1161 | */ |
| 1162 | if (mp->m_flags & XFS_MOUNT_WSYNC) |
| 1163 | xfs_trans_set_sync(tp); |
| 1164 | code = xfs_trans_commit(tp, 0); |
| 1165 | xfs_iunlock(ip, lock_flags); |
| 1166 | |
| 1167 | /* |
| 1168 | * Release any dquot(s) the inode had kept before chown. |
| 1169 | */ |
| 1170 | XFS_QM_DQRELE(mp, olddquot); |
| 1171 | XFS_QM_DQRELE(mp, udqp); |
| 1172 | XFS_QM_DQRELE(mp, gdqp); |
| 1173 | |
| 1174 | if (code) |
| 1175 | return code; |
| 1176 | |
| 1177 | if (DM_EVENT_ENABLED(ip, DM_EVENT_ATTRIBUTE)) { |
| 1178 | XFS_SEND_NAMESP(mp, DM_EVENT_ATTRIBUTE, ip, DM_RIGHT_NULL, |
| 1179 | NULL, DM_RIGHT_NULL, NULL, NULL, 0, 0, |
| 1180 | (mask & FSX_NONBLOCK) ? DM_FLAGS_NDELAY : 0); |
| 1181 | } |
| 1182 | |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1183 | return 0; |
| 1184 | |
| 1185 | error_return: |
| 1186 | XFS_QM_DQRELE(mp, udqp); |
| 1187 | XFS_QM_DQRELE(mp, gdqp); |
| 1188 | xfs_trans_cancel(tp, 0); |
| 1189 | if (lock_flags) |
| 1190 | xfs_iunlock(ip, lock_flags); |
| 1191 | return code; |
| 1192 | } |
| 1193 | |
Christoph Hellwig | c83bfab | 2007-10-11 17:47:00 +1000 | [diff] [blame] | 1194 | STATIC int |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1195 | xfs_ioc_fssetxattr( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | xfs_inode_t *ip, |
| 1197 | struct file *filp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | void __user *arg) |
| 1199 | { |
| 1200 | struct fsxattr fa; |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1201 | unsigned int mask; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1202 | |
| 1203 | if (copy_from_user(&fa, arg, sizeof(fa))) |
| 1204 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1206 | mask = FSX_XFLAGS | FSX_EXTSIZE | FSX_PROJID; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1207 | if (filp->f_flags & (O_NDELAY|O_NONBLOCK)) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1208 | mask |= FSX_NONBLOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1210 | return -xfs_ioctl_setattr(ip, &fa, mask); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1213 | STATIC int |
| 1214 | xfs_ioc_getxflags( |
| 1215 | xfs_inode_t *ip, |
| 1216 | void __user *arg) |
| 1217 | { |
| 1218 | unsigned int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1220 | flags = xfs_di2lxflags(ip->i_d.di_flags); |
| 1221 | if (copy_to_user(arg, &flags, sizeof(flags))) |
| 1222 | return -EFAULT; |
| 1223 | return 0; |
| 1224 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1226 | STATIC int |
| 1227 | xfs_ioc_setxflags( |
| 1228 | xfs_inode_t *ip, |
| 1229 | struct file *filp, |
| 1230 | void __user *arg) |
| 1231 | { |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1232 | struct fsxattr fa; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1233 | unsigned int flags; |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1234 | unsigned int mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1236 | if (copy_from_user(&flags, arg, sizeof(flags))) |
| 1237 | return -EFAULT; |
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 (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \ |
| 1240 | FS_NOATIME_FL | FS_NODUMP_FL | \ |
| 1241 | FS_SYNC_FL)) |
| 1242 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1244 | mask = FSX_XFLAGS; |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1245 | if (filp->f_flags & (O_NDELAY|O_NONBLOCK)) |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1246 | mask |= FSX_NONBLOCK; |
| 1247 | fa.fsx_xflags = xfs_merge_ioc_xflags(flags, xfs_ip2xflags(ip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
Christoph Hellwig | 25fe55e | 2008-07-18 17:13:20 +1000 | [diff] [blame] | 1249 | return -xfs_ioctl_setattr(ip, &fa, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | STATIC int |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame^] | 1253 | xfs_getbmap_format(void **ap, struct getbmapx *bmv, int *full) |
| 1254 | { |
| 1255 | struct getbmap __user *base = *ap; |
| 1256 | |
| 1257 | /* copy only getbmap portion (not getbmapx) */ |
| 1258 | if (copy_to_user(base, bmv, sizeof(struct getbmap))) |
| 1259 | return XFS_ERROR(EFAULT); |
| 1260 | |
| 1261 | *ap += sizeof(struct getbmap); |
| 1262 | return 0; |
| 1263 | } |
| 1264 | |
| 1265 | STATIC int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | xfs_ioc_getbmap( |
Christoph Hellwig | 993386c | 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 | { |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame^] | 1272 | struct getbmapx bmx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | int error; |
| 1274 | |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame^] | 1275 | if (copy_from_user(&bmx, arg, sizeof(struct getbmapx))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | return -XFS_ERROR(EFAULT); |
| 1277 | |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame^] | 1278 | if (bmx.bmv_count < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | return -XFS_ERROR(EINVAL); |
| 1280 | |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame^] | 1281 | bmx.bmv_iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | if (ioflags & IO_INVIS) |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame^] | 1283 | bmx.bmv_iflags |= BMV_IF_NO_DMAPI_READ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame^] | 1285 | error = xfs_getbmap(ip, &bmx, xfs_getbmap_format, |
| 1286 | (struct getbmap *)arg+1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | if (error) |
| 1288 | return -error; |
| 1289 | |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame^] | 1290 | /* copy back header - only size of getbmap */ |
| 1291 | if (copy_to_user(arg, &bmx, sizeof(struct getbmap))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | return -XFS_ERROR(EFAULT); |
| 1293 | return 0; |
| 1294 | } |
| 1295 | |
| 1296 | STATIC int |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame^] | 1297 | xfs_getbmapx_format(void **ap, struct getbmapx *bmv, int *full) |
| 1298 | { |
| 1299 | struct getbmapx __user *base = *ap; |
| 1300 | |
| 1301 | if (copy_to_user(base, bmv, sizeof(struct getbmapx))) |
| 1302 | return XFS_ERROR(EFAULT); |
| 1303 | |
| 1304 | *ap += sizeof(struct getbmapx); |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | STATIC int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | xfs_ioc_getbmapx( |
Christoph Hellwig | 993386c | 2007-08-28 16:12:30 +1000 | [diff] [blame] | 1310 | struct xfs_inode *ip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | void __user *arg) |
| 1312 | { |
| 1313 | struct getbmapx bmx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | int error; |
| 1315 | |
| 1316 | if (copy_from_user(&bmx, arg, sizeof(bmx))) |
| 1317 | return -XFS_ERROR(EFAULT); |
| 1318 | |
| 1319 | if (bmx.bmv_count < 2) |
| 1320 | return -XFS_ERROR(EINVAL); |
| 1321 | |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame^] | 1322 | if (bmx.bmv_iflags & (~BMV_IF_VALID)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | return -XFS_ERROR(EINVAL); |
| 1324 | |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame^] | 1325 | error = xfs_getbmap(ip, &bmx, xfs_getbmapx_format, |
| 1326 | (struct getbmapx *)arg+1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | if (error) |
| 1328 | return -error; |
| 1329 | |
Eric Sandeen | 8a7141a | 2008-11-28 14:23:35 +1100 | [diff] [blame^] | 1330 | /* copy back header */ |
| 1331 | if (copy_to_user(arg, &bmx, sizeof(struct getbmapx))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | return -XFS_ERROR(EFAULT); |
| 1333 | |
| 1334 | return 0; |
| 1335 | } |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1336 | |
| 1337 | int |
| 1338 | xfs_ioctl( |
| 1339 | xfs_inode_t *ip, |
| 1340 | struct file *filp, |
| 1341 | int ioflags, |
| 1342 | unsigned int cmd, |
| 1343 | void __user *arg) |
| 1344 | { |
| 1345 | struct inode *inode = filp->f_path.dentry->d_inode; |
| 1346 | xfs_mount_t *mp = ip->i_mount; |
| 1347 | int error; |
| 1348 | |
| 1349 | xfs_itrace_entry(XFS_I(inode)); |
| 1350 | switch (cmd) { |
| 1351 | |
| 1352 | case XFS_IOC_ALLOCSP: |
| 1353 | case XFS_IOC_FREESP: |
| 1354 | case XFS_IOC_RESVSP: |
| 1355 | case XFS_IOC_UNRESVSP: |
| 1356 | case XFS_IOC_ALLOCSP64: |
| 1357 | case XFS_IOC_FREESP64: |
| 1358 | case XFS_IOC_RESVSP64: |
| 1359 | case XFS_IOC_UNRESVSP64: |
| 1360 | /* |
| 1361 | * Only allow the sys admin to reserve space unless |
| 1362 | * unwritten extents are enabled. |
| 1363 | */ |
| 1364 | if (!xfs_sb_version_hasextflgbit(&mp->m_sb) && |
| 1365 | !capable(CAP_SYS_ADMIN)) |
| 1366 | return -EPERM; |
| 1367 | |
| 1368 | return xfs_ioc_space(ip, inode, filp, ioflags, cmd, arg); |
| 1369 | |
| 1370 | case XFS_IOC_DIOINFO: { |
| 1371 | struct dioattr da; |
| 1372 | xfs_buftarg_t *target = |
| 1373 | XFS_IS_REALTIME_INODE(ip) ? |
| 1374 | mp->m_rtdev_targp : mp->m_ddev_targp; |
| 1375 | |
| 1376 | da.d_mem = da.d_miniosz = 1 << target->bt_sshift; |
| 1377 | da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1); |
| 1378 | |
| 1379 | if (copy_to_user(arg, &da, sizeof(da))) |
| 1380 | return -XFS_ERROR(EFAULT); |
| 1381 | return 0; |
| 1382 | } |
| 1383 | |
| 1384 | case XFS_IOC_FSBULKSTAT_SINGLE: |
| 1385 | case XFS_IOC_FSBULKSTAT: |
| 1386 | case XFS_IOC_FSINUMBERS: |
| 1387 | return xfs_ioc_bulkstat(mp, cmd, arg); |
| 1388 | |
| 1389 | case XFS_IOC_FSGEOMETRY_V1: |
| 1390 | return xfs_ioc_fsgeometry_v1(mp, arg); |
| 1391 | |
| 1392 | case XFS_IOC_FSGEOMETRY: |
| 1393 | return xfs_ioc_fsgeometry(mp, arg); |
| 1394 | |
| 1395 | case XFS_IOC_GETVERSION: |
| 1396 | return put_user(inode->i_generation, (int __user *)arg); |
| 1397 | |
| 1398 | case XFS_IOC_FSGETXATTR: |
| 1399 | return xfs_ioc_fsgetxattr(ip, 0, arg); |
| 1400 | case XFS_IOC_FSGETXATTRA: |
| 1401 | return xfs_ioc_fsgetxattr(ip, 1, arg); |
Lachlan McIlroy | 3b2816b | 2008-04-18 12:43:35 +1000 | [diff] [blame] | 1402 | case XFS_IOC_FSSETXATTR: |
Lachlan McIlroy | 65e67f5 | 2008-04-18 12:59:45 +1000 | [diff] [blame] | 1403 | return xfs_ioc_fssetxattr(ip, filp, arg); |
| 1404 | case XFS_IOC_GETXFLAGS: |
| 1405 | return xfs_ioc_getxflags(ip, arg); |
| 1406 | case XFS_IOC_SETXFLAGS: |
| 1407 | return xfs_ioc_setxflags(ip, filp, arg); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1408 | |
| 1409 | case XFS_IOC_FSSETDM: { |
| 1410 | struct fsdmidata dmi; |
| 1411 | |
| 1412 | if (copy_from_user(&dmi, arg, sizeof(dmi))) |
| 1413 | return -XFS_ERROR(EFAULT); |
| 1414 | |
| 1415 | error = xfs_set_dmattrs(ip, dmi.fsd_dmevmask, |
| 1416 | dmi.fsd_dmstate); |
| 1417 | return -error; |
| 1418 | } |
| 1419 | |
| 1420 | case XFS_IOC_GETBMAP: |
| 1421 | case XFS_IOC_GETBMAPA: |
| 1422 | return xfs_ioc_getbmap(ip, ioflags, cmd, arg); |
| 1423 | |
| 1424 | case XFS_IOC_GETBMAPX: |
| 1425 | return xfs_ioc_getbmapx(ip, arg); |
| 1426 | |
| 1427 | case XFS_IOC_FD_TO_HANDLE: |
| 1428 | case XFS_IOC_PATH_TO_HANDLE: |
| 1429 | case XFS_IOC_PATH_TO_FSHANDLE: |
| 1430 | return xfs_find_handle(cmd, arg); |
| 1431 | |
| 1432 | case XFS_IOC_OPEN_BY_HANDLE: |
| 1433 | return xfs_open_by_handle(mp, arg, filp, inode); |
| 1434 | |
| 1435 | case XFS_IOC_FSSETDM_BY_HANDLE: |
| 1436 | return xfs_fssetdm_by_handle(mp, arg, inode); |
| 1437 | |
| 1438 | case XFS_IOC_READLINK_BY_HANDLE: |
| 1439 | return xfs_readlink_by_handle(mp, arg, inode); |
| 1440 | |
| 1441 | case XFS_IOC_ATTRLIST_BY_HANDLE: |
| 1442 | return xfs_attrlist_by_handle(mp, arg, inode); |
| 1443 | |
| 1444 | case XFS_IOC_ATTRMULTI_BY_HANDLE: |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 1445 | return xfs_attrmulti_by_handle(mp, arg, filp, inode); |
Lachlan McIlroy | df26cfe | 2008-04-18 11:44:03 +1000 | [diff] [blame] | 1446 | |
| 1447 | case XFS_IOC_SWAPEXT: { |
| 1448 | error = xfs_swapext((struct xfs_swapext __user *)arg); |
| 1449 | return -error; |
| 1450 | } |
| 1451 | |
| 1452 | case XFS_IOC_FSCOUNTS: { |
| 1453 | xfs_fsop_counts_t out; |
| 1454 | |
| 1455 | error = xfs_fs_counts(mp, &out); |
| 1456 | if (error) |
| 1457 | return -error; |
| 1458 | |
| 1459 | if (copy_to_user(arg, &out, sizeof(out))) |
| 1460 | return -XFS_ERROR(EFAULT); |
| 1461 | return 0; |
| 1462 | } |
| 1463 | |
| 1464 | case XFS_IOC_SET_RESBLKS: { |
| 1465 | xfs_fsop_resblks_t inout; |
| 1466 | __uint64_t in; |
| 1467 | |
| 1468 | if (!capable(CAP_SYS_ADMIN)) |
| 1469 | return -EPERM; |
| 1470 | |
| 1471 | if (copy_from_user(&inout, arg, sizeof(inout))) |
| 1472 | return -XFS_ERROR(EFAULT); |
| 1473 | |
| 1474 | /* input parameter is passed in resblks field of structure */ |
| 1475 | in = inout.resblks; |
| 1476 | error = xfs_reserve_blocks(mp, &in, &inout); |
| 1477 | if (error) |
| 1478 | return -error; |
| 1479 | |
| 1480 | if (copy_to_user(arg, &inout, sizeof(inout))) |
| 1481 | return -XFS_ERROR(EFAULT); |
| 1482 | return 0; |
| 1483 | } |
| 1484 | |
| 1485 | case XFS_IOC_GET_RESBLKS: { |
| 1486 | xfs_fsop_resblks_t out; |
| 1487 | |
| 1488 | if (!capable(CAP_SYS_ADMIN)) |
| 1489 | return -EPERM; |
| 1490 | |
| 1491 | error = xfs_reserve_blocks(mp, NULL, &out); |
| 1492 | if (error) |
| 1493 | return -error; |
| 1494 | |
| 1495 | if (copy_to_user(arg, &out, sizeof(out))) |
| 1496 | return -XFS_ERROR(EFAULT); |
| 1497 | |
| 1498 | return 0; |
| 1499 | } |
| 1500 | |
| 1501 | case XFS_IOC_FSGROWFSDATA: { |
| 1502 | xfs_growfs_data_t in; |
| 1503 | |
| 1504 | if (!capable(CAP_SYS_ADMIN)) |
| 1505 | return -EPERM; |
| 1506 | |
| 1507 | if (copy_from_user(&in, arg, sizeof(in))) |
| 1508 | return -XFS_ERROR(EFAULT); |
| 1509 | |
| 1510 | error = xfs_growfs_data(mp, &in); |
| 1511 | return -error; |
| 1512 | } |
| 1513 | |
| 1514 | case XFS_IOC_FSGROWFSLOG: { |
| 1515 | xfs_growfs_log_t in; |
| 1516 | |
| 1517 | if (!capable(CAP_SYS_ADMIN)) |
| 1518 | return -EPERM; |
| 1519 | |
| 1520 | if (copy_from_user(&in, arg, sizeof(in))) |
| 1521 | return -XFS_ERROR(EFAULT); |
| 1522 | |
| 1523 | error = xfs_growfs_log(mp, &in); |
| 1524 | return -error; |
| 1525 | } |
| 1526 | |
| 1527 | case XFS_IOC_FSGROWFSRT: { |
| 1528 | xfs_growfs_rt_t in; |
| 1529 | |
| 1530 | if (!capable(CAP_SYS_ADMIN)) |
| 1531 | return -EPERM; |
| 1532 | |
| 1533 | if (copy_from_user(&in, arg, sizeof(in))) |
| 1534 | return -XFS_ERROR(EFAULT); |
| 1535 | |
| 1536 | error = xfs_growfs_rt(mp, &in); |
| 1537 | return -error; |
| 1538 | } |
| 1539 | |
| 1540 | case XFS_IOC_FREEZE: |
| 1541 | if (!capable(CAP_SYS_ADMIN)) |
| 1542 | return -EPERM; |
| 1543 | |
| 1544 | if (inode->i_sb->s_frozen == SB_UNFROZEN) |
| 1545 | freeze_bdev(inode->i_sb->s_bdev); |
| 1546 | return 0; |
| 1547 | |
| 1548 | case XFS_IOC_THAW: |
| 1549 | if (!capable(CAP_SYS_ADMIN)) |
| 1550 | return -EPERM; |
| 1551 | if (inode->i_sb->s_frozen != SB_UNFROZEN) |
| 1552 | thaw_bdev(inode->i_sb->s_bdev, inode->i_sb); |
| 1553 | return 0; |
| 1554 | |
| 1555 | case XFS_IOC_GOINGDOWN: { |
| 1556 | __uint32_t in; |
| 1557 | |
| 1558 | if (!capable(CAP_SYS_ADMIN)) |
| 1559 | return -EPERM; |
| 1560 | |
| 1561 | if (get_user(in, (__uint32_t __user *)arg)) |
| 1562 | return -XFS_ERROR(EFAULT); |
| 1563 | |
| 1564 | error = xfs_fs_goingdown(mp, in); |
| 1565 | return -error; |
| 1566 | } |
| 1567 | |
| 1568 | case XFS_IOC_ERROR_INJECTION: { |
| 1569 | xfs_error_injection_t in; |
| 1570 | |
| 1571 | if (!capable(CAP_SYS_ADMIN)) |
| 1572 | return -EPERM; |
| 1573 | |
| 1574 | if (copy_from_user(&in, arg, sizeof(in))) |
| 1575 | return -XFS_ERROR(EFAULT); |
| 1576 | |
| 1577 | error = xfs_errortag_add(in.errtag, mp); |
| 1578 | return -error; |
| 1579 | } |
| 1580 | |
| 1581 | case XFS_IOC_ERROR_CLEARALL: |
| 1582 | if (!capable(CAP_SYS_ADMIN)) |
| 1583 | return -EPERM; |
| 1584 | |
| 1585 | error = xfs_errortag_clearall(mp, 1); |
| 1586 | return -error; |
| 1587 | |
| 1588 | default: |
| 1589 | return -ENOTTY; |
| 1590 | } |
| 1591 | } |