| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
On 04/03/07, NAHieu <email@hidden> wrote:
Hello,
I am writing an application (running in userspace) to detect all the
USB storage devices currently connected to my Tiger box.
A naive way is to look for all the mount directories under /Volumes.
However, the (internal) HDDs are also mounted there. Besides,
sometimes software packages might also mount there. So I found that
this way does work well.
Any hint on how to solve this problem? I suspect that it is possible
to verify if those mounted directories are from USB devices or not,
but I dont know how to do that.
Many thanks,
Hieu
Hieu,
Sorry if this is a bit pedantic (I'd rather give you the tools than write the code to give you your exact answer).
Start with the VolumeToBSDNode sample (developer.apple.com <http://developer.apple.com> ). That doesn't quite do what you want but that's your first step.
Now, plug your USB storage device into your machine. When it mounts, open a Terminal window and execute the "df" command
e.g.
$df
Filesystem 512-blocks Used Avail Capacity Mounted on
/dev/disk0s2 487725344 322404632 164808712 66% /
/dev/disk4s2 2212616 702824 1509792 32% /Volumes/iDisk
/dev/disk5s1 2004912 1605848 399064 80% /Volumes/Key
disk0s2 (disk 0, slice 2) is my root device
disk4s2 is where my iDisk mounts. (disk4s2 is the bsd name)
disk5s1 is my USB Key
Find the bsd name that corresponds to you USB Key
now type in "ioreg -l" and you'll get a rather large dump in your Terminal window.
Find the bsd name that corresponds to your usb key (e.g. disk5s1)
Mine is:
| | | | | +-o Apple_HFS_Untitled_1@1 <class IOMedia, registered, matched, active, busy 0, retain count 8>
| | | | | | {
| | | | | | "Leaf" = Yes
| | | | | | "Writable" = Yes
| | | | | | "BSD Minor" = 17
| | | | | | "IOBusyInterest" = "IOCommand is not serializable"
| | | | | | "Partition ID" = 1
| | | | | | "Preferred Block Size" = 512
| | | | | | "UUID" = "DD42F217-92C7-416C-84A6-E0296AE9BDA7"
| | | | | | "BSD Major" = 14
| | | | | | "BSD Name" = "disk5s1"
| | | | | | "Size" = 1026514944
| | | | | | "Content Hint" = "48465300-0000-11AA-AA11-00306543ECAC"
| | | | | | "Removable" = Yes
| | | | | | "BSD Unit" = 5
| | | | | | "Ejectable" = Yes
| | | | | | "Content" = "48465300-0000-11AA-AA11-00306543ECAC"
| | | | | | "Whole" = No
| | | | | | }
| | | | | |
Scroll up and you will see an IOMediaBSDClient, an IOMedia (where "Whole" = Yes), ... and further up the food chain you will see an IOUSBMassStorageClass and then then IOUSBInterface (etc., etc). Some people prefer to use IORegistryExplorer (/Developer/Applications/...).
Now do the same for the bsd name that corresponds to your root device. Notice any differences that you could search for? :-)
Now, from user space each of these entries (like the one I pasted in, above) are called "io_registry_entry_t", and going up the food chain corresponds to calling IORegistryEntryGetParentIterator() (couple that with IOIteratorNext(), IOObjectConformsTo() and IOObjectRelease() and there's your more or less complete tool set).
VolumeToBSDNode is a nice little project to play around in.
hth,
Cheers,
-H.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-userlevel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-userlevel/email@hidden
This email sent to email@hidden
_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-userlevel mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-userlevel/email@hidden This email sent to email@hidden
| References: | |
| >Re: Enumerate USB storage devices? (From: "Herb Petschauer" <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
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.