IOKit KEXT Won't Load If Start Code Tries to Attach and Register?
IOKit KEXT Won't Load If Start Code Tries to Attach and Register?
- Subject: IOKit KEXT Won't Load If Start Code Tries to Attach and Register?
- From: "Chase Colman" <email@hidden>
- Date: Tue, 12 Jun 2007 02:01:36 -0400
I am working on an IOKit KEXT that blocks external USB drives that are not writable. When I try to load the KEXT my computer locks up with everything except for mouse movement, but this is only when it has the code that attaches the media object and registers service. When I remove the code that attaches the media and registers the service the KEXT loads fine, but blocks all drives including the read-only ones that I want.
The code I will give is heavily based off of the SampleFilterScheme example. The attachMediaObjectToDeviceTree function is exactly the same as the one from the SampleFilterScheme example.
Declarations:
IOMedia* _childMedia;
UInt32 _partitionCount;
Code:
bool com_ChangeLater_driver_TouchDrives::start(IOService* provider) {
IOMedia* media = OSDynamicCast(IOMedia, provider);
assert(media);
if (super::start(provider)==false) return false;
IOMedia* childMedia = new IOMedia;
if (childMedia) {
if (childMedia->init(0,
media->getSize(),
media->getPreferredBlockSize(),
media->isEjectable(),
false,
false //Don't allow any write access.
)) {
_partitionCount++;
char name[24];
sprintf(name,"ChangeLater_External%ld",_partitionCount);
childMedia->setName(name);
char location[12];
sprintf(location,"%ld",_partitionCount);
childMedia->setLocation(location);
_childMedia=childMedia;
childMedia->attach(this);
if (media->isWritable()==false) {
DEBUG_LOG("about to attach");
(void) attachMediaObjectToDeviceTree(childMedia);
DEBUG_LOG("attached, about to register");
childMedia->registerService();
}
DEBUG_LOG("passed attach®");
return true;
} else {
childMedia->release();
childMedia=0;
}
}
return false;
}Here is the IOKitPersonalities:
<key>CFBundleIdentifier</key>
<string>com.ChangeLater.driver.TouchDrives</string>
<key>IOClass</key>
<string>com_ChangeLater_driver_TouchDrives</string>
<key>IOProviderClass</key>
<string>IOMedia</string>
<key>Physical Interconnect</key>
<string>USB</string>
<key>Physical Interconnect Location</key>
<string>External</string>
<key>IOMatchCategory</key>
<string>IOStorage</string>
If anyone could help me figure out why it is locking up my system instead of attaching and registering, I would be very appreciative. A fix would be good too.
Thanks,
Chase
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden