Make UKERNEL's panic() a real function, not a macro
[openafs.git] / src / afs / UKERNEL / sysincludes.h
index 95cf275..e401956 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #define __AFS_SYSINCLUDESH__ 1
 
 #include  <stdio.h>
-#if !defined(AFS_USR_DARWIN_ENV) && !defined(AFS_USR_FBSD_ENV) /* must be included after KERNEL undef'd */
+#include  <afs/opr.h>
+
+#if !defined(AFS_USR_DARWIN_ENV) && !defined(AFS_USR_FBSD_ENV) && !defined(AFS_USR_DFBSD_ENV) /* must be included after KERNEL undef'd */
 #include  <errno.h>
 #endif
 #include  <stdlib.h>
 #include  <string.h>
-#include  <unistd.h>
-#include  <dirent.h>
 #include  <limits.h>
 #include  <assert.h>
 #include  <stdarg.h>
-#include <setjmp.h>
+
+#if !defined(AFS_USR_DARWIN_ENV) && !defined(AFS_USR_FBSD_ENV) && !defined(AFS_USR_DFBSD_ENV) /* must be included after KERNEL undef'd */
+#include  <unistd.h>
+#include  <ctype.h>
+#include  <sys/types.h>
+#include  <dirent.h>
+#include  <setjmp.h>
+#endif
 
 #ifdef AFS_USR_SUN5_ENV
 #include  <signal.h>
 #include  <sys/param.h>
-#include  <sys/types.h>
 #include  <sys/socket.h>
 #include  <net/if.h>
 #include  <sys/sockio.h>
@@ -41,7 +47,6 @@
 
 #ifdef AFS_USR_AIX_ENV
 #include  <sys/param.h>
-#include  <sys/types.h>
 #include  <sys/socket.h>
 #include  <net/if.h>
 #include  <fcntl.h>
@@ -54,7 +59,6 @@
 
 #ifdef AFS_USR_SGI_ENV
 #include  <sys/param.h>
-#include  <sys/types.h>
 #include  <sys/socket.h>
 #include  <net/if.h>
 #include  <sys/sockio.h>
@@ -68,7 +72,6 @@
 
 #ifdef AFS_USR_HPUX_ENV
 #include  <sys/param.h>
-#include  <sys/types.h>
 #include  <sys/socket.h>
 #include  <net/if.h>
 #include  <sys/file.h>
@@ -85,7 +88,6 @@
 #define AFS_USR_UNDEF_KERNEL_ENV 1
 #endif
 #include  <sys/param.h>
-#include  <sys/types.h>
 #include  <sys/socket.h>
 #include  <net/if.h>
 #include  <sys/file.h>
 #define FREAD                  0x0001
 #endif /* AFS_USR_LINUX22_ENV */
 
-#if defined(AFS_USR_DARWIN_ENV) || defined(AFS_USR_FBSD_ENV)
+#if defined(AFS_USR_DARWIN_ENV) || defined(AFS_USR_FBSD_ENV) || defined(AFS_USR_DFBSD_ENV)
+#ifdef _KERNEL
+#undef _KERNEL
+#endif
 #ifdef KERNEL
 #undef KERNEL
 #define AFS_USR_UNDEF_KERNEL_ENV 1
 #endif
 #include  <errno.h>
+#include  <setjmp.h>
 #include  <sys/param.h>
 #include  <sys/types.h>
 #include  <sys/socket.h>
 #include  <netinet/in.h>
 #include  <netdb.h>
 #include  <arpa/inet.h>
+#include  <dirent.h>
+#include  <ctype.h>
+#include  <unistd.h>
 #ifndef O_SYNC
 #define O_SYNC O_FSYNC
 #endif
 #endif /* AFS_USR_DARWIN_ENV || AFS_USR_FBSD_ENV */
 
-#ifdef AFS_AFSDB_ENV
+#ifdef HAVE_SYS_BITYPES_H
+#include <sys/bitypes.h>
+#endif
+#ifdef HAVE_SYS_STATFS_H
+#include <sys/statfs.h>
+#endif
+#ifdef HAVE_SYS_STATVFS_H
+#include <sys/statvfs.h>
+#endif
+
+#ifndef HAVE_FSBLKCNT_T
+typedef unsigned int fsblkcnt_t;
+#endif
+
 #include <arpa/nameser.h>
+#ifdef HAVE_ARPA_NAMESER_COMPAT_H
+#include <arpa/nameser_compat.h>
+#endif
 #include <resolv.h>
-#endif /* AFS_AFSDB_ENV */
 
 /* glibc 2.2 has pthread_attr_setstacksize */
-#if defined(AFS_LINUX22_ENV) || defined(AFS_USR_LINUX22_ENV) && (__GLIBC_MINOR__ < 2)
+#if (defined(AFS_LINUX22_ENV) && !defined(AFS_USR_LINUX22_ENV)) || (defined(AFS_USR_LINUX22_ENV) && (__GLIBC_MINOR__ < 2))
 #define pthread_attr_setstacksize(a,b) 0
 #endif
 
 #define MAXNAMLEN              512
 #endif
 
-#ifndef PAGESIZE
-#define PAGESIZE               4096
-#endif
-
 /*
  * This file contains data types and definitions for running
  * the AFS client in user space. Kernel data structures
 
 #ifdef UKERNEL
 
-#ifdef AFS_USR_SGI_ENV
 #undef socket
-#endif /* AFS_USR_SGI_ENV */
+#undef flock
 
 #if defined(AFS_USR_DARWIN_ENV) || defined(AFS_USR_FBSD_ENV)
 #undef if_mtu
 #define vattr                  usr_vattr
 #define buf                    usr_buf
 #define statfs                 usr_statfs
-#define ucred                  usr_ucred
-#define user                   usr_user
-#define proc                   usr_proc
 #define file                   usr_file
 #define dirent                 usr_dirent
 #define flock                  usr_flock
 #define fid                    usr_fid
 #define sysent                 usr_sysent
+#define ifaddr                  usr_ifaddr
+#define ifnet                   usr_ifnet
 #define in_ifaddr              usr_in_ifaddr
-#define ifaddr                 usr_ifaddr
-#define ifnet                  usr_ifnet
+#undef socket
 #define socket                 usr_socket
 #define crget                  usr_crget
 #define crcopy                 usr_crcopy
 #define offset_t               usr_offset_t
 #define getpid()               usr_getpid()
 #define setpag(A,B,C,D)                usr_setpag((A),(B),(C),(D))
+#define osi_getpid()           afs_pointer_to_int(usr_thread_self())
 #ifdef pid_t
 #undef pid_t
 #endif
@@ -325,26 +343,18 @@ typedef long usr_ino_t;
 #ifdef VFIFO
 #undef VFIFO
 #endif
-#ifdef VDOOR
-#undef VDOOR
-#endif
-#ifdef VBAD
-#undef VBAD
-#endif
 #ifdef VSOCK
 #undef VSOCK
 #endif
 
-#define VNON                   0
-#define VREG                   1
-#define VDIR                   2
-#define VBLK                   3
-#define VCHR                   4
-#define VLNK                   5
-#define VFIFO                  6
-#define VDOOR                  7
-#define VBAD                   8
-#define VSOCK                  9
+#define VNON 0
+#define VREG S_IFREG
+#define VDIR S_IFDIR
+#define VBLK S_IFBLK
+#define VCHR S_IFCHR
+#define VLNK S_IFLNK
+#define VSOCK S_IFSOCK
+#define VFIFO S_IFIFO
 
 typedef int usr_vtype_t;
 
@@ -826,7 +836,15 @@ enum usr_uio_rw { USR_UIO_READ, USR_UIO_WRITE };
 #endif
 #define NBPG                   4096
 
-#define panic(S)               do{fprintf(stderr, S);assert(0);}while(0)
+static_inline void panic(const char *format, ...) AFS_NORETURN;
+static_inline void panic(const char *format, ...)
+{
+    va_list ap;
+    va_start(ap, format);
+    vfprintf(stderr, format, ap);
+    va_end(ap);
+    assert(0);
+};
 #define abort()                        assert(0)
 #define usr_assert(A)          assert(A)
 
@@ -927,29 +945,29 @@ extern pthread_cond_t usr_sleep_cond;
 #define usr_thread_t           pthread_t
 #define usr_key_t              pthread_key_t
 
-#define usr_mutex_init(A)      assert(pthread_mutex_init(A,NULL) == 0)
-#define usr_mutex_destroy(A)   assert(pthread_mutex_destroy(A) == 0)
-#define usr_mutex_lock(A)      assert(pthread_mutex_lock(A) == 0)
+#define usr_mutex_init(A)      opr_Verify(pthread_mutex_init(A,NULL) == 0)
+#define usr_mutex_destroy(A)   opr_Verify(pthread_mutex_destroy(A) == 0)
+#define usr_mutex_lock(A)      opr_Verify(pthread_mutex_lock(A) == 0)
 #define usr_mutex_trylock(A)   ((pthread_mutex_trylock(A)==0)?1:0)
-#define usr_mutex_unlock(A)    assert(pthread_mutex_unlock(A) == 0)
-#define usr_cond_init(A)       assert(pthread_cond_init(A,NULL) == 0)
-#define usr_cond_destroy(A)    assert(pthread_cond_destroy(A) == 0)
-#define usr_cond_signal(A)     assert(pthread_cond_signal(A) == 0)
-#define usr_cond_broadcast(A)  assert(pthread_cond_broadcast(A) == 0)
+#define usr_mutex_unlock(A)    opr_Verify(pthread_mutex_unlock(A) == 0)
+#define usr_cond_init(A)       opr_Verify(pthread_cond_init(A,NULL) == 0)
+#define usr_cond_destroy(A)    opr_Verify(pthread_cond_destroy(A) == 0)
+#define usr_cond_signal(A)     opr_Verify(pthread_cond_signal(A) == 0)
+#define usr_cond_broadcast(A)  opr_Verify(pthread_cond_broadcast(A) == 0)
 #define usr_cond_wait(A,B)     pthread_cond_wait(A,B)
 #define usr_cond_timedwait(A,B,C)  pthread_cond_timedwait(A,B,C)
 
 #define usr_thread_create(A,B,C) \
     do { \
        pthread_attr_t attr; \
-       assert(pthread_attr_init(&attr) == 0); \
-       assert(pthread_attr_setstacksize(&attr, 124288) == 0); \
-       assert(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0); \
-       assert(pthread_create((A), &attr, (B), (void *)(C)) == 0); \
-       assert(pthread_attr_destroy(&attr) == 0); \
+       opr_Verify(pthread_attr_init(&attr) == 0); \
+       opr_Verify(pthread_attr_setstacksize(&attr, 122880) == 0); \
+       opr_Verify(pthread_create((A), &attr, (B), (void *)(C)) == 0); \
+       opr_Verify(pthread_attr_destroy(&attr) == 0); \
     } while(0)
+#define usr_thread_join(A,B)   pthread_join(A, B)
 #define usr_thread_detach(A)   pthread_detach(A)
-#define usr_keycreate(A,B)     assert(pthread_key_create(A,B) == 0)
+#define usr_keycreate(A,B)     opr_Verify(pthread_key_create(A,B) == 0)
 #define usr_setspecific(A,B)   pthread_setspecific(A,B)
 #define usr_getspecific(A,B)   (*(B)=pthread_getspecific(A),0)
 #define usr_thread_self()      pthread_self()
@@ -965,9 +983,9 @@ extern pthread_cond_t usr_sleep_cond;
        _sleep_ts.tv_sec += 1;                                             \
        _sleep_ts.tv_nsec -= 1000000000;                                   \
     }                                                                     \
-    assert(pthread_mutex_lock(&usr_sleep_mutex) == 0);                    \
+    opr_Verify(pthread_mutex_lock(&usr_sleep_mutex) == 0);                        \
     pthread_cond_timedwait(&usr_sleep_cond, &usr_sleep_mutex, &_sleep_ts); \
-    assert(pthread_mutex_unlock(&usr_sleep_mutex) == 0);                  \
+    opr_Verify(pthread_mutex_unlock(&usr_sleep_mutex) == 0);              \
 }
 
 #define uprintf                        printf
@@ -997,7 +1015,7 @@ do { \
     AFS_ASSERT_GLOCK(); \
     usr_assert((vp)->v_count > 0); \
     if (--((vp)->v_count) == 0) \
-       afs_inactive(vp, u.u_cred); \
+       afs_inactive(VTOAFS(vp), get_user_struct()->u_cred); \
 } while(0)
 
 struct usr_statfs {
@@ -1018,22 +1036,28 @@ struct usr_statfs {
     unsigned long f_files;
 };
 
+#define ATTR_MODE      (1 << 0)
+#define ATTR_UID       (1 << 1)
+#define ATTR_GID       (1 << 2)
+#define ATTR_MTIME     (1 << 3)
+#define ATTR_SIZE      (1 << 4)
+
 struct usr_vattr {
-    long va_mask;
+    int va_mask;       /* bitmask of ATTR_* values above */
     usr_vtype_t va_type;
-    unsigned short va_mode;
-    long va_uid;
-    long va_gid;
-    unsigned long va_fsid;
-    unsigned long va_nodeid;
-    unsigned long va_nlink;
-    unsigned long va_size;
+    mode_t va_mode;
+    uid_t va_uid;
+    gid_t va_gid;
+    int va_fsid;
+    ino_t va_nodeid;
+    nlink_t va_nlink;
+    afs_size_t va_size;
     struct timeval va_atime;
     struct timeval va_mtime;
     struct timeval va_ctime;
-    unsigned long va_rdev;
+    dev_t va_rdev;
     unsigned long va_blocksize;
-    unsigned long va_blocks;
+    fsblkcnt_t va_blocks;
     unsigned long va_vcode;
 };
 
@@ -1093,7 +1117,6 @@ struct usr_inode {
        unsigned long ic_spare[4];
     } i_ic;
 };
-extern struct usr_inode *iget();
 
 struct usr_fileops {
     int (*vno_rw) (void);
@@ -1110,7 +1133,7 @@ struct usr_file {
     char *f_data;
     long f_type;
 };
-extern struct usr_file *falloc();
+
 extern struct usr_file *getf(int);
 
 #ifdef fid_len
@@ -1139,7 +1162,6 @@ extern struct usr_ucred *usr_crget(void);
 extern struct usr_ucred *usr_crcopy(struct usr_ucred *);
 extern int usr_crhold(struct usr_ucred *);
 extern int usr_crfree(struct usr_ucred *);
-extern struct usr_ucred *afs_global_ucredp;
 
 struct usr_proc {
     unsigned long p_flag;
@@ -1201,33 +1223,46 @@ struct usr_socket {
 #define NDIRSIZ_LEN(len) \
 ((sizeof (struct usr_dirent)+4 - (MAXNAMLEN+1)) + (((len)+1 + 3) &~ 3))
 
+struct vcache;
+#define afs_ucred_t struct usr_ucred
+#define AFS_FLOCK       flock
+
+
 struct usr_vnodeops {
-    int (*vn_open) (char *path, int flags, int mode);
-    int (*vn_close) (int fd);
-    int (*vn_rdwr) ();
+    int (*vn_open) (struct vcache **, afs_int32, afs_ucred_t *);
+    int (*vn_close) (struct vcache *, afs_int32, afs_ucred_t *);
+    int (*vn_rdwr) (struct usr_vnode *avc, struct usr_uio *uio,
+                   int rw, int io, struct usr_ucred *cred);
     int (*vn_ioctl) (void);
     int (*vn_select) (void);
-    int (*vn_getattr) ();
-    int (*vn_setattr) ();
-    int (*vn_access) ();
-    int (*vn_lookup) ();
-    int (*vn_create) ();
-    int (*vn_remove) ();
-    int (*vn_link) ();
-    int (*vn_rename) ();
-    int (*vn_mkdir) ();
-    int (*vn_rmdir) ();
-    int (*vn_readdir) ();
-    int (*vn_symlink) ();
-    int (*vn_readlink) ();
-    int (*vn_fsync) ();
-    int (*vn_inactive) ();
-    int (*vn_bmap) ();
-    int (*vn_strategy) ();
-    int (*vn_bread) ();
-    int (*vn_brelse) ();
-    int (*vn_lockctl) ();
-    int (*vn_fid) ();
+    int (*vn_getattr) (struct vcache *avc, struct vattr *, afs_ucred_t *);
+    int (*vn_setattr) (struct vcache *avc, struct vattr *, afs_ucred_t *);
+    int (*vn_access) (struct vcache *avc, afs_int32, afs_ucred_t *);
+    int (*vn_lookup) (struct vcache *adp, char *, struct vcache **,
+                     afs_ucred_t *, int);
+    int (*vn_create) (struct vcache *adp, char *, struct vattr *,
+                     enum vcexcl, int, struct vcache **, afs_ucred_t *);
+    int (*vn_remove) (struct vcache *adp, char *, afs_ucred_t *);
+    int (*vn_link) (struct vcache *avc, struct vcache *adp, char *,
+                   afs_ucred_t *);
+    int (*vn_rename) (struct vcache *aodp, char *, struct vcache *, char *,
+                     afs_ucred_t *);
+    int (*vn_mkdir) (struct vcache *adp, char *, struct vattr *,
+                    struct vcache **, afs_ucred_t *);
+    int (*vn_rmdir) (struct vcache *adp, char *, afs_ucred_t *);
+    int (*vn_readdir) (struct vcache *avc, struct uio *, afs_ucred_t *);
+    int (*vn_symlink) (struct vcache *adp, char *, struct vattr *, char *,
+                      afs_ucred_t *);
+    int (*vn_readlink) (struct vcache *avc, struct uio *, afs_ucred_t *);
+    int (*vn_fsync) (struct vcache *avc, afs_ucred_t *);
+    int (*vn_inactive) (struct vcache *avc, afs_ucred_t *acred);
+    int (*vn_bmap) (void);
+    int (*vn_strategy) (void);
+    int (*vn_bread) (void);
+    int (*vn_brelse) (void);
+    int (*vn_lockctl) (struct vcache *, struct AFS_FLOCK *, int,
+                      afs_ucred_t *);
+    int (*vn_fid) (struct vcache *avc, struct fid **);
 };
 
 struct usr_fs {
@@ -1246,12 +1281,12 @@ extern struct usr_mount *getmp(unsigned long);
 typedef long usr_whymountroot_t;
 
 struct usr_vfsops {
-    int (*vfs_mount) ();
-    int (*vfs_unmount) ();
-    int (*vfs_root) ();
-    int (*vfs_statfs) ();
-    int (*vfs_mountroot) ();
-    int (*vfs_swapvp) ();
+    int (*vfs_mount) (struct vfs *, char *, void *);
+    int (*vfs_unmount) (struct vfs *);
+    int (*vfs_root) (struct vfs *, struct vnode **);
+    int (*vfs_statfs) (struct vfs *, struct statfs *);
+    int (*vfs_mountroot) (struct vfs *);
+    int (*vfs_swapvp) (void);
 };
 
 struct usr_vfs {
@@ -1265,12 +1300,6 @@ struct usr_vfs {
     struct usr_vfsops *vfs_op;
 };
 
-struct usr_sysent {
-    char sy_narg;
-    int (*sy_call) ();
-};
-extern struct usr_sysent usr_sysent[];
-
 struct usr_ifnet {
     struct usr_ifnet *if_next;
     short if_flags;
@@ -1305,18 +1334,10 @@ struct usr_in_ifaddr {
 };
 extern struct usr_in_ifaddr *usr_in_ifaddr;
 
-extern usr_key_t afs_global_u_key;     /* for per thread authentication */
-
-#if defined(AFS_USR_OSF_ENV)
-extern char V;
-#else
-extern long V;
-#endif
-
 #endif /* UKERNEL */
 
 struct min_direct {
-#if defined(AFS_OFS_ENV) || defined(AFS_USR_OSF_ENV)
+#if defined(AFS_USR_OSF_ENV)
     unsigned int d_fileno;
 #else                          /* AFS_OFS_ENV || AFS_USR_OSF_ENV */
     unsigned long d_fileno;
@@ -1365,7 +1386,6 @@ struct usr_user {
     } u_r;
 };
 #define u_rval1                        u_r.r_val1
-#define u                      (*(get_user_struct()))
 
 extern struct usr_user *get_user_struct(void);