public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: cygwin-patches@cygwin.com
Subject: [PATCH] Cygwin: Map ERROR_NO_SUCH_DEVICE and ERROR_MEDIA_CHANGED to ENODEV
Date: Fri, 23 Feb 2024 19:14:02 +0100	[thread overview]
Message-ID: <04f337bf-7197-b4af-3519-832ad2be5b14@t-online.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 438 bytes --]

Experiments with damaged USB flash drives and ddrescue revealed that the 
current mapping of these Win32 errors to the fallback EACCES could be 
improved.

BTW: I wonder why EACCES was selected as the fallback. Source code 
control forensics suggest that this was decided in the last millennium. 
A related comment from CGF added August 2000 persists until today :-)
/* FIXME: what's so special about EACCESS? */

-- 
Regards,
Christian


[-- Attachment #2: 0001-Cygwin-Map-ERROR_NO_SUCH_DEVICE-and-ERROR_MEDIA_CHAN.patch --]
[-- Type: text/plain, Size: 1550 bytes --]

From 8aa19c7fd13dc3790dc271dede8954539bffcd4d Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Fri, 23 Feb 2024 19:01:09 +0100
Subject: [PATCH] Cygwin: Map ERROR_NO_SUCH_DEVICE and ERROR_MEDIA_CHANGED to
 ENODEV

If a removable (USB) device is disconnected after opening its raw
device, R/W attempts fail with ERROR_NO_SUCH_DEVICE(433).  If the
raw device of a partition is used, ERROR_MEDIA_CHANGED(1110) is
returned instead.  Both are mapped to ENODEV(19) because <errno.h>
does not offer a value which better matches ERROR_MEDIA_CHANGED.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
---
 winsup/cygwin/local_includes/errmap.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/local_includes/errmap.h b/winsup/cygwin/local_includes/errmap.h
index 326b35b6c..a0b3ff400 100644
--- a/winsup/cygwin/local_includes/errmap.h
+++ b/winsup/cygwin/local_includes/errmap.h
@@ -438,7 +438,7 @@ static const int errmap[] =
   0,			/* 430 */
   0,			/* 431 */
   0,			/* 432 */
-  0,			/* 433 */
+  ENODEV,		/* ERROR_NO_SUCH_DEVICE */
   0,			/* 434 */
   0,			/* 435 */
   0,			/* 436 */
@@ -1115,7 +1115,7 @@ static const int errmap[] =
   0,			/* ERROR_DEVICE_NOT_PARTITIONED */
   0,			/* ERROR_UNABLE_TO_LOCK_MEDIA */
   0,			/* ERROR_UNABLE_TO_UNLOAD_MEDIA */
-  0,			/* ERROR_MEDIA_CHANGED */
+  ENODEV,		/* ERROR_MEDIA_CHANGED */
   EIO,			/* ERROR_BUS_RESET */
   ENOMEDIUM,		/* ERROR_NO_MEDIA_IN_DRIVE */
   0,			/* ERROR_NO_UNICODE_TRANSLATION */
-- 
2.43.0


             reply	other threads:[~2024-02-23 18:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-23 18:14 Christian Franke [this message]
2024-02-24 12:21 ` Corinna Vinschen
2024-02-25  9:12   ` Christian Franke
2024-02-26 10:27     ` Corinna Vinschen
2024-02-26 11:14       ` Christian Franke
2024-02-26 11:36         ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=04f337bf-7197-b4af-3519-832ad2be5b14@t-online.de \
    --to=christian.franke@t-online.de \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).