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 "afs/afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h" /* afs statistics */
21 int afs_osicred_initialized;
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_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(cacheDev.mp, ainode->ufs, &vp);
43 if (code == 0 && vp->v_type == VNON)
46 osi_FreeSmallSpace(afile);
47 osi_Panic("UFSOpen: igetinode failed");
49 VOP_UNLOCK(vp, 0, curproc);
52 afile->size = VTOI(vp)->i_ffs1_size;
54 afile->size = VTOI(vp)->i_ffs_size;
58 afile->inum = ainode->ufs; /* for hint validity checking */
63 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
68 AFS_STATCNT(osi_Stat);
69 MObtainWriteLock(&afs_xosi, 320);
71 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
74 astat->size = afile->size = tvattr.va_size;
75 astat->mtime = tvattr.va_mtime.tv_sec;
76 astat->atime = tvattr.va_atime.tv_sec;
78 MReleaseWriteLock(&afs_xosi);
83 osi_UFSClose(struct osi_file *afile)
85 AFS_STATCNT(osi_Close);
88 AFS_RELE(afile->vnode);
90 osi_FreeSmallSpace(afile);
95 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
99 struct osi_stat tstat;
101 AFS_STATCNT(osi_Truncate);
104 * This routine only shrinks files, and most systems
105 * have very slow truncates, even when the file is already
106 * small enough. Check now and save some time.
108 code = afs_osi_Stat(afile, &tstat);
109 if (code || tstat.size <= asize)
112 MObtainWriteLock(&afs_xosi, 321);
114 tvattr.va_size = asize;
116 VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curproc);
117 code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
118 VOP_UNLOCK(afile->vnode, 0, curproc);
122 MReleaseWriteLock(&afs_xosi);
127 osi_DisableAtimes(struct vnode *avp)
130 VTOI(avp)->i_flag &= ~IN_ACCESS;
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)
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, curproc);
163 code = asize - resid;
164 afile->offset += code;
165 osi_DisableAtimes(afile->vnode);
167 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32,
168 (unsigned int) resid, ICL_TYPE_INT32, code);
174 /* Generic write interface */
176 afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
182 AFS_STATCNT(osi_Write);
184 osi_Panic("afs_osi_Write called with null afile");
186 afile->offset = offset;
189 VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curproc);
191 vn_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
192 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, curproc);
193 VOP_UNLOCK(afile->vnode, 0, curproc);
197 code = asize - resid;
198 afile->offset += code;
199 if (afile->offset > afile->size)
200 afile->size = afile->offset;
205 (*afile->proc) (afile, code);
211 * This work should be handled by physstrat in ca/machdep.c. This routine
212 * written from the RT NFS port strategy routine. It has been generalized a
213 * bit, but should still be pretty clear.
216 afs_osi_MapStrategy(int (*aproc) (), struct buf *bp)
218 afs_int32 returnCode;
220 AFS_STATCNT(osi_MapStrategy);
221 returnCode = (*aproc) (bp);
227 shutdown_osifile(void)
229 AFS_STATCNT(shutdown_osifile);
230 if (afs_cold_shutdown)
231 afs_osicred_initialized = 0;