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"
13 #include "afs/sysincludes.h" /* Standard vendor system headers */
14 #include "afs/afsincludes.h" /* Afs-based standard headers */
15 #include "afs/afs_stats.h" /* afs statistics */
18 int afs_osicred_initialized
;
19 extern struct osi_dev cacheDev
;
20 extern struct mount
*afs_cacheVfsp
;
23 osi_UFSOpen(afs_dcache_id_t
*ainode
)
25 struct osi_file
*afile
;
27 extern int cacheDiskType
;
30 AFS_STATCNT(osi_UFSOpen
);
31 if (cacheDiskType
!= AFS_FCACHE_TYPE_UFS
)
32 osi_Panic("UFSOpen called for non-UFS cache\n");
33 afile
= osi_AllocSmallSpace(sizeof(struct osi_file
));
35 code
= VFS_VGET(cacheDev
.mp
, (ino_t
) ainode
->ufs
, &vp
);
37 if (code
== 0 && vp
->v_type
== VNON
)
40 osi_FreeSmallSpace(afile
);
41 osi_Panic("UFSOpen: igetinode failed");
43 #if defined(AFS_NBSD60_ENV)
49 afile
->size
= VTOI(vp
)->i_ffs1_size
;
56 afs_osi_Stat(struct osi_file
*afile
, struct osi_stat
*astat
)
61 AFS_STATCNT(osi_Stat
);
64 code
= VOP_GETATTR(afile
->vnode
, &tvattr
, afs_osi_credp
);
66 code
= VOP_GETATTR(afile
->vnode
, &tvattr
, afs_osi_credp
,
71 astat
->size
= afile
->size
= tvattr
.va_size
;
72 astat
->mtime
= tvattr
.va_mtime
.tv_sec
;
73 astat
->atime
= tvattr
.va_atime
.tv_sec
;
79 osi_UFSClose(struct osi_file
*afile
)
81 AFS_STATCNT(osi_Close
);
84 AFS_RELE(afile
->vnode
);
86 osi_FreeSmallSpace(afile
);
91 osi_UFSTruncate(struct osi_file
*afile
, afs_int32 asize
)
95 struct osi_stat tstat
;
97 AFS_STATCNT(osi_Truncate
);
100 * This routine only shrinks files, and most systems
101 * have very slow truncates, even when the file is already
102 * small enough. Check now and save some time.
104 code
= afs_osi_Stat(afile
, &tstat
);
105 if (code
|| tstat
.size
<= asize
)
109 tvattr
.va_size
= asize
;
111 VOP_LOCK(afile
->vnode
, LK_EXCLUSIVE
| LK_RETRY
);
112 #ifdef AFS_NBSD50_ENV
113 code
= VOP_SETATTR(afile
->vnode
, &tvattr
, afs_osi_credp
);
115 code
= VOP_SETATTR(afile
->vnode
, &tvattr
, afs_osi_credp
,
118 #ifdef AFS_NBSD60_ENV
119 VOP_UNLOCK(afile
->vnode
);
121 VOP_UNLOCK(afile
->vnode
, 0);
130 osi_DisableAtimes(struct vnode
*avp
)
133 VTOI(avp
)->i_flag
&= ~IN_ACCESS
;
138 /* Generic read interface */
140 afs_osi_Read(struct osi_file
*afile
, int offset
, void *aptr
, afs_int32 asize
)
145 AFS_STATCNT(osi_Read
);
148 * If the osi_file passed in is NULL, panic only if AFS is not shutting
149 * down. No point in crashing when we are already shutting down
152 if (afs_shuttingdown
== AFS_RUNNING
)
153 osi_Panic("osi_Read called with null param");
159 afile
->offset
= offset
;
162 vn_rdwr(UIO_READ
, afile
->vnode
, aptr
, asize
, afile
->offset
,
163 AFS_UIOSYS
, IO_UNIT
, afs_osi_credp
, &resid
,
167 code
= asize
- resid
;
168 afile
->offset
+= code
;
169 osi_DisableAtimes(afile
->vnode
);
171 afs_Trace2(afs_iclSetp
, CM_TRACE_READFAILED
, ICL_TYPE_INT32
, resid
,
172 ICL_TYPE_INT32
, code
);
180 /* Generic write interface */
182 afs_osi_Write(struct osi_file
*afile
, afs_int32 offset
, void *aptr
,
188 AFS_STATCNT(osi_Write
);
190 osi_Panic("afs_osi_Write called with null afile");
192 afile
->offset
= offset
;
196 vn_rdwr(UIO_WRITE
, afile
->vnode
, aptr
, asize
, afile
->offset
,
197 AFS_UIOSYS
, IO_UNIT
, afs_osi_credp
, &resid
, osi_curproc());
201 code
= asize
- resid
;
202 afile
->offset
+= code
;
203 if (afile
->offset
> afile
->size
)
204 afile
->size
= afile
->offset
;
212 (*afile
->proc
) (afile
, code
);
218 * This work should be handled by physstrat in ca/machdep.c. This routine
219 * written from the RT NFS port strategy routine. It has been generalized a
220 * bit, but should still be pretty clear.
223 afs_osi_MapStrategy(int (*aproc
)(struct buf
*), struct buf
*bp
)
225 afs_int32 returnCode
;
227 AFS_STATCNT(osi_MapStrategy
);
228 returnCode
= (*aproc
) (bp
);
234 shutdown_osifile(void)
236 AFS_STATCNT(shutdown_osifile
);
237 if (afs_cold_shutdown
)
238 afs_osicred_initialized
= 0;