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)) || (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())
979 #define ISAFS_GLOCK() (usr_thread_self() == afs_global_owner)
981 #endif /* NETSCAPE_NSAPI */
983 #define copyin(A,B,C) (memcpy((void *)B,(void *)A,C), 0)
984 #define copyout(A,B,C) (memcpy((void *)B,(void *)A,C), 0)
985 #define copyinstr(A,B,C,D) (strncpy(B,A,C),(*D)=strlen(B), 0)
986 #define copyoutstr(A,B,C,D) (strncpy(B,A,C),(*D)=strlen(B), 0)
988 #define vattr_null(A) usr_vattr_null(A)
990 #define VN_HOLD(vp) \
995 #define VN_RELE(vp) \
997 AFS_ASSERT_GLOCK(); \
998 usr_assert((vp)->v_count > 0); \
999 if (--((vp)->v_count) == 0) \
1000 afs_inactive(vp, u.u_cred); \
1004 unsigned long f_type;
1005 unsigned long f_bsize;
1006 unsigned long f_frsize;
1007 unsigned long f_ffree;
1008 unsigned long f_favail;
1010 unsigned long val[2];
1012 char f_basetype[FSTYPSZ];
1013 unsigned long f_flag;
1014 unsigned long f_namemax;
1015 unsigned long f_blocks;
1016 unsigned long f_bfree;
1017 unsigned long f_bavail;
1018 unsigned long f_files;
1023 usr_vtype_t va_type;
1024 unsigned short va_mode;
1027 unsigned long va_fsid;
1028 unsigned long va_nodeid;
1029 unsigned long va_nlink;
1030 unsigned long va_size;
1031 struct timeval va_atime;
1032 struct timeval va_mtime;
1033 struct timeval va_ctime;
1034 unsigned long va_rdev;
1035 unsigned long va_blocksize;
1036 unsigned long va_blocks;
1037 unsigned long va_vcode;
1063 #define VWRITE 00200
1068 unsigned short v_flag;
1069 unsigned long v_count;
1070 struct usr_vnodeops *v_op;
1071 struct usr_vfs *v_vfsp;
1073 unsigned long v_rdev;
1078 daddr_t i_db[NDADDR];
1079 struct usr_vnode *i_devvp;
1080 unsigned long i_dev;
1082 struct usr_inode *i_freef;
1083 struct usr_inode **i_freeb;
1085 daddr_t i_ib[NIADDR];
1086 unsigned short i_mode;
1088 unsigned long i_number;
1091 struct usr_vnode i_vnode;
1093 unsigned long ic_spare[4];
1096 extern struct usr_inode *iget();
1098 struct usr_fileops {
1099 int (*vno_rw) (void);
1100 int (*vno_ioctl) (void);
1101 int (*vno_select) (void);
1102 int (*vno_closex) (void);
1106 unsigned short f_flag;
1108 struct usr_ucred *f_cred;
1109 struct usr_fileops *f_ops;
1113 extern struct usr_file *falloc();
1114 extern struct usr_file *getf(int);
1124 unsigned short fid_len;
1125 unsigned short fid_reserved;
1126 char fid_data[MAXFIDSZ];
1138 extern struct usr_ucred *usr_crget(void);
1139 extern struct usr_ucred *usr_crcopy(struct usr_ucred *);
1140 extern int usr_crhold(struct usr_ucred *);
1141 extern int usr_crfree(struct usr_ucred *);
1142 extern struct usr_ucred *afs_global_ucredp;
1145 unsigned long p_flag;
1148 struct usr_ucred *p_ucred;
1168 struct iovec *uio_iov;
1189 struct usr_fs *b_fs;
1192 unsigned int b_resid;
1193 struct usr_vnode *b_vp;
1201 #define NDIRSIZ_LEN(len) \
1202 ((sizeof (struct usr_dirent)+4 - (MAXNAMLEN+1)) + (((len)+1 + 3) &~ 3))
1204 struct usr_vnodeops {
1205 int (*vn_open) (char *path, int flags, int mode);
1206 int (*vn_close) (int fd);
1208 int (*vn_ioctl) (void);
1209 int (*vn_select) (void);
1210 int (*vn_getattr) ();
1211 int (*vn_setattr) ();
1212 int (*vn_access) ();
1213 int (*vn_lookup) ();
1214 int (*vn_create) ();
1215 int (*vn_remove) ();
1217 int (*vn_rename) ();
1220 int (*vn_readdir) ();
1221 int (*vn_symlink) ();
1222 int (*vn_readlink) ();
1224 int (*vn_inactive) ();
1226 int (*vn_strategy) ();
1228 int (*vn_brelse) ();
1229 int (*vn_lockctl) ();
1239 unsigned long m_dev;
1240 struct usr_inode *m_inodp;
1241 struct usr_buf *m_bufp;
1242 struct usr_vnode *m_mount;
1244 extern struct usr_mount *getmp(unsigned long);
1246 typedef long usr_whymountroot_t;
1249 int (*vfs_mount) ();
1250 int (*vfs_unmount) ();
1252 int (*vfs_statfs) ();
1253 int (*vfs_mountroot) ();
1254 int (*vfs_swapvp) ();
1258 struct usr_vnode *vfs_vnodecovered;
1260 unsigned long val[2];
1263 unsigned long vfs_bsize;
1264 struct usr_mount *vfs_mount;
1265 struct usr_vfsops *vfs_op;
1272 extern struct usr_sysent usr_sysent[];
1275 struct usr_ifnet *if_next;
1279 struct usr_ifaddr *if_addrlist;
1281 extern struct usr_ifnet *usr_ifnet;
1284 struct usr_ifaddr *ifa_next;
1285 struct usr_ifnet *ifa_ifp;
1286 struct sockaddr ifa_addr;
1296 struct usr_in_ifaddr {
1297 struct usr_in_ifaddr *ia_next;
1298 struct usr_ifnet *ia_ifp;
1299 struct sockaddr_in ia_addr;
1300 unsigned long ia_net;
1301 unsigned long ia_netmask;
1302 unsigned long ia_subnet;
1303 unsigned long ia_subnetmask;
1304 struct in_addr ia_netbroadcast;
1306 extern struct usr_in_ifaddr *usr_in_ifaddr;
1308 extern usr_key_t afs_global_u_key; /* for per thread authentication */
1310 #if defined(AFS_USR_OSF_ENV)
1316 #endif /* UKERNEL */
1319 #if defined(AFS_OFS_ENV) || defined(AFS_USR_OSF_ENV)
1320 unsigned int d_fileno;
1321 #else /* AFS_OFS_ENV || AFS_USR_OSF_ENV */
1322 unsigned long d_fileno;
1323 #endif /* AFS_OFS_ENV || AFS_USR_OSF_ENV */
1324 unsigned short d_reclen;
1325 unsigned short d_namlen;
1329 #define NGROUPS NGROUPS_MAX
1332 #define NOGROUP (-1)
1339 unsigned long cr_ref;
1347 gid_t cr_groups[NGROUPS];
1360 unsigned long u_expiration;
1361 struct usr_proc *u_procp;
1362 struct usr_ucred *u_cred;
1367 #define u_rval1 u_r.r_val1
1368 #define u (*(get_user_struct()))
1370 extern struct usr_user *get_user_struct(void);
1372 #define USR_DIRSIZE 2048
1375 unsigned long d_ino;
1376 unsigned long d_off;
1377 unsigned short d_reclen;
1378 char d_name[MAXNAMLEN + 1];
1389 extern unsigned short usr_rx_port;
1391 #define AFS_LOOKUP_NOEVAL 1
1393 #endif /* __AFS_SYSINCLUDESH__ so idempotent */