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 #ifndef AFS_FBSD80_ENV /* cr_groups is now malloc()'d */
21 afs_ucred_t afs_osi_cred;
23 extern struct osi_dev cacheDev;
24 extern struct mount *afs_cacheVfsp;
28 osi_UFSOpen(afs_dcache_id_t *ainode)
30 struct osi_file *afile;
32 extern int cacheDiskType;
35 AFS_STATCNT(osi_UFSOpen);
36 if (cacheDiskType != AFS_FCACHE_TYPE_UFS)
37 osi_Panic("UFSOpen called for non-UFS cache\n");
38 afile = osi_AllocSmallSpace(sizeof(struct osi_file));
40 code = VFS_VGET(afs_cacheVfsp, (ino_t) ainode->ufs, LK_EXCLUSIVE, &vp);
42 if (code == 0 && vp->v_type == VNON)
45 osi_FreeSmallSpace(afile);
46 osi_Panic("UFSOpen: igetinode failed");
48 #if defined(AFS_FBSD80_ENV)
51 VOP_UNLOCK(vp, 0, curthread);
54 afile->size = VTOI(vp)->i_size;
61 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
65 AFS_STATCNT(osi_Stat);
67 #if defined(AFS_FBSD80_ENV)
68 vn_lock(afile->vnode, LK_EXCLUSIVE | LK_RETRY);
69 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp);
70 VOP_UNLOCK(afile->vnode, 0);
72 vn_lock(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curthread);
73 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread);
74 VOP_UNLOCK(afile->vnode, LK_EXCLUSIVE, curthread);
78 astat->size = tvattr.va_size;
79 astat->mtime = tvattr.va_mtime.tv_sec;
80 astat->atime = tvattr.va_atime.tv_sec;
86 osi_UFSClose(struct osi_file *afile)
88 AFS_STATCNT(osi_Close);
90 AFS_RELE(afile->vnode);
93 osi_FreeSmallSpace(afile);
98 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
102 afs_int32 code, glocked;
103 AFS_STATCNT(osi_Truncate);
107 * This routine only shrinks files, and most systems
108 * have very slow truncates, even when the file is already
109 * small enough. Check now and save some time.
111 glocked = ISAFS_GLOCK();
114 #if defined(AFS_FBSD80_ENV)
115 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
116 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp);
118 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
119 code = VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, curthread);
121 if (code != 0 || tvattr.va_size <= asize)
125 tvattr.va_size = asize;
126 #if defined(AFS_FBSD80_ENV)
127 code = VOP_SETATTR(vp, &tvattr, afs_osi_credp);
129 code = VOP_SETATTR(vp, &tvattr, afs_osi_credp, curthread);
133 #if defined(AFS_FBSD80_ENV)
136 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
144 osi_DisableAtimes(struct vnode *avp)
146 struct inode *ip = VTOI(avp);
147 ip->i_flag &= ~IN_ACCESS;
151 /* Generic read interface */
153 afs_osi_Read(struct osi_file *afile, int offset, void *aptr,
156 #if (__FreeBSD_version >= 900505 && __FreeBSD_Version < 1000000) ||__FreeBSD_version >= 1000009
162 AFS_STATCNT(osi_Read);
165 * If the osi_file passed in is NULL, panic only if AFS is not shutting
166 * down. No point in crashing when we are already shutting down
169 if (afs_shuttingdown == AFS_RUNNING)
170 osi_Panic("osi_Read called with null param");
176 afile->offset = offset;
179 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
180 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid);
183 code = asize - resid;
184 afile->offset += code;
185 osi_DisableAtimes(afile->vnode);
187 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, (int)resid,
188 ICL_TYPE_INT32, code);
196 /* Generic write interface */
198 afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
201 #if (__FreeBSD_version >= 900505 && __FreeBSD_Version < 1000000) ||__FreeBSD_version >= 1000009
207 AFS_STATCNT(osi_Write);
209 osi_Panic("afs_osi_Write called with null param");
211 afile->offset = offset;
215 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
216 afile->offset, AFS_UIOSYS, IO_UNIT, afs_osi_credp,
221 code = asize - resid;
222 afile->offset += code;
229 (*afile->proc) (afile, code);
235 /* This work should be handled by physstrat in ca/machdep.c.
236 This routine written from the RT NFS port strategy routine.
237 It has been generalized a bit, but should still be pretty clear. */
239 afs_osi_MapStrategy(int (*aproc) (), struct buf *bp)
241 afs_int32 returnCode;
243 AFS_STATCNT(osi_MapStrategy);
244 returnCode = (*aproc) (bp);
252 shutdown_osifile(void)
254 AFS_STATCNT(shutdown_osifile);
255 if (afs_cold_shutdown) {
256 afs_osicred_initialized = 0;