Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unique Identifier for Disk



On Mon, 26 Apr 2004 22:15:20 -0500, Jeffrey Berman <email@hidden> wrote:

On 4/26/04 4:44 PM, email@hidden wrote:

Is there a unique identifier for a disk that is not the startup disk
and that would persist over restarts so that an AppleScript script
referring to the disk would work as expected even if the name of the
disk changes?

Yes, via unique UNIX identifier from which one can then obtain the
User editable Volume Name.

'df | grep '/dev/'| awk '{print $1}'' - via 'Terminal', or
do shell script ("df | grep '/dev/' | awk '{print $1}'") - via
AppleScript's 'Script Editor' will display the UNIX low level
assignment of each mounted Volume.

Will the identifier stay the same across restarts? For example, if the
device file name in the /dev directory representing a volume is "disk0s10",
will this be the same each time the machine is restarted?


Replacing '$1' with '$6' will instead display the User's editable
Name of the mounted Volume(s).

Using '$6' captures the path (not the name) and then only up to the first
word of a disk name if there are spaces in the name. For example, if the
name of the disk is "OS X", the syntax returns "/Volumes/OS" for that line.

One could get the disk name associated with "disk0s10" (and eliminate the
grep pipe) using the following:

df | awk -F/ '/disk0s10/ {print $5}'

However, getting the disk name this way is not of much use unless the
associated device file name in the /dev directory is unique across restarts.

Does anyone know if this is the case?

-Jeffrey Berman

No, the device entry is not guaranteed to be the same across restarts. Internal drives (other than the startup drive) may spin up and be identified in a non-deterministic order. Removable media (flash memory devices, optical discs, etc.) may be present or absent. External devices (FireWire and USB drives) may be powered up or not. After boot, devices may be unmounted and remounted in a different order (Disk Utility). Disk images may be mounted and unmounted. All the while device identifiers are being dynamically assigned and revoked.

But HFS formatted hard drives are assigned a unique identifier when they are formatted. For example, the following bash pipeline displays the unique identifier and mount point for all locally mounted volumes:

df -t hfs | tail +2 | sed -e 's|^/dev/||' | while read d b u a c m; do
x=$(/System/Library/Filesystems/hfs.fs/hfs.util -k "$d"); echo "$x $m";
done

Transforming the above shell syntax into AppleScript which performs the originally requested actions is left to the reader. :-)

Michael
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.