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