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
20 #include "xfs_shared.h"
21 #include "xfs_format.h"
22 #include "xfs_log_format.h"
23 #include "xfs_trans_resv.h"
26 #include "xfs_alloc.h"
27 #include "xfs_mount.h"
28 #include "xfs_bmap_btree.h"
29 #include "xfs_dinode.h"
30 #include "xfs_inode.h"
31 #include "xfs_ioctl.h"
32 #include "xfs_rtalloc.h"
33 #include "xfs_itable.h"
34 #include "xfs_error.h"
37 #include "xfs_bmap_util.h"
38 #include "xfs_trans.h"
39 #include "xfs_buf_item.h"
40 #include "xfs_fsops.h"
41 #include "xfs_discard.h"
42 #include "xfs_quota.h"
43 #include "xfs_inode_item.h"
44 #include "xfs_export.h"
45 #include "xfs_trace.h"
46 #include "xfs_icache.h"
47 #include "xfs_symlink.h"
49 #include <linux/capability.h>
50 #include <linux/dcache.h>
51 #include <linux/mount.h>
52 #include <linux/namei.h>
53 #include <linux/pagemap.h>
54 #include <linux/slab.h>
55 #include <linux/exportfs.h>
58 * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to
59 * a file or fs handle.
61 * XFS_IOC_PATH_TO_FSHANDLE
62 * returns fs handle for a mount point or path within that mount point
63 * XFS_IOC_FD_TO_HANDLE
64 * returns full handle for a FD opened in user space
65 * XFS_IOC_PATH_TO_HANDLE
66 * returns full handle for a path
71 xfs_fsop_handlereq_t
*hreq
)
81 if (cmd
== XFS_IOC_FD_TO_HANDLE
) {
85 inode
= file_inode(f
.file
);
87 error
= user_lpath((const char __user
*)hreq
->path
, &path
);
90 inode
= path
.dentry
->d_inode
;
95 * We can only generate handles for inodes residing on a XFS filesystem,
96 * and only for regular files, directories or symbolic links.
99 if (inode
->i_sb
->s_magic
!= XFS_SB_MAGIC
)
103 if (!S_ISREG(inode
->i_mode
) &&
104 !S_ISDIR(inode
->i_mode
) &&
105 !S_ISLNK(inode
->i_mode
))
109 memcpy(&handle
.ha_fsid
, ip
->i_mount
->m_fixedfsid
, sizeof(xfs_fsid_t
));
111 if (cmd
== XFS_IOC_PATH_TO_FSHANDLE
) {
113 * This handle only contains an fsid, zero the rest.
115 memset(&handle
.ha_fid
, 0, sizeof(handle
.ha_fid
));
116 hsize
= sizeof(xfs_fsid_t
);
120 lock_mode
= xfs_ilock_map_shared(ip
);
121 handle
.ha_fid
.fid_len
= sizeof(xfs_fid_t
) -
122 sizeof(handle
.ha_fid
.fid_len
);
123 handle
.ha_fid
.fid_pad
= 0;
124 handle
.ha_fid
.fid_gen
= ip
->i_d
.di_gen
;
125 handle
.ha_fid
.fid_ino
= ip
->i_ino
;
126 xfs_iunlock_map_shared(ip
, lock_mode
);
128 hsize
= XFS_HSIZE(handle
);
132 if (copy_to_user(hreq
->ohandle
, &handle
, hsize
) ||
133 copy_to_user(hreq
->ohandlen
, &hsize
, sizeof(__s32
)))
139 if (cmd
== XFS_IOC_FD_TO_HANDLE
)
147 * No need to do permission checks on the various pathname components
148 * as the handle operations are privileged.
151 xfs_handle_acceptable(
153 struct dentry
*dentry
)
159 * Convert userspace handle data into a dentry.
162 xfs_handle_to_dentry(
163 struct file
*parfilp
,
164 void __user
*uhandle
,
168 struct xfs_fid64 fid
;
171 * Only allow handle opens under a directory.
173 if (!S_ISDIR(file_inode(parfilp
)->i_mode
))
174 return ERR_PTR(-ENOTDIR
);
176 if (hlen
!= sizeof(xfs_handle_t
))
177 return ERR_PTR(-EINVAL
);
178 if (copy_from_user(&handle
, uhandle
, hlen
))
179 return ERR_PTR(-EFAULT
);
180 if (handle
.ha_fid
.fid_len
!=
181 sizeof(handle
.ha_fid
) - sizeof(handle
.ha_fid
.fid_len
))
182 return ERR_PTR(-EINVAL
);
184 memset(&fid
, 0, sizeof(struct fid
));
185 fid
.ino
= handle
.ha_fid
.fid_ino
;
186 fid
.gen
= handle
.ha_fid
.fid_gen
;
188 return exportfs_decode_fh(parfilp
->f_path
.mnt
, (struct fid
*)&fid
, 3,
189 FILEID_INO32_GEN
| XFS_FILEID_TYPE_64FLAG
,
190 xfs_handle_acceptable
, NULL
);
193 STATIC
struct dentry
*
194 xfs_handlereq_to_dentry(
195 struct file
*parfilp
,
196 xfs_fsop_handlereq_t
*hreq
)
198 return xfs_handle_to_dentry(parfilp
, hreq
->ihandle
, hreq
->ihandlen
);
203 struct file
*parfilp
,
204 xfs_fsop_handlereq_t
*hreq
)
206 const struct cred
*cred
= current_cred();
212 struct dentry
*dentry
;
216 if (!capable(CAP_SYS_ADMIN
))
217 return -XFS_ERROR(EPERM
);
219 dentry
= xfs_handlereq_to_dentry(parfilp
, hreq
);
221 return PTR_ERR(dentry
);
222 inode
= dentry
->d_inode
;
224 /* Restrict xfs_open_by_handle to directories & regular files. */
225 if (!(S_ISREG(inode
->i_mode
) || S_ISDIR(inode
->i_mode
))) {
226 error
= -XFS_ERROR(EPERM
);
230 #if BITS_PER_LONG != 32
231 hreq
->oflags
|= O_LARGEFILE
;
234 permflag
= hreq
->oflags
;
235 fmode
= OPEN_FMODE(permflag
);
236 if ((!(permflag
& O_APPEND
) || (permflag
& O_TRUNC
)) &&
237 (fmode
& FMODE_WRITE
) && IS_APPEND(inode
)) {
238 error
= -XFS_ERROR(EPERM
);
242 if ((fmode
& FMODE_WRITE
) && IS_IMMUTABLE(inode
)) {
243 error
= -XFS_ERROR(EACCES
);
247 /* Can't write directories. */
248 if (S_ISDIR(inode
->i_mode
) && (fmode
& FMODE_WRITE
)) {
249 error
= -XFS_ERROR(EISDIR
);
253 fd
= get_unused_fd_flags(0);
259 path
.mnt
= parfilp
->f_path
.mnt
;
260 path
.dentry
= dentry
;
261 filp
= dentry_open(&path
, hreq
->oflags
, cred
);
265 return PTR_ERR(filp
);
268 if (S_ISREG(inode
->i_mode
)) {
269 filp
->f_flags
|= O_NOATIME
;
270 filp
->f_mode
|= FMODE_NOCMTIME
;
273 fd_install(fd
, filp
);
282 * This is a copy from fs/namei.c:vfs_readlink(), except for removing it's
283 * unused first argument.
298 if (len
> (unsigned) buflen
)
300 if (copy_to_user(buffer
, link
, len
))
308 xfs_readlink_by_handle(
309 struct file
*parfilp
,
310 xfs_fsop_handlereq_t
*hreq
)
312 struct dentry
*dentry
;
317 if (!capable(CAP_SYS_ADMIN
))
318 return -XFS_ERROR(EPERM
);
320 dentry
= xfs_handlereq_to_dentry(parfilp
, hreq
);
322 return PTR_ERR(dentry
);
324 /* Restrict this handle operation to symlinks only. */
325 if (!S_ISLNK(dentry
->d_inode
->i_mode
)) {
326 error
= -XFS_ERROR(EINVAL
);
330 if (copy_from_user(&olen
, hreq
->ohandlen
, sizeof(__u32
))) {
331 error
= -XFS_ERROR(EFAULT
);
335 link
= kmalloc(MAXPATHLEN
+1, GFP_KERNEL
);
337 error
= -XFS_ERROR(ENOMEM
);
341 error
= -xfs_readlink(XFS_I(dentry
->d_inode
), link
);
344 error
= do_readlink(hreq
->ohandle
, olen
, link
);
361 xfs_mount_t
*mp
= ip
->i_mount
;
365 if (!capable(CAP_SYS_ADMIN
))
366 return XFS_ERROR(EPERM
);
368 if (XFS_FORCED_SHUTDOWN(mp
))
369 return XFS_ERROR(EIO
);
371 tp
= xfs_trans_alloc(mp
, XFS_TRANS_SET_DMATTRS
);
372 error
= xfs_trans_reserve(tp
, &M_RES(mp
)->tr_ichange
, 0, 0);
374 xfs_trans_cancel(tp
, 0);
377 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
378 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
);
380 ip
->i_d
.di_dmevmask
= evmask
;
381 ip
->i_d
.di_dmstate
= state
;
383 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
384 error
= xfs_trans_commit(tp
, 0);
390 xfs_fssetdm_by_handle(
391 struct file
*parfilp
,
395 struct fsdmidata fsd
;
396 xfs_fsop_setdm_handlereq_t dmhreq
;
397 struct dentry
*dentry
;
399 if (!capable(CAP_MKNOD
))
400 return -XFS_ERROR(EPERM
);
401 if (copy_from_user(&dmhreq
, arg
, sizeof(xfs_fsop_setdm_handlereq_t
)))
402 return -XFS_ERROR(EFAULT
);
404 error
= mnt_want_write_file(parfilp
);
408 dentry
= xfs_handlereq_to_dentry(parfilp
, &dmhreq
.hreq
);
409 if (IS_ERR(dentry
)) {
410 mnt_drop_write_file(parfilp
);
411 return PTR_ERR(dentry
);
414 if (IS_IMMUTABLE(dentry
->d_inode
) || IS_APPEND(dentry
->d_inode
)) {
415 error
= -XFS_ERROR(EPERM
);
419 if (copy_from_user(&fsd
, dmhreq
.data
, sizeof(fsd
))) {
420 error
= -XFS_ERROR(EFAULT
);
424 error
= -xfs_set_dmattrs(XFS_I(dentry
->d_inode
), fsd
.fsd_dmevmask
,
428 mnt_drop_write_file(parfilp
);
434 xfs_attrlist_by_handle(
435 struct file
*parfilp
,
439 attrlist_cursor_kern_t
*cursor
;
440 xfs_fsop_attrlist_handlereq_t al_hreq
;
441 struct dentry
*dentry
;
444 if (!capable(CAP_SYS_ADMIN
))
445 return -XFS_ERROR(EPERM
);
446 if (copy_from_user(&al_hreq
, arg
, sizeof(xfs_fsop_attrlist_handlereq_t
)))
447 return -XFS_ERROR(EFAULT
);
448 if (al_hreq
.buflen
> XATTR_LIST_MAX
)
449 return -XFS_ERROR(EINVAL
);
452 * Reject flags, only allow namespaces.
454 if (al_hreq
.flags
& ~(ATTR_ROOT
| ATTR_SECURE
))
455 return -XFS_ERROR(EINVAL
);
457 dentry
= xfs_handlereq_to_dentry(parfilp
, &al_hreq
.hreq
);
459 return PTR_ERR(dentry
);
461 kbuf
= kmem_zalloc_large(al_hreq
.buflen
, KM_SLEEP
);
465 cursor
= (attrlist_cursor_kern_t
*)&al_hreq
.pos
;
466 error
= -xfs_attr_list(XFS_I(dentry
->d_inode
), kbuf
, al_hreq
.buflen
,
467 al_hreq
.flags
, cursor
);
471 if (copy_to_user(al_hreq
.buffer
, kbuf
, al_hreq
.buflen
))
482 xfs_attrmulti_attr_get(
485 unsigned char __user
*ubuf
,
492 if (*len
> XATTR_SIZE_MAX
)
494 kbuf
= kmem_zalloc_large(*len
, KM_SLEEP
);
498 error
= xfs_attr_get(XFS_I(inode
), name
, kbuf
, (int *)len
, flags
);
502 if (copy_to_user(ubuf
, kbuf
, *len
))
511 xfs_attrmulti_attr_set(
514 const unsigned char __user
*ubuf
,
521 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
523 if (len
> XATTR_SIZE_MAX
)
526 kbuf
= memdup_user(ubuf
, len
);
528 return PTR_ERR(kbuf
);
530 error
= xfs_attr_set(XFS_I(inode
), name
, kbuf
, len
, flags
);
536 xfs_attrmulti_attr_remove(
541 if (IS_IMMUTABLE(inode
) || IS_APPEND(inode
))
543 return xfs_attr_remove(XFS_I(inode
), name
, flags
);
547 xfs_attrmulti_by_handle(
548 struct file
*parfilp
,
552 xfs_attr_multiop_t
*ops
;
553 xfs_fsop_attrmulti_handlereq_t am_hreq
;
554 struct dentry
*dentry
;
555 unsigned int i
, size
;
556 unsigned char *attr_name
;
558 if (!capable(CAP_SYS_ADMIN
))
559 return -XFS_ERROR(EPERM
);
560 if (copy_from_user(&am_hreq
, arg
, sizeof(xfs_fsop_attrmulti_handlereq_t
)))
561 return -XFS_ERROR(EFAULT
);
564 if (am_hreq
.opcount
>= INT_MAX
/ sizeof(xfs_attr_multiop_t
))
567 dentry
= xfs_handlereq_to_dentry(parfilp
, &am_hreq
.hreq
);
569 return PTR_ERR(dentry
);
572 size
= am_hreq
.opcount
* sizeof(xfs_attr_multiop_t
);
573 if (!size
|| size
> 16 * PAGE_SIZE
)
576 ops
= memdup_user(am_hreq
.ops
, size
);
578 error
= PTR_ERR(ops
);
582 attr_name
= kmalloc(MAXNAMELEN
, GFP_KERNEL
);
587 for (i
= 0; i
< am_hreq
.opcount
; i
++) {
588 ops
[i
].am_error
= strncpy_from_user((char *)attr_name
,
589 ops
[i
].am_attrname
, MAXNAMELEN
);
590 if (ops
[i
].am_error
== 0 || ops
[i
].am_error
== MAXNAMELEN
)
592 if (ops
[i
].am_error
< 0)
595 switch (ops
[i
].am_opcode
) {
597 ops
[i
].am_error
= xfs_attrmulti_attr_get(
598 dentry
->d_inode
, attr_name
,
599 ops
[i
].am_attrvalue
, &ops
[i
].am_length
,
603 ops
[i
].am_error
= mnt_want_write_file(parfilp
);
606 ops
[i
].am_error
= xfs_attrmulti_attr_set(
607 dentry
->d_inode
, attr_name
,
608 ops
[i
].am_attrvalue
, ops
[i
].am_length
,
610 mnt_drop_write_file(parfilp
);
613 ops
[i
].am_error
= mnt_want_write_file(parfilp
);
616 ops
[i
].am_error
= xfs_attrmulti_attr_remove(
617 dentry
->d_inode
, attr_name
,
619 mnt_drop_write_file(parfilp
);
622 ops
[i
].am_error
= EINVAL
;
626 if (copy_to_user(am_hreq
.ops
, ops
, size
))
627 error
= XFS_ERROR(EFAULT
);
639 struct xfs_inode
*ip
,
646 struct xfs_mount
*mp
= ip
->i_mount
;
647 struct xfs_trans
*tp
;
649 bool setprealloc
= false;
650 bool clrprealloc
= false;
654 * Only allow the sys admin to reserve space unless
655 * unwritten extents are enabled.
657 if (!xfs_sb_version_hasextflgbit(&ip
->i_mount
->m_sb
) &&
658 !capable(CAP_SYS_ADMIN
))
659 return -XFS_ERROR(EPERM
);
661 if (inode
->i_flags
& (S_IMMUTABLE
|S_APPEND
))
662 return -XFS_ERROR(EPERM
);
664 if (!(filp
->f_mode
& FMODE_WRITE
))
665 return -XFS_ERROR(EBADF
);
667 if (!S_ISREG(inode
->i_mode
))
668 return -XFS_ERROR(EINVAL
);
670 error
= mnt_want_write_file(filp
);
674 xfs_ilock(ip
, XFS_IOLOCK_EXCL
);
676 switch (bf
->l_whence
) {
680 bf
->l_start
+= filp
->f_pos
;
683 bf
->l_start
+= XFS_ISIZE(ip
);
686 error
= XFS_ERROR(EINVAL
);
691 * length of <= 0 for resv/unresv/zero is invalid. length for
692 * alloc/free is ignored completely and we have no idea what userspace
693 * might have set it to, so set it to zero to allow range
697 case XFS_IOC_ZERO_RANGE
:
699 case XFS_IOC_RESVSP64
:
700 case XFS_IOC_UNRESVSP
:
701 case XFS_IOC_UNRESVSP64
:
702 if (bf
->l_len
<= 0) {
703 error
= XFS_ERROR(EINVAL
);
712 if (bf
->l_start
< 0 ||
713 bf
->l_start
> mp
->m_super
->s_maxbytes
||
714 bf
->l_start
+ bf
->l_len
< 0 ||
715 bf
->l_start
+ bf
->l_len
>= mp
->m_super
->s_maxbytes
) {
716 error
= XFS_ERROR(EINVAL
);
721 case XFS_IOC_ZERO_RANGE
:
722 error
= xfs_zero_file_space(ip
, bf
->l_start
, bf
->l_len
);
727 case XFS_IOC_RESVSP64
:
728 error
= xfs_alloc_file_space(ip
, bf
->l_start
, bf
->l_len
,
733 case XFS_IOC_UNRESVSP
:
734 case XFS_IOC_UNRESVSP64
:
735 error
= xfs_free_file_space(ip
, bf
->l_start
, bf
->l_len
);
737 case XFS_IOC_ALLOCSP
:
738 case XFS_IOC_ALLOCSP64
:
740 case XFS_IOC_FREESP64
:
741 if (bf
->l_start
> XFS_ISIZE(ip
)) {
742 error
= xfs_alloc_file_space(ip
, XFS_ISIZE(ip
),
743 bf
->l_start
- XFS_ISIZE(ip
), 0);
748 iattr
.ia_valid
= ATTR_SIZE
;
749 iattr
.ia_size
= bf
->l_start
;
751 error
= xfs_setattr_size(ip
, &iattr
);
757 error
= XFS_ERROR(EINVAL
);
763 tp
= xfs_trans_alloc(mp
, XFS_TRANS_WRITEID
);
764 error
= xfs_trans_reserve(tp
, &M_RES(mp
)->tr_writeid
, 0, 0);
766 xfs_trans_cancel(tp
, 0);
770 xfs_ilock(ip
, XFS_ILOCK_EXCL
);
771 xfs_trans_ijoin(tp
, ip
, XFS_ILOCK_EXCL
);
773 if (!(ioflags
& IO_INVIS
)) {
774 ip
->i_d
.di_mode
&= ~S_ISUID
;
775 if (ip
->i_d
.di_mode
& S_IXGRP
)
776 ip
->i_d
.di_mode
&= ~S_ISGID
;
777 xfs_trans_ichgtime(tp
, ip
, XFS_ICHGTIME_MOD
| XFS_ICHGTIME_CHG
);
781 ip
->i_d
.di_flags
|= XFS_DIFLAG_PREALLOC
;
782 else if (clrprealloc
)
783 ip
->i_d
.di_flags
&= ~XFS_DIFLAG_PREALLOC
;
785 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
786 if (filp
->f_flags
& O_DSYNC
)
787 xfs_trans_set_sync(tp
);
788 error
= xfs_trans_commit(tp
, 0);
791 xfs_iunlock(ip
, XFS_IOLOCK_EXCL
);
792 mnt_drop_write_file(filp
);
802 xfs_fsop_bulkreq_t bulkreq
;
803 int count
; /* # of records returned */
804 xfs_ino_t inlast
; /* last inode number */
808 /* done = 1 if there are more stats to get and if bulkstat */
809 /* should be called again (unused here, but used in dmapi) */
811 if (!capable(CAP_SYS_ADMIN
))
814 if (XFS_FORCED_SHUTDOWN(mp
))
815 return -XFS_ERROR(EIO
);
817 if (copy_from_user(&bulkreq
, arg
, sizeof(xfs_fsop_bulkreq_t
)))
818 return -XFS_ERROR(EFAULT
);
820 if (copy_from_user(&inlast
, bulkreq
.lastip
, sizeof(__s64
)))
821 return -XFS_ERROR(EFAULT
);
823 if ((count
= bulkreq
.icount
) <= 0)
824 return -XFS_ERROR(EINVAL
);
826 if (bulkreq
.ubuffer
== NULL
)
827 return -XFS_ERROR(EINVAL
);
829 if (cmd
== XFS_IOC_FSINUMBERS
)
830 error
= xfs_inumbers(mp
, &inlast
, &count
,
831 bulkreq
.ubuffer
, xfs_inumbers_fmt
);
832 else if (cmd
== XFS_IOC_FSBULKSTAT_SINGLE
)
833 error
= xfs_bulkstat_single(mp
, &inlast
,
834 bulkreq
.ubuffer
, &done
);
835 else /* XFS_IOC_FSBULKSTAT */
836 error
= xfs_bulkstat(mp
, &inlast
, &count
, xfs_bulkstat_one
,
837 sizeof(xfs_bstat_t
), bulkreq
.ubuffer
,
843 if (bulkreq
.ocount
!= NULL
) {
844 if (copy_to_user(bulkreq
.lastip
, &inlast
,
846 return -XFS_ERROR(EFAULT
);
848 if (copy_to_user(bulkreq
.ocount
, &count
, sizeof(count
)))
849 return -XFS_ERROR(EFAULT
);
856 xfs_ioc_fsgeometry_v1(
860 xfs_fsop_geom_t fsgeo
;
863 error
= xfs_fs_geometry(mp
, &fsgeo
, 3);
868 * Caller should have passed an argument of type
869 * xfs_fsop_geom_v1_t. This is a proper subset of the
870 * xfs_fsop_geom_t that xfs_fs_geometry() fills in.
872 if (copy_to_user(arg
, &fsgeo
, sizeof(xfs_fsop_geom_v1_t
)))
873 return -XFS_ERROR(EFAULT
);
882 xfs_fsop_geom_t fsgeo
;
885 error
= xfs_fs_geometry(mp
, &fsgeo
, 4);
889 if (copy_to_user(arg
, &fsgeo
, sizeof(fsgeo
)))
890 return -XFS_ERROR(EFAULT
);
895 * Linux extended inode flags interface.
899 xfs_merge_ioc_xflags(
903 unsigned int xflags
= start
;
905 if (flags
& FS_IMMUTABLE_FL
)
906 xflags
|= XFS_XFLAG_IMMUTABLE
;
908 xflags
&= ~XFS_XFLAG_IMMUTABLE
;
909 if (flags
& FS_APPEND_FL
)
910 xflags
|= XFS_XFLAG_APPEND
;
912 xflags
&= ~XFS_XFLAG_APPEND
;
913 if (flags
& FS_SYNC_FL
)
914 xflags
|= XFS_XFLAG_SYNC
;
916 xflags
&= ~XFS_XFLAG_SYNC
;
917 if (flags
& FS_NOATIME_FL
)
918 xflags
|= XFS_XFLAG_NOATIME
;
920 xflags
&= ~XFS_XFLAG_NOATIME
;
921 if (flags
& FS_NODUMP_FL
)
922 xflags
|= XFS_XFLAG_NODUMP
;
924 xflags
&= ~XFS_XFLAG_NODUMP
;
933 unsigned int flags
= 0;
935 if (di_flags
& XFS_DIFLAG_IMMUTABLE
)
936 flags
|= FS_IMMUTABLE_FL
;
937 if (di_flags
& XFS_DIFLAG_APPEND
)
938 flags
|= FS_APPEND_FL
;
939 if (di_flags
& XFS_DIFLAG_SYNC
)
941 if (di_flags
& XFS_DIFLAG_NOATIME
)
942 flags
|= FS_NOATIME_FL
;
943 if (di_flags
& XFS_DIFLAG_NODUMP
)
944 flags
|= FS_NODUMP_FL
;
956 memset(&fa
, 0, sizeof(struct fsxattr
));
958 xfs_ilock(ip
, XFS_ILOCK_SHARED
);
959 fa
.fsx_xflags
= xfs_ip2xflags(ip
);
960 fa
.fsx_extsize
= ip
->i_d
.di_extsize
<< ip
->i_mount
->m_sb
.sb_blocklog
;
961 fa
.fsx_projid
= xfs_get_projid(ip
);
965 if (ip
->i_afp
->if_flags
& XFS_IFEXTENTS
)
966 fa
.fsx_nextents
= ip
->i_afp
->if_bytes
/
967 sizeof(xfs_bmbt_rec_t
);
969 fa
.fsx_nextents
= ip
->i_d
.di_anextents
;
973 if (ip
->i_df
.if_flags
& XFS_IFEXTENTS
)
974 fa
.fsx_nextents
= ip
->i_df
.if_bytes
/
975 sizeof(xfs_bmbt_rec_t
);
977 fa
.fsx_nextents
= ip
->i_d
.di_nextents
;
979 xfs_iunlock(ip
, XFS_ILOCK_SHARED
);
981 if (copy_to_user(arg
, &fa
, sizeof(fa
)))
988 struct xfs_inode
*ip
,
991 unsigned int di_flags
;
993 /* can't set PREALLOC this way, just preserve it */
994 di_flags
= (ip
->i_d
.di_flags
& XFS_DIFLAG_PREALLOC
);
995 if (xflags
& XFS_XFLAG_IMMUTABLE
)
996 di_flags
|= XFS_DIFLAG_IMMUTABLE
;
997 if (xflags
& XFS_XFLAG_APPEND
)
998 di_flags
|= XFS_DIFLAG_APPEND
;
999 if (xflags
& XFS_XFLAG_SYNC
)
1000 di_flags
|= XFS_DIFLAG_SYNC
;
1001 if (xflags
& XFS_XFLAG_NOATIME
)
1002 di_flags
|= XFS_DIFLAG_NOATIME
;
1003 if (xflags
& XFS_XFLAG_NODUMP
)
1004 di_flags
|= XFS_DIFLAG_NODUMP
;
1005 if (xflags
& XFS_XFLAG_PROJINHERIT
)
1006 di_flags
|= XFS_DIFLAG_PROJINHERIT
;
1007 if (xflags
& XFS_XFLAG_NODEFRAG
)
1008 di_flags
|= XFS_DIFLAG_NODEFRAG
;
1009 if (xflags
& XFS_XFLAG_FILESTREAM
)
1010 di_flags
|= XFS_DIFLAG_FILESTREAM
;
1011 if (S_ISDIR(ip
->i_d
.di_mode
)) {
1012 if (xflags
& XFS_XFLAG_RTINHERIT
)
1013 di_flags
|= XFS_DIFLAG_RTINHERIT
;
1014 if (xflags
& XFS_XFLAG_NOSYMLINKS
)
1015 di_flags
|= XFS_DIFLAG_NOSYMLINKS
;
1016 if (xflags
& XFS_XFLAG_EXTSZINHERIT
)
1017 di_flags
|= XFS_DIFLAG_EXTSZINHERIT
;
1018 } else if (S_ISREG(ip
->i_d
.di_mode
)) {
1019 if (xflags
& XFS_XFLAG_REALTIME
)
1020 di_flags
|= XFS_DIFLAG_REALTIME
;
1021 if (xflags
& XFS_XFLAG_EXTSIZE
)
1022 di_flags
|= XFS_DIFLAG_EXTSIZE
;
1025 ip
->i_d
.di_flags
= di_flags
;
1029 xfs_diflags_to_linux(
1030 struct xfs_inode
*ip
)
1032 struct inode
*inode
= VFS_I(ip
);
1033 unsigned int xflags
= xfs_ip2xflags(ip
);
1035 if (xflags
& XFS_XFLAG_IMMUTABLE
)
1036 inode
->i_flags
|= S_IMMUTABLE
;
1038 inode
->i_flags
&= ~S_IMMUTABLE
;
1039 if (xflags
& XFS_XFLAG_APPEND
)
1040 inode
->i_flags
|= S_APPEND
;
1042 inode
->i_flags
&= ~S_APPEND
;
1043 if (xflags
& XFS_XFLAG_SYNC
)
1044 inode
->i_flags
|= S_SYNC
;
1046 inode
->i_flags
&= ~S_SYNC
;
1047 if (xflags
& XFS_XFLAG_NOATIME
)
1048 inode
->i_flags
|= S_NOATIME
;
1050 inode
->i_flags
&= ~S_NOATIME
;
1053 #define FSX_PROJID 1
1054 #define FSX_EXTSIZE 2
1055 #define FSX_XFLAGS 4
1056 #define FSX_NONBLOCK 8
1064 struct xfs_mount
*mp
= ip
->i_mount
;
1065 struct xfs_trans
*tp
;
1066 unsigned int lock_flags
= 0;
1067 struct xfs_dquot
*udqp
= NULL
;
1068 struct xfs_dquot
*pdqp
= NULL
;
1069 struct xfs_dquot
*olddquot
= NULL
;
1072 trace_xfs_ioctl_setattr(ip
);
1074 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
1075 return XFS_ERROR(EROFS
);
1076 if (XFS_FORCED_SHUTDOWN(mp
))
1077 return XFS_ERROR(EIO
);
1080 * Disallow 32bit project ids when projid32bit feature is not enabled.
1082 if ((mask
& FSX_PROJID
) && (fa
->fsx_projid
> (__uint16_t
)-1) &&
1083 !xfs_sb_version_hasprojid32bit(&ip
->i_mount
->m_sb
))
1084 return XFS_ERROR(EINVAL
);
1087 * If disk quotas is on, we make sure that the dquots do exist on disk,
1088 * before we start any other transactions. Trying to do this later
1089 * is messy. We don't care to take a readlock to look at the ids
1090 * in inode here, because we can't hold it across the trans_reserve.
1091 * If the IDs do change before we take the ilock, we're covered
1092 * because the i_*dquot fields will get updated anyway.
1094 if (XFS_IS_QUOTA_ON(mp
) && (mask
& FSX_PROJID
)) {
1095 code
= xfs_qm_vop_dqalloc(ip
, ip
->i_d
.di_uid
,
1096 ip
->i_d
.di_gid
, fa
->fsx_projid
,
1097 XFS_QMOPT_PQUOTA
, &udqp
, NULL
, &pdqp
);
1103 * For the other attributes, we acquire the inode lock and
1104 * first do an error checking pass.
1106 tp
= xfs_trans_alloc(mp
, XFS_TRANS_SETATTR_NOT_SIZE
);
1107 code
= xfs_trans_reserve(tp
, &M_RES(mp
)->tr_ichange
, 0, 0);
1111 lock_flags
= XFS_ILOCK_EXCL
;
1112 xfs_ilock(ip
, lock_flags
);
1115 * CAP_FOWNER overrides the following restrictions:
1117 * The user ID of the calling process must be equal
1118 * to the file owner ID, except in cases where the
1119 * CAP_FSETID capability is applicable.
1121 if (!inode_owner_or_capable(VFS_I(ip
))) {
1122 code
= XFS_ERROR(EPERM
);
1127 * Do a quota reservation only if projid is actually going to change.
1128 * Only allow changing of projid from init_user_ns since it is a
1129 * non user namespace aware identifier.
1131 if (mask
& FSX_PROJID
) {
1132 if (current_user_ns() != &init_user_ns
) {
1133 code
= XFS_ERROR(EINVAL
);
1137 if (XFS_IS_QUOTA_RUNNING(mp
) &&
1138 XFS_IS_PQUOTA_ON(mp
) &&
1139 xfs_get_projid(ip
) != fa
->fsx_projid
) {
1141 code
= xfs_qm_vop_chown_reserve(tp
, ip
, udqp
, NULL
,
1142 pdqp
, capable(CAP_FOWNER
) ?
1143 XFS_QMOPT_FORCE_RES
: 0);
1144 if (code
) /* out of quota */
1149 if (mask
& FSX_EXTSIZE
) {
1151 * Can't change extent size if any extents are allocated.
1153 if (ip
->i_d
.di_nextents
&&
1154 ((ip
->i_d
.di_extsize
<< mp
->m_sb
.sb_blocklog
) !=
1156 code
= XFS_ERROR(EINVAL
); /* EFBIG? */
1161 * Extent size must be a multiple of the appropriate block
1162 * size, if set at all. It must also be smaller than the
1163 * maximum extent size supported by the filesystem.
1165 * Also, for non-realtime files, limit the extent size hint to
1166 * half the size of the AGs in the filesystem so alignment
1167 * doesn't result in extents larger than an AG.
1169 if (fa
->fsx_extsize
!= 0) {
1171 xfs_fsblock_t extsize_fsb
;
1173 extsize_fsb
= XFS_B_TO_FSB(mp
, fa
->fsx_extsize
);
1174 if (extsize_fsb
> MAXEXTLEN
) {
1175 code
= XFS_ERROR(EINVAL
);
1179 if (XFS_IS_REALTIME_INODE(ip
) ||
1180 ((mask
& FSX_XFLAGS
) &&
1181 (fa
->fsx_xflags
& XFS_XFLAG_REALTIME
))) {
1182 size
= mp
->m_sb
.sb_rextsize
<<
1183 mp
->m_sb
.sb_blocklog
;
1185 size
= mp
->m_sb
.sb_blocksize
;
1186 if (extsize_fsb
> mp
->m_sb
.sb_agblocks
/ 2) {
1187 code
= XFS_ERROR(EINVAL
);
1192 if (fa
->fsx_extsize
% size
) {
1193 code
= XFS_ERROR(EINVAL
);
1200 if (mask
& FSX_XFLAGS
) {
1202 * Can't change realtime flag if any extents are allocated.
1204 if ((ip
->i_d
.di_nextents
|| ip
->i_delayed_blks
) &&
1205 (XFS_IS_REALTIME_INODE(ip
)) !=
1206 (fa
->fsx_xflags
& XFS_XFLAG_REALTIME
)) {
1207 code
= XFS_ERROR(EINVAL
); /* EFBIG? */
1212 * If realtime flag is set then must have realtime data.
1214 if ((fa
->fsx_xflags
& XFS_XFLAG_REALTIME
)) {
1215 if ((mp
->m_sb
.sb_rblocks
== 0) ||
1216 (mp
->m_sb
.sb_rextsize
== 0) ||
1217 (ip
->i_d
.di_extsize
% mp
->m_sb
.sb_rextsize
)) {
1218 code
= XFS_ERROR(EINVAL
);
1224 * Can't modify an immutable/append-only file unless
1225 * we have appropriate permission.
1227 if ((ip
->i_d
.di_flags
&
1228 (XFS_DIFLAG_IMMUTABLE
|XFS_DIFLAG_APPEND
) ||
1230 (XFS_XFLAG_IMMUTABLE
| XFS_XFLAG_APPEND
))) &&
1231 !capable(CAP_LINUX_IMMUTABLE
)) {
1232 code
= XFS_ERROR(EPERM
);
1237 xfs_trans_ijoin(tp
, ip
, 0);
1240 * Change file ownership. Must be the owner or privileged.
1242 if (mask
& FSX_PROJID
) {
1244 * CAP_FSETID overrides the following restrictions:
1246 * The set-user-ID and set-group-ID bits of a file will be
1247 * cleared upon successful return from chown()
1249 if ((ip
->i_d
.di_mode
& (S_ISUID
|S_ISGID
)) &&
1250 !inode_capable(VFS_I(ip
), CAP_FSETID
))
1251 ip
->i_d
.di_mode
&= ~(S_ISUID
|S_ISGID
);
1254 * Change the ownerships and register quota modifications
1255 * in the transaction.
1257 if (xfs_get_projid(ip
) != fa
->fsx_projid
) {
1258 if (XFS_IS_QUOTA_RUNNING(mp
) && XFS_IS_PQUOTA_ON(mp
)) {
1259 olddquot
= xfs_qm_vop_chown(tp
, ip
,
1260 &ip
->i_pdquot
, pdqp
);
1262 xfs_set_projid(ip
, fa
->fsx_projid
);
1265 * We may have to rev the inode as well as
1266 * the superblock version number since projids didn't
1267 * exist before DINODE_VERSION_2 and SB_VERSION_NLINK.
1269 if (ip
->i_d
.di_version
== 1)
1270 xfs_bump_ino_vers2(tp
, ip
);
1275 if (mask
& FSX_EXTSIZE
)
1276 ip
->i_d
.di_extsize
= fa
->fsx_extsize
>> mp
->m_sb
.sb_blocklog
;
1277 if (mask
& FSX_XFLAGS
) {
1278 xfs_set_diflags(ip
, fa
->fsx_xflags
);
1279 xfs_diflags_to_linux(ip
);
1282 xfs_trans_ichgtime(tp
, ip
, XFS_ICHGTIME_CHG
);
1283 xfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
1285 XFS_STATS_INC(xs_ig_attrchg
);
1288 * If this is a synchronous mount, make sure that the
1289 * transaction goes to disk before returning to the user.
1290 * This is slightly sub-optimal in that truncates require
1291 * two sync transactions instead of one for wsync filesystems.
1292 * One for the truncate and one for the timestamps since we
1293 * don't want to change the timestamps unless we're sure the
1294 * truncate worked. Truncates are less than 1% of the laddis
1295 * mix so this probably isn't worth the trouble to optimize.
1297 if (mp
->m_flags
& XFS_MOUNT_WSYNC
)
1298 xfs_trans_set_sync(tp
);
1299 code
= xfs_trans_commit(tp
, 0);
1300 xfs_iunlock(ip
, lock_flags
);
1303 * Release any dquot(s) the inode had kept before chown.
1305 xfs_qm_dqrele(olddquot
);
1306 xfs_qm_dqrele(udqp
);
1307 xfs_qm_dqrele(pdqp
);
1312 xfs_qm_dqrele(udqp
);
1313 xfs_qm_dqrele(pdqp
);
1314 xfs_trans_cancel(tp
, 0);
1316 xfs_iunlock(ip
, lock_flags
);
1330 if (copy_from_user(&fa
, arg
, sizeof(fa
)))
1333 mask
= FSX_XFLAGS
| FSX_EXTSIZE
| FSX_PROJID
;
1334 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1335 mask
|= FSX_NONBLOCK
;
1337 error
= mnt_want_write_file(filp
);
1340 error
= xfs_ioctl_setattr(ip
, &fa
, mask
);
1341 mnt_drop_write_file(filp
);
1352 flags
= xfs_di2lxflags(ip
->i_d
.di_flags
);
1353 if (copy_to_user(arg
, &flags
, sizeof(flags
)))
1369 if (copy_from_user(&flags
, arg
, sizeof(flags
)))
1372 if (flags
& ~(FS_IMMUTABLE_FL
| FS_APPEND_FL
| \
1373 FS_NOATIME_FL
| FS_NODUMP_FL
| \
1378 if (filp
->f_flags
& (O_NDELAY
|O_NONBLOCK
))
1379 mask
|= FSX_NONBLOCK
;
1380 fa
.fsx_xflags
= xfs_merge_ioc_xflags(flags
, xfs_ip2xflags(ip
));
1382 error
= mnt_want_write_file(filp
);
1385 error
= xfs_ioctl_setattr(ip
, &fa
, mask
);
1386 mnt_drop_write_file(filp
);
1391 xfs_getbmap_format(void **ap
, struct getbmapx
*bmv
, int *full
)
1393 struct getbmap __user
*base
= *ap
;
1395 /* copy only getbmap portion (not getbmapx) */
1396 if (copy_to_user(base
, bmv
, sizeof(struct getbmap
)))
1397 return XFS_ERROR(EFAULT
);
1399 *ap
+= sizeof(struct getbmap
);
1405 struct xfs_inode
*ip
,
1410 struct getbmapx bmx
;
1413 if (copy_from_user(&bmx
, arg
, sizeof(struct getbmapx
)))
1414 return -XFS_ERROR(EFAULT
);
1416 if (bmx
.bmv_count
< 2)
1417 return -XFS_ERROR(EINVAL
);
1419 bmx
.bmv_iflags
= (cmd
== XFS_IOC_GETBMAPA
? BMV_IF_ATTRFORK
: 0);
1420 if (ioflags
& IO_INVIS
)
1421 bmx
.bmv_iflags
|= BMV_IF_NO_DMAPI_READ
;
1423 error
= xfs_getbmap(ip
, &bmx
, xfs_getbmap_format
,
1424 (struct getbmap
*)arg
+1);
1428 /* copy back header - only size of getbmap */
1429 if (copy_to_user(arg
, &bmx
, sizeof(struct getbmap
)))
1430 return -XFS_ERROR(EFAULT
);
1435 xfs_getbmapx_format(void **ap
, struct getbmapx
*bmv
, int *full
)
1437 struct getbmapx __user
*base
= *ap
;
1439 if (copy_to_user(base
, bmv
, sizeof(struct getbmapx
)))
1440 return XFS_ERROR(EFAULT
);
1442 *ap
+= sizeof(struct getbmapx
);
1448 struct xfs_inode
*ip
,
1451 struct getbmapx bmx
;
1454 if (copy_from_user(&bmx
, arg
, sizeof(bmx
)))
1455 return -XFS_ERROR(EFAULT
);
1457 if (bmx
.bmv_count
< 2)
1458 return -XFS_ERROR(EINVAL
);
1460 if (bmx
.bmv_iflags
& (~BMV_IF_VALID
))
1461 return -XFS_ERROR(EINVAL
);
1463 error
= xfs_getbmap(ip
, &bmx
, xfs_getbmapx_format
,
1464 (struct getbmapx
*)arg
+1);
1468 /* copy back header */
1469 if (copy_to_user(arg
, &bmx
, sizeof(struct getbmapx
)))
1470 return -XFS_ERROR(EFAULT
);
1479 xfs_inode_t
*ip
, *tip
;
1483 /* Pull information for the target fd */
1484 f
= fdget((int)sxp
->sx_fdtarget
);
1486 error
= XFS_ERROR(EINVAL
);
1490 if (!(f
.file
->f_mode
& FMODE_WRITE
) ||
1491 !(f
.file
->f_mode
& FMODE_READ
) ||
1492 (f
.file
->f_flags
& O_APPEND
)) {
1493 error
= XFS_ERROR(EBADF
);
1497 tmp
= fdget((int)sxp
->sx_fdtmp
);
1499 error
= XFS_ERROR(EINVAL
);
1503 if (!(tmp
.file
->f_mode
& FMODE_WRITE
) ||
1504 !(tmp
.file
->f_mode
& FMODE_READ
) ||
1505 (tmp
.file
->f_flags
& O_APPEND
)) {
1506 error
= XFS_ERROR(EBADF
);
1507 goto out_put_tmp_file
;
1510 if (IS_SWAPFILE(file_inode(f
.file
)) ||
1511 IS_SWAPFILE(file_inode(tmp
.file
))) {
1512 error
= XFS_ERROR(EINVAL
);
1513 goto out_put_tmp_file
;
1516 ip
= XFS_I(file_inode(f
.file
));
1517 tip
= XFS_I(file_inode(tmp
.file
));
1519 if (ip
->i_mount
!= tip
->i_mount
) {
1520 error
= XFS_ERROR(EINVAL
);
1521 goto out_put_tmp_file
;
1524 if (ip
->i_ino
== tip
->i_ino
) {
1525 error
= XFS_ERROR(EINVAL
);
1526 goto out_put_tmp_file
;
1529 if (XFS_FORCED_SHUTDOWN(ip
->i_mount
)) {
1530 error
= XFS_ERROR(EIO
);
1531 goto out_put_tmp_file
;
1534 error
= xfs_swap_extents(ip
, tip
, sxp
);
1545 * Note: some of the ioctl's return positive numbers as a
1546 * byte count indicating success, such as readlink_by_handle.
1547 * So we don't "sign flip" like most other routines. This means
1548 * true errors need to be returned as a negative value.
1556 struct inode
*inode
= file_inode(filp
);
1557 struct xfs_inode
*ip
= XFS_I(inode
);
1558 struct xfs_mount
*mp
= ip
->i_mount
;
1559 void __user
*arg
= (void __user
*)p
;
1563 if (filp
->f_mode
& FMODE_NOCMTIME
)
1564 ioflags
|= IO_INVIS
;
1566 trace_xfs_file_ioctl(ip
);
1570 return xfs_ioc_trim(mp
, arg
);
1571 case XFS_IOC_ALLOCSP
:
1572 case XFS_IOC_FREESP
:
1573 case XFS_IOC_RESVSP
:
1574 case XFS_IOC_UNRESVSP
:
1575 case XFS_IOC_ALLOCSP64
:
1576 case XFS_IOC_FREESP64
:
1577 case XFS_IOC_RESVSP64
:
1578 case XFS_IOC_UNRESVSP64
:
1579 case XFS_IOC_ZERO_RANGE
: {
1582 if (copy_from_user(&bf
, arg
, sizeof(bf
)))
1583 return -XFS_ERROR(EFAULT
);
1584 return xfs_ioc_space(ip
, inode
, filp
, ioflags
, cmd
, &bf
);
1586 case XFS_IOC_DIOINFO
: {
1588 xfs_buftarg_t
*target
=
1589 XFS_IS_REALTIME_INODE(ip
) ?
1590 mp
->m_rtdev_targp
: mp
->m_ddev_targp
;
1592 da
.d_mem
= da
.d_miniosz
= 1 << target
->bt_sshift
;
1593 da
.d_maxiosz
= INT_MAX
& ~(da
.d_miniosz
- 1);
1595 if (copy_to_user(arg
, &da
, sizeof(da
)))
1596 return -XFS_ERROR(EFAULT
);
1600 case XFS_IOC_FSBULKSTAT_SINGLE
:
1601 case XFS_IOC_FSBULKSTAT
:
1602 case XFS_IOC_FSINUMBERS
:
1603 return xfs_ioc_bulkstat(mp
, cmd
, arg
);
1605 case XFS_IOC_FSGEOMETRY_V1
:
1606 return xfs_ioc_fsgeometry_v1(mp
, arg
);
1608 case XFS_IOC_FSGEOMETRY
:
1609 return xfs_ioc_fsgeometry(mp
, arg
);
1611 case XFS_IOC_GETVERSION
:
1612 return put_user(inode
->i_generation
, (int __user
*)arg
);
1614 case XFS_IOC_FSGETXATTR
:
1615 return xfs_ioc_fsgetxattr(ip
, 0, arg
);
1616 case XFS_IOC_FSGETXATTRA
:
1617 return xfs_ioc_fsgetxattr(ip
, 1, arg
);
1618 case XFS_IOC_FSSETXATTR
:
1619 return xfs_ioc_fssetxattr(ip
, filp
, arg
);
1620 case XFS_IOC_GETXFLAGS
:
1621 return xfs_ioc_getxflags(ip
, arg
);
1622 case XFS_IOC_SETXFLAGS
:
1623 return xfs_ioc_setxflags(ip
, filp
, arg
);
1625 case XFS_IOC_FSSETDM
: {
1626 struct fsdmidata dmi
;
1628 if (copy_from_user(&dmi
, arg
, sizeof(dmi
)))
1629 return -XFS_ERROR(EFAULT
);
1631 error
= mnt_want_write_file(filp
);
1635 error
= xfs_set_dmattrs(ip
, dmi
.fsd_dmevmask
,
1637 mnt_drop_write_file(filp
);
1641 case XFS_IOC_GETBMAP
:
1642 case XFS_IOC_GETBMAPA
:
1643 return xfs_ioc_getbmap(ip
, ioflags
, cmd
, arg
);
1645 case XFS_IOC_GETBMAPX
:
1646 return xfs_ioc_getbmapx(ip
, arg
);
1648 case XFS_IOC_FD_TO_HANDLE
:
1649 case XFS_IOC_PATH_TO_HANDLE
:
1650 case XFS_IOC_PATH_TO_FSHANDLE
: {
1651 xfs_fsop_handlereq_t hreq
;
1653 if (copy_from_user(&hreq
, arg
, sizeof(hreq
)))
1654 return -XFS_ERROR(EFAULT
);
1655 return xfs_find_handle(cmd
, &hreq
);
1657 case XFS_IOC_OPEN_BY_HANDLE
: {
1658 xfs_fsop_handlereq_t hreq
;
1660 if (copy_from_user(&hreq
, arg
, sizeof(xfs_fsop_handlereq_t
)))
1661 return -XFS_ERROR(EFAULT
);
1662 return xfs_open_by_handle(filp
, &hreq
);
1664 case XFS_IOC_FSSETDM_BY_HANDLE
:
1665 return xfs_fssetdm_by_handle(filp
, arg
);
1667 case XFS_IOC_READLINK_BY_HANDLE
: {
1668 xfs_fsop_handlereq_t hreq
;
1670 if (copy_from_user(&hreq
, arg
, sizeof(xfs_fsop_handlereq_t
)))
1671 return -XFS_ERROR(EFAULT
);
1672 return xfs_readlink_by_handle(filp
, &hreq
);
1674 case XFS_IOC_ATTRLIST_BY_HANDLE
:
1675 return xfs_attrlist_by_handle(filp
, arg
);
1677 case XFS_IOC_ATTRMULTI_BY_HANDLE
:
1678 return xfs_attrmulti_by_handle(filp
, arg
);
1680 case XFS_IOC_SWAPEXT
: {
1681 struct xfs_swapext sxp
;
1683 if (copy_from_user(&sxp
, arg
, sizeof(xfs_swapext_t
)))
1684 return -XFS_ERROR(EFAULT
);
1685 error
= mnt_want_write_file(filp
);
1688 error
= xfs_ioc_swapext(&sxp
);
1689 mnt_drop_write_file(filp
);
1693 case XFS_IOC_FSCOUNTS
: {
1694 xfs_fsop_counts_t out
;
1696 error
= xfs_fs_counts(mp
, &out
);
1700 if (copy_to_user(arg
, &out
, sizeof(out
)))
1701 return -XFS_ERROR(EFAULT
);
1705 case XFS_IOC_SET_RESBLKS
: {
1706 xfs_fsop_resblks_t inout
;
1709 if (!capable(CAP_SYS_ADMIN
))
1712 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
1713 return -XFS_ERROR(EROFS
);
1715 if (copy_from_user(&inout
, arg
, sizeof(inout
)))
1716 return -XFS_ERROR(EFAULT
);
1718 error
= mnt_want_write_file(filp
);
1722 /* input parameter is passed in resblks field of structure */
1724 error
= xfs_reserve_blocks(mp
, &in
, &inout
);
1725 mnt_drop_write_file(filp
);
1729 if (copy_to_user(arg
, &inout
, sizeof(inout
)))
1730 return -XFS_ERROR(EFAULT
);
1734 case XFS_IOC_GET_RESBLKS
: {
1735 xfs_fsop_resblks_t out
;
1737 if (!capable(CAP_SYS_ADMIN
))
1740 error
= xfs_reserve_blocks(mp
, NULL
, &out
);
1744 if (copy_to_user(arg
, &out
, sizeof(out
)))
1745 return -XFS_ERROR(EFAULT
);
1750 case XFS_IOC_FSGROWFSDATA
: {
1751 xfs_growfs_data_t in
;
1753 if (copy_from_user(&in
, arg
, sizeof(in
)))
1754 return -XFS_ERROR(EFAULT
);
1756 error
= mnt_want_write_file(filp
);
1759 error
= xfs_growfs_data(mp
, &in
);
1760 mnt_drop_write_file(filp
);
1764 case XFS_IOC_FSGROWFSLOG
: {
1765 xfs_growfs_log_t in
;
1767 if (copy_from_user(&in
, arg
, sizeof(in
)))
1768 return -XFS_ERROR(EFAULT
);
1770 error
= mnt_want_write_file(filp
);
1773 error
= xfs_growfs_log(mp
, &in
);
1774 mnt_drop_write_file(filp
);
1778 case XFS_IOC_FSGROWFSRT
: {
1781 if (copy_from_user(&in
, arg
, sizeof(in
)))
1782 return -XFS_ERROR(EFAULT
);
1784 error
= mnt_want_write_file(filp
);
1787 error
= xfs_growfs_rt(mp
, &in
);
1788 mnt_drop_write_file(filp
);
1792 case XFS_IOC_GOINGDOWN
: {
1795 if (!capable(CAP_SYS_ADMIN
))
1798 if (get_user(in
, (__uint32_t __user
*)arg
))
1799 return -XFS_ERROR(EFAULT
);
1801 error
= xfs_fs_goingdown(mp
, in
);
1805 case XFS_IOC_ERROR_INJECTION
: {
1806 xfs_error_injection_t in
;
1808 if (!capable(CAP_SYS_ADMIN
))
1811 if (copy_from_user(&in
, arg
, sizeof(in
)))
1812 return -XFS_ERROR(EFAULT
);
1814 error
= xfs_errortag_add(in
.errtag
, mp
);
1818 case XFS_IOC_ERROR_CLEARALL
:
1819 if (!capable(CAP_SYS_ADMIN
))
1822 error
= xfs_errortag_clearall(mp
, 1);
1825 case XFS_IOC_FREE_EOFBLOCKS
: {
1826 struct xfs_fs_eofblocks eofb
;
1827 struct xfs_eofblocks keofb
;
1829 if (!capable(CAP_SYS_ADMIN
))
1832 if (mp
->m_flags
& XFS_MOUNT_RDONLY
)
1833 return -XFS_ERROR(EROFS
);
1835 if (copy_from_user(&eofb
, arg
, sizeof(eofb
)))
1836 return -XFS_ERROR(EFAULT
);
1838 error
= xfs_fs_eofblocks_from_user(&eofb
, &keofb
);
1842 return -xfs_icache_free_eofblocks(mp
, &keofb
);