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 "afs/afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h" /* afs statistics */
19 int afs_osicred_initialized;
20 afs_ucred_t afs_osi_cred;
21 afs_lock_t afs_xosi; /* lock is for tvattr */
22 extern struct osi_dev cacheDev;
23 extern struct mount *afs_cacheVfsp;
27 osi_UFSOpen(afs_dcache_id_t *ainode)
29 struct osi_file *afile;
31 extern int cacheDiskType;
34 AFS_STATCNT(osi_UFSOpen);
35 if (cacheDiskType != AFS_FCACHE_TYPE_UFS)
36 osi_Panic("UFSOpen called for non-UFS cache\n");
37 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
39 code = VFS_VGET(cacheDev.mp, ainode->ufs, &vp);
41 if (code == 0 && vp->v_type == VNON)
44 osi_FreeSmallSpace(afile);
45 osi_Panic("UFSOpen: igetinode failed");
47 VOP_UNLOCK(vp, 0, curproc);
50 afile->size = VTOI(vp)->i_ffs1_size;
52 afile->size = VTOI(vp)->i_ffs_size;
60 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
65 AFS_STATCNT(osi_Stat);
66 ObtainWriteLock(&afs_xosi, 320);
68 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
71 astat->size = afile->size = tvattr.va_size;
72 astat->mtime = tvattr.va_mtime.tv_sec;
73 astat->atime = tvattr.va_atime.tv_sec;
75 ReleaseWriteLock(&afs_xosi);
80 osi_UFSClose(struct osi_file *afile)
82 AFS_STATCNT(osi_Close);
85 AFS_RELE(afile->vnode);
87 osi_FreeSmallSpace(afile);
92 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
96 struct osi_stat tstat;
98 AFS_STATCNT(osi_Truncate);
101 * This routine only shrinks files, and most systems
102 * have very slow truncates, even when the file is already
103 * small enough. Check now and save some time.
105 code = afs_osi_Stat(afile, &tstat);
106 if (code || tstat.size <= asize)
109 ObtainWriteLock(&afs_xosi, 321);
111 tvattr.va_size = asize;
113 VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curproc);
114 code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
115 VOP_UNLOCK(afile->vnode, 0, curproc);
119 ReleaseWriteLock(&afs_xosi);
124 osi_DisableAtimes(struct vnode *avp)
127 VTOI(avp)->i_flag &= ~IN_ACCESS;
132 /* Generic read interface */
134 afs_osi_Read(struct osi_file *afile, int offset, void *aptr, afs_int32 asize)
139 AFS_STATCNT(osi_Read);
142 * If the osi_file passed in is NULL, panic only if AFS is not shutting
143 * down. No point in crashing when we are already shutting down
146 if (!afs_shuttingdown)
147 osi_Panic("osi_Read called with null param");
153 afile->offset = offset;
156 vn_rdwr(UIO_READ, afile->vnode, aptr, asize, afile->offset,
157 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, curproc);
160 code = asize - resid;
161 afile->offset += code;
162 osi_DisableAtimes(afile->vnode);
164 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32,
165 (unsigned int) resid, ICL_TYPE_INT32, code);
171 /* Generic write interface */
173 afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
179 AFS_STATCNT(osi_Write);
181 osi_Panic("afs_osi_Write called with null afile");
183 afile->offset = offset;
186 VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curproc);
188 vn_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
189 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, curproc);
190 VOP_UNLOCK(afile->vnode, 0, curproc);
194 code = asize - resid;
195 afile->offset += code;
196 if (afile->offset > afile->size)
197 afile->size = afile->offset;
202 (*afile->proc) (afile, code);
208 * This work should be handled by physstrat in ca/machdep.c. This routine
209 * written from the RT NFS port strategy routine. It has been generalized a
210 * bit, but should still be pretty clear.
213 afs_osi_MapStrategy(int (*aproc) (), struct buf *bp)
215 afs_int32 returnCode;
217 AFS_STATCNT(osi_MapStrategy);
218 returnCode = (*aproc) (bp);
224 shutdown_osifile(void)
226 AFS_STATCNT(shutdown_osifile);
227 if (afs_cold_shutdown)
228 afs_osicred_initialized = 0;