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"
21 #if !defined(AFS_HPUX_ENV) && !defined(AFS_SGI_ENV) && !defined(AFS_LINUX20_ENV)
23 #include "afs/sysincludes.h" /* Standard vendor system headers */
24 #include "afsincludes.h" /* Afs-based standard headers */
25 #include "afs/afs_stats.h" /* statistics */
26 #include "afs/afs_cbqueue.h"
27 #include "afs/nfsclient.h"
28 #include "afs/afs_osidnlc.h"
33 #if defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
34 afs_ustrategy(abp, credp)
35 struct AFS_UCRED *credp;
39 register struct buf *abp;
41 register afs_int32 code;
43 register struct vcache *tvc = VTOAFS(abp->b_vp);
44 register afs_int32 len = abp->b_bcount;
45 #if !defined(AFS_SUN5_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV)
49 struct AFS_UCRED *credp = u.u_cred;
52 struct iovec tiovec[1];
54 AFS_STATCNT(afs_ustrategy);
57 * So that it won't change while reading it
59 ObtainReadLock(&tvc->lock);
66 ReleaseReadLock(&tvc->lock);
70 if (abp->b_iocmd == BIO_READ) {
72 if ((abp->b_flags & B_READ) == B_READ) {
74 /* read b_bcount bytes into kernel address b_un.b_addr starting
75 * at byte DEV_BSIZE * b_blkno. Bzero anything we can't read,
76 * and finally call iodone(abp). File is in abp->b_vp. Credentials
79 tuio.afsio_iov = tiovec;
80 tuio.afsio_iovcnt = 1;
81 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_XBSD_ENV)
82 #ifdef AFS_64BIT_CLIENT
83 tuio.afsio_offset = (afs_offs_t) dbtob(abp->b_blkno);
84 #else /* AFS_64BIT_CLIENT */
85 tuio.afsio_offset = (u_int) dbtob(abp->b_blkno);
86 #if defined(AFS_SUN5_ENV)
87 tuio._uio_offset._p._u = 0;
89 #endif /* AFS_64BIT_CLIENT */
91 tuio.afsio_offset = DEV_BSIZE * abp->b_blkno;
93 tuio.afsio_seg = AFS_UIOSYS;
97 tuio.afsio_resid = abp->b_bcount;
98 #if defined(AFS_XBSD_ENV)
99 tiovec[0].iov_base = abp->b_saveaddr;
101 tiovec[0].iov_base = abp->b_un.b_addr;
102 #endif /* AFS_XBSD_ENV */
103 tiovec[0].iov_len = abp->b_bcount;
104 /* are user's credentials valid here? probably, but this
105 * sure seems like the wrong things to do. */
106 #if defined(AFS_SUN5_ENV)
107 code = afs_nlrdwr(VTOAFS(abp->b_vp), &tuio, UIO_READ, 0, credp);
109 code = afs_rdwr(VTOAFS(abp->b_vp), &tuio, UIO_READ, 0, credp);
112 if (tuio.afsio_resid > 0)
113 #if defined(AFS_XBSD_ENV)
114 memset(abp->b_saveaddr + abp->b_bcount - tuio.afsio_resid, 0,
117 memset(abp->b_un.b_addr + abp->b_bcount - tuio.afsio_resid, 0,
119 #endif /* AFS_XBSD_ENV */
122 * If we read a block that is past EOF and the user was not storing
123 * to it, go ahead and write protect the page. This way we will detect
124 * storing beyond EOF in the future
126 if (dbtob(abp->b_blkno) + abp->b_bcount > tvc->m.Length) {
127 if ((abp->b_flags & B_PFSTORE) == 0) {
129 vm_protectp(tvc->segid, dbtob(abp->b_blkno) / PAGESIZE,
130 abp->b_bcount / PAGESIZE, RDONLY);
137 tuio.afsio_iov = tiovec;
138 tuio.afsio_iovcnt = 1;
139 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
140 #ifdef AFS_64BIT_CLIENT
141 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);
145 tuio._uio_offset._p._u = 0;
147 #endif /* AFS_64BIT_CLIENT */
150 tuio.uio_limit = curproc->p_fsz_ctl.rlim_cur;
152 tuio.uio_limit = u.u_rlimit[RLIMIT_FSIZE].rlim_cur;
156 tuio.afsio_offset = DEV_BSIZE * abp->b_blkno;
158 tuio.afsio_seg = AFS_UIOSYS;
160 tuio.afsio_fmode = 0;
164 * XXX It this really right? Ideally we should always write block size multiple
165 * and not any arbitrary size, right? XXX
167 len = MIN(len, tvc->m.Length - dbtob(abp->b_blkno));
172 (VTOAFS(abp->b_vp))->m.Length - dbtob(abp->b_blkno));
173 #endif /* AFS_ALPHA_ENV */
174 tuio.afsio_resid = len;
175 #if defined(AFS_XBSD_ENV)
176 tiovec[0].iov_base = abp->b_saveaddr;
178 tiovec[0].iov_base = abp->b_un.b_addr;
179 #endif /* AFS_XBSD_ENV */
180 tiovec[0].iov_len = len;
181 /* are user's credentials valid here? probably, but this
182 * sure seems like the wrong things to do. */
183 #if defined(AFS_SUN5_ENV)
184 code = afs_nlrdwr(VTOAFS(abp->b_vp), &tuio, UIO_WRITE, 0, credp);
186 code = afs_rdwr(VTOAFS(abp->b_vp), &tuio, UIO_WRITE, 0, credp);
189 #if !defined(AFS_AIX32_ENV) && !defined(AFS_SUN5_ENV)
190 #if defined(AFS_DUX40_ENV) || (defined (AFS_XBSD_ENV) && !defined (AFS_FBSD50_ENV))
193 abp->b_flags |= B_ERROR;
196 #if defined(AFS_DUX40_ENV)
197 if (code && !(abp->b_flags & B_READ)) {
198 /* prevent ubc from retrying writes */
200 ubc_invalidate(AFSTOV(tvc)->v_object,
201 (vm_offset_t) dbtob(abp->b_blkno), PAGE_SIZE, B_INVAL);
205 #elif defined(AFS_FBSD50_ENV)
207 #else /* AFS_DUX40_ENV */
209 #endif /* AFS_DUX40_ENV */
214 afs_Trace3(afs_iclSetp, CM_TRACE_STRATEGYDONE, ICL_TYPE_POINTER, tvc,
215 ICL_TYPE_INT32, code, ICL_TYPE_LONG, tuio.afsio_resid);
219 #endif /* !AFS_HPUX_ENV && !AFS_SGI_ENV && !AFS_LINUX20_ENV */