mtio.h 1.3 KB

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