reindent-20030715
[openafs.git] / src / afs / LINUX / 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 /* Only needed for xdr.h in glibc 2.1.x */
19 #ifndef quad_t
20 #define quad_t __quad_t
21 #define u_quad_t __u_quad_t
22 #endif
23
24 #undef getuerror
25
26 #define getpid() current->pid
27 #ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT
28 #define getppid() current->real_parent->pid
29 #else
30 #define getppid() current->p_opptr->pid
31 #endif
32
33 #ifdef RECALC_SIGPENDING_TAKES_VOID
34 #define RECALC_SIGPENDING(X) recalc_sigpending()
35 #else
36 #define RECALC_SIGPENDING(X) recalc_sigpending(X)
37 #endif
38
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)
45 #else
46 #define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock)
47 #define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock)
48 #endif
49
50
51 #define afs_hz HZ
52 #include "h/sched.h"
53 #define osi_Time() (xtime.tv_sec)
54 #if  (CPU == sparc64)
55 #define osi_GetTime(V) do { (*(V)).tv_sec = xtime.tv_sec; (*(V)).tv_usec = xtime.tv_usec; } while (0)
56 #else
57 #define osi_GetTime(V) (*(V)=xtime)
58 #endif
59
60 #undef gop_lookupname
61 #define gop_lookupname osi_lookupname
62
63 #define osi_vnhold(v, n)  VN_HOLD(v)
64
65 #define osi_AllocSmall afs_osi_Alloc
66 #define osi_FreeSmall afs_osi_Free
67
68 #define afs_suser suser
69 #define wakeup afs_osi_Wakeup
70
71 #undef vType
72 #define vType(V) ((( vnode_t *)V)->v_type & S_IFMT)
73
74 /* IsAfsVnode relies on the fast that there is only one vnodeop table for AFS.
75  * Use the same type of test as other OS's for compatibility.
76  */
77 #undef IsAfsVnode
78 extern struct vnodeops afs_dir_iops, afs_symlink_iops;
79 #define IsAfsVnode(vc) (((vc)->v_op == afs_ops) ? 1 : \
80                         ((vc)->v_op == &afs_dir_iops) ? 1 : \
81                         ((vc)->v_op == &afs_symlink_iops))
82
83 #if 0
84 /* bcopy is in stds.h, just so fcrypt.c can pick it up. */
85 #define bzero(D,C)   memset((D), 0, (C))
86 #define bcmp(A,B,C)  memcmp((A), (B), (C))
87 #endif
88
89 /* We often need to pretend we're in user space to get memory transfers
90  * right for the kernel calls we use.
91  */
92 #ifdef KERNEL_SPACE_DECL
93 #undef KERNEL_SPACE_DECL
94 #undef TO_USER_SPACE
95 #undef TO_KERNEL_SPACE
96 #endif
97 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl
98 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
99 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
100
101 /* Backwards compatibilty macros - copyin/copyout are redone because macro
102  * inside parentheses is not evalutated.
103  */
104 #define memcpy_fromfs copy_from_user
105 #define memcpy_tofs copy_to_user
106 #define copyin(F, T, C)  (copy_from_user ((char*)(T), (char*)(F), (C)), 0)
107 #define copyinstr(F, T, C, L) (copyin(F, T, C), *(L)=strlen(T), 0)
108 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)), 0)
109
110 /* kernel print statements */
111 #define printf printk
112 #define uprintf printk
113
114
115 #define PAGESIZE PAGE_SIZE
116
117 /* cred struct */
118 typedef struct cred {           /* maps to task field: */
119 #if (CPU == sparc64)
120     long cr_ref;
121 #else
122     int cr_ref;
123 #endif
124     uid_t cr_uid;               /* euid */
125     uid_t cr_ruid;              /* uid */
126     gid_t cr_gid;               /* egid */
127     gid_t cr_rgid;              /* gid */
128     gid_t cr_groups[NGROUPS];   /* 32 groups - empty set to NOGROUP */
129     int cr_ngroups;
130 } cred_t;
131 #define AFS_UCRED cred
132 #define AFS_PROC struct task_struct
133 #define crhold(c) (c)->cr_ref++
134
135 /* UIO manipulation */
136 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
137 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
138 typedef struct uio {
139     struct iovec *uio_iov;
140     int uio_iovcnt;
141     afs_offs_t uio_offset;
142     uio_seg_t uio_seg;
143     int uio_resid;
144     uio_flag_t uio_flag;
145 } uio_t;
146 #define afsio_iov       uio_iov
147 #define afsio_iovcnt    uio_iovcnt
148 #define afsio_offset    uio_offset
149 #define afsio_seg       uio_segflg
150 #define afsio_fmode     uio_fmode
151 #define afsio_resid     uio_resid
152
153 /* Get/set the inode in the osifile struct. */
154 #define FILE_INODE(F) (F)->f_dentry->d_inode
155
156
157 /* page offset is obtained and stored here during module initialization 
158  * We need a variable to do this because, the PAGE_OFFSET macro defined in
159  * include/asm/page.h can change from kernel to kernel and we cannot use
160  * the hardcoded version.
161  */
162 extern unsigned long afs_linux_page_offset;
163
164 /* some more functions to help with the page offset stuff */
165 #define AFS_LINUX_MAP_NR(addr) ((((unsigned long)addr) - afs_linux_page_offset)  >> PAGE_SHIFT)
166
167 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
168
169 #if defined(__KERNEL__) && defined(CONFIG_SMP)
170 #include "../h/sched.h"
171 #include "linux/wait.h"
172
173 extern struct semaphore afs_global_lock;
174 extern int afs_global_owner;
175
176 #define AFS_GLOCK() \
177 do { \
178          down(&afs_global_lock); \
179          if (afs_global_owner) \
180              osi_Panic("afs_global_lock already held by pid %d", \
181                        afs_global_owner); \
182          afs_global_owner = current->pid; \
183 } while (0)
184
185 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
186
187 #define AFS_GUNLOCK() \
188 do { \
189     if (!ISAFS_GLOCK()) \
190         osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \
191     afs_global_owner = 0; \
192     up(&afs_global_lock); \
193 } while (0)
194
195
196 #else
197 #define AFS_GLOCK()
198 #define AFS_GUNLOCK()
199 #define ISAFS_GLOCK() 1
200 #define AFS_ASSERT_GLOCK()
201 #define AFS_ASSERT_RXGLOCK()
202 #endif
203
204 #define AFS_RXGLOCK()
205 #define AFS_RXGUNLOCK()
206 #define ISAFS_RXGLOCK() 1
207 #endif /* OSI_MACHDEP_H_ */