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