public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: Christian Franke <Christian.Franke@t-online.de>
Cc: cygwin-patches@cygwin.com
Subject: Re: [PATCH] Cygwin: Add /dev/disk/by-id symlinks
Date: Sat, 4 Nov 2023 10:57:13 +0100	[thread overview]
Message-ID: <ZUYVeeYDcAKC74wg@calimero.vinschen.de> (raw)
In-Reply-To: <ZUYQPPsrxf5yp1Ir@calimero.vinschen.de>

On Nov  4 10:34, Corinna Vinschen wrote:
> On Nov  3 18:54, Christian Franke wrote:
> > Corinna Vinschen wrote:
> > > On Nov  3 17:27, Corinna Vinschen wrote:
> > > > On Nov  3 17:09, Christian Franke wrote:
> > > > > Unlike (S)ATA and NVMe, the serial number
> > > > > is not available for free in the device identify data block but requires an
> > > > > extra command (SCSI INQUIRY of VPD page 0x80). This might not be supported
> > > > > by the emulated controller or Windows does not use this command.
> > > > AFAICS, only the data from STORAGE_DEVICE_ID_DESCRIPTOR is available
> > > > which is equivalent to the data from VPD page 0x83.  As you can see,
> > > > it's part of the STORAGE_DEVICE_UNIQUE_IDENTIFIER data.  The data
> > > > returned for the VirtIo device is the identifier string "\x01\x00",
> > > > which is a bit underwhelming.
> > > > 
> > > > Would be great if we would learn how to access page 0x80...
> > > Uhm...
> > > 
> > > MSDN claims:
> > > 
> > >    If the storage device is SCSI-compliant, the port driver attempts to
> > >    extract the serial number from the optional Unit Serial Number page
> > >    (page 0x80) of the VPD.
> > > 
> > > Now I'm puzzled.
> > 
> > A quick test with a Debian 12 VM in VirtualBox with many virtual
> > controllers+drives shows the same problem:
> > Entries in /dev/disk/by-id appear only for virtual disks behind emulated
> > SATA and NVMe controllers, but not for SCSI and SAS controllers.
> > A test with "smartctl -i ..." with SCSI/SAS devices doesn't print a serial
> > number. In debug mode it prints "Vital Product Data (VPD) INQUIRY failed..."
> > and other messages that suggest limited/buggy support of optional SCSI
> > commands.
> > 
> > If a Win11 PE (from install ISO) is run in same VM, the
> > STORAGE_DEVICE_DESCRIPTOR only provides the serial number for SATA (NVMe
> > drives not detected), but not for SCSI.
> > 
> > Conclusion: The behavior of the current patch is compatible with Linux :-)
> 
> Ok, but with the DUID we have a workaround which makes it  work even
> better than on Linux, so it would begreat if we used it, unless we find
> out where the UUID in "\GLOBAL??\Disk{<UUID>} comes from...
> 
> Given the size of the STORAGE_DEVICE_UNIQUE_IDENTIFIER struct, we could
> even contemplate a 128 bit hash, just to be on the safe side.

Kind of like this

-  strcat (name, ioctl_buf + desc->SerialNumberOffset);
+  /* Use SerialNumber in the first place, if available */
+  if (desc->SerialNumberOffset && desc_buf[desc->SerialNumberOffset])
+    strcat (name, desc_buf + desc->SerialNumberOffset);
+  else /* Utilize the DUID as defined by MSDN to generate a hash */
+    {
+      union {
+	unsigned __int128 all;
+	struct {
+	  unsigned long high;
+	  unsigned long low;
+	};
+      } hash = { 0 };
+
+      for (ULONG i = 0; i < id->Size; ++i)
+	hash.all = ioctl_buf[i] + (hash.all << 6) + (hash.all << 16) - hash.all;
+      __small_sprintf (name + strlen (name), "%X%X", hash.high, hash.low);
+    }


Corinna

  reply	other threads:[~2023-11-04  9:57 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-25 11:57 Christian Franke
2023-10-03 12:39 ` Christian Franke
2023-11-03  9:55   ` Corinna Vinschen
2023-11-03 10:09     ` Corinna Vinschen
2023-11-03 11:06       ` Christian Franke
2023-11-03 11:11         ` Corinna Vinschen
2023-11-03 11:10       ` Corinna Vinschen
2023-11-03 13:27         ` Corinna Vinschen
2023-11-03 16:09           ` Christian Franke
2023-11-03 16:27             ` Corinna Vinschen
2023-11-03 16:30               ` Corinna Vinschen
2023-11-03 17:54                 ` Christian Franke
2023-11-04  9:34                   ` Corinna Vinschen
2023-11-04  9:57                     ` Corinna Vinschen [this message]
2023-11-04 11:34                       ` Christian Franke
2023-11-04 15:53                       ` Christian Franke
2023-11-04 20:51                         ` Corinna Vinschen
2023-11-05 15:45                           ` Christian Franke
2023-11-05 19:59                             ` Corinna Vinschen
2023-11-07 10:10                               ` Christian Franke
2023-11-07 13:29                                 ` Corinna Vinschen
2023-11-07 14:30                                   ` Christian Franke
2023-11-07 15:23                                     ` 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=ZUYVeeYDcAKC74wg@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=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).