- if (resid > uio->uio_resid) hp->h_nodeflags |= IN_CHANGE | IN_UPDATE;
-
- } else {
-
- while (retval == E_NONE && uio->uio_resid > 0) {
- logBlockNo = currOffset / PAGE_SIZE;
- blkoffset = currOffset & PAGE_MASK;
-
- if (((off_t)(fcb->fcbPLen) - currOffset) < PAGE_SIZE_64)
- fragSize = (off_t)(fcb->fcbPLen) - ((off_t)logBlockNo * PAGE_SIZE_64);
- else
- fragSize = PAGE_SIZE;
- xfersize = fragSize - blkoffset;
-
- DBG_RW(("\tcurrOffset = Ox%lX, logBlockNo = Ox%X, blkoffset = Ox%lX, xfersize = Ox%lX, fragSize = Ox%lX.\n",
- (unsigned long)currOffset, logBlockNo, blkoffset, xfersize, fragSize));
-
- /* Make any adjustments for boundary conditions */
- if (currOffset + (off_t)xfersize > writelimit) {
- xfersize = writelimit - currOffset;
- DBG_RW(("\ttrimming xfersize to 0x%lX to match writelimit (uio_resid)...\n", xfersize));
- };
-
- /*
- * There is no need to read into bp if:
- * We start on a block boundary and will overwrite the whole block
- *
- * OR
- */
- if ((blkoffset == 0) && (xfersize >= fragSize)) {
- DBG_RW(("\tRequesting %ld-byte block Ox%lX w/o read...\n", fragSize, (long)logBlockNo));
-
- bp = getblk(vp, logBlockNo, fragSize, 0, 0, BLK_READ);
- retval = 0;
-
- if (bp->b_blkno == -1) {
- brelse(bp);
- retval = EIO; /* XXX */
- break;
- }
- } else {
-
- if (currOffset == fcb->fcbEOF && blkoffset == 0) {
- bp = getblk(vp, logBlockNo, fragSize, 0, 0, BLK_READ);
- retval = 0;
-
- if (bp->b_blkno == -1) {
- brelse(bp);
- retval = EIO; /* XXX */
- break;
- }
-
- } else {
- /*
- * This I/O transfer is not sufficiently aligned, so read the affected block into a buffer:
- */
- DBG_VOP(("\tRequesting block Ox%X, size = 0x%08lX...\n", logBlockNo, fragSize));
- retval = bread(vp, logBlockNo, fragSize, ap->a_cred, &bp);
-
- if (retval != E_NONE) {
- if (bp)
- brelse(bp);
- break;
- }
- }
- }
-
- /* See if we are starting to write within file boundaries:
- If not, then we need to present a "hole" for the area between
- the current EOF and the start of the current I/O operation:
-
- Note that currOffset is only less than uio_offset if uio_offset > LEOF...
- */
- if (uio->uio_offset > currOffset) {
- clearSize = MIN(uio->uio_offset - currOffset, xfersize);
- DBG_RW(("\tzeroing Ox%lX bytes Ox%lX bytes into block Ox%X...\n", clearSize, blkoffset, logBlockNo));
- bzero(bp->b_data + blkoffset, clearSize);
- currOffset += clearSize;
- blkoffset += clearSize;
- xfersize -= clearSize;
- };
-
- if (xfersize > 0) {
- DBG_RW(("\tCopying Ox%lX bytes Ox%lX bytes into block Ox%X... ioflag == 0x%X\n",
- xfersize, blkoffset, logBlockNo, ioflag));
- retval = uiomove((caddr_t)bp->b_data + blkoffset, (int)xfersize, uio);
- currOffset += xfersize;
- };
- DBG_ASSERT((bp->b_bcount % devBlockSize) == 0);
-
- if (ioflag & IO_SYNC) {
- (void)VOP_BWRITE(bp);
- //DBG_RW(("\tissuing bwrite\n"));
- } else if ((xfersize + blkoffset) == fragSize) {
- //DBG_RW(("\tissuing bawrite\n"));
- bp->b_flags |= B_AGE;
- bawrite(bp);
- } else {
- //DBG_RW(("\tissuing bdwrite\n"));
- bdwrite(bp);
- };
-
- /* Update the EOF if we just extended the file
- (the PEOF has already been moved out and the block mapping table has been updated): */
- if (currOffset > fcb->fcbEOF) {
- DBG_VOP(("\textending EOF to 0x%lX...\n", (UInt32)fcb->fcbEOF));
- fcb->fcbEOF = currOffset;
-
- if (UBCISVALID(vp))
- ubc_setsize(vp, (off_t)fcb->fcbEOF); /* XXX check errors */
- };
-
- if (retval || (resid == 0))
- break;
- hp->h_nodeflags |= IN_CHANGE | IN_UPDATE;
- };
- };
+ if (resid > uio->uio_resid)
+ cp->c_flag |= C_CHANGE | C_UPDATE;
+ } else {
+ while (retval == E_NONE && uio->uio_resid > 0) {
+ logBlockNo = currOffset / PAGE_SIZE;
+ blkoffset = currOffset & PAGE_MASK;
+
+ if ((filebytes - currOffset) < PAGE_SIZE_64)
+ fragSize = filebytes - ((off_t)logBlockNo * PAGE_SIZE_64);
+ else
+ fragSize = PAGE_SIZE;
+ xfersize = fragSize - blkoffset;
+
+ /* Make any adjustments for boundary conditions */
+ if (currOffset + (off_t)xfersize > writelimit)
+ xfersize = writelimit - currOffset;
+
+ /*
+ * There is no need to read into bp if:
+ * We start on a block boundary and will overwrite the whole block
+ *
+ * OR
+ */
+ if ((blkoffset == 0) && (xfersize >= fragSize)) {
+ bp = getblk(vp, logBlockNo, fragSize, 0, 0, BLK_READ);
+ retval = 0;
+
+ if (bp->b_blkno == -1) {
+ brelse(bp);
+ retval = EIO; /* XXX */
+ break;
+ }
+ } else {
+
+ if (currOffset == fp->ff_size && blkoffset == 0) {
+ bp = getblk(vp, logBlockNo, fragSize, 0, 0, BLK_READ);
+ retval = 0;
+ if (bp->b_blkno == -1) {
+ brelse(bp);
+ retval = EIO; /* XXX */
+ break;
+ }
+ } else {
+ /*
+ * This I/O transfer is not sufficiently aligned,
+ * so read the affected block into a buffer:
+ */
+ retval = bread(vp, logBlockNo, fragSize, ap->a_cred, &bp);
+ if (retval != E_NONE) {
+ if (bp)
+ brelse(bp);
+ break;
+ }
+ }
+ }
+
+ /* See if we are starting to write within file boundaries:
+ * If not, then we need to present a "hole" for the area
+ * between the current EOF and the start of the current
+ * I/O operation:
+ *
+ * Note that currOffset is only less than uio_offset if
+ * uio_offset > LEOF...
+ */
+ if (uio->uio_offset > currOffset) {
+ clearSize = MIN(uio->uio_offset - currOffset, xfersize);
+ bzero(bp->b_data + blkoffset, clearSize);
+ currOffset += clearSize;
+ blkoffset += clearSize;
+ xfersize -= clearSize;
+ }
+
+ if (xfersize > 0) {
+ retval = uiomove((caddr_t)bp->b_data + blkoffset, (int)xfersize, uio);
+ currOffset += xfersize;
+ }
+
+ if (ioflag & IO_SYNC) {
+ (void)VOP_BWRITE(bp);
+ } else if ((xfersize + blkoffset) == fragSize) {
+ bp->b_flags |= B_AGE;
+ bawrite(bp);
+ } else {
+ bdwrite(bp);
+ }
+
+ /* Update the EOF if we just extended the file
+ * (the PEOF has already been moved out and the
+ * block mapping table has been updated):
+ */
+ if (currOffset > fp->ff_size) {
+ fp->ff_size = currOffset;
+ if (UBCISVALID(vp))
+ ubc_setsize(vp, fp->ff_size); /* XXX check errors */
+ }
+ if (retval || (resid == 0))
+ break;
+ cp->c_flag |= C_CHANGE | C_UPDATE;
+ } /* endwhile */
+ }