2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
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
23 #include "xfs_trans.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_btree.h"
38 #include "xfs_ialloc.h"
39 #include "xfs_rtalloc.h"
40 #include "xfs_itable.h"
41 #include "xfs_error.h"
48 #include "xfs_buf_item.h"
49 #include "xfs_utils.h"
50 #include "xfs_dfrag.h"
51 #include "xfs_fsops.h"
53 #include <linux/capability.h>
54 #include <linux/dcache.h>
55 #include <linux/mount.h>
56 #include <linux/namei.h>
57 #include <linux/pagemap.h>
60 * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to
61 * a file or fs handle.
63 * XFS_IOC_PATH_TO_FSHANDLE
64 * returns fs handle for a mount point or path within that mount point
65 * XFS_IOC_FD_TO_HANDLE
66 * returns full handle for a FD opened in user space
67 * XFS_IOC_PATH_TO_HANDLE
68 * returns full handle for a path
77 xfs_fsop_handlereq_t hreq;
81 if (copy_from_user(&hreq, arg, sizeof(hreq)))
82 return -XFS_ERROR(EFAULT);
84 memset((char *)&handle, 0, sizeof(handle));
87 case XFS_IOC_PATH_TO_FSHANDLE:
88 case XFS_IOC_PATH_TO_HANDLE: {
92 error = user_path_walk_link((const char __user *)hreq.path, &nd);
97 ASSERT(nd.dentry->d_inode);
98 inode = igrab(nd.dentry->d_inode);
103 case XFS_IOC_FD_TO_HANDLE: {
106 file = fget(hreq.fd);
110 ASSERT(file->f_dentry);
111 ASSERT(file->f_dentry->d_inode);
112 inode = igrab(file->f_dentry->d_inode);
119 return -XFS_ERROR(EINVAL);
122 if (inode->i_sb->s_magic != XFS_SB_MAGIC) {
123 /* we're not in XFS anymore, Toto */
125 return -XFS_ERROR(EINVAL);
128 switch (inode->i_mode & S_IFMT) {
135 return -XFS_ERROR(EBADF);
138 /* we need the vnode */
139 vp = vn_from_inode(inode);
141 /* now we can grab the fsid */
142 memcpy(&handle.ha_fsid, vp->v_vfsp->vfs_altfsid, sizeof(xfs_fsid_t));
143 hsize = sizeof(xfs_fsid_t);
145 if (cmd != XFS_IOC_PATH_TO_FSHANDLE) {
149 /* need to get access to the xfs_inode to read the generation */
152 lock_mode = xfs_ilock_map_shared(ip);
154 /* fill in fid section of handle from inode */
155 handle.ha_fid.xfs_fid_len = sizeof(xfs_fid_t) -
156 sizeof(handle.ha_fid.xfs_fid_len);
157 handle.ha_fid.xfs_fid_pad = 0;
158 handle.ha_fid.xfs_fid_gen = ip->i_d.di_gen;
159 handle.ha_fid.xfs_fid_ino = ip->i_ino;
161 xfs_iunlock_map_shared(ip, lock_mode);
163 hsize = XFS_HSIZE(handle);
166 /* now copy our handle into the user buffer & write out the size */
167 if (copy_to_user(hreq.ohandle, &handle, hsize) ||
168 copy_to_user(hreq.ohandlen, &hsize, sizeof(__s32))) {
170 return -XFS_ERROR(EFAULT);
179 * Convert userspace handle data into vnode (and inode).
180 * We [ab]use the fact that all the fsop_handlereq ioctl calls
181 * have a data structure argument whose first component is always
182 * a xfs_fsop_handlereq_t, so we can cast to and from this type.
183 * This allows us to optimise the copy_from_user calls and gives
184 * a handy, shared routine.
186 * If no error, caller must always VN_RELE the returned vp.
189 xfs_vget_fsop_handlereq(
191 struct inode *parinode, /* parent inode pointer */
192 xfs_fsop_handlereq_t *hreq,
194 struct inode **inode)
199 xfs_handle_t *handlep;
202 struct inode *inodep;
209 * Only allow handle opens under a directory.
211 if (!S_ISDIR(parinode->i_mode))
212 return XFS_ERROR(ENOTDIR);
214 hanp = hreq->ihandle;
215 hlen = hreq->ihandlen;
218 if (hlen < sizeof(handlep->ha_fsid) || hlen > sizeof(*handlep))
219 return XFS_ERROR(EINVAL);
220 if (copy_from_user(handlep, hanp, hlen))
221 return XFS_ERROR(EFAULT);
222 if (hlen < sizeof(*handlep))
223 memset(((char *)handlep) + hlen, 0, sizeof(*handlep) - hlen);
224 if (hlen > sizeof(handlep->ha_fsid)) {
225 if (handlep->ha_fid.xfs_fid_len !=
226 (hlen - sizeof(handlep->ha_fsid)
227 - sizeof(handlep->ha_fid.xfs_fid_len))
228 || handlep->ha_fid.xfs_fid_pad)
229 return XFS_ERROR(EINVAL);
233 * Crack the handle, obtain the inode # & generation #
235 xfid = (struct xfs_fid *)&handlep->ha_fid;
236 if (xfid->xfs_fid_len == sizeof(*xfid) - sizeof(xfid->xfs_fid_len)) {
237 ino = xfid->xfs_fid_ino;
238 igen = xfid->xfs_fid_gen;
240 return XFS_ERROR(EINVAL);
244 * Get the XFS inode, building a vnode to go with it.
246 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
250 return XFS_ERROR(EIO);
251 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
252 xfs_iput_new(ip, XFS_ILOCK_SHARED);
253 return XFS_ERROR(ENOENT);
257 inodep = vn_to_inode(vpp);
258 xfs_iunlock(ip, XFS_ILOCK_SHARED);
269 struct file *parfilp,
270 struct inode *parinode)
277 struct dentry *dentry;
279 xfs_fsop_handlereq_t hreq;
281 if (!capable(CAP_SYS_ADMIN))
282 return -XFS_ERROR(EPERM);
283 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
284 return -XFS_ERROR(EFAULT);
286 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
290 /* Restrict xfs_open_by_handle to directories & regular files. */
291 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
293 return -XFS_ERROR(EINVAL);
296 #if BITS_PER_LONG != 32
297 hreq.oflags |= O_LARGEFILE;
299 /* Put open permission in namei format. */
300 permflag = hreq.oflags;
301 if ((permflag+1) & O_ACCMODE)
303 if (permflag & O_TRUNC)
306 if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
307 (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
309 return -XFS_ERROR(EPERM);
312 if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
314 return -XFS_ERROR(EACCES);
317 /* Can't write directories. */
318 if ( S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
320 return -XFS_ERROR(EISDIR);
323 if ((new_fd = get_unused_fd()) < 0) {
328 dentry = d_alloc_anon(inode);
329 if (dentry == NULL) {
331 put_unused_fd(new_fd);
332 return -XFS_ERROR(ENOMEM);
335 /* Ensure umount returns EBUSY on umounts while this file is open. */
336 mntget(parfilp->f_vfsmnt);
338 /* Create file pointer. */
339 filp = dentry_open(dentry, parfilp->f_vfsmnt, hreq.oflags);
341 put_unused_fd(new_fd);
342 return -XFS_ERROR(-PTR_ERR(filp));
344 if (inode->i_mode & S_IFREG)
345 filp->f_op = &xfs_invis_file_operations;
347 fd_install(new_fd, filp);
352 xfs_readlink_by_handle(
355 struct file *parfilp,
356 struct inode *parinode)
362 xfs_fsop_handlereq_t hreq;
366 if (!capable(CAP_SYS_ADMIN))
367 return -XFS_ERROR(EPERM);
368 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
369 return -XFS_ERROR(EFAULT);
371 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
375 /* Restrict this handle operation to symlinks only. */
376 if (!S_ISLNK(inode->i_mode)) {
378 return -XFS_ERROR(EINVAL);
381 if (copy_from_user(&olen, hreq.ohandlen, sizeof(__u32))) {
383 return -XFS_ERROR(EFAULT);
386 aiov.iov_base = hreq.ohandle;
388 auio.uio_iov = &aiov;
391 auio.uio_segflg = UIO_USERSPACE;
392 auio.uio_resid = olen;
394 error = bhv_vop_readlink(vp, &auio, IO_INVIS, NULL);
399 return (olen - auio.uio_resid);
403 xfs_fssetdm_by_handle(
406 struct file *parfilp,
407 struct inode *parinode)
410 struct fsdmidata fsd;
411 xfs_fsop_setdm_handlereq_t dmhreq;
416 if (!capable(CAP_MKNOD))
417 return -XFS_ERROR(EPERM);
418 if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t)))
419 return -XFS_ERROR(EFAULT);
421 error = xfs_vget_fsop_handlereq(mp, parinode, &dmhreq.hreq, &vp, &inode);
425 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
427 return -XFS_ERROR(EPERM);
430 if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
432 return -XFS_ERROR(EFAULT);
435 bdp = bhv_base_unlocked(VN_BHV_HEAD(vp));
436 error = xfs_set_dmattrs(bdp, fsd.fsd_dmevmask, fsd.fsd_dmstate, NULL);
445 xfs_attrlist_by_handle(
448 struct file *parfilp,
449 struct inode *parinode)
452 attrlist_cursor_kern_t *cursor;
453 xfs_fsop_attrlist_handlereq_t al_hreq;
458 if (!capable(CAP_SYS_ADMIN))
459 return -XFS_ERROR(EPERM);
460 if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t)))
461 return -XFS_ERROR(EFAULT);
462 if (al_hreq.buflen > XATTR_LIST_MAX)
463 return -XFS_ERROR(EINVAL);
465 error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq,
470 kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
474 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
475 error = bhv_vop_attr_list(vp, kbuf, al_hreq.buflen, al_hreq.flags,
480 if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen))
492 xfs_attrmulti_attr_get(
502 if (*len > XATTR_SIZE_MAX)
504 kbuf = kmalloc(*len, GFP_KERNEL);
508 error = bhv_vop_attr_get(vp, name, kbuf, len, flags, NULL);
512 if (copy_to_user(ubuf, kbuf, *len))
521 xfs_attrmulti_attr_set(
524 const char __user *ubuf,
531 if (IS_RDONLY(&vp->v_inode))
533 if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
535 if (len > XATTR_SIZE_MAX)
538 kbuf = kmalloc(len, GFP_KERNEL);
542 if (copy_from_user(kbuf, ubuf, len))
545 error = bhv_vop_attr_set(vp, name, kbuf, len, flags, NULL);
553 xfs_attrmulti_attr_remove(
558 if (IS_RDONLY(&vp->v_inode))
560 if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
562 return bhv_vop_attr_remove(vp, name, flags, NULL);
566 xfs_attrmulti_by_handle(
569 struct file *parfilp,
570 struct inode *parinode)
573 xfs_attr_multiop_t *ops;
574 xfs_fsop_attrmulti_handlereq_t am_hreq;
577 unsigned int i, size;
580 if (!capable(CAP_SYS_ADMIN))
581 return -XFS_ERROR(EPERM);
582 if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t)))
583 return -XFS_ERROR(EFAULT);
585 error = xfs_vget_fsop_handlereq(mp, parinode, &am_hreq.hreq, &vp, &inode);
590 size = am_hreq.opcount * sizeof(attr_multiop_t);
591 if (!size || size > 16 * PAGE_SIZE)
595 ops = kmalloc(size, GFP_KERNEL);
600 if (copy_from_user(ops, am_hreq.ops, size))
603 attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
609 for (i = 0; i < am_hreq.opcount; i++) {
610 ops[i].am_error = strncpy_from_user(attr_name,
611 ops[i].am_attrname, MAXNAMELEN);
612 if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
614 if (ops[i].am_error < 0)
617 switch (ops[i].am_opcode) {
619 ops[i].am_error = xfs_attrmulti_attr_get(vp,
620 attr_name, ops[i].am_attrvalue,
621 &ops[i].am_length, ops[i].am_flags);
624 ops[i].am_error = xfs_attrmulti_attr_set(vp,
625 attr_name, ops[i].am_attrvalue,
626 ops[i].am_length, ops[i].am_flags);
629 ops[i].am_error = xfs_attrmulti_attr_remove(vp,
630 attr_name, ops[i].am_flags);
633 ops[i].am_error = EINVAL;
637 if (copy_to_user(am_hreq.ops, ops, size))
638 error = XFS_ERROR(EFAULT);
649 /* prototypes for a few of the stack-hungry cases that have
650 * their own functions. Functions are defined after their use
651 * so gcc doesn't get fancy and inline them with -03 */
669 xfs_ioc_fsgeometry_v1(
713 vp = vn_from_inode(inode);
715 vn_trace_entry(vp, "xfs_ioctl", (inst_t *)__return_address);
717 ip = XFS_BHVTOI(bdp);
722 case XFS_IOC_ALLOCSP:
725 case XFS_IOC_UNRESVSP:
726 case XFS_IOC_ALLOCSP64:
727 case XFS_IOC_FREESP64:
728 case XFS_IOC_RESVSP64:
729 case XFS_IOC_UNRESVSP64:
731 * Only allow the sys admin to reserve space unless
732 * unwritten extents are enabled.
734 if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb) &&
735 !capable(CAP_SYS_ADMIN))
738 return xfs_ioc_space(bdp, vp, filp, ioflags, cmd, arg);
740 case XFS_IOC_DIOINFO: {
742 xfs_buftarg_t *target =
743 (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
744 mp->m_rtdev_targp : mp->m_ddev_targp;
746 da.d_mem = da.d_miniosz = 1 << target->bt_sshift;
747 da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1);
749 if (copy_to_user(arg, &da, sizeof(da)))
750 return -XFS_ERROR(EFAULT);
754 case XFS_IOC_FSBULKSTAT_SINGLE:
755 case XFS_IOC_FSBULKSTAT:
756 case XFS_IOC_FSINUMBERS:
757 return xfs_ioc_bulkstat(mp, cmd, arg);
759 case XFS_IOC_FSGEOMETRY_V1:
760 return xfs_ioc_fsgeometry_v1(mp, arg);
762 case XFS_IOC_FSGEOMETRY:
763 return xfs_ioc_fsgeometry(mp, arg);
765 case XFS_IOC_GETVERSION:
766 case XFS_IOC_GETXFLAGS:
767 case XFS_IOC_SETXFLAGS:
768 case XFS_IOC_FSGETXATTR:
769 case XFS_IOC_FSSETXATTR:
770 case XFS_IOC_FSGETXATTRA:
771 return xfs_ioc_xattr(vp, ip, filp, cmd, arg);
773 case XFS_IOC_FSSETDM: {
774 struct fsdmidata dmi;
776 if (copy_from_user(&dmi, arg, sizeof(dmi)))
777 return -XFS_ERROR(EFAULT);
779 error = xfs_set_dmattrs(bdp, dmi.fsd_dmevmask, dmi.fsd_dmstate,
784 case XFS_IOC_GETBMAP:
785 case XFS_IOC_GETBMAPA:
786 return xfs_ioc_getbmap(bdp, filp, ioflags, cmd, arg);
788 case XFS_IOC_GETBMAPX:
789 return xfs_ioc_getbmapx(bdp, arg);
791 case XFS_IOC_FD_TO_HANDLE:
792 case XFS_IOC_PATH_TO_HANDLE:
793 case XFS_IOC_PATH_TO_FSHANDLE:
794 return xfs_find_handle(cmd, arg);
796 case XFS_IOC_OPEN_BY_HANDLE:
797 return xfs_open_by_handle(mp, arg, filp, inode);
799 case XFS_IOC_FSSETDM_BY_HANDLE:
800 return xfs_fssetdm_by_handle(mp, arg, filp, inode);
802 case XFS_IOC_READLINK_BY_HANDLE:
803 return xfs_readlink_by_handle(mp, arg, filp, inode);
805 case XFS_IOC_ATTRLIST_BY_HANDLE:
806 return xfs_attrlist_by_handle(mp, arg, filp, inode);
808 case XFS_IOC_ATTRMULTI_BY_HANDLE:
809 return xfs_attrmulti_by_handle(mp, arg, filp, inode);
811 case XFS_IOC_SWAPEXT: {
812 error = xfs_swapext((struct xfs_swapext __user *)arg);
816 case XFS_IOC_FSCOUNTS: {
817 xfs_fsop_counts_t out;
819 error = xfs_fs_counts(mp, &out);
823 if (copy_to_user(arg, &out, sizeof(out)))
824 return -XFS_ERROR(EFAULT);
828 case XFS_IOC_SET_RESBLKS: {
829 xfs_fsop_resblks_t inout;
832 if (!capable(CAP_SYS_ADMIN))
835 if (copy_from_user(&inout, arg, sizeof(inout)))
836 return -XFS_ERROR(EFAULT);
838 /* input parameter is passed in resblks field of structure */
840 error = xfs_reserve_blocks(mp, &in, &inout);
844 if (copy_to_user(arg, &inout, sizeof(inout)))
845 return -XFS_ERROR(EFAULT);
849 case XFS_IOC_GET_RESBLKS: {
850 xfs_fsop_resblks_t out;
852 if (!capable(CAP_SYS_ADMIN))
855 error = xfs_reserve_blocks(mp, NULL, &out);
859 if (copy_to_user(arg, &out, sizeof(out)))
860 return -XFS_ERROR(EFAULT);
865 case XFS_IOC_FSGROWFSDATA: {
866 xfs_growfs_data_t in;
868 if (!capable(CAP_SYS_ADMIN))
871 if (copy_from_user(&in, arg, sizeof(in)))
872 return -XFS_ERROR(EFAULT);
874 error = xfs_growfs_data(mp, &in);
878 case XFS_IOC_FSGROWFSLOG: {
881 if (!capable(CAP_SYS_ADMIN))
884 if (copy_from_user(&in, arg, sizeof(in)))
885 return -XFS_ERROR(EFAULT);
887 error = xfs_growfs_log(mp, &in);
891 case XFS_IOC_FSGROWFSRT: {
894 if (!capable(CAP_SYS_ADMIN))
897 if (copy_from_user(&in, arg, sizeof(in)))
898 return -XFS_ERROR(EFAULT);
900 error = xfs_growfs_rt(mp, &in);
905 if (!capable(CAP_SYS_ADMIN))
908 if (inode->i_sb->s_frozen == SB_UNFROZEN)
909 freeze_bdev(inode->i_sb->s_bdev);
913 if (!capable(CAP_SYS_ADMIN))
915 if (inode->i_sb->s_frozen != SB_UNFROZEN)
916 thaw_bdev(inode->i_sb->s_bdev, inode->i_sb);
919 case XFS_IOC_GOINGDOWN: {
922 if (!capable(CAP_SYS_ADMIN))
925 if (get_user(in, (__uint32_t __user *)arg))
926 return -XFS_ERROR(EFAULT);
928 error = xfs_fs_goingdown(mp, in);
932 case XFS_IOC_ERROR_INJECTION: {
933 xfs_error_injection_t in;
935 if (!capable(CAP_SYS_ADMIN))
938 if (copy_from_user(&in, arg, sizeof(in)))
939 return -XFS_ERROR(EFAULT);
941 error = xfs_errortag_add(in.errtag, mp);
945 case XFS_IOC_ERROR_CLEARALL:
946 if (!capable(CAP_SYS_ADMIN))
949 error = xfs_errortag_clearall(mp);
970 if (vp->v_inode.i_flags & (S_IMMUTABLE|S_APPEND))
971 return -XFS_ERROR(EPERM);
973 if (!(filp->f_mode & FMODE_WRITE))
974 return -XFS_ERROR(EBADF);
977 return -XFS_ERROR(EINVAL);
979 if (copy_from_user(&bf, arg, sizeof(bf)))
980 return -XFS_ERROR(EFAULT);
982 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
983 attr_flags |= ATTR_NONBLOCK;
984 if (ioflags & IO_INVIS)
985 attr_flags |= ATTR_DMI;
987 error = xfs_change_file_space(bdp, cmd, &bf, filp->f_pos,
998 xfs_fsop_bulkreq_t bulkreq;
999 int count; /* # of records returned */
1000 xfs_ino_t inlast; /* last inode number */
1004 /* done = 1 if there are more stats to get and if bulkstat */
1005 /* should be called again (unused here, but used in dmapi) */
1007 if (!capable(CAP_SYS_ADMIN))
1010 if (XFS_FORCED_SHUTDOWN(mp))
1011 return -XFS_ERROR(EIO);
1013 if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t)))
1014 return -XFS_ERROR(EFAULT);
1016 if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
1017 return -XFS_ERROR(EFAULT);
1019 if ((count = bulkreq.icount) <= 0)
1020 return -XFS_ERROR(EINVAL);
1022 if (cmd == XFS_IOC_FSINUMBERS)
1023 error = xfs_inumbers(mp, &inlast, &count,
1025 else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE)
1026 error = xfs_bulkstat_single(mp, &inlast,
1027 bulkreq.ubuffer, &done);
1028 else { /* XFS_IOC_FSBULKSTAT */
1029 if (count == 1 && inlast != 0) {
1031 error = xfs_bulkstat_single(mp, &inlast,
1032 bulkreq.ubuffer, &done);
1034 error = xfs_bulkstat(mp, &inlast, &count,
1035 (bulkstat_one_pf)xfs_bulkstat_one, NULL,
1036 sizeof(xfs_bstat_t), bulkreq.ubuffer,
1037 BULKSTAT_FG_QUICK, &done);
1044 if (bulkreq.ocount != NULL) {
1045 if (copy_to_user(bulkreq.lastip, &inlast,
1047 return -XFS_ERROR(EFAULT);
1049 if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
1050 return -XFS_ERROR(EFAULT);
1057 xfs_ioc_fsgeometry_v1(
1061 xfs_fsop_geom_v1_t fsgeo;
1064 error = xfs_fs_geometry(mp, (xfs_fsop_geom_t *)&fsgeo, 3);
1068 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
1069 return -XFS_ERROR(EFAULT);
1078 xfs_fsop_geom_t fsgeo;
1081 error = xfs_fs_geometry(mp, &fsgeo, 4);
1085 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
1086 return -XFS_ERROR(EFAULT);
1091 * Linux extended inode flags interface.
1093 #define LINUX_XFLAG_SYNC 0x00000008 /* Synchronous updates */
1094 #define LINUX_XFLAG_IMMUTABLE 0x00000010 /* Immutable file */
1095 #define LINUX_XFLAG_APPEND 0x00000020 /* writes to file may only append */
1096 #define LINUX_XFLAG_NODUMP 0x00000040 /* do not dump file */
1097 #define LINUX_XFLAG_NOATIME 0x00000080 /* do not update atime */
1100 xfs_merge_ioc_xflags(
1104 unsigned int xflags = start;
1106 if (flags & LINUX_XFLAG_IMMUTABLE)
1107 xflags |= XFS_XFLAG_IMMUTABLE;
1109 xflags &= ~XFS_XFLAG_IMMUTABLE;
1110 if (flags & LINUX_XFLAG_APPEND)
1111 xflags |= XFS_XFLAG_APPEND;
1113 xflags &= ~XFS_XFLAG_APPEND;
1114 if (flags & LINUX_XFLAG_SYNC)
1115 xflags |= XFS_XFLAG_SYNC;
1117 xflags &= ~XFS_XFLAG_SYNC;
1118 if (flags & LINUX_XFLAG_NOATIME)
1119 xflags |= XFS_XFLAG_NOATIME;
1121 xflags &= ~XFS_XFLAG_NOATIME;
1122 if (flags & LINUX_XFLAG_NODUMP)
1123 xflags |= XFS_XFLAG_NODUMP;
1125 xflags &= ~XFS_XFLAG_NODUMP;
1132 __uint16_t di_flags)
1134 unsigned int flags = 0;
1136 if (di_flags & XFS_DIFLAG_IMMUTABLE)
1137 flags |= LINUX_XFLAG_IMMUTABLE;
1138 if (di_flags & XFS_DIFLAG_APPEND)
1139 flags |= LINUX_XFLAG_APPEND;
1140 if (di_flags & XFS_DIFLAG_SYNC)
1141 flags |= LINUX_XFLAG_SYNC;
1142 if (di_flags & XFS_DIFLAG_NOATIME)
1143 flags |= LINUX_XFLAG_NOATIME;
1144 if (di_flags & XFS_DIFLAG_NODUMP)
1145 flags |= LINUX_XFLAG_NODUMP;
1158 struct bhv_vattr *vattr;
1163 vattr = kmalloc(sizeof(*vattr), GFP_KERNEL);
1164 if (unlikely(!vattr))
1168 case XFS_IOC_FSGETXATTR: {
1169 vattr->va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | \
1170 XFS_AT_NEXTENTS | XFS_AT_PROJID;
1171 error = bhv_vop_getattr(vp, vattr, 0, NULL);
1172 if (unlikely(error)) {
1177 fa.fsx_xflags = vattr->va_xflags;
1178 fa.fsx_extsize = vattr->va_extsize;
1179 fa.fsx_nextents = vattr->va_nextents;
1180 fa.fsx_projid = vattr->va_projid;
1182 if (copy_to_user(arg, &fa, sizeof(fa))) {
1189 case XFS_IOC_FSSETXATTR: {
1190 if (copy_from_user(&fa, arg, sizeof(fa))) {
1196 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1197 attr_flags |= ATTR_NONBLOCK;
1199 vattr->va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | XFS_AT_PROJID;
1200 vattr->va_xflags = fa.fsx_xflags;
1201 vattr->va_extsize = fa.fsx_extsize;
1202 vattr->va_projid = fa.fsx_projid;
1204 error = bhv_vop_setattr(vp, vattr, attr_flags, NULL);
1206 __vn_revalidate(vp, vattr); /* update flags */
1211 case XFS_IOC_FSGETXATTRA: {
1212 vattr->va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | \
1213 XFS_AT_ANEXTENTS | XFS_AT_PROJID;
1214 error = bhv_vop_getattr(vp, vattr, 0, NULL);
1215 if (unlikely(error)) {
1220 fa.fsx_xflags = vattr->va_xflags;
1221 fa.fsx_extsize = vattr->va_extsize;
1222 fa.fsx_nextents = vattr->va_anextents;
1223 fa.fsx_projid = vattr->va_projid;
1225 if (copy_to_user(arg, &fa, sizeof(fa))) {
1232 case XFS_IOC_GETXFLAGS: {
1233 flags = xfs_di2lxflags(ip->i_d.di_flags);
1234 if (copy_to_user(arg, &flags, sizeof(flags)))
1239 case XFS_IOC_SETXFLAGS: {
1240 if (copy_from_user(&flags, arg, sizeof(flags))) {
1245 if (flags & ~(LINUX_XFLAG_IMMUTABLE | LINUX_XFLAG_APPEND | \
1246 LINUX_XFLAG_NOATIME | LINUX_XFLAG_NODUMP | \
1247 LINUX_XFLAG_SYNC)) {
1248 error = -EOPNOTSUPP;
1253 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1254 attr_flags |= ATTR_NONBLOCK;
1256 vattr->va_mask = XFS_AT_XFLAGS;
1257 vattr->va_xflags = xfs_merge_ioc_xflags(flags,
1260 error = bhv_vop_setattr(vp, vattr, attr_flags, NULL);
1262 __vn_revalidate(vp, vattr); /* update flags */
1267 case XFS_IOC_GETVERSION: {
1268 flags = vn_to_inode(vp)->i_generation;
1269 if (copy_to_user(arg, &flags, sizeof(flags)))
1295 if (copy_from_user(&bm, arg, sizeof(bm)))
1296 return -XFS_ERROR(EFAULT);
1298 if (bm.bmv_count < 2)
1299 return -XFS_ERROR(EINVAL);
1301 iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0);
1302 if (ioflags & IO_INVIS)
1303 iflags |= BMV_IF_NO_DMAPI_READ;
1305 error = xfs_getbmap(bdp, &bm, (struct getbmap __user *)arg+1, iflags);
1309 if (copy_to_user(arg, &bm, sizeof(bm)))
1310 return -XFS_ERROR(EFAULT);
1319 struct getbmapx bmx;
1324 if (copy_from_user(&bmx, arg, sizeof(bmx)))
1325 return -XFS_ERROR(EFAULT);
1327 if (bmx.bmv_count < 2)
1328 return -XFS_ERROR(EINVAL);
1331 * Map input getbmapx structure to a getbmap
1332 * structure for xfs_getbmap.
1334 GETBMAP_CONVERT(bmx, bm);
1336 iflags = bmx.bmv_iflags;
1338 if (iflags & (~BMV_IF_VALID))
1339 return -XFS_ERROR(EINVAL);
1341 iflags |= BMV_IF_EXTENDED;
1343 error = xfs_getbmap(bdp, &bm, (struct getbmapx __user *)arg+1, iflags);
1347 GETBMAP_CONVERT(bm, bmx);
1349 if (copy_to_user(arg, &bmx, sizeof(bmx)))
1350 return -XFS_ERROR(EFAULT);