Mark O'Keefe
2012-10-04 00:47:29 UTC
Hi all,
I'm new to this list so not entirely sure of the protocol, but I'd like to suggest an enhancement
to the mount capabilities of cygwin. I would guess I'm not the only one who plugs various
external drives into my PC and would like to predictably define where they get mounted
under cygwin. At the moment this is limited to just the drive letter (which can change). I
would like your thoughts on an enhancement which allowed the use of the drive UUID to
identify the connected drive letter, ie., make the drive letter dynamic. The intent is to add
an optional parameter to fstab to support UUID.
I have explored using libblkid to achieve this, however there are a few drawbacks to this
approach: It introduces a dependency on this library; when using UUID's, the mount
functions become slow as libblkid has to open the drives to read the UUID information.
In exploring this I discovered that libblkid uses /dev/disk/by-uuid to help with performance,
however this is not present in cygwin.
To cut to the chase, I've created a version which leverages aspects of the /proc virtual
filesystem, behaviours of Windows, blkid and the special file names of cygwin.
When a drive is first attached to Windows it creates a unique GUID for that drive. This does
not change (unless you deliberately delete these from the registry). These unique
references appear in the /proc filesystem as: /proc/sys/GLOBAL??/Volume{GUID}
These are links to the device under /proc/sys/Device
Also under the /proc filesystem are the drive letter references:
/proc/sys/GLOBAL??/[A-Z]:
These link to the device under /proc/sys/Device also.
So, you can map a unique device GUID to a drive letter dynamically using this information.
Now to get the UUID into the picture.
If you had a script which populated the UUID as a link to the unique volume you can map
the UUID to a drive letter dynamically by expanding the links at run-time.
/dev/disk/by-uuid/<UUID> => /dev/sys/GLOBAL??/Volume{<GUID>}
/dev/sys/GLOBAL??/Volume{<GUID>} => /dev/sys/Device/<device>
/dev/sys/Device/harddisk[0-9]*/partition[0-9]* => /dev/sys/Device/<device>
http://www.cygwin.com/cygwin-ug-net/using-specialnames.html
Provides the mapping of POSIX device name to Internal NT device name (3rd line above).
So, using this you can take the output of blkid and get a valid mapping to the various
components required above.
You can use a bootstrap process to create the /dev/disk/by-uuid/<UUID> link for each
of your devices the first time you attach them (manual process) and after this rely on
the /proc filesystem to reliably map a connected UUID drive to the mapped drive letter.
You can also rely on this to determine if it is connected as the /proc filesystem only shows
the links for connected devices, so while the /dev/disk/by-uuid link is permanent, the
destination only exists if the drive is mounted.
Sample directory listings:
$ ls -l /dev/disk/by-uuid
total 6.0K
lrwxrwxrwx 1 Administrators SYSTEM 63 Oct 3 14:56 022A4E072A4DF865 -> /proc/sys/GLOBAL??/Volume{07f378c0-0785-11e2-8b16-9d8354493d98}
lrwxrwxrwx 1 Administrators SYSTEM 63 Oct 3 11:12 20E819DCE819B150 ->/proc/sys/GLOBAL??/Volume{33795e42-562b-11e1-9e43-806e6f6e6963}
lrwxrwxrwx 1 Administrators SYSTEM 63 Oct 3 15:07 5E83-34DB ->/proc/sys/GLOBAL??/Volume{a056ffe4-c49b-11e1-9a60-e01fff2983d8}
lrwxrwxrwx 1 Administrators SYSTEM 63 Oct 3 14:56 78F07EF2F07EB5CA -> /proc/sys/GLOBAL??/Volume{82620ba9-ebef-11e1-b0aa-c0aa65e5609c}
lrwxrwxrwx 1 Administrators SYSTEM 63 Oct 2 17:41 BC28CC9C28CC56D4 ->/proc/sys/GLOBAL??/Volume{ff6beeb7-ef41-11e1-be0b-bb34ac766d9f}
lrwxrwxrwx 1 Administrators SYSTEM 63 Oct 2 17:42 D258228358226707 ->/proc/sys/GLOBAL??/Volume{ff6beea8-ef41-11e1-be0b-bb34ac766d9f}
$ ls -l /proc/sys/GLOBAL\?\?/Volume*
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:22/proc/sys/GLOBAL??/Volume{33795e42-562b-11e1-9e43-806e6f6e6963} ->/proc/sys/Device/HarddiskVolume1
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:22/proc/sys/GLOBAL??/Volume{33795e45-562b-11e1-9e43-806e6f6e6963} ->/proc/sys/Device/CdRom0
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:22/proc/sys/GLOBAL??/Volume{a056ffe4-c49b-11e1-9a60-e01fff2983d8} ->/proc/sys/Device/HarddiskVolume24
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:22/proc/sys/GLOBAL??/Volume{ff6beea8-ef41-11e1-be0b-bb34ac766d9f} ->/proc/sys/Device/HarddiskVolume30
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:22/proc/sys/GLOBAL??/Volume{ff6beeb7-ef41-11e1-be0b-bb34ac766d9f} ->/proc/sys/Device/HarddiskVolume29
$ ls -l /proc/sys/GLOBAL\?\?/[A-Z]:*
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:23 /proc/sys/GLOBAL??/C: ->/proc/sys/Device/HarddiskVolume1
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:23 /proc/sys/GLOBAL??/D: ->/proc/sys/Device/CdRom0
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:23 /proc/sys/GLOBAL??/E: ->/proc/sys/Device/HarddiskVolume24
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:23 /proc/sys/GLOBAL??/F: ->/proc/sys/Device/HarddiskVolume29
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:23 /proc/sys/GLOBAL??/G: ->/proc/sys/Device/HarddiskVolume30
Sample fstab:
# For a description of the file format, see the Users Guide
# http://cygwin.com/cygwin-ug-net/using.html#mount-table
# This is default anyway:
# none /cygdrive cygdrive binary,posix=0,user 0 0
/slots UUID=D258228358226707 /mnt/vtapes/slots none binary,user
/slots UUID=BC28CC9C28CC56D4 /mnt/archive/slots none binary,user
/slots UUID=5E83-34DB /mnt/4Gmodem/slots none binary,user
Output from mount:
$ mount
C:/cygwin/bin on /usr/bin type ntfs (binary,auto)
C:/cygwin/lib on /usr/lib type ntfs (binary,auto)
C:/cygwin on / type ntfs (binary,auto)
E:/slots on /mnt/4Gmodem/slots type vfat (binary,user)
F:/slots on /mnt/archive/slots type ntfs (binary,user)
G:/slots on /mnt/vtapes/slots type ntfs (binary,user)
C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
E: on /cygdrive/e type vfat (binary,posix=0,user,noumount,auto)
F: on /cygdrive/f type ntfs (binary,posix=0,user,noumount,auto)
G: on /cygdrive/g type ntfs (binary,posix=0,user,noumount,auto)
Thoughts of the developer community? I have a patch that I can send to someone
if they are interested in looking at including this into cygwin.
Cheers,
Mark.
I'm new to this list so not entirely sure of the protocol, but I'd like to suggest an enhancement
to the mount capabilities of cygwin. I would guess I'm not the only one who plugs various
external drives into my PC and would like to predictably define where they get mounted
under cygwin. At the moment this is limited to just the drive letter (which can change). I
would like your thoughts on an enhancement which allowed the use of the drive UUID to
identify the connected drive letter, ie., make the drive letter dynamic. The intent is to add
an optional parameter to fstab to support UUID.
I have explored using libblkid to achieve this, however there are a few drawbacks to this
approach: It introduces a dependency on this library; when using UUID's, the mount
functions become slow as libblkid has to open the drives to read the UUID information.
In exploring this I discovered that libblkid uses /dev/disk/by-uuid to help with performance,
however this is not present in cygwin.
To cut to the chase, I've created a version which leverages aspects of the /proc virtual
filesystem, behaviours of Windows, blkid and the special file names of cygwin.
When a drive is first attached to Windows it creates a unique GUID for that drive. This does
not change (unless you deliberately delete these from the registry). These unique
references appear in the /proc filesystem as: /proc/sys/GLOBAL??/Volume{GUID}
These are links to the device under /proc/sys/Device
Also under the /proc filesystem are the drive letter references:
/proc/sys/GLOBAL??/[A-Z]:
These link to the device under /proc/sys/Device also.
So, you can map a unique device GUID to a drive letter dynamically using this information.
Now to get the UUID into the picture.
If you had a script which populated the UUID as a link to the unique volume you can map
the UUID to a drive letter dynamically by expanding the links at run-time.
/dev/disk/by-uuid/<UUID> => /dev/sys/GLOBAL??/Volume{<GUID>}
/dev/sys/GLOBAL??/Volume{<GUID>} => /dev/sys/Device/<device>
/dev/sys/Device/harddisk[0-9]*/partition[0-9]* => /dev/sys/Device/<device>
http://www.cygwin.com/cygwin-ug-net/using-specialnames.html
Provides the mapping of POSIX device name to Internal NT device name (3rd line above).
So, using this you can take the output of blkid and get a valid mapping to the various
components required above.
You can use a bootstrap process to create the /dev/disk/by-uuid/<UUID> link for each
of your devices the first time you attach them (manual process) and after this rely on
the /proc filesystem to reliably map a connected UUID drive to the mapped drive letter.
You can also rely on this to determine if it is connected as the /proc filesystem only shows
the links for connected devices, so while the /dev/disk/by-uuid link is permanent, the
destination only exists if the drive is mounted.
Sample directory listings:
$ ls -l /dev/disk/by-uuid
total 6.0K
lrwxrwxrwx 1 Administrators SYSTEM 63 Oct 3 14:56 022A4E072A4DF865 -> /proc/sys/GLOBAL??/Volume{07f378c0-0785-11e2-8b16-9d8354493d98}
lrwxrwxrwx 1 Administrators SYSTEM 63 Oct 3 11:12 20E819DCE819B150 ->/proc/sys/GLOBAL??/Volume{33795e42-562b-11e1-9e43-806e6f6e6963}
lrwxrwxrwx 1 Administrators SYSTEM 63 Oct 3 15:07 5E83-34DB ->/proc/sys/GLOBAL??/Volume{a056ffe4-c49b-11e1-9a60-e01fff2983d8}
lrwxrwxrwx 1 Administrators SYSTEM 63 Oct 3 14:56 78F07EF2F07EB5CA -> /proc/sys/GLOBAL??/Volume{82620ba9-ebef-11e1-b0aa-c0aa65e5609c}
lrwxrwxrwx 1 Administrators SYSTEM 63 Oct 2 17:41 BC28CC9C28CC56D4 ->/proc/sys/GLOBAL??/Volume{ff6beeb7-ef41-11e1-be0b-bb34ac766d9f}
lrwxrwxrwx 1 Administrators SYSTEM 63 Oct 2 17:42 D258228358226707 ->/proc/sys/GLOBAL??/Volume{ff6beea8-ef41-11e1-be0b-bb34ac766d9f}
$ ls -l /proc/sys/GLOBAL\?\?/Volume*
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:22/proc/sys/GLOBAL??/Volume{33795e42-562b-11e1-9e43-806e6f6e6963} ->/proc/sys/Device/HarddiskVolume1
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:22/proc/sys/GLOBAL??/Volume{33795e45-562b-11e1-9e43-806e6f6e6963} ->/proc/sys/Device/CdRom0
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:22/proc/sys/GLOBAL??/Volume{a056ffe4-c49b-11e1-9a60-e01fff2983d8} ->/proc/sys/Device/HarddiskVolume24
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:22/proc/sys/GLOBAL??/Volume{ff6beea8-ef41-11e1-be0b-bb34ac766d9f} ->/proc/sys/Device/HarddiskVolume30
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:22/proc/sys/GLOBAL??/Volume{ff6beeb7-ef41-11e1-be0b-bb34ac766d9f} ->/proc/sys/Device/HarddiskVolume29
$ ls -l /proc/sys/GLOBAL\?\?/[A-Z]:*
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:23 /proc/sys/GLOBAL??/C: ->/proc/sys/Device/HarddiskVolume1
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:23 /proc/sys/GLOBAL??/D: ->/proc/sys/Device/CdRom0
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:23 /proc/sys/GLOBAL??/E: ->/proc/sys/Device/HarddiskVolume24
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:23 /proc/sys/GLOBAL??/F: ->/proc/sys/Device/HarddiskVolume29
lr--r--r-- 1 Administrators SYSTEM 0 Oct 4 10:23 /proc/sys/GLOBAL??/G: ->/proc/sys/Device/HarddiskVolume30
Sample fstab:
# For a description of the file format, see the Users Guide
# http://cygwin.com/cygwin-ug-net/using.html#mount-table
# This is default anyway:
# none /cygdrive cygdrive binary,posix=0,user 0 0
/slots UUID=D258228358226707 /mnt/vtapes/slots none binary,user
/slots UUID=BC28CC9C28CC56D4 /mnt/archive/slots none binary,user
/slots UUID=5E83-34DB /mnt/4Gmodem/slots none binary,user
Output from mount:
$ mount
C:/cygwin/bin on /usr/bin type ntfs (binary,auto)
C:/cygwin/lib on /usr/lib type ntfs (binary,auto)
C:/cygwin on / type ntfs (binary,auto)
E:/slots on /mnt/4Gmodem/slots type vfat (binary,user)
F:/slots on /mnt/archive/slots type ntfs (binary,user)
G:/slots on /mnt/vtapes/slots type ntfs (binary,user)
C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
E: on /cygdrive/e type vfat (binary,posix=0,user,noumount,auto)
F: on /cygdrive/f type ntfs (binary,posix=0,user,noumount,auto)
G: on /cygdrive/g type ntfs (binary,posix=0,user,noumount,auto)
Thoughts of the developer community? I have a patch that I can send to someone
if they are interested in looking at including this into cygwin.
Cheers,
Mark.