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(ainode)
31 register 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 alpha_osf, SunOS, Ultrix */
41 memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
42 afs_osi_cred.cr_ref++;
43 afs_osicred_initialized = 1;
45 afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
47 code = igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t)ainode, &ip, &dummy);
50 osi_FreeSmallSpace(afile);
51 osi_Panic("UFSOpen: igetinode failed");
53 afile->vnode = ITOV(ip);
54 VOP_UNLOCK(afile->vnode, 0, curproc);
55 afile->size = VTOI(afile->vnode)->i_size;
57 afile->proc = (int (*)()) 0;
58 afile->inum = ainode; /* for hint validity checking */
62 afs_osi_Stat(afile, astat)
63 register struct osi_file *afile;
64 register struct osi_stat *astat; {
65 register afs_int32 code;
67 AFS_STATCNT(osi_Stat);
68 MObtainWriteLock(&afs_xosi,320);
70 code=VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
73 astat->size = tvattr.va_size;
74 astat->blksize = tvattr.va_blocksize;
75 astat->mtime = tvattr.va_mtime.tv_sec;
76 astat->atime = tvattr.va_atime.tv_sec;
78 MReleaseWriteLock(&afs_xosi);
83 register struct osi_file *afile;
85 AFS_STATCNT(osi_Close);
87 AFS_RELE(afile->vnode);
90 osi_FreeSmallSpace(afile);
94 osi_UFSTruncate(afile, asize)
95 register struct osi_file *afile;
98 register afs_int32 code;
99 struct osi_stat tstat;
100 AFS_STATCNT(osi_Truncate);
102 /* This routine only shrinks files, and most systems
103 * have very slow truncates, even when the file is already
104 * small enough. Check now and save some time.
106 code = afs_osi_Stat(afile, &tstat);
107 if (code || tstat.size <= asize) return code;
108 MObtainWriteLock(&afs_xosi,321);
110 tvattr.va_size = asize;
112 code=VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
114 MReleaseWriteLock(&afs_xosi);
118 void osi_DisableAtimes(avp)
121 struct inode *ip = VTOI(avp);
122 ip->i_flag &= ~IN_ACCESS;
126 /* Generic read interface */
127 afs_osi_Read(afile, offset, aptr, asize)
128 register struct osi_file *afile;
133 register afs_int32 code;
134 register afs_int32 cnt1=0;
135 AFS_STATCNT(osi_Read);
138 * If the osi_file passed in is NULL, panic only if AFS is not shutting
139 * down. No point in crashing when we are already shutting down
142 if ( !afs_shuttingdown )
143 osi_Panic("osi_Read called with null param");
148 if (offset != -1) afile->offset = offset;
150 code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
151 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
154 code = asize - resid;
155 afile->offset += code;
156 osi_DisableAtimes(afile->vnode);
159 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
160 ICL_TYPE_INT32, code);
166 /* Generic write interface */
167 afs_osi_Write(afile, offset, aptr, asize)
168 register struct osi_file *afile;
173 register afs_int32 code;
174 AFS_STATCNT(osi_Write);
176 osi_Panic("afs_osi_Write called with null param");
177 if (offset != -1) afile->offset = offset;
180 code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
181 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
185 code = asize - resid;
186 afile->offset += code;
192 (*afile->proc)(afile, code);
198 /* This work should be handled by physstrat in ca/machdep.c.
199 This routine written from the RT NFS port strategy routine.
200 It has been generalized a bit, but should still be pretty clear. */
201 int afs_osi_MapStrategy(aproc, bp)
203 register struct buf *bp;
205 afs_int32 returnCode;
207 AFS_STATCNT(osi_MapStrategy);
208 returnCode = (*aproc) (bp);
218 extern int afs_cold_shutdown;
220 AFS_STATCNT(shutdown_osifile);
221 if (afs_cold_shutdown) {
222 afs_osicred_initialized = 0;