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 #define osi_GetTime(V) do_gettimeofday((V))
57 #define gop_lookupname osi_lookupname
59 #define osi_vnhold(v, n) VN_HOLD(v)
61 #define osi_AllocSmall afs_osi_Alloc
62 #define osi_FreeSmall afs_osi_Free
64 #define afs_suser(x) capable(CAP_SYS_ADMIN)
65 #define wakeup afs_osi_Wakeup
68 #define vType(V) ((( vnode_t *)V)->v_type & S_IFMT)
70 /* IsAfsVnode relies on the fast that there is only one vnodeop table for AFS.
71 * Use the same type of test as other OS's for compatibility.
74 extern struct vnodeops afs_file_iops, afs_dir_iops, afs_symlink_iops;
75 #define IsAfsVnode(v) (((v)->v_op == &afs_file_iops) ? 1 : \
76 ((v)->v_op == &afs_dir_iops) ? 1 : \
77 ((v)->v_op == &afs_symlink_iops))
79 #define SetAfsVnode(v)
81 /* We often need to pretend we're in user space to get memory transfers
82 * right for the kernel calls we use.
84 #ifdef KERNEL_SPACE_DECL
85 #undef KERNEL_SPACE_DECL
87 #undef TO_KERNEL_SPACE
89 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl
90 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
91 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
93 /* Backwards compatibilty macros - copyin/copyout are redone because macro
94 * inside parentheses is not evalutated.
96 #define memcpy_fromfs copy_from_user
97 #define memcpy_tofs copy_to_user
98 #define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)), 0)
99 #define copyinstr(F, T, C, L) (copyin(F, T, C), *(L)=strlen(T), 0)
100 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)), 0)
102 /* kernel print statements */
103 #define printf printk
104 #define uprintf printk
107 #define PAGESIZE PAGE_SIZE
109 #define NGROUPS NGROUPS_MAX
113 typedef struct cred { /* maps to task field: */
119 uid_t cr_uid; /* euid */
120 uid_t cr_ruid; /* uid */
121 gid_t cr_gid; /* egid */
122 gid_t cr_rgid; /* gid */
123 gid_t cr_groups[NGROUPS]; /* 32 groups - empty set to NOGROUP */
126 #define AFS_UCRED cred
127 #define AFS_PROC struct task_struct
128 #define crhold(c) (c)->cr_ref++
130 /* UIO manipulation */
131 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
132 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
134 struct iovec *uio_iov;
136 afs_offs_t uio_offset;
141 #define afsio_iov uio_iov
142 #define afsio_iovcnt uio_iovcnt
143 #define afsio_offset uio_offset
144 #define afsio_seg uio_segflg
145 #define afsio_fmode uio_fmode
146 #define afsio_resid uio_resid
148 /* Get/set the inode in the osifile struct. */
149 #define FILE_INODE(F) (F)->f_dentry->d_inode
152 /* page offset is obtained and stored here during module initialization
153 * We need a variable to do this because, the PAGE_OFFSET macro defined in
154 * include/asm/page.h can change from kernel to kernel and we cannot use
155 * the hardcoded version.
157 extern unsigned long afs_linux_page_offset;
159 /* function to help with the page offset stuff */
160 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
162 #if defined(__KERNEL__) && defined(CONFIG_SMP)
163 #include "../h/sched.h"
164 #include "linux/wait.h"
166 extern struct semaphore afs_global_lock;
167 extern int afs_global_owner;
169 #define AFS_GLOCK() \
171 down(&afs_global_lock); \
172 if (afs_global_owner) \
173 osi_Panic("afs_global_lock already held by pid %d", \
175 afs_global_owner = current->pid; \
178 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
180 #define AFS_GUNLOCK() \
182 if (!ISAFS_GLOCK()) \
183 osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \
184 afs_global_owner = 0; \
185 up(&afs_global_lock); \
191 #define AFS_GUNLOCK()
192 #define ISAFS_GLOCK() 1
193 #define AFS_ASSERT_GLOCK()
194 #define AFS_ASSERT_RXGLOCK()
197 #define AFS_RXGLOCK()
198 #define AFS_RXGUNLOCK()
199 #define ISAFS_RXGLOCK() 1
200 #endif /* OSI_MACHDEP_H_ */