sys_sunos.c 28 KB

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