This source file includes following definitions.
- hpux_sys_creat
- hpux_sys_open
- hpux_sys_fcntl
- hpux_sys_fstat
- hpux_sys_stat
- hpux_sys_lstat
- hpux_stat1
- hpux_sys_fstat_6x
- hpux_sys_stat_6x
- bsd_to_hpux_ostat
- bsd_to_hpux_stat
- hpux_sys_access
- hpux_sys_unlink
- hpux_sys_chdir
- hpux_sys_mknod
- hpux_sys_chmod
- hpux_sys_chown
- hpux_sys_rename
- hpux_sys_mkdir
- hpux_sys_rmdir
- hpux_sys_symlink
- hpux_sys_readlink
- hpux_sys_truncate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/signalvar.h>
51 #include <sys/kernel.h>
52 #include <sys/filedesc.h>
53 #include <sys/proc.h>
54 #include <sys/buf.h>
55 #include <sys/wait.h>
56 #include <sys/file.h>
57 #include <sys/namei.h>
58 #include <sys/vnode.h>
59 #include <sys/ioctl.h>
60 #include <sys/ptrace.h>
61 #include <sys/stat.h>
62 #include <sys/syslog.h>
63 #include <sys/malloc.h>
64 #include <sys/mount.h>
65 #include <sys/ipc.h>
66 #include <sys/user.h>
67 #include <sys/mman.h>
68
69 #include <machine/cpu.h>
70 #include <machine/reg.h>
71 #include <machine/psl.h>
72 #include <machine/vmparam.h>
73
74 #include <sys/syscallargs.h>
75
76 #include <compat/hpux/hpux.h>
77 #include <compat/hpux/hpux_util.h>
78 #include <compat/hpux/hpux_termio.h>
79 #include <compat/hpux/hpux_syscall.h>
80 #include <compat/hpux/hpux_syscallargs.h>
81
82 #include <machine/hpux_machdep.h>
83
84 int hpux_stat1(struct proc *, void *, register_t *, int);
85 void bsd_to_hpux_stat(struct stat *, struct hpux_stat *);
86 void bsd_to_hpux_ostat(struct stat *, struct hpux_ostat *);
87
88
89
90
91
92
93 int
94 hpux_sys_creat(p, v, retval)
95 struct proc *p;
96 void *v;
97 register_t *retval;
98 {
99 struct hpux_sys_creat_args
100
101
102 *uap = v;
103
104 struct sys_open_args oa;
105 caddr_t sg;
106
107 sg = stackgap_init(p->p_emul);
108 HPUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
109
110 SCARG(&oa, path) = SCARG(uap, path);
111 SCARG(&oa, flags) = O_CREAT | O_TRUNC | O_WRONLY;
112 SCARG(&oa, mode) = SCARG(uap, mode);
113
114 return sys_open(p, &oa, retval);
115 }
116
117
118
119
120
121
122
123
124
125
126
127 int
128 hpux_sys_open(p, v, retval)
129 struct proc *p;
130 void *v;
131 register_t *retval;
132 {
133 struct hpux_sys_open_args
134
135
136
137 *uap = v;
138 struct sys_open_args oa;
139 int flags, nflags, error;
140 caddr_t sg;
141
142 sg = stackgap_init(p->p_emul);
143
144
145
146
147
148 flags = SCARG(uap, flags);
149 nflags =
150 flags & ~(HPUXNONBLOCK|HPUXFSYNCIO|HPUXFEXCL|HPUXFTRUNC|HPUXFCREAT);
151 if (flags & HPUXFCREAT) {
152
153
154
155
156
157
158 if ((flags & HPUXFEXCL) || (FFLAGS(flags) & FWRITE))
159 nflags |= O_CREAT;
160 }
161 if (flags & HPUXFTRUNC)
162 nflags |= O_TRUNC;
163 if (flags & HPUXFEXCL)
164 nflags |= O_EXCL;
165 if (flags & HPUXNONBLOCK)
166 nflags |= O_NDELAY;
167
168
169
170
171 if (SCARG(&oa, flags) & O_CREAT)
172 HPUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
173 else
174 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
175
176
177
178
179 SCARG(&oa, path) = SCARG(uap, path);
180 SCARG(&oa, flags) = nflags;
181 SCARG(&oa, mode) = SCARG(uap, mode);
182
183 error = sys_open(p, &oa, retval);
184
185
186
187
188 if ((error == 0) && (nflags & O_NDELAY))
189 p->p_fd->fd_ofileflags[*retval] |=
190 (flags & HPUXNONBLOCK) ?
191 HPUX_UF_NONBLOCK_ON : HPUX_UF_FNDELAY_ON;
192
193 return (error);
194 }
195
196
197
198
199 int
200 hpux_sys_fcntl(p, v, retval)
201 struct proc *p;
202 void *v;
203 register_t *retval;
204 {
205 struct hpux_sys_fcntl_args
206
207
208
209 *uap = v;
210 int arg, mode, error, flg = F_POSIX;
211 struct file *fp;
212 char *pop;
213 struct hpux_flock hfl;
214 struct flock fl;
215 struct vnode *vp;
216 struct sys_fcntl_args fa;
217 struct filedesc *fdp = p->p_fd;
218
219 if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
220 return (EBADF);
221 FREF(fp);
222
223 pop = &p->p_fd->fd_ofileflags[SCARG(uap, fd)];
224 arg = SCARG(uap, arg);
225
226 switch (SCARG(uap, cmd)) {
227 case F_SETFL:
228 if (arg & HPUXNONBLOCK)
229 *pop |= HPUX_UF_NONBLOCK_ON;
230 else
231 *pop &= ~HPUX_UF_NONBLOCK_ON;
232
233 if (arg & HPUXNDELAY)
234 *pop |= HPUX_UF_FNDELAY_ON;
235 else
236 *pop &= ~HPUX_UF_FNDELAY_ON;
237
238 if (*pop & (HPUX_UF_NONBLOCK_ON|HPUX_UF_FNDELAY_ON|HPUX_UF_FIONBIO_ON))
239 arg |= FNONBLOCK;
240 else
241 arg &= ~FNONBLOCK;
242
243 arg &= ~(HPUXNONBLOCK|HPUXFSYNCIO|HPUXFREMOTE);
244 break;
245
246 case F_GETFL:
247 case F_DUPFD:
248 case F_GETFD:
249 case F_SETFD:
250 break;
251
252 case HPUXF_SETLKW:
253 flg |= F_WAIT;
254
255
256 case HPUXF_SETLK:
257 if (fp->f_type != DTYPE_VNODE) {
258 error = EBADF;
259 goto out;
260 }
261
262 vp = (struct vnode *)fp->f_data;
263
264
265 error = copyin((caddr_t)SCARG(uap, arg), (caddr_t)&hfl,
266 sizeof (hfl));
267 if (error)
268 goto out;
269
270 fl.l_start = hfl.hl_start;
271 fl.l_len = hfl.hl_len;
272 fl.l_pid = hfl.hl_pid;
273 fl.l_type = hfl.hl_type;
274 fl.l_whence = hfl.hl_whence;
275 if (fl.l_whence == SEEK_CUR)
276 fl.l_start += fp->f_offset;
277
278 switch (fl.l_type) {
279 case F_RDLCK:
280 if ((fp->f_flag & FREAD) == 0) {
281 error = EBADF;
282 goto out;
283 }
284
285 atomic_setbits_int(&p->p_flag, P_ADVLOCK);
286 error = VOP_ADVLOCK(vp, (caddr_t)p, F_SETLK, &fl, flg);
287 goto out;
288
289 case F_WRLCK:
290 if ((fp->f_flag & FWRITE) == 0) {
291 error = EBADF;
292 goto out;
293 }
294 atomic_setbits_int(&p->p_flag, P_ADVLOCK);
295 error = VOP_ADVLOCK(vp, (caddr_t)p, F_SETLK, &fl, flg);
296 goto out;
297
298 case F_UNLCK:
299 error = VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &fl,
300 F_POSIX);
301 goto out;
302
303 default:
304 error = EINVAL;
305 goto out;
306 }
307
308
309 case F_GETLK:
310 if (fp->f_type != DTYPE_VNODE) {
311 error = EBADF;
312 goto out;
313 }
314
315 vp = (struct vnode *)fp->f_data;
316
317
318 error = copyin((caddr_t)SCARG(uap, arg), (caddr_t)&hfl,
319 sizeof (hfl));
320 if (error)
321 goto out;
322
323 fl.l_start = hfl.hl_start;
324 fl.l_len = hfl.hl_len;
325 fl.l_pid = hfl.hl_pid;
326 fl.l_type = hfl.hl_type;
327 fl.l_whence = hfl.hl_whence;
328 if (fl.l_whence == SEEK_CUR)
329 fl.l_start += fp->f_offset;
330
331 if ((error =
332 VOP_ADVLOCK(vp, (caddr_t)p, F_GETLK, &fl, F_POSIX)))
333 goto out;
334
335 hfl.hl_start = fl.l_start;
336 hfl.hl_len = fl.l_len;
337 hfl.hl_pid = fl.l_pid;
338 hfl.hl_type = fl.l_type;
339 hfl.hl_whence = fl.l_whence;
340 error = copyout((caddr_t)&hfl, (caddr_t)SCARG(uap, arg),
341 sizeof (hfl));
342 goto out;
343
344 default:
345 error = EINVAL;
346 goto out;
347 }
348
349
350
351
352 SCARG(&fa, fd) = SCARG(uap, fd);
353 SCARG(&fa, cmd) = SCARG(uap, cmd);
354 SCARG(&fa, arg) = (void *)arg;
355
356 error = sys_fcntl(p, &fa, retval);
357
358 if ((error == 0) && (SCARG(&fa, cmd) == F_GETFL)) {
359 mode = *retval;
360 *retval &= ~(O_CREAT|O_TRUNC|O_EXCL);
361 if (mode & FNONBLOCK) {
362 if (*pop & HPUX_UF_NONBLOCK_ON)
363 *retval |= HPUXNONBLOCK;
364
365 if ((*pop & HPUX_UF_FNDELAY_ON) == 0)
366 *retval &= ~HPUXNDELAY;
367 }
368 if (mode & O_CREAT)
369 *retval |= HPUXFCREAT;
370
371 if (mode & O_TRUNC)
372 *retval |= HPUXFTRUNC;
373
374 if (mode & O_EXCL)
375 *retval |= HPUXFEXCL;
376 }
377 out:
378 FRELE(fp);
379 return (error);
380 }
381
382
383
384
385 int
386 hpux_sys_fstat(p, v, retval)
387 struct proc *p;
388 void *v;
389 register_t *retval;
390 {
391 struct hpux_sys_fstat_args
392
393
394 *uap = v;
395 struct sys_fstat_args fsa;
396 struct hpux_stat tmphst;
397 struct stat *st, tmpst;
398 caddr_t sg;
399 int error;
400
401 sg = stackgap_init(p->p_emul);
402
403 st = stackgap_alloc(&sg, sizeof (struct stat));
404
405 SCARG(&fsa, fd) = SCARG(uap, fd);
406 SCARG(&fsa, sb) = st;
407
408 if ((error = sys_fstat(p, &fsa, retval)))
409 return (error);
410
411 if ((error = copyin(st, &tmpst, sizeof(tmpst))))
412 return (error);
413
414 bsd_to_hpux_stat(&tmpst, &tmphst);
415
416 return (copyout(&tmphst, SCARG(uap, sb), sizeof(struct hpux_stat)));
417 }
418
419
420
421
422 int
423 hpux_sys_stat(p, v, retval)
424 struct proc *p;
425 void *v;
426 register_t *retval;
427 {
428
429 return (hpux_stat1(p, v, retval, 0));
430 }
431
432
433
434
435 int
436 hpux_sys_lstat(p, v, retval)
437 struct proc *p;
438 void *v;
439 register_t *retval;
440 {
441
442 return (hpux_stat1(p, v, retval, 1));
443 }
444
445
446
447
448 int
449 hpux_stat1(p, v, retval, dolstat)
450 struct proc *p;
451 void *v;
452 register_t *retval;
453 int dolstat;
454 {
455 struct hpux_sys_stat_args
456
457
458 *uap = v;
459 struct sys_stat_args sa;
460 struct hpux_stat tmphst;
461 struct stat *st, tmpst;
462 caddr_t sg;
463 int error;
464
465 sg = stackgap_init(p->p_emul);
466
467 st = stackgap_alloc(&sg, sizeof (struct stat));
468 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
469
470 SCARG(&sa, ub) = st;
471 SCARG(&sa, path) = SCARG(uap, path);
472
473 if (dolstat)
474 error = sys_lstat(p, &sa, retval);
475 else
476 error = sys_stat(p, &sa, retval);
477
478 if (error)
479 return (error);
480
481 if ((error = copyin(st, &tmpst, sizeof(tmpst))))
482 return (error);
483
484 bsd_to_hpux_stat(&tmpst, &tmphst);
485
486 return (copyout(&tmphst, SCARG(uap, sb), sizeof(struct hpux_stat)));
487 }
488
489 #ifndef __hppa__
490
491
492
493 int
494 hpux_sys_fstat_6x(p, v, retval)
495 struct proc *p;
496 void *v;
497 register_t *retval;
498 {
499 struct hpux_sys_fstat_6x_args
500
501
502 *uap = v;
503 struct sys_fstat_args fsa;
504 struct hpux_ostat tmphst;
505 struct stat *st, tmpst;
506 caddr_t sg;
507 int error;
508
509 sg = stackgap_init(p->p_emul);
510
511 st = stackgap_alloc(&sg, sizeof (struct stat));
512
513 SCARG(&fsa, fd) = SCARG(uap, fd);
514 SCARG(&fsa, sb) = st;
515
516 if ((error = sys_fstat(p, &fsa, retval)))
517 return (error);
518
519 if ((error = copyin(st, &tmpst, sizeof(tmpst))))
520 return (error);
521
522 bsd_to_hpux_ostat(&tmpst, &tmphst);
523
524 return (copyout(&tmphst, SCARG(uap, sb), sizeof(struct hpux_ostat)));
525 }
526
527
528
529
530 int
531 hpux_sys_stat_6x(p, v, retval)
532 struct proc *p;
533 void *v;
534 register_t *retval;
535 {
536 struct hpux_sys_stat_6x_args
537
538
539 *uap = v;
540 struct sys_stat_args sa;
541 struct hpux_ostat tmphst;
542 struct stat *st, tmpst;
543 caddr_t sg;
544 int error;
545
546 sg = stackgap_init(p->p_emul);
547
548 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
549
550 st = stackgap_alloc(&sg, sizeof (struct stat));
551 SCARG(&sa, ub) = st;
552 SCARG(&sa, path) = SCARG(uap, path);
553
554 if ((error = sys_stat(p, &sa, retval)))
555 return (error);
556
557 if ((error = copyin(st, &tmpst, sizeof(tmpst))))
558 return (error);
559
560 bsd_to_hpux_ostat(&tmpst, &tmphst);
561
562 return (copyout(&tmphst, SCARG(uap, sb), sizeof(struct hpux_ostat)));
563 }
564
565
566
567
568 void
569 bsd_to_hpux_ostat(sb, hsb)
570 struct stat *sb;
571 struct hpux_ostat *hsb;
572 {
573
574 bzero(hsb, sizeof(struct hpux_ostat));
575 hsb->hst_dev = (u_short)sb->st_dev;
576 hsb->hst_ino = (u_short)sb->st_ino;
577 hsb->hst_mode = (u_short)sb->st_mode;
578 hsb->hst_nlink = (u_short)sb->st_nlink;
579 hsb->hst_uid = (u_short)sb->st_uid;
580 hsb->hst_gid = (u_short)sb->st_gid;
581 hsb->hst_rdev = (u_short)sb->st_rdev;
582 if (sb->st_size < (off_t)(((off_t)1) << 32))
583 hsb->hst_size = (int)sb->st_size;
584 else
585 hsb->hst_size = -2;
586 hsb->hst_atime = (int)sb->st_atime;
587 hsb->hst_mtime = (int)sb->st_mtime;
588 hsb->hst_ctime = (int)sb->st_ctime;
589 }
590 #endif
591
592
593
594
595 void
596 bsd_to_hpux_stat(sb, hsb)
597 struct stat *sb;
598 struct hpux_stat *hsb;
599 {
600
601 bzero((caddr_t)hsb, sizeof(struct hpux_stat));
602 hsb->hst_dev = (long)sb->st_dev;
603 hsb->hst_ino = (u_long)sb->st_ino;
604 hsb->hst_mode = (u_short)sb->st_mode;
605 hsb->hst_nlink = (u_short)sb->st_nlink;
606 hsb->hst_uid = (u_long)sb->st_uid;
607 hsb->hst_gid = (u_long)sb->st_gid;
608 hsb->hst_rdev = (long)bsdtohpuxdev(sb->st_rdev);
609
610
611
612 hsb->hst_old_uid = (u_short)sb->st_uid;
613 hsb->hst_old_gid = (u_short)sb->st_gid;
614
615 if (sb->st_size < (off_t)(((off_t)1) << 32))
616 hsb->hst_size = (long)sb->st_size;
617 else
618 hsb->hst_size = -2;
619 hsb->hst_atime = (long)sb->st_atime;
620 hsb->hst_mtime = (long)sb->st_mtime;
621 hsb->hst_ctime = (long)sb->st_ctime;
622 hsb->hst_blksize = (long)sb->st_blksize;
623 hsb->hst_blocks = (long)sb->st_blocks;
624 }
625
626
627
628
629 int
630 hpux_sys_access(p, v, retval)
631 struct proc *p;
632 void *v;
633 register_t *retval;
634 {
635 struct hpux_sys_access_args
636
637
638 *uap = v;
639 caddr_t sg = stackgap_init(p->p_emul);
640
641 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
642
643 return (sys_access(p, uap, retval));
644 }
645
646
647
648
649 int
650 hpux_sys_unlink(p, v, retval)
651 struct proc *p;
652 void *v;
653 register_t *retval;
654 {
655 struct hpux_sys_unlink_args
656
657 *uap = v;
658 caddr_t sg = stackgap_init(p->p_emul);
659
660 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
661
662 return (sys_unlink(p, uap, retval));
663 }
664
665
666
667
668 int
669 hpux_sys_chdir(p, v, retval)
670 struct proc *p;
671 void *v;
672 register_t *retval;
673 {
674 struct hpux_sys_chdir_args
675
676 *uap = v;
677 caddr_t sg = stackgap_init(p->p_emul);
678
679 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
680
681 return (sys_chdir(p, uap, retval));
682 }
683
684
685
686
687 int
688 hpux_sys_mknod(p, v, retval)
689 struct proc *p;
690 void *v;
691 register_t *retval;
692 {
693 struct hpux_sys_mknod_args
694
695
696
697 *uap = v;
698 caddr_t sg = stackgap_init(p->p_emul);
699 struct sys_mkfifo_args bma;
700
701 HPUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
702
703
704
705
706 if (S_ISFIFO(SCARG(uap, mode))) {
707 SCARG(&bma, path) = SCARG(uap, path);
708 SCARG(&bma, mode) = SCARG(uap, mode);
709 return (sys_mkfifo(p, uap, retval));
710 } else
711 return (sys_mknod(p, uap, retval));
712 }
713
714
715
716
717 int
718 hpux_sys_chmod(p, v, retval)
719 struct proc *p;
720 void *v;
721 register_t *retval;
722 {
723 struct hpux_sys_chmod_args
724
725
726 *uap = v;
727 caddr_t sg = stackgap_init(p->p_emul);
728
729 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
730
731 return (sys_chmod(p, uap, retval));
732 }
733
734
735
736
737 int
738 hpux_sys_chown(p, v, retval)
739 struct proc *p;
740 void *v;
741 register_t *retval;
742 {
743 struct hpux_sys_chown_args
744
745
746
747 *uap = v;
748 caddr_t sg = stackgap_init(p->p_emul);
749
750 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
751
752
753
754 return (sys_lchown(p, uap, retval));
755 }
756
757
758
759
760 int
761 hpux_sys_rename(p, v, retval)
762 struct proc *p;
763 void *v;
764 register_t *retval;
765 {
766 struct hpux_sys_rename_args
767
768
769 *uap = v;
770 caddr_t sg = stackgap_init(p->p_emul);
771
772 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, from));
773 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, to));
774
775 return (sys_rename(p, uap, retval));
776 }
777
778
779
780
781 int
782 hpux_sys_mkdir(p, v, retval)
783 struct proc *p;
784 void *v;
785 register_t *retval;
786 {
787 struct hpux_sys_mkdir_args
788
789
790 *uap = v;
791 caddr_t sg = stackgap_init(p->p_emul);
792
793 HPUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
794
795 return (sys_mkdir(p, uap, retval));
796 }
797
798
799
800
801 int
802 hpux_sys_rmdir(p, v, retval)
803 struct proc *p;
804 void *v;
805 register_t *retval;
806 {
807 struct hpux_sys_rmdir_args
808
809 *uap = v;
810 caddr_t sg = stackgap_init(p->p_emul);
811
812 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
813
814 return (sys_rmdir(p, uap, retval));
815 }
816
817
818
819
820 int
821 hpux_sys_symlink(p, v, retval)
822 struct proc *p;
823 void *v;
824 register_t *retval;
825 {
826 struct hpux_sys_symlink_args
827
828
829 *uap = v;
830 caddr_t sg = stackgap_init(p->p_emul);
831
832 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
833 HPUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, link));
834
835 return (sys_symlink(p, uap, retval));
836 }
837
838
839
840
841 int
842 hpux_sys_readlink(p, v, retval)
843 struct proc *p;
844 void *v;
845 register_t *retval;
846 {
847 struct hpux_sys_readlink_args
848
849
850
851 *uap = v;
852 caddr_t sg = stackgap_init(p->p_emul);
853
854 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
855
856 return (sys_readlink(p, uap, retval));
857 }
858
859
860
861
862 int
863 hpux_sys_truncate(p, v, retval)
864 struct proc *p;
865 void *v;
866 register_t *retval;
867 {
868 struct hpux_sys_truncate_args
869
870
871 *uap = v;
872 caddr_t sg = stackgap_init(p->p_emul);
873
874 HPUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
875
876 return (compat_43_sys_truncate(p, uap, retval));
877 }