delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1998/11/06/04:09:27

From: corinna DOT vinschen AT cityweb DOT de (Corinna Vinschen)
Subject: B20 patch: Recognition of raw mass storage devices
6 Nov 1998 04:09:27 -0800 :
Message-ID: <3642DBE6.7EE43884.cygnus.cygwin32.developers@cityweb.de>
Mime-Version: 1.0
To: cygwin32-developers AT cygnus DOT com

The following patch enables the cygwin dll, to recognize
raw devices in the mount table by their Windows device name.
The restriction is the recognition of norewind tapes, which
must have a mount path, beginning with "/dev/n", because the
difference between rewind/norewind is not supported by WinNT,
but requires a special handling in the cygwin dll. I don't
have a better solution at the moment.

This patch is runnable standalone. It prepares the (soon coming)
patch, for working fhandler_dev_tape and fhandler_dev_floppy
(which works not only on floppy, but on any partition and
physical drive).

Best Regards,
Corinna

ChangeLog:
----------
Mon Nov 02 23:29:45 1998 Corinna Vinschen <corinna DOT vinschen AT cityweb DOT de>

        * path.cc: New function `get_raw_device_number()', to support
        dynamic recognition of raw mass storage devices (tapes,
        partitions, physicaldrives).

        * path.cc (get_device_number): New parameter, to support
        a call to get_raw_device_number() only if allowed.

        * path.h: Changed prototype for get_device_number().

        * path.cc (win32_device_name): Changed call to get_device_number.

        * path.cc (mount_info::conv_to_win32_path): calls get_raw_device_number
        before any successful return now.

---- snip ----
--- path.h.orig Tue Nov 03 00:16:10 1998
+++ path.h      Tue Nov 03 00:16:59 1998
@@ -115,7 +115,7 @@ class mount_info

 extern suffix_info std_suffixes[];

-int get_device_number (const char *name, int &unit);
+int get_device_number (const char *name, int &unit, BOOL from_conv = FALSE);
 BOOL win32_device_name (const char *src_path, char *win32_path);

 /* These are exported from the dll as cygwin_foo.  */
--- path.cc.orig        Mon Nov 02 23:29:45 1998
+++ path.cc     Fri Nov 06 09:24:38 1998
@@ -392,8 +392,34 @@ const char *windows_device_names[] =
   "nul",
 };

+static int
+get_raw_device_number (const char *uxname, const char *w32path, int &unit)
+{
+  DWORD devn = FH_BAD;
+
+  if (strncasecmp (w32path, "\\\\.\\tape", 8) == 0)
+    {
+      devn = FH_TAPE;
+      unit = digits (w32path + 8);
+      // norewind tape devices have leading n in name
+      if (! strncasecmp (uxname, "/dev/n", 6))
+        unit += 128;
+    }
+  else if (isalpha (w32path[4]) && w32path[5] == ':')
+    {
+      devn = FH_FLOPPY;
+      unit = tolower (w32path[4]) - 'a';
+    }
+  else if (strncasecmp (w32path, "\\\\.\\physicaldrive", 17) == 0)
+    {
+      devn = FH_FLOPPY;
+      unit = digits (w32path + 17) + 128;
+    }
+  return devn;
+}
+
 int
-get_device_number (const char *name, int &unit)
+get_device_number (const char *name, int &unit, BOOL from_conv)
 {

   DWORD devn = FH_BAD;
@@ -427,10 +453,6 @@ get_device_number (const char *name, int
        devn = FH_CONOUT;
       else if (deveq ("null"))
        devn = FH_NULL;
-      else if (deveqn ("fd", 2) && (unit = digits (name + 2)) >= 0)
-       devn = FH_FLOPPY;
-      else if (deveqn ("st", 2) && (unit = digits (name + 2)) >= 0)
-       devn = FH_TAPE;
       else if (deveqn ("com", 3) && (unit = digits (name + 3)) >= 0)
        devn = FH_SERIAL;
       else if (deveq ("pipe") || deveq ("piper") || deveq ("pipew"))
@@ -438,6 +460,10 @@ get_device_number (const char *name, int
       else if (deveq ("tcp") || deveq ("udp") || deveq ("streamsocket")
               || deveq ("dgsocket"))
        devn = FH_SOCKET;
+      else if (! from_conv)
+        devn = get_raw_device_number (name - 5,
+                                      path_conv (name - 5, -1).get_win32 (),
+                                      unit);
     }
   else if (deveqn ("com", 3) && (unit = digits (name + 3)) >= 0)
     devn = FH_SERIAL;
@@ -451,7 +477,7 @@ win32_device_name (const char *src_path,
 {
   const char *devfmt;

-  devn = get_device_number (src_path, unit);
+  devn = get_device_number (src_path, unit, TRUE);

   if (devn == FH_BAD)
     return FALSE;
@@ -600,6 +626,9 @@ mount_info::conv_to_win32_path (const ch
        backslashify (src_path, win32_path, trailing_slash_p);
        backslashify (src_path, win32_path, trailing_slash_p);
       if (full_win32_path != NULL)
        backslashify (src_path, full_win32_path, trailing_slash_p);
+      devn = get_raw_device_number (src_path,
+                                    full_win32_path ?: win32_path,
+                                    unit);
       return 0;
     }

@@ -710,6 +739,9 @@ mount_info::conv_to_win32_path (const ch
       debug_printf ("%s = conv_to_win32_path (%s)",
                    win32_path != NULL ? win32_path : full_win32_path,
                    src_path);
+      devn = get_raw_device_number (src_path,
+                                    full_win32_path ?: win32_path,
+                                    unit);
       return 0;
     }

@@ -739,6 +771,9 @@ mount_info::conv_to_win32_path (const ch
   debug_printf ("%s = conv_to_win32_path (%s)",
                win32_path != NULL ? win32_path : full_win32_path,
                src_path);
+  devn = get_raw_device_number (src_path,
+                                full_win32_path ?: win32_path,
+                                unit);
   return 0;
 }

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019