3e8c886816463dea0960acc2aaa34559da40ce5b
[openafs.git] / src / afs / SOLARIS / osi_machdep.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 /*
11  * Solaris OSI header file. Extends afs_osi.h.
12  *
13  * afs_osi.h includes this file, which is the only way this file should
14  * be included in a source file. This file can redefine macros declared in
15  * afs_osi.h.
16  */
17
18 #ifndef _OSI_MACHDEP_H_
19 #define _OSI_MACHDEP_H_
20
21 #ifdef AFS_SUN57_64BIT_ENV
22 #include <sys/model.h>          /* for get_udatamodel() */
23 #endif
24
25 #define getpid()                curproc->p_pid
26
27 /**
28   * The location of the NFSSRV module
29   * Used in osi_vfsops.c when checking to see if the nfssrv module is
30   * loaded
31   */
32 #define NFSSRV          "/kernel/misc/nfssrv"
33 #define NFSSRV_V9       "/kernel/misc/sparcv9/nfssrv"
34 #define NFSSRV_AMD64    "/kernel/misc/amd64/nfssrv"
35
36 typedef struct cred afs_ucred_t;
37 typedef struct proc afs_proc_t;
38
39 /*
40  * Time related macros
41  */
42 #define afs_hz      hz
43 #ifdef AFS_SUN59_ENV
44 #define osi_Time() local_osi_Time()
45 extern void gethrestime(timespec_t *);
46 static int
47 local_osi_Time()
48 {
49     timespec_t start;
50     gethrestime(&start);
51     return start.tv_sec;
52 }
53 #else
54 #define osi_Time() (hrestime.tv_sec)
55 #endif
56
57 #undef afs_osi_Alloc_NoSleep
58 extern void *afs_osi_Alloc_NoSleep(size_t size);
59
60 #ifdef AFS_SUN58_ENV
61 # define osi_vnhold(avc, r)  do {    \
62     struct vnode *vp = AFSTOV(avc); \
63     uint_t prevcount;               \
64                                     \
65     mutex_enter(&vp->v_lock);       \
66     prevcount = vp->v_count++;      \
67     mutex_exit(&vp->v_lock);        \
68                                     \
69     if (prevcount == 0) {           \
70         VFS_HOLD(afs_globalVFS);    \
71     }                               \
72 } while(0)
73 #else /* !AFS_SUN58_ENV */
74 # define osi_vnhold(avc, r)  do { VN_HOLD(AFSTOV(avc)); } while(0)
75 #endif /* !AFS_SUN58_ENV */
76
77 #define gop_rdwr(rw,gp,base,len,offset,segflg,ioflag,ulimit,cr,aresid) \
78   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(ioflag),(ulimit),(cr),(aresid))
79 #define gop_lookupname(fnamep,segflg,followlink,compvpp) \
80   lookupname((fnamep),(segflg),(followlink),NULL,(compvpp))
81 #define gop_lookupname_user(fnamep,segflg,followlink,compvpp) \
82   lookupname((fnamep),(segflg),(followlink),NULL,(compvpp))
83
84
85 #if defined(AFS_SUN510_ENV)
86 #define afs_suser(x)        afs_osi_suser(x)
87 #else
88 #define afs_suser(x)        suser(x)
89 #endif
90
91 /*
92  * Global lock support.
93  */
94 #include <sys/mutex.h>
95 extern kmutex_t afs_global_lock;
96
97 #define AFS_GLOCK()     mutex_enter(&afs_global_lock);
98 #define AFS_GUNLOCK()   mutex_exit(&afs_global_lock);
99 #define ISAFS_GLOCK()   mutex_owned(&afs_global_lock)
100 #define osi_InitGlock() \
101         mutex_init(&afs_global_lock, "afs_global_lock", MUTEX_DEFAULT, NULL);
102 #endif
103
104
105 /* Associate the Berkley signal equivalent lock types to System V's */
106 #define LOCK_SH 1               /* F_RDLCK */
107 #define LOCK_EX 2               /* F_WRLCK */
108 #define LOCK_NB 4               /* XXX */
109 #define LOCK_UN 8               /* F_UNLCK */
110
111 #ifndef IO_APPEND
112 #define IO_APPEND       FAPPEND
113 #endif
114
115 #ifndef IO_SYNC
116 #define IO_SYNC         FSYNC
117 #endif
118
119 #if     defined(AFS_SUN56_ENV)
120 /*
121 ** Macro returns 1 if file is larger than 2GB; else returns 0
122 */
123 #undef AfsLargeFileUio
124 #define AfsLargeFileUio(uio)       ( (uio)->_uio_offset._p._u ? 1 : 0 )
125 #undef AfsLargeFileSize
126 #define AfsLargeFileSize(pos, off) ( ((offset_t)(pos)+(offset_t)(off) > (offset_t)0x7fffffff)?1:0)
127 #endif
128
129 #if defined(AFS_SUN510_ENV)
130 #include "h/sunddi.h"
131 extern ddi_taskq_t *afs_taskq;
132 extern krwlock_t afsifinfo_lock;
133
134 /* this should be in rx/SOLARIS/rx_knet.c accessed via accessor functions,
135    eventually */
136 #include "net/if.h"
137 /* Global interface info struct */
138 struct afs_ifinfo {
139   char        ifname[LIFNAMSIZ];
140   ipaddr_t    ipaddr;
141   ipaddr_t    netmask;
142   uint_t      mtu;
143   uint64_t    flags;
144   int         metric;
145   ipaddr_t    dstaddr;
146 };
147
148 #define osi_procname(procname, size) strncpy(procname, PTOU(ttoproc(curthread))->u_comm, size)
149
150 #endif /* _OSI_MACHDEP_H_ */