Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (c) 2004-2005 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/fsmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "xfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "xfs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "xfs_shared.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "xfs_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "xfs_log_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "xfs_trans_resv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "xfs_mount.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "xfs_inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "xfs_iwalk.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "xfs_itable.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "xfs_fsops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "xfs_rtalloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "xfs_attr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "xfs_ioctl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "xfs_ioctl32.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "xfs_trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "xfs_sb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define  _NATIVE_IOC(cmd, type) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	  _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #ifdef BROKEN_X86_ALIGNMENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) xfs_compat_flock64_copyin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	xfs_flock64_t		*bf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	compat_xfs_flock64_t	__user *arg32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	if (get_user(bf->l_type,	&arg32->l_type) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	    get_user(bf->l_whence,	&arg32->l_whence) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	    get_user(bf->l_start,	&arg32->l_start) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	    get_user(bf->l_len,		&arg32->l_len) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	    get_user(bf->l_sysid,	&arg32->l_sysid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	    get_user(bf->l_pid,		&arg32->l_pid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	    copy_from_user(bf->l_pad,	&arg32->l_pad,	4*sizeof(u32)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) xfs_compat_ioc_fsgeometry_v1(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct xfs_mount	  *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	compat_xfs_fsop_geom_v1_t __user *arg32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct xfs_fsop_geom	  fsgeo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	xfs_fs_geometry(&mp->m_sb, &fsgeo, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	/* The 32-bit variant simply has some padding at the end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (copy_to_user(arg32, &fsgeo, sizeof(struct compat_xfs_fsop_geom_v1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) xfs_compat_growfs_data_copyin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct xfs_growfs_data	 *in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	compat_xfs_growfs_data_t __user *arg32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (get_user(in->newblocks, &arg32->newblocks) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	    get_user(in->imaxpct,   &arg32->imaxpct))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) xfs_compat_growfs_rt_copyin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct xfs_growfs_rt	 *in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	compat_xfs_growfs_rt_t	__user *arg32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	if (get_user(in->newblocks, &arg32->newblocks) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	    get_user(in->extsize,   &arg32->extsize))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) xfs_fsinumbers_fmt_compat(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct xfs_ibulk		*breq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	const struct xfs_inumbers	*ig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct compat_xfs_inogrp __user	*p32 = breq->ubuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct xfs_inogrp		ig1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct xfs_inogrp		*igrp = &ig1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	xfs_inumbers_to_inogrp(&ig1, ig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (put_user(igrp->xi_startino,   &p32->xi_startino) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	    put_user(igrp->xi_alloccount, &p32->xi_alloccount) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	    put_user(igrp->xi_allocmask,  &p32->xi_allocmask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return xfs_ibulk_advance(breq, sizeof(struct compat_xfs_inogrp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define xfs_fsinumbers_fmt_compat xfs_fsinumbers_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #endif	/* BROKEN_X86_ALIGNMENT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) xfs_ioctl32_bstime_copyin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	xfs_bstime_t		*bstime,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	compat_xfs_bstime_t	__user *bstime32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	old_time32_t		sec32;	/* tv_sec differs on 64 vs. 32 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (get_user(sec32,		&bstime32->tv_sec)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	    get_user(bstime->tv_nsec,	&bstime32->tv_nsec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	bstime->tv_sec = sec32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * struct xfs_bstat has differing alignment on intel, & bstime_t sizes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * everywhere
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) xfs_ioctl32_bstat_copyin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct xfs_bstat		*bstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct compat_xfs_bstat	__user	*bstat32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (get_user(bstat->bs_ino,	&bstat32->bs_ino)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	    get_user(bstat->bs_mode,	&bstat32->bs_mode)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	    get_user(bstat->bs_nlink,	&bstat32->bs_nlink)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	    get_user(bstat->bs_uid,	&bstat32->bs_uid)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	    get_user(bstat->bs_gid,	&bstat32->bs_gid)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	    get_user(bstat->bs_rdev,	&bstat32->bs_rdev)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	    get_user(bstat->bs_blksize,	&bstat32->bs_blksize)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	    get_user(bstat->bs_size,	&bstat32->bs_size)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	    xfs_ioctl32_bstime_copyin(&bstat->bs_atime, &bstat32->bs_atime) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	    xfs_ioctl32_bstime_copyin(&bstat->bs_mtime, &bstat32->bs_mtime) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	    xfs_ioctl32_bstime_copyin(&bstat->bs_ctime, &bstat32->bs_ctime) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	    get_user(bstat->bs_blocks,	&bstat32->bs_size)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	    get_user(bstat->bs_xflags,	&bstat32->bs_size)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	    get_user(bstat->bs_extsize,	&bstat32->bs_extsize)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	    get_user(bstat->bs_extents,	&bstat32->bs_extents)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	    get_user(bstat->bs_gen,	&bstat32->bs_gen)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	    get_user(bstat->bs_projid_lo, &bstat32->bs_projid_lo) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	    get_user(bstat->bs_projid_hi, &bstat32->bs_projid_hi) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	    get_user(bstat->bs_forkoff,	&bstat32->bs_forkoff)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	    get_user(bstat->bs_dmevmask, &bstat32->bs_dmevmask)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	    get_user(bstat->bs_dmstate,	&bstat32->bs_dmstate)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	    get_user(bstat->bs_aextents, &bstat32->bs_aextents))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* XFS_IOC_FSBULKSTAT and friends */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) xfs_bstime_store_compat(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	compat_xfs_bstime_t	__user *p32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	const xfs_bstime_t	*p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	__s32			sec32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	sec32 = p->tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (put_user(sec32, &p32->tv_sec) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	    put_user(p->tv_nsec, &p32->tv_nsec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* Return 0 on success or positive error (to xfs_bulkstat()) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) xfs_fsbulkstat_one_fmt_compat(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct xfs_ibulk		*breq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	const struct xfs_bulkstat	*bstat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	struct compat_xfs_bstat	__user	*p32 = breq->ubuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct xfs_bstat		bs1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct xfs_bstat		*buffer = &bs1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	xfs_bulkstat_to_bstat(breq->mp, &bs1, bstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (put_user(buffer->bs_ino,	  &p32->bs_ino)		||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	    put_user(buffer->bs_mode,	  &p32->bs_mode)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	    put_user(buffer->bs_nlink,	  &p32->bs_nlink)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	    put_user(buffer->bs_uid,	  &p32->bs_uid)		||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	    put_user(buffer->bs_gid,	  &p32->bs_gid)		||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	    put_user(buffer->bs_rdev,	  &p32->bs_rdev)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	    put_user(buffer->bs_blksize,  &p32->bs_blksize)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	    put_user(buffer->bs_size,	  &p32->bs_size)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	    xfs_bstime_store_compat(&p32->bs_atime, &buffer->bs_atime) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	    xfs_bstime_store_compat(&p32->bs_mtime, &buffer->bs_mtime) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	    xfs_bstime_store_compat(&p32->bs_ctime, &buffer->bs_ctime) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	    put_user(buffer->bs_blocks,	  &p32->bs_blocks)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	    put_user(buffer->bs_xflags,	  &p32->bs_xflags)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	    put_user(buffer->bs_extsize,  &p32->bs_extsize)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	    put_user(buffer->bs_extents,  &p32->bs_extents)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	    put_user(buffer->bs_gen,	  &p32->bs_gen)		||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	    put_user(buffer->bs_projid,	  &p32->bs_projid)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	    put_user(buffer->bs_projid_hi,	&p32->bs_projid_hi)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	    put_user(buffer->bs_forkoff,  &p32->bs_forkoff)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	    put_user(buffer->bs_dmevmask, &p32->bs_dmevmask)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	    put_user(buffer->bs_dmstate,  &p32->bs_dmstate)	||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	    put_user(buffer->bs_aextents, &p32->bs_aextents))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return xfs_ibulk_advance(breq, sizeof(struct compat_xfs_bstat));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* copied from xfs_ioctl.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) xfs_compat_ioc_fsbulkstat(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	xfs_mount_t		  *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	unsigned int		  cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct compat_xfs_fsop_bulkreq __user *p32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	u32			addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct xfs_fsop_bulkreq	bulkreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct xfs_ibulk	breq = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		.mp		= mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		.ocount		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	xfs_ino_t		lastino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	int			error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	 * Output structure handling functions.  Depending on the command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	 * either the xfs_bstat and xfs_inogrp structures are written out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	 * to userpace memory via bulkreq.ubuffer.  Normally the compat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	 * functions and structure size are the correct ones to use ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	inumbers_fmt_pf		inumbers_func = xfs_fsinumbers_fmt_compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	bulkstat_one_fmt_pf	bs_one_func = xfs_fsbulkstat_one_fmt_compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #ifdef CONFIG_X86_X32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (in_x32_syscall()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		 * ... but on x32 the input xfs_fsop_bulkreq has pointers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		 * which must be handled in the "compat" (32-bit) way, while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		 * the xfs_bstat and xfs_inogrp structures follow native 64-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		 * bit layout convention.  So adjust accordingly, otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		 * the data written out in compat layout will not match what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		 * x32 userspace expects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		inumbers_func = xfs_fsinumbers_fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		bs_one_func = xfs_fsbulkstat_one_fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	/* done = 1 if there are more stats to get and if bulkstat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	/* should be called again (unused here, but used in dmapi) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (XFS_FORCED_SHUTDOWN(mp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (get_user(addr, &p32->lastip))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	bulkreq.lastip = compat_ptr(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (get_user(bulkreq.icount, &p32->icount) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	    get_user(addr, &p32->ubuffer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	bulkreq.ubuffer = compat_ptr(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (get_user(addr, &p32->ocount))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	bulkreq.ocount = compat_ptr(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (copy_from_user(&lastino, bulkreq.lastip, sizeof(__s64)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (bulkreq.icount <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (bulkreq.ubuffer == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	breq.ubuffer = bulkreq.ubuffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	breq.icount = bulkreq.icount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	 * FSBULKSTAT_SINGLE expects that *lastip contains the inode number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	 * that we want to stat.  However, FSINUMBERS and FSBULKSTAT expect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	 * that *lastip contains either zero or the number of the last inode to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	 * be examined by the previous call and return results starting with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	 * the next inode after that.  The new bulk request back end functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	 * take the inode to start with, so we have to compute the startino
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	 * parameter from lastino to maintain correct function.  lastino == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	 * is a special case because it has traditionally meant "first inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	 * in filesystem".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (cmd == XFS_IOC_FSINUMBERS_32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		breq.startino = lastino ? lastino + 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		error = xfs_inumbers(&breq, inumbers_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		lastino = breq.startino - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	} else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE_32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		breq.startino = lastino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		breq.icount = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		error = xfs_bulkstat_one(&breq, bs_one_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		lastino = breq.startino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	} else if (cmd == XFS_IOC_FSBULKSTAT_32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		breq.startino = lastino ? lastino + 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		error = xfs_bulkstat(&breq, bs_one_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		lastino = breq.startino - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	if (bulkreq.lastip != NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	    copy_to_user(bulkreq.lastip, &lastino, sizeof(xfs_ino_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	if (bulkreq.ocount != NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	    copy_to_user(bulkreq.ocount, &breq.ocount, sizeof(__s32)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) xfs_compat_handlereq_copyin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	xfs_fsop_handlereq_t		*hreq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	compat_xfs_fsop_handlereq_t	__user *arg32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	compat_xfs_fsop_handlereq_t	hreq32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	if (copy_from_user(&hreq32, arg32, sizeof(compat_xfs_fsop_handlereq_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	hreq->fd = hreq32.fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	hreq->path = compat_ptr(hreq32.path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	hreq->oflags = hreq32.oflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	hreq->ihandle = compat_ptr(hreq32.ihandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	hreq->ihandlen = hreq32.ihandlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	hreq->ohandle = compat_ptr(hreq32.ohandle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	hreq->ohandlen = compat_ptr(hreq32.ohandlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) STATIC struct dentry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) xfs_compat_handlereq_to_dentry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	struct file		*parfilp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	compat_xfs_fsop_handlereq_t *hreq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	return xfs_handle_to_dentry(parfilp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			compat_ptr(hreq->ihandle), hreq->ihandlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) xfs_compat_attrlist_by_handle(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	struct file		*parfilp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	compat_xfs_fsop_attrlist_handlereq_t __user *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	compat_xfs_fsop_attrlist_handlereq_t al_hreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	struct dentry		*dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	int			error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (copy_from_user(&al_hreq, p, sizeof(al_hreq)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	dentry = xfs_compat_handlereq_to_dentry(parfilp, &al_hreq.hreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	if (IS_ERR(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		return PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	error = xfs_ioc_attr_list(XFS_I(d_inode(dentry)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 			compat_ptr(al_hreq.buffer), al_hreq.buflen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			al_hreq.flags, &p->pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) xfs_compat_attrmulti_by_handle(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	struct file				*parfilp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	void					__user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	int					error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	compat_xfs_attr_multiop_t		*ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	compat_xfs_fsop_attrmulti_handlereq_t	am_hreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	struct dentry				*dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	unsigned int				i, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	if (copy_from_user(&am_hreq, arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			   sizeof(compat_xfs_fsop_attrmulti_handlereq_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	/* overflow check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	if (am_hreq.opcount >= INT_MAX / sizeof(compat_xfs_attr_multiop_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		return -E2BIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	dentry = xfs_compat_handlereq_to_dentry(parfilp, &am_hreq.hreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	if (IS_ERR(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		return PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	error = -E2BIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	size = am_hreq.opcount * sizeof(compat_xfs_attr_multiop_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	if (!size || size > 16 * PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		goto out_dput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	ops = memdup_user(compat_ptr(am_hreq.ops), size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	if (IS_ERR(ops)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		error = PTR_ERR(ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		goto out_dput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	for (i = 0; i < am_hreq.opcount; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		ops[i].am_error = xfs_ioc_attrmulti_one(parfilp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 				d_inode(dentry), ops[i].am_opcode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 				compat_ptr(ops[i].am_attrname),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 				compat_ptr(ops[i].am_attrvalue),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 				&ops[i].am_length, ops[i].am_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (copy_to_user(compat_ptr(am_hreq.ops), ops, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		error = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	kfree(ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)  out_dput:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) xfs_file_compat_ioctl(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	struct file		*filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	unsigned		cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	unsigned long		p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	struct inode		*inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	struct xfs_inode	*ip = XFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	struct xfs_mount	*mp = ip->i_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	void			__user *arg = compat_ptr(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	int			error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	trace_xfs_file_compat_ioctl(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) #if defined(BROKEN_X86_ALIGNMENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	case XFS_IOC_ALLOCSP_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	case XFS_IOC_FREESP_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	case XFS_IOC_ALLOCSP64_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	case XFS_IOC_FREESP64_32: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		struct xfs_flock64	bf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		if (xfs_compat_flock64_copyin(&bf, arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		cmd = _NATIVE_IOC(cmd, struct xfs_flock64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		return xfs_ioc_space(filp, &bf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	case XFS_IOC_FSGEOMETRY_V1_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		return xfs_compat_ioc_fsgeometry_v1(mp, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	case XFS_IOC_FSGROWFSDATA_32: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		struct xfs_growfs_data	in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		if (xfs_compat_growfs_data_copyin(&in, arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		error = mnt_want_write_file(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		error = xfs_growfs_data(mp, &in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		mnt_drop_write_file(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	case XFS_IOC_FSGROWFSRT_32: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		struct xfs_growfs_rt	in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		if (xfs_compat_growfs_rt_copyin(&in, arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		error = mnt_want_write_file(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		error = xfs_growfs_rt(mp, &in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		mnt_drop_write_file(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	/* long changes size, but xfs only copiese out 32 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	case XFS_IOC_GETXFLAGS_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	case XFS_IOC_SETXFLAGS_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	case XFS_IOC_GETVERSION_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		cmd = _NATIVE_IOC(cmd, long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		return xfs_file_ioctl(filp, cmd, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	case XFS_IOC_SWAPEXT_32: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		struct xfs_swapext	  sxp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		struct compat_xfs_swapext __user *sxu = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		/* Bulk copy in up to the sx_stat field, then copy bstat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		if (copy_from_user(&sxp, sxu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 				   offsetof(struct xfs_swapext, sx_stat)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		    xfs_ioctl32_bstat_copyin(&sxp.sx_stat, &sxu->sx_stat))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		error = mnt_want_write_file(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		error = xfs_ioc_swapext(&sxp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		mnt_drop_write_file(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	case XFS_IOC_FSBULKSTAT_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	case XFS_IOC_FSBULKSTAT_SINGLE_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	case XFS_IOC_FSINUMBERS_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		return xfs_compat_ioc_fsbulkstat(mp, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	case XFS_IOC_FD_TO_HANDLE_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	case XFS_IOC_PATH_TO_HANDLE_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	case XFS_IOC_PATH_TO_FSHANDLE_32: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		struct xfs_fsop_handlereq	hreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		if (xfs_compat_handlereq_copyin(&hreq, arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		cmd = _NATIVE_IOC(cmd, struct xfs_fsop_handlereq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		return xfs_find_handle(cmd, &hreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	case XFS_IOC_OPEN_BY_HANDLE_32: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		struct xfs_fsop_handlereq	hreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		if (xfs_compat_handlereq_copyin(&hreq, arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		return xfs_open_by_handle(filp, &hreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	case XFS_IOC_READLINK_BY_HANDLE_32: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		struct xfs_fsop_handlereq	hreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		if (xfs_compat_handlereq_copyin(&hreq, arg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		return xfs_readlink_by_handle(filp, &hreq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	case XFS_IOC_ATTRLIST_BY_HANDLE_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		return xfs_compat_attrlist_by_handle(filp, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	case XFS_IOC_ATTRMULTI_BY_HANDLE_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		return xfs_compat_attrmulti_by_handle(filp, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		/* try the native version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		return xfs_file_ioctl(filp, cmd, (unsigned long)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }