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"
28 #include "xfs_alloc.h"
29 #include "xfs_dmapi.h"
30 #include "xfs_mount.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_alloc_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_dir_sf.h"
35 #include "xfs_attr_sf.h"
36 #include "xfs_dir2_sf.h"
37 #include "xfs_dinode.h"
38 #include "xfs_inode.h"
39 #include "xfs_btree.h"
40 #include "xfs_ialloc.h"
41 #include "xfs_rtalloc.h"
42 #include "xfs_itable.h"
43 #include "xfs_error.h"
50 #include "xfs_buf_item.h"
51 #include "xfs_utils.h"
52 #include "xfs_dfrag.h"
53 #include "xfs_fsops.h"
55 #include <linux/dcache.h>
56 #include <linux/mount.h>
57 #include <linux/namei.h>
58 #include <linux/pagemap.h>
61 * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to
62 * a file or fs handle.
64 * XFS_IOC_PATH_TO_FSHANDLE
65 * returns fs handle for a mount point or path within that mount point
66 * XFS_IOC_FD_TO_HANDLE
67 * returns full handle for a FD opened in user space
68 * XFS_IOC_PATH_TO_HANDLE
69 * returns full handle for a path
78 xfs_fsop_handlereq_t hreq;
82 if (copy_from_user(&hreq, arg, sizeof(hreq)))
83 return -XFS_ERROR(EFAULT);
85 memset((char *)&handle, 0, sizeof(handle));
88 case XFS_IOC_PATH_TO_FSHANDLE:
89 case XFS_IOC_PATH_TO_HANDLE: {
93 error = user_path_walk_link((const char __user *)hreq.path, &nd);
98 ASSERT(nd.dentry->d_inode);
99 inode = igrab(nd.dentry->d_inode);
104 case XFS_IOC_FD_TO_HANDLE: {
107 file = fget(hreq.fd);
111 ASSERT(file->f_dentry);
112 ASSERT(file->f_dentry->d_inode);
113 inode = igrab(file->f_dentry->d_inode);
120 return -XFS_ERROR(EINVAL);
123 if (inode->i_sb->s_magic != XFS_SB_MAGIC) {
124 /* we're not in XFS anymore, Toto */
126 return -XFS_ERROR(EINVAL);
129 switch (inode->i_mode & S_IFMT) {
136 return -XFS_ERROR(EBADF);
139 /* we need the vnode */
140 vp = LINVFS_GET_VP(inode);
142 /* now we can grab the fsid */
143 memcpy(&handle.ha_fsid, vp->v_vfsp->vfs_altfsid, sizeof(xfs_fsid_t));
144 hsize = sizeof(xfs_fsid_t);
146 if (cmd != XFS_IOC_PATH_TO_FSHANDLE) {
151 /* need to get access to the xfs_inode to read the generation */
152 bhv = vn_bhv_lookup_unlocked(VN_BHV_HEAD(vp), &xfs_vnodeops);
154 ip = XFS_BHVTOI(bhv);
156 lock_mode = xfs_ilock_map_shared(ip);
158 /* fill in fid section of handle from inode */
159 handle.ha_fid.xfs_fid_len = sizeof(xfs_fid_t) -
160 sizeof(handle.ha_fid.xfs_fid_len);
161 handle.ha_fid.xfs_fid_pad = 0;
162 handle.ha_fid.xfs_fid_gen = ip->i_d.di_gen;
163 handle.ha_fid.xfs_fid_ino = ip->i_ino;
165 xfs_iunlock_map_shared(ip, lock_mode);
167 hsize = XFS_HSIZE(handle);
170 /* now copy our handle into the user buffer & write out the size */
171 if (copy_to_user(hreq.ohandle, &handle, hsize) ||
172 copy_to_user(hreq.ohandlen, &hsize, sizeof(__s32))) {
174 return -XFS_ERROR(EFAULT);
183 * Convert userspace handle data into vnode (and inode).
184 * We [ab]use the fact that all the fsop_handlereq ioctl calls
185 * have a data structure argument whose first component is always
186 * a xfs_fsop_handlereq_t, so we can cast to and from this type.
187 * This allows us to optimise the copy_from_user calls and gives
188 * a handy, shared routine.
190 * If no error, caller must always VN_RELE the returned vp.
193 xfs_vget_fsop_handlereq(
195 struct inode *parinode, /* parent inode pointer */
196 xfs_fsop_handlereq_t *hreq,
198 struct inode **inode)
203 xfs_handle_t *handlep;
206 struct inode *inodep;
213 * Only allow handle opens under a directory.
215 if (!S_ISDIR(parinode->i_mode))
216 return XFS_ERROR(ENOTDIR);
218 hanp = hreq->ihandle;
219 hlen = hreq->ihandlen;
222 if (hlen < sizeof(handlep->ha_fsid) || hlen > sizeof(*handlep))
223 return XFS_ERROR(EINVAL);
224 if (copy_from_user(handlep, hanp, hlen))
225 return XFS_ERROR(EFAULT);
226 if (hlen < sizeof(*handlep))
227 memset(((char *)handlep) + hlen, 0, sizeof(*handlep) - hlen);
228 if (hlen > sizeof(handlep->ha_fsid)) {
229 if (handlep->ha_fid.xfs_fid_len !=
230 (hlen - sizeof(handlep->ha_fsid)
231 - sizeof(handlep->ha_fid.xfs_fid_len))
232 || handlep->ha_fid.xfs_fid_pad)
233 return XFS_ERROR(EINVAL);
237 * Crack the handle, obtain the inode # & generation #
239 xfid = (struct xfs_fid *)&handlep->ha_fid;
240 if (xfid->xfs_fid_len == sizeof(*xfid) - sizeof(xfid->xfs_fid_len)) {
241 ino = xfid->xfs_fid_ino;
242 igen = xfid->xfs_fid_gen;
244 return XFS_ERROR(EINVAL);
248 * Get the XFS inode, building a vnode to go with it.
250 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
254 return XFS_ERROR(EIO);
255 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
256 xfs_iput_new(ip, XFS_ILOCK_SHARED);
257 return XFS_ERROR(ENOENT);
261 inodep = LINVFS_GET_IP(vpp);
262 xfs_iunlock(ip, XFS_ILOCK_SHARED);
273 struct file *parfilp,
274 struct inode *parinode)
281 struct dentry *dentry;
283 xfs_fsop_handlereq_t hreq;
285 if (!capable(CAP_SYS_ADMIN))
286 return -XFS_ERROR(EPERM);
287 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
288 return -XFS_ERROR(EFAULT);
290 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
294 /* Restrict xfs_open_by_handle to directories & regular files. */
295 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
297 return -XFS_ERROR(EINVAL);
300 #if BITS_PER_LONG != 32
301 hreq.oflags |= O_LARGEFILE;
303 /* Put open permission in namei format. */
304 permflag = hreq.oflags;
305 if ((permflag+1) & O_ACCMODE)
307 if (permflag & O_TRUNC)
310 if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
311 (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
313 return -XFS_ERROR(EPERM);
316 if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
318 return -XFS_ERROR(EACCES);
321 /* Can't write directories. */
322 if ( S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
324 return -XFS_ERROR(EISDIR);
327 if ((new_fd = get_unused_fd()) < 0) {
332 dentry = d_alloc_anon(inode);
333 if (dentry == NULL) {
335 put_unused_fd(new_fd);
336 return -XFS_ERROR(ENOMEM);
339 /* Ensure umount returns EBUSY on umounts while this file is open. */
340 mntget(parfilp->f_vfsmnt);
342 /* Create file pointer. */
343 filp = dentry_open(dentry, parfilp->f_vfsmnt, hreq.oflags);
345 put_unused_fd(new_fd);
346 return -XFS_ERROR(-PTR_ERR(filp));
348 if (inode->i_mode & S_IFREG)
349 filp->f_op = &linvfs_invis_file_operations;
351 fd_install(new_fd, filp);
356 xfs_readlink_by_handle(
359 struct file *parfilp,
360 struct inode *parinode)
366 xfs_fsop_handlereq_t hreq;
370 if (!capable(CAP_SYS_ADMIN))
371 return -XFS_ERROR(EPERM);
372 if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
373 return -XFS_ERROR(EFAULT);
375 error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
379 /* Restrict this handle operation to symlinks only. */
380 if (!S_ISLNK(inode->i_mode)) {
382 return -XFS_ERROR(EINVAL);
385 if (copy_from_user(&olen, hreq.ohandlen, sizeof(__u32))) {
387 return -XFS_ERROR(EFAULT);
390 aiov.iov_base = hreq.ohandle;
392 auio.uio_iov = &aiov;
395 auio.uio_segflg = UIO_USERSPACE;
396 auio.uio_resid = olen;
398 VOP_READLINK(vp, &auio, IO_INVIS, NULL, error);
401 return (olen - auio.uio_resid);
405 xfs_fssetdm_by_handle(
408 struct file *parfilp,
409 struct inode *parinode)
412 struct fsdmidata fsd;
413 xfs_fsop_setdm_handlereq_t dmhreq;
418 if (!capable(CAP_MKNOD))
419 return -XFS_ERROR(EPERM);
420 if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t)))
421 return -XFS_ERROR(EFAULT);
423 error = xfs_vget_fsop_handlereq(mp, parinode, &dmhreq.hreq, &vp, &inode);
427 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
429 return -XFS_ERROR(EPERM);
432 if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
434 return -XFS_ERROR(EFAULT);
437 bdp = bhv_base_unlocked(VN_BHV_HEAD(vp));
438 error = xfs_set_dmattrs(bdp, fsd.fsd_dmevmask, fsd.fsd_dmstate, NULL);
447 xfs_attrlist_by_handle(
450 struct file *parfilp,
451 struct inode *parinode)
454 attrlist_cursor_kern_t *cursor;
455 xfs_fsop_attrlist_handlereq_t al_hreq;
460 if (!capable(CAP_SYS_ADMIN))
461 return -XFS_ERROR(EPERM);
462 if (copy_from_user(&al_hreq, arg, sizeof(xfs_fsop_attrlist_handlereq_t)))
463 return -XFS_ERROR(EFAULT);
464 if (al_hreq.buflen > XATTR_LIST_MAX)
465 return -XFS_ERROR(EINVAL);
467 error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq,
472 kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
476 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
477 VOP_ATTR_LIST(vp, kbuf, al_hreq.buflen, al_hreq.flags,
478 cursor, NULL, error);
482 if (copy_to_user(al_hreq.buffer, kbuf, al_hreq.buflen))
494 xfs_attrmulti_attr_get(
504 if (*len > XATTR_SIZE_MAX)
506 kbuf = kmalloc(*len, GFP_KERNEL);
510 VOP_ATTR_GET(vp, name, kbuf, len, flags, NULL, error);
514 if (copy_to_user(ubuf, kbuf, *len))
523 xfs_attrmulti_attr_set(
526 const char __user *ubuf,
533 if (IS_RDONLY(&vp->v_inode))
535 if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
537 if (len > XATTR_SIZE_MAX)
540 kbuf = kmalloc(len, GFP_KERNEL);
544 if (copy_from_user(kbuf, ubuf, len))
547 VOP_ATTR_SET(vp, name, kbuf, len, flags, NULL, error);
555 xfs_attrmulti_attr_remove(
563 if (IS_RDONLY(&vp->v_inode))
565 if (IS_IMMUTABLE(&vp->v_inode) || IS_APPEND(&vp->v_inode))
568 VOP_ATTR_REMOVE(vp, name, flags, NULL, error);
573 xfs_attrmulti_by_handle(
576 struct file *parfilp,
577 struct inode *parinode)
580 xfs_attr_multiop_t *ops;
581 xfs_fsop_attrmulti_handlereq_t am_hreq;
584 unsigned int i, size;
587 if (!capable(CAP_SYS_ADMIN))
588 return -XFS_ERROR(EPERM);
589 if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t)))
590 return -XFS_ERROR(EFAULT);
592 error = xfs_vget_fsop_handlereq(mp, parinode, &am_hreq.hreq, &vp, &inode);
597 size = am_hreq.opcount * sizeof(attr_multiop_t);
598 if (!size || size > 16 * PAGE_SIZE)
602 ops = kmalloc(size, GFP_KERNEL);
607 if (copy_from_user(ops, am_hreq.ops, size))
610 attr_name = kmalloc(MAXNAMELEN, GFP_KERNEL);
616 for (i = 0; i < am_hreq.opcount; i++) {
617 ops[i].am_error = strncpy_from_user(attr_name,
618 ops[i].am_attrname, MAXNAMELEN);
619 if (ops[i].am_error == 0 || ops[i].am_error == MAXNAMELEN)
621 if (ops[i].am_error < 0)
624 switch (ops[i].am_opcode) {
626 ops[i].am_error = xfs_attrmulti_attr_get(vp,
627 attr_name, ops[i].am_attrvalue,
628 &ops[i].am_length, ops[i].am_flags);
631 ops[i].am_error = xfs_attrmulti_attr_set(vp,
632 attr_name, ops[i].am_attrvalue,
633 ops[i].am_length, ops[i].am_flags);
636 ops[i].am_error = xfs_attrmulti_attr_remove(vp,
637 attr_name, ops[i].am_flags);
640 ops[i].am_error = EINVAL;
644 if (copy_to_user(am_hreq.ops, ops, size))
645 error = XFS_ERROR(EFAULT);
656 /* prototypes for a few of the stack-hungry cases that have
657 * their own functions. Functions are defined after their use
658 * so gcc doesn't get fancy and inline them with -03 */
676 xfs_ioc_fsgeometry_v1(
720 vp = LINVFS_GET_VP(inode);
722 vn_trace_entry(vp, "xfs_ioctl", (inst_t *)__return_address);
724 ip = XFS_BHVTOI(bdp);
729 case XFS_IOC_ALLOCSP:
732 case XFS_IOC_UNRESVSP:
733 case XFS_IOC_ALLOCSP64:
734 case XFS_IOC_FREESP64:
735 case XFS_IOC_RESVSP64:
736 case XFS_IOC_UNRESVSP64:
738 * Only allow the sys admin to reserve space unless
739 * unwritten extents are enabled.
741 if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb) &&
742 !capable(CAP_SYS_ADMIN))
745 return xfs_ioc_space(bdp, vp, filp, ioflags, cmd, arg);
747 case XFS_IOC_DIOINFO: {
749 xfs_buftarg_t *target =
750 (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
751 mp->m_rtdev_targp : mp->m_ddev_targp;
753 da.d_mem = da.d_miniosz = 1 << target->pbr_sshift;
754 /* The size dio will do in one go */
755 da.d_maxiosz = 64 * PAGE_CACHE_SIZE;
757 if (copy_to_user(arg, &da, sizeof(da)))
758 return -XFS_ERROR(EFAULT);
762 case XFS_IOC_FSBULKSTAT_SINGLE:
763 case XFS_IOC_FSBULKSTAT:
764 case XFS_IOC_FSINUMBERS:
765 return xfs_ioc_bulkstat(mp, cmd, arg);
767 case XFS_IOC_FSGEOMETRY_V1:
768 return xfs_ioc_fsgeometry_v1(mp, arg);
770 case XFS_IOC_FSGEOMETRY:
771 return xfs_ioc_fsgeometry(mp, arg);
773 case XFS_IOC_GETVERSION:
774 case XFS_IOC_GETXFLAGS:
775 case XFS_IOC_SETXFLAGS:
776 case XFS_IOC_FSGETXATTR:
777 case XFS_IOC_FSSETXATTR:
778 case XFS_IOC_FSGETXATTRA:
779 return xfs_ioc_xattr(vp, ip, filp, cmd, arg);
781 case XFS_IOC_FSSETDM: {
782 struct fsdmidata dmi;
784 if (copy_from_user(&dmi, arg, sizeof(dmi)))
785 return -XFS_ERROR(EFAULT);
787 error = xfs_set_dmattrs(bdp, dmi.fsd_dmevmask, dmi.fsd_dmstate,
792 case XFS_IOC_GETBMAP:
793 case XFS_IOC_GETBMAPA:
794 return xfs_ioc_getbmap(bdp, filp, ioflags, cmd, arg);
796 case XFS_IOC_GETBMAPX:
797 return xfs_ioc_getbmapx(bdp, arg);
799 case XFS_IOC_FD_TO_HANDLE:
800 case XFS_IOC_PATH_TO_HANDLE:
801 case XFS_IOC_PATH_TO_FSHANDLE:
802 return xfs_find_handle(cmd, arg);
804 case XFS_IOC_OPEN_BY_HANDLE:
805 return xfs_open_by_handle(mp, arg, filp, inode);
807 case XFS_IOC_FSSETDM_BY_HANDLE:
808 return xfs_fssetdm_by_handle(mp, arg, filp, inode);
810 case XFS_IOC_READLINK_BY_HANDLE:
811 return xfs_readlink_by_handle(mp, arg, filp, inode);
813 case XFS_IOC_ATTRLIST_BY_HANDLE:
814 return xfs_attrlist_by_handle(mp, arg, filp, inode);
816 case XFS_IOC_ATTRMULTI_BY_HANDLE:
817 return xfs_attrmulti_by_handle(mp, arg, filp, inode);
819 case XFS_IOC_SWAPEXT: {
820 error = xfs_swapext((struct xfs_swapext __user *)arg);
824 case XFS_IOC_FSCOUNTS: {
825 xfs_fsop_counts_t out;
827 error = xfs_fs_counts(mp, &out);
831 if (copy_to_user(arg, &out, sizeof(out)))
832 return -XFS_ERROR(EFAULT);
836 case XFS_IOC_SET_RESBLKS: {
837 xfs_fsop_resblks_t inout;
840 if (!capable(CAP_SYS_ADMIN))
843 if (copy_from_user(&inout, arg, sizeof(inout)))
844 return -XFS_ERROR(EFAULT);
846 /* input parameter is passed in resblks field of structure */
848 error = xfs_reserve_blocks(mp, &in, &inout);
852 if (copy_to_user(arg, &inout, sizeof(inout)))
853 return -XFS_ERROR(EFAULT);
857 case XFS_IOC_GET_RESBLKS: {
858 xfs_fsop_resblks_t out;
860 if (!capable(CAP_SYS_ADMIN))
863 error = xfs_reserve_blocks(mp, NULL, &out);
867 if (copy_to_user(arg, &out, sizeof(out)))
868 return -XFS_ERROR(EFAULT);
873 case XFS_IOC_FSGROWFSDATA: {
874 xfs_growfs_data_t in;
876 if (!capable(CAP_SYS_ADMIN))
879 if (copy_from_user(&in, arg, sizeof(in)))
880 return -XFS_ERROR(EFAULT);
882 error = xfs_growfs_data(mp, &in);
886 case XFS_IOC_FSGROWFSLOG: {
889 if (!capable(CAP_SYS_ADMIN))
892 if (copy_from_user(&in, arg, sizeof(in)))
893 return -XFS_ERROR(EFAULT);
895 error = xfs_growfs_log(mp, &in);
899 case XFS_IOC_FSGROWFSRT: {
902 if (!capable(CAP_SYS_ADMIN))
905 if (copy_from_user(&in, arg, sizeof(in)))
906 return -XFS_ERROR(EFAULT);
908 error = xfs_growfs_rt(mp, &in);
913 if (!capable(CAP_SYS_ADMIN))
916 if (inode->i_sb->s_frozen == SB_UNFROZEN)
917 freeze_bdev(inode->i_sb->s_bdev);
921 if (!capable(CAP_SYS_ADMIN))
923 if (inode->i_sb->s_frozen != SB_UNFROZEN)
924 thaw_bdev(inode->i_sb->s_bdev, inode->i_sb);
927 case XFS_IOC_GOINGDOWN: {
930 if (!capable(CAP_SYS_ADMIN))
933 if (get_user(in, (__uint32_t __user *)arg))
934 return -XFS_ERROR(EFAULT);
936 error = xfs_fs_goingdown(mp, in);
940 case XFS_IOC_ERROR_INJECTION: {
941 xfs_error_injection_t in;
943 if (!capable(CAP_SYS_ADMIN))
946 if (copy_from_user(&in, arg, sizeof(in)))
947 return -XFS_ERROR(EFAULT);
949 error = xfs_errortag_add(in.errtag, mp);
953 case XFS_IOC_ERROR_CLEARALL:
954 if (!capable(CAP_SYS_ADMIN))
957 error = xfs_errortag_clearall(mp);
978 if (vp->v_inode.i_flags & (S_IMMUTABLE|S_APPEND))
979 return -XFS_ERROR(EPERM);
981 if (!(filp->f_mode & FMODE_WRITE))
982 return -XFS_ERROR(EBADF);
985 return -XFS_ERROR(EINVAL);
987 if (copy_from_user(&bf, arg, sizeof(bf)))
988 return -XFS_ERROR(EFAULT);
990 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
991 attr_flags |= ATTR_NONBLOCK;
992 if (ioflags & IO_INVIS)
993 attr_flags |= ATTR_DMI;
995 error = xfs_change_file_space(bdp, cmd, &bf, filp->f_pos,
1006 xfs_fsop_bulkreq_t bulkreq;
1007 int count; /* # of records returned */
1008 xfs_ino_t inlast; /* last inode number */
1012 /* done = 1 if there are more stats to get and if bulkstat */
1013 /* should be called again (unused here, but used in dmapi) */
1015 if (!capable(CAP_SYS_ADMIN))
1018 if (XFS_FORCED_SHUTDOWN(mp))
1019 return -XFS_ERROR(EIO);
1021 if (copy_from_user(&bulkreq, arg, sizeof(xfs_fsop_bulkreq_t)))
1022 return -XFS_ERROR(EFAULT);
1024 if (copy_from_user(&inlast, bulkreq.lastip, sizeof(__s64)))
1025 return -XFS_ERROR(EFAULT);
1027 if ((count = bulkreq.icount) <= 0)
1028 return -XFS_ERROR(EINVAL);
1030 if (cmd == XFS_IOC_FSINUMBERS)
1031 error = xfs_inumbers(mp, &inlast, &count,
1033 else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE)
1034 error = xfs_bulkstat_single(mp, &inlast,
1035 bulkreq.ubuffer, &done);
1036 else { /* XFS_IOC_FSBULKSTAT */
1037 if (count == 1 && inlast != 0) {
1039 error = xfs_bulkstat_single(mp, &inlast,
1040 bulkreq.ubuffer, &done);
1042 error = xfs_bulkstat(mp, &inlast, &count,
1043 (bulkstat_one_pf)xfs_bulkstat_one, NULL,
1044 sizeof(xfs_bstat_t), bulkreq.ubuffer,
1045 BULKSTAT_FG_QUICK, &done);
1052 if (bulkreq.ocount != NULL) {
1053 if (copy_to_user(bulkreq.lastip, &inlast,
1055 return -XFS_ERROR(EFAULT);
1057 if (copy_to_user(bulkreq.ocount, &count, sizeof(count)))
1058 return -XFS_ERROR(EFAULT);
1065 xfs_ioc_fsgeometry_v1(
1069 xfs_fsop_geom_v1_t fsgeo;
1072 error = xfs_fs_geometry(mp, (xfs_fsop_geom_t *)&fsgeo, 3);
1076 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
1077 return -XFS_ERROR(EFAULT);
1086 xfs_fsop_geom_t fsgeo;
1089 error = xfs_fs_geometry(mp, &fsgeo, 4);
1093 if (copy_to_user(arg, &fsgeo, sizeof(fsgeo)))
1094 return -XFS_ERROR(EFAULT);
1099 * Linux extended inode flags interface.
1101 #define LINUX_XFLAG_SYNC 0x00000008 /* Synchronous updates */
1102 #define LINUX_XFLAG_IMMUTABLE 0x00000010 /* Immutable file */
1103 #define LINUX_XFLAG_APPEND 0x00000020 /* writes to file may only append */
1104 #define LINUX_XFLAG_NODUMP 0x00000040 /* do not dump file */
1105 #define LINUX_XFLAG_NOATIME 0x00000080 /* do not update atime */
1108 xfs_merge_ioc_xflags(
1112 unsigned int xflags = start;
1114 if (flags & LINUX_XFLAG_IMMUTABLE)
1115 xflags |= XFS_XFLAG_IMMUTABLE;
1117 xflags &= ~XFS_XFLAG_IMMUTABLE;
1118 if (flags & LINUX_XFLAG_APPEND)
1119 xflags |= XFS_XFLAG_APPEND;
1121 xflags &= ~XFS_XFLAG_APPEND;
1122 if (flags & LINUX_XFLAG_SYNC)
1123 xflags |= XFS_XFLAG_SYNC;
1125 xflags &= ~XFS_XFLAG_SYNC;
1126 if (flags & LINUX_XFLAG_NOATIME)
1127 xflags |= XFS_XFLAG_NOATIME;
1129 xflags &= ~XFS_XFLAG_NOATIME;
1130 if (flags & LINUX_XFLAG_NODUMP)
1131 xflags |= XFS_XFLAG_NODUMP;
1133 xflags &= ~XFS_XFLAG_NODUMP;
1140 __uint16_t di_flags)
1142 unsigned int flags = 0;
1144 if (di_flags & XFS_DIFLAG_IMMUTABLE)
1145 flags |= LINUX_XFLAG_IMMUTABLE;
1146 if (di_flags & XFS_DIFLAG_APPEND)
1147 flags |= LINUX_XFLAG_APPEND;
1148 if (di_flags & XFS_DIFLAG_SYNC)
1149 flags |= LINUX_XFLAG_SYNC;
1150 if (di_flags & XFS_DIFLAG_NOATIME)
1151 flags |= LINUX_XFLAG_NOATIME;
1152 if (di_flags & XFS_DIFLAG_NODUMP)
1153 flags |= LINUX_XFLAG_NODUMP;
1172 case XFS_IOC_FSGETXATTR: {
1173 va.va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | \
1174 XFS_AT_NEXTENTS | XFS_AT_PROJID;
1175 VOP_GETATTR(vp, &va, 0, NULL, error);
1179 fa.fsx_xflags = va.va_xflags;
1180 fa.fsx_extsize = va.va_extsize;
1181 fa.fsx_nextents = va.va_nextents;
1182 fa.fsx_projid = va.va_projid;
1184 if (copy_to_user(arg, &fa, sizeof(fa)))
1185 return -XFS_ERROR(EFAULT);
1189 case XFS_IOC_FSSETXATTR: {
1190 if (copy_from_user(&fa, arg, sizeof(fa)))
1191 return -XFS_ERROR(EFAULT);
1194 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1195 attr_flags |= ATTR_NONBLOCK;
1197 va.va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | XFS_AT_PROJID;
1198 va.va_xflags = fa.fsx_xflags;
1199 va.va_extsize = fa.fsx_extsize;
1200 va.va_projid = fa.fsx_projid;
1202 VOP_SETATTR(vp, &va, attr_flags, NULL, error);
1204 vn_revalidate(vp); /* update Linux inode flags */
1208 case XFS_IOC_FSGETXATTRA: {
1209 va.va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | \
1210 XFS_AT_ANEXTENTS | XFS_AT_PROJID;
1211 VOP_GETATTR(vp, &va, 0, NULL, error);
1215 fa.fsx_xflags = va.va_xflags;
1216 fa.fsx_extsize = va.va_extsize;
1217 fa.fsx_nextents = va.va_anextents;
1218 fa.fsx_projid = va.va_projid;
1220 if (copy_to_user(arg, &fa, sizeof(fa)))
1221 return -XFS_ERROR(EFAULT);
1225 case XFS_IOC_GETXFLAGS: {
1226 flags = xfs_di2lxflags(ip->i_d.di_flags);
1227 if (copy_to_user(arg, &flags, sizeof(flags)))
1228 return -XFS_ERROR(EFAULT);
1232 case XFS_IOC_SETXFLAGS: {
1233 if (copy_from_user(&flags, arg, sizeof(flags)))
1234 return -XFS_ERROR(EFAULT);
1236 if (flags & ~(LINUX_XFLAG_IMMUTABLE | LINUX_XFLAG_APPEND | \
1237 LINUX_XFLAG_NOATIME | LINUX_XFLAG_NODUMP | \
1239 return -XFS_ERROR(EOPNOTSUPP);
1242 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1243 attr_flags |= ATTR_NONBLOCK;
1245 va.va_mask = XFS_AT_XFLAGS;
1246 va.va_xflags = xfs_merge_ioc_xflags(flags,
1249 VOP_SETATTR(vp, &va, attr_flags, NULL, error);
1251 vn_revalidate(vp); /* update Linux inode flags */
1255 case XFS_IOC_GETVERSION: {
1256 flags = LINVFS_GET_IP(vp)->i_generation;
1257 if (copy_to_user(arg, &flags, sizeof(flags)))
1258 return -XFS_ERROR(EFAULT);
1279 if (copy_from_user(&bm, arg, sizeof(bm)))
1280 return -XFS_ERROR(EFAULT);
1282 if (bm.bmv_count < 2)
1283 return -XFS_ERROR(EINVAL);
1285 iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0);
1286 if (ioflags & IO_INVIS)
1287 iflags |= BMV_IF_NO_DMAPI_READ;
1289 error = xfs_getbmap(bdp, &bm, (struct getbmap __user *)arg+1, iflags);
1293 if (copy_to_user(arg, &bm, sizeof(bm)))
1294 return -XFS_ERROR(EFAULT);
1303 struct getbmapx bmx;
1308 if (copy_from_user(&bmx, arg, sizeof(bmx)))
1309 return -XFS_ERROR(EFAULT);
1311 if (bmx.bmv_count < 2)
1312 return -XFS_ERROR(EINVAL);
1315 * Map input getbmapx structure to a getbmap
1316 * structure for xfs_getbmap.
1318 GETBMAP_CONVERT(bmx, bm);
1320 iflags = bmx.bmv_iflags;
1322 if (iflags & (~BMV_IF_VALID))
1323 return -XFS_ERROR(EINVAL);
1325 iflags |= BMV_IF_EXTENDED;
1327 error = xfs_getbmap(bdp, &bm, (struct getbmapx __user *)arg+1, iflags);
1331 GETBMAP_CONVERT(bm, bmx);
1333 if (copy_to_user(arg, &bmx, sizeof(bmx)))
1334 return -XFS_ERROR(EFAULT);