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 xfs_itrace_entry(XFS_I(inode
));
745 case XFS_IOC_ALLOCSP
:
748 case XFS_IOC_UNRESVSP
:
749 case XFS_IOC_ALLOCSP64
:
750 case XFS_IOC_FREESP64
:
751 case XFS_IOC_RESVSP64
:
752 case XFS_IOC_UNRESVSP64
:
754 * Only allow the sys admin to reserve space unless
755 * unwritten extents are enabled.
757 if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp
->m_sb
) &&
758 !capable(CAP_SYS_ADMIN
))
761 return xfs_ioc_space(ip
, inode
, filp
, ioflags
, cmd
, arg
);
763 case XFS_IOC_DIOINFO
: {
765 xfs_buftarg_t
*target
=
766 (ip
->i_d
.di_flags
& XFS_DIFLAG_REALTIME
) ?
767 mp
->m_rtdev_targp
: mp
->m_ddev_targp
;
769 da
.d_mem
= da
.d_miniosz
= 1 << target
->bt_sshift
;
770 da
.d_maxiosz
= INT_MAX
& ~(da
.d_miniosz
- 1);
772 if (copy_to_user(arg
, &da
, sizeof(da
)))
773 return -XFS_ERROR(EFAULT
);
777 case XFS_IOC_FSBULKSTAT_SINGLE
:
778 case XFS_IOC_FSBULKSTAT
:
779 case XFS_IOC_FSINUMBERS
:
780 return xfs_ioc_bulkstat(mp
, cmd
, arg
);
782 case XFS_IOC_FSGEOMETRY_V1
:
783 return xfs_ioc_fsgeometry_v1(mp
, arg
);
785 case XFS_IOC_FSGEOMETRY
:
786 return xfs_ioc_fsgeometry(mp
, arg
);
788 case XFS_IOC_GETVERSION
:
789 return put_user(inode
->i_generation
, (int __user
*)arg
);
791 case XFS_IOC_FSGETXATTR
:
792 return xfs_ioc_fsgetxattr(ip
, 0, arg
);
793 case XFS_IOC_FSGETXATTRA
:
794 return xfs_ioc_fsgetxattr(ip
, 1, arg
);
795 case XFS_IOC_GETXFLAGS
:
796 case XFS_IOC_SETXFLAGS
:
797 case XFS_IOC_FSSETXATTR
:
798 return xfs_ioc_xattr(vp
, ip
, filp
, cmd
, arg
);
800 case XFS_IOC_FSSETDM
: {
801 struct fsdmidata dmi
;
803 if (copy_from_user(&dmi
, arg
, sizeof(dmi
)))
804 return -XFS_ERROR(EFAULT
);
806 error
= xfs_set_dmattrs(ip
, dmi
.fsd_dmevmask
,
811 case XFS_IOC_GETBMAP
:
812 case XFS_IOC_GETBMAPA
:
813 return xfs_ioc_getbmap(ip
, ioflags
, cmd
, arg
);
815 case XFS_IOC_GETBMAPX
:
816 return xfs_ioc_getbmapx(ip
, arg
);
818 case XFS_IOC_FD_TO_HANDLE
:
819 case XFS_IOC_PATH_TO_HANDLE
:
820 case XFS_IOC_PATH_TO_FSHANDLE
:
821 return xfs_find_handle(cmd
, arg
);
823 case XFS_IOC_OPEN_BY_HANDLE
:
824 return xfs_open_by_handle(mp
, arg
, filp
, inode
);
826 case XFS_IOC_FSSETDM_BY_HANDLE
:
827 return xfs_fssetdm_by_handle(mp
, arg
, inode
);
829 case XFS_IOC_READLINK_BY_HANDLE
:
830 return xfs_readlink_by_handle(mp
, arg
, inode
);
832 case XFS_IOC_ATTRLIST_BY_HANDLE
:
833 return xfs_attrlist_by_handle(mp
, arg
, inode
);
835 case XFS_IOC_ATTRMULTI_BY_HANDLE
:
836 return xfs_attrmulti_by_handle(mp
, arg
, inode
);
838 case XFS_IOC_SWAPEXT
: {
839 error
= xfs_swapext((struct xfs_swapext __user
*)arg
);
843 case XFS_IOC_FSCOUNTS
: {
844 xfs_fsop_counts_t out
;
846 error
= xfs_fs_counts(mp
, &out
);
850 if (copy_to_user(arg
, &out
, sizeof(out
)))
851 return -XFS_ERROR(EFAULT
);
855 case XFS_IOC_SET_RESBLKS
: {
856 xfs_fsop_resblks_t inout
;
859 if (!capable(CAP_SYS_ADMIN
))
862 if (copy_from_user(&inout
, arg
, sizeof(inout
)))
863 return -XFS_ERROR(EFAULT
);
865 /* input parameter is passed in resblks field of structure */
867 error
= xfs_reserve_blocks(mp
, &in
, &inout
);
871 if (copy_to_user(arg
, &inout
, sizeof(inout
)))
872 return -XFS_ERROR(EFAULT
);
876 case XFS_IOC_GET_RESBLKS
: {
877 xfs_fsop_resblks_t out
;
879 if (!capable(CAP_SYS_ADMIN
))
882 error
= xfs_reserve_blocks(mp
, NULL
, &out
);
886 if (copy_to_user(arg
, &out
, sizeof(out
)))
887 return -XFS_ERROR(EFAULT
);
892 case XFS_IOC_FSGROWFSDATA
: {
893 xfs_growfs_data_t in
;
895 if (!capable(CAP_SYS_ADMIN
))
898 if (copy_from_user(&in
, arg
, sizeof(in
)))
899 return -XFS_ERROR(EFAULT
);
901 error
= xfs_growfs_data(mp
, &in
);
905 case XFS_IOC_FSGROWFSLOG
: {
908 if (!capable(CAP_SYS_ADMIN
))
911 if (copy_from_user(&in
, arg
, sizeof(in
)))
912 return -XFS_ERROR(EFAULT
);
914 error
= xfs_growfs_log(mp
, &in
);
918 case XFS_IOC_FSGROWFSRT
: {
921 if (!capable(CAP_SYS_ADMIN
))
924 if (copy_from_user(&in
, arg
, sizeof(in
)))
925 return -XFS_ERROR(EFAULT
);
927 error
= xfs_growfs_rt(mp
, &in
);
932 if (!capable(CAP_SYS_ADMIN
))
935 if (inode
->i_sb
->s_frozen
== SB_UNFROZEN
)
936 freeze_bdev(inode
->i_sb
->s_bdev
);
940 if (!capable(CAP_SYS_ADMIN
))
942 if (inode
->i_sb
->s_frozen
!= SB_UNFROZEN
)
943 thaw_bdev(inode
->i_sb
->s_bdev
, inode
->i_sb
);
946 case XFS_IOC_GOINGDOWN
: {
949 if (!capable(CAP_SYS_ADMIN
))
952 if (get_user(in
, (__uint32_t __user
*)arg
))
953 return -XFS_ERROR(EFAULT
);
955 error
= xfs_fs_goingdown(mp
, in
);
959 case XFS_IOC_ERROR_INJECTION
: {
960 xfs_error_injection_t in
;
962 if (!capable(CAP_SYS_ADMIN
))
965 if (copy_from_user(&in
, arg
, sizeof(in
)))
966 return -XFS_ERROR(EFAULT
);
968 error
= xfs_errortag_add(in
.errtag
, mp
);
972 case XFS_IOC_ERROR_CLEARALL
:
973 if (!capable(CAP_SYS_ADMIN
))
976 error
= xfs_errortag_clearall(mp
, 1);
986 struct xfs_inode
*ip
,
997 if (inode
->i_flags
& (S_IMMUTABLE
|S_APPEND
))
998 return -XFS_ERROR(EPERM
);
1000 if (!(filp
->f_mode
& FMODE_WRITE
))
1001 return -XFS_ERROR(EBADF
);
1003 if (!S_ISREG(inode
->i_mode
))
1004 return -XFS_ERROR(EINVAL
);
1006 if (copy_from_user(&bf
, arg
, sizeof(bf
)))
1007 return -XFS_ERROR(EFAULT
);
1009 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1010 attr_flags
|= ATTR_NONBLOCK
;
1011 if (ioflags
& IO_INVIS
)
1012 attr_flags
|= ATTR_DMI
;
1014 error
= xfs_change_file_space(ip
, cmd
, &bf
, filp
->f_pos
,
1025 xfs_fsop_bulkreq_t bulkreq
;
1026 int count
; /* # of records returned */
1027 xfs_ino_t inlast
; /* last inode number */
1031 /* done = 1 if there are more stats to get and if bulkstat */
1032 /* should be called again (unused here, but used in dmapi) */
1034 if (!capable(CAP_SYS_ADMIN
))
1037 if (XFS_FORCED_SHUTDOWN(mp
))
1038 return -XFS_ERROR(EIO
);
1040 if (copy_from_user(&bulkreq
, arg
, sizeof(xfs_fsop_bulkreq_t
)))
1041 return -XFS_ERROR(EFAULT
);
1043 if (copy_from_user(&inlast
, bulkreq
.lastip
, sizeof(__s64
)))
1044 return -XFS_ERROR(EFAULT
);
1046 if ((count
= bulkreq
.icount
) <= 0)
1047 return -XFS_ERROR(EINVAL
);
1049 if (bulkreq
.ubuffer
== NULL
)
1050 return -XFS_ERROR(EINVAL
);
1052 if (cmd
== XFS_IOC_FSINUMBERS
)
1053 error
= xfs_inumbers(mp
, &inlast
, &count
,
1054 bulkreq
.ubuffer
, xfs_inumbers_fmt
);
1055 else if (cmd
== XFS_IOC_FSBULKSTAT_SINGLE
)
1056 error
= xfs_bulkstat_single(mp
, &inlast
,
1057 bulkreq
.ubuffer
, &done
);
1058 else /* XFS_IOC_FSBULKSTAT */
1059 error
= xfs_bulkstat(mp
, &inlast
, &count
,
1060 (bulkstat_one_pf
)xfs_bulkstat_one
, NULL
,
1061 sizeof(xfs_bstat_t
), bulkreq
.ubuffer
,
1062 BULKSTAT_FG_QUICK
, &done
);
1067 if (bulkreq
.ocount
!= NULL
) {
1068 if (copy_to_user(bulkreq
.lastip
, &inlast
,
1070 return -XFS_ERROR(EFAULT
);
1072 if (copy_to_user(bulkreq
.ocount
, &count
, sizeof(count
)))
1073 return -XFS_ERROR(EFAULT
);
1080 xfs_ioc_fsgeometry_v1(
1084 xfs_fsop_geom_v1_t fsgeo
;
1087 error
= xfs_fs_geometry(mp
, (xfs_fsop_geom_t
*)&fsgeo
, 3);
1091 if (copy_to_user(arg
, &fsgeo
, sizeof(fsgeo
)))
1092 return -XFS_ERROR(EFAULT
);
1101 xfs_fsop_geom_t fsgeo
;
1104 error
= xfs_fs_geometry(mp
, &fsgeo
, 4);
1108 if (copy_to_user(arg
, &fsgeo
, sizeof(fsgeo
)))
1109 return -XFS_ERROR(EFAULT
);
1114 * Linux extended inode flags interface.
1118 xfs_merge_ioc_xflags(
1122 unsigned int xflags
= start
;
1124 if (flags
& FS_IMMUTABLE_FL
)
1125 xflags
|= XFS_XFLAG_IMMUTABLE
;
1127 xflags
&= ~XFS_XFLAG_IMMUTABLE
;
1128 if (flags
& FS_APPEND_FL
)
1129 xflags
|= XFS_XFLAG_APPEND
;
1131 xflags
&= ~XFS_XFLAG_APPEND
;
1132 if (flags
& FS_SYNC_FL
)
1133 xflags
|= XFS_XFLAG_SYNC
;
1135 xflags
&= ~XFS_XFLAG_SYNC
;
1136 if (flags
& FS_NOATIME_FL
)
1137 xflags
|= XFS_XFLAG_NOATIME
;
1139 xflags
&= ~XFS_XFLAG_NOATIME
;
1140 if (flags
& FS_NODUMP_FL
)
1141 xflags
|= XFS_XFLAG_NODUMP
;
1143 xflags
&= ~XFS_XFLAG_NODUMP
;
1150 __uint16_t di_flags
)
1152 unsigned int flags
= 0;
1154 if (di_flags
& XFS_DIFLAG_IMMUTABLE
)
1155 flags
|= FS_IMMUTABLE_FL
;
1156 if (di_flags
& XFS_DIFLAG_APPEND
)
1157 flags
|= FS_APPEND_FL
;
1158 if (di_flags
& XFS_DIFLAG_SYNC
)
1159 flags
|= FS_SYNC_FL
;
1160 if (di_flags
& XFS_DIFLAG_NOATIME
)
1161 flags
|= FS_NOATIME_FL
;
1162 if (di_flags
& XFS_DIFLAG_NODUMP
)
1163 flags
|= FS_NODUMP_FL
;
1175 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
1176 fa
.fsx_xflags
= xfs_ip2xflags(ip
);
1177 fa
.fsx_extsize
= ip
->i_d
.di_extsize
<< ip
->i_mount
->m_sb
.sb_blocklog
;
1178 fa
.fsx_projid
= ip
->i_d
.di_projid
;
1182 if (ip
->i_afp
->if_flags
& XFS_IFEXTENTS
)
1183 fa
.fsx_nextents
= ip
->i_afp
->if_bytes
/
1184 sizeof(xfs_bmbt_rec_t
);
1186 fa
.fsx_nextents
= ip
->i_d
.di_anextents
;
1188 fa
.fsx_nextents
= 0;
1190 if (ip
->i_df
.if_flags
& XFS_IFEXTENTS
)
1191 fa
.fsx_nextents
= ip
->i_df
.if_bytes
/
1192 sizeof(xfs_bmbt_rec_t
);
1194 fa
.fsx_nextents
= ip
->i_d
.di_nextents
;
1196 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
1198 if (copy_to_user(arg
, &fa
, sizeof(fa
)))
1212 struct bhv_vattr
*vattr
;
1217 vattr
= kmalloc(sizeof(*vattr
), GFP_KERNEL
);
1218 if (unlikely(!vattr
))
1222 case XFS_IOC_FSSETXATTR
: {
1223 if (copy_from_user(&fa
, arg
, sizeof(fa
))) {
1229 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1230 attr_flags
|= ATTR_NONBLOCK
;
1232 vattr
->va_mask
= XFS_AT_XFLAGS
| XFS_AT_EXTSIZE
| XFS_AT_PROJID
;
1233 vattr
->va_xflags
= fa
.fsx_xflags
;
1234 vattr
->va_extsize
= fa
.fsx_extsize
;
1235 vattr
->va_projid
= fa
.fsx_projid
;
1237 error
= xfs_setattr(ip
, vattr
, attr_flags
, NULL
);
1239 vn_revalidate(vp
); /* update flags */
1244 case XFS_IOC_GETXFLAGS
: {
1245 flags
= xfs_di2lxflags(ip
->i_d
.di_flags
);
1246 if (copy_to_user(arg
, &flags
, sizeof(flags
)))
1251 case XFS_IOC_SETXFLAGS
: {
1252 if (copy_from_user(&flags
, arg
, sizeof(flags
))) {
1257 if (flags
& ~(FS_IMMUTABLE_FL
| FS_APPEND_FL
| \
1258 FS_NOATIME_FL
| FS_NODUMP_FL
| \
1260 error
= -EOPNOTSUPP
;
1265 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1266 attr_flags
|= ATTR_NONBLOCK
;
1268 vattr
->va_mask
= XFS_AT_XFLAGS
;
1269 vattr
->va_xflags
= xfs_merge_ioc_xflags(flags
,
1272 error
= xfs_setattr(ip
, vattr
, attr_flags
, NULL
);
1274 vn_revalidate(vp
); /* update flags */
1290 struct xfs_inode
*ip
,
1299 if (copy_from_user(&bm
, arg
, sizeof(bm
)))
1300 return -XFS_ERROR(EFAULT
);
1302 if (bm
.bmv_count
< 2)
1303 return -XFS_ERROR(EINVAL
);
1305 iflags
= (cmd
== XFS_IOC_GETBMAPA
? BMV_IF_ATTRFORK
: 0);
1306 if (ioflags
& IO_INVIS
)
1307 iflags
|= BMV_IF_NO_DMAPI_READ
;
1309 error
= xfs_getbmap(ip
, &bm
, (struct getbmap __user
*)arg
+1, iflags
);
1313 if (copy_to_user(arg
, &bm
, sizeof(bm
)))
1314 return -XFS_ERROR(EFAULT
);
1320 struct xfs_inode
*ip
,
1323 struct getbmapx bmx
;
1328 if (copy_from_user(&bmx
, arg
, sizeof(bmx
)))
1329 return -XFS_ERROR(EFAULT
);
1331 if (bmx
.bmv_count
< 2)
1332 return -XFS_ERROR(EINVAL
);
1335 * Map input getbmapx structure to a getbmap
1336 * structure for xfs_getbmap.
1338 GETBMAP_CONVERT(bmx
, bm
);
1340 iflags
= bmx
.bmv_iflags
;
1342 if (iflags
& (~BMV_IF_VALID
))
1343 return -XFS_ERROR(EINVAL
);
1345 iflags
|= BMV_IF_EXTENDED
;
1347 error
= xfs_getbmap(ip
, &bm
, (struct getbmapx __user
*)arg
+1, iflags
);
1351 GETBMAP_CONVERT(bm
, bmx
);
1353 if (copy_to_user(arg
, &bmx
, sizeof(bmx
)))
1354 return -XFS_ERROR(EFAULT
);