xfs_ioctl32.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Copyright (c) 2004-2005 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #include <linux/config.h>
  33. #include <linux/compat.h>
  34. #include <linux/init.h>
  35. #include <linux/ioctl.h>
  36. #include <linux/ioctl32.h>
  37. #include <linux/syscalls.h>
  38. #include <linux/types.h>
  39. #include <linux/fs.h>
  40. #include <asm/uaccess.h>
  41. #include "xfs.h"
  42. #include "xfs_types.h"
  43. #include "xfs_fs.h"
  44. #include "xfs_vfs.h"
  45. #include "xfs_vnode.h"
  46. #include "xfs_dfrag.h"
  47. #define _NATIVE_IOC(cmd, type) \
  48. _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
  49. #if defined(CONFIG_IA64) || defined(CONFIG_X86_64)
  50. #define BROKEN_X86_ALIGNMENT
  51. /* on ia32 l_start is on a 32-bit boundary */
  52. typedef struct xfs_flock64_32 {
  53. __s16 l_type;
  54. __s16 l_whence;
  55. __s64 l_start __attribute__((packed));
  56. /* len == 0 means until end of file */
  57. __s64 l_len __attribute__((packed));
  58. __s32 l_sysid;
  59. __u32 l_pid;
  60. __s32 l_pad[4]; /* reserve area */
  61. } xfs_flock64_32_t;
  62. #define XFS_IOC_ALLOCSP_32 _IOW ('X', 10, struct xfs_flock64_32)
  63. #define XFS_IOC_FREESP_32 _IOW ('X', 11, struct xfs_flock64_32)
  64. #define XFS_IOC_ALLOCSP64_32 _IOW ('X', 36, struct xfs_flock64_32)
  65. #define XFS_IOC_FREESP64_32 _IOW ('X', 37, struct xfs_flock64_32)
  66. #define XFS_IOC_RESVSP_32 _IOW ('X', 40, struct xfs_flock64_32)
  67. #define XFS_IOC_UNRESVSP_32 _IOW ('X', 41, struct xfs_flock64_32)
  68. #define XFS_IOC_RESVSP64_32 _IOW ('X', 42, struct xfs_flock64_32)
  69. #define XFS_IOC_UNRESVSP64_32 _IOW ('X', 43, struct xfs_flock64_32)
  70. /* just account for different alignment */
  71. STATIC unsigned long
  72. xfs_ioctl32_flock(
  73. unsigned long arg)
  74. {
  75. xfs_flock64_32_t __user *p32 = (void __user *)arg;
  76. xfs_flock64_t __user *p = compat_alloc_user_space(sizeof(*p));
  77. if (copy_in_user(&p->l_type, &p32->l_type, sizeof(s16)) ||
  78. copy_in_user(&p->l_whence, &p32->l_whence, sizeof(s16)) ||
  79. copy_in_user(&p->l_start, &p32->l_start, sizeof(s64)) ||
  80. copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
  81. copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
  82. copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
  83. copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
  84. return -EFAULT;
  85. return (unsigned long)p;
  86. }
  87. #else
  88. typedef struct xfs_fsop_bulkreq32 {
  89. compat_uptr_t lastip; /* last inode # pointer */
  90. __s32 icount; /* count of entries in buffer */
  91. compat_uptr_t ubuffer; /* user buffer for inode desc. */
  92. __s32 ocount; /* output count pointer */
  93. } xfs_fsop_bulkreq32_t;
  94. STATIC unsigned long
  95. xfs_ioctl32_bulkstat(
  96. unsigned long arg)
  97. {
  98. xfs_fsop_bulkreq32_t __user *p32 = (void __user *)arg;
  99. xfs_fsop_bulkreq_t __user *p = compat_alloc_user_space(sizeof(*p));
  100. u32 addr;
  101. if (get_user(addr, &p32->lastip) ||
  102. put_user(compat_ptr(addr), &p->lastip) ||
  103. copy_in_user(&p->icount, &p32->icount, sizeof(s32)) ||
  104. get_user(addr, &p32->ubuffer) ||
  105. put_user(compat_ptr(addr), &p->ubuffer) ||
  106. get_user(addr, &p32->ocount) ||
  107. put_user(compat_ptr(addr), &p->ocount))
  108. return -EFAULT;
  109. return (unsigned long)p;
  110. }
  111. #endif
  112. STATIC long
  113. __linvfs_compat_ioctl(int mode, struct file *f, unsigned cmd, unsigned long arg)
  114. {
  115. int error;
  116. struct inode *inode = f->f_dentry->d_inode;
  117. vnode_t *vp = LINVFS_GET_VP(inode);
  118. switch (cmd) {
  119. case XFS_IOC_DIOINFO:
  120. case XFS_IOC_FSGEOMETRY_V1:
  121. case XFS_IOC_FSGEOMETRY:
  122. case XFS_IOC_GETVERSION:
  123. case XFS_IOC_GETXFLAGS:
  124. case XFS_IOC_SETXFLAGS:
  125. case XFS_IOC_FSGETXATTR:
  126. case XFS_IOC_FSSETXATTR:
  127. case XFS_IOC_FSGETXATTRA:
  128. case XFS_IOC_FSSETDM:
  129. case XFS_IOC_GETBMAP:
  130. case XFS_IOC_GETBMAPA:
  131. case XFS_IOC_GETBMAPX:
  132. /* not handled
  133. case XFS_IOC_FD_TO_HANDLE:
  134. case XFS_IOC_PATH_TO_HANDLE:
  135. case XFS_IOC_PATH_TO_FSHANDLE:
  136. case XFS_IOC_OPEN_BY_HANDLE:
  137. case XFS_IOC_FSSETDM_BY_HANDLE:
  138. case XFS_IOC_READLINK_BY_HANDLE:
  139. case XFS_IOC_ATTRLIST_BY_HANDLE:
  140. case XFS_IOC_ATTRMULTI_BY_HANDLE:
  141. */
  142. case XFS_IOC_FSCOUNTS:
  143. case XFS_IOC_SET_RESBLKS:
  144. case XFS_IOC_GET_RESBLKS:
  145. case XFS_IOC_FSGROWFSDATA:
  146. case XFS_IOC_FSGROWFSLOG:
  147. case XFS_IOC_FSGROWFSRT:
  148. case XFS_IOC_FREEZE:
  149. case XFS_IOC_THAW:
  150. case XFS_IOC_GOINGDOWN:
  151. case XFS_IOC_ERROR_INJECTION:
  152. case XFS_IOC_ERROR_CLEARALL:
  153. break;
  154. #ifdef BROKEN_X86_ALIGNMENT
  155. /* xfs_flock_t has wrong u32 vs u64 alignment */
  156. case XFS_IOC_ALLOCSP_32:
  157. case XFS_IOC_FREESP_32:
  158. case XFS_IOC_ALLOCSP64_32:
  159. case XFS_IOC_FREESP64_32:
  160. case XFS_IOC_RESVSP_32:
  161. case XFS_IOC_UNRESVSP_32:
  162. case XFS_IOC_RESVSP64_32:
  163. case XFS_IOC_UNRESVSP64_32:
  164. arg = xfs_ioctl32_flock(arg);
  165. cmd = _NATIVE_IOC(cmd, struct xfs_flock64);
  166. break;
  167. #else /* These are handled fine if no alignment issues */
  168. case XFS_IOC_ALLOCSP:
  169. case XFS_IOC_FREESP:
  170. case XFS_IOC_RESVSP:
  171. case XFS_IOC_UNRESVSP:
  172. case XFS_IOC_ALLOCSP64:
  173. case XFS_IOC_FREESP64:
  174. case XFS_IOC_RESVSP64:
  175. case XFS_IOC_UNRESVSP64:
  176. break;
  177. /* xfs_bstat_t still has wrong u32 vs u64 alignment */
  178. case XFS_IOC_SWAPEXT:
  179. break;
  180. case XFS_IOC_FSBULKSTAT_SINGLE:
  181. case XFS_IOC_FSBULKSTAT:
  182. case XFS_IOC_FSINUMBERS:
  183. arg = xfs_ioctl32_bulkstat(arg);
  184. break;
  185. #endif
  186. default:
  187. return -ENOIOCTLCMD;
  188. }
  189. VOP_IOCTL(vp, inode, f, mode, cmd, (void __user *)arg, error);
  190. VMODIFY(vp);
  191. return error;
  192. }
  193. long
  194. linvfs_compat_ioctl(
  195. struct file *f,
  196. unsigned cmd,
  197. unsigned long arg)
  198. {
  199. return __linvfs_compat_ioctl(0, f, cmd, arg);
  200. }
  201. long
  202. linvfs_compat_invis_ioctl(
  203. struct file *f,
  204. unsigned cmd,
  205. unsigned long arg)
  206. {
  207. return __linvfs_compat_ioctl(IO_INVIS, f, cmd, arg);
  208. }