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