X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KHOP_THREADED,LOTS_OF_MONEY,RCVD_IN_HOSTKARMA_YE,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.7.7855,1.0.431,0.0.0000 definitions=2012-09-25_06:2012-09-25,2012-09-25,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=4 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1203120001 definitions=main-1209250335 Subject: Re: associating volume labels with drive letters From: "Mark O'Keefe" In-reply-to: <0D835E9B9CD07F40A48423F80D3B5A7001F66B@USA7109MB022.na.xerox.net> Date: Wed, 26 Sep 2012 10:36:35 +1000 Message-id: <6CC6471C-FBB4-4980-A667-E83EC841B6A6@mac.com> References: <20110729201556 DOT GA13084 AT calimero DOT vinschen DOT de> <0D835E9B9CD07F40A48423F80D3B5A7001F66B AT USA7109MB022 DOT na DOT xerox DOT net> To: "Nellis, Kenneth" , cygwin AT cygwin DOT com X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On 14/09/2012, at 12:35 AM, Nellis, Kenneth wrote: > From: Corinna Vinschen > On Jul 29 15:34, Schwarz, Konrad wrote: >>>>> Can you answer the following question: >>>>> >>>>> Given a volume label, how does one figure out where the >>>> corresponding >>>>> volume has been mounted into the Cygwin namespace? >>>> > >>> In Linux, you can look up the mount point for device /dev/sdXY >>> in /proc/mounts or in the output of mount(8). Thus, given >>> a volume label, you can figure out where to access the files >>> on the volume. >>> >>> How do you do that in Cygwin? >> >> ls /cygdrive. Insert the disk. ls /cygdrive again. There's a new >> directory entry now. >> >> Or, open the "Computer" Window on your desktop. > > Dredging up an old thread > (http://sourceware.org/ml/cygwin/2011-07/msg00390.html)... > > Regarding Corinna's last suggestion, it seems to me that if > Windows can associate a volume label with a drive letter, > there must be a way to script this association, whether > using Cygwin shell commands directly or indirectly through > DOS commands. > > Using blkid(8), from the util-linux package, I can get a device > name from a label: > > $ blkid -L CRUZER > /dev/sdc1 > > Now, if I'm on the right path, how can I associate that > block-special file with a drive letter or a /cygdrive/x > path reference? > > --Ken Nellis Hi, Here is a perl script which I believe should do the trick. It adds: (for example) DRIVE="C:" to the end of the blkid output where the drive letter matches the correct drive location. Along the same lines I've also played around with a customised version of cygwin that allows the mount command to use UUID's to identify the drive letter instead of hard coding into fstab. This would be useful if you wanted specific drives to be mounted to specific locations without dependence on the drive letter. I haven't extensively tested this, just quickly put it together to give you the idea. ------------ cut ------------- #!/usr/bin/perl use strict; use Cwd 'abs_path'; # no buffer $| = 1; my %drives; for (my $i = 0; $i < 26; $i++) { my $chr = chr(ord('A') + $i); my $str = sprintf ("/proc/sys/GLOBAL\?\?/$chr:"); if (-l $str) { my $path = abs_path ($str); $drives{"$path"} = "$chr"; } } open (BLKID, "blkid |") or die "Failed: $!"; while () { chomp; my $line = $_; my $drive; # Print the blkid line. printf ("%s", $line); # Deal with harddisk case. if (s|(^/dev/sd)([a-z]*)([0-9]*):.*$|$1$2$3|) { # Convert to cygwin device. my $disk = ord(substr($2, 0, 1)) - ord('a'); if (length($2) == 2) { $disk = ($disk + 1) * 26 + (ord(substr($2, 1, 1)) - ord('a')); } my $partition = ord(substr($3, 0, 1)) - ord('0'); if (length($3) == 2) { $partition = ($partition * 10) + (ord(substr($3, 1, 1)) - ord('0')); } my $path = abs_path("/proc/sys/Device/harddisk${disk}/partition${partition}"); $drive = $drives{$path}; printf (" DRIVE=\"%s:\"\n", $drive); } } ------------ cut ------------- Cheers, Mark. -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple