1  /* SPDX-License-Identifier: GPL-2.0 */
2  #ifndef _LINUX_MTIO_COMPAT_H
3  #define _LINUX_MTIO_COMPAT_H
4  
5  #include <linux/compat.h>
6  #include <uapi/linux/mtio.h>
7  #include <linux/uaccess.h>
8  
9  /*
10   * helper functions for implementing compat ioctls on the four tape
11   * drivers: we define the 32-bit layout of each incompatible structure,
12   * plus a wrapper function to copy it to user space in either format.
13   */
14  
15  struct	mtget32 {
16  	s32	mt_type;
17  	s32	mt_resid;
18  	s32	mt_dsreg;
19  	s32	mt_gstat;
20  	s32	mt_erreg;
21  	s32	mt_fileno;
22  	s32	mt_blkno;
23  };
24  #define	MTIOCGET32	_IOR('m', 2, struct mtget32)
25  
26  struct	mtpos32 {
27  	s32 	mt_blkno;
28  };
29  #define	MTIOCPOS32	_IOR('m', 3, struct mtpos32)
30  
put_user_mtget(void __user * u,struct mtget * k)31  static inline int put_user_mtget(void __user *u, struct mtget *k)
32  {
33  	struct mtget32 k32 = {
34  		.mt_type   = k->mt_type,
35  		.mt_resid  = k->mt_resid,
36  		.mt_dsreg  = k->mt_dsreg,
37  		.mt_gstat  = k->mt_gstat,
38  		.mt_erreg  = k->mt_erreg,
39  		.mt_fileno = k->mt_fileno,
40  		.mt_blkno  = k->mt_blkno,
41  	};
42  	int ret;
43  
44  	if (in_compat_syscall())
45  		ret = copy_to_user(u, &k32, sizeof(k32));
46  	else
47  		ret = copy_to_user(u, k, sizeof(*k));
48  
49  	return ret ? -EFAULT : 0;
50  }
51  
put_user_mtpos(void __user * u,struct mtpos * k)52  static inline int put_user_mtpos(void __user *u, struct mtpos *k)
53  {
54  	if (in_compat_syscall())
55  		return put_user(k->mt_blkno, (u32 __user *)u);
56  	else
57  		return put_user(k->mt_blkno, (long __user *)u);
58  }
59  
60  #endif
61