OpenAFS
OpenAFS distributed network file system
/cygdrive/c/src/openafs/openafs.git/repo/src/afs/DARWIN/osi_machdep.h
00001 /*
00002  * Copyright 2000, International Business Machines Corporation and others.
00003  * All Rights Reserved.
00004  *
00005  * This software has been released under the terms of the IBM Public
00006  * License.  For details, see the LICENSE file in the top-level source
00007  * directory or online at http://www.openafs.org/dl/license10.html
00008  */
00009 /*
00010  *
00011  * MACOS OSI header file. Extends afs_osi.h.
00012  *
00013  * afs_osi.h includes this file, which is the only way this file should
00014  * be included in a source file. This file can redefine macros declared in
00015  * afs_osi.h.
00016  */
00017 
00018 #ifndef _OSI_MACHDEP_H_
00019 #define _OSI_MACHDEP_H_
00020 
00021 #ifdef XAFS_DARWIN_ENV
00022 #ifndef _MACH_ETAP_H_
00023 #define _MACH_ETAP_H_
00024 typedef unsigned short etap_event_t;
00025 #endif
00026 #endif
00027 
00028 #ifdef AFS_DARWIN80_ENV
00029 #include <kern/locks.h>
00030 #include <sys/mount.h>
00031 #include <h/vnode.h>
00032 #else
00033 #include <sys/lock.h>
00034 #include <sys/user.h>
00035 #include <sys/vnode.h>
00036 #include <sys/kauth.h>
00037 #endif
00038 #include <kern/thread.h>
00039 
00040 #ifdef AFS_DARWIN80_ENV
00041 #define vop_proc vfs_context_proc(ap->a_context)
00042 #define vop_cred vfs_context_ucred(ap->a_context)
00043 #define cn_proc(cnp) vfs_context_proc(ap->a_context)
00044 #define cn_cred(cnp) vfs_context_ucred(ap->a_context)
00045 #define vop_cn_proc vfs_context_proc(ap->a_context)
00046 #define vop_cn_cred vfs_context_ucred(ap->a_context)
00047 #define getpid()                proc_selfpid()
00048 #define getppid()               proc_selfppid()
00049 #else
00050 #define vop_proc ap->a_p
00051 #define vop_cred ap->a_cred
00052 #define cn_proc(cnp) (cnp)->cn_proc
00053 #define cn_cred(cnp) (cnp)->cn_cred
00054 #define vop_cn_proc cn_proc(ap->a_cnp)
00055 #define vop_cn_cred cn_cred(ap->a_cnp)
00056 #define getpid()                current_proc()->p_pid
00057 #define getppid()               current_proc()->p_pptr->p_pid
00058 #endif
00059 #undef gop_lookupname
00060 #define gop_lookupname osi_lookupname
00061 #undef gop_lookupname_user
00062 #define gop_lookupname_user osi_lookupname_user
00063 
00064 #define FTRUNC 0
00065 
00066 /* vcexcl - used only by afs_create */
00067 enum vcexcl { EXCL, NONEXCL };
00068 
00069 #ifndef AFS_DARWIN80_ENV
00070 #define vnode_clearfsnode(x) ((x)->v_data = 0)
00071 #define vnode_fsnode(x) (x)->v_data
00072 #define vnode_lock(x) vn_lock(x, LK_EXCLUSIVE | LK_RETRY, current_proc());
00073 #define vnode_isvroot(x) (((x)->v_flag & VROOT)?1:0)
00074 #define vnode_vtype(x) (x)->v_type
00075 #define vnode_isdir(x) ((x)->v_type == VDIR)
00076 
00077 #define vfs_flags(x) (x)->v_flags
00078 #define vfs_setflags(x, y) (x)->mnt_flag |= (y)
00079 #define vfs_clearflags(x, y) (x)->mnt_flag &= (~(y))
00080 #define vfs_isupdate(x) ((x)->mnt_flag & MNT_UPDATE)
00081 #define vfs_fsprivate(x) (x)->mnt_data
00082 #define vfs_setfsprivate(x,y) (x)->mnt_data = (y)
00083 #define vfs_typenum(x) (x)->mnt_vfc->vfc_typenum
00084 #endif
00085 
00086 #ifdef AFS_DARWIN80_ENV
00087 #define vrele vnode_rele
00088 #define vput vnode_rele
00089 #define vref vnode_ref
00090 #define vattr vnode_attr
00091 #if 0
00092 #define vn_lock(v, unused1, unused2) vnode_get((v))
00093 #define VOP_LOCK(v, unused1, unused2) vnode_get((v))
00094 #define VOP_UNLOCK(v, unused1, unused2) vnode_put((v))
00095 #endif
00096 
00097 #define va_size va_data_size
00098 #define va_atime va_access_time
00099 #define va_mtime va_modify_time
00100 #define va_ctime va_change_time
00101 #define va_bytes va_total_alloc
00102 #define va_blocksize va_iosize
00103 #define va_nodeid va_fileid
00104 
00105 #define crref kauth_cred_get_with_ref
00106 #define crhold kauth_cred_ref
00107 #ifdef AFS_DARWIN100_ENV
00108 static inline void crfree(kauth_cred_t X) { kauth_cred_unref(&X); }
00109 #else
00110 #define crfree kauth_cred_rele
00111 #endif
00112 #define crdup kauth_cred_dup
00113 #ifdef AFS_DARWIN100_ENV
00114 #define ubc_msync_range(X,Y,Z,A) ubc_msync(X,Y,Z,NULL,A)
00115 #else
00116 #define ubc_msync_range(X,Y,Z,A) ubc_sync_range(X,Y,Z,A)
00117 #endif
00118 extern vfs_context_t afs_osi_ctxtp;
00119 extern int afs_osi_ctxtp_initialized;
00120 #endif
00121 extern u_int32_t afs_darwin_realmodes;
00122 extern u_int32_t afs_darwin_fsevents;
00123 
00124 /*
00125  * Time related macros
00126  */
00127 #ifdef AFS_DARWIN80_ENV
00128 static inline time_t osi_Time(void) {
00129     struct timeval _now;
00130     microtime(&_now);
00131     return _now.tv_sec;
00132 }
00133 #else
00134 #define osi_Time() (time.tv_sec)
00135 #endif
00136 #define afs_hz      hz
00137 #ifdef AFS_DARWIN80_ENV
00138 extern int hz;
00139 #endif
00140 
00141 typedef struct ucred afs_ucred_t;
00142 typedef struct proc afs_proc_t;
00143 
00144 #define osi_vnhold(avc,r)       VN_HOLD(AFSTOV(avc))
00145 #define VN_HOLD(vp) darwin_vn_hold(vp)
00146 #define VN_RELE(vp) vrele(vp);
00147 
00148 void darwin_vn_hold(struct vnode *vp);
00149 
00150 #define gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
00151   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid),current_proc())
00152 
00153 #undef afs_suser
00154 
00155 extern thread_t afs_global_owner;
00156 /* simple locks cannot be used since sleep can happen at any time */
00157 #ifdef AFS_DARWIN80_ENV
00158 /* mach locks still don't have an exported try, but we are forced to use them */
00159 extern lck_mtx_t  *afs_global_lock;
00160 #define AFS_GLOCK() \
00161     do { \
00162         osi_Assert(afs_global_owner != current_thread()); \
00163         lck_mtx_lock(afs_global_lock); \
00164         osi_Assert(afs_global_owner == 0); \
00165         afs_global_owner = current_thread(); \
00166     } while (0)
00167 #define AFS_GUNLOCK() \
00168     do { \
00169         osi_Assert(afs_global_owner == current_thread()); \
00170         afs_global_owner = 0; \
00171         lck_mtx_unlock(afs_global_lock); \
00172     } while(0)
00173 #define osi_InitGlock() \
00174     do { \
00175         afs_global_owner = 0; \
00176     } while (0)
00177 #else
00178 /* Should probably use mach locks rather than bsd locks, since we use the
00179    mach thread control api's elsewhere (mach locks not used for consistency
00180    with rx, since rx needs lock_write_try() in order to use mach locks
00181  */
00182 extern struct lock__bsd__ afs_global_lock;
00183 #define AFS_GLOCK() \
00184     do { \
00185         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, current_proc()); \
00186         osi_Assert(afs_global_owner == 0); \
00187         afs_global_owner = current_thread(); \
00188     } while (0)
00189 #define AFS_GUNLOCK() \
00190     do { \
00191         osi_Assert(afs_global_owner == current_thread()); \
00192         afs_global_owner = 0; \
00193         lockmgr(&afs_global_lock, LK_RELEASE, 0, current_proc()); \
00194     } while(0)
00195 #define osi_InitGlock() \
00196     do { \
00197         lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0); \
00198         afs_global_owner = 0; \
00199     } while (0)
00200 #endif
00201 #define ISAFS_GLOCK() (afs_global_owner == current_thread())
00202 
00203 #define SPLVAR
00204 #define NETPRI
00205 #define USERPRI
00206 #if 0
00207 #undef SPLVAR
00208 #define SPLVAR int x;
00209 #undef NETPRI
00210 #define NETPRI x=splnet();
00211 #undef USERPRI
00212 #define USERPRI splx(x);
00213 #endif
00214 
00215 #define AFS_APPL_UFS_CACHE 1
00216 #define AFS_APPL_HFS_CACHE 2
00217 
00218 extern ino_t VnodeToIno(vnode_t avp);
00219 extern dev_t VnodeToDev(vnode_t vp);
00220 extern int igetinode(mount_t vfsp, dev_t dev , ino_t inode, vnode_t *vpp,
00221               struct vattr *va, int *perror);
00222 
00223 #define osi_curproc() current_proc()
00224 
00225 /* FIXME */
00226 #define osi_curcred() &afs_osi_cred
00227 
00228 #ifdef AFS_DARWIN80_ENV
00229 # define afsio_free(X) uio_free(X)
00230 # define afsio_setoffset(X, Y) uio_setoffset(X, Y)
00231 # define uprintf printf
00232 #endif
00233 
00234 /* Vnode related macros */
00235 
00236 #if defined(AFS_DARWIN80_ENV)
00237 extern int afs_vfs_typenum;
00238 # define vType(vc)               vnode_vtype(AFSTOV(vc))
00239 # define vSetVfsp(vc, vfsp)
00240 # define vSetType(vc, type)      (vc)->f.m.Type = (type)
00241 # define SetAfsVnode(vn)         /* nothing; done in getnewvnode() */
00242 # define IsAfsVnode(v) (vfs_typenum(vnode_mount((v))) == afs_vfs_typenum)
00243 #else
00244 extern int (**afs_vnodeop_p) ();
00245 # define vType(vc)               AFSTOV(vc)->v_type
00246 # define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
00247 # define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
00248 # define IsAfsVnode(v)      ((v)->v_op == afs_vnodeop_p)
00249 # define SetAfsVnode(v)     /* nothing; done in getnewvnode() */
00250 #endif
00251 
00252 #ifdef AFS_DARWIN80_ENV
00253 #define osi_procname(procname, size) proc_selfname(procname, size)
00254 #else
00255 #define osi_procname(procname, size) strncpy(procname, curproc->p_comm, size)
00256 #endif
00257 
00258 #endif /* _OSI_MACHDEP_H_ */
 All Data Structures Files Functions Variables