[PATCH] Cygwin: Add /dev/disk/by-id symlinks

Corinna Vinschen corinna-cygwin@cygwin.com
Sat Nov 4 20:51:00 GMT 2023


Hi Christian,

patch looks pretty good to me.  Just two minor points:

> +  /* Traverse \Device directory ... */
> +  bool errno_set = false;
> +  HANDLE devhdl = INVALID_HANDLE_VALUE;

INVALID_HANDLE_VALUE is a Win32 API concept and is only returned by
CreateFile and friends.  The native NT API doesn't know
INVALID_HANDLE_VALUE and, fortunately, only uses NULL.  I think it's
puzzeling to use INVALID_HANDLE_VALUE in a native NT context. So, would
you mind to just use NULL (or nullptr) instead?  As in...

> +      if (devhdl != INVALID_HANDLE_VALUE)

         if (devhdl)

Sounds easier to me :)

> +	  /* Fetch drive layout info to get size of all partitions on disk. */
> +	  DWORD part_cnt = 0;
> +	  PARTITION_INFORMATION_EX *pix = nullptr;
> +	  PARTITION_INFORMATION *pi = nullptr;
> +	  DWORD bytes_read;
> +	  if (DeviceIoControl (devhdl, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, nullptr, 0,
> +			       ioctl_buf, NT_MAX_PATH, &bytes_read, nullptr))
> +	    {
> +	      DRIVE_LAYOUT_INFORMATION_EX *pdlix =
> +		  reinterpret_cast<DRIVE_LAYOUT_INFORMATION_EX *>(ioctl_buf);
> +	      part_cnt = pdlix->PartitionCount;
> +	      pix = pdlix->PartitionEntry;
> +	    }
> +	  else if (DeviceIoControl (devhdl, IOCTL_DISK_GET_DRIVE_LAYOUT, nullptr,

Do we really still need IOCTL_DISK_GET_DRIVE_LAYOUT w/o _EX?

fhandler_proc still uses it, too, but the EX variation is available
since XP. I can't imagine that a fallback to the non-EX-version is still
necessary.  If you like you could drop it immediately, or we can drop
both usages as a followup patch.

Last, but not least, do you see a chance to add any other /dev/disk
subdir?  by-partuuid, perhaps?


Thanks,
Corinna



More information about the Cygwin-patches mailing list