Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_MTIO_COMPAT_H
0003 #define _LINUX_MTIO_COMPAT_H
0004 
0005 #include <linux/compat.h>
0006 #include <uapi/linux/mtio.h>
0007 #include <linux/uaccess.h>
0008 
0009 /*
0010  * helper functions for implementing compat ioctls on the four tape
0011  * drivers: we define the 32-bit layout of each incompatible structure,
0012  * plus a wrapper function to copy it to user space in either format.
0013  */
0014 
0015 struct  mtget32 {
0016     s32 mt_type;
0017     s32 mt_resid;
0018     s32 mt_dsreg;
0019     s32 mt_gstat;
0020     s32 mt_erreg;
0021     s32 mt_fileno;
0022     s32 mt_blkno;
0023 };
0024 #define MTIOCGET32  _IOR('m', 2, struct mtget32)
0025 
0026 struct  mtpos32 {
0027     s32     mt_blkno;
0028 };
0029 #define MTIOCPOS32  _IOR('m', 3, struct mtpos32)
0030 
0031 static inline int put_user_mtget(void __user *u, struct mtget *k)
0032 {
0033     struct mtget32 k32 = {
0034         .mt_type   = k->mt_type,
0035         .mt_resid  = k->mt_resid,
0036         .mt_dsreg  = k->mt_dsreg,
0037         .mt_gstat  = k->mt_gstat,
0038         .mt_erreg  = k->mt_erreg,
0039         .mt_fileno = k->mt_fileno,
0040         .mt_blkno  = k->mt_blkno,
0041     };
0042     int ret;
0043 
0044     if (in_compat_syscall())
0045         ret = copy_to_user(u, &k32, sizeof(k32));
0046     else
0047         ret = copy_to_user(u, k, sizeof(*k));
0048 
0049     return ret ? -EFAULT : 0;
0050 }
0051 
0052 static inline int put_user_mtpos(void __user *u, struct mtpos *k)
0053 {
0054     if (in_compat_syscall())
0055         return put_user(k->mt_blkno, (u32 __user *)u);
0056     else
0057         return put_user(k->mt_blkno, (long __user *)u);
0058 }
0059 
0060 #endif