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_ucred_t afs_osi_cred;
20 afs_lock_t afs_xosi; /* lock is for tvattr */
21 extern struct osi_dev cacheDev;
22 extern struct mount *afs_cacheVfsp;
25 osi_UFSOpen(afs_dcache_id_t *ainode)
27 struct osi_file *afile;
29 extern int cacheDiskType;
32 AFS_STATCNT(osi_UFSOpen);
33 if (cacheDiskType != AFS_FCACHE_TYPE_UFS)
34 osi_Panic("UFSOpen called for non-UFS cache\n");
35 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
37 code = VFS_VGET(cacheDev.mp, (ino_t) ainode->ufs, &vp);
39 if (code == 0 && vp->v_type == VNON)
42 osi_FreeSmallSpace(afile);
43 osi_Panic("UFSOpen: igetinode failed");
47 afile->size = VTOI(vp)->i_ffs1_size;
54 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
59 AFS_STATCNT(osi_Stat);
60 MObtainWriteLock(&afs_xosi, 320);
62 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp,
66 astat->size = afile->size = tvattr.va_size;
67 astat->mtime = tvattr.va_mtime.tv_sec;
68 astat->atime = tvattr.va_atime.tv_sec;
70 MReleaseWriteLock(&afs_xosi);
75 osi_UFSClose(struct osi_file *afile)
77 AFS_STATCNT(osi_Close);
80 AFS_RELE(afile->vnode);
82 osi_FreeSmallSpace(afile);
87 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
91 struct osi_stat tstat;
93 AFS_STATCNT(osi_Truncate);
96 * This routine only shrinks files, and most systems
97 * have very slow truncates, even when the file is already
98 * small enough. Check now and save some time.
100 code = afs_osi_Stat(afile, &tstat);
101 if (code || tstat.size <= asize)
104 MObtainWriteLock(&afs_xosi, 321);
106 tvattr.va_size = asize;
108 VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY);
109 code = VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp,
111 VOP_UNLOCK(afile->vnode, 0);
115 MReleaseWriteLock(&afs_xosi);
120 osi_DisableAtimes(struct vnode *avp)
123 VTOI(avp)->i_flag &= ~IN_ACCESS;
128 /* Generic read interface */
130 afs_osi_Read(struct osi_file *afile, int offset, void *aptr, afs_int32 asize)
135 AFS_STATCNT(osi_Read);
138 * If the osi_file passed in is NULL, panic only if AFS is not shutting
139 * down. No point in crashing when we are already shutting down
142 if (!afs_shuttingdown)
143 osi_Panic("osi_Read called with null param");
149 afile->offset = offset;
152 vn_rdwr(UIO_READ, afile->vnode, aptr, asize, afile->offset,
153 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid,
157 code = asize - resid;
158 afile->offset += code;
159 osi_DisableAtimes(afile->vnode);
161 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
162 ICL_TYPE_INT32, code);
168 /* Generic write interface */
170 afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
176 AFS_STATCNT(osi_Write);
178 osi_Panic("afs_osi_Write called with null afile");
180 afile->offset = offset;
183 VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY);
185 vn_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
186 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid, osi_curproc());
187 VOP_UNLOCK(afile->vnode, 0);
191 code = asize - resid;
192 afile->offset += code;
193 if (afile->offset > afile->size)
194 afile->size = afile->offset;
199 (*afile->proc) (afile, code);
205 * This work should be handled by physstrat in ca/machdep.c. This routine
206 * written from the RT NFS port strategy routine. It has been generalized a
207 * bit, but should still be pretty clear.
210 afs_osi_MapStrategy(int (*aproc) (), struct buf *bp)
212 afs_int32 returnCode;
214 AFS_STATCNT(osi_MapStrategy);
215 returnCode = (*aproc) (bp);
221 shutdown_osifile(void)
223 AFS_STATCNT(shutdown_osifile);
224 if (afs_cold_shutdown)
225 afs_osicred_initialized = 0;