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 "afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h" /* afs statistics */
19 int afs_osicred_initialized = 0;
20 extern struct osi_dev cacheDev;
21 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 = osi_AllocSmallSpace(sizeof(struct osi_file));
37 code = VFS_VGET(afs_cacheVfsp, (ino_t) ainode->ufs, LK_EXCLUSIVE, &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_size;
54 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
58 AFS_STATCNT(osi_Stat);
60 vn_lock(afile->vnode, LK_EXCLUSIVE | LK_RETRY);
61 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp);
62 VOP_UNLOCK(afile->vnode, 0);
65 astat->size = tvattr.va_size;
66 astat->mtime = tvattr.va_mtime.tv_sec;
67 astat->atime = tvattr.va_atime.tv_sec;
73 osi_UFSClose(struct osi_file *afile)
75 AFS_STATCNT(osi_Close);
77 AFS_RELE(afile->vnode);
80 osi_FreeSmallSpace(afile);
85 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
89 afs_int32 code, glocked;
90 AFS_STATCNT(osi_Truncate);
94 * This routine only shrinks files, and most systems
95 * have very slow truncates, even when the file is already
96 * small enough. Check now and save some time.
98 glocked = ISAFS_GLOCK();
101 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
102 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp);
103 if (code != 0 || tvattr.va_size <= asize)
107 tvattr.va_size = asize;
108 code = VOP_SETATTR(vp, &tvattr, afs_osi_credp);
118 osi_DisableAtimes(struct vnode *avp)
120 struct inode *ip = VTOI(avp);
121 ip->i_flag &= ~IN_ACCESS;
125 /* Generic read interface */
127 afs_osi_Read(struct osi_file *afile, int offset, void *aptr,
130 #if __FreeBSD_version >= 1000009
136 AFS_STATCNT(osi_Read);
139 * If the osi_file passed in is NULL, panic only if AFS is not shutting
140 * down. No point in crashing when we are already shutting down
143 if (afs_shuttingdown == AFS_RUNNING)
144 osi_Panic("osi_Read called with null param");
150 afile->offset = offset;
153 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
154 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, (int)resid,
162 ICL_TYPE_INT32, code);
170 /* Generic write interface */
172 afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
175 #if __FreeBSD_version >= 1000009
181 AFS_STATCNT(osi_Write);
183 osi_Panic("afs_osi_Write called with null param");
185 afile->offset = offset;
189 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
190 afile->offset, AFS_UIOSYS, IO_UNIT, afs_osi_credp,
195 code = asize - resid;
196 afile->offset += code;
203 (*afile->proc) (afile, code);
209 /* This work should be handled by physstrat in ca/machdep.c.
210 This routine written from the RT NFS port strategy routine.
211 It has been generalized a bit, but should still be pretty clear. */
213 afs_osi_MapStrategy(int (*aproc) (), struct buf *bp)
215 afs_int32 returnCode;
217 AFS_STATCNT(osi_MapStrategy);
218 returnCode = (*aproc) (bp);
226 shutdown_osifile(void)
228 AFS_STATCNT(shutdown_osifile);
229 if (afs_cold_shutdown) {
230 afs_osicred_initialized = 0;