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"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
15 #include "afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h" /* afs statistics */
19 int afs_osicred_initialized = 0;
20 AFS_UCRED afs_osi_cred;
21 afs_lock_t afs_xosi; /* lock is for tvattr */
22 extern struct osi_dev cacheDev;
23 extern struct mount *afs_cacheVfsp;
27 osi_UFSOpen(afs_dcache_id_t *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");
37 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
40 igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, ainode->ufs, &ip,
44 osi_FreeSmallSpace(afile);
45 osi_Panic("UFSOpen: igetinode failed");
48 afile->vnode = ITOV(ip);
49 afile->size = VTOI(afile->vnode)->i_size;
51 afile->proc = (int (*)())0;
52 afile->inum = ainode->ufs; /* for hint validity checking */
57 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
59 register afs_int32 code;
61 AFS_STATCNT(osi_Stat);
62 MObtainWriteLock(&afs_xosi, 320);
64 VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, code);
67 astat->size = tvattr.va_size;
68 astat->mtime = tvattr.va_mtime.tv_sec;
69 astat->atime = tvattr.va_atime.tv_sec;
71 MReleaseWriteLock(&afs_xosi);
76 osi_UFSClose(register struct osi_file *afile)
78 AFS_STATCNT(osi_Close);
80 AFS_RELE(afile->vnode);
83 osi_FreeSmallSpace(afile);
88 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
92 register afs_int32 code;
93 struct osi_stat tstat;
94 AFS_STATCNT(osi_Truncate);
96 /* This routine only shrinks files, and most systems
97 * have very slow truncates, even when the file is already
98 * small enough. Check now and save some time.
100 code = afs_osi_Stat(afile, &tstat);
101 if (code || tstat.size <= asize)
103 MObtainWriteLock(&afs_xosi, 321);
105 /* note that this credential swapping stuff is only necessary because
106 * of ufs's references directly to cred instead of to
107 * credentials parameter. Probably should fix ufs some day. */
108 oldCred = curproc->p_cred->pc_ucred; /* remember old credentials pointer */
109 curproc->p_cred->pc_ucred = afs_osi_credp;
110 /* temporarily use superuser credentials */
111 tvattr.va_size = asize;
113 VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp, code);
115 curproc->p_cred->pc_ucred = oldCred; /* restore */
116 MReleaseWriteLock(&afs_xosi);
121 osi_DisableAtimes(struct vnode *avp)
123 struct inode *ip = VTOI(avp);
128 /* Generic read interface */
130 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
135 register afs_int32 code;
136 register afs_int32 cnt1 = 0;
137 AFS_STATCNT(osi_Read);
140 * If the osi_file passed in is NULL, panic only if AFS is not shutting
141 * down. No point in crashing when we are already shutting down
144 if (!afs_shuttingdown)
145 osi_Panic("osi_Read called with null param");
151 afile->offset = offset;
154 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
155 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid);
158 code = asize - resid;
159 afile->offset += code;
160 osi_DisableAtimes(afile->vnode);
162 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
163 ICL_TYPE_INT32, code);
169 /* Generic write interface */
171 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
176 register afs_int32 code;
177 AFS_STATCNT(osi_Write);
179 osi_Panic("afs_osi_Write called with null param");
181 afile->offset = offset;
183 struct ucred *tmpcred = curproc->p_cred->pc_ucred;
184 curproc->p_cred->pc_ucred = afs_osi_credp;
187 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
188 afile->offset, AFS_UIOSYS, IO_UNIT, afs_osi_credp,
191 curproc->p_cred->pc_ucred = tmpcred;
194 code = asize - resid;
195 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. */
210 afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
212 afs_int32 returnCode;
214 AFS_STATCNT(osi_MapStrategy);
215 returnCode = (*aproc) (bp);
223 shutdown_osifile(void)
225 AFS_STATCNT(shutdown_osifile);
226 if (afs_cold_shutdown) {
227 afs_osicred_initialized = 0;