xfs: zero proper structure size for geometry calls
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / xfs / linux-2.6 / xfs_ioctl.c
blobdbf7e09ccccff3f3269463e19ee66d5bdb0520a6
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"
54 #include "xfs_trace.h"
56 #include <linux/capability.h>
57 #include <linux/dcache.h>
58 #include <linux/mount.h>
59 #include <linux/namei.h>
60 #include <linux/pagemap.h>
61 #include <linux/exportfs.h>
64 * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to
65 * a file or fs handle.
67 * XFS_IOC_PATH_TO_FSHANDLE
68 * returns fs handle for a mount point or path within that mount point
69 * XFS_IOC_FD_TO_HANDLE
70 * returns full handle for a FD opened in user space
71 * XFS_IOC_PATH_TO_HANDLE
72 * returns full handle for a path
74 int
75 xfs_find_handle(
76 unsigned int cmd,
77 xfs_fsop_handlereq_t *hreq)
79 int hsize;
80 xfs_handle_t handle;
81 struct inode *inode;
82 struct file *file = NULL;
83 struct path path;
84 int error;
85 struct xfs_inode *ip;
87 if (cmd == XFS_IOC_FD_TO_HANDLE) {
88 file = fget(hreq->fd);
89 if (!file)
90 return -EBADF;
91 inode = file->f_path.dentry->d_inode;
92 } else {
93 error = user_lpath((const char __user *)hreq->path, &path);
94 if (error)
95 return error;
96 inode = path.dentry->d_inode;
98 ip = XFS_I(inode);
101 * We can only generate handles for inodes residing on a XFS filesystem,
102 * and only for regular files, directories or symbolic links.
104 error = -EINVAL;
105 if (inode->i_sb->s_magic != XFS_SB_MAGIC)
106 goto out_put;
108 error = -EBADF;
109 if (!S_ISREG(inode->i_mode) &&
110 !S_ISDIR(inode->i_mode) &&
111 !S_ISLNK(inode->i_mode))
112 goto out_put;
115 memcpy(&handle.ha_fsid, ip->i_mount->m_fixedfsid, sizeof(xfs_fsid_t));
117 if (cmd == XFS_IOC_PATH_TO_FSHANDLE) {
119 * This handle only contains an fsid, zero the rest.
121 memset(&handle.ha_fid, 0, sizeof(handle.ha_fid));
122 hsize = sizeof(xfs_fsid_t);
123 } else {
124 int lock_mode;
126 lock_mode = xfs_ilock_map_shared(ip);
127 handle.ha_fid.fid_len = sizeof(xfs_fid_t) -
128 sizeof(handle.ha_fid.fid_len);
129 handle.ha_fid.fid_pad = 0;
130 handle.ha_fid.fid_gen = ip->i_d.di_gen;
131 handle.ha_fid.fid_ino = ip->i_ino;
132 xfs_iunlock_map_shared(ip, lock_mode);
134 hsize = XFS_HSIZE(handle);
137 error = -EFAULT;
138 if (copy_to_user(hreq->ohandle, &handle, hsize) ||
139 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
140 goto out_put;
142 error = 0;
144 out_put:
145 if (cmd == XFS_IOC_FD_TO_HANDLE)
146 fput(file);
147 else
148 path_put(&path);
149 return error;
153 * No need to do permission checks on the various pathname components
154 * as the handle operations are privileged.
156 STATIC int
157 xfs_handle_acceptable(
158 void *context,
159 struct dentry *dentry)
161 return 1;
165 * Convert userspace handle data into a dentry.
167 struct dentry *
168 xfs_handle_to_dentry(
169 struct file *parfilp,
170 void __user *uhandle,
171 u32 hlen)
173 xfs_handle_t handle;
174 struct xfs_fid64 fid;
177 * Only allow handle opens under a directory.
179 if (!S_ISDIR(parfilp->f_path.dentry->d_inode->i_mode))
180 return ERR_PTR(-ENOTDIR);
182 if (hlen != sizeof(xfs_handle_t))
183 return ERR_PTR(-EINVAL);
184 if (copy_from_user(&handle, uhandle, hlen))
185 return ERR_PTR(-EFAULT);
186 if (handle.ha_fid.fid_len !=
187 sizeof(handle.ha_fid) - sizeof(handle.ha_fid.fid_len))
188 return ERR_PTR(-EINVAL);
190 memset(&fid, 0, sizeof(struct fid));
191 fid.ino = handle.ha_fid.fid_ino;
192 fid.gen = handle.ha_fid.fid_gen;
194 return exportfs_decode_fh(parfilp->f_path.mnt, (struct fid *)&fid, 3,
195 FILEID_INO32_GEN | XFS_FILEID_TYPE_64FLAG,
196 xfs_handle_acceptable, NULL);
199 STATIC struct dentry *
200 xfs_handlereq_to_dentry(
201 struct file *parfilp,
202 xfs_fsop_handlereq_t *hreq)
204 return xfs_handle_to_dentry(parfilp, hreq->ihandle, hreq->ihandlen);
208 xfs_open_by_handle(
209 struct file *parfilp,
210 xfs_fsop_handlereq_t *hreq)
212 const struct cred *cred = current_cred();
213 int error;
214 int fd;
215 int permflag;
216 struct file *filp;
217 struct inode *inode;
218 struct dentry *dentry;
220 if (!capable(CAP_SYS_ADMIN))
221 return -XFS_ERROR(EPERM);
223 dentry = xfs_handlereq_to_dentry(parfilp, hreq);
224 if (IS_ERR(dentry))
225 return PTR_ERR(dentry);
226 inode = dentry->d_inode;
228 /* Restrict xfs_open_by_handle to directories & regular files. */
229 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
230 error = -XFS_ERROR(EPERM);
231 goto out_dput;
234 #if BITS_PER_LONG != 32
235 hreq->oflags |= O_LARGEFILE;
236 #endif
238 /* Put open permission in namei format. */
239 permflag = hreq->oflags;
240 if ((permflag+1) & O_ACCMODE)
241 permflag++;
242 if (permflag & O_TRUNC)
243 permflag |= 2;
245 if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
246 (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
247 error = -XFS_ERROR(EPERM);
248 goto out_dput;
251 if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
252 error = -XFS_ERROR(EACCES);
253 goto out_dput;
256 /* Can't write directories. */
257 if (S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
258 error = -XFS_ERROR(EISDIR);
259 goto out_dput;
262 fd = get_unused_fd();
263 if (fd < 0) {
264 error = fd;
265 goto out_dput;
268 filp = dentry_open(dentry, mntget(parfilp->f_path.mnt),
269 hreq->oflags, cred);
270 if (IS_ERR(filp)) {
271 put_unused_fd(fd);
272 return PTR_ERR(filp);
275 if (inode->i_mode & S_IFREG) {
276 filp->f_flags |= O_NOATIME;
277 filp->f_mode |= FMODE_NOCMTIME;
280 fd_install(fd, filp);
281 return fd;
283 out_dput:
284 dput(dentry);
285 return error;
289 * This is a copy from fs/namei.c:vfs_readlink(), except for removing it's
290 * unused first argument.
292 STATIC int
293 do_readlink(
294 char __user *buffer,
295 int buflen,
296 const char *link)
298 int len;
300 len = PTR_ERR(link);
301 if (IS_ERR(link))
302 goto out;
304 len = strlen(link);
305 if (len > (unsigned) buflen)
306 len = buflen;
307 if (copy_to_user(buffer, link, len))
308 len = -EFAULT;
309 out:
310 return len;
315 xfs_readlink_by_handle(
316 struct file *parfilp,
317 xfs_fsop_handlereq_t *hreq)
319 struct dentry *dentry;
320 __u32 olen;
321 void *link;
322 int error;
324 if (!capable(CAP_SYS_ADMIN))
325 return -XFS_ERROR(EPERM);
327 dentry = xfs_handlereq_to_dentry(parfilp, hreq);
328 if (IS_ERR(dentry))
329 return PTR_ERR(dentry);
331 /* Restrict this handle operation to symlinks only. */
332 if (!S_ISLNK(dentry->d_inode->i_mode)) {
333 error = -XFS_ERROR(EINVAL);
334 goto out_dput;
337 if (copy_from_user(&olen, hreq->ohandlen, sizeof(__u32))) {
338 error = -XFS_ERROR(EFAULT);
339 goto out_dput;
342 link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
343 if (!link) {
344 error = -XFS_ERROR(ENOMEM);
345 goto out_dput;
348 error = -xfs_readlink(XFS_I(dentry->d_inode), link);
349 if (error)
350 goto out_kfree;
351 error = do_readlink(hreq->ohandle, olen, link);
352 if (error)
353 goto out_kfree;
355 out_kfree:
356 kfree(link);
357 out_dput:
358 dput(dentry);
359 return error;
362 STATIC int
363 xfs_fssetdm_by_handle(
364 struct file *parfilp,
365 void __user *arg)
367 int error;
368 struct fsdmidata fsd;
369 xfs_fsop_setdm_handlereq_t dmhreq;
370 struct dentry *dentry;
372 if (!capable(CAP_MKNOD))
373 return -XFS_ERROR(EPERM);
374 if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t)))
375 return -XFS_ERROR(EFAULT);
377 dentry = xfs_handlereq_to_dentry(parfilp, &dmhreq.hreq);
378 if (IS_ERR(dentry))
379 return PTR_ERR(dentry);
381 if (IS_IMMUTABLE(dentry->d_inode) || IS_APPEND(dentry->d_inode)) {
382 error = -XFS_ERROR(EPERM);
383 goto out;
386 if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
387 error = -XFS_ERROR(EFAULT);
388 goto out;
391 error = -xfs_set_dmattrs(XFS_I(dentry->d_inode), fsd.fsd_dmevmask,
392 fsd.fsd_dmstate);
394 out:
395 dput(dentry);
396 return error;
399 STATIC int
400 xfs_attrlist_by_handle(
401 struct file *parfilp,
402 void __user *arg)
404 int error = -ENOMEM;
405 attrlist_cursor_kern_t *cursor;
406 xfs_fsop_attrlist_handlereq_t al_hreq;
407 struct dentry *dentry;
408 char *kbuf;
410 if (!capable(CAP_SYS_ADMIN))
411 return -XFS_ERROR(EPERM);
412 if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t)))
413 return -XFS_ERROR(EFAULT);
414 if (al_hreq.buflen > XATTR_LIST_MAX)
415 return -XFS_ERROR(EINVAL);
418 * Reject flags, only allow namespaces.
420 if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE))
421 return -XFS_ERROR(EINVAL);
423 dentry = xfs_handlereq_to_dentry(parfilp, &al_hreq.hreq);
424 if (IS_ERR(dentry))
425 return PTR_ERR(dentry);
427 kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
428 if (!kbuf)
429 goto out_dput;
431 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
432 error = -xfs_attr_list(XFS_I(dentry->d_inode), kbuf, al_hreq.buflen,
433 al_hreq.flags, cursor);
434 if (error)
435 goto out_kfree;
437 if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen))
438 error = -EFAULT;
440 out_kfree:
441 kfree(kbuf);
442 out_dput:
443 dput(dentry);
444 return error;
448 xfs_attrmulti_attr_get(
449 struct inode *inode,
450 char *name,
451 char __user *ubuf,
452 __uint32_t *len,
453 __uint32_t flags)
455 char *kbuf;
456 int error = EFAULT;
458 if (*len > XATTR_SIZE_MAX)
459 return EINVAL;
460 kbuf = kmalloc(*len, GFP_KERNEL);
461 if (!kbuf)
462 return ENOMEM;
464 error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags);
465 if (error)
466 goto out_kfree;
468 if (copy_to_user(ubuf, kbuf, *len))
469 error = EFAULT;
471 out_kfree:
472 kfree(kbuf);
473 return error;
477 xfs_attrmulti_attr_set(
478 struct inode *inode,
479 char *name,
480 const char __user *ubuf,
481 __uint32_t len,
482 __uint32_t flags)
484 char *kbuf;
485 int error = EFAULT;
487 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
488 return EPERM;
489 if (len > XATTR_SIZE_MAX)
490 return EINVAL;
492 kbuf = memdup_user(ubuf, len);
493 if (IS_ERR(kbuf))
494 return PTR_ERR(kbuf);
496 error = xfs_attr_set(XFS_I(inode), name, kbuf, len, flags);
498 return error;
502 xfs_attrmulti_attr_remove(
503 struct inode *inode,
504 char *name,
505 __uint32_t flags)
507 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
508 return EPERM;
509 return xfs_attr_remove(XFS_I(inode), name, flags);
512 STATIC int
513 xfs_attrmulti_by_handle(
514 struct file *parfilp,
515 void __user *arg)
517 int error;
518 xfs_attr_multiop_t *ops;
519 xfs_fsop_attrmulti_handlereq_t am_hreq;
520 struct dentry *dentry;
521 unsigned int i, size;
522 char *attr_name;
524 if (!capable(CAP_SYS_ADMIN))
525 return -XFS_ERROR(EPERM);
526 if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t)))
527 return -XFS_ERROR(EFAULT);
529 dentry = xfs_handlereq_to_dentry(parfilp, &am_hreq.hreq);
530 if (IS_ERR(dentry))
531 return PTR_ERR(dentry);
533 error = E2BIG;
534 size = am_hreq.opcount * sizeof(xfs_attr_multiop_t);
535 if (!size || size > 16 * PAGE_SIZE)
536 goto out_dput;
538 ops = memdup_user(am_hreq.ops, size);
539 if (IS_ERR(ops)) {
540 error = PTR_ERR(ops);
541 goto out_dput;
544 attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
545 if (!attr_name)
546 goto out_kfree_ops;
548 error = 0;
549 for (i = 0; i < am_hreq.opcount; i++) {
550 ops[i].am_error = strncpy_from_user(attr_name,
551 ops[i].am_attrname, MAXNAMELEN);
552 if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
553 error = -ERANGE;
554 if (ops[i].am_error < 0)
555 break;
557 switch (ops[i].am_opcode) {
558 case ATTR_OP_GET:
559 ops[i].am_error = xfs_attrmulti_attr_get(
560 dentry->d_inode, attr_name,
561 ops[i].am_attrvalue, &ops[i].am_length,
562 ops[i].am_flags);
563 break;
564 case ATTR_OP_SET:
565 ops[i].am_error = mnt_want_write(parfilp->f_path.mnt);
566 if (ops[i].am_error)
567 break;
568 ops[i].am_error = xfs_attrmulti_attr_set(
569 dentry->d_inode, attr_name,
570 ops[i].am_attrvalue, ops[i].am_length,
571 ops[i].am_flags);
572 mnt_drop_write(parfilp->f_path.mnt);
573 break;
574 case ATTR_OP_REMOVE:
575 ops[i].am_error = mnt_want_write(parfilp->f_path.mnt);
576 if (ops[i].am_error)
577 break;
578 ops[i].am_error = xfs_attrmulti_attr_remove(
579 dentry->d_inode, attr_name,
580 ops[i].am_flags);
581 mnt_drop_write(parfilp->f_path.mnt);
582 break;
583 default:
584 ops[i].am_error = EINVAL;
588 if (copy_to_user(am_hreq.ops, ops, size))
589 error = XFS_ERROR(EFAULT);
591 kfree(attr_name);
592 out_kfree_ops:
593 kfree(ops);
594 out_dput:
595 dput(dentry);
596 return -error;
600 xfs_ioc_space(
601 struct xfs_inode *ip,
602 struct inode *inode,
603 struct file *filp,
604 int ioflags,
605 unsigned int cmd,
606 xfs_flock64_t *bf)
608 int attr_flags = 0;
609 int error;
612 * Only allow the sys admin to reserve space unless
613 * unwritten extents are enabled.
615 if (!xfs_sb_version_hasextflgbit(&ip->i_mount->m_sb) &&
616 !capable(CAP_SYS_ADMIN))
617 return -XFS_ERROR(EPERM);
619 if (inode->i_flags & (S_IMMUTABLE|S_APPEND))
620 return -XFS_ERROR(EPERM);
622 if (!(filp->f_mode & FMODE_WRITE))
623 return -XFS_ERROR(EBADF);
625 if (!S_ISREG(inode->i_mode))
626 return -XFS_ERROR(EINVAL);
628 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
629 attr_flags |= XFS_ATTR_NONBLOCK;
630 if (ioflags & IO_INVIS)
631 attr_flags |= XFS_ATTR_DMI;
633 error = xfs_change_file_space(ip, cmd, bf, filp->f_pos, attr_flags);
634 return -error;
637 STATIC int
638 xfs_ioc_bulkstat(
639 xfs_mount_t *mp,
640 unsigned int cmd,
641 void __user *arg)
643 xfs_fsop_bulkreq_t bulkreq;
644 int count; /* # of records returned */
645 xfs_ino_t inlast; /* last inode number */
646 int done;
647 int error;
649 /* done = 1 if there are more stats to get and if bulkstat */
650 /* should be called again (unused here, but used in dmapi) */
652 if (!capable(CAP_SYS_ADMIN))
653 return -EPERM;
655 if (XFS_FORCED_SHUTDOWN(mp))
656 return -XFS_ERROR(EIO);
658 if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t)))
659 return -XFS_ERROR(EFAULT);
661 if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
662 return -XFS_ERROR(EFAULT);
664 if ((count = bulkreq.icount) <= 0)
665 return -XFS_ERROR(EINVAL);
667 if (bulkreq.ubuffer == NULL)
668 return -XFS_ERROR(EINVAL);
670 if (cmd == XFS_IOC_FSINUMBERS)
671 error = xfs_inumbers(mp, &inlast, &count,
672 bulkreq.ubuffer, xfs_inumbers_fmt);
673 else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE)
674 error = xfs_bulkstat_single(mp, &inlast,
675 bulkreq.ubuffer, &done);
676 else /* XFS_IOC_FSBULKSTAT */
677 error = xfs_bulkstat(mp, &inlast, &count,
678 (bulkstat_one_pf)xfs_bulkstat_one, NULL,
679 sizeof(xfs_bstat_t), bulkreq.ubuffer,
680 BULKSTAT_FG_QUICK, &done);
682 if (error)
683 return -error;
685 if (bulkreq.ocount != NULL) {
686 if (copy_to_user(bulkreq.lastip, &inlast,
687 sizeof(xfs_ino_t)))
688 return -XFS_ERROR(EFAULT);
690 if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
691 return -XFS_ERROR(EFAULT);
694 return 0;
697 STATIC int
698 xfs_ioc_fsgeometry_v1(
699 xfs_mount_t *mp,
700 void __user *arg)
702 xfs_fsop_geom_t fsgeo;
703 int error;
705 error = xfs_fs_geometry(mp, &fsgeo, 3);
706 if (error)
707 return -error;
710 * Caller should have passed an argument of type
711 * xfs_fsop_geom_v1_t. This is a proper subset of the
712 * xfs_fsop_geom_t that xfs_fs_geometry() fills in.
714 if (copy_to_user(arg, &fsgeo, sizeof(xfs_fsop_geom_v1_t)))
715 return -XFS_ERROR(EFAULT);
716 return 0;
719 STATIC int
720 xfs_ioc_fsgeometry(
721 xfs_mount_t *mp,
722 void __user *arg)
724 xfs_fsop_geom_t fsgeo;
725 int error;
727 error = xfs_fs_geometry(mp, &fsgeo, 4);
728 if (error)
729 return -error;
731 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
732 return -XFS_ERROR(EFAULT);
733 return 0;
737 * Linux extended inode flags interface.
740 STATIC unsigned int
741 xfs_merge_ioc_xflags(
742 unsigned int flags,
743 unsigned int start)
745 unsigned int xflags = start;
747 if (flags & FS_IMMUTABLE_FL)
748 xflags |= XFS_XFLAG_IMMUTABLE;
749 else
750 xflags &= ~XFS_XFLAG_IMMUTABLE;
751 if (flags & FS_APPEND_FL)
752 xflags |= XFS_XFLAG_APPEND;
753 else
754 xflags &= ~XFS_XFLAG_APPEND;
755 if (flags & FS_SYNC_FL)
756 xflags |= XFS_XFLAG_SYNC;
757 else
758 xflags &= ~XFS_XFLAG_SYNC;
759 if (flags & FS_NOATIME_FL)
760 xflags |= XFS_XFLAG_NOATIME;
761 else
762 xflags &= ~XFS_XFLAG_NOATIME;
763 if (flags & FS_NODUMP_FL)
764 xflags |= XFS_XFLAG_NODUMP;
765 else
766 xflags &= ~XFS_XFLAG_NODUMP;
768 return xflags;
771 STATIC unsigned int
772 xfs_di2lxflags(
773 __uint16_t di_flags)
775 unsigned int flags = 0;
777 if (di_flags & XFS_DIFLAG_IMMUTABLE)
778 flags |= FS_IMMUTABLE_FL;
779 if (di_flags & XFS_DIFLAG_APPEND)
780 flags |= FS_APPEND_FL;
781 if (di_flags & XFS_DIFLAG_SYNC)
782 flags |= FS_SYNC_FL;
783 if (di_flags & XFS_DIFLAG_NOATIME)
784 flags |= FS_NOATIME_FL;
785 if (di_flags & XFS_DIFLAG_NODUMP)
786 flags |= FS_NODUMP_FL;
787 return flags;
790 STATIC int
791 xfs_ioc_fsgetxattr(
792 xfs_inode_t *ip,
793 int attr,
794 void __user *arg)
796 struct fsxattr fa;
798 memset(&fa, 0, sizeof(struct fsxattr));
800 xfs_ilock(ip, XFS_ILOCK_SHARED);
801 fa.fsx_xflags = xfs_ip2xflags(ip);
802 fa.fsx_extsize = ip->i_d.di_extsize << ip->i_mount->m_sb.sb_blocklog;
803 fa.fsx_projid = ip->i_d.di_projid;
805 if (attr) {
806 if (ip->i_afp) {
807 if (ip->i_afp->if_flags & XFS_IFEXTENTS)
808 fa.fsx_nextents = ip->i_afp->if_bytes /
809 sizeof(xfs_bmbt_rec_t);
810 else
811 fa.fsx_nextents = ip->i_d.di_anextents;
812 } else
813 fa.fsx_nextents = 0;
814 } else {
815 if (ip->i_df.if_flags & XFS_IFEXTENTS)
816 fa.fsx_nextents = ip->i_df.if_bytes /
817 sizeof(xfs_bmbt_rec_t);
818 else
819 fa.fsx_nextents = ip->i_d.di_nextents;
821 xfs_iunlock(ip, XFS_ILOCK_SHARED);
823 if (copy_to_user(arg, &fa, sizeof(fa)))
824 return -EFAULT;
825 return 0;
828 STATIC void
829 xfs_set_diflags(
830 struct xfs_inode *ip,
831 unsigned int xflags)
833 unsigned int di_flags;
835 /* can't set PREALLOC this way, just preserve it */
836 di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
837 if (xflags & XFS_XFLAG_IMMUTABLE)
838 di_flags |= XFS_DIFLAG_IMMUTABLE;
839 if (xflags & XFS_XFLAG_APPEND)
840 di_flags |= XFS_DIFLAG_APPEND;
841 if (xflags & XFS_XFLAG_SYNC)
842 di_flags |= XFS_DIFLAG_SYNC;
843 if (xflags & XFS_XFLAG_NOATIME)
844 di_flags |= XFS_DIFLAG_NOATIME;
845 if (xflags & XFS_XFLAG_NODUMP)
846 di_flags |= XFS_DIFLAG_NODUMP;
847 if (xflags & XFS_XFLAG_PROJINHERIT)
848 di_flags |= XFS_DIFLAG_PROJINHERIT;
849 if (xflags & XFS_XFLAG_NODEFRAG)
850 di_flags |= XFS_DIFLAG_NODEFRAG;
851 if (xflags & XFS_XFLAG_FILESTREAM)
852 di_flags |= XFS_DIFLAG_FILESTREAM;
853 if ((ip->i_d.di_mode & S_IFMT) == S_IFDIR) {
854 if (xflags & XFS_XFLAG_RTINHERIT)
855 di_flags |= XFS_DIFLAG_RTINHERIT;
856 if (xflags & XFS_XFLAG_NOSYMLINKS)
857 di_flags |= XFS_DIFLAG_NOSYMLINKS;
858 if (xflags & XFS_XFLAG_EXTSZINHERIT)
859 di_flags |= XFS_DIFLAG_EXTSZINHERIT;
860 } else if ((ip->i_d.di_mode & S_IFMT) == S_IFREG) {
861 if (xflags & XFS_XFLAG_REALTIME)
862 di_flags |= XFS_DIFLAG_REALTIME;
863 if (xflags & XFS_XFLAG_EXTSIZE)
864 di_flags |= XFS_DIFLAG_EXTSIZE;
867 ip->i_d.di_flags = di_flags;
870 STATIC void
871 xfs_diflags_to_linux(
872 struct xfs_inode *ip)
874 struct inode *inode = VFS_I(ip);
875 unsigned int xflags = xfs_ip2xflags(ip);
877 if (xflags & XFS_XFLAG_IMMUTABLE)
878 inode->i_flags |= S_IMMUTABLE;
879 else
880 inode->i_flags &= ~S_IMMUTABLE;
881 if (xflags & XFS_XFLAG_APPEND)
882 inode->i_flags |= S_APPEND;
883 else
884 inode->i_flags &= ~S_APPEND;
885 if (xflags & XFS_XFLAG_SYNC)
886 inode->i_flags |= S_SYNC;
887 else
888 inode->i_flags &= ~S_SYNC;
889 if (xflags & XFS_XFLAG_NOATIME)
890 inode->i_flags |= S_NOATIME;
891 else
892 inode->i_flags &= ~S_NOATIME;
895 #define FSX_PROJID 1
896 #define FSX_EXTSIZE 2
897 #define FSX_XFLAGS 4
898 #define FSX_NONBLOCK 8
900 STATIC int
901 xfs_ioctl_setattr(
902 xfs_inode_t *ip,
903 struct fsxattr *fa,
904 int mask)
906 struct xfs_mount *mp = ip->i_mount;
907 struct xfs_trans *tp;
908 unsigned int lock_flags = 0;
909 struct xfs_dquot *udqp = NULL;
910 struct xfs_dquot *gdqp = NULL;
911 struct xfs_dquot *olddquot = NULL;
912 int code;
914 xfs_itrace_entry(ip);
916 if (mp->m_flags & XFS_MOUNT_RDONLY)
917 return XFS_ERROR(EROFS);
918 if (XFS_FORCED_SHUTDOWN(mp))
919 return XFS_ERROR(EIO);
922 * If disk quotas is on, we make sure that the dquots do exist on disk,
923 * before we start any other transactions. Trying to do this later
924 * is messy. We don't care to take a readlock to look at the ids
925 * in inode here, because we can't hold it across the trans_reserve.
926 * If the IDs do change before we take the ilock, we're covered
927 * because the i_*dquot fields will get updated anyway.
929 if (XFS_IS_QUOTA_ON(mp) && (mask & FSX_PROJID)) {
930 code = xfs_qm_vop_dqalloc(ip, ip->i_d.di_uid,
931 ip->i_d.di_gid, fa->fsx_projid,
932 XFS_QMOPT_PQUOTA, &udqp, &gdqp);
933 if (code)
934 return code;
938 * For the other attributes, we acquire the inode lock and
939 * first do an error checking pass.
941 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
942 code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
943 if (code)
944 goto error_return;
946 lock_flags = XFS_ILOCK_EXCL;
947 xfs_ilock(ip, lock_flags);
950 * CAP_FOWNER overrides the following restrictions:
952 * The user ID of the calling process must be equal
953 * to the file owner ID, except in cases where the
954 * CAP_FSETID capability is applicable.
956 if (current_fsuid() != ip->i_d.di_uid && !capable(CAP_FOWNER)) {
957 code = XFS_ERROR(EPERM);
958 goto error_return;
962 * Do a quota reservation only if projid is actually going to change.
964 if (mask & FSX_PROJID) {
965 if (XFS_IS_QUOTA_RUNNING(mp) &&
966 XFS_IS_PQUOTA_ON(mp) &&
967 ip->i_d.di_projid != fa->fsx_projid) {
968 ASSERT(tp);
969 code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
970 capable(CAP_FOWNER) ?
971 XFS_QMOPT_FORCE_RES : 0);
972 if (code) /* out of quota */
973 goto error_return;
977 if (mask & FSX_EXTSIZE) {
979 * Can't change extent size if any extents are allocated.
981 if (ip->i_d.di_nextents &&
982 ((ip->i_d.di_extsize << mp->m_sb.sb_blocklog) !=
983 fa->fsx_extsize)) {
984 code = XFS_ERROR(EINVAL); /* EFBIG? */
985 goto error_return;
989 * Extent size must be a multiple of the appropriate block
990 * size, if set at all.
992 if (fa->fsx_extsize != 0) {
993 xfs_extlen_t size;
995 if (XFS_IS_REALTIME_INODE(ip) ||
996 ((mask & FSX_XFLAGS) &&
997 (fa->fsx_xflags & XFS_XFLAG_REALTIME))) {
998 size = mp->m_sb.sb_rextsize <<
999 mp->m_sb.sb_blocklog;
1000 } else {
1001 size = mp->m_sb.sb_blocksize;
1004 if (fa->fsx_extsize % size) {
1005 code = XFS_ERROR(EINVAL);
1006 goto error_return;
1012 if (mask & FSX_XFLAGS) {
1014 * Can't change realtime flag if any extents are allocated.
1016 if ((ip->i_d.di_nextents || ip->i_delayed_blks) &&
1017 (XFS_IS_REALTIME_INODE(ip)) !=
1018 (fa->fsx_xflags & XFS_XFLAG_REALTIME)) {
1019 code = XFS_ERROR(EINVAL); /* EFBIG? */
1020 goto error_return;
1024 * If realtime flag is set then must have realtime data.
1026 if ((fa->fsx_xflags & XFS_XFLAG_REALTIME)) {
1027 if ((mp->m_sb.sb_rblocks == 0) ||
1028 (mp->m_sb.sb_rextsize == 0) ||
1029 (ip->i_d.di_extsize % mp->m_sb.sb_rextsize)) {
1030 code = XFS_ERROR(EINVAL);
1031 goto error_return;
1036 * Can't modify an immutable/append-only file unless
1037 * we have appropriate permission.
1039 if ((ip->i_d.di_flags &
1040 (XFS_DIFLAG_IMMUTABLE|XFS_DIFLAG_APPEND) ||
1041 (fa->fsx_xflags &
1042 (XFS_XFLAG_IMMUTABLE | XFS_XFLAG_APPEND))) &&
1043 !capable(CAP_LINUX_IMMUTABLE)) {
1044 code = XFS_ERROR(EPERM);
1045 goto error_return;
1049 xfs_trans_ijoin(tp, ip, lock_flags);
1050 xfs_trans_ihold(tp, ip);
1053 * Change file ownership. Must be the owner or privileged.
1055 if (mask & FSX_PROJID) {
1057 * CAP_FSETID overrides the following restrictions:
1059 * The set-user-ID and set-group-ID bits of a file will be
1060 * cleared upon successful return from chown()
1062 if ((ip->i_d.di_mode & (S_ISUID|S_ISGID)) &&
1063 !capable(CAP_FSETID))
1064 ip->i_d.di_mode &= ~(S_ISUID|S_ISGID);
1067 * Change the ownerships and register quota modifications
1068 * in the transaction.
1070 if (ip->i_d.di_projid != fa->fsx_projid) {
1071 if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_PQUOTA_ON(mp)) {
1072 olddquot = xfs_qm_vop_chown(tp, ip,
1073 &ip->i_gdquot, gdqp);
1075 ip->i_d.di_projid = fa->fsx_projid;
1078 * We may have to rev the inode as well as
1079 * the superblock version number since projids didn't
1080 * exist before DINODE_VERSION_2 and SB_VERSION_NLINK.
1082 if (ip->i_d.di_version == 1)
1083 xfs_bump_ino_vers2(tp, ip);
1088 if (mask & FSX_EXTSIZE)
1089 ip->i_d.di_extsize = fa->fsx_extsize >> mp->m_sb.sb_blocklog;
1090 if (mask & FSX_XFLAGS) {
1091 xfs_set_diflags(ip, fa->fsx_xflags);
1092 xfs_diflags_to_linux(ip);
1095 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1096 xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
1098 XFS_STATS_INC(xs_ig_attrchg);
1101 * If this is a synchronous mount, make sure that the
1102 * transaction goes to disk before returning to the user.
1103 * This is slightly sub-optimal in that truncates require
1104 * two sync transactions instead of one for wsync filesystems.
1105 * One for the truncate and one for the timestamps since we
1106 * don't want to change the timestamps unless we're sure the
1107 * truncate worked. Truncates are less than 1% of the laddis
1108 * mix so this probably isn't worth the trouble to optimize.
1110 if (mp->m_flags & XFS_MOUNT_WSYNC)
1111 xfs_trans_set_sync(tp);
1112 code = xfs_trans_commit(tp, 0);
1113 xfs_iunlock(ip, lock_flags);
1116 * Release any dquot(s) the inode had kept before chown.
1118 xfs_qm_dqrele(olddquot);
1119 xfs_qm_dqrele(udqp);
1120 xfs_qm_dqrele(gdqp);
1122 if (code)
1123 return code;
1125 if (DM_EVENT_ENABLED(ip, DM_EVENT_ATTRIBUTE)) {
1126 XFS_SEND_NAMESP(mp, DM_EVENT_ATTRIBUTE, ip, DM_RIGHT_NULL,
1127 NULL, DM_RIGHT_NULL, NULL, NULL, 0, 0,
1128 (mask & FSX_NONBLOCK) ? DM_FLAGS_NDELAY : 0);
1131 return 0;
1133 error_return:
1134 xfs_qm_dqrele(udqp);
1135 xfs_qm_dqrele(gdqp);
1136 xfs_trans_cancel(tp, 0);
1137 if (lock_flags)
1138 xfs_iunlock(ip, lock_flags);
1139 return code;
1142 STATIC int
1143 xfs_ioc_fssetxattr(
1144 xfs_inode_t *ip,
1145 struct file *filp,
1146 void __user *arg)
1148 struct fsxattr fa;
1149 unsigned int mask;
1151 if (copy_from_user(&fa, arg, sizeof(fa)))
1152 return -EFAULT;
1154 mask = FSX_XFLAGS | FSX_EXTSIZE | FSX_PROJID;
1155 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1156 mask |= FSX_NONBLOCK;
1158 return -xfs_ioctl_setattr(ip, &fa, mask);
1161 STATIC int
1162 xfs_ioc_getxflags(
1163 xfs_inode_t *ip,
1164 void __user *arg)
1166 unsigned int flags;
1168 flags = xfs_di2lxflags(ip->i_d.di_flags);
1169 if (copy_to_user(arg, &flags, sizeof(flags)))
1170 return -EFAULT;
1171 return 0;
1174 STATIC int
1175 xfs_ioc_setxflags(
1176 xfs_inode_t *ip,
1177 struct file *filp,
1178 void __user *arg)
1180 struct fsxattr fa;
1181 unsigned int flags;
1182 unsigned int mask;
1184 if (copy_from_user(&flags, arg, sizeof(flags)))
1185 return -EFAULT;
1187 if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
1188 FS_NOATIME_FL | FS_NODUMP_FL | \
1189 FS_SYNC_FL))
1190 return -EOPNOTSUPP;
1192 mask = FSX_XFLAGS;
1193 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1194 mask |= FSX_NONBLOCK;
1195 fa.fsx_xflags = xfs_merge_ioc_xflags(flags, xfs_ip2xflags(ip));
1197 return -xfs_ioctl_setattr(ip, &fa, mask);
1200 STATIC int
1201 xfs_getbmap_format(void **ap, struct getbmapx *bmv, int *full)
1203 struct getbmap __user *base = *ap;
1205 /* copy only getbmap portion (not getbmapx) */
1206 if (copy_to_user(base, bmv, sizeof(struct getbmap)))
1207 return XFS_ERROR(EFAULT);
1209 *ap += sizeof(struct getbmap);
1210 return 0;
1213 STATIC int
1214 xfs_ioc_getbmap(
1215 struct xfs_inode *ip,
1216 int ioflags,
1217 unsigned int cmd,
1218 void __user *arg)
1220 struct getbmapx bmx;
1221 int error;
1223 if (copy_from_user(&bmx, arg, sizeof(struct getbmapx)))
1224 return -XFS_ERROR(EFAULT);
1226 if (bmx.bmv_count < 2)
1227 return -XFS_ERROR(EINVAL);
1229 bmx.bmv_iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0);
1230 if (ioflags & IO_INVIS)
1231 bmx.bmv_iflags |= BMV_IF_NO_DMAPI_READ;
1233 error = xfs_getbmap(ip, &bmx, xfs_getbmap_format,
1234 (struct getbmap *)arg+1);
1235 if (error)
1236 return -error;
1238 /* copy back header - only size of getbmap */
1239 if (copy_to_user(arg, &bmx, sizeof(struct getbmap)))
1240 return -XFS_ERROR(EFAULT);
1241 return 0;
1244 STATIC int
1245 xfs_getbmapx_format(void **ap, struct getbmapx *bmv, int *full)
1247 struct getbmapx __user *base = *ap;
1249 if (copy_to_user(base, bmv, sizeof(struct getbmapx)))
1250 return XFS_ERROR(EFAULT);
1252 *ap += sizeof(struct getbmapx);
1253 return 0;
1256 STATIC int
1257 xfs_ioc_getbmapx(
1258 struct xfs_inode *ip,
1259 void __user *arg)
1261 struct getbmapx bmx;
1262 int error;
1264 if (copy_from_user(&bmx, arg, sizeof(bmx)))
1265 return -XFS_ERROR(EFAULT);
1267 if (bmx.bmv_count < 2)
1268 return -XFS_ERROR(EINVAL);
1270 if (bmx.bmv_iflags & (~BMV_IF_VALID))
1271 return -XFS_ERROR(EINVAL);
1273 error = xfs_getbmap(ip, &bmx, xfs_getbmapx_format,
1274 (struct getbmapx *)arg+1);
1275 if (error)
1276 return -error;
1278 /* copy back header */
1279 if (copy_to_user(arg, &bmx, sizeof(struct getbmapx)))
1280 return -XFS_ERROR(EFAULT);
1282 return 0;
1286 * Note: some of the ioctl's return positive numbers as a
1287 * byte count indicating success, such as readlink_by_handle.
1288 * So we don't "sign flip" like most other routines. This means
1289 * true errors need to be returned as a negative value.
1291 long
1292 xfs_file_ioctl(
1293 struct file *filp,
1294 unsigned int cmd,
1295 unsigned long p)
1297 struct inode *inode = filp->f_path.dentry->d_inode;
1298 struct xfs_inode *ip = XFS_I(inode);
1299 struct xfs_mount *mp = ip->i_mount;
1300 void __user *arg = (void __user *)p;
1301 int ioflags = 0;
1302 int error;
1304 if (filp->f_mode & FMODE_NOCMTIME)
1305 ioflags |= IO_INVIS;
1307 xfs_itrace_entry(ip);
1309 switch (cmd) {
1310 case XFS_IOC_ALLOCSP:
1311 case XFS_IOC_FREESP:
1312 case XFS_IOC_RESVSP:
1313 case XFS_IOC_UNRESVSP:
1314 case XFS_IOC_ALLOCSP64:
1315 case XFS_IOC_FREESP64:
1316 case XFS_IOC_RESVSP64:
1317 case XFS_IOC_UNRESVSP64: {
1318 xfs_flock64_t bf;
1320 if (copy_from_user(&bf, arg, sizeof(bf)))
1321 return -XFS_ERROR(EFAULT);
1322 return xfs_ioc_space(ip, inode, filp, ioflags, cmd, &bf);
1324 case XFS_IOC_DIOINFO: {
1325 struct dioattr da;
1326 xfs_buftarg_t *target =
1327 XFS_IS_REALTIME_INODE(ip) ?
1328 mp->m_rtdev_targp : mp->m_ddev_targp;
1330 da.d_mem = da.d_miniosz = 1 << target->bt_sshift;
1331 da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1);
1333 if (copy_to_user(arg, &da, sizeof(da)))
1334 return -XFS_ERROR(EFAULT);
1335 return 0;
1338 case XFS_IOC_FSBULKSTAT_SINGLE:
1339 case XFS_IOC_FSBULKSTAT:
1340 case XFS_IOC_FSINUMBERS:
1341 return xfs_ioc_bulkstat(mp, cmd, arg);
1343 case XFS_IOC_FSGEOMETRY_V1:
1344 return xfs_ioc_fsgeometry_v1(mp, arg);
1346 case XFS_IOC_FSGEOMETRY:
1347 return xfs_ioc_fsgeometry(mp, arg);
1349 case XFS_IOC_GETVERSION:
1350 return put_user(inode->i_generation, (int __user *)arg);
1352 case XFS_IOC_FSGETXATTR:
1353 return xfs_ioc_fsgetxattr(ip, 0, arg);
1354 case XFS_IOC_FSGETXATTRA:
1355 return xfs_ioc_fsgetxattr(ip, 1, arg);
1356 case XFS_IOC_FSSETXATTR:
1357 return xfs_ioc_fssetxattr(ip, filp, arg);
1358 case XFS_IOC_GETXFLAGS:
1359 return xfs_ioc_getxflags(ip, arg);
1360 case XFS_IOC_SETXFLAGS:
1361 return xfs_ioc_setxflags(ip, filp, arg);
1363 case XFS_IOC_FSSETDM: {
1364 struct fsdmidata dmi;
1366 if (copy_from_user(&dmi, arg, sizeof(dmi)))
1367 return -XFS_ERROR(EFAULT);
1369 error = xfs_set_dmattrs(ip, dmi.fsd_dmevmask,
1370 dmi.fsd_dmstate);
1371 return -error;
1374 case XFS_IOC_GETBMAP:
1375 case XFS_IOC_GETBMAPA:
1376 return xfs_ioc_getbmap(ip, ioflags, cmd, arg);
1378 case XFS_IOC_GETBMAPX:
1379 return xfs_ioc_getbmapx(ip, arg);
1381 case XFS_IOC_FD_TO_HANDLE:
1382 case XFS_IOC_PATH_TO_HANDLE:
1383 case XFS_IOC_PATH_TO_FSHANDLE: {
1384 xfs_fsop_handlereq_t hreq;
1386 if (copy_from_user(&hreq, arg, sizeof(hreq)))
1387 return -XFS_ERROR(EFAULT);
1388 return xfs_find_handle(cmd, &hreq);
1390 case XFS_IOC_OPEN_BY_HANDLE: {
1391 xfs_fsop_handlereq_t hreq;
1393 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
1394 return -XFS_ERROR(EFAULT);
1395 return xfs_open_by_handle(filp, &hreq);
1397 case XFS_IOC_FSSETDM_BY_HANDLE:
1398 return xfs_fssetdm_by_handle(filp, arg);
1400 case XFS_IOC_READLINK_BY_HANDLE: {
1401 xfs_fsop_handlereq_t hreq;
1403 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
1404 return -XFS_ERROR(EFAULT);
1405 return xfs_readlink_by_handle(filp, &hreq);
1407 case XFS_IOC_ATTRLIST_BY_HANDLE:
1408 return xfs_attrlist_by_handle(filp, arg);
1410 case XFS_IOC_ATTRMULTI_BY_HANDLE:
1411 return xfs_attrmulti_by_handle(filp, arg);
1413 case XFS_IOC_SWAPEXT: {
1414 struct xfs_swapext sxp;
1416 if (copy_from_user(&sxp, arg, sizeof(xfs_swapext_t)))
1417 return -XFS_ERROR(EFAULT);
1418 error = xfs_swapext(&sxp);
1419 return -error;
1422 case XFS_IOC_FSCOUNTS: {
1423 xfs_fsop_counts_t out;
1425 error = xfs_fs_counts(mp, &out);
1426 if (error)
1427 return -error;
1429 if (copy_to_user(arg, &out, sizeof(out)))
1430 return -XFS_ERROR(EFAULT);
1431 return 0;
1434 case XFS_IOC_SET_RESBLKS: {
1435 xfs_fsop_resblks_t inout;
1436 __uint64_t in;
1438 if (!capable(CAP_SYS_ADMIN))
1439 return -EPERM;
1441 if (copy_from_user(&inout, arg, sizeof(inout)))
1442 return -XFS_ERROR(EFAULT);
1444 /* input parameter is passed in resblks field of structure */
1445 in = inout.resblks;
1446 error = xfs_reserve_blocks(mp, &in, &inout);
1447 if (error)
1448 return -error;
1450 if (copy_to_user(arg, &inout, sizeof(inout)))
1451 return -XFS_ERROR(EFAULT);
1452 return 0;
1455 case XFS_IOC_GET_RESBLKS: {
1456 xfs_fsop_resblks_t out;
1458 if (!capable(CAP_SYS_ADMIN))
1459 return -EPERM;
1461 error = xfs_reserve_blocks(mp, NULL, &out);
1462 if (error)
1463 return -error;
1465 if (copy_to_user(arg, &out, sizeof(out)))
1466 return -XFS_ERROR(EFAULT);
1468 return 0;
1471 case XFS_IOC_FSGROWFSDATA: {
1472 xfs_growfs_data_t in;
1474 if (copy_from_user(&in, arg, sizeof(in)))
1475 return -XFS_ERROR(EFAULT);
1477 error = xfs_growfs_data(mp, &in);
1478 return -error;
1481 case XFS_IOC_FSGROWFSLOG: {
1482 xfs_growfs_log_t in;
1484 if (copy_from_user(&in, arg, sizeof(in)))
1485 return -XFS_ERROR(EFAULT);
1487 error = xfs_growfs_log(mp, &in);
1488 return -error;
1491 case XFS_IOC_FSGROWFSRT: {
1492 xfs_growfs_rt_t in;
1494 if (copy_from_user(&in, arg, sizeof(in)))
1495 return -XFS_ERROR(EFAULT);
1497 error = xfs_growfs_rt(mp, &in);
1498 return -error;
1501 case XFS_IOC_GOINGDOWN: {
1502 __uint32_t in;
1504 if (!capable(CAP_SYS_ADMIN))
1505 return -EPERM;
1507 if (get_user(in, (__uint32_t __user *)arg))
1508 return -XFS_ERROR(EFAULT);
1510 error = xfs_fs_goingdown(mp, in);
1511 return -error;
1514 case XFS_IOC_ERROR_INJECTION: {
1515 xfs_error_injection_t in;
1517 if (!capable(CAP_SYS_ADMIN))
1518 return -EPERM;
1520 if (copy_from_user(&in, arg, sizeof(in)))
1521 return -XFS_ERROR(EFAULT);
1523 error = xfs_errortag_add(in.errtag, mp);
1524 return -error;
1527 case XFS_IOC_ERROR_CLEARALL:
1528 if (!capable(CAP_SYS_ADMIN))
1529 return -EPERM;
1531 error = xfs_errortag_clearall(mp, 1);
1532 return -error;
1534 default:
1535 return -ENOTTY;