* fhandler_floppy.cc (fhandler_dev_floppy::lseek): Don't invalidate

devbuf if new position is within buffered range.
This commit is contained in:
Corinna Vinschen 2007-05-22 07:16:19 +00:00
parent a1f7599670
commit ba75e8c878
2 changed files with 20 additions and 1 deletions

View File

@ -1,3 +1,8 @@
2007-05-21 Christian Franke <franke@computer.org>
* fhandler_floppy.cc (fhandler_dev_floppy::lseek): Don't invalidate
devbuf if new position is within buffered range.
2007-05-21 Eric Blake <ebb9@byu.net>
* include/search.h (hsearch_r): Provide declaration.

View File

@ -410,6 +410,7 @@ fhandler_dev_floppy::lseek (_off64_t offset, int whence)
{
char buf[bytes_per_sector];
_off64_t lloffset = offset;
_off64_t current_pos = (_off64_t) -1;
LARGE_INTEGER sector_aligned_offset;
size_t bytes_left;
@ -420,7 +421,8 @@ fhandler_dev_floppy::lseek (_off64_t offset, int whence)
}
else if (whence == SEEK_CUR)
{
lloffset += get_current_position () - (devbufend - devbufstart);
current_pos = get_current_position ();
lloffset += current_pos - (devbufend - devbufstart);
whence = SEEK_SET;
}
@ -430,6 +432,18 @@ fhandler_dev_floppy::lseek (_off64_t offset, int whence)
return -1;
}
/* If new position is in buffered range, adjust buffer and return */
if (devbufstart < devbufend)
{
if (current_pos == (_off64_t) -1)
current_pos = get_current_position ();
if (current_pos - devbufend <= lloffset && lloffset <= current_pos)
{
devbufstart = devbufend - (current_pos - lloffset);
return lloffset;
}
}
sector_aligned_offset.QuadPart = (lloffset / bytes_per_sector)
* bytes_per_sector;
bytes_left = lloffset - sector_aligned_offset.QuadPart;