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"
15 #include "../afs/sysincludes.h" /* Standard vendor system headers */
16 #include "../afs/afsincludes.h" /* Afs-based standard headers */
17 #include "../afs/afs_stats.h" /* afs statistics */
20 int afs_osicred_initialized=0;
21 struct AFS_UCRED afs_osi_cred;
22 afs_lock_t afs_xosi; /* lock is for tvattr */
23 extern struct osi_dev cacheDev;
24 extern struct mount *afs_cacheVfsp;
27 void *osi_UFSOpen(afs_int32 ainode)
30 register struct osi_file *afile = NULL;
31 extern int cacheDiskType;
34 AFS_STATCNT(osi_UFSOpen);
35 if(cacheDiskType != AFS_FCACHE_TYPE_UFS) {
36 osi_Panic("UFSOpen called for non-UFS cache\n");
38 if (!afs_osicred_initialized) {
39 /* valid for alpha_osf, SunOS, Ultrix */
40 memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
41 afs_osi_cred.cr_ref++;
42 afs_osicred_initialized = 1;
44 afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
46 code = igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t)ainode, &ip, &dummy);
49 osi_FreeSmallSpace(afile);
50 osi_Panic("UFSOpen: igetinode failed");
52 afile->vnode = ITOV(ip);
53 VOP_UNLOCK(afile->vnode, 0, curproc);
54 afile->size = VTOI(afile->vnode)->i_size;
56 afile->proc = (int (*)()) 0;
57 afile->inum = ainode; /* for hint validity checking */
61 int afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
63 register afs_int32 code;
65 AFS_STATCNT(osi_Stat);
66 MObtainWriteLock(&afs_xosi,320);
68 code=VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
71 astat->size = tvattr.va_size;
72 astat->blksize = tvattr.va_blocksize;
73 astat->mtime = tvattr.va_mtime.tv_sec;
74 astat->atime = tvattr.va_atime.tv_sec;
76 MReleaseWriteLock(&afs_xosi);
80 int osi_UFSClose(register struct osi_file *afile)
82 AFS_STATCNT(osi_Close);
84 AFS_RELE(afile->vnode);
87 osi_FreeSmallSpace(afile);
91 int osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
94 register afs_int32 code;
95 struct osi_stat tstat;
96 AFS_STATCNT(osi_Truncate);
98 /* This routine only shrinks files, and most systems
99 * have very slow truncates, even when the file is already
100 * small enough. Check now and save some time.
102 code = afs_osi_Stat(afile, &tstat);
103 if (code || tstat.size <= asize) return code;
104 MObtainWriteLock(&afs_xosi,321);
106 tvattr.va_size = asize;
108 code=VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
110 MReleaseWriteLock(&afs_xosi);
114 void osi_DisableAtimes(struct vnode *avp)
116 struct inode *ip = VTOI(avp);
117 ip->i_flag &= ~IN_ACCESS;
121 /* Generic read interface */
122 int afs_osi_Read(register struct osi_file *afile, int offset, void *aptr, afs_int32 asize)
125 register afs_int32 code;
126 register afs_int32 cnt1=0;
127 AFS_STATCNT(osi_Read);
130 * If the osi_file passed in is NULL, panic only if AFS is not shutting
131 * down. No point in crashing when we are already shutting down
134 if ( !afs_shuttingdown )
135 osi_Panic("osi_Read called with null param");
140 if (offset != -1) afile->offset = offset;
142 code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
143 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
146 code = asize - resid;
147 afile->offset += code;
148 osi_DisableAtimes(afile->vnode);
151 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
152 ICL_TYPE_INT32, code);
158 /* Generic write interface */
159 int afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr, afs_int32 asize)
162 register afs_int32 code;
163 AFS_STATCNT(osi_Write);
165 osi_Panic("afs_osi_Write called with null param");
166 if (offset != -1) afile->offset = offset;
169 code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
170 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
174 code = asize - resid;
175 afile->offset += code;
181 (*afile->proc)(afile, code);
187 /* This work should be handled by physstrat in ca/machdep.c.
188 This routine written from the RT NFS port strategy routine.
189 It has been generalized a bit, but should still be pretty clear. */
190 int afs_osi_MapStrategy(int (*aproc)(), register struct buf *bp)
192 afs_int32 returnCode;
194 AFS_STATCNT(osi_MapStrategy);
195 returnCode = (*aproc) (bp);
202 void shutdown_osifile(void)
204 extern int afs_cold_shutdown;
206 AFS_STATCNT(shutdown_osifile);
207 if (afs_cold_shutdown) {
208 afs_osicred_initialized = 0;