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 * ioctl commands that are used by Linux filesystems
78 #define XFS_IOC_GETXFLAGS _IOR('f', 1, long)
79 #define XFS_IOC_SETXFLAGS _IOW('f', 2, long)
80 #define XFS_IOC_GETVERSION _IOR('v', 1, long)
84 * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to
85 * a file or fs handle.
87 * XFS_IOC_PATH_TO_FSHANDLE
88 * returns fs handle for a mount point or path within that mount point
89 * XFS_IOC_FD_TO_HANDLE
90 * returns full handle for a FD opened in user space
91 * XFS_IOC_PATH_TO_HANDLE
92 * returns full handle for a path
101 xfs_fsop_handlereq_t hreq;
105 if (copy_from_user(&hreq, (xfs_fsop_handlereq_t *)arg, sizeof(hreq)))
106 return -XFS_ERROR(EFAULT);
108 memset((char *)&handle, 0, sizeof(handle));
111 case XFS_IOC_PATH_TO_FSHANDLE:
112 case XFS_IOC_PATH_TO_HANDLE: {
116 error = user_path_walk_link(hreq.path, &nd);
121 ASSERT(nd.dentry->d_inode);
122 inode = igrab(nd.dentry->d_inode);
127 case XFS_IOC_FD_TO_HANDLE: {
130 file = fget(hreq.fd);
134 ASSERT(file->f_dentry);
135 ASSERT(file->f_dentry->d_inode);
136 inode = igrab(file->f_dentry->d_inode);
143 return -XFS_ERROR(EINVAL);
146 if (inode->i_sb->s_magic != XFS_SB_MAGIC) {
147 /* we're not in XFS anymore, Toto */
149 return -XFS_ERROR(EINVAL);
152 /* we need the vnode */
153 vp = LINVFS_GET_VP(inode);
154 if (vp->v_type != VREG && vp->v_type != VDIR && vp->v_type != VLNK) {
156 return -XFS_ERROR(EBADF);
159 /* now we can grab the fsid */
160 memcpy(&handle.ha_fsid, vp->v_vfsp->vfs_altfsid, sizeof(xfs_fsid_t));
161 hsize = sizeof(xfs_fsid_t);
163 if (cmd != XFS_IOC_PATH_TO_FSHANDLE) {
168 /* need to get access to the xfs_inode to read the generation */
169 bhv = vn_bhv_lookup_unlocked(VN_BHV_HEAD(vp), &xfs_vnodeops);
171 ip = XFS_BHVTOI(bhv);
173 lock_mode = xfs_ilock_map_shared(ip);
175 /* fill in fid section of handle from inode */
176 handle.ha_fid.xfs_fid_len = sizeof(xfs_fid_t) -
177 sizeof(handle.ha_fid.xfs_fid_len);
178 handle.ha_fid.xfs_fid_pad = 0;
179 handle.ha_fid.xfs_fid_gen = ip->i_d.di_gen;
180 handle.ha_fid.xfs_fid_ino = ip->i_ino;
182 xfs_iunlock_map_shared(ip, lock_mode);
184 hsize = XFS_HSIZE(handle);
187 /* now copy our handle into the user buffer & write out the size */
188 if (copy_to_user((xfs_handle_t *)hreq.ohandle, &handle, hsize) ||
189 copy_to_user(hreq.ohandlen, &hsize, sizeof(__s32))) {
191 return -XFS_ERROR(EFAULT);
200 * Convert userspace handle data into vnode (and inode).
201 * We [ab]use the fact that all the fsop_handlereq ioctl calls
202 * have a data structure argument whose first component is always
203 * a xfs_fsop_handlereq_t, so we can cast to and from this type.
204 * This allows us to optimise the copy_from_user calls and gives
205 * a handy, shared routine.
207 * If no error, caller must always VN_RELE the returned vp.
210 xfs_vget_fsop_handlereq(
212 struct inode *parinode, /* parent inode pointer */
213 int cap, /* capability level for op */
214 unsigned long arg, /* userspace data pointer */
215 unsigned long size, /* size of expected struct */
216 /* output arguments */
217 xfs_fsop_handlereq_t *hreq,
219 struct inode **inode)
224 xfs_handle_t *handlep;
227 struct inode *inodep;
234 return XFS_ERROR(EPERM);
237 * Only allow handle opens under a directory.
239 if (!S_ISDIR(parinode->i_mode))
240 return XFS_ERROR(ENOTDIR);
243 * Copy the handle down from the user and validate
244 * that it looks to be in the correct format.
246 if (copy_from_user(hreq, (struct xfs_fsop_handlereq *)arg, size))
247 return XFS_ERROR(EFAULT);
249 hanp = hreq->ihandle;
250 hlen = hreq->ihandlen;
253 if (hlen < sizeof(handlep->ha_fsid) || hlen > sizeof(*handlep))
254 return XFS_ERROR(EINVAL);
255 if (copy_from_user(handlep, hanp, hlen))
256 return XFS_ERROR(EFAULT);
257 if (hlen < sizeof(*handlep))
258 memset(((char *)handlep) + hlen, 0, sizeof(*handlep) - hlen);
259 if (hlen > sizeof(handlep->ha_fsid)) {
260 if (handlep->ha_fid.xfs_fid_len !=
261 (hlen - sizeof(handlep->ha_fsid)
262 - sizeof(handlep->ha_fid.xfs_fid_len))
263 || handlep->ha_fid.xfs_fid_pad)
264 return XFS_ERROR(EINVAL);
268 * Crack the handle, obtain the inode # & generation #
270 xfid = (struct xfs_fid *)&handlep->ha_fid;
271 if (xfid->xfs_fid_len == sizeof(*xfid) - sizeof(xfid->xfs_fid_len)) {
272 ino = xfid->xfs_fid_ino;
273 igen = xfid->xfs_fid_gen;
275 return XFS_ERROR(EINVAL);
279 * Get the XFS inode, building a vnode to go with it.
281 error = xfs_iget(mp, NULL, ino, XFS_ILOCK_SHARED, &ip, 0);
285 return XFS_ERROR(EIO);
286 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
287 xfs_iput_new(ip, XFS_ILOCK_SHARED);
288 return XFS_ERROR(ENOENT);
292 inodep = LINVFS_GET_IP(vpp);
293 xfs_iunlock(ip, XFS_ILOCK_SHARED);
304 struct file *parfilp,
305 struct inode *parinode)
312 struct dentry *dentry;
314 xfs_fsop_handlereq_t hreq;
316 error = xfs_vget_fsop_handlereq(mp, parinode, CAP_SYS_ADMIN, arg,
317 sizeof(xfs_fsop_handlereq_t),
322 /* Restrict xfs_open_by_handle to directories & regular files. */
323 if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
325 return -XFS_ERROR(EINVAL);
328 #if BITS_PER_LONG != 32
329 hreq.oflags |= O_LARGEFILE;
331 /* Put open permission in namei format. */
332 permflag = hreq.oflags;
333 if ((permflag+1) & O_ACCMODE)
335 if (permflag & O_TRUNC)
338 if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
339 (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
341 return -XFS_ERROR(EPERM);
344 if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
346 return -XFS_ERROR(EACCES);
349 /* Can't write directories. */
350 if ( S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
352 return -XFS_ERROR(EISDIR);
355 if ((new_fd = get_unused_fd()) < 0) {
360 dentry = d_alloc_anon(inode);
361 if (dentry == NULL) {
363 put_unused_fd(new_fd);
364 return -XFS_ERROR(ENOMEM);
367 /* Ensure umount returns EBUSY on umounts while this file is open. */
368 mntget(parfilp->f_vfsmnt);
370 /* Create file pointer. */
371 filp = dentry_open(dentry, parfilp->f_vfsmnt, hreq.oflags);
373 put_unused_fd(new_fd);
374 return -XFS_ERROR(-PTR_ERR(filp));
376 if (inode->i_mode & S_IFREG)
377 filp->f_op = &linvfs_invis_file_operations;
379 fd_install(new_fd, filp);
384 xfs_readlink_by_handle(
387 struct file *parfilp,
388 struct inode *parinode)
394 xfs_fsop_handlereq_t hreq;
398 error = xfs_vget_fsop_handlereq(mp, parinode, CAP_SYS_ADMIN, arg,
399 sizeof(xfs_fsop_handlereq_t),
404 /* Restrict this handle operation to symlinks only. */
405 if (vp->v_type != VLNK) {
407 return -XFS_ERROR(EINVAL);
410 if (copy_from_user(&olen, hreq.ohandlen, sizeof(__u32))) {
412 return -XFS_ERROR(EFAULT);
415 aiov.iov_base = hreq.ohandle;
417 auio.uio_iov = &aiov;
420 auio.uio_segflg = UIO_USERSPACE;
421 auio.uio_resid = olen;
423 VOP_READLINK(vp, &auio, IO_INVIS, NULL, error);
426 return (olen - auio.uio_resid);
430 xfs_fssetdm_by_handle(
433 struct file *parfilp,
434 struct inode *parinode)
437 struct fsdmidata fsd;
438 xfs_fsop_setdm_handlereq_t dmhreq;
443 error = xfs_vget_fsop_handlereq(mp, parinode, CAP_MKNOD, arg,
444 sizeof(xfs_fsop_setdm_handlereq_t),
445 (xfs_fsop_handlereq_t *)&dmhreq,
450 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
452 return -XFS_ERROR(EPERM);
455 if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
457 return -XFS_ERROR(EFAULT);
460 bdp = bhv_base_unlocked(VN_BHV_HEAD(vp));
461 error = xfs_set_dmattrs(bdp, fsd.fsd_dmevmask, fsd.fsd_dmstate, NULL);
470 xfs_attrlist_by_handle(
473 struct file *parfilp,
474 struct inode *parinode)
477 attrlist_cursor_kern_t *cursor;
478 xfs_fsop_attrlist_handlereq_t al_hreq;
482 error = xfs_vget_fsop_handlereq(mp, parinode, CAP_SYS_ADMIN, arg,
483 sizeof(xfs_fsop_attrlist_handlereq_t),
484 (xfs_fsop_handlereq_t *)&al_hreq,
489 cursor = (attrlist_cursor_kern_t *)&al_hreq.pos;
490 VOP_ATTR_LIST(vp, al_hreq.buffer, al_hreq.buflen, al_hreq.flags,
491 cursor, NULL, error);
499 xfs_attrmulti_by_handle(
502 struct file *parfilp,
503 struct inode *parinode)
506 xfs_attr_multiop_t *ops;
507 xfs_fsop_attrmulti_handlereq_t am_hreq;
512 error = xfs_vget_fsop_handlereq(mp, parinode, CAP_SYS_ADMIN, arg,
513 sizeof(xfs_fsop_attrmulti_handlereq_t),
514 (xfs_fsop_handlereq_t *)&am_hreq,
519 size = am_hreq.opcount * sizeof(attr_multiop_t);
520 ops = (xfs_attr_multiop_t *)kmalloc(size, GFP_KERNEL);
523 return -XFS_ERROR(ENOMEM);
526 if (copy_from_user(ops, am_hreq.ops, size)) {
529 return -XFS_ERROR(EFAULT);
532 for (i = 0; i < am_hreq.opcount; i++) {
533 switch(ops[i].am_opcode) {
535 VOP_ATTR_GET(vp,ops[i].am_attrname, ops[i].am_attrvalue,
536 &ops[i].am_length, ops[i].am_flags,
537 NULL, ops[i].am_error);
540 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
541 ops[i].am_error = EPERM;
544 VOP_ATTR_SET(vp,ops[i].am_attrname, ops[i].am_attrvalue,
545 ops[i].am_length, ops[i].am_flags,
546 NULL, ops[i].am_error);
549 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
550 ops[i].am_error = EPERM;
553 VOP_ATTR_REMOVE(vp, ops[i].am_attrname, ops[i].am_flags,
554 NULL, ops[i].am_error);
557 ops[i].am_error = EINVAL;
561 if (copy_to_user(am_hreq.ops, ops, size))
562 error = -XFS_ERROR(EFAULT);
569 /* prototypes for a few of the stack-hungry cases that have
570 * their own functions. Functions are defined after their use
571 * so gcc doesn't get fancy and inline them with -03 */
589 xfs_ioc_fsgeometry_v1(
633 vp = LINVFS_GET_VP(inode);
635 vn_trace_entry(vp, "xfs_ioctl", (inst_t *)__return_address);
637 ip = XFS_BHVTOI(bdp);
642 case XFS_IOC_ALLOCSP:
645 case XFS_IOC_UNRESVSP:
646 case XFS_IOC_ALLOCSP64:
647 case XFS_IOC_FREESP64:
648 case XFS_IOC_RESVSP64:
649 case XFS_IOC_UNRESVSP64:
651 * Only allow the sys admin to reserve space unless
652 * unwritten extents are enabled.
654 if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb) &&
655 !capable(CAP_SYS_ADMIN))
658 return xfs_ioc_space(bdp, vp, filp, ioflags, cmd, arg);
660 case XFS_IOC_DIOINFO: {
662 xfs_buftarg_t *target =
663 (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
664 mp->m_rtdev_targp : mp->m_ddev_targp;
666 da.d_mem = da.d_miniosz = 1 << target->pbr_sshift;
667 /* The size dio will do in one go */
668 da.d_maxiosz = 64 * PAGE_CACHE_SIZE;
670 if (copy_to_user((struct dioattr *)arg, &da, sizeof(da)))
671 return -XFS_ERROR(EFAULT);
675 case XFS_IOC_FSBULKSTAT_SINGLE:
676 case XFS_IOC_FSBULKSTAT:
677 case XFS_IOC_FSINUMBERS:
678 return xfs_ioc_bulkstat(mp, cmd, arg);
680 case XFS_IOC_FSGEOMETRY_V1:
681 return xfs_ioc_fsgeometry_v1(mp, arg);
683 case XFS_IOC_FSGEOMETRY:
684 return xfs_ioc_fsgeometry(mp, arg);
686 case XFS_IOC_GETVERSION:
687 case XFS_IOC_GETXFLAGS:
688 case XFS_IOC_SETXFLAGS:
689 case XFS_IOC_FSGETXATTR:
690 case XFS_IOC_FSSETXATTR:
691 case XFS_IOC_FSGETXATTRA:
692 return xfs_ioc_xattr(vp, ip, filp, cmd, arg);
694 case XFS_IOC_FSSETDM: {
695 struct fsdmidata dmi;
697 if (copy_from_user(&dmi, (struct fsdmidata *)arg, sizeof(dmi)))
698 return -XFS_ERROR(EFAULT);
700 error = xfs_set_dmattrs(bdp, dmi.fsd_dmevmask, dmi.fsd_dmstate,
705 case XFS_IOC_GETBMAP:
706 case XFS_IOC_GETBMAPA:
707 return xfs_ioc_getbmap(bdp, filp, ioflags, cmd, arg);
709 case XFS_IOC_GETBMAPX:
710 return xfs_ioc_getbmapx(bdp, arg);
712 case XFS_IOC_FD_TO_HANDLE:
713 case XFS_IOC_PATH_TO_HANDLE:
714 case XFS_IOC_PATH_TO_FSHANDLE:
715 return xfs_find_handle(cmd, arg);
717 case XFS_IOC_OPEN_BY_HANDLE:
718 return xfs_open_by_handle(mp, arg, filp, inode);
720 case XFS_IOC_FSSETDM_BY_HANDLE:
721 return xfs_fssetdm_by_handle(mp, arg, filp, inode);
723 case XFS_IOC_READLINK_BY_HANDLE:
724 return xfs_readlink_by_handle(mp, arg, filp, inode);
726 case XFS_IOC_ATTRLIST_BY_HANDLE:
727 return xfs_attrlist_by_handle(mp, arg, filp, inode);
729 case XFS_IOC_ATTRMULTI_BY_HANDLE:
730 return xfs_attrmulti_by_handle(mp, arg, filp, inode);
732 case XFS_IOC_SWAPEXT: {
733 error = xfs_swapext((struct xfs_swapext *)arg);
737 case XFS_IOC_FSCOUNTS: {
738 xfs_fsop_counts_t out;
740 error = xfs_fs_counts(mp, &out);
744 if (copy_to_user((char *)arg, &out, sizeof(out)))
745 return -XFS_ERROR(EFAULT);
749 case XFS_IOC_SET_RESBLKS: {
750 xfs_fsop_resblks_t inout;
753 if (!capable(CAP_SYS_ADMIN))
756 if (copy_from_user(&inout, (char *)arg, sizeof(inout)))
757 return -XFS_ERROR(EFAULT);
759 /* input parameter is passed in resblks field of structure */
761 error = xfs_reserve_blocks(mp, &in, &inout);
765 if (copy_to_user((char *)arg, &inout, sizeof(inout)))
766 return -XFS_ERROR(EFAULT);
770 case XFS_IOC_GET_RESBLKS: {
771 xfs_fsop_resblks_t out;
773 if (!capable(CAP_SYS_ADMIN))
776 error = xfs_reserve_blocks(mp, NULL, &out);
780 if (copy_to_user((char *)arg, &out, sizeof(out)))
781 return -XFS_ERROR(EFAULT);
786 case XFS_IOC_FSGROWFSDATA: {
787 xfs_growfs_data_t in;
789 if (!capable(CAP_SYS_ADMIN))
792 if (copy_from_user(&in, (char *)arg, sizeof(in)))
793 return -XFS_ERROR(EFAULT);
795 error = xfs_growfs_data(mp, &in);
799 case XFS_IOC_FSGROWFSLOG: {
802 if (!capable(CAP_SYS_ADMIN))
805 if (copy_from_user(&in, (char *)arg, sizeof(in)))
806 return -XFS_ERROR(EFAULT);
808 error = xfs_growfs_log(mp, &in);
812 case XFS_IOC_FSGROWFSRT: {
815 if (!capable(CAP_SYS_ADMIN))
818 if (copy_from_user(&in, (char *)arg, sizeof(in)))
819 return -XFS_ERROR(EFAULT);
821 error = xfs_growfs_rt(mp, &in);
826 if (!capable(CAP_SYS_ADMIN))
829 freeze_bdev(inode->i_sb->s_bdev);
833 if (!capable(CAP_SYS_ADMIN))
835 thaw_bdev(inode->i_sb->s_bdev, inode->i_sb);
838 case XFS_IOC_GOINGDOWN: {
841 if (!capable(CAP_SYS_ADMIN))
844 if (get_user(in, (__uint32_t *)arg))
845 return -XFS_ERROR(EFAULT);
847 error = xfs_fs_goingdown(mp, in);
851 case XFS_IOC_ERROR_INJECTION: {
852 xfs_error_injection_t in;
854 if (!capable(CAP_SYS_ADMIN))
857 if (copy_from_user(&in, (char *)arg, sizeof(in)))
858 return -XFS_ERROR(EFAULT);
860 error = xfs_errortag_add(in.errtag, mp);
864 case XFS_IOC_ERROR_CLEARALL:
865 if (!capable(CAP_SYS_ADMIN))
868 error = xfs_errortag_clearall(mp);
889 if (vp->v_inode.i_flags & (S_IMMUTABLE|S_APPEND))
890 return -XFS_ERROR(EPERM);
892 if (!(filp->f_flags & FMODE_WRITE))
893 return -XFS_ERROR(EBADF);
895 if (vp->v_type != VREG)
896 return -XFS_ERROR(EINVAL);
898 if (copy_from_user(&bf, (xfs_flock64_t *)arg, sizeof(bf)))
899 return -XFS_ERROR(EFAULT);
901 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
902 attr_flags |= ATTR_NONBLOCK;
903 if (ioflags & IO_INVIS)
904 attr_flags |= ATTR_DMI;
906 error = xfs_change_file_space(bdp, cmd, &bf, filp->f_pos,
917 xfs_fsop_bulkreq_t bulkreq;
918 int count; /* # of records returned */
919 xfs_ino_t inlast; /* last inode number */
923 /* done = 1 if there are more stats to get and if bulkstat */
924 /* should be called again (unused here, but used in dmapi) */
926 if (!capable(CAP_SYS_ADMIN))
929 if (XFS_FORCED_SHUTDOWN(mp))
930 return -XFS_ERROR(EIO);
932 if (copy_from_user(&bulkreq, (xfs_fsop_bulkreq_t *)arg,
933 sizeof(xfs_fsop_bulkreq_t)))
934 return -XFS_ERROR(EFAULT);
936 if (copy_from_user(&inlast, (__s64 *)bulkreq.lastip,
938 return -XFS_ERROR(EFAULT);
940 if ((count = bulkreq.icount) <= 0)
941 return -XFS_ERROR(EINVAL);
943 if (cmd == XFS_IOC_FSINUMBERS)
944 error = xfs_inumbers(mp, &inlast, &count,
946 else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE)
947 error = xfs_bulkstat_single(mp, &inlast,
948 bulkreq.ubuffer, &done);
949 else { /* XFS_IOC_FSBULKSTAT */
950 if (count == 1 && inlast != 0) {
952 error = xfs_bulkstat_single(mp, &inlast,
953 bulkreq.ubuffer, &done);
955 error = xfs_bulkstat(mp, &inlast, &count,
956 (bulkstat_one_pf)xfs_bulkstat_one, NULL,
957 sizeof(xfs_bstat_t), bulkreq.ubuffer,
958 BULKSTAT_FG_QUICK, &done);
965 if (bulkreq.ocount != NULL) {
966 if (copy_to_user((xfs_ino_t *)bulkreq.lastip, &inlast,
968 return -XFS_ERROR(EFAULT);
970 if (copy_to_user((__s32 *)bulkreq.ocount, &count,
972 return -XFS_ERROR(EFAULT);
979 xfs_ioc_fsgeometry_v1(
983 xfs_fsop_geom_v1_t fsgeo;
986 error = xfs_fs_geometry(mp, (xfs_fsop_geom_t *)&fsgeo, 3);
990 if (copy_to_user((xfs_fsop_geom_t *)arg, &fsgeo, sizeof(fsgeo)))
991 return -XFS_ERROR(EFAULT);
1000 xfs_fsop_geom_t fsgeo;
1003 error = xfs_fs_geometry(mp, &fsgeo, 4);
1007 if (copy_to_user((xfs_fsop_geom_t *)arg, &fsgeo, sizeof(fsgeo)))
1008 return -XFS_ERROR(EFAULT);
1013 * Linux extended inode flags interface.
1015 #define LINUX_XFLAG_SYNC 0x00000008 /* Synchronous updates */
1016 #define LINUX_XFLAG_IMMUTABLE 0x00000010 /* Immutable file */
1017 #define LINUX_XFLAG_APPEND 0x00000020 /* writes to file may only append */
1018 #define LINUX_XFLAG_NODUMP 0x00000040 /* do not dump file */
1019 #define LINUX_XFLAG_NOATIME 0x00000080 /* do not update atime */
1022 xfs_merge_ioc_xflags(
1026 unsigned int xflags = start;
1028 if (flags & LINUX_XFLAG_IMMUTABLE)
1029 xflags |= XFS_XFLAG_IMMUTABLE;
1031 xflags &= ~XFS_XFLAG_IMMUTABLE;
1032 if (flags & LINUX_XFLAG_APPEND)
1033 xflags |= XFS_XFLAG_APPEND;
1035 xflags &= ~XFS_XFLAG_APPEND;
1036 if (flags & LINUX_XFLAG_SYNC)
1037 xflags |= XFS_XFLAG_SYNC;
1039 xflags &= ~XFS_XFLAG_SYNC;
1040 if (flags & LINUX_XFLAG_NOATIME)
1041 xflags |= XFS_XFLAG_NOATIME;
1043 xflags &= ~XFS_XFLAG_NOATIME;
1044 if (flags & LINUX_XFLAG_NODUMP)
1045 xflags |= XFS_XFLAG_NODUMP;
1047 xflags &= ~XFS_XFLAG_NODUMP;
1054 __uint16_t di_flags)
1056 unsigned int flags = 0;
1058 if (di_flags & XFS_DIFLAG_IMMUTABLE)
1059 flags |= LINUX_XFLAG_IMMUTABLE;
1060 if (di_flags & XFS_DIFLAG_APPEND)
1061 flags |= LINUX_XFLAG_APPEND;
1062 if (di_flags & XFS_DIFLAG_SYNC)
1063 flags |= LINUX_XFLAG_SYNC;
1064 if (di_flags & XFS_DIFLAG_NOATIME)
1065 flags |= LINUX_XFLAG_NOATIME;
1066 if (di_flags & XFS_DIFLAG_NODUMP)
1067 flags |= LINUX_XFLAG_NODUMP;
1086 case XFS_IOC_FSGETXATTR: {
1087 va.va_mask = XFS_AT_XFLAGS|XFS_AT_EXTSIZE|XFS_AT_NEXTENTS;
1088 VOP_GETATTR(vp, &va, 0, NULL, error);
1092 fa.fsx_xflags = va.va_xflags;
1093 fa.fsx_extsize = va.va_extsize;
1094 fa.fsx_nextents = va.va_nextents;
1096 if (copy_to_user((struct fsxattr *)arg, &fa, sizeof(fa)))
1097 return -XFS_ERROR(EFAULT);
1101 case XFS_IOC_FSSETXATTR: {
1102 if (copy_from_user(&fa, (struct fsxattr *)arg, sizeof(fa)))
1103 return -XFS_ERROR(EFAULT);
1106 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1107 attr_flags |= ATTR_NONBLOCK;
1109 va.va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE;
1110 va.va_xflags = fa.fsx_xflags;
1111 va.va_extsize = fa.fsx_extsize;
1113 VOP_SETATTR(vp, &va, attr_flags, NULL, error);
1115 vn_revalidate(vp); /* update Linux inode flags */
1119 case XFS_IOC_FSGETXATTRA: {
1120 va.va_mask = XFS_AT_XFLAGS|XFS_AT_EXTSIZE|XFS_AT_ANEXTENTS;
1121 VOP_GETATTR(vp, &va, 0, NULL, error);
1125 fa.fsx_xflags = va.va_xflags;
1126 fa.fsx_extsize = va.va_extsize;
1127 fa.fsx_nextents = va.va_anextents;
1129 if (copy_to_user((struct fsxattr *)arg, &fa, sizeof(fa)))
1130 return -XFS_ERROR(EFAULT);
1134 case XFS_IOC_GETXFLAGS: {
1135 flags = xfs_di2lxflags(ip->i_d.di_flags);
1136 if (copy_to_user((unsigned int *)arg, &flags, sizeof(flags)))
1137 return -XFS_ERROR(EFAULT);
1141 case XFS_IOC_SETXFLAGS: {
1142 if (copy_from_user(&flags, (unsigned int *)arg, sizeof(flags)))
1143 return -XFS_ERROR(EFAULT);
1145 if (flags & ~(LINUX_XFLAG_IMMUTABLE | LINUX_XFLAG_APPEND | \
1146 LINUX_XFLAG_NOATIME | LINUX_XFLAG_NODUMP | \
1148 return -XFS_ERROR(EOPNOTSUPP);
1151 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
1152 attr_flags |= ATTR_NONBLOCK;
1154 va.va_mask = XFS_AT_XFLAGS;
1155 va.va_xflags = xfs_merge_ioc_xflags(flags,
1156 xfs_dic2xflags(&ip->i_d, ARCH_NOCONVERT));
1158 VOP_SETATTR(vp, &va, attr_flags, NULL, error);
1160 vn_revalidate(vp); /* update Linux inode flags */
1164 case XFS_IOC_GETVERSION: {
1165 flags = LINVFS_GET_IP(vp)->i_generation;
1166 if (copy_to_user((unsigned int *)arg, &flags, sizeof(flags)))
1167 return -XFS_ERROR(EFAULT);
1188 if (copy_from_user(&bm, (struct getbmap *)arg, sizeof(bm)))
1189 return -XFS_ERROR(EFAULT);
1191 if (bm.bmv_count < 2)
1192 return -XFS_ERROR(EINVAL);
1194 iflags = (cmd == XFS_IOC_GETBMAPA ? BMV_IF_ATTRFORK : 0);
1195 if (ioflags & IO_INVIS)
1196 iflags |= BMV_IF_NO_DMAPI_READ;
1198 error = xfs_getbmap(bdp, &bm, (struct getbmap *)arg+1, iflags);
1202 if (copy_to_user((struct getbmap *)arg, &bm, sizeof(bm)))
1203 return -XFS_ERROR(EFAULT);
1212 struct getbmapx bmx;
1217 if (copy_from_user(&bmx, (struct getbmapx *)arg, sizeof(bmx)))
1218 return -XFS_ERROR(EFAULT);
1220 if (bmx.bmv_count < 2)
1221 return -XFS_ERROR(EINVAL);
1224 * Map input getbmapx structure to a getbmap
1225 * structure for xfs_getbmap.
1227 GETBMAP_CONVERT(bmx, bm);
1229 iflags = bmx.bmv_iflags;
1231 if (iflags & (~BMV_IF_VALID))
1232 return -XFS_ERROR(EINVAL);
1234 iflags |= BMV_IF_EXTENDED;
1236 error = xfs_getbmap(bdp, &bm, (struct getbmapx *)arg+1, iflags);
1240 GETBMAP_CONVERT(bm, bmx);
1242 if (copy_to_user((struct getbmapx *)arg, &bmx, sizeof(bmx)))
1243 return -XFS_ERROR(EFAULT);