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
16 #if !defined(AFS_USR_DARWIN_ENV) && !defined(AFS_USR_FBSD_ENV) && !defined(AFS_USR_DFBSD_ENV) /* must be included after KERNEL undef'd */
25 #if !defined(AFS_USR_DARWIN_ENV) && !defined(AFS_USR_FBSD_ENV) && !defined(AFS_USR_DFBSD_ENV) /* must be included after KERNEL undef'd */
28 #include <sys/types.h>
33 #ifdef AFS_USR_SUN5_ENV
35 #include <sys/param.h>
36 #include <sys/socket.h>
38 #include <sys/sockio.h>
41 #include <sys/fcntl.h>
42 #include <netinet/in.h>
44 #include <arpa/inet.h>
45 #endif /* AFS_USR_SUN5_ENV */
48 #ifdef AFS_USR_AIX_ENV
49 #include <sys/param.h>
50 #include <sys/socket.h>
53 #include <netinet/in.h>
54 #include <sys/stropts.h>
56 #include <sys/timers.h>
57 #include <arpa/inet.h>
58 #endif /* AFS_USR_AIX_ENV */
60 #ifdef AFS_USR_SGI_ENV
61 #include <sys/param.h>
62 #include <sys/socket.h>
64 #include <sys/sockio.h>
67 #include <sys/fcntl.h>
68 #include <netinet/in.h>
70 #include <arpa/inet.h>
71 #endif /* AFS_USR_SGI_ENV */
73 #ifdef AFS_USR_HPUX_ENV
74 #include <sys/param.h>
75 #include <sys/socket.h>
79 #include <sys/fcntl.h>
80 #include <netinet/in.h>
82 #include <arpa/inet.h>
83 #endif /* AFS_USR_HPUX_ENV */
85 #ifdef AFS_USR_OSF_ENV
88 #define AFS_USR_UNDEF_KERNEL_ENV 1
90 #include <sys/param.h>
91 #include <sys/socket.h>
94 #include <sys/ioctl.h>
96 #include <sys/fcntl.h>
97 #include <netinet/in.h>
99 #include <arpa/inet.h>
100 #endif /* AFS_USR_OSF_ENV */
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>
110 #include <sys/file.h>
111 #include <sys/stat.h>
112 #include <sys/fcntl.h>
113 #include <netinet/in.h>
115 #include <arpa/inet.h>
117 #endif /* AFS_USR_LINUX22_ENV */
119 #if defined(AFS_USR_DARWIN_ENV) || defined(AFS_USR_FBSD_ENV) || defined(AFS_USR_DFBSD_ENV)
125 #define AFS_USR_UNDEF_KERNEL_ENV 1
129 #include <sys/param.h>
130 #include <sys/types.h>
131 #include <sys/socket.h>
133 #include <sys/file.h>
134 #include <sys/ioctl.h>
135 #include <sys/stat.h>
136 #include <sys/fcntl.h>
138 #include <netinet/in.h>
140 #include <arpa/inet.h>
145 #define O_SYNC O_FSYNC
147 #endif /* AFS_USR_DARWIN_ENV || AFS_USR_FBSD_ENV */
149 #ifdef HAVE_SYS_BITYPES_H
150 #include <sys/bitypes.h>
152 #ifdef HAVE_SYS_STATFS_H
153 #include <sys/statfs.h>
155 #ifdef HAVE_SYS_STATVFS_H
156 #include <sys/statvfs.h>
159 #ifndef HAVE_FSBLKCNT_T
160 typedef unsigned int fsblkcnt_t
;
163 #include <arpa/nameser.h>
164 #ifdef HAVE_ARPA_NAMESER_COMPAT_H
165 #include <arpa/nameser_compat.h>
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
174 #include <sys/stat.h> /* afs_usrops.h uses struct stat in prototypes */
178 #ifdef AFS_USR_UNDEF_KERNEL_ENV
179 #undef AFS_USR_UNDEF_KERNEL_ENV
184 * User space versions of kernel data structures.
188 #define MAXNAMLEN 512
192 * This file contains data types and definitions for running
193 * the AFS client in user space. Kernel data structures
194 * are renamed from XXXX to usr_XXXX.
202 #if defined(AFS_USR_DARWIN_ENV) || defined(AFS_USR_FBSD_ENV)
207 #define mount usr_mount
210 #define fileops usr_fileops
211 #define vnodeops usr_vnodeops
212 #define vnode usr_vnode
213 #define inode usr_inode
214 #define whymountroot_t usr_whymountroot_t
215 #define vfsops usr_vfsops
217 #define vattr usr_vattr
219 #define statfs usr_statfs
220 #define file usr_file
221 #define dirent usr_dirent
222 #define flock usr_flock
224 #define sysent usr_sysent
225 #define ifaddr usr_ifaddr
226 #define ifnet usr_ifnet
227 #define in_ifaddr usr_in_ifaddr
229 #define socket usr_socket
230 #define crget usr_crget
231 #define crcopy usr_crcopy
232 #define crhold usr_crhold
233 #define crfree usr_crfree
234 #define vtype_t usr_vtype_t
235 #define vcexcl usr_vcexcl
236 #define m_free usr_m_free
237 #define m_freem usr_m_freem
238 #define m_adj usr_m_adj
239 #define m_pullup usr_m_pullup
240 #define uiomove usr_uiomove
241 #define EXCL usr_EXCL
242 #define NONEXCL usr_NONEXCL
243 #define uio_rw usr_uio_rw
247 #define ino_t usr_ino_t
248 #define offset_t usr_offset_t
249 #define getpid() usr_getpid()
250 #define setpag(A,B,C,D) usr_setpag((A),(B),(C),(D))
251 #define osi_getpid() afs_pointer_to_int(usr_thread_self())
257 enum usr_vcexcl
{ usr_NONEXCL
, usr_EXCL
};
258 typedef long offset_t
;
259 #ifdef AFS_USR_OSF_ENV
260 typedef int usr_ino_t
;
261 #else /* AFS_USR_OSF_ENV */
262 typedef long usr_ino_t
;
263 #endif /* AFS_USR_OSF_ENV */
265 #if defined(AFS_USR_AIX_ENV) || defined(AFS_USR_SGI_ENV)
266 #define SYS_setgroups 101
269 #define ioctl() usr_ioctl()
271 #define label_t jmp_buf
277 #define VFSTOM(VP) ((struct usr_mount *)(VP)->vfs_mount)
307 #define VINACT 0x0001
309 #define VNOMAP 0x0004
311 #define VSHARE 0x0010
314 #define VWASMAP 0x0080
315 #define VXLOCK 0x0100
348 #define VSOCK S_IFSOCK
349 #define VFIFO S_IFIFO
351 typedef int usr_vtype_t
;
357 #define VOP_RDWR afs_osi_VOP_RDWR
373 #define DTYPE_VNODE 1
422 #define INOACC 0x0010
423 #define IMODTIME 0x0020
426 #define IFASTSYMLNK 0x0100
427 #define IMODACC 0x0200
428 #define IATTCHG 0x0400
429 #define IBDWRITE 0x0800
462 #define IFIFO 0010000
463 #define IFCHR 0020000
464 #define IFDIR 0040000
465 #define IFBLK 0060000
466 #define IFREG 0100000
467 #define IFLNK 0120000
468 #define IFSHAD 0130000
469 #define IFSOCK 0140000
530 #define I_FREE 0x00000001
531 #define I_DIR 0x00000002
532 #define I_IBLK 0x00000004
533 #define I_CHEAP 0x00000008
534 #define I_SHAD 0x00000010
535 #define I_QUOTA 0x00000020
544 #define VTOI(VP) ((struct usr_inode *)(VP)->v_data)
545 #define ITOV(IP) ((struct usr_vnode *)&(IP)->i_vnode)
563 #ifdef ROOT_FRONTMOUNT
564 #undef ROOT_FRONTMOUNT
566 #ifdef ROOT_BACKMOUNT
567 #undef ROOT_BACKMOUNT
570 #define ROOT_INIT 0x0001
571 #define ROOT_REMOUNT 0X0002
572 #define ROOT_UNMOUNT 0x0003
573 #define ROOT_FRONTMOUNT 0x0004
574 #define ROOT_BACKMOUNT 0x0005
616 #define VFS_STATFS(vfsp, sp) ((sp)->f_bsize=4096, 0)
637 #define FAPPEND 0x0100
638 #define IO_APPEND FAPPEND
640 #define IO_SYNC FSYNC
641 #define FTRUNC 0x0400
642 #define FWRITE 0x0800
663 #define F_GETLK 0x0001
664 #define F_RDLCK 0x0002
665 #define F_SETLK 0x0003
666 #define F_SETLKW 0x0004
667 #define F_UNLCK 0x0005
668 #define F_WRLCK 0x0006
683 #define LOCK_SH F_RDLCK
684 #define LOCK_UN F_UNLCK
685 #define LOCK_EX F_WRLCK
686 #define LOCK_NB 0x0007
695 #define FEXLOCK F_WRLCK
696 #define FSHLOCK F_RDLCK
704 enum usr_uio_rw
{ USR_UIO_READ
, USR_UIO_WRITE
};
713 #define UIO_READ 0x0000
714 #define UIO_WRITE 0x0001
723 #define UIO_USERSPACE 0x0000
724 #define UIO_SYSSPACE 0x0001
767 #define B_ASYNC 0x0002
768 #define B_DELWRI 0x0004
769 #define B_DIRTY 0x0008
770 #define B_DONE 0x0010
771 #define B_ERROR 0x0020
772 #define B_FREE 0x0040
773 #define B_NOCACHE 0x0080
774 #define B_PFSTORE 0x0100
775 #define B_READ 0x0200
777 #define B_WANTED 0x0800
778 #define B_WRITE 0x1000
806 #define MMAXOFF 16384
812 #define IA_SIN(IA) (&(IA)->ia_addr)
824 #define mtod(m,t) ((t)((m)->m_data))
831 static_inline
void panic(const char *format
, ...) AFS_NORETURN
;
832 static_inline
void panic(const char *format
, ...)
835 va_start(ap
, format
);
836 vfprintf(stderr
, format
, ap
);
840 #define abort() assert(0)
841 #define usr_assert(A) assert(A)
845 * Mutex and condition variable used to implement sleep
847 extern pthread_mutex_t usr_sleep_mutex
;
848 extern pthread_cond_t usr_sleep_cond
;
850 #define usr_cond_t pthread_cond_t
851 #define usr_mutex_t pthread_mutex_t
852 #define usr_thread_t pthread_t
853 #define usr_key_t pthread_key_t
855 #define usr_mutex_init(A) opr_Verify(pthread_mutex_init(A,NULL) == 0)
856 #define usr_mutex_destroy(A) opr_Verify(pthread_mutex_destroy(A) == 0)
857 #define usr_mutex_lock(A) opr_Verify(pthread_mutex_lock(A) == 0)
858 #define usr_mutex_trylock(A) ((pthread_mutex_trylock(A)==0)?1:0)
859 #define usr_mutex_unlock(A) opr_Verify(pthread_mutex_unlock(A) == 0)
860 #define usr_cond_init(A) opr_Verify(pthread_cond_init(A,NULL) == 0)
861 #define usr_cond_destroy(A) opr_Verify(pthread_cond_destroy(A) == 0)
862 #define usr_cond_signal(A) opr_Verify(pthread_cond_signal(A) == 0)
863 #define usr_cond_broadcast(A) opr_Verify(pthread_cond_broadcast(A) == 0)
864 #define usr_cond_wait(A,B) pthread_cond_wait(A,B)
865 #define usr_cond_timedwait(A,B,C) pthread_cond_timedwait(A,B,C)
867 #define usr_thread_create(A,B,C) \
869 pthread_attr_t attr; \
870 opr_Verify(pthread_attr_init(&attr) == 0); \
871 opr_Verify(pthread_attr_setstacksize(&attr, 122880) == 0); \
872 opr_Verify(pthread_create((A), &attr, (B), (void *)(C)) == 0); \
873 opr_Verify(pthread_attr_destroy(&attr) == 0); \
875 #define usr_thread_join(A,B) pthread_join(A, B)
876 #define usr_thread_detach(A) pthread_detach(A)
877 #define usr_keycreate(A,B) opr_Verify(pthread_key_create(A,B) == 0)
878 #define usr_setspecific(A,B) pthread_setspecific(A,B)
879 #define usr_getspecific(A,B) (*(B)=pthread_getspecific(A),0)
880 #define usr_thread_self() pthread_self()
881 #define usr_thread_sleep(A) \
883 struct timespec _sleep_ts; \
884 struct timeval _sleep_tv; \
885 gettimeofday(&_sleep_tv, NULL); \
887 _sleep_ts.tv_sec += _sleep_tv.tv_sec; \
888 _sleep_ts.tv_nsec += _sleep_tv.tv_usec * 1000; \
889 if (_sleep_ts.tv_nsec >= 1000000000) { \
890 _sleep_ts.tv_sec += 1; \
891 _sleep_ts.tv_nsec -= 1000000000; \
893 opr_Verify(pthread_mutex_lock(&usr_sleep_mutex) == 0); \
894 pthread_cond_timedwait(&usr_sleep_cond, &usr_sleep_mutex, &_sleep_ts); \
895 opr_Verify(pthread_mutex_unlock(&usr_sleep_mutex) == 0); \
898 #define uprintf printf
900 #define usr_getpid() (int)(usr_thread_self())
904 #define ISAFS_GLOCK() (usr_thread_self() == afs_global_owner)
906 #define copyin(A,B,C) (memcpy((void *)B,(void *)A,C), 0)
907 #define copyout(A,B,C) (memcpy((void *)B,(void *)A,C), 0)
908 #define copyinstr(A,B,C,D) (strncpy(B,A,C),(*D)=strlen(B), 0)
909 #define copyoutstr(A,B,C,D) (strncpy(B,A,C),(*D)=strlen(B), 0)
911 #define vattr_null(A) usr_vattr_null(A)
913 #define VN_HOLD(vp) \
918 #define VN_RELE(vp) \
920 AFS_ASSERT_GLOCK(); \
921 usr_assert((vp)->v_count > 0); \
922 if (--((vp)->v_count) == 0) \
923 afs_inactive(VTOAFS(vp), get_user_struct()->u_cred); \
927 unsigned long f_type
;
928 unsigned long f_bsize
;
929 unsigned long f_frsize
;
930 unsigned long f_ffree
;
931 unsigned long f_favail
;
933 unsigned long val
[2];
935 char f_basetype
[FSTYPSZ
];
936 unsigned long f_flag
;
937 unsigned long f_namemax
;
938 unsigned long f_blocks
;
939 unsigned long f_bfree
;
940 unsigned long f_bavail
;
941 unsigned long f_files
;
944 #define ATTR_MODE (1 << 0)
945 #define ATTR_UID (1 << 1)
946 #define ATTR_GID (1 << 2)
947 #define ATTR_MTIME (1 << 3)
948 #define ATTR_SIZE (1 << 4)
951 int va_mask
; /* bitmask of ATTR_* values above */
960 struct timeval va_atime
;
961 struct timeval va_mtime
;
962 struct timeval va_ctime
;
964 unsigned long va_blocksize
;
965 fsblkcnt_t va_blocks
;
966 unsigned long va_vcode
;
997 unsigned short v_flag
;
998 unsigned long v_count
;
999 struct usr_vnodeops
*v_op
;
1000 struct usr_vfs
*v_vfsp
;
1002 unsigned long v_rdev
;
1007 daddr_t i_db
[NDADDR
];
1008 struct usr_vnode
*i_devvp
;
1009 unsigned long i_dev
;
1011 struct usr_inode
*i_freef
;
1012 struct usr_inode
**i_freeb
;
1014 daddr_t i_ib
[NIADDR
];
1015 unsigned short i_mode
;
1017 unsigned long i_number
;
1020 struct usr_vnode i_vnode
;
1022 unsigned long ic_spare
[4];
1026 struct usr_fileops
{
1027 int (*vno_rw
) (void);
1028 int (*vno_ioctl
) (void);
1029 int (*vno_select
) (void);
1030 int (*vno_closex
) (void);
1034 unsigned short f_flag
;
1036 struct usr_ucred
*f_cred
;
1037 struct usr_fileops
*f_ops
;
1042 extern struct usr_file
*getf(int);
1052 unsigned short fid_len
;
1053 unsigned short fid_reserved
;
1054 char fid_data
[MAXFIDSZ
];
1066 extern struct usr_ucred
*usr_crget(void);
1067 extern struct usr_ucred
*usr_crcopy(struct usr_ucred
*);
1068 extern int usr_crhold(struct usr_ucred
*);
1069 extern int usr_crfree(struct usr_ucred
*);
1072 unsigned long p_flag
;
1075 struct usr_ucred
*p_ucred
;
1095 struct iovec
*uio_iov
;
1116 struct usr_fs
*b_fs
;
1119 unsigned int b_resid
;
1120 struct usr_vnode
*b_vp
;
1128 #define NDIRSIZ_LEN(len) \
1129 ((sizeof (struct usr_dirent)+4 - (MAXNAMLEN+1)) + (((len)+1 + 3) &~ 3))
1132 #define afs_ucred_t struct usr_ucred
1133 #define AFS_FLOCK flock
1136 struct usr_vnodeops
{
1137 int (*vn_open
) (struct vcache
**, afs_int32
, afs_ucred_t
*);
1138 int (*vn_close
) (struct vcache
*, afs_int32
, afs_ucred_t
*);
1139 int (*vn_rdwr
) (struct usr_vnode
*avc
, struct usr_uio
*uio
,
1140 int rw
, int io
, struct usr_ucred
*cred
);
1141 int (*vn_ioctl
) (void);
1142 int (*vn_select
) (void);
1143 int (*vn_getattr
) (struct vcache
*avc
, struct vattr
*, afs_ucred_t
*);
1144 int (*vn_setattr
) (struct vcache
*avc
, struct vattr
*, afs_ucred_t
*);
1145 int (*vn_access
) (struct vcache
*avc
, afs_int32
, afs_ucred_t
*);
1146 int (*vn_lookup
) (struct vcache
*adp
, char *, struct vcache
**,
1147 afs_ucred_t
*, int);
1148 int (*vn_create
) (struct vcache
*adp
, char *, struct vattr
*,
1149 enum vcexcl
, int, struct vcache
**, afs_ucred_t
*);
1150 int (*vn_remove
) (struct vcache
*adp
, char *, afs_ucred_t
*);
1151 int (*vn_link
) (struct vcache
*avc
, struct vcache
*adp
, char *,
1153 int (*vn_rename
) (struct vcache
*aodp
, char *, struct vcache
*, char *,
1155 int (*vn_mkdir
) (struct vcache
*adp
, char *, struct vattr
*,
1156 struct vcache
**, afs_ucred_t
*);
1157 int (*vn_rmdir
) (struct vcache
*adp
, char *, afs_ucred_t
*);
1158 int (*vn_readdir
) (struct vcache
*avc
, struct uio
*, afs_ucred_t
*);
1159 int (*vn_symlink
) (struct vcache
*adp
, char *, struct vattr
*, char *,
1160 struct vcache
**pvc
, afs_ucred_t
*);
1161 int (*vn_readlink
) (struct vcache
*avc
, struct uio
*, afs_ucred_t
*);
1162 int (*vn_fsync
) (struct vcache
*avc
, afs_ucred_t
*);
1163 int (*vn_inactive
) (struct vcache
*avc
, afs_ucred_t
*acred
);
1164 int (*vn_bmap
) (void);
1165 int (*vn_strategy
) (void);
1166 int (*vn_bread
) (void);
1167 int (*vn_brelse
) (void);
1168 int (*vn_lockctl
) (struct vcache
*, struct AFS_FLOCK
*, int,
1170 int (*vn_fid
) (struct vcache
*avc
, struct fid
**);
1179 unsigned long m_dev
;
1180 struct usr_inode
*m_inodp
;
1181 struct usr_buf
*m_bufp
;
1182 struct usr_vnode
*m_mount
;
1184 extern struct usr_mount
*getmp(unsigned long);
1186 typedef long usr_whymountroot_t
;
1189 int (*vfs_mount
) (struct vfs
*, char *, void *);
1190 int (*vfs_unmount
) (struct vfs
*);
1191 int (*vfs_root
) (struct vfs
*, struct vnode
**);
1192 int (*vfs_statfs
) (struct vfs
*, struct statfs
*);
1193 int (*vfs_mountroot
) (struct vfs
*);
1194 int (*vfs_swapvp
) (void);
1198 struct usr_vnode
*vfs_vnodecovered
;
1200 unsigned long val
[2];
1203 unsigned long vfs_bsize
;
1204 struct usr_mount
*vfs_mount
;
1205 struct usr_vfsops
*vfs_op
;
1209 struct usr_ifnet
*if_next
;
1213 struct usr_ifaddr
*if_addrlist
;
1215 extern struct usr_ifnet
*usr_ifnet
;
1218 struct usr_ifaddr
*ifa_next
;
1219 struct usr_ifnet
*ifa_ifp
;
1220 struct sockaddr ifa_addr
;
1230 struct usr_in_ifaddr
{
1231 struct usr_in_ifaddr
*ia_next
;
1232 struct usr_ifnet
*ia_ifp
;
1233 struct sockaddr_in ia_addr
;
1234 unsigned long ia_net
;
1235 unsigned long ia_netmask
;
1236 unsigned long ia_subnet
;
1237 unsigned long ia_subnetmask
;
1238 struct in_addr ia_netbroadcast
;
1240 extern struct usr_in_ifaddr
*usr_in_ifaddr
;
1242 #endif /* UKERNEL */
1245 #if defined(AFS_USR_OSF_ENV)
1246 unsigned int d_fileno
;
1247 #else /* AFS_OFS_ENV || AFS_USR_OSF_ENV */
1248 unsigned long d_fileno
;
1249 #endif /* AFS_OFS_ENV || AFS_USR_OSF_ENV */
1250 unsigned short d_reclen
;
1251 unsigned short d_namlen
;
1255 #define NGROUPS NGROUPS_MAX
1258 #define NOGROUP (-1)
1265 unsigned long cr_ref
;
1273 gid_t cr_groups
[NGROUPS
];
1286 unsigned long u_expiration
;
1287 struct usr_proc
*u_procp
;
1288 struct usr_ucred
*u_cred
;
1293 #define u_rval1 u_r.r_val1
1295 extern struct usr_user
*get_user_struct(void);
1297 #define USR_DIRSIZE 2048
1300 unsigned long d_ino
;
1301 unsigned long d_off
;
1302 unsigned short d_reclen
;
1303 char d_name
[MAXNAMLEN
+ 1];
1314 extern unsigned short usr_rx_port
;
1316 #define AFS_LOOKUP_NOEVAL 1
1318 #endif /* __AFS_SYSINCLUDESH__ so idempotent */