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");
54 afile->vnode = ITOV(ip);
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 VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, code);
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;
97 struct AFS_UCRED *oldCred;
99 register afs_int32 code;
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) return code;
109 MObtainWriteLock(&afs_xosi,321);
111 /* note that this credential swapping stuff is only necessary because
112 of ufs's references directly to cred instead of to
113 credentials parameter. Probably should fix ufs some day. */
114 oldCred = curproc->p_cred->pc_ucred; /* remember old credentials pointer */
115 curproc->p_cred->pc_ucred = &afs_osi_cred;
116 /* temporarily use superuser credentials */
117 tvattr.va_size = asize;
119 VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, code);
121 curproc->p_cred->pc_ucred = oldCred; /* restore */
122 MReleaseWriteLock(&afs_xosi);
126 void osi_DisableAtimes(avp)
129 struct inode *ip = VTOI(avp);
134 /* Generic read interface */
135 afs_osi_Read(afile, offset, aptr, asize)
136 register struct osi_file *afile;
140 struct AFS_UCRED *oldCred;
142 register afs_int32 code;
143 register afs_int32 cnt1=0;
144 AFS_STATCNT(osi_Read);
147 * If the osi_file passed in is NULL, panic only if AFS is not shutting
148 * down. No point in crashing when we are already shutting down
151 if ( !afs_shuttingdown )
152 osi_Panic("osi_Read called with null param");
157 if (offset != -1) afile->offset = offset;
159 code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
160 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
163 code = asize - resid;
164 afile->offset += code;
165 osi_DisableAtimes(afile->vnode);
168 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
169 ICL_TYPE_INT32, code);
175 /* Generic write interface */
176 afs_osi_Write(afile, offset, aptr, asize)
177 register struct osi_file *afile;
181 struct AFS_UCRED *oldCred;
183 register afs_int32 code;
184 AFS_STATCNT(osi_Write);
186 osi_Panic("afs_osi_Write called with null param");
187 if (offset != -1) afile->offset = offset;
189 struct ucred *tmpcred = curproc->p_cred->pc_ucred;
190 curproc->p_cred->pc_ucred = &afs_osi_cred;
192 code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
193 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
195 curproc->p_cred->pc_ucred = tmpcred;
198 code = asize - resid;
199 afile->offset += code;
205 (*afile->proc)(afile, code);
211 /* This work should be handled by physstrat in ca/machdep.c.
212 This routine written from the RT NFS port strategy routine.
213 It has been generalized a bit, but should still be pretty clear. */
214 int afs_osi_MapStrategy(aproc, bp)
216 register struct buf *bp;
218 afs_int32 returnCode;
220 AFS_STATCNT(osi_MapStrategy);
221 returnCode = (*aproc) (bp);
231 extern int afs_cold_shutdown;
233 AFS_STATCNT(shutdown_osifile);
234 if (afs_cold_shutdown) {
235 afs_osicred_initialized = 0;