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 "../afs/param.h" /* Should be always first */
11 #include "../afs/sysincludes.h" /* Standard vendor system headers */
12 #include "../afs/afsincludes.h" /* Afs-based standard headers */
13 #include "../afs/afs_stats.h" /* afs statistics */
15 int afs_osicred_initialized=0;
16 struct AFS_UCRED afs_osi_cred;
17 afs_lock_t afs_xosi; /* lock is for tvattr */
18 extern struct osi_dev cacheDev;
19 extern struct vfs *afs_cacheVfsp;
22 /* As of 6.2, we support either XFS or EFS clients. osi_UFSOpen
23 * now vectors to the correct EFS or XFS function. If new functionality is
24 * added which accesses the inode, that will also need EFS/XFS variants.
26 vnode_t *afs_EFSIGetVnode(ino_t ainode)
31 if ((error = igetinode(afs_cacheVfsp, (dev_t)cacheDev.dev, ainode, &ip))) {
32 osi_Panic("afs_EFSIGetVnode: igetinode failed, error=%d", error);
34 /* We don't care about atimes on the cache files, so disable them. I'm not
35 * sure that this is the right place to do this: it should be *after* readi
36 * and getattr and stuff.
38 ip->i_flags &= ~(ISYN|IACC);
40 return (EFS_ITOV(ip));
43 vnode_t *afs_XFSIGetVnode(ino_t ainode)
50 xfs_igetinode(afs_cacheVfsp, (dev_t)cacheDev.dev, ainode, &ip))) {
51 osi_Panic("afs_XFSIGetVnode: xfs_igetinode failed, error=%d", error);
57 /* Force to 64 bits, even for EFS filesystems. */
58 void *osi_UFSOpen(ino_t ainode)
61 register struct osi_file *afile = NULL;
62 extern int cacheDiskType;
65 AFS_STATCNT(osi_UFSOpen);
66 if(cacheDiskType != AFS_FCACHE_TYPE_UFS) {
67 osi_Panic("UFSOpen called for non-UFS cache\n");
69 if (!afs_osicred_initialized) {
70 /* valid for alpha_osf, SunOS, Ultrix */
71 bzero((char *)&afs_osi_cred, sizeof(struct AFS_UCRED));
72 crhold(&afs_osi_cred); /* don't let it evaporate, since it is static */
73 afs_osicred_initialized = 1;
75 afile = (struct osi_file *) osi_AllocSmallSpace(sizeof(struct osi_file));
77 afile->vnode = AFS_SGI_IGETVNODE(ainode);
79 afile->size = VnodeToSize(afile->vnode);
81 afile->proc = (int (*)()) 0;
82 afile->inum = ainode; /* for hint validity checking */
86 afs_osi_Stat(afile, astat)
87 register struct osi_file *afile;
88 register struct osi_stat *astat; {
89 register afs_int32 code;
91 AFS_STATCNT(osi_Stat);
92 MObtainWriteLock(&afs_xosi,320);
94 tvattr.va_mask = AT_SIZE|AT_BLKSIZE|AT_MTIME|AT_ATIME;
95 AFS_VOP_GETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, code);
98 astat->size = tvattr.va_size;
99 astat->blksize = tvattr.va_blocksize;
100 astat->mtime = tvattr.va_mtime.tv_sec;
101 astat->atime = tvattr.va_atime.tv_sec;
103 MReleaseWriteLock(&afs_xosi);
108 register struct osi_file *afile;
110 AFS_STATCNT(osi_Close);
112 VN_RELE(afile->vnode);
115 osi_FreeSmallSpace(afile);
119 osi_UFSTruncate(afile, asize)
120 register struct osi_file *afile;
122 struct AFS_UCRED *oldCred;
124 register afs_int32 code;
125 struct osi_stat tstat;
127 AFS_STATCNT(osi_Truncate);
129 /* This routine only shrinks files, and most systems
130 * have very slow truncates, even when the file is already
131 * small enough. Check now and save some time.
133 code = afs_osi_Stat(afile, &tstat);
134 if (code || tstat.size <= asize) return code;
135 MObtainWriteLock(&afs_xosi,321);
137 tvattr.va_mask = AT_SIZE;
138 tvattr.va_size = asize;
139 AFS_VOP_SETATTR(afile->vnode, &tvattr, 0, &afs_osi_cred, code);
141 MReleaseWriteLock(&afs_xosi);
145 void osi_DisableAtimes(avp)
148 if (afs_CacheFSType == AFS_SGI_EFS_CACHE)
150 struct inode *ip = EFS_VTOI(avp);
151 ip->i_flags &= ~IACC;
157 /* Generic read interface */
158 afs_osi_Read(afile, offset, aptr, asize)
159 register struct osi_file *afile;
163 struct AFS_UCRED *oldCred;
165 register afs_int32 code;
166 register afs_int32 cnt1=0;
167 AFS_STATCNT(osi_Read);
170 * If the osi_file passed in is NULL, panic only if AFS is not shutting
171 * down. No point in crashing when we are already shutting down
174 if ( !afs_shuttingdown )
175 osi_Panic("osi_Read called with null param");
180 if (offset != -1) afile->offset = offset;
182 code = gop_rdwr(UIO_READ, afile->vnode, (caddr_t) aptr, asize, afile->offset,
183 AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred, &resid);
186 code = asize - resid;
187 afile->offset += code;
188 osi_DisableAtimes(afile->vnode);
191 afs_Trace2(afs_iclSetp, CM_TRACE_READFAILED, ICL_TYPE_INT32, resid,
192 ICL_TYPE_INT32, code);
198 /* Generic write interface */
199 afs_osi_Write(afile, offset, aptr, asize)
200 register struct osi_file *afile;
204 struct AFS_UCRED *oldCred;
206 register afs_int32 code;
207 AFS_STATCNT(osi_Write);
209 osi_Panic("afs_osi_Write called with null param");
210 if (offset != -1) afile->offset = offset;
212 code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset,
213 AFS_UIOSYS, 0, 0x7fffffff, &afs_osi_cred, &resid);
216 code = asize - resid;
217 afile->offset += code;
220 if (code == ENOSPC) afs_warnuser("\n\n\n*** Cache partition is FULL - Decrease cachesize!!! ***\n\n");
224 (*afile->proc)(afile, code);
230 /* This work should be handled by physstrat in ca/machdep.c.
231 This routine written from the RT NFS port strategy routine.
232 It has been generalized a bit, but should still be pretty clear. */
233 int afs_osi_MapStrategy(aproc, bp)
235 register struct buf *bp;
237 afs_int32 returnCode;
239 AFS_STATCNT(osi_MapStrategy);
240 returnCode = (*aproc) (bp);
250 extern int afs_cold_shutdown;
252 AFS_STATCNT(shutdown_osifile);
253 if (afs_cold_shutdown) {
254 afs_osicred_initialized = 0;