diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2018-06-29 15:29:36 +0200 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2018-06-29 15:31:15 +0200 |
commit | 995d2a824a8faf71ef91eb8b7a7b3054209565d8 (patch) | |
tree | 85484a786153c2d8b6aa3fc763b4768c03d032ca /winsup/cygwin | |
parent | 4b97244d125e6a7a043ee798a488a17e25cb5d0c (diff) | |
download | newlib-995d2a824a8faf71ef91eb8b7a7b3054209565d8.zip newlib-995d2a824a8faf71ef91eb8b7a7b3054209565d8.tar.gz newlib-995d2a824a8faf71ef91eb8b7a7b3054209565d8.tar.bz2 |
Cygwin: tape: Handle non-standard "no medium" error code
Certain tape drives (known example: QUANTUM_ULTRIUM-HH6) return
the non-standard ERROR_NOT_READY rather than ERROR_NO_MEDIA_IN_DRIVE
if no media is present. ERROR_NOT_READY is not documented as valid
return code from GetTapeStatus. Without handling this error code
Cygwin's tape code can't report an offline state to user space.
Fix this by converting ERROR_NOT_READY to ERROR_NO_MEDIA_IN_DRIVE
where appropriate.
Add a debug_printf to mtinfo_drive::get_status to allow requesting
user info without having to rebuild the DLL.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin')
-rw-r--r-- | winsup/cygwin/fhandler_tape.cc | 27 | ||||
-rw-r--r-- | winsup/cygwin/release/2.11.0 | 4 |
2 files changed, 26 insertions, 5 deletions
diff --git a/winsup/cygwin/fhandler_tape.cc b/winsup/cygwin/fhandler_tape.cc index 9cfa2bb..a7f64ea 100644 --- a/winsup/cygwin/fhandler_tape.cc +++ b/winsup/cygwin/fhandler_tape.cc @@ -32,6 +32,16 @@ details. */ part (partition)->initialize (0); \ } +/* Certain tape drives (known example: QUANTUM_ULTRIUM-HH6) return + ERROR_NOT_READY rather than ERROR_NO_MEDIA_IN_DRIVE if no media + is in the drive. Convert this to the only sane error code. */ +#define GET_TAPE_STATUS(_h) ({ \ + int _err = GetTapeStatus (_h); \ + if (_err == ERROR_NOT_READY) \ + _err = ERROR_NO_MEDIA_IN_DRIVE; \ + _err; \ + }) + #define IS_BOT(err) ((err) == ERROR_BEGINNING_OF_MEDIA) #define IS_EOF(err) ((err) == ERROR_FILEMARK_DETECTED \ @@ -98,6 +108,9 @@ mtinfo_drive::get_mp (HANDLE mt) { DWORD len = sizeof _mp; TAPE_FUNC (GetTapeParameters (mt, GET_TAPE_MEDIA_INFORMATION, &len, &_mp)); + /* See GET_TAPE_STATUS comment. */ + if (lasterr == ERROR_NOT_READY) + lasterr = ERROR_NO_MEDIA_IN_DRIVE; return error ("get_mp"); } @@ -130,7 +143,7 @@ int mtinfo_drive::close (HANDLE mt, bool rewind) { lasterr = 0; - if (GetTapeStatus (mt) == ERROR_NO_MEDIA_IN_DRIVE) + if (GET_TAPE_STATUS (mt) == ERROR_NO_MEDIA_IN_DRIVE) dirty = clean; if (dirty >= has_written) { @@ -187,7 +200,7 @@ mtinfo_drive::read (HANDLE mt, LPOVERLAPPED pov, void *ptr, size_t &ulen) BOOL ret; DWORD bytes_read = 0; - if (GetTapeStatus (mt) == ERROR_NO_MEDIA_IN_DRIVE) + if (GET_TAPE_STATUS (mt) == ERROR_NO_MEDIA_IN_DRIVE) return lasterr = ERROR_NO_MEDIA_IN_DRIVE; if (lasterr == ERROR_BUS_RESET) { @@ -300,7 +313,7 @@ mtinfo_drive::write (HANDLE mt, LPOVERLAPPED pov, const void *ptr, size_t &len) DWORD bytes_written = 0; int async_err = 0; - if (GetTapeStatus (mt) == ERROR_NO_MEDIA_IN_DRIVE) + if (GET_TAPE_STATUS (mt) == ERROR_NO_MEDIA_IN_DRIVE) return lasterr = ERROR_NO_MEDIA_IN_DRIVE; if (lasterr == ERROR_BUS_RESET) { @@ -762,8 +775,12 @@ mtinfo_drive::get_status (HANDLE mt, struct mtget *get) if (!get) return ERROR_INVALID_PARAMETER; - if ((tstat = GetTapeStatus (mt)) == ERROR_NO_MEDIA_IN_DRIVE - || get_mp (mt) == ERROR_NO_MEDIA_IN_DRIVE) + tstat = GET_TAPE_STATUS (mt); + DWORD mpstat = (DWORD) get_mp (mt); + + debug_printf ("GetTapeStatus: %u, get_mp: %d", tstat, mpstat); + + if (tstat == ERROR_NO_MEDIA_IN_DRIVE || mpstat == ERROR_NO_MEDIA_IN_DRIVE) notape = 1; memset (get, 0, sizeof *get); diff --git a/winsup/cygwin/release/2.11.0 b/winsup/cygwin/release/2.11.0 index b1aaaf3..9e73e0a 100644 --- a/winsup/cygwin/release/2.11.0 +++ b/winsup/cygwin/release/2.11.0 @@ -40,3 +40,7 @@ Bug Fixes - Fix Unicode table. Addresses: https://cygwin.com/ml/cygwin/2018-06/msg00248.html + +- Handle a non-standard return value from some tape drives to + report a "no-media" error. + Addresses: https://cygwin.com/ml/cygwin/2018-06/msg00245.html |