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