sys_sunos.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. /* $Id: sys_sunos.c,v 1.137 2002/02/08 03:57:14 davem Exp $
  2. * sys_sunos.c: SunOS specific syscall compatibility support.
  3. *
  4. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5. * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
  6. *
  7. * Based upon preliminary work which is:
  8. *
  9. * Copyright (C) 1995 Adrian M. Rodriguez (adrian@remus.rutgers.edu)
  10. *
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/types.h>
  15. #include <linux/mman.h>
  16. #include <linux/mm.h>
  17. #include <linux/swap.h>
  18. #include <linux/fs.h>
  19. #include <linux/file.h>
  20. #include <linux/resource.h>
  21. #include <linux/ipc.h>
  22. #include <linux/shm.h>
  23. #include <linux/msg.h>
  24. #include <linux/sem.h>
  25. #include <linux/signal.h>
  26. #include <linux/uio.h>
  27. #include <linux/utsname.h>
  28. #include <linux/major.h>
  29. #include <linux/stat.h>
  30. #include <linux/slab.h>
  31. #include <linux/pagemap.h>
  32. #include <linux/capability.h>
  33. #include <linux/errno.h>
  34. #include <linux/smp.h>
  35. #include <linux/smp_lock.h>
  36. #include <linux/syscalls.h>
  37. #include <net/sock.h>
  38. #include <asm/uaccess.h>
  39. #ifndef KERNEL_DS
  40. #include <linux/segment.h>
  41. #endif
  42. #include <asm/page.h>
  43. #include <asm/pgtable.h>
  44. #include <asm/pconf.h>
  45. #include <asm/idprom.h> /* for gethostid() */
  46. #include <asm/unistd.h>
  47. #include <asm/system.h>
  48. /* For the nfs mount emulation */
  49. #include <linux/socket.h>
  50. #include <linux/in.h>
  51. #include <linux/nfs.h>
  52. #include <linux/nfs2.h>
  53. #include <linux/nfs_mount.h>
  54. /* for sunos_select */
  55. #include <linux/time.h>
  56. #include <linux/personality.h>
  57. /* NR_OPEN is now larger and dynamic in recent kernels. */
  58. #define SUNOS_NR_OPEN 256
  59. /* We use the SunOS mmap() semantics. */
  60. asmlinkage unsigned long sunos_mmap(unsigned long addr, unsigned long len,
  61. unsigned long prot, unsigned long flags,
  62. unsigned long fd, unsigned long off)
  63. {
  64. struct file * file = NULL;
  65. unsigned long retval, ret_type;
  66. if (flags & MAP_NORESERVE) {
  67. static int cnt;
  68. if (cnt++ < 10)
  69. printk("%s: unimplemented SunOS MAP_NORESERVE mmap() flag\n",
  70. current->comm);
  71. flags &= ~MAP_NORESERVE;
  72. }
  73. retval = -EBADF;
  74. if (!(flags & MAP_ANONYMOUS)) {
  75. if (fd >= SUNOS_NR_OPEN)
  76. goto out;
  77. file = fget(fd);
  78. if (!file)
  79. goto out;
  80. }
  81. retval = -EINVAL;
  82. /* If this is ld.so or a shared library doing an mmap
  83. * of /dev/zero, transform it into an anonymous mapping.
  84. * SunOS is so stupid some times... hmph!
  85. */
  86. if (file) {
  87. if (imajor(file->f_path.dentry->d_inode) == MEM_MAJOR &&
  88. iminor(file->f_path.dentry->d_inode) == 5) {
  89. flags |= MAP_ANONYMOUS;
  90. fput(file);
  91. file = NULL;
  92. }
  93. }
  94. ret_type = flags & _MAP_NEW;
  95. flags &= ~_MAP_NEW;
  96. if (!(flags & MAP_FIXED))
  97. addr = 0;
  98. else {
  99. if (ARCH_SUN4C_SUN4 &&
  100. (len > 0x20000000 ||
  101. ((flags & MAP_FIXED) &&
  102. addr < 0xe0000000 && addr + len > 0x20000000)))
  103. goto out_putf;
  104. /* See asm-sparc/uaccess.h */
  105. if (len > TASK_SIZE - PAGE_SIZE ||
  106. addr + len > TASK_SIZE - PAGE_SIZE)
  107. goto out_putf;
  108. }
  109. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  110. down_write(&current->mm->mmap_sem);
  111. retval = do_mmap(file, addr, len, prot, flags, off);
  112. up_write(&current->mm->mmap_sem);
  113. if (!ret_type)
  114. retval = ((retval < PAGE_OFFSET) ? 0 : retval);
  115. out_putf:
  116. if (file)
  117. fput(file);
  118. out:
  119. return retval;
  120. }
  121. /* lmbench calls this, just say "yeah, ok" */
  122. asmlinkage int sunos_mctl(unsigned long addr, unsigned long len, int function, char *arg)
  123. {
  124. return 0;
  125. }
  126. /* SunOS is completely broken... it returns 0 on success, otherwise
  127. * ENOMEM. For sys_sbrk() it wants the old brk value as a return
  128. * on success and ENOMEM as before on failure.
  129. */
  130. asmlinkage int sunos_brk(unsigned long brk)
  131. {
  132. int freepages, retval = -ENOMEM;
  133. unsigned long rlim;
  134. unsigned long newbrk, oldbrk;
  135. down_write(&current->mm->mmap_sem);
  136. if (ARCH_SUN4C_SUN4) {
  137. if (brk >= 0x20000000 && brk < 0xe0000000) {
  138. goto out;
  139. }
  140. }
  141. if (brk < current->mm->end_code)
  142. goto out;
  143. newbrk = PAGE_ALIGN(brk);
  144. oldbrk = PAGE_ALIGN(current->mm->brk);
  145. retval = 0;
  146. if (oldbrk == newbrk) {
  147. current->mm->brk = brk;
  148. goto out;
  149. }
  150. /*
  151. * Always allow shrinking brk
  152. */
  153. if (brk <= current->mm->brk) {
  154. current->mm->brk = brk;
  155. do_munmap(current->mm, newbrk, oldbrk-newbrk);
  156. goto out;
  157. }
  158. /*
  159. * Check against rlimit and stack..
  160. */
  161. retval = -ENOMEM;
  162. rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
  163. if (rlim >= RLIM_INFINITY)
  164. rlim = ~0;
  165. if (brk - current->mm->end_code > rlim)
  166. goto out;
  167. /*
  168. * Check against existing mmap mappings.
  169. */
  170. if (find_vma_intersection(current->mm, oldbrk, newbrk+PAGE_SIZE))
  171. goto out;
  172. /*
  173. * stupid algorithm to decide if we have enough memory: while
  174. * simple, it hopefully works in most obvious cases.. Easy to
  175. * fool it, but this should catch most mistakes.
  176. */
  177. freepages = global_page_state(NR_FILE_PAGES);
  178. freepages >>= 1;
  179. freepages += nr_free_pages();
  180. freepages += nr_swap_pages;
  181. freepages -= num_physpages >> 4;
  182. freepages -= (newbrk-oldbrk) >> PAGE_SHIFT;
  183. if (freepages < 0)
  184. goto out;
  185. /*
  186. * Ok, we have probably got enough memory - let it rip.
  187. */
  188. current->mm->brk = brk;
  189. do_brk(oldbrk, newbrk-oldbrk);
  190. retval = 0;
  191. out:
  192. up_write(&current->mm->mmap_sem);
  193. return retval;
  194. }
  195. asmlinkage unsigned long sunos_sbrk(int increment)
  196. {
  197. int error;
  198. unsigned long oldbrk;
  199. /* This should do it hopefully... */
  200. lock_kernel();
  201. oldbrk = current->mm->brk;
  202. error = sunos_brk(((int) current->mm->brk) + increment);
  203. if (!error)
  204. error = oldbrk;
  205. unlock_kernel();
  206. return error;
  207. }
  208. /* XXX Completely undocumented, and completely magic...
  209. * XXX I believe it is to increase the size of the stack by
  210. * XXX argument 'increment' and return the new end of stack
  211. * XXX area. Wheee...
  212. */
  213. asmlinkage unsigned long sunos_sstk(int increment)
  214. {
  215. lock_kernel();
  216. printk("%s: Call to sunos_sstk(increment<%d>) is unsupported\n",
  217. current->comm, increment);
  218. unlock_kernel();
  219. return -1;
  220. }
  221. /* Give hints to the kernel as to what paging strategy to use...
  222. * Completely bogus, don't remind me.
  223. */
  224. #define VA_NORMAL 0 /* Normal vm usage expected */
  225. #define VA_ABNORMAL 1 /* Abnormal/random vm usage probable */
  226. #define VA_SEQUENTIAL 2 /* Accesses will be of a sequential nature */
  227. #define VA_INVALIDATE 3 /* Page table entries should be flushed ??? */
  228. static char *vstrings[] = {
  229. "VA_NORMAL",
  230. "VA_ABNORMAL",
  231. "VA_SEQUENTIAL",
  232. "VA_INVALIDATE",
  233. };
  234. asmlinkage void sunos_vadvise(unsigned long strategy)
  235. {
  236. /* I wanna see who uses this... */
  237. lock_kernel();
  238. printk("%s: Advises us to use %s paging strategy\n",
  239. current->comm,
  240. strategy <= 3 ? vstrings[strategy] : "BOGUS");
  241. unlock_kernel();
  242. }
  243. /* This just wants the soft limit (ie. rlim_cur element) of the RLIMIT_NOFILE
  244. * resource limit and is for backwards compatibility with older sunos
  245. * revs.
  246. */
  247. asmlinkage long sunos_getdtablesize(void)
  248. {
  249. return SUNOS_NR_OPEN;
  250. }
  251. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  252. asmlinkage unsigned long sunos_sigblock(unsigned long blk_mask)
  253. {
  254. unsigned long old;
  255. spin_lock_irq(&current->sighand->siglock);
  256. old = current->blocked.sig[0];
  257. current->blocked.sig[0] |= (blk_mask & _BLOCKABLE);
  258. recalc_sigpending();
  259. spin_unlock_irq(&current->sighand->siglock);
  260. return old;
  261. }
  262. asmlinkage unsigned long sunos_sigsetmask(unsigned long newmask)
  263. {
  264. unsigned long retval;
  265. spin_lock_irq(&current->sighand->siglock);
  266. retval = current->blocked.sig[0];
  267. current->blocked.sig[0] = (newmask & _BLOCKABLE);
  268. recalc_sigpending();
  269. spin_unlock_irq(&current->sighand->siglock);
  270. return retval;
  271. }
  272. /* SunOS getdents is very similar to the newer Linux (iBCS2 compliant) */
  273. /* getdents system call, the format of the structure just has a different */
  274. /* layout (d_off+d_ino instead of d_ino+d_off) */
  275. struct sunos_dirent {
  276. long d_off;
  277. unsigned long d_ino;
  278. unsigned short d_reclen;
  279. unsigned short d_namlen;
  280. char d_name[1];
  281. };
  282. struct sunos_dirent_callback {
  283. struct sunos_dirent __user *curr;
  284. struct sunos_dirent __user *previous;
  285. int count;
  286. int error;
  287. };
  288. #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
  289. #define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
  290. static int sunos_filldir(void * __buf, const char * name, int namlen,
  291. loff_t offset, u64 ino, unsigned int d_type)
  292. {
  293. struct sunos_dirent __user *dirent;
  294. struct sunos_dirent_callback * buf = __buf;
  295. unsigned long d_ino;
  296. int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
  297. buf->error = -EINVAL; /* only used if we fail.. */
  298. if (reclen > buf->count)
  299. return -EINVAL;
  300. d_ino = ino;
  301. if (sizeof(d_ino) < sizeof(ino) && d_ino != ino)
  302. return -EOVERFLOW;
  303. dirent = buf->previous;
  304. if (dirent)
  305. put_user(offset, &dirent->d_off);
  306. dirent = buf->curr;
  307. buf->previous = dirent;
  308. put_user(d_ino, &dirent->d_ino);
  309. put_user(namlen, &dirent->d_namlen);
  310. put_user(reclen, &dirent->d_reclen);
  311. copy_to_user(dirent->d_name, name, namlen);
  312. put_user(0, dirent->d_name + namlen);
  313. dirent = (void __user *) dirent + reclen;
  314. buf->curr = dirent;
  315. buf->count -= reclen;
  316. return 0;
  317. }
  318. asmlinkage int sunos_getdents(unsigned int fd, void __user *dirent, int cnt)
  319. {
  320. struct file * file;
  321. struct sunos_dirent __user *lastdirent;
  322. struct sunos_dirent_callback buf;
  323. int error = -EBADF;
  324. if (fd >= SUNOS_NR_OPEN)
  325. goto out;
  326. file = fget(fd);
  327. if (!file)
  328. goto out;
  329. error = -EINVAL;
  330. if (cnt < (sizeof(struct sunos_dirent) + 255))
  331. goto out_putf;
  332. buf.curr = (struct sunos_dirent __user *) dirent;
  333. buf.previous = NULL;
  334. buf.count = cnt;
  335. buf.error = 0;
  336. error = vfs_readdir(file, sunos_filldir, &buf);
  337. if (error < 0)
  338. goto out_putf;
  339. lastdirent = buf.previous;
  340. error = buf.error;
  341. if (lastdirent) {
  342. put_user(file->f_pos, &lastdirent->d_off);
  343. error = cnt - buf.count;
  344. }
  345. out_putf:
  346. fput(file);
  347. out:
  348. return error;
  349. }
  350. /* Old sunos getdirentries, severely broken compatibility stuff here. */
  351. struct sunos_direntry {
  352. unsigned long d_ino;
  353. unsigned short d_reclen;
  354. unsigned short d_namlen;
  355. char d_name[1];
  356. };
  357. struct sunos_direntry_callback {
  358. struct sunos_direntry __user *curr;
  359. struct sunos_direntry __user *previous;
  360. int count;
  361. int error;
  362. };
  363. static int sunos_filldirentry(void * __buf, const char * name, int namlen,
  364. loff_t offset, u64 ino, unsigned int d_type)
  365. {
  366. struct sunos_direntry __user *dirent;
  367. struct sunos_direntry_callback *buf = __buf;
  368. unsigned long d_ino;
  369. int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
  370. buf->error = -EINVAL; /* only used if we fail.. */
  371. if (reclen > buf->count)
  372. return -EINVAL;
  373. d_ino = ino;
  374. if (sizeof(d_ino) < sizeof(ino) && d_ino != ino)
  375. return -EOVERFLOW;
  376. dirent = buf->previous;
  377. dirent = buf->curr;
  378. buf->previous = dirent;
  379. put_user(d_ino, &dirent->d_ino);
  380. put_user(namlen, &dirent->d_namlen);
  381. put_user(reclen, &dirent->d_reclen);
  382. copy_to_user(dirent->d_name, name, namlen);
  383. put_user(0, dirent->d_name + namlen);
  384. dirent = (void __user *) dirent + reclen;
  385. buf->curr = dirent;
  386. buf->count -= reclen;
  387. return 0;
  388. }
  389. asmlinkage int sunos_getdirentries(unsigned int fd, void __user *dirent,
  390. int cnt, unsigned int __user *basep)
  391. {
  392. struct file * file;
  393. struct sunos_direntry __user *lastdirent;
  394. struct sunos_direntry_callback buf;
  395. int error = -EBADF;
  396. if (fd >= SUNOS_NR_OPEN)
  397. goto out;
  398. file = fget(fd);
  399. if (!file)
  400. goto out;
  401. error = -EINVAL;
  402. if (cnt < (sizeof(struct sunos_direntry) + 255))
  403. goto out_putf;
  404. buf.curr = (struct sunos_direntry __user *) dirent;
  405. buf.previous = NULL;
  406. buf.count = cnt;
  407. buf.error = 0;
  408. error = vfs_readdir(file, sunos_filldirentry, &buf);
  409. if (error < 0)
  410. goto out_putf;
  411. lastdirent = buf.previous;
  412. error = buf.error;
  413. if (lastdirent) {
  414. put_user(file->f_pos, basep);
  415. error = cnt - buf.count;
  416. }
  417. out_putf:
  418. fput(file);
  419. out:
  420. return error;
  421. }
  422. struct sunos_utsname {
  423. char sname[9];
  424. char nname[9];
  425. char nnext[56];
  426. char rel[9];
  427. char ver[9];
  428. char mach[9];
  429. };
  430. asmlinkage int sunos_uname(struct sunos_utsname __user *name)
  431. {
  432. int ret;
  433. down_read(&uts_sem);
  434. ret = copy_to_user(&name->sname[0], &utsname()->sysname[0],
  435. sizeof(name->sname) - 1);
  436. if (!ret) {
  437. ret |= __copy_to_user(&name->nname[0], &utsname()->nodename[0],
  438. sizeof(name->nname) - 1);
  439. ret |= __put_user('\0', &name->nname[8]);
  440. ret |= __copy_to_user(&name->rel[0], &utsname()->release[0],
  441. sizeof(name->rel) - 1);
  442. ret |= __copy_to_user(&name->ver[0], &utsname()->version[0],
  443. sizeof(name->ver) - 1);
  444. ret |= __copy_to_user(&name->mach[0], &utsname()->machine[0],
  445. sizeof(name->mach) - 1);
  446. }
  447. up_read(&uts_sem);
  448. return ret ? -EFAULT : 0;
  449. }
  450. asmlinkage int sunos_nosys(void)
  451. {
  452. struct pt_regs *regs;
  453. siginfo_t info;
  454. static int cnt;
  455. lock_kernel();
  456. regs = current->thread.kregs;
  457. info.si_signo = SIGSYS;
  458. info.si_errno = 0;
  459. info.si_code = __SI_FAULT|0x100;
  460. info.si_addr = (void __user *)regs->pc;
  461. info.si_trapno = regs->u_regs[UREG_G1];
  462. send_sig_info(SIGSYS, &info, current);
  463. if (cnt++ < 4) {
  464. printk("Process makes ni_syscall number %d, register dump:\n",
  465. (int) regs->u_regs[UREG_G1]);
  466. show_regs(regs);
  467. }
  468. unlock_kernel();
  469. return -ENOSYS;
  470. }
  471. /* This is not a real and complete implementation yet, just to keep
  472. * the easy SunOS binaries happy.
  473. */
  474. asmlinkage int sunos_fpathconf(int fd, int name)
  475. {
  476. int ret;
  477. switch(name) {
  478. case _PCONF_LINK:
  479. ret = LINK_MAX;
  480. break;
  481. case _PCONF_CANON:
  482. ret = MAX_CANON;
  483. break;
  484. case _PCONF_INPUT:
  485. ret = MAX_INPUT;
  486. break;
  487. case _PCONF_NAME:
  488. ret = NAME_MAX;
  489. break;
  490. case _PCONF_PATH:
  491. ret = PATH_MAX;
  492. break;
  493. case _PCONF_PIPE:
  494. ret = PIPE_BUF;
  495. break;
  496. case _PCONF_CHRESTRICT: /* XXX Investigate XXX */
  497. ret = 1;
  498. break;
  499. case _PCONF_NOTRUNC: /* XXX Investigate XXX */
  500. case _PCONF_VDISABLE:
  501. ret = 0;
  502. break;
  503. default:
  504. ret = -EINVAL;
  505. break;
  506. }
  507. return ret;
  508. }
  509. asmlinkage int sunos_pathconf(char __user *path, int name)
  510. {
  511. int ret;
  512. ret = sunos_fpathconf(0, name); /* XXX cheese XXX */
  513. return ret;
  514. }
  515. /* SunOS mount system call emulation */
  516. asmlinkage int sunos_select(int width, fd_set __user *inp, fd_set __user *outp,
  517. fd_set __user *exp, struct timeval __user *tvp)
  518. {
  519. int ret;
  520. /* SunOS binaries expect that select won't change the tvp contents */
  521. ret = sys_select (width, inp, outp, exp, tvp);
  522. if (ret == -EINTR && tvp) {
  523. time_t sec, usec;
  524. __get_user(sec, &tvp->tv_sec);
  525. __get_user(usec, &tvp->tv_usec);
  526. if (sec == 0 && usec == 0)
  527. ret = 0;
  528. }
  529. return ret;
  530. }
  531. asmlinkage void sunos_nop(void)
  532. {
  533. return;
  534. }
  535. /* SunOS mount/umount. */
  536. #define SMNT_RDONLY 1
  537. #define SMNT_NOSUID 2
  538. #define SMNT_NEWTYPE 4
  539. #define SMNT_GRPID 8
  540. #define SMNT_REMOUNT 16
  541. #define SMNT_NOSUB 32
  542. #define SMNT_MULTI 64
  543. #define SMNT_SYS5 128
  544. struct sunos_fh_t {
  545. char fh_data [NFS_FHSIZE];
  546. };
  547. struct sunos_nfs_mount_args {
  548. struct sockaddr_in __user *addr; /* file server address */
  549. struct nfs_fh __user *fh; /* File handle to be mounted */
  550. int flags; /* flags */
  551. int wsize; /* write size in bytes */
  552. int rsize; /* read size in bytes */
  553. int timeo; /* initial timeout in .1 secs */
  554. int retrans; /* times to retry send */
  555. char __user *hostname; /* server's hostname */
  556. int acregmin; /* attr cache file min secs */
  557. int acregmax; /* attr cache file max secs */
  558. int acdirmin; /* attr cache dir min secs */
  559. int acdirmax; /* attr cache dir max secs */
  560. char __user *netname; /* server's netname */
  561. };
  562. /* Bind the socket on a local reserved port and connect it to the
  563. * remote server. This on Linux/i386 is done by the mount program,
  564. * not by the kernel.
  565. */
  566. static int
  567. sunos_nfs_get_server_fd (int fd, struct sockaddr_in *addr)
  568. {
  569. struct sockaddr_in local;
  570. struct sockaddr_in server;
  571. int try_port;
  572. struct socket *socket;
  573. struct inode *inode;
  574. struct file *file;
  575. int ret, result = 0;
  576. file = fget(fd);
  577. if (!file)
  578. goto out;
  579. inode = file->f_path.dentry->d_inode;
  580. socket = SOCKET_I(inode);
  581. local.sin_family = AF_INET;
  582. local.sin_addr.s_addr = INADDR_ANY;
  583. /* IPPORT_RESERVED = 1024, can't find the definition in the kernel */
  584. try_port = 1024;
  585. do {
  586. local.sin_port = htons (--try_port);
  587. ret = socket->ops->bind(socket, (struct sockaddr*)&local,
  588. sizeof(local));
  589. } while (ret && try_port > (1024 / 2));
  590. if (ret)
  591. goto out_putf;
  592. server.sin_family = AF_INET;
  593. server.sin_addr = addr->sin_addr;
  594. server.sin_port = NFS_PORT;
  595. /* Call sys_connect */
  596. ret = socket->ops->connect (socket, (struct sockaddr *) &server,
  597. sizeof (server), file->f_flags);
  598. if (ret >= 0)
  599. result = 1;
  600. out_putf:
  601. fput(file);
  602. out:
  603. return result;
  604. }
  605. static int get_default (int value, int def_value)
  606. {
  607. if (value)
  608. return value;
  609. else
  610. return def_value;
  611. }
  612. static int sunos_nfs_mount(char *dir_name, int linux_flags, void __user *data)
  613. {
  614. int server_fd, err;
  615. char *the_name, *mount_page;
  616. struct nfs_mount_data linux_nfs_mount;
  617. struct sunos_nfs_mount_args sunos_mount;
  618. /* Ok, here comes the fun part: Linux's nfs mount needs a
  619. * socket connection to the server, but SunOS mount does not
  620. * require this, so we use the information on the destination
  621. * address to create a socket and bind it to a reserved
  622. * port on this system
  623. */
  624. if (copy_from_user(&sunos_mount, data, sizeof(sunos_mount)))
  625. return -EFAULT;
  626. server_fd = sys_socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  627. if (server_fd < 0)
  628. return -ENXIO;
  629. if (copy_from_user(&linux_nfs_mount.addr,sunos_mount.addr,
  630. sizeof(*sunos_mount.addr)) ||
  631. copy_from_user(&linux_nfs_mount.root,sunos_mount.fh,
  632. sizeof(*sunos_mount.fh))) {
  633. sys_close (server_fd);
  634. return -EFAULT;
  635. }
  636. if (!sunos_nfs_get_server_fd (server_fd, &linux_nfs_mount.addr)){
  637. sys_close (server_fd);
  638. return -ENXIO;
  639. }
  640. /* Now, bind it to a locally reserved port */
  641. linux_nfs_mount.version = NFS_MOUNT_VERSION;
  642. linux_nfs_mount.flags = sunos_mount.flags;
  643. linux_nfs_mount.fd = server_fd;
  644. linux_nfs_mount.rsize = get_default (sunos_mount.rsize, 8192);
  645. linux_nfs_mount.wsize = get_default (sunos_mount.wsize, 8192);
  646. linux_nfs_mount.timeo = get_default (sunos_mount.timeo, 10);
  647. linux_nfs_mount.retrans = sunos_mount.retrans;
  648. linux_nfs_mount.acregmin = sunos_mount.acregmin;
  649. linux_nfs_mount.acregmax = sunos_mount.acregmax;
  650. linux_nfs_mount.acdirmin = sunos_mount.acdirmin;
  651. linux_nfs_mount.acdirmax = sunos_mount.acdirmax;
  652. the_name = getname(sunos_mount.hostname);
  653. if (IS_ERR(the_name))
  654. return PTR_ERR(the_name);
  655. strlcpy(linux_nfs_mount.hostname, the_name,
  656. sizeof(linux_nfs_mount.hostname));
  657. putname (the_name);
  658. mount_page = (char *) get_zeroed_page(GFP_KERNEL);
  659. if (!mount_page)
  660. return -ENOMEM;
  661. memcpy(mount_page, &linux_nfs_mount, sizeof(linux_nfs_mount));
  662. err = do_mount("", dir_name, "nfs", linux_flags, mount_page);
  663. free_page((unsigned long) mount_page);
  664. return err;
  665. }
  666. asmlinkage int
  667. sunos_mount(char __user *type, char __user *dir, int flags, void __user *data)
  668. {
  669. int linux_flags = 0;
  670. int ret = -EINVAL;
  671. char *dev_fname = NULL;
  672. char *dir_page, *type_page;
  673. if (!capable (CAP_SYS_ADMIN))
  674. return -EPERM;
  675. lock_kernel();
  676. /* We don't handle the integer fs type */
  677. if ((flags & SMNT_NEWTYPE) == 0)
  678. goto out;
  679. /* Do not allow for those flags we don't support */
  680. if (flags & (SMNT_GRPID|SMNT_NOSUB|SMNT_MULTI|SMNT_SYS5))
  681. goto out;
  682. if (flags & SMNT_REMOUNT)
  683. linux_flags |= MS_REMOUNT;
  684. if (flags & SMNT_RDONLY)
  685. linux_flags |= MS_RDONLY;
  686. if (flags & SMNT_NOSUID)
  687. linux_flags |= MS_NOSUID;
  688. dir_page = getname(dir);
  689. ret = PTR_ERR(dir_page);
  690. if (IS_ERR(dir_page))
  691. goto out;
  692. type_page = getname(type);
  693. ret = PTR_ERR(type_page);
  694. if (IS_ERR(type_page))
  695. goto out1;
  696. if (strcmp(type_page, "ext2") == 0) {
  697. dev_fname = getname(data);
  698. } else if (strcmp(type_page, "iso9660") == 0) {
  699. dev_fname = getname(data);
  700. } else if (strcmp(type_page, "minix") == 0) {
  701. dev_fname = getname(data);
  702. } else if (strcmp(type_page, "nfs") == 0) {
  703. ret = sunos_nfs_mount (dir_page, flags, data);
  704. goto out2;
  705. } else if (strcmp(type_page, "ufs") == 0) {
  706. printk("Warning: UFS filesystem mounts unsupported.\n");
  707. ret = -ENODEV;
  708. goto out2;
  709. } else if (strcmp(type_page, "proc")) {
  710. ret = -ENODEV;
  711. goto out2;
  712. }
  713. ret = PTR_ERR(dev_fname);
  714. if (IS_ERR(dev_fname))
  715. goto out2;
  716. ret = do_mount(dev_fname, dir_page, type_page, linux_flags, NULL);
  717. if (dev_fname)
  718. putname(dev_fname);
  719. out2:
  720. putname(type_page);
  721. out1:
  722. putname(dir_page);
  723. out:
  724. unlock_kernel();
  725. return ret;
  726. }
  727. asmlinkage int sunos_setpgrp(pid_t pid, pid_t pgid)
  728. {
  729. int ret;
  730. /* So stupid... */
  731. if ((!pid || pid == current->pid) &&
  732. !pgid) {
  733. sys_setsid();
  734. ret = 0;
  735. } else {
  736. ret = sys_setpgid(pid, pgid);
  737. }
  738. return ret;
  739. }
  740. /* So stupid... */
  741. asmlinkage int sunos_wait4(pid_t pid, unsigned int __user *stat_addr,
  742. int options, struct rusage __user*ru)
  743. {
  744. int ret;
  745. ret = sys_wait4((pid ? pid : -1), stat_addr, options, ru);
  746. return ret;
  747. }
  748. extern int kill_pg(int, int, int);
  749. asmlinkage int sunos_killpg(int pgrp, int sig)
  750. {
  751. int ret;
  752. lock_kernel();
  753. ret = kill_pg(pgrp, sig, 0);
  754. unlock_kernel();
  755. return ret;
  756. }
  757. asmlinkage int sunos_audit(void)
  758. {
  759. lock_kernel();
  760. printk ("sys_audit\n");
  761. unlock_kernel();
  762. return -1;
  763. }
  764. asmlinkage unsigned long sunos_gethostid(void)
  765. {
  766. unsigned long ret;
  767. lock_kernel();
  768. ret = ((unsigned long)idprom->id_machtype << 24) |
  769. (unsigned long)idprom->id_sernum;
  770. unlock_kernel();
  771. return ret;
  772. }
  773. /* sysconf options, for SunOS compatibility */
  774. #define _SC_ARG_MAX 1
  775. #define _SC_CHILD_MAX 2
  776. #define _SC_CLK_TCK 3
  777. #define _SC_NGROUPS_MAX 4
  778. #define _SC_OPEN_MAX 5
  779. #define _SC_JOB_CONTROL 6
  780. #define _SC_SAVED_IDS 7
  781. #define _SC_VERSION 8
  782. asmlinkage long sunos_sysconf (int name)
  783. {
  784. long ret;
  785. switch (name){
  786. case _SC_ARG_MAX:
  787. ret = ARG_MAX;
  788. break;
  789. case _SC_CHILD_MAX:
  790. ret = -1; /* no limit */
  791. break;
  792. case _SC_CLK_TCK:
  793. ret = HZ;
  794. break;
  795. case _SC_NGROUPS_MAX:
  796. ret = NGROUPS_MAX;
  797. break;
  798. case _SC_OPEN_MAX:
  799. ret = OPEN_MAX;
  800. break;
  801. case _SC_JOB_CONTROL:
  802. ret = 1; /* yes, we do support job control */
  803. break;
  804. case _SC_SAVED_IDS:
  805. ret = 1; /* yes, we do support saved uids */
  806. break;
  807. case _SC_VERSION:
  808. /* mhm, POSIX_VERSION is in /usr/include/unistd.h
  809. * should it go on /usr/include/linux?
  810. */
  811. ret = 199009L;
  812. break;
  813. default:
  814. ret = -1;
  815. break;
  816. };
  817. return ret;
  818. }
  819. asmlinkage int sunos_semsys(int op, unsigned long arg1, unsigned long arg2,
  820. unsigned long arg3, void *ptr)
  821. {
  822. union semun arg4;
  823. int ret;
  824. switch (op) {
  825. case 0:
  826. /* Most arguments match on a 1:1 basis but cmd doesn't */
  827. switch(arg3) {
  828. case 4:
  829. arg3=GETPID; break;
  830. case 5:
  831. arg3=GETVAL; break;
  832. case 6:
  833. arg3=GETALL; break;
  834. case 3:
  835. arg3=GETNCNT; break;
  836. case 7:
  837. arg3=GETZCNT; break;
  838. case 8:
  839. arg3=SETVAL; break;
  840. case 9:
  841. arg3=SETALL; break;
  842. }
  843. /* sys_semctl(): */
  844. /* value to modify semaphore to */
  845. arg4.__pad = (void __user *) ptr;
  846. ret = sys_semctl((int)arg1, (int)arg2, (int)arg3, arg4 );
  847. break;
  848. case 1:
  849. /* sys_semget(): */
  850. ret = sys_semget((key_t)arg1, (int)arg2, (int)arg3);
  851. break;
  852. case 2:
  853. /* sys_semop(): */
  854. ret = sys_semop((int)arg1, (struct sembuf __user *)arg2, (unsigned)arg3);
  855. break;
  856. default:
  857. ret = -EINVAL;
  858. break;
  859. };
  860. return ret;
  861. }
  862. asmlinkage int sunos_msgsys(int op, unsigned long arg1, unsigned long arg2,
  863. unsigned long arg3, unsigned long arg4)
  864. {
  865. struct sparc_stackf *sp;
  866. unsigned long arg5;
  867. int rval;
  868. switch(op) {
  869. case 0:
  870. rval = sys_msgget((key_t)arg1, (int)arg2);
  871. break;
  872. case 1:
  873. rval = sys_msgctl((int)arg1, (int)arg2,
  874. (struct msqid_ds __user *)arg3);
  875. break;
  876. case 2:
  877. lock_kernel();
  878. sp = (struct sparc_stackf *)current->thread.kregs->u_regs[UREG_FP];
  879. arg5 = sp->xxargs[0];
  880. unlock_kernel();
  881. rval = sys_msgrcv((int)arg1, (struct msgbuf __user *)arg2,
  882. (size_t)arg3, (long)arg4, (int)arg5);
  883. break;
  884. case 3:
  885. rval = sys_msgsnd((int)arg1, (struct msgbuf __user *)arg2,
  886. (size_t)arg3, (int)arg4);
  887. break;
  888. default:
  889. rval = -EINVAL;
  890. break;
  891. }
  892. return rval;
  893. }
  894. asmlinkage int sunos_shmsys(int op, unsigned long arg1, unsigned long arg2,
  895. unsigned long arg3)
  896. {
  897. unsigned long raddr;
  898. int rval;
  899. switch(op) {
  900. case 0:
  901. /* do_shmat(): attach a shared memory area */
  902. rval = do_shmat((int)arg1,(char __user *)arg2,(int)arg3,&raddr);
  903. if (!rval)
  904. rval = (int) raddr;
  905. break;
  906. case 1:
  907. /* sys_shmctl(): modify shared memory area attr. */
  908. rval = sys_shmctl((int)arg1,(int)arg2,(struct shmid_ds __user *)arg3);
  909. break;
  910. case 2:
  911. /* sys_shmdt(): detach a shared memory area */
  912. rval = sys_shmdt((char __user *)arg1);
  913. break;
  914. case 3:
  915. /* sys_shmget(): get a shared memory area */
  916. rval = sys_shmget((key_t)arg1,(int)arg2,(int)arg3);
  917. break;
  918. default:
  919. rval = -EINVAL;
  920. break;
  921. };
  922. return rval;
  923. }
  924. #define SUNOS_EWOULDBLOCK 35
  925. /* see the sunos man page read(2v) for an explanation
  926. of this garbage. We use O_NDELAY to mark
  927. file descriptors that have been set non-blocking
  928. using 4.2BSD style calls. (tridge) */
  929. static inline int check_nonblock(int ret, int fd)
  930. {
  931. if (ret == -EAGAIN) {
  932. struct file * file = fget(fd);
  933. if (file) {
  934. if (file->f_flags & O_NDELAY)
  935. ret = -SUNOS_EWOULDBLOCK;
  936. fput(file);
  937. }
  938. }
  939. return ret;
  940. }
  941. asmlinkage int sunos_read(unsigned int fd, char __user *buf, int count)
  942. {
  943. int ret;
  944. ret = check_nonblock(sys_read(fd,buf,count),fd);
  945. return ret;
  946. }
  947. asmlinkage int sunos_readv(unsigned long fd, const struct iovec __user *vector,
  948. long count)
  949. {
  950. int ret;
  951. ret = check_nonblock(sys_readv(fd,vector,count),fd);
  952. return ret;
  953. }
  954. asmlinkage int sunos_write(unsigned int fd, char __user *buf, int count)
  955. {
  956. int ret;
  957. ret = check_nonblock(sys_write(fd,buf,count),fd);
  958. return ret;
  959. }
  960. asmlinkage int sunos_writev(unsigned long fd,
  961. const struct iovec __user *vector, long count)
  962. {
  963. int ret;
  964. ret = check_nonblock(sys_writev(fd,vector,count),fd);
  965. return ret;
  966. }
  967. asmlinkage int sunos_recv(int fd, void __user *ubuf, int size, unsigned flags)
  968. {
  969. int ret;
  970. ret = check_nonblock(sys_recv(fd,ubuf,size,flags),fd);
  971. return ret;
  972. }
  973. asmlinkage int sunos_send(int fd, void __user *buff, int len, unsigned flags)
  974. {
  975. int ret;
  976. ret = check_nonblock(sys_send(fd,buff,len,flags),fd);
  977. return ret;
  978. }
  979. asmlinkage int sunos_accept(int fd, struct sockaddr __user *sa,
  980. int __user *addrlen)
  981. {
  982. int ret;
  983. while (1) {
  984. ret = check_nonblock(sys_accept(fd,sa,addrlen),fd);
  985. if (ret != -ENETUNREACH && ret != -EHOSTUNREACH)
  986. break;
  987. }
  988. return ret;
  989. }
  990. #define SUNOS_SV_INTERRUPT 2
  991. asmlinkage int
  992. sunos_sigaction(int sig, const struct old_sigaction __user *act,
  993. struct old_sigaction __user *oact)
  994. {
  995. struct k_sigaction new_ka, old_ka;
  996. int ret;
  997. if (act) {
  998. old_sigset_t mask;
  999. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  1000. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  1001. __get_user(new_ka.sa.sa_flags, &act->sa_flags))
  1002. return -EFAULT;
  1003. __get_user(mask, &act->sa_mask);
  1004. new_ka.sa.sa_restorer = NULL;
  1005. new_ka.ka_restorer = NULL;
  1006. siginitset(&new_ka.sa.sa_mask, mask);
  1007. new_ka.sa.sa_flags ^= SUNOS_SV_INTERRUPT;
  1008. }
  1009. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  1010. if (!ret && oact) {
  1011. /* In the clone() case we could copy half consistent
  1012. * state to the user, however this could sleep and
  1013. * deadlock us if we held the signal lock on SMP. So for
  1014. * now I take the easy way out and do no locking.
  1015. * But then again we don't support SunOS lwp's anyways ;-)
  1016. */
  1017. old_ka.sa.sa_flags ^= SUNOS_SV_INTERRUPT;
  1018. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  1019. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  1020. __put_user(old_ka.sa.sa_flags, &oact->sa_flags))
  1021. return -EFAULT;
  1022. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  1023. }
  1024. return ret;
  1025. }
  1026. asmlinkage int sunos_setsockopt(int fd, int level, int optname,
  1027. char __user *optval, int optlen)
  1028. {
  1029. int tr_opt = optname;
  1030. int ret;
  1031. if (level == SOL_IP) {
  1032. /* Multicast socketopts (ttl, membership) */
  1033. if (tr_opt >=2 && tr_opt <= 6)
  1034. tr_opt += 30;
  1035. }
  1036. ret = sys_setsockopt(fd, level, tr_opt, optval, optlen);
  1037. return ret;
  1038. }
  1039. asmlinkage int sunos_getsockopt(int fd, int level, int optname,
  1040. char __user *optval, int __user *optlen)
  1041. {
  1042. int tr_opt = optname;
  1043. int ret;
  1044. if (level == SOL_IP) {
  1045. /* Multicast socketopts (ttl, membership) */
  1046. if (tr_opt >=2 && tr_opt <= 6)
  1047. tr_opt += 30;
  1048. }
  1049. ret = sys_getsockopt(fd, level, tr_opt, optval, optlen);
  1050. return ret;
  1051. }