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 #define getppid() current->p_opptr->pid
31 #include "../h/sched.h"
32 #define osi_Time() (xtime.tv_sec)
33 #define osi_GetTime(V) (*(V)=xtime)
36 #define gop_lookupname osi_lookupname
38 #define osi_vnhold(v, n) VN_HOLD(v)
40 #define osi_AllocSmall afs_osi_Alloc
41 #define osi_FreeSmall afs_osi_Free
43 #define afs_suser suser
44 #define wakeup afs_osi_Wakeup
47 #define vType(V) ((( vnode_t *)V)->v_type & S_IFMT)
49 /* IsAfsVnode relies on the fast that there is only one vnodeop table for AFS.
50 * Use the same type of test as other OS's for compatibility.
53 extern struct vnodeops afs_dir_iops, afs_symlink_iops;
54 #define IsAfsVnode(vc) (((vc)->v_op == afs_ops) ? 1 : \
55 ((vc)->v_op == &afs_dir_iops) ? 1 : \
56 ((vc)->v_op == &afs_symlink_iops))
58 /* bcopy is in stds.h, just so fcrpyt.c can pick it up. */
59 #define bzero(D,C) memset((D), 0, (C))
60 #define bcmp(A,B,C) memcmp((A), (B), (C))
62 /* We often need to pretend we're in user space to get memory transfers
63 * right for the kernel calls we use.
65 #ifdef KERNEL_SPACE_DECL
66 #undef KERNEL_SPACE_DECL
68 #undef TO_KERNEL_SPACE
70 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl
71 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
72 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
74 /* Backwards compatibilty macros - copyin/copyout are redone because macro
75 * inside parentheses is not evalutated.
77 #define memcpy_fromfs copy_from_user
78 #define memcpy_tofs copy_to_user
79 #define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)), 0)
80 #define copyinstr(F, T, C, L) (copyin(F, T, C), *(L)=strlen(T), 0)
81 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)), 0)
83 /* kernel print statements */
85 #define uprintf printk
88 #define PAGESIZE PAGE_SIZE
91 typedef struct cred { /* maps to task field: */
93 unsigned short cr_uid; /* euid */
94 unsigned short cr_ruid; /* uid */
95 unsigned short cr_gid; /* egid */
96 unsigned short cr_rgid; /* gid */
97 gid_t cr_groups[NGROUPS]; /* 32 groups - empty set to NOGROUP */
100 #define AFS_UCRED cred
101 #define crhold(c) (c)->cr_ref++
103 /* UIO manipulation */
104 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
105 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
107 struct iovec *uio_iov;
114 #define afsio_iov uio_iov
115 #define afsio_iovcnt uio_iovcnt
116 #define afsio_offset uio_offset
117 #define afsio_seg uio_segflg
118 #define afsio_fmode uio_fmode
119 #define afsio_resid uio_resid
121 /* Get/set the inode in the osifile struct. */
122 #define FILE_INODE(F) (F)->f_dentry->d_inode
125 /* page offset is obtained and stored here during module initialization
126 * We need a variable to do this because, the PAGE_OFFSET macro defined in
127 * include/asm/page.h can change from kernel to kernel and we cannot use
128 * the hardcoded version.
130 extern unsigned long afs_linux_page_offset;
132 /* some more functions to help with the page offset stuff */
133 #define AFS_LINUX_MAP_NR(addr) ((((unsigned long)addr) - afs_linux_page_offset) >> PAGE_SHIFT)
135 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
137 #if defined(__KERNEL__) && defined(CONFIG_SMP)
138 #include "linux/wait.h"
140 extern struct semaphore afs_global_lock;
141 extern int afs_global_owner;
143 #define AFS_GLOCK() \
145 down(&afs_global_lock); \
146 if (afs_global_owner) \
147 osi_Panic("afs_global_lock already held by pid %d", \
149 afs_global_owner = current->pid; \
152 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
154 #define AFS_GUNLOCK() \
156 if (!ISAFS_GLOCK()) \
157 osi_Panic("afs global lock not held"); \
158 afs_global_owner = 0; \
159 up(&afs_global_lock); \
165 #define AFS_GUNLOCK()
166 #define ISAFS_GLOCK() 1
167 #define AFS_ASSERT_GLOCK()
168 #define AFS_ASSERT_RXGLOCK()
171 #define AFS_RXGLOCK()
172 #define AFS_RXGUNLOCK()
173 #define ISAFS_RXGLOCK() 1
174 #endif /* OSI_MACHDEP_H_ */