more-redhate-beta-fun-20030131
[openafs.git] / src / afs / LINUX / 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  * Linux implementation.
12  *
13  */
14
15 #ifndef OSI_MACHDEP_H_
16 #define OSI_MACHDEP_H_
17
18 /* Only needed for xdr.h in glibc 2.1.x */
19 #ifndef quad_t
20 #define quad_t __quad_t
21 #define u_quad_t __u_quad_t
22 #endif
23
24 #undef getuerror
25
26 #define getpid() current->pid
27 #ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
28 #define getppid() current->real_parent->pid
29 #else
30 #define getppid() current->p_opptr->pid
31 #endif
32
33 #ifdef RECALC_SIGPENDING_TAKES_VOID
34 /* Principal of maximum uselessness says we need to provide this */
35 static inline int _has_pending_signals(sigset_t *signal, sigset_t *blocked)
36 {
37   unsigned long ready;
38   long i;
39
40   switch (_NSIG_WORDS) {
41   default:
42     for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)
43       ready |= signal->sig[i] &~ blocked->sig[i];
44     break;
45
46   case 4: ready  = signal->sig[3] &~ blocked->sig[3];
47     ready |= signal->sig[2] &~ blocked->sig[2];
48     ready |= signal->sig[1] &~ blocked->sig[1];
49     ready |= signal->sig[0] &~ blocked->sig[0];
50     break;
51
52   case 2: ready  = signal->sig[1] &~ blocked->sig[1];
53     ready |= signal->sig[0] &~ blocked->sig[0];
54     break;
55
56   case 1: ready  = signal->sig[0] &~ blocked->sig[0];
57   }
58   return ready != 0;
59 }
60
61 #define PENDING(p,b) _has_pending_signals(&(p)->signal, (b))
62 static inline void _recalc_sigpending_tsk(struct task_struct *t)
63 {
64     t->sigpending = PENDING(&t->pending, &t->blocked) ||
65         PENDING(&t->sig->shared_pending, &t->blocked);
66 }
67
68 #define RECALC_SIGPENDING(X) _recalc_sigpending_tsk(X)
69 #else
70 #define RECALC_SIGPENDING(X) recalc_sigpending(X)
71 #endif
72  
73 #ifdef STRUCT_TASK_STRUCT_HAS_SIGMASK_LOCK
74 #define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock)
75 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock)
76 #else
77 #define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock)
78 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock)
79 #endif
80
81
82 #define afs_hz HZ
83 #include "h/sched.h"
84 #define osi_Time() (xtime.tv_sec)
85 #if  (CPU == sparc64)
86 #define osi_GetTime(V) do { (*(V)).tv_sec = xtime.tv_sec; (*(V)).tv_usec = xtime.tv_usec; } while (0)
87 #else
88 #define osi_GetTime(V) (*(V)=xtime)
89 #endif
90
91 #undef gop_lookupname
92 #define gop_lookupname osi_lookupname
93
94 #define osi_vnhold(v, n)  VN_HOLD(v)
95
96 #define osi_AllocSmall afs_osi_Alloc
97 #define osi_FreeSmall afs_osi_Free
98
99 #define afs_suser suser
100 #define wakeup afs_osi_Wakeup
101
102 #undef vType
103 #define vType(V) ((( vnode_t *)V)->v_type & S_IFMT)
104
105 /* IsAfsVnode relies on the fast that there is only one vnodeop table for AFS.
106  * Use the same type of test as other OS's for compatibility.
107  */
108 #undef IsAfsVnode
109 extern struct vnodeops afs_dir_iops, afs_symlink_iops;
110 #define IsAfsVnode(vc) (((vc)->v_op == afs_ops) ? 1 : \
111                         ((vc)->v_op == &afs_dir_iops) ? 1 : \
112                         ((vc)->v_op == &afs_symlink_iops))
113
114 #if 0
115 /* bcopy is in stds.h, just so fcrypt.c can pick it up. */
116 #define bzero(D,C)   memset((D), 0, (C))
117 #define bcmp(A,B,C)  memcmp((A), (B), (C))
118 #endif
119
120 /* We often need to pretend we're in user space to get memory transfers
121  * right for the kernel calls we use.
122  */
123 #ifdef KERNEL_SPACE_DECL
124 #undef KERNEL_SPACE_DECL
125 #undef TO_USER_SPACE
126 #undef TO_KERNEL_SPACE
127 #endif
128 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl
129 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
130 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
131
132 /* Backwards compatibilty macros - copyin/copyout are redone because macro
133  * inside parentheses is not evalutated.
134  */
135 #define memcpy_fromfs copy_from_user
136 #define memcpy_tofs copy_to_user
137 #define copyin(F, T, C)  (copy_from_user ((char*)(T), (char*)(F), (C)), 0)
138 #define copyinstr(F, T, C, L) (copyin(F, T, C), *(L)=strlen(T), 0)
139 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)), 0)
140
141 /* kernel print statements */
142 #define printf printk
143 #define uprintf printk
144
145
146 #define PAGESIZE PAGE_SIZE
147
148 /* cred struct */
149 typedef struct cred {           /* maps to task field: */
150 #if (CPU == sparc64)
151     long cr_ref;
152 #else
153     int cr_ref;
154 #endif
155     uid_t cr_uid;       /* euid */
156     uid_t cr_ruid;      /* uid */
157     gid_t cr_gid;       /* egid */
158     gid_t cr_rgid;      /* gid */
159     gid_t cr_groups[NGROUPS];   /* 32 groups - empty set to NOGROUP */
160     int cr_ngroups;
161 } cred_t;
162 #define AFS_UCRED cred
163 #define AFS_PROC struct task_struct
164 #define crhold(c) (c)->cr_ref++
165
166 /* UIO manipulation */
167 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
168 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
169 typedef struct uio {
170     struct      iovec *uio_iov;
171     int         uio_iovcnt;
172     afs_offs_t  uio_offset;
173     uio_seg_t   uio_seg;
174     int         uio_resid;
175     uio_flag_t  uio_flag;
176 } uio_t;
177 #define afsio_iov       uio_iov
178 #define afsio_iovcnt    uio_iovcnt
179 #define afsio_offset    uio_offset
180 #define afsio_seg       uio_segflg
181 #define afsio_fmode     uio_fmode
182 #define afsio_resid     uio_resid
183
184 /* Get/set the inode in the osifile struct. */
185 #define FILE_INODE(F) (F)->f_dentry->d_inode
186
187
188 /* page offset is obtained and stored here during module initialization 
189  * We need a variable to do this because, the PAGE_OFFSET macro defined in
190  * include/asm/page.h can change from kernel to kernel and we cannot use
191  * the hardcoded version.
192  */
193 extern unsigned long afs_linux_page_offset;
194
195 /* some more functions to help with the page offset stuff */
196 #define AFS_LINUX_MAP_NR(addr) ((((unsigned long)addr) - afs_linux_page_offset)  >> PAGE_SHIFT)
197
198 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
199
200 #if defined(__KERNEL__) && defined(CONFIG_SMP)
201 #include "../h/sched.h"
202 #include "linux/wait.h"
203
204 extern struct semaphore afs_global_lock;
205 extern int afs_global_owner;
206
207 #define AFS_GLOCK() \
208 do { \
209          down(&afs_global_lock); \
210          if (afs_global_owner) \
211              osi_Panic("afs_global_lock already held by pid %d", \
212                        afs_global_owner); \
213          afs_global_owner = current->pid; \
214 } while (0)
215
216 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
217
218 #define AFS_GUNLOCK() \
219 do { \
220     if (!ISAFS_GLOCK()) \
221         osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \
222     afs_global_owner = 0; \
223     up(&afs_global_lock); \
224 } while (0)
225
226
227 #else
228 #define AFS_GLOCK()
229 #define AFS_GUNLOCK()
230 #define ISAFS_GLOCK() 1
231 #define AFS_ASSERT_GLOCK()
232 #define AFS_ASSERT_RXGLOCK()
233 #endif
234
235 #define AFS_RXGLOCK()
236 #define AFS_RXGUNLOCK()
237 #define ISAFS_RXGLOCK() 1
238 #endif /* OSI_MACHDEP_H_ */