Re: How to get a vendor and product ID of a mounted flash drive?
Re: How to get a vendor and product ID of a mounted flash drive?
- Subject: Re: How to get a vendor and product ID of a mounted flash drive?
- From: Nick <email@hidden>
- Date: Fri, 16 Dec 2011 18:12:09 +0200
Aaron,
Thanks for the response. I have asked the question in drawin-dev list
either, after not getting response in usb list.
My basic question was - how to get the mounting point (/Volumes/My
Disk Name/) when the disk has been mounted.
Disk Arbitration's DeviceAppeared callback usually gives me a
DADiskRef which has a kDADiskDescriptionVolumePathKey property, which
contains this mounting point.
However, if the device wasn't properly ejected previously (just
unplugged from the usb port), after it has been plugged in back, the
callback is called without this "mounting point"
property key. I can't retrieve the mounting point for each next device
connection, unless it has been unmounted in a graceful way previously.
The callback is being called, though, and I get DADiskRef,
disregarding on how the device was ejected. I just need to get where
it has been (re)mounted. Is there a way, using DA or IOKIT to get the
mounting point?
2011/12/16 Aaron Burghardt <email@hidden>:
> Hi Nick,
>
> I presume you know the VID/PID of your device but you want to easily identify when and where it's mounted. Here is one approach:
>
> 1. Register for an I/O Kit callback to match your VID/PID when it shows up.
>
> 2. In your callback, get the IOMedia objects created for your device.
>
> 3. With the IOMedia objects, use a property such as BSD Name to register for a matching disk appeared or disk mount approval callback from the Disk Arbitration (DA) framework.
>
> 4. In your DA callback, do whatever you were looking to do. Note, if the the disk was already mounted when you register for the did appear callback, you should still receive your callback, but I'm not certain of that.
>
> This approach has the advantage of filtering callbacks to only the I/O Kit and DA objects to only the ones you are interested in.
>
> You may have to experiment with the callbacks to get the timing you need, but most of these callbacks will happen sooner than the NSWorkspace notification you referenced. If you want to guarantee that you have access to the disk before it is mounted, you may have to register with DA for all disks, then inspect the parents of each IOMedia to see if your device is the source of it.
>
> I have a Disk Arbitration open source project that might be instructive:
>
> https://github.com/aburgh/Disk-Arbitrator
>
> Run it, select your disk, and click the "Info" button to get a window that is basically a dump of the DADisk description.
>
> Read up on the DA framework here:
>
> http://developer.apple.com/library/mac/#documentation/Darwin/Reference/DiscArbitrationFramework/index.html
>
> Also, any followups should probably be to another mailing list, such as the darwin-dev. The fact that your device is USB is a minor consideration.
>
> Regards,
>
> Aaron
>
>
> On Dec 15, 2011, at 4:57 AM, Nick wrote:
>
>> Hello
>> I need to check, whether the mounted flash drive is "mine".
>> At the moment I am detecting if a new device has been mounted using
>> NSWorkspace's NSWorkspaceDidMountNotification notification, which
>> returns me this in its [NSNotification userInfo]:
>>
>> userInfo = {
>> NSDevicePath = "/Volumes/NO NAME";
>> NSWorkspaceVolumeLocalizedNameKey = "NO NAME";
>> NSWorkspaceVolumeURLKey = "file://localhost/Volumes/NO NAME/";
>> }
>>
>> However, since the Volume name of the device can be changed, I need to
>> verify some other parameters of the flash drive to make sure this is
>> the right one.
>>
>> Having a mount point path, and a volume name, how can I determine
>> Vendor ID and Product ID of the flash drive?
>> As I understand, this information is stored into IO Registry, and I
>> need to query IOKit services (unless there's a more high level path)
>> but I don't know how can I connect the actual device ID with the mount
>> point that I am getting with NSWorkspace notification.
>>
>> Unlike the IO Registry Explorer, a console utility "system_profiler",
>> listing all the connected devices, also shows their mount points. How
>> this is done?
>>
>> Can you give me an advice?
>> Thank you
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Usb mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden