blob: d3438c72dcaf555b8d18174a00d1b6eab264615f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * 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 Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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 Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include "xfs_fs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110020#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110022#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "xfs_trans.h"
24#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110025#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_dir2.h"
27#include "xfs_alloc.h"
28#include "xfs_dmapi.h"
29#include "xfs_mount.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include "xfs_bmap_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110031#include "xfs_alloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include "xfs_ialloc_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110033#include "xfs_attr_sf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_dir2_sf.h"
35#include "xfs_dinode.h"
36#include "xfs_inode.h"
Nathan Scotta844f452005-11-02 14:38:42 +110037#include "xfs_btree.h"
38#include "xfs_ialloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include "xfs_rtalloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include "xfs_itable.h"
Nathan Scotta844f452005-11-02 14:38:42 +110041#include "xfs_error.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include "xfs_rw.h"
43#include "xfs_acl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include "xfs_attr.h"
Nathan Scotta844f452005-11-02 14:38:42 +110045#include "xfs_bmap.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include "xfs_buf_item.h"
47#include "xfs_utils.h"
48#include "xfs_dfrag.h"
49#include "xfs_fsops.h"
Christoph Hellwig993386c2007-08-28 16:12:30 +100050#include "xfs_vnodeops.h"
Christoph Hellwig25fe55e2008-07-18 17:13:20 +100051#include "xfs_quota.h"
52#include "xfs_inode_item.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Randy Dunlap16f7e0f2006-01-11 12:17:46 -080054#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#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 */
71STATIC int
72xfs_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 Torvalds1da177e2005-04-16 15:20:36 -070080
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 Viro2d8f3032008-07-22 09:59:21 -040089 struct path path;
90 int error = user_lpath((const char __user *)hreq.path, &path);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 if (error)
92 return error;
93
Al Viro2d8f3032008-07-22 09:59:21 -040094 ASSERT(path.dentry);
95 ASSERT(path.dentry->d_inode);
96 inode = igrab(path.dentry->d_inode);
97 path_put(&path);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 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" Sipeke678fb02006-12-08 02:36:49 -0800108 ASSERT(file->f_path.dentry);
109 ASSERT(file->f_path.dentry->d_inode);
110 inode = igrab(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 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 Hellwig0432dab2005-09-02 16:46:51 +1000126 switch (inode->i_mode & S_IFMT) {
127 case S_IFREG:
128 case S_IFDIR:
129 case S_IFLNK:
130 break;
131 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 iput(inode);
133 return -XFS_ERROR(EBADF);
134 }
135
136 /* now we can grab the fsid */
Christoph Hellwig0ce4cfd2007-08-30 17:20:53 +1000137 memcpy(&handle.ha_fsid, XFS_I(inode)->i_mount->m_fixedfsid,
Christoph Hellwig2f6f7b32007-08-29 11:44:18 +1000138 sizeof(xfs_fsid_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 hsize = sizeof(xfs_fsid_t);
140
141 if (cmd != XFS_IOC_PATH_TO_FSHANDLE) {
Christoph Hellwig6e7f75e2007-10-11 18:09:50 +1000142 xfs_inode_t *ip = XFS_I(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 int lock_mode;
144
145 /* need to get access to the xfs_inode to read the generation */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 lock_mode = xfs_ilock_map_shared(ip);
147
148 /* fill in fid section of handle from inode */
Christoph Hellwigc6143912007-09-14 15:22:37 +1000149 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 Torvalds1da177e2005-04-16 15:20:36 -0700154
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 Hellwig6e7f75e2007-10-11 18:09:50 +1000173 * Convert userspace handle data into inode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 *
Christoph Hellwig6e7f75e2007-10-11 18:09:50 +1000175 * 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 Torvalds1da177e2005-04-16 15:20:36 -0700180 */
181STATIC int
182xfs_vget_fsop_handlereq(
183 xfs_mount_t *mp,
184 struct inode *parinode, /* parent inode pointer */
185 xfs_fsop_handlereq_t *hreq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 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 Torvalds1da177e2005-04-16 15:20:36 -0700194 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 Hellwigc6143912007-09-14 15:22:37 +1000215 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 Torvalds1da177e2005-04-16 15:20:36 -0700219 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 Hellwigc6143912007-09-14 15:22:37 +1000226 if (xfid->fid_len == sizeof(*xfid) - sizeof(xfid->fid_len)) {
227 ino = xfid->fid_ino;
228 igen = xfid->fid_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 } else {
230 return XFS_ERROR(EINVAL);
231 }
232
233 /*
Christoph Hellwig6e7f75e2007-10-11 18:09:50 +1000234 * Get the XFS inode, building a Linux inode to go with it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 */
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 Hellwig6a7f4222008-04-22 17:33:40 +1000241 if (ip->i_d.di_gen != igen) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 xfs_iput_new(ip, XFS_ILOCK_SHARED);
243 return XFS_ERROR(ENOENT);
244 }
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 xfs_iunlock(ip, XFS_ILOCK_SHARED);
247
David Chinnere4f75292008-08-13 16:00:45 +1000248 *inode = VFS_I(ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 return 0;
250}
251
252STATIC int
253xfs_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 Torvalds1da177e2005-04-16 15:20:36 -0700265 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 Hellwig6e7f75e2007-10-11 18:09:50 +1000272 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 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 Hellwig44003722008-08-11 15:49:04 +0200314 dentry = d_obtain_alias(inode);
315 if (IS_ERR(dentry)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 put_unused_fd(new_fd);
Christoph Hellwig44003722008-08-11 15:49:04 +0200317 return PTR_ERR(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 }
319
320 /* Ensure umount returns EBUSY on umounts while this file is open. */
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800321 mntget(parfilp->f_path.mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 /* Create file pointer. */
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800324 filp = dentry_open(dentry, parfilp->f_path.mnt, hreq.oflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if (IS_ERR(filp)) {
326 put_unused_fd(new_fd);
327 return -XFS_ERROR(-PTR_ERR(filp));
328 }
Vlad Apostolov2e2e7bb2006-11-11 18:04:47 +1100329 if (inode->i_mode & S_IFREG) {
330 /* invisible operation should not change atime */
331 filp->f_flags |= O_NOATIME;
Nathan Scott3562fd42006-03-14 14:00:35 +1100332 filp->f_op = &xfs_invis_file_operations;
Vlad Apostolov2e2e7bb2006-11-11 18:04:47 +1100333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 fd_install(new_fd, filp);
336 return new_fd;
337}
338
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000339/*
340 * This is a copy from fs/namei.c:vfs_readlink(), except for removing it's
341 * unused first argument.
342 */
343STATIC int
344do_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 Torvalds1da177e2005-04-16 15:20:36 -0700365STATIC int
366xfs_readlink_by_handle(
367 xfs_mount_t *mp,
368 void __user *arg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 struct inode *parinode)
370{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 struct inode *inode;
372 xfs_fsop_handlereq_t hreq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 __u32 olen;
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000374 void *link;
375 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
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 Hellwig6e7f75e2007-10-11 18:09:50 +1000382 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 if (error)
384 return -error;
385
386 /* Restrict this handle operation to symlinks only. */
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000387 if (!S_ISLNK(inode->i_mode)) {
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000388 error = -XFS_ERROR(EINVAL);
389 goto out_iput;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 }
391
392 if (copy_from_user(&olen, hreq.ohandlen, sizeof(__u32))) {
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000393 error = -XFS_ERROR(EFAULT);
394 goto out_iput;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000397 link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
398 if (!link)
399 goto out_iput;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000401 error = -xfs_readlink(XFS_I(inode), link);
Nathan Scott67fcaa72006-06-09 17:00:52 +1000402 if (error)
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000403 goto out_kfree;
404 error = do_readlink(hreq.ohandle, olen, link);
405 if (error)
406 goto out_kfree;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000407
Christoph Hellwig804c83c2007-08-28 13:59:03 +1000408 out_kfree:
409 kfree(link);
410 out_iput:
411 iput(inode);
412 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
415STATIC int
416xfs_fssetdm_by_handle(
417 xfs_mount_t *mp,
418 void __user *arg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 struct inode *parinode)
420{
421 int error;
422 struct fsdmidata fsd;
423 xfs_fsop_setdm_handlereq_t dmhreq;
424 struct inode *inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
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 Hellwig6e7f75e2007-10-11 18:09:50 +1000431 error = xfs_vget_fsop_handlereq(mp, parinode, &dmhreq.hreq, &inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 if (error)
433 return -error;
434
435 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
Christoph Hellwig6e7f75e2007-10-11 18:09:50 +1000436 error = -XFS_ERROR(EPERM);
437 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 }
439
440 if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
Christoph Hellwig6e7f75e2007-10-11 18:09:50 +1000441 error = -XFS_ERROR(EFAULT);
442 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 }
444
Christoph Hellwig6e7f75e2007-10-11 18:09:50 +1000445 error = -xfs_set_dmattrs(XFS_I(inode), fsd.fsd_dmevmask,
446 fsd.fsd_dmstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Christoph Hellwig6e7f75e2007-10-11 18:09:50 +1000448 out:
449 iput(inode);
450 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451}
452
453STATIC int
454xfs_attrlist_by_handle(
455 xfs_mount_t *mp,
456 void __user *arg,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 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 Torvalds1da177e2005-04-16 15:20:36 -0700463 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 Hellwig90ad58a2008-06-27 13:32:19 +1000472 /*
473 * Reject flags, only allow namespaces.
474 */
475 if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE))
476 return -XFS_ERROR(EINVAL);
477
Christoph Hellwig6e7f75e2007-10-11 18:09:50 +1000478 error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq, &inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 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 Hellwig739bfb22007-08-29 10:58:01 +1000487 error = xfs_attr_list(XFS_I(inode), kbuf, al_hreq.buflen,
488 al_hreq.flags, cursor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 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 Hellwig6e7f75e2007-10-11 18:09:50 +1000498 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 out:
500 return -error;
501}
502
503STATIC int
504xfs_attrmulti_attr_get(
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000505 struct inode *inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 char *name,
507 char __user *ubuf,
508 __uint32_t *len,
509 __uint32_t flags)
510{
511 char *kbuf;
512 int error = EFAULT;
Barry Naujoke8b0eba2008-04-22 17:34:31 +1000513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 if (*len > XATTR_SIZE_MAX)
515 return EINVAL;
516 kbuf = kmalloc(*len, GFP_KERNEL);
517 if (!kbuf)
518 return ENOMEM;
519
Barry Naujoke8b0eba2008-04-22 17:34:31 +1000520 error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 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
532STATIC int
533xfs_attrmulti_attr_set(
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000534 struct inode *inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 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 Hellwig739bfb22007-08-29 10:58:01 +1000543 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 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 Naujoke8b0eba2008-04-22 17:34:31 +1000554
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000555 error = xfs_attr_set(XFS_I(inode), name, kbuf, len, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 out_kfree:
558 kfree(kbuf);
559 return error;
560}
561
562STATIC int
563xfs_attrmulti_attr_remove(
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000564 struct inode *inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 char *name,
566 __uint32_t flags)
567{
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000568 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 return EPERM;
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000570 return xfs_attr_remove(XFS_I(inode), name, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571}
572
573STATIC int
574xfs_attrmulti_by_handle(
575 xfs_mount_t *mp,
576 void __user *arg,
Dave Hansen42a74f22008-02-15 14:37:46 -0800577 struct file *parfilp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 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 Torvalds1da177e2005-04-16 15:20:36 -0700584 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 Hellwig6e7f75e2007-10-11 18:09:50 +1000592 error = xfs_vget_fsop_handlereq(mp, parinode, &am_hreq.hreq, &inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 if (error)
594 goto out;
595
596 error = E2BIG;
Christoph Hellwige182f572008-06-27 13:32:31 +1000597 size = am_hreq.opcount * sizeof(xfs_attr_multiop_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 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 Hellwig739bfb22007-08-29 10:58:01 +1000626 ops[i].am_error = xfs_attrmulti_attr_get(inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 attr_name, ops[i].am_attrvalue,
628 &ops[i].am_length, ops[i].am_flags);
629 break;
630 case ATTR_OP_SET:
Dave Hansen42a74f22008-02-15 14:37:46 -0800631 ops[i].am_error = mnt_want_write(parfilp->f_path.mnt);
632 if (ops[i].am_error)
633 break;
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000634 ops[i].am_error = xfs_attrmulti_attr_set(inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 attr_name, ops[i].am_attrvalue,
636 ops[i].am_length, ops[i].am_flags);
Dave Hansen42a74f22008-02-15 14:37:46 -0800637 mnt_drop_write(parfilp->f_path.mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 break;
639 case ATTR_OP_REMOVE:
Dave Hansen42a74f22008-02-15 14:37:46 -0800640 ops[i].am_error = mnt_want_write(parfilp->f_path.mnt);
641 if (ops[i].am_error)
642 break;
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000643 ops[i].am_error = xfs_attrmulti_attr_remove(inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 attr_name, ops[i].am_flags);
Dave Hansen42a74f22008-02-15 14:37:46 -0800645 mnt_drop_write(parfilp->f_path.mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 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 Hellwig6e7f75e2007-10-11 18:09:50 +1000659 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 out:
661 return -error;
662}
663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664STATIC int
665xfs_ioc_space(
Christoph Hellwig993386c2007-08-28 16:12:30 +1000666 struct xfs_inode *ip,
Alexey Dobriyanf37ea142006-09-28 10:52:04 +1000667 struct inode *inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 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 Dobriyanf37ea142006-09-28 10:52:04 +1000677 if (inode->i_flags & (S_IMMUTABLE|S_APPEND))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 return -XFS_ERROR(EPERM);
679
Eric Sandeenad4a8ac2005-09-02 16:41:16 +1000680 if (!(filp->f_mode & FMODE_WRITE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 return -XFS_ERROR(EBADF);
682
Alexey Dobriyanf37ea142006-09-28 10:52:04 +1000683 if (!S_ISREG(inode->i_mode))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 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 Hellwig0f285c82008-07-18 17:13:28 +1000690 attr_flags |= XFS_ATTR_NONBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 if (ioflags & IO_INVIS)
Christoph Hellwig0f285c82008-07-18 17:13:28 +1000692 attr_flags |= XFS_ATTR_DMI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Christoph Hellwig993386c2007-08-28 16:12:30 +1000694 error = xfs_change_file_space(ip, cmd, &bf, filp->f_pos,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 NULL, attr_flags);
696 return -error;
697}
698
699STATIC int
700xfs_ioc_bulkstat(
701 xfs_mount_t *mp,
702 unsigned int cmd,
703 void __user *arg)
704{
705 xfs_fsop_bulkreq_t bulkreq;
706 int count; /* # of records returned */
707 xfs_ino_t inlast; /* last inode number */
708 int done;
709 int error;
710
711 /* done = 1 if there are more stats to get and if bulkstat */
712 /* should be called again (unused here, but used in dmapi) */
713
714 if (!capable(CAP_SYS_ADMIN))
715 return -EPERM;
716
717 if (XFS_FORCED_SHUTDOWN(mp))
718 return -XFS_ERROR(EIO);
719
720 if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t)))
721 return -XFS_ERROR(EFAULT);
722
723 if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
724 return -XFS_ERROR(EFAULT);
725
726 if ((count = bulkreq.icount) <= 0)
727 return -XFS_ERROR(EINVAL);
728
Lachlan McIlroycd57e592007-11-23 16:30:32 +1100729 if (bulkreq.ubuffer == NULL)
730 return -XFS_ERROR(EINVAL);
731
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 if (cmd == XFS_IOC_FSINUMBERS)
733 error = xfs_inumbers(mp, &inlast, &count,
Michal Marekfaa63e92007-07-11 11:10:19 +1000734 bulkreq.ubuffer, xfs_inumbers_fmt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE)
736 error = xfs_bulkstat_single(mp, &inlast,
737 bulkreq.ubuffer, &done);
Lachlan McIlroycd57e592007-11-23 16:30:32 +1100738 else /* XFS_IOC_FSBULKSTAT */
739 error = xfs_bulkstat(mp, &inlast, &count,
740 (bulkstat_one_pf)xfs_bulkstat_one, NULL,
741 sizeof(xfs_bstat_t), bulkreq.ubuffer,
742 BULKSTAT_FG_QUICK, &done);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
744 if (error)
745 return -error;
746
747 if (bulkreq.ocount != NULL) {
748 if (copy_to_user(bulkreq.lastip, &inlast,
749 sizeof(xfs_ino_t)))
750 return -XFS_ERROR(EFAULT);
751
752 if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
753 return -XFS_ERROR(EFAULT);
754 }
755
756 return 0;
757}
758
759STATIC int
760xfs_ioc_fsgeometry_v1(
761 xfs_mount_t *mp,
762 void __user *arg)
763{
764 xfs_fsop_geom_v1_t fsgeo;
765 int error;
766
767 error = xfs_fs_geometry(mp, (xfs_fsop_geom_t *)&fsgeo, 3);
768 if (error)
769 return -error;
770
771 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
772 return -XFS_ERROR(EFAULT);
773 return 0;
774}
775
776STATIC int
777xfs_ioc_fsgeometry(
778 xfs_mount_t *mp,
779 void __user *arg)
780{
781 xfs_fsop_geom_t fsgeo;
782 int error;
783
784 error = xfs_fs_geometry(mp, &fsgeo, 4);
785 if (error)
786 return -error;
787
788 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
789 return -XFS_ERROR(EFAULT);
790 return 0;
791}
792
793/*
794 * Linux extended inode flags interface.
795 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797STATIC unsigned int
798xfs_merge_ioc_xflags(
799 unsigned int flags,
800 unsigned int start)
801{
802 unsigned int xflags = start;
803
Eric Sandeen39058a02007-02-10 18:37:10 +1100804 if (flags & FS_IMMUTABLE_FL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 xflags |= XFS_XFLAG_IMMUTABLE;
806 else
807 xflags &= ~XFS_XFLAG_IMMUTABLE;
Eric Sandeen39058a02007-02-10 18:37:10 +1100808 if (flags & FS_APPEND_FL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 xflags |= XFS_XFLAG_APPEND;
810 else
811 xflags &= ~XFS_XFLAG_APPEND;
Eric Sandeen39058a02007-02-10 18:37:10 +1100812 if (flags & FS_SYNC_FL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 xflags |= XFS_XFLAG_SYNC;
814 else
815 xflags &= ~XFS_XFLAG_SYNC;
Eric Sandeen39058a02007-02-10 18:37:10 +1100816 if (flags & FS_NOATIME_FL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 xflags |= XFS_XFLAG_NOATIME;
818 else
819 xflags &= ~XFS_XFLAG_NOATIME;
Eric Sandeen39058a02007-02-10 18:37:10 +1100820 if (flags & FS_NODUMP_FL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 xflags |= XFS_XFLAG_NODUMP;
822 else
823 xflags &= ~XFS_XFLAG_NODUMP;
824
825 return xflags;
826}
827
828STATIC unsigned int
829xfs_di2lxflags(
830 __uint16_t di_flags)
831{
832 unsigned int flags = 0;
833
834 if (di_flags & XFS_DIFLAG_IMMUTABLE)
Eric Sandeen39058a02007-02-10 18:37:10 +1100835 flags |= FS_IMMUTABLE_FL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 if (di_flags & XFS_DIFLAG_APPEND)
Eric Sandeen39058a02007-02-10 18:37:10 +1100837 flags |= FS_APPEND_FL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 if (di_flags & XFS_DIFLAG_SYNC)
Eric Sandeen39058a02007-02-10 18:37:10 +1100839 flags |= FS_SYNC_FL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 if (di_flags & XFS_DIFLAG_NOATIME)
Eric Sandeen39058a02007-02-10 18:37:10 +1100841 flags |= FS_NOATIME_FL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 if (di_flags & XFS_DIFLAG_NODUMP)
Eric Sandeen39058a02007-02-10 18:37:10 +1100843 flags |= FS_NODUMP_FL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 return flags;
845}
846
847STATIC int
Christoph Hellwigc83bfab2007-10-11 17:47:00 +1000848xfs_ioc_fsgetxattr(
849 xfs_inode_t *ip,
850 int attr,
851 void __user *arg)
852{
853 struct fsxattr fa;
854
855 xfs_ilock(ip, XFS_ILOCK_SHARED);
856 fa.fsx_xflags = xfs_ip2xflags(ip);
857 fa.fsx_extsize = ip->i_d.di_extsize << ip->i_mount->m_sb.sb_blocklog;
858 fa.fsx_projid = ip->i_d.di_projid;
859
860 if (attr) {
861 if (ip->i_afp) {
862 if (ip->i_afp->if_flags & XFS_IFEXTENTS)
863 fa.fsx_nextents = ip->i_afp->if_bytes /
864 sizeof(xfs_bmbt_rec_t);
865 else
866 fa.fsx_nextents = ip->i_d.di_anextents;
867 } else
868 fa.fsx_nextents = 0;
869 } else {
870 if (ip->i_df.if_flags & XFS_IFEXTENTS)
871 fa.fsx_nextents = ip->i_df.if_bytes /
872 sizeof(xfs_bmbt_rec_t);
873 else
874 fa.fsx_nextents = ip->i_d.di_nextents;
875 }
876 xfs_iunlock(ip, XFS_ILOCK_SHARED);
877
878 if (copy_to_user(arg, &fa, sizeof(fa)))
879 return -EFAULT;
880 return 0;
881}
882
Christoph Hellwig25fe55e2008-07-18 17:13:20 +1000883STATIC void
884xfs_set_diflags(
885 struct xfs_inode *ip,
886 unsigned int xflags)
887{
888 unsigned int di_flags;
889
890 /* can't set PREALLOC this way, just preserve it */
891 di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
892 if (xflags & XFS_XFLAG_IMMUTABLE)
893 di_flags |= XFS_DIFLAG_IMMUTABLE;
894 if (xflags & XFS_XFLAG_APPEND)
895 di_flags |= XFS_DIFLAG_APPEND;
896 if (xflags & XFS_XFLAG_SYNC)
897 di_flags |= XFS_DIFLAG_SYNC;
898 if (xflags & XFS_XFLAG_NOATIME)
899 di_flags |= XFS_DIFLAG_NOATIME;
900 if (xflags & XFS_XFLAG_NODUMP)
901 di_flags |= XFS_DIFLAG_NODUMP;
902 if (xflags & XFS_XFLAG_PROJINHERIT)
903 di_flags |= XFS_DIFLAG_PROJINHERIT;
904 if (xflags & XFS_XFLAG_NODEFRAG)
905 di_flags |= XFS_DIFLAG_NODEFRAG;
906 if (xflags & XFS_XFLAG_FILESTREAM)
907 di_flags |= XFS_DIFLAG_FILESTREAM;
908 if ((ip->i_d.di_mode & S_IFMT) == S_IFDIR) {
909 if (xflags & XFS_XFLAG_RTINHERIT)
910 di_flags |= XFS_DIFLAG_RTINHERIT;
911 if (xflags & XFS_XFLAG_NOSYMLINKS)
912 di_flags |= XFS_DIFLAG_NOSYMLINKS;
913 if (xflags & XFS_XFLAG_EXTSZINHERIT)
914 di_flags |= XFS_DIFLAG_EXTSZINHERIT;
915 } else if ((ip->i_d.di_mode & S_IFMT) == S_IFREG) {
916 if (xflags & XFS_XFLAG_REALTIME)
917 di_flags |= XFS_DIFLAG_REALTIME;
918 if (xflags & XFS_XFLAG_EXTSIZE)
919 di_flags |= XFS_DIFLAG_EXTSIZE;
920 }
921
922 ip->i_d.di_flags = di_flags;
923}
924
Christoph Hellwigf13fae22008-07-21 16:16:15 +1000925STATIC void
926xfs_diflags_to_linux(
927 struct xfs_inode *ip)
928{
David Chinnere4f75292008-08-13 16:00:45 +1000929 struct inode *inode = VFS_I(ip);
Christoph Hellwigf13fae22008-07-21 16:16:15 +1000930 unsigned int xflags = xfs_ip2xflags(ip);
931
932 if (xflags & XFS_XFLAG_IMMUTABLE)
933 inode->i_flags |= S_IMMUTABLE;
934 else
935 inode->i_flags &= ~S_IMMUTABLE;
936 if (xflags & XFS_XFLAG_APPEND)
937 inode->i_flags |= S_APPEND;
938 else
939 inode->i_flags &= ~S_APPEND;
940 if (xflags & XFS_XFLAG_SYNC)
941 inode->i_flags |= S_SYNC;
942 else
943 inode->i_flags &= ~S_SYNC;
944 if (xflags & XFS_XFLAG_NOATIME)
945 inode->i_flags |= S_NOATIME;
946 else
947 inode->i_flags &= ~S_NOATIME;
948}
Christoph Hellwig25fe55e2008-07-18 17:13:20 +1000949
950#define FSX_PROJID 1
951#define FSX_EXTSIZE 2
952#define FSX_XFLAGS 4
953#define FSX_NONBLOCK 8
954
955STATIC int
956xfs_ioctl_setattr(
957 xfs_inode_t *ip,
958 struct fsxattr *fa,
959 int mask)
960{
961 struct xfs_mount *mp = ip->i_mount;
962 struct xfs_trans *tp;
963 unsigned int lock_flags = 0;
964 struct xfs_dquot *udqp = NULL, *gdqp = NULL;
965 struct xfs_dquot *olddquot = NULL;
966 int code;
967
968 xfs_itrace_entry(ip);
969
970 if (mp->m_flags & XFS_MOUNT_RDONLY)
971 return XFS_ERROR(EROFS);
972 if (XFS_FORCED_SHUTDOWN(mp))
973 return XFS_ERROR(EIO);
974
975 /*
976 * If disk quotas is on, we make sure that the dquots do exist on disk,
977 * before we start any other transactions. Trying to do this later
978 * is messy. We don't care to take a readlock to look at the ids
979 * in inode here, because we can't hold it across the trans_reserve.
980 * If the IDs do change before we take the ilock, we're covered
981 * because the i_*dquot fields will get updated anyway.
982 */
983 if (XFS_IS_QUOTA_ON(mp) && (mask & FSX_PROJID)) {
984 code = XFS_QM_DQVOPALLOC(mp, ip, ip->i_d.di_uid,
985 ip->i_d.di_gid, fa->fsx_projid,
986 XFS_QMOPT_PQUOTA, &udqp, &gdqp);
987 if (code)
988 return code;
989 }
990
991 /*
992 * For the other attributes, we acquire the inode lock and
993 * first do an error checking pass.
994 */
995 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
996 code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
997 if (code)
998 goto error_return;
999
1000 lock_flags = XFS_ILOCK_EXCL;
1001 xfs_ilock(ip, lock_flags);
1002
1003 /*
1004 * CAP_FOWNER overrides the following restrictions:
1005 *
1006 * The user ID of the calling process must be equal
1007 * to the file owner ID, except in cases where the
1008 * CAP_FSETID capability is applicable.
1009 */
1010 if (current->fsuid != ip->i_d.di_uid && !capable(CAP_FOWNER)) {
1011 code = XFS_ERROR(EPERM);
1012 goto error_return;
1013 }
1014
1015 /*
1016 * Do a quota reservation only if projid is actually going to change.
1017 */
1018 if (mask & FSX_PROJID) {
1019 if (XFS_IS_PQUOTA_ON(mp) &&
1020 ip->i_d.di_projid != fa->fsx_projid) {
1021 ASSERT(tp);
1022 code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
1023 capable(CAP_FOWNER) ?
1024 XFS_QMOPT_FORCE_RES : 0);
1025 if (code) /* out of quota */
1026 goto error_return;
1027 }
1028 }
1029
1030 if (mask & FSX_EXTSIZE) {
1031 /*
1032 * Can't change extent size if any extents are allocated.
1033 */
1034 if (ip->i_d.di_nextents &&
1035 ((ip->i_d.di_extsize << mp->m_sb.sb_blocklog) !=
1036 fa->fsx_extsize)) {
1037 code = XFS_ERROR(EINVAL); /* EFBIG? */
1038 goto error_return;
1039 }
1040
1041 /*
1042 * Extent size must be a multiple of the appropriate block
1043 * size, if set at all.
1044 */
1045 if (fa->fsx_extsize != 0) {
1046 xfs_extlen_t size;
1047
1048 if (XFS_IS_REALTIME_INODE(ip) ||
1049 ((mask & FSX_XFLAGS) &&
1050 (fa->fsx_xflags & XFS_XFLAG_REALTIME))) {
1051 size = mp->m_sb.sb_rextsize <<
1052 mp->m_sb.sb_blocklog;
1053 } else {
1054 size = mp->m_sb.sb_blocksize;
1055 }
1056
1057 if (fa->fsx_extsize % size) {
1058 code = XFS_ERROR(EINVAL);
1059 goto error_return;
1060 }
1061 }
1062 }
1063
1064
1065 if (mask & FSX_XFLAGS) {
1066 /*
1067 * Can't change realtime flag if any extents are allocated.
1068 */
1069 if ((ip->i_d.di_nextents || ip->i_delayed_blks) &&
1070 (XFS_IS_REALTIME_INODE(ip)) !=
1071 (fa->fsx_xflags & XFS_XFLAG_REALTIME)) {
1072 code = XFS_ERROR(EINVAL); /* EFBIG? */
1073 goto error_return;
1074 }
1075
1076 /*
1077 * If realtime flag is set then must have realtime data.
1078 */
1079 if ((fa->fsx_xflags & XFS_XFLAG_REALTIME)) {
1080 if ((mp->m_sb.sb_rblocks == 0) ||
1081 (mp->m_sb.sb_rextsize == 0) ||
1082 (ip->i_d.di_extsize % mp->m_sb.sb_rextsize)) {
1083 code = XFS_ERROR(EINVAL);
1084 goto error_return;
1085 }
1086 }
1087
1088 /*
1089 * Can't modify an immutable/append-only file unless
1090 * we have appropriate permission.
1091 */
1092 if ((ip->i_d.di_flags &
1093 (XFS_DIFLAG_IMMUTABLE|XFS_DIFLAG_APPEND) ||
1094 (fa->fsx_xflags &
1095 (XFS_XFLAG_IMMUTABLE | XFS_XFLAG_APPEND))) &&
1096 !capable(CAP_LINUX_IMMUTABLE)) {
1097 code = XFS_ERROR(EPERM);
1098 goto error_return;
1099 }
1100 }
1101
1102 xfs_trans_ijoin(tp, ip, lock_flags);
1103 xfs_trans_ihold(tp, ip);
1104
1105 /*
1106 * Change file ownership. Must be the owner or privileged.
1107 * If the system was configured with the "restricted_chown"
1108 * option, the owner is not permitted to give away the file,
1109 * and can change the group id only to a group of which he
1110 * or she is a member.
1111 */
1112 if (mask & FSX_PROJID) {
1113 /*
1114 * CAP_FSETID overrides the following restrictions:
1115 *
1116 * The set-user-ID and set-group-ID bits of a file will be
1117 * cleared upon successful return from chown()
1118 */
1119 if ((ip->i_d.di_mode & (S_ISUID|S_ISGID)) &&
1120 !capable(CAP_FSETID))
1121 ip->i_d.di_mode &= ~(S_ISUID|S_ISGID);
1122
1123 /*
1124 * Change the ownerships and register quota modifications
1125 * in the transaction.
1126 */
1127 if (ip->i_d.di_projid != fa->fsx_projid) {
1128 if (XFS_IS_PQUOTA_ON(mp)) {
1129 olddquot = XFS_QM_DQVOPCHOWN(mp, tp, ip,
1130 &ip->i_gdquot, gdqp);
1131 }
1132 ip->i_d.di_projid = fa->fsx_projid;
1133
1134 /*
1135 * We may have to rev the inode as well as
1136 * the superblock version number since projids didn't
1137 * exist before DINODE_VERSION_2 and SB_VERSION_NLINK.
1138 */
1139 if (ip->i_d.di_version == XFS_DINODE_VERSION_1)
1140 xfs_bump_ino_vers2(tp, ip);
1141 }
1142
1143 }
1144
1145 if (mask & FSX_EXTSIZE)
1146 ip->i_d.di_extsize = fa->fsx_extsize >> mp->m_sb.sb_blocklog;
Christoph Hellwigf13fae22008-07-21 16:16:15 +10001147 if (mask & FSX_XFLAGS) {
Christoph Hellwig25fe55e2008-07-18 17:13:20 +10001148 xfs_set_diflags(ip, fa->fsx_xflags);
Christoph Hellwigf13fae22008-07-21 16:16:15 +10001149 xfs_diflags_to_linux(ip);
1150 }
Christoph Hellwig25fe55e2008-07-18 17:13:20 +10001151
1152 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1153 xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
1154
1155 XFS_STATS_INC(xs_ig_attrchg);
1156
1157 /*
1158 * If this is a synchronous mount, make sure that the
1159 * transaction goes to disk before returning to the user.
1160 * This is slightly sub-optimal in that truncates require
1161 * two sync transactions instead of one for wsync filesystems.
1162 * One for the truncate and one for the timestamps since we
1163 * don't want to change the timestamps unless we're sure the
1164 * truncate worked. Truncates are less than 1% of the laddis
1165 * mix so this probably isn't worth the trouble to optimize.
1166 */
1167 if (mp->m_flags & XFS_MOUNT_WSYNC)
1168 xfs_trans_set_sync(tp);
1169 code = xfs_trans_commit(tp, 0);
1170 xfs_iunlock(ip, lock_flags);
1171
1172 /*
1173 * Release any dquot(s) the inode had kept before chown.
1174 */
1175 XFS_QM_DQRELE(mp, olddquot);
1176 XFS_QM_DQRELE(mp, udqp);
1177 XFS_QM_DQRELE(mp, gdqp);
1178
1179 if (code)
1180 return code;
1181
1182 if (DM_EVENT_ENABLED(ip, DM_EVENT_ATTRIBUTE)) {
1183 XFS_SEND_NAMESP(mp, DM_EVENT_ATTRIBUTE, ip, DM_RIGHT_NULL,
1184 NULL, DM_RIGHT_NULL, NULL, NULL, 0, 0,
1185 (mask & FSX_NONBLOCK) ? DM_FLAGS_NDELAY : 0);
1186 }
1187
Christoph Hellwig25fe55e2008-07-18 17:13:20 +10001188 return 0;
1189
1190 error_return:
1191 XFS_QM_DQRELE(mp, udqp);
1192 XFS_QM_DQRELE(mp, gdqp);
1193 xfs_trans_cancel(tp, 0);
1194 if (lock_flags)
1195 xfs_iunlock(ip, lock_flags);
1196 return code;
1197}
1198
Christoph Hellwigc83bfab2007-10-11 17:47:00 +10001199STATIC int
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001200xfs_ioc_fssetxattr(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 xfs_inode_t *ip,
1202 struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 void __user *arg)
1204{
1205 struct fsxattr fa;
Christoph Hellwig25fe55e2008-07-18 17:13:20 +10001206 unsigned int mask;
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001207
1208 if (copy_from_user(&fa, arg, sizeof(fa)))
1209 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Christoph Hellwig25fe55e2008-07-18 17:13:20 +10001211 mask = FSX_XFLAGS | FSX_EXTSIZE | FSX_PROJID;
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001212 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
Christoph Hellwig25fe55e2008-07-18 17:13:20 +10001213 mask |= FSX_NONBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
Christoph Hellwig25fe55e2008-07-18 17:13:20 +10001215 return -xfs_ioctl_setattr(ip, &fa, mask);
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001216}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001218STATIC int
1219xfs_ioc_getxflags(
1220 xfs_inode_t *ip,
1221 void __user *arg)
1222{
1223 unsigned int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001225 flags = xfs_di2lxflags(ip->i_d.di_flags);
1226 if (copy_to_user(arg, &flags, sizeof(flags)))
1227 return -EFAULT;
1228 return 0;
1229}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001231STATIC int
1232xfs_ioc_setxflags(
1233 xfs_inode_t *ip,
1234 struct file *filp,
1235 void __user *arg)
1236{
Christoph Hellwig25fe55e2008-07-18 17:13:20 +10001237 struct fsxattr fa;
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001238 unsigned int flags;
Christoph Hellwig25fe55e2008-07-18 17:13:20 +10001239 unsigned int mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001241 if (copy_from_user(&flags, arg, sizeof(flags)))
1242 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001244 if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
1245 FS_NOATIME_FL | FS_NODUMP_FL | \
1246 FS_SYNC_FL))
1247 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Christoph Hellwig25fe55e2008-07-18 17:13:20 +10001249 mask = FSX_XFLAGS;
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001250 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
Christoph Hellwig25fe55e2008-07-18 17:13:20 +10001251 mask |= FSX_NONBLOCK;
1252 fa.fsx_xflags = xfs_merge_ioc_xflags(flags, xfs_ip2xflags(ip));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
Christoph Hellwig25fe55e2008-07-18 17:13:20 +10001254 return -xfs_ioctl_setattr(ip, &fa, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255}
1256
1257STATIC int
1258xfs_ioc_getbmap(
Christoph Hellwig993386c2007-08-28 16:12:30 +10001259 struct xfs_inode *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 int ioflags,
1261 unsigned int cmd,
1262 void __user *arg)
1263{
1264 struct getbmap bm;
1265 int iflags;
1266 int error;
1267
1268 if (copy_from_user(&bm, arg, sizeof(bm)))
1269 return -XFS_ERROR(EFAULT);
1270
1271 if (bm.bmv_count < 2)
1272 return -XFS_ERROR(EINVAL);
1273
1274 iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0);
1275 if (ioflags & IO_INVIS)
1276 iflags |= BMV_IF_NO_DMAPI_READ;
1277
Christoph Hellwig993386c2007-08-28 16:12:30 +10001278 error = xfs_getbmap(ip, &bm, (struct getbmap __user *)arg+1, iflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 if (error)
1280 return -error;
1281
1282 if (copy_to_user(arg, &bm, sizeof(bm)))
1283 return -XFS_ERROR(EFAULT);
1284 return 0;
1285}
1286
1287STATIC int
1288xfs_ioc_getbmapx(
Christoph Hellwig993386c2007-08-28 16:12:30 +10001289 struct xfs_inode *ip,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 void __user *arg)
1291{
1292 struct getbmapx bmx;
1293 struct getbmap bm;
1294 int iflags;
1295 int error;
1296
1297 if (copy_from_user(&bmx, arg, sizeof(bmx)))
1298 return -XFS_ERROR(EFAULT);
1299
1300 if (bmx.bmv_count < 2)
1301 return -XFS_ERROR(EINVAL);
1302
1303 /*
1304 * Map input getbmapx structure to a getbmap
1305 * structure for xfs_getbmap.
1306 */
1307 GETBMAP_CONVERT(bmx, bm);
1308
1309 iflags = bmx.bmv_iflags;
1310
1311 if (iflags & (~BMV_IF_VALID))
1312 return -XFS_ERROR(EINVAL);
1313
1314 iflags |= BMV_IF_EXTENDED;
1315
Christoph Hellwig993386c2007-08-28 16:12:30 +10001316 error = xfs_getbmap(ip, &bm, (struct getbmapx __user *)arg+1, iflags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 if (error)
1318 return -error;
1319
1320 GETBMAP_CONVERT(bm, bmx);
1321
1322 if (copy_to_user(arg, &bmx, sizeof(bmx)))
1323 return -XFS_ERROR(EFAULT);
1324
1325 return 0;
1326}
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001327
1328int
1329xfs_ioctl(
1330 xfs_inode_t *ip,
1331 struct file *filp,
1332 int ioflags,
1333 unsigned int cmd,
1334 void __user *arg)
1335{
1336 struct inode *inode = filp->f_path.dentry->d_inode;
1337 xfs_mount_t *mp = ip->i_mount;
1338 int error;
1339
1340 xfs_itrace_entry(XFS_I(inode));
1341 switch (cmd) {
1342
1343 case XFS_IOC_ALLOCSP:
1344 case XFS_IOC_FREESP:
1345 case XFS_IOC_RESVSP:
1346 case XFS_IOC_UNRESVSP:
1347 case XFS_IOC_ALLOCSP64:
1348 case XFS_IOC_FREESP64:
1349 case XFS_IOC_RESVSP64:
1350 case XFS_IOC_UNRESVSP64:
1351 /*
1352 * Only allow the sys admin to reserve space unless
1353 * unwritten extents are enabled.
1354 */
1355 if (!xfs_sb_version_hasextflgbit(&mp->m_sb) &&
1356 !capable(CAP_SYS_ADMIN))
1357 return -EPERM;
1358
1359 return xfs_ioc_space(ip, inode, filp, ioflags, cmd, arg);
1360
1361 case XFS_IOC_DIOINFO: {
1362 struct dioattr da;
1363 xfs_buftarg_t *target =
1364 XFS_IS_REALTIME_INODE(ip) ?
1365 mp->m_rtdev_targp : mp->m_ddev_targp;
1366
1367 da.d_mem = da.d_miniosz = 1 << target->bt_sshift;
1368 da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1);
1369
1370 if (copy_to_user(arg, &da, sizeof(da)))
1371 return -XFS_ERROR(EFAULT);
1372 return 0;
1373 }
1374
1375 case XFS_IOC_FSBULKSTAT_SINGLE:
1376 case XFS_IOC_FSBULKSTAT:
1377 case XFS_IOC_FSINUMBERS:
1378 return xfs_ioc_bulkstat(mp, cmd, arg);
1379
1380 case XFS_IOC_FSGEOMETRY_V1:
1381 return xfs_ioc_fsgeometry_v1(mp, arg);
1382
1383 case XFS_IOC_FSGEOMETRY:
1384 return xfs_ioc_fsgeometry(mp, arg);
1385
1386 case XFS_IOC_GETVERSION:
1387 return put_user(inode->i_generation, (int __user *)arg);
1388
1389 case XFS_IOC_FSGETXATTR:
1390 return xfs_ioc_fsgetxattr(ip, 0, arg);
1391 case XFS_IOC_FSGETXATTRA:
1392 return xfs_ioc_fsgetxattr(ip, 1, arg);
Lachlan McIlroy3b2816b2008-04-18 12:43:35 +10001393 case XFS_IOC_FSSETXATTR:
Lachlan McIlroy65e67f52008-04-18 12:59:45 +10001394 return xfs_ioc_fssetxattr(ip, filp, arg);
1395 case XFS_IOC_GETXFLAGS:
1396 return xfs_ioc_getxflags(ip, arg);
1397 case XFS_IOC_SETXFLAGS:
1398 return xfs_ioc_setxflags(ip, filp, arg);
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001399
1400 case XFS_IOC_FSSETDM: {
1401 struct fsdmidata dmi;
1402
1403 if (copy_from_user(&dmi, arg, sizeof(dmi)))
1404 return -XFS_ERROR(EFAULT);
1405
1406 error = xfs_set_dmattrs(ip, dmi.fsd_dmevmask,
1407 dmi.fsd_dmstate);
1408 return -error;
1409 }
1410
1411 case XFS_IOC_GETBMAP:
1412 case XFS_IOC_GETBMAPA:
1413 return xfs_ioc_getbmap(ip, ioflags, cmd, arg);
1414
1415 case XFS_IOC_GETBMAPX:
1416 return xfs_ioc_getbmapx(ip, arg);
1417
1418 case XFS_IOC_FD_TO_HANDLE:
1419 case XFS_IOC_PATH_TO_HANDLE:
1420 case XFS_IOC_PATH_TO_FSHANDLE:
1421 return xfs_find_handle(cmd, arg);
1422
1423 case XFS_IOC_OPEN_BY_HANDLE:
1424 return xfs_open_by_handle(mp, arg, filp, inode);
1425
1426 case XFS_IOC_FSSETDM_BY_HANDLE:
1427 return xfs_fssetdm_by_handle(mp, arg, inode);
1428
1429 case XFS_IOC_READLINK_BY_HANDLE:
1430 return xfs_readlink_by_handle(mp, arg, inode);
1431
1432 case XFS_IOC_ATTRLIST_BY_HANDLE:
1433 return xfs_attrlist_by_handle(mp, arg, inode);
1434
1435 case XFS_IOC_ATTRMULTI_BY_HANDLE:
Dave Hansen42a74f22008-02-15 14:37:46 -08001436 return xfs_attrmulti_by_handle(mp, arg, filp, inode);
Lachlan McIlroydf26cfe2008-04-18 11:44:03 +10001437
1438 case XFS_IOC_SWAPEXT: {
1439 error = xfs_swapext((struct xfs_swapext __user *)arg);
1440 return -error;
1441 }
1442
1443 case XFS_IOC_FSCOUNTS: {
1444 xfs_fsop_counts_t out;
1445
1446 error = xfs_fs_counts(mp, &out);
1447 if (error)
1448 return -error;
1449
1450 if (copy_to_user(arg, &out, sizeof(out)))
1451 return -XFS_ERROR(EFAULT);
1452 return 0;
1453 }
1454
1455 case XFS_IOC_SET_RESBLKS: {
1456 xfs_fsop_resblks_t inout;
1457 __uint64_t in;
1458
1459 if (!capable(CAP_SYS_ADMIN))
1460 return -EPERM;
1461
1462 if (copy_from_user(&inout, arg, sizeof(inout)))
1463 return -XFS_ERROR(EFAULT);
1464
1465 /* input parameter is passed in resblks field of structure */
1466 in = inout.resblks;
1467 error = xfs_reserve_blocks(mp, &in, &inout);
1468 if (error)
1469 return -error;
1470
1471 if (copy_to_user(arg, &inout, sizeof(inout)))
1472 return -XFS_ERROR(EFAULT);
1473 return 0;
1474 }
1475
1476 case XFS_IOC_GET_RESBLKS: {
1477 xfs_fsop_resblks_t out;
1478
1479 if (!capable(CAP_SYS_ADMIN))
1480 return -EPERM;
1481
1482 error = xfs_reserve_blocks(mp, NULL, &out);
1483 if (error)
1484 return -error;
1485
1486 if (copy_to_user(arg, &out, sizeof(out)))
1487 return -XFS_ERROR(EFAULT);
1488
1489 return 0;
1490 }
1491
1492 case XFS_IOC_FSGROWFSDATA: {
1493 xfs_growfs_data_t in;
1494
1495 if (!capable(CAP_SYS_ADMIN))
1496 return -EPERM;
1497
1498 if (copy_from_user(&in, arg, sizeof(in)))
1499 return -XFS_ERROR(EFAULT);
1500
1501 error = xfs_growfs_data(mp, &in);
1502 return -error;
1503 }
1504
1505 case XFS_IOC_FSGROWFSLOG: {
1506 xfs_growfs_log_t in;
1507
1508 if (!capable(CAP_SYS_ADMIN))
1509 return -EPERM;
1510
1511 if (copy_from_user(&in, arg, sizeof(in)))
1512 return -XFS_ERROR(EFAULT);
1513
1514 error = xfs_growfs_log(mp, &in);
1515 return -error;
1516 }
1517
1518 case XFS_IOC_FSGROWFSRT: {
1519 xfs_growfs_rt_t in;
1520
1521 if (!capable(CAP_SYS_ADMIN))
1522 return -EPERM;
1523
1524 if (copy_from_user(&in, arg, sizeof(in)))
1525 return -XFS_ERROR(EFAULT);
1526
1527 error = xfs_growfs_rt(mp, &in);
1528 return -error;
1529 }
1530
1531 case XFS_IOC_FREEZE:
1532 if (!capable(CAP_SYS_ADMIN))
1533 return -EPERM;
1534
1535 if (inode->i_sb->s_frozen == SB_UNFROZEN)
1536 freeze_bdev(inode->i_sb->s_bdev);
1537 return 0;
1538
1539 case XFS_IOC_THAW:
1540 if (!capable(CAP_SYS_ADMIN))
1541 return -EPERM;
1542 if (inode->i_sb->s_frozen != SB_UNFROZEN)
1543 thaw_bdev(inode->i_sb->s_bdev, inode->i_sb);
1544 return 0;
1545
1546 case XFS_IOC_GOINGDOWN: {
1547 __uint32_t in;
1548
1549 if (!capable(CAP_SYS_ADMIN))
1550 return -EPERM;
1551
1552 if (get_user(in, (__uint32_t __user *)arg))
1553 return -XFS_ERROR(EFAULT);
1554
1555 error = xfs_fs_goingdown(mp, in);
1556 return -error;
1557 }
1558
1559 case XFS_IOC_ERROR_INJECTION: {
1560 xfs_error_injection_t in;
1561
1562 if (!capable(CAP_SYS_ADMIN))
1563 return -EPERM;
1564
1565 if (copy_from_user(&in, arg, sizeof(in)))
1566 return -XFS_ERROR(EFAULT);
1567
1568 error = xfs_errortag_add(in.errtag, mp);
1569 return -error;
1570 }
1571
1572 case XFS_IOC_ERROR_CLEARALL:
1573 if (!capable(CAP_SYS_ADMIN))
1574 return -EPERM;
1575
1576 error = xfs_errortag_clearall(mp, 1);
1577 return -error;
1578
1579 default:
1580 return -ENOTTY;
1581 }
1582}