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
) {
150 /* need to get access to the xfs_inode to read the generation */
153 lock_mode
= xfs_ilock_map_shared(ip
);
155 /* fill in fid section of handle from inode */
156 handle
.ha_fid
.xfs_fid_len
= sizeof(xfs_fid_t
) -
157 sizeof(handle
.ha_fid
.xfs_fid_len
);
158 handle
.ha_fid
.xfs_fid_pad
= 0;
159 handle
.ha_fid
.xfs_fid_gen
= ip
->i_d
.di_gen
;
160 handle
.ha_fid
.xfs_fid_ino
= ip
->i_ino
;
162 xfs_iunlock_map_shared(ip
, lock_mode
);
164 hsize
= XFS_HSIZE(handle
);
167 /* now copy our handle into the user buffer & write out the size */
168 if (copy_to_user(hreq
.ohandle
, &handle
, hsize
) ||
169 copy_to_user(hreq
.ohandlen
, &hsize
, sizeof(__s32
))) {
171 return -XFS_ERROR(EFAULT
);
180 * Convert userspace handle data into vnode (and inode).
181 * We [ab]use the fact that all the fsop_handlereq ioctl calls
182 * have a data structure argument whose first component is always
183 * a xfs_fsop_handlereq_t, so we can cast to and from this type.
184 * This allows us to optimise the copy_from_user calls and gives
185 * a handy, shared routine.
187 * If no error, caller must always VN_RELE the returned vp.
190 xfs_vget_fsop_handlereq(
192 struct inode
*parinode
, /* parent inode pointer */
193 xfs_fsop_handlereq_t
*hreq
,
195 struct inode
**inode
)
200 xfs_handle_t
*handlep
;
203 struct inode
*inodep
;
210 * Only allow handle opens under a directory.
212 if (!S_ISDIR(parinode
->i_mode
))
213 return XFS_ERROR(ENOTDIR
);
215 hanp
= hreq
->ihandle
;
216 hlen
= hreq
->ihandlen
;
219 if (hlen
< sizeof(handlep
->ha_fsid
) || hlen
> sizeof(*handlep
))
220 return XFS_ERROR(EINVAL
);
221 if (copy_from_user(handlep
, hanp
, hlen
))
222 return XFS_ERROR(EFAULT
);
223 if (hlen
< sizeof(*handlep
))
224 memset(((char *)handlep
) + hlen
, 0, sizeof(*handlep
) - hlen
);
225 if (hlen
> sizeof(handlep
->ha_fsid
)) {
226 if (handlep
->ha_fid
.xfs_fid_len
!=
227 (hlen
- sizeof(handlep
->ha_fsid
)
228 - sizeof(handlep
->ha_fid
.xfs_fid_len
))
229 || handlep
->ha_fid
.xfs_fid_pad
)
230 return XFS_ERROR(EINVAL
);
234 * Crack the handle, obtain the inode # & generation #
236 xfid
= (struct xfs_fid
*)&handlep
->ha_fid
;
237 if (xfid
->xfs_fid_len
== sizeof(*xfid
) - sizeof(xfid
->xfs_fid_len
)) {
238 ino
= xfid
->xfs_fid_ino
;
239 igen
= xfid
->xfs_fid_gen
;
241 return XFS_ERROR(EINVAL
);
245 * Get the XFS inode, building a vnode to go with it.
247 error
= xfs_iget(mp
, NULL
, ino
, 0, XFS_ILOCK_SHARED
, &ip
, 0);
251 return XFS_ERROR(EIO
);
252 if (ip
->i_d
.di_mode
== 0 || ip
->i_d
.di_gen
!= igen
) {
253 xfs_iput_new(ip
, XFS_ILOCK_SHARED
);
254 return XFS_ERROR(ENOENT
);
258 inodep
= LINVFS_GET_IP(vpp
);
259 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
270 struct file
*parfilp
,
271 struct inode
*parinode
)
278 struct dentry
*dentry
;
280 xfs_fsop_handlereq_t hreq
;
282 if (!capable(CAP_SYS_ADMIN
))
283 return -XFS_ERROR(EPERM
);
284 if (copy_from_user(&hreq
, arg
, sizeof(xfs_fsop_handlereq_t
)))
285 return -XFS_ERROR(EFAULT
);
287 error
= xfs_vget_fsop_handlereq(mp
, parinode
, &hreq
, &vp
, &inode
);
291 /* Restrict xfs_open_by_handle to directories & regular files. */
292 if (!(S_ISREG(inode
->i_mode
) || S_ISDIR(inode
->i_mode
))) {
294 return -XFS_ERROR(EINVAL
);
297 #if BITS_PER_LONG != 32
298 hreq
.oflags
|= O_LARGEFILE
;
300 /* Put open permission in namei format. */
301 permflag
= hreq
.oflags
;
302 if ((permflag
+1) & O_ACCMODE
)
304 if (permflag
& O_TRUNC
)
307 if ((!(permflag
& O_APPEND
) || (permflag
& O_TRUNC
)) &&
308 (permflag
& FMODE_WRITE
) && IS_APPEND(inode
)) {
310 return -XFS_ERROR(EPERM
);
313 if ((permflag
& FMODE_WRITE
) && IS_IMMUTABLE(inode
)) {
315 return -XFS_ERROR(EACCES
);
318 /* Can't write directories. */
319 if ( S_ISDIR(inode
->i_mode
) && (permflag
& FMODE_WRITE
)) {
321 return -XFS_ERROR(EISDIR
);
324 if ((new_fd
= get_unused_fd()) < 0) {
329 dentry
= d_alloc_anon(inode
);
330 if (dentry
== NULL
) {
332 put_unused_fd(new_fd
);
333 return -XFS_ERROR(ENOMEM
);
336 /* Ensure umount returns EBUSY on umounts while this file is open. */
337 mntget(parfilp
->f_vfsmnt
);
339 /* Create file pointer. */
340 filp
= dentry_open(dentry
, parfilp
->f_vfsmnt
, hreq
.oflags
);
342 put_unused_fd(new_fd
);
343 return -XFS_ERROR(-PTR_ERR(filp
));
345 if (inode
->i_mode
& S_IFREG
)
346 filp
->f_op
= &linvfs_invis_file_operations
;
348 fd_install(new_fd
, filp
);
353 xfs_readlink_by_handle(
356 struct file
*parfilp
,
357 struct inode
*parinode
)
363 xfs_fsop_handlereq_t hreq
;
367 if (!capable(CAP_SYS_ADMIN
))
368 return -XFS_ERROR(EPERM
);
369 if (copy_from_user(&hreq
, arg
, sizeof(xfs_fsop_handlereq_t
)))
370 return -XFS_ERROR(EFAULT
);
372 error
= xfs_vget_fsop_handlereq(mp
, parinode
, &hreq
, &vp
, &inode
);
376 /* Restrict this handle operation to symlinks only. */
377 if (!S_ISLNK(inode
->i_mode
)) {
379 return -XFS_ERROR(EINVAL
);
382 if (copy_from_user(&olen
, hreq
.ohandlen
, sizeof(__u32
))) {
384 return -XFS_ERROR(EFAULT
);
387 aiov
.iov_base
= hreq
.ohandle
;
389 auio
.uio_iov
= &aiov
;
392 auio
.uio_segflg
= UIO_USERSPACE
;
393 auio
.uio_resid
= olen
;
395 VOP_READLINK(vp
, &auio
, IO_INVIS
, NULL
, error
);
398 return (olen
- auio
.uio_resid
);
402 xfs_fssetdm_by_handle(
405 struct file
*parfilp
,
406 struct inode
*parinode
)
409 struct fsdmidata fsd
;
410 xfs_fsop_setdm_handlereq_t dmhreq
;
415 if (!capable(CAP_MKNOD
))
416 return -XFS_ERROR(EPERM
);
417 if (copy_from_user(&dmhreq
, arg
, sizeof(xfs_fsop_setdm_handlereq_t
)))
418 return -XFS_ERROR(EFAULT
);
420 error
= xfs_vget_fsop_handlereq(mp
, parinode
, &dmhreq
.hreq
, &vp
, &inode
);
424 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
)) {
426 return -XFS_ERROR(EPERM
);
429 if (copy_from_user(&fsd
, dmhreq
.data
, sizeof(fsd
))) {
431 return -XFS_ERROR(EFAULT
);
434 bdp
= bhv_base_unlocked(VN_BHV_HEAD(vp
));
435 error
= xfs_set_dmattrs(bdp
, fsd
.fsd_dmevmask
, fsd
.fsd_dmstate
, NULL
);
444 xfs_attrlist_by_handle(
447 struct file
*parfilp
,
448 struct inode
*parinode
)
451 attrlist_cursor_kern_t
*cursor
;
452 xfs_fsop_attrlist_handlereq_t al_hreq
;
457 if (!capable(CAP_SYS_ADMIN
))
458 return -XFS_ERROR(EPERM
);
459 if (copy_from_user(&al_hreq
, arg
, sizeof(xfs_fsop_attrlist_handlereq_t
)))
460 return -XFS_ERROR(EFAULT
);
461 if (al_hreq
.buflen
> XATTR_LIST_MAX
)
462 return -XFS_ERROR(EINVAL
);
464 error
= xfs_vget_fsop_handlereq(mp
, parinode
, &al_hreq
.hreq
,
469 kbuf
= kmalloc(al_hreq
.buflen
, GFP_KERNEL
);
473 cursor
= (attrlist_cursor_kern_t
*)&al_hreq
.pos
;
474 VOP_ATTR_LIST(vp
, kbuf
, al_hreq
.buflen
, al_hreq
.flags
,
475 cursor
, NULL
, error
);
479 if (copy_to_user(al_hreq
.buffer
, kbuf
, al_hreq
.buflen
))
491 xfs_attrmulti_attr_get(
501 if (*len
> XATTR_SIZE_MAX
)
503 kbuf
= kmalloc(*len
, GFP_KERNEL
);
507 VOP_ATTR_GET(vp
, name
, kbuf
, len
, flags
, NULL
, error
);
511 if (copy_to_user(ubuf
, kbuf
, *len
))
520 xfs_attrmulti_attr_set(
523 const char __user
*ubuf
,
530 if (IS_RDONLY(&vp
->v_inode
))
532 if (IS_IMMUTABLE(&vp
->v_inode
) || IS_APPEND(&vp
->v_inode
))
534 if (len
> XATTR_SIZE_MAX
)
537 kbuf
= kmalloc(len
, GFP_KERNEL
);
541 if (copy_from_user(kbuf
, ubuf
, len
))
544 VOP_ATTR_SET(vp
, name
, kbuf
, len
, flags
, NULL
, error
);
552 xfs_attrmulti_attr_remove(
560 if (IS_RDONLY(&vp
->v_inode
))
562 if (IS_IMMUTABLE(&vp
->v_inode
) || IS_APPEND(&vp
->v_inode
))
565 VOP_ATTR_REMOVE(vp
, name
, flags
, NULL
, error
);
570 xfs_attrmulti_by_handle(
573 struct file
*parfilp
,
574 struct inode
*parinode
)
577 xfs_attr_multiop_t
*ops
;
578 xfs_fsop_attrmulti_handlereq_t am_hreq
;
581 unsigned int i
, size
;
584 if (!capable(CAP_SYS_ADMIN
))
585 return -XFS_ERROR(EPERM
);
586 if (copy_from_user(&am_hreq
, arg
, sizeof(xfs_fsop_attrmulti_handlereq_t
)))
587 return -XFS_ERROR(EFAULT
);
589 error
= xfs_vget_fsop_handlereq(mp
, parinode
, &am_hreq
.hreq
, &vp
, &inode
);
594 size
= am_hreq
.opcount
* sizeof(attr_multiop_t
);
595 if (!size
|| size
> 16 * PAGE_SIZE
)
599 ops
= kmalloc(size
, GFP_KERNEL
);
604 if (copy_from_user(ops
, am_hreq
.ops
, size
))
607 attr_name
= kmalloc(MAXNAMELEN
, GFP_KERNEL
);
613 for (i
= 0; i
< am_hreq
.opcount
; i
++) {
614 ops
[i
].am_error
= strncpy_from_user(attr_name
,
615 ops
[i
].am_attrname
, MAXNAMELEN
);
616 if (ops
[i
].am_error
== 0 || ops
[i
].am_error
== MAXNAMELEN
)
618 if (ops
[i
].am_error
< 0)
621 switch (ops
[i
].am_opcode
) {
623 ops
[i
].am_error
= xfs_attrmulti_attr_get(vp
,
624 attr_name
, ops
[i
].am_attrvalue
,
625 &ops
[i
].am_length
, ops
[i
].am_flags
);
628 ops
[i
].am_error
= xfs_attrmulti_attr_set(vp
,
629 attr_name
, ops
[i
].am_attrvalue
,
630 ops
[i
].am_length
, ops
[i
].am_flags
);
633 ops
[i
].am_error
= xfs_attrmulti_attr_remove(vp
,
634 attr_name
, ops
[i
].am_flags
);
637 ops
[i
].am_error
= EINVAL
;
641 if (copy_to_user(am_hreq
.ops
, ops
, size
))
642 error
= XFS_ERROR(EFAULT
);
653 /* prototypes for a few of the stack-hungry cases that have
654 * their own functions. Functions are defined after their use
655 * so gcc doesn't get fancy and inline them with -03 */
673 xfs_ioc_fsgeometry_v1(
717 vp
= LINVFS_GET_VP(inode
);
719 vn_trace_entry(vp
, "xfs_ioctl", (inst_t
*)__return_address
);
721 ip
= XFS_BHVTOI(bdp
);
726 case XFS_IOC_ALLOCSP
:
729 case XFS_IOC_UNRESVSP
:
730 case XFS_IOC_ALLOCSP64
:
731 case XFS_IOC_FREESP64
:
732 case XFS_IOC_RESVSP64
:
733 case XFS_IOC_UNRESVSP64
:
735 * Only allow the sys admin to reserve space unless
736 * unwritten extents are enabled.
738 if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp
->m_sb
) &&
739 !capable(CAP_SYS_ADMIN
))
742 return xfs_ioc_space(bdp
, vp
, filp
, ioflags
, cmd
, arg
);
744 case XFS_IOC_DIOINFO
: {
746 xfs_buftarg_t
*target
=
747 (ip
->i_d
.di_flags
& XFS_DIFLAG_REALTIME
) ?
748 mp
->m_rtdev_targp
: mp
->m_ddev_targp
;
750 da
.d_mem
= da
.d_miniosz
= 1 << target
->bt_sshift
;
751 da
.d_maxiosz
= INT_MAX
& ~(da
.d_miniosz
- 1);
753 if (copy_to_user(arg
, &da
, sizeof(da
)))
754 return -XFS_ERROR(EFAULT
);
758 case XFS_IOC_FSBULKSTAT_SINGLE
:
759 case XFS_IOC_FSBULKSTAT
:
760 case XFS_IOC_FSINUMBERS
:
761 return xfs_ioc_bulkstat(mp
, cmd
, arg
);
763 case XFS_IOC_FSGEOMETRY_V1
:
764 return xfs_ioc_fsgeometry_v1(mp
, arg
);
766 case XFS_IOC_FSGEOMETRY
:
767 return xfs_ioc_fsgeometry(mp
, arg
);
769 case XFS_IOC_GETVERSION
:
770 case XFS_IOC_GETXFLAGS
:
771 case XFS_IOC_SETXFLAGS
:
772 case XFS_IOC_FSGETXATTR
:
773 case XFS_IOC_FSSETXATTR
:
774 case XFS_IOC_FSGETXATTRA
:
775 return xfs_ioc_xattr(vp
, ip
, filp
, cmd
, arg
);
777 case XFS_IOC_FSSETDM
: {
778 struct fsdmidata dmi
;
780 if (copy_from_user(&dmi
, arg
, sizeof(dmi
)))
781 return -XFS_ERROR(EFAULT
);
783 error
= xfs_set_dmattrs(bdp
, dmi
.fsd_dmevmask
, dmi
.fsd_dmstate
,
788 case XFS_IOC_GETBMAP
:
789 case XFS_IOC_GETBMAPA
:
790 return xfs_ioc_getbmap(bdp
, filp
, ioflags
, cmd
, arg
);
792 case XFS_IOC_GETBMAPX
:
793 return xfs_ioc_getbmapx(bdp
, arg
);
795 case XFS_IOC_FD_TO_HANDLE
:
796 case XFS_IOC_PATH_TO_HANDLE
:
797 case XFS_IOC_PATH_TO_FSHANDLE
:
798 return xfs_find_handle(cmd
, arg
);
800 case XFS_IOC_OPEN_BY_HANDLE
:
801 return xfs_open_by_handle(mp
, arg
, filp
, inode
);
803 case XFS_IOC_FSSETDM_BY_HANDLE
:
804 return xfs_fssetdm_by_handle(mp
, arg
, filp
, inode
);
806 case XFS_IOC_READLINK_BY_HANDLE
:
807 return xfs_readlink_by_handle(mp
, arg
, filp
, inode
);
809 case XFS_IOC_ATTRLIST_BY_HANDLE
:
810 return xfs_attrlist_by_handle(mp
, arg
, filp
, inode
);
812 case XFS_IOC_ATTRMULTI_BY_HANDLE
:
813 return xfs_attrmulti_by_handle(mp
, arg
, filp
, inode
);
815 case XFS_IOC_SWAPEXT
: {
816 error
= xfs_swapext((struct xfs_swapext __user
*)arg
);
820 case XFS_IOC_FSCOUNTS
: {
821 xfs_fsop_counts_t out
;
823 error
= xfs_fs_counts(mp
, &out
);
827 if (copy_to_user(arg
, &out
, sizeof(out
)))
828 return -XFS_ERROR(EFAULT
);
832 case XFS_IOC_SET_RESBLKS
: {
833 xfs_fsop_resblks_t inout
;
836 if (!capable(CAP_SYS_ADMIN
))
839 if (copy_from_user(&inout
, arg
, sizeof(inout
)))
840 return -XFS_ERROR(EFAULT
);
842 /* input parameter is passed in resblks field of structure */
844 error
= xfs_reserve_blocks(mp
, &in
, &inout
);
848 if (copy_to_user(arg
, &inout
, sizeof(inout
)))
849 return -XFS_ERROR(EFAULT
);
853 case XFS_IOC_GET_RESBLKS
: {
854 xfs_fsop_resblks_t out
;
856 if (!capable(CAP_SYS_ADMIN
))
859 error
= xfs_reserve_blocks(mp
, NULL
, &out
);
863 if (copy_to_user(arg
, &out
, sizeof(out
)))
864 return -XFS_ERROR(EFAULT
);
869 case XFS_IOC_FSGROWFSDATA
: {
870 xfs_growfs_data_t in
;
872 if (!capable(CAP_SYS_ADMIN
))
875 if (copy_from_user(&in
, arg
, sizeof(in
)))
876 return -XFS_ERROR(EFAULT
);
878 error
= xfs_growfs_data(mp
, &in
);
882 case XFS_IOC_FSGROWFSLOG
: {
885 if (!capable(CAP_SYS_ADMIN
))
888 if (copy_from_user(&in
, arg
, sizeof(in
)))
889 return -XFS_ERROR(EFAULT
);
891 error
= xfs_growfs_log(mp
, &in
);
895 case XFS_IOC_FSGROWFSRT
: {
898 if (!capable(CAP_SYS_ADMIN
))
901 if (copy_from_user(&in
, arg
, sizeof(in
)))
902 return -XFS_ERROR(EFAULT
);
904 error
= xfs_growfs_rt(mp
, &in
);
909 if (!capable(CAP_SYS_ADMIN
))
912 if (inode
->i_sb
->s_frozen
== SB_UNFROZEN
)
913 freeze_bdev(inode
->i_sb
->s_bdev
);
917 if (!capable(CAP_SYS_ADMIN
))
919 if (inode
->i_sb
->s_frozen
!= SB_UNFROZEN
)
920 thaw_bdev(inode
->i_sb
->s_bdev
, inode
->i_sb
);
923 case XFS_IOC_GOINGDOWN
: {
926 if (!capable(CAP_SYS_ADMIN
))
929 if (get_user(in
, (__uint32_t __user
*)arg
))
930 return -XFS_ERROR(EFAULT
);
932 error
= xfs_fs_goingdown(mp
, in
);
936 case XFS_IOC_ERROR_INJECTION
: {
937 xfs_error_injection_t in
;
939 if (!capable(CAP_SYS_ADMIN
))
942 if (copy_from_user(&in
, arg
, sizeof(in
)))
943 return -XFS_ERROR(EFAULT
);
945 error
= xfs_errortag_add(in
.errtag
, mp
);
949 case XFS_IOC_ERROR_CLEARALL
:
950 if (!capable(CAP_SYS_ADMIN
))
953 error
= xfs_errortag_clearall(mp
);
974 if (vp
->v_inode
.i_flags
& (S_IMMUTABLE
|S_APPEND
))
975 return -XFS_ERROR(EPERM
);
977 if (!(filp
->f_mode
& FMODE_WRITE
))
978 return -XFS_ERROR(EBADF
);
981 return -XFS_ERROR(EINVAL
);
983 if (copy_from_user(&bf
, arg
, sizeof(bf
)))
984 return -XFS_ERROR(EFAULT
);
986 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
987 attr_flags
|= ATTR_NONBLOCK
;
988 if (ioflags
& IO_INVIS
)
989 attr_flags
|= ATTR_DMI
;
991 error
= xfs_change_file_space(bdp
, cmd
, &bf
, filp
->f_pos
,
1002 xfs_fsop_bulkreq_t bulkreq
;
1003 int count
; /* # of records returned */
1004 xfs_ino_t inlast
; /* last inode number */
1008 /* done = 1 if there are more stats to get and if bulkstat */
1009 /* should be called again (unused here, but used in dmapi) */
1011 if (!capable(CAP_SYS_ADMIN
))
1014 if (XFS_FORCED_SHUTDOWN(mp
))
1015 return -XFS_ERROR(EIO
);
1017 if (copy_from_user(&bulkreq
, arg
, sizeof(xfs_fsop_bulkreq_t
)))
1018 return -XFS_ERROR(EFAULT
);
1020 if (copy_from_user(&inlast
, bulkreq
.lastip
, sizeof(__s64
)))
1021 return -XFS_ERROR(EFAULT
);
1023 if ((count
= bulkreq
.icount
) <= 0)
1024 return -XFS_ERROR(EINVAL
);
1026 if (cmd
== XFS_IOC_FSINUMBERS
)
1027 error
= xfs_inumbers(mp
, &inlast
, &count
,
1029 else if (cmd
== XFS_IOC_FSBULKSTAT_SINGLE
)
1030 error
= xfs_bulkstat_single(mp
, &inlast
,
1031 bulkreq
.ubuffer
, &done
);
1032 else { /* XFS_IOC_FSBULKSTAT */
1033 if (count
== 1 && inlast
!= 0) {
1035 error
= xfs_bulkstat_single(mp
, &inlast
,
1036 bulkreq
.ubuffer
, &done
);
1038 error
= xfs_bulkstat(mp
, &inlast
, &count
,
1039 (bulkstat_one_pf
)xfs_bulkstat_one
, NULL
,
1040 sizeof(xfs_bstat_t
), bulkreq
.ubuffer
,
1041 BULKSTAT_FG_QUICK
, &done
);
1048 if (bulkreq
.ocount
!= NULL
) {
1049 if (copy_to_user(bulkreq
.lastip
, &inlast
,
1051 return -XFS_ERROR(EFAULT
);
1053 if (copy_to_user(bulkreq
.ocount
, &count
, sizeof(count
)))
1054 return -XFS_ERROR(EFAULT
);
1061 xfs_ioc_fsgeometry_v1(
1065 xfs_fsop_geom_v1_t fsgeo
;
1068 error
= xfs_fs_geometry(mp
, (xfs_fsop_geom_t
*)&fsgeo
, 3);
1072 if (copy_to_user(arg
, &fsgeo
, sizeof(fsgeo
)))
1073 return -XFS_ERROR(EFAULT
);
1082 xfs_fsop_geom_t fsgeo
;
1085 error
= xfs_fs_geometry(mp
, &fsgeo
, 4);
1089 if (copy_to_user(arg
, &fsgeo
, sizeof(fsgeo
)))
1090 return -XFS_ERROR(EFAULT
);
1095 * Linux extended inode flags interface.
1097 #define LINUX_XFLAG_SYNC 0x00000008 /* Synchronous updates */
1098 #define LINUX_XFLAG_IMMUTABLE 0x00000010 /* Immutable file */
1099 #define LINUX_XFLAG_APPEND 0x00000020 /* writes to file may only append */
1100 #define LINUX_XFLAG_NODUMP 0x00000040 /* do not dump file */
1101 #define LINUX_XFLAG_NOATIME 0x00000080 /* do not update atime */
1104 xfs_merge_ioc_xflags(
1108 unsigned int xflags
= start
;
1110 if (flags
& LINUX_XFLAG_IMMUTABLE
)
1111 xflags
|= XFS_XFLAG_IMMUTABLE
;
1113 xflags
&= ~XFS_XFLAG_IMMUTABLE
;
1114 if (flags
& LINUX_XFLAG_APPEND
)
1115 xflags
|= XFS_XFLAG_APPEND
;
1117 xflags
&= ~XFS_XFLAG_APPEND
;
1118 if (flags
& LINUX_XFLAG_SYNC
)
1119 xflags
|= XFS_XFLAG_SYNC
;
1121 xflags
&= ~XFS_XFLAG_SYNC
;
1122 if (flags
& LINUX_XFLAG_NOATIME
)
1123 xflags
|= XFS_XFLAG_NOATIME
;
1125 xflags
&= ~XFS_XFLAG_NOATIME
;
1126 if (flags
& LINUX_XFLAG_NODUMP
)
1127 xflags
|= XFS_XFLAG_NODUMP
;
1129 xflags
&= ~XFS_XFLAG_NODUMP
;
1136 __uint16_t di_flags
)
1138 unsigned int flags
= 0;
1140 if (di_flags
& XFS_DIFLAG_IMMUTABLE
)
1141 flags
|= LINUX_XFLAG_IMMUTABLE
;
1142 if (di_flags
& XFS_DIFLAG_APPEND
)
1143 flags
|= LINUX_XFLAG_APPEND
;
1144 if (di_flags
& XFS_DIFLAG_SYNC
)
1145 flags
|= LINUX_XFLAG_SYNC
;
1146 if (di_flags
& XFS_DIFLAG_NOATIME
)
1147 flags
|= LINUX_XFLAG_NOATIME
;
1148 if (di_flags
& XFS_DIFLAG_NODUMP
)
1149 flags
|= LINUX_XFLAG_NODUMP
;
1168 case XFS_IOC_FSGETXATTR
: {
1169 va
.va_mask
= XFS_AT_XFLAGS
| XFS_AT_EXTSIZE
| \
1170 XFS_AT_NEXTENTS
| XFS_AT_PROJID
;
1171 VOP_GETATTR(vp
, &va
, 0, NULL
, error
);
1175 fa
.fsx_xflags
= va
.va_xflags
;
1176 fa
.fsx_extsize
= va
.va_extsize
;
1177 fa
.fsx_nextents
= va
.va_nextents
;
1178 fa
.fsx_projid
= va
.va_projid
;
1180 if (copy_to_user(arg
, &fa
, sizeof(fa
)))
1181 return -XFS_ERROR(EFAULT
);
1185 case XFS_IOC_FSSETXATTR
: {
1186 if (copy_from_user(&fa
, arg
, sizeof(fa
)))
1187 return -XFS_ERROR(EFAULT
);
1190 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1191 attr_flags
|= ATTR_NONBLOCK
;
1193 va
.va_mask
= XFS_AT_XFLAGS
| XFS_AT_EXTSIZE
| XFS_AT_PROJID
;
1194 va
.va_xflags
= fa
.fsx_xflags
;
1195 va
.va_extsize
= fa
.fsx_extsize
;
1196 va
.va_projid
= fa
.fsx_projid
;
1198 VOP_SETATTR(vp
, &va
, attr_flags
, NULL
, error
);
1200 vn_revalidate(vp
); /* update Linux inode flags */
1204 case XFS_IOC_FSGETXATTRA
: {
1205 va
.va_mask
= XFS_AT_XFLAGS
| XFS_AT_EXTSIZE
| \
1206 XFS_AT_ANEXTENTS
| XFS_AT_PROJID
;
1207 VOP_GETATTR(vp
, &va
, 0, NULL
, error
);
1211 fa
.fsx_xflags
= va
.va_xflags
;
1212 fa
.fsx_extsize
= va
.va_extsize
;
1213 fa
.fsx_nextents
= va
.va_anextents
;
1214 fa
.fsx_projid
= va
.va_projid
;
1216 if (copy_to_user(arg
, &fa
, sizeof(fa
)))
1217 return -XFS_ERROR(EFAULT
);
1221 case XFS_IOC_GETXFLAGS
: {
1222 flags
= xfs_di2lxflags(ip
->i_d
.di_flags
);
1223 if (copy_to_user(arg
, &flags
, sizeof(flags
)))
1224 return -XFS_ERROR(EFAULT
);
1228 case XFS_IOC_SETXFLAGS
: {
1229 if (copy_from_user(&flags
, arg
, sizeof(flags
)))
1230 return -XFS_ERROR(EFAULT
);
1232 if (flags
& ~(LINUX_XFLAG_IMMUTABLE
| LINUX_XFLAG_APPEND
| \
1233 LINUX_XFLAG_NOATIME
| LINUX_XFLAG_NODUMP
| \
1235 return -XFS_ERROR(EOPNOTSUPP
);
1238 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1239 attr_flags
|= ATTR_NONBLOCK
;
1241 va
.va_mask
= XFS_AT_XFLAGS
;
1242 va
.va_xflags
= xfs_merge_ioc_xflags(flags
,
1245 VOP_SETATTR(vp
, &va
, attr_flags
, NULL
, error
);
1247 vn_revalidate(vp
); /* update Linux inode flags */
1251 case XFS_IOC_GETVERSION
: {
1252 flags
= LINVFS_GET_IP(vp
)->i_generation
;
1253 if (copy_to_user(arg
, &flags
, sizeof(flags
)))
1254 return -XFS_ERROR(EFAULT
);
1275 if (copy_from_user(&bm
, arg
, sizeof(bm
)))
1276 return -XFS_ERROR(EFAULT
);
1278 if (bm
.bmv_count
< 2)
1279 return -XFS_ERROR(EINVAL
);
1281 iflags
= (cmd
== XFS_IOC_GETBMAPA
? BMV_IF_ATTRFORK
: 0);
1282 if (ioflags
& IO_INVIS
)
1283 iflags
|= BMV_IF_NO_DMAPI_READ
;
1285 error
= xfs_getbmap(bdp
, &bm
, (struct getbmap __user
*)arg
+1, iflags
);
1289 if (copy_to_user(arg
, &bm
, sizeof(bm
)))
1290 return -XFS_ERROR(EFAULT
);
1299 struct getbmapx bmx
;
1304 if (copy_from_user(&bmx
, arg
, sizeof(bmx
)))
1305 return -XFS_ERROR(EFAULT
);
1307 if (bmx
.bmv_count
< 2)
1308 return -XFS_ERROR(EINVAL
);
1311 * Map input getbmapx structure to a getbmap
1312 * structure for xfs_getbmap.
1314 GETBMAP_CONVERT(bmx
, bm
);
1316 iflags
= bmx
.bmv_iflags
;
1318 if (iflags
& (~BMV_IF_VALID
))
1319 return -XFS_ERROR(EINVAL
);
1321 iflags
|= BMV_IF_EXTENDED
;
1323 error
= xfs_getbmap(bdp
, &bm
, (struct getbmapx __user
*)arg
+1, iflags
);
1327 GETBMAP_CONVERT(bm
, bmx
);
1329 if (copy_to_user(arg
, &bmx
, sizeof(bmx
)))
1330 return -XFS_ERROR(EFAULT
);