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