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
, XFS_I(inode
)->i_mount
->m_fixedfsid
,
143 hsize
= sizeof(xfs_fsid_t
);
145 if (cmd
!= XFS_IOC_PATH_TO_FSHANDLE
) {
149 /* need to get access to the xfs_inode to read the generation */
152 lock_mode
= xfs_ilock_map_shared(ip
);
154 /* fill in fid section of handle from inode */
155 handle
.ha_fid
.fid_len
= sizeof(xfs_fid_t
) -
156 sizeof(handle
.ha_fid
.fid_len
);
157 handle
.ha_fid
.fid_pad
= 0;
158 handle
.ha_fid
.fid_gen
= ip
->i_d
.di_gen
;
159 handle
.ha_fid
.fid_ino
= ip
->i_ino
;
161 xfs_iunlock_map_shared(ip
, lock_mode
);
163 hsize
= XFS_HSIZE(handle
);
166 /* now copy our handle into the user buffer & write out the size */
167 if (copy_to_user(hreq
.ohandle
, &handle
, hsize
) ||
168 copy_to_user(hreq
.ohandlen
, &hsize
, sizeof(__s32
))) {
170 return -XFS_ERROR(EFAULT
);
179 * Convert userspace handle data into vnode (and inode).
180 * We [ab]use the fact that all the fsop_handlereq ioctl calls
181 * have a data structure argument whose first component is always
182 * a xfs_fsop_handlereq_t, so we can cast to and from this type.
183 * This allows us to optimise the copy_from_user calls and gives
184 * a handy, shared routine.
186 * If no error, caller must always VN_RELE the returned vp.
189 xfs_vget_fsop_handlereq(
191 struct inode
*parinode
, /* parent inode pointer */
192 xfs_fsop_handlereq_t
*hreq
,
194 struct inode
**inode
)
199 xfs_handle_t
*handlep
;
202 struct inode
*inodep
;
209 * Only allow handle opens under a directory.
211 if (!S_ISDIR(parinode
->i_mode
))
212 return XFS_ERROR(ENOTDIR
);
214 hanp
= hreq
->ihandle
;
215 hlen
= hreq
->ihandlen
;
218 if (hlen
< sizeof(handlep
->ha_fsid
) || hlen
> sizeof(*handlep
))
219 return XFS_ERROR(EINVAL
);
220 if (copy_from_user(handlep
, hanp
, hlen
))
221 return XFS_ERROR(EFAULT
);
222 if (hlen
< sizeof(*handlep
))
223 memset(((char *)handlep
) + hlen
, 0, sizeof(*handlep
) - hlen
);
224 if (hlen
> sizeof(handlep
->ha_fsid
)) {
225 if (handlep
->ha_fid
.fid_len
!=
226 (hlen
- sizeof(handlep
->ha_fsid
) -
227 sizeof(handlep
->ha_fid
.fid_len
)) ||
228 handlep
->ha_fid
.fid_pad
)
229 return XFS_ERROR(EINVAL
);
233 * Crack the handle, obtain the inode # & generation #
235 xfid
= (struct xfs_fid
*)&handlep
->ha_fid
;
236 if (xfid
->fid_len
== sizeof(*xfid
) - sizeof(xfid
->fid_len
)) {
238 igen
= xfid
->fid_gen
;
240 return XFS_ERROR(EINVAL
);
244 * Get the XFS inode, building a vnode to go with it.
246 error
= xfs_iget(mp
, NULL
, ino
, 0, XFS_ILOCK_SHARED
, &ip
, 0);
250 return XFS_ERROR(EIO
);
251 if (ip
->i_d
.di_mode
== 0 || ip
->i_d
.di_gen
!= igen
) {
252 xfs_iput_new(ip
, XFS_ILOCK_SHARED
);
253 return XFS_ERROR(ENOENT
);
257 inodep
= vn_to_inode(vpp
);
258 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
269 struct file
*parfilp
,
270 struct inode
*parinode
)
277 struct dentry
*dentry
;
279 xfs_fsop_handlereq_t hreq
;
281 if (!capable(CAP_SYS_ADMIN
))
282 return -XFS_ERROR(EPERM
);
283 if (copy_from_user(&hreq
, arg
, sizeof(xfs_fsop_handlereq_t
)))
284 return -XFS_ERROR(EFAULT
);
286 error
= xfs_vget_fsop_handlereq(mp
, parinode
, &hreq
, &vp
, &inode
);
290 /* Restrict xfs_open_by_handle to directories & regular files. */
291 if (!(S_ISREG(inode
->i_mode
) || S_ISDIR(inode
->i_mode
))) {
293 return -XFS_ERROR(EINVAL
);
296 #if BITS_PER_LONG != 32
297 hreq
.oflags
|= O_LARGEFILE
;
299 /* Put open permission in namei format. */
300 permflag
= hreq
.oflags
;
301 if ((permflag
+1) & O_ACCMODE
)
303 if (permflag
& O_TRUNC
)
306 if ((!(permflag
& O_APPEND
) || (permflag
& O_TRUNC
)) &&
307 (permflag
& FMODE_WRITE
) && IS_APPEND(inode
)) {
309 return -XFS_ERROR(EPERM
);
312 if ((permflag
& FMODE_WRITE
) && IS_IMMUTABLE(inode
)) {
314 return -XFS_ERROR(EACCES
);
317 /* Can't write directories. */
318 if ( S_ISDIR(inode
->i_mode
) && (permflag
& FMODE_WRITE
)) {
320 return -XFS_ERROR(EISDIR
);
323 if ((new_fd
= get_unused_fd()) < 0) {
328 dentry
= d_alloc_anon(inode
);
329 if (dentry
== NULL
) {
331 put_unused_fd(new_fd
);
332 return -XFS_ERROR(ENOMEM
);
335 /* Ensure umount returns EBUSY on umounts while this file is open. */
336 mntget(parfilp
->f_path
.mnt
);
338 /* Create file pointer. */
339 filp
= dentry_open(dentry
, parfilp
->f_path
.mnt
, hreq
.oflags
);
341 put_unused_fd(new_fd
);
342 return -XFS_ERROR(-PTR_ERR(filp
));
344 if (inode
->i_mode
& S_IFREG
) {
345 /* invisible operation should not change atime */
346 filp
->f_flags
|= O_NOATIME
;
347 filp
->f_op
= &xfs_invis_file_operations
;
350 fd_install(new_fd
, filp
);
355 * This is a copy from fs/namei.c:vfs_readlink(), except for removing it's
356 * unused first argument.
371 if (len
> (unsigned) buflen
)
373 if (copy_to_user(buffer
, link
, len
))
381 xfs_readlink_by_handle(
384 struct inode
*parinode
)
387 xfs_fsop_handlereq_t hreq
;
393 if (!capable(CAP_SYS_ADMIN
))
394 return -XFS_ERROR(EPERM
);
395 if (copy_from_user(&hreq
, arg
, sizeof(xfs_fsop_handlereq_t
)))
396 return -XFS_ERROR(EFAULT
);
398 error
= xfs_vget_fsop_handlereq(mp
, parinode
, &hreq
, &vp
, &inode
);
402 /* Restrict this handle operation to symlinks only. */
403 if (!S_ISLNK(inode
->i_mode
)) {
404 error
= -XFS_ERROR(EINVAL
);
408 if (copy_from_user(&olen
, hreq
.ohandlen
, sizeof(__u32
))) {
409 error
= -XFS_ERROR(EFAULT
);
413 link
= kmalloc(MAXPATHLEN
+1, GFP_KERNEL
);
417 error
= -xfs_readlink(XFS_I(inode
), link
);
420 error
= do_readlink(hreq
.ohandle
, olen
, link
);
432 xfs_fssetdm_by_handle(
435 struct inode
*parinode
)
438 struct fsdmidata fsd
;
439 xfs_fsop_setdm_handlereq_t dmhreq
;
443 if (!capable(CAP_MKNOD
))
444 return -XFS_ERROR(EPERM
);
445 if (copy_from_user(&dmhreq
, arg
, sizeof(xfs_fsop_setdm_handlereq_t
)))
446 return -XFS_ERROR(EFAULT
);
448 error
= xfs_vget_fsop_handlereq(mp
, parinode
, &dmhreq
.hreq
, &vp
, &inode
);
452 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
)) {
454 return -XFS_ERROR(EPERM
);
457 if (copy_from_user(&fsd
, dmhreq
.data
, sizeof(fsd
))) {
459 return -XFS_ERROR(EFAULT
);
462 error
= xfs_set_dmattrs(xfs_vtoi(vp
),
463 fsd
.fsd_dmevmask
, fsd
.fsd_dmstate
);
472 xfs_attrlist_by_handle(
475 struct inode
*parinode
)
478 attrlist_cursor_kern_t
*cursor
;
479 xfs_fsop_attrlist_handlereq_t al_hreq
;
484 if (!capable(CAP_SYS_ADMIN
))
485 return -XFS_ERROR(EPERM
);
486 if (copy_from_user(&al_hreq
, arg
, sizeof(xfs_fsop_attrlist_handlereq_t
)))
487 return -XFS_ERROR(EFAULT
);
488 if (al_hreq
.buflen
> XATTR_LIST_MAX
)
489 return -XFS_ERROR(EINVAL
);
491 error
= xfs_vget_fsop_handlereq(mp
, parinode
, &al_hreq
.hreq
,
496 kbuf
= kmalloc(al_hreq
.buflen
, GFP_KERNEL
);
500 cursor
= (attrlist_cursor_kern_t
*)&al_hreq
.pos
;
501 error
= xfs_attr_list(XFS_I(inode
), kbuf
, al_hreq
.buflen
,
502 al_hreq
.flags
, cursor
);
506 if (copy_to_user(al_hreq
.buffer
, kbuf
, al_hreq
.buflen
))
518 xfs_attrmulti_attr_get(
528 if (*len
> XATTR_SIZE_MAX
)
530 kbuf
= kmalloc(*len
, GFP_KERNEL
);
534 error
= xfs_attr_get(XFS_I(inode
), name
, kbuf
, len
, flags
, NULL
);
538 if (copy_to_user(ubuf
, kbuf
, *len
))
547 xfs_attrmulti_attr_set(
550 const char __user
*ubuf
,
557 if (IS_RDONLY(inode
))
559 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
561 if (len
> XATTR_SIZE_MAX
)
564 kbuf
= kmalloc(len
, GFP_KERNEL
);
568 if (copy_from_user(kbuf
, ubuf
, len
))
571 error
= xfs_attr_set(XFS_I(inode
), name
, kbuf
, len
, flags
);
579 xfs_attrmulti_attr_remove(
584 if (IS_RDONLY(inode
))
586 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
588 return xfs_attr_remove(XFS_I(inode
), name
, flags
);
592 xfs_attrmulti_by_handle(
595 struct inode
*parinode
)
598 xfs_attr_multiop_t
*ops
;
599 xfs_fsop_attrmulti_handlereq_t am_hreq
;
602 unsigned int i
, size
;
605 if (!capable(CAP_SYS_ADMIN
))
606 return -XFS_ERROR(EPERM
);
607 if (copy_from_user(&am_hreq
, arg
, sizeof(xfs_fsop_attrmulti_handlereq_t
)))
608 return -XFS_ERROR(EFAULT
);
610 error
= xfs_vget_fsop_handlereq(mp
, parinode
, &am_hreq
.hreq
, &vp
, &inode
);
615 size
= am_hreq
.opcount
* sizeof(attr_multiop_t
);
616 if (!size
|| size
> 16 * PAGE_SIZE
)
620 ops
= kmalloc(size
, GFP_KERNEL
);
625 if (copy_from_user(ops
, am_hreq
.ops
, size
))
628 attr_name
= kmalloc(MAXNAMELEN
, GFP_KERNEL
);
634 for (i
= 0; i
< am_hreq
.opcount
; i
++) {
635 ops
[i
].am_error
= strncpy_from_user(attr_name
,
636 ops
[i
].am_attrname
, MAXNAMELEN
);
637 if (ops
[i
].am_error
== 0 || ops
[i
].am_error
== MAXNAMELEN
)
639 if (ops
[i
].am_error
< 0)
642 switch (ops
[i
].am_opcode
) {
644 ops
[i
].am_error
= xfs_attrmulti_attr_get(inode
,
645 attr_name
, ops
[i
].am_attrvalue
,
646 &ops
[i
].am_length
, ops
[i
].am_flags
);
649 ops
[i
].am_error
= xfs_attrmulti_attr_set(inode
,
650 attr_name
, ops
[i
].am_attrvalue
,
651 ops
[i
].am_length
, ops
[i
].am_flags
);
654 ops
[i
].am_error
= xfs_attrmulti_attr_remove(inode
,
655 attr_name
, ops
[i
].am_flags
);
658 ops
[i
].am_error
= EINVAL
;
662 if (copy_to_user(am_hreq
.ops
, ops
, size
))
663 error
= XFS_ERROR(EFAULT
);
674 /* prototypes for a few of the stack-hungry cases that have
675 * their own functions. Functions are defined after their use
676 * so gcc doesn't get fancy and inline them with -03 */
680 struct xfs_inode
*ip
,
694 xfs_ioc_fsgeometry_v1(
719 struct xfs_inode
*ip
,
726 struct xfs_inode
*ip
,
737 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
738 bhv_vnode_t
*vp
= vn_from_inode(inode
);
739 xfs_mount_t
*mp
= ip
->i_mount
;
742 vn_trace_entry(XFS_I(inode
), "xfs_ioctl", (inst_t
*)__return_address
);
746 case XFS_IOC_ALLOCSP
:
749 case XFS_IOC_UNRESVSP
:
750 case XFS_IOC_ALLOCSP64
:
751 case XFS_IOC_FREESP64
:
752 case XFS_IOC_RESVSP64
:
753 case XFS_IOC_UNRESVSP64
:
755 * Only allow the sys admin to reserve space unless
756 * unwritten extents are enabled.
758 if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp
->m_sb
) &&
759 !capable(CAP_SYS_ADMIN
))
762 return xfs_ioc_space(ip
, inode
, filp
, ioflags
, cmd
, arg
);
764 case XFS_IOC_DIOINFO
: {
766 xfs_buftarg_t
*target
=
767 (ip
->i_d
.di_flags
& XFS_DIFLAG_REALTIME
) ?
768 mp
->m_rtdev_targp
: mp
->m_ddev_targp
;
770 da
.d_mem
= da
.d_miniosz
= 1 << target
->bt_sshift
;
771 da
.d_maxiosz
= INT_MAX
& ~(da
.d_miniosz
- 1);
773 if (copy_to_user(arg
, &da
, sizeof(da
)))
774 return -XFS_ERROR(EFAULT
);
778 case XFS_IOC_FSBULKSTAT_SINGLE
:
779 case XFS_IOC_FSBULKSTAT
:
780 case XFS_IOC_FSINUMBERS
:
781 return xfs_ioc_bulkstat(mp
, cmd
, arg
);
783 case XFS_IOC_FSGEOMETRY_V1
:
784 return xfs_ioc_fsgeometry_v1(mp
, arg
);
786 case XFS_IOC_FSGEOMETRY
:
787 return xfs_ioc_fsgeometry(mp
, arg
);
789 case XFS_IOC_GETVERSION
:
790 return put_user(inode
->i_generation
, (int __user
*)arg
);
792 case XFS_IOC_FSGETXATTR
:
793 return xfs_ioc_fsgetxattr(ip
, 0, arg
);
794 case XFS_IOC_FSGETXATTRA
:
795 return xfs_ioc_fsgetxattr(ip
, 1, arg
);
796 case XFS_IOC_GETXFLAGS
:
797 case XFS_IOC_SETXFLAGS
:
798 case XFS_IOC_FSSETXATTR
:
799 return xfs_ioc_xattr(vp
, ip
, filp
, cmd
, arg
);
801 case XFS_IOC_FSSETDM
: {
802 struct fsdmidata dmi
;
804 if (copy_from_user(&dmi
, arg
, sizeof(dmi
)))
805 return -XFS_ERROR(EFAULT
);
807 error
= xfs_set_dmattrs(ip
, dmi
.fsd_dmevmask
,
812 case XFS_IOC_GETBMAP
:
813 case XFS_IOC_GETBMAPA
:
814 return xfs_ioc_getbmap(ip
, ioflags
, cmd
, arg
);
816 case XFS_IOC_GETBMAPX
:
817 return xfs_ioc_getbmapx(ip
, arg
);
819 case XFS_IOC_FD_TO_HANDLE
:
820 case XFS_IOC_PATH_TO_HANDLE
:
821 case XFS_IOC_PATH_TO_FSHANDLE
:
822 return xfs_find_handle(cmd
, arg
);
824 case XFS_IOC_OPEN_BY_HANDLE
:
825 return xfs_open_by_handle(mp
, arg
, filp
, inode
);
827 case XFS_IOC_FSSETDM_BY_HANDLE
:
828 return xfs_fssetdm_by_handle(mp
, arg
, inode
);
830 case XFS_IOC_READLINK_BY_HANDLE
:
831 return xfs_readlink_by_handle(mp
, arg
, inode
);
833 case XFS_IOC_ATTRLIST_BY_HANDLE
:
834 return xfs_attrlist_by_handle(mp
, arg
, inode
);
836 case XFS_IOC_ATTRMULTI_BY_HANDLE
:
837 return xfs_attrmulti_by_handle(mp
, arg
, inode
);
839 case XFS_IOC_SWAPEXT
: {
840 error
= xfs_swapext((struct xfs_swapext __user
*)arg
);
844 case XFS_IOC_FSCOUNTS
: {
845 xfs_fsop_counts_t out
;
847 error
= xfs_fs_counts(mp
, &out
);
851 if (copy_to_user(arg
, &out
, sizeof(out
)))
852 return -XFS_ERROR(EFAULT
);
856 case XFS_IOC_SET_RESBLKS
: {
857 xfs_fsop_resblks_t inout
;
860 if (!capable(CAP_SYS_ADMIN
))
863 if (copy_from_user(&inout
, arg
, sizeof(inout
)))
864 return -XFS_ERROR(EFAULT
);
866 /* input parameter is passed in resblks field of structure */
868 error
= xfs_reserve_blocks(mp
, &in
, &inout
);
872 if (copy_to_user(arg
, &inout
, sizeof(inout
)))
873 return -XFS_ERROR(EFAULT
);
877 case XFS_IOC_GET_RESBLKS
: {
878 xfs_fsop_resblks_t out
;
880 if (!capable(CAP_SYS_ADMIN
))
883 error
= xfs_reserve_blocks(mp
, NULL
, &out
);
887 if (copy_to_user(arg
, &out
, sizeof(out
)))
888 return -XFS_ERROR(EFAULT
);
893 case XFS_IOC_FSGROWFSDATA
: {
894 xfs_growfs_data_t in
;
896 if (!capable(CAP_SYS_ADMIN
))
899 if (copy_from_user(&in
, arg
, sizeof(in
)))
900 return -XFS_ERROR(EFAULT
);
902 error
= xfs_growfs_data(mp
, &in
);
906 case XFS_IOC_FSGROWFSLOG
: {
909 if (!capable(CAP_SYS_ADMIN
))
912 if (copy_from_user(&in
, arg
, sizeof(in
)))
913 return -XFS_ERROR(EFAULT
);
915 error
= xfs_growfs_log(mp
, &in
);
919 case XFS_IOC_FSGROWFSRT
: {
922 if (!capable(CAP_SYS_ADMIN
))
925 if (copy_from_user(&in
, arg
, sizeof(in
)))
926 return -XFS_ERROR(EFAULT
);
928 error
= xfs_growfs_rt(mp
, &in
);
933 if (!capable(CAP_SYS_ADMIN
))
936 if (inode
->i_sb
->s_frozen
== SB_UNFROZEN
)
937 freeze_bdev(inode
->i_sb
->s_bdev
);
941 if (!capable(CAP_SYS_ADMIN
))
943 if (inode
->i_sb
->s_frozen
!= SB_UNFROZEN
)
944 thaw_bdev(inode
->i_sb
->s_bdev
, inode
->i_sb
);
947 case XFS_IOC_GOINGDOWN
: {
950 if (!capable(CAP_SYS_ADMIN
))
953 if (get_user(in
, (__uint32_t __user
*)arg
))
954 return -XFS_ERROR(EFAULT
);
956 error
= xfs_fs_goingdown(mp
, in
);
960 case XFS_IOC_ERROR_INJECTION
: {
961 xfs_error_injection_t in
;
963 if (!capable(CAP_SYS_ADMIN
))
966 if (copy_from_user(&in
, arg
, sizeof(in
)))
967 return -XFS_ERROR(EFAULT
);
969 error
= xfs_errortag_add(in
.errtag
, mp
);
973 case XFS_IOC_ERROR_CLEARALL
:
974 if (!capable(CAP_SYS_ADMIN
))
977 error
= xfs_errortag_clearall(mp
, 1);
987 struct xfs_inode
*ip
,
998 if (inode
->i_flags
& (S_IMMUTABLE
|S_APPEND
))
999 return -XFS_ERROR(EPERM
);
1001 if (!(filp
->f_mode
& FMODE_WRITE
))
1002 return -XFS_ERROR(EBADF
);
1004 if (!S_ISREG(inode
->i_mode
))
1005 return -XFS_ERROR(EINVAL
);
1007 if (copy_from_user(&bf
, arg
, sizeof(bf
)))
1008 return -XFS_ERROR(EFAULT
);
1010 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1011 attr_flags
|= ATTR_NONBLOCK
;
1012 if (ioflags
& IO_INVIS
)
1013 attr_flags
|= ATTR_DMI
;
1015 error
= xfs_change_file_space(ip
, cmd
, &bf
, filp
->f_pos
,
1026 xfs_fsop_bulkreq_t bulkreq
;
1027 int count
; /* # of records returned */
1028 xfs_ino_t inlast
; /* last inode number */
1032 /* done = 1 if there are more stats to get and if bulkstat */
1033 /* should be called again (unused here, but used in dmapi) */
1035 if (!capable(CAP_SYS_ADMIN
))
1038 if (XFS_FORCED_SHUTDOWN(mp
))
1039 return -XFS_ERROR(EIO
);
1041 if (copy_from_user(&bulkreq
, arg
, sizeof(xfs_fsop_bulkreq_t
)))
1042 return -XFS_ERROR(EFAULT
);
1044 if (copy_from_user(&inlast
, bulkreq
.lastip
, sizeof(__s64
)))
1045 return -XFS_ERROR(EFAULT
);
1047 if ((count
= bulkreq
.icount
) <= 0)
1048 return -XFS_ERROR(EINVAL
);
1050 if (bulkreq
.ubuffer
== NULL
)
1051 return -XFS_ERROR(EINVAL
);
1053 if (cmd
== XFS_IOC_FSINUMBERS
)
1054 error
= xfs_inumbers(mp
, &inlast
, &count
,
1055 bulkreq
.ubuffer
, xfs_inumbers_fmt
);
1056 else if (cmd
== XFS_IOC_FSBULKSTAT_SINGLE
)
1057 error
= xfs_bulkstat_single(mp
, &inlast
,
1058 bulkreq
.ubuffer
, &done
);
1059 else /* XFS_IOC_FSBULKSTAT */
1060 error
= xfs_bulkstat(mp
, &inlast
, &count
,
1061 (bulkstat_one_pf
)xfs_bulkstat_one
, NULL
,
1062 sizeof(xfs_bstat_t
), bulkreq
.ubuffer
,
1063 BULKSTAT_FG_QUICK
, &done
);
1068 if (bulkreq
.ocount
!= NULL
) {
1069 if (copy_to_user(bulkreq
.lastip
, &inlast
,
1071 return -XFS_ERROR(EFAULT
);
1073 if (copy_to_user(bulkreq
.ocount
, &count
, sizeof(count
)))
1074 return -XFS_ERROR(EFAULT
);
1081 xfs_ioc_fsgeometry_v1(
1085 xfs_fsop_geom_v1_t fsgeo
;
1088 error
= xfs_fs_geometry(mp
, (xfs_fsop_geom_t
*)&fsgeo
, 3);
1092 if (copy_to_user(arg
, &fsgeo
, sizeof(fsgeo
)))
1093 return -XFS_ERROR(EFAULT
);
1102 xfs_fsop_geom_t fsgeo
;
1105 error
= xfs_fs_geometry(mp
, &fsgeo
, 4);
1109 if (copy_to_user(arg
, &fsgeo
, sizeof(fsgeo
)))
1110 return -XFS_ERROR(EFAULT
);
1115 * Linux extended inode flags interface.
1119 xfs_merge_ioc_xflags(
1123 unsigned int xflags
= start
;
1125 if (flags
& FS_IMMUTABLE_FL
)
1126 xflags
|= XFS_XFLAG_IMMUTABLE
;
1128 xflags
&= ~XFS_XFLAG_IMMUTABLE
;
1129 if (flags
& FS_APPEND_FL
)
1130 xflags
|= XFS_XFLAG_APPEND
;
1132 xflags
&= ~XFS_XFLAG_APPEND
;
1133 if (flags
& FS_SYNC_FL
)
1134 xflags
|= XFS_XFLAG_SYNC
;
1136 xflags
&= ~XFS_XFLAG_SYNC
;
1137 if (flags
& FS_NOATIME_FL
)
1138 xflags
|= XFS_XFLAG_NOATIME
;
1140 xflags
&= ~XFS_XFLAG_NOATIME
;
1141 if (flags
& FS_NODUMP_FL
)
1142 xflags
|= XFS_XFLAG_NODUMP
;
1144 xflags
&= ~XFS_XFLAG_NODUMP
;
1151 __uint16_t di_flags
)
1153 unsigned int flags
= 0;
1155 if (di_flags
& XFS_DIFLAG_IMMUTABLE
)
1156 flags
|= FS_IMMUTABLE_FL
;
1157 if (di_flags
& XFS_DIFLAG_APPEND
)
1158 flags
|= FS_APPEND_FL
;
1159 if (di_flags
& XFS_DIFLAG_SYNC
)
1160 flags
|= FS_SYNC_FL
;
1161 if (di_flags
& XFS_DIFLAG_NOATIME
)
1162 flags
|= FS_NOATIME_FL
;
1163 if (di_flags
& XFS_DIFLAG_NODUMP
)
1164 flags
|= FS_NODUMP_FL
;
1176 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
1177 fa
.fsx_xflags
= xfs_ip2xflags(ip
);
1178 fa
.fsx_extsize
= ip
->i_d
.di_extsize
<< ip
->i_mount
->m_sb
.sb_blocklog
;
1179 fa
.fsx_projid
= ip
->i_d
.di_projid
;
1183 if (ip
->i_afp
->if_flags
& XFS_IFEXTENTS
)
1184 fa
.fsx_nextents
= ip
->i_afp
->if_bytes
/
1185 sizeof(xfs_bmbt_rec_t
);
1187 fa
.fsx_nextents
= ip
->i_d
.di_anextents
;
1189 fa
.fsx_nextents
= 0;
1191 if (ip
->i_df
.if_flags
& XFS_IFEXTENTS
)
1192 fa
.fsx_nextents
= ip
->i_df
.if_bytes
/
1193 sizeof(xfs_bmbt_rec_t
);
1195 fa
.fsx_nextents
= ip
->i_d
.di_nextents
;
1197 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
1199 if (copy_to_user(arg
, &fa
, sizeof(fa
)))
1213 struct bhv_vattr
*vattr
;
1218 vattr
= kmalloc(sizeof(*vattr
), GFP_KERNEL
);
1219 if (unlikely(!vattr
))
1223 case XFS_IOC_FSSETXATTR
: {
1224 if (copy_from_user(&fa
, arg
, sizeof(fa
))) {
1230 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1231 attr_flags
|= ATTR_NONBLOCK
;
1233 vattr
->va_mask
= XFS_AT_XFLAGS
| XFS_AT_EXTSIZE
| XFS_AT_PROJID
;
1234 vattr
->va_xflags
= fa
.fsx_xflags
;
1235 vattr
->va_extsize
= fa
.fsx_extsize
;
1236 vattr
->va_projid
= fa
.fsx_projid
;
1238 error
= xfs_setattr(ip
, vattr
, attr_flags
, NULL
);
1240 __vn_revalidate(vp
, vattr
); /* update flags */
1245 case XFS_IOC_GETXFLAGS
: {
1246 flags
= xfs_di2lxflags(ip
->i_d
.di_flags
);
1247 if (copy_to_user(arg
, &flags
, sizeof(flags
)))
1252 case XFS_IOC_SETXFLAGS
: {
1253 if (copy_from_user(&flags
, arg
, sizeof(flags
))) {
1258 if (flags
& ~(FS_IMMUTABLE_FL
| FS_APPEND_FL
| \
1259 FS_NOATIME_FL
| FS_NODUMP_FL
| \
1261 error
= -EOPNOTSUPP
;
1266 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1267 attr_flags
|= ATTR_NONBLOCK
;
1269 vattr
->va_mask
= XFS_AT_XFLAGS
;
1270 vattr
->va_xflags
= xfs_merge_ioc_xflags(flags
,
1273 error
= xfs_setattr(ip
, vattr
, attr_flags
, NULL
);
1275 __vn_revalidate(vp
, vattr
); /* update flags */
1291 struct xfs_inode
*ip
,
1300 if (copy_from_user(&bm
, arg
, sizeof(bm
)))
1301 return -XFS_ERROR(EFAULT
);
1303 if (bm
.bmv_count
< 2)
1304 return -XFS_ERROR(EINVAL
);
1306 iflags
= (cmd
== XFS_IOC_GETBMAPA
? BMV_IF_ATTRFORK
: 0);
1307 if (ioflags
& IO_INVIS
)
1308 iflags
|= BMV_IF_NO_DMAPI_READ
;
1310 error
= xfs_getbmap(ip
, &bm
, (struct getbmap __user
*)arg
+1, iflags
);
1314 if (copy_to_user(arg
, &bm
, sizeof(bm
)))
1315 return -XFS_ERROR(EFAULT
);
1321 struct xfs_inode
*ip
,
1324 struct getbmapx bmx
;
1329 if (copy_from_user(&bmx
, arg
, sizeof(bmx
)))
1330 return -XFS_ERROR(EFAULT
);
1332 if (bmx
.bmv_count
< 2)
1333 return -XFS_ERROR(EINVAL
);
1336 * Map input getbmapx structure to a getbmap
1337 * structure for xfs_getbmap.
1339 GETBMAP_CONVERT(bmx
, bm
);
1341 iflags
= bmx
.bmv_iflags
;
1343 if (iflags
& (~BMV_IF_VALID
))
1344 return -XFS_ERROR(EINVAL
);
1346 iflags
|= BMV_IF_EXTENDED
;
1348 error
= xfs_getbmap(ip
, &bm
, (struct getbmapx __user
*)arg
+1, iflags
);
1352 GETBMAP_CONVERT(bm
, bmx
);
1354 if (copy_to_user(arg
, &bmx
, sizeof(bmx
)))
1355 return -XFS_ERROR(EFAULT
);