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 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;
56 afile->inum = ainode->ufs; /* for hint validity checking */
61 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
66 AFS_STATCNT(osi_Stat);
67 MObtainWriteLock(&afs_xosi, 320);
69 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
72 astat->size = afile->size = tvattr.va_size;
73 astat->mtime = tvattr.va_mtime.tv_sec;
74 astat->atime = tvattr.va_atime.tv_sec;
76 MReleaseWriteLock(&afs_xosi);
81 osi_UFSClose(struct osi_file *afile)
83 AFS_STATCNT(osi_Close);
86 AFS_RELE(afile->vnode);
88 osi_FreeSmallSpace(afile);
93 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
97 struct osi_stat tstat;
99 AFS_STATCNT(osi_Truncate);
102 * This routine only shrinks files, and most systems
103 * have very slow truncates, even when the file is already
104 * small enough. Check now and save some time.
106 code = afs_osi_Stat(afile, &tstat);
107 if (code || tstat.size <= asize)
110 MObtainWriteLock(&afs_xosi, 321);
112 tvattr.va_size = asize;
114 VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curproc);
115 code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp, curproc);
116 VOP_UNLOCK(afile->vnode, 0, curproc);
120 MReleaseWriteLock(&afs_xosi);
125 osi_DisableAtimes(struct vnode *avp)
128 VTOI(avp)->i_flag &= ~IN_ACCESS;
133 /* Generic read interface */
135 afs_osi_Read(struct osi_file *afile, int offset, void *aptr, afs_int32 asize)
140 AFS_STATCNT(osi_Read);
143 * If the osi_file passed in is NULL, panic only if AFS is not shutting
144 * down. No point in crashing when we are already shutting down
147 if (!afs_shuttingdown)
148 osi_Panic("osi_Read called with null param");
154 afile->offset = offset;
157 vn_rdwr(UIO_READ, afile->vnode, aptr, asize, afile->offset,
158 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, curproc);
161 code = asize - resid;
162 afile->offset += code;
163 osi_DisableAtimes(afile->vnode);
165 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32,
166 (unsigned int) resid, ICL_TYPE_INT32, code);
172 /* Generic write interface */
174 afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
180 AFS_STATCNT(osi_Write);
182 osi_Panic("afs_osi_Write called with null afile");
184 afile->offset = offset;
187 VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curproc);
189 vn_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
190 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, curproc);
191 VOP_UNLOCK(afile->vnode, 0, curproc);
195 code = asize - resid;
196 afile->offset += code;
197 if (afile->offset > afile->size)
198 afile->size = afile->offset;
203 (*afile->proc) (afile, code);
209 * This work should be handled by physstrat in ca/machdep.c. This routine
210 * written from the RT NFS port strategy routine. It has been generalized a
211 * bit, but should still be pretty clear.
214 afs_osi_MapStrategy(int (*aproc) (), struct buf *bp)
216 afs_int32 returnCode;
218 AFS_STATCNT(osi_MapStrategy);
219 returnCode = (*aproc) (bp);
225 shutdown_osifile(void)
227 AFS_STATCNT(shutdown_osifile);
228 if (afs_cold_shutdown)
229 afs_osicred_initialized = 0;