From 166d3ddf5a04d6f915f9eb3c7befc50a2a40edfc Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 24 Jun 2016 13:39:42 +0200 Subject: [PATCH] Fix major device check when locking partitions The change introduced in commit b2867a6 contains a faulty check for the major device number in fhandler_dev_floppy::lock_partition. Fix this. Also fix comments. Signed-off-by: Corinna Vinschen --- winsup/cygwin/fhandler_floppy.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/winsup/cygwin/fhandler_floppy.cc b/winsup/cygwin/fhandler_floppy.cc index 8c9ef9d02..1bb3aca6b 100644 --- a/winsup/cygwin/fhandler_floppy.cc +++ b/winsup/cygwin/fhandler_floppy.cc @@ -159,9 +159,9 @@ fhandler_dev_floppy::lock_partition (DWORD to_write) /* The simple case. We have only a single partition open anyway. Try to lock the partition so that a subsequent write succeeds. If there's some file handle open on one of the affected partitions, - this fails, but that's how it works on Vista and later... - Only DEV_SD7_MAJOR and less can point to partition 0. */ - if (get_major () <= DEV_SD7_MAJOR && get_minor () % 16 != 0) + this fails, but that's how it works... + The high partition major numbers don't have a partition 0. */ + if (get_major () >= DEV_SD_HIGHPART_START || get_minor () % 16 != 0) { if (!DeviceIoControl (get_handle (), FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &bytes_read, NULL)) @@ -297,13 +297,10 @@ fhandler_dev_floppy::write_file (const void *buf, DWORD to_write, *err = 0; if (!(ret = WriteFile (get_handle (), buf, to_write, written, 0))) *err = GetLastError (); - /* When writing to a disk or partition on Vista, an "Access denied" error - is potentially a result of the raw disk write restriction. See - http://support.microsoft.com/kb/942448 for details. What we have to - do here is to lock the partition and retry. The previous solution - locked one or all partitions immediately in open. Which is overly - wasteful, given that the user might only want to change, say, the boot - sector. */ + /* When writing to a disk or partition an "Access denied" error may + occur due to the raw disk write restriction. + See http://support.microsoft.com/kb/942448 for details. + What we do here is to lock the affected partition(s) and retry. */ if (*err == ERROR_ACCESS_DENIED && wincap.has_restricted_raw_disk_access () && get_major () != DEV_FLOPPY_MAJOR -- 2.43.5