compat_ioctl.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781
  1. /*
  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. * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
  7. * Copyright (C) 2003 Pavel Machek (pavel@suse.cz)
  8. *
  9. * These routines maintain argument size conversion between 32bit and 64bit
  10. * ioctls.
  11. */
  12. #include <linux/types.h>
  13. #include <linux/compat.h>
  14. #include <linux/kernel.h>
  15. #include <linux/capability.h>
  16. #include <linux/compiler.h>
  17. #include <linux/sched.h>
  18. #include <linux/smp.h>
  19. #include <linux/smp_lock.h>
  20. #include <linux/ioctl.h>
  21. #include <linux/if.h>
  22. #include <linux/if_bridge.h>
  23. #include <linux/slab.h>
  24. #include <linux/hdreg.h>
  25. #include <linux/raid/md.h>
  26. #include <linux/kd.h>
  27. #include <linux/dirent.h>
  28. #include <linux/route.h>
  29. #include <linux/in6.h>
  30. #include <linux/ipv6_route.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/netlink.h>
  33. #include <linux/vt.h>
  34. #include <linux/fs.h>
  35. #include <linux/file.h>
  36. #include <linux/fd.h>
  37. #include <linux/ppp_defs.h>
  38. #include <linux/if_ppp.h>
  39. #include <linux/if_pppox.h>
  40. #include <linux/mtio.h>
  41. #include <linux/cdrom.h>
  42. #include <linux/auto_fs.h>
  43. #include <linux/auto_fs4.h>
  44. #include <linux/tty.h>
  45. #include <linux/vt_kern.h>
  46. #include <linux/fb.h>
  47. #include <linux/videodev.h>
  48. #include <linux/netdevice.h>
  49. #include <linux/raw.h>
  50. #include <linux/smb_fs.h>
  51. #include <linux/blkpg.h>
  52. #include <linux/blkdev.h>
  53. #include <linux/elevator.h>
  54. #include <linux/rtc.h>
  55. #include <linux/pci.h>
  56. #include <linux/module.h>
  57. #include <linux/serial.h>
  58. #include <linux/if_tun.h>
  59. #include <linux/ctype.h>
  60. #include <linux/ioctl32.h>
  61. #include <linux/syscalls.h>
  62. #include <linux/ncp_fs.h>
  63. #include <linux/i2c.h>
  64. #include <linux/i2c-dev.h>
  65. #include <linux/wireless.h>
  66. #include <linux/atalk.h>
  67. #include <linux/blktrace_api.h>
  68. #include <net/sock.h> /* siocdevprivate_ioctl */
  69. #include <net/bluetooth/bluetooth.h>
  70. #include <net/bluetooth/hci.h>
  71. #include <net/bluetooth/rfcomm.h>
  72. #include <linux/capi.h>
  73. #include <linux/gigaset_dev.h>
  74. #include <scsi/scsi.h>
  75. #include <scsi/scsi_ioctl.h>
  76. #include <scsi/sg.h>
  77. #include <asm/uaccess.h>
  78. #include <linux/ethtool.h>
  79. #include <linux/mii.h>
  80. #include <linux/if_bonding.h>
  81. #include <linux/watchdog.h>
  82. #include <linux/dm-ioctl.h>
  83. #include <linux/soundcard.h>
  84. #include <linux/lp.h>
  85. #include <linux/ppdev.h>
  86. #include <linux/atm.h>
  87. #include <linux/atmarp.h>
  88. #include <linux/atmclip.h>
  89. #include <linux/atmdev.h>
  90. #include <linux/atmioc.h>
  91. #include <linux/atmlec.h>
  92. #include <linux/atmmpc.h>
  93. #include <linux/atmsvc.h>
  94. #include <linux/atm_tcp.h>
  95. #include <linux/sonet.h>
  96. #include <linux/atm_suni.h>
  97. #include <linux/mtd/mtd.h>
  98. #include <linux/usb.h>
  99. #include <linux/usbdevice_fs.h>
  100. #include <linux/nbd.h>
  101. #include <linux/random.h>
  102. #include <linux/filter.h>
  103. #include <linux/pktcdvd.h>
  104. #include <linux/hiddev.h>
  105. #include <linux/dvb/audio.h>
  106. #include <linux/dvb/dmx.h>
  107. #include <linux/dvb/frontend.h>
  108. #include <linux/dvb/video.h>
  109. #include <linux/lp.h>
  110. static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd,
  111. unsigned long arg, struct file *f)
  112. {
  113. return sys_ioctl(fd, cmd, (unsigned long)compat_ptr(arg));
  114. }
  115. static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
  116. {
  117. mm_segment_t old_fs = get_fs();
  118. int err;
  119. unsigned long val;
  120. set_fs (KERNEL_DS);
  121. err = sys_ioctl(fd, cmd, (unsigned long)&val);
  122. set_fs (old_fs);
  123. if (!err && put_user(val, (u32 __user *)compat_ptr(arg)))
  124. return -EFAULT;
  125. return err;
  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. u32 __user *argptr = compat_ptr(arg);
  131. int err;
  132. unsigned long val;
  133. if(get_user(val, argptr))
  134. return -EFAULT;
  135. set_fs (KERNEL_DS);
  136. err = sys_ioctl(fd, cmd, (unsigned long)&val);
  137. set_fs (old_fs);
  138. if (!err && put_user(val, argptr))
  139. return -EFAULT;
  140. return err;
  141. }
  142. struct compat_video_event {
  143. int32_t type;
  144. compat_time_t timestamp;
  145. union {
  146. video_size_t size;
  147. unsigned int frame_rate;
  148. } u;
  149. };
  150. static int do_video_get_event(unsigned int fd, unsigned int cmd, unsigned long arg)
  151. {
  152. struct video_event kevent;
  153. mm_segment_t old_fs = get_fs();
  154. int err;
  155. set_fs(KERNEL_DS);
  156. err = sys_ioctl(fd, cmd, (unsigned long) &kevent);
  157. set_fs(old_fs);
  158. if (!err) {
  159. struct compat_video_event __user *up = compat_ptr(arg);
  160. err = put_user(kevent.type, &up->type);
  161. err |= put_user(kevent.timestamp, &up->timestamp);
  162. err |= put_user(kevent.u.size.w, &up->u.size.w);
  163. err |= put_user(kevent.u.size.h, &up->u.size.h);
  164. err |= put_user(kevent.u.size.aspect_ratio,
  165. &up->u.size.aspect_ratio);
  166. if (err)
  167. err = -EFAULT;
  168. }
  169. return err;
  170. }
  171. struct compat_video_still_picture {
  172. compat_uptr_t iFrame;
  173. int32_t size;
  174. };
  175. static int do_video_stillpicture(unsigned int fd, unsigned int cmd, unsigned long arg)
  176. {
  177. struct compat_video_still_picture __user *up;
  178. struct video_still_picture __user *up_native;
  179. compat_uptr_t fp;
  180. int32_t size;
  181. int err;
  182. up = (struct compat_video_still_picture __user *) arg;
  183. err = get_user(fp, &up->iFrame);
  184. err |= get_user(size, &up->size);
  185. if (err)
  186. return -EFAULT;
  187. up_native =
  188. compat_alloc_user_space(sizeof(struct video_still_picture));
  189. put_user(compat_ptr(fp), &up_native->iFrame);
  190. put_user(size, &up_native->size);
  191. err = sys_ioctl(fd, cmd, (unsigned long) up_native);
  192. return err;
  193. }
  194. struct compat_video_spu_palette {
  195. int length;
  196. compat_uptr_t palette;
  197. };
  198. static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned long arg)
  199. {
  200. struct compat_video_spu_palette __user *up;
  201. struct video_spu_palette __user *up_native;
  202. compat_uptr_t palp;
  203. int length, err;
  204. up = (struct compat_video_spu_palette __user *) arg;
  205. err = get_user(palp, &up->palette);
  206. err |= get_user(length, &up->length);
  207. up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
  208. put_user(compat_ptr(palp), &up_native->palette);
  209. put_user(length, &up_native->length);
  210. err = sys_ioctl(fd, cmd, (unsigned long) up_native);
  211. return err;
  212. }
  213. #ifdef CONFIG_NET
  214. static int do_siocgstamp(unsigned int fd, unsigned int cmd, unsigned long arg)
  215. {
  216. struct compat_timeval __user *up = compat_ptr(arg);
  217. struct timeval ktv;
  218. mm_segment_t old_fs = get_fs();
  219. int err;
  220. set_fs(KERNEL_DS);
  221. err = sys_ioctl(fd, cmd, (unsigned long)&ktv);
  222. set_fs(old_fs);
  223. if(!err) {
  224. err = put_user(ktv.tv_sec, &up->tv_sec);
  225. err |= __put_user(ktv.tv_usec, &up->tv_usec);
  226. }
  227. return err;
  228. }
  229. struct ifmap32 {
  230. compat_ulong_t mem_start;
  231. compat_ulong_t mem_end;
  232. unsigned short base_addr;
  233. unsigned char irq;
  234. unsigned char dma;
  235. unsigned char port;
  236. };
  237. struct ifreq32 {
  238. #define IFHWADDRLEN 6
  239. #define IFNAMSIZ 16
  240. union {
  241. char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  242. } ifr_ifrn;
  243. union {
  244. struct sockaddr ifru_addr;
  245. struct sockaddr ifru_dstaddr;
  246. struct sockaddr ifru_broadaddr;
  247. struct sockaddr ifru_netmask;
  248. struct sockaddr ifru_hwaddr;
  249. short ifru_flags;
  250. compat_int_t ifru_ivalue;
  251. compat_int_t ifru_mtu;
  252. struct ifmap32 ifru_map;
  253. char ifru_slave[IFNAMSIZ]; /* Just fits the size */
  254. char ifru_newname[IFNAMSIZ];
  255. compat_caddr_t ifru_data;
  256. /* XXXX? ifru_settings should be here */
  257. } ifr_ifru;
  258. };
  259. struct ifconf32 {
  260. compat_int_t ifc_len; /* size of buffer */
  261. compat_caddr_t ifcbuf;
  262. };
  263. static int dev_ifname32(unsigned int fd, unsigned int cmd, unsigned long arg)
  264. {
  265. struct net_device *dev;
  266. struct ifreq32 ifr32;
  267. int err;
  268. if (copy_from_user(&ifr32, compat_ptr(arg), sizeof(ifr32)))
  269. return -EFAULT;
  270. dev = dev_get_by_index(ifr32.ifr_ifindex);
  271. if (!dev)
  272. return -ENODEV;
  273. strlcpy(ifr32.ifr_name, dev->name, sizeof(ifr32.ifr_name));
  274. dev_put(dev);
  275. err = copy_to_user(compat_ptr(arg), &ifr32, sizeof(ifr32));
  276. return (err ? -EFAULT : 0);
  277. }
  278. static int dev_ifconf(unsigned int fd, unsigned int cmd, unsigned long arg)
  279. {
  280. struct ifconf32 ifc32;
  281. struct ifconf ifc;
  282. struct ifconf __user *uifc;
  283. struct ifreq32 __user *ifr32;
  284. struct ifreq __user *ifr;
  285. unsigned int i, j;
  286. int err;
  287. if (copy_from_user(&ifc32, compat_ptr(arg), sizeof(struct ifconf32)))
  288. return -EFAULT;
  289. if (ifc32.ifcbuf == 0) {
  290. ifc32.ifc_len = 0;
  291. ifc.ifc_len = 0;
  292. ifc.ifc_req = NULL;
  293. uifc = compat_alloc_user_space(sizeof(struct ifconf));
  294. } else {
  295. size_t len =((ifc32.ifc_len / sizeof (struct ifreq32)) + 1) *
  296. sizeof (struct ifreq);
  297. uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
  298. ifc.ifc_len = len;
  299. ifr = ifc.ifc_req = (void __user *)(uifc + 1);
  300. ifr32 = compat_ptr(ifc32.ifcbuf);
  301. for (i = 0; i < ifc32.ifc_len; i += sizeof (struct ifreq32)) {
  302. if (copy_in_user(ifr, ifr32, sizeof(struct ifreq32)))
  303. return -EFAULT;
  304. ifr++;
  305. ifr32++;
  306. }
  307. }
  308. if (copy_to_user(uifc, &ifc, sizeof(struct ifconf)))
  309. return -EFAULT;
  310. err = sys_ioctl (fd, SIOCGIFCONF, (unsigned long)uifc);
  311. if (err)
  312. return err;
  313. if (copy_from_user(&ifc, uifc, sizeof(struct ifconf)))
  314. return -EFAULT;
  315. ifr = ifc.ifc_req;
  316. ifr32 = compat_ptr(ifc32.ifcbuf);
  317. for (i = 0, j = 0;
  318. i + sizeof (struct ifreq32) <= ifc32.ifc_len && j < ifc.ifc_len;
  319. i += sizeof (struct ifreq32), j += sizeof (struct ifreq)) {
  320. if (copy_in_user(ifr32, ifr, sizeof (struct ifreq32)))
  321. return -EFAULT;
  322. ifr32++;
  323. ifr++;
  324. }
  325. if (ifc32.ifcbuf == 0) {
  326. /* Translate from 64-bit structure multiple to
  327. * a 32-bit one.
  328. */
  329. i = ifc.ifc_len;
  330. i = ((i / sizeof(struct ifreq)) * sizeof(struct ifreq32));
  331. ifc32.ifc_len = i;
  332. } else {
  333. ifc32.ifc_len = i;
  334. }
  335. if (copy_to_user(compat_ptr(arg), &ifc32, sizeof(struct ifconf32)))
  336. return -EFAULT;
  337. return 0;
  338. }
  339. static int ethtool_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  340. {
  341. struct ifreq __user *ifr;
  342. struct ifreq32 __user *ifr32;
  343. u32 data;
  344. void __user *datap;
  345. ifr = compat_alloc_user_space(sizeof(*ifr));
  346. ifr32 = compat_ptr(arg);
  347. if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
  348. return -EFAULT;
  349. if (get_user(data, &ifr32->ifr_ifru.ifru_data))
  350. return -EFAULT;
  351. datap = compat_ptr(data);
  352. if (put_user(datap, &ifr->ifr_ifru.ifru_data))
  353. return -EFAULT;
  354. return sys_ioctl(fd, cmd, (unsigned long) ifr);
  355. }
  356. static int bond_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  357. {
  358. struct ifreq kifr;
  359. struct ifreq __user *uifr;
  360. struct ifreq32 __user *ifr32 = compat_ptr(arg);
  361. mm_segment_t old_fs;
  362. int err;
  363. u32 data;
  364. void __user *datap;
  365. switch (cmd) {
  366. case SIOCBONDENSLAVE:
  367. case SIOCBONDRELEASE:
  368. case SIOCBONDSETHWADDR:
  369. case SIOCBONDCHANGEACTIVE:
  370. if (copy_from_user(&kifr, ifr32, sizeof(struct ifreq32)))
  371. return -EFAULT;
  372. old_fs = get_fs();
  373. set_fs (KERNEL_DS);
  374. err = sys_ioctl (fd, cmd, (unsigned long)&kifr);
  375. set_fs (old_fs);
  376. return err;
  377. case SIOCBONDSLAVEINFOQUERY:
  378. case SIOCBONDINFOQUERY:
  379. uifr = compat_alloc_user_space(sizeof(*uifr));
  380. if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
  381. return -EFAULT;
  382. if (get_user(data, &ifr32->ifr_ifru.ifru_data))
  383. return -EFAULT;
  384. datap = compat_ptr(data);
  385. if (put_user(datap, &uifr->ifr_ifru.ifru_data))
  386. return -EFAULT;
  387. return sys_ioctl (fd, cmd, (unsigned long)uifr);
  388. default:
  389. return -EINVAL;
  390. };
  391. }
  392. int siocdevprivate_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  393. {
  394. struct ifreq __user *u_ifreq64;
  395. struct ifreq32 __user *u_ifreq32 = compat_ptr(arg);
  396. char tmp_buf[IFNAMSIZ];
  397. void __user *data64;
  398. u32 data32;
  399. if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
  400. IFNAMSIZ))
  401. return -EFAULT;
  402. if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
  403. return -EFAULT;
  404. data64 = compat_ptr(data32);
  405. u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
  406. /* Don't check these user accesses, just let that get trapped
  407. * in the ioctl handler instead.
  408. */
  409. if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0],
  410. IFNAMSIZ))
  411. return -EFAULT;
  412. if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data))
  413. return -EFAULT;
  414. return sys_ioctl(fd, cmd, (unsigned long) u_ifreq64);
  415. }
  416. static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
  417. {
  418. struct ifreq ifr;
  419. struct ifreq32 __user *uifr32;
  420. struct ifmap32 __user *uifmap32;
  421. mm_segment_t old_fs;
  422. int err;
  423. uifr32 = compat_ptr(arg);
  424. uifmap32 = &uifr32->ifr_ifru.ifru_map;
  425. switch (cmd) {
  426. case SIOCSIFMAP:
  427. err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name));
  428. err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
  429. err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
  430. err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
  431. err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq);
  432. err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma);
  433. err |= __get_user(ifr.ifr_map.port, &uifmap32->port);
  434. if (err)
  435. return -EFAULT;
  436. break;
  437. default:
  438. if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
  439. return -EFAULT;
  440. break;
  441. }
  442. old_fs = get_fs();
  443. set_fs (KERNEL_DS);
  444. err = sys_ioctl (fd, cmd, (unsigned long)&ifr);
  445. set_fs (old_fs);
  446. if (!err) {
  447. switch (cmd) {
  448. /* TUNSETIFF is defined as _IOW, it should be _IORW
  449. * as the data is copied back to user space, but that
  450. * cannot be fixed without breaking all existing apps.
  451. */
  452. case TUNSETIFF:
  453. case SIOCGIFFLAGS:
  454. case SIOCGIFMETRIC:
  455. case SIOCGIFMTU:
  456. case SIOCGIFMEM:
  457. case SIOCGIFHWADDR:
  458. case SIOCGIFINDEX:
  459. case SIOCGIFADDR:
  460. case SIOCGIFBRDADDR:
  461. case SIOCGIFDSTADDR:
  462. case SIOCGIFNETMASK:
  463. case SIOCGIFTXQLEN:
  464. if (copy_to_user(uifr32, &ifr, sizeof(*uifr32)))
  465. return -EFAULT;
  466. break;
  467. case SIOCGIFMAP:
  468. err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
  469. err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
  470. err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
  471. err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
  472. err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq);
  473. err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma);
  474. err |= __put_user(ifr.ifr_map.port, &uifmap32->port);
  475. if (err)
  476. err = -EFAULT;
  477. break;
  478. }
  479. }
  480. return err;
  481. }
  482. struct rtentry32 {
  483. u32 rt_pad1;
  484. struct sockaddr rt_dst; /* target address */
  485. struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
  486. struct sockaddr rt_genmask; /* target network mask (IP) */
  487. unsigned short rt_flags;
  488. short rt_pad2;
  489. u32 rt_pad3;
  490. unsigned char rt_tos;
  491. unsigned char rt_class;
  492. short rt_pad4;
  493. short rt_metric; /* +1 for binary compatibility! */
  494. /* char * */ u32 rt_dev; /* forcing the device at add */
  495. u32 rt_mtu; /* per route MTU/Window */
  496. u32 rt_window; /* Window clamping */
  497. unsigned short rt_irtt; /* Initial RTT */
  498. };
  499. struct in6_rtmsg32 {
  500. struct in6_addr rtmsg_dst;
  501. struct in6_addr rtmsg_src;
  502. struct in6_addr rtmsg_gateway;
  503. u32 rtmsg_type;
  504. u16 rtmsg_dst_len;
  505. u16 rtmsg_src_len;
  506. u32 rtmsg_metric;
  507. u32 rtmsg_info;
  508. u32 rtmsg_flags;
  509. s32 rtmsg_ifindex;
  510. };
  511. static int routing_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  512. {
  513. int ret;
  514. void *r = NULL;
  515. struct in6_rtmsg r6;
  516. struct rtentry r4;
  517. char devname[16];
  518. u32 rtdev;
  519. mm_segment_t old_fs = get_fs();
  520. struct socket *mysock = sockfd_lookup(fd, &ret);
  521. if (mysock && mysock->sk && mysock->sk->sk_family == AF_INET6) { /* ipv6 */
  522. struct in6_rtmsg32 __user *ur6 = compat_ptr(arg);
  523. ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst),
  524. 3 * sizeof(struct in6_addr));
  525. ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type));
  526. ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
  527. ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
  528. ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric));
  529. ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info));
  530. ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags));
  531. ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
  532. r = (void *) &r6;
  533. } else { /* ipv4 */
  534. struct rtentry32 __user *ur4 = compat_ptr(arg);
  535. ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst),
  536. 3 * sizeof(struct sockaddr));
  537. ret |= __get_user (r4.rt_flags, &(ur4->rt_flags));
  538. ret |= __get_user (r4.rt_metric, &(ur4->rt_metric));
  539. ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu));
  540. ret |= __get_user (r4.rt_window, &(ur4->rt_window));
  541. ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt));
  542. ret |= __get_user (rtdev, &(ur4->rt_dev));
  543. if (rtdev) {
  544. ret |= copy_from_user (devname, compat_ptr(rtdev), 15);
  545. r4.rt_dev = devname; devname[15] = 0;
  546. } else
  547. r4.rt_dev = NULL;
  548. r = (void *) &r4;
  549. }
  550. if (ret) {
  551. ret = -EFAULT;
  552. goto out;
  553. }
  554. set_fs (KERNEL_DS);
  555. ret = sys_ioctl (fd, cmd, (unsigned long) r);
  556. set_fs (old_fs);
  557. out:
  558. if (mysock)
  559. sockfd_put(mysock);
  560. return ret;
  561. }
  562. #endif
  563. #ifdef CONFIG_BLOCK
  564. struct hd_geometry32 {
  565. unsigned char heads;
  566. unsigned char sectors;
  567. unsigned short cylinders;
  568. u32 start;
  569. };
  570. static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg)
  571. {
  572. mm_segment_t old_fs = get_fs();
  573. struct hd_geometry geo;
  574. struct hd_geometry32 __user *ugeo;
  575. int err;
  576. set_fs (KERNEL_DS);
  577. err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo);
  578. set_fs (old_fs);
  579. ugeo = compat_ptr(arg);
  580. if (!err) {
  581. err = copy_to_user (ugeo, &geo, 4);
  582. err |= __put_user (geo.start, &ugeo->start);
  583. }
  584. return err ? -EFAULT : 0;
  585. }
  586. static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  587. {
  588. mm_segment_t old_fs = get_fs();
  589. unsigned long kval;
  590. unsigned int __user *uvp;
  591. int error;
  592. set_fs(KERNEL_DS);
  593. error = sys_ioctl(fd, cmd, (long)&kval);
  594. set_fs(old_fs);
  595. if(error == 0) {
  596. uvp = compat_ptr(arg);
  597. if(put_user(kval, uvp))
  598. error = -EFAULT;
  599. }
  600. return error;
  601. }
  602. typedef struct sg_io_hdr32 {
  603. compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
  604. compat_int_t dxfer_direction; /* [i] data transfer direction */
  605. unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */
  606. unsigned char mx_sb_len; /* [i] max length to write to sbp */
  607. unsigned short iovec_count; /* [i] 0 implies no scatter gather */
  608. compat_uint_t dxfer_len; /* [i] byte count of data transfer */
  609. compat_uint_t dxferp; /* [i], [*io] points to data transfer memory
  610. or scatter gather list */
  611. compat_uptr_t cmdp; /* [i], [*i] points to command to perform */
  612. compat_uptr_t sbp; /* [i], [*o] points to sense_buffer memory */
  613. compat_uint_t timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */
  614. compat_uint_t flags; /* [i] 0 -> default, see SG_FLAG... */
  615. compat_int_t pack_id; /* [i->o] unused internally (normally) */
  616. compat_uptr_t usr_ptr; /* [i->o] unused internally */
  617. unsigned char status; /* [o] scsi status */
  618. unsigned char masked_status; /* [o] shifted, masked scsi status */
  619. unsigned char msg_status; /* [o] messaging level data (optional) */
  620. unsigned char sb_len_wr; /* [o] byte count actually written to sbp */
  621. unsigned short host_status; /* [o] errors from host adapter */
  622. unsigned short driver_status; /* [o] errors from software driver */
  623. compat_int_t resid; /* [o] dxfer_len - actual_transferred */
  624. compat_uint_t duration; /* [o] time taken by cmd (unit: millisec) */
  625. compat_uint_t info; /* [o] auxiliary information */
  626. } sg_io_hdr32_t; /* 64 bytes long (on sparc32) */
  627. typedef struct sg_iovec32 {
  628. compat_uint_t iov_base;
  629. compat_uint_t iov_len;
  630. } sg_iovec32_t;
  631. static int sg_build_iovec(sg_io_hdr_t __user *sgio, void __user *dxferp, u16 iovec_count)
  632. {
  633. sg_iovec_t __user *iov = (sg_iovec_t __user *) (sgio + 1);
  634. sg_iovec32_t __user *iov32 = dxferp;
  635. int i;
  636. for (i = 0; i < iovec_count; i++) {
  637. u32 base, len;
  638. if (get_user(base, &iov32[i].iov_base) ||
  639. get_user(len, &iov32[i].iov_len) ||
  640. put_user(compat_ptr(base), &iov[i].iov_base) ||
  641. put_user(len, &iov[i].iov_len))
  642. return -EFAULT;
  643. }
  644. if (put_user(iov, &sgio->dxferp))
  645. return -EFAULT;
  646. return 0;
  647. }
  648. static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  649. {
  650. sg_io_hdr_t __user *sgio;
  651. sg_io_hdr32_t __user *sgio32;
  652. u16 iovec_count;
  653. u32 data;
  654. void __user *dxferp;
  655. int err;
  656. sgio32 = compat_ptr(arg);
  657. if (get_user(iovec_count, &sgio32->iovec_count))
  658. return -EFAULT;
  659. {
  660. void __user *top = compat_alloc_user_space(0);
  661. void __user *new = compat_alloc_user_space(sizeof(sg_io_hdr_t) +
  662. (iovec_count * sizeof(sg_iovec_t)));
  663. if (new > top)
  664. return -EINVAL;
  665. sgio = new;
  666. }
  667. /* Ok, now construct. */
  668. if (copy_in_user(&sgio->interface_id, &sgio32->interface_id,
  669. (2 * sizeof(int)) +
  670. (2 * sizeof(unsigned char)) +
  671. (1 * sizeof(unsigned short)) +
  672. (1 * sizeof(unsigned int))))
  673. return -EFAULT;
  674. if (get_user(data, &sgio32->dxferp))
  675. return -EFAULT;
  676. dxferp = compat_ptr(data);
  677. if (iovec_count) {
  678. if (sg_build_iovec(sgio, dxferp, iovec_count))
  679. return -EFAULT;
  680. } else {
  681. if (put_user(dxferp, &sgio->dxferp))
  682. return -EFAULT;
  683. }
  684. {
  685. unsigned char __user *cmdp;
  686. unsigned char __user *sbp;
  687. if (get_user(data, &sgio32->cmdp))
  688. return -EFAULT;
  689. cmdp = compat_ptr(data);
  690. if (get_user(data, &sgio32->sbp))
  691. return -EFAULT;
  692. sbp = compat_ptr(data);
  693. if (put_user(cmdp, &sgio->cmdp) ||
  694. put_user(sbp, &sgio->sbp))
  695. return -EFAULT;
  696. }
  697. if (copy_in_user(&sgio->timeout, &sgio32->timeout,
  698. 3 * sizeof(int)))
  699. return -EFAULT;
  700. if (get_user(data, &sgio32->usr_ptr))
  701. return -EFAULT;
  702. if (put_user(compat_ptr(data), &sgio->usr_ptr))
  703. return -EFAULT;
  704. if (copy_in_user(&sgio->status, &sgio32->status,
  705. (4 * sizeof(unsigned char)) +
  706. (2 * sizeof(unsigned (short))) +
  707. (3 * sizeof(int))))
  708. return -EFAULT;
  709. err = sys_ioctl(fd, cmd, (unsigned long) sgio);
  710. if (err >= 0) {
  711. void __user *datap;
  712. if (copy_in_user(&sgio32->pack_id, &sgio->pack_id,
  713. sizeof(int)) ||
  714. get_user(datap, &sgio->usr_ptr) ||
  715. put_user((u32)(unsigned long)datap,
  716. &sgio32->usr_ptr) ||
  717. copy_in_user(&sgio32->status, &sgio->status,
  718. (4 * sizeof(unsigned char)) +
  719. (2 * sizeof(unsigned short)) +
  720. (3 * sizeof(int))))
  721. err = -EFAULT;
  722. }
  723. return err;
  724. }
  725. struct compat_sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
  726. char req_state;
  727. char orphan;
  728. char sg_io_owned;
  729. char problem;
  730. int pack_id;
  731. compat_uptr_t usr_ptr;
  732. unsigned int duration;
  733. int unused;
  734. };
  735. static int sg_grt_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  736. {
  737. int err, i;
  738. sg_req_info_t __user *r;
  739. struct compat_sg_req_info __user *o = (void __user *)arg;
  740. r = compat_alloc_user_space(sizeof(sg_req_info_t)*SG_MAX_QUEUE);
  741. err = sys_ioctl(fd,cmd,(unsigned long)r);
  742. if (err < 0)
  743. return err;
  744. for (i = 0; i < SG_MAX_QUEUE; i++) {
  745. void __user *ptr;
  746. int d;
  747. if (copy_in_user(o + i, r + i, offsetof(sg_req_info_t, usr_ptr)) ||
  748. get_user(ptr, &r[i].usr_ptr) ||
  749. get_user(d, &r[i].duration) ||
  750. put_user((u32)(unsigned long)(ptr), &o[i].usr_ptr) ||
  751. put_user(d, &o[i].duration))
  752. return -EFAULT;
  753. }
  754. return err;
  755. }
  756. #endif /* CONFIG_BLOCK */
  757. struct sock_fprog32 {
  758. unsigned short len;
  759. compat_caddr_t filter;
  760. };
  761. #define PPPIOCSPASS32 _IOW('t', 71, struct sock_fprog32)
  762. #define PPPIOCSACTIVE32 _IOW('t', 70, struct sock_fprog32)
  763. static int ppp_sock_fprog_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  764. {
  765. struct sock_fprog32 __user *u_fprog32 = compat_ptr(arg);
  766. struct sock_fprog __user *u_fprog64 = compat_alloc_user_space(sizeof(struct sock_fprog));
  767. void __user *fptr64;
  768. u32 fptr32;
  769. u16 flen;
  770. if (get_user(flen, &u_fprog32->len) ||
  771. get_user(fptr32, &u_fprog32->filter))
  772. return -EFAULT;
  773. fptr64 = compat_ptr(fptr32);
  774. if (put_user(flen, &u_fprog64->len) ||
  775. put_user(fptr64, &u_fprog64->filter))
  776. return -EFAULT;
  777. if (cmd == PPPIOCSPASS32)
  778. cmd = PPPIOCSPASS;
  779. else
  780. cmd = PPPIOCSACTIVE;
  781. return sys_ioctl(fd, cmd, (unsigned long) u_fprog64);
  782. }
  783. struct ppp_option_data32 {
  784. compat_caddr_t ptr;
  785. u32 length;
  786. compat_int_t transmit;
  787. };
  788. #define PPPIOCSCOMPRESS32 _IOW('t', 77, struct ppp_option_data32)
  789. struct ppp_idle32 {
  790. compat_time_t xmit_idle;
  791. compat_time_t recv_idle;
  792. };
  793. #define PPPIOCGIDLE32 _IOR('t', 63, struct ppp_idle32)
  794. static int ppp_gidle(unsigned int fd, unsigned int cmd, unsigned long arg)
  795. {
  796. struct ppp_idle __user *idle;
  797. struct ppp_idle32 __user *idle32;
  798. __kernel_time_t xmit, recv;
  799. int err;
  800. idle = compat_alloc_user_space(sizeof(*idle));
  801. idle32 = compat_ptr(arg);
  802. err = sys_ioctl(fd, PPPIOCGIDLE, (unsigned long) idle);
  803. if (!err) {
  804. if (get_user(xmit, &idle->xmit_idle) ||
  805. get_user(recv, &idle->recv_idle) ||
  806. put_user(xmit, &idle32->xmit_idle) ||
  807. put_user(recv, &idle32->recv_idle))
  808. err = -EFAULT;
  809. }
  810. return err;
  811. }
  812. static int ppp_scompress(unsigned int fd, unsigned int cmd, unsigned long arg)
  813. {
  814. struct ppp_option_data __user *odata;
  815. struct ppp_option_data32 __user *odata32;
  816. __u32 data;
  817. void __user *datap;
  818. odata = compat_alloc_user_space(sizeof(*odata));
  819. odata32 = compat_ptr(arg);
  820. if (get_user(data, &odata32->ptr))
  821. return -EFAULT;
  822. datap = compat_ptr(data);
  823. if (put_user(datap, &odata->ptr))
  824. return -EFAULT;
  825. if (copy_in_user(&odata->length, &odata32->length,
  826. sizeof(__u32) + sizeof(int)))
  827. return -EFAULT;
  828. return sys_ioctl(fd, PPPIOCSCOMPRESS, (unsigned long) odata);
  829. }
  830. static int ppp_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  831. {
  832. int err;
  833. switch (cmd) {
  834. case PPPIOCGIDLE32:
  835. err = ppp_gidle(fd, cmd, arg);
  836. break;
  837. case PPPIOCSCOMPRESS32:
  838. err = ppp_scompress(fd, cmd, arg);
  839. break;
  840. default:
  841. do {
  842. static int count;
  843. if (++count <= 20)
  844. printk("ppp_ioctl: Unknown cmd fd(%d) "
  845. "cmd(%08x) arg(%08x)\n",
  846. (int)fd, (unsigned int)cmd, (unsigned int)arg);
  847. } while(0);
  848. err = -EINVAL;
  849. break;
  850. };
  851. return err;
  852. }
  853. #ifdef CONFIG_BLOCK
  854. struct mtget32 {
  855. compat_long_t mt_type;
  856. compat_long_t mt_resid;
  857. compat_long_t mt_dsreg;
  858. compat_long_t mt_gstat;
  859. compat_long_t mt_erreg;
  860. compat_daddr_t mt_fileno;
  861. compat_daddr_t mt_blkno;
  862. };
  863. #define MTIOCGET32 _IOR('m', 2, struct mtget32)
  864. struct mtpos32 {
  865. compat_long_t mt_blkno;
  866. };
  867. #define MTIOCPOS32 _IOR('m', 3, struct mtpos32)
  868. static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  869. {
  870. mm_segment_t old_fs = get_fs();
  871. struct mtget get;
  872. struct mtget32 __user *umget32;
  873. struct mtpos pos;
  874. struct mtpos32 __user *upos32;
  875. unsigned long kcmd;
  876. void *karg;
  877. int err = 0;
  878. switch(cmd) {
  879. case MTIOCPOS32:
  880. kcmd = MTIOCPOS;
  881. karg = &pos;
  882. break;
  883. case MTIOCGET32:
  884. kcmd = MTIOCGET;
  885. karg = &get;
  886. break;
  887. default:
  888. do {
  889. static int count;
  890. if (++count <= 20)
  891. printk("mt_ioctl: Unknown cmd fd(%d) "
  892. "cmd(%08x) arg(%08x)\n",
  893. (int)fd, (unsigned int)cmd, (unsigned int)arg);
  894. } while(0);
  895. return -EINVAL;
  896. }
  897. set_fs (KERNEL_DS);
  898. err = sys_ioctl (fd, kcmd, (unsigned long)karg);
  899. set_fs (old_fs);
  900. if (err)
  901. return err;
  902. switch (cmd) {
  903. case MTIOCPOS32:
  904. upos32 = compat_ptr(arg);
  905. err = __put_user(pos.mt_blkno, &upos32->mt_blkno);
  906. break;
  907. case MTIOCGET32:
  908. umget32 = compat_ptr(arg);
  909. err = __put_user(get.mt_type, &umget32->mt_type);
  910. err |= __put_user(get.mt_resid, &umget32->mt_resid);
  911. err |= __put_user(get.mt_dsreg, &umget32->mt_dsreg);
  912. err |= __put_user(get.mt_gstat, &umget32->mt_gstat);
  913. err |= __put_user(get.mt_erreg, &umget32->mt_erreg);
  914. err |= __put_user(get.mt_fileno, &umget32->mt_fileno);
  915. err |= __put_user(get.mt_blkno, &umget32->mt_blkno);
  916. break;
  917. }
  918. return err ? -EFAULT: 0;
  919. }
  920. struct cdrom_read_audio32 {
  921. union cdrom_addr addr;
  922. u8 addr_format;
  923. compat_int_t nframes;
  924. compat_caddr_t buf;
  925. };
  926. struct cdrom_generic_command32 {
  927. unsigned char cmd[CDROM_PACKET_SIZE];
  928. compat_caddr_t buffer;
  929. compat_uint_t buflen;
  930. compat_int_t stat;
  931. compat_caddr_t sense;
  932. unsigned char data_direction;
  933. compat_int_t quiet;
  934. compat_int_t timeout;
  935. compat_caddr_t reserved[1];
  936. };
  937. static int cdrom_do_read_audio(unsigned int fd, unsigned int cmd, unsigned long arg)
  938. {
  939. struct cdrom_read_audio __user *cdread_audio;
  940. struct cdrom_read_audio32 __user *cdread_audio32;
  941. __u32 data;
  942. void __user *datap;
  943. cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio));
  944. cdread_audio32 = compat_ptr(arg);
  945. if (copy_in_user(&cdread_audio->addr,
  946. &cdread_audio32->addr,
  947. (sizeof(*cdread_audio32) -
  948. sizeof(compat_caddr_t))))
  949. return -EFAULT;
  950. if (get_user(data, &cdread_audio32->buf))
  951. return -EFAULT;
  952. datap = compat_ptr(data);
  953. if (put_user(datap, &cdread_audio->buf))
  954. return -EFAULT;
  955. return sys_ioctl(fd, cmd, (unsigned long) cdread_audio);
  956. }
  957. static int cdrom_do_generic_command(unsigned int fd, unsigned int cmd, unsigned long arg)
  958. {
  959. struct cdrom_generic_command __user *cgc;
  960. struct cdrom_generic_command32 __user *cgc32;
  961. u32 data;
  962. unsigned char dir;
  963. int itmp;
  964. cgc = compat_alloc_user_space(sizeof(*cgc));
  965. cgc32 = compat_ptr(arg);
  966. if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
  967. get_user(data, &cgc32->buffer) ||
  968. put_user(compat_ptr(data), &cgc->buffer) ||
  969. copy_in_user(&cgc->buflen, &cgc32->buflen,
  970. (sizeof(unsigned int) + sizeof(int))) ||
  971. get_user(data, &cgc32->sense) ||
  972. put_user(compat_ptr(data), &cgc->sense) ||
  973. get_user(dir, &cgc32->data_direction) ||
  974. put_user(dir, &cgc->data_direction) ||
  975. get_user(itmp, &cgc32->quiet) ||
  976. put_user(itmp, &cgc->quiet) ||
  977. get_user(itmp, &cgc32->timeout) ||
  978. put_user(itmp, &cgc->timeout) ||
  979. get_user(data, &cgc32->reserved[0]) ||
  980. put_user(compat_ptr(data), &cgc->reserved[0]))
  981. return -EFAULT;
  982. return sys_ioctl(fd, cmd, (unsigned long) cgc);
  983. }
  984. static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  985. {
  986. int err;
  987. switch(cmd) {
  988. case CDROMREADAUDIO:
  989. err = cdrom_do_read_audio(fd, cmd, arg);
  990. break;
  991. case CDROM_SEND_PACKET:
  992. err = cdrom_do_generic_command(fd, cmd, arg);
  993. break;
  994. default:
  995. do {
  996. static int count;
  997. if (++count <= 20)
  998. printk("cdrom_ioctl: Unknown cmd fd(%d) "
  999. "cmd(%08x) arg(%08x)\n",
  1000. (int)fd, (unsigned int)cmd, (unsigned int)arg);
  1001. } while(0);
  1002. err = -EINVAL;
  1003. break;
  1004. };
  1005. return err;
  1006. }
  1007. #endif /* CONFIG_BLOCK */
  1008. #ifdef CONFIG_VT
  1009. static int vt_check(struct file *file)
  1010. {
  1011. struct tty_struct *tty;
  1012. struct inode *inode = file->f_dentry->d_inode;
  1013. if (file->f_op->ioctl != tty_ioctl)
  1014. return -EINVAL;
  1015. tty = (struct tty_struct *)file->private_data;
  1016. if (tty_paranoia_check(tty, inode, "tty_ioctl"))
  1017. return -EINVAL;
  1018. if (tty->driver->ioctl != vt_ioctl)
  1019. return -EINVAL;
  1020. /*
  1021. * To have permissions to do most of the vt ioctls, we either have
  1022. * to be the owner of the tty, or super-user.
  1023. */
  1024. if (current->signal->tty == tty || capable(CAP_SYS_ADMIN))
  1025. return 1;
  1026. return 0;
  1027. }
  1028. struct consolefontdesc32 {
  1029. unsigned short charcount; /* characters in font (256 or 512) */
  1030. unsigned short charheight; /* scan lines per character (1-32) */
  1031. compat_caddr_t chardata; /* font data in expanded form */
  1032. };
  1033. static int do_fontx_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
  1034. {
  1035. struct consolefontdesc32 __user *user_cfd = compat_ptr(arg);
  1036. struct console_font_op op;
  1037. compat_caddr_t data;
  1038. int i, perm;
  1039. perm = vt_check(file);
  1040. if (perm < 0) return perm;
  1041. switch (cmd) {
  1042. case PIO_FONTX:
  1043. if (!perm)
  1044. return -EPERM;
  1045. op.op = KD_FONT_OP_SET;
  1046. op.flags = 0;
  1047. op.width = 8;
  1048. if (get_user(op.height, &user_cfd->charheight) ||
  1049. get_user(op.charcount, &user_cfd->charcount) ||
  1050. get_user(data, &user_cfd->chardata))
  1051. return -EFAULT;
  1052. op.data = compat_ptr(data);
  1053. return con_font_op(vc_cons[fg_console].d, &op);
  1054. case GIO_FONTX:
  1055. op.op = KD_FONT_OP_GET;
  1056. op.flags = 0;
  1057. op.width = 8;
  1058. if (get_user(op.height, &user_cfd->charheight) ||
  1059. get_user(op.charcount, &user_cfd->charcount) ||
  1060. get_user(data, &user_cfd->chardata))
  1061. return -EFAULT;
  1062. if (!data)
  1063. return 0;
  1064. op.data = compat_ptr(data);
  1065. i = con_font_op(vc_cons[fg_console].d, &op);
  1066. if (i)
  1067. return i;
  1068. if (put_user(op.height, &user_cfd->charheight) ||
  1069. put_user(op.charcount, &user_cfd->charcount) ||
  1070. put_user((compat_caddr_t)(unsigned long)op.data,
  1071. &user_cfd->chardata))
  1072. return -EFAULT;
  1073. return 0;
  1074. }
  1075. return -EINVAL;
  1076. }
  1077. struct console_font_op32 {
  1078. compat_uint_t op; /* operation code KD_FONT_OP_* */
  1079. compat_uint_t flags; /* KD_FONT_FLAG_* */
  1080. compat_uint_t width, height; /* font size */
  1081. compat_uint_t charcount;
  1082. compat_caddr_t data; /* font data with height fixed to 32 */
  1083. };
  1084. static int do_kdfontop_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
  1085. {
  1086. struct console_font_op op;
  1087. struct console_font_op32 __user *fontop = compat_ptr(arg);
  1088. int perm = vt_check(file), i;
  1089. struct vc_data *vc;
  1090. if (perm < 0) return perm;
  1091. if (copy_from_user(&op, fontop, sizeof(struct console_font_op32)))
  1092. return -EFAULT;
  1093. if (!perm && op.op != KD_FONT_OP_GET)
  1094. return -EPERM;
  1095. op.data = compat_ptr(((struct console_font_op32 *)&op)->data);
  1096. op.flags |= KD_FONT_FLAG_OLD;
  1097. vc = ((struct tty_struct *)file->private_data)->driver_data;
  1098. i = con_font_op(vc, &op);
  1099. if (i)
  1100. return i;
  1101. ((struct console_font_op32 *)&op)->data = (unsigned long)op.data;
  1102. if (copy_to_user(fontop, &op, sizeof(struct console_font_op32)))
  1103. return -EFAULT;
  1104. return 0;
  1105. }
  1106. struct unimapdesc32 {
  1107. unsigned short entry_ct;
  1108. compat_caddr_t entries;
  1109. };
  1110. static int do_unimap_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg, struct file *file)
  1111. {
  1112. struct unimapdesc32 tmp;
  1113. struct unimapdesc32 __user *user_ud = compat_ptr(arg);
  1114. int perm = vt_check(file);
  1115. if (perm < 0) return perm;
  1116. if (copy_from_user(&tmp, user_ud, sizeof tmp))
  1117. return -EFAULT;
  1118. switch (cmd) {
  1119. case PIO_UNIMAP:
  1120. if (!perm) return -EPERM;
  1121. return con_set_unimap(vc_cons[fg_console].d, tmp.entry_ct, compat_ptr(tmp.entries));
  1122. case GIO_UNIMAP:
  1123. return con_get_unimap(vc_cons[fg_console].d, tmp.entry_ct, &(user_ud->entry_ct), compat_ptr(tmp.entries));
  1124. }
  1125. return 0;
  1126. }
  1127. #endif /* CONFIG_VT */
  1128. static int do_smb_getmountuid(unsigned int fd, unsigned int cmd, unsigned long arg)
  1129. {
  1130. mm_segment_t old_fs = get_fs();
  1131. __kernel_uid_t kuid;
  1132. int err;
  1133. cmd = SMB_IOC_GETMOUNTUID;
  1134. set_fs(KERNEL_DS);
  1135. err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
  1136. set_fs(old_fs);
  1137. if (err >= 0)
  1138. err = put_user(kuid, (compat_uid_t __user *)compat_ptr(arg));
  1139. return err;
  1140. }
  1141. struct atmif_sioc32 {
  1142. compat_int_t number;
  1143. compat_int_t length;
  1144. compat_caddr_t arg;
  1145. };
  1146. struct atm_iobuf32 {
  1147. compat_int_t length;
  1148. compat_caddr_t buffer;
  1149. };
  1150. #define ATM_GETLINKRATE32 _IOW('a', ATMIOC_ITF+1, struct atmif_sioc32)
  1151. #define ATM_GETNAMES32 _IOW('a', ATMIOC_ITF+3, struct atm_iobuf32)
  1152. #define ATM_GETTYPE32 _IOW('a', ATMIOC_ITF+4, struct atmif_sioc32)
  1153. #define ATM_GETESI32 _IOW('a', ATMIOC_ITF+5, struct atmif_sioc32)
  1154. #define ATM_GETADDR32 _IOW('a', ATMIOC_ITF+6, struct atmif_sioc32)
  1155. #define ATM_RSTADDR32 _IOW('a', ATMIOC_ITF+7, struct atmif_sioc32)
  1156. #define ATM_ADDADDR32 _IOW('a', ATMIOC_ITF+8, struct atmif_sioc32)
  1157. #define ATM_DELADDR32 _IOW('a', ATMIOC_ITF+9, struct atmif_sioc32)
  1158. #define ATM_GETCIRANGE32 _IOW('a', ATMIOC_ITF+10, struct atmif_sioc32)
  1159. #define ATM_SETCIRANGE32 _IOW('a', ATMIOC_ITF+11, struct atmif_sioc32)
  1160. #define ATM_SETESI32 _IOW('a', ATMIOC_ITF+12, struct atmif_sioc32)
  1161. #define ATM_SETESIF32 _IOW('a', ATMIOC_ITF+13, struct atmif_sioc32)
  1162. #define ATM_GETSTAT32 _IOW('a', ATMIOC_SARCOM+0, struct atmif_sioc32)
  1163. #define ATM_GETSTATZ32 _IOW('a', ATMIOC_SARCOM+1, struct atmif_sioc32)
  1164. #define ATM_GETLOOP32 _IOW('a', ATMIOC_SARCOM+2, struct atmif_sioc32)
  1165. #define ATM_SETLOOP32 _IOW('a', ATMIOC_SARCOM+3, struct atmif_sioc32)
  1166. #define ATM_QUERYLOOP32 _IOW('a', ATMIOC_SARCOM+4, struct atmif_sioc32)
  1167. static struct {
  1168. unsigned int cmd32;
  1169. unsigned int cmd;
  1170. } atm_ioctl_map[] = {
  1171. { ATM_GETLINKRATE32, ATM_GETLINKRATE },
  1172. { ATM_GETNAMES32, ATM_GETNAMES },
  1173. { ATM_GETTYPE32, ATM_GETTYPE },
  1174. { ATM_GETESI32, ATM_GETESI },
  1175. { ATM_GETADDR32, ATM_GETADDR },
  1176. { ATM_RSTADDR32, ATM_RSTADDR },
  1177. { ATM_ADDADDR32, ATM_ADDADDR },
  1178. { ATM_DELADDR32, ATM_DELADDR },
  1179. { ATM_GETCIRANGE32, ATM_GETCIRANGE },
  1180. { ATM_SETCIRANGE32, ATM_SETCIRANGE },
  1181. { ATM_SETESI32, ATM_SETESI },
  1182. { ATM_SETESIF32, ATM_SETESIF },
  1183. { ATM_GETSTAT32, ATM_GETSTAT },
  1184. { ATM_GETSTATZ32, ATM_GETSTATZ },
  1185. { ATM_GETLOOP32, ATM_GETLOOP },
  1186. { ATM_SETLOOP32, ATM_SETLOOP },
  1187. { ATM_QUERYLOOP32, ATM_QUERYLOOP }
  1188. };
  1189. #define NR_ATM_IOCTL ARRAY_SIZE(atm_ioctl_map)
  1190. static int do_atm_iobuf(unsigned int fd, unsigned int cmd, unsigned long arg)
  1191. {
  1192. struct atm_iobuf __user *iobuf;
  1193. struct atm_iobuf32 __user *iobuf32;
  1194. u32 data;
  1195. void __user *datap;
  1196. int len, err;
  1197. iobuf = compat_alloc_user_space(sizeof(*iobuf));
  1198. iobuf32 = compat_ptr(arg);
  1199. if (get_user(len, &iobuf32->length) ||
  1200. get_user(data, &iobuf32->buffer))
  1201. return -EFAULT;
  1202. datap = compat_ptr(data);
  1203. if (put_user(len, &iobuf->length) ||
  1204. put_user(datap, &iobuf->buffer))
  1205. return -EFAULT;
  1206. err = sys_ioctl(fd, cmd, (unsigned long)iobuf);
  1207. if (!err) {
  1208. if (copy_in_user(&iobuf32->length, &iobuf->length,
  1209. sizeof(int)))
  1210. err = -EFAULT;
  1211. }
  1212. return err;
  1213. }
  1214. static int do_atmif_sioc(unsigned int fd, unsigned int cmd, unsigned long arg)
  1215. {
  1216. struct atmif_sioc __user *sioc;
  1217. struct atmif_sioc32 __user *sioc32;
  1218. u32 data;
  1219. void __user *datap;
  1220. int err;
  1221. sioc = compat_alloc_user_space(sizeof(*sioc));
  1222. sioc32 = compat_ptr(arg);
  1223. if (copy_in_user(&sioc->number, &sioc32->number, 2 * sizeof(int)) ||
  1224. get_user(data, &sioc32->arg))
  1225. return -EFAULT;
  1226. datap = compat_ptr(data);
  1227. if (put_user(datap, &sioc->arg))
  1228. return -EFAULT;
  1229. err = sys_ioctl(fd, cmd, (unsigned long) sioc);
  1230. if (!err) {
  1231. if (copy_in_user(&sioc32->length, &sioc->length,
  1232. sizeof(int)))
  1233. err = -EFAULT;
  1234. }
  1235. return err;
  1236. }
  1237. static int do_atm_ioctl(unsigned int fd, unsigned int cmd32, unsigned long arg)
  1238. {
  1239. int i;
  1240. unsigned int cmd = 0;
  1241. switch (cmd32) {
  1242. case SONET_GETSTAT:
  1243. case SONET_GETSTATZ:
  1244. case SONET_GETDIAG:
  1245. case SONET_SETDIAG:
  1246. case SONET_CLRDIAG:
  1247. case SONET_SETFRAMING:
  1248. case SONET_GETFRAMING:
  1249. case SONET_GETFRSENSE:
  1250. return do_atmif_sioc(fd, cmd32, arg);
  1251. }
  1252. for (i = 0; i < NR_ATM_IOCTL; i++) {
  1253. if (cmd32 == atm_ioctl_map[i].cmd32) {
  1254. cmd = atm_ioctl_map[i].cmd;
  1255. break;
  1256. }
  1257. }
  1258. if (i == NR_ATM_IOCTL)
  1259. return -EINVAL;
  1260. switch (cmd) {
  1261. case ATM_GETNAMES:
  1262. return do_atm_iobuf(fd, cmd, arg);
  1263. case ATM_GETLINKRATE:
  1264. case ATM_GETTYPE:
  1265. case ATM_GETESI:
  1266. case ATM_GETADDR:
  1267. case ATM_RSTADDR:
  1268. case ATM_ADDADDR:
  1269. case ATM_DELADDR:
  1270. case ATM_GETCIRANGE:
  1271. case ATM_SETCIRANGE:
  1272. case ATM_SETESI:
  1273. case ATM_SETESIF:
  1274. case ATM_GETSTAT:
  1275. case ATM_GETSTATZ:
  1276. case ATM_GETLOOP:
  1277. case ATM_SETLOOP:
  1278. case ATM_QUERYLOOP:
  1279. return do_atmif_sioc(fd, cmd, arg);
  1280. }
  1281. return -EINVAL;
  1282. }
  1283. static __attribute_used__ int
  1284. ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
  1285. {
  1286. return -EINVAL;
  1287. }
  1288. #ifdef CONFIG_BLOCK
  1289. static int broken_blkgetsize(unsigned int fd, unsigned int cmd, unsigned long arg)
  1290. {
  1291. /* The mkswap binary hard codes it to Intel value :-((( */
  1292. return w_long(fd, BLKGETSIZE, arg);
  1293. }
  1294. struct blkpg_ioctl_arg32 {
  1295. compat_int_t op;
  1296. compat_int_t flags;
  1297. compat_int_t datalen;
  1298. compat_caddr_t data;
  1299. };
  1300. static int blkpg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  1301. {
  1302. struct blkpg_ioctl_arg32 __user *ua32 = compat_ptr(arg);
  1303. struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
  1304. compat_caddr_t udata;
  1305. compat_int_t n;
  1306. int err;
  1307. err = get_user(n, &ua32->op);
  1308. err |= put_user(n, &a->op);
  1309. err |= get_user(n, &ua32->flags);
  1310. err |= put_user(n, &a->flags);
  1311. err |= get_user(n, &ua32->datalen);
  1312. err |= put_user(n, &a->datalen);
  1313. err |= get_user(udata, &ua32->data);
  1314. err |= put_user(compat_ptr(udata), &a->data);
  1315. if (err)
  1316. return err;
  1317. return sys_ioctl(fd, cmd, (unsigned long)a);
  1318. }
  1319. #endif
  1320. static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
  1321. {
  1322. return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
  1323. }
  1324. #ifdef CONFIG_BLOCK
  1325. /* Fix sizeof(sizeof()) breakage */
  1326. #define BLKBSZGET_32 _IOR(0x12,112,int)
  1327. #define BLKBSZSET_32 _IOW(0x12,113,int)
  1328. #define BLKGETSIZE64_32 _IOR(0x12,114,int)
  1329. static int do_blkbszget(unsigned int fd, unsigned int cmd, unsigned long arg)
  1330. {
  1331. return sys_ioctl(fd, BLKBSZGET, (unsigned long)compat_ptr(arg));
  1332. }
  1333. static int do_blkbszset(unsigned int fd, unsigned int cmd, unsigned long arg)
  1334. {
  1335. return sys_ioctl(fd, BLKBSZSET, (unsigned long)compat_ptr(arg));
  1336. }
  1337. static int do_blkgetsize64(unsigned int fd, unsigned int cmd,
  1338. unsigned long arg)
  1339. {
  1340. return sys_ioctl(fd, BLKGETSIZE64, (unsigned long)compat_ptr(arg));
  1341. }
  1342. #endif
  1343. /* Bluetooth ioctls */
  1344. #define HCIUARTSETPROTO _IOW('U', 200, int)
  1345. #define HCIUARTGETPROTO _IOR('U', 201, int)
  1346. #define BNEPCONNADD _IOW('B', 200, int)
  1347. #define BNEPCONNDEL _IOW('B', 201, int)
  1348. #define BNEPGETCONNLIST _IOR('B', 210, int)
  1349. #define BNEPGETCONNINFO _IOR('B', 211, int)
  1350. #define CMTPCONNADD _IOW('C', 200, int)
  1351. #define CMTPCONNDEL _IOW('C', 201, int)
  1352. #define CMTPGETCONNLIST _IOR('C', 210, int)
  1353. #define CMTPGETCONNINFO _IOR('C', 211, int)
  1354. #define HIDPCONNADD _IOW('H', 200, int)
  1355. #define HIDPCONNDEL _IOW('H', 201, int)
  1356. #define HIDPGETCONNLIST _IOR('H', 210, int)
  1357. #define HIDPGETCONNINFO _IOR('H', 211, int)
  1358. #ifdef CONFIG_BLOCK
  1359. struct floppy_struct32 {
  1360. compat_uint_t size;
  1361. compat_uint_t sect;
  1362. compat_uint_t head;
  1363. compat_uint_t track;
  1364. compat_uint_t stretch;
  1365. unsigned char gap;
  1366. unsigned char rate;
  1367. unsigned char spec1;
  1368. unsigned char fmt_gap;
  1369. const compat_caddr_t name;
  1370. };
  1371. struct floppy_drive_params32 {
  1372. char cmos;
  1373. compat_ulong_t max_dtr;
  1374. compat_ulong_t hlt;
  1375. compat_ulong_t hut;
  1376. compat_ulong_t srt;
  1377. compat_ulong_t spinup;
  1378. compat_ulong_t spindown;
  1379. unsigned char spindown_offset;
  1380. unsigned char select_delay;
  1381. unsigned char rps;
  1382. unsigned char tracks;
  1383. compat_ulong_t timeout;
  1384. unsigned char interleave_sect;
  1385. struct floppy_max_errors max_errors;
  1386. char flags;
  1387. char read_track;
  1388. short autodetect[8];
  1389. compat_int_t checkfreq;
  1390. compat_int_t native_format;
  1391. };
  1392. struct floppy_drive_struct32 {
  1393. signed char flags;
  1394. compat_ulong_t spinup_date;
  1395. compat_ulong_t select_date;
  1396. compat_ulong_t first_read_date;
  1397. short probed_format;
  1398. short track;
  1399. short maxblock;
  1400. short maxtrack;
  1401. compat_int_t generation;
  1402. compat_int_t keep_data;
  1403. compat_int_t fd_ref;
  1404. compat_int_t fd_device;
  1405. compat_int_t last_checked;
  1406. compat_caddr_t dmabuf;
  1407. compat_int_t bufblocks;
  1408. };
  1409. struct floppy_fdc_state32 {
  1410. compat_int_t spec1;
  1411. compat_int_t spec2;
  1412. compat_int_t dtr;
  1413. unsigned char version;
  1414. unsigned char dor;
  1415. compat_ulong_t address;
  1416. unsigned int rawcmd:2;
  1417. unsigned int reset:1;
  1418. unsigned int need_configure:1;
  1419. unsigned int perp_mode:2;
  1420. unsigned int has_fifo:1;
  1421. unsigned int driver_version;
  1422. unsigned char track[4];
  1423. };
  1424. struct floppy_write_errors32 {
  1425. unsigned int write_errors;
  1426. compat_ulong_t first_error_sector;
  1427. compat_int_t first_error_generation;
  1428. compat_ulong_t last_error_sector;
  1429. compat_int_t last_error_generation;
  1430. compat_uint_t badness;
  1431. };
  1432. #define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32)
  1433. #define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32)
  1434. #define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32)
  1435. #define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32)
  1436. #define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32)
  1437. #define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32)
  1438. #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32)
  1439. #define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32)
  1440. #define FDWERRORGET32 _IOR(2, 0x17, struct floppy_write_errors32)
  1441. static struct {
  1442. unsigned int cmd32;
  1443. unsigned int cmd;
  1444. } fd_ioctl_trans_table[] = {
  1445. { FDSETPRM32, FDSETPRM },
  1446. { FDDEFPRM32, FDDEFPRM },
  1447. { FDGETPRM32, FDGETPRM },
  1448. { FDSETDRVPRM32, FDSETDRVPRM },
  1449. { FDGETDRVPRM32, FDGETDRVPRM },
  1450. { FDGETDRVSTAT32, FDGETDRVSTAT },
  1451. { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
  1452. { FDGETFDCSTAT32, FDGETFDCSTAT },
  1453. { FDWERRORGET32, FDWERRORGET }
  1454. };
  1455. #define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table)
  1456. static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  1457. {
  1458. mm_segment_t old_fs = get_fs();
  1459. void *karg = NULL;
  1460. unsigned int kcmd = 0;
  1461. int i, err;
  1462. for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
  1463. if (cmd == fd_ioctl_trans_table[i].cmd32) {
  1464. kcmd = fd_ioctl_trans_table[i].cmd;
  1465. break;
  1466. }
  1467. if (!kcmd)
  1468. return -EINVAL;
  1469. switch (cmd) {
  1470. case FDSETPRM32:
  1471. case FDDEFPRM32:
  1472. case FDGETPRM32:
  1473. {
  1474. compat_uptr_t name;
  1475. struct floppy_struct32 __user *uf;
  1476. struct floppy_struct *f;
  1477. uf = compat_ptr(arg);
  1478. f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
  1479. if (!karg)
  1480. return -ENOMEM;
  1481. if (cmd == FDGETPRM32)
  1482. break;
  1483. err = __get_user(f->size, &uf->size);
  1484. err |= __get_user(f->sect, &uf->sect);
  1485. err |= __get_user(f->head, &uf->head);
  1486. err |= __get_user(f->track, &uf->track);
  1487. err |= __get_user(f->stretch, &uf->stretch);
  1488. err |= __get_user(f->gap, &uf->gap);
  1489. err |= __get_user(f->rate, &uf->rate);
  1490. err |= __get_user(f->spec1, &uf->spec1);
  1491. err |= __get_user(f->fmt_gap, &uf->fmt_gap);
  1492. err |= __get_user(name, &uf->name);
  1493. f->name = compat_ptr(name);
  1494. if (err) {
  1495. err = -EFAULT;
  1496. goto out;
  1497. }
  1498. break;
  1499. }
  1500. case FDSETDRVPRM32:
  1501. case FDGETDRVPRM32:
  1502. {
  1503. struct floppy_drive_params32 __user *uf;
  1504. struct floppy_drive_params *f;
  1505. uf = compat_ptr(arg);
  1506. f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
  1507. if (!karg)
  1508. return -ENOMEM;
  1509. if (cmd == FDGETDRVPRM32)
  1510. break;
  1511. err = __get_user(f->cmos, &uf->cmos);
  1512. err |= __get_user(f->max_dtr, &uf->max_dtr);
  1513. err |= __get_user(f->hlt, &uf->hlt);
  1514. err |= __get_user(f->hut, &uf->hut);
  1515. err |= __get_user(f->srt, &uf->srt);
  1516. err |= __get_user(f->spinup, &uf->spinup);
  1517. err |= __get_user(f->spindown, &uf->spindown);
  1518. err |= __get_user(f->spindown_offset, &uf->spindown_offset);
  1519. err |= __get_user(f->select_delay, &uf->select_delay);
  1520. err |= __get_user(f->rps, &uf->rps);
  1521. err |= __get_user(f->tracks, &uf->tracks);
  1522. err |= __get_user(f->timeout, &uf->timeout);
  1523. err |= __get_user(f->interleave_sect, &uf->interleave_sect);
  1524. err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors));
  1525. err |= __get_user(f->flags, &uf->flags);
  1526. err |= __get_user(f->read_track, &uf->read_track);
  1527. err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect));
  1528. err |= __get_user(f->checkfreq, &uf->checkfreq);
  1529. err |= __get_user(f->native_format, &uf->native_format);
  1530. if (err) {
  1531. err = -EFAULT;
  1532. goto out;
  1533. }
  1534. break;
  1535. }
  1536. case FDGETDRVSTAT32:
  1537. case FDPOLLDRVSTAT32:
  1538. karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
  1539. if (!karg)
  1540. return -ENOMEM;
  1541. break;
  1542. case FDGETFDCSTAT32:
  1543. karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
  1544. if (!karg)
  1545. return -ENOMEM;
  1546. break;
  1547. case FDWERRORGET32:
  1548. karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
  1549. if (!karg)
  1550. return -ENOMEM;
  1551. break;
  1552. default:
  1553. return -EINVAL;
  1554. }
  1555. set_fs (KERNEL_DS);
  1556. err = sys_ioctl (fd, kcmd, (unsigned long)karg);
  1557. set_fs (old_fs);
  1558. if (err)
  1559. goto out;
  1560. switch (cmd) {
  1561. case FDGETPRM32:
  1562. {
  1563. struct floppy_struct *f = karg;
  1564. struct floppy_struct32 __user *uf = compat_ptr(arg);
  1565. err = __put_user(f->size, &uf->size);
  1566. err |= __put_user(f->sect, &uf->sect);
  1567. err |= __put_user(f->head, &uf->head);
  1568. err |= __put_user(f->track, &uf->track);
  1569. err |= __put_user(f->stretch, &uf->stretch);
  1570. err |= __put_user(f->gap, &uf->gap);
  1571. err |= __put_user(f->rate, &uf->rate);
  1572. err |= __put_user(f->spec1, &uf->spec1);
  1573. err |= __put_user(f->fmt_gap, &uf->fmt_gap);
  1574. err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name);
  1575. break;
  1576. }
  1577. case FDGETDRVPRM32:
  1578. {
  1579. struct floppy_drive_params32 __user *uf;
  1580. struct floppy_drive_params *f = karg;
  1581. uf = compat_ptr(arg);
  1582. err = __put_user(f->cmos, &uf->cmos);
  1583. err |= __put_user(f->max_dtr, &uf->max_dtr);
  1584. err |= __put_user(f->hlt, &uf->hlt);
  1585. err |= __put_user(f->hut, &uf->hut);
  1586. err |= __put_user(f->srt, &uf->srt);
  1587. err |= __put_user(f->spinup, &uf->spinup);
  1588. err |= __put_user(f->spindown, &uf->spindown);
  1589. err |= __put_user(f->spindown_offset, &uf->spindown_offset);
  1590. err |= __put_user(f->select_delay, &uf->select_delay);
  1591. err |= __put_user(f->rps, &uf->rps);
  1592. err |= __put_user(f->tracks, &uf->tracks);
  1593. err |= __put_user(f->timeout, &uf->timeout);
  1594. err |= __put_user(f->interleave_sect, &uf->interleave_sect);
  1595. err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors));
  1596. err |= __put_user(f->flags, &uf->flags);
  1597. err |= __put_user(f->read_track, &uf->read_track);
  1598. err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect));
  1599. err |= __put_user(f->checkfreq, &uf->checkfreq);
  1600. err |= __put_user(f->native_format, &uf->native_format);
  1601. break;
  1602. }
  1603. case FDGETDRVSTAT32:
  1604. case FDPOLLDRVSTAT32:
  1605. {
  1606. struct floppy_drive_struct32 __user *uf;
  1607. struct floppy_drive_struct *f = karg;
  1608. uf = compat_ptr(arg);
  1609. err = __put_user(f->flags, &uf->flags);
  1610. err |= __put_user(f->spinup_date, &uf->spinup_date);
  1611. err |= __put_user(f->select_date, &uf->select_date);
  1612. err |= __put_user(f->first_read_date, &uf->first_read_date);
  1613. err |= __put_user(f->probed_format, &uf->probed_format);
  1614. err |= __put_user(f->track, &uf->track);
  1615. err |= __put_user(f->maxblock, &uf->maxblock);
  1616. err |= __put_user(f->maxtrack, &uf->maxtrack);
  1617. err |= __put_user(f->generation, &uf->generation);
  1618. err |= __put_user(f->keep_data, &uf->keep_data);
  1619. err |= __put_user(f->fd_ref, &uf->fd_ref);
  1620. err |= __put_user(f->fd_device, &uf->fd_device);
  1621. err |= __put_user(f->last_checked, &uf->last_checked);
  1622. err |= __put_user((u64)f->dmabuf, &uf->dmabuf);
  1623. err |= __put_user((u64)f->bufblocks, &uf->bufblocks);
  1624. break;
  1625. }
  1626. case FDGETFDCSTAT32:
  1627. {
  1628. struct floppy_fdc_state32 __user *uf;
  1629. struct floppy_fdc_state *f = karg;
  1630. uf = compat_ptr(arg);
  1631. err = __put_user(f->spec1, &uf->spec1);
  1632. err |= __put_user(f->spec2, &uf->spec2);
  1633. err |= __put_user(f->dtr, &uf->dtr);
  1634. err |= __put_user(f->version, &uf->version);
  1635. err |= __put_user(f->dor, &uf->dor);
  1636. err |= __put_user(f->address, &uf->address);
  1637. err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address),
  1638. (char *)&f->address + sizeof(f->address), sizeof(int));
  1639. err |= __put_user(f->driver_version, &uf->driver_version);
  1640. err |= __copy_to_user(uf->track, f->track, sizeof(f->track));
  1641. break;
  1642. }
  1643. case FDWERRORGET32:
  1644. {
  1645. struct floppy_write_errors32 __user *uf;
  1646. struct floppy_write_errors *f = karg;
  1647. uf = compat_ptr(arg);
  1648. err = __put_user(f->write_errors, &uf->write_errors);
  1649. err |= __put_user(f->first_error_sector, &uf->first_error_sector);
  1650. err |= __put_user(f->first_error_generation, &uf->first_error_generation);
  1651. err |= __put_user(f->last_error_sector, &uf->last_error_sector);
  1652. err |= __put_user(f->last_error_generation, &uf->last_error_generation);
  1653. err |= __put_user(f->badness, &uf->badness);
  1654. break;
  1655. }
  1656. default:
  1657. break;
  1658. }
  1659. if (err)
  1660. err = -EFAULT;
  1661. out:
  1662. kfree(karg);
  1663. return err;
  1664. }
  1665. #endif
  1666. struct mtd_oob_buf32 {
  1667. u_int32_t start;
  1668. u_int32_t length;
  1669. compat_caddr_t ptr; /* unsigned char* */
  1670. };
  1671. #define MEMWRITEOOB32 _IOWR('M',3,struct mtd_oob_buf32)
  1672. #define MEMREADOOB32 _IOWR('M',4,struct mtd_oob_buf32)
  1673. static int mtd_rw_oob(unsigned int fd, unsigned int cmd, unsigned long arg)
  1674. {
  1675. struct mtd_oob_buf __user *buf = compat_alloc_user_space(sizeof(*buf));
  1676. struct mtd_oob_buf32 __user *buf32 = compat_ptr(arg);
  1677. u32 data;
  1678. char __user *datap;
  1679. unsigned int real_cmd;
  1680. int err;
  1681. real_cmd = (cmd == MEMREADOOB32) ?
  1682. MEMREADOOB : MEMWRITEOOB;
  1683. if (copy_in_user(&buf->start, &buf32->start,
  1684. 2 * sizeof(u32)) ||
  1685. get_user(data, &buf32->ptr))
  1686. return -EFAULT;
  1687. datap = compat_ptr(data);
  1688. if (put_user(datap, &buf->ptr))
  1689. return -EFAULT;
  1690. err = sys_ioctl(fd, real_cmd, (unsigned long) buf);
  1691. if (!err) {
  1692. if (copy_in_user(&buf32->start, &buf->start,
  1693. 2 * sizeof(u32)))
  1694. err = -EFAULT;
  1695. }
  1696. return err;
  1697. }
  1698. #ifdef CONFIG_BLOCK
  1699. struct raw32_config_request
  1700. {
  1701. compat_int_t raw_minor;
  1702. __u64 block_major;
  1703. __u64 block_minor;
  1704. } __attribute__((packed));
  1705. static int get_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
  1706. {
  1707. int ret;
  1708. if (!access_ok(VERIFY_READ, user_req, sizeof(struct raw32_config_request)))
  1709. return -EFAULT;
  1710. ret = __get_user(req->raw_minor, &user_req->raw_minor);
  1711. ret |= __get_user(req->block_major, &user_req->block_major);
  1712. ret |= __get_user(req->block_minor, &user_req->block_minor);
  1713. return ret ? -EFAULT : 0;
  1714. }
  1715. static int set_raw32_request(struct raw_config_request *req, struct raw32_config_request __user *user_req)
  1716. {
  1717. int ret;
  1718. if (!access_ok(VERIFY_WRITE, user_req, sizeof(struct raw32_config_request)))
  1719. return -EFAULT;
  1720. ret = __put_user(req->raw_minor, &user_req->raw_minor);
  1721. ret |= __put_user(req->block_major, &user_req->block_major);
  1722. ret |= __put_user(req->block_minor, &user_req->block_minor);
  1723. return ret ? -EFAULT : 0;
  1724. }
  1725. static int raw_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
  1726. {
  1727. int ret;
  1728. switch (cmd) {
  1729. case RAW_SETBIND:
  1730. case RAW_GETBIND: {
  1731. struct raw_config_request req;
  1732. struct raw32_config_request __user *user_req = compat_ptr(arg);
  1733. mm_segment_t oldfs = get_fs();
  1734. if ((ret = get_raw32_request(&req, user_req)))
  1735. return ret;
  1736. set_fs(KERNEL_DS);
  1737. ret = sys_ioctl(fd,cmd,(unsigned long)&req);
  1738. set_fs(oldfs);
  1739. if ((!ret) && (cmd == RAW_GETBIND)) {
  1740. ret = set_raw32_request(&req, user_req);
  1741. }
  1742. break;
  1743. }
  1744. default:
  1745. ret = sys_ioctl(fd, cmd, arg);
  1746. break;
  1747. }
  1748. return ret;
  1749. }
  1750. #endif /* CONFIG_BLOCK */
  1751. struct serial_struct32 {
  1752. compat_int_t type;
  1753. compat_int_t line;
  1754. compat_uint_t port;
  1755. compat_int_t irq;
  1756. compat_int_t flags;
  1757. compat_int_t xmit_fifo_size;
  1758. compat_int_t custom_divisor;
  1759. compat_int_t baud_base;
  1760. unsigned short close_delay;
  1761. char io_type;
  1762. char reserved_char[1];
  1763. compat_int_t hub6;
  1764. unsigned short closing_wait; /* time to wait before closing */
  1765. unsigned short closing_wait2; /* no longer used... */
  1766. compat_uint_t iomem_base;
  1767. unsigned short iomem_reg_shift;
  1768. unsigned int port_high;
  1769. /* compat_ulong_t iomap_base FIXME */
  1770. compat_int_t reserved[1];
  1771. };
  1772. static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
  1773. {
  1774. typedef struct serial_struct SS;
  1775. typedef struct serial_struct32 SS32;
  1776. struct serial_struct32 __user *ss32 = compat_ptr(arg);
  1777. int err;
  1778. struct serial_struct ss;
  1779. mm_segment_t oldseg = get_fs();
  1780. __u32 udata;
  1781. if (cmd == TIOCSSERIAL) {
  1782. if (!access_ok(VERIFY_READ, ss32, sizeof(SS32)))
  1783. return -EFAULT;
  1784. if (__copy_from_user(&ss, ss32, offsetof(SS32, iomem_base)))
  1785. return -EFAULT;
  1786. __get_user(udata, &ss32->iomem_base);
  1787. ss.iomem_base = compat_ptr(udata);
  1788. __get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift);
  1789. __get_user(ss.port_high, &ss32->port_high);
  1790. ss.iomap_base = 0UL;
  1791. }
  1792. set_fs(KERNEL_DS);
  1793. err = sys_ioctl(fd,cmd,(unsigned long)(&ss));
  1794. set_fs(oldseg);
  1795. if (cmd == TIOCGSERIAL && err >= 0) {
  1796. if (!access_ok(VERIFY_WRITE, ss32, sizeof(SS32)))
  1797. return -EFAULT;
  1798. if (__copy_to_user(ss32,&ss,offsetof(SS32,iomem_base)))
  1799. return -EFAULT;
  1800. __put_user((unsigned long)ss.iomem_base >> 32 ?
  1801. 0xffffffff : (unsigned)(unsigned long)ss.iomem_base,
  1802. &ss32->iomem_base);
  1803. __put_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift);
  1804. __put_user(ss.port_high, &ss32->port_high);
  1805. }
  1806. return err;
  1807. }
  1808. struct usbdevfs_ctrltransfer32 {
  1809. u8 bRequestType;
  1810. u8 bRequest;
  1811. u16 wValue;
  1812. u16 wIndex;
  1813. u16 wLength;
  1814. u32 timeout; /* in milliseconds */
  1815. compat_caddr_t data;
  1816. };
  1817. #define USBDEVFS_CONTROL32 _IOWR('U', 0, struct usbdevfs_ctrltransfer32)
  1818. static int do_usbdevfs_control(unsigned int fd, unsigned int cmd, unsigned long arg)
  1819. {
  1820. struct usbdevfs_ctrltransfer32 __user *p32 = compat_ptr(arg);
  1821. struct usbdevfs_ctrltransfer __user *p;
  1822. __u32 udata;
  1823. p = compat_alloc_user_space(sizeof(*p));
  1824. if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
  1825. get_user(udata, &p32->data) ||
  1826. put_user(compat_ptr(udata), &p->data))
  1827. return -EFAULT;
  1828. return sys_ioctl(fd, USBDEVFS_CONTROL, (unsigned long)p);
  1829. }
  1830. struct usbdevfs_bulktransfer32 {
  1831. compat_uint_t ep;
  1832. compat_uint_t len;
  1833. compat_uint_t timeout; /* in milliseconds */
  1834. compat_caddr_t data;
  1835. };
  1836. #define USBDEVFS_BULK32 _IOWR('U', 2, struct usbdevfs_bulktransfer32)
  1837. static int do_usbdevfs_bulk(unsigned int fd, unsigned int cmd, unsigned long arg)
  1838. {
  1839. struct usbdevfs_bulktransfer32 __user *p32 = compat_ptr(arg);
  1840. struct usbdevfs_bulktransfer __user *p;
  1841. compat_uint_t n;
  1842. compat_caddr_t addr;
  1843. p = compat_alloc_user_space(sizeof(*p));
  1844. if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
  1845. get_user(n, &p32->len) || put_user(n, &p->len) ||
  1846. get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
  1847. get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
  1848. return -EFAULT;
  1849. return sys_ioctl(fd, USBDEVFS_BULK, (unsigned long)p);
  1850. }
  1851. /*
  1852. * USBDEVFS_SUBMITURB, USBDEVFS_REAPURB and USBDEVFS_REAPURBNDELAY
  1853. * are handled in usbdevfs core. -Christopher Li
  1854. */
  1855. struct usbdevfs_disconnectsignal32 {
  1856. compat_int_t signr;
  1857. compat_caddr_t context;
  1858. };
  1859. #define USBDEVFS_DISCSIGNAL32 _IOR('U', 14, struct usbdevfs_disconnectsignal32)
  1860. static int do_usbdevfs_discsignal(unsigned int fd, unsigned int cmd, unsigned long arg)
  1861. {
  1862. struct usbdevfs_disconnectsignal kdis;
  1863. struct usbdevfs_disconnectsignal32 __user *udis;
  1864. mm_segment_t old_fs;
  1865. u32 uctx;
  1866. int err;
  1867. udis = compat_ptr(arg);
  1868. if (get_user(kdis.signr, &udis->signr) ||
  1869. __get_user(uctx, &udis->context))
  1870. return -EFAULT;
  1871. kdis.context = compat_ptr(uctx);
  1872. old_fs = get_fs();
  1873. set_fs(KERNEL_DS);
  1874. err = sys_ioctl(fd, USBDEVFS_DISCSIGNAL, (unsigned long) &kdis);
  1875. set_fs(old_fs);
  1876. return err;
  1877. }
  1878. /*
  1879. * I2C layer ioctls
  1880. */
  1881. struct i2c_msg32 {
  1882. u16 addr;
  1883. u16 flags;
  1884. u16 len;
  1885. compat_caddr_t buf;
  1886. };
  1887. struct i2c_rdwr_ioctl_data32 {
  1888. compat_caddr_t msgs; /* struct i2c_msg __user *msgs */
  1889. u32 nmsgs;
  1890. };
  1891. struct i2c_smbus_ioctl_data32 {
  1892. u8 read_write;
  1893. u8 command;
  1894. u32 size;
  1895. compat_caddr_t data; /* union i2c_smbus_data *data */
  1896. };
  1897. struct i2c_rdwr_aligned {
  1898. struct i2c_rdwr_ioctl_data cmd;
  1899. struct i2c_msg msgs[0];
  1900. };
  1901. static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  1902. {
  1903. struct i2c_rdwr_ioctl_data32 __user *udata = compat_ptr(arg);
  1904. struct i2c_rdwr_aligned __user *tdata;
  1905. struct i2c_msg __user *tmsgs;
  1906. struct i2c_msg32 __user *umsgs;
  1907. compat_caddr_t datap;
  1908. int nmsgs, i;
  1909. if (get_user(nmsgs, &udata->nmsgs))
  1910. return -EFAULT;
  1911. if (nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
  1912. return -EINVAL;
  1913. if (get_user(datap, &udata->msgs))
  1914. return -EFAULT;
  1915. umsgs = compat_ptr(datap);
  1916. tdata = compat_alloc_user_space(sizeof(*tdata) +
  1917. nmsgs * sizeof(struct i2c_msg));
  1918. tmsgs = &tdata->msgs[0];
  1919. if (put_user(nmsgs, &tdata->cmd.nmsgs) ||
  1920. put_user(tmsgs, &tdata->cmd.msgs))
  1921. return -EFAULT;
  1922. for (i = 0; i < nmsgs; i++) {
  1923. if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
  1924. return -EFAULT;
  1925. if (get_user(datap, &umsgs[i].buf) ||
  1926. put_user(compat_ptr(datap), &tmsgs[i].buf))
  1927. return -EFAULT;
  1928. }
  1929. return sys_ioctl(fd, cmd, (unsigned long)tdata);
  1930. }
  1931. static int do_i2c_smbus_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  1932. {
  1933. struct i2c_smbus_ioctl_data __user *tdata;
  1934. struct i2c_smbus_ioctl_data32 __user *udata;
  1935. compat_caddr_t datap;
  1936. tdata = compat_alloc_user_space(sizeof(*tdata));
  1937. if (tdata == NULL)
  1938. return -ENOMEM;
  1939. if (!access_ok(VERIFY_WRITE, tdata, sizeof(*tdata)))
  1940. return -EFAULT;
  1941. udata = compat_ptr(arg);
  1942. if (!access_ok(VERIFY_READ, udata, sizeof(*udata)))
  1943. return -EFAULT;
  1944. if (__copy_in_user(&tdata->read_write, &udata->read_write, 2 * sizeof(u8)))
  1945. return -EFAULT;
  1946. if (__copy_in_user(&tdata->size, &udata->size, 2 * sizeof(u32)))
  1947. return -EFAULT;
  1948. if (__get_user(datap, &udata->data) ||
  1949. __put_user(compat_ptr(datap), &tdata->data))
  1950. return -EFAULT;
  1951. return sys_ioctl(fd, cmd, (unsigned long)tdata);
  1952. }
  1953. struct compat_iw_point {
  1954. compat_caddr_t pointer;
  1955. __u16 length;
  1956. __u16 flags;
  1957. };
  1958. static int do_wireless_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  1959. {
  1960. struct iwreq __user *iwr;
  1961. struct iwreq __user *iwr_u;
  1962. struct iw_point __user *iwp;
  1963. struct compat_iw_point __user *iwp_u;
  1964. compat_caddr_t pointer;
  1965. __u16 length, flags;
  1966. iwr_u = compat_ptr(arg);
  1967. iwp_u = (struct compat_iw_point __user *) &iwr_u->u.data;
  1968. iwr = compat_alloc_user_space(sizeof(*iwr));
  1969. if (iwr == NULL)
  1970. return -ENOMEM;
  1971. iwp = &iwr->u.data;
  1972. if (!access_ok(VERIFY_WRITE, iwr, sizeof(*iwr)))
  1973. return -EFAULT;
  1974. if (__copy_in_user(&iwr->ifr_ifrn.ifrn_name[0],
  1975. &iwr_u->ifr_ifrn.ifrn_name[0],
  1976. sizeof(iwr->ifr_ifrn.ifrn_name)))
  1977. return -EFAULT;
  1978. if (__get_user(pointer, &iwp_u->pointer) ||
  1979. __get_user(length, &iwp_u->length) ||
  1980. __get_user(flags, &iwp_u->flags))
  1981. return -EFAULT;
  1982. if (__put_user(compat_ptr(pointer), &iwp->pointer) ||
  1983. __put_user(length, &iwp->length) ||
  1984. __put_user(flags, &iwp->flags))
  1985. return -EFAULT;
  1986. return sys_ioctl(fd, cmd, (unsigned long) iwr);
  1987. }
  1988. /* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
  1989. * for some operations; this forces use of the newer bridge-utils that
  1990. * use compatiable ioctls
  1991. */
  1992. static int old_bridge_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  1993. {
  1994. u32 tmp;
  1995. if (get_user(tmp, (u32 __user *) arg))
  1996. return -EFAULT;
  1997. if (tmp == BRCTL_GET_VERSION)
  1998. return BRCTL_VERSION + 1;
  1999. return -EINVAL;
  2000. }
  2001. #define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t)
  2002. #define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t)
  2003. #define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t)
  2004. #define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t)
  2005. static int rtc_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
  2006. {
  2007. mm_segment_t oldfs = get_fs();
  2008. compat_ulong_t val32;
  2009. unsigned long kval;
  2010. int ret;
  2011. switch (cmd) {
  2012. case RTC_IRQP_READ32:
  2013. case RTC_EPOCH_READ32:
  2014. set_fs(KERNEL_DS);
  2015. ret = sys_ioctl(fd, (cmd == RTC_IRQP_READ32) ?
  2016. RTC_IRQP_READ : RTC_EPOCH_READ,
  2017. (unsigned long)&kval);
  2018. set_fs(oldfs);
  2019. if (ret)
  2020. return ret;
  2021. val32 = kval;
  2022. return put_user(val32, (unsigned int __user *)arg);
  2023. case RTC_IRQP_SET32:
  2024. return sys_ioctl(fd, RTC_IRQP_SET, arg);
  2025. case RTC_EPOCH_SET32:
  2026. return sys_ioctl(fd, RTC_EPOCH_SET, arg);
  2027. default:
  2028. /* unreached */
  2029. return -ENOIOCTLCMD;
  2030. }
  2031. }
  2032. #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE)
  2033. struct ncp_ioctl_request_32 {
  2034. u32 function;
  2035. u32 size;
  2036. compat_caddr_t data;
  2037. };
  2038. struct ncp_fs_info_v2_32 {
  2039. s32 version;
  2040. u32 mounted_uid;
  2041. u32 connection;
  2042. u32 buffer_size;
  2043. u32 volume_number;
  2044. u32 directory_id;
  2045. u32 dummy1;
  2046. u32 dummy2;
  2047. u32 dummy3;
  2048. };
  2049. struct ncp_objectname_ioctl_32
  2050. {
  2051. s32 auth_type;
  2052. u32 object_name_len;
  2053. compat_caddr_t object_name; /* an userspace data, in most cases user name */
  2054. };
  2055. struct ncp_privatedata_ioctl_32
  2056. {
  2057. u32 len;
  2058. compat_caddr_t data; /* ~1000 for NDS */
  2059. };
  2060. #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct ncp_ioctl_request_32)
  2061. #define NCP_IOC_GETMOUNTUID2_32 _IOW('n', 2, u32)
  2062. #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct ncp_fs_info_v2_32)
  2063. #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct ncp_objectname_ioctl_32)
  2064. #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct ncp_objectname_ioctl_32)
  2065. #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct ncp_privatedata_ioctl_32)
  2066. #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct ncp_privatedata_ioctl_32)
  2067. static int do_ncp_ncprequest(unsigned int fd, unsigned int cmd, unsigned long arg)
  2068. {
  2069. struct ncp_ioctl_request_32 n32;
  2070. struct ncp_ioctl_request __user *p = compat_alloc_user_space(sizeof(*p));
  2071. if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32)) ||
  2072. put_user(n32.function, &p->function) ||
  2073. put_user(n32.size, &p->size) ||
  2074. put_user(compat_ptr(n32.data), &p->data))
  2075. return -EFAULT;
  2076. return sys_ioctl(fd, NCP_IOC_NCPREQUEST, (unsigned long)p);
  2077. }
  2078. static int do_ncp_getmountuid2(unsigned int fd, unsigned int cmd, unsigned long arg)
  2079. {
  2080. mm_segment_t old_fs = get_fs();
  2081. __kernel_uid_t kuid;
  2082. int err;
  2083. cmd = NCP_IOC_GETMOUNTUID2;
  2084. set_fs(KERNEL_DS);
  2085. err = sys_ioctl(fd, cmd, (unsigned long)&kuid);
  2086. set_fs(old_fs);
  2087. if (!err)
  2088. err = put_user(kuid,
  2089. (unsigned int __user *) compat_ptr(arg));
  2090. return err;
  2091. }
  2092. static int do_ncp_getfsinfo2(unsigned int fd, unsigned int cmd, unsigned long arg)
  2093. {
  2094. mm_segment_t old_fs = get_fs();
  2095. struct ncp_fs_info_v2_32 n32;
  2096. struct ncp_fs_info_v2 n;
  2097. int err;
  2098. if (copy_from_user(&n32, compat_ptr(arg), sizeof(n32)))
  2099. return -EFAULT;
  2100. if (n32.version != NCP_GET_FS_INFO_VERSION_V2)
  2101. return -EINVAL;
  2102. n.version = NCP_GET_FS_INFO_VERSION_V2;
  2103. set_fs(KERNEL_DS);
  2104. err = sys_ioctl(fd, NCP_IOC_GET_FS_INFO_V2, (unsigned long)&n);
  2105. set_fs(old_fs);
  2106. if (!err) {
  2107. n32.version = n.version;
  2108. n32.mounted_uid = n.mounted_uid;
  2109. n32.connection = n.connection;
  2110. n32.buffer_size = n.buffer_size;
  2111. n32.volume_number = n.volume_number;
  2112. n32.directory_id = n.directory_id;
  2113. n32.dummy1 = n.dummy1;
  2114. n32.dummy2 = n.dummy2;
  2115. n32.dummy3 = n.dummy3;
  2116. err = copy_to_user(compat_ptr(arg), &n32, sizeof(n32)) ? -EFAULT : 0;
  2117. }
  2118. return err;
  2119. }
  2120. static int do_ncp_getobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
  2121. {
  2122. struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg);
  2123. struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p));
  2124. s32 auth_type;
  2125. u32 name_len;
  2126. int err;
  2127. if (copy_from_user(&n32, p32, sizeof(n32)) ||
  2128. put_user(n32.object_name_len, &p->object_name_len) ||
  2129. put_user(compat_ptr(n32.object_name), &p->object_name))
  2130. return -EFAULT;
  2131. err = sys_ioctl(fd, NCP_IOC_GETOBJECTNAME, (unsigned long)p);
  2132. if (err)
  2133. return err;
  2134. if (get_user(auth_type, &p->auth_type) ||
  2135. put_user(auth_type, &p32->auth_type) ||
  2136. get_user(name_len, &p->object_name_len) ||
  2137. put_user(name_len, &p32->object_name_len))
  2138. return -EFAULT;
  2139. return 0;
  2140. }
  2141. static int do_ncp_setobjectname(unsigned int fd, unsigned int cmd, unsigned long arg)
  2142. {
  2143. struct ncp_objectname_ioctl_32 n32, __user *p32 = compat_ptr(arg);
  2144. struct ncp_objectname_ioctl __user *p = compat_alloc_user_space(sizeof(*p));
  2145. if (copy_from_user(&n32, p32, sizeof(n32)) ||
  2146. put_user(n32.auth_type, &p->auth_type) ||
  2147. put_user(n32.object_name_len, &p->object_name_len) ||
  2148. put_user(compat_ptr(n32.object_name), &p->object_name))
  2149. return -EFAULT;
  2150. return sys_ioctl(fd, NCP_IOC_SETOBJECTNAME, (unsigned long)p);
  2151. }
  2152. static int do_ncp_getprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
  2153. {
  2154. struct ncp_privatedata_ioctl_32 n32, __user *p32 = compat_ptr(arg);
  2155. struct ncp_privatedata_ioctl __user *p =
  2156. compat_alloc_user_space(sizeof(*p));
  2157. u32 len;
  2158. int err;
  2159. if (copy_from_user(&n32, p32, sizeof(n32)) ||
  2160. put_user(n32.len, &p->len) ||
  2161. put_user(compat_ptr(n32.data), &p->data))
  2162. return -EFAULT;
  2163. err = sys_ioctl(fd, NCP_IOC_GETPRIVATEDATA, (unsigned long)p);
  2164. if (err)
  2165. return err;
  2166. if (get_user(len, &p->len) ||
  2167. put_user(len, &p32->len))
  2168. return -EFAULT;
  2169. return 0;
  2170. }
  2171. static int do_ncp_setprivatedata(unsigned int fd, unsigned int cmd, unsigned long arg)
  2172. {
  2173. struct ncp_privatedata_ioctl_32 n32;
  2174. struct ncp_privatedata_ioctl_32 __user *p32 = compat_ptr(arg);
  2175. struct ncp_privatedata_ioctl __user *p =
  2176. compat_alloc_user_space(sizeof(*p));
  2177. if (copy_from_user(&n32, p32, sizeof(n32)) ||
  2178. put_user(n32.len, &p->len) ||
  2179. put_user(compat_ptr(n32.data), &p->data))
  2180. return -EFAULT;
  2181. return sys_ioctl(fd, NCP_IOC_SETPRIVATEDATA, (unsigned long)p);
  2182. }
  2183. #endif
  2184. static int
  2185. lp_timeout_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
  2186. {
  2187. struct compat_timeval __user *tc = (struct compat_timeval __user *)arg;
  2188. struct timeval __user *tn = compat_alloc_user_space(sizeof(struct timeval));
  2189. struct timeval ts;
  2190. if (get_user(ts.tv_sec, &tc->tv_sec) ||
  2191. get_user(ts.tv_usec, &tc->tv_usec) ||
  2192. put_user(ts.tv_sec, &tn->tv_sec) ||
  2193. put_user(ts.tv_usec, &tn->tv_usec))
  2194. return -EFAULT;
  2195. return sys_ioctl(fd, cmd, (unsigned long)tn);
  2196. }
  2197. #define HANDLE_IOCTL(cmd,handler) \
  2198. { (cmd), (ioctl_trans_handler_t)(handler) },
  2199. /* pointer to compatible structure or no argument */
  2200. #define COMPATIBLE_IOCTL(cmd) \
  2201. { (cmd), do_ioctl32_pointer },
  2202. /* argument is an unsigned long integer, not a pointer */
  2203. #define ULONG_IOCTL(cmd) \
  2204. { (cmd), (ioctl_trans_handler_t)sys_ioctl },
  2205. struct ioctl_trans ioctl_start[] = {
  2206. #include <linux/compat_ioctl.h>
  2207. HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob)
  2208. HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob)
  2209. #ifdef CONFIG_NET
  2210. HANDLE_IOCTL(SIOCGIFNAME, dev_ifname32)
  2211. HANDLE_IOCTL(SIOCGIFCONF, dev_ifconf)
  2212. HANDLE_IOCTL(SIOCGIFFLAGS, dev_ifsioc)
  2213. HANDLE_IOCTL(SIOCSIFFLAGS, dev_ifsioc)
  2214. HANDLE_IOCTL(SIOCGIFMETRIC, dev_ifsioc)
  2215. HANDLE_IOCTL(SIOCSIFMETRIC, dev_ifsioc)
  2216. HANDLE_IOCTL(SIOCGIFMTU, dev_ifsioc)
  2217. HANDLE_IOCTL(SIOCSIFMTU, dev_ifsioc)
  2218. HANDLE_IOCTL(SIOCGIFMEM, dev_ifsioc)
  2219. HANDLE_IOCTL(SIOCSIFMEM, dev_ifsioc)
  2220. HANDLE_IOCTL(SIOCGIFHWADDR, dev_ifsioc)
  2221. HANDLE_IOCTL(SIOCSIFHWADDR, dev_ifsioc)
  2222. HANDLE_IOCTL(SIOCADDMULTI, dev_ifsioc)
  2223. HANDLE_IOCTL(SIOCDELMULTI, dev_ifsioc)
  2224. HANDLE_IOCTL(SIOCGIFINDEX, dev_ifsioc)
  2225. HANDLE_IOCTL(SIOCGIFMAP, dev_ifsioc)
  2226. HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
  2227. HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
  2228. HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
  2229. /* ioctls used by appletalk ddp.c */
  2230. HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc)
  2231. HANDLE_IOCTL(SIOCDIFADDR, dev_ifsioc)
  2232. HANDLE_IOCTL(SIOCSARP, dev_ifsioc)
  2233. HANDLE_IOCTL(SIOCDARP, dev_ifsioc)
  2234. HANDLE_IOCTL(SIOCGIFBRDADDR, dev_ifsioc)
  2235. HANDLE_IOCTL(SIOCSIFBRDADDR, dev_ifsioc)
  2236. HANDLE_IOCTL(SIOCGIFDSTADDR, dev_ifsioc)
  2237. HANDLE_IOCTL(SIOCSIFDSTADDR, dev_ifsioc)
  2238. HANDLE_IOCTL(SIOCGIFNETMASK, dev_ifsioc)
  2239. HANDLE_IOCTL(SIOCSIFNETMASK, dev_ifsioc)
  2240. HANDLE_IOCTL(SIOCSIFPFLAGS, dev_ifsioc)
  2241. HANDLE_IOCTL(SIOCGIFPFLAGS, dev_ifsioc)
  2242. HANDLE_IOCTL(SIOCGIFTXQLEN, dev_ifsioc)
  2243. HANDLE_IOCTL(SIOCSIFTXQLEN, dev_ifsioc)
  2244. HANDLE_IOCTL(TUNSETIFF, dev_ifsioc)
  2245. HANDLE_IOCTL(SIOCETHTOOL, ethtool_ioctl)
  2246. HANDLE_IOCTL(SIOCBONDENSLAVE, bond_ioctl)
  2247. HANDLE_IOCTL(SIOCBONDRELEASE, bond_ioctl)
  2248. HANDLE_IOCTL(SIOCBONDSETHWADDR, bond_ioctl)
  2249. HANDLE_IOCTL(SIOCBONDSLAVEINFOQUERY, bond_ioctl)
  2250. HANDLE_IOCTL(SIOCBONDINFOQUERY, bond_ioctl)
  2251. HANDLE_IOCTL(SIOCBONDCHANGEACTIVE, bond_ioctl)
  2252. HANDLE_IOCTL(SIOCADDRT, routing_ioctl)
  2253. HANDLE_IOCTL(SIOCDELRT, routing_ioctl)
  2254. HANDLE_IOCTL(SIOCBRADDIF, dev_ifsioc)
  2255. HANDLE_IOCTL(SIOCBRDELIF, dev_ifsioc)
  2256. /* Note SIOCRTMSG is no longer, so this is safe and * the user would have seen just an -EINVAL anyways. */
  2257. HANDLE_IOCTL(SIOCRTMSG, ret_einval)
  2258. HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
  2259. #endif
  2260. #ifdef CONFIG_BLOCK
  2261. HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo)
  2262. HANDLE_IOCTL(BLKRAGET, w_long)
  2263. HANDLE_IOCTL(BLKGETSIZE, w_long)
  2264. HANDLE_IOCTL(0x1260, broken_blkgetsize)
  2265. HANDLE_IOCTL(BLKFRAGET, w_long)
  2266. HANDLE_IOCTL(BLKSECTGET, w_long)
  2267. HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans)
  2268. HANDLE_IOCTL(HDIO_GET_KEEPSETTINGS, hdio_ioctl_trans)
  2269. HANDLE_IOCTL(HDIO_GET_UNMASKINTR, hdio_ioctl_trans)
  2270. HANDLE_IOCTL(HDIO_GET_DMA, hdio_ioctl_trans)
  2271. HANDLE_IOCTL(HDIO_GET_32BIT, hdio_ioctl_trans)
  2272. HANDLE_IOCTL(HDIO_GET_MULTCOUNT, hdio_ioctl_trans)
  2273. HANDLE_IOCTL(HDIO_GET_NOWERR, hdio_ioctl_trans)
  2274. HANDLE_IOCTL(HDIO_GET_NICE, hdio_ioctl_trans)
  2275. HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans)
  2276. HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans)
  2277. HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans)
  2278. HANDLE_IOCTL(FDSETDRVPRM32, fd_ioctl_trans)
  2279. HANDLE_IOCTL(FDGETDRVPRM32, fd_ioctl_trans)
  2280. HANDLE_IOCTL(FDGETDRVSTAT32, fd_ioctl_trans)
  2281. HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans)
  2282. HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans)
  2283. HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans)
  2284. HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
  2285. HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans)
  2286. #endif
  2287. HANDLE_IOCTL(PPPIOCGIDLE32, ppp_ioctl_trans)
  2288. HANDLE_IOCTL(PPPIOCSCOMPRESS32, ppp_ioctl_trans)
  2289. HANDLE_IOCTL(PPPIOCSPASS32, ppp_sock_fprog_ioctl_trans)
  2290. HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
  2291. #ifdef CONFIG_BLOCK
  2292. HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
  2293. HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
  2294. HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans)
  2295. HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans)
  2296. #endif
  2297. #define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
  2298. HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
  2299. #ifdef CONFIG_VT
  2300. HANDLE_IOCTL(PIO_FONTX, do_fontx_ioctl)
  2301. HANDLE_IOCTL(GIO_FONTX, do_fontx_ioctl)
  2302. HANDLE_IOCTL(PIO_UNIMAP, do_unimap_ioctl)
  2303. HANDLE_IOCTL(GIO_UNIMAP, do_unimap_ioctl)
  2304. HANDLE_IOCTL(KDFONTOP, do_kdfontop_ioctl)
  2305. #endif
  2306. /* One SMB ioctl needs translations. */
  2307. #define SMB_IOC_GETMOUNTUID_32 _IOR('u', 1, compat_uid_t)
  2308. HANDLE_IOCTL(SMB_IOC_GETMOUNTUID_32, do_smb_getmountuid)
  2309. HANDLE_IOCTL(ATM_GETLINKRATE32, do_atm_ioctl)
  2310. HANDLE_IOCTL(ATM_GETNAMES32, do_atm_ioctl)
  2311. HANDLE_IOCTL(ATM_GETTYPE32, do_atm_ioctl)
  2312. HANDLE_IOCTL(ATM_GETESI32, do_atm_ioctl)
  2313. HANDLE_IOCTL(ATM_GETADDR32, do_atm_ioctl)
  2314. HANDLE_IOCTL(ATM_RSTADDR32, do_atm_ioctl)
  2315. HANDLE_IOCTL(ATM_ADDADDR32, do_atm_ioctl)
  2316. HANDLE_IOCTL(ATM_DELADDR32, do_atm_ioctl)
  2317. HANDLE_IOCTL(ATM_GETCIRANGE32, do_atm_ioctl)
  2318. HANDLE_IOCTL(ATM_SETCIRANGE32, do_atm_ioctl)
  2319. HANDLE_IOCTL(ATM_SETESI32, do_atm_ioctl)
  2320. HANDLE_IOCTL(ATM_SETESIF32, do_atm_ioctl)
  2321. HANDLE_IOCTL(ATM_GETSTAT32, do_atm_ioctl)
  2322. HANDLE_IOCTL(ATM_GETSTATZ32, do_atm_ioctl)
  2323. HANDLE_IOCTL(ATM_GETLOOP32, do_atm_ioctl)
  2324. HANDLE_IOCTL(ATM_SETLOOP32, do_atm_ioctl)
  2325. HANDLE_IOCTL(ATM_QUERYLOOP32, do_atm_ioctl)
  2326. HANDLE_IOCTL(SONET_GETSTAT, do_atm_ioctl)
  2327. HANDLE_IOCTL(SONET_GETSTATZ, do_atm_ioctl)
  2328. HANDLE_IOCTL(SONET_GETDIAG, do_atm_ioctl)
  2329. HANDLE_IOCTL(SONET_SETDIAG, do_atm_ioctl)
  2330. HANDLE_IOCTL(SONET_CLRDIAG, do_atm_ioctl)
  2331. HANDLE_IOCTL(SONET_SETFRAMING, do_atm_ioctl)
  2332. HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
  2333. HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
  2334. /* block stuff */
  2335. #ifdef CONFIG_BLOCK
  2336. HANDLE_IOCTL(BLKBSZGET_32, do_blkbszget)
  2337. HANDLE_IOCTL(BLKBSZSET_32, do_blkbszset)
  2338. HANDLE_IOCTL(BLKGETSIZE64_32, do_blkgetsize64)
  2339. /* Raw devices */
  2340. HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
  2341. HANDLE_IOCTL(RAW_GETBIND, raw_ioctl)
  2342. #endif
  2343. /* Serial */
  2344. HANDLE_IOCTL(TIOCGSERIAL, serial_struct_ioctl)
  2345. HANDLE_IOCTL(TIOCSSERIAL, serial_struct_ioctl)
  2346. #ifdef TIOCGLTC
  2347. COMPATIBLE_IOCTL(TIOCGLTC)
  2348. COMPATIBLE_IOCTL(TIOCSLTC)
  2349. #endif
  2350. #ifdef TIOCSTART
  2351. /*
  2352. * For these two we have defintions in ioctls.h and/or termios.h on
  2353. * some architectures but no actual implemention. Some applications
  2354. * like bash call them if they are defined in the headers, so we provide
  2355. * entries here to avoid syslog message spew.
  2356. */
  2357. COMPATIBLE_IOCTL(TIOCSTART)
  2358. COMPATIBLE_IOCTL(TIOCSTOP)
  2359. #endif
  2360. /* Usbdevfs */
  2361. HANDLE_IOCTL(USBDEVFS_CONTROL32, do_usbdevfs_control)
  2362. HANDLE_IOCTL(USBDEVFS_BULK32, do_usbdevfs_bulk)
  2363. HANDLE_IOCTL(USBDEVFS_DISCSIGNAL32, do_usbdevfs_discsignal)
  2364. COMPATIBLE_IOCTL(USBDEVFS_IOCTL32)
  2365. /* i2c */
  2366. HANDLE_IOCTL(I2C_FUNCS, w_long)
  2367. HANDLE_IOCTL(I2C_RDWR, do_i2c_rdwr_ioctl)
  2368. HANDLE_IOCTL(I2C_SMBUS, do_i2c_smbus_ioctl)
  2369. /* wireless */
  2370. HANDLE_IOCTL(SIOCGIWRANGE, do_wireless_ioctl)
  2371. HANDLE_IOCTL(SIOCSIWSPY, do_wireless_ioctl)
  2372. HANDLE_IOCTL(SIOCGIWSPY, do_wireless_ioctl)
  2373. HANDLE_IOCTL(SIOCSIWTHRSPY, do_wireless_ioctl)
  2374. HANDLE_IOCTL(SIOCGIWTHRSPY, do_wireless_ioctl)
  2375. HANDLE_IOCTL(SIOCGIWAPLIST, do_wireless_ioctl)
  2376. HANDLE_IOCTL(SIOCGIWSCAN, do_wireless_ioctl)
  2377. HANDLE_IOCTL(SIOCSIWESSID, do_wireless_ioctl)
  2378. HANDLE_IOCTL(SIOCGIWESSID, do_wireless_ioctl)
  2379. HANDLE_IOCTL(SIOCSIWNICKN, do_wireless_ioctl)
  2380. HANDLE_IOCTL(SIOCGIWNICKN, do_wireless_ioctl)
  2381. HANDLE_IOCTL(SIOCSIWENCODE, do_wireless_ioctl)
  2382. HANDLE_IOCTL(SIOCGIWENCODE, do_wireless_ioctl)
  2383. HANDLE_IOCTL(SIOCSIFBR, old_bridge_ioctl)
  2384. HANDLE_IOCTL(SIOCGIFBR, old_bridge_ioctl)
  2385. HANDLE_IOCTL(RTC_IRQP_READ32, rtc_ioctl)
  2386. HANDLE_IOCTL(RTC_IRQP_SET32, rtc_ioctl)
  2387. HANDLE_IOCTL(RTC_EPOCH_READ32, rtc_ioctl)
  2388. HANDLE_IOCTL(RTC_EPOCH_SET32, rtc_ioctl)
  2389. #if defined(CONFIG_NCP_FS) || defined(CONFIG_NCP_FS_MODULE)
  2390. HANDLE_IOCTL(NCP_IOC_NCPREQUEST_32, do_ncp_ncprequest)
  2391. HANDLE_IOCTL(NCP_IOC_GETMOUNTUID2_32, do_ncp_getmountuid2)
  2392. HANDLE_IOCTL(NCP_IOC_GET_FS_INFO_V2_32, do_ncp_getfsinfo2)
  2393. HANDLE_IOCTL(NCP_IOC_GETOBJECTNAME_32, do_ncp_getobjectname)
  2394. HANDLE_IOCTL(NCP_IOC_SETOBJECTNAME_32, do_ncp_setobjectname)
  2395. HANDLE_IOCTL(NCP_IOC_GETPRIVATEDATA_32, do_ncp_getprivatedata)
  2396. HANDLE_IOCTL(NCP_IOC_SETPRIVATEDATA_32, do_ncp_setprivatedata)
  2397. #endif
  2398. /* dvb */
  2399. HANDLE_IOCTL(VIDEO_GET_EVENT, do_video_get_event)
  2400. HANDLE_IOCTL(VIDEO_STILLPICTURE, do_video_stillpicture)
  2401. HANDLE_IOCTL(VIDEO_SET_SPU_PALETTE, do_video_set_spu_palette)
  2402. /* parport */
  2403. COMPATIBLE_IOCTL(LPTIME)
  2404. COMPATIBLE_IOCTL(LPCHAR)
  2405. COMPATIBLE_IOCTL(LPABORTOPEN)
  2406. COMPATIBLE_IOCTL(LPCAREFUL)
  2407. COMPATIBLE_IOCTL(LPWAIT)
  2408. COMPATIBLE_IOCTL(LPSETIRQ)
  2409. COMPATIBLE_IOCTL(LPGETSTATUS)
  2410. COMPATIBLE_IOCTL(LPGETSTATUS)
  2411. COMPATIBLE_IOCTL(LPRESET)
  2412. /*LPGETSTATS not implemented, but no kernels seem to compile it in anyways*/
  2413. COMPATIBLE_IOCTL(LPGETFLAGS)
  2414. HANDLE_IOCTL(LPSETTIMEOUT, lp_timeout_trans)
  2415. };
  2416. int ioctl_table_size = ARRAY_SIZE(ioctl_start);