*** empty log message ***

git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@71 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
Jim Tabor 2000-09-05 00:56:50 +00:00
parent 21693a0432
commit d53d9f4445
2 changed files with 70 additions and 7 deletions

View File

@ -1,3 +1,12 @@
2000 Aug 15 - Build 2022
-------- James Tabor (jimtabor@infohwy.com)
2000/08/12 22:49:00 Ron Cemer (roncemer@gte.net)
Fixed writeblock() to only use getbuf() if writing a
complete sector; otherwise use getbloc() and do a
read-modify-write to prevent writing garbage back
over pre-existing data in the file.
This was a major BUG.
2000 Aug 05 - Build 2021 2000 Aug 05 - Build 2021
-------- James Tabor (jimtabor@infohwy.com) -------- James Tabor (jimtabor@infohwy.com)
Clean up and finish umb code to get 2021 out. Clean up and finish umb code to get 2021 out.

View File

@ -36,6 +36,17 @@ BYTE *RcsId = "$Id$";
/* /*
* $Log$ * $Log$
* Revision 1.7 2000/09/05 00:56:50 jimtabor
* *** empty log message ***
*
*
* /// 2000/08/12 22:49:00 Ron Cemer
* Fixed writeblock() to only use getbuf() if writing a
* complete sector; otherwise use getbloc() and do a
* read-modify-write to prevent writing garbage back
* over pre-existing data in the file.
* This was a major BUG.
*
* Revision 1.6 2000/08/06 05:50:17 jimtabor * Revision 1.6 2000/08/06 05:50:17 jimtabor
* Add new files and update cvs with patches and changes * Add new files and update cvs with patches and changes
* *
@ -1602,6 +1613,15 @@ UCOUNT writeblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err)
return 0; return 0;
} }
/* /// BUG!!! Moved from below next block because we should NOT be able
to truncate the file if we can't write to it. - Ron Cemer */
/* test that we have a valid mode for this fnode */
if (fnp->f_mode != WRONLY && fnp->f_mode != RDWR)
{
*err = DE_INVLDACC;
return 0;
}
/* Test that we are really about to do a data transfer. If the */ /* Test that we are really about to do a data transfer. If the */
/* count is zero and the mode is XFR_READ, just exit. (Any */ /* count is zero and the mode is XFR_READ, just exit. (Any */
/* read with a count of zero is a nop). */ /* read with a count of zero is a nop). */
@ -1618,12 +1638,16 @@ UCOUNT writeblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err)
return 0; return 0;
} }
/* /// BUG!!! Moved to above previous block because we should NOT be able
to truncate the file if we can't write to it. - Ron Cemer
/* test that we have a valid mode for this fnode */ /* test that we have a valid mode for this fnode */
/*
if (fnp->f_mode != WRONLY && fnp->f_mode != RDWR) if (fnp->f_mode != WRONLY && fnp->f_mode != RDWR)
{ {
*err = DE_INVLDACC; *err = DE_INVLDACC;
return 0; return 0;
} }
*/
/* The variable secsize will be used later. */ /* The variable secsize will be used later. */
secsize = fnp->f_dpb->dpb_secsize; secsize = fnp->f_dpb->dpb_secsize;
@ -1726,14 +1750,40 @@ UCOUNT writeblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err)
fnp->f_cluster); fnp->f_cluster);
#endif #endif
/* /// Moved xfr_cnt calculation from below so we can
use it to help decide how to get the block:
read-modify-write using getblock() if we are only
going to write part of the block, or
write using getbuf() if we are going to write
the entire block.
- Ron Cemer */
xfr_cnt = min(to_xfer, secsize - fnp->f_boff);
/* get a buffer to store the block in */ /* get a buffer to store the block in */
if (!getbuf(&bp, (ULONG) clus2phys(fnp->f_cluster, /* /// BUG!!! Added conditional to only use getbuf() if we're going
(fnp->f_dpb->dpb_clsmask + 1), to write the entire block, which is faster because it does
fnp->f_dpb->dpb_data) + fnp->f_sector, not first read the block from disk. However, if we are
fnp->f_dpb->dpb_unit)) going to only write part of the block, we MUST use the
{ getblock() call, which first reads the block from disk.
*err = DE_BLKINVLD; Without this modification, the kernel was writing garbage
return ret_cnt; to the file when sequential writes were attempted at less
than the block size. This was causing problems with
piping and redirection in FreeCOM, as well as many other
potential problems.
- Ron Cemer */
if ( (fnp->f_boff == 0) && (xfr_cnt == secsize) ) {
if (!getbuf(&bp, (ULONG) clus2phys(fnp->f_cluster,
(fnp->f_dpb->dpb_clsmask + 1),
fnp->f_dpb->dpb_data) + fnp->f_sector,
fnp->f_dpb->dpb_unit)) {
*err = DE_BLKINVLD;
return ret_cnt;
}
} else {
bp = getblock((ULONG) clus2phys(fnp->f_cluster,
(fnp->f_dpb->dpb_clsmask + 1),
fnp->f_dpb->dpb_data) + fnp->f_sector,
fnp->f_dpb->dpb_unit);
} }
/* transfer a block */ /* transfer a block */
@ -1741,7 +1791,11 @@ UCOUNT writeblock(COUNT fd, VOID FAR * buffer, UCOUNT count, COUNT * err)
/* requested transfer size, whichever is smaller. */ /* requested transfer size, whichever is smaller. */
/* Then compare to what is left, since we can transfer */ /* Then compare to what is left, since we can transfer */
/* a maximum of what is left. */ /* a maximum of what is left. */
/* /// Moved xfr_cnt calculation to above getbuf/getblock calls so we can
use it to help decide which one to call.
- Ron Cemer
xfr_cnt = min(to_xfer, secsize - fnp->f_boff); xfr_cnt = min(to_xfer, secsize - fnp->f_boff);
*/
fbcopy(buffer, (BYTE FAR *) & bp->b_buffer[fnp->f_boff], xfr_cnt); fbcopy(buffer, (BYTE FAR *) & bp->b_buffer[fnp->f_boff], xfr_cnt);
bp->b_flag |= BFR_DIRTY | BFR_VALID; bp->b_flag |= BFR_DIRTY | BFR_VALID;