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