xfs_ioctl32.c 5.9 KB

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