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"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
15 #include "afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h" /* afs statistics */
19 int afs_osicred_initialized = 0;
20 #ifndef AFS_FBSD80_ENV /* cr_groups is now malloc()'d */
21 afs_ucred_t 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_dcache_id_t *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 code = VFS_VGET(afs_cacheVfsp, (ino_t) ainode->ufs, LK_EXCLUSIVE, &vp);
43 if (code == 0 && vp->v_type == VNON)
46 osi_FreeSmallSpace(afile);
47 osi_Panic("UFSOpen: igetinode failed");
49 #if defined(AFS_FBSD80_ENV)
52 VOP_UNLOCK(vp, 0, curthread);
55 afile->size = VTOI(vp)->i_size;
62 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
66 AFS_STATCNT(osi_Stat);
67 ObtainWriteLock(&afs_xosi, 320);
69 #if defined(AFS_FBSD80_ENV)
70 vn_lock(afile->vnode, LK_EXCLUSIVE | LK_RETRY);
71 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp);
72 VOP_UNLOCK(afile->vnode, 0);
74 vn_lock(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curthread);
75 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread);
76 VOP_UNLOCK(afile->vnode, LK_EXCLUSIVE, curthread);
80 astat->size = tvattr.va_size;
81 astat->mtime = tvattr.va_mtime.tv_sec;
82 astat->atime = tvattr.va_atime.tv_sec;
84 ReleaseWriteLock(&afs_xosi);
89 osi_UFSClose(struct osi_file *afile)
91 AFS_STATCNT(osi_Close);
93 AFS_RELE(afile->vnode);
96 osi_FreeSmallSpace(afile);
101 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
105 afs_int32 code, glocked;
106 AFS_STATCNT(osi_Truncate);
108 ObtainWriteLock(&afs_xosi, 321);
111 * This routine only shrinks files, and most systems
112 * have very slow truncates, even when the file is already
113 * small enough. Check now and save some time.
115 glocked = ISAFS_GLOCK();
118 #if defined(AFS_FBSD80_ENV)
119 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
120 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp);
122 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
123 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread);
125 if (code != 0 || tvattr.va_size <= asize)
129 tvattr.va_size = asize;
130 #if defined(AFS_FBSD80_ENV)
131 code = VOP_SETATTR(vp, &tvattr, afs_osi_credp);
133 code = VOP_SETATTR(vp, &tvattr, afs_osi_credp, curthread);
137 #if defined(AFS_FBSD80_ENV)
140 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
144 ReleaseWriteLock(&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(struct osi_file *afile, int offset, void *aptr,
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(struct osi_file *afile, afs_int32 offset, void *aptr,
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) (), struct buf *bp)
234 afs_int32 returnCode;
236 AFS_STATCNT(osi_MapStrategy);
237 returnCode = (*aproc) (bp);
245 shutdown_osifile(void)
247 AFS_STATCNT(shutdown_osifile);
248 if (afs_cold_shutdown) {
249 afs_osicred_initialized = 0;