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 "afs/afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h" /* afs statistics */
19 int afs_osicred_initialized
;
20 afs_ucred_t afs_osi_cred
;
21 extern struct osi_dev cacheDev
;
22 extern struct mount
*afs_cacheVfsp
;
26 osi_UFSOpen(afs_dcache_id_t
*ainode
)
28 struct osi_file
*afile
;
30 extern int cacheDiskType
;
33 AFS_STATCNT(osi_UFSOpen
);
34 if (cacheDiskType
!= AFS_FCACHE_TYPE_UFS
)
35 osi_Panic("UFSOpen called for non-UFS cache\n");
36 afile
= osi_AllocSmallSpace(sizeof(struct osi_file
));
38 code
= VFS_VGET(cacheDev
.mp
, ainode
->ufs
, &vp
);
40 if (code
== 0 && vp
->v_type
== VNON
)
43 osi_FreeSmallSpace(afile
);
44 osi_Panic("UFSOpen: igetinode failed");
46 VOP_UNLOCK(vp
, 0, curproc
);
49 afile
->size
= VTOI(vp
)->i_ffs1_size
;
51 afile
->size
= VTOI(vp
)->i_ffs_size
;
59 afs_osi_Stat(struct osi_file
*afile
, struct osi_stat
*astat
)
64 AFS_STATCNT(osi_Stat
);
66 code
= VOP_GETATTR(afile
->vnode
, &tvattr
, afs_osi_credp
, curproc
);
69 astat
->size
= afile
->size
= tvattr
.va_size
;
70 astat
->mtime
= tvattr
.va_mtime
.tv_sec
;
71 astat
->atime
= tvattr
.va_atime
.tv_sec
;
77 osi_UFSClose(struct osi_file
*afile
)
79 AFS_STATCNT(osi_Close
);
82 AFS_RELE(afile
->vnode
);
84 osi_FreeSmallSpace(afile
);
89 osi_UFSTruncate(struct osi_file
*afile
, afs_int32 asize
)
93 struct osi_stat tstat
;
95 AFS_STATCNT(osi_Truncate
);
98 * This routine only shrinks files, and most systems
99 * have very slow truncates, even when the file is already
100 * small enough. Check now and save some time.
102 code
= afs_osi_Stat(afile
, &tstat
);
103 if (code
|| tstat
.size
<= asize
)
107 tvattr
.va_size
= asize
;
109 VOP_LOCK(afile
->vnode
, LK_EXCLUSIVE
| LK_RETRY
, curproc
);
110 code
= VOP_SETATTR(afile
->vnode
, &tvattr
, afs_osi_credp
, curproc
);
111 VOP_UNLOCK(afile
->vnode
, 0, curproc
);
119 osi_DisableAtimes(struct vnode
*avp
)
122 VTOI(avp
)->i_flag
&= ~IN_ACCESS
;
127 /* Generic read interface */
129 afs_osi_Read(struct osi_file
*afile
, int offset
, void *aptr
, afs_int32 asize
)
134 AFS_STATCNT(osi_Read
);
137 * If the osi_file passed in is NULL, panic only if AFS is not shutting
138 * down. No point in crashing when we are already shutting down
141 if (afs_shuttingdown
== AFS_RUNNING
)
142 osi_Panic("osi_Read called with null param");
148 afile
->offset
= offset
;
151 vn_rdwr(UIO_READ
, afile
->vnode
, aptr
, asize
, afile
->offset
,
152 AFS_UIOSYS
, IO_UNIT
, afs_osi_credp
, &resid
, curproc
);
155 code
= asize
- resid
;
156 afile
->offset
+= code
;
157 osi_DisableAtimes(afile
->vnode
);
159 afs_Trace2(afs_iclSetp
, CM_TRACE_READFAILED
, ICL_TYPE_INT32
,
160 (unsigned int) resid
, ICL_TYPE_INT32
, code
);
168 /* Generic write interface */
170 afs_osi_Write(struct osi_file
*afile
, afs_int32 offset
, void *aptr
,
176 AFS_STATCNT(osi_Write
);
178 osi_Panic("afs_osi_Write called with null afile");
180 afile
->offset
= offset
;
183 VOP_LOCK(afile
->vnode
, LK_EXCLUSIVE
| LK_RETRY
, curproc
);
185 vn_rdwr(UIO_WRITE
, afile
->vnode
, (caddr_t
) aptr
, asize
, afile
->offset
,
186 AFS_UIOSYS
, IO_UNIT
, afs_osi_credp
, &resid
, curproc
);
187 VOP_UNLOCK(afile
->vnode
, 0, curproc
);
191 code
= asize
- resid
;
192 afile
->offset
+= code
;
193 if (afile
->offset
> afile
->size
)
194 afile
->size
= afile
->offset
;
202 (*afile
->proc
) (afile
, code
);
208 * This work should be handled by physstrat in ca/machdep.c. This routine
209 * written from the RT NFS port strategy routine. It has been generalized a
210 * bit, but should still be pretty clear.
213 afs_osi_MapStrategy(int (*aproc
) (), struct buf
*bp
)
215 afs_int32 returnCode
;
217 AFS_STATCNT(osi_MapStrategy
);
218 returnCode
= (*aproc
) (bp
);
224 shutdown_osifile(void)
226 AFS_STATCNT(shutdown_osifile
);
227 if (afs_cold_shutdown
)
228 afs_osicred_initialized
= 0;