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"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
17 #include "afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h" /* afs statistics */
20 struct AFS_UCRED afs_osi_cred;
21 int afs_osicred_initialized = 0;
22 afs_lock_t afs_xosi; /* lock is for tvattr */
23 extern struct osi_dev cacheDev;
24 extern struct vfs *afs_cacheVfsp;
27 afs_XFSIGetVnode(ino_t ainode)
34 xfs_igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, ainode, &ip))) {
35 osi_Panic("afs_XFSIGetVnode: xfs_igetinode failed, error=%d", error);
41 /* Force to 64 bits, even for EFS filesystems. */
43 osi_UFSOpen(ino_t ainode)
46 register struct osi_file *afile = NULL;
47 extern int cacheDiskType;
50 AFS_STATCNT(osi_UFSOpen);
51 if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
52 osi_Panic("UFSOpen called for non-UFS cache\n");
54 if (!afs_osicred_initialized) {
55 /* valid for alpha_osf, SunOS, Ultrix */
56 memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
57 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
58 afs_osicred_initialized = 1;
60 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
62 afile->vnode = AFS_SGI_IGETVNODE(ainode);
64 afile->size = VnodeToSize(afile->vnode);
66 afile->proc = (int (*)())0;
67 afile->inum = ainode; /* for hint validity checking */
72 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
74 register afs_int32 code;
76 AFS_STATCNT(osi_Stat);
77 MObtainWriteLock(&afs_xosi, 320);
79 tvattr.va_mask = AT_SIZE | AT_BLKSIZE | AT_MTIME | AT_ATIME;
80 AFS_VOP_GETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, code);
83 astat->size = tvattr.va_size;
84 astat->mtime = tvattr.va_mtime.tv_sec;
85 astat->atime = tvattr.va_atime.tv_sec;
87 MReleaseWriteLock(&afs_xosi);
92 osi_UFSClose(register struct osi_file *afile)
94 AFS_STATCNT(osi_Close);
96 VN_RELE(afile->vnode);
99 osi_FreeSmallSpace(afile);
104 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
106 struct AFS_UCRED *oldCred;
108 register afs_int32 code;
109 struct osi_stat tstat;
111 AFS_STATCNT(osi_Truncate);
113 /* This routine only shrinks files, and most systems
114 * have very slow truncates, even when the file is already
115 * small enough. Check now and save some time.
117 code = afs_osi_Stat(afile, &tstat);
118 if (code || tstat.size <= asize)
120 MObtainWriteLock(&afs_xosi, 321);
122 tvattr.va_mask = AT_SIZE;
123 tvattr.va_size = asize;
124 AFS_VOP_SETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, code);
126 MReleaseWriteLock(&afs_xosi);
131 /* Generic read interface */
133 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
136 struct AFS_UCRED *oldCred;
138 register afs_int32 code;
139 register afs_int32 cnt1 = 0;
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 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
158 AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred, &resid);
161 code = asize - resid;
162 afile->offset += code;
164 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
165 ICL_TYPE_INT32, code);
171 /* Generic write interface */
173 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
176 struct AFS_UCRED *oldCred;
178 register afs_int32 code;
179 AFS_STATCNT(osi_Write);
181 osi_Panic("afs_osi_Write called with null param");
183 afile->offset = offset;
186 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
187 afile->offset, AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred,
191 code = asize - resid;
192 afile->offset += code;
196 ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
200 (*afile->proc) (afile, code);
206 /* This work should be handled by physstrat in ca/machdep.c.
207 This routine written from the RT NFS port strategy routine.
208 It has been generalized a bit, but should still be pretty clear. */
210 afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
212 afs_int32 returnCode;
214 AFS_STATCNT(osi_MapStrategy);
215 returnCode = (*aproc) (bp);
223 shutdown_osifile(void)
225 AFS_STATCNT(shutdown_osifile);
226 if (afs_cold_shutdown) {
227 afs_osicred_initialized = 0;