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_t 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;
56 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
58 register afs_int32 code;
60 AFS_STATCNT(osi_Stat);
61 ObtainWriteLock(&afs_xosi, 320);
63 VOP_GETATTR(afile->vnode, &tvattr, afs_osi_credp, code);
66 astat->size = tvattr.va_size;
67 astat->mtime = tvattr.va_mtime.tv_sec;
68 astat->atime = tvattr.va_atime.tv_sec;
70 ReleaseWriteLock(&afs_xosi);
75 osi_UFSClose(register struct osi_file *afile)
77 AFS_STATCNT(osi_Close);
79 AFS_RELE(afile->vnode);
82 osi_FreeSmallSpace(afile);
87 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
91 register afs_int32 code;
92 struct osi_stat tstat;
93 AFS_STATCNT(osi_Truncate);
95 /* This routine only shrinks files, and most systems
96 * have very slow truncates, even when the file is already
97 * small enough. Check now and save some time.
99 code = afs_osi_Stat(afile, &tstat);
100 if (code || tstat.size <= asize)
102 ObtainWriteLock(&afs_xosi, 321);
104 /* note that this credential swapping stuff is only necessary because
105 * of ufs's references directly to cred instead of to
106 * credentials parameter. Probably should fix ufs some day. */
107 oldCred = curproc->p_cred->pc_ucred; /* remember old credentials pointer */
108 curproc->p_cred->pc_ucred = afs_osi_credp;
109 /* temporarily use superuser credentials */
110 tvattr.va_size = asize;
112 VOP_SETATTR(afile->vnode, &tvattr, afs_osi_credp, code);
114 curproc->p_cred->pc_ucred = oldCred; /* restore */
115 ReleaseWriteLock(&afs_xosi);
120 osi_DisableAtimes(struct vnode *avp)
122 struct inode *ip = VTOI(avp);
127 /* Generic read interface */
129 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
132 afs_ucred_t *oldCred;
134 register afs_int32 code;
135 register afs_int32 cnt1 = 0;
136 AFS_STATCNT(osi_Read);
139 * If the osi_file passed in is NULL, panic only if AFS is not shutting
140 * down. No point in crashing when we are already shutting down
143 if (!afs_shuttingdown)
144 osi_Panic("osi_Read called with null param");
150 afile->offset = offset;
153 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
154 AFS_UIOSYS, IO_UNIT, afs_osi_credp, &resid);
157 code = asize - resid;
158 afile->offset += code;
159 osi_DisableAtimes(afile->vnode);
161 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
162 ICL_TYPE_INT32, code);
168 /* Generic write interface */
170 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
173 afs_ucred_t *oldCred;
175 register afs_int32 code;
176 AFS_STATCNT(osi_Write);
178 osi_Panic("afs_osi_Write called with null param");
180 afile->offset = offset;
182 struct ucred *tmpcred = curproc->p_cred->pc_ucred;
183 curproc->p_cred->pc_ucred = afs_osi_credp;
186 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
187 afile->offset, AFS_UIOSYS, IO_UNIT, afs_osi_credp,
190 curproc->p_cred->pc_ucred = tmpcred;
193 code = asize - resid;
194 afile->offset += code;
199 (*afile->proc) (afile, code);
205 /* This work should be handled by physstrat in ca/machdep.c.
206 This routine written from the RT NFS port strategy routine.
207 It has been generalized a bit, but should still be pretty clear. */
209 afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
211 afs_int32 returnCode;
213 AFS_STATCNT(osi_MapStrategy);
214 returnCode = (*aproc) (bp);
222 shutdown_osifile(void)
224 AFS_STATCNT(shutdown_osifile);
225 if (afs_cold_shutdown) {
226 afs_osicred_initialized = 0;