From ba75e8c878ecda8daa400f9ccb3ce463bef066b5 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 22 May 2007 07:16:19 +0000 Subject: [PATCH] * fhandler_floppy.cc (fhandler_dev_floppy::lseek): Don't invalidate devbuf if new position is within buffered range. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/fhandler_floppy.cc | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 1a8de02ff..e9047b288 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2007-05-21 Christian Franke + + * fhandler_floppy.cc (fhandler_dev_floppy::lseek): Don't invalidate + devbuf if new position is within buffered range. + 2007-05-21 Eric Blake * include/search.h (hsearch_r): Provide declaration. 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;