init from v2.6.32.60
[mach-moxart.git] / fs / xfs / linux-2.6 / xfs_ioctl.c
blob942362fa9c7a56f97f2b23724604d2bdfd411bab
1 /*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
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
7 * published by the Free Software Foundation.
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.
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
18 #include "xfs.h"
19 #include "xfs_fs.h"
20 #include "xfs_bit.h"
21 #include "xfs_log.h"
22 #include "xfs_inum.h"
23 #include "xfs_trans.h"
24 #include "xfs_sb.h"
25 #include "xfs_ag.h"
26 #include "xfs_dir2.h"
27 #include "xfs_alloc.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_mount.h"
30 #include "xfs_bmap_btree.h"
31 #include "xfs_alloc_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_attr_sf.h"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_dinode.h"
36 #include "xfs_inode.h"
37 #include "xfs_ioctl.h"
38 #include "xfs_btree.h"
39 #include "xfs_ialloc.h"
40 #include "xfs_rtalloc.h"
41 #include "xfs_itable.h"
42 #include "xfs_error.h"
43 #include "xfs_rw.h"
44 #include "xfs_attr.h"
45 #include "xfs_bmap.h"
46 #include "xfs_buf_item.h"
47 #include "xfs_utils.h"
48 #include "xfs_dfrag.h"
49 #include "xfs_fsops.h"
50 #include "xfs_vnodeops.h"
51 #include "xfs_quota.h"
52 #include "xfs_inode_item.h"
53 #include "xfs_export.h"
55 #include <linux/capability.h>
56 #include <linux/dcache.h>
57 #include <linux/mount.h>
58 #include <linux/namei.h>
59 #include <linux/pagemap.h>
60 #include <linux/exportfs.h>
63 * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to
64 * a file or fs handle.
66 * XFS_IOC_PATH_TO_FSHANDLE
67 * returns fs handle for a mount point or path within that mount point
68 * XFS_IOC_FD_TO_HANDLE
69 * returns full handle for a FD opened in user space
70 * XFS_IOC_PATH_TO_HANDLE
71 * returns full handle for a path
73 int
74 xfs_find_handle(
75 unsigned int cmd,
76 xfs_fsop_handlereq_t *hreq)
78 int hsize;
79 xfs_handle_t handle;
80 struct inode *inode;
81 struct file *file = NULL;
82 struct path path;
83 int error;
84 struct xfs_inode *ip;
86 if (cmd == XFS_IOC_FD_TO_HANDLE) {
87 file = fget(hreq->fd);
88 if (!file)
89 return -EBADF;
90 inode = file->f_path.dentry->d_inode;
91 } else {
92 error = user_lpath((const char __user *)hreq->path, &path);
93 if (error)
94 return error;
95 inode = path.dentry->d_inode;
97 ip = XFS_I(inode);
100 * We can only generate handles for inodes residing on a XFS filesystem,
101 * and only for regular files, directories or symbolic links.
103 error = -EINVAL;
104 if (inode->i_sb->s_magic != XFS_SB_MAGIC)
105 goto out_put;
107 error = -EBADF;
108 if (!S_ISREG(inode->i_mode) &&
109 !S_ISDIR(inode->i_mode) &&
110 !S_ISLNK(inode->i_mode))
111 goto out_put;
114 memcpy(&handle.ha_fsid, ip->i_mount->m_fixedfsid, sizeof(xfs_fsid_t));
116 if (cmd == XFS_IOC_PATH_TO_FSHANDLE) {
118 * This handle only contains an fsid, zero the rest.
120 memset(&handle.ha_fid, 0, sizeof(handle.ha_fid));
121 hsize = sizeof(xfs_fsid_t);
122 } else {
123 int lock_mode;
125 lock_mode = xfs_ilock_map_shared(ip);
126 handle.ha_fid.fid_len = sizeof(xfs_fid_t) -
127 sizeof(handle.ha_fid.fid_len);
128 handle.ha_fid.fid_pad = 0;
129 handle.ha_fid.fid_gen = ip->i_d.di_gen;
130 handle.ha_fid.fid_ino = ip->i_ino;
131 xfs_iunlock_map_shared(ip, lock_mode);
133 hsize = XFS_HSIZE(handle);
136 error = -EFAULT;
137 if (copy_to_user(hreq->ohandle, &handle, hsize) ||
138 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
139 goto out_put;
141 error = 0;
143 out_put:
144 if (cmd == XFS_IOC_FD_TO_HANDLE)
145 fput(file);
146 else
147 path_put(&path);
148 return error;
152 * No need to do permission checks on the various pathname components
153 * as the handle operations are privileged.
155 STATIC int
156 xfs_handle_acceptable(
157 void *context,
158 struct dentry *dentry)
160 return 1;
164 * Convert userspace handle data into a dentry.
166 struct dentry *
167 xfs_handle_to_dentry(
168 struct file *parfilp,
169 void __user *uhandle,
170 u32 hlen)
172 xfs_handle_t handle;
173 struct xfs_fid64 fid;
176 * Only allow handle opens under a directory.
178 if (!S_ISDIR(parfilp->f_path.dentry->d_inode->i_mode))
179 return ERR_PTR(-ENOTDIR);
181 if (hlen != sizeof(xfs_handle_t))
182 return ERR_PTR(-EINVAL);
183 if (copy_from_user(&handle, uhandle, hlen))
184 return ERR_PTR(-EFAULT);
185 if (handle.ha_fid.fid_len !=
186 sizeof(handle.ha_fid) - sizeof(handle.ha_fid.fid_len))
187 return ERR_PTR(-EINVAL);
189 memset(&fid, 0, sizeof(struct fid));
190 fid.ino = handle.ha_fid.fid_ino;
191 fid.gen = handle.ha_fid.fid_gen;
193 return exportfs_decode_fh(parfilp->f_path.mnt, (struct fid *)&fid, 3,
194 FILEID_INO32_GEN | XFS_FILEID_TYPE_64FLAG,
195 xfs_handle_acceptable, NULL);
198 STATIC struct dentry *
199 xfs_handlereq_to_dentry(
200 struct file *parfilp,
201 xfs_fsop_handlereq_t *hreq)
203 return xfs_handle_to_dentry(parfilp, hreq->ihandle, hreq->ihandlen);
207 xfs_open_by_handle(
208 struct file *parfilp,
209 xfs_fsop_handlereq_t *hreq)
211 const struct cred *cred = current_cred();
212 int error;
213 int fd;
214 int permflag;
215 struct file *filp;
216 struct inode *inode;
217 struct dentry *dentry;
219 if (!capable(CAP_SYS_ADMIN))
220 return -XFS_ERROR(EPERM);
222 dentry = xfs_handlereq_to_dentry(parfilp, hreq);
223 if (IS_ERR(dentry))
224 return PTR_ERR(dentry);
225 inode = dentry->d_inode;
227 /* Restrict xfs_open_by_handle to directories & regular files. */
228 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
229 error = -XFS_ERROR(EPERM);
230 goto out_dput;
233 #if BITS_PER_LONG != 32
234 hreq->oflags |= O_LARGEFILE;
235 #endif
237 /* Put open permission in namei format. */
238 permflag = hreq->oflags;
239 if ((permflag+1) & O_ACCMODE)
240 permflag++;
241 if (permflag & O_TRUNC)
242 permflag |= 2;
244 if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
245 (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
246 error = -XFS_ERROR(EPERM);
247 goto out_dput;
250 if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
251 error = -XFS_ERROR(EACCES);
252 goto out_dput;
255 /* Can't write directories. */
256 if (S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
257 error = -XFS_ERROR(EISDIR);
258 goto out_dput;
261 fd = get_unused_fd();
262 if (fd < 0) {
263 error = fd;
264 goto out_dput;
267 filp = dentry_open(dentry, mntget(parfilp->f_path.mnt),
268 hreq->oflags, cred);
269 if (IS_ERR(filp)) {
270 put_unused_fd(fd);
271 return PTR_ERR(filp);
274 if (inode->i_mode & S_IFREG) {
275 filp->f_flags |= O_NOATIME;
276 filp->f_mode |= FMODE_NOCMTIME;
279 fd_install(fd, filp);
280 return fd;
282 out_dput:
283 dput(dentry);
284 return error;
288 * This is a copy from fs/namei.c:vfs_readlink(), except for removing it's
289 * unused first argument.
291 STATIC int
292 do_readlink(
293 char __user *buffer,
294 int buflen,
295 const char *link)
297 int len;
299 len = PTR_ERR(link);
300 if (IS_ERR(link))
301 goto out;
303 len = strlen(link);
304 if (len > (unsigned) buflen)
305 len = buflen;
306 if (copy_to_user(buffer, link, len))
307 len = -EFAULT;
308 out:
309 return len;
314 xfs_readlink_by_handle(
315 struct file *parfilp,
316 xfs_fsop_handlereq_t *hreq)
318 struct dentry *dentry;
319 __u32 olen;
320 void *link;
321 int error;
323 if (!capable(CAP_SYS_ADMIN))
324 return -XFS_ERROR(EPERM);
326 dentry = xfs_handlereq_to_dentry(parfilp, hreq);
327 if (IS_ERR(dentry))
328 return PTR_ERR(dentry);
330 /* Restrict this handle operation to symlinks only. */
331 if (!S_ISLNK(dentry->d_inode->i_mode)) {
332 error = -XFS_ERROR(EINVAL);
333 goto out_dput;
336 if (copy_from_user(&olen, hreq->ohandlen, sizeof(__u32))) {
337 error = -XFS_ERROR(EFAULT);
338 goto out_dput;
341 link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
342 if (!link) {
343 error = -XFS_ERROR(ENOMEM);
344 goto out_dput;
347 error = -xfs_readlink(XFS_I(dentry->d_inode), link);
348 if (error)
349 goto out_kfree;
350 error = do_readlink(hreq->ohandle, olen, link);
351 if (error)
352 goto out_kfree;
354 out_kfree:
355 kfree(link);
356 out_dput:
357 dput(dentry);
358 return error;
361 STATIC int
362 xfs_fssetdm_by_handle(
363 struct file *parfilp,
364 void __user *arg)
366 int error;
367 struct fsdmidata fsd;
368 xfs_fsop_setdm_handlereq_t dmhreq;
369 struct dentry *dentry;
371 if (!capable(CAP_MKNOD))
372 return -XFS_ERROR(EPERM);
373 if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t)))
374 return -XFS_ERROR(EFAULT);
376 dentry = xfs_handlereq_to_dentry(parfilp, &dmhreq.hreq);
377 if (IS_ERR(dentry))
378 return PTR_ERR(dentry);
380 if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode)) {
381 error = -XFS_ERROR(EPERM);
382 goto out;
385 if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
386 error = -XFS_ERROR(EFAULT);
387 goto out;
390 error = -xfs_set_dmattrs(XFS_I(dentry->d_inode), fsd.fsd_dmevmask,
391 fsd.fsd_dmstate);
393 out:
394 dput(dentry);
395 return error;
398 STATIC int
399 xfs_attrlist_by_handle(
400 struct file *parfilp,
401 void __user *arg)
403 int error = -ENOMEM;
404 attrlist_cursor_kern_t *cursor;
405 xfs_fsop_attrlist_handlereq_t al_hreq;
406 struct dentry *dentry;
407 char *kbuf;
409 if (!capable(CAP_SYS_ADMIN))
410 return -XFS_ERROR(EPERM);
411 if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t)))
412 return -XFS_ERROR(EFAULT);
413 if (al_hreq.buflen > XATTR_LIST_MAX)
414 return -XFS_ERROR(EINVAL);
417 * Reject flags, only allow namespaces.
419 if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE))
420 return -XFS_ERROR(EINVAL);
422 dentry = xfs_handlereq_to_dentry(parfilp, &al_hreq.hreq);
423 if (IS_ERR(dentry))
424 return PTR_ERR(dentry);
426 kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
427 if (!kbuf)
428 goto out_dput;
430 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
431 error = -xfs_attr_list(XFS_I(dentry->d_inode), kbuf, al_hreq.buflen,
432 al_hreq.flags, cursor);
433 if (error)
434 goto out_kfree;
436 if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen))
437 error = -EFAULT;
439 out_kfree:
440 kfree(kbuf);
441 out_dput:
442 dput(dentry);
443 return error;
447 xfs_attrmulti_attr_get(
448 struct inode *inode,
449 char *name,
450 char __user *ubuf,
451 __uint32_t *len,
452 __uint32_t flags)
454 char *kbuf;
455 int error = EFAULT;
457 if (*len > XATTR_SIZE_MAX)
458 return EINVAL;
459 kbuf = kmalloc(*len, GFP_KERNEL);
460 if (!kbuf)
461 return ENOMEM;
463 error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags);
464 if (error)
465 goto out_kfree;
467 if (copy_to_user(ubuf, kbuf, *len))
468 error = EFAULT;
470 out_kfree:
471 kfree(kbuf);
472 return error;
476 xfs_attrmulti_attr_set(
477 struct inode *inode,
478 char *name,
479 const char __user *ubuf,
480 __uint32_t len,
481 __uint32_t flags)
483 char *kbuf;
484 int error = EFAULT;
486 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
487 return EPERM;
488 if (len > XATTR_SIZE_MAX)
489 return EINVAL;
491 kbuf = memdup_user(ubuf, len);
492 if (IS_ERR(kbuf))
493 return PTR_ERR(kbuf);
495 error = xfs_attr_set(XFS_I(inode), name, kbuf, len, flags);
497 return error;
501 xfs_attrmulti_attr_remove(
502 struct inode *inode,
503 char *name,
504 __uint32_t flags)
506 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
507 return EPERM;
508 return xfs_attr_remove(XFS_I(inode), name, flags);
511 STATIC int
512 xfs_attrmulti_by_handle(
513 struct file *parfilp,
514 void __user *arg)
516 int error;
517 xfs_attr_multiop_t *ops;
518 xfs_fsop_attrmulti_handlereq_t am_hreq;
519 struct dentry *dentry;
520 unsigned int i, size;
521 char *attr_name;
523 if (!capable(CAP_SYS_ADMIN))
524 return -XFS_ERROR(EPERM);
525 if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t)))
526 return -XFS_ERROR(EFAULT);
528 dentry = xfs_handlereq_to_dentry(parfilp, &am_hreq.hreq);
529 if (IS_ERR(dentry))
530 return PTR_ERR(dentry);
532 error = E2BIG;
533 size = am_hreq.opcount * sizeof(xfs_attr_multiop_t);
534 if (!size || size > 16 * PAGE_SIZE)
535 goto out_dput;
537 ops = memdup_user(am_hreq.ops, size);
538 if (IS_ERR(ops)) {
539 error = PTR_ERR(ops);
540 goto out_dput;
543 attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
544 if (!attr_name)
545 goto out_kfree_ops;
547 error = 0;
548 for (i = 0; i < am_hreq.opcount; i++) {
549 ops[i].am_error = strncpy_from_user(attr_name,
550 ops[i].am_attrname, MAXNAMELEN);
551 if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
552 error = -ERANGE;
553 if (ops[i].am_error < 0)
554 break;
556 switch (ops[i].am_opcode) {
557 case ATTR_OP_GET:
558 ops[i].am_error = xfs_attrmulti_attr_get(
559 dentry->d_inode, attr_name,
560 ops[i].am_attrvalue, &ops[i].am_length,
561 ops[i].am_flags);
562 break;
563 case ATTR_OP_SET:
564 ops[i].am_error = mnt_want_write(parfilp->f_path.mnt);
565 if (ops[i].am_error)
566 break;
567 ops[i].am_error = xfs_attrmulti_attr_set(
568 dentry->d_inode, attr_name,
569 ops[i].am_attrvalue, ops[i].am_length,
570 ops[i].am_flags);
571 mnt_drop_write(parfilp->f_path.mnt);
572 break;
573 case ATTR_OP_REMOVE:
574 ops[i].am_error = mnt_want_write(parfilp->f_path.mnt);
575 if (ops[i].am_error)
576 break;
577 ops[i].am_error = xfs_attrmulti_attr_remove(
578 dentry->d_inode, attr_name,
579 ops[i].am_flags);
580 mnt_drop_write(parfilp->f_path.mnt);
581 break;
582 default:
583 ops[i].am_error = EINVAL;
587 if (copy_to_user(am_hreq.ops, ops, size))
588 error = XFS_ERROR(EFAULT);
590 kfree(attr_name);
591 out_kfree_ops:
592 kfree(ops);
593 out_dput:
594 dput(dentry);
595 return -error;
599 xfs_ioc_space(
600 struct xfs_inode *ip,
601 struct inode *inode,
602 struct file *filp,
603 int ioflags,
604 unsigned int cmd,
605 xfs_flock64_t *bf)
607 int attr_flags = 0;
608 int error;
611 * Only allow the sys admin to reserve space unless
612 * unwritten extents are enabled.
614 if (!xfs_sb_version_hasextflgbit(&ip->i_mount->m_sb) &&
615 !capable(CAP_SYS_ADMIN))
616 return -XFS_ERROR(EPERM);
618 if (inode->i_flags & (S_IMMUTABLE|S_APPEND))
619 return -XFS_ERROR(EPERM);
621 if (!(filp->f_mode & FMODE_WRITE))
622 return -XFS_ERROR(EBADF);
624 if (!S_ISREG(inode->i_mode))
625 return -XFS_ERROR(EINVAL);
627 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
628 attr_flags |= XFS_ATTR_NONBLOCK;
629 if (ioflags & IO_INVIS)
630 attr_flags |= XFS_ATTR_DMI;
632 error = xfs_change_file_space(ip, cmd, bf, filp->f_pos, attr_flags);
633 return -error;
636 STATIC int
637 xfs_ioc_bulkstat(
638 xfs_mount_t *mp,
639 unsigned int cmd,
640 void __user *arg)
642 xfs_fsop_bulkreq_t bulkreq;
643 int count; /* # of records returned */
644 xfs_ino_t inlast; /* last inode number */
645 int done;
646 int error;
648 /* done = 1 if there are more stats to get and if bulkstat */
649 /* should be called again (unused here, but used in dmapi) */
651 if (!capable(CAP_SYS_ADMIN))
652 return -EPERM;
654 if (XFS_FORCED_SHUTDOWN(mp))
655 return -XFS_ERROR(EIO);
657 if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t)))
658 return -XFS_ERROR(EFAULT);
660 if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
661 return -XFS_ERROR(EFAULT);
663 if ((count = bulkreq.icount) <= 0)
664 return -XFS_ERROR(EINVAL);
666 if (bulkreq.ubuffer == NULL)
667 return -XFS_ERROR(EINVAL);
669 if (cmd == XFS_IOC_FSINUMBERS)
670 error = xfs_inumbers(mp, &inlast, &count,
671 bulkreq.ubuffer, xfs_inumbers_fmt);
672 else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE)
673 error = xfs_bulkstat_single(mp, &inlast,
674 bulkreq.ubuffer, &done);
675 else /* XFS_IOC_FSBULKSTAT */
676 error = xfs_bulkstat(mp, &inlast, &count, xfs_bulkstat_one,
677 sizeof(xfs_bstat_t), bulkreq.ubuffer,
678 &done);
680 if (error)
681 return -error;
683 if (bulkreq.ocount != NULL) {
684 if (copy_to_user(bulkreq.lastip, &inlast,
685 sizeof(xfs_ino_t)))
686 return -XFS_ERROR(EFAULT);
688 if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
689 return -XFS_ERROR(EFAULT);
692 return 0;
695 STATIC int
696 xfs_ioc_fsgeometry_v1(
697 xfs_mount_t *mp,
698 void __user *arg)
700 xfs_fsop_geom_t fsgeo;
701 int error;
703 error = xfs_fs_geometry(mp, &fsgeo, 3);
704 if (error)
705 return -error;
708 * Caller should have passed an argument of type
709 * xfs_fsop_geom_v1_t. This is a proper subset of the
710 * xfs_fsop_geom_t that xfs_fs_geometry() fills in.
712 if (copy_to_user(arg, &fsgeo, sizeof(xfs_fsop_geom_v1_t)))
713 return -XFS_ERROR(EFAULT);
714 return 0;
717 STATIC int
718 xfs_ioc_fsgeometry(
719 xfs_mount_t *mp,
720 void __user *arg)
722 xfs_fsop_geom_t fsgeo;
723 int error;
725 error = xfs_fs_geometry(mp, &fsgeo, 4);
726 if (error)
727 return -error;
729 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
730 return -XFS_ERROR(EFAULT);
731 return 0;
735 * Linux extended inode flags interface.
738 STATIC unsigned int
739 xfs_merge_ioc_xflags(
740 unsigned int flags,
741 unsigned int start)
743 unsigned int xflags = start;
745 if (flags & FS_IMMUTABLE_FL)
746 xflags |= XFS_XFLAG_IMMUTABLE;
747 else
748 xflags &= ~XFS_XFLAG_IMMUTABLE;
749 if (flags & FS_APPEND_FL)
750 xflags |= XFS_XFLAG_APPEND;
751 else
752 xflags &= ~XFS_XFLAG_APPEND;
753 if (flags & FS_SYNC_FL)
754 xflags |= XFS_XFLAG_SYNC;
755 else
756 xflags &= ~XFS_XFLAG_SYNC;
757 if (flags & FS_NOATIME_FL)
758 xflags |= XFS_XFLAG_NOATIME;
759 else
760 xflags &= ~XFS_XFLAG_NOATIME;
761 if (flags & FS_NODUMP_FL)
762 xflags |= XFS_XFLAG_NODUMP;
763 else
764 xflags &= ~XFS_XFLAG_NODUMP;
766 return xflags;
769 STATIC unsigned int
770 xfs_di2lxflags(
771 __uint16_t di_flags)
773 unsigned int flags = 0;
775 if (di_flags & XFS_DIFLAG_IMMUTABLE)
776 flags |= FS_IMMUTABLE_FL;
777 if (di_flags & XFS_DIFLAG_APPEND)
778 flags |= FS_APPEND_FL;
779 if (di_flags & XFS_DIFLAG_SYNC)
780 flags |= FS_SYNC_FL;
781 if (di_flags & XFS_DIFLAG_NOATIME)
782 flags |= FS_NOATIME_FL;
783 if (di_flags & XFS_DIFLAG_NODUMP)
784 flags |= FS_NODUMP_FL;
785 return flags;
788 STATIC int
789 xfs_ioc_fsgetxattr(
790 xfs_inode_t *ip,
791 int attr,
792 void __user *arg)
794 struct fsxattr fa;
796 memset(&fa, 0, sizeof(struct fsxattr));
798 xfs_ilock(ip, XFS_ILOCK_SHARED);
799 fa.fsx_xflags = xfs_ip2xflags(ip);
800 fa.fsx_extsize = ip->i_d.di_extsize << ip->i_mount->m_sb.sb_blocklog;
801 fa.fsx_projid = ip->i_d.di_projid;
803 if (attr) {
804 if (ip->i_afp) {
805 if (ip->i_afp->if_flags & XFS_IFEXTENTS)
806 fa.fsx_nextents = ip->i_afp->if_bytes /
807 sizeof(xfs_bmbt_rec_t);
808 else
809 fa.fsx_nextents = ip->i_d.di_anextents;
810 } else
811 fa.fsx_nextents = 0;
812 } else {
813 if (ip->i_df.if_flags & XFS_IFEXTENTS)
814 fa.fsx_nextents = ip->i_df.if_bytes /
815 sizeof(xfs_bmbt_rec_t);
816 else
817 fa.fsx_nextents = ip->i_d.di_nextents;
819 xfs_iunlock(ip, XFS_ILOCK_SHARED);
821 if (copy_to_user(arg, &fa, sizeof(fa)))
822 return -EFAULT;
823 return 0;
826 STATIC void
827 xfs_set_diflags(
828 struct xfs_inode *ip,
829 unsigned int xflags)
831 unsigned int di_flags;
833 /* can't set PREALLOC this way, just preserve it */
834 di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
835 if (xflags & XFS_XFLAG_IMMUTABLE)
836 di_flags |= XFS_DIFLAG_IMMUTABLE;
837 if (xflags & XFS_XFLAG_APPEND)
838 di_flags |= XFS_DIFLAG_APPEND;
839 if (xflags & XFS_XFLAG_SYNC)
840 di_flags |= XFS_DIFLAG_SYNC;
841 if (xflags & XFS_XFLAG_NOATIME)
842 di_flags |= XFS_DIFLAG_NOATIME;
843 if (xflags & XFS_XFLAG_NODUMP)
844 di_flags |= XFS_DIFLAG_NODUMP;
845 if (xflags & XFS_XFLAG_PROJINHERIT)
846 di_flags |= XFS_DIFLAG_PROJINHERIT;
847 if (xflags & XFS_XFLAG_NODEFRAG)
848 di_flags |= XFS_DIFLAG_NODEFRAG;
849 if (xflags & XFS_XFLAG_FILESTREAM)
850 di_flags |= XFS_DIFLAG_FILESTREAM;
851 if ((ip->i_d.di_mode & S_IFMT) == S_IFDIR) {
852 if (xflags & XFS_XFLAG_RTINHERIT)
853 di_flags |= XFS_DIFLAG_RTINHERIT;
854 if (xflags & XFS_XFLAG_NOSYMLINKS)
855 di_flags |= XFS_DIFLAG_NOSYMLINKS;
856 if (xflags & XFS_XFLAG_EXTSZINHERIT)
857 di_flags |= XFS_DIFLAG_EXTSZINHERIT;
858 } else if ((ip->i_d.di_mode & S_IFMT) == S_IFREG) {
859 if (xflags & XFS_XFLAG_REALTIME)
860 di_flags |= XFS_DIFLAG_REALTIME;
861 if (xflags & XFS_XFLAG_EXTSIZE)
862 di_flags |= XFS_DIFLAG_EXTSIZE;
865 ip->i_d.di_flags = di_flags;
868 STATIC void
869 xfs_diflags_to_linux(
870 struct xfs_inode *ip)
872 struct inode *inode = VFS_I(ip);
873 unsigned int xflags = xfs_ip2xflags(ip);
875 if (xflags & XFS_XFLAG_IMMUTABLE)
876 inode->i_flags |= S_IMMUTABLE;
877 else
878 inode->i_flags &= ~S_IMMUTABLE;
879 if (xflags & XFS_XFLAG_APPEND)
880 inode->i_flags |= S_APPEND;
881 else
882 inode->i_flags &= ~S_APPEND;
883 if (xflags & XFS_XFLAG_SYNC)
884 inode->i_flags |= S_SYNC;
885 else
886 inode->i_flags &= ~S_SYNC;
887 if (xflags & XFS_XFLAG_NOATIME)
888 inode->i_flags |= S_NOATIME;
889 else
890 inode->i_flags &= ~S_NOATIME;
893 #define FSX_PROJID 1
894 #define FSX_EXTSIZE 2
895 #define FSX_XFLAGS 4
896 #define FSX_NONBLOCK 8
898 STATIC int
899 xfs_ioctl_setattr(
900 xfs_inode_t *ip,
901 struct fsxattr *fa,
902 int mask)
904 struct xfs_mount *mp = ip->i_mount;
905 struct xfs_trans *tp;
906 unsigned int lock_flags = 0;
907 struct xfs_dquot *udqp = NULL;
908 struct xfs_dquot *gdqp = NULL;
909 struct xfs_dquot *olddquot = NULL;
910 int code;
912 xfs_itrace_entry(ip);
914 if (mp->m_flags & XFS_MOUNT_RDONLY)
915 return XFS_ERROR(EROFS);
916 if (XFS_FORCED_SHUTDOWN(mp))
917 return XFS_ERROR(EIO);
920 * If disk quotas is on, we make sure that the dquots do exist on disk,
921 * before we start any other transactions. Trying to do this later
922 * is messy. We don't care to take a readlock to look at the ids
923 * in inode here, because we can't hold it across the trans_reserve.
924 * If the IDs do change before we take the ilock, we're covered
925 * because the i_*dquot fields will get updated anyway.
927 if (XFS_IS_QUOTA_ON(mp) && (mask & FSX_PROJID)) {
928 code = xfs_qm_vop_dqalloc(ip, ip->i_d.di_uid,
929 ip->i_d.di_gid, fa->fsx_projid,
930 XFS_QMOPT_PQUOTA, &udqp, &gdqp);
931 if (code)
932 return code;
936 * For the other attributes, we acquire the inode lock and
937 * first do an error checking pass.
939 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
940 code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
941 if (code)
942 goto error_return;
944 lock_flags = XFS_ILOCK_EXCL;
945 xfs_ilock(ip, lock_flags);
948 * CAP_FOWNER overrides the following restrictions:
950 * The user ID of the calling process must be equal
951 * to the file owner ID, except in cases where the
952 * CAP_FSETID capability is applicable.
954 if (current_fsuid() != ip->i_d.di_uid && !capable(CAP_FOWNER)) {
955 code = XFS_ERROR(EPERM);
956 goto error_return;
960 * Do a quota reservation only if projid is actually going to change.
962 if (mask & FSX_PROJID) {
963 if (XFS_IS_QUOTA_RUNNING(mp) &&
964 XFS_IS_PQUOTA_ON(mp) &&
965 ip->i_d.di_projid != fa->fsx_projid) {
966 ASSERT(tp);
967 code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
968 capable(CAP_FOWNER) ?
969 XFS_QMOPT_FORCE_RES : 0);
970 if (code) /* out of quota */
971 goto error_return;
975 if (mask & FSX_EXTSIZE) {
977 * Can't change extent size if any extents are allocated.
979 if (ip->i_d.di_nextents &&
980 ((ip->i_d.di_extsize << mp->m_sb.sb_blocklog) !=
981 fa->fsx_extsize)) {
982 code = XFS_ERROR(EINVAL); /* EFBIG? */
983 goto error_return;
987 * Extent size must be a multiple of the appropriate block
988 * size, if set at all.
990 if (fa->fsx_extsize != 0) {
991 xfs_extlen_t size;
993 if (XFS_IS_REALTIME_INODE(ip) ||
994 ((mask & FSX_XFLAGS) &&
995 (fa->fsx_xflags & XFS_XFLAG_REALTIME))) {
996 size = mp->m_sb.sb_rextsize <<
997 mp->m_sb.sb_blocklog;
998 } else {
999 size = mp->m_sb.sb_blocksize;
1002 if (fa->fsx_extsize % size) {
1003 code = XFS_ERROR(EINVAL);
1004 goto error_return;
1010 if (mask & FSX_XFLAGS) {
1012 * Can't change realtime flag if any extents are allocated.
1014 if ((ip->i_d.di_nextents || ip->i_delayed_blks) &&
1015 (XFS_IS_REALTIME_INODE(ip)) !=
1016 (fa->fsx_xflags & XFS_XFLAG_REALTIME)) {
1017 code = XFS_ERROR(EINVAL); /* EFBIG? */
1018 goto error_return;
1022 * If realtime flag is set then must have realtime data.
1024 if ((fa->fsx_xflags & XFS_XFLAG_REALTIME)) {
1025 if ((mp->m_sb.sb_rblocks == 0) ||
1026 (mp->m_sb.sb_rextsize == 0) ||
1027 (ip->i_d.di_extsize % mp->m_sb.sb_rextsize)) {
1028 code = XFS_ERROR(EINVAL);
1029 goto error_return;
1034 * Can't modify an immutable/append-only file unless
1035 * we have appropriate permission.
1037 if ((ip->i_d.di_flags &
1038 (XFS_DIFLAG_IMMUTABLE|XFS_DIFLAG_APPEND) ||
1039 (fa->fsx_xflags &
1040 (XFS_XFLAG_IMMUTABLE | XFS_XFLAG_APPEND))) &&
1041 !capable(CAP_LINUX_IMMUTABLE)) {
1042 code = XFS_ERROR(EPERM);
1043 goto error_return;
1047 xfs_trans_ijoin(tp, ip, lock_flags);
1048 xfs_trans_ihold(tp, ip);
1051 * Change file ownership. Must be the owner or privileged.
1053 if (mask & FSX_PROJID) {
1055 * CAP_FSETID overrides the following restrictions:
1057 * The set-user-ID and set-group-ID bits of a file will be
1058 * cleared upon successful return from chown()
1060 if ((ip->i_d.di_mode & (S_ISUID|S_ISGID)) &&
1061 !capable(CAP_FSETID))
1062 ip->i_d.di_mode &= ~(S_ISUID|S_ISGID);
1065 * Change the ownerships and register quota modifications
1066 * in the transaction.
1068 if (ip->i_d.di_projid != fa->fsx_projid) {
1069 if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp)) {
1070 olddquot = xfs_qm_vop_chown(tp, ip,
1071 &ip->i_gdquot, gdqp);
1073 ip->i_d.di_projid = fa->fsx_projid;
1076 * We may have to rev the inode as well as
1077 * the superblock version number since projids didn't
1078 * exist before DINODE_VERSION_2 and SB_VERSION_NLINK.
1080 if (ip->i_d.di_version == 1)
1081 xfs_bump_ino_vers2(tp, ip);
1086 if (mask & FSX_EXTSIZE)
1087 ip->i_d.di_extsize = fa->fsx_extsize >> mp->m_sb.sb_blocklog;
1088 if (mask & FSX_XFLAGS) {
1089 xfs_set_diflags(ip, fa->fsx_xflags);
1090 xfs_diflags_to_linux(ip);
1093 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1094 xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
1096 XFS_STATS_INC(xs_ig_attrchg);
1099 * If this is a synchronous mount, make sure that the
1100 * transaction goes to disk before returning to the user.
1101 * This is slightly sub-optimal in that truncates require
1102 * two sync transactions instead of one for wsync filesystems.
1103 * One for the truncate and one for the timestamps since we
1104 * don't want to change the timestamps unless we're sure the
1105 * truncate worked. Truncates are less than 1% of the laddis
1106 * mix so this probably isn't worth the trouble to optimize.
1108 if (mp->m_flags & XFS_MOUNT_WSYNC)
1109 xfs_trans_set_sync(tp);
1110 code = xfs_trans_commit(tp, 0);
1111 xfs_iunlock(ip, lock_flags);
1114 * Release any dquot(s) the inode had kept before chown.
1116 xfs_qm_dqrele(olddquot);
1117 xfs_qm_dqrele(udqp);
1118 xfs_qm_dqrele(gdqp);
1120 if (code)
1121 return code;
1123 if (DM_EVENT_ENABLED(ip, DM_EVENT_ATTRIBUTE)) {
1124 XFS_SEND_NAMESP(mp, DM_EVENT_ATTRIBUTE, ip, DM_RIGHT_NULL,
1125 NULL, DM_RIGHT_NULL, NULL, NULL, 0, 0,
1126 (mask & FSX_NONBLOCK) ? DM_FLAGS_NDELAY : 0);
1129 return 0;
1131 error_return:
1132 xfs_qm_dqrele(udqp);
1133 xfs_qm_dqrele(gdqp);
1134 xfs_trans_cancel(tp, 0);
1135 if (lock_flags)
1136 xfs_iunlock(ip, lock_flags);
1137 return code;
1140 STATIC int
1141 xfs_ioc_fssetxattr(
1142 xfs_inode_t *ip,
1143 struct file *filp,
1144 void __user *arg)
1146 struct fsxattr fa;
1147 unsigned int mask;
1149 if (copy_from_user(&fa, arg, sizeof(fa)))
1150 return -EFAULT;
1152 mask = FSX_XFLAGS | FSX_EXTSIZE | FSX_PROJID;
1153 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1154 mask |= FSX_NONBLOCK;
1156 return -xfs_ioctl_setattr(ip, &fa, mask);
1159 STATIC int
1160 xfs_ioc_getxflags(
1161 xfs_inode_t *ip,
1162 void __user *arg)
1164 unsigned int flags;
1166 flags = xfs_di2lxflags(ip->i_d.di_flags);
1167 if (copy_to_user(arg, &flags, sizeof(flags)))
1168 return -EFAULT;
1169 return 0;
1172 STATIC int
1173 xfs_ioc_setxflags(
1174 xfs_inode_t *ip,
1175 struct file *filp,
1176 void __user *arg)
1178 struct fsxattr fa;
1179 unsigned int flags;
1180 unsigned int mask;
1182 if (copy_from_user(&flags, arg, sizeof(flags)))
1183 return -EFAULT;
1185 if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
1186 FS_NOATIME_FL | FS_NODUMP_FL | \
1187 FS_SYNC_FL))
1188 return -EOPNOTSUPP;
1190 mask = FSX_XFLAGS;
1191 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1192 mask |= FSX_NONBLOCK;
1193 fa.fsx_xflags = xfs_merge_ioc_xflags(flags, xfs_ip2xflags(ip));
1195 return -xfs_ioctl_setattr(ip, &fa, mask);
1198 STATIC int
1199 xfs_getbmap_format(void **ap, struct getbmapx *bmv, int *full)
1201 struct getbmap __user *base = *ap;
1203 /* copy only getbmap portion (not getbmapx) */
1204 if (copy_to_user(base, bmv, sizeof(struct getbmap)))
1205 return XFS_ERROR(EFAULT);
1207 *ap += sizeof(struct getbmap);
1208 return 0;
1211 STATIC int
1212 xfs_ioc_getbmap(
1213 struct xfs_inode *ip,
1214 int ioflags,
1215 unsigned int cmd,
1216 void __user *arg)
1218 struct getbmapx bmx;
1219 int error;
1221 if (copy_from_user(&bmx, arg, sizeof(struct getbmapx)))
1222 return -XFS_ERROR(EFAULT);
1224 if (bmx.bmv_count < 2)
1225 return -XFS_ERROR(EINVAL);
1227 bmx.bmv_iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0);
1228 if (ioflags & IO_INVIS)
1229 bmx.bmv_iflags |= BMV_IF_NO_DMAPI_READ;
1231 error = xfs_getbmap(ip, &bmx, xfs_getbmap_format,
1232 (struct getbmap *)arg+1);
1233 if (error)
1234 return -error;
1236 /* copy back header - only size of getbmap */
1237 if (copy_to_user(arg, &bmx, sizeof(struct getbmap)))
1238 return -XFS_ERROR(EFAULT);
1239 return 0;
1242 STATIC int
1243 xfs_getbmapx_format(void **ap, struct getbmapx *bmv, int *full)
1245 struct getbmapx __user *base = *ap;
1247 if (copy_to_user(base, bmv, sizeof(struct getbmapx)))
1248 return XFS_ERROR(EFAULT);
1250 *ap += sizeof(struct getbmapx);
1251 return 0;
1254 STATIC int
1255 xfs_ioc_getbmapx(
1256 struct xfs_inode *ip,
1257 void __user *arg)
1259 struct getbmapx bmx;
1260 int error;
1262 if (copy_from_user(&bmx, arg, sizeof(bmx)))
1263 return -XFS_ERROR(EFAULT);
1265 if (bmx.bmv_count < 2)
1266 return -XFS_ERROR(EINVAL);
1268 if (bmx.bmv_iflags & (~BMV_IF_VALID))
1269 return -XFS_ERROR(EINVAL);
1271 error = xfs_getbmap(ip, &bmx, xfs_getbmapx_format,
1272 (struct getbmapx *)arg+1);
1273 if (error)
1274 return -error;
1276 /* copy back header */
1277 if (copy_to_user(arg, &bmx, sizeof(struct getbmapx)))
1278 return -XFS_ERROR(EFAULT);
1280 return 0;
1284 * Note: some of the ioctl's return positive numbers as a
1285 * byte count indicating success, such as readlink_by_handle.
1286 * So we don't "sign flip" like most other routines. This means
1287 * true errors need to be returned as a negative value.
1289 long
1290 xfs_file_ioctl(
1291 struct file *filp,
1292 unsigned int cmd,
1293 unsigned long p)
1295 struct inode *inode = filp->f_path.dentry->d_inode;
1296 struct xfs_inode *ip = XFS_I(inode);
1297 struct xfs_mount *mp = ip->i_mount;
1298 void __user *arg = (void __user *)p;
1299 int ioflags = 0;
1300 int error;
1302 if (filp->f_mode & FMODE_NOCMTIME)
1303 ioflags |= IO_INVIS;
1305 xfs_itrace_entry(ip);
1307 switch (cmd) {
1308 case XFS_IOC_ALLOCSP:
1309 case XFS_IOC_FREESP:
1310 case XFS_IOC_RESVSP:
1311 case XFS_IOC_UNRESVSP:
1312 case XFS_IOC_ALLOCSP64:
1313 case XFS_IOC_FREESP64:
1314 case XFS_IOC_RESVSP64:
1315 case XFS_IOC_UNRESVSP64: {
1316 xfs_flock64_t bf;
1318 if (copy_from_user(&bf, arg, sizeof(bf)))
1319 return -XFS_ERROR(EFAULT);
1320 return xfs_ioc_space(ip, inode, filp, ioflags, cmd, &bf);
1322 case XFS_IOC_DIOINFO: {
1323 struct dioattr da;
1324 xfs_buftarg_t *target =
1325 XFS_IS_REALTIME_INODE(ip) ?
1326 mp->m_rtdev_targp : mp->m_ddev_targp;
1328 da.d_mem = da.d_miniosz = 1 << target->bt_sshift;
1329 da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1);
1331 if (copy_to_user(arg, &da, sizeof(da)))
1332 return -XFS_ERROR(EFAULT);
1333 return 0;
1336 case XFS_IOC_FSBULKSTAT_SINGLE:
1337 case XFS_IOC_FSBULKSTAT:
1338 case XFS_IOC_FSINUMBERS:
1339 return xfs_ioc_bulkstat(mp, cmd, arg);
1341 case XFS_IOC_FSGEOMETRY_V1:
1342 return xfs_ioc_fsgeometry_v1(mp, arg);
1344 case XFS_IOC_FSGEOMETRY:
1345 return xfs_ioc_fsgeometry(mp, arg);
1347 case XFS_IOC_GETVERSION:
1348 return put_user(inode->i_generation, (int __user *)arg);
1350 case XFS_IOC_FSGETXATTR:
1351 return xfs_ioc_fsgetxattr(ip, 0, arg);
1352 case XFS_IOC_FSGETXATTRA:
1353 return xfs_ioc_fsgetxattr(ip, 1, arg);
1354 case XFS_IOC_FSSETXATTR:
1355 return xfs_ioc_fssetxattr(ip, filp, arg);
1356 case XFS_IOC_GETXFLAGS:
1357 return xfs_ioc_getxflags(ip, arg);
1358 case XFS_IOC_SETXFLAGS:
1359 return xfs_ioc_setxflags(ip, filp, arg);
1361 case XFS_IOC_FSSETDM: {
1362 struct fsdmidata dmi;
1364 if (copy_from_user(&dmi, arg, sizeof(dmi)))
1365 return -XFS_ERROR(EFAULT);
1367 error = xfs_set_dmattrs(ip, dmi.fsd_dmevmask,
1368 dmi.fsd_dmstate);
1369 return -error;
1372 case XFS_IOC_GETBMAP:
1373 case XFS_IOC_GETBMAPA:
1374 return xfs_ioc_getbmap(ip, ioflags, cmd, arg);
1376 case XFS_IOC_GETBMAPX:
1377 return xfs_ioc_getbmapx(ip, arg);
1379 case XFS_IOC_FD_TO_HANDLE:
1380 case XFS_IOC_PATH_TO_HANDLE:
1381 case XFS_IOC_PATH_TO_FSHANDLE: {
1382 xfs_fsop_handlereq_t hreq;
1384 if (copy_from_user(&hreq, arg, sizeof(hreq)))
1385 return -XFS_ERROR(EFAULT);
1386 return xfs_find_handle(cmd, &hreq);
1388 case XFS_IOC_OPEN_BY_HANDLE: {
1389 xfs_fsop_handlereq_t hreq;
1391 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
1392 return -XFS_ERROR(EFAULT);
1393 return xfs_open_by_handle(filp, &hreq);
1395 case XFS_IOC_FSSETDM_BY_HANDLE:
1396 return xfs_fssetdm_by_handle(filp, arg);
1398 case XFS_IOC_READLINK_BY_HANDLE: {
1399 xfs_fsop_handlereq_t hreq;
1401 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
1402 return -XFS_ERROR(EFAULT);
1403 return xfs_readlink_by_handle(filp, &hreq);
1405 case XFS_IOC_ATTRLIST_BY_HANDLE:
1406 return xfs_attrlist_by_handle(filp, arg);
1408 case XFS_IOC_ATTRMULTI_BY_HANDLE:
1409 return xfs_attrmulti_by_handle(filp, arg);
1411 case XFS_IOC_SWAPEXT: {
1412 struct xfs_swapext sxp;
1414 if (copy_from_user(&sxp, arg, sizeof(xfs_swapext_t)))
1415 return -XFS_ERROR(EFAULT);
1416 error = xfs_swapext(&sxp);
1417 return -error;
1420 case XFS_IOC_FSCOUNTS: {
1421 xfs_fsop_counts_t out;
1423 error = xfs_fs_counts(mp, &out);
1424 if (error)
1425 return -error;
1427 if (copy_to_user(arg, &out, sizeof(out)))
1428 return -XFS_ERROR(EFAULT);
1429 return 0;
1432 case XFS_IOC_SET_RESBLKS: {
1433 xfs_fsop_resblks_t inout;
1434 __uint64_t in;
1436 if (!capable(CAP_SYS_ADMIN))
1437 return -EPERM;
1439 if (copy_from_user(&inout, arg, sizeof(inout)))
1440 return -XFS_ERROR(EFAULT);
1442 /* input parameter is passed in resblks field of structure */
1443 in = inout.resblks;
1444 error = xfs_reserve_blocks(mp, &in, &inout);
1445 if (error)
1446 return -error;
1448 if (copy_to_user(arg, &inout, sizeof(inout)))
1449 return -XFS_ERROR(EFAULT);
1450 return 0;
1453 case XFS_IOC_GET_RESBLKS: {
1454 xfs_fsop_resblks_t out;
1456 if (!capable(CAP_SYS_ADMIN))
1457 return -EPERM;
1459 error = xfs_reserve_blocks(mp, NULL, &out);
1460 if (error)
1461 return -error;
1463 if (copy_to_user(arg, &out, sizeof(out)))
1464 return -XFS_ERROR(EFAULT);
1466 return 0;
1469 case XFS_IOC_FSGROWFSDATA: {
1470 xfs_growfs_data_t in;
1472 if (copy_from_user(&in, arg, sizeof(in)))
1473 return -XFS_ERROR(EFAULT);
1475 error = xfs_growfs_data(mp, &in);
1476 return -error;
1479 case XFS_IOC_FSGROWFSLOG: {
1480 xfs_growfs_log_t in;
1482 if (copy_from_user(&in, arg, sizeof(in)))
1483 return -XFS_ERROR(EFAULT);
1485 error = xfs_growfs_log(mp, &in);
1486 return -error;
1489 case XFS_IOC_FSGROWFSRT: {
1490 xfs_growfs_rt_t in;
1492 if (copy_from_user(&in, arg, sizeof(in)))
1493 return -XFS_ERROR(EFAULT);
1495 error = xfs_growfs_rt(mp, &in);
1496 return -error;
1499 case XFS_IOC_GOINGDOWN: {
1500 __uint32_t in;
1502 if (!capable(CAP_SYS_ADMIN))
1503 return -EPERM;
1505 if (get_user(in, (__uint32_t __user *)arg))
1506 return -XFS_ERROR(EFAULT);
1508 error = xfs_fs_goingdown(mp, in);
1509 return -error;
1512 case XFS_IOC_ERROR_INJECTION: {
1513 xfs_error_injection_t in;
1515 if (!capable(CAP_SYS_ADMIN))
1516 return -EPERM;
1518 if (copy_from_user(&in, arg, sizeof(in)))
1519 return -XFS_ERROR(EFAULT);
1521 error = xfs_errortag_add(in.errtag, mp);
1522 return -error;
1525 case XFS_IOC_ERROR_CLEARALL:
1526 if (!capable(CAP_SYS_ADMIN))
1527 return -EPERM;
1529 error = xfs_errortag_clearall(mp, 1);
1530 return -error;
1532 default:
1533 return -ENOTTY;