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 /* Only needed for xdr.h in glibc 2.1.x */
20 #define quad_t __quad_t
21 #define u_quad_t __u_quad_t
26 #define getpid() current->pid
27 #ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
28 #define getppid() current->real_parent->pid
30 #define getppid() current->p_opptr->pid
33 #ifdef RECALC_SIGPENDING_TAKES_VOID
34 #define RECALC_SIGPENDING(X) recalc_sigpending()
36 #define RECALC_SIGPENDING(X) recalc_sigpending(X)
39 #if defined (STRUCT_TASK_STRUCT_HAS_SIGMASK_LOCK)
40 #define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock)
41 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock)
42 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGHAND)
43 #define SIG_LOCK(X) spin_lock_irq(&X->sighand->siglock)
44 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sighand->siglock)
46 #define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock)
47 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock)
53 #define osi_Time() (xtime.tv_sec)
54 #ifdef AFS_LINUX_64BIT_KERNEL
55 #define osi_GetTime(V) \
58 do_gettimeofday(&tv); \
59 (V)->tv_sec = (afs_int32)tv.tv_sec; \
60 (V)->tv_usec = (afs_int32)tv.tv_usec; \
63 #define osi_GetTime(V) do_gettimeofday((V))
67 #define gop_lookupname osi_lookupname
69 #define osi_vnhold(v, n) do { VN_HOLD(AFSTOV(v)); } while (0)
71 #if defined(AFS_LINUX24_ENV)
72 #define VN_HOLD(V) atomic_inc(&((vnode_t *) V)->i_count)
74 #define VN_HOLD(V) ((vnode_t *) V)->i_count++
77 #if defined(AFS_LINUX26_ENV)
78 #define VN_RELE(V) iput((struct inode *) V)
80 #define VN_RELE(V) osi_iput((struct inode *) V)
83 #define osi_AllocSmall afs_osi_Alloc
84 #define osi_FreeSmall afs_osi_Free
86 #define afs_suser(x) capable(CAP_SYS_ADMIN)
87 #define wakeup afs_osi_Wakeup
90 #define vType(V) ((( vnode_t *)V)->v_type & S_IFMT)
92 /* IsAfsVnode relies on the fast that there is only one vnodeop table for AFS.
93 * Use the same type of test as other OS's for compatibility.
96 extern struct vnodeops afs_file_iops, afs_dir_iops, afs_symlink_iops;
97 #define IsAfsVnode(v) (((v)->v_op == &afs_file_iops) ? 1 : \
98 ((v)->v_op == &afs_dir_iops) ? 1 : \
99 ((v)->v_op == &afs_symlink_iops))
101 #define SetAfsVnode(v)
103 /* We often need to pretend we're in user space to get memory transfers
104 * right for the kernel calls we use.
106 #ifdef KERNEL_SPACE_DECL
107 #undef KERNEL_SPACE_DECL
109 #undef TO_KERNEL_SPACE
111 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl
112 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
113 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
115 /* Backwards compatibilty macros - copyin/copyout are redone because macro
116 * inside parentheses is not evalutated.
118 #define memcpy_fromfs copy_from_user
119 #define memcpy_tofs copy_to_user
120 #define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)), 0)
121 #define copyinstr(F, T, C, L) (copyin(F, T, C), *(L)=strlen(T), 0)
122 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)), 0)
124 /* kernel print statements */
125 #define printf printk
126 #define uprintf printk
129 #define PAGESIZE PAGE_SIZE
131 #define NGROUPS NGROUPS_SMALL
135 typedef struct cred { /* maps to task field: */
141 uid_t cr_uid; /* euid */
142 uid_t cr_ruid; /* uid */
143 gid_t cr_gid; /* egid */
144 gid_t cr_rgid; /* gid */
145 #if defined(AFS_LINUX26_ENV)
146 struct group_info *cr_group_info;
148 gid_t cr_groups[NGROUPS]; /* 32 groups - empty set to NOGROUP */
152 #define AFS_UCRED cred
153 #define AFS_PROC struct task_struct
154 #define crhold(c) (c)->cr_ref++
156 /* UIO manipulation */
157 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
158 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
160 struct iovec *uio_iov;
162 afs_offs_t uio_offset;
167 #define afsio_iov uio_iov
168 #define afsio_iovcnt uio_iovcnt
169 #define afsio_offset uio_offset
170 #define afsio_seg uio_segflg
171 #define afsio_fmode uio_fmode
172 #define afsio_resid uio_resid
174 /* Get/set the inode in the osifile struct. */
175 #define FILE_INODE(F) (F)->f_dentry->d_inode
178 /* page offset is obtained and stored here during module initialization
179 * We need a variable to do this because, the PAGE_OFFSET macro defined in
180 * include/asm/page.h can change from kernel to kernel and we cannot use
181 * the hardcoded version.
183 extern unsigned long afs_linux_page_offset;
185 /* function to help with the page offset stuff */
186 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
188 #if defined(__KERNEL__) && defined(CONFIG_SMP)
189 #include "../h/sched.h"
190 #include "linux/wait.h"
192 extern struct semaphore afs_global_lock;
193 extern int afs_global_owner;
195 #define AFS_GLOCK() \
197 down(&afs_global_lock); \
198 if (afs_global_owner) \
199 osi_Panic("afs_global_lock already held by pid %d", \
201 afs_global_owner = current->pid; \
204 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
206 #define AFS_GUNLOCK() \
208 if (!ISAFS_GLOCK()) \
209 osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \
210 afs_global_owner = 0; \
211 up(&afs_global_lock); \
217 #define AFS_GUNLOCK()
218 #define ISAFS_GLOCK() 1
219 #define AFS_ASSERT_GLOCK()
220 #define AFS_ASSERT_RXGLOCK()
223 #define AFS_RXGLOCK()
224 #define AFS_RXGUNLOCK()
225 #define ISAFS_RXGLOCK() 1
226 #endif /* OSI_MACHDEP_H_ */