Index: winsup/cygwin/fhandler_floppy.cc =================================================================== RCS file: /cvs/src/src/winsup/cygwin/fhandler_floppy.cc,v retrieving revision 1.6 diff -u -p -2 -r1.6 fhandler_floppy.cc --- fhandler_floppy.cc 2001/02/05 16:10:06 1.6 +++ fhandler_floppy.cc 2001/02/26 19:02:30 @@ -17,4 +17,5 @@ details. */ #include "fhandler.h" #include "cygerrno.h" +#include /**********************************************************************/ @@ -83,8 +84,40 @@ fhandler_dev_floppy::lseek (off_t offset DWORD off; char buf[512]; + long drive_size = 0; + if (os_being_run == winNT) + { + DISK_GEOMETRY di; + DWORD bytes_read; + + if ( !DeviceIoControl ( get_handle(), + IOCTL_DISK_GET_DRIVE_GEOMETRY, + NULL, 0, + &di, sizeof (di), + &bytes_read, NULL) ) + { + __seterrno (); + return -1; + } + debug_printf ( "disk geometry: (%ld cyl)*(%ld trk)*(%ld sec)*(%ld bps)", + di.Cylinders, + di.TracksPerCylinder, + di.SectorsPerTrack, + di.BytesPerSector ); + drive_size = di.Cylinders.LowPart * di.TracksPerCylinder * + di.SectorsPerTrack * di.BytesPerSector; + debug_printf ( "drive size: %ld", drive_size ); + } + + if (whence == SEEK_END && drive_size > 0) + { + offset += drive_size; + whence = SEEK_SET; + } + if (whence == SEEK_SET) { - if (offset < 0) + if (offset < 0 || + drive_size > 0 && offset > drive_size) { set_errno (EINVAL); @@ -106,5 +139,5 @@ fhandler_dev_floppy::lseek (off_t offset return -1; } - return raw_read (buf, offset - off); + return off + raw_read (buf, offset - off); } else if (whence == SEEK_CUR) @@ -132,5 +165,6 @@ fhandler_dev_floppy::lseek (off_t offset cur += offset; - if (cur < 0) + if (cur < 0 || + drive_size > 0 && cur > drive_size) { set_errno (EINVAL); @@ -150,7 +184,6 @@ fhandler_dev_floppy::lseek (off_t offset return -1; } - return raw_read (buf, off); + return off + raw_read (buf, off); } - /* SEEK_END is not supported on raw disk devices. */ set_errno (EINVAL); return -1;