• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Notifications when iPods are mounted...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Notifications when iPods are mounted...


  • Subject: Re: Notifications when iPods are mounted...
  • From: Steve Checkoway <email@hidden>
  • Date: Sat, 14 Jan 2006 13:38:38 -0800


On Jan 14, 2006, at 7:44 AM, Uli Kusterer wrote:

Am 14.01.2006 um 06:58 schrieb Steve Checkoway:
I'm not quite sure which info you're looking for here, but see below.

Ummm... I just realised that half of my devices don't have the name I was looking for (or have the same), so it's moot. :-( And just for the archives: IORegistryEntryGetName() only gives the volume name (i.e. the name shown in Finder that the user can change).


But I guess the USB Vendor and Device ID would serve the same purpose.

It's probably best to use those.


About the easiest way to do this is to get the notification from NSWorkspace (or the Carbon event), get the mounted path to the device and call statfs(2) on that path. Then, if you look at the f_mntfromname member of the statfs struct, it should start with / dev/ (or _PATH_DEV as defined in <paths.h>). Remove that bit and you should have disk[#[s#]]. To get the io_object_t that you would use with the IOKit, you set up a matching dictionary using IOBSDNameMatching() followed a call to IOServiceGetMatchingServices () to get an io_iterator_t to iterate over the devices.

Okay, I got this working as well (though using Carbon's PBHGetVolParmsSync() instead of statfs()). The trouble is that the IOKit device doesn't seem to have any vendor and device IDs. When I call IORegistryEntryCreateCFProperties(), I get:


<snip>

Lots of info I can use for other nefarious purposes, but nothing that even remotely looks like those IDs. I guess I could take all the possible vendor/device IDs and match for each one with IOServiceGetMatchingServices(), but since the typical user will have at most one of these devices attached and the list of possible ones could be rather large, I'd rather just be able to check the newly-inserted device's ID.

I also tried checking the parents of this service, but they didn't contain any info that was much different.

 errr... help?


You have to quite a ways up to find the information you want. The way I did it may not be the best but it seems to work. Basically, you look at the registry path and then chop off a bunch until you get to what you want. If iter is the io_iterator_t, you can do this:


io_registry_entry_t entry;
while( (entry = IOIteratorNext(iter)) )
{
io_string_t path;
kern_return_t ret = IORegistryEntryGetPath( entry, kIOServicePlane, path );


	IOObjectRelease( entry );

	if( ret != KERN_SUCCESS )
	{
		// I have yet to have this code execute...
		continue;
	}
	string registryPath = path;
	string::size_type pos = registryPath.rfind( "/IOUSBMassStorageClass" );

	if( pos == string::npos )
		continue; // Not a USB mass storage device
	pos = registryPath.rfind( '/', pos - 1 );
	if( pos == string::npos )
		continue;
	path[pos] = '\0';

io_registry_entry_t device = IORegistryEntryFromPath ( kIOMasterPortDefault, path );

if( device == MACH_PORT_NULL ) // I have no idea why this can return that
continue;
/* At this point you can use IORegistryEntryCreateCFProperty()
* to get kUSBVendorID, kUSBProductID, "USB Vendor Name",
* "USB Product Name", "USB Serial Number", etc. */


	IOObjectRelease( device );
}

Typed in Mail and all that implies. I hope it is helpful.

- Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Notifications when iPods are mounted... (From: <email@hidden>)
 >Re: Notifications when iPods are mounted... (From: Eamon Ford <email@hidden>)
 >Re: Notifications when iPods are mounted... (From: Uli Kusterer <email@hidden>)
 >Re: Notifications when iPods are mounted... (From: Steve Checkoway <email@hidden>)
 >Re: Notifications when iPods are mounted... (From: Uli Kusterer <email@hidden>)

  • Prev by Date: Re: Cocoa Custom NSCell Binding Issue
  • Next by Date: NSScroller
  • Previous by thread: Re: Notifications when iPods are mounted...
  • Next by thread: Re: Notifications when iPods are mounted...
  • Index(es):
    • Date
    • Thread