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"
50 #include "xfs_vnodeops.h"
52 #include <linux/capability.h>
53 #include <linux/dcache.h>
54 #include <linux/mount.h>
55 #include <linux/namei.h>
56 #include <linux/pagemap.h>
59 * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to
60 * a file or fs handle.
62 * XFS_IOC_PATH_TO_FSHANDLE
63 * returns fs handle for a mount point or path within that mount point
64 * XFS_IOC_FD_TO_HANDLE
65 * returns full handle for a FD opened in user space
66 * XFS_IOC_PATH_TO_HANDLE
67 * returns full handle for a path
76 xfs_fsop_handlereq_t hreq
;
80 if (copy_from_user(&hreq
, arg
, sizeof(hreq
)))
81 return -XFS_ERROR(EFAULT
);
83 memset((char *)&handle
, 0, sizeof(handle
));
86 case XFS_IOC_PATH_TO_FSHANDLE
:
87 case XFS_IOC_PATH_TO_HANDLE
: {
91 error
= user_path_walk_link((const char __user
*)hreq
.path
, &nd
);
96 ASSERT(nd
.dentry
->d_inode
);
97 inode
= igrab(nd
.dentry
->d_inode
);
102 case XFS_IOC_FD_TO_HANDLE
: {
105 file
= fget(hreq
.fd
);
109 ASSERT(file
->f_path
.dentry
);
110 ASSERT(file
->f_path
.dentry
->d_inode
);
111 inode
= igrab(file
->f_path
.dentry
->d_inode
);
118 return -XFS_ERROR(EINVAL
);
121 if (inode
->i_sb
->s_magic
!= XFS_SB_MAGIC
) {
122 /* we're not in XFS anymore, Toto */
124 return -XFS_ERROR(EINVAL
);
127 switch (inode
->i_mode
& S_IFMT
) {
134 return -XFS_ERROR(EBADF
);
137 /* we need the vnode */
138 vp
= vn_from_inode(inode
);
140 /* now we can grab the fsid */
141 memcpy(&handle
.ha_fsid
, vp
->v_vfsp
->vfs_altfsid
, sizeof(xfs_fsid_t
));
142 hsize
= sizeof(xfs_fsid_t
);
144 if (cmd
!= XFS_IOC_PATH_TO_FSHANDLE
) {
148 /* need to get access to the xfs_inode to read the generation */
151 lock_mode
= xfs_ilock_map_shared(ip
);
153 /* fill in fid section of handle from inode */
154 handle
.ha_fid
.xfs_fid_len
= sizeof(xfs_fid_t
) -
155 sizeof(handle
.ha_fid
.xfs_fid_len
);
156 handle
.ha_fid
.xfs_fid_pad
= 0;
157 handle
.ha_fid
.xfs_fid_gen
= ip
->i_d
.di_gen
;
158 handle
.ha_fid
.xfs_fid_ino
= ip
->i_ino
;
160 xfs_iunlock_map_shared(ip
, lock_mode
);
162 hsize
= XFS_HSIZE(handle
);
165 /* now copy our handle into the user buffer & write out the size */
166 if (copy_to_user(hreq
.ohandle
, &handle
, hsize
) ||
167 copy_to_user(hreq
.ohandlen
, &hsize
, sizeof(__s32
))) {
169 return -XFS_ERROR(EFAULT
);
178 * Convert userspace handle data into vnode (and inode).
179 * We [ab]use the fact that all the fsop_handlereq ioctl calls
180 * have a data structure argument whose first component is always
181 * a xfs_fsop_handlereq_t, so we can cast to and from this type.
182 * This allows us to optimise the copy_from_user calls and gives
183 * a handy, shared routine.
185 * If no error, caller must always VN_RELE the returned vp.
188 xfs_vget_fsop_handlereq(
190 struct inode
*parinode
, /* parent inode pointer */
191 xfs_fsop_handlereq_t
*hreq
,
193 struct inode
**inode
)
198 xfs_handle_t
*handlep
;
201 struct inode
*inodep
;
208 * Only allow handle opens under a directory.
210 if (!S_ISDIR(parinode
->i_mode
))
211 return XFS_ERROR(ENOTDIR
);
213 hanp
= hreq
->ihandle
;
214 hlen
= hreq
->ihandlen
;
217 if (hlen
< sizeof(handlep
->ha_fsid
) || hlen
> sizeof(*handlep
))
218 return XFS_ERROR(EINVAL
);
219 if (copy_from_user(handlep
, hanp
, hlen
))
220 return XFS_ERROR(EFAULT
);
221 if (hlen
< sizeof(*handlep
))
222 memset(((char *)handlep
) + hlen
, 0, sizeof(*handlep
) - hlen
);
223 if (hlen
> sizeof(handlep
->ha_fsid
)) {
224 if (handlep
->ha_fid
.xfs_fid_len
!=
225 (hlen
- sizeof(handlep
->ha_fsid
)
226 - sizeof(handlep
->ha_fid
.xfs_fid_len
))
227 || handlep
->ha_fid
.xfs_fid_pad
)
228 return XFS_ERROR(EINVAL
);
232 * Crack the handle, obtain the inode # & generation #
234 xfid
= (struct xfs_fid
*)&handlep
->ha_fid
;
235 if (xfid
->xfs_fid_len
== sizeof(*xfid
) - sizeof(xfid
->xfs_fid_len
)) {
236 ino
= xfid
->xfs_fid_ino
;
237 igen
= xfid
->xfs_fid_gen
;
239 return XFS_ERROR(EINVAL
);
243 * Get the XFS inode, building a vnode to go with it.
245 error
= xfs_iget(mp
, NULL
, ino
, 0, XFS_ILOCK_SHARED
, &ip
, 0);
249 return XFS_ERROR(EIO
);
250 if (ip
->i_d
.di_mode
== 0 || ip
->i_d
.di_gen
!= igen
) {
251 xfs_iput_new(ip
, XFS_ILOCK_SHARED
);
252 return XFS_ERROR(ENOENT
);
256 inodep
= vn_to_inode(vpp
);
257 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
268 struct file
*parfilp
,
269 struct inode
*parinode
)
276 struct dentry
*dentry
;
278 xfs_fsop_handlereq_t hreq
;
280 if (!capable(CAP_SYS_ADMIN
))
281 return -XFS_ERROR(EPERM
);
282 if (copy_from_user(&hreq
, arg
, sizeof(xfs_fsop_handlereq_t
)))
283 return -XFS_ERROR(EFAULT
);
285 error
= xfs_vget_fsop_handlereq(mp
, parinode
, &hreq
, &vp
, &inode
);
289 /* Restrict xfs_open_by_handle to directories & regular files. */
290 if (!(S_ISREG(inode
->i_mode
) || S_ISDIR(inode
->i_mode
))) {
292 return -XFS_ERROR(EINVAL
);
295 #if BITS_PER_LONG != 32
296 hreq
.oflags
|= O_LARGEFILE
;
298 /* Put open permission in namei format. */
299 permflag
= hreq
.oflags
;
300 if ((permflag
+1) & O_ACCMODE
)
302 if (permflag
& O_TRUNC
)
305 if ((!(permflag
& O_APPEND
) || (permflag
& O_TRUNC
)) &&
306 (permflag
& FMODE_WRITE
) && IS_APPEND(inode
)) {
308 return -XFS_ERROR(EPERM
);
311 if ((permflag
& FMODE_WRITE
) && IS_IMMUTABLE(inode
)) {
313 return -XFS_ERROR(EACCES
);
316 /* Can't write directories. */
317 if ( S_ISDIR(inode
->i_mode
) && (permflag
& FMODE_WRITE
)) {
319 return -XFS_ERROR(EISDIR
);
322 if ((new_fd
= get_unused_fd()) < 0) {
327 dentry
= d_alloc_anon(inode
);
328 if (dentry
== NULL
) {
330 put_unused_fd(new_fd
);
331 return -XFS_ERROR(ENOMEM
);
334 /* Ensure umount returns EBUSY on umounts while this file is open. */
335 mntget(parfilp
->f_path
.mnt
);
337 /* Create file pointer. */
338 filp
= dentry_open(dentry
, parfilp
->f_path
.mnt
, hreq
.oflags
);
340 put_unused_fd(new_fd
);
341 return -XFS_ERROR(-PTR_ERR(filp
));
343 if (inode
->i_mode
& S_IFREG
) {
344 /* invisible operation should not change atime */
345 filp
->f_flags
|= O_NOATIME
;
346 filp
->f_op
= &xfs_invis_file_operations
;
349 fd_install(new_fd
, filp
);
354 * This is a copy from fs/namei.c:vfs_readlink(), except for removing it's
355 * unused first argument.
370 if (len
> (unsigned) buflen
)
372 if (copy_to_user(buffer
, link
, len
))
380 xfs_readlink_by_handle(
383 struct inode
*parinode
)
386 xfs_fsop_handlereq_t hreq
;
392 if (!capable(CAP_SYS_ADMIN
))
393 return -XFS_ERROR(EPERM
);
394 if (copy_from_user(&hreq
, arg
, sizeof(xfs_fsop_handlereq_t
)))
395 return -XFS_ERROR(EFAULT
);
397 error
= xfs_vget_fsop_handlereq(mp
, parinode
, &hreq
, &vp
, &inode
);
401 /* Restrict this handle operation to symlinks only. */
402 if (!S_ISLNK(inode
->i_mode
)) {
403 error
= -XFS_ERROR(EINVAL
);
407 if (copy_from_user(&olen
, hreq
.ohandlen
, sizeof(__u32
))) {
408 error
= -XFS_ERROR(EFAULT
);
412 link
= kmalloc(MAXPATHLEN
+1, GFP_KERNEL
);
416 error
= -xfs_readlink(XFS_I(inode
), link
);
419 error
= do_readlink(hreq
.ohandle
, olen
, link
);
431 xfs_fssetdm_by_handle(
434 struct inode
*parinode
)
437 struct fsdmidata fsd
;
438 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 error
= xfs_set_dmattrs(xfs_vtoi(vp
),
462 fsd
.fsd_dmevmask
, fsd
.fsd_dmstate
);
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
= xfs_attr_list(XFS_I(inode
), kbuf
, al_hreq
.buflen
,
501 al_hreq
.flags
, cursor
);
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
= xfs_attr_get(XFS_I(inode
), 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(inode
))
558 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
560 if (len
> XATTR_SIZE_MAX
)
563 kbuf
= kmalloc(len
, GFP_KERNEL
);
567 if (copy_from_user(kbuf
, ubuf
, len
))
570 error
= xfs_attr_set(XFS_I(inode
), name
, kbuf
, len
, flags
);
578 xfs_attrmulti_attr_remove(
583 if (IS_RDONLY(inode
))
585 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
587 return xfs_attr_remove(XFS_I(inode
), name
, flags
);
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(inode
,
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(inode
,
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(inode
,
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 */
679 struct xfs_inode
*ip
,
693 xfs_ioc_fsgeometry_v1(
712 struct xfs_inode
*ip
,
719 struct xfs_inode
*ip
,
730 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
731 bhv_vnode_t
*vp
= vn_from_inode(inode
);
732 xfs_mount_t
*mp
= ip
->i_mount
;
735 vn_trace_entry(vp
, "xfs_ioctl", (inst_t
*)__return_address
);
739 case XFS_IOC_ALLOCSP
:
742 case XFS_IOC_UNRESVSP
:
743 case XFS_IOC_ALLOCSP64
:
744 case XFS_IOC_FREESP64
:
745 case XFS_IOC_RESVSP64
:
746 case XFS_IOC_UNRESVSP64
:
748 * Only allow the sys admin to reserve space unless
749 * unwritten extents are enabled.
751 if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp
->m_sb
) &&
752 !capable(CAP_SYS_ADMIN
))
755 return xfs_ioc_space(ip
, inode
, filp
, ioflags
, cmd
, arg
);
757 case XFS_IOC_DIOINFO
: {
759 xfs_buftarg_t
*target
=
760 (ip
->i_d
.di_flags
& XFS_DIFLAG_REALTIME
) ?
761 mp
->m_rtdev_targp
: mp
->m_ddev_targp
;
763 da
.d_mem
= da
.d_miniosz
= 1 << target
->bt_sshift
;
764 da
.d_maxiosz
= INT_MAX
& ~(da
.d_miniosz
- 1);
766 if (copy_to_user(arg
, &da
, sizeof(da
)))
767 return -XFS_ERROR(EFAULT
);
771 case XFS_IOC_FSBULKSTAT_SINGLE
:
772 case XFS_IOC_FSBULKSTAT
:
773 case XFS_IOC_FSINUMBERS
:
774 return xfs_ioc_bulkstat(mp
, cmd
, arg
);
776 case XFS_IOC_FSGEOMETRY_V1
:
777 return xfs_ioc_fsgeometry_v1(mp
, arg
);
779 case XFS_IOC_FSGEOMETRY
:
780 return xfs_ioc_fsgeometry(mp
, arg
);
782 case XFS_IOC_GETVERSION
:
783 return put_user(inode
->i_generation
, (int __user
*)arg
);
785 case XFS_IOC_GETXFLAGS
:
786 case XFS_IOC_SETXFLAGS
:
787 case XFS_IOC_FSGETXATTR
:
788 case XFS_IOC_FSSETXATTR
:
789 case XFS_IOC_FSGETXATTRA
:
790 return xfs_ioc_xattr(vp
, ip
, filp
, cmd
, arg
);
792 case XFS_IOC_FSSETDM
: {
793 struct fsdmidata dmi
;
795 if (copy_from_user(&dmi
, arg
, sizeof(dmi
)))
796 return -XFS_ERROR(EFAULT
);
798 error
= xfs_set_dmattrs(ip
, dmi
.fsd_dmevmask
,
803 case XFS_IOC_GETBMAP
:
804 case XFS_IOC_GETBMAPA
:
805 return xfs_ioc_getbmap(ip
, ioflags
, cmd
, arg
);
807 case XFS_IOC_GETBMAPX
:
808 return xfs_ioc_getbmapx(ip
, arg
);
810 case XFS_IOC_FD_TO_HANDLE
:
811 case XFS_IOC_PATH_TO_HANDLE
:
812 case XFS_IOC_PATH_TO_FSHANDLE
:
813 return xfs_find_handle(cmd
, arg
);
815 case XFS_IOC_OPEN_BY_HANDLE
:
816 return xfs_open_by_handle(mp
, arg
, filp
, inode
);
818 case XFS_IOC_FSSETDM_BY_HANDLE
:
819 return xfs_fssetdm_by_handle(mp
, arg
, inode
);
821 case XFS_IOC_READLINK_BY_HANDLE
:
822 return xfs_readlink_by_handle(mp
, arg
, inode
);
824 case XFS_IOC_ATTRLIST_BY_HANDLE
:
825 return xfs_attrlist_by_handle(mp
, arg
, inode
);
827 case XFS_IOC_ATTRMULTI_BY_HANDLE
:
828 return xfs_attrmulti_by_handle(mp
, arg
, inode
);
830 case XFS_IOC_SWAPEXT
: {
831 error
= xfs_swapext((struct xfs_swapext __user
*)arg
);
835 case XFS_IOC_FSCOUNTS
: {
836 xfs_fsop_counts_t out
;
838 error
= xfs_fs_counts(mp
, &out
);
842 if (copy_to_user(arg
, &out
, sizeof(out
)))
843 return -XFS_ERROR(EFAULT
);
847 case XFS_IOC_SET_RESBLKS
: {
848 xfs_fsop_resblks_t inout
;
851 if (!capable(CAP_SYS_ADMIN
))
854 if (copy_from_user(&inout
, arg
, sizeof(inout
)))
855 return -XFS_ERROR(EFAULT
);
857 /* input parameter is passed in resblks field of structure */
859 error
= xfs_reserve_blocks(mp
, &in
, &inout
);
863 if (copy_to_user(arg
, &inout
, sizeof(inout
)))
864 return -XFS_ERROR(EFAULT
);
868 case XFS_IOC_GET_RESBLKS
: {
869 xfs_fsop_resblks_t out
;
871 if (!capable(CAP_SYS_ADMIN
))
874 error
= xfs_reserve_blocks(mp
, NULL
, &out
);
878 if (copy_to_user(arg
, &out
, sizeof(out
)))
879 return -XFS_ERROR(EFAULT
);
884 case XFS_IOC_FSGROWFSDATA
: {
885 xfs_growfs_data_t in
;
887 if (!capable(CAP_SYS_ADMIN
))
890 if (copy_from_user(&in
, arg
, sizeof(in
)))
891 return -XFS_ERROR(EFAULT
);
893 error
= xfs_growfs_data(mp
, &in
);
897 case XFS_IOC_FSGROWFSLOG
: {
900 if (!capable(CAP_SYS_ADMIN
))
903 if (copy_from_user(&in
, arg
, sizeof(in
)))
904 return -XFS_ERROR(EFAULT
);
906 error
= xfs_growfs_log(mp
, &in
);
910 case XFS_IOC_FSGROWFSRT
: {
913 if (!capable(CAP_SYS_ADMIN
))
916 if (copy_from_user(&in
, arg
, sizeof(in
)))
917 return -XFS_ERROR(EFAULT
);
919 error
= xfs_growfs_rt(mp
, &in
);
924 if (!capable(CAP_SYS_ADMIN
))
927 if (inode
->i_sb
->s_frozen
== SB_UNFROZEN
)
928 freeze_bdev(inode
->i_sb
->s_bdev
);
932 if (!capable(CAP_SYS_ADMIN
))
934 if (inode
->i_sb
->s_frozen
!= SB_UNFROZEN
)
935 thaw_bdev(inode
->i_sb
->s_bdev
, inode
->i_sb
);
938 case XFS_IOC_GOINGDOWN
: {
941 if (!capable(CAP_SYS_ADMIN
))
944 if (get_user(in
, (__uint32_t __user
*)arg
))
945 return -XFS_ERROR(EFAULT
);
947 error
= xfs_fs_goingdown(mp
, in
);
951 case XFS_IOC_ERROR_INJECTION
: {
952 xfs_error_injection_t in
;
954 if (!capable(CAP_SYS_ADMIN
))
957 if (copy_from_user(&in
, arg
, sizeof(in
)))
958 return -XFS_ERROR(EFAULT
);
960 error
= xfs_errortag_add(in
.errtag
, mp
);
964 case XFS_IOC_ERROR_CLEARALL
:
965 if (!capable(CAP_SYS_ADMIN
))
968 error
= xfs_errortag_clearall(mp
);
978 struct xfs_inode
*ip
,
989 if (inode
->i_flags
& (S_IMMUTABLE
|S_APPEND
))
990 return -XFS_ERROR(EPERM
);
992 if (!(filp
->f_mode
& FMODE_WRITE
))
993 return -XFS_ERROR(EBADF
);
995 if (!S_ISREG(inode
->i_mode
))
996 return -XFS_ERROR(EINVAL
);
998 if (copy_from_user(&bf
, arg
, sizeof(bf
)))
999 return -XFS_ERROR(EFAULT
);
1001 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1002 attr_flags
|= ATTR_NONBLOCK
;
1003 if (ioflags
& IO_INVIS
)
1004 attr_flags
|= ATTR_DMI
;
1006 error
= xfs_change_file_space(ip
, cmd
, &bf
, filp
->f_pos
,
1017 xfs_fsop_bulkreq_t bulkreq
;
1018 int count
; /* # of records returned */
1019 xfs_ino_t inlast
; /* last inode number */
1023 /* done = 1 if there are more stats to get and if bulkstat */
1024 /* should be called again (unused here, but used in dmapi) */
1026 if (!capable(CAP_SYS_ADMIN
))
1029 if (XFS_FORCED_SHUTDOWN(mp
))
1030 return -XFS_ERROR(EIO
);
1032 if (copy_from_user(&bulkreq
, arg
, sizeof(xfs_fsop_bulkreq_t
)))
1033 return -XFS_ERROR(EFAULT
);
1035 if (copy_from_user(&inlast
, bulkreq
.lastip
, sizeof(__s64
)))
1036 return -XFS_ERROR(EFAULT
);
1038 if ((count
= bulkreq
.icount
) <= 0)
1039 return -XFS_ERROR(EINVAL
);
1041 if (cmd
== XFS_IOC_FSINUMBERS
)
1042 error
= xfs_inumbers(mp
, &inlast
, &count
,
1043 bulkreq
.ubuffer
, xfs_inumbers_fmt
);
1044 else if (cmd
== XFS_IOC_FSBULKSTAT_SINGLE
)
1045 error
= xfs_bulkstat_single(mp
, &inlast
,
1046 bulkreq
.ubuffer
, &done
);
1047 else { /* XFS_IOC_FSBULKSTAT */
1048 if (count
== 1 && inlast
!= 0) {
1050 error
= xfs_bulkstat_single(mp
, &inlast
,
1051 bulkreq
.ubuffer
, &done
);
1053 error
= xfs_bulkstat(mp
, &inlast
, &count
,
1054 (bulkstat_one_pf
)xfs_bulkstat_one
, NULL
,
1055 sizeof(xfs_bstat_t
), bulkreq
.ubuffer
,
1056 BULKSTAT_FG_QUICK
, &done
);
1063 if (bulkreq
.ocount
!= NULL
) {
1064 if (copy_to_user(bulkreq
.lastip
, &inlast
,
1066 return -XFS_ERROR(EFAULT
);
1068 if (copy_to_user(bulkreq
.ocount
, &count
, sizeof(count
)))
1069 return -XFS_ERROR(EFAULT
);
1076 xfs_ioc_fsgeometry_v1(
1080 xfs_fsop_geom_v1_t fsgeo
;
1083 error
= xfs_fs_geometry(mp
, (xfs_fsop_geom_t
*)&fsgeo
, 3);
1087 if (copy_to_user(arg
, &fsgeo
, sizeof(fsgeo
)))
1088 return -XFS_ERROR(EFAULT
);
1097 xfs_fsop_geom_t fsgeo
;
1100 error
= xfs_fs_geometry(mp
, &fsgeo
, 4);
1104 if (copy_to_user(arg
, &fsgeo
, sizeof(fsgeo
)))
1105 return -XFS_ERROR(EFAULT
);
1110 * Linux extended inode flags interface.
1114 xfs_merge_ioc_xflags(
1118 unsigned int xflags
= start
;
1120 if (flags
& FS_IMMUTABLE_FL
)
1121 xflags
|= XFS_XFLAG_IMMUTABLE
;
1123 xflags
&= ~XFS_XFLAG_IMMUTABLE
;
1124 if (flags
& FS_APPEND_FL
)
1125 xflags
|= XFS_XFLAG_APPEND
;
1127 xflags
&= ~XFS_XFLAG_APPEND
;
1128 if (flags
& FS_SYNC_FL
)
1129 xflags
|= XFS_XFLAG_SYNC
;
1131 xflags
&= ~XFS_XFLAG_SYNC
;
1132 if (flags
& FS_NOATIME_FL
)
1133 xflags
|= XFS_XFLAG_NOATIME
;
1135 xflags
&= ~XFS_XFLAG_NOATIME
;
1136 if (flags
& FS_NODUMP_FL
)
1137 xflags
|= XFS_XFLAG_NODUMP
;
1139 xflags
&= ~XFS_XFLAG_NODUMP
;
1146 __uint16_t di_flags
)
1148 unsigned int flags
= 0;
1150 if (di_flags
& XFS_DIFLAG_IMMUTABLE
)
1151 flags
|= FS_IMMUTABLE_FL
;
1152 if (di_flags
& XFS_DIFLAG_APPEND
)
1153 flags
|= FS_APPEND_FL
;
1154 if (di_flags
& XFS_DIFLAG_SYNC
)
1155 flags
|= FS_SYNC_FL
;
1156 if (di_flags
& XFS_DIFLAG_NOATIME
)
1157 flags
|= FS_NOATIME_FL
;
1158 if (di_flags
& XFS_DIFLAG_NODUMP
)
1159 flags
|= FS_NODUMP_FL
;
1172 struct bhv_vattr
*vattr
;
1177 vattr
= kmalloc(sizeof(*vattr
), GFP_KERNEL
);
1178 if (unlikely(!vattr
))
1182 case XFS_IOC_FSGETXATTR
: {
1183 vattr
->va_mask
= XFS_AT_XFLAGS
| XFS_AT_EXTSIZE
| \
1184 XFS_AT_NEXTENTS
| XFS_AT_PROJID
;
1185 error
= xfs_getattr(ip
, vattr
, 0);
1186 if (unlikely(error
)) {
1191 fa
.fsx_xflags
= vattr
->va_xflags
;
1192 fa
.fsx_extsize
= vattr
->va_extsize
;
1193 fa
.fsx_nextents
= vattr
->va_nextents
;
1194 fa
.fsx_projid
= vattr
->va_projid
;
1196 if (copy_to_user(arg
, &fa
, sizeof(fa
))) {
1203 case XFS_IOC_FSSETXATTR
: {
1204 if (copy_from_user(&fa
, arg
, sizeof(fa
))) {
1210 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1211 attr_flags
|= ATTR_NONBLOCK
;
1213 vattr
->va_mask
= XFS_AT_XFLAGS
| XFS_AT_EXTSIZE
| XFS_AT_PROJID
;
1214 vattr
->va_xflags
= fa
.fsx_xflags
;
1215 vattr
->va_extsize
= fa
.fsx_extsize
;
1216 vattr
->va_projid
= fa
.fsx_projid
;
1218 error
= xfs_setattr(ip
, vattr
, attr_flags
, NULL
);
1220 __vn_revalidate(vp
, vattr
); /* update flags */
1225 case XFS_IOC_FSGETXATTRA
: {
1226 vattr
->va_mask
= XFS_AT_XFLAGS
| XFS_AT_EXTSIZE
| \
1227 XFS_AT_ANEXTENTS
| XFS_AT_PROJID
;
1228 error
= xfs_getattr(ip
, vattr
, 0);
1229 if (unlikely(error
)) {
1234 fa
.fsx_xflags
= vattr
->va_xflags
;
1235 fa
.fsx_extsize
= vattr
->va_extsize
;
1236 fa
.fsx_nextents
= vattr
->va_anextents
;
1237 fa
.fsx_projid
= vattr
->va_projid
;
1239 if (copy_to_user(arg
, &fa
, sizeof(fa
))) {
1246 case XFS_IOC_GETXFLAGS
: {
1247 flags
= xfs_di2lxflags(ip
->i_d
.di_flags
);
1248 if (copy_to_user(arg
, &flags
, sizeof(flags
)))
1253 case XFS_IOC_SETXFLAGS
: {
1254 if (copy_from_user(&flags
, arg
, sizeof(flags
))) {
1259 if (flags
& ~(FS_IMMUTABLE_FL
| FS_APPEND_FL
| \
1260 FS_NOATIME_FL
| FS_NODUMP_FL
| \
1262 error
= -EOPNOTSUPP
;
1267 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1268 attr_flags
|= ATTR_NONBLOCK
;
1270 vattr
->va_mask
= XFS_AT_XFLAGS
;
1271 vattr
->va_xflags
= xfs_merge_ioc_xflags(flags
,
1274 error
= xfs_setattr(ip
, vattr
, attr_flags
, NULL
);
1276 __vn_revalidate(vp
, vattr
); /* update flags */
1292 struct xfs_inode
*ip
,
1301 if (copy_from_user(&bm
, arg
, sizeof(bm
)))
1302 return -XFS_ERROR(EFAULT
);
1304 if (bm
.bmv_count
< 2)
1305 return -XFS_ERROR(EINVAL
);
1307 iflags
= (cmd
== XFS_IOC_GETBMAPA
? BMV_IF_ATTRFORK
: 0);
1308 if (ioflags
& IO_INVIS
)
1309 iflags
|= BMV_IF_NO_DMAPI_READ
;
1311 error
= xfs_getbmap(ip
, &bm
, (struct getbmap __user
*)arg
+1, iflags
);
1315 if (copy_to_user(arg
, &bm
, sizeof(bm
)))
1316 return -XFS_ERROR(EFAULT
);
1322 struct xfs_inode
*ip
,
1325 struct getbmapx bmx
;
1330 if (copy_from_user(&bmx
, arg
, sizeof(bmx
)))
1331 return -XFS_ERROR(EFAULT
);
1333 if (bmx
.bmv_count
< 2)
1334 return -XFS_ERROR(EINVAL
);
1337 * Map input getbmapx structure to a getbmap
1338 * structure for xfs_getbmap.
1340 GETBMAP_CONVERT(bmx
, bm
);
1342 iflags
= bmx
.bmv_iflags
;
1344 if (iflags
& (~BMV_IF_VALID
))
1345 return -XFS_ERROR(EINVAL
);
1347 iflags
|= BMV_IF_EXTENDED
;
1349 error
= xfs_getbmap(ip
, &bm
, (struct getbmapx __user
*)arg
+1, iflags
);
1353 GETBMAP_CONVERT(bm
, bmx
);
1355 if (copy_to_user(arg
, &bmx
, sizeof(bmx
)))
1356 return -XFS_ERROR(EFAULT
);