xfs_ioctl32.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * Copyright (c) 2004-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  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.
  8. *
  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.
  13. *
  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
  17. */
  18. #include <linux/config.h>
  19. #include <linux/compat.h>
  20. #include <linux/init.h>
  21. #include <linux/ioctl.h>
  22. #include <linux/ioctl32.h>
  23. #include <linux/syscalls.h>
  24. #include <linux/types.h>
  25. #include <linux/fs.h>
  26. #include <asm/uaccess.h>
  27. #include "xfs.h"
  28. #include "xfs_types.h"
  29. #include "xfs_fs.h"
  30. #include "xfs_vfs.h"
  31. #include "xfs_vnode.h"
  32. #include "xfs_dfrag.h"
  33. #define _NATIVE_IOC(cmd, type) \
  34. _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
  35. #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
  36. #define BROKEN_X86_ALIGNMENT
  37. /* on ia32 l_start is on a 32-bit boundary */
  38. typedef struct xfs_flock64_32 {
  39. __s16 l_type;
  40. __s16 l_whence;
  41. __s64 l_start __attribute__((packed));
  42. /* len == 0 means until end of file */
  43. __s64 l_len __attribute__((packed));
  44. __s32 l_sysid;
  45. __u32 l_pid;
  46. __s32 l_pad[4]; /* reserve area */
  47. } xfs_flock64_32_t;
  48. #define XFS_IOC_ALLOCSP_32 _IOW ('X', 10, struct xfs_flock64_32)
  49. #define XFS_IOC_FREESP_32 _IOW ('X', 11, struct xfs_flock64_32)
  50. #define XFS_IOC_ALLOCSP64_32 _IOW ('X', 36, struct xfs_flock64_32)
  51. #define XFS_IOC_FREESP64_32 _IOW ('X', 37, struct xfs_flock64_32)
  52. #define XFS_IOC_RESVSP_32 _IOW ('X', 40, struct xfs_flock64_32)
  53. #define XFS_IOC_UNRESVSP_32 _IOW ('X', 41, struct xfs_flock64_32)
  54. #define XFS_IOC_RESVSP64_32 _IOW ('X', 42, struct xfs_flock64_32)
  55. #define XFS_IOC_UNRESVSP64_32 _IOW ('X', 43, struct xfs_flock64_32)
  56. /* just account for different alignment */
  57. STATIC unsigned long
  58. xfs_ioctl32_flock(
  59. unsigned long arg)
  60. {
  61. xfs_flock64_32_t __user *p32 = (void __user *)arg;
  62. xfs_flock64_t __user *p = compat_alloc_user_space(sizeof(*p));
  63. if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) ||
  64. copy_in_user(&p->l_whence, &p32->l_whence, sizeof(s16)) ||
  65. copy_in_user(&p->l_start, &p32->l_start, sizeof(s64)) ||
  66. copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
  67. copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
  68. copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
  69. copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
  70. return -EFAULT;
  71. return (unsigned long)p;
  72. }
  73. #else
  74. typedef struct xfs_fsop_bulkreq32 {
  75. compat_uptr_t lastip; /* last inode # pointer */
  76. __s32 icount; /* count of entries in buffer */
  77. compat_uptr_t ubuffer; /* user buffer for inode desc. */
  78. __s32 ocount; /* output count pointer */
  79. } xfs_fsop_bulkreq32_t;
  80. STATIC unsigned long
  81. xfs_ioctl32_bulkstat(
  82. unsigned long arg)
  83. {
  84. xfs_fsop_bulkreq32_t __user *p32 = (void __user *)arg;
  85. xfs_fsop_bulkreq_t __user *p = compat_alloc_user_space(sizeof(*p));
  86. u32 addr;
  87. if (get_user(addr, &p32->lastip) ||
  88. put_user(compat_ptr(addr), &p->lastip) ||
  89. copy_in_user(&p->icount, &p32->icount, sizeof(s32)) ||
  90. get_user(addr, &p32->ubuffer) ||
  91. put_user(compat_ptr(addr), &p->ubuffer) ||
  92. get_user(addr, &p32->ocount) ||
  93. put_user(compat_ptr(addr), &p->ocount))
  94. return -EFAULT;
  95. return (unsigned long)p;
  96. }
  97. #endif
  98. STATIC long
  99. __linvfs_compat_ioctl(int mode, struct file *f, unsigned cmd, unsigned long arg)
  100. {
  101. int error;
  102. struct inode *inode = f->f_dentry->d_inode;
  103. vnode_t *vp = LINVFS_GET_VP(inode);
  104. switch (cmd) {
  105. case XFS_IOC_DIOINFO:
  106. case XFS_IOC_FSGEOMETRY_V1:
  107. case XFS_IOC_FSGEOMETRY:
  108. case XFS_IOC_GETVERSION:
  109. case XFS_IOC_GETXFLAGS:
  110. case XFS_IOC_SETXFLAGS:
  111. case XFS_IOC_FSGETXATTR:
  112. case XFS_IOC_FSSETXATTR:
  113. case XFS_IOC_FSGETXATTRA:
  114. case XFS_IOC_FSSETDM:
  115. case XFS_IOC_GETBMAP:
  116. case XFS_IOC_GETBMAPA:
  117. case XFS_IOC_GETBMAPX:
  118. /* not handled
  119. case XFS_IOC_FD_TO_HANDLE:
  120. case XFS_IOC_PATH_TO_HANDLE:
  121. case XFS_IOC_PATH_TO_FSHANDLE:
  122. case XFS_IOC_OPEN_BY_HANDLE:
  123. case XFS_IOC_FSSETDM_BY_HANDLE:
  124. case XFS_IOC_READLINK_BY_HANDLE:
  125. case XFS_IOC_ATTRLIST_BY_HANDLE:
  126. case XFS_IOC_ATTRMULTI_BY_HANDLE:
  127. */
  128. case XFS_IOC_FSCOUNTS:
  129. case XFS_IOC_SET_RESBLKS:
  130. case XFS_IOC_GET_RESBLKS:
  131. case XFS_IOC_FSGROWFSDATA:
  132. case XFS_IOC_FSGROWFSLOG:
  133. case XFS_IOC_FSGROWFSRT:
  134. case XFS_IOC_FREEZE:
  135. case XFS_IOC_THAW:
  136. case XFS_IOC_GOINGDOWN:
  137. case XFS_IOC_ERROR_INJECTION:
  138. case XFS_IOC_ERROR_CLEARALL:
  139. break;
  140. #ifdef BROKEN_X86_ALIGNMENT
  141. /* xfs_flock_t has wrong u32 vs u64 alignment */
  142. case XFS_IOC_ALLOCSP_32:
  143. case XFS_IOC_FREESP_32:
  144. case XFS_IOC_ALLOCSP64_32:
  145. case XFS_IOC_FREESP64_32:
  146. case XFS_IOC_RESVSP_32:
  147. case XFS_IOC_UNRESVSP_32:
  148. case XFS_IOC_RESVSP64_32:
  149. case XFS_IOC_UNRESVSP64_32:
  150. arg = xfs_ioctl32_flock(arg);
  151. cmd = _NATIVE_IOC(cmd, struct xfs_flock64);
  152. break;
  153. #else /* These are handled fine if no alignment issues */
  154. case XFS_IOC_ALLOCSP:
  155. case XFS_IOC_FREESP:
  156. case XFS_IOC_RESVSP:
  157. case XFS_IOC_UNRESVSP:
  158. case XFS_IOC_ALLOCSP64:
  159. case XFS_IOC_FREESP64:
  160. case XFS_IOC_RESVSP64:
  161. case XFS_IOC_UNRESVSP64:
  162. break;
  163. /* xfs_bstat_t still has wrong u32 vs u64 alignment */
  164. case XFS_IOC_SWAPEXT:
  165. break;
  166. case XFS_IOC_FSBULKSTAT_SINGLE:
  167. case XFS_IOC_FSBULKSTAT:
  168. case XFS_IOC_FSINUMBERS:
  169. arg = xfs_ioctl32_bulkstat(arg);
  170. break;
  171. #endif
  172. default:
  173. return -ENOIOCTLCMD;
  174. }
  175. VOP_IOCTL(vp, inode, f, mode, cmd, (void __user *)arg, error);
  176. VMODIFY(vp);
  177. return error;
  178. }
  179. long
  180. linvfs_compat_ioctl(
  181. struct file *f,
  182. unsigned cmd,
  183. unsigned long arg)
  184. {
  185. return __linvfs_compat_ioctl(0, f, cmd, arg);
  186. }
  187. long
  188. linvfs_compat_invis_ioctl(
  189. struct file *f,
  190. unsigned cmd,
  191. unsigned long arg)
  192. {
  193. return __linvfs_compat_ioctl(IO_INVIS, f, cmd, arg);
  194. }