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 "afsincludes.h" /* Afs-based standard headers */
16 #include "afs/afs_stats.h" /* afs statistics */
18 afs_ucred_t afs_osi_cred
;
19 int afs_osicred_initialized
= 0;
20 extern struct osi_dev cacheDev
;
21 extern struct vfs
*afs_cacheVfsp
;
24 afs_XFSIGetVnode(ino_t ainode
)
31 xfs_igetinode(afs_cacheVfsp
, (dev_t
) cacheDev
.dev
, ainode
, &ip
))) {
32 osi_Panic("afs_XFSIGetVnode: xfs_igetinode failed, error=%d", error
);
38 /* Force to 64 bits, even for EFS filesystems. */
40 osi_UFSOpen(afs_dcache_id_t
*ainode
)
43 struct osi_file
*afile
= NULL
;
44 extern int cacheDiskType
;
47 AFS_STATCNT(osi_UFSOpen
);
48 if (cacheDiskType
!= AFS_FCACHE_TYPE_UFS
) {
49 osi_Panic("UFSOpen called for non-UFS cache\n");
51 if (!afs_osicred_initialized
) {
52 /* valid for alpha_osf, SunOS, Ultrix */
53 memset(&afs_osi_cred
, 0, sizeof(afs_ucred_t
));
54 crhold(&afs_osi_cred
); /* don't let it evaporate, since it is static */
55 afs_osicred_initialized
= 1;
57 afile
= osi_AllocSmallSpace(sizeof(struct osi_file
));
59 afile
->vnode
= afs_XFSIGetVnode(ainode
->ufs
);
61 afile
->size
= VnodeToSize(afile
->vnode
);
63 afile
->proc
= (int (*)())0;
68 afs_osi_Stat(struct osi_file
*afile
, struct osi_stat
*astat
)
72 AFS_STATCNT(osi_Stat
);
74 tvattr
.va_mask
= AT_SIZE
| AT_BLKSIZE
| AT_MTIME
| AT_ATIME
;
75 AFS_VOP_GETATTR(afile
->vnode
, &tvattr
, 0, &afs_osi_cred
, code
);
78 astat
->size
= tvattr
.va_size
;
79 astat
->mtime
= tvattr
.va_mtime
.tv_sec
;
80 astat
->atime
= tvattr
.va_atime
.tv_sec
;
86 osi_UFSClose(struct osi_file
*afile
)
88 AFS_STATCNT(osi_Close
);
90 VN_RELE(afile
->vnode
);
93 osi_FreeSmallSpace(afile
);
98 osi_UFSTruncate(struct osi_file
*afile
, afs_int32 asize
)
100 afs_ucred_t
*oldCred
;
103 struct osi_stat tstat
;
105 AFS_STATCNT(osi_Truncate
);
107 /* This routine only shrinks files, and most systems
108 * have very slow truncates, even when the file is already
109 * small enough. Check now and save some time.
111 code
= afs_osi_Stat(afile
, &tstat
);
112 if (code
|| tstat
.size
<= asize
)
115 tvattr
.va_mask
= AT_SIZE
;
116 tvattr
.va_size
= asize
;
117 AFS_VOP_SETATTR(afile
->vnode
, &tvattr
, 0, &afs_osi_cred
, code
);
123 /* Generic read interface */
125 afs_osi_Read(struct osi_file
*afile
, int offset
, void *aptr
,
128 afs_ucred_t
*oldCred
;
132 AFS_STATCNT(osi_Read
);
135 * If the osi_file passed in is NULL, panic only if AFS is not shutting
136 * down. No point in crashing when we are already shutting down
139 if (afs_shuttingdown
== AFS_RUNNING
)
140 osi_Panic("osi_Read called with null param");
146 afile
->offset
= offset
;
149 gop_rdwr(UIO_READ
, afile
->vnode
, (caddr_t
) aptr
, asize
, afile
->offset
,
150 AFS_UIOSYS
, 0, 0x7fffffff, &afs_osi_cred
, &resid
);
153 code
= asize
- resid
;
154 afile
->offset
+= code
;
156 afs_Trace2(afs_iclSetp
, CM_TRACE_READFAILED
, ICL_TYPE_INT32
, resid
,
157 ICL_TYPE_INT32
, code
);
165 /* Generic write interface */
167 afs_osi_Write(struct osi_file
*afile
, afs_int32 offset
, void *aptr
,
170 afs_ucred_t
*oldCred
;
173 AFS_STATCNT(osi_Write
);
175 osi_Panic("afs_osi_Write called with null param");
177 afile
->offset
= offset
;
180 gop_rdwr(UIO_WRITE
, afile
->vnode
, (caddr_t
) aptr
, asize
,
181 afile
->offset
, AFS_UIOSYS
, 0, 0x7fffffff, &afs_osi_cred
,
185 code
= asize
- resid
;
186 afile
->offset
+= code
;
195 (*afile
->proc
) (afile
, code
);
201 /* This work should be handled by physstrat in ca/machdep.c.
202 This routine written from the RT NFS port strategy routine.
203 It has been generalized a bit, but should still be pretty clear. */
205 afs_osi_MapStrategy(int (*aproc
) (), struct buf
*bp
)
207 afs_int32 returnCode
;
209 AFS_STATCNT(osi_MapStrategy
);
210 returnCode
= (*aproc
) (bp
);
218 shutdown_osifile(void)
220 AFS_STATCNT(shutdown_osifile
);
221 if (afs_cold_shutdown
) {
222 afs_osicred_initialized
= 0;