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 "afs/afsincludes.h" /* Afs-based standard headers */
18 #include "afs/afs_stats.h" /* afs statistics */
21 int afs_osicred_initialized;
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)
31 struct osi_file *afile;
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");
39 afile = (struct osi_file *)osi_AllocSmallSpace(sizeof(struct osi_file));
40 code = VFS_VGET(cacheDev.mp, (ino_t) ainode, &vp);
42 osi_FreeSmallSpace(afile);
43 osi_Panic("UFSOpen: igetinode failed");
46 afile->size = VTOI(vp)->i_ffs_size;
49 afile->inum = ainode; /* for hint validity checking */
50 VOP_UNLOCK(vp, 0, curproc);
55 afs_osi_Stat(struct osi_file *afile, struct osi_stat *astat)
60 AFS_STATCNT(osi_Stat);
61 MObtainWriteLock(&afs_xosi, 320);
63 code = VOP_GETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
66 astat->size = afile->size = tvattr.va_size;
67 astat->blksize = tvattr.va_blocksize;
68 astat->mtime = tvattr.va_mtime.tv_sec;
69 astat->atime = tvattr.va_atime.tv_sec;
71 MReleaseWriteLock(&afs_xosi);
76 osi_UFSClose(struct osi_file *afile)
78 AFS_STATCNT(osi_Close);
81 AFS_RELE(afile->vnode);
83 osi_FreeSmallSpace(afile);
88 osi_UFSTruncate(struct osi_file *afile, afs_int32 asize)
92 struct osi_stat tstat;
94 AFS_STATCNT(osi_Truncate);
97 * This routine only shrinks files, and most systems
98 * have very slow truncates, even when the file is already
99 * small enough. Check now and save some time.
101 code = afs_osi_Stat(afile, &tstat);
102 if (code || tstat.size <= asize)
105 MObtainWriteLock(&afs_xosi, 321);
107 tvattr.va_size = asize;
109 VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curproc);
110 code = VOP_SETATTR(afile->vnode, &tvattr, &afs_osi_cred, curproc);
111 VOP_UNLOCK(afile->vnode, 0, curproc);
115 MReleaseWriteLock(&afs_xosi);
120 osi_DisableAtimes(struct vnode *avp)
123 VTOI(avp)->i_flag &= ~IN_ACCESS;
128 /* Generic read interface */
130 afs_osi_Read(struct osi_file *afile, int offset, void *aptr, afs_int32 asize)
135 AFS_STATCNT(osi_Read);
138 * If the osi_file passed in is NULL, panic only if AFS is not shutting
139 * down. No point in crashing when we are already shutting down
142 if (!afs_shuttingdown)
143 osi_Panic("osi_Read called with null param");
149 afile->offset = offset;
152 vn_rdwr(UIO_READ, afile->vnode, aptr, asize, afile->offset,
153 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid, curproc);
156 code = asize - resid;
157 afile->offset += code;
158 osi_DisableAtimes(afile->vnode);
160 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
161 ICL_TYPE_INT32, code);
167 /* Generic write interface */
169 afs_osi_Write(struct osi_file *afile, afs_int32 offset, void *aptr,
175 AFS_STATCNT(osi_Write);
177 osi_Panic("afs_osi_Write called with null afile");
179 afile->offset = offset;
182 VOP_LOCK(afile->vnode, LK_EXCLUSIVE | LK_RETRY, curproc);
184 vn_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
185 AFS_UIOSYS, IO_UNIT, &afs_osi_cred, &resid, curproc);
186 VOP_UNLOCK(afile->vnode, 0, curproc);
190 code = asize - resid;
191 afile->offset += code;
192 if (afile->offset > afile->size)
193 afile->size = afile->offset;
198 (*afile->proc) (afile, code);
204 * This work should be handled by physstrat in ca/machdep.c. This routine
205 * written from the RT NFS port strategy routine. It has been generalized a
206 * bit, but should still be pretty clear.
209 afs_osi_MapStrategy(int (*aproc) (), struct buf *bp)
211 afs_int32 returnCode;
213 AFS_STATCNT(osi_MapStrategy);
214 returnCode = (*aproc) (bp);
220 shutdown_osifile(void)
222 AFS_STATCNT(shutdown_osifile);
223 if (afs_cold_shutdown)
224 afs_osicred_initialized = 0;