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"
13 #include "afs/sysincludes.h" /* Standard vendor system headers */
14 #include "afs/afsincludes.h" /* Afs-based standard headers */
15 #include "afs/afs_stats.h" /* afs statistics */
18 int afs_osicred_initialized;
19 extern struct osi_dev cacheDev;
20 extern struct mount *afs_cacheVfsp;
23 osi_UFSOpen(afs_dcache_id_t *ainode)
25 struct osi_file *afile;
27 extern int cacheDiskType;
30 AFS_STATCNT(osi_UFSOpen);
31 if (cacheDiskType != AFS_FCACHE_TYPE_UFS)
32 osi_Panic("UFSOpen called for non-UFS cache\n");
33 afile = osi_AllocSmallSpace(sizeof(struct osi_file));
35 code = VFS_VGET(cacheDev.mp, (ino_t) ainode->ufs, &vp);
37 if (code == 0 && vp->v_type == VNON)
40 osi_FreeSmallSpace(afile);
41 osi_Panic("UFSOpen: igetinode failed");
43 #if defined(AFS_NBSD60_ENV)
49 afile->size = VTOI(vp)->i_ffs1_size;
56 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
61 AFS_STATCNT(osi_Stat);
64 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp);
66 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp,
71 astat->size = afile->size = tvattr.va_size;
72 astat->mtime = tvattr.va_mtime.tv_sec;
73 astat->atime = tvattr.va_atime.tv_sec;
79 osi_UFSClose(struct osi_file *afile)
81 AFS_STATCNT(osi_Close);
84 AFS_RELE(afile->vnode);
86 osi_FreeSmallSpace(afile);
91 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
95 struct osi_stat tstat;
97 AFS_STATCNT(osi_Truncate);
100 * This routine only shrinks files, and most systems
101 * have very slow truncates, even when the file is already
102 * small enough. Check now and save some time.
104 code = afs_osi_Stat(afile, &tstat);
105 if (code || tstat.size <= asize)
109 tvattr.va_size = asize;
111 VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY);
112 #ifdef AFS_NBSD50_ENV
113 code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp);
115 code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp,
118 #ifdef AFS_NBSD60_ENV
119 VOP_UNLOCK(afile->vnode);
121 VOP_UNLOCK(afile->vnode, 0);
130 osi_DisableAtimes(struct vnode *avp)
135 /* Generic read interface */
137 afs_osi_Read(struct osi_file *afile, int offset, void *aptr, afs_int32 asize)
142 AFS_STATCNT(osi_Read);
145 * If the osi_file passed in is NULL, panic only if AFS is not shutting
146 * down. No point in crashing when we are already shutting down
149 if (afs_shuttingdown == AFS_RUNNING)
150 osi_Panic("osi_Read called with null param");
156 afile->offset = offset;
159 vn_rdwr(UIO_READ, afile->vnode, aptr, asize, afile->offset,
160 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid,
164 code = asize - resid;
165 afile->offset += code;
166 osi_DisableAtimes(afile->vnode);
168 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
169 ICL_TYPE_INT32, code);
177 /* Generic write interface */
179 afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
185 AFS_STATCNT(osi_Write);
187 osi_Panic("afs_osi_Write called with null afile");
189 afile->offset = offset;
193 vn_rdwr(UIO_WRITE, afile->vnode, aptr, asize, afile->offset,
194 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, osi_curproc());
198 code = asize - resid;
199 afile->offset += code;
200 if (afile->offset > afile->size)
201 afile->size = afile->offset;
209 (*afile->proc) (afile, code);
215 * This work should be handled by physstrat in ca/machdep.c. This routine
216 * written from the RT NFS port strategy routine. It has been generalized a
217 * bit, but should still be pretty clear.
220 afs_osi_MapStrategy(int (*aproc)(struct buf *), struct buf *bp)
222 afs_int32 returnCode;
224 AFS_STATCNT(osi_MapStrategy);
225 returnCode = (*aproc) (bp);
231 shutdown_osifile(void)
233 AFS_STATCNT(shutdown_osifile);
234 if (afs_cold_shutdown)
235 afs_osicred_initialized = 0;