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
15 #include <afsconfig.h>
16 #include "afs/param.h"
19 #if !defined(AFS_HPUX_ENV) && !defined(AFS_SGI_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN80_ENV)
21 #include "afs/sysincludes.h" /* Standard vendor system headers */
22 #include "afsincludes.h" /* Afs-based standard headers */
23 #include "afs/afs_stats.h" /* statistics */
24 #include "afs/afs_cbqueue.h"
25 #include "afs/nfsclient.h"
26 #include "afs/afs_osidnlc.h"
30 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
31 int afs_ustrategy(register struct buf *abp, afs_ucred_t *credp)
33 int afs_ustrategy(register struct buf *abp)
36 register afs_int32 code;
38 struct iovec tiovec[1];
39 register struct vcache *tvc = VTOAFS(abp->b_vp);
40 register afs_int32 len = abp->b_bcount;
41 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
45 afs_ucred_t *credp = u.u_cred;
49 AFS_STATCNT(afs_ustrategy);
52 * So that it won't change while reading it
54 ObtainReadLock(&tvc->lock);
61 ReleaseReadLock(&tvc->lock);
65 if (abp->b_iocmd == BIO_READ) {
67 if ((abp->b_flags & B_READ) == B_READ) {
69 /* read b_bcount bytes into kernel address b_un.b_addr starting
70 * at byte DEV_BSIZE * b_blkno. Bzero anything we can't read,
71 * and finally call iodone(abp). File is in abp->b_vp. Credentials
74 tuio.afsio_iov = tiovec;
75 tuio.afsio_iovcnt = 1;
76 #if defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_XBSD_ENV)
77 #ifdef AFS_64BIT_CLIENT
79 tuio.afsio_offset = (afs_offs_t) ldbtob(abp->b_lblkno);
81 tuio.afsio_offset = (afs_offs_t) dbtob(abp->b_blkno);
83 #else /* AFS_64BIT_CLIENT */
84 tuio.afsio_offset = (u_int) dbtob(abp->b_blkno);
85 #endif /* AFS_64BIT_CLIENT */
87 tuio.afsio_offset = DEV_BSIZE * abp->b_blkno;
89 tuio.afsio_seg = AFS_UIOSYS;
93 tuio.afsio_resid = abp->b_bcount;
94 #if defined(AFS_XBSD_ENV)
95 tiovec[0].iov_base = abp->b_saveaddr;
97 tiovec[0].iov_base = abp->b_un.b_addr;
98 #endif /* AFS_XBSD_ENV */
99 tiovec[0].iov_len = abp->b_bcount;
100 /* are user's credentials valid here? probably, but this
101 * sure seems like the wrong things to do. */
102 #if defined(AFS_SUN5_ENV)
103 code = afs_nlrdwr(VTOAFS(abp->b_vp), &tuio, UIO_READ, 0, credp);
105 code = afs_rdwr(VTOAFS(abp->b_vp), &tuio, UIO_READ, 0, credp);
108 if (tuio.afsio_resid > 0)
109 #if defined(AFS_XBSD_ENV)
110 memset(abp->b_saveaddr + abp->b_bcount - tuio.afsio_resid, 0,
113 memset(abp->b_un.b_addr + abp->b_bcount - tuio.afsio_resid, 0,
115 #endif /* AFS_XBSD_ENV */
118 * If we read a block that is past EOF and the user was not storing
119 * to it, go ahead and write protect the page. This way we will detect
120 * storing beyond EOF in the future
122 if (dbtob(abp->b_blkno) + abp->b_bcount > tvc->f.m.Length) {
123 if ((abp->b_flags & B_PFSTORE) == 0) {
125 vm_protectp(tvc->segid, dbtob(abp->b_blkno) / PAGESIZE,
126 abp->b_bcount / PAGESIZE, RDONLY);
133 tuio.afsio_iov = tiovec;
134 tuio.afsio_iovcnt = 1;
135 #if defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV)
136 #ifdef AFS_64BIT_CLIENT
138 tuio.afsio_offset = (afs_offs_t) ldbtob(abp->b_lblkno);
140 tuio.afsio_offset = (afs_offs_t) dbtob(abp->b_blkno);
142 #else /* AFS_64BIT_CLIENT */
143 tuio.afsio_offset = (u_int) dbtob(abp->b_blkno);
144 #endif /* AFS_64BIT_CLIENT */
147 tuio.uio_limit = curproc->p_fsz_ctl.rlim_cur;
149 tuio.uio_limit = u.u_rlimit[RLIMIT_FSIZE].rlim_cur;
153 tuio.afsio_offset = DEV_BSIZE * abp->b_blkno;
155 tuio.afsio_seg = AFS_UIOSYS;
157 tuio.afsio_fmode = 0;
161 * XXX It this really right? Ideally we should always write block size multiple
162 * and not any arbitrary size, right? XXX
164 len = MIN(len, tvc->f.m.Length - dbtob(abp->b_blkno));
169 (VTOAFS(abp->b_vp))->f.m.Length - dbtob(abp->b_blkno));
170 #endif /* AFS_OSF_ENV */
171 tuio.afsio_resid = len;
172 #if defined(AFS_XBSD_ENV)
173 tiovec[0].iov_base = abp->b_saveaddr;
175 tiovec[0].iov_base = abp->b_un.b_addr;
176 #endif /* AFS_XBSD_ENV */
177 tiovec[0].iov_len = len;
178 /* are user's credentials valid here? probably, but this
179 * sure seems like the wrong things to do. */
180 #if defined(AFS_SUN5_ENV)
181 code = afs_nlrdwr(VTOAFS(abp->b_vp), &tuio, UIO_WRITE, 0, credp);
183 code = afs_rdwr(VTOAFS(abp->b_vp), &tuio, UIO_WRITE, 0, credp);
187 #if defined(AFS_DUX40_ENV) || defined (AFS_XBSD_ENV)
190 #if !defined(AFS_FBSD50_ENV)
191 abp->b_flags |= B_ERROR;
196 #if defined(AFS_AIX32_ENV)
198 #elif defined(AFS_DUX40_ENV)
200 if (code && !(abp->b_flags & B_READ)) {
201 /* prevent ubc from retrying writes */
203 ubc_invalidate(AFSTOV(tvc)->v_object,
204 (vm_offset_t) dbtob(abp->b_blkno), PAGE_SIZE, B_INVAL);
207 #elif defined(AFS_FBSD60_ENV)
208 (*abp->b_iodone)(abp);
209 #elif defined(AFS_FBSD50_ENV)
211 #elif defined(AFS_XBSD_ENV)
213 #elif !defined(AFS_SUN5_ENV)
217 afs_Trace3(afs_iclSetp, CM_TRACE_STRATEGYDONE, ICL_TYPE_POINTER, tvc,
218 ICL_TYPE_INT32, code, ICL_TYPE_LONG, tuio.afsio_resid);
222 #endif /* !AFS_HPUX_ENV && !AFS_SGI_ENV && !AFS_LINUX20_ENV */