1 /* Copyright 1998 Transarc Corporation - All Rights Reserved.
5 * Linux implementation.
10 #define OSI_MACHDEP_H_
12 /* Only needed for xdr.h in glibc 2.1.x */
14 #define quad_t __quad_t
15 #define u_quad_t __u_quad_t
20 #define getpid() current->pid
21 #define getppid() current->p_opptr->pid
25 #include "../h/sched.h"
26 #define osi_Time() (xtime.tv_sec)
27 #define osi_GetTime(V) (*(V)=xtime)
30 #define gop_lookupname osi_lookupname
32 #define osi_vnhold(v, n) VN_HOLD(v)
34 #define osi_AllocSmall afs_osi_Alloc
35 #define osi_FreeSmall afs_osi_Free
37 #define afs_suser suser
38 #define wakeup afs_osi_Wakeup
41 #define vType(V) ((( vnode_t *)V)->v_type & S_IFMT)
43 /* IsAfsVnode relies on the fast that there is only one vnodeop table for AFS.
44 * Use the same type of test as other OS's for compatibility.
47 extern struct vnodeops afs_dir_iops, afs_symlink_iops;
48 #define IsAfsVnode(vc) (((vc)->v_op == afs_ops) ? 1 : \
49 ((vc)->v_op == &afs_dir_iops) ? 1 : \
50 ((vc)->v_op == &afs_symlink_iops))
52 /* bcopy is in stds.h, just so fcrpyt.c can pick it up. */
53 #define bzero(D,C) memset((D), 0, (C))
54 #define bcmp(A,B,C) memcmp((A), (B), (C))
56 /* We often need to pretend we're in user space to get memory transfers
57 * right for the kernel calls we use.
59 #ifdef KERNEL_SPACE_DECL
60 #undef KERNEL_SPACE_DECL
62 #undef TO_KERNEL_SPACE
64 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl
65 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
66 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
68 /* Backwards compatibilty macros - copyin/copyout are redone because macro
69 * inside parentheses is not evalutated.
71 #define memcpy_fromfs copy_from_user
72 #define memcpy_tofs copy_to_user
73 #define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)), 0)
74 #define copyinstr(F, T, C, L) (copyin(F, T, C), *(L)=strlen(T), 0)
75 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)), 0)
77 /* kernel print statements */
79 #define uprintf printk
82 #define PAGESIZE PAGE_SIZE
85 typedef struct cred { /* maps to task field: */
87 unsigned short cr_uid; /* euid */
88 unsigned short cr_ruid; /* uid */
89 unsigned short cr_gid; /* egid */
90 unsigned short cr_rgid; /* gid */
91 gid_t cr_groups[NGROUPS]; /* 32 groups - empty set to NOGROUP */
94 #define AFS_UCRED cred
95 #define crhold(c) (c)->cr_ref++
97 /* UIO manipulation */
98 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
99 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
101 struct iovec *uio_iov;
108 #define afsio_iov uio_iov
109 #define afsio_iovcnt uio_iovcnt
110 #define afsio_offset uio_offset
111 #define afsio_seg uio_segflg
112 #define afsio_fmode uio_fmode
113 #define afsio_resid uio_resid
115 /* Get/set the inode in the osifile struct. */
116 #define FILE_INODE(F) (F)->f_dentry->d_inode
119 /* page offset is obtained and stored here during module initialization
120 * We need a variable to do this because, the PAGE_OFFSET macro defined in
121 * include/asm/page.h can change from kernel to kernel and we cannot use
122 * the hardcoded version.
124 extern unsigned long afs_linux_page_offset;
126 /* some more functions to help with the page offset stuff */
127 #define AFS_LINUX_MAP_NR(addr) ((((unsigned long)addr) - afs_linux_page_offset) >> PAGE_SHIFT)
129 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
131 #if defined(__KERNEL__) && defined(CONFIG_SMP)
132 #include "linux/wait.h"
134 extern struct semaphore afs_global_lock;
135 extern int afs_global_owner;
137 #define AFS_GLOCK() \
139 down(&afs_global_lock); \
140 if (afs_global_owner) \
141 osi_Panic("afs_global_lock already held by pid %d", \
143 afs_global_owner = current->pid; \
146 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
148 #define AFS_GUNLOCK() \
150 if (!ISAFS_GLOCK()) \
151 osi_Panic("afs global lock not held"); \
152 afs_global_owner = 0; \
153 up(&afs_global_lock); \
159 #define AFS_GUNLOCK()
160 #define ISAFS_GLOCK() 1
161 #define AFS_ASSERT_GLOCK()
162 #define AFS_ASSERT_RXGLOCK()
165 #define AFS_RXGLOCK()
166 #define AFS_RXGUNLOCK()
167 #define ISAFS_RXGLOCK() 1
168 #endif /* OSI_MACHDEP_H_ */