Linux: Use the correct ATIME flag
[openafs.git] / src / afs / LINUX24 / 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 #include <linux/version.h>
19
20 /* Only needed for xdr.h in glibc 2.1.x */
21 #ifndef quad_t
22 #define quad_t __quad_t
23 #define u_quad_t __u_quad_t
24 #endif
25
26 #undef getuerror
27
28 #ifdef STRUCT_TASK_STRUCT_HAS_TGID
29 #define getpid() current->tgid
30 #ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
31 #define getppid() current->real_parent->tgid
32 #elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
33 #define getppid() current->parent->tgid
34 #else
35 #define getppid() current->p_opptr->tgid
36 #endif
37 #else /* !STRUCT_TASK_STRUCT_HAS_TGID */
38 #define getpid() current->pid
39 #ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
40 #define getppid() current->real_parent->pid
41 #elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
42 #define getppid() current->parent->pid
43 #else
44 #define getppid() current->p_opptr->pid
45 #endif
46 #endif /* STRUCT_TASK_STRUCT_HAS_TGID */
47
48 #ifdef RECALC_SIGPENDING_TAKES_VOID
49 #define RECALC_SIGPENDING(X) recalc_sigpending()
50 #else
51 #define RECALC_SIGPENDING(X) recalc_sigpending(X)
52 #endif
53
54 #if defined (STRUCT_TASK_STRUCT_HAS_SIGMASK_LOCK)
55 #define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock)
56 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock)
57 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGHAND)
58 #define SIG_LOCK(X) spin_lock_irq(&X->sighand->siglock)
59 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sighand->siglock)
60 #else
61 #define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock)
62 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock)
63 #endif
64
65 #if defined (STRUCT_TASK_STRUCT_HAS_RLIM)
66 #define TASK_STRUCT_RLIM rlim
67 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGNAL_RLIM)
68 #define TASK_STRUCT_RLIM signal->rlim
69 #else
70 #error Not sure what to do about rlim (should be in the Linux task struct somewhere....)
71 #endif
72
73
74 #define afs_hz HZ
75 #include "h/sched.h"
76 #if defined(HAVE_CURRENT_KERNEL_TIME)
77 static inline time_t osi_Time(void) { 
78     struct timespec xtime;
79     xtime = current_kernel_time();
80     return xtime.tv_sec;
81 }
82 #else
83 #define osi_Time() (xtime.tv_sec)
84 #endif
85
86
87
88 #ifdef AFS_LINUX_64BIT_KERNEL
89 #define osi_GetTime(V)                                 \
90     do {                                               \
91        struct timeval __afs_tv;                              \
92        do_gettimeofday(&__afs_tv);                           \
93        (V)->tv_sec = (afs_int32)__afs_tv.tv_sec;             \
94        (V)->tv_usec = (afs_int32)__afs_tv.tv_usec;           \
95     } while (0)
96 #else
97 #define osi_GetTime(V) do_gettimeofday((V))
98 #endif
99
100 #undef gop_lookupname
101 #define gop_lookupname osi_lookupname
102
103 #undef gop_lookupname_user
104 #define gop_lookupname_user osi_lookupname
105
106 #define osi_vnhold(V, N) do { VN_HOLD(AFSTOV(V)); } while (0)
107 #define VN_HOLD(V) osi_Assert(igrab((V)) == (V))
108 #define VN_RELE(V) iput((V))
109
110 #define afs_suser(x) capable(CAP_SYS_ADMIN)
111 #define wakeup afs_osi_Wakeup
112
113 #undef vType
114 #define vType(V) ((AFSTOV((V)))->i_mode & S_IFMT)
115 #undef vSetType
116 #define vSetType(V, type) AFSTOV((V))->i_mode = ((type) | (AFSTOV((V))->i_mode & ~S_IFMT))      /* preserve mode */
117
118 #undef IsAfsVnode
119 #define IsAfsVnode(V) ((V)->i_sb == afs_globalVFS)      /* test superblock instead */
120 #undef SetAfsVnode
121 #define SetAfsVnode(V)                                  /* unnecessary */
122
123 /* We often need to pretend we're in user space to get memory transfers
124  * right for the kernel calls we use.
125  */
126 #include <asm/uaccess.h>
127
128 #ifdef KERNEL_SPACE_DECL
129 #undef KERNEL_SPACE_DECL
130 #undef TO_USER_SPACE
131 #undef TO_KERNEL_SPACE
132 #endif
133 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl={0}
134 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
135 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
136
137 #define copyin(F, T, C)  (copy_from_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0)
138 static inline long copyinstr(char *from, char *to, int count, int *length) {
139     long tmp;
140     tmp = strncpy_from_user(to, from, count);
141     if (tmp < 0)
142             return EFAULT;
143     *length = tmp;
144     return 0;
145 }
146 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0)
147
148 /* kernel print statements */
149 #define printf printk
150 #define uprintf printk
151
152
153 #ifndef NGROUPS
154 #define NGROUPS NGROUPS_SMALL
155 #endif
156
157 /* cred struct */
158 typedef struct afs_cred {               /* maps to task field: */
159     int cr_ref;
160     uid_t cr_uid;               /* euid */
161     uid_t cr_ruid;              /* uid */
162     gid_t cr_gid;               /* egid */
163     gid_t cr_rgid;              /* gid */
164     gid_t cr_groups[NGROUPS];   /* 32 groups - empty set to NOGROUP */
165     int cr_ngroups;
166 } cred_t;
167
168 typedef struct afs_cred afs_ucred_t;
169 typedef struct task_struct afs_proc_t;
170
171 #define cr_group_info(cred) ((cred)->cr_group_info)
172 static inline void
173 set_cr_group_info(afs_ucred_t *cred, struct group_info *group_info) {
174     cred->cr_group_info = group_info;
175 }
176
177 #if !defined(current_cred)
178 #define current_gid() (current->gid)
179 #define current_uid() (current->uid)
180 #define current_fsgid() (current->fsgid)
181 #define current_fsuid() (current->fsuid)
182 #endif
183 #if defined(STRUCT_TASK_HAS_CRED)
184 #define current_group_info() (current->cred->group_info)
185 #define task_gid(task) (task->cred->gid)
186 #define task_user(task) (task->cred->user)
187 #define task_session_keyring(task) (task->cred->tgcred->session_keyring)
188 #define current_session_keyring() (current->cred->tgcred->session_keyring)
189 #else
190 #define current_group_info() (current->group_info)
191 #if !defined(task_gid)
192 #define task_gid(task) (task->gid)
193 #endif
194 #if !defined(task_uid)
195 #define task_uid(task) (task->uid)
196 #endif
197 #define task_user(task) (task->user)
198 #define task_session_keyring(task) (task->signal->session_keyring)
199 #define current_session_keyring() (current->signal->session_keyring)
200 #endif
201 #define crhold(c) (c)->cr_ref++
202
203 /* UIO manipulation */
204 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
205 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
206 typedef struct uio {
207     struct iovec *uio_iov;
208     int uio_iovcnt;
209     afs_offs_t uio_offset;
210     uio_seg_t uio_seg;
211     int uio_resid;
212     uio_flag_t uio_flag;
213 } uio_t;
214 #define afsio_iov       uio_iov
215 #define afsio_iovcnt    uio_iovcnt
216 #define afsio_offset    uio_offset
217 #define afsio_seg       uio_segflg
218 #define afsio_fmode     uio_fmode
219 #define afsio_resid     uio_resid
220
221 /* Get/set the inode in the osifile struct. */
222 #define FILE_INODE(F) (F)->f_dentry->d_inode
223
224 #define OSIFILE_INODE(a) FILE_INODE(&(a)->file)
225
226 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
227 #define NEED_IOCTL32
228 #endif
229
230 /* page offset is obtained and stored here during module initialization 
231  * We need a variable to do this because, the PAGE_OFFSET macro defined in
232  * include/asm/page.h can change from kernel to kernel and we cannot use
233  * the hardcoded version.
234  */
235 extern unsigned long afs_linux_page_offset;
236
237 /* function to help with the page offset stuff */
238 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
239
240 #if defined(__KERNEL__)
241 #include <linux/version.h>
242 #include <linux/sched.h>
243 #include <linux/wait.h>
244
245 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
246 extern struct mutex afs_global_lock;
247 #else
248 extern struct semaphore afs_global_lock;
249 #define mutex_lock(lock) down(lock)
250 #define mutex_unlock(lock) up(lock)
251 #endif
252 extern int afs_global_owner;
253
254 #define AFS_GLOCK() \
255 do { \
256          mutex_lock(&afs_global_lock); \
257          if (afs_global_owner) \
258              osi_Panic("afs_global_lock already held by pid %d", \
259                        afs_global_owner); \
260          afs_global_owner = current->pid; \
261 } while (0)
262
263 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
264
265 #define AFS_GUNLOCK() \
266 do { \
267     if (!ISAFS_GLOCK()) \
268         osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \
269     afs_global_owner = 0; \
270     mutex_unlock(&afs_global_lock); \
271 } while (0)
272 #else
273 #define AFS_GLOCK()
274 #define AFS_GUNLOCK()
275 #define ISAFS_GLOCK() 1
276 #define AFS_ASSERT_GLOCK()
277 #endif
278
279 #ifdef AFS_AMD64_LINUX20_ENV
280 /* RHEL5 beta's kernel doesn't define these. They aren't gonna change, so... */
281
282 #ifndef __NR_ia32_afs_syscall
283 #define __NR_ia32_afs_syscall 137
284 #endif
285 #ifndef __NR_ia32_setgroups
286 #define __NR_ia32_setgroups 81
287 #endif
288 #ifndef __NR_ia32_setgroups32
289 #define __NR_ia32_setgroups32 206
290 #endif
291 #ifndef __NR_ia32_close
292 #define __NR_ia32_close 6
293 #endif
294 #ifndef __NR_ia32_chdir
295 #define __NR_ia32_chdir 12
296 #endif
297 #ifndef __NR_ia32_break
298 #define __NR_ia32_break 17
299 #endif
300 #ifndef __NR_ia32_stty
301 #define __NR_ia32_stty 31
302 #endif
303 #ifndef __NR_ia32_gtty
304 #define __NR_ia32_gtty 32
305 #endif
306 #ifndef __NR_ia32_ftime
307 #define __NR_ia32_ftime 35
308 #endif
309 #ifndef __NR_ia32_prof
310 #define __NR_ia32_prof 44
311 #endif
312 #ifndef __NR_ia32_lock
313 #define __NR_ia32_lock 53
314 #endif
315 #ifndef __NR_ia32_mpx
316 #define __NR_ia32_mpx 56
317 #endif
318 #ifndef __NR_ia32_exit
319 #define __NR_ia32_exit 1
320 #endif
321 #ifndef __NR_ia32_mount
322 #define __NR_ia32_mount 21
323 #endif
324 #ifndef __NR_ia32_read
325 #define __NR_ia32_read 3
326 #endif
327 #ifndef __NR_ia32_write
328 #define __NR_ia32_write 4
329 #endif
330 #ifndef __NR_ia32_open
331 #define __NR_ia32_open 5
332 #endif
333 #ifndef __NR_ia32_close
334 #define __NR_ia32_close 6
335 #endif
336 #ifndef __NR_ia32_unlink
337 #define __NR_ia32_unlink 10
338 #endif
339 #endif
340
341 #endif /* OSI_MACHDEP_H_ */