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