summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fhandler_floppy.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2007-05-22 07:16:19 +0000
committerCorinna Vinschen <corinna@vinschen.de>2007-05-22 07:16:19 +0000
commitba75e8c878ecda8daa400f9ccb3ce463bef066b5 (patch)
tree886784be591a148d1aee6ab74237728bda49bb25 /winsup/cygwin/fhandler_floppy.cc
parenta1f7599670d477687a0990414e3abcb58b41f3a1 (diff)
downloadcygnal-ba75e8c878ecda8daa400f9ccb3ce463bef066b5.tar.gz
cygnal-ba75e8c878ecda8daa400f9ccb3ce463bef066b5.tar.bz2
cygnal-ba75e8c878ecda8daa400f9ccb3ce463bef066b5.zip
* fhandler_floppy.cc (fhandler_dev_floppy::lseek): Don't invalidate
devbuf if new position is within buffered range.
Diffstat (limited to 'winsup/cygwin/fhandler_floppy.cc')
-rw-r--r--winsup/cygwin/fhandler_floppy.cc16
1 files changed, 15 insertions, 1 deletions
diff --git a/winsup/cygwin/fhandler_floppy.cc b/winsup/cygwin/fhandler_floppy.cc
index ee8d56b57..bcd0c7df6 100644
--- a/winsup/cygwin/fhandler_floppy.cc
+++ b/winsup/cygwin/fhandler_floppy.cc
@@ -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;