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
10 #include <afsconfig.h>
11 #include "afs/param.h"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
17 #include "afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h" /* afs statistics */
21 int afs_osicred_initialized = 0;
22 struct AFS_UCRED afs_osi_cred;
23 afs_lock_t afs_xosi; /* lock is for tvattr */
24 extern struct osi_dev cacheDev;
25 extern struct mount *afs_cacheVfsp;
29 osi_UFSOpen(afs_int32 ainode)
31 struct osi_file *afile;
33 extern int cacheDiskType;
36 AFS_STATCNT(osi_UFSOpen);
37 if (cacheDiskType != AFS_FCACHE_TYPE_UFS)
38 osi_Panic("UFSOpen called for non-UFS cache\n");
39 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
41 #if defined(AFS_FBSD50_ENV)
42 code = VFS_VGET(afs_cacheVfsp, (ino_t) ainode, LK_EXCLUSIVE, &vp);
44 code = VFS_VGET(afs_cacheVfsp, (ino_t) ainode, &vp);
47 if (code == 0 && vp->v_type == VNON)
50 osi_FreeSmallSpace(afile);
51 osi_Panic("UFSOpen: igetinode failed");
53 #if defined(AFS_FBSD50_ENV)
54 VOP_UNLOCK(vp, 0, curthread);
56 VOP_UNLOCK(vp, 0, curproc);
59 afile->size = VTOI(vp)->i_size;
62 afile->inum = ainode; /* for hint validity checking */
67 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
69 register afs_int32 code;
71 AFS_STATCNT(osi_Stat);
72 MObtainWriteLock(&afs_xosi, 320);
74 #if defined(AFS_FBSD50_ENV)
75 vn_lock(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curthread);
76 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread);
77 VOP_UNLOCK(afile->vnode, LK_EXCLUSIVE, curthread);
79 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
83 astat->size = tvattr.va_size;
84 astat->mtime = tvattr.va_mtime.tv_sec;
85 astat->atime = tvattr.va_atime.tv_sec;
87 MReleaseWriteLock(&afs_xosi);
92 osi_UFSClose(register struct osi_file *afile)
94 AFS_STATCNT(osi_Close);
96 AFS_RELE(afile->vnode);
99 osi_FreeSmallSpace(afile);
104 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
108 register afs_int32 code;
109 AFS_STATCNT(osi_Truncate);
111 MObtainWriteLock(&afs_xosi, 321);
114 * This routine only shrinks files, and most systems
115 * have very slow truncates, even when the file is already
116 * small enough. Check now and save some time.
119 #if defined(AFS_FBSD50_ENV)
120 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
121 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread);
123 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
124 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
126 if (code != 0 || tvattr.va_size <= asize)
130 tvattr.va_size = asize;
131 #if defined(AFS_FBSD50_ENV)
132 code = VOP_SETATTR(vp, &tvattr, afs_osi_credp, curthread);
134 code = VOP_SETATTR(vp, &tvattr, afs_osi_credp, curproc);
138 #if defined(AFS_FBSD50_ENV)
139 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
141 VOP_UNLOCK(vp, LK_EXCLUSIVE, curproc);
144 MReleaseWriteLock(&afs_xosi);
149 osi_DisableAtimes(struct vnode *avp)
151 struct inode *ip = VTOI(avp);
152 ip->i_flag &= ~IN_ACCESS;
156 /* Generic read interface */
158 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
162 register afs_int32 code;
163 AFS_STATCNT(osi_Read);
166 * If the osi_file passed in is NULL, panic only if AFS is not shutting
167 * down. No point in crashing when we are already shutting down
170 if (!afs_shuttingdown)
171 osi_Panic("osi_Read called with null param");
177 afile->offset = offset;
180 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
181 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid);
184 code = asize - resid;
185 afile->offset += code;
186 osi_DisableAtimes(afile->vnode);
188 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
189 ICL_TYPE_INT32, code);
195 /* Generic write interface */
197 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
201 register afs_int32 code;
202 AFS_STATCNT(osi_Write);
204 osi_Panic("afs_osi_Write called with null param");
206 afile->offset = offset;
210 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
211 afile->offset, AFS_UIOSYS, IO_UNIT, afs_osi_credp,
216 code = asize - resid;
217 afile->offset += code;
222 (*afile->proc) (afile, code);
228 /* This work should be handled by physstrat in ca/machdep.c.
229 This routine written from the RT NFS port strategy routine.
230 It has been generalized a bit, but should still be pretty clear. */
232 afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
234 afs_int32 returnCode;
236 AFS_STATCNT(osi_MapStrategy);
237 returnCode = (*aproc) (bp);
245 shutdown_osifile(void)
247 extern int afs_cold_shutdown;
249 AFS_STATCNT(shutdown_osifile);
250 if (afs_cold_shutdown) {
251 afs_osicred_initialized = 0;