2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
38 #include "xfs_trans.h"
42 #include "xfs_alloc.h"
43 #include "xfs_dmapi.h"
44 #include "xfs_mount.h"
45 #include "xfs_alloc_btree.h"
46 #include "xfs_bmap_btree.h"
47 #include "xfs_ialloc_btree.h"
48 #include "xfs_btree.h"
49 #include "xfs_ialloc.h"
50 #include "xfs_attr_sf.h"
51 #include "xfs_dir_sf.h"
52 #include "xfs_dir2_sf.h"
53 #include "xfs_dinode.h"
54 #include "xfs_inode.h"
57 #include "xfs_rtalloc.h"
58 #include "xfs_error.h"
59 #include "xfs_itable.h"
65 #include "xfs_buf_item.h"
66 #include "xfs_utils.h"
67 #include "xfs_dfrag.h"
68 #include "xfs_fsops.h"
70 #include <linux/dcache.h>
71 #include <linux/mount.h>
72 #include <linux/namei.h>
73 #include <linux/pagemap.h>
76 * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to
77 * a file or fs handle.
79 * XFS_IOC_PATH_TO_FSHANDLE
80 * returns fs handle for a mount point or path within that mount point
81 * XFS_IOC_FD_TO_HANDLE
82 * returns full handle for a FD opened in user space
83 * XFS_IOC_PATH_TO_HANDLE
84 * returns full handle for a path
93 xfs_fsop_handlereq_t hreq;
97 if (copy_from_user(&hreq, arg, sizeof(hreq)))
98 return -XFS_ERROR(EFAULT);
100 memset((char *)&handle, 0, sizeof(handle));
103 case XFS_IOC_PATH_TO_FSHANDLE:
104 case XFS_IOC_PATH_TO_HANDLE: {
108 error = user_path_walk_link((const char __user *)hreq.path, &nd);
113 ASSERT(nd.dentry->d_inode);
114 inode = igrab(nd.dentry->d_inode);
119 case XFS_IOC_FD_TO_HANDLE: {
122 file = fget(hreq.fd);
126 ASSERT(file->f_dentry);
127 ASSERT(file->f_dentry->d_inode);
128 inode = igrab(file->f_dentry->d_inode);
135 return -XFS_ERROR(EINVAL);
138 if (inode->i_sb->s_magic != XFS_SB_MAGIC) {
139 /* we're not in XFS anymore, Toto */
141 return -XFS_ERROR(EINVAL);
144 switch (inode->i_mode & S_IFMT) {
151 return -XFS_ERROR(EBADF);
154 /* we need the vnode */
155 vp = LINVFS_GET_VP(inode);
157 /* now we can grab the fsid */
158 memcpy(&handle.ha_fsid, vp->v_vfsp->vfs_altfsid, sizeof(xfs_fsid_t));
159 hsize = sizeof(xfs_fsid_t);
161 if (cmd != XFS_IOC_PATH_TO_FSHANDLE) {
166 /* need to get access to the xfs_inode to read the generation */
167 bhv = vn_bhv_lookup_unlocked(VN_BHV_HEAD(vp), &xfs_vnodeops);
169 ip = XFS_BHVTOI(bhv);
171 lock_mode = xfs_ilock_map_shared(ip);
173 /* fill in fid section of handle from inode */
174 handle.ha_fid.xfs_fid_len = sizeof(xfs_fid_t) -
175 sizeof(handle.ha_fid.xfs_fid_len);
176 handle.ha_fid.xfs_fid_pad = 0;
177 handle.ha_fid.xfs_fid_gen = ip->i_d.di_gen;
178 handle.ha_fid.xfs_fid_ino = ip->i_ino;
180 xfs_iunlock_map_shared(ip, lock_mode);
182 hsize = XFS_HSIZE(handle);
185 /* now copy our handle into the user buffer & write out the size */
186 if (copy_to_user(hreq.ohandle, &handle, hsize) ||
187 copy_to_user(hreq.ohandlen, &hsize, sizeof(__s32))) {
189 return -XFS_ERROR(EFAULT);
198 * Convert userspace handle data into vnode (and inode).
199 * We [ab]use the fact that all the fsop_handlereq ioctl calls
200 * have a data structure argument whose first component is always
201 * a xfs_fsop_handlereq_t, so we can cast to and from this type.
202 * This allows us to optimise the copy_from_user calls and gives
203 * a handy, shared routine.
205 * If no error, caller must always VN_RELE the returned vp.
208 xfs_vget_fsop_handlereq(
210 struct inode *parinode, /* parent inode pointer */
211 xfs_fsop_handlereq_t *hreq,
213 struct inode **inode)
218 xfs_handle_t *handlep;
221 struct inode *inodep;
228 * Only allow handle opens under a directory.
230 if (!S_ISDIR(parinode->i_mode))
231 return XFS_ERROR(ENOTDIR);
233 hanp = hreq->ihandle;
234 hlen = hreq->ihandlen;
237 if (hlen < sizeof(handlep->ha_fsid) || hlen > sizeof(*handlep))
238 return XFS_ERROR(EINVAL);
239 if (copy_from_user(handlep, hanp, hlen))
240 return XFS_ERROR(EFAULT);
241 if (hlen < sizeof(*handlep))
242 memset(((char *)handlep) + hlen, 0, sizeof(*handlep) - hlen);
243 if (hlen > sizeof(handlep->ha_fsid)) {
244 if (handlep->ha_fid.xfs_fid_len !=
245 (hlen - sizeof(handlep->ha_fsid)
246 - sizeof(handlep->ha_fid.xfs_fid_len))
247 || handlep->ha_fid.xfs_fid_pad)
248 return XFS_ERROR(EINVAL);
252 * Crack the handle, obtain the inode # & generation #
254 xfid = (struct xfs_fid *)&handlep->ha_fid;
255 if (xfid->xfs_fid_len == sizeof(*xfid) - sizeof(xfid->xfs_fid_len)) {
256 ino = xfid->xfs_fid_ino;
257 igen = xfid->xfs_fid_gen;
259 return XFS_ERROR(EINVAL);
263 * Get the XFS inode, building a vnode to go with it.
265 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
269 return XFS_ERROR(EIO);
270 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
271 xfs_iput_new(ip, XFS_ILOCK_SHARED);
272 return XFS_ERROR(ENOENT);
276 inodep = LINVFS_GET_IP(vpp);
277 xfs_iunlock(ip, XFS_ILOCK_SHARED);
288 struct file *parfilp,
289 struct inode *parinode)
296 struct dentry *dentry;
298 xfs_fsop_handlereq_t hreq;
300 if (!capable(CAP_SYS_ADMIN))
301 return -XFS_ERROR(EPERM);
302 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
303 return -XFS_ERROR(EFAULT);
305 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
309 /* Restrict xfs_open_by_handle to directories & regular files. */
310 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
312 return -XFS_ERROR(EINVAL);
315 #if BITS_PER_LONG != 32
316 hreq.oflags |= O_LARGEFILE;
318 /* Put open permission in namei format. */
319 permflag = hreq.oflags;
320 if ((permflag+1) & O_ACCMODE)
322 if (permflag & O_TRUNC)
325 if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
326 (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
328 return -XFS_ERROR(EPERM);
331 if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
333 return -XFS_ERROR(EACCES);
336 /* Can't write directories. */
337 if ( S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
339 return -XFS_ERROR(EISDIR);
342 if ((new_fd = get_unused_fd()) < 0) {
347 dentry = d_alloc_anon(inode);
348 if (dentry == NULL) {
350 put_unused_fd(new_fd);
351 return -XFS_ERROR(ENOMEM);
354 /* Ensure umount returns EBUSY on umounts while this file is open. */
355 mntget(parfilp->f_vfsmnt);
357 /* Create file pointer. */
358 filp = dentry_open(dentry, parfilp->f_vfsmnt, hreq.oflags);
360 put_unused_fd(new_fd);
361 return -XFS_ERROR(-PTR_ERR(filp));
363 if (inode->i_mode & S_IFREG)
364 filp->f_op = &linvfs_invis_file_operations;
366 fd_install(new_fd, filp);
371 xfs_readlink_by_handle(
374 struct file *parfilp,
375 struct inode *parinode)
381 xfs_fsop_handlereq_t hreq;
385 if (!capable(CAP_SYS_ADMIN))
386 return -XFS_ERROR(EPERM);
387 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
388 return -XFS_ERROR(EFAULT);
390 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
394 /* Restrict this handle operation to symlinks only. */
395 if (!S_ISLNK(inode->i_mode)) {
397 return -XFS_ERROR(EINVAL);
400 if (copy_from_user(&olen, hreq.ohandlen, sizeof(__u32))) {
402 return -XFS_ERROR(EFAULT);
405 aiov.iov_base = hreq.ohandle;
407 auio.uio_iov = &aiov;
410 auio.uio_segflg = UIO_USERSPACE;
411 auio.uio_resid = olen;
413 VOP_READLINK(vp, &auio, IO_INVIS, NULL, error);
416 return (olen - auio.uio_resid);
420 xfs_fssetdm_by_handle(
423 struct file *parfilp,
424 struct inode *parinode)
427 struct fsdmidata fsd;
428 xfs_fsop_setdm_handlereq_t dmhreq;
433 if (!capable(CAP_MKNOD))
434 return -XFS_ERROR(EPERM);
435 if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t)))
436 return -XFS_ERROR(EFAULT);
438 error = xfs_vget_fsop_handlereq(mp, parinode, &dmhreq.hreq, &vp, &inode);
442 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
444 return -XFS_ERROR(EPERM);
447 if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
449 return -XFS_ERROR(EFAULT);
452 bdp = bhv_base_unlocked(VN_BHV_HEAD(vp));
453 error = xfs_set_dmattrs(bdp, fsd.fsd_dmevmask, fsd.fsd_dmstate, NULL);
462 xfs_attrlist_by_handle(
465 struct file *parfilp,
466 struct inode *parinode)
469 attrlist_cursor_kern_t *cursor;
470 xfs_fsop_attrlist_handlereq_t al_hreq;
475 if (!capable(CAP_SYS_ADMIN))
476 return -XFS_ERROR(EPERM);
477 if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t)))
478 return -XFS_ERROR(EFAULT);
479 if (al_hreq.buflen > XATTR_LIST_MAX)
480 return -XFS_ERROR(EINVAL);
482 error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq,
487 kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
491 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
492 VOP_ATTR_LIST(vp, kbuf, al_hreq.buflen, al_hreq.flags,
493 cursor, NULL, error);
497 if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen))
509 xfs_attrmulti_attr_get(
519 if (*len > XATTR_SIZE_MAX)
521 kbuf = kmalloc(*len, GFP_KERNEL);
525 VOP_ATTR_GET(vp, name, kbuf, len, flags, NULL, error);
529 if (copy_to_user(ubuf, kbuf, *len))
538 xfs_attrmulti_attr_set(
541 const char __user *ubuf,
548 if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
550 if (len > XATTR_SIZE_MAX)
553 kbuf = kmalloc(len, GFP_KERNEL);
557 if (copy_from_user(kbuf, ubuf, len))
560 VOP_ATTR_SET(vp, name, kbuf, len, flags, NULL, error);
568 xfs_attrmulti_attr_remove(
575 if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
578 VOP_ATTR_REMOVE(vp, name, flags, NULL, error);
583 xfs_attrmulti_by_handle(
586 struct file *parfilp,
587 struct inode *parinode)
590 xfs_attr_multiop_t *ops;
591 xfs_fsop_attrmulti_handlereq_t am_hreq;
594 unsigned int i, size;
597 if (!capable(CAP_SYS_ADMIN))
598 return -XFS_ERROR(EPERM);
599 if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t)))
600 return -XFS_ERROR(EFAULT);
602 error = xfs_vget_fsop_handlereq(mp, parinode, &am_hreq.hreq, &vp, &inode);
607 size = am_hreq.opcount * sizeof(attr_multiop_t);
608 if (!size || size > 16 * PAGE_SIZE)
612 ops = kmalloc(size, GFP_KERNEL);
617 if (copy_from_user(ops, am_hreq.ops, size))
620 attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
626 for (i = 0; i < am_hreq.opcount; i++) {
627 ops[i].am_error = strncpy_from_user(attr_name,
628 ops[i].am_attrname, MAXNAMELEN);
629 if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
631 if (ops[i].am_error < 0)
634 switch (ops[i].am_opcode) {
636 ops[i].am_error = xfs_attrmulti_attr_get(vp,
637 attr_name, ops[i].am_attrvalue,
638 &ops[i].am_length, ops[i].am_flags);
641 ops[i].am_error = xfs_attrmulti_attr_set(vp,
642 attr_name, ops[i].am_attrvalue,
643 ops[i].am_length, ops[i].am_flags);
646 ops[i].am_error = xfs_attrmulti_attr_remove(vp,
647 attr_name, ops[i].am_flags);
650 ops[i].am_error = EINVAL;
654 if (copy_to_user(am_hreq.ops, ops, size))
655 error = XFS_ERROR(EFAULT);
666 /* prototypes for a few of the stack-hungry cases that have
667 * their own functions. Functions are defined after their use
668 * so gcc doesn't get fancy and inline them with -03 */
686 xfs_ioc_fsgeometry_v1(
730 vp = LINVFS_GET_VP(inode);
732 vn_trace_entry(vp, "xfs_ioctl", (inst_t *)__return_address);
734 ip = XFS_BHVTOI(bdp);
739 case XFS_IOC_ALLOCSP:
742 case XFS_IOC_UNRESVSP:
743 case XFS_IOC_ALLOCSP64:
744 case XFS_IOC_FREESP64:
745 case XFS_IOC_RESVSP64:
746 case XFS_IOC_UNRESVSP64:
748 * Only allow the sys admin to reserve space unless
749 * unwritten extents are enabled.
751 if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb) &&
752 !capable(CAP_SYS_ADMIN))
755 return xfs_ioc_space(bdp, vp, filp, ioflags, cmd, arg);
757 case XFS_IOC_DIOINFO: {
759 xfs_buftarg_t *target =
760 (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
761 mp->m_rtdev_targp : mp->m_ddev_targp;
763 da.d_mem = da.d_miniosz = 1 << target->pbr_sshift;
764 /* The size dio will do in one go */
765 da.d_maxiosz = 64 * PAGE_CACHE_SIZE;
767 if (copy_to_user(arg, &da, sizeof(da)))
768 return -XFS_ERROR(EFAULT);
772 case XFS_IOC_FSBULKSTAT_SINGLE:
773 case XFS_IOC_FSBULKSTAT:
774 case XFS_IOC_FSINUMBERS:
775 return xfs_ioc_bulkstat(mp, cmd, arg);
777 case XFS_IOC_FSGEOMETRY_V1:
778 return xfs_ioc_fsgeometry_v1(mp, arg);
780 case XFS_IOC_FSGEOMETRY:
781 return xfs_ioc_fsgeometry(mp, arg);
783 case XFS_IOC_GETVERSION:
784 case XFS_IOC_GETXFLAGS:
785 case XFS_IOC_SETXFLAGS:
786 case XFS_IOC_FSGETXATTR:
787 case XFS_IOC_FSSETXATTR:
788 case XFS_IOC_FSGETXATTRA:
789 return xfs_ioc_xattr(vp, ip, filp, cmd, arg);
791 case XFS_IOC_FSSETDM: {
792 struct fsdmidata dmi;
794 if (copy_from_user(&dmi, arg, sizeof(dmi)))
795 return -XFS_ERROR(EFAULT);
797 error = xfs_set_dmattrs(bdp, dmi.fsd_dmevmask, dmi.fsd_dmstate,
802 case XFS_IOC_GETBMAP:
803 case XFS_IOC_GETBMAPA:
804 return xfs_ioc_getbmap(bdp, filp, ioflags, cmd, arg);
806 case XFS_IOC_GETBMAPX:
807 return xfs_ioc_getbmapx(bdp, arg);
809 case XFS_IOC_FD_TO_HANDLE:
810 case XFS_IOC_PATH_TO_HANDLE:
811 case XFS_IOC_PATH_TO_FSHANDLE:
812 return xfs_find_handle(cmd, arg);
814 case XFS_IOC_OPEN_BY_HANDLE:
815 return xfs_open_by_handle(mp, arg, filp, inode);
817 case XFS_IOC_FSSETDM_BY_HANDLE:
818 return xfs_fssetdm_by_handle(mp, arg, filp, inode);
820 case XFS_IOC_READLINK_BY_HANDLE:
821 return xfs_readlink_by_handle(mp, arg, filp, inode);
823 case XFS_IOC_ATTRLIST_BY_HANDLE:
824 return xfs_attrlist_by_handle(mp, arg, filp, inode);
826 case XFS_IOC_ATTRMULTI_BY_HANDLE:
827 return xfs_attrmulti_by_handle(mp, arg, filp, inode);
829 case XFS_IOC_SWAPEXT: {
830 error = xfs_swapext((struct xfs_swapext __user *)arg);
834 case XFS_IOC_FSCOUNTS: {
835 xfs_fsop_counts_t out;
837 error = xfs_fs_counts(mp, &out);
841 if (copy_to_user(arg, &out, sizeof(out)))
842 return -XFS_ERROR(EFAULT);
846 case XFS_IOC_SET_RESBLKS: {
847 xfs_fsop_resblks_t inout;
850 if (!capable(CAP_SYS_ADMIN))
853 if (copy_from_user(&inout, arg, sizeof(inout)))
854 return -XFS_ERROR(EFAULT);
856 /* input parameter is passed in resblks field of structure */
858 error = xfs_reserve_blocks(mp, &in, &inout);
862 if (copy_to_user(arg, &inout, sizeof(inout)))
863 return -XFS_ERROR(EFAULT);
867 case XFS_IOC_GET_RESBLKS: {
868 xfs_fsop_resblks_t out;
870 if (!capable(CAP_SYS_ADMIN))
873 error = xfs_reserve_blocks(mp, NULL, &out);
877 if (copy_to_user(arg, &out, sizeof(out)))
878 return -XFS_ERROR(EFAULT);
883 case XFS_IOC_FSGROWFSDATA: {
884 xfs_growfs_data_t in;
886 if (!capable(CAP_SYS_ADMIN))
889 if (copy_from_user(&in, arg, sizeof(in)))
890 return -XFS_ERROR(EFAULT);
892 error = xfs_growfs_data(mp, &in);
896 case XFS_IOC_FSGROWFSLOG: {
899 if (!capable(CAP_SYS_ADMIN))
902 if (copy_from_user(&in, arg, sizeof(in)))
903 return -XFS_ERROR(EFAULT);
905 error = xfs_growfs_log(mp, &in);
909 case XFS_IOC_FSGROWFSRT: {
912 if (!capable(CAP_SYS_ADMIN))
915 if (copy_from_user(&in, arg, sizeof(in)))
916 return -XFS_ERROR(EFAULT);
918 error = xfs_growfs_rt(mp, &in);
923 if (!capable(CAP_SYS_ADMIN))
926 if (inode->i_sb->s_frozen == SB_UNFROZEN)
927 freeze_bdev(inode->i_sb->s_bdev);
931 if (!capable(CAP_SYS_ADMIN))
933 if (inode->i_sb->s_frozen != SB_UNFROZEN)
934 thaw_bdev(inode->i_sb->s_bdev, inode->i_sb);
937 case XFS_IOC_GOINGDOWN: {
940 if (!capable(CAP_SYS_ADMIN))
943 if (get_user(in, (__uint32_t __user *)arg))
944 return -XFS_ERROR(EFAULT);
946 error = xfs_fs_goingdown(mp, in);
950 case XFS_IOC_ERROR_INJECTION: {
951 xfs_error_injection_t in;
953 if (!capable(CAP_SYS_ADMIN))
956 if (copy_from_user(&in, arg, sizeof(in)))
957 return -XFS_ERROR(EFAULT);
959 error = xfs_errortag_add(in.errtag, mp);
963 case XFS_IOC_ERROR_CLEARALL:
964 if (!capable(CAP_SYS_ADMIN))
967 error = xfs_errortag_clearall(mp);
988 if (vp->v_inode.i_flags & (S_IMMUTABLE|S_APPEND))
989 return -XFS_ERROR(EPERM);
991 if (!(filp->f_mode & FMODE_WRITE))
992 return -XFS_ERROR(EBADF);
995 return -XFS_ERROR(EINVAL);
997 if (copy_from_user(&bf, arg, sizeof(bf)))
998 return -XFS_ERROR(EFAULT);
1000 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1001 attr_flags |= ATTR_NONBLOCK;
1002 if (ioflags & IO_INVIS)
1003 attr_flags |= ATTR_DMI;
1005 error = xfs_change_file_space(bdp, cmd, &bf, filp->f_pos,
1016 xfs_fsop_bulkreq_t bulkreq;
1017 int count; /* # of records returned */
1018 xfs_ino_t inlast; /* last inode number */
1022 /* done = 1 if there are more stats to get and if bulkstat */
1023 /* should be called again (unused here, but used in dmapi) */
1025 if (!capable(CAP_SYS_ADMIN))
1028 if (XFS_FORCED_SHUTDOWN(mp))
1029 return -XFS_ERROR(EIO);
1031 if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t)))
1032 return -XFS_ERROR(EFAULT);
1034 if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
1035 return -XFS_ERROR(EFAULT);
1037 if ((count = bulkreq.icount) <= 0)
1038 return -XFS_ERROR(EINVAL);
1040 if (cmd == XFS_IOC_FSINUMBERS)
1041 error = xfs_inumbers(mp, &inlast, &count,
1043 else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE)
1044 error = xfs_bulkstat_single(mp, &inlast,
1045 bulkreq.ubuffer, &done);
1046 else { /* XFS_IOC_FSBULKSTAT */
1047 if (count == 1 && inlast != 0) {
1049 error = xfs_bulkstat_single(mp, &inlast,
1050 bulkreq.ubuffer, &done);
1052 error = xfs_bulkstat(mp, &inlast, &count,
1053 (bulkstat_one_pf)xfs_bulkstat_one, NULL,
1054 sizeof(xfs_bstat_t), bulkreq.ubuffer,
1055 BULKSTAT_FG_QUICK, &done);
1062 if (bulkreq.ocount != NULL) {
1063 if (copy_to_user(bulkreq.lastip, &inlast,
1065 return -XFS_ERROR(EFAULT);
1067 if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
1068 return -XFS_ERROR(EFAULT);
1075 xfs_ioc_fsgeometry_v1(
1079 xfs_fsop_geom_v1_t fsgeo;
1082 error = xfs_fs_geometry(mp, (xfs_fsop_geom_t *)&fsgeo, 3);
1086 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
1087 return -XFS_ERROR(EFAULT);
1096 xfs_fsop_geom_t fsgeo;
1099 error = xfs_fs_geometry(mp, &fsgeo, 4);
1103 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
1104 return -XFS_ERROR(EFAULT);
1109 * Linux extended inode flags interface.
1111 #define LINUX_XFLAG_SYNC 0x00000008 /* Synchronous updates */
1112 #define LINUX_XFLAG_IMMUTABLE 0x00000010 /* Immutable file */
1113 #define LINUX_XFLAG_APPEND 0x00000020 /* writes to file may only append */
1114 #define LINUX_XFLAG_NODUMP 0x00000040 /* do not dump file */
1115 #define LINUX_XFLAG_NOATIME 0x00000080 /* do not update atime */
1118 xfs_merge_ioc_xflags(
1122 unsigned int xflags = start;
1124 if (flags & LINUX_XFLAG_IMMUTABLE)
1125 xflags |= XFS_XFLAG_IMMUTABLE;
1127 xflags &= ~XFS_XFLAG_IMMUTABLE;
1128 if (flags & LINUX_XFLAG_APPEND)
1129 xflags |= XFS_XFLAG_APPEND;
1131 xflags &= ~XFS_XFLAG_APPEND;
1132 if (flags & LINUX_XFLAG_SYNC)
1133 xflags |= XFS_XFLAG_SYNC;
1135 xflags &= ~XFS_XFLAG_SYNC;
1136 if (flags & LINUX_XFLAG_NOATIME)
1137 xflags |= XFS_XFLAG_NOATIME;
1139 xflags &= ~XFS_XFLAG_NOATIME;
1140 if (flags & LINUX_XFLAG_NODUMP)
1141 xflags |= XFS_XFLAG_NODUMP;
1143 xflags &= ~XFS_XFLAG_NODUMP;
1150 __uint16_t di_flags)
1152 unsigned int flags = 0;
1154 if (di_flags & XFS_DIFLAG_IMMUTABLE)
1155 flags |= LINUX_XFLAG_IMMUTABLE;
1156 if (di_flags & XFS_DIFLAG_APPEND)
1157 flags |= LINUX_XFLAG_APPEND;
1158 if (di_flags & XFS_DIFLAG_SYNC)
1159 flags |= LINUX_XFLAG_SYNC;
1160 if (di_flags & XFS_DIFLAG_NOATIME)
1161 flags |= LINUX_XFLAG_NOATIME;
1162 if (di_flags & XFS_DIFLAG_NODUMP)
1163 flags |= LINUX_XFLAG_NODUMP;
1182 case XFS_IOC_FSGETXATTR: {
1183 va.va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | \
1184 XFS_AT_NEXTENTS | XFS_AT_PROJID;
1185 VOP_GETATTR(vp, &va, 0, NULL, error);
1189 fa.fsx_xflags = va.va_xflags;
1190 fa.fsx_extsize = va.va_extsize;
1191 fa.fsx_nextents = va.va_nextents;
1192 fa.fsx_projid = va.va_projid;
1194 if (copy_to_user(arg, &fa, sizeof(fa)))
1195 return -XFS_ERROR(EFAULT);
1199 case XFS_IOC_FSSETXATTR: {
1200 if (copy_from_user(&fa, arg, sizeof(fa)))
1201 return -XFS_ERROR(EFAULT);
1204 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1205 attr_flags |= ATTR_NONBLOCK;
1207 va.va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | XFS_AT_PROJID;
1208 va.va_xflags = fa.fsx_xflags;
1209 va.va_extsize = fa.fsx_extsize;
1210 va.va_projid = fa.fsx_projid;
1212 VOP_SETATTR(vp, &va, attr_flags, NULL, error);
1214 vn_revalidate(vp); /* update Linux inode flags */
1218 case XFS_IOC_FSGETXATTRA: {
1219 va.va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | \
1220 XFS_AT_ANEXTENTS | XFS_AT_PROJID;
1221 VOP_GETATTR(vp, &va, 0, NULL, error);
1225 fa.fsx_xflags = va.va_xflags;
1226 fa.fsx_extsize = va.va_extsize;
1227 fa.fsx_nextents = va.va_anextents;
1228 fa.fsx_projid = va.va_projid;
1230 if (copy_to_user(arg, &fa, sizeof(fa)))
1231 return -XFS_ERROR(EFAULT);
1235 case XFS_IOC_GETXFLAGS: {
1236 flags = xfs_di2lxflags(ip->i_d.di_flags);
1237 if (copy_to_user(arg, &flags, sizeof(flags)))
1238 return -XFS_ERROR(EFAULT);
1242 case XFS_IOC_SETXFLAGS: {
1243 if (copy_from_user(&flags, arg, sizeof(flags)))
1244 return -XFS_ERROR(EFAULT);
1246 if (flags & ~(LINUX_XFLAG_IMMUTABLE | LINUX_XFLAG_APPEND | \
1247 LINUX_XFLAG_NOATIME | LINUX_XFLAG_NODUMP | \
1249 return -XFS_ERROR(EOPNOTSUPP);
1252 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1253 attr_flags |= ATTR_NONBLOCK;
1255 va.va_mask = XFS_AT_XFLAGS;
1256 va.va_xflags = xfs_merge_ioc_xflags(flags,
1259 VOP_SETATTR(vp, &va, attr_flags, NULL, error);
1261 vn_revalidate(vp); /* update Linux inode flags */
1265 case XFS_IOC_GETVERSION: {
1266 flags = LINVFS_GET_IP(vp)->i_generation;
1267 if (copy_to_user(arg, &flags, sizeof(flags)))
1268 return -XFS_ERROR(EFAULT);
1289 if (copy_from_user(&bm, arg, sizeof(bm)))
1290 return -XFS_ERROR(EFAULT);
1292 if (bm.bmv_count < 2)
1293 return -XFS_ERROR(EINVAL);
1295 iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0);
1296 if (ioflags & IO_INVIS)
1297 iflags |= BMV_IF_NO_DMAPI_READ;
1299 error = xfs_getbmap(bdp, &bm, (struct getbmap __user *)arg+1, iflags);
1303 if (copy_to_user(arg, &bm, sizeof(bm)))
1304 return -XFS_ERROR(EFAULT);
1313 struct getbmapx bmx;
1318 if (copy_from_user(&bmx, arg, sizeof(bmx)))
1319 return -XFS_ERROR(EFAULT);
1321 if (bmx.bmv_count < 2)
1322 return -XFS_ERROR(EINVAL);
1325 * Map input getbmapx structure to a getbmap
1326 * structure for xfs_getbmap.
1328 GETBMAP_CONVERT(bmx, bm);
1330 iflags = bmx.bmv_iflags;
1332 if (iflags & (~BMV_IF_VALID))
1333 return -XFS_ERROR(EINVAL);
1335 iflags |= BMV_IF_EXTENDED;
1337 error = xfs_getbmap(bdp, &bm, (struct getbmapx __user *)arg+1, iflags);
1341 GETBMAP_CONVERT(bm, bmx);
1343 if (copy_to_user(arg, &bmx, sizeof(bmx)))
1344 return -XFS_ERROR(EFAULT);