2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #ifndef __AFS_SYSINCLUDESH__
11 #define __AFS_SYSINCLUDESH__ 1
14 #if !defined(AFS_USR_DARWIN_ENV) && !defined(AFS_USR_FBSD_ENV) /* must be included after KERNEL undef'd */
26 #ifdef AFS_USR_SUN5_ENV
28 #include <sys/param.h>
29 #include <sys/types.h>
30 #include <sys/socket.h>
32 #include <sys/sockio.h>
35 #include <sys/fcntl.h>
36 #include <netinet/in.h>
38 #include <arpa/inet.h>
39 #endif /* AFS_USR_SUN5_ENV */
42 #ifdef AFS_USR_AIX_ENV
43 #include <sys/param.h>
44 #include <sys/types.h>
45 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <sys/stropts.h>
51 #include <sys/timers.h>
52 #include <arpa/inet.h>
53 #endif /* AFS_USR_AIX_ENV */
55 #ifdef AFS_USR_SGI_ENV
56 #include <sys/param.h>
57 #include <sys/types.h>
58 #include <sys/socket.h>
60 #include <sys/sockio.h>
63 #include <sys/fcntl.h>
64 #include <netinet/in.h>
66 #include <arpa/inet.h>
67 #endif /* AFS_USR_SGI_ENV */
69 #ifdef AFS_USR_HPUX_ENV
70 #include <sys/param.h>
71 #include <sys/types.h>
72 #include <sys/socket.h>
76 #include <sys/fcntl.h>
77 #include <netinet/in.h>
79 #include <arpa/inet.h>
80 #endif /* AFS_USR_HPUX_ENV */
82 #ifdef AFS_USR_OSF_ENV
85 #define AFS_USR_UNDEF_KERNEL_ENV 1
87 #include <sys/param.h>
88 #include <sys/types.h>
89 #include <sys/socket.h>
92 #include <sys/ioctl.h>
94 #include <sys/fcntl.h>
95 #include <netinet/in.h>
97 #include <arpa/inet.h>
98 #endif /* AFS_USR_OSF_ENV */
100 #ifdef AFS_USR_LINUX22_ENV
101 #include <sys/ioctl.h> /* _IOW() */
102 #include <sys/uio.h> /* struct iovec */
103 #include <sys/time.h> /* struct timeval */
104 #include <sys/param.h>
105 #include <sys/types.h>
106 #include <sys/socket.h>
108 #include <sys/file.h>
109 #include <sys/stat.h>
110 #include <sys/fcntl.h>
111 #include <netinet/in.h>
113 #include <arpa/inet.h>
115 #endif /* AFS_USR_LINUX22_ENV */
117 #if defined(AFS_USR_DARWIN_ENV) || defined(AFS_USR_FBSD_ENV)
120 #define AFS_USR_UNDEF_KERNEL_ENV 1
123 #include <sys/param.h>
124 #include <sys/types.h>
125 #include <sys/socket.h>
127 #include <sys/file.h>
128 #include <sys/ioctl.h>
129 #include <sys/stat.h>
130 #include <sys/fcntl.h>
132 #include <netinet/in.h>
134 #include <arpa/inet.h>
136 #define O_SYNC O_FSYNC
138 #endif /* AFS_USR_DARWIN_ENV || AFS_USR_FBSD_ENV */
141 #include <arpa/nameser.h>
143 #endif /* AFS_AFSDB_ENV */
145 /* glibc 2.2 has pthread_attr_setstacksize */
146 #if defined(AFS_LINUX22_ENV) || defined(AFS_USR_LINUX22_ENV) && (__GLIBC_MINOR__ < 2)
147 #define pthread_attr_setstacksize(a,b) 0
150 #include <sys/stat.h> /* afs_usrops.h uses struct stat in prototypes */
152 #ifdef NETSCAPE_NSAPI
156 #else /* NETSCAPE_NSAPI */
160 #endif /* NETSCAPE_NSAPI */
162 #ifdef AFS_USR_UNDEF_KERNEL_ENV
163 #undef AFS_USR_UNDEF_KERNEL_ENV
168 * User space versions of kernel data structures.
172 #define MAXNAMLEN 512
176 #define PAGESIZE 4096
180 * This file contains data types and definitions for running
181 * the AFS client in user space. Kernel data structures
182 * are renamed from XXXX to usr_XXXX.
187 #ifdef AFS_USR_SGI_ENV
189 #endif /* AFS_USR_SGI_ENV */
191 #if defined(AFS_USR_DARWIN_ENV) || defined(AFS_USR_FBSD_ENV)
196 #define mount usr_mount
199 #define fileops usr_fileops
200 #define vnodeops usr_vnodeops
201 #define vnode usr_vnode
202 #define inode usr_inode
203 #define whymountroot_t usr_whymountroot_t
204 #define vfsops usr_vfsops
206 #define vattr usr_vattr
208 #define statfs usr_statfs
209 #define ucred usr_ucred
210 #define user usr_user
211 #define proc usr_proc
212 #define file usr_file
213 #define dirent usr_dirent
214 #define flock usr_flock
216 #define sysent usr_sysent
217 #define in_ifaddr usr_in_ifaddr
218 #define ifaddr usr_ifaddr
219 #define ifnet usr_ifnet
220 #define socket usr_socket
221 #define crget usr_crget
222 #define crcopy usr_crcopy
223 #define crhold usr_crhold
224 #define crfree usr_crfree
225 #define vtype_t usr_vtype_t
226 #define vcexcl usr_vcexcl
227 #define m_free usr_m_free
228 #define m_freem usr_m_freem
229 #define m_adj usr_m_adj
230 #define m_pullup usr_m_pullup
231 #define uiomove usr_uiomove
232 #define EXCL usr_EXCL
233 #define NONEXCL usr_NONEXCL
234 #define uio_rw usr_uio_rw
238 #define ino_t usr_ino_t
239 #define offset_t usr_offset_t
240 #define getpid() usr_getpid()
241 #define setpag(A,B,C,D) usr_setpag((A),(B),(C),(D))
247 enum usr_vcexcl { usr_NONEXCL, usr_EXCL };
248 typedef long offset_t;
249 #ifdef AFS_USR_OSF_ENV
250 typedef int usr_ino_t;
251 #else /* AFS_USR_OSF_ENV */
252 typedef long usr_ino_t;
253 #endif /* AFS_USR_OSF_ENV */
255 #if defined(AFS_USR_AIX_ENV) || defined(AFS_USR_SGI_ENV)
256 #define SYS_setgroups 101
259 #define ioctl() usr_ioctl()
261 #define label_t jmp_buf
267 #define VFSTOM(VP) ((struct usr_mount *)(VP)->vfs_mount)
297 #define VINACT 0x0001
299 #define VNOMAP 0x0004
301 #define VSHARE 0x0010
304 #define VWASMAP 0x0080
305 #define VXLOCK 0x0100
349 typedef int usr_vtype_t;
355 #define VOP_RDWR afs_osi_VOP_RDWR
371 #define DTYPE_VNODE 1
420 #define INOACC 0x0010
421 #define IMODTIME 0x0020
424 #define IFASTSYMLNK 0x0100
425 #define IMODACC 0x0200
426 #define IATTCHG 0x0400
427 #define IBDWRITE 0x0800
460 #define IFIFO 0010000
461 #define IFCHR 0020000
462 #define IFDIR 0040000
463 #define IFBLK 0060000
464 #define IFREG 0100000
465 #define IFLNK 0120000
466 #define IFSHAD 0130000
467 #define IFSOCK 0140000
528 #define I_FREE 0x00000001
529 #define I_DIR 0x00000002
530 #define I_IBLK 0x00000004
531 #define I_CHEAP 0x00000008
532 #define I_SHAD 0x00000010
533 #define I_QUOTA 0x00000020
542 #define VTOI(VP) ((struct usr_inode *)(VP)->v_data)
543 #define ITOV(IP) ((struct usr_vnode *)&(IP)->i_vnode)
561 #ifdef ROOT_FRONTMOUNT
562 #undef ROOT_FRONTMOUNT
564 #ifdef ROOT_BACKMOUNT
565 #undef ROOT_BACKMOUNT
568 #define ROOT_INIT 0x0001
569 #define ROOT_REMOUNT 0X0002
570 #define ROOT_UNMOUNT 0x0003
571 #define ROOT_FRONTMOUNT 0x0004
572 #define ROOT_BACKMOUNT 0x0005
614 #define VFS_STATFS(vfsp, sp) ((sp)->f_bsize=4096, 0)
635 #define FAPPEND 0x0100
636 #define IO_APPEND FAPPEND
638 #define IO_SYNC FSYNC
639 #define FTRUNC 0x0400
640 #define FWRITE 0x0800
661 #define F_GETLK 0x0001
662 #define F_RDLCK 0x0002
663 #define F_SETLK 0x0003
664 #define F_SETLKW 0x0004
665 #define F_UNLCK 0x0005
666 #define F_WRLCK 0x0006
681 #define LOCK_SH F_RDLCK
682 #define LOCK_UN F_UNLCK
683 #define LOCK_EX F_WRLCK
684 #define LOCK_NB 0x0007
693 #define FEXLOCK F_WRLCK
694 #define FSHLOCK F_RDLCK
702 enum usr_uio_rw { USR_UIO_READ, USR_UIO_WRITE };
711 #define UIO_READ 0x0000
712 #define UIO_WRITE 0x0001
721 #define UIO_USERSPACE 0x0000
722 #define UIO_SYSSPACE 0x0001
765 #define B_ASYNC 0x0002
766 #define B_DELWRI 0x0004
767 #define B_DIRTY 0x0008
768 #define B_DONE 0x0010
769 #define B_ERROR 0x0020
770 #define B_FREE 0x0040
771 #define B_NOCACHE 0x0080
772 #define B_PFSTORE 0x0100
773 #define B_READ 0x0200
775 #define B_WANTED 0x0800
776 #define B_WRITE 0x1000
804 #define MMAXOFF 16384
810 #define IA_SIN(IA) (&(IA)->ia_addr)
822 #define mtod(m,t) ((t)((m)->m_data))
829 #define panic(S) do{fprintf(stderr, S);assert(0);}while(0)
830 #define abort() assert(0)
831 #define usr_assert(A) assert(A)
833 #ifdef NETSCAPE_NSAPI
836 * All CONDVARs created with the same CRITICAL end up being the
837 * same CONDVAR, not a new one. If we want to use more than
838 * one usr_cond_t with the same usr_mutex_t, then we need a CRITICAL
839 * for each CONDVAR, otherwise we cannot know which thread we are
840 * waking when we do the signal.
848 #define usr_mutex_t CRITICAL
849 #define usr_thread_t SYS_THREAD
850 #define usr_key_t int
852 #define usr_mutex_init(A) (*(A)=crit_init(), 0)
853 #define usr_mutex_destroy(A) (crit_terminate(*(A)), 0)
854 #define usr_mutex_lock(A) crit_enter(*(A))
855 #define usr_mutex_trylock(A) (crit_enter(*(A)),1)
856 #define usr_mutex_unlock(A) crit_exit(*(A))
858 #define usr_cond_init(A) \
860 (A)->lock = crit_init(), \
861 (A)->cond = condvar_init((A)->lock), 0)
863 #define usr_cond_destroy(A) \
864 (condvar_terminate((A)->cond), \
865 crit_terminate((A)->lock), 0)
867 #define usr_cond_signal(A) \
869 crit_enter((A)->lock); \
870 if ((A)->waiters != 0) { \
871 condvar_notify((A)->cond);\
874 crit_exit((A)->lock); \
877 #define usr_cond_broadcast(A) \
879 crit_enter((A)->lock); \
880 while ((A)->waiters != 0) { \
881 condvar_notify((A)->cond); \
884 crit_exit((A)->lock); \
887 #define usr_cond_wait(A,B) \
888 (crit_enter((A)->lock), \
891 condvar_wait((A)->cond), \
892 crit_exit((A)->lock), \
895 #define usr_thread_create(A,B,C) \
896 ((*(A)=systhread_start(SYSTHREAD_DEFAULT_PRIORITY, \
897 0,B,C))==SYS_THREAD_ERROR)
898 #define usr_thread_detach(A) 0
899 #define usr_keycreate(A,B) (*(A)=systhread_newkey(),0)
900 #define usr_setspecific(A,B) (systhread_setdata(A,B),0)
901 #define usr_getspecific(A,B) (*(B)=systhread_getdata(A),0)
902 #define usr_thread_self() systhread_current()
903 #ifdef AFS_USR_SUN5_ENV
904 #define usr_thread_sleep(A) \
905 poll(0, 0, (A)->tv_sec*1000+(A)->tv_nsec/1000000)
906 #else /* AFS_USR_SUN5_ENV */
907 #define usr_thread_sleep(A) \
908 systhread_sleep((A)->tv_sec*1000+(A)->tv_nsec/1000000)
909 #endif /* AFS_USR_SUN5_ENV */
911 #define uprintf printf
913 #define usr_getpid() (int)(usr_thread_self())
915 #define ISAFS_GLOCK() (usr_thread_self() == afs_global_owner)
917 #else /* NETSCAPE_NSAPI */
920 * Mutex and condition variable used to implement sleep
922 extern pthread_mutex_t usr_sleep_mutex;
923 extern pthread_cond_t usr_sleep_cond;
925 #define usr_cond_t pthread_cond_t
926 #define usr_mutex_t pthread_mutex_t
927 #define usr_thread_t pthread_t
928 #define usr_key_t pthread_key_t
930 #define usr_mutex_init(A) assert(pthread_mutex_init(A,NULL) == 0)
931 #define usr_mutex_destroy(A) assert(pthread_mutex_destroy(A) == 0)
932 #define usr_mutex_lock(A) assert(pthread_mutex_lock(A) == 0)
933 #define usr_mutex_trylock(A) ((pthread_mutex_trylock(A)==0)?1:0)
934 #define usr_mutex_unlock(A) assert(pthread_mutex_unlock(A) == 0)
935 #define usr_cond_init(A) assert(pthread_cond_init(A,NULL) == 0)
936 #define usr_cond_destroy(A) assert(pthread_cond_destroy(A) == 0)
937 #define usr_cond_signal(A) assert(pthread_cond_signal(A) == 0)
938 #define usr_cond_broadcast(A) assert(pthread_cond_broadcast(A) == 0)
939 #define usr_cond_wait(A,B) pthread_cond_wait(A,B)
940 #define usr_cond_timedwait(A,B,C) pthread_cond_timedwait(A,B,C)
942 #define usr_thread_create(A,B,C) \
944 pthread_attr_t attr; \
945 assert(pthread_attr_init(&attr) == 0); \
946 assert(pthread_attr_setstacksize(&attr, 124288) == 0); \
947 assert(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0); \
948 assert(pthread_create((A), &attr, (B), (void *)(C)) == 0); \
949 assert(pthread_attr_destroy(&attr) == 0); \
951 #define usr_thread_detach(A) pthread_detach(A)
952 #define usr_keycreate(A,B) assert(pthread_key_create(A,B) == 0)
953 #define usr_setspecific(A,B) pthread_setspecific(A,B)
954 #define usr_getspecific(A,B) (*(B)=pthread_getspecific(A),0)
955 #define usr_thread_self() pthread_self()
956 #define usr_thread_sleep(A) \
958 struct timespec _sleep_ts; \
959 struct timeval _sleep_tv; \
960 gettimeofday(&_sleep_tv, NULL); \
962 _sleep_ts.tv_sec += _sleep_tv.tv_sec; \
963 _sleep_ts.tv_nsec += _sleep_tv.tv_usec * 1000; \
964 if (_sleep_ts.tv_nsec >= 1000000000) { \
965 _sleep_ts.tv_sec += 1; \
966 _sleep_ts.tv_nsec -= 1000000000; \
968 assert(pthread_mutex_lock(&usr_sleep_mutex) == 0); \
969 pthread_cond_timedwait(&usr_sleep_cond, &usr_sleep_mutex, &_sleep_ts); \
970 assert(pthread_mutex_unlock(&usr_sleep_mutex) == 0); \
973 #define uprintf printf
975 #define usr_getpid() (int)(usr_thread_self())
976 #define ISAFS_GLOCK() (usr_thread_self() == afs_global_owner)
978 #endif /* NETSCAPE_NSAPI */
980 #define copyin(A,B,C) (memcpy((void *)B,(void *)A,C), 0)
981 #define copyout(A,B,C) (memcpy((void *)B,(void *)A,C), 0)
982 #define copyinstr(A,B,C,D) (strncpy(B,A,C),(*D)=strlen(B), 0)
983 #define copyoutstr(A,B,C,D) (strncpy(B,A,C),(*D)=strlen(B), 0)
985 #define vattr_null(A) usr_vattr_null(A)
987 #define VN_HOLD(vp) \
992 #define VN_RELE(vp) \
994 AFS_ASSERT_GLOCK(); \
995 usr_assert((vp)->v_count > 0); \
996 if (--((vp)->v_count) == 0) \
997 afs_inactive(vp, u.u_cred); \
1001 unsigned long f_type;
1002 unsigned long f_bsize;
1003 unsigned long f_frsize;
1004 unsigned long f_ffree;
1005 unsigned long f_favail;
1007 unsigned long val[2];
1009 char f_basetype[FSTYPSZ];
1010 unsigned long f_flag;
1011 unsigned long f_namemax;
1012 unsigned long f_blocks;
1013 unsigned long f_bfree;
1014 unsigned long f_bavail;
1015 unsigned long f_files;
1020 usr_vtype_t va_type;
1021 unsigned short va_mode;
1024 unsigned long va_fsid;
1025 unsigned long va_nodeid;
1026 unsigned long va_nlink;
1027 unsigned long va_size;
1028 struct timeval va_atime;
1029 struct timeval va_mtime;
1030 struct timeval va_ctime;
1031 unsigned long va_rdev;
1032 unsigned long va_blocksize;
1033 unsigned long va_blocks;
1034 unsigned long va_vcode;
1060 #define VWRITE 00200
1065 unsigned short v_flag;
1066 unsigned long v_count;
1067 struct usr_vnodeops *v_op;
1068 struct usr_vfs * v_vfsp;
1070 unsigned long v_rdev;
1075 daddr_t i_db[NDADDR];
1076 struct usr_vnode *i_devvp;
1077 unsigned long i_dev;
1079 struct usr_inode *i_freef;
1080 struct usr_inode **i_freeb;
1082 daddr_t i_ib[NIADDR];
1083 unsigned short i_mode;
1085 unsigned long i_number;
1088 struct usr_vnode i_vnode;
1090 unsigned long ic_spare[4];
1093 extern struct usr_inode *iget();
1095 struct usr_fileops {
1096 int (*vno_rw)(void);
1097 int (*vno_ioctl)(void);
1098 int (*vno_select)(void);
1099 int (*vno_closex)(void);
1103 unsigned short f_flag;
1105 struct usr_ucred *f_cred;
1106 struct usr_fileops *f_ops;
1110 extern struct usr_file *falloc();
1111 extern struct usr_file *getf(int);
1121 unsigned short fid_len;
1122 unsigned short fid_reserved;
1123 char fid_data[MAXFIDSZ];
1135 extern struct usr_ucred *usr_crget(void);
1136 extern struct usr_ucred *usr_crcopy(struct usr_ucred *);
1137 extern int usr_crhold(struct usr_ucred *);
1138 extern int usr_crfree(struct usr_ucred *);
1139 extern struct usr_ucred *afs_global_ucredp;
1142 unsigned long p_flag;
1145 struct usr_ucred *p_ucred;
1165 struct iovec *uio_iov;
1186 struct usr_fs *b_fs;
1189 unsigned int b_resid;
1190 struct usr_vnode *b_vp;
1198 #define NDIRSIZ_LEN(len) \
1199 ((sizeof (struct usr_dirent)+4 - (MAXNAMLEN+1)) + (((len)+1 + 3) &~ 3))
1201 struct usr_vnodeops {
1202 int (*vn_open)(char *path, int flags, int mode);
1203 int (*vn_close)(int fd);
1205 int (*vn_ioctl)(void);
1206 int (*vn_select)(void);
1207 int (*vn_getattr)();
1208 int (*vn_setattr)();
1217 int (*vn_readdir)();
1218 int (*vn_symlink)();
1219 int (*vn_readlink)();
1221 int (*vn_inactive)();
1223 int (*vn_strategy)();
1226 int (*vn_lockctl)();
1237 unsigned long m_dev;
1238 struct usr_inode *m_inodp;
1239 struct usr_buf *m_bufp;
1240 struct usr_vnode *m_mount;
1242 extern struct usr_mount *getmp(unsigned long);
1244 typedef long usr_whymountroot_t;
1248 int (*vfs_unmount)();
1250 int (*vfs_statfs)();
1251 int (*vfs_mountroot)();
1252 int (*vfs_swapvp)();
1256 struct usr_vnode *vfs_vnodecovered;
1258 unsigned long val[2];
1261 unsigned long vfs_bsize;
1262 struct usr_mount *vfs_mount;
1263 struct usr_vfsops *vfs_op;
1270 extern struct usr_sysent usr_sysent[];
1273 struct usr_ifnet *if_next;
1277 struct usr_ifaddr *if_addrlist;
1279 extern struct usr_ifnet *usr_ifnet;
1282 struct usr_ifaddr *ifa_next;
1283 struct usr_ifnet *ifa_ifp;
1284 struct sockaddr ifa_addr;
1294 struct usr_in_ifaddr {
1295 struct usr_in_ifaddr *ia_next;
1296 struct usr_ifnet *ia_ifp;
1297 struct sockaddr_in ia_addr;
1298 unsigned long ia_net;
1299 unsigned long ia_netmask;
1300 unsigned long ia_subnet;
1301 unsigned long ia_subnetmask;
1302 struct in_addr ia_netbroadcast;
1304 extern struct usr_in_ifaddr *usr_in_ifaddr;
1306 extern usr_key_t afs_global_u_key; /* for per thread authentication */
1308 #if defined(AFS_USR_OSF_ENV)
1314 #endif /* UKERNEL */
1317 #if defined(AFS_OFS_ENV) || defined(AFS_USR_OSF_ENV)
1318 unsigned int d_fileno;
1319 #else /* AFS_OFS_ENV || AFS_USR_OSF_ENV */
1320 unsigned long d_fileno;
1321 #endif /* AFS_OFS_ENV || AFS_USR_OSF_ENV */
1322 unsigned short d_reclen;
1323 unsigned short d_namlen;
1327 #define NGROUPS NGROUPS_MAX
1330 #define NOGROUP (-1)
1337 unsigned long cr_ref;
1345 gid_t cr_groups[NGROUPS];
1358 unsigned long u_expiration;
1359 struct usr_proc *u_procp;
1360 struct usr_ucred *u_cred;
1365 #define u_rval1 u_r.r_val1
1366 #define u (*(get_user_struct()))
1368 extern struct usr_user *get_user_struct(void);
1370 #define USR_DIRSIZE 2048
1373 unsigned long d_ino;
1374 unsigned long d_off;
1375 unsigned short d_reclen;
1376 char d_name[MAXNAMLEN+1];
1387 extern unsigned short usr_rx_port;
1389 #define AFS_LOOKUP_NOEVAL 1
1391 #endif /* __AFS_SYSINCLUDESH__ so idempotent */