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 */
17 #include "afs/osi_inode.h" /* igetinode() */
20 int afs_osicred_initialized = 0;
21 afs_ucred_t afs_osi_cred;
22 afs_lock_t afs_xosi; /* lock is for tvattr */
23 extern struct osi_dev cacheDev;
24 extern struct vfs *afs_cacheVfsp;
28 osi_UFSOpen(afs_dcache_id_t *ainode)
31 struct osi_file *afile = NULL;
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");
39 if (!afs_osicred_initialized) {
40 /* valid for SunOS, Ultrix */
41 memset(&afs_osi_cred, 0, sizeof(afs_ucred_t));
42 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
43 afs_osicred_initialized = 1;
45 afile = osi_AllocSmallSpace(sizeof(struct osi_file));
48 ip = (struct inode *)igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev,
49 (ino_t) ainode->ufs, &dummy);
52 osi_FreeSmallSpace(afile);
53 osi_Panic("UFSOpen: igetinode failed");
56 afile->vnode = ITOV(ip);
57 afile->size = VTOI(afile->vnode)->i_size;
59 afile->proc = (int (*)())0;
64 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
68 AFS_STATCNT(osi_Stat);
69 ObtainWriteLock(&afs_xosi, 320);
71 code = VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, VSYNC);
74 astat->size = tvattr.va_size;
75 astat->mtime = tvattr.va_mtime.tv_sec;
76 astat->atime = tvattr.va_atime.tv_sec;
78 ReleaseWriteLock(&afs_xosi);
83 osi_UFSClose(struct osi_file *afile)
85 AFS_STATCNT(osi_Close);
87 AFS_RELE(afile->vnode);
90 osi_FreeSmallSpace(afile);
95 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
100 struct osi_stat tstat;
101 AFS_STATCNT(osi_Truncate);
103 /* This routine only shrinks files, and most systems
104 * have very slow truncates, even when the file is already
105 * small enough. Check now and save some time.
107 code = afs_osi_Stat(afile, &tstat);
108 if (code || tstat.size <= asize)
110 ObtainWriteLock(&afs_xosi, 321);
112 /* note that this credential swapping stuff is only necessary because
113 * of ufs's references directly to u.u_cred instead of to
114 * credentials parameter. Probably should fix ufs some day. */
115 oldCred = p_cred(u.u_procp);
116 set_p_cred(u.u_procp, &afs_osi_cred);
117 tvattr.va_size = asize;
119 code = VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, 0);
121 set_p_cred(u.u_procp, oldCred); /* restore */
122 ReleaseWriteLock(&afs_xosi);
127 osi_DisableAtimes(struct vnode *avp)
129 struct inode *ip = VTOI(avp);
134 /* Generic read interface */
136 afs_osi_Read(struct osi_file *afile, int offset, void *aptr,
139 afs_ucred_t *oldCred;
143 AFS_STATCNT(osi_Read);
146 * If the osi_file passed in is NULL, panic only if AFS is not shutting
147 * down. No point in crashing when we are already shutting down
150 if (afs_shuttingdown == AFS_RUNNING)
151 osi_Panic("osi_Read called with null param");
157 afile->offset = offset;
161 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
162 AFS_UIOSYS, IO_UNIT, &resid);
165 code = asize - resid;
166 afile->offset += code;
167 osi_DisableAtimes(afile->vnode);
169 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32,
170 (afs_int32) resid, ICL_TYPE_INT32, code);
172 * To handle periodic low-level EFAULT failures that we've seen with the
173 * Weitek chip; in all observed failed cases a second read succeeded.
175 if ((code == EFAULT) && (cnt1++ < 5)) {
176 afs_stats_cmperf.osiread_efaults++;
187 /* Generic write interface */
189 afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
192 afs_ucred_t *oldCred;
195 AFS_STATCNT(osi_Write);
197 osi_Panic("afs_osi_Write called with null param");
199 afile->offset = offset;
202 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
203 afile->offset, AFS_UIOSYS, IO_UNIT, &resid);
206 code = asize - resid;
207 afile->offset += code;
211 ("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
218 (*afile->proc) (afile, code);
225 shutdown_osifile(void)
227 AFS_STATCNT(shutdown_osifile);
228 if (afs_cold_shutdown) {
229 afs_osicred_initialized = 0;