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_path.dentry);
111 ASSERT(file->f_path.dentry->d_inode);
112 inode = igrab(file->f_path.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_path.mnt);
338 /* Create file pointer. */
339 filp = dentry_open(dentry, parfilp->f_path.mnt, hreq.oflags);
341 put_unused_fd(new_fd);
342 return -XFS_ERROR(-PTR_ERR(filp));
344 if (inode->i_mode & S_IFREG) {
345 /* invisible operation should not change atime */
346 filp->f_flags |= O_NOATIME;
347 filp->f_op = &xfs_invis_file_operations;
350 fd_install(new_fd, filp);
355 xfs_readlink_by_handle(
358 struct file *parfilp,
359 struct inode *parinode)
365 xfs_fsop_handlereq_t hreq;
369 if (!capable(CAP_SYS_ADMIN))
370 return -XFS_ERROR(EPERM);
371 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
372 return -XFS_ERROR(EFAULT);
374 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
378 /* Restrict this handle operation to symlinks only. */
379 if (!S_ISLNK(inode->i_mode)) {
381 return -XFS_ERROR(EINVAL);
384 if (copy_from_user(&olen, hreq.ohandlen, sizeof(__u32))) {
386 return -XFS_ERROR(EFAULT);
389 aiov.iov_base = hreq.ohandle;
391 auio.uio_iov = &aiov;
394 auio.uio_segflg = UIO_USERSPACE;
395 auio.uio_resid = olen;
397 error = bhv_vop_readlink(vp, &auio, IO_INVIS, NULL);
402 return (olen - auio.uio_resid);
406 xfs_fssetdm_by_handle(
409 struct file *parfilp,
410 struct inode *parinode)
413 struct fsdmidata fsd;
414 xfs_fsop_setdm_handlereq_t dmhreq;
419 if (!capable(CAP_MKNOD))
420 return -XFS_ERROR(EPERM);
421 if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t)))
422 return -XFS_ERROR(EFAULT);
424 error = xfs_vget_fsop_handlereq(mp, parinode, &dmhreq.hreq, &vp, &inode);
428 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
430 return -XFS_ERROR(EPERM);
433 if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
435 return -XFS_ERROR(EFAULT);
438 bdp = bhv_base_unlocked(VN_BHV_HEAD(vp));
439 error = xfs_set_dmattrs(bdp, fsd.fsd_dmevmask, fsd.fsd_dmstate, NULL);
448 xfs_attrlist_by_handle(
451 struct file *parfilp,
452 struct inode *parinode)
455 attrlist_cursor_kern_t *cursor;
456 xfs_fsop_attrlist_handlereq_t al_hreq;
461 if (!capable(CAP_SYS_ADMIN))
462 return -XFS_ERROR(EPERM);
463 if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t)))
464 return -XFS_ERROR(EFAULT);
465 if (al_hreq.buflen > XATTR_LIST_MAX)
466 return -XFS_ERROR(EINVAL);
468 error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq,
473 kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
477 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
478 error = bhv_vop_attr_list(vp, kbuf, al_hreq.buflen, al_hreq.flags,
483 if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen))
495 xfs_attrmulti_attr_get(
505 if (*len > XATTR_SIZE_MAX)
507 kbuf = kmalloc(*len, GFP_KERNEL);
511 error = bhv_vop_attr_get(vp, name, kbuf, len, flags, NULL);
515 if (copy_to_user(ubuf, kbuf, *len))
524 xfs_attrmulti_attr_set(
527 const char __user *ubuf,
534 if (IS_RDONLY(&vp->v_inode))
536 if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
538 if (len > XATTR_SIZE_MAX)
541 kbuf = kmalloc(len, GFP_KERNEL);
545 if (copy_from_user(kbuf, ubuf, len))
548 error = bhv_vop_attr_set(vp, name, kbuf, len, flags, NULL);
556 xfs_attrmulti_attr_remove(
561 if (IS_RDONLY(&vp->v_inode))
563 if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
565 return bhv_vop_attr_remove(vp, name, flags, NULL);
569 xfs_attrmulti_by_handle(
572 struct file *parfilp,
573 struct inode *parinode)
576 xfs_attr_multiop_t *ops;
577 xfs_fsop_attrmulti_handlereq_t am_hreq;
580 unsigned int i, size;
583 if (!capable(CAP_SYS_ADMIN))
584 return -XFS_ERROR(EPERM);
585 if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t)))
586 return -XFS_ERROR(EFAULT);
588 error = xfs_vget_fsop_handlereq(mp, parinode, &am_hreq.hreq, &vp, &inode);
593 size = am_hreq.opcount * sizeof(attr_multiop_t);
594 if (!size || size > 16 * PAGE_SIZE)
598 ops = kmalloc(size, GFP_KERNEL);
603 if (copy_from_user(ops, am_hreq.ops, size))
606 attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
612 for (i = 0; i < am_hreq.opcount; i++) {
613 ops[i].am_error = strncpy_from_user(attr_name,
614 ops[i].am_attrname, MAXNAMELEN);
615 if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
617 if (ops[i].am_error < 0)
620 switch (ops[i].am_opcode) {
622 ops[i].am_error = xfs_attrmulti_attr_get(vp,
623 attr_name, ops[i].am_attrvalue,
624 &ops[i].am_length, ops[i].am_flags);
627 ops[i].am_error = xfs_attrmulti_attr_set(vp,
628 attr_name, ops[i].am_attrvalue,
629 ops[i].am_length, ops[i].am_flags);
632 ops[i].am_error = xfs_attrmulti_attr_remove(vp,
633 attr_name, ops[i].am_flags);
636 ops[i].am_error = EINVAL;
640 if (copy_to_user(am_hreq.ops, ops, size))
641 error = XFS_ERROR(EFAULT);
652 /* prototypes for a few of the stack-hungry cases that have
653 * their own functions. Functions are defined after their use
654 * so gcc doesn't get fancy and inline them with -03 */
672 xfs_ioc_fsgeometry_v1(
716 vp = vn_from_inode(inode);
718 vn_trace_entry(vp, "xfs_ioctl", (inst_t *)__return_address);
720 ip = XFS_BHVTOI(bdp);
725 case XFS_IOC_ALLOCSP:
728 case XFS_IOC_UNRESVSP:
729 case XFS_IOC_ALLOCSP64:
730 case XFS_IOC_FREESP64:
731 case XFS_IOC_RESVSP64:
732 case XFS_IOC_UNRESVSP64:
734 * Only allow the sys admin to reserve space unless
735 * unwritten extents are enabled.
737 if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb) &&
738 !capable(CAP_SYS_ADMIN))
741 return xfs_ioc_space(bdp, inode, filp, ioflags, cmd, arg);
743 case XFS_IOC_DIOINFO: {
745 xfs_buftarg_t *target =
746 (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
747 mp->m_rtdev_targp : mp->m_ddev_targp;
749 da.d_mem = da.d_miniosz = 1 << target->bt_sshift;
750 da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1);
752 if (copy_to_user(arg, &da, sizeof(da)))
753 return -XFS_ERROR(EFAULT);
757 case XFS_IOC_FSBULKSTAT_SINGLE:
758 case XFS_IOC_FSBULKSTAT:
759 case XFS_IOC_FSINUMBERS:
760 return xfs_ioc_bulkstat(mp, cmd, arg);
762 case XFS_IOC_FSGEOMETRY_V1:
763 return xfs_ioc_fsgeometry_v1(mp, arg);
765 case XFS_IOC_FSGEOMETRY:
766 return xfs_ioc_fsgeometry(mp, arg);
768 case XFS_IOC_GETVERSION:
769 return put_user(inode->i_generation, (int __user *)arg);
771 case XFS_IOC_GETXFLAGS:
772 case XFS_IOC_SETXFLAGS:
773 case XFS_IOC_FSGETXATTR:
774 case XFS_IOC_FSSETXATTR:
775 case XFS_IOC_FSGETXATTRA:
776 return xfs_ioc_xattr(vp, ip, filp, cmd, arg);
778 case XFS_IOC_FSSETDM: {
779 struct fsdmidata dmi;
781 if (copy_from_user(&dmi, arg, sizeof(dmi)))
782 return -XFS_ERROR(EFAULT);
784 error = xfs_set_dmattrs(bdp, dmi.fsd_dmevmask, dmi.fsd_dmstate,
789 case XFS_IOC_GETBMAP:
790 case XFS_IOC_GETBMAPA:
791 return xfs_ioc_getbmap(bdp, filp, ioflags, cmd, arg);
793 case XFS_IOC_GETBMAPX:
794 return xfs_ioc_getbmapx(bdp, arg);
796 case XFS_IOC_FD_TO_HANDLE:
797 case XFS_IOC_PATH_TO_HANDLE:
798 case XFS_IOC_PATH_TO_FSHANDLE:
799 return xfs_find_handle(cmd, arg);
801 case XFS_IOC_OPEN_BY_HANDLE:
802 return xfs_open_by_handle(mp, arg, filp, inode);
804 case XFS_IOC_FSSETDM_BY_HANDLE:
805 return xfs_fssetdm_by_handle(mp, arg, filp, inode);
807 case XFS_IOC_READLINK_BY_HANDLE:
808 return xfs_readlink_by_handle(mp, arg, filp, inode);
810 case XFS_IOC_ATTRLIST_BY_HANDLE:
811 return xfs_attrlist_by_handle(mp, arg, filp, inode);
813 case XFS_IOC_ATTRMULTI_BY_HANDLE:
814 return xfs_attrmulti_by_handle(mp, arg, filp, inode);
816 case XFS_IOC_SWAPEXT: {
817 error = xfs_swapext((struct xfs_swapext __user *)arg);
821 case XFS_IOC_FSCOUNTS: {
822 xfs_fsop_counts_t out;
824 error = xfs_fs_counts(mp, &out);
828 if (copy_to_user(arg, &out, sizeof(out)))
829 return -XFS_ERROR(EFAULT);
833 case XFS_IOC_SET_RESBLKS: {
834 xfs_fsop_resblks_t inout;
837 if (!capable(CAP_SYS_ADMIN))
840 if (copy_from_user(&inout, arg, sizeof(inout)))
841 return -XFS_ERROR(EFAULT);
843 /* input parameter is passed in resblks field of structure */
845 error = xfs_reserve_blocks(mp, &in, &inout);
849 if (copy_to_user(arg, &inout, sizeof(inout)))
850 return -XFS_ERROR(EFAULT);
854 case XFS_IOC_GET_RESBLKS: {
855 xfs_fsop_resblks_t out;
857 if (!capable(CAP_SYS_ADMIN))
860 error = xfs_reserve_blocks(mp, NULL, &out);
864 if (copy_to_user(arg, &out, sizeof(out)))
865 return -XFS_ERROR(EFAULT);
870 case XFS_IOC_FSGROWFSDATA: {
871 xfs_growfs_data_t in;
873 if (!capable(CAP_SYS_ADMIN))
876 if (copy_from_user(&in, arg, sizeof(in)))
877 return -XFS_ERROR(EFAULT);
879 error = xfs_growfs_data(mp, &in);
883 case XFS_IOC_FSGROWFSLOG: {
886 if (!capable(CAP_SYS_ADMIN))
889 if (copy_from_user(&in, arg, sizeof(in)))
890 return -XFS_ERROR(EFAULT);
892 error = xfs_growfs_log(mp, &in);
896 case XFS_IOC_FSGROWFSRT: {
899 if (!capable(CAP_SYS_ADMIN))
902 if (copy_from_user(&in, arg, sizeof(in)))
903 return -XFS_ERROR(EFAULT);
905 error = xfs_growfs_rt(mp, &in);
910 if (!capable(CAP_SYS_ADMIN))
913 if (inode->i_sb->s_frozen == SB_UNFROZEN)
914 freeze_bdev(inode->i_sb->s_bdev);
918 if (!capable(CAP_SYS_ADMIN))
920 if (inode->i_sb->s_frozen != SB_UNFROZEN)
921 thaw_bdev(inode->i_sb->s_bdev, inode->i_sb);
924 case XFS_IOC_GOINGDOWN: {
927 if (!capable(CAP_SYS_ADMIN))
930 if (get_user(in, (__uint32_t __user *)arg))
931 return -XFS_ERROR(EFAULT);
933 error = xfs_fs_goingdown(mp, in);
937 case XFS_IOC_ERROR_INJECTION: {
938 xfs_error_injection_t in;
940 if (!capable(CAP_SYS_ADMIN))
943 if (copy_from_user(&in, arg, sizeof(in)))
944 return -XFS_ERROR(EFAULT);
946 error = xfs_errortag_add(in.errtag, mp);
950 case XFS_IOC_ERROR_CLEARALL:
951 if (!capable(CAP_SYS_ADMIN))
954 error = xfs_errortag_clearall(mp);
975 if (inode->i_flags & (S_IMMUTABLE|S_APPEND))
976 return -XFS_ERROR(EPERM);
978 if (!(filp->f_mode & FMODE_WRITE))
979 return -XFS_ERROR(EBADF);
981 if (!S_ISREG(inode->i_mode))
982 return -XFS_ERROR(EINVAL);
984 if (copy_from_user(&bf, arg, sizeof(bf)))
985 return -XFS_ERROR(EFAULT);
987 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
988 attr_flags |= ATTR_NONBLOCK;
989 if (ioflags & IO_INVIS)
990 attr_flags |= ATTR_DMI;
992 error = xfs_change_file_space(bdp, cmd, &bf, filp->f_pos,
1003 xfs_fsop_bulkreq_t bulkreq;
1004 int count; /* # of records returned */
1005 xfs_ino_t inlast; /* last inode number */
1009 /* done = 1 if there are more stats to get and if bulkstat */
1010 /* should be called again (unused here, but used in dmapi) */
1012 if (!capable(CAP_SYS_ADMIN))
1015 if (XFS_FORCED_SHUTDOWN(mp))
1016 return -XFS_ERROR(EIO);
1018 if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t)))
1019 return -XFS_ERROR(EFAULT);
1021 if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
1022 return -XFS_ERROR(EFAULT);
1024 if ((count = bulkreq.icount) <= 0)
1025 return -XFS_ERROR(EINVAL);
1027 if (cmd == XFS_IOC_FSINUMBERS)
1028 error = xfs_inumbers(mp, &inlast, &count,
1030 else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE)
1031 error = xfs_bulkstat_single(mp, &inlast,
1032 bulkreq.ubuffer, &done);
1033 else { /* XFS_IOC_FSBULKSTAT */
1034 if (count == 1 && inlast != 0) {
1036 error = xfs_bulkstat_single(mp, &inlast,
1037 bulkreq.ubuffer, &done);
1039 error = xfs_bulkstat(mp, &inlast, &count,
1040 (bulkstat_one_pf)xfs_bulkstat_one, NULL,
1041 sizeof(xfs_bstat_t), bulkreq.ubuffer,
1042 BULKSTAT_FG_QUICK, &done);
1049 if (bulkreq.ocount != NULL) {
1050 if (copy_to_user(bulkreq.lastip, &inlast,
1052 return -XFS_ERROR(EFAULT);
1054 if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
1055 return -XFS_ERROR(EFAULT);
1062 xfs_ioc_fsgeometry_v1(
1066 xfs_fsop_geom_v1_t fsgeo;
1069 error = xfs_fs_geometry(mp, (xfs_fsop_geom_t *)&fsgeo, 3);
1073 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
1074 return -XFS_ERROR(EFAULT);
1083 xfs_fsop_geom_t fsgeo;
1086 error = xfs_fs_geometry(mp, &fsgeo, 4);
1090 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
1091 return -XFS_ERROR(EFAULT);
1096 * Linux extended inode flags interface.
1098 #define LINUX_XFLAG_SYNC 0x00000008 /* Synchronous updates */
1099 #define LINUX_XFLAG_IMMUTABLE 0x00000010 /* Immutable file */
1100 #define LINUX_XFLAG_APPEND 0x00000020 /* writes to file may only append */
1101 #define LINUX_XFLAG_NODUMP 0x00000040 /* do not dump file */
1102 #define LINUX_XFLAG_NOATIME 0x00000080 /* do not update atime */
1105 xfs_merge_ioc_xflags(
1109 unsigned int xflags = start;
1111 if (flags & LINUX_XFLAG_IMMUTABLE)
1112 xflags |= XFS_XFLAG_IMMUTABLE;
1114 xflags &= ~XFS_XFLAG_IMMUTABLE;
1115 if (flags & LINUX_XFLAG_APPEND)
1116 xflags |= XFS_XFLAG_APPEND;
1118 xflags &= ~XFS_XFLAG_APPEND;
1119 if (flags & LINUX_XFLAG_SYNC)
1120 xflags |= XFS_XFLAG_SYNC;
1122 xflags &= ~XFS_XFLAG_SYNC;
1123 if (flags & LINUX_XFLAG_NOATIME)
1124 xflags |= XFS_XFLAG_NOATIME;
1126 xflags &= ~XFS_XFLAG_NOATIME;
1127 if (flags & LINUX_XFLAG_NODUMP)
1128 xflags |= XFS_XFLAG_NODUMP;
1130 xflags &= ~XFS_XFLAG_NODUMP;
1137 __uint16_t di_flags)
1139 unsigned int flags = 0;
1141 if (di_flags & XFS_DIFLAG_IMMUTABLE)
1142 flags |= LINUX_XFLAG_IMMUTABLE;
1143 if (di_flags & XFS_DIFLAG_APPEND)
1144 flags |= LINUX_XFLAG_APPEND;
1145 if (di_flags & XFS_DIFLAG_SYNC)
1146 flags |= LINUX_XFLAG_SYNC;
1147 if (di_flags & XFS_DIFLAG_NOATIME)
1148 flags |= LINUX_XFLAG_NOATIME;
1149 if (di_flags & XFS_DIFLAG_NODUMP)
1150 flags |= LINUX_XFLAG_NODUMP;
1163 struct bhv_vattr *vattr;
1168 vattr = kmalloc(sizeof(*vattr), GFP_KERNEL);
1169 if (unlikely(!vattr))
1173 case XFS_IOC_FSGETXATTR: {
1174 vattr->va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | \
1175 XFS_AT_NEXTENTS | XFS_AT_PROJID;
1176 error = bhv_vop_getattr(vp, vattr, 0, NULL);
1177 if (unlikely(error)) {
1182 fa.fsx_xflags = vattr->va_xflags;
1183 fa.fsx_extsize = vattr->va_extsize;
1184 fa.fsx_nextents = vattr->va_nextents;
1185 fa.fsx_projid = vattr->va_projid;
1187 if (copy_to_user(arg, &fa, sizeof(fa))) {
1194 case XFS_IOC_FSSETXATTR: {
1195 if (copy_from_user(&fa, arg, sizeof(fa))) {
1201 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1202 attr_flags |= ATTR_NONBLOCK;
1204 vattr->va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | XFS_AT_PROJID;
1205 vattr->va_xflags = fa.fsx_xflags;
1206 vattr->va_extsize = fa.fsx_extsize;
1207 vattr->va_projid = fa.fsx_projid;
1209 error = bhv_vop_setattr(vp, vattr, attr_flags, NULL);
1211 __vn_revalidate(vp, vattr); /* update flags */
1216 case XFS_IOC_FSGETXATTRA: {
1217 vattr->va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | \
1218 XFS_AT_ANEXTENTS | XFS_AT_PROJID;
1219 error = bhv_vop_getattr(vp, vattr, 0, NULL);
1220 if (unlikely(error)) {
1225 fa.fsx_xflags = vattr->va_xflags;
1226 fa.fsx_extsize = vattr->va_extsize;
1227 fa.fsx_nextents = vattr->va_anextents;
1228 fa.fsx_projid = vattr->va_projid;
1230 if (copy_to_user(arg, &fa, sizeof(fa))) {
1237 case XFS_IOC_GETXFLAGS: {
1238 flags = xfs_di2lxflags(ip->i_d.di_flags);
1239 if (copy_to_user(arg, &flags, sizeof(flags)))
1244 case XFS_IOC_SETXFLAGS: {
1245 if (copy_from_user(&flags, arg, sizeof(flags))) {
1250 if (flags & ~(LINUX_XFLAG_IMMUTABLE | LINUX_XFLAG_APPEND | \
1251 LINUX_XFLAG_NOATIME | LINUX_XFLAG_NODUMP | \
1252 LINUX_XFLAG_SYNC)) {
1253 error = -EOPNOTSUPP;
1258 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1259 attr_flags |= ATTR_NONBLOCK;
1261 vattr->va_mask = XFS_AT_XFLAGS;
1262 vattr->va_xflags = xfs_merge_ioc_xflags(flags,
1265 error = bhv_vop_setattr(vp, vattr, attr_flags, NULL);
1267 __vn_revalidate(vp, vattr); /* update flags */
1293 if (copy_from_user(&bm, arg, sizeof(bm)))
1294 return -XFS_ERROR(EFAULT);
1296 if (bm.bmv_count < 2)
1297 return -XFS_ERROR(EINVAL);
1299 iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0);
1300 if (ioflags & IO_INVIS)
1301 iflags |= BMV_IF_NO_DMAPI_READ;
1303 error = xfs_getbmap(bdp, &bm, (struct getbmap __user *)arg+1, iflags);
1307 if (copy_to_user(arg, &bm, sizeof(bm)))
1308 return -XFS_ERROR(EFAULT);
1317 struct getbmapx bmx;
1322 if (copy_from_user(&bmx, arg, sizeof(bmx)))
1323 return -XFS_ERROR(EFAULT);
1325 if (bmx.bmv_count < 2)
1326 return -XFS_ERROR(EINVAL);
1329 * Map input getbmapx structure to a getbmap
1330 * structure for xfs_getbmap.
1332 GETBMAP_CONVERT(bmx, bm);
1334 iflags = bmx.bmv_iflags;
1336 if (iflags & (~BMV_IF_VALID))
1337 return -XFS_ERROR(EINVAL);
1339 iflags |= BMV_IF_EXTENDED;
1341 error = xfs_getbmap(bdp, &bm, (struct getbmapx __user *)arg+1, iflags);
1345 GETBMAP_CONVERT(bm, bmx);
1347 if (copy_to_user(arg, &bmx, sizeof(bmx)))
1348 return -XFS_ERROR(EFAULT);