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 /* we need the vnode */
145 vp = LINVFS_GET_VP(inode);
146 if (vp->v_type != VREG && vp->v_type != VDIR && vp->v_type != VLNK) {
148 return -XFS_ERROR(EBADF);
151 /* now we can grab the fsid */
152 memcpy(&handle.ha_fsid, vp->v_vfsp->vfs_altfsid, sizeof(xfs_fsid_t));
153 hsize = sizeof(xfs_fsid_t);
155 if (cmd != XFS_IOC_PATH_TO_FSHANDLE) {
160 /* need to get access to the xfs_inode to read the generation */
161 bhv = vn_bhv_lookup_unlocked(VN_BHV_HEAD(vp), &xfs_vnodeops);
163 ip = XFS_BHVTOI(bhv);
165 lock_mode = xfs_ilock_map_shared(ip);
167 /* fill in fid section of handle from inode */
168 handle.ha_fid.xfs_fid_len = sizeof(xfs_fid_t) -
169 sizeof(handle.ha_fid.xfs_fid_len);
170 handle.ha_fid.xfs_fid_pad = 0;
171 handle.ha_fid.xfs_fid_gen = ip->i_d.di_gen;
172 handle.ha_fid.xfs_fid_ino = ip->i_ino;
174 xfs_iunlock_map_shared(ip, lock_mode);
176 hsize = XFS_HSIZE(handle);
179 /* now copy our handle into the user buffer & write out the size */
180 if (copy_to_user(hreq.ohandle, &handle, hsize) ||
181 copy_to_user(hreq.ohandlen, &hsize, sizeof(__s32))) {
183 return -XFS_ERROR(EFAULT);
192 * Convert userspace handle data into vnode (and inode).
193 * We [ab]use the fact that all the fsop_handlereq ioctl calls
194 * have a data structure argument whose first component is always
195 * a xfs_fsop_handlereq_t, so we can cast to and from this type.
196 * This allows us to optimise the copy_from_user calls and gives
197 * a handy, shared routine.
199 * If no error, caller must always VN_RELE the returned vp.
202 xfs_vget_fsop_handlereq(
204 struct inode *parinode, /* parent inode pointer */
205 xfs_fsop_handlereq_t *hreq,
207 struct inode **inode)
212 xfs_handle_t *handlep;
215 struct inode *inodep;
222 * Only allow handle opens under a directory.
224 if (!S_ISDIR(parinode->i_mode))
225 return XFS_ERROR(ENOTDIR);
227 hanp = hreq->ihandle;
228 hlen = hreq->ihandlen;
231 if (hlen < sizeof(handlep->ha_fsid) || hlen > sizeof(*handlep))
232 return XFS_ERROR(EINVAL);
233 if (copy_from_user(handlep, hanp, hlen))
234 return XFS_ERROR(EFAULT);
235 if (hlen < sizeof(*handlep))
236 memset(((char *)handlep) + hlen, 0, sizeof(*handlep) - hlen);
237 if (hlen > sizeof(handlep->ha_fsid)) {
238 if (handlep->ha_fid.xfs_fid_len !=
239 (hlen - sizeof(handlep->ha_fsid)
240 - sizeof(handlep->ha_fid.xfs_fid_len))
241 || handlep->ha_fid.xfs_fid_pad)
242 return XFS_ERROR(EINVAL);
246 * Crack the handle, obtain the inode # & generation #
248 xfid = (struct xfs_fid *)&handlep->ha_fid;
249 if (xfid->xfs_fid_len == sizeof(*xfid) - sizeof(xfid->xfs_fid_len)) {
250 ino = xfid->xfs_fid_ino;
251 igen = xfid->xfs_fid_gen;
253 return XFS_ERROR(EINVAL);
257 * Get the XFS inode, building a vnode to go with it.
259 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
263 return XFS_ERROR(EIO);
264 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
265 xfs_iput_new(ip, XFS_ILOCK_SHARED);
266 return XFS_ERROR(ENOENT);
270 inodep = LINVFS_GET_IP(vpp);
271 xfs_iunlock(ip, XFS_ILOCK_SHARED);
282 struct file *parfilp,
283 struct inode *parinode)
290 struct dentry *dentry;
292 xfs_fsop_handlereq_t hreq;
294 if (!capable(CAP_SYS_ADMIN))
295 return -XFS_ERROR(EPERM);
296 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
297 return -XFS_ERROR(EFAULT);
299 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
303 /* Restrict xfs_open_by_handle to directories & regular files. */
304 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
306 return -XFS_ERROR(EINVAL);
309 #if BITS_PER_LONG != 32
310 hreq.oflags |= O_LARGEFILE;
312 /* Put open permission in namei format. */
313 permflag = hreq.oflags;
314 if ((permflag+1) & O_ACCMODE)
316 if (permflag & O_TRUNC)
319 if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
320 (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
322 return -XFS_ERROR(EPERM);
325 if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
327 return -XFS_ERROR(EACCES);
330 /* Can't write directories. */
331 if ( S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
333 return -XFS_ERROR(EISDIR);
336 if ((new_fd = get_unused_fd()) < 0) {
341 dentry = d_alloc_anon(inode);
342 if (dentry == NULL) {
344 put_unused_fd(new_fd);
345 return -XFS_ERROR(ENOMEM);
348 /* Ensure umount returns EBUSY on umounts while this file is open. */
349 mntget(parfilp->f_vfsmnt);
351 /* Create file pointer. */
352 filp = dentry_open(dentry, parfilp->f_vfsmnt, hreq.oflags);
354 put_unused_fd(new_fd);
355 return -XFS_ERROR(-PTR_ERR(filp));
357 if (inode->i_mode & S_IFREG)
358 filp->f_op = &linvfs_invis_file_operations;
360 fd_install(new_fd, filp);
365 xfs_readlink_by_handle(
368 struct file *parfilp,
369 struct inode *parinode)
375 xfs_fsop_handlereq_t hreq;
379 if (!capable(CAP_SYS_ADMIN))
380 return -XFS_ERROR(EPERM);
381 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
382 return -XFS_ERROR(EFAULT);
384 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
388 /* Restrict this handle operation to symlinks only. */
389 if (vp->v_type != VLNK) {
391 return -XFS_ERROR(EINVAL);
394 if (copy_from_user(&olen, hreq.ohandlen, sizeof(__u32))) {
396 return -XFS_ERROR(EFAULT);
399 aiov.iov_base = hreq.ohandle;
401 auio.uio_iov = &aiov;
404 auio.uio_segflg = UIO_USERSPACE;
405 auio.uio_resid = olen;
407 VOP_READLINK(vp, &auio, IO_INVIS, NULL, error);
410 return (olen - auio.uio_resid);
414 xfs_fssetdm_by_handle(
417 struct file *parfilp,
418 struct inode *parinode)
421 struct fsdmidata fsd;
422 xfs_fsop_setdm_handlereq_t dmhreq;
427 if (!capable(CAP_MKNOD))
428 return -XFS_ERROR(EPERM);
429 if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t)))
430 return -XFS_ERROR(EFAULT);
432 error = xfs_vget_fsop_handlereq(mp, parinode, &dmhreq.hreq, &vp, &inode);
436 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
438 return -XFS_ERROR(EPERM);
441 if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
443 return -XFS_ERROR(EFAULT);
446 bdp = bhv_base_unlocked(VN_BHV_HEAD(vp));
447 error = xfs_set_dmattrs(bdp, fsd.fsd_dmevmask, fsd.fsd_dmstate, NULL);
456 xfs_attrlist_by_handle(
459 struct file *parfilp,
460 struct inode *parinode)
463 attrlist_cursor_kern_t *cursor;
464 xfs_fsop_attrlist_handlereq_t al_hreq;
469 if (!capable(CAP_SYS_ADMIN))
470 return -XFS_ERROR(EPERM);
471 if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t)))
472 return -XFS_ERROR(EFAULT);
473 if (al_hreq.buflen > XATTR_LIST_MAX)
474 return -XFS_ERROR(EINVAL);
476 error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq,
481 kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
485 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
486 VOP_ATTR_LIST(vp, kbuf, al_hreq.buflen, al_hreq.flags,
487 cursor, NULL, error);
491 if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen))
503 xfs_attrmulti_attr_get(
513 if (*len > XATTR_SIZE_MAX)
515 kbuf = kmalloc(*len, GFP_KERNEL);
519 VOP_ATTR_GET(vp, name, kbuf, len, flags, NULL, error);
523 if (copy_to_user(ubuf, kbuf, *len))
532 xfs_attrmulti_attr_set(
535 const char __user *ubuf,
542 if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
544 if (len > XATTR_SIZE_MAX)
547 kbuf = kmalloc(len, GFP_KERNEL);
551 if (copy_from_user(kbuf, ubuf, len))
554 VOP_ATTR_SET(vp, name, kbuf, len, flags, NULL, error);
562 xfs_attrmulti_attr_remove(
569 if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
572 VOP_ATTR_REMOVE(vp, name, flags, NULL, error);
577 xfs_attrmulti_by_handle(
580 struct file *parfilp,
581 struct inode *parinode)
584 xfs_attr_multiop_t *ops;
585 xfs_fsop_attrmulti_handlereq_t am_hreq;
588 unsigned int i, size;
591 if (!capable(CAP_SYS_ADMIN))
592 return -XFS_ERROR(EPERM);
593 if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t)))
594 return -XFS_ERROR(EFAULT);
596 error = xfs_vget_fsop_handlereq(mp, parinode, &am_hreq.hreq, &vp, &inode);
601 size = am_hreq.opcount * sizeof(attr_multiop_t);
602 if (!size || size > 16 * PAGE_SIZE)
606 ops = kmalloc(size, GFP_KERNEL);
611 if (copy_from_user(ops, am_hreq.ops, size))
614 attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
620 for (i = 0; i < am_hreq.opcount; i++) {
621 ops[i].am_error = strncpy_from_user(attr_name,
622 ops[i].am_attrname, MAXNAMELEN);
623 if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
625 if (ops[i].am_error < 0)
628 switch (ops[i].am_opcode) {
630 ops[i].am_error = xfs_attrmulti_attr_get(vp,
631 attr_name, ops[i].am_attrvalue,
632 &ops[i].am_length, ops[i].am_flags);
635 ops[i].am_error = xfs_attrmulti_attr_set(vp,
636 attr_name, ops[i].am_attrvalue,
637 ops[i].am_length, ops[i].am_flags);
640 ops[i].am_error = xfs_attrmulti_attr_remove(vp,
641 attr_name, ops[i].am_flags);
644 ops[i].am_error = EINVAL;
648 if (copy_to_user(am_hreq.ops, ops, size))
649 error = XFS_ERROR(EFAULT);
660 /* prototypes for a few of the stack-hungry cases that have
661 * their own functions. Functions are defined after their use
662 * so gcc doesn't get fancy and inline them with -03 */
680 xfs_ioc_fsgeometry_v1(
724 vp = LINVFS_GET_VP(inode);
726 vn_trace_entry(vp, "xfs_ioctl", (inst_t *)__return_address);
728 ip = XFS_BHVTOI(bdp);
733 case XFS_IOC_ALLOCSP:
736 case XFS_IOC_UNRESVSP:
737 case XFS_IOC_ALLOCSP64:
738 case XFS_IOC_FREESP64:
739 case XFS_IOC_RESVSP64:
740 case XFS_IOC_UNRESVSP64:
742 * Only allow the sys admin to reserve space unless
743 * unwritten extents are enabled.
745 if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb) &&
746 !capable(CAP_SYS_ADMIN))
749 return xfs_ioc_space(bdp, vp, filp, ioflags, cmd, arg);
751 case XFS_IOC_DIOINFO: {
753 xfs_buftarg_t *target =
754 (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
755 mp->m_rtdev_targp : mp->m_ddev_targp;
757 da.d_mem = da.d_miniosz = 1 << target->pbr_sshift;
758 /* The size dio will do in one go */
759 da.d_maxiosz = 64 * PAGE_CACHE_SIZE;
761 if (copy_to_user(arg, &da, sizeof(da)))
762 return -XFS_ERROR(EFAULT);
766 case XFS_IOC_FSBULKSTAT_SINGLE:
767 case XFS_IOC_FSBULKSTAT:
768 case XFS_IOC_FSINUMBERS:
769 return xfs_ioc_bulkstat(mp, cmd, arg);
771 case XFS_IOC_FSGEOMETRY_V1:
772 return xfs_ioc_fsgeometry_v1(mp, arg);
774 case XFS_IOC_FSGEOMETRY:
775 return xfs_ioc_fsgeometry(mp, arg);
777 case XFS_IOC_GETVERSION:
778 case XFS_IOC_GETXFLAGS:
779 case XFS_IOC_SETXFLAGS:
780 case XFS_IOC_FSGETXATTR:
781 case XFS_IOC_FSSETXATTR:
782 case XFS_IOC_FSGETXATTRA:
783 return xfs_ioc_xattr(vp, ip, filp, cmd, arg);
785 case XFS_IOC_FSSETDM: {
786 struct fsdmidata dmi;
788 if (copy_from_user(&dmi, arg, sizeof(dmi)))
789 return -XFS_ERROR(EFAULT);
791 error = xfs_set_dmattrs(bdp, dmi.fsd_dmevmask, dmi.fsd_dmstate,
796 case XFS_IOC_GETBMAP:
797 case XFS_IOC_GETBMAPA:
798 return xfs_ioc_getbmap(bdp, filp, ioflags, cmd, arg);
800 case XFS_IOC_GETBMAPX:
801 return xfs_ioc_getbmapx(bdp, arg);
803 case XFS_IOC_FD_TO_HANDLE:
804 case XFS_IOC_PATH_TO_HANDLE:
805 case XFS_IOC_PATH_TO_FSHANDLE:
806 return xfs_find_handle(cmd, arg);
808 case XFS_IOC_OPEN_BY_HANDLE:
809 return xfs_open_by_handle(mp, arg, filp, inode);
811 case XFS_IOC_FSSETDM_BY_HANDLE:
812 return xfs_fssetdm_by_handle(mp, arg, filp, inode);
814 case XFS_IOC_READLINK_BY_HANDLE:
815 return xfs_readlink_by_handle(mp, arg, filp, inode);
817 case XFS_IOC_ATTRLIST_BY_HANDLE:
818 return xfs_attrlist_by_handle(mp, arg, filp, inode);
820 case XFS_IOC_ATTRMULTI_BY_HANDLE:
821 return xfs_attrmulti_by_handle(mp, arg, filp, inode);
823 case XFS_IOC_SWAPEXT: {
824 error = xfs_swapext((struct xfs_swapext __user *)arg);
828 case XFS_IOC_FSCOUNTS: {
829 xfs_fsop_counts_t out;
831 error = xfs_fs_counts(mp, &out);
835 if (copy_to_user(arg, &out, sizeof(out)))
836 return -XFS_ERROR(EFAULT);
840 case XFS_IOC_SET_RESBLKS: {
841 xfs_fsop_resblks_t inout;
844 if (!capable(CAP_SYS_ADMIN))
847 if (copy_from_user(&inout, arg, sizeof(inout)))
848 return -XFS_ERROR(EFAULT);
850 /* input parameter is passed in resblks field of structure */
852 error = xfs_reserve_blocks(mp, &in, &inout);
856 if (copy_to_user(arg, &inout, sizeof(inout)))
857 return -XFS_ERROR(EFAULT);
861 case XFS_IOC_GET_RESBLKS: {
862 xfs_fsop_resblks_t out;
864 if (!capable(CAP_SYS_ADMIN))
867 error = xfs_reserve_blocks(mp, NULL, &out);
871 if (copy_to_user(arg, &out, sizeof(out)))
872 return -XFS_ERROR(EFAULT);
877 case XFS_IOC_FSGROWFSDATA: {
878 xfs_growfs_data_t in;
880 if (!capable(CAP_SYS_ADMIN))
883 if (copy_from_user(&in, arg, sizeof(in)))
884 return -XFS_ERROR(EFAULT);
886 error = xfs_growfs_data(mp, &in);
890 case XFS_IOC_FSGROWFSLOG: {
893 if (!capable(CAP_SYS_ADMIN))
896 if (copy_from_user(&in, arg, sizeof(in)))
897 return -XFS_ERROR(EFAULT);
899 error = xfs_growfs_log(mp, &in);
903 case XFS_IOC_FSGROWFSRT: {
906 if (!capable(CAP_SYS_ADMIN))
909 if (copy_from_user(&in, arg, sizeof(in)))
910 return -XFS_ERROR(EFAULT);
912 error = xfs_growfs_rt(mp, &in);
917 if (!capable(CAP_SYS_ADMIN))
920 if (inode->i_sb->s_frozen == SB_UNFROZEN)
921 freeze_bdev(inode->i_sb->s_bdev);
925 if (!capable(CAP_SYS_ADMIN))
927 if (inode->i_sb->s_frozen != SB_UNFROZEN)
928 thaw_bdev(inode->i_sb->s_bdev, inode->i_sb);
931 case XFS_IOC_GOINGDOWN: {
934 if (!capable(CAP_SYS_ADMIN))
937 if (get_user(in, (__uint32_t __user *)arg))
938 return -XFS_ERROR(EFAULT);
940 error = xfs_fs_goingdown(mp, in);
944 case XFS_IOC_ERROR_INJECTION: {
945 xfs_error_injection_t in;
947 if (!capable(CAP_SYS_ADMIN))
950 if (copy_from_user(&in, arg, sizeof(in)))
951 return -XFS_ERROR(EFAULT);
953 error = xfs_errortag_add(in.errtag, mp);
957 case XFS_IOC_ERROR_CLEARALL:
958 if (!capable(CAP_SYS_ADMIN))
961 error = xfs_errortag_clearall(mp);
982 if (vp->v_inode.i_flags & (S_IMMUTABLE|S_APPEND))
983 return -XFS_ERROR(EPERM);
985 if (!(filp->f_flags & FMODE_WRITE))
986 return -XFS_ERROR(EBADF);
988 if (vp->v_type != VREG)
989 return -XFS_ERROR(EINVAL);
991 if (copy_from_user(&bf, arg, sizeof(bf)))
992 return -XFS_ERROR(EFAULT);
994 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
995 attr_flags |= ATTR_NONBLOCK;
996 if (ioflags & IO_INVIS)
997 attr_flags |= ATTR_DMI;
999 error = xfs_change_file_space(bdp, cmd, &bf, filp->f_pos,
1010 xfs_fsop_bulkreq_t bulkreq;
1011 int count; /* # of records returned */
1012 xfs_ino_t inlast; /* last inode number */
1016 /* done = 1 if there are more stats to get and if bulkstat */
1017 /* should be called again (unused here, but used in dmapi) */
1019 if (!capable(CAP_SYS_ADMIN))
1022 if (XFS_FORCED_SHUTDOWN(mp))
1023 return -XFS_ERROR(EIO);
1025 if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t)))
1026 return -XFS_ERROR(EFAULT);
1028 if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
1029 return -XFS_ERROR(EFAULT);
1031 if ((count = bulkreq.icount) <= 0)
1032 return -XFS_ERROR(EINVAL);
1034 if (cmd == XFS_IOC_FSINUMBERS)
1035 error = xfs_inumbers(mp, &inlast, &count,
1037 else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE)
1038 error = xfs_bulkstat_single(mp, &inlast,
1039 bulkreq.ubuffer, &done);
1040 else { /* XFS_IOC_FSBULKSTAT */
1041 if (count == 1 && inlast != 0) {
1043 error = xfs_bulkstat_single(mp, &inlast,
1044 bulkreq.ubuffer, &done);
1046 error = xfs_bulkstat(mp, &inlast, &count,
1047 (bulkstat_one_pf)xfs_bulkstat_one, NULL,
1048 sizeof(xfs_bstat_t), bulkreq.ubuffer,
1049 BULKSTAT_FG_QUICK, &done);
1056 if (bulkreq.ocount != NULL) {
1057 if (copy_to_user(bulkreq.lastip, &inlast,
1059 return -XFS_ERROR(EFAULT);
1061 if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
1062 return -XFS_ERROR(EFAULT);
1069 xfs_ioc_fsgeometry_v1(
1073 xfs_fsop_geom_v1_t fsgeo;
1076 error = xfs_fs_geometry(mp, (xfs_fsop_geom_t *)&fsgeo, 3);
1080 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
1081 return -XFS_ERROR(EFAULT);
1090 xfs_fsop_geom_t fsgeo;
1093 error = xfs_fs_geometry(mp, &fsgeo, 4);
1097 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
1098 return -XFS_ERROR(EFAULT);
1103 * Linux extended inode flags interface.
1105 #define LINUX_XFLAG_SYNC 0x00000008 /* Synchronous updates */
1106 #define LINUX_XFLAG_IMMUTABLE 0x00000010 /* Immutable file */
1107 #define LINUX_XFLAG_APPEND 0x00000020 /* writes to file may only append */
1108 #define LINUX_XFLAG_NODUMP 0x00000040 /* do not dump file */
1109 #define LINUX_XFLAG_NOATIME 0x00000080 /* do not update atime */
1112 xfs_merge_ioc_xflags(
1116 unsigned int xflags = start;
1118 if (flags & LINUX_XFLAG_IMMUTABLE)
1119 xflags |= XFS_XFLAG_IMMUTABLE;
1121 xflags &= ~XFS_XFLAG_IMMUTABLE;
1122 if (flags & LINUX_XFLAG_APPEND)
1123 xflags |= XFS_XFLAG_APPEND;
1125 xflags &= ~XFS_XFLAG_APPEND;
1126 if (flags & LINUX_XFLAG_SYNC)
1127 xflags |= XFS_XFLAG_SYNC;
1129 xflags &= ~XFS_XFLAG_SYNC;
1130 if (flags & LINUX_XFLAG_NOATIME)
1131 xflags |= XFS_XFLAG_NOATIME;
1133 xflags &= ~XFS_XFLAG_NOATIME;
1134 if (flags & LINUX_XFLAG_NODUMP)
1135 xflags |= XFS_XFLAG_NODUMP;
1137 xflags &= ~XFS_XFLAG_NODUMP;
1144 __uint16_t di_flags)
1146 unsigned int flags = 0;
1148 if (di_flags & XFS_DIFLAG_IMMUTABLE)
1149 flags |= LINUX_XFLAG_IMMUTABLE;
1150 if (di_flags & XFS_DIFLAG_APPEND)
1151 flags |= LINUX_XFLAG_APPEND;
1152 if (di_flags & XFS_DIFLAG_SYNC)
1153 flags |= LINUX_XFLAG_SYNC;
1154 if (di_flags & XFS_DIFLAG_NOATIME)
1155 flags |= LINUX_XFLAG_NOATIME;
1156 if (di_flags & XFS_DIFLAG_NODUMP)
1157 flags |= LINUX_XFLAG_NODUMP;
1176 case XFS_IOC_FSGETXATTR: {
1177 va.va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | \
1178 XFS_AT_NEXTENTS | XFS_AT_PROJID;
1179 VOP_GETATTR(vp, &va, 0, NULL, error);
1183 fa.fsx_xflags = va.va_xflags;
1184 fa.fsx_extsize = va.va_extsize;
1185 fa.fsx_nextents = va.va_nextents;
1186 fa.fsx_projid = va.va_projid;
1188 if (copy_to_user(arg, &fa, sizeof(fa)))
1189 return -XFS_ERROR(EFAULT);
1193 case XFS_IOC_FSSETXATTR: {
1194 if (copy_from_user(&fa, arg, sizeof(fa)))
1195 return -XFS_ERROR(EFAULT);
1198 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1199 attr_flags |= ATTR_NONBLOCK;
1201 va.va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | XFS_AT_PROJID;
1202 va.va_xflags = fa.fsx_xflags;
1203 va.va_extsize = fa.fsx_extsize;
1204 va.va_projid = fa.fsx_projid;
1206 VOP_SETATTR(vp, &va, attr_flags, NULL, error);
1208 vn_revalidate(vp); /* update Linux inode flags */
1212 case XFS_IOC_FSGETXATTRA: {
1213 va.va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | \
1214 XFS_AT_ANEXTENTS | XFS_AT_PROJID;
1215 VOP_GETATTR(vp, &va, 0, NULL, error);
1219 fa.fsx_xflags = va.va_xflags;
1220 fa.fsx_extsize = va.va_extsize;
1221 fa.fsx_nextents = va.va_anextents;
1222 fa.fsx_projid = va.va_projid;
1224 if (copy_to_user(arg, &fa, sizeof(fa)))
1225 return -XFS_ERROR(EFAULT);
1229 case XFS_IOC_GETXFLAGS: {
1230 flags = xfs_di2lxflags(ip->i_d.di_flags);
1231 if (copy_to_user(arg, &flags, sizeof(flags)))
1232 return -XFS_ERROR(EFAULT);
1236 case XFS_IOC_SETXFLAGS: {
1237 if (copy_from_user(&flags, arg, sizeof(flags)))
1238 return -XFS_ERROR(EFAULT);
1240 if (flags & ~(LINUX_XFLAG_IMMUTABLE | LINUX_XFLAG_APPEND | \
1241 LINUX_XFLAG_NOATIME | LINUX_XFLAG_NODUMP | \
1243 return -XFS_ERROR(EOPNOTSUPP);
1246 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1247 attr_flags |= ATTR_NONBLOCK;
1249 va.va_mask = XFS_AT_XFLAGS;
1250 va.va_xflags = xfs_merge_ioc_xflags(flags,
1253 VOP_SETATTR(vp, &va, attr_flags, NULL, error);
1255 vn_revalidate(vp); /* update Linux inode flags */
1259 case XFS_IOC_GETVERSION: {
1260 flags = LINVFS_GET_IP(vp)->i_generation;
1261 if (copy_to_user(arg, &flags, sizeof(flags)))
1262 return -XFS_ERROR(EFAULT);
1283 if (copy_from_user(&bm, arg, sizeof(bm)))
1284 return -XFS_ERROR(EFAULT);
1286 if (bm.bmv_count < 2)
1287 return -XFS_ERROR(EINVAL);
1289 iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0);
1290 if (ioflags & IO_INVIS)
1291 iflags |= BMV_IF_NO_DMAPI_READ;
1293 error = xfs_getbmap(bdp, &bm, (struct getbmap __user *)arg+1, iflags);
1297 if (copy_to_user(arg, &bm, sizeof(bm)))
1298 return -XFS_ERROR(EFAULT);
1307 struct getbmapx bmx;
1312 if (copy_from_user(&bmx, arg, sizeof(bmx)))
1313 return -XFS_ERROR(EFAULT);
1315 if (bmx.bmv_count < 2)
1316 return -XFS_ERROR(EINVAL);
1319 * Map input getbmapx structure to a getbmap
1320 * structure for xfs_getbmap.
1322 GETBMAP_CONVERT(bmx, bm);
1324 iflags = bmx.bmv_iflags;
1326 if (iflags & (~BMV_IF_VALID))
1327 return -XFS_ERROR(EINVAL);
1329 iflags |= BMV_IF_EXTENDED;
1331 error = xfs_getbmap(bdp, &bm, (struct getbmapx __user *)arg+1, iflags);
1335 GETBMAP_CONVERT(bm, bmx);
1337 if (copy_to_user(arg, &bmx, sizeof(bmx)))
1338 return -XFS_ERROR(EFAULT);