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 PENDING(p,b) has_pending_signals(&(p)->signal, (b))
35 static inline void _recalc_sigpending_tsk(struct task_struct *t)
37 t->sigpending = PENDING(&t->pending, &t->blocked) ||
38 PENDING(&t->sig->shared_pending, &t->blocked);
41 #define RECALC_SIGPENDING(X) _recalc_sigpending_tsk(X)
43 #define RECALC_SIGPENDING(X) recalc_sigpending(X)
46 #ifdef STRUCT_TASK_STRUCT_HAS_SIGMASK_LOCK
47 #define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock)
48 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock)
50 #define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock)
51 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock)
57 #define osi_Time() (xtime.tv_sec)
59 #define osi_GetTime(V) do { (*(V)).tv_sec = xtime.tv_sec; (*(V)).tv_usec = xtime.tv_usec; } while (0)
61 #define osi_GetTime(V) (*(V)=xtime)
65 #define gop_lookupname osi_lookupname
67 #define osi_vnhold(v, n) VN_HOLD(v)
69 #define osi_AllocSmall afs_osi_Alloc
70 #define osi_FreeSmall afs_osi_Free
72 #define afs_suser suser
73 #define wakeup afs_osi_Wakeup
76 #define vType(V) ((( vnode_t *)V)->v_type & S_IFMT)
78 /* IsAfsVnode relies on the fast that there is only one vnodeop table for AFS.
79 * Use the same type of test as other OS's for compatibility.
82 extern struct vnodeops afs_dir_iops, afs_symlink_iops;
83 #define IsAfsVnode(vc) (((vc)->v_op == afs_ops) ? 1 : \
84 ((vc)->v_op == &afs_dir_iops) ? 1 : \
85 ((vc)->v_op == &afs_symlink_iops))
88 /* bcopy is in stds.h, just so fcrypt.c can pick it up. */
89 #define bzero(D,C) memset((D), 0, (C))
90 #define bcmp(A,B,C) memcmp((A), (B), (C))
93 /* We often need to pretend we're in user space to get memory transfers
94 * right for the kernel calls we use.
96 #ifdef KERNEL_SPACE_DECL
97 #undef KERNEL_SPACE_DECL
99 #undef TO_KERNEL_SPACE
101 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl
102 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
103 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
105 /* Backwards compatibilty macros - copyin/copyout are redone because macro
106 * inside parentheses is not evalutated.
108 #define memcpy_fromfs copy_from_user
109 #define memcpy_tofs copy_to_user
110 #define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)), 0)
111 #define copyinstr(F, T, C, L) (copyin(F, T, C), *(L)=strlen(T), 0)
112 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)), 0)
114 /* kernel print statements */
115 #define printf printk
116 #define uprintf printk
119 #define PAGESIZE PAGE_SIZE
122 typedef struct cred { /* maps to task field: */
128 uid_t cr_uid; /* euid */
129 uid_t cr_ruid; /* uid */
130 gid_t cr_gid; /* egid */
131 gid_t cr_rgid; /* gid */
132 gid_t cr_groups[NGROUPS]; /* 32 groups - empty set to NOGROUP */
135 #define AFS_UCRED cred
136 #define AFS_PROC struct task_struct
137 #define crhold(c) (c)->cr_ref++
139 /* UIO manipulation */
140 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
141 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
143 struct iovec *uio_iov;
145 afs_offs_t uio_offset;
150 #define afsio_iov uio_iov
151 #define afsio_iovcnt uio_iovcnt
152 #define afsio_offset uio_offset
153 #define afsio_seg uio_segflg
154 #define afsio_fmode uio_fmode
155 #define afsio_resid uio_resid
157 /* Get/set the inode in the osifile struct. */
158 #define FILE_INODE(F) (F)->f_dentry->d_inode
161 /* page offset is obtained and stored here during module initialization
162 * We need a variable to do this because, the PAGE_OFFSET macro defined in
163 * include/asm/page.h can change from kernel to kernel and we cannot use
164 * the hardcoded version.
166 extern unsigned long afs_linux_page_offset;
168 /* some more functions to help with the page offset stuff */
169 #define AFS_LINUX_MAP_NR(addr) ((((unsigned long)addr) - afs_linux_page_offset) >> PAGE_SHIFT)
171 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
173 #if defined(__KERNEL__) && defined(CONFIG_SMP)
174 #include "../h/sched.h"
175 #include "linux/wait.h"
177 extern struct semaphore afs_global_lock;
178 extern int afs_global_owner;
180 #define AFS_GLOCK() \
182 down(&afs_global_lock); \
183 if (afs_global_owner) \
184 osi_Panic("afs_global_lock already held by pid %d", \
186 afs_global_owner = current->pid; \
189 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
191 #define AFS_GUNLOCK() \
193 if (!ISAFS_GLOCK()) \
194 osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \
195 afs_global_owner = 0; \
196 up(&afs_global_lock); \
202 #define AFS_GUNLOCK()
203 #define ISAFS_GLOCK() 1
204 #define AFS_ASSERT_GLOCK()
205 #define AFS_ASSERT_RXGLOCK()
208 #define AFS_RXGLOCK()
209 #define AFS_RXGUNLOCK()
210 #define ISAFS_RXGLOCK() 1
211 #endif /* OSI_MACHDEP_H_ */