Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afs / UKERNEL / sysincludes.h
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10 #ifndef __AFS_SYSINCLUDESH__
11 #define __AFS_SYSINCLUDESH__ 1
12
13 #include <stdio.h>
14 #include <afs/opr.h>
15
16 #if !defined(AFS_USR_DARWIN_ENV) && !defined(AFS_USR_FBSD_ENV) && !defined(AFS_USR_DFBSD_ENV) /* must be included after KERNEL undef'd */
17 #include <errno.h>
18 #endif
19 #include <stdlib.h>
20 #include <string.h>
21 #include <limits.h>
22 #include <assert.h>
23 #include <stdarg.h>
24
25 #if !defined(AFS_USR_DARWIN_ENV) && !defined(AFS_USR_FBSD_ENV) && !defined(AFS_USR_DFBSD_ENV) /* must be included after KERNEL undef'd */
26 #include <unistd.h>
27 #include <ctype.h>
28 #include <sys/types.h>
29 #include <dirent.h>
30 #include <setjmp.h>
31 #endif
32
33 #ifdef AFS_USR_SUN5_ENV
34 #include <signal.h>
35 #include <sys/param.h>
36 #include <sys/socket.h>
37 #include <net/if.h>
38 #include <sys/sockio.h>
39 #include <sys/file.h>
40 #include <sys/stat.h>
41 #include <sys/fcntl.h>
42 #include <netinet/in.h>
43 #include <netdb.h>
44 #include <arpa/inet.h>
45 #endif /* AFS_USR_SUN5_ENV */
46
47
48 #ifdef AFS_USR_AIX_ENV
49 #include <sys/param.h>
50 #include <sys/socket.h>
51 #include <net/if.h>
52 #include <fcntl.h>
53 #include <netinet/in.h>
54 #include <sys/stropts.h>
55 #include <netdb.h>
56 #include <sys/timers.h>
57 #include <arpa/inet.h>
58 #endif /* AFS_USR_AIX_ENV */
59
60 #ifdef AFS_USR_SGI_ENV
61 #include <sys/param.h>
62 #include <sys/socket.h>
63 #include <net/if.h>
64 #include <sys/sockio.h>
65 #include <sys/file.h>
66 #include <sys/stat.h>
67 #include <sys/fcntl.h>
68 #include <netinet/in.h>
69 #include <netdb.h>
70 #include <arpa/inet.h>
71 #endif /* AFS_USR_SGI_ENV */
72
73 #ifdef AFS_USR_HPUX_ENV
74 #include <sys/param.h>
75 #include <sys/socket.h>
76 #include <net/if.h>
77 #include <sys/file.h>
78 #include <sys/stat.h>
79 #include <sys/fcntl.h>
80 #include <netinet/in.h>
81 #include <netdb.h>
82 #include <arpa/inet.h>
83 #endif /* AFS_USR_HPUX_ENV */
84
85 #ifdef AFS_USR_OSF_ENV
86 #ifdef KERNEL
87 #undef KERNEL
88 #define AFS_USR_UNDEF_KERNEL_ENV 1
89 #endif
90 #include <sys/param.h>
91 #include <sys/socket.h>
92 #include <net/if.h>
93 #include <sys/file.h>
94 #include <sys/ioctl.h>
95 #include <sys/stat.h>
96 #include <sys/fcntl.h>
97 #include <netinet/in.h>
98 #include <netdb.h>
99 #include <arpa/inet.h>
100 #endif /* AFS_USR_OSF_ENV */
101
102 #ifdef AFS_USR_LINUX22_ENV
103 #include <sys/ioctl.h> /* _IOW() */
104 #include <sys/uio.h> /* struct iovec */
105 #include <sys/time.h> /* struct timeval */
106 #include <sys/param.h>
107 #include <sys/types.h>
108 #include <sys/socket.h>
109 #include <net/if.h>
110 #include <sys/file.h>
111 #include <sys/stat.h>
112 #include <sys/fcntl.h>
113 #include <netinet/in.h>
114 #include <netdb.h>
115 #include <arpa/inet.h>
116 #define FREAD 0x0001
117 #endif /* AFS_USR_LINUX22_ENV */
118
119 #if defined(AFS_USR_DARWIN_ENV) || defined(AFS_USR_FBSD_ENV) || defined(AFS_USR_DFBSD_ENV)
120 #ifdef _KERNEL
121 #undef _KERNEL
122 #endif
123 #ifdef KERNEL
124 #undef KERNEL
125 #define AFS_USR_UNDEF_KERNEL_ENV 1
126 #endif
127 #include <errno.h>
128 #include <setjmp.h>
129 #include <sys/param.h>
130 #include <sys/types.h>
131 #include <sys/socket.h>
132 #include <net/if.h>
133 #include <sys/file.h>
134 #include <sys/ioctl.h>
135 #include <sys/stat.h>
136 #include <sys/fcntl.h>
137 #include <sys/uio.h>
138 #include <netinet/in.h>
139 #include <netdb.h>
140 #include <arpa/inet.h>
141 #include <dirent.h>
142 #include <ctype.h>
143 #include <unistd.h>
144 #ifndef O_SYNC
145 #define O_SYNC O_FSYNC
146 #endif
147 #endif /* AFS_USR_DARWIN_ENV || AFS_USR_FBSD_ENV */
148
149 #ifdef HAVE_SYS_BITYPES_H
150 #include <sys/bitypes.h>
151 #endif
152 #ifdef HAVE_SYS_STATFS_H
153 #include <sys/statfs.h>
154 #endif
155 #ifdef HAVE_SYS_STATVFS_H
156 #include <sys/statvfs.h>
157 #endif
158
159 #ifndef HAVE_FSBLKCNT_T
160 typedef unsigned int fsblkcnt_t;
161 #endif
162
163 #include <arpa/nameser.h>
164 #ifdef HAVE_ARPA_NAMESER_COMPAT_H
165 #include <arpa/nameser_compat.h>
166 #endif
167 #include <resolv.h>
168
169 /* glibc 2.2 has pthread_attr_setstacksize */
170 #if (defined(AFS_LINUX22_ENV) && !defined(AFS_USR_LINUX22_ENV)) || (defined(AFS_USR_LINUX22_ENV) && (__GLIBC_MINOR__ < 2))
171 #define pthread_attr_setstacksize(a,b) 0
172 #endif
173
174 #include <sys/stat.h> /* afs_usrops.h uses struct stat in prototypes */
175
176 #include <pthread.h>
177
178 #ifdef AFS_USR_UNDEF_KERNEL_ENV
179 #undef AFS_USR_UNDEF_KERNEL_ENV
180 #define KERNEL 1
181 #endif
182
183 /*
184 * User space versions of kernel data structures.
185 */
186
187 #ifndef MAXNAMLEN
188 #define MAXNAMLEN 512
189 #endif
190
191 /*
192 * This file contains data types and definitions for running
193 * the AFS client in user space. Kernel data structures
194 * are renamed from XXXX to usr_XXXX.
195 */
196
197 #ifdef UKERNEL
198
199 #undef socket
200 #undef flock
201
202 #if defined(AFS_USR_DARWIN_ENV) || defined(AFS_USR_FBSD_ENV)
203 #undef if_mtu
204 #undef if_metric
205 #endif
206
207 #define mount usr_mount
208 #define fs usr_fs
209 #define uio usr_uio
210 #define fileops usr_fileops
211 #define vnodeops usr_vnodeops
212 #define vnode usr_vnode
213 #define inode usr_inode
214 #define whymountroot_t usr_whymountroot_t
215 #define vfsops usr_vfsops
216 #define vfs usr_vfs
217 #define vattr usr_vattr
218 #define buf usr_buf
219 #define statfs usr_statfs
220 #define file usr_file
221 #define dirent usr_dirent
222 #define flock usr_flock
223 #define fid usr_fid
224 #define sysent usr_sysent
225 #define ifaddr usr_ifaddr
226 #define ifnet usr_ifnet
227 #define in_ifaddr usr_in_ifaddr
228 #undef socket
229 #define socket usr_socket
230 #define crget usr_crget
231 #define crcopy usr_crcopy
232 #define crhold usr_crhold
233 #define crfree usr_crfree
234 #define vtype_t usr_vtype_t
235 #define vcexcl usr_vcexcl
236 #define m_free usr_m_free
237 #define m_freem usr_m_freem
238 #define m_adj usr_m_adj
239 #define m_pullup usr_m_pullup
240 #define uiomove usr_uiomove
241 #define EXCL usr_EXCL
242 #define NONEXCL usr_NONEXCL
243 #define uio_rw usr_uio_rw
244 #ifdef ino_t
245 #undef ino_t
246 #endif
247 #define ino_t usr_ino_t
248 #define offset_t usr_offset_t
249 #define getpid() usr_getpid()
250 #define setpag(A,B,C,D) usr_setpag((A),(B),(C),(D))
251 #define osi_getpid() afs_pointer_to_int(usr_thread_self())
252 #ifdef pid_t
253 #undef pid_t
254 #endif
255 #define pid_t int
256
257 enum usr_vcexcl { usr_NONEXCL, usr_EXCL };
258 typedef long offset_t;
259 #ifdef AFS_USR_OSF_ENV
260 typedef int usr_ino_t;
261 #else /* AFS_USR_OSF_ENV */
262 typedef long usr_ino_t;
263 #endif /* AFS_USR_OSF_ENV */
264
265 #if defined(AFS_USR_AIX_ENV) || defined(AFS_USR_SGI_ENV)
266 #define SYS_setgroups 101
267 #endif
268
269 #define ioctl() usr_ioctl()
270
271 #define label_t jmp_buf
272
273 #ifdef VFSTOM
274 #undef VFSTOM
275 #endif
276
277 #define VFSTOM(VP) ((struct usr_mount *)(VP)->vfs_mount)
278
279 #ifdef VINACT
280 #undef VINACT
281 #endif
282 #ifdef VLOCK
283 #undef VLOCK
284 #endif
285 #ifdef VNOMAP
286 #undef VNOMAP
287 #endif
288 #ifdef VROOT
289 #undef VROOT
290 #endif
291 #ifdef VSHARE
292 #undef VSHARE
293 #endif
294 #ifdef VTEXT
295 #undef VTEXT
296 #endif
297 #ifdef VWAIT
298 #undef VWAIT
299 #endif
300 #ifdef VWASMAP
301 #undef VWASMAP
302 #endif
303 #ifdef VXLOCK
304 #undef VXLOCK
305 #endif
306
307 #define VINACT 0x0001
308 #define VLOCK 0x0002
309 #define VNOMAP 0x0004
310 #define VROOT 0x0008
311 #define VSHARE 0x0010
312 #define VTEXT 0x0020
313 #define VWAIT 0x0040
314 #define VWASMAP 0x0080
315 #define VXLOCK 0x0100
316
317 #ifdef VNON
318 #undef VNON
319 #endif
320 #ifdef VREG
321 #undef VREG
322 #endif
323 #ifdef VDIR
324 #undef VDIR
325 #endif
326 #ifdef VBLK
327 #undef VBLK
328 #endif
329 #ifdef VCHR
330 #undef VCHR
331 #endif
332 #ifdef VLNK
333 #undef VLNK
334 #endif
335 #ifdef VFIFO
336 #undef VFIFO
337 #endif
338 #ifdef VSOCK
339 #undef VSOCK
340 #endif
341
342 #define VNON 0
343 #define VREG S_IFREG
344 #define VDIR S_IFDIR
345 #define VBLK S_IFBLK
346 #define VCHR S_IFCHR
347 #define VLNK S_IFLNK
348 #define VSOCK S_IFSOCK
349 #define VFIFO S_IFIFO
350
351 typedef int usr_vtype_t;
352
353 #ifdef VOP_RDWR
354 #undef VOP_RDWR
355 #endif
356
357 #define VOP_RDWR afs_osi_VOP_RDWR
358
359 #ifdef NDADDR
360 #undef NDADDR
361 #endif
362 #ifdef NIADDR
363 #undef NIADDR
364 #endif
365
366 #define NDADDR 12
367 #define NIADDR 3
368
369 #ifdef DTYPE_VNODE
370 #undef DTYPE_VNODE
371 #endif
372
373 #define DTYPE_VNODE 1
374
375 #ifdef IUPD
376 #undef IUPD
377 #endif
378 #ifdef IACC
379 #undef IACC
380 #endif
381 #ifdef IMOD
382 #undef IMOD
383 #endif
384 #ifdef ICHG
385 #undef ICHG
386 #endif
387 #ifdef INOACC
388 #undef INOACC
389 #endif
390 #ifdef IMODTIME
391 #undef IMODTIME
392 #endif
393 #ifdef IREF
394 #undef IREF
395 #endif
396 #ifdef ISYNC
397 #undef ISYNC
398 #endif
399 #ifdef IFASTSYMLNK
400 #undef IFASTSYMLNK
401 #endif
402 #ifdef IMODACC
403 #undef IMODACC
404 #endif
405 #ifdef IATTCHG
406 #undef IATTCHG
407 #endif
408 #ifdef IBDWRITE
409 #undef IBDWRITE
410 #endif
411 #ifdef IBAD
412 #undef IBAD
413 #endif
414 #ifdef IDEL
415 #undef IDEL
416 #endif
417
418 #define IUPD 0x0001
419 #define IACC 0x0002
420 #define IMOD 0x0004
421 #define ICHG 0x0008
422 #define INOACC 0x0010
423 #define IMODTIME 0x0020
424 #define IREF 0x0040
425 #define ISYNC 0x0080
426 #define IFASTSYMLNK 0x0100
427 #define IMODACC 0x0200
428 #define IATTCHG 0x0400
429 #define IBDWRITE 0x0800
430 #define IBAD 0x1000
431 #define IDEL 0x2000
432
433 #ifdef IFMT
434 #undef IFMT
435 #endif
436 #ifdef IFIFO
437 #undef IFIFO
438 #endif
439 #ifdef IFCHR
440 #undef IFCHR
441 #endif
442 #ifdef IFDIR
443 #undef IFDIR
444 #endif
445 #ifdef IFBLK
446 #undef IFBLK
447 #endif
448 #ifdef IFREG
449 #undef IFREG
450 #endif
451 #ifdef IFLNK
452 #undef IFLNK
453 #endif
454 #ifdef IFSHAD
455 #undef IFSHAD
456 #endif
457 #ifdef IFSOCK
458 #undef IFSOCK
459 #endif
460
461 #define IFMT 0170000
462 #define IFIFO 0010000
463 #define IFCHR 0020000
464 #define IFDIR 0040000
465 #define IFBLK 0060000
466 #define IFREG 0100000
467 #define IFLNK 0120000
468 #define IFSHAD 0130000
469 #define IFSOCK 0140000
470
471 #ifdef ISUID
472 #undef ISUID
473 #endif
474 #ifdef ISGID
475 #undef ISGID
476 #endif
477 #ifdef ISVTX
478 #undef ISVTX
479 #endif
480 #ifdef IREAD
481 #undef IREAD
482 #endif
483 #ifdef IWRITE
484 #undef IWRITE
485 #endif
486 #ifdef IEXEC
487 #undef IEXEC
488 #endif
489
490 #define ISUID 04000
491 #define ISGID 02000
492 #define ISVTX 01000
493 #define IREAD 0400
494 #define IWRITE 0200
495 #define IEXEC 0100
496
497 #ifdef I_SYNC
498 #undef I_SYNC
499 #endif
500 #ifdef I_DSYNC
501 #undef I_DSYNC
502 #endif
503 #ifdef I_ASYNC
504 #undef I_ASYNC
505 #endif
506
507 #define I_SYNC 1
508 #define I_DSYNC 2
509 #define I_ASYNC 0
510
511 #ifdef I_FREE
512 #undef I_FREE
513 #endif
514 #ifdef I_DIR
515 #undef I_DIR
516 #endif
517 #ifdef I_IBLK
518 #undef I_IBLK
519 #endif
520 #ifdef I_CHEAP
521 #undef I_CHEAP
522 #endif
523 #ifdef I_SHAD
524 #undef I_SHAD
525 #endif
526 #ifdef I_QUOTA
527 #undef I_QUOTA
528 #endif
529
530 #define I_FREE 0x00000001
531 #define I_DIR 0x00000002
532 #define I_IBLK 0x00000004
533 #define I_CHEAP 0x00000008
534 #define I_SHAD 0x00000010
535 #define I_QUOTA 0x00000020
536
537 #ifdef VTOI
538 #undef VTOI
539 #endif
540 #ifdef ITOV
541 #undef ITOV
542 #endif
543
544 #define VTOI(VP) ((struct usr_inode *)(VP)->v_data)
545 #define ITOV(IP) ((struct usr_vnode *)&(IP)->i_vnode)
546
547 #ifdef VN_HOLD
548 #undef VN_HOLD
549 #endif
550 #ifdef VN_RELE
551 #undef VN_RELE
552 #endif
553
554 #ifdef ROOT_INIT
555 #undef ROOT_INIT
556 #endif
557 #ifdef ROOT_REMOUNT
558 #undef ROOT_REMOUNT
559 #endif
560 #ifdef ROOT_UNMOUNT
561 #undef ROOT_UNMOUNT
562 #endif
563 #ifdef ROOT_FRONTMOUNT
564 #undef ROOT_FRONTMOUNT
565 #endif
566 #ifdef ROOT_BACKMOUNT
567 #undef ROOT_BACKMOUNT
568 #endif
569
570 #define ROOT_INIT 0x0001
571 #define ROOT_REMOUNT 0X0002
572 #define ROOT_UNMOUNT 0x0003
573 #define ROOT_FRONTMOUNT 0x0004
574 #define ROOT_BACKMOUNT 0x0005
575
576 #ifdef MAXFIDSZ
577 #undef MAXFIDSZ
578 #endif
579
580 #define MAXFIDSZ 64
581
582 #ifdef FSTYPSZ
583 #undef FSTYPSZ
584 #endif
585
586 #define FSTYPSZ 16
587
588 #ifdef VFS_MOUNT
589 #undef VFS_MOUNT
590 #endif
591 #ifdef VFS_UNMOUNT
592 #undef VFS_UNMOUNT
593 #endif
594 #ifdef VFS_ROOT
595 #undef VFS_ROOT
596 #endif
597 #ifdef VFS_STATFS
598 #undef VFS_STATFFS
599 #endif
600 #ifdef VFS_SYNC
601 #undef VFS_SYNC
602 #endif
603 #ifdef VFS_VGET
604 #undef VFS_VGET
605 #endif
606 #ifdef VFS_MOUNTROOT
607 #undef VFS_MOUNTROOT
608 #endif
609 #ifdef VFS_SWAPVP
610 #undef VFS_SWAPVP
611 #endif
612 #ifdef VFS_MOUNT
613 #undef VFS_MOUNT
614 #endif
615
616 #define VFS_STATFS(vfsp, sp) ((sp)->f_bsize=4096, 0)
617
618 #ifdef FAPPEND
619 #undef FAPPEND
620 #endif
621 #ifdef FSYNC
622 #undef FSYNC
623 #endif
624 #ifdef FTRUNC
625 #undef FTRUNC
626 #endif
627 #ifdef FWRITE
628 #undef FWRITE
629 #endif
630 #ifdef IO_APPEND
631 #undef IO_APPEND
632 #endif
633 #ifdef IO_SYNC
634 #undef IO_SYNC
635 #endif
636
637 #define FAPPEND 0x0100
638 #define IO_APPEND FAPPEND
639 #define FSYNC 0x0200
640 #define IO_SYNC FSYNC
641 #define FTRUNC 0x0400
642 #define FWRITE 0x0800
643
644 #ifdef F_GETLK
645 #undef F_GETLK
646 #endif
647 #ifdef F_RDLCK
648 #undef F_RDLCK
649 #endif
650 #ifdef F_SETLK
651 #undef F_SETLK
652 #endif
653 #ifdef F_SETLKW
654 #undef F_SETLKW
655 #endif
656 #ifdef F_UNLCK
657 #undef F_UNLCK
658 #endif
659 #ifdef F_WRLCK
660 #undef F_WRLCK
661 #endif
662
663 #define F_GETLK 0x0001
664 #define F_RDLCK 0x0002
665 #define F_SETLK 0x0003
666 #define F_SETLKW 0x0004
667 #define F_UNLCK 0x0005
668 #define F_WRLCK 0x0006
669
670 #ifdef LOCK_SH
671 #undef LOCK_SH
672 #endif
673 #ifdef LOCK_EX
674 #undef LOCK_EX
675 #endif
676 #ifdef LOCK_NB
677 #undef LOCK_NB
678 #endif
679 #ifdef LOCK_UN
680 #undef LOCK_UN
681 #endif
682
683 #define LOCK_SH F_RDLCK
684 #define LOCK_UN F_UNLCK
685 #define LOCK_EX F_WRLCK
686 #define LOCK_NB 0x0007
687
688 #ifdef FEXLOCK
689 #undef FEXLOCK
690 #endif
691 #ifdef FSHLOCK
692 #undef FSHLOCK
693 #endif
694
695 #define FEXLOCK F_WRLCK
696 #define FSHLOCK F_RDLCK
697
698 #ifdef SSYS
699 #undef SSYS
700 #endif
701
702 #define SSYS 0x0001
703
704 enum usr_uio_rw { USR_UIO_READ, USR_UIO_WRITE };
705
706 #ifdef UIO_READ
707 #undef UIO_READ
708 #endif
709 #ifdef UIO_WRITE
710 #undef UIO_WRITE
711 #endif
712
713 #define UIO_READ 0x0000
714 #define UIO_WRITE 0x0001
715
716 #ifdef UIO_USERSPACE
717 #undef UIO_USERSPACE
718 #endif
719 #ifdef UIO_SYSSPACE
720 #undef UIO_SYSSPACE
721 #endif
722
723 #define UIO_USERSPACE 0x0000
724 #define UIO_SYSSPACE 0x0001
725
726 #ifdef B_AGE
727 #undef B_AGE
728 #endif
729 #ifdef B_ASYNC
730 #undef B_ASYNC
731 #endif
732 #ifdef B_DELWRI
733 #undef B_DELWRI
734 #endif
735 #ifdef B_DIRTY
736 #undef B_DIRTY
737 #endif
738 #ifdef B_DONE
739 #undef B_DONE
740 #endif
741 #ifdef B_ERROR
742 #undef B_ERROR
743 #endif
744 #ifdef B_FREE
745 #undef B_FREE
746 #endif
747 #ifdef B_NOCACHE
748 #undef B_NOCACHE
749 #endif
750 #ifdef B_PFSTORE
751 #undef B_PFSTORE
752 #endif
753 #ifdef B_READ
754 #undef B_READ
755 #endif
756 #ifdef B_UBC
757 #undef B_UBC
758 #endif
759 #ifdef B_WANTED
760 #undef B_WANTED
761 #endif
762 #ifdef B_WRITE
763 #undef B_WRITE
764 #endif
765
766 #define B_AGE 0x0001
767 #define B_ASYNC 0x0002
768 #define B_DELWRI 0x0004
769 #define B_DIRTY 0x0008
770 #define B_DONE 0x0010
771 #define B_ERROR 0x0020
772 #define B_FREE 0x0040
773 #define B_NOCACHE 0x0080
774 #define B_PFSTORE 0x0100
775 #define B_READ 0x0200
776 #define B_UBC 0x0400
777 #define B_WANTED 0x0800
778 #define B_WRITE 0x1000
779
780 #ifdef MFREE
781 #undef MFREE
782 #endif
783 #ifdef MINUSE
784 #undef MINUSE
785 #endif
786 #ifdef MINTER
787 #undef MINTER
788 #endif
789 #ifdef MUPDATE
790 #undef MUPDATE
791 #endif
792
793 #define MFREE 0
794 #define MINUSE 1
795 #define MINTER 2
796 #define MUPDATE 4
797
798 #ifdef MSIZE
799 #undef MSIZE
800 #endif
801 #ifdef MMAXOFF
802 #undef MMAXOFF
803 #endif
804
805 #define MSIZE 16384
806 #define MMAXOFF 16384
807
808 #ifdef IA_SIN
809 #undef IA_SIN
810 #endif
811
812 #define IA_SIN(IA) (&(IA)->ia_addr)
813
814 #ifdef mtod
815 #undef mtod
816 #endif
817 #ifdef dtom
818 #undef dtom
819 #endif
820 #ifdef mtocl
821 #undef mtocl
822 #endif
823
824 #define mtod(m,t) ((t)((m)->m_data))
825
826 #ifdef NBPG
827 #undef NBPG
828 #endif
829 #define NBPG 4096
830
831 static_inline void panic(const char *format, ...) AFS_NORETURN;
832 static_inline void panic(const char *format, ...)
833 {
834 va_list ap;
835 va_start(ap, format);
836 vfprintf(stderr, format, ap);
837 va_end(ap);
838 assert(0);
839 }
840 #define abort() assert(0)
841 #define usr_assert(A) assert(A)
842
843
844 /*
845 * Mutex and condition variable used to implement sleep
846 */
847 extern pthread_mutex_t usr_sleep_mutex;
848 extern pthread_cond_t usr_sleep_cond;
849
850 #define usr_cond_t pthread_cond_t
851 #define usr_mutex_t pthread_mutex_t
852 #define usr_thread_t pthread_t
853 #define usr_key_t pthread_key_t
854
855 #define usr_mutex_init(A) opr_Verify(pthread_mutex_init(A,NULL) == 0)
856 #define usr_mutex_destroy(A) opr_Verify(pthread_mutex_destroy(A) == 0)
857 #define usr_mutex_lock(A) opr_Verify(pthread_mutex_lock(A) == 0)
858 #define usr_mutex_trylock(A) ((pthread_mutex_trylock(A)==0)?1:0)
859 #define usr_mutex_unlock(A) opr_Verify(pthread_mutex_unlock(A) == 0)
860 #define usr_cond_init(A) opr_Verify(pthread_cond_init(A,NULL) == 0)
861 #define usr_cond_destroy(A) opr_Verify(pthread_cond_destroy(A) == 0)
862 #define usr_cond_signal(A) opr_Verify(pthread_cond_signal(A) == 0)
863 #define usr_cond_broadcast(A) opr_Verify(pthread_cond_broadcast(A) == 0)
864 #define usr_cond_wait(A,B) pthread_cond_wait(A,B)
865 #define usr_cond_timedwait(A,B,C) pthread_cond_timedwait(A,B,C)
866
867 #define usr_thread_create(A,B,C) \
868 do { \
869 pthread_attr_t attr; \
870 opr_Verify(pthread_attr_init(&attr) == 0); \
871 opr_Verify(pthread_attr_setstacksize(&attr, 122880) == 0); \
872 opr_Verify(pthread_create((A), &attr, (B), (void *)(C)) == 0); \
873 opr_Verify(pthread_attr_destroy(&attr) == 0); \
874 } while(0)
875 #define usr_thread_join(A,B) pthread_join(A, B)
876 #define usr_thread_detach(A) pthread_detach(A)
877 #define usr_keycreate(A,B) opr_Verify(pthread_key_create(A,B) == 0)
878 #define usr_setspecific(A,B) pthread_setspecific(A,B)
879 #define usr_getspecific(A,B) (*(B)=pthread_getspecific(A),0)
880 #define usr_thread_self() pthread_self()
881 #define usr_thread_sleep(A) \
882 { \
883 struct timespec _sleep_ts; \
884 struct timeval _sleep_tv; \
885 gettimeofday(&_sleep_tv, NULL); \
886 _sleep_ts = *(A); \
887 _sleep_ts.tv_sec += _sleep_tv.tv_sec; \
888 _sleep_ts.tv_nsec += _sleep_tv.tv_usec * 1000; \
889 if (_sleep_ts.tv_nsec >= 1000000000) { \
890 _sleep_ts.tv_sec += 1; \
891 _sleep_ts.tv_nsec -= 1000000000; \
892 } \
893 opr_Verify(pthread_mutex_lock(&usr_sleep_mutex) == 0); \
894 pthread_cond_timedwait(&usr_sleep_cond, &usr_sleep_mutex, &_sleep_ts); \
895 opr_Verify(pthread_mutex_unlock(&usr_sleep_mutex) == 0); \
896 }
897
898 #define uprintf printf
899
900 #define usr_getpid() (int)(usr_thread_self())
901 #ifdef ISAFS_GLOCK
902 #undef ISAFS_GLOCK
903 #endif
904 #define ISAFS_GLOCK() (usr_thread_self() == afs_global_owner)
905
906 #define copyin(A,B,C) (memcpy((void *)B,(void *)A,C), 0)
907 #define copyout(A,B,C) (memcpy((void *)B,(void *)A,C), 0)
908 #define copyinstr(A,B,C,D) (strncpy(B,A,C),(*D)=strlen(B), 0)
909 #define copyoutstr(A,B,C,D) (strncpy(B,A,C),(*D)=strlen(B), 0)
910
911 #define vattr_null(A) usr_vattr_null(A)
912
913 #define VN_HOLD(vp) \
914 { \
915 (vp)->v_count++; \
916 }
917
918 #define VN_RELE(vp) \
919 do { \
920 AFS_ASSERT_GLOCK(); \
921 usr_assert((vp)->v_count > 0); \
922 if (--((vp)->v_count) == 0) \
923 afs_inactive(VTOAFS(vp), get_user_struct()->u_cred); \
924 } while(0)
925
926 struct usr_statfs {
927 unsigned long f_type;
928 unsigned long f_bsize;
929 unsigned long f_frsize;
930 unsigned long f_ffree;
931 unsigned long f_favail;
932 struct {
933 unsigned long val[2];
934 } f_fsid;
935 char f_basetype[FSTYPSZ];
936 unsigned long f_flag;
937 unsigned long f_namemax;
938 unsigned long f_blocks;
939 unsigned long f_bfree;
940 unsigned long f_bavail;
941 unsigned long f_files;
942 };
943
944 #define ATTR_MODE (1 << 0)
945 #define ATTR_UID (1 << 1)
946 #define ATTR_GID (1 << 2)
947 #define ATTR_MTIME (1 << 3)
948 #define ATTR_SIZE (1 << 4)
949
950 struct usr_vattr {
951 int va_mask; /* bitmask of ATTR_* values above */
952 usr_vtype_t va_type;
953 mode_t va_mode;
954 uid_t va_uid;
955 gid_t va_gid;
956 int va_fsid;
957 ino_t va_nodeid;
958 nlink_t va_nlink;
959 afs_size_t va_size;
960 struct timeval va_atime;
961 struct timeval va_mtime;
962 struct timeval va_ctime;
963 dev_t va_rdev;
964 unsigned long va_blocksize;
965 fsblkcnt_t va_blocks;
966 unsigned long va_vcode;
967 };
968
969 #ifdef VSUID
970 #undef VSUID
971 #endif
972 #ifdef VSGID
973 #undef VSGID
974 #endif
975 #ifdef VSVTX
976 #undef VSVTX
977 #endif
978 #ifdef VREAD
979 #undef VREAD
980 #endif
981 #ifdef VWRITE
982 #undef VWRITE
983 #endif
984 #ifdef VEXEC
985 #undef VEXEC
986 #endif
987
988 #define VSUID 04000
989 #define VSGID 02000
990 #define VSVTX 01000
991 #define VREAD 00400
992 #define VWRITE 00200
993 #define VEXEC 00100
994
995
996 struct usr_vnode {
997 unsigned short v_flag;
998 unsigned long v_count;
999 struct usr_vnodeops *v_op;
1000 struct usr_vfs *v_vfsp;
1001 long v_type;
1002 unsigned long v_rdev;
1003 char *v_data;
1004 };
1005
1006 struct usr_inode {
1007 daddr_t i_db[NDADDR];
1008 struct usr_vnode *i_devvp;
1009 unsigned long i_dev;
1010 long i_flag;
1011 struct usr_inode *i_freef;
1012 struct usr_inode **i_freeb;
1013 long i_gid;
1014 daddr_t i_ib[NIADDR];
1015 unsigned short i_mode;
1016 short i_nlink;
1017 unsigned long i_number;
1018 long i_size;
1019 long i_uid;
1020 struct usr_vnode i_vnode;
1021 struct {
1022 unsigned long ic_spare[4];
1023 } i_ic;
1024 };
1025
1026 struct usr_fileops {
1027 int (*vno_rw) (void);
1028 int (*vno_ioctl) (void);
1029 int (*vno_select) (void);
1030 int (*vno_closex) (void);
1031 };
1032
1033 struct usr_file {
1034 unsigned short f_flag;
1035 offset_t f_offset;
1036 struct usr_ucred *f_cred;
1037 struct usr_fileops *f_ops;
1038 char *f_data;
1039 long f_type;
1040 };
1041
1042 extern struct usr_file *getf(int);
1043
1044 #ifdef fid_len
1045 #undef fid_len
1046 #endif
1047 #ifdef fid_data
1048 #undef fid_data
1049 #endif
1050
1051 struct usr_fid {
1052 unsigned short fid_len;
1053 unsigned short fid_reserved;
1054 char fid_data[MAXFIDSZ];
1055 };
1056
1057 struct usr_flock {
1058 short l_type;
1059 short l_whence;
1060 off_t l_start;
1061 off_t l_len;
1062 long l_sysid;
1063 pid_t l_pid;
1064 };
1065
1066 extern struct usr_ucred *usr_crget(void);
1067 extern struct usr_ucred *usr_crcopy(struct usr_ucred *);
1068 extern int usr_crhold(struct usr_ucred *);
1069 extern int usr_crfree(struct usr_ucred *);
1070
1071 struct usr_proc {
1072 unsigned long p_flag;
1073 pid_t p_pid;
1074 pid_t p_ppid;
1075 struct usr_ucred *p_ucred;
1076 char p_cursig;
1077 };
1078
1079 struct usr_a {
1080 int fd;
1081 int syscall;
1082 int parm1;
1083 int parm2;
1084 int parm3;
1085 int parm4;
1086 int parm5;
1087 int parm6;
1088 };
1089
1090 #ifdef uio_offset
1091 #undef uio_offset
1092 #endif
1093
1094 struct usr_uio {
1095 struct iovec *uio_iov;
1096 int uio_iovcnt;
1097 long uio_offset;
1098 int uio_segflg;
1099 short uio_fmode;
1100 int uio_resid;
1101 };
1102
1103 #ifdef b_blkno
1104 #undef b_blkno
1105 #endif
1106 #ifdef b_vp
1107 #undef b_vp
1108 #endif
1109
1110 struct usr_buf {
1111 int b_flags;
1112 short b_dev;
1113 unsigned b_bcount;
1114 struct {
1115 char *b_addr;
1116 struct usr_fs *b_fs;
1117 } b_un;
1118 long b_blkno;
1119 unsigned int b_resid;
1120 struct usr_vnode *b_vp;
1121 };
1122
1123 struct usr_socket {
1124 int sock;
1125 short port;
1126 };
1127
1128 #define NDIRSIZ_LEN(len) \
1129 ((sizeof (struct usr_dirent)+4 - (MAXNAMLEN+1)) + (((len)+1 + 3) &~ 3))
1130
1131 struct vcache;
1132 #define afs_ucred_t struct usr_ucred
1133 #define AFS_FLOCK flock
1134
1135
1136 struct usr_vnodeops {
1137 int (*vn_open) (struct vcache **, afs_int32, afs_ucred_t *);
1138 int (*vn_close) (struct vcache *, afs_int32, afs_ucred_t *);
1139 int (*vn_rdwr) (struct usr_vnode *avc, struct usr_uio *uio,
1140 int rw, int io, struct usr_ucred *cred);
1141 int (*vn_ioctl) (void);
1142 int (*vn_select) (void);
1143 int (*vn_getattr) (struct vcache *avc, struct vattr *, afs_ucred_t *);
1144 int (*vn_setattr) (struct vcache *avc, struct vattr *, afs_ucred_t *);
1145 int (*vn_access) (struct vcache *avc, afs_int32, afs_ucred_t *);
1146 int (*vn_lookup) (struct vcache *adp, char *, struct vcache **,
1147 afs_ucred_t *, int);
1148 int (*vn_create) (struct vcache *adp, char *, struct vattr *,
1149 enum vcexcl, int, struct vcache **, afs_ucred_t *);
1150 int (*vn_remove) (struct vcache *adp, char *, afs_ucred_t *);
1151 int (*vn_link) (struct vcache *avc, struct vcache *adp, char *,
1152 afs_ucred_t *);
1153 int (*vn_rename) (struct vcache *aodp, char *, struct vcache *, char *,
1154 afs_ucred_t *);
1155 int (*vn_mkdir) (struct vcache *adp, char *, struct vattr *,
1156 struct vcache **, afs_ucred_t *);
1157 int (*vn_rmdir) (struct vcache *adp, char *, afs_ucred_t *);
1158 int (*vn_readdir) (struct vcache *avc, struct uio *, afs_ucred_t *);
1159 int (*vn_symlink) (struct vcache *adp, char *, struct vattr *, char *,
1160 struct vcache **pvc, afs_ucred_t *);
1161 int (*vn_readlink) (struct vcache *avc, struct uio *, afs_ucred_t *);
1162 int (*vn_fsync) (struct vcache *avc, afs_ucred_t *);
1163 int (*vn_inactive) (struct vcache *avc, afs_ucred_t *acred);
1164 int (*vn_bmap) (void);
1165 int (*vn_strategy) (void);
1166 int (*vn_bread) (void);
1167 int (*vn_brelse) (void);
1168 int (*vn_lockctl) (struct vcache *, struct AFS_FLOCK *, int,
1169 afs_ucred_t *);
1170 int (*vn_fid) (struct vcache *avc, struct fid **);
1171 };
1172
1173 struct usr_fs {
1174 int dummy;
1175 };
1176
1177 struct usr_mount {
1178 char m_flags;
1179 unsigned long m_dev;
1180 struct usr_inode *m_inodp;
1181 struct usr_buf *m_bufp;
1182 struct usr_vnode *m_mount;
1183 };
1184 extern struct usr_mount *getmp(unsigned long);
1185
1186 typedef long usr_whymountroot_t;
1187
1188 struct usr_vfsops {
1189 int (*vfs_mount) (struct vfs *, char *, void *);
1190 int (*vfs_unmount) (struct vfs *);
1191 int (*vfs_root) (struct vfs *, struct vnode **);
1192 int (*vfs_statfs) (struct vfs *, struct statfs *);
1193 int (*vfs_mountroot) (struct vfs *);
1194 int (*vfs_swapvp) (void);
1195 };
1196
1197 struct usr_vfs {
1198 struct usr_vnode *vfs_vnodecovered;
1199 struct {
1200 unsigned long val[2];
1201 } vfs_fsid;
1202 char *vfs_data;
1203 unsigned long vfs_bsize;
1204 struct usr_mount *vfs_mount;
1205 struct usr_vfsops *vfs_op;
1206 };
1207
1208 struct usr_ifnet {
1209 struct usr_ifnet *if_next;
1210 short if_flags;
1211 u_int if_mtu;
1212 u_int if_metric;
1213 struct usr_ifaddr *if_addrlist;
1214 };
1215 extern struct usr_ifnet *usr_ifnet;
1216
1217 struct usr_ifaddr {
1218 struct usr_ifaddr *ifa_next;
1219 struct usr_ifnet *ifa_ifp;
1220 struct sockaddr ifa_addr;
1221 };
1222
1223 #ifdef ia_ifp
1224 #undef ia_ifp
1225 #endif
1226 #ifdef ia_addr
1227 #undef ia_addr
1228 #endif
1229
1230 struct usr_in_ifaddr {
1231 struct usr_in_ifaddr *ia_next;
1232 struct usr_ifnet *ia_ifp;
1233 struct sockaddr_in ia_addr;
1234 unsigned long ia_net;
1235 unsigned long ia_netmask;
1236 unsigned long ia_subnet;
1237 unsigned long ia_subnetmask;
1238 struct in_addr ia_netbroadcast;
1239 };
1240 extern struct usr_in_ifaddr *usr_in_ifaddr;
1241
1242 #endif /* UKERNEL */
1243
1244 struct min_direct {
1245 #if defined(AFS_USR_OSF_ENV)
1246 unsigned int d_fileno;
1247 #else /* AFS_OFS_ENV || AFS_USR_OSF_ENV */
1248 unsigned long d_fileno;
1249 #endif /* AFS_OFS_ENV || AFS_USR_OSF_ENV */
1250 unsigned short d_reclen;
1251 unsigned short d_namlen;
1252 };
1253
1254 #ifndef NGROUPS
1255 #define NGROUPS NGROUPS_MAX
1256 #endif
1257 #ifndef NOGROUP
1258 #define NOGROUP (-1)
1259 #endif
1260 #ifdef cr_gid
1261 #undef cr_gid
1262 #endif
1263
1264 struct usr_ucred {
1265 unsigned long cr_ref;
1266 long cr_uid;
1267 long cr_gid;
1268 long cr_ruid;
1269 long cr_rgid;
1270 long cr_suid;
1271 long cr_sgid;
1272 long cr_ngroups;
1273 gid_t cr_groups[NGROUPS];
1274 };
1275
1276 #ifdef u_rval1
1277 #undef u_rval1
1278 #endif
1279
1280 struct usr_user {
1281 int u_error;
1282 int u_prio;
1283 char *u_ap;
1284 int u_rval1;
1285 long u_viceid;
1286 unsigned long u_expiration;
1287 struct usr_proc *u_procp;
1288 struct usr_ucred *u_cred;
1289 struct {
1290 int r_val1;
1291 } u_r;
1292 };
1293 #define u_rval1 u_r.r_val1
1294
1295 extern struct usr_user *get_user_struct(void);
1296
1297 #define USR_DIRSIZE 2048
1298
1299 struct usr_dirent {
1300 unsigned long d_ino;
1301 unsigned long d_off;
1302 unsigned short d_reclen;
1303 char d_name[MAXNAMLEN + 1];
1304 };
1305
1306 typedef struct {
1307 int dd_fd;
1308 int dd_loc;
1309 int dd_size;
1310 int dd_reserved;
1311 char *dd_buf;
1312 } usr_DIR;
1313
1314 extern unsigned short usr_rx_port;
1315
1316 #define AFS_LOOKUP_NOEVAL 1
1317
1318 #endif /* __AFS_SYSINCLUDESH__ so idempotent */