ioctl32.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:151k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* $Id: ioctl32.c,v 1.133.2.5 2002/03/01 08:52:38 davem Exp $
  2.  * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
  3.  *
  4.  * Copyright (C) 1997-2000  Jakub Jelinek  (jakub@redhat.com)
  5.  * Copyright (C) 1998  Eddie C. Dost  (ecd@skynet.be)
  6.  *
  7.  * These routines maintain argument size conversion between 32bit and 64bit
  8.  * ioctls.
  9.  */
  10. #include <linux/config.h>
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/smp.h>
  15. #include <linux/smp_lock.h>
  16. #include <linux/ioctl.h>
  17. #include <linux/if.h>
  18. #include <linux/slab.h>
  19. #include <linux/hdreg.h>
  20. #include <linux/raid/md.h>
  21. #include <linux/kd.h>
  22. #include <linux/route.h>
  23. #include <linux/in6.h>
  24. #include <linux/ipv6_route.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/netlink.h>
  27. #include <linux/vt.h>
  28. #include <linux/fs.h>
  29. #include <linux/file.h>
  30. #include <linux/fd.h>
  31. #include <linux/ppp_defs.h>
  32. #include <linux/if_ppp.h>
  33. #include <linux/if_pppox.h>
  34. #include <linux/if_tun.h>
  35. #include <linux/mtio.h>
  36. #include <linux/cdrom.h>
  37. #include <linux/loop.h>
  38. #include <linux/auto_fs.h>
  39. #include <linux/devfs_fs.h>
  40. #include <linux/tty.h>
  41. #include <linux/vt_kern.h>
  42. #include <linux/fb.h>
  43. #include <linux/ext2_fs.h>
  44. #include <linux/videodev.h>
  45. #include <linux/netdevice.h>
  46. #include <linux/raw.h>
  47. #include <linux/smb_fs.h>
  48. #include <linux/ncp_fs.h>
  49. #include <linux/blkpg.h>
  50. #include <linux/blk.h>
  51. #include <linux/elevator.h>
  52. #include <linux/rtc.h>
  53. #include <linux/pci.h>
  54. #if defined(CONFIG_BLK_DEV_LVM) || defined(CONFIG_BLK_DEV_LVM_MODULE)
  55. #include <linux/lvm.h>
  56. #endif /* LVM */
  57. #include <scsi/scsi.h>
  58. /* Ugly hack. */
  59. #undef __KERNEL__
  60. #include <scsi/scsi_ioctl.h>
  61. #define __KERNEL__
  62. #include <scsi/sg.h>
  63. #include <asm/types.h>
  64. #include <asm/uaccess.h>
  65. #include <asm/fbio.h>
  66. #include <asm/kbio.h>
  67. #include <asm/vuid_event.h>
  68. #include <asm/openpromio.h>
  69. #include <asm/envctrl.h>
  70. #include <asm/audioio.h>
  71. #include <linux/ethtool.h>
  72. #include <linux/mii.h>
  73. #include <linux/if_bonding.h>
  74. #include <asm/display7seg.h>
  75. #include <asm/watchdog.h>
  76. #include <asm/module.h>
  77. #include <linux/soundcard.h>
  78. #include <linux/lp.h>
  79. #include <linux/atm.h>
  80. #include <linux/atmarp.h>
  81. #include <linux/atmclip.h>
  82. #include <linux/atmdev.h>
  83. #include <linux/atmioc.h>
  84. #include <linux/atmlec.h>
  85. #include <linux/atmmpc.h>
  86. #include <linux/atmsvc.h>
  87. #include <linux/atm_tcp.h>
  88. #include <linux/sonet.h>
  89. #include <linux/atm_suni.h>
  90. #include <linux/mtd/mtd.h>
  91. #include <net/bluetooth/bluetooth.h>
  92. #include <net/bluetooth/hci.h>
  93. #include <linux/usb.h>
  94. #include <linux/usbdevice_fs.h>
  95. #include <linux/nbd.h>
  96. #include <linux/random.h>
  97. #include <linux/filter.h>
  98. /* Use this to get at 32-bit user passed pointers. 
  99.    See sys_sparc32.c for description about these. */
  100. #define A(__x) ((unsigned long)(__x))
  101. #define AA(__x)
  102. ({ unsigned long __ret;
  103. __asm__ ("srl %0, 0, %0"
  104.  : "=r" (__ret)
  105.  : "0" (__x));
  106. __ret;
  107. })
  108. /* Aiee. Someone does not find a difference between int and long */
  109. #define EXT2_IOC32_GETFLAGS               _IOR('f', 1, int)
  110. #define EXT2_IOC32_SETFLAGS               _IOW('f', 2, int)
  111. #define EXT2_IOC32_GETVERSION             _IOR('v', 1, int)
  112. #define EXT2_IOC32_SETVERSION             _IOW('v', 2, int)
  113. extern asmlinkage int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg);
  114. static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
  115. {
  116. mm_segment_t old_fs = get_fs();
  117. int err;
  118. unsigned long val;
  119. set_fs (KERNEL_DS);
  120. err = sys_ioctl(fd, cmd, (unsigned long)&val);
  121. set_fs (old_fs);
  122. if (!err && put_user(val, (u32 *)arg))
  123. return -EFAULT;
  124. return err;
  125. }
  126.  
  127. static int rw_long(unsigned int fd, unsigned int cmd, unsigned long arg)
  128. {
  129. mm_segment_t old_fs = get_fs();
  130. int err;
  131. unsigned long val;
  132. if(get_user(val, (u32 *)arg))
  133. return -EFAULT;
  134. set_fs (KERNEL_DS);
  135. err = sys_ioctl(fd, cmd, (unsigned long)&val);
  136. set_fs (old_fs);
  137. if (!err && put_user(val, (u32 *)arg))
  138. return -EFAULT;
  139. return err;
  140. }
  141. static int do_ext2_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  142. {
  143. /* These are just misnamed, they actually get/put from/to user an int */
  144. switch (cmd) {
  145. case EXT2_IOC32_GETFLAGS: cmd = EXT2_IOC_GETFLAGS; break;
  146. case EXT2_IOC32_SETFLAGS: cmd = EXT2_IOC_SETFLAGS; break;
  147. case EXT2_IOC32_GETVERSION: cmd = EXT2_IOC_GETVERSION; break;
  148. case EXT2_IOC32_SETVERSION: cmd = EXT2_IOC_SETVERSION; break;
  149. }
  150. return sys_ioctl(fd, cmd, arg);
  151. }
  152.  
  153. struct video_tuner32 {
  154. s32 tuner;
  155. u8 name[32];
  156. u32 rangelow, rangehigh;
  157. u32 flags;
  158. u16 mode, signal;
  159. };
  160. static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 *up)
  161. {
  162. int i;
  163. if(get_user(kp->tuner, &up->tuner))
  164. return -EFAULT;
  165. for(i = 0; i < 32; i++)
  166. __get_user(kp->name[i], &up->name[i]);
  167. __get_user(kp->rangelow, &up->rangelow);
  168. __get_user(kp->rangehigh, &up->rangehigh);
  169. __get_user(kp->flags, &up->flags);
  170. __get_user(kp->mode, &up->mode);
  171. __get_user(kp->signal, &up->signal);
  172. return 0;
  173. }
  174. static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 *up)
  175. {
  176. int i;
  177. if(put_user(kp->tuner, &up->tuner))
  178. return -EFAULT;
  179. for(i = 0; i < 32; i++)
  180. __put_user(kp->name[i], &up->name[i]);
  181. __put_user(kp->rangelow, &up->rangelow);
  182. __put_user(kp->rangehigh, &up->rangehigh);
  183. __put_user(kp->flags, &up->flags);
  184. __put_user(kp->mode, &up->mode);
  185. __put_user(kp->signal, &up->signal);
  186. return 0;
  187. }
  188. struct video_buffer32 {
  189. /* void * */ u32 base;
  190. s32 height, width, depth, bytesperline;
  191. };
  192. static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 *up)
  193. {
  194. u32 tmp;
  195. if(get_user(tmp, &up->base))
  196. return -EFAULT;
  197. kp->base = (void *) ((unsigned long)tmp);
  198. __get_user(kp->height, &up->height);
  199. __get_user(kp->width, &up->width);
  200. __get_user(kp->depth, &up->depth);
  201. __get_user(kp->bytesperline, &up->bytesperline);
  202. return 0;
  203. }
  204. static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 *up)
  205. {
  206. u32 tmp = (u32)((unsigned long)kp->base);
  207. if(put_user(tmp, &up->base))
  208. return -EFAULT;
  209. __put_user(kp->height, &up->height);
  210. __put_user(kp->width, &up->width);
  211. __put_user(kp->depth, &up->depth);
  212. __put_user(kp->bytesperline, &up->bytesperline);
  213. return 0;
  214. }
  215. struct video_clip32 {
  216. s32 x, y, width, height;
  217. /* struct video_clip32 * */ u32 next;
  218. };
  219. struct video_window32 {
  220. u32 x, y, width, height, chromakey, flags;
  221. /* struct video_clip32 * */ u32 clips;
  222. s32 clipcount;
  223. };
  224. static void free_kvideo_clips(struct video_window *kp)
  225. {
  226. struct video_clip *cp;
  227. cp = kp->clips;
  228. if(cp != NULL)
  229. kfree(cp);
  230. }
  231. static int get_video_window32(struct video_window *kp, struct video_window32 *up)
  232. {
  233. struct video_clip32 *ucp;
  234. struct video_clip *kcp;
  235. int nclips, err, i;
  236. u32 tmp;
  237. if(get_user(kp->x, &up->x))
  238. return -EFAULT;
  239. __get_user(kp->y, &up->y);
  240. __get_user(kp->width, &up->width);
  241. __get_user(kp->height, &up->height);
  242. __get_user(kp->chromakey, &up->chromakey);
  243. __get_user(kp->flags, &up->flags);
  244. __get_user(kp->clipcount, &up->clipcount);
  245. __get_user(tmp, &up->clips);
  246. ucp = (struct video_clip32 *)A(tmp);
  247. kp->clips = NULL;
  248. nclips = kp->clipcount;
  249. if(nclips == 0)
  250. return 0;
  251. if(ucp == 0)
  252. return -EINVAL;
  253. /* Peculiar interface... */
  254. if(nclips < 0)
  255. nclips = VIDEO_CLIPMAP_SIZE;
  256. kcp = kmalloc(nclips * sizeof(struct video_clip), GFP_KERNEL);
  257. err = -ENOMEM;
  258. if(kcp == NULL)
  259. goto cleanup_and_err;
  260. kp->clips = kcp;
  261. for(i = 0; i < nclips; i++) {
  262. __get_user(kcp[i].x, &ucp[i].x);
  263. __get_user(kcp[i].y, &ucp[i].y);
  264. __get_user(kcp[i].width, &ucp[i].width);
  265. __get_user(kcp[i].height, &ucp[i].height);
  266. kcp[nclips].next = NULL;
  267. }
  268. return 0;
  269. cleanup_and_err:
  270. free_kvideo_clips(kp);
  271. return err;
  272. }
  273. /* You get back everything except the clips... */
  274. static int put_video_window32(struct video_window *kp, struct video_window32 *up)
  275. {
  276. if(put_user(kp->x, &up->x))
  277. return -EFAULT;
  278. __put_user(kp->y, &up->y);
  279. __put_user(kp->width, &up->width);
  280. __put_user(kp->height, &up->height);
  281. __put_user(kp->chromakey, &up->chromakey);
  282. __put_user(kp->flags, &up->flags);
  283. __put_user(kp->clipcount, &up->clipcount);
  284. return 0;
  285. }
  286. #define VIDIOCGTUNER32 _IOWR('v',4, struct video_tuner32)
  287. #define VIDIOCSTUNER32 _IOW('v',5, struct video_tuner32)
  288. #define VIDIOCGWIN32 _IOR('v',9, struct video_window32)
  289. #define VIDIOCSWIN32 _IOW('v',10, struct video_window32)
  290. #define VIDIOCGFBUF32 _IOR('v',11, struct video_buffer32)
  291. #define VIDIOCSFBUF32 _IOW('v',12, struct video_buffer32)
  292. #define VIDIOCGFREQ32 _IOR('v',14, u32)
  293. #define VIDIOCSFREQ32 _IOW('v',15, u32)
  294. static int do_video_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  295. {
  296. union {
  297. struct video_tuner vt;
  298. struct video_buffer vb;
  299. struct video_window vw;
  300. unsigned long vx;
  301. } karg;
  302. mm_segment_t old_fs = get_fs();
  303. void *up = (void *)arg;
  304. int err = 0;
  305. /* First, convert the command. */
  306. switch(cmd) {
  307. case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break;
  308. case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break;
  309. case VIDIOCGWIN32: cmd = VIDIOCGWIN; break;
  310. case VIDIOCSWIN32: cmd = VIDIOCSWIN; break;
  311. case VIDIOCGFBUF32: cmd = VIDIOCGFBUF; break;
  312. case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break;
  313. case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break;
  314. case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break;
  315. };
  316. switch(cmd) {
  317. case VIDIOCSTUNER:
  318. case VIDIOCGTUNER:
  319. err = get_video_tuner32(&karg.vt, up);
  320. break;
  321. case VIDIOCSWIN:
  322. err = get_video_window32(&karg.vw, up);
  323. break;
  324. case VIDIOCSFBUF:
  325. err = get_video_buffer32(&karg.vb, up);
  326. break;
  327. case VIDIOCSFREQ:
  328. err = get_user(karg.vx, (u32 *)up);
  329. break;
  330. };
  331. if(err)
  332. goto out;
  333. set_fs(KERNEL_DS);
  334. err = sys_ioctl(fd, cmd, (unsigned long)&karg);
  335. set_fs(old_fs);
  336. if(cmd == VIDIOCSWIN)
  337. free_kvideo_clips(&karg.vw);
  338. if(err == 0) {
  339. switch(cmd) {
  340. case VIDIOCGTUNER:
  341. err = put_video_tuner32(&karg.vt, up);
  342. break;
  343. case VIDIOCGWIN:
  344. err = put_video_window32(&karg.vw, up);
  345. break;
  346. case VIDIOCGFBUF:
  347. err = put_video_buffer32(&karg.vb, up);
  348. break;
  349. case VIDIOCGFREQ:
  350. err = put_user(((u32)karg.vx), (u32 *)up);
  351. break;
  352. };
  353. }
  354. out:
  355. return err;
  356. }
  357. struct timeval32 {
  358. int tv_sec;
  359. int tv_usec;
  360. };
  361. static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
  362. {
  363. struct timeval32 *up = (struct timeval32 *)arg;
  364. struct timeval ktv;
  365. mm_segment_t old_fs = get_fs();
  366. int err;
  367. set_fs(KERNEL_DS);
  368. err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
  369. set_fs(old_fs);
  370. if(!err) {
  371. err = put_user(ktv.tv_sec, &up->tv_sec);
  372. err |= __put_user(ktv.tv_usec, &up->tv_usec);
  373. }
  374. return err;
  375. }
  376. struct ifmap32 {
  377. u32 mem_start;
  378. u32 mem_end;
  379. unsigned short base_addr;
  380. unsigned char irq;
  381. unsigned char dma;
  382. unsigned char port;
  383. };
  384. struct ifreq32 {
  385. #define IFHWADDRLEN     6
  386. #define IFNAMSIZ        16
  387.         union {
  388.                 char    ifrn_name[IFNAMSIZ];            /* if name, e.g. "en0" */
  389.         } ifr_ifrn;
  390.         union {
  391.                 struct  sockaddr ifru_addr;
  392.                 struct  sockaddr ifru_dstaddr;
  393.                 struct  sockaddr ifru_broadaddr;
  394.                 struct  sockaddr ifru_netmask;
  395.                 struct  sockaddr ifru_hwaddr;
  396.                 short   ifru_flags;
  397.                 int     ifru_ivalue;
  398.                 int     ifru_mtu;
  399.                 struct  ifmap32 ifru_map;
  400.                 char    ifru_slave[IFNAMSIZ];   /* Just fits the size */
  401. char ifru_newname[IFNAMSIZ];
  402.                 __kernel_caddr_t32 ifru_data;
  403.         } ifr_ifru;
  404. };
  405. struct ifconf32 {
  406.         int     ifc_len;                        /* size of buffer       */
  407.         __kernel_caddr_t32  ifcbuf;
  408. };
  409. #ifdef CONFIG_NET
  410. static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
  411. {
  412. struct net_device *dev;
  413. struct ifreq32 ifr32;
  414. int err;
  415. if (copy_from_user(&ifr32, (struct ifreq32 *)arg, sizeof(struct ifreq32)))
  416. return -EFAULT;
  417. dev = dev_get_by_index(ifr32.ifr_ifindex);
  418. if (!dev)
  419. return -ENODEV;
  420. strcpy(ifr32.ifr_name, dev->name);
  421. dev_put(dev);
  422. err = copy_to_user((struct ifreq32 *)arg, &ifr32, sizeof(struct ifreq32));
  423. return (err ? -EFAULT : 0);
  424. }
  425. #endif
  426. static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
  427. {
  428. struct ifconf32 ifc32;
  429. struct ifconf ifc;
  430. struct ifreq32 *ifr32;
  431. struct ifreq *ifr;
  432. mm_segment_t old_fs;
  433. unsigned int i, j;
  434. int err;
  435. if (copy_from_user(&ifc32, (struct ifconf32 *)arg, sizeof(struct ifconf32)))
  436. return -EFAULT;
  437. if(ifc32.ifcbuf == 0) {
  438. ifc32.ifc_len = 0;
  439. ifc.ifc_len = 0;
  440. ifc.ifc_buf = NULL;
  441. } else {
  442. ifc.ifc_len = ((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
  443. sizeof (struct ifreq);
  444. ifc.ifc_buf = kmalloc (ifc.ifc_len, GFP_KERNEL);
  445. if (!ifc.ifc_buf)
  446. return -ENOMEM;
  447. }
  448. ifr = ifc.ifc_req;
  449. ifr32 = (struct ifreq32 *)A(ifc32.ifcbuf);
  450. for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
  451. if (copy_from_user(ifr++, ifr32++, sizeof (struct ifreq32))) {
  452. kfree (ifc.ifc_buf);
  453. return -EFAULT;
  454. }
  455. }
  456. old_fs = get_fs(); set_fs (KERNEL_DS);
  457. err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)&ifc);
  458. set_fs (old_fs);
  459. if (!err) {
  460. ifr = ifc.ifc_req;
  461. ifr32 = (struct ifreq32 *)A(ifc32.ifcbuf);
  462. for (i = 0, j = 0; i < ifc32.ifc_len && j < ifc.ifc_len;
  463.      i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
  464. if (copy_to_user(ifr32++, ifr++, sizeof (struct ifreq32))) {
  465. err = -EFAULT;
  466. break;
  467. }
  468. }
  469. if (!err) {
  470. if (ifc32.ifcbuf == 0) {
  471. /* Translate from 64-bit structure multiple to
  472.  * a 32-bit one.
  473.  */
  474. i = ifc.ifc_len;
  475. i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
  476. ifc32.ifc_len = i;
  477. } else {
  478. if (i <= ifc32.ifc_len)
  479. ifc32.ifc_len = i;
  480. else
  481. ifc32.ifc_len = i - sizeof (struct ifreq32);
  482. }
  483. if (copy_to_user((struct ifconf32 *)arg, &ifc32, sizeof(struct ifconf32)))
  484. err = -EFAULT;
  485. }
  486. }
  487. if(ifc.ifc_buf != NULL)
  488. kfree (ifc.ifc_buf);
  489. return err;
  490. }
  491. static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  492. {
  493. struct ifreq ifr;
  494. mm_segment_t old_fs;
  495. int err, len;
  496. u32 data, ethcmd;
  497. if (copy_from_user(&ifr, (struct ifreq32 *)arg, sizeof(struct ifreq32)))
  498. return -EFAULT;
  499. ifr.ifr_data = (__kernel_caddr_t)get_free_page(GFP_KERNEL);
  500. if (!ifr.ifr_data)
  501. return -EAGAIN;
  502. __get_user(data, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_data));
  503. if (get_user(ethcmd, (u32 *)A(data))) {
  504. err = -EFAULT;
  505. goto out;
  506. }
  507. switch (ethcmd) {
  508. case ETHTOOL_GDRVINFO: len = sizeof(struct ethtool_drvinfo); break;
  509. case ETHTOOL_GMSGLVL:
  510. case ETHTOOL_SMSGLVL:
  511. case ETHTOOL_GLINK:
  512. case ETHTOOL_NWAY_RST: len = sizeof(struct ethtool_value); break;
  513. case ETHTOOL_GREGS: {
  514. struct ethtool_regs *regaddr = (struct ethtool_regs *)A(data);
  515. /* darned variable size arguments */
  516. if (get_user(len, (u32 *)&regaddr->len)) {
  517. err = -EFAULT;
  518. goto out;
  519. }
  520. len += sizeof(struct ethtool_regs);
  521. break;
  522. }
  523. case ETHTOOL_GSET:
  524. case ETHTOOL_SSET: len = sizeof(struct ethtool_cmd); break;
  525. default:
  526. err = -EOPNOTSUPP;
  527. goto out;
  528. }
  529. if (copy_from_user(ifr.ifr_data, (char *)A(data), len)) {
  530. err = -EFAULT;
  531. goto out;
  532. }
  533. old_fs = get_fs();
  534. set_fs (KERNEL_DS);
  535. err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
  536. set_fs (old_fs);
  537. if (!err) {
  538. u32 data;
  539. __get_user(data, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_data));
  540. len = copy_to_user((char *)A(data), ifr.ifr_data, len);
  541. if (len)
  542. err = -EFAULT;
  543. }
  544. out:
  545. free_page((unsigned long)ifr.ifr_data);
  546. return err;
  547. }
  548. static int bond_ioctl(unsigned long fd, unsigned int cmd, unsigned long arg)
  549. {
  550. struct ifreq ifr;
  551. mm_segment_t old_fs;
  552. int err, len;
  553. u32 data;
  554. if (copy_from_user(&ifr, (struct ifreq32 *)arg, sizeof(struct ifreq32)))
  555. return -EFAULT;
  556. ifr.ifr_data = (__kernel_caddr_t)get_free_page(GFP_KERNEL);
  557. if (!ifr.ifr_data)
  558. return -EAGAIN;
  559. switch (cmd) {
  560. case SIOCBONDENSLAVE:
  561. case SIOCBONDRELEASE:
  562. case SIOCBONDSETHWADDR:
  563. case SIOCBONDCHANGEACTIVE:
  564. len = IFNAMSIZ * sizeof(char);
  565. break;
  566. case SIOCBONDSLAVEINFOQUERY:
  567. len = sizeof(struct ifslave);
  568. break;
  569. case SIOCBONDINFOQUERY:
  570. len = sizeof(struct ifbond);
  571. break;
  572. default:
  573. err = -EINVAL;
  574. goto out;
  575. };
  576. __get_user(data, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_data));
  577. if (copy_from_user(ifr.ifr_data, (char *)A(data), len)) {
  578. err = -EFAULT;
  579. goto out;
  580. }
  581. old_fs = get_fs();
  582. set_fs (KERNEL_DS);
  583. err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
  584. set_fs (old_fs);
  585. if (!err) {
  586. len = copy_to_user((char *)A(data), ifr.ifr_data, len);
  587. if (len)
  588. err = -EFAULT;
  589. }
  590. out:
  591. free_page((unsigned long)ifr.ifr_data);
  592. return err;
  593. }
  594. static __inline__ void *alloc_user_space(long len)
  595. {
  596. struct pt_regs *regs = current->thread.kregs;
  597. unsigned long usp = regs->u_regs[UREG_I6];
  598. if (!(current->thread.flags & SPARC_FLAG_32BIT))
  599. usp += STACK_BIAS;
  600. return (void *) (usp - len);
  601. }
  602. static int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  603. {
  604. struct ifreq *u_ifreq64;
  605. struct ifreq32 *u_ifreq32 = (struct ifreq32 *) arg;
  606. char tmp_buf[IFNAMSIZ];
  607. void *data64;
  608. u32 data32;
  609. if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
  610.    IFNAMSIZ))
  611. return -EFAULT;
  612. if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
  613. return -EFAULT;
  614. data64 = (void *) A(data32);
  615. u_ifreq64 = alloc_user_space(sizeof(*u_ifreq64));
  616. /* Don't check these user accesses, just let that get trapped
  617.  * in the ioctl handler instead.
  618.  */
  619. copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0], IFNAMSIZ);
  620. __put_user(data64, &u_ifreq64->ifr_ifru.ifru_data);
  621. return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
  622. }
  623. static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
  624. {
  625. struct ifreq ifr;
  626. mm_segment_t old_fs;
  627. int err;
  628. switch (cmd) {
  629. case SIOCSIFMAP:
  630. err = copy_from_user(&ifr, (struct ifreq32 *)arg, sizeof(ifr.ifr_name));
  631. err |= __get_user(ifr.ifr_map.mem_start, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.mem_start));
  632. err |= __get_user(ifr.ifr_map.mem_end, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.mem_end));
  633. err |= __get_user(ifr.ifr_map.base_addr, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.base_addr));
  634. err |= __get_user(ifr.ifr_map.irq, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.irq));
  635. err |= __get_user(ifr.ifr_map.dma, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.dma));
  636. err |= __get_user(ifr.ifr_map.port, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.port));
  637. if (err)
  638. return -EFAULT;
  639. break;
  640. default:
  641. if (copy_from_user(&ifr, (struct ifreq32 *)arg, sizeof(struct ifreq32)))
  642. return -EFAULT;
  643. break;
  644. }
  645. old_fs = get_fs();
  646. set_fs (KERNEL_DS);
  647. err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
  648. set_fs (old_fs);
  649. if (!err) {
  650. switch (cmd) {
  651. case SIOCGIFFLAGS:
  652. case SIOCGIFMETRIC:
  653. case SIOCGIFMTU:
  654. case SIOCGIFMEM:
  655. case SIOCGIFHWADDR:
  656. case SIOCGIFINDEX:
  657. case SIOCGIFADDR:
  658. case SIOCGIFBRDADDR:
  659. case SIOCGIFDSTADDR:
  660. case SIOCGIFNETMASK:
  661. case SIOCGIFTXQLEN:
  662. if (copy_to_user((struct ifreq32 *)arg, &ifr, sizeof(struct ifreq32)))
  663. return -EFAULT;
  664. break;
  665. case SIOCGIFMAP:
  666. err = copy_to_user((struct ifreq32 *)arg, &ifr, sizeof(ifr.ifr_name));
  667. err |= __put_user(ifr.ifr_map.mem_start, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.mem_start));
  668. err |= __put_user(ifr.ifr_map.mem_end, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.mem_end));
  669. err |= __put_user(ifr.ifr_map.base_addr, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.base_addr));
  670. err |= __put_user(ifr.ifr_map.irq, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.irq));
  671. err |= __put_user(ifr.ifr_map.dma, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.dma));
  672. err |= __put_user(ifr.ifr_map.port, &(((struct ifreq32 *)arg)->ifr_ifru.ifru_map.port));
  673. if (err)
  674. err = -EFAULT;
  675. break;
  676. }
  677. }
  678. return err;
  679. }
  680. struct rtentry32 {
  681.         u32    rt_pad1;
  682.         struct sockaddr rt_dst;         /* target address               */
  683.         struct sockaddr rt_gateway;     /* gateway addr (RTF_GATEWAY)   */
  684.         struct sockaddr rt_genmask;     /* target network mask (IP)     */
  685.         unsigned short  rt_flags;
  686.         short           rt_pad2;
  687.         u32    rt_pad3;
  688.         unsigned char   rt_tos;
  689.         unsigned char   rt_class;
  690.         short           rt_pad4;
  691.         short           rt_metric;      /* +1 for binary compatibility! */
  692.         /* char * */ u32 rt_dev;        /* forcing the device at add    */
  693.         u32    rt_mtu;         /* per route MTU/Window         */
  694.         u32    rt_window;      /* Window clamping              */
  695.         unsigned short  rt_irtt;        /* Initial RTT                  */
  696. };
  697. struct in6_rtmsg32 {
  698. struct in6_addr rtmsg_dst;
  699. struct in6_addr rtmsg_src;
  700. struct in6_addr rtmsg_gateway;
  701. u32 rtmsg_type;
  702. u16 rtmsg_dst_len;
  703. u16 rtmsg_src_len;
  704. u32 rtmsg_metric;
  705. u32 rtmsg_info;
  706. u32 rtmsg_flags;
  707. s32 rtmsg_ifindex;
  708. };
  709. extern struct socket *sockfd_lookup(int fd, int *err);
  710. extern __inline__ void sockfd_put(struct socket *sock)
  711. {
  712. fput(sock->file);
  713. }
  714. static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  715. {
  716. int ret;
  717. void *r = NULL;
  718. struct in6_rtmsg r6;
  719. struct rtentry r4;
  720. char devname[16];
  721. u32 rtdev;
  722. mm_segment_t old_fs = get_fs();
  723. struct socket *mysock = sockfd_lookup(fd, &ret);
  724. if (mysock && mysock->sk && mysock->sk->family == AF_INET6) { /* ipv6 */
  725. ret = copy_from_user (&r6.rtmsg_dst, &(((struct in6_rtmsg32 *)arg)->rtmsg_dst),
  726. 3 * sizeof(struct in6_addr));
  727. ret |= __get_user (r6.rtmsg_type, &(((struct in6_rtmsg32 *)arg)->rtmsg_type));
  728. ret |= __get_user (r6.rtmsg_dst_len, &(((struct in6_rtmsg32 *)arg)->rtmsg_dst_len));
  729. ret |= __get_user (r6.rtmsg_src_len, &(((struct in6_rtmsg32 *)arg)->rtmsg_src_len));
  730. ret |= __get_user (r6.rtmsg_metric, &(((struct in6_rtmsg32 *)arg)->rtmsg_metric));
  731. ret |= __get_user (r6.rtmsg_info, &(((struct in6_rtmsg32 *)arg)->rtmsg_info));
  732. ret |= __get_user (r6.rtmsg_flags, &(((struct in6_rtmsg32 *)arg)->rtmsg_flags));
  733. ret |= __get_user (r6.rtmsg_ifindex, &(((struct in6_rtmsg32 *)arg)->rtmsg_ifindex));
  734. r = (void *) &r6;
  735. } else { /* ipv4 */
  736. ret = copy_from_user (&r4.rt_dst, &(((struct rtentry32 *)arg)->rt_dst), 3 * sizeof(struct sockaddr));
  737. ret |= __get_user (r4.rt_flags, &(((struct rtentry32 *)arg)->rt_flags));
  738. ret |= __get_user (r4.rt_metric, &(((struct rtentry32 *)arg)->rt_metric));
  739. ret |= __get_user (r4.rt_mtu, &(((struct rtentry32 *)arg)->rt_mtu));
  740. ret |= __get_user (r4.rt_window, &(((struct rtentry32 *)arg)->rt_window));
  741. ret |= __get_user (r4.rt_irtt, &(((struct rtentry32 *)arg)->rt_irtt));
  742. ret |= __get_user (rtdev, &(((struct rtentry32 *)arg)->rt_dev));
  743. if (rtdev) {
  744. ret |= copy_from_user (devname, (char *)A(rtdev), 15);
  745. r4.rt_dev = devname; devname[15] = 0;
  746. } else
  747. r4.rt_dev = 0;
  748. r = (void *) &r4;
  749. }
  750. if (ret)
  751. return -EFAULT;
  752. set_fs (KERNEL_DS);
  753. ret = sys_ioctl (fd, cmd, (long) r);
  754. set_fs (old_fs);
  755. if (mysock)
  756. sockfd_put(mysock);
  757. return ret;
  758. }
  759. struct hd_geometry32 {
  760. unsigned char heads;
  761. unsigned char sectors;
  762. unsigned short cylinders;
  763. u32 start;
  764. };
  765.                         
  766. static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg)
  767. {
  768. mm_segment_t old_fs = get_fs();
  769. struct hd_geometry geo;
  770. int err;
  771. set_fs (KERNEL_DS);
  772. err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo);
  773. set_fs (old_fs);
  774. if (!err) {
  775. if (copy_to_user ((struct hd_geometry32 *)arg, &geo, 4) ||
  776.     __put_user (geo.start, &(((struct hd_geometry32 *)arg)->start)))
  777. err = -EFAULT;
  778. }
  779. return err;
  780. }
  781. struct hd_big_geometry32 {
  782. unsigned char heads;
  783. unsigned char sectors;
  784. unsigned int cylinders;
  785. u32 start;
  786. };
  787.                         
  788. static int hdio_getgeo_big(unsigned int fd, unsigned int cmd, unsigned long arg)
  789. {
  790. mm_segment_t old_fs = get_fs();
  791. struct hd_big_geometry geo;
  792. int err;
  793. set_fs (KERNEL_DS);
  794. err = sys_ioctl(fd, cmd, (unsigned long)&geo);
  795. set_fs (old_fs);
  796. if (!err) {
  797. struct hd_big_geometry32 *up = (struct hd_big_geometry32 *) arg;
  798. if (put_user(geo.heads, &up->heads) ||
  799.     __put_user(geo.sectors, &up->sectors) ||
  800.     __put_user(geo.cylinders, &up->cylinders) ||
  801.     __put_user(((u32) geo.start), &up->start))
  802. err = -EFAULT;
  803. }
  804. return err;
  805. }
  806. struct  fbcmap32 {
  807. int             index;          /* first element (0 origin) */
  808. int             count;
  809. u32 red;
  810. u32 green;
  811. u32 blue;
  812. };
  813. #define FBIOPUTCMAP32 _IOW('F', 3, struct fbcmap32)
  814. #define FBIOGETCMAP32 _IOW('F', 4, struct fbcmap32)
  815. static int fbiogetputcmap(unsigned int fd, unsigned int cmd, unsigned long arg)
  816. {
  817. struct fbcmap f;
  818. int ret;
  819. char red[256], green[256], blue[256];
  820. u32 r, g, b;
  821. mm_segment_t old_fs = get_fs();
  822. ret = get_user(f.index, &(((struct fbcmap32 *)arg)->index));
  823. ret |= __get_user(f.count, &(((struct fbcmap32 *)arg)->count));
  824. ret |= __get_user(r, &(((struct fbcmap32 *)arg)->red));
  825. ret |= __get_user(g, &(((struct fbcmap32 *)arg)->green));
  826. ret |= __get_user(b, &(((struct fbcmap32 *)arg)->blue));
  827. if (ret)
  828. return -EFAULT;
  829. if ((f.index < 0) || (f.index > 255)) return -EINVAL;
  830. if (f.index + f.count > 256)
  831. f.count = 256 - f.index;
  832. if (cmd == FBIOPUTCMAP32) {
  833. ret = copy_from_user (red, (char *)A(r), f.count);
  834. ret |= copy_from_user (green, (char *)A(g), f.count);
  835. ret |= copy_from_user (blue, (char *)A(b), f.count);
  836. if (ret)
  837. return -EFAULT;
  838. }
  839. f.red = red; f.green = green; f.blue = blue;
  840. set_fs (KERNEL_DS);
  841. ret = sys_ioctl (fd, (cmd == FBIOPUTCMAP32) ? FBIOPUTCMAP_SPARC : FBIOGETCMAP_SPARC, (long)&f);
  842. set_fs (old_fs);
  843. if (!ret && cmd == FBIOGETCMAP32) {
  844. ret = copy_to_user ((char *)A(r), red, f.count);
  845. ret |= copy_to_user ((char *)A(g), green, f.count);
  846. ret |= copy_to_user ((char *)A(b), blue, f.count);
  847. }
  848. return ret ? -EFAULT : 0;
  849. }
  850. struct fbcursor32 {
  851. short set; /* what to set, choose from the list above */
  852. short enable; /* cursor on/off */
  853. struct fbcurpos pos; /* cursor position */
  854. struct fbcurpos hot; /* cursor hot spot */
  855. struct fbcmap32 cmap; /* color map info */
  856. struct fbcurpos size; /* cursor bit map size */
  857. u32 image; /* cursor image bits */
  858. u32 mask; /* cursor mask bits */
  859. };
  860. #define FBIOSCURSOR32 _IOW('F', 24, struct fbcursor32)
  861. #define FBIOGCURSOR32 _IOW('F', 25, struct fbcursor32)
  862. static int fbiogscursor(unsigned int fd, unsigned int cmd, unsigned long arg)
  863. {
  864. struct fbcursor f;
  865. int ret;
  866. char red[2], green[2], blue[2];
  867. char image[128], mask[128];
  868. u32 r, g, b;
  869. u32 m, i;
  870. mm_segment_t old_fs = get_fs();
  871. ret = copy_from_user (&f, (struct fbcursor32 *)arg, 2 * sizeof (short) + 2 * sizeof(struct fbcurpos));
  872. ret |= __get_user(f.size.fbx, &(((struct fbcursor32 *)arg)->size.fbx));
  873. ret |= __get_user(f.size.fby, &(((struct fbcursor32 *)arg)->size.fby));
  874. ret |= __get_user(f.cmap.index, &(((struct fbcursor32 *)arg)->cmap.index));
  875. ret |= __get_user(f.cmap.count, &(((struct fbcursor32 *)arg)->cmap.count));
  876. ret |= __get_user(r, &(((struct fbcursor32 *)arg)->cmap.red));
  877. ret |= __get_user(g, &(((struct fbcursor32 *)arg)->cmap.green));
  878. ret |= __get_user(b, &(((struct fbcursor32 *)arg)->cmap.blue));
  879. ret |= __get_user(m, &(((struct fbcursor32 *)arg)->mask));
  880. ret |= __get_user(i, &(((struct fbcursor32 *)arg)->image));
  881. if (ret)
  882. return -EFAULT;
  883. if (f.set & FB_CUR_SETCMAP) {
  884. if ((uint) f.size.fby > 32)
  885. return -EINVAL;
  886. ret = copy_from_user (mask, (char *)A(m), f.size.fby * 4);
  887. ret |= copy_from_user (image, (char *)A(i), f.size.fby * 4);
  888. if (ret)
  889. return -EFAULT;
  890. f.image = image; f.mask = mask;
  891. }
  892. if (f.set & FB_CUR_SETCMAP) {
  893. ret = copy_from_user (red, (char *)A(r), 2);
  894. ret |= copy_from_user (green, (char *)A(g), 2);
  895. ret |= copy_from_user (blue, (char *)A(b), 2);
  896. if (ret)
  897. return -EFAULT;
  898. f.cmap.red = red; f.cmap.green = green; f.cmap.blue = blue;
  899. }
  900. set_fs (KERNEL_DS);
  901. ret = sys_ioctl (fd, FBIOSCURSOR, (long)&f);
  902. set_fs (old_fs);
  903. return ret;
  904. }
  905. struct fb_fix_screeninfo32 {
  906. char id[16];
  907.         __kernel_caddr_t32 smem_start;
  908. __u32 smem_len;
  909. __u32 type;
  910. __u32 type_aux;
  911. __u32 visual;
  912. __u16 xpanstep;
  913. __u16 ypanstep;
  914. __u16 ywrapstep;
  915. __u32 line_length;
  916.         __kernel_caddr_t32 mmio_start;
  917. __u32 mmio_len;
  918. __u32 accel;
  919. __u16 reserved[3];
  920. };
  921. struct fb_cmap32 {
  922. __u32 start;
  923. __u32 len;
  924. __kernel_caddr_t32 red;
  925. __kernel_caddr_t32 green;
  926. __kernel_caddr_t32 blue;
  927. __kernel_caddr_t32 transp;
  928. };
  929. static int fb_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  930. {
  931. mm_segment_t old_fs = get_fs();
  932. u32 red = 0, green = 0, blue = 0, transp = 0;
  933. struct fb_fix_screeninfo fix;
  934. struct fb_cmap cmap;
  935. void *karg;
  936. int err = 0;
  937. memset(&cmap, 0, sizeof(cmap));
  938. switch (cmd) {
  939. case FBIOGET_FSCREENINFO:
  940. karg = &fix;
  941. break;
  942. case FBIOGETCMAP:
  943. case FBIOPUTCMAP:
  944. karg = &cmap;
  945. err = __get_user(cmap.start, &((struct fb_cmap32 *)arg)->start);
  946. err |= __get_user(cmap.len, &((struct fb_cmap32 *)arg)->len);
  947. err |= __get_user(red, &((struct fb_cmap32 *)arg)->red);
  948. err |= __get_user(green, &((struct fb_cmap32 *)arg)->green);
  949. err |= __get_user(blue, &((struct fb_cmap32 *)arg)->blue);
  950. err |= __get_user(transp, &((struct fb_cmap32 *)arg)->transp);
  951. if (err) {
  952. err = -EFAULT;
  953. goto out;
  954. }
  955. err = -ENOMEM;
  956. cmap.red = kmalloc(cmap.len * sizeof(__u16), GFP_KERNEL);
  957. if (!cmap.red)
  958. goto out;
  959. cmap.green = kmalloc(cmap.len * sizeof(__u16), GFP_KERNEL);
  960. if (!cmap.green)
  961. goto out;
  962. cmap.blue = kmalloc(cmap.len * sizeof(__u16), GFP_KERNEL);
  963. if (!cmap.blue)
  964. goto out;
  965. if (transp) {
  966. cmap.transp = kmalloc(cmap.len * sizeof(__u16), GFP_KERNEL);
  967. if (!cmap.transp)
  968. goto out;
  969. }
  970. if (cmd == FBIOGETCMAP)
  971. break;
  972. err = __copy_from_user(cmap.red, (char *)A(red), cmap.len * sizeof(__u16));
  973. err |= __copy_from_user(cmap.green, (char *)A(green), cmap.len * sizeof(__u16));
  974. err |= __copy_from_user(cmap.blue, (char *)A(blue), cmap.len * sizeof(__u16));
  975. if (cmap.transp) err |= __copy_from_user(cmap.transp, (char *)A(transp), cmap.len * sizeof(__u16));
  976. if (err) {
  977. err = -EFAULT;
  978. goto out;
  979. }
  980. break;
  981. default:
  982. do {
  983. static int count;
  984. if (++count <= 20)
  985. printk("%s: Unknown fb ioctl cmd fd(%d) "
  986.        "cmd(%08x) arg(%08lx)n",
  987.        __FUNCTION__, fd, cmd, arg);
  988. } while(0);
  989. return -ENOSYS;
  990. }
  991. set_fs(KERNEL_DS);
  992. err = sys_ioctl(fd, cmd, (unsigned long)karg);
  993. set_fs(old_fs);
  994. if (err)
  995. goto out;
  996. switch (cmd) {
  997. case FBIOGET_FSCREENINFO:
  998. err = __copy_to_user((char *)((struct fb_fix_screeninfo32 *)arg)->id, (char *)fix.id, sizeof(fix.id));
  999. err |= __put_user((__u32)(unsigned long)fix.smem_start, &((struct fb_fix_screeninfo32 *)arg)->smem_start);
  1000. err |= __put_user(fix.smem_len, &((struct fb_fix_screeninfo32 *)arg)->smem_len);
  1001. err |= __put_user(fix.type, &((struct fb_fix_screeninfo32 *)arg)->type);
  1002. err |= __put_user(fix.type_aux, &((struct fb_fix_screeninfo32 *)arg)->type_aux);
  1003. err |= __put_user(fix.visual, &((struct fb_fix_screeninfo32 *)arg)->visual);
  1004. err |= __put_user(fix.xpanstep, &((struct fb_fix_screeninfo32 *)arg)->xpanstep);
  1005. err |= __put_user(fix.ypanstep, &((struct fb_fix_screeninfo32 *)arg)->ypanstep);
  1006. err |= __put_user(fix.ywrapstep, &((struct fb_fix_screeninfo32 *)arg)->ywrapstep);
  1007. err |= __put_user(fix.line_length, &((struct fb_fix_screeninfo32 *)arg)->line_length);
  1008. err |= __put_user((__u32)(unsigned long)fix.mmio_start, &((struct fb_fix_screeninfo32 *)arg)->mmio_start);
  1009. err |= __put_user(fix.mmio_len, &((struct fb_fix_screeninfo32 *)arg)->mmio_len);
  1010. err |= __put_user(fix.accel, &((struct fb_fix_screeninfo32 *)arg)->accel);
  1011. err |= __copy_to_user((char *)((struct fb_fix_screeninfo32 *)arg)->reserved, (char *)fix.reserved, sizeof(fix.reserved));
  1012. break;
  1013. case FBIOGETCMAP:
  1014. err = __copy_to_user((char *)A(red), cmap.red, cmap.len * sizeof(__u16));
  1015. err |= __copy_to_user((char *)A(green), cmap.blue, cmap.len * sizeof(__u16));
  1016. err |= __copy_to_user((char *)A(blue), cmap.blue, cmap.len * sizeof(__u16));
  1017. if (cmap.transp)
  1018. err |= __copy_to_user((char *)A(transp), cmap.transp, cmap.len * sizeof(__u16));
  1019. break;
  1020. case FBIOPUTCMAP:
  1021. break;
  1022. }
  1023. if (err)
  1024. err = -EFAULT;
  1025. out: if (cmap.red) kfree(cmap.red);
  1026. if (cmap.green) kfree(cmap.green);
  1027. if (cmap.blue) kfree(cmap.blue);
  1028. if (cmap.transp) kfree(cmap.transp);
  1029. return err;
  1030. }
  1031. static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  1032. {
  1033. mm_segment_t old_fs = get_fs();
  1034. unsigned long kval;
  1035. unsigned int *uvp;
  1036. int error;
  1037. set_fs(KERNEL_DS);
  1038. error = sys_ioctl(fd, cmd, (long)&kval);
  1039. set_fs(old_fs);
  1040. if(error == 0) {
  1041. uvp = (unsigned int *)arg;
  1042. if(put_user(kval, uvp))
  1043. error = -EFAULT;
  1044. }
  1045. return error;
  1046. }
  1047. struct floppy_struct32 {
  1048. unsigned int size;
  1049. unsigned int sect;
  1050. unsigned int head;
  1051. unsigned int track;
  1052. unsigned int stretch;
  1053. unsigned char gap;
  1054. unsigned char rate;
  1055. unsigned char spec1;
  1056. unsigned char fmt_gap;
  1057. const __kernel_caddr_t32 name;
  1058. };
  1059. struct floppy_drive_params32 {
  1060. char cmos;
  1061. u32 max_dtr;
  1062. u32 hlt;
  1063. u32 hut;
  1064. u32 srt;
  1065. u32 spinup;
  1066. u32 spindown;
  1067. unsigned char spindown_offset;
  1068. unsigned char select_delay;
  1069. unsigned char rps;
  1070. unsigned char tracks;
  1071. u32 timeout;
  1072. unsigned char interleave_sect;
  1073. struct floppy_max_errors max_errors;
  1074. char flags;
  1075. char read_track;
  1076. short autodetect[8];
  1077. int checkfreq;
  1078. int native_format;
  1079. };
  1080. struct floppy_drive_struct32 {
  1081. signed char flags;
  1082. u32 spinup_date;
  1083. u32 select_date;
  1084. u32 first_read_date;
  1085. short probed_format;
  1086. short track;
  1087. short maxblock;
  1088. short maxtrack;
  1089. int generation;
  1090. int keep_data;
  1091. int fd_ref;
  1092. int fd_device;
  1093. int last_checked;
  1094. __kernel_caddr_t32 dmabuf;
  1095. int bufblocks;
  1096. };
  1097. struct floppy_fdc_state32 {
  1098. int spec1;
  1099. int spec2;
  1100. int dtr;
  1101. unsigned char version;
  1102. unsigned char dor;
  1103. u32 address;
  1104. unsigned int rawcmd:2;
  1105. unsigned int reset:1;
  1106. unsigned int need_configure:1;
  1107. unsigned int perp_mode:2;
  1108. unsigned int has_fifo:1;
  1109. unsigned int driver_version;
  1110. unsigned char track[4];
  1111. };
  1112. struct floppy_write_errors32 {
  1113. unsigned int write_errors;
  1114. u32 first_error_sector;
  1115. int first_error_generation;
  1116. u32 last_error_sector;
  1117. int last_error_generation;
  1118. unsigned int badness;
  1119. };
  1120. #define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32)
  1121. #define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32)
  1122. #define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32)
  1123. #define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32)
  1124. #define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32)
  1125. #define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32)
  1126. #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32)
  1127. #define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32)
  1128. #define FDWERRORGET32  _IOR(2, 0x17, struct floppy_write_errors32)
  1129. static struct {
  1130. unsigned int cmd32;
  1131. unsigned int cmd;
  1132. } fd_ioctl_trans_table[] = {
  1133. { FDSETPRM32, FDSETPRM },
  1134. { FDDEFPRM32, FDDEFPRM },
  1135. { FDGETPRM32, FDGETPRM },
  1136. { FDSETDRVPRM32, FDSETDRVPRM },
  1137. { FDGETDRVPRM32, FDGETDRVPRM },
  1138. { FDGETDRVSTAT32, FDGETDRVSTAT },
  1139. { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
  1140. { FDGETFDCSTAT32, FDGETFDCSTAT },
  1141. { FDWERRORGET32, FDWERRORGET }
  1142. };
  1143. #define NR_FD_IOCTL_TRANS (sizeof(fd_ioctl_trans_table)/sizeof(fd_ioctl_trans_table[0]))
  1144. static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  1145. {
  1146. mm_segment_t old_fs = get_fs();
  1147. void *karg = NULL;
  1148. unsigned int kcmd = 0;
  1149. int i, err;
  1150. for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
  1151. if (cmd == fd_ioctl_trans_table[i].cmd32) {
  1152. kcmd = fd_ioctl_trans_table[i].cmd;
  1153. break;
  1154. }
  1155. if (!kcmd)
  1156. return -EINVAL;
  1157. switch (cmd) {
  1158. case FDSETPRM32:
  1159. case FDDEFPRM32:
  1160. case FDGETPRM32:
  1161. {
  1162. struct floppy_struct *f;
  1163. f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
  1164. if (!karg)
  1165. return -ENOMEM;
  1166. if (cmd == FDGETPRM32)
  1167. break;
  1168. err = __get_user(f->size, &((struct floppy_struct32 *)arg)->size);
  1169. err |= __get_user(f->sect, &((struct floppy_struct32 *)arg)->sect);
  1170. err |= __get_user(f->head, &((struct floppy_struct32 *)arg)->head);
  1171. err |= __get_user(f->track, &((struct floppy_struct32 *)arg)->track);
  1172. err |= __get_user(f->stretch, &((struct floppy_struct32 *)arg)->stretch);
  1173. err |= __get_user(f->gap, &((struct floppy_struct32 *)arg)->gap);
  1174. err |= __get_user(f->rate, &((struct floppy_struct32 *)arg)->rate);
  1175. err |= __get_user(f->spec1, &((struct floppy_struct32 *)arg)->spec1);
  1176. err |= __get_user(f->fmt_gap, &((struct floppy_struct32 *)arg)->fmt_gap);
  1177. err |= __get_user((u64)f->name, &((struct floppy_struct32 *)arg)->name);
  1178. if (err) {
  1179. err = -EFAULT;
  1180. goto out;
  1181. }
  1182. break;
  1183. }
  1184. case FDSETDRVPRM32:
  1185. case FDGETDRVPRM32:
  1186. {
  1187. struct floppy_drive_params *f;
  1188. f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
  1189. if (!karg)
  1190. return -ENOMEM;
  1191. if (cmd == FDGETDRVPRM32)
  1192. break;
  1193. err = __get_user(f->cmos, &((struct floppy_drive_params32 *)arg)->cmos);
  1194. err |= __get_user(f->max_dtr, &((struct floppy_drive_params32 *)arg)->max_dtr);
  1195. err |= __get_user(f->hlt, &((struct floppy_drive_params32 *)arg)->hlt);
  1196. err |= __get_user(f->hut, &((struct floppy_drive_params32 *)arg)->hut);
  1197. err |= __get_user(f->srt, &((struct floppy_drive_params32 *)arg)->srt);
  1198. err |= __get_user(f->spinup, &((struct floppy_drive_params32 *)arg)->spinup);
  1199. err |= __get_user(f->spindown, &((struct floppy_drive_params32 *)arg)->spindown);
  1200. err |= __get_user(f->spindown_offset, &((struct floppy_drive_params32 *)arg)->spindown_offset);
  1201. err |= __get_user(f->select_delay, &((struct floppy_drive_params32 *)arg)->select_delay);
  1202. err |= __get_user(f->rps, &((struct floppy_drive_params32 *)arg)->rps);
  1203. err |= __get_user(f->tracks, &((struct floppy_drive_params32 *)arg)->tracks);
  1204. err |= __get_user(f->timeout, &((struct floppy_drive_params32 *)arg)->timeout);
  1205. err |= __get_user(f->interleave_sect, &((struct floppy_drive_params32 *)arg)->interleave_sect);
  1206. err |= __copy_from_user(&f->max_errors, &((struct floppy_drive_params32 *)arg)->max_errors, sizeof(f->max_errors));
  1207. err |= __get_user(f->flags, &((struct floppy_drive_params32 *)arg)->flags);
  1208. err |= __get_user(f->read_track, &((struct floppy_drive_params32 *)arg)->read_track);
  1209. err |= __copy_from_user(f->autodetect, ((struct floppy_drive_params32 *)arg)->autodetect, sizeof(f->autodetect));
  1210. err |= __get_user(f->checkfreq, &((struct floppy_drive_params32 *)arg)->checkfreq);
  1211. err |= __get_user(f->native_format, &((struct floppy_drive_params32 *)arg)->native_format);
  1212. if (err) {
  1213. err = -EFAULT;
  1214. goto out;
  1215. }
  1216. break;
  1217. }
  1218. case FDGETDRVSTAT32:
  1219. case FDPOLLDRVSTAT32:
  1220. karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
  1221. if (!karg)
  1222. return -ENOMEM;
  1223. break;
  1224. case FDGETFDCSTAT32:
  1225. karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
  1226. if (!karg)
  1227. return -ENOMEM;
  1228. break;
  1229. case FDWERRORGET32:
  1230. karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
  1231. if (!karg)
  1232. return -ENOMEM;
  1233. break;
  1234. default:
  1235. return -EINVAL;
  1236. }
  1237. set_fs (KERNEL_DS);
  1238. err = sys_ioctl (fd, kcmd, (unsigned long)karg);
  1239. set_fs (old_fs);
  1240. if (err)
  1241. goto out;
  1242. switch (cmd) {
  1243. case FDGETPRM32:
  1244. {
  1245. struct floppy_struct *f = karg;
  1246. err = __put_user(f->size, &((struct floppy_struct32 *)arg)->size);
  1247. err |= __put_user(f->sect, &((struct floppy_struct32 *)arg)->sect);
  1248. err |= __put_user(f->head, &((struct floppy_struct32 *)arg)->head);
  1249. err |= __put_user(f->track, &((struct floppy_struct32 *)arg)->track);
  1250. err |= __put_user(f->stretch, &((struct floppy_struct32 *)arg)->stretch);
  1251. err |= __put_user(f->gap, &((struct floppy_struct32 *)arg)->gap);
  1252. err |= __put_user(f->rate, &((struct floppy_struct32 *)arg)->rate);
  1253. err |= __put_user(f->spec1, &((struct floppy_struct32 *)arg)->spec1);
  1254. err |= __put_user(f->fmt_gap, &((struct floppy_struct32 *)arg)->fmt_gap);
  1255. err |= __put_user((u64)f->name, &((struct floppy_struct32 *)arg)->name);
  1256. break;
  1257. }
  1258. case FDGETDRVPRM32:
  1259. {
  1260. struct floppy_drive_params *f = karg;
  1261. err = __put_user(f->cmos, &((struct floppy_drive_params32 *)arg)->cmos);
  1262. err |= __put_user(f->max_dtr, &((struct floppy_drive_params32 *)arg)->max_dtr);
  1263. err |= __put_user(f->hlt, &((struct floppy_drive_params32 *)arg)->hlt);
  1264. err |= __put_user(f->hut, &((struct floppy_drive_params32 *)arg)->hut);
  1265. err |= __put_user(f->srt, &((struct floppy_drive_params32 *)arg)->srt);
  1266. err |= __put_user(f->spinup, &((struct floppy_drive_params32 *)arg)->spinup);
  1267. err |= __put_user(f->spindown, &((struct floppy_drive_params32 *)arg)->spindown);
  1268. err |= __put_user(f->spindown_offset, &((struct floppy_drive_params32 *)arg)->spindown_offset);
  1269. err |= __put_user(f->select_delay, &((struct floppy_drive_params32 *)arg)->select_delay);
  1270. err |= __put_user(f->rps, &((struct floppy_drive_params32 *)arg)->rps);
  1271. err |= __put_user(f->tracks, &((struct floppy_drive_params32 *)arg)->tracks);
  1272. err |= __put_user(f->timeout, &((struct floppy_drive_params32 *)arg)->timeout);
  1273. err |= __put_user(f->interleave_sect, &((struct floppy_drive_params32 *)arg)->interleave_sect);
  1274. err |= __copy_to_user(&((struct floppy_drive_params32 *)arg)->max_errors, &f->max_errors, sizeof(f->max_errors));
  1275. err |= __put_user(f->flags, &((struct floppy_drive_params32 *)arg)->flags);
  1276. err |= __put_user(f->read_track, &((struct floppy_drive_params32 *)arg)->read_track);
  1277. err |= __copy_to_user(((struct floppy_drive_params32 *)arg)->autodetect, f->autodetect, sizeof(f->autodetect));
  1278. err |= __put_user(f->checkfreq, &((struct floppy_drive_params32 *)arg)->checkfreq);
  1279. err |= __put_user(f->native_format, &((struct floppy_drive_params32 *)arg)->native_format);
  1280. break;
  1281. }
  1282. case FDGETDRVSTAT32:
  1283. case FDPOLLDRVSTAT32:
  1284. {
  1285. struct floppy_drive_struct *f = karg;
  1286. err = __put_user(f->flags, &((struct floppy_drive_struct32 *)arg)->flags);
  1287. err |= __put_user(f->spinup_date, &((struct floppy_drive_struct32 *)arg)->spinup_date);
  1288. err |= __put_user(f->select_date, &((struct floppy_drive_struct32 *)arg)->select_date);
  1289. err |= __put_user(f->first_read_date, &((struct floppy_drive_struct32 *)arg)->first_read_date);
  1290. err |= __put_user(f->probed_format, &((struct floppy_drive_struct32 *)arg)->probed_format);
  1291. err |= __put_user(f->track, &((struct floppy_drive_struct32 *)arg)->track);
  1292. err |= __put_user(f->maxblock, &((struct floppy_drive_struct32 *)arg)->maxblock);
  1293. err |= __put_user(f->maxtrack, &((struct floppy_drive_struct32 *)arg)->maxtrack);
  1294. err |= __put_user(f->generation, &((struct floppy_drive_struct32 *)arg)->generation);
  1295. err |= __put_user(f->keep_data, &((struct floppy_drive_struct32 *)arg)->keep_data);
  1296. err |= __put_user(f->fd_ref, &((struct floppy_drive_struct32 *)arg)->fd_ref);
  1297. err |= __put_user(f->fd_device, &((struct floppy_drive_struct32 *)arg)->fd_device);
  1298. err |= __put_user(f->last_checked, &((struct floppy_drive_struct32 *)arg)->last_checked);
  1299. err |= __put_user((u64)f->dmabuf, &((struct floppy_drive_struct32 *)arg)->dmabuf);
  1300. err |= __put_user((u64)f->bufblocks, &((struct floppy_drive_struct32 *)arg)->bufblocks);
  1301. break;
  1302. }
  1303. case FDGETFDCSTAT32:
  1304. {
  1305. struct floppy_fdc_state *f = karg;
  1306. err = __put_user(f->spec1, &((struct floppy_fdc_state32 *)arg)->spec1);
  1307. err |= __put_user(f->spec2, &((struct floppy_fdc_state32 *)arg)->spec2);
  1308. err |= __put_user(f->dtr, &((struct floppy_fdc_state32 *)arg)->dtr);
  1309. err |= __put_user(f->version, &((struct floppy_fdc_state32 *)arg)->version);
  1310. err |= __put_user(f->dor, &((struct floppy_fdc_state32 *)arg)->dor);
  1311. err |= __put_user(f->address, &((struct floppy_fdc_state32 *)arg)->address);
  1312. err |= __copy_to_user((char *)&((struct floppy_fdc_state32 *)arg)->address
  1313.         + sizeof(((struct floppy_fdc_state32 *)arg)->address),
  1314.    (char *)&f->address + sizeof(f->address), sizeof(int));
  1315. err |= __put_user(f->driver_version, &((struct floppy_fdc_state32 *)arg)->driver_version);
  1316. err |= __copy_to_user(((struct floppy_fdc_state32 *)arg)->track, f->track, sizeof(f->track));
  1317. break;
  1318. }
  1319. case FDWERRORGET32:
  1320. {
  1321. struct floppy_write_errors *f = karg;
  1322. err = __put_user(f->write_errors, &((struct floppy_write_errors32 *)arg)->write_errors);
  1323. err |= __put_user(f->first_error_sector, &((struct floppy_write_errors32 *)arg)->first_error_sector);
  1324. err |= __put_user(f->first_error_generation, &((struct floppy_write_errors32 *)arg)->first_error_generation);
  1325. err |= __put_user(f->last_error_sector, &((struct floppy_write_errors32 *)arg)->last_error_sector);
  1326. err |= __put_user(f->last_error_generation, &((struct floppy_write_errors32 *)arg)->last_error_generation);
  1327. err |= __put_user(f->badness, &((struct floppy_write_errors32 *)arg)->badness);
  1328. break;
  1329. }
  1330. default:
  1331. break;
  1332. }
  1333. if (err)
  1334. err = -EFAULT;
  1335. out: if (karg) kfree(karg);
  1336. return err;
  1337. }
  1338. typedef struct sg_io_hdr32 {
  1339. s32 interface_id; /* [i] 'S' for SCSI generic (required) */
  1340. s32 dxfer_direction; /* [i] data transfer direction  */
  1341. u8  cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
  1342. u8  mx_sb_len; /* [i] max length to write to sbp */
  1343. u16 iovec_count; /* [i] 0 implies no scatter gather */
  1344. u32 dxfer_len; /* [i] byte count of data transfer */
  1345. u32 dxferp; /* [i], [*io] points to data transfer memory
  1346.       or scatter gather list */
  1347. u32 cmdp; /* [i], [*i] points to command to perform */
  1348. u32 sbp; /* [i], [*o] points to sense_buffer memory */
  1349. u32 timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
  1350. u32 flags; /* [i] 0 -> default, see SG_FLAG... */
  1351. s32 pack_id; /* [i->o] unused internally (normally) */
  1352. u32 usr_ptr; /* [i->o] unused internally */
  1353. u8  status; /* [o] scsi status */
  1354. u8  masked_status; /* [o] shifted, masked scsi status */
  1355. u8  msg_status; /* [o] messaging level data (optional) */
  1356. u8  sb_len_wr; /* [o] byte count actually written to sbp */
  1357. u16 host_status; /* [o] errors from host adapter */
  1358. u16 driver_status; /* [o] errors from software driver */
  1359. s32 resid; /* [o] dxfer_len - actual_transferred */
  1360. u32 duration; /* [o] time taken by cmd (unit: millisec) */
  1361. u32 info; /* [o] auxiliary information */
  1362. } sg_io_hdr32_t;  /* 64 bytes long (on sparc32) */
  1363. typedef struct sg_iovec32 {
  1364. u32 iov_base;
  1365. u32 iov_len;
  1366. } sg_iovec32_t;
  1367. static int alloc_sg_iovec(sg_io_hdr_t *sgp, u32 uptr32)
  1368. {
  1369. sg_iovec32_t *uiov = (sg_iovec32_t *) A(uptr32);
  1370. sg_iovec_t *kiov;
  1371. int i;
  1372. sgp->dxferp = kmalloc(sgp->iovec_count *
  1373.       sizeof(sg_iovec_t), GFP_KERNEL);
  1374. if (!sgp->dxferp)
  1375. return -ENOMEM;
  1376. memset(sgp->dxferp, 0,
  1377.        sgp->iovec_count * sizeof(sg_iovec_t));
  1378. kiov = (sg_iovec_t *) sgp->dxferp;
  1379. for (i = 0; i < sgp->iovec_count; i++) {
  1380. u32 iov_base32;
  1381. if (__get_user(iov_base32, &uiov->iov_base) ||
  1382.     __get_user(kiov->iov_len, &uiov->iov_len))
  1383. return -EFAULT;
  1384. kiov->iov_base = kmalloc(kiov->iov_len, GFP_KERNEL);
  1385. if (!kiov->iov_base)
  1386. return -ENOMEM;
  1387. if (copy_from_user(kiov->iov_base,
  1388.    (void *) A(iov_base32),
  1389.    kiov->iov_len))
  1390. return -EFAULT;
  1391. uiov++;
  1392. kiov++;
  1393. }
  1394. return 0;
  1395. }
  1396. static int copy_back_sg_iovec(sg_io_hdr_t *sgp, u32 uptr32)
  1397. {
  1398. sg_iovec32_t *uiov = (sg_iovec32_t *) A(uptr32);
  1399. sg_iovec_t *kiov = (sg_iovec_t *) sgp->dxferp;
  1400. int i;
  1401. for (i = 0; i < sgp->iovec_count; i++) {
  1402. u32 iov_base32;
  1403. if (__get_user(iov_base32, &uiov->iov_base))
  1404. return -EFAULT;
  1405. if (copy_to_user((void *) A(iov_base32),
  1406.  kiov->iov_base,
  1407.  kiov->iov_len))
  1408. return -EFAULT;
  1409. uiov++;
  1410. kiov++;
  1411. }
  1412. return 0;
  1413. }
  1414. static void free_sg_iovec(sg_io_hdr_t *sgp)
  1415. {
  1416. sg_iovec_t *kiov = (sg_iovec_t *) sgp->dxferp;
  1417. int i;
  1418. for (i = 0; i < sgp->iovec_count; i++) {
  1419. if (kiov->iov_base) {
  1420. kfree(kiov->iov_base);
  1421. kiov->iov_base = NULL;
  1422. }
  1423. kiov++;
  1424. }
  1425. kfree(sgp->dxferp);
  1426. sgp->dxferp = NULL;
  1427. }
  1428. static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  1429. {
  1430. sg_io_hdr32_t *sg_io32;
  1431. sg_io_hdr_t sg_io64;
  1432. u32 dxferp32, cmdp32, sbp32;
  1433. mm_segment_t old_fs;
  1434. int err = 0;
  1435. sg_io32 = (sg_io_hdr32_t *)arg;
  1436. err = __get_user(sg_io64.interface_id, &sg_io32->interface_id);
  1437. err |= __get_user(sg_io64.dxfer_direction, &sg_io32->dxfer_direction);
  1438. err |= __get_user(sg_io64.cmd_len, &sg_io32->cmd_len);
  1439. err |= __get_user(sg_io64.mx_sb_len, &sg_io32->mx_sb_len);
  1440. err |= __get_user(sg_io64.iovec_count, &sg_io32->iovec_count);
  1441. err |= __get_user(sg_io64.dxfer_len, &sg_io32->dxfer_len);
  1442. err |= __get_user(sg_io64.timeout, &sg_io32->timeout);
  1443. err |= __get_user(sg_io64.flags, &sg_io32->flags);
  1444. err |= __get_user(sg_io64.pack_id, &sg_io32->pack_id);
  1445. sg_io64.dxferp = NULL;
  1446. sg_io64.cmdp = NULL;
  1447. sg_io64.sbp = NULL;
  1448. err |= __get_user(cmdp32, &sg_io32->cmdp);
  1449. sg_io64.cmdp = kmalloc(sg_io64.cmd_len, GFP_KERNEL);
  1450. if (!sg_io64.cmdp) {
  1451. err = -ENOMEM;
  1452. goto out;
  1453. }
  1454. if (copy_from_user(sg_io64.cmdp,
  1455.    (void *) A(cmdp32),
  1456.    sg_io64.cmd_len)) {
  1457. err = -EFAULT;
  1458. goto out;
  1459. }
  1460. err |= __get_user(sbp32, &sg_io32->sbp);
  1461. sg_io64.sbp = kmalloc(sg_io64.mx_sb_len, GFP_KERNEL);
  1462. if (!sg_io64.sbp) {
  1463. err = -ENOMEM;
  1464. goto out;
  1465. }
  1466. if (copy_from_user(sg_io64.sbp,
  1467.    (void *) A(sbp32),
  1468.    sg_io64.mx_sb_len)) {
  1469. err = -EFAULT;
  1470. goto out;
  1471. }
  1472. err |= __get_user(dxferp32, &sg_io32->dxferp);
  1473. if (sg_io64.iovec_count) {
  1474. int ret;
  1475. if ((ret = alloc_sg_iovec(&sg_io64, dxferp32))) {
  1476. err = ret;
  1477. goto out;
  1478. }
  1479. } else {
  1480. sg_io64.dxferp = kmalloc(sg_io64.dxfer_len, GFP_KERNEL);
  1481. if (!sg_io64.dxferp) {
  1482. err = -ENOMEM;
  1483. goto out;
  1484. }
  1485. if (copy_from_user(sg_io64.dxferp,
  1486.    (void *) A(dxferp32),
  1487.    sg_io64.dxfer_len)) {
  1488. err = -EFAULT;
  1489. goto out;
  1490. }
  1491. }
  1492. /* Unused internally, do not even bother to copy it over. */
  1493. sg_io64.usr_ptr = NULL;
  1494. if (err)
  1495. return -EFAULT;
  1496. old_fs = get_fs();
  1497. set_fs (KERNEL_DS);
  1498. err = sys_ioctl (fd, cmd, (unsigned long) &sg_io64);
  1499. set_fs (old_fs);
  1500. if (err < 0)
  1501. goto out;
  1502. err = __put_user(sg_io64.pack_id, &sg_io32->pack_id);
  1503. err |= __put_user(sg_io64.status, &sg_io32->status);
  1504. err |= __put_user(sg_io64.masked_status, &sg_io32->masked_status);
  1505. err |= __put_user(sg_io64.msg_status, &sg_io32->msg_status);
  1506. err |= __put_user(sg_io64.sb_len_wr, &sg_io32->sb_len_wr);
  1507. err |= __put_user(sg_io64.host_status, &sg_io32->host_status);
  1508. err |= __put_user(sg_io64.driver_status, &sg_io32->driver_status);
  1509. err |= __put_user(sg_io64.resid, &sg_io32->resid);
  1510. err |= __put_user(sg_io64.duration, &sg_io32->duration);
  1511. err |= __put_user(sg_io64.info, &sg_io32->info);
  1512. err |= copy_to_user((void *)A(sbp32), sg_io64.sbp, sg_io64.mx_sb_len);
  1513. if (sg_io64.dxferp) {
  1514. if (sg_io64.iovec_count)
  1515. err |= copy_back_sg_iovec(&sg_io64, dxferp32);
  1516. else
  1517. err |= copy_to_user((void *)A(dxferp32),
  1518.     sg_io64.dxferp,
  1519.     sg_io64.dxfer_len);
  1520. }
  1521. if (err)
  1522. err = -EFAULT;
  1523. out:
  1524. if (sg_io64.cmdp)
  1525. kfree(sg_io64.cmdp);
  1526. if (sg_io64.sbp)
  1527. kfree(sg_io64.sbp);
  1528. if (sg_io64.dxferp) {
  1529. if (sg_io64.iovec_count) {
  1530. free_sg_iovec(&sg_io64);
  1531. } else {
  1532. kfree(sg_io64.dxferp);
  1533. }
  1534. }
  1535. return err;
  1536. }
  1537. struct sock_fprog32 {
  1538. __u16 len;
  1539. __u32 filter;
  1540. };
  1541. #define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
  1542. #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
  1543. static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  1544. {
  1545. struct sock_fprog32 *u_fprog32 = (struct sock_fprog32 *) arg;
  1546. struct sock_fprog *u_fprog64 = alloc_user_space(sizeof(struct sock_fprog));
  1547. void *fptr64;
  1548. u32 fptr32;
  1549. u16 flen;
  1550. if (get_user(flen, &u_fprog32->len) ||
  1551.     get_user(fptr32, &u_fprog32->filter))
  1552. return -EFAULT;
  1553. fptr64 = (void *) A(fptr32);
  1554. if (put_user(flen, &u_fprog64->len) ||
  1555.     put_user(fptr64, &u_fprog64->filter))
  1556. return -EFAULT;
  1557. if (cmd == PPPIOCSPASS32)
  1558. cmd = PPPIOCSPASS;
  1559. else
  1560. cmd = PPPIOCSACTIVE;
  1561. return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
  1562. }
  1563. struct ppp_option_data32 {
  1564. __kernel_caddr_t32 ptr;
  1565. __u32 length;
  1566. int transmit;
  1567. };
  1568. #define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
  1569. struct ppp_idle32 {
  1570. __kernel_time_t32 xmit_idle;
  1571. __kernel_time_t32 recv_idle;
  1572. };
  1573. #define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
  1574. static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  1575. {
  1576. mm_segment_t old_fs = get_fs();
  1577. struct ppp_option_data32 data32;
  1578. struct ppp_option_data data;
  1579. struct ppp_idle32 idle32;
  1580. struct ppp_idle idle;
  1581. unsigned int kcmd;
  1582. void *karg;
  1583. int err = 0;
  1584. switch (cmd) {
  1585. case PPPIOCGIDLE32:
  1586. kcmd = PPPIOCGIDLE;
  1587. karg = &idle;
  1588. break;
  1589. case PPPIOCSCOMPRESS32:
  1590. if (copy_from_user(&data32, (struct ppp_option_data32 *)arg, sizeof(struct ppp_option_data32)))
  1591. return -EFAULT;
  1592. data.ptr = kmalloc (data32.length, GFP_KERNEL);
  1593. if (!data.ptr)
  1594. return -ENOMEM;
  1595. if (copy_from_user(data.ptr, (__u8 *)A(data32.ptr), data32.length)) {
  1596. kfree(data.ptr);
  1597. return -EFAULT;
  1598. }
  1599. data.length = data32.length;
  1600. data.transmit = data32.transmit;
  1601. kcmd = PPPIOCSCOMPRESS;
  1602. karg = &data;
  1603. break;
  1604. default:
  1605. do {
  1606. static int count;
  1607. if (++count <= 20)
  1608. printk("ppp_ioctl: Unknown cmd fd(%d) "
  1609.        "cmd(%08x) arg(%08x)n",
  1610.        (int)fd, (unsigned int)cmd, (unsigned int)arg);
  1611. } while(0);
  1612. return -EINVAL;
  1613. }
  1614. set_fs (KERNEL_DS);
  1615. err = sys_ioctl (fd, kcmd, (unsigned long)karg);
  1616. set_fs (old_fs);
  1617. switch (cmd) {
  1618. case PPPIOCGIDLE32:
  1619. if (err)
  1620. return err;
  1621. idle32.xmit_idle = idle.xmit_idle;
  1622. idle32.recv_idle = idle.recv_idle;
  1623. if (copy_to_user((struct ppp_idle32 *)arg, &idle32, sizeof(struct ppp_idle32)))
  1624. return -EFAULT;
  1625. break;
  1626. case PPPIOCSCOMPRESS32:
  1627. kfree(data.ptr);
  1628. break;
  1629. default:
  1630. break;
  1631. }
  1632. return err;
  1633. }
  1634. struct mtget32 {
  1635. __u32 mt_type;
  1636. __u32 mt_resid;
  1637. __u32 mt_dsreg;
  1638. __u32 mt_gstat;
  1639. __u32 mt_erreg;
  1640. __kernel_daddr_t32 mt_fileno;
  1641. __kernel_daddr_t32 mt_blkno;
  1642. };
  1643. #define MTIOCGET32 _IOR('m', 2, struct mtget32)
  1644. struct mtpos32 {
  1645. __u32 mt_blkno;
  1646. };
  1647. #define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
  1648. struct mtconfiginfo32 {
  1649. __u32 mt_type;
  1650. __u32 ifc_type;
  1651. __u16 irqnr;
  1652. __u16 dmanr;
  1653. __u16 port;
  1654. __u32 debug;
  1655. __u32 have_dens:1;
  1656. __u32 have_bsf:1;
  1657. __u32 have_fsr:1;
  1658. __u32 have_bsr:1;
  1659. __u32 have_eod:1;
  1660. __u32 have_seek:1;
  1661. __u32 have_tell:1;
  1662. __u32 have_ras1:1;
  1663. __u32 have_ras2:1;
  1664. __u32 have_ras3:1;
  1665. __u32 have_qfa:1;
  1666. __u32 pad1:5;
  1667. char reserved[10];
  1668. };
  1669. #define MTIOCGETCONFIG32 _IOR('m', 4, struct mtconfiginfo32)
  1670. #define MTIOCSETCONFIG32 _IOW('m', 5, struct mtconfiginfo32)
  1671. static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  1672. {
  1673. mm_segment_t old_fs = get_fs();
  1674. struct mtconfiginfo info;
  1675. struct mtget get;
  1676. struct mtpos pos;
  1677. unsigned long kcmd;
  1678. void *karg;
  1679. int err = 0;
  1680. switch(cmd) {
  1681. case MTIOCPOS32:
  1682. kcmd = MTIOCPOS;
  1683. karg = &pos;
  1684. break;
  1685. case MTIOCGET32:
  1686. kcmd = MTIOCGET;
  1687. karg = &get;
  1688. break;
  1689. case MTIOCGETCONFIG32:
  1690. kcmd = MTIOCGETCONFIG;
  1691. karg = &info;
  1692. break;
  1693. case MTIOCSETCONFIG32:
  1694. kcmd = MTIOCSETCONFIG;
  1695. karg = &info;
  1696. err = __get_user(info.mt_type, &((struct mtconfiginfo32 *)arg)->mt_type);
  1697. err |= __get_user(info.ifc_type, &((struct mtconfiginfo32 *)arg)->ifc_type);
  1698. err |= __get_user(info.irqnr, &((struct mtconfiginfo32 *)arg)->irqnr);
  1699. err |= __get_user(info.dmanr, &((struct mtconfiginfo32 *)arg)->dmanr);
  1700. err |= __get_user(info.port, &((struct mtconfiginfo32 *)arg)->port);
  1701. err |= __get_user(info.debug, &((struct mtconfiginfo32 *)arg)->debug);
  1702. err |= __copy_from_user((char *)&info.debug + sizeof(info.debug),
  1703.      (char *)&((struct mtconfiginfo32 *)arg)->debug
  1704.      + sizeof(((struct mtconfiginfo32 *)arg)->debug), sizeof(__u32));
  1705. if (err)
  1706. return -EFAULT;
  1707. break;
  1708. default:
  1709. do {
  1710. static int count;
  1711. if (++count <= 20)
  1712. printk("mt_ioctl: Unknown cmd fd(%d) "
  1713.        "cmd(%08x) arg(%08x)n",
  1714.        (int)fd, (unsigned int)cmd, (unsigned int)arg);
  1715. } while(0);
  1716. return -EINVAL;
  1717. }
  1718. set_fs (KERNEL_DS);
  1719. err = sys_ioctl (fd, kcmd, (unsigned long)karg);
  1720. set_fs (old_fs);
  1721. if (err)
  1722. return err;
  1723. switch (cmd) {
  1724. case MTIOCPOS32:
  1725. err = __put_user(pos.mt_blkno, &((struct mtpos32 *)arg)->mt_blkno);
  1726. break;
  1727. case MTIOCGET32:
  1728. err = __put_user(get.mt_type, &((struct mtget32 *)arg)->mt_type);
  1729. err |= __put_user(get.mt_resid, &((struct mtget32 *)arg)->mt_resid);
  1730. err |= __put_user(get.mt_dsreg, &((struct mtget32 *)arg)->mt_dsreg);
  1731. err |= __put_user(get.mt_gstat, &((struct mtget32 *)arg)->mt_gstat);
  1732. err |= __put_user(get.mt_erreg, &((struct mtget32 *)arg)->mt_erreg);
  1733. err |= __put_user(get.mt_fileno, &((struct mtget32 *)arg)->mt_fileno);
  1734. err |= __put_user(get.mt_blkno, &((struct mtget32 *)arg)->mt_blkno);
  1735. break;
  1736. case MTIOCGETCONFIG32:
  1737. err = __put_user(info.mt_type, &((struct mtconfiginfo32 *)arg)->mt_type);
  1738. err |= __put_user(info.ifc_type, &((struct mtconfiginfo32 *)arg)->ifc_type);
  1739. err |= __put_user(info.irqnr, &((struct mtconfiginfo32 *)arg)->irqnr);
  1740. err |= __put_user(info.dmanr, &((struct mtconfiginfo32 *)arg)->dmanr);
  1741. err |= __put_user(info.port, &((struct mtconfiginfo32 *)arg)->port);
  1742. err |= __put_user(info.debug, &((struct mtconfiginfo32 *)arg)->debug);
  1743. err |= __copy_to_user((char *)&((struct mtconfiginfo32 *)arg)->debug
  1744.         + sizeof(((struct mtconfiginfo32 *)arg)->debug),
  1745.    (char *)&info.debug + sizeof(info.debug), sizeof(__u32));
  1746. break;
  1747. case MTIOCSETCONFIG32:
  1748. break;
  1749. }
  1750. return err ? -EFAULT: 0;
  1751. }
  1752. struct cdrom_read32 {
  1753. int cdread_lba;
  1754. __kernel_caddr_t32 cdread_bufaddr;
  1755. int cdread_buflen;
  1756. };
  1757. struct cdrom_read_audio32 {
  1758. union cdrom_addr addr;
  1759. u_char addr_format;
  1760. int nframes;
  1761. __kernel_caddr_t32 buf;
  1762. };
  1763. struct cdrom_generic_command32 {
  1764. unsigned char cmd[CDROM_PACKET_SIZE];
  1765. __kernel_caddr_t32 buffer;
  1766. unsigned int buflen;
  1767. int stat;
  1768. __kernel_caddr_t32 sense;
  1769. __kernel_caddr_t32 reserved[3];
  1770. };
  1771. static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  1772. {
  1773. mm_segment_t old_fs = get_fs();
  1774. struct cdrom_read cdread;
  1775. struct cdrom_read_audio cdreadaudio;
  1776. struct cdrom_generic_command cgc;
  1777. __kernel_caddr_t32 addr;
  1778. char *data = 0;
  1779. void *karg;
  1780. int err = 0;
  1781. switch(cmd) {
  1782. case CDROMREADMODE2:
  1783. case CDROMREADMODE1:
  1784. case CDROMREADRAW:
  1785. case CDROMREADCOOKED:
  1786. karg = &cdread;
  1787. err = __get_user(cdread.cdread_lba, &((struct cdrom_read32 *)arg)->cdread_lba);
  1788. err |= __get_user(addr, &((struct cdrom_read32 *)arg)->cdread_bufaddr);
  1789. err |= __get_user(cdread.cdread_buflen, &((struct cdrom_read32 *)arg)->cdread_buflen);
  1790. if (err)
  1791. return -EFAULT;
  1792. data = kmalloc(cdread.cdread_buflen, GFP_KERNEL);
  1793. if (!data)
  1794. return -ENOMEM;
  1795. cdread.cdread_bufaddr = data;
  1796. break;
  1797. case CDROMREADAUDIO:
  1798. karg = &cdreadaudio;
  1799. err = copy_from_user(&cdreadaudio.addr, &((struct cdrom_read_audio32 *)arg)->addr, sizeof(cdreadaudio.addr));
  1800. err |= __get_user(cdreadaudio.addr_format, &((struct cdrom_read_audio32 *)arg)->addr_format);
  1801. err |= __get_user(cdreadaudio.nframes, &((struct cdrom_read_audio32 *)arg)->nframes); 
  1802. err |= __get_user(addr, &((struct cdrom_read_audio32 *)arg)->buf);
  1803. if (err)
  1804. return -EFAULT;
  1805. data = kmalloc(cdreadaudio.nframes * 2352, GFP_KERNEL);
  1806. if (!data)
  1807. return -ENOMEM;
  1808. cdreadaudio.buf = data;
  1809. break;
  1810. case CDROM_SEND_PACKET:
  1811. karg = &cgc;
  1812. err = copy_from_user(cgc.cmd, &((struct cdrom_generic_command32 *)arg)->cmd, sizeof(cgc.cmd));
  1813. err |= __get_user(addr, &((struct cdrom_generic_command32 *)arg)->buffer);
  1814. err |= __get_user(cgc.buflen, &((struct cdrom_generic_command32 *)arg)->buflen);
  1815. if (err)
  1816. return -EFAULT;
  1817. if ((data = kmalloc(cgc.buflen, GFP_KERNEL)) == NULL)
  1818. return -ENOMEM;
  1819. cgc.buffer = data;
  1820. break;
  1821. default:
  1822. do {
  1823. static int count;
  1824. if (++count <= 20)
  1825. printk("cdrom_ioctl: Unknown cmd fd(%d) "
  1826.        "cmd(%08x) arg(%08x)n",
  1827.        (int)fd, (unsigned int)cmd, (unsigned int)arg);
  1828. } while(0);
  1829. return -EINVAL;
  1830. }
  1831. set_fs (KERNEL_DS);
  1832. err = sys_ioctl (fd, cmd, (unsigned long)karg);
  1833. set_fs (old_fs);
  1834. if (err)
  1835. goto out;
  1836. switch (cmd) {
  1837. case CDROMREADMODE2:
  1838. case CDROMREADMODE1:
  1839. case CDROMREADRAW:
  1840. case CDROMREADCOOKED:
  1841. err = copy_to_user((char *)A(addr), data, cdread.cdread_buflen);
  1842. break;
  1843. case CDROMREADAUDIO:
  1844. err = copy_to_user((char *)A(addr), data, cdreadaudio.nframes * 2352);
  1845. break;
  1846. case CDROM_SEND_PACKET:
  1847. err = copy_to_user((char *)A(addr), data, cgc.buflen);
  1848. break;
  1849. default:
  1850. break;
  1851. }
  1852. out: if (data)
  1853. kfree(data);
  1854. return err ? -EFAULT : 0;
  1855. }
  1856. struct loop_info32 {
  1857. int lo_number;      /* ioctl r/o */
  1858. __kernel_dev_t32 lo_device;      /* ioctl r/o */
  1859. unsigned int lo_inode;       /* ioctl r/o */
  1860. __kernel_dev_t32 lo_rdevice;     /* ioctl r/o */
  1861. int lo_offset;
  1862. int lo_encrypt_type;
  1863. int lo_encrypt_key_size;    /* ioctl w/o */
  1864. int lo_flags;       /* ioctl r/o */
  1865. char lo_name[LO_NAME_SIZE];
  1866. unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
  1867. unsigned int lo_init[2];
  1868. char reserved[4];
  1869. };
  1870. static int loop_status(unsigned int fd, unsigned int cmd, unsigned long arg)
  1871. {
  1872. mm_segment_t old_fs = get_fs();
  1873. struct loop_info l;
  1874. int err = -EINVAL;
  1875. switch(cmd) {
  1876. case LOOP_SET_STATUS:
  1877. err = get_user(l.lo_number, &((struct loop_info32 *)arg)->lo_number);
  1878. err |= __get_user(l.lo_device, &((struct loop_info32 *)arg)->lo_device);
  1879. err |= __get_user(l.lo_inode, &((struct loop_info32 *)arg)->lo_inode);
  1880. err |= __get_user(l.lo_rdevice, &((struct loop_info32 *)arg)->lo_rdevice);
  1881. err |= __copy_from_user((char *)&l.lo_offset, (char *)&((struct loop_info32 *)arg)->lo_offset,
  1882.    8 + (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);
  1883. if (err) {
  1884. err = -EFAULT;
  1885. } else {
  1886. set_fs (KERNEL_DS);
  1887. err = sys_ioctl (fd, cmd, (unsigned long)&l);
  1888. set_fs (old_fs);
  1889. }
  1890. break;
  1891. case LOOP_GET_STATUS:
  1892. set_fs (KERNEL_DS);
  1893. err = sys_ioctl (fd, cmd, (unsigned long)&l);
  1894. set_fs (old_fs);
  1895. if (!err) {
  1896. err = put_user(l.lo_number, &((struct loop_info32 *)arg)->lo_number);
  1897. err |= __put_user(l.lo_device, &((struct loop_info32 *)arg)->lo_device);
  1898. err |= __put_user(l.lo_inode, &((struct loop_info32 *)arg)->lo_inode);
  1899. err |= __put_user(l.lo_rdevice, &((struct loop_info32 *)arg)->lo_rdevice);
  1900. err |= __copy_to_user((char *)&((struct loop_info32 *)arg)->lo_offset,
  1901.    (char *)&l.lo_offset, (unsigned long)l.lo_init - (unsigned long)&l.lo_offset);
  1902. if (err)
  1903. err = -EFAULT;
  1904. }
  1905. break;
  1906. default: {
  1907. static int count;
  1908. if (++count <= 20)
  1909. printk("%s: Unknown loop ioctl cmd, fd(%d) "
  1910.        "cmd(%08x) arg(%08lx)n",
  1911.        __FUNCTION__, fd, cmd, arg);
  1912. }
  1913. }
  1914. return err;
  1915. }
  1916. extern int tty_ioctl(struct inode * inode, struct file * file, unsigned int cmd, unsigned long arg);
  1917. static int vt_check(struct file *file)
  1918. {
  1919. struct tty_struct *tty;
  1920. struct inode *inode = file->f_dentry->d_inode;
  1921. if (file->f_op->ioctl != tty_ioctl)
  1922. return -EINVAL;
  1923.                 
  1924. tty = (struct tty_struct *)file->private_data;
  1925. if (tty_paranoia_check(tty, inode->i_rdev, "tty_ioctl"))
  1926. return -EINVAL;
  1927.                                                 
  1928. if (tty->driver.ioctl != vt_ioctl)
  1929. return -EINVAL;
  1930. /*
  1931.  * To have permissions to do most of the vt ioctls, we either have
  1932.  * to be the owner of the tty, or super-user.
  1933.  */
  1934. if (current->tty == tty || suser())
  1935. return 1;
  1936. return 0;                                                    
  1937. }
  1938. struct consolefontdesc32 {
  1939. unsigned short charcount;       /* characters in font (256 or 512) */
  1940. unsigned short charheight;      /* scan lines per character (1-32) */
  1941. u32 chardata; /* font data in expanded form */
  1942. };
  1943. static int do_fontx_ioctl(unsigned int fd, int cmd, struct consolefontdesc32 *user_cfd, struct file *file)
  1944. {
  1945. struct consolefontdesc cfdarg;
  1946. struct console_font_op op;
  1947. int i, perm;
  1948. perm = vt_check(file);
  1949. if (perm < 0) return perm;
  1950. if (copy_from_user(&cfdarg, user_cfd, sizeof(struct consolefontdesc32)))
  1951. return -EFAULT;
  1952. cfdarg.chardata = (unsigned char *)A(((struct consolefontdesc32 *)&cfdarg)->chardata);
  1953.  
  1954. switch (cmd) {
  1955. case PIO_FONTX:
  1956. if (!perm)
  1957. return -EPERM;
  1958. op.op = KD_FONT_OP_SET;
  1959. op.flags = 0;
  1960. op.width = 8;
  1961. op.height = cfdarg.charheight;
  1962. op.charcount = cfdarg.charcount;
  1963. op.data = cfdarg.chardata;
  1964. return con_font_op(fg_console, &op);
  1965. case GIO_FONTX:
  1966. if (!cfdarg.chardata)
  1967. return 0;
  1968. op.op = KD_FONT_OP_GET;
  1969. op.flags = 0;
  1970. op.width = 8;
  1971. op.height = cfdarg.charheight;
  1972. op.charcount = cfdarg.charcount;
  1973. op.data = cfdarg.chardata;
  1974. i = con_font_op(fg_console, &op);
  1975. if (i)
  1976. return i;
  1977. cfdarg.charheight = op.height;
  1978. cfdarg.charcount = op.charcount;
  1979. ((struct consolefontdesc32 *)&cfdarg)->chardata = (unsigned long)cfdarg.chardata;
  1980. if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc32)))
  1981. return -EFAULT;
  1982. return 0;
  1983. }
  1984. return -EINVAL;
  1985. }
  1986. struct console_font_op32 {
  1987. unsigned int op;        /* operation code KD_FONT_OP_* */
  1988. unsigned int flags;     /* KD_FONT_FLAG_* */
  1989. unsigned int width, height;     /* font size */
  1990. unsigned int charcount;
  1991. u32 data;    /* font data with height fixed to 32 */
  1992. };
  1993.                                         
  1994. static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, struct console_font_op32 *fontop, struct file *file)
  1995. {
  1996. struct console_font_op op;
  1997. int perm = vt_check(file), i;
  1998. struct vt_struct *vt;
  1999. if (perm < 0) return perm;
  2000. if (copy_from_user(&op, (void *) fontop, sizeof(struct console_font_op32)))
  2001. return -EFAULT;
  2002. if (!perm && op.op != KD_FONT_OP_GET)
  2003. return -EPERM;
  2004. op.data = (unsigned char *)A(((struct console_font_op32 *)&op)->data);
  2005. op.flags |= KD_FONT_FLAG_OLD;
  2006. vt = (struct vt_struct *)((struct tty_struct *)file->private_data)->driver_data;
  2007. i = con_font_op(vt->vc_num, &op);
  2008. if (i) return i;
  2009. ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
  2010. if (copy_to_user((void *) fontop, &op, sizeof(struct console_font_op32)))
  2011. return -EFAULT;
  2012. return 0;
  2013. }
  2014. struct unimapdesc32 {
  2015. unsigned short entry_ct;
  2016. u32 entries;
  2017. };
  2018. static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, struct unimapdesc32 *user_ud, struct file *file)
  2019. {
  2020. struct unimapdesc32 tmp;
  2021. int perm = vt_check(file);
  2022. if (perm < 0) return perm;
  2023. if (copy_from_user(&tmp, user_ud, sizeof tmp))
  2024. return -EFAULT;
  2025. switch (cmd) {
  2026. case PIO_UNIMAP:
  2027. if (!perm) return -EPERM;
  2028. return con_set_unimap(fg_console, tmp.entry_ct, (struct unipair *)A(tmp.entries));
  2029. case GIO_UNIMAP:
  2030. return con_get_unimap(fg_console, tmp.entry_ct, &(user_ud->entry_ct), (struct unipair *)A(tmp.entries));
  2031. }
  2032. return 0;
  2033. }
  2034. static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
  2035. {
  2036. mm_segment_t old_fs = get_fs();
  2037. __kernel_uid_t kuid;
  2038. int err;
  2039. cmd = SMB_IOC_GETMOUNTUID;
  2040. set_fs(KERNEL_DS);
  2041. err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
  2042. set_fs(old_fs);
  2043. if (err >= 0)
  2044. err = put_user(kuid, (__kernel_uid_t32 *)arg);
  2045. return err;
  2046. }
  2047. struct ncp_ioctl_request_32 {
  2048. unsigned int function;
  2049. unsigned int size;
  2050. __kernel_caddr_t32 data;
  2051. };
  2052. struct ncp_fs_info_v2_32 {
  2053. int version;
  2054. unsigned int mounted_uid;
  2055. unsigned int connection;
  2056. unsigned int buffer_size;
  2057. unsigned int volume_number;
  2058. __u32 directory_id;
  2059. __u32 dummy1;
  2060. __u32 dummy2;
  2061. __u32 dummy3;
  2062. };
  2063. struct ncp_objectname_ioctl_32
  2064. {
  2065. int auth_type;
  2066. unsigned int object_name_len;
  2067. __kernel_caddr_t32 object_name; /* an userspace data, in most cases user name */
  2068. };
  2069. struct ncp_privatedata_ioctl_32
  2070. {
  2071. unsigned int len;
  2072. __kernel_caddr_t32 data; /* ~1000 for NDS */
  2073. };
  2074. #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct ncp_ioctl_request_32)
  2075. #define NCP_IOC_GETMOUNTUID2_32 _IOW('n', 2, unsigned int)
  2076. #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct ncp_fs_info_v2_32)
  2077. #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct ncp_objectname_ioctl_32)
  2078. #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct ncp_objectname_ioctl_32)
  2079. #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct ncp_privatedata_ioctl_32)
  2080. #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct ncp_privatedata_ioctl_32)
  2081. static int do_ncp_ncprequest(unsigned int fd, unsigned int cmd, unsigned long arg)
  2082. {
  2083. struct ncp_ioctl_request_32 n32;
  2084. struct ncp_ioctl_request n;
  2085. mm_segment_t old_fs;
  2086. int err;
  2087. if (copy_from_user(&n32, (struct ncp_ioctl_request_32*)arg,
  2088.     sizeof(n32)))
  2089. return -EFAULT;
  2090. n.function = n32.function;
  2091. n.size = n32.size;
  2092. if (n.size > 65536)
  2093. return -EINVAL;
  2094. n.data = vmalloc(65536); /* 65536 must be same as NCP_PACKET_SIZE_INTERNAL in ncpfs */
  2095. if (!n.data)
  2096. return -ENOMEM;
  2097. err = -EFAULT;
  2098. if (copy_from_user(n.data, A(n32.data), n.size))
  2099. goto out;
  2100. old_fs = get_fs(); set_fs (KERNEL_DS);
  2101. err = sys_ioctl (fd, NCP_IOC_NCPREQUEST, (unsigned long)&n);
  2102. set_fs (old_fs);
  2103.         if(err <= 0)
  2104. goto out;
  2105. if (err > 65536) {
  2106. err = -EINVAL;
  2107. goto out;
  2108. }
  2109. if (copy_to_user(A(n32.data), n.data, err)) {
  2110. err = -EFAULT;
  2111. goto out;
  2112. }
  2113.  out:
  2114. vfree(n.data);
  2115. return err;
  2116. }
  2117. static int do_ncp_getmountuid2(unsigned int fd, unsigned int cmd, unsigned long arg)
  2118. {
  2119. mm_segment_t old_fs = get_fs();
  2120. __kernel_uid_t kuid;
  2121. int err;
  2122. cmd = NCP_IOC_GETMOUNTUID2;
  2123. set_fs(KERNEL_DS);
  2124. err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
  2125. set_fs(old_fs);
  2126. if (!err)
  2127. err = put_user(kuid, (unsigned int*)arg);
  2128. return err;
  2129. }
  2130. static int do_ncp_getfsinfo2(unsigned int fd, unsigned int cmd, unsigned long arg)
  2131. {
  2132. mm_segment_t old_fs = get_fs();
  2133. struct ncp_fs_info_v2_32 n32;
  2134. struct ncp_fs_info_v2 n;
  2135. int err;
  2136. if (copy_from_user(&n32, (struct ncp_fs_info_v2_32*)arg, sizeof(n32)))
  2137. return -EFAULT;
  2138. if (n32.version != NCP_GET_FS_INFO_VERSION_V2)
  2139. return -EINVAL;
  2140. n.version = NCP_GET_FS_INFO_VERSION_V2;
  2141. set_fs(KERNEL_DS);
  2142. err = sys_ioctl(fd, NCP_IOC_GET_FS_INFO_V2, (unsigned long)&n);
  2143. set_fs(old_fs);
  2144. if (!err) {
  2145. n32.version = n.version;
  2146. n32.mounted_uid = n.mounted_uid;
  2147. n32.connection = n.connection;
  2148. n32.buffer_size = n.buffer_size;
  2149. n32.volume_number = n.volume_number;
  2150. n32.directory_id = n.directory_id;
  2151. n32.dummy1 = n.dummy1;
  2152. n32.dummy2 = n.dummy2;
  2153. n32.dummy3 = n.dummy3;
  2154. err = copy_to_user((struct ncp_fs_info_v2_32*)arg, &n32, sizeof(n32)) ? -EFAULT : 0;
  2155. }
  2156. return err;
  2157. }
  2158. static int do_ncp_getobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
  2159. {
  2160. struct ncp_objectname_ioctl_32 n32;
  2161. struct ncp_objectname_ioctl n;
  2162. mm_segment_t old_fs;
  2163. int err;
  2164. size_t tl;
  2165. if (copy_from_user(&n32, (struct ncp_objectname_ioctl_32*)arg,
  2166.     sizeof(n32)))
  2167. return -EFAULT;
  2168. n.object_name_len = tl = n32.object_name_len;
  2169. if (tl) {
  2170. n.object_name = kmalloc(tl, GFP_KERNEL);
  2171. if (!n.object_name)
  2172. return -ENOMEM;
  2173. } else {
  2174. n.object_name = NULL;
  2175. }
  2176. old_fs = get_fs(); set_fs (KERNEL_DS);
  2177. err = sys_ioctl (fd, NCP_IOC_GETOBJECTNAME, (unsigned long)&n);
  2178. set_fs (old_fs);
  2179.         if(err)
  2180. goto out;
  2181. if (tl > n.object_name_len)
  2182. tl = n.object_name_len;
  2183. err = -EFAULT;
  2184. if (tl && copy_to_user(A(n32.object_name), n.object_name, tl))
  2185. goto out;
  2186. n32.auth_type = n.auth_type;
  2187. n32.object_name_len = n.object_name_len;
  2188. if (copy_to_user((struct ncp_objectname_ioctl_32*)arg, &n32, sizeof(n32)))
  2189. goto out;
  2190. err = 0;
  2191.  out:
  2192.   if (n.object_name)
  2193. kfree(n.object_name);
  2194. return err;
  2195. }
  2196. static int do_ncp_setobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
  2197. {
  2198. struct ncp_objectname_ioctl_32 n32;
  2199. struct ncp_objectname_ioctl n;
  2200. mm_segment_t old_fs;
  2201. int err;
  2202. size_t tl;
  2203. if (copy_from_user(&n32, (struct ncp_objectname_ioctl_32*)arg,
  2204.     sizeof(n32)))
  2205. return -EFAULT;
  2206. n.auth_type = n32.auth_type;
  2207. n.object_name_len = tl = n32.object_name_len;
  2208. if (tl) {
  2209. n.object_name = kmalloc(tl, GFP_KERNEL);
  2210. if (!n.object_name)
  2211. return -ENOMEM;
  2212. err = -EFAULT;
  2213. if (copy_from_user(n.object_name, A(n32.object_name), tl))
  2214. goto out;
  2215. } else {
  2216. n.object_name = NULL;
  2217. }
  2218. old_fs = get_fs(); set_fs (KERNEL_DS);
  2219. err = sys_ioctl (fd, NCP_IOC_SETOBJECTNAME, (unsigned long)&n);
  2220. set_fs (old_fs);
  2221.  out:
  2222. if (n.object_name)
  2223. kfree(n.object_name);
  2224. return err;
  2225. }
  2226. static int do_ncp_getprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
  2227. {
  2228. struct ncp_privatedata_ioctl_32 n32;
  2229. struct ncp_privatedata_ioctl n;
  2230. mm_segment_t old_fs;
  2231. int err;
  2232. size_t tl;
  2233. if (copy_from_user(&n32, (struct ncp_privatedata_ioctl_32*)arg,
  2234.     sizeof(n32)))
  2235. return -EFAULT;
  2236. n.len = tl = n32.len;
  2237. if (tl) {
  2238. n.data = kmalloc(tl, GFP_KERNEL);
  2239. if (!n.data)
  2240. return -ENOMEM;
  2241. } else {
  2242. n.data = NULL;
  2243. }
  2244. old_fs = get_fs(); set_fs (KERNEL_DS);
  2245. err = sys_ioctl (fd, NCP_IOC_GETPRIVATEDATA, (unsigned long)&n);
  2246. set_fs (old_fs);
  2247.         if(err)
  2248. goto out;
  2249. if (tl > n.len)
  2250. tl = n.len;
  2251. err = -EFAULT;
  2252. if (tl && copy_to_user(A(n32.data), n.data, tl))
  2253. goto out;
  2254. n32.len = n.len;
  2255. if (copy_to_user((struct ncp_privatedata_ioctl_32*)arg, &n32, sizeof(n32)))
  2256. goto out;
  2257. err = 0;
  2258.  out:
  2259.   if (n.data)
  2260. kfree(n.data);
  2261. return err;
  2262. }
  2263. static int do_ncp_setprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
  2264. {
  2265. struct ncp_privatedata_ioctl_32 n32;
  2266. struct ncp_privatedata_ioctl n;
  2267. mm_segment_t old_fs;
  2268. int err;
  2269. size_t tl;
  2270. if (copy_from_user(&n32, (struct ncp_privatedata_ioctl_32*)arg,
  2271.     sizeof(n32)))
  2272. return -EFAULT;
  2273. n.len = tl = n32.len;
  2274. if (tl) {
  2275. n.data = kmalloc(tl, GFP_KERNEL);
  2276. if (!n.data)
  2277. return -ENOMEM;
  2278. err = -EFAULT;
  2279. if (copy_from_user(n.data, A(n32.data), tl))
  2280. goto out;
  2281. } else {
  2282. n.data = NULL;
  2283. }
  2284. old_fs = get_fs(); set_fs (KERNEL_DS);
  2285. err = sys_ioctl (fd, NCP_IOC_SETPRIVATEDATA, (unsigned long)&n);
  2286. set_fs (old_fs);
  2287.  out:
  2288. if (n.data)
  2289. kfree(n.data);
  2290. return err;
  2291. }
  2292. struct atmif_sioc32 {
  2293.         int                number;
  2294.         int                length;
  2295.         __kernel_caddr_t32 arg;
  2296. };
  2297. struct atm_iobuf32 {
  2298. int                length;
  2299. __kernel_caddr_t32 buffer;
  2300. };
  2301. #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
  2302. #define ATM_GETNAMES32    _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
  2303. #define ATM_GETTYPE32     _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
  2304. #define ATM_GETESI32   _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
  2305. #define ATM_GETADDR32   _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
  2306. #define ATM_RSTADDR32   _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
  2307. #define ATM_ADDADDR32   _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
  2308. #define ATM_DELADDR32   _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
  2309. #define ATM_GETCIRANGE32  _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
  2310. #define ATM_SETCIRANGE32  _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
  2311. #define ATM_SETESI32      _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
  2312. #define ATM_SETESIF32     _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
  2313. #define ATM_GETSTAT32     _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
  2314. #define ATM_GETSTATZ32    _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
  2315. #define ATM_GETLOOP32   _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
  2316. #define ATM_SETLOOP32   _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
  2317. #define ATM_QUERYLOOP32   _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
  2318. static struct {
  2319.         unsigned int cmd32;
  2320.         unsigned int cmd;
  2321. } atm_ioctl_map[] = {
  2322.         { ATM_GETLINKRATE32, ATM_GETLINKRATE },
  2323. { ATM_GETNAMES32,    ATM_GETNAMES },
  2324.         { ATM_GETTYPE32,     ATM_GETTYPE },
  2325.         { ATM_GETESI32,      ATM_GETESI },
  2326.         { ATM_GETADDR32,     ATM_GETADDR },
  2327.         { ATM_RSTADDR32,     ATM_RSTADDR },
  2328.         { ATM_ADDADDR32,     ATM_ADDADDR },
  2329.         { ATM_DELADDR32,     ATM_DELADDR },
  2330.         { ATM_GETCIRANGE32,  ATM_GETCIRANGE },
  2331. { ATM_SETCIRANGE32,  ATM_SETCIRANGE },
  2332. { ATM_SETESI32,      ATM_SETESI },
  2333. { ATM_SETESIF32,     ATM_SETESIF },
  2334. { ATM_GETSTAT32,     ATM_GETSTAT },
  2335. { ATM_GETSTATZ32,    ATM_GETSTATZ },
  2336. { ATM_GETLOOP32,     ATM_GETLOOP },
  2337. { ATM_SETLOOP32,     ATM_SETLOOP },
  2338. { ATM_QUERYLOOP32,   ATM_QUERYLOOP }
  2339. };
  2340. #define NR_ATM_IOCTL (sizeof(atm_ioctl_map)/sizeof(atm_ioctl_map[0]))
  2341. static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
  2342. {
  2343. struct atm_iobuf32 iobuf32;
  2344. struct atm_iobuf   iobuf = { 0, NULL };
  2345. mm_segment_t old_fs;
  2346. int err;
  2347. err = copy_from_user(&iobuf32, (struct atm_iobuf32*)arg,
  2348.     sizeof(struct atm_iobuf32));
  2349. if (err)
  2350. return -EFAULT;
  2351. iobuf.length = iobuf32.length;
  2352. if (iobuf32.buffer == (__kernel_caddr_t32) NULL || iobuf32.length == 0) {
  2353. iobuf.buffer = (void*)(unsigned long)iobuf32.buffer;
  2354. } else {
  2355. iobuf.buffer = kmalloc(iobuf.length, GFP_KERNEL);
  2356. if (iobuf.buffer == NULL) {
  2357. err = -ENOMEM;
  2358. goto out;
  2359. }
  2360. err = copy_from_user(iobuf.buffer, A(iobuf32.buffer), iobuf.length);
  2361. if (err) {
  2362. err = -EFAULT;
  2363. goto out;
  2364. }
  2365. }
  2366. old_fs = get_fs(); set_fs (KERNEL_DS);
  2367. err = sys_ioctl (fd, cmd, (unsigned long)&iobuf);      
  2368. set_fs (old_fs);
  2369.         if(err)
  2370. goto out;
  2371.         if(iobuf.buffer && iobuf.length > 0) {
  2372. err = copy_to_user(A(iobuf32.buffer), iobuf.buffer, iobuf.length);
  2373. if (err) {
  2374. err = -EFAULT;
  2375. goto out;
  2376. }
  2377. }
  2378. err = __put_user(iobuf.length, &(((struct atm_iobuf32*)arg)->length));
  2379.  out:
  2380.         if(iobuf32.buffer && iobuf32.length > 0)
  2381. kfree(iobuf.buffer);
  2382. return err;
  2383. }
  2384. static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
  2385. {
  2386.         struct atmif_sioc32 sioc32;
  2387.         struct atmif_sioc   sioc = { 0, 0, NULL };