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"
46 #include "xfs_buf_item.h"
47 #include "xfs_utils.h"
48 #include "xfs_dfrag.h"
49 #include "xfs_fsops.h"
51 #include <linux/capability.h>
52 #include <linux/dcache.h>
53 #include <linux/mount.h>
54 #include <linux/namei.h>
55 #include <linux/pagemap.h>
58 * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to
59 * a file or fs handle.
61 * XFS_IOC_PATH_TO_FSHANDLE
62 * returns fs handle for a mount point or path within that mount point
63 * XFS_IOC_FD_TO_HANDLE
64 * returns full handle for a FD opened in user space
65 * XFS_IOC_PATH_TO_HANDLE
66 * returns full handle for a path
75 xfs_fsop_handlereq_t hreq;
79 if (copy_from_user(&hreq, arg, sizeof(hreq)))
80 return -XFS_ERROR(EFAULT);
82 memset((char *)&handle, 0, sizeof(handle));
85 case XFS_IOC_PATH_TO_FSHANDLE:
86 case XFS_IOC_PATH_TO_HANDLE: {
90 error = user_path_walk_link((const char __user *)hreq.path, &nd);
95 ASSERT(nd.dentry->d_inode);
96 inode = igrab(nd.dentry->d_inode);
101 case XFS_IOC_FD_TO_HANDLE: {
104 file = fget(hreq.fd);
108 ASSERT(file->f_path.dentry);
109 ASSERT(file->f_path.dentry->d_inode);
110 inode = igrab(file->f_path.dentry->d_inode);
117 return -XFS_ERROR(EINVAL);
120 if (inode->i_sb->s_magic != XFS_SB_MAGIC) {
121 /* we're not in XFS anymore, Toto */
123 return -XFS_ERROR(EINVAL);
126 switch (inode->i_mode & S_IFMT) {
133 return -XFS_ERROR(EBADF);
136 /* we need the vnode */
137 vp = vn_from_inode(inode);
139 /* now we can grab the fsid */
140 memcpy(&handle.ha_fsid, vp->v_vfsp->vfs_altfsid, sizeof(xfs_fsid_t));
141 hsize = sizeof(xfs_fsid_t);
143 if (cmd != XFS_IOC_PATH_TO_FSHANDLE) {
147 /* need to get access to the xfs_inode to read the generation */
150 lock_mode = xfs_ilock_map_shared(ip);
152 /* fill in fid section of handle from inode */
153 handle.ha_fid.xfs_fid_len = sizeof(xfs_fid_t) -
154 sizeof(handle.ha_fid.xfs_fid_len);
155 handle.ha_fid.xfs_fid_pad = 0;
156 handle.ha_fid.xfs_fid_gen = ip->i_d.di_gen;
157 handle.ha_fid.xfs_fid_ino = ip->i_ino;
159 xfs_iunlock_map_shared(ip, lock_mode);
161 hsize = XFS_HSIZE(handle);
164 /* now copy our handle into the user buffer & write out the size */
165 if (copy_to_user(hreq.ohandle, &handle, hsize) ||
166 copy_to_user(hreq.ohandlen, &hsize, sizeof(__s32))) {
168 return -XFS_ERROR(EFAULT);
177 * Convert userspace handle data into vnode (and inode).
178 * We [ab]use the fact that all the fsop_handlereq ioctl calls
179 * have a data structure argument whose first component is always
180 * a xfs_fsop_handlereq_t, so we can cast to and from this type.
181 * This allows us to optimise the copy_from_user calls and gives
182 * a handy, shared routine.
184 * If no error, caller must always VN_RELE the returned vp.
187 xfs_vget_fsop_handlereq(
189 struct inode *parinode, /* parent inode pointer */
190 xfs_fsop_handlereq_t *hreq,
192 struct inode **inode)
197 xfs_handle_t *handlep;
200 struct inode *inodep;
207 * Only allow handle opens under a directory.
209 if (!S_ISDIR(parinode->i_mode))
210 return XFS_ERROR(ENOTDIR);
212 hanp = hreq->ihandle;
213 hlen = hreq->ihandlen;
216 if (hlen < sizeof(handlep->ha_fsid) || hlen > sizeof(*handlep))
217 return XFS_ERROR(EINVAL);
218 if (copy_from_user(handlep, hanp, hlen))
219 return XFS_ERROR(EFAULT);
220 if (hlen < sizeof(*handlep))
221 memset(((char *)handlep) + hlen, 0, sizeof(*handlep) - hlen);
222 if (hlen > sizeof(handlep->ha_fsid)) {
223 if (handlep->ha_fid.xfs_fid_len !=
224 (hlen - sizeof(handlep->ha_fsid)
225 - sizeof(handlep->ha_fid.xfs_fid_len))
226 || handlep->ha_fid.xfs_fid_pad)
227 return XFS_ERROR(EINVAL);
231 * Crack the handle, obtain the inode # & generation #
233 xfid = (struct xfs_fid *)&handlep->ha_fid;
234 if (xfid->xfs_fid_len == sizeof(*xfid) - sizeof(xfid->xfs_fid_len)) {
235 ino = xfid->xfs_fid_ino;
236 igen = xfid->xfs_fid_gen;
238 return XFS_ERROR(EINVAL);
242 * Get the XFS inode, building a vnode to go with it.
244 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
248 return XFS_ERROR(EIO);
249 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
250 xfs_iput_new(ip, XFS_ILOCK_SHARED);
251 return XFS_ERROR(ENOENT);
255 inodep = vn_to_inode(vpp);
256 xfs_iunlock(ip, XFS_ILOCK_SHARED);
267 struct file *parfilp,
268 struct inode *parinode)
275 struct dentry *dentry;
277 xfs_fsop_handlereq_t hreq;
279 if (!capable(CAP_SYS_ADMIN))
280 return -XFS_ERROR(EPERM);
281 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
282 return -XFS_ERROR(EFAULT);
284 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
288 /* Restrict xfs_open_by_handle to directories & regular files. */
289 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
291 return -XFS_ERROR(EINVAL);
294 #if BITS_PER_LONG != 32
295 hreq.oflags |= O_LARGEFILE;
297 /* Put open permission in namei format. */
298 permflag = hreq.oflags;
299 if ((permflag+1) & O_ACCMODE)
301 if (permflag & O_TRUNC)
304 if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
305 (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
307 return -XFS_ERROR(EPERM);
310 if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
312 return -XFS_ERROR(EACCES);
315 /* Can't write directories. */
316 if ( S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
318 return -XFS_ERROR(EISDIR);
321 if ((new_fd = get_unused_fd()) < 0) {
326 dentry = d_alloc_anon(inode);
327 if (dentry == NULL) {
329 put_unused_fd(new_fd);
330 return -XFS_ERROR(ENOMEM);
333 /* Ensure umount returns EBUSY on umounts while this file is open. */
334 mntget(parfilp->f_path.mnt);
336 /* Create file pointer. */
337 filp = dentry_open(dentry, parfilp->f_path.mnt, hreq.oflags);
339 put_unused_fd(new_fd);
340 return -XFS_ERROR(-PTR_ERR(filp));
342 if (inode->i_mode & S_IFREG) {
343 /* invisible operation should not change atime */
344 filp->f_flags |= O_NOATIME;
345 filp->f_op = &xfs_invis_file_operations;
348 fd_install(new_fd, filp);
353 * This is a copy from fs/namei.c:vfs_readlink(), except for removing it's
354 * unused first argument.
369 if (len > (unsigned) buflen)
371 if (copy_to_user(buffer, link, len))
379 xfs_readlink_by_handle(
382 struct inode *parinode)
385 xfs_fsop_handlereq_t hreq;
391 if (!capable(CAP_SYS_ADMIN))
392 return -XFS_ERROR(EPERM);
393 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
394 return -XFS_ERROR(EFAULT);
396 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
400 /* Restrict this handle operation to symlinks only. */
401 if (!S_ISLNK(inode->i_mode)) {
402 error = -XFS_ERROR(EINVAL);
406 if (copy_from_user(&olen, hreq.ohandlen, sizeof(__u32))) {
407 error = -XFS_ERROR(EFAULT);
411 link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
415 error = -bhv_vop_readlink(vp, link);
418 error = do_readlink(hreq.ohandle, olen, link);
430 xfs_fssetdm_by_handle(
433 struct inode *parinode)
436 struct fsdmidata fsd;
437 xfs_fsop_setdm_handlereq_t dmhreq;
442 if (!capable(CAP_MKNOD))
443 return -XFS_ERROR(EPERM);
444 if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t)))
445 return -XFS_ERROR(EFAULT);
447 error = xfs_vget_fsop_handlereq(mp, parinode, &dmhreq.hreq, &vp, &inode);
451 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
453 return -XFS_ERROR(EPERM);
456 if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
458 return -XFS_ERROR(EFAULT);
461 bdp = bhv_base_unlocked(VN_BHV_HEAD(vp));
462 error = xfs_set_dmattrs(bdp, fsd.fsd_dmevmask, fsd.fsd_dmstate, NULL);
471 xfs_attrlist_by_handle(
474 struct inode *parinode)
477 attrlist_cursor_kern_t *cursor;
478 xfs_fsop_attrlist_handlereq_t al_hreq;
483 if (!capable(CAP_SYS_ADMIN))
484 return -XFS_ERROR(EPERM);
485 if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t)))
486 return -XFS_ERROR(EFAULT);
487 if (al_hreq.buflen > XATTR_LIST_MAX)
488 return -XFS_ERROR(EINVAL);
490 error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq,
495 kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
499 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
500 error = bhv_vop_attr_list(vp, kbuf, al_hreq.buflen, al_hreq.flags,
505 if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen))
517 xfs_attrmulti_attr_get(
527 if (*len > XATTR_SIZE_MAX)
529 kbuf = kmalloc(*len, GFP_KERNEL);
533 error = bhv_vop_attr_get(vp, name, kbuf, len, flags, NULL);
537 if (copy_to_user(ubuf, kbuf, *len))
546 xfs_attrmulti_attr_set(
549 const char __user *ubuf,
556 if (IS_RDONLY(&vp->v_inode))
558 if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
560 if (len > XATTR_SIZE_MAX)
563 kbuf = kmalloc(len, GFP_KERNEL);
567 if (copy_from_user(kbuf, ubuf, len))
570 error = bhv_vop_attr_set(vp, name, kbuf, len, flags, NULL);
578 xfs_attrmulti_attr_remove(
583 if (IS_RDONLY(&vp->v_inode))
585 if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
587 return bhv_vop_attr_remove(vp, name, flags, NULL);
591 xfs_attrmulti_by_handle(
594 struct inode *parinode)
597 xfs_attr_multiop_t *ops;
598 xfs_fsop_attrmulti_handlereq_t am_hreq;
601 unsigned int i, size;
604 if (!capable(CAP_SYS_ADMIN))
605 return -XFS_ERROR(EPERM);
606 if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t)))
607 return -XFS_ERROR(EFAULT);
609 error = xfs_vget_fsop_handlereq(mp, parinode, &am_hreq.hreq, &vp, &inode);
614 size = am_hreq.opcount * sizeof(attr_multiop_t);
615 if (!size || size > 16 * PAGE_SIZE)
619 ops = kmalloc(size, GFP_KERNEL);
624 if (copy_from_user(ops, am_hreq.ops, size))
627 attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
633 for (i = 0; i < am_hreq.opcount; i++) {
634 ops[i].am_error = strncpy_from_user(attr_name,
635 ops[i].am_attrname, MAXNAMELEN);
636 if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
638 if (ops[i].am_error < 0)
641 switch (ops[i].am_opcode) {
643 ops[i].am_error = xfs_attrmulti_attr_get(vp,
644 attr_name, ops[i].am_attrvalue,
645 &ops[i].am_length, ops[i].am_flags);
648 ops[i].am_error = xfs_attrmulti_attr_set(vp,
649 attr_name, ops[i].am_attrvalue,
650 ops[i].am_length, ops[i].am_flags);
653 ops[i].am_error = xfs_attrmulti_attr_remove(vp,
654 attr_name, ops[i].am_flags);
657 ops[i].am_error = EINVAL;
661 if (copy_to_user(am_hreq.ops, ops, size))
662 error = XFS_ERROR(EFAULT);
673 /* prototypes for a few of the stack-hungry cases that have
674 * their own functions. Functions are defined after their use
675 * so gcc doesn't get fancy and inline them with -03 */
693 xfs_ioc_fsgeometry_v1(
736 vp = vn_from_inode(inode);
738 vn_trace_entry(vp, "xfs_ioctl", (inst_t *)__return_address);
740 ip = XFS_BHVTOI(bdp);
745 case XFS_IOC_ALLOCSP:
748 case XFS_IOC_UNRESVSP:
749 case XFS_IOC_ALLOCSP64:
750 case XFS_IOC_FREESP64:
751 case XFS_IOC_RESVSP64:
752 case XFS_IOC_UNRESVSP64:
754 * Only allow the sys admin to reserve space unless
755 * unwritten extents are enabled.
757 if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb) &&
758 !capable(CAP_SYS_ADMIN))
761 return xfs_ioc_space(bdp, inode, filp, ioflags, cmd, arg);
763 case XFS_IOC_DIOINFO: {
765 xfs_buftarg_t *target =
766 (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
767 mp->m_rtdev_targp : mp->m_ddev_targp;
769 da.d_mem = da.d_miniosz = 1 << target->bt_sshift;
770 da.d_maxiosz = INT_MAX & ~(da.d_miniosz - 1);
772 if (copy_to_user(arg, &da, sizeof(da)))
773 return -XFS_ERROR(EFAULT);
777 case XFS_IOC_FSBULKSTAT_SINGLE:
778 case XFS_IOC_FSBULKSTAT:
779 case XFS_IOC_FSINUMBERS:
780 return xfs_ioc_bulkstat(mp, cmd, arg);
782 case XFS_IOC_FSGEOMETRY_V1:
783 return xfs_ioc_fsgeometry_v1(mp, arg);
785 case XFS_IOC_FSGEOMETRY:
786 return xfs_ioc_fsgeometry(mp, arg);
788 case XFS_IOC_GETVERSION:
789 return put_user(inode->i_generation, (int __user *)arg);
791 case XFS_IOC_GETXFLAGS:
792 case XFS_IOC_SETXFLAGS:
793 case XFS_IOC_FSGETXATTR:
794 case XFS_IOC_FSSETXATTR:
795 case XFS_IOC_FSGETXATTRA:
796 return xfs_ioc_xattr(vp, ip, filp, cmd, arg);
798 case XFS_IOC_FSSETDM: {
799 struct fsdmidata dmi;
801 if (copy_from_user(&dmi, arg, sizeof(dmi)))
802 return -XFS_ERROR(EFAULT);
804 error = xfs_set_dmattrs(bdp, dmi.fsd_dmevmask, dmi.fsd_dmstate,
809 case XFS_IOC_GETBMAP:
810 case XFS_IOC_GETBMAPA:
811 return xfs_ioc_getbmap(bdp, ioflags, cmd, arg);
813 case XFS_IOC_GETBMAPX:
814 return xfs_ioc_getbmapx(bdp, arg);
816 case XFS_IOC_FD_TO_HANDLE:
817 case XFS_IOC_PATH_TO_HANDLE:
818 case XFS_IOC_PATH_TO_FSHANDLE:
819 return xfs_find_handle(cmd, arg);
821 case XFS_IOC_OPEN_BY_HANDLE:
822 return xfs_open_by_handle(mp, arg, filp, inode);
824 case XFS_IOC_FSSETDM_BY_HANDLE:
825 return xfs_fssetdm_by_handle(mp, arg, inode);
827 case XFS_IOC_READLINK_BY_HANDLE:
828 return xfs_readlink_by_handle(mp, arg, inode);
830 case XFS_IOC_ATTRLIST_BY_HANDLE:
831 return xfs_attrlist_by_handle(mp, arg, inode);
833 case XFS_IOC_ATTRMULTI_BY_HANDLE:
834 return xfs_attrmulti_by_handle(mp, arg, inode);
836 case XFS_IOC_SWAPEXT: {
837 error = xfs_swapext((struct xfs_swapext __user *)arg);
841 case XFS_IOC_FSCOUNTS: {
842 xfs_fsop_counts_t out;
844 error = xfs_fs_counts(mp, &out);
848 if (copy_to_user(arg, &out, sizeof(out)))
849 return -XFS_ERROR(EFAULT);
853 case XFS_IOC_SET_RESBLKS: {
854 xfs_fsop_resblks_t inout;
857 if (!capable(CAP_SYS_ADMIN))
860 if (copy_from_user(&inout, arg, sizeof(inout)))
861 return -XFS_ERROR(EFAULT);
863 /* input parameter is passed in resblks field of structure */
865 error = xfs_reserve_blocks(mp, &in, &inout);
869 if (copy_to_user(arg, &inout, sizeof(inout)))
870 return -XFS_ERROR(EFAULT);
874 case XFS_IOC_GET_RESBLKS: {
875 xfs_fsop_resblks_t out;
877 if (!capable(CAP_SYS_ADMIN))
880 error = xfs_reserve_blocks(mp, NULL, &out);
884 if (copy_to_user(arg, &out, sizeof(out)))
885 return -XFS_ERROR(EFAULT);
890 case XFS_IOC_FSGROWFSDATA: {
891 xfs_growfs_data_t in;
893 if (!capable(CAP_SYS_ADMIN))
896 if (copy_from_user(&in, arg, sizeof(in)))
897 return -XFS_ERROR(EFAULT);
899 error = xfs_growfs_data(mp, &in);
903 case XFS_IOC_FSGROWFSLOG: {
906 if (!capable(CAP_SYS_ADMIN))
909 if (copy_from_user(&in, arg, sizeof(in)))
910 return -XFS_ERROR(EFAULT);
912 error = xfs_growfs_log(mp, &in);
916 case XFS_IOC_FSGROWFSRT: {
919 if (!capable(CAP_SYS_ADMIN))
922 if (copy_from_user(&in, arg, sizeof(in)))
923 return -XFS_ERROR(EFAULT);
925 error = xfs_growfs_rt(mp, &in);
930 if (!capable(CAP_SYS_ADMIN))
933 if (inode->i_sb->s_frozen == SB_UNFROZEN)
934 freeze_bdev(inode->i_sb->s_bdev);
938 if (!capable(CAP_SYS_ADMIN))
940 if (inode->i_sb->s_frozen != SB_UNFROZEN)
941 thaw_bdev(inode->i_sb->s_bdev, inode->i_sb);
944 case XFS_IOC_GOINGDOWN: {
947 if (!capable(CAP_SYS_ADMIN))
950 if (get_user(in, (__uint32_t __user *)arg))
951 return -XFS_ERROR(EFAULT);
953 error = xfs_fs_goingdown(mp, in);
957 case XFS_IOC_ERROR_INJECTION: {
958 xfs_error_injection_t in;
960 if (!capable(CAP_SYS_ADMIN))
963 if (copy_from_user(&in, arg, sizeof(in)))
964 return -XFS_ERROR(EFAULT);
966 error = xfs_errortag_add(in.errtag, mp);
970 case XFS_IOC_ERROR_CLEARALL:
971 if (!capable(CAP_SYS_ADMIN))
974 error = xfs_errortag_clearall(mp);
995 if (inode->i_flags & (S_IMMUTABLE|S_APPEND))
996 return -XFS_ERROR(EPERM);
998 if (!(filp->f_mode & FMODE_WRITE))
999 return -XFS_ERROR(EBADF);
1001 if (!S_ISREG(inode->i_mode))
1002 return -XFS_ERROR(EINVAL);
1004 if (copy_from_user(&bf, arg, sizeof(bf)))
1005 return -XFS_ERROR(EFAULT);
1007 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1008 attr_flags |= ATTR_NONBLOCK;
1009 if (ioflags & IO_INVIS)
1010 attr_flags |= ATTR_DMI;
1012 error = xfs_change_file_space(bdp, cmd, &bf, filp->f_pos,
1023 xfs_fsop_bulkreq_t bulkreq;
1024 int count; /* # of records returned */
1025 xfs_ino_t inlast; /* last inode number */
1029 /* done = 1 if there are more stats to get and if bulkstat */
1030 /* should be called again (unused here, but used in dmapi) */
1032 if (!capable(CAP_SYS_ADMIN))
1035 if (XFS_FORCED_SHUTDOWN(mp))
1036 return -XFS_ERROR(EIO);
1038 if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t)))
1039 return -XFS_ERROR(EFAULT);
1041 if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
1042 return -XFS_ERROR(EFAULT);
1044 if ((count = bulkreq.icount) <= 0)
1045 return -XFS_ERROR(EINVAL);
1047 if (cmd == XFS_IOC_FSINUMBERS)
1048 error = xfs_inumbers(mp, &inlast, &count,
1049 bulkreq.ubuffer, xfs_inumbers_fmt);
1050 else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE)
1051 error = xfs_bulkstat_single(mp, &inlast,
1052 bulkreq.ubuffer, &done);
1053 else { /* XFS_IOC_FSBULKSTAT */
1054 if (count == 1 && inlast != 0) {
1056 error = xfs_bulkstat_single(mp, &inlast,
1057 bulkreq.ubuffer, &done);
1059 error = xfs_bulkstat(mp, &inlast, &count,
1060 (bulkstat_one_pf)xfs_bulkstat_one, NULL,
1061 sizeof(xfs_bstat_t), bulkreq.ubuffer,
1062 BULKSTAT_FG_QUICK, &done);
1069 if (bulkreq.ocount != NULL) {
1070 if (copy_to_user(bulkreq.lastip, &inlast,
1072 return -XFS_ERROR(EFAULT);
1074 if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
1075 return -XFS_ERROR(EFAULT);
1082 xfs_ioc_fsgeometry_v1(
1086 xfs_fsop_geom_v1_t fsgeo;
1089 error = xfs_fs_geometry(mp, (xfs_fsop_geom_t *)&fsgeo, 3);
1093 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
1094 return -XFS_ERROR(EFAULT);
1103 xfs_fsop_geom_t fsgeo;
1106 error = xfs_fs_geometry(mp, &fsgeo, 4);
1110 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
1111 return -XFS_ERROR(EFAULT);
1116 * Linux extended inode flags interface.
1120 xfs_merge_ioc_xflags(
1124 unsigned int xflags = start;
1126 if (flags & FS_IMMUTABLE_FL)
1127 xflags |= XFS_XFLAG_IMMUTABLE;
1129 xflags &= ~XFS_XFLAG_IMMUTABLE;
1130 if (flags & FS_APPEND_FL)
1131 xflags |= XFS_XFLAG_APPEND;
1133 xflags &= ~XFS_XFLAG_APPEND;
1134 if (flags & FS_SYNC_FL)
1135 xflags |= XFS_XFLAG_SYNC;
1137 xflags &= ~XFS_XFLAG_SYNC;
1138 if (flags & FS_NOATIME_FL)
1139 xflags |= XFS_XFLAG_NOATIME;
1141 xflags &= ~XFS_XFLAG_NOATIME;
1142 if (flags & FS_NODUMP_FL)
1143 xflags |= XFS_XFLAG_NODUMP;
1145 xflags &= ~XFS_XFLAG_NODUMP;
1152 __uint16_t di_flags)
1154 unsigned int flags = 0;
1156 if (di_flags & XFS_DIFLAG_IMMUTABLE)
1157 flags |= FS_IMMUTABLE_FL;
1158 if (di_flags & XFS_DIFLAG_APPEND)
1159 flags |= FS_APPEND_FL;
1160 if (di_flags & XFS_DIFLAG_SYNC)
1161 flags |= FS_SYNC_FL;
1162 if (di_flags & XFS_DIFLAG_NOATIME)
1163 flags |= FS_NOATIME_FL;
1164 if (di_flags & XFS_DIFLAG_NODUMP)
1165 flags |= FS_NODUMP_FL;
1178 struct bhv_vattr *vattr;
1183 vattr = kmalloc(sizeof(*vattr), GFP_KERNEL);
1184 if (unlikely(!vattr))
1188 case XFS_IOC_FSGETXATTR: {
1189 vattr->va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | \
1190 XFS_AT_NEXTENTS | XFS_AT_PROJID;
1191 error = bhv_vop_getattr(vp, vattr, 0, NULL);
1192 if (unlikely(error)) {
1197 fa.fsx_xflags = vattr->va_xflags;
1198 fa.fsx_extsize = vattr->va_extsize;
1199 fa.fsx_nextents = vattr->va_nextents;
1200 fa.fsx_projid = vattr->va_projid;
1202 if (copy_to_user(arg, &fa, sizeof(fa))) {
1209 case XFS_IOC_FSSETXATTR: {
1210 if (copy_from_user(&fa, arg, sizeof(fa))) {
1216 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1217 attr_flags |= ATTR_NONBLOCK;
1219 vattr->va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | XFS_AT_PROJID;
1220 vattr->va_xflags = fa.fsx_xflags;
1221 vattr->va_extsize = fa.fsx_extsize;
1222 vattr->va_projid = fa.fsx_projid;
1224 error = bhv_vop_setattr(vp, vattr, attr_flags, NULL);
1226 __vn_revalidate(vp, vattr); /* update flags */
1231 case XFS_IOC_FSGETXATTRA: {
1232 vattr->va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | \
1233 XFS_AT_ANEXTENTS | XFS_AT_PROJID;
1234 error = bhv_vop_getattr(vp, vattr, 0, NULL);
1235 if (unlikely(error)) {
1240 fa.fsx_xflags = vattr->va_xflags;
1241 fa.fsx_extsize = vattr->va_extsize;
1242 fa.fsx_nextents = vattr->va_anextents;
1243 fa.fsx_projid = vattr->va_projid;
1245 if (copy_to_user(arg, &fa, sizeof(fa))) {
1252 case XFS_IOC_GETXFLAGS: {
1253 flags = xfs_di2lxflags(ip->i_d.di_flags);
1254 if (copy_to_user(arg, &flags, sizeof(flags)))
1259 case XFS_IOC_SETXFLAGS: {
1260 if (copy_from_user(&flags, arg, sizeof(flags))) {
1265 if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
1266 FS_NOATIME_FL | FS_NODUMP_FL | \
1268 error = -EOPNOTSUPP;
1273 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1274 attr_flags |= ATTR_NONBLOCK;
1276 vattr->va_mask = XFS_AT_XFLAGS;
1277 vattr->va_xflags = xfs_merge_ioc_xflags(flags,
1280 error = bhv_vop_setattr(vp, vattr, attr_flags, NULL);
1282 __vn_revalidate(vp, vattr); /* update flags */
1307 if (copy_from_user(&bm, arg, sizeof(bm)))
1308 return -XFS_ERROR(EFAULT);
1310 if (bm.bmv_count < 2)
1311 return -XFS_ERROR(EINVAL);
1313 iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0);
1314 if (ioflags & IO_INVIS)
1315 iflags |= BMV_IF_NO_DMAPI_READ;
1317 error = xfs_getbmap(bdp, &bm, (struct getbmap __user *)arg+1, iflags);
1321 if (copy_to_user(arg, &bm, sizeof(bm)))
1322 return -XFS_ERROR(EFAULT);
1331 struct getbmapx bmx;
1336 if (copy_from_user(&bmx, arg, sizeof(bmx)))
1337 return -XFS_ERROR(EFAULT);
1339 if (bmx.bmv_count < 2)
1340 return -XFS_ERROR(EINVAL);
1343 * Map input getbmapx structure to a getbmap
1344 * structure for xfs_getbmap.
1346 GETBMAP_CONVERT(bmx, bm);
1348 iflags = bmx.bmv_iflags;
1350 if (iflags & (~BMV_IF_VALID))
1351 return -XFS_ERROR(EINVAL);
1353 iflags |= BMV_IF_EXTENDED;
1355 error = xfs_getbmap(bdp, &bm, (struct getbmapx __user *)arg+1, iflags);
1359 GETBMAP_CONVERT(bm, bmx);
1361 if (copy_to_user(arg, &bmx, sizeof(bmx)))
1362 return -XFS_ERROR(EFAULT);