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 */
17 #include "afs/osi_inode.h" /* igetinode() */
20 int afs_osicred_initialized
= 0;
21 afs_ucred_t afs_osi_cred
;
22 extern struct osi_dev cacheDev
;
23 extern struct vfs
*afs_cacheVfsp
;
27 osi_UFSOpen(afs_dcache_id_t
*ainode
)
30 struct osi_file
*afile
= NULL
;
31 extern int cacheDiskType
;
34 AFS_STATCNT(osi_UFSOpen
);
35 if (cacheDiskType
!= AFS_FCACHE_TYPE_UFS
) {
36 osi_Panic("UFSOpen called for non-UFS cache\n");
38 if (!afs_osicred_initialized
) {
39 /* valid for alpha_osf, SunOS, Ultrix */
40 memset(&afs_osi_cred
, 0, sizeof(afs_ucred_t
));
41 crhold(&afs_osi_cred
); /* don't let it evaporate, since it is static */
42 afs_osicred_initialized
= 1;
44 afile
= osi_AllocSmallSpace(sizeof(struct osi_file
));
47 ip
= (struct inode
*)igetinode(afs_cacheVfsp
, (dev_t
) cacheDev
.dev
,
48 (ino_t
) ainode
->ufs
, &dummy
);
51 osi_FreeSmallSpace(afile
);
52 osi_Panic("UFSOpen: igetinode failed");
55 afile
->vnode
= ITOV(ip
);
56 afile
->size
= VTOI(afile
->vnode
)->i_size
;
58 afile
->proc
= (int (*)())0;
63 afs_osi_Stat(struct osi_file
*afile
, struct osi_stat
*astat
)
67 AFS_STATCNT(osi_Stat
);
69 code
= VOP_GETATTR(afile
->vnode
, &tvattr
, &afs_osi_cred
, VSYNC
);
72 astat
->size
= tvattr
.va_size
;
73 astat
->mtime
= tvattr
.va_mtime
.tv_sec
;
74 astat
->atime
= tvattr
.va_atime
.tv_sec
;
80 osi_UFSClose(struct osi_file
*afile
)
82 AFS_STATCNT(osi_Close
);
84 AFS_RELE(afile
->vnode
);
87 osi_FreeSmallSpace(afile
);
92 osi_UFSTruncate(struct osi_file
*afile
, afs_int32 asize
)
97 struct osi_stat tstat
;
98 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
)
108 /* note that this credential swapping stuff is only necessary because
109 * of ufs's references directly to u.u_cred instead of to
110 * credentials parameter. Probably should fix ufs some day. */
111 oldCred
= p_cred(u
.u_procp
);
112 set_p_cred(u
.u_procp
, &afs_osi_cred
);
113 tvattr
.va_size
= asize
;
115 code
= VOP_SETATTR(afile
->vnode
, &tvattr
, &afs_osi_cred
, 0);
117 set_p_cred(u
.u_procp
, oldCred
); /* restore */
122 osi_DisableAtimes(struct vnode
*avp
)
124 struct inode
*ip
= VTOI(avp
);
129 /* Generic read interface */
131 afs_osi_Read(struct osi_file
*afile
, int offset
, void *aptr
,
134 afs_ucred_t
*oldCred
;
138 AFS_STATCNT(osi_Read
);
141 * If the osi_file passed in is NULL, panic only if AFS is not shutting
142 * down. No point in crashing when we are already shutting down
145 if (afs_shuttingdown
== AFS_RUNNING
)
146 osi_Panic("osi_Read called with null param");
152 afile
->offset
= offset
;
156 gop_rdwr(UIO_READ
, afile
->vnode
, (caddr_t
) aptr
, asize
, afile
->offset
,
157 AFS_UIOSYS
, IO_UNIT
, &resid
);
160 code
= asize
- resid
;
161 afile
->offset
+= code
;
162 osi_DisableAtimes(afile
->vnode
);
164 afs_Trace2(afs_iclSetp
, CM_TRACE_READFAILED
, ICL_TYPE_INT32
,
165 (afs_int32
) resid
, ICL_TYPE_INT32
, code
);
167 * To handle periodic low-level EFAULT failures that we've seen with the
168 * Weitek chip; in all observed failed cases a second read succeeded.
170 if ((code
== EFAULT
) && (cnt1
++ < 5)) {
171 afs_stats_cmperf
.osiread_efaults
++;
182 /* Generic write interface */
184 afs_osi_Write(struct osi_file
*afile
, afs_int32 offset
, void *aptr
,
187 afs_ucred_t
*oldCred
;
190 AFS_STATCNT(osi_Write
);
192 osi_Panic("afs_osi_Write called with null param");
194 afile
->offset
= offset
;
197 gop_rdwr(UIO_WRITE
, afile
->vnode
, (caddr_t
) aptr
, asize
,
198 afile
->offset
, AFS_UIOSYS
, IO_UNIT
, &resid
);
201 code
= asize
- resid
;
202 afile
->offset
+= code
;
212 (*afile
->proc
) (afile
, code
);
219 shutdown_osifile(void)
221 AFS_STATCNT(shutdown_osifile
);
222 if (afs_cold_shutdown
) {
223 afs_osicred_initialized
= 0;