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 */
18 afs_ucred_t afs_osi_cred;
19 int afs_osicred_initialized = 0;
20 afs_lock_t afs_xosi; /* lock is for tvattr */
21 extern struct osi_dev cacheDev;
22 extern struct vfs *afs_cacheVfsp;
25 afs_XFSIGetVnode(ino_t ainode)
32 xfs_igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, ainode, &ip))) {
33 osi_Panic("afs_XFSIGetVnode: xfs_igetinode failed, error=%d", error);
39 /* Force to 64 bits, even for EFS filesystems. */
41 osi_UFSOpen(afs_dcache_id_t *ainode)
44 struct osi_file *afile = NULL;
45 extern int cacheDiskType;
48 AFS_STATCNT(osi_UFSOpen);
49 if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
50 osi_Panic("UFSOpen called for non-UFS cache\n");
52 if (!afs_osicred_initialized) {
53 /* valid for SunOS, Ultrix */
54 memset(&afs_osi_cred, 0, sizeof(afs_ucred_t));
55 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
56 afs_osicred_initialized = 1;
58 afile = osi_AllocSmallSpace(sizeof(struct osi_file));
60 afile->vnode = afs_XFSIGetVnode(ainode->ufs);
62 afile->size = VnodeToSize(afile->vnode);
64 afile->proc = (int (*)())0;
69 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
73 AFS_STATCNT(osi_Stat);
74 ObtainWriteLock(&afs_xosi, 320);
76 tvattr.va_mask = AT_SIZE | AT_BLKSIZE | AT_MTIME | AT_ATIME;
77 AFS_VOP_GETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, code);
80 astat->size = tvattr.va_size;
81 astat->mtime = tvattr.va_mtime.tv_sec;
82 astat->atime = tvattr.va_atime.tv_sec;
84 ReleaseWriteLock(&afs_xosi);
89 osi_UFSClose(struct osi_file *afile)
91 AFS_STATCNT(osi_Close);
93 VN_RELE(afile->vnode);
96 osi_FreeSmallSpace(afile);
101 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
103 afs_ucred_t *oldCred;
106 struct osi_stat tstat;
108 AFS_STATCNT(osi_Truncate);
110 /* This routine only shrinks files, and most systems
111 * have very slow truncates, even when the file is already
112 * small enough. Check now and save some time.
114 code = afs_osi_Stat(afile, &tstat);
115 if (code || tstat.size <= asize)
117 ObtainWriteLock(&afs_xosi, 321);
119 tvattr.va_mask = AT_SIZE;
120 tvattr.va_size = asize;
121 AFS_VOP_SETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, code);
123 ReleaseWriteLock(&afs_xosi);
128 /* Generic read interface */
130 afs_osi_Read(struct osi_file *afile, int offset, void *aptr,
133 afs_ucred_t *oldCred;
137 AFS_STATCNT(osi_Read);
140 * If the osi_file passed in is NULL, panic only if AFS is not shutting
141 * down. No point in crashing when we are already shutting down
144 if (afs_shuttingdown == AFS_RUNNING)
145 osi_Panic("osi_Read called with null param");
151 afile->offset = offset;
154 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
155 AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred, &resid);
158 code = asize - resid;
159 afile->offset += code;
161 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
162 ICL_TYPE_INT32, code);
170 /* Generic write interface */
172 afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
175 afs_ucred_t *oldCred;
178 AFS_STATCNT(osi_Write);
180 osi_Panic("afs_osi_Write called with null param");
182 afile->offset = offset;
185 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
186 afile->offset, AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred,
190 code = asize - resid;
191 afile->offset += code;
195 ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
201 (*afile->proc) (afile, code);
207 /* This work should be handled by physstrat in ca/machdep.c.
208 This routine written from the RT NFS port strategy routine.
209 It has been generalized a bit, but should still be pretty clear. */
211 afs_osi_MapStrategy(int (*aproc) (), struct buf *bp)
213 afs_int32 returnCode;
215 AFS_STATCNT(osi_MapStrategy);
216 returnCode = (*aproc) (bp);
224 shutdown_osifile(void)
226 AFS_STATCNT(shutdown_osifile);
227 if (afs_cold_shutdown) {
228 afs_osicred_initialized = 0;