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