2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * Linux implementation.
15 #ifndef OSI_MACHDEP_H_
16 #define OSI_MACHDEP_H_
18 #include <linux/version.h>
19 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
20 #define AFS_LINUX26_ONEGROUP_ENV 1
23 /* Only needed for xdr.h in glibc 2.1.x */
25 #define quad_t __quad_t
26 #define u_quad_t __u_quad_t
31 #ifdef STRUCT_TASK_STRUCT_HAS_TGID
32 #define getpid() current->tgid
33 #ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
34 #define getppid() current->real_parent->tgid
35 #elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
36 #define getppid() current->parent->tgid
38 #define getppid() current->p_opptr->tgid
40 #else /* !STRUCT_TASK_STRUCT_HAS_TGID */
41 #define getpid() current->pid
42 #ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
43 #define getppid() current->real_parent->pid
44 #elif defined(STRUCT_TASK_STRUCT_HAS_PARENT)
45 #define getppid() current->parent->pid
47 #define getppid() current->p_opptr->pid
49 #endif /* STRUCT_TASK_STRUCT_HAS_TGID */
51 #ifdef RECALC_SIGPENDING_TAKES_VOID
52 #define RECALC_SIGPENDING(X) recalc_sigpending()
54 #define RECALC_SIGPENDING(X) recalc_sigpending(X)
57 #if defined (STRUCT_TASK_STRUCT_HAS_SIGMASK_LOCK)
58 #define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock)
59 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock)
60 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGHAND)
61 #define SIG_LOCK(X) spin_lock_irq(&X->sighand->siglock)
62 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sighand->siglock)
64 #define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock)
65 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock)
68 #if defined (STRUCT_TASK_STRUCT_HAS_RLIM)
69 #define TASK_STRUCT_RLIM rlim
70 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGNAL_RLIM)
71 #define TASK_STRUCT_RLIM signal->rlim
73 #error Not sure what to do about rlim (should be in the Linux task struct somewhere....)
79 #define osi_Time() (xtime.tv_sec)
80 #ifdef AFS_LINUX_64BIT_KERNEL
81 #define osi_GetTime(V) \
83 struct timeval __afs_tv; \
84 do_gettimeofday(&__afs_tv); \
85 (V)->tv_sec = (afs_int32)__afs_tv.tv_sec; \
86 (V)->tv_usec = (afs_int32)__afs_tv.tv_usec; \
89 #define osi_GetTime(V) do_gettimeofday((V))
93 #define gop_lookupname osi_lookupname
95 #define osi_vnhold(V, N) do { VN_HOLD(AFSTOV(V)); } while (0)
96 #define VN_HOLD(V) osi_Assert(igrab((V)) == (V))
97 #define VN_RELE(V) iput((V))
99 #define afs_suser(x) capable(CAP_SYS_ADMIN)
100 #define wakeup afs_osi_Wakeup
103 #define vType(V) ((AFSTOV((V)))->i_mode & S_IFMT)
105 #define vSetType(V, type) AFSTOV((V))->i_mode = ((type) | (AFSTOV((V))->i_mode & ~S_IFMT)) /* preserve mode */
108 #define IsAfsVnode(V) ((V)->i_sb == afs_globalVFS) /* test superblock instead */
110 #define SetAfsVnode(V) /* unnecessary */
112 /* We often need to pretend we're in user space to get memory transfers
113 * right for the kernel calls we use.
115 #include <asm/uaccess.h>
117 #ifdef KERNEL_SPACE_DECL
118 #undef KERNEL_SPACE_DECL
120 #undef TO_KERNEL_SPACE
122 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl
123 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
124 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
126 #define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0)
127 static inline long copyinstr(char *from, char *to, int count, int *length) {
129 tmp = strncpy_from_user(to, from, count);
135 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0)
137 /* kernel print statements */
138 #define printf printk
139 #define uprintf printk
143 #define NGROUPS NGROUPS_SMALL
147 typedef struct cred { /* maps to task field: */
149 uid_t cr_uid; /* euid */
150 uid_t cr_ruid; /* uid */
151 gid_t cr_gid; /* egid */
152 gid_t cr_rgid; /* gid */
153 #if defined(AFS_LINUX26_ENV)
154 struct group_info *cr_group_info;
156 gid_t cr_groups[NGROUPS]; /* 32 groups - empty set to NOGROUP */
159 struct cred *cr_next;
161 #define AFS_UCRED cred
162 #define AFS_PROC struct task_struct
163 #define crhold(c) (c)->cr_ref++
165 /* UIO manipulation */
166 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
167 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
169 struct iovec *uio_iov;
171 afs_offs_t uio_offset;
176 #define afsio_iov uio_iov
177 #define afsio_iovcnt uio_iovcnt
178 #define afsio_offset uio_offset
179 #define afsio_seg uio_segflg
180 #define afsio_fmode uio_fmode
181 #define afsio_resid uio_resid
183 /* Get/set the inode in the osifile struct. */
184 #define FILE_INODE(F) (F)->f_dentry->d_inode
186 #ifdef AFS_LINUX26_ENV
187 #define OSIFILE_INODE(a) FILE_INODE((a)->filp)
189 #define OSIFILE_INODE(a) FILE_INODE(&(a)->file)
192 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
196 /* page offset is obtained and stored here during module initialization
197 * We need a variable to do this because, the PAGE_OFFSET macro defined in
198 * include/asm/page.h can change from kernel to kernel and we cannot use
199 * the hardcoded version.
201 extern unsigned long afs_linux_page_offset;
203 /* function to help with the page offset stuff */
204 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
206 #if defined(__KERNEL__)
207 #include <linux/version.h>
208 #include <linux/sched.h>
209 #include <linux/wait.h>
211 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
212 extern struct mutex afs_global_lock;
214 extern struct semaphore afs_global_lock;
215 #define mutex_lock(lock) down(lock)
216 #define mutex_unlock(lock) up(lock)
218 extern int afs_global_owner;
220 #define AFS_GLOCK() \
222 mutex_lock(&afs_global_lock); \
223 if (afs_global_owner) \
224 osi_Panic("afs_global_lock already held by pid %d", \
226 afs_global_owner = current->pid; \
229 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
231 #define AFS_GUNLOCK() \
233 if (!ISAFS_GLOCK()) \
234 osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \
235 afs_global_owner = 0; \
236 mutex_unlock(&afs_global_lock); \
240 #define AFS_GUNLOCK()
241 #define ISAFS_GLOCK() 1
242 #define AFS_ASSERT_GLOCK()
245 #ifdef AFS_AMD64_LINUX20_ENV
246 /* RHEL5 beta's kernel doesn't define these. They aren't gonna change, so... */
248 #ifndef __NR_ia32_afs_syscall
249 #define __NR_ia32_afs_syscall 137
251 #ifndef __NR_ia32_setgroups
252 #define __NR_ia32_setgroups 81
254 #ifndef __NR_ia32_setgroups32
255 #define __NR_ia32_setgroups32 206
257 #ifndef __NR_ia32_close
258 #define __NR_ia32_close 6
260 #ifndef __NR_ia32_chdir
261 #define __NR_ia32_chdir 12
263 #ifndef __NR_ia32_break
264 #define __NR_ia32_break 17
266 #ifndef __NR_ia32_stty
267 #define __NR_ia32_stty 31
269 #ifndef __NR_ia32_gtty
270 #define __NR_ia32_gtty 32
272 #ifndef __NR_ia32_ftime
273 #define __NR_ia32_ftime 35
275 #ifndef __NR_ia32_prof
276 #define __NR_ia32_prof 44
278 #ifndef __NR_ia32_lock
279 #define __NR_ia32_lock 53
281 #ifndef __NR_ia32_mpx
282 #define __NR_ia32_mpx 56
284 #ifndef __NR_ia32_exit
285 #define __NR_ia32_exit 1
287 #ifndef __NR_ia32_mount
288 #define __NR_ia32_mount 21
290 #ifndef __NR_ia32_read
291 #define __NR_ia32_read 3
293 #ifndef __NR_ia32_write
294 #define __NR_ia32_write 4
296 #ifndef __NR_ia32_open
297 #define __NR_ia32_open 5
299 #ifndef __NR_ia32_close
300 #define __NR_ia32_close 6
302 #ifndef __NR_ia32_unlink
303 #define __NR_ia32_unlink 10
307 #endif /* OSI_MACHDEP_H_ */