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 "../afs/param.h" /* Should be always first */
11 #include "../afs/sysincludes.h" /* Standard vendor system headers */
12 #include "../afs/afsincludes.h" /* Afs-based standard headers */
13 #include "../afs/afs_stats.h" /* afs statistics */
16 int afs_osicred_initialized=0;
17 struct AFS_UCRED afs_osi_cred;
18 afs_lock_t afs_xosi; /* lock is for tvattr */
19 extern struct osi_dev cacheDev;
20 extern struct mount *afs_cacheVfsp;
23 void *osi_UFSOpen(ainode)
27 register struct osi_file *afile = NULL;
28 extern int cacheDiskType;
31 AFS_STATCNT(osi_UFSOpen);
32 if(cacheDiskType != AFS_FCACHE_TYPE_UFS) {
33 osi_Panic("UFSOpen called for non-UFS cache\n");
35 if (!afs_osicred_initialized) {
36 /* valid for alpha_osf, SunOS, Ultrix */
37 bzero((char *)&afs_osi_cred, sizeof(struct AFS_UCRED));
38 afs_osi_cred.cr_ref++;
39 afs_osicred_initialized = 1;
41 afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
43 code = igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t)ainode, &ip, &dummy);
46 osi_FreeSmallSpace(afile);
47 osi_Panic("UFSOpen: igetinode failed");
50 afile->vnode = ITOV(ip);
51 afile->size = VTOI(afile->vnode)->i_size;
53 afile->proc = (int (*)()) 0;
54 afile->inum = ainode; /* for hint validity checking */
58 afs_osi_Stat(afile, astat)
59 register struct osi_file *afile;
60 register struct osi_stat *astat; {
61 register afs_int32 code;
63 AFS_STATCNT(osi_Stat);
64 MObtainWriteLock(&afs_xosi,320);
66 VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, code);
69 astat->size = tvattr.va_size;
70 astat->blksize = tvattr.va_blocksize;
71 astat->mtime = tvattr.va_mtime.tv_sec;
72 astat->atime = tvattr.va_atime.tv_sec;
74 MReleaseWriteLock(&afs_xosi);
79 register struct osi_file *afile;
81 AFS_STATCNT(osi_Close);
83 AFS_RELE(afile->vnode);
86 osi_FreeSmallSpace(afile);
90 osi_UFSTruncate(afile, asize)
91 register struct osi_file *afile;
93 struct AFS_UCRED *oldCred;
95 register afs_int32 code;
96 struct osi_stat tstat;
97 AFS_STATCNT(osi_Truncate);
99 /* This routine only shrinks files, and most systems
100 * have very slow truncates, even when the file is already
101 * small enough. Check now and save some time.
103 code = afs_osi_Stat(afile, &tstat);
104 if (code || tstat.size <= asize) return code;
105 MObtainWriteLock(&afs_xosi,321);
107 /* note that this credential swapping stuff is only necessary because
108 of ufs's references directly to u.u_cred instead of to
109 credentials parameter. Probably should fix ufs some day. */
110 oldCred = u.u_cred; /* remember old credentials pointer */
111 u.u_cred = &afs_osi_cred; /* temporarily use superuser credentials */
112 tvattr.va_size = asize;
114 VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, code);
116 u.u_cred = oldCred; /* restore */
117 MReleaseWriteLock(&afs_xosi);
121 void osi_DisableAtimes(avp)
124 struct inode *ip = VTOI(avp);
129 /* Generic read interface */
130 afs_osi_Read(afile, offset, aptr, asize)
131 register struct osi_file *afile;
135 struct AFS_UCRED *oldCred;
137 register afs_int32 code;
138 register afs_int32 cnt1=0;
139 AFS_STATCNT(osi_Read);
142 * If the osi_file passed in is NULL, panic only if AFS is not shutting
143 * down. No point in crashing when we are already shutting down
146 if ( !afs_shuttingdown )
147 osi_Panic("osi_Read called with null param");
152 if (offset != -1) afile->offset = offset;
154 code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
155 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
158 code = asize - resid;
159 afile->offset += code;
160 osi_DisableAtimes(afile->vnode);
163 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
164 ICL_TYPE_INT32, code);
170 /* Generic write interface */
171 afs_osi_Write(afile, offset, aptr, asize)
172 register struct osi_file *afile;
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");
182 if (offset != -1) afile->offset = offset;
184 struct ucred *tmpcred = u.u_cred;
185 u.u_cred = &afs_osi_cred;
187 code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
188 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
193 code = asize - resid;
194 afile->offset += code;
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. */
209 int afs_osi_MapStrategy(aproc, bp)
211 register struct buf *bp;
213 afs_int32 returnCode;
215 AFS_STATCNT(osi_MapStrategy);
216 returnCode = (*aproc) (bp);
226 extern int afs_cold_shutdown;
228 AFS_STATCNT(shutdown_osifile);
229 if (afs_cold_shutdown) {
230 afs_osicred_initialized = 0;