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 afs_lock_t afs_xosi; /* lock is for tvattr */
20 extern struct osi_dev cacheDev;
21 extern struct mount *afs_cacheVfsp;
24 osi_UFSOpen(afs_dcache_id_t *ainode)
26 struct osi_file *afile;
28 extern int cacheDiskType;
31 AFS_STATCNT(osi_UFSOpen);
32 if (cacheDiskType != AFS_FCACHE_TYPE_UFS)
33 osi_Panic("UFSOpen called for non-UFS cache\n");
34 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
36 code = VFS_VGET(cacheDev.mp, (ino_t) ainode->ufs, &vp);
38 if (code == 0 && vp->v_type == VNON)
41 osi_FreeSmallSpace(afile);
42 osi_Panic("UFSOpen: igetinode failed");
44 #if defined(AFS_NBSD60_ENV)
50 afile->size = VTOI(vp)->i_ffs1_size;
57 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
62 AFS_STATCNT(osi_Stat);
63 ObtainWriteLock(&afs_xosi, 320);
66 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp);
68 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp,
73 astat->size = afile->size = tvattr.va_size;
74 astat->mtime = tvattr.va_mtime.tv_sec;
75 astat->atime = tvattr.va_atime.tv_sec;
77 ReleaseWriteLock(&afs_xosi);
82 osi_UFSClose(struct osi_file *afile)
84 AFS_STATCNT(osi_Close);
87 AFS_RELE(afile->vnode);
89 osi_FreeSmallSpace(afile);
94 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
98 struct osi_stat tstat;
100 AFS_STATCNT(osi_Truncate);
103 * This routine only shrinks files, and most systems
104 * have very slow truncates, even when the file is already
105 * small enough. Check now and save some time.
107 code = afs_osi_Stat(afile, &tstat);
108 if (code || tstat.size <= asize)
111 ObtainWriteLock(&afs_xosi, 321);
113 tvattr.va_size = asize;
115 VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY);
116 #ifdef AFS_NBSD50_ENV
117 code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp);
119 code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp,
122 #ifdef AFS_NBSD60_ENV
123 VOP_UNLOCK(afile->vnode);
125 VOP_UNLOCK(afile->vnode, 0);
130 ReleaseWriteLock(&afs_xosi);
135 osi_DisableAtimes(struct vnode *avp)
138 VTOI(avp)->i_flag &= ~IN_ACCESS;
143 /* Generic read interface */
145 afs_osi_Read(struct osi_file *afile, int offset, void *aptr, afs_int32 asize)
150 AFS_STATCNT(osi_Read);
153 * If the osi_file passed in is NULL, panic only if AFS is not shutting
154 * down. No point in crashing when we are already shutting down
157 if (!afs_shuttingdown)
158 osi_Panic("osi_Read called with null param");
164 afile->offset = offset;
167 vn_rdwr(UIO_READ, afile->vnode, aptr, asize, afile->offset,
168 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid,
172 code = asize - resid;
173 afile->offset += code;
174 osi_DisableAtimes(afile->vnode);
176 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
177 ICL_TYPE_INT32, code);
185 /* Generic write interface */
187 afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
193 AFS_STATCNT(osi_Write);
195 osi_Panic("afs_osi_Write called with null afile");
197 afile->offset = offset;
201 vn_rdwr(UIO_WRITE, afile->vnode, aptr, asize, afile->offset,
202 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, osi_curproc());
206 code = asize - resid;
207 afile->offset += code;
208 if (afile->offset > afile->size)
209 afile->size = afile->offset;
217 (*afile->proc) (afile, code);
223 * This work should be handled by physstrat in ca/machdep.c. This routine
224 * written from the RT NFS port strategy routine. It has been generalized a
225 * bit, but should still be pretty clear.
228 afs_osi_MapStrategy(int (*aproc)(struct buf *), struct buf *bp)
230 afs_int32 returnCode;
232 AFS_STATCNT(osi_MapStrategy);
233 returnCode = (*aproc) (bp);
239 shutdown_osifile(void)
241 AFS_STATCNT(shutdown_osifile);
242 if (afs_cold_shutdown)
243 afs_osicred_initialized = 0;