prototypes-fixes-20020821
[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 #define ISAFS_GLOCK() (usr_thread_self() == afs_global_owner)
977
978 #endif /* NETSCAPE_NSAPI */
979
980 #define copyin(A,B,C)           (memcpy((void *)B,(void *)A,C), 0)
981 #define copyout(A,B,C)          (memcpy((void *)B,(void *)A,C), 0)
982 #define copyinstr(A,B,C,D)      (strncpy(B,A,C),(*D)=strlen(B), 0)
983 #define copyoutstr(A,B,C,D)     (strncpy(B,A,C),(*D)=strlen(B), 0)
984
985 #define vattr_null(A)           usr_vattr_null(A)
986
987 #define VN_HOLD(vp)     \
988 { \
989     (vp)->v_count++; \
990 }
991  
992 #define VN_RELE(vp)     \
993 do { \
994     AFS_ASSERT_GLOCK(); \
995     usr_assert((vp)->v_count > 0); \
996     if (--((vp)->v_count) == 0) \
997         afs_inactive(vp, u.u_cred); \
998 } while(0)
999
1000 struct usr_statfs {
1001         unsigned long           f_type;
1002         unsigned long           f_bsize;
1003         unsigned long           f_frsize;
1004         unsigned long           f_ffree;
1005         unsigned long           f_favail;
1006         struct {
1007             unsigned long       val[2];
1008         } f_fsid;
1009         char                    f_basetype[FSTYPSZ];
1010         unsigned long           f_flag;
1011         unsigned long           f_namemax;
1012         unsigned long           f_blocks;
1013         unsigned long           f_bfree;
1014         unsigned long           f_bavail;
1015         unsigned long           f_files;
1016 };
1017
1018 struct usr_vattr {
1019         long                    va_mask;
1020         usr_vtype_t             va_type;
1021         unsigned short          va_mode;
1022         long                    va_uid;
1023         long                    va_gid;
1024         unsigned long           va_fsid;
1025         unsigned long           va_nodeid;
1026         unsigned long           va_nlink;
1027         unsigned long           va_size;
1028         struct timeval          va_atime;
1029         struct timeval          va_mtime;
1030         struct timeval          va_ctime;
1031         unsigned long           va_rdev;
1032         unsigned long           va_blocksize;
1033         unsigned long           va_blocks;
1034         unsigned long           va_vcode;
1035 };
1036
1037 #ifdef VSUID
1038 #undef VSUID
1039 #endif
1040 #ifdef VSGID
1041 #undef VSGID
1042 #endif
1043 #ifdef VSVTX
1044 #undef VSVTX
1045 #endif
1046 #ifdef VREAD
1047 #undef VREAD
1048 #endif
1049 #ifdef VWRITE
1050 #undef VWRITE
1051 #endif
1052 #ifdef VEXEC
1053 #undef VEXEC
1054 #endif
1055
1056 #define VSUID                   04000 
1057 #define VSGID                   02000
1058 #define VSVTX                   01000
1059 #define VREAD                   00400
1060 #define VWRITE                  00200
1061 #define VEXEC                   00100
1062
1063
1064 struct usr_vnode {
1065         unsigned short          v_flag;
1066         unsigned long           v_count;
1067         struct usr_vnodeops     *v_op;
1068         struct usr_vfs  *       v_vfsp;
1069         long                    v_type;
1070         unsigned long           v_rdev;
1071         char *                  v_data;
1072 };
1073
1074 struct  usr_inode {
1075         daddr_t                 i_db[NDADDR];
1076         struct usr_vnode        *i_devvp;
1077         unsigned long           i_dev;
1078         long                    i_flag;
1079         struct usr_inode        *i_freef;
1080         struct usr_inode        **i_freeb;
1081         long                    i_gid;
1082         daddr_t                 i_ib[NIADDR];
1083         unsigned short          i_mode;
1084         short                   i_nlink;
1085         unsigned long           i_number;
1086         long                    i_size;
1087         long                    i_uid;
1088         struct usr_vnode        i_vnode;
1089         struct {
1090             unsigned long       ic_spare[4];
1091         } i_ic;
1092 };
1093 extern struct usr_inode *iget();
1094
1095 struct usr_fileops {
1096         int                     (*vno_rw)();
1097         int                     (*vno_ioctl)();
1098         int                     (*vno_select)();
1099         int                     (*vno_closex)();
1100 };
1101
1102 struct usr_file {
1103         unsigned short          f_flag;
1104         offset_t                f_offset;
1105         struct usr_ucred        *f_cred;
1106         struct usr_fileops      *f_ops;
1107         char *                  f_data;
1108         long                    f_type;
1109 };
1110 extern struct usr_file *falloc();
1111 extern struct usr_file *getf(int);
1112
1113 #ifdef  fid_len 
1114 #undef  fid_len 
1115 #endif
1116 #ifdef  fid_data
1117 #undef  fid_data
1118 #endif
1119
1120 struct usr_fid {
1121         unsigned short          fid_len;
1122         unsigned short          fid_reserved;
1123         char                    fid_data[MAXFIDSZ];
1124 };
1125
1126 struct usr_flock {
1127         short                   l_type;
1128         short                   l_whence;
1129         off_t                   l_start;
1130         off_t                   l_len;
1131         long                    l_sysid;
1132         pid_t                   l_pid;
1133 };
1134
1135 extern struct usr_ucred *usr_crget();
1136 extern struct usr_ucred *usr_crcopy(struct usr_ucred *);
1137 extern int usr_crhold(struct usr_ucred *);
1138 extern int usr_crfree(struct usr_ucred *);
1139 extern struct usr_ucred *afs_global_ucredp;
1140
1141 struct  usr_proc {
1142         unsigned long           p_flag;
1143         pid_t                   p_pid;
1144         pid_t                   p_ppid;
1145         struct usr_ucred        *p_ucred;
1146         char                    p_cursig;
1147 };
1148
1149 struct  usr_a {
1150         int                     fd;
1151         int                     syscall;
1152         int                     parm1;
1153         int                     parm2;
1154         int                     parm3;
1155         int                     parm4;
1156         int                     parm5;
1157         int                     parm6;
1158 };
1159
1160 #ifdef uio_offset
1161 #undef uio_offset
1162 #endif
1163
1164 struct usr_uio {
1165         struct iovec            *uio_iov;
1166         int                     uio_iovcnt;
1167         long                    uio_offset;
1168         int                     uio_segflg;
1169         short                   uio_fmode;
1170         int                     uio_resid;
1171 };
1172
1173 #ifdef b_blkno
1174 #undef b_blkno
1175 #endif
1176 #ifdef b_vp
1177 #undef b_vp
1178 #endif
1179
1180 struct  usr_buf {
1181         int                     b_flags;
1182         short                   b_dev;
1183         unsigned                b_bcount;
1184         struct {
1185             char *              b_addr;
1186             struct usr_fs       *b_fs;
1187         } b_un;
1188         long                    b_blkno;
1189         unsigned int            b_resid;
1190         struct  usr_vnode       *b_vp;
1191 };
1192
1193 struct usr_socket {
1194         int                     sock;
1195         short                   port;
1196 };
1197
1198 #define NDIRSIZ_LEN(len) \
1199 ((sizeof (struct usr_dirent)+4 - (MAXNAMLEN+1)) + (((len)+1 + 3) &~ 3))
1200
1201 struct usr_vnodeops {
1202         int                     (*vn_open)();
1203         int                     (*vn_close)();
1204         int                     (*vn_rdwr)();
1205         int                     (*vn_ioctl)();
1206         int                     (*vn_select)();
1207         int                     (*vn_getattr)();
1208         int                     (*vn_setattr)();
1209         int                     (*vn_access)();
1210         int                     (*vn_lookup)();
1211         int                     (*vn_create)();
1212         int                     (*vn_remove)();
1213         int                     (*vn_link)();
1214         int                     (*vn_rename)();
1215         int                     (*vn_mkdir)();
1216         int                     (*vn_rmdir)();
1217         int                     (*vn_readdir)();
1218         int                     (*vn_symlink)();
1219         int                     (*vn_readlink)();
1220         int                     (*vn_fsync)();
1221         int                     (*vn_inactive)();
1222         int                     (*vn_bmap)();
1223         int                     (*vn_strategy)();
1224         int                     (*vn_bread)();
1225         int                     (*vn_brelse)();
1226         int                     (*vn_lockctl)();
1227         int                     (*vn_fid)();
1228 };
1229
1230 struct usr_fs {
1231         int                     dummy;
1232 };
1233
1234 struct usr_mount
1235 {
1236         char                    m_flags;
1237         unsigned long           m_dev;
1238         struct usr_inode        *m_inodp;
1239         struct usr_buf          *m_bufp;
1240         struct usr_vnode        *m_mount;
1241 };
1242 extern struct usr_mount *getmp(unsigned long);
1243
1244 typedef long usr_whymountroot_t;
1245
1246 struct usr_vfsops {
1247         int (*vfs_mount)();
1248         int (*vfs_unmount)();
1249         int (*vfs_root)();
1250         int (*vfs_statfs)();
1251         int (*vfs_mountroot)();
1252         int (*vfs_swapvp)();
1253 };
1254
1255 struct usr_vfs {
1256         struct usr_vnode        *vfs_vnodecovered;
1257         struct {
1258             unsigned long       val[2];
1259         } vfs_fsid;
1260         char *                  vfs_data;
1261         unsigned long           vfs_bsize;
1262         struct usr_mount        *vfs_mount;
1263         struct usr_vfsops       *vfs_op;
1264 };
1265
1266 struct usr_sysent {
1267         char                    sy_narg;
1268         int                     (*sy_call)();
1269 };
1270 extern struct usr_sysent usr_sysent[];
1271
1272 struct usr_ifnet {
1273         struct usr_ifnet        *if_next;
1274         short                   if_flags;
1275         u_int                   if_mtu;
1276         u_int                   if_metric;
1277         struct usr_ifaddr       *if_addrlist;
1278 };
1279 extern struct usr_ifnet *usr_ifnet;
1280
1281 struct usr_ifaddr {
1282         struct usr_ifaddr       *ifa_next;
1283         struct usr_ifnet        *ifa_ifp;
1284         struct sockaddr         ifa_addr;
1285 };
1286
1287 #ifdef ia_ifp
1288 #undef ia_ifp
1289 #endif
1290 #ifdef ia_addr
1291 #undef ia_addr
1292 #endif
1293
1294 struct usr_in_ifaddr {
1295         struct usr_in_ifaddr    *ia_next;
1296         struct usr_ifnet        *ia_ifp;
1297         struct                  sockaddr_in ia_addr;
1298         unsigned long           ia_net;
1299         unsigned long           ia_netmask;
1300         unsigned long           ia_subnet;
1301         unsigned long           ia_subnetmask;
1302         struct                  in_addr ia_netbroadcast;
1303 };
1304 extern struct usr_in_ifaddr *usr_in_ifaddr;
1305
1306 extern usr_key_t afs_global_u_key;      /* for per thread authentication */
1307
1308 #if defined(AFS_USR_OSF_ENV)
1309 extern char V;
1310 #else
1311 extern long V;
1312 #endif
1313
1314 #endif /* UKERNEL */
1315
1316 struct min_direct {
1317 #if defined(AFS_OFS_ENV) || defined(AFS_USR_OSF_ENV)
1318     unsigned int                d_fileno;
1319 #else /* AFS_OFS_ENV || AFS_USR_OSF_ENV */
1320     unsigned long               d_fileno;
1321 #endif /* AFS_OFS_ENV || AFS_USR_OSF_ENV */
1322     unsigned short              d_reclen;
1323     unsigned short              d_namlen;
1324 };
1325
1326 #ifndef NGROUPS
1327 #define NGROUPS                 NGROUPS_MAX
1328 #endif
1329 #ifndef NOGROUP
1330 #define NOGROUP                 (-1)
1331 #endif
1332
1333 struct usr_ucred {
1334         unsigned long           cr_ref;
1335         long                    cr_uid;
1336 #if !defined(AFS_USR_FBSD_ENV)
1337         long                    cr_gid;
1338 #endif
1339         long                    cr_ruid;
1340         long                    cr_rgid;
1341         long                    cr_suid;
1342         long                    cr_sgid;
1343         long                    cr_ngroups;
1344         gid_t                   cr_groups[NGROUPS];
1345 };
1346
1347 #ifdef u_rval1
1348 #undef u_rval1
1349 #endif
1350
1351 struct  usr_user {
1352         int                     u_error;
1353         int                     u_prio;
1354         char *                  u_ap;
1355         int                     u_rval1;
1356         long                    u_viceid;
1357         unsigned long           u_expiration;
1358         struct usr_proc         *u_procp;
1359         struct usr_ucred        *u_cred;
1360         struct {
1361             int                 r_val1;
1362         } u_r;
1363 };
1364 #define u_rval1                 u_r.r_val1
1365 #define u                       (*(get_user_struct()))
1366
1367 extern struct usr_user *get_user_struct(void);
1368
1369 #define USR_DIRSIZE             2048
1370
1371 struct usr_dirent {
1372         unsigned long           d_ino;
1373         unsigned long           d_off;
1374         unsigned short          d_reclen;
1375         char                    d_name[MAXNAMLEN+1];
1376 };
1377
1378 typedef struct {
1379         int                     dd_fd;
1380         int                     dd_loc;
1381         int                     dd_size;
1382         int                     dd_reserved;
1383         char                    *dd_buf;
1384 } usr_DIR;
1385
1386 extern unsigned short usr_rx_port;
1387
1388 #define AFS_LOOKUP_NOEVAL 1
1389
1390 #endif /* __AFS_SYSINCLUDESH__  so idempotent */