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