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 */
21 int afs_osicred_initialized = 0;
22 struct AFS_UCRED afs_osi_cred;
23 afs_lock_t afs_xosi; /* lock is for tvattr */
24 extern struct osi_dev cacheDev;
25 extern struct mount *afs_cacheVfsp;
29 osi_UFSOpen(afs_int32 ainode)
32 register struct osi_file *afile = NULL;
33 extern int cacheDiskType;
36 AFS_STATCNT(osi_UFSOpen);
37 if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
38 osi_Panic("UFSOpen called for non-UFS cache\n");
40 if (!afs_osicred_initialized) {
41 /* valid for alpha_osf, SunOS, Ultrix */
42 memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
43 afs_osi_cred.cr_ref++;
44 afs_osicred_initialized = 1;
46 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
49 igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t) ainode, &ip,
53 osi_FreeSmallSpace(afile);
54 osi_Panic("UFSOpen: igetinode failed");
56 afile->vnode = ITOV(ip);
57 #if defined(AFS_FBSD50_ENV)
58 VOP_UNLOCK(afile->vnode, 0, curthread);
60 VOP_UNLOCK(afile->vnode, 0, curproc);
62 afile->size = VTOI(afile->vnode)->i_size;
64 afile->proc = (int (*)())0;
65 afile->inum = ainode; /* for hint validity checking */
70 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
72 register afs_int32 code;
74 AFS_STATCNT(osi_Stat);
75 MObtainWriteLock(&afs_xosi, 320);
77 #if defined(AFS_FBSD50_ENV)
78 code = VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, curthread);
80 code = VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
84 astat->size = tvattr.va_size;
85 astat->blksize = tvattr.va_blocksize;
86 astat->mtime = tvattr.va_mtime.tv_sec;
87 astat->atime = tvattr.va_atime.tv_sec;
89 MReleaseWriteLock(&afs_xosi);
94 osi_UFSClose(register struct osi_file *afile)
96 AFS_STATCNT(osi_Close);
98 AFS_RELE(afile->vnode);
101 osi_FreeSmallSpace(afile);
106 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
109 register afs_int32 code;
110 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_size = asize;
124 #if defined(AFS_FBSD50_ENV)
125 code = VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, curthread);
127 code = VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
130 MReleaseWriteLock(&afs_xosi);
135 osi_DisableAtimes(struct vnode *avp)
137 struct inode *ip = VTOI(avp);
138 ip->i_flag &= ~IN_ACCESS;
142 /* Generic read interface */
144 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
148 register afs_int32 code;
149 AFS_STATCNT(osi_Read);
152 * If the osi_file passed in is NULL, panic only if AFS is not shutting
153 * down. No point in crashing when we are already shutting down
156 if (!afs_shuttingdown)
157 osi_Panic("osi_Read called with null param");
163 afile->offset = offset;
166 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
167 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
170 code = asize - resid;
171 afile->offset += code;
172 osi_DisableAtimes(afile->vnode);
174 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
175 ICL_TYPE_INT32, code);
181 /* Generic write interface */
183 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
187 register afs_int32 code;
188 AFS_STATCNT(osi_Write);
190 osi_Panic("afs_osi_Write called with null param");
192 afile->offset = offset;
196 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
197 afile->offset, AFS_UIOSYS, IO_UNIT, &afs_osi_cred,
202 code = asize - resid;
203 afile->offset += code;
208 (*afile->proc) (afile, code);
214 /* This work should be handled by physstrat in ca/machdep.c.
215 This routine written from the RT NFS port strategy routine.
216 It has been generalized a bit, but should still be pretty clear. */
218 afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
220 afs_int32 returnCode;
222 AFS_STATCNT(osi_MapStrategy);
223 returnCode = (*aproc) (bp);
231 shutdown_osifile(void)
233 extern int afs_cold_shutdown;
235 AFS_STATCNT(shutdown_osifile);
236 if (afs_cold_shutdown) {
237 afs_osicred_initialized = 0;