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