OpenAFS
OpenAFS distributed network file system
|
00001 /* 00002 * Copyright 2000, International Business Machines Corporation and others. 00003 * All Rights Reserved. 00004 * 00005 * This software has been released under the terms of the IBM Public 00006 * License. For details, see the LICENSE file in the top-level source 00007 * directory or online at http://www.openafs.org/dl/license10.html 00008 */ 00009 00010 /* 00011 * Linux implementation. 00012 * 00013 */ 00014 00015 #ifndef OSI_MACHDEP_H_ 00016 #define OSI_MACHDEP_H_ 00017 00018 #include <linux/version.h> 00019 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4) 00020 # define AFS_LINUX26_ONEGROUP_ENV 1 00021 #endif 00022 00023 /* Only needed for xdr.h in glibc 2.1.x */ 00024 #ifndef quad_t 00025 # define quad_t __quad_t 00026 # define u_quad_t __u_quad_t 00027 #endif 00028 00029 #undef getuerror 00030 00031 #ifdef STRUCT_TASK_STRUCT_HAS_TGID 00032 # define getpid() current->tgid 00033 # ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT 00034 # define getppid() current->real_parent->tgid 00035 # elif defined(STRUCT_TASK_STRUCT_HAS_PARENT) 00036 # define getppid() current->parent->tgid 00037 # else 00038 # define getppid() current->p_opptr->tgid 00039 # endif 00040 #else /* !STRUCT_TASK_STRUCT_HAS_TGID */ 00041 # define getpid() current->pid 00042 # ifdef STRUCT_TASK_STRUCT_HAS_REAL_PARENT 00043 # define getppid() current->real_parent->pid 00044 # elif defined(STRUCT_TASK_STRUCT_HAS_PARENT) 00045 # define getppid() current->parent->pid 00046 # else 00047 # define getppid() current->p_opptr->pid 00048 # endif 00049 #endif /* STRUCT_TASK_STRUCT_HAS_TGID */ 00050 00051 #ifdef RECALC_SIGPENDING_TAKES_VOID 00052 # define RECALC_SIGPENDING(X) recalc_sigpending() 00053 #else 00054 # define RECALC_SIGPENDING(X) recalc_sigpending(X) 00055 #endif 00056 00057 #if defined (STRUCT_TASK_STRUCT_HAS_SIGMASK_LOCK) 00058 # define SIG_LOCK(X) spin_lock_irq(&X->sigmask_lock) 00059 # define SIG_UNLOCK(X) spin_unlock_irq(&X->sigmask_lock) 00060 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGHAND) 00061 # define SIG_LOCK(X) spin_lock_irq(&X->sighand->siglock) 00062 # define SIG_UNLOCK(X) spin_unlock_irq(&X->sighand->siglock) 00063 #else 00064 # define SIG_LOCK(X) spin_lock_irq(&X->sig->siglock) 00065 # define SIG_UNLOCK(X) spin_unlock_irq(&X->sig->siglock) 00066 #endif 00067 00068 #if defined (STRUCT_TASK_STRUCT_HAS_RLIM) 00069 # define TASK_STRUCT_RLIM rlim 00070 #elif defined (STRUCT_TASK_STRUCT_HAS_SIGNAL_RLIM) 00071 # define TASK_STRUCT_RLIM signal->rlim 00072 #else 00073 # error Not sure what to do about rlim (should be in the Linux task struct somewhere....) 00074 #endif 00075 00076 00077 #define afs_hz HZ 00078 #include "h/sched.h" 00079 #if defined(HAVE_LINUX_CURRENT_KERNEL_TIME) 00080 static inline time_t osi_Time(void) { 00081 struct timespec xtime; 00082 xtime = current_kernel_time(); 00083 return xtime.tv_sec; 00084 } 00085 #else 00086 # define osi_Time() (xtime.tv_sec) 00087 #endif 00088 00089 00090 00091 #ifdef AFS_LINUX_64BIT_KERNEL 00092 # define osi_GetTime(V) \ 00093 do { \ 00094 struct timeval __afs_tv; \ 00095 do_gettimeofday(&__afs_tv); \ 00096 (V)->tv_sec = (afs_int32)__afs_tv.tv_sec; \ 00097 (V)->tv_usec = (afs_int32)__afs_tv.tv_usec; \ 00098 } while (0) 00099 #else 00100 # define osi_GetTime(V) do_gettimeofday((V)) 00101 #endif 00102 00103 #undef gop_lookupname 00104 #define gop_lookupname osi_lookupname 00105 00106 #undef gop_lookupname_user 00107 #define gop_lookupname_user osi_lookupname 00108 00109 #define osi_vnhold(V, N) do { VN_HOLD(AFSTOV(V)); } while (0) 00110 #define VN_HOLD(V) osi_Assert(igrab((V)) == (V)) 00111 #define VN_RELE(V) iput((V)) 00112 00113 #define afs_suser(x) capable(CAP_SYS_ADMIN) 00114 #define wakeup afs_osi_Wakeup 00115 00116 #define vType(V) ((AFSTOV((V)))->i_mode & S_IFMT) 00117 #define vSetType(V, type) AFSTOV((V))->i_mode = ((type) | (AFSTOV((V))->i_mode & ~S_IFMT)) /* preserve mode */ 00118 #define vSetVfsp(V, vfsp) /* unused */ 00119 #define IsAfsVnode(V) ((V)->i_sb == afs_globalVFS) /* test superblock instead */ 00120 #define SetAfsVnode(V) /* unnecessary */ 00121 00122 #include <asm/uaccess.h> 00123 00124 #define copyin(F, T, C) (copy_from_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0) 00125 static inline long copyinstr(char *from, char *to, int count, int *length) { 00126 long tmp; 00127 tmp = strncpy_from_user(to, from, count); 00128 if (tmp < 0) 00129 return EFAULT; 00130 *length = tmp; 00131 return 0; 00132 } 00133 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)) > 0 ? EFAULT : 0) 00134 00135 /* kernel print statements */ 00136 #define printf printk 00137 #define uprintf printk 00138 00139 00140 #ifndef NGROUPS 00141 #define NGROUPS NGROUPS_SMALL 00142 #endif 00143 00144 typedef struct task_struct afs_proc_t; 00145 00146 /* Credentials. For newer kernels we use the kernel structure directly. */ 00147 #if defined(STRUCT_TASK_STRUCT_HAS_CRED) 00148 00149 typedef struct cred afs_ucred_t; 00150 typedef struct cred cred_t; 00151 00152 # define afs_cr_uid(cred) ((cred)->fsuid) 00153 # define afs_cr_gid(cred) ((cred)->fsgid) 00154 # define afs_cr_ruid(cred) ((cred)->uid) 00155 # define afs_cr_rgid(cred) ((cred)->gid) 00156 # define afs_cr_group_info(cred) ((cred)->group_info) 00157 # define crhold(c) (get_cred(c)) 00158 static inline void 00159 afs_set_cr_uid(cred_t *cred, uid_t uid) { 00160 cred->fsuid = uid; 00161 } 00162 static inline void 00163 afs_set_cr_gid(cred_t *cred, gid_t gid) { 00164 cred->fsgid = gid; 00165 } 00166 static inline void 00167 afs_set_cr_ruid(cred_t *cred, uid_t uid) { 00168 cred->uid = uid; 00169 } 00170 static inline void 00171 afs_set_cr_rgid(cred_t *cred, gid_t gid) { 00172 cred->gid = gid; 00173 } 00174 static inline void 00175 afs_set_cr_group_info(cred_t *cred, struct group_info *group_info) { 00176 cred->group_info = group_info; 00177 } 00178 00179 # define current_group_info() (current->cred->group_info) 00180 # define task_gid(task) (task->cred->gid) 00181 # define task_user(task) (task->cred->user) 00182 # define task_session_keyring(task) (task->cred->tgcred->session_keyring) 00183 # define current_session_keyring() (current->cred->tgcred->session_keyring) 00184 00185 #else 00186 00187 typedef struct afs_cred { 00188 atomic_t cr_ref; 00189 uid_t cr_uid; 00190 uid_t cr_ruid; 00191 gid_t cr_gid; 00192 gid_t cr_rgid; 00193 struct group_info *cr_group_info; 00194 } cred_t; 00195 00196 typedef struct afs_cred afs_ucred_t; 00197 # define afs_cr_group_info(cred) ((cred)->cr_group_info) 00198 static inline void 00199 afs_set_cr_group_info(cred_t *cred, struct group_info *group_info) { 00200 cred->cr_group_info = group_info; 00201 } 00202 00203 # define current_group_info() (current->group_info) 00204 # if !defined(task_gid) 00205 # define task_gid(task) (task->gid) 00206 # endif 00207 # if !defined(task_uid) 00208 # define task_uid(task) (task->uid) 00209 # endif 00210 # define task_user(task) (task->user) 00211 # define task_session_keyring(task) (task->signal->session_keyring) 00212 # define current_session_keyring() (current->signal->session_keyring) 00213 # define crhold(c) atomic_inc(&(c)->cr_ref) 00214 00215 #endif /* defined(STRUCT_TASK_STRUCT_HAS_CRED) */ 00216 00217 #if !defined(current_cred) 00218 # define current_gid() (current->gid) 00219 # define current_uid() (current->uid) 00220 # define current_fsgid() (current->fsgid) 00221 # define current_fsuid() (current->fsuid) 00222 #endif 00223 00224 /* UIO manipulation */ 00225 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t; 00226 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t; 00227 struct uio { 00228 struct iovec *uio_iov; 00229 int uio_iovcnt; 00230 afs_offs_t uio_offset; 00231 uio_seg_t uio_seg; 00232 int uio_resid; 00233 uio_flag_t uio_flag; 00234 }; 00235 #define afsio_iov uio_iov 00236 #define afsio_iovcnt uio_iovcnt 00237 #define afsio_offset uio_offset 00238 #define afsio_seg uio_segflg 00239 #define afsio_fmode uio_fmode 00240 #define afsio_resid uio_resid 00241 00242 /* Get/set the inode in the osifile struct. */ 00243 #define FILE_INODE(F) (F)->f_dentry->d_inode 00244 00245 #define OSIFILE_INODE(a) FILE_INODE((a)->filp) 00246 00247 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) 00248 # define NEED_IOCTL32 00249 #endif 00250 00251 #include <linux/version.h> 00252 #include <linux/sched.h> 00253 #include <linux/wait.h> 00254 00255 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) 00256 extern struct mutex afs_global_lock; 00257 #else 00258 extern struct semaphore afs_global_lock; 00259 # define mutex_lock(lock) down(lock) 00260 # define mutex_unlock(lock) up(lock) 00261 #endif 00262 extern int afs_global_owner; 00263 00264 #define AFS_GLOCK() \ 00265 do { \ 00266 mutex_lock(&afs_global_lock); \ 00267 if (afs_global_owner) \ 00268 osi_Panic("afs_global_lock already held by pid %d", \ 00269 afs_global_owner); \ 00270 afs_global_owner = current->pid; \ 00271 } while (0) 00272 00273 #define ISAFS_GLOCK() (afs_global_owner == current->pid) 00274 00275 #define AFS_GUNLOCK() \ 00276 do { \ 00277 if (!ISAFS_GLOCK()) \ 00278 osi_Panic("afs global lock not held at %s:%d", __FILE__, __LINE__); \ 00279 afs_global_owner = 0; \ 00280 mutex_unlock(&afs_global_lock); \ 00281 } while (0) 00282 00283 #define osi_InitGlock() 00284 00285 #ifdef AFS_AMD64_LINUX20_ENV 00286 /* RHEL5 beta's kernel doesn't define these. They aren't gonna change, so... */ 00287 00288 # ifndef __NR_ia32_afs_syscall 00289 # define __NR_ia32_afs_syscall 137 00290 # endif 00291 # ifndef __NR_ia32_setgroups 00292 # define __NR_ia32_setgroups 81 00293 # endif 00294 # ifndef __NR_ia32_setgroups32 00295 # define __NR_ia32_setgroups32 206 00296 # endif 00297 # ifndef __NR_ia32_close 00298 # define __NR_ia32_close 6 00299 # endif 00300 # ifndef __NR_ia32_chdir 00301 # define __NR_ia32_chdir 12 00302 # endif 00303 # ifndef __NR_ia32_break 00304 # define __NR_ia32_break 17 00305 # endif 00306 # ifndef __NR_ia32_stty 00307 # define __NR_ia32_stty 31 00308 # endif 00309 # ifndef __NR_ia32_gtty 00310 # define __NR_ia32_gtty 32 00311 # endif 00312 # ifndef __NR_ia32_ftime 00313 # define __NR_ia32_ftime 35 00314 # endif 00315 # ifndef __NR_ia32_prof 00316 # define __NR_ia32_prof 44 00317 # endif 00318 # ifndef __NR_ia32_lock 00319 # define __NR_ia32_lock 53 00320 # endif 00321 # ifndef __NR_ia32_mpx 00322 # define __NR_ia32_mpx 56 00323 # endif 00324 # ifndef __NR_ia32_exit 00325 # define __NR_ia32_exit 1 00326 # endif 00327 # ifndef __NR_ia32_mount 00328 # define __NR_ia32_mount 21 00329 # endif 00330 # ifndef __NR_ia32_read 00331 # define __NR_ia32_read 3 00332 # endif 00333 # ifndef __NR_ia32_write 00334 # define __NR_ia32_write 4 00335 # endif 00336 # ifndef __NR_ia32_open 00337 # define __NR_ia32_open 5 00338 # endif 00339 # ifndef __NR_ia32_close 00340 # define __NR_ia32_close 6 00341 # endif 00342 # ifndef __NR_ia32_unlink 00343 # define __NR_ia32_unlink 10 00344 # endif 00345 #endif 00346 00347 #define osi_procname(procname, size) strncpy(procname, current->comm, size) 00348 00349 #endif /* OSI_MACHDEP_H_ */