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"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
17 #include "afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h" /* afs statistics */
21 int afs_osicred_initialized = 0;
22 struct AFS_UCRED afs_osi_cred;
23 afs_lock_t afs_xosi; /* lock is for tvattr */
24 extern struct osi_dev cacheDev;
25 extern struct mount *afs_cacheVfsp;
29 osi_UFSOpen(afs_int32 ainode)
32 register struct osi_file *afile = NULL;
33 extern int cacheDiskType;
36 AFS_STATCNT(osi_UFSOpen);
37 if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
38 osi_Panic("UFSOpen called for non-UFS cache\n");
40 if (!afs_osicred_initialized) {
41 /* valid for alpha_osf, SunOS, Ultrix */
42 memset((char *)&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
43 afs_osi_cred.cr_ref++;
44 afs_osicred_initialized = 1;
46 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
49 igetinode(afs_cacheVfsp, (dev_t) cacheDev.dev, (ino_t) ainode, &ip,
53 osi_FreeSmallSpace(afile);
54 osi_Panic("UFSOpen: igetinode failed");
57 afile->vnode = ITOV(ip);
58 afile->size = VTOI(afile->vnode)->i_size;
60 afile->proc = (int (*)())0;
61 afile->inum = ainode; /* for hint validity checking */
66 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
68 register afs_int32 code;
70 AFS_STATCNT(osi_Stat);
71 MObtainWriteLock(&afs_xosi, 320);
73 VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, code);
76 astat->size = tvattr.va_size;
77 astat->blksize = tvattr.va_blocksize;
78 astat->mtime = tvattr.va_mtime.tv_sec;
79 astat->atime = tvattr.va_atime.tv_sec;
81 MReleaseWriteLock(&afs_xosi);
86 osi_UFSClose(register struct osi_file *afile)
88 AFS_STATCNT(osi_Close);
90 AFS_RELE(afile->vnode);
93 osi_FreeSmallSpace(afile);
98 osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
100 struct AFS_UCRED *oldCred;
102 register afs_int32 code;
103 struct osi_stat tstat;
104 AFS_STATCNT(osi_Truncate);
106 /* This routine only shrinks files, and most systems
107 * have very slow truncates, even when the file is already
108 * small enough. Check now and save some time.
110 code = afs_osi_Stat(afile, &tstat);
111 if (code || tstat.size <= asize)
113 MObtainWriteLock(&afs_xosi, 321);
115 /* note that this credential swapping stuff is only necessary because
116 * of ufs's references directly to cred instead of to
117 * credentials parameter. Probably should fix ufs some day. */
118 oldCred = curproc->p_cred->pc_ucred; /* remember old credentials pointer */
119 curproc->p_cred->pc_ucred = &afs_osi_cred;
120 /* temporarily use superuser credentials */
121 tvattr.va_size = asize;
123 VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, code);
125 curproc->p_cred->pc_ucred = oldCred; /* restore */
126 MReleaseWriteLock(&afs_xosi);
131 osi_DisableAtimes(struct vnode *avp)
133 struct inode *ip = VTOI(avp);
138 /* Generic read interface */
140 afs_osi_Read(register struct osi_file *afile, int offset, void *aptr,
143 struct AFS_UCRED *oldCred;
145 register afs_int32 code;
146 register afs_int32 cnt1 = 0;
147 AFS_STATCNT(osi_Read);
150 * If the osi_file passed in is NULL, panic only if AFS is not shutting
151 * down. No point in crashing when we are already shutting down
154 if (!afs_shuttingdown)
155 osi_Panic("osi_Read called with null param");
161 afile->offset = offset;
164 gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
165 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid);
168 code = asize - resid;
169 afile->offset += code;
170 osi_DisableAtimes(afile->vnode);
172 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
173 ICL_TYPE_INT32, code);
179 /* Generic write interface */
181 afs_osi_Write(register struct osi_file *afile, afs_int32 offset, void *aptr,
184 struct AFS_UCRED *oldCred;
186 register afs_int32 code;
187 AFS_STATCNT(osi_Write);
189 osi_Panic("afs_osi_Write called with null param");
191 afile->offset = offset;
193 struct ucred *tmpcred = curproc->p_cred->pc_ucred;
194 curproc->p_cred->pc_ucred = &afs_osi_cred;
197 gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize,
198 afile->offset, AFS_UIOSYS, IO_UNIT, &afs_osi_cred,
201 curproc->p_cred->pc_ucred = tmpcred;
204 code = asize - resid;
205 afile->offset += code;
210 (*afile->proc) (afile, code);
216 /* This work should be handled by physstrat in ca/machdep.c.
217 This routine written from the RT NFS port strategy routine.
218 It has been generalized a bit, but should still be pretty clear. */
220 afs_osi_MapStrategy(int (*aproc) (), register struct buf *bp)
222 afs_int32 returnCode;
224 AFS_STATCNT(osi_MapStrategy);
225 returnCode = (*aproc) (bp);
233 shutdown_osifile(void)
235 extern int afs_cold_shutdown;
237 AFS_STATCNT(shutdown_osifile);
238 if (afs_cold_shutdown) {
239 afs_osicred_initialized = 0;