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