| Hi Wenhua,
Why do you need to do it at the IOBlockStorageServices layer? You can implement "read, write and all other IO related methods" by subclassing IOSCSIPeripheralDeviceType00, so what makes IOBlockStorageServices more useful to you? What is in IOBlockStorageServices that precludes IOSCSIPeripheralDeviceType00?
To answer to your question, though, subclass CreateStorageServiceNub() in IOSCSIPeripheralDeviceType00 to allocate MyIOBlockStorageServices in place of IOBlockStorageServices. I do not see the point, based on such reasons, but that is how to do it.
Dan
On 9 Jun 2005, at 1:44 PM, Wenhua Liu wrote: Hi Dan, I am aware of that difference, but for my special purpose, I have to implement read, write and all other IO related methods(formatMedia,ejectMedia and others) by subclassing IOBlockStorageServices. I just want to know: If I embed an object of class IOBlockStorageServices in MyIOBlockStorageServices, before it can be referenced for IO handling, what should I do on this object? Thanks. Hi Wenhua,
There is a difference. The latter is not a driver.
Introduction to Writing Drivers for Mass Storage Devices
http://developer.apple.com/documentation/DeviceDrivers/Conceptual/ MassStorage/01_Introduction/chapter_1_section_1.html#//apple_ref/doc/ uid/TP30000733
"If, however, your hard drive implements its read command differently than the specification, you can simply subclass the IOSCSIPeripheralDeviceType00 driver to create a new driver whose only function is to override the read command implementation."
You can override AsyncReadWrite(), EjectTheMedium(), FormatMedium(), etc, to call into a custom method that does it all. You can subclass it to do whatever you need. Please see the documentation on the remainder of the details.
Dan
On 9 Jun 2005, at 1:00 PM, Wenhua Liu wrote:
&g! t; Hi Dan, > > Thank for your reply. > > There is no difference to subclassing IOSCSIPeripheraldeviceType00 > than subclassing IOBlockStorageServices, I still need to subclass > all those IO related methods, that's why I had my questions posted > here. > > Wenhua > > Dan Markarian wrote: > Hi Wenhua, > > Why not subclass AsyncReadWrite(), EjectTheMedium(), FormatMedium(), > etc, in IOSCSIPeripheralDeviceType00? IOBlockStorageServices routes > those calls through there. > > Dan > > On 8 Jun 2005, at 3:56 PM, Wenhua Liu wrote: > > > Hi, > > > > I'm writing my logical unit driver by subclassing > > IOSCSIPeripheralDeviceType00 and > > IOBlockStorageServices(class of device services nub). > > I need to implement some common functions in most of > > I/O related methods in cla! ss IOBlockStorageServices, > > such as doAsyncReadWrite, doSyncReadWrite, > > doEjectMedia, doFormatMedia and others. If all this > > methods call a common method, I just need to rewrite > > this method, this would be the best way. But there is > > no such a method, so this is not doable. > > > > If I rewrite all thoses metho! ds, it'll be too much > > work, the worse thing is I have to maintain all those > > methods even I don't change them. So I have another > > idea. > > > > 1. By subclassing IOBlockStorageServices, my driver > > can provide the same interface to the clients. > > 2. By embedding an object of class > > IOBlockStorageServices in my subclass, my driver can > > reuse the methods of class IOBlockStorageServices. > > > > Here is the definition of my subclass > > > > class MyIOBlockStorageServices : public > > IOBlockStorageServices > > { > > OSDeclareDefaultStructors (MyIOBlockStorageServices) > > > > private: > > IOBlockStorageServices parentObject; > > > > public: > > virtual IOReturn doAsyncReadWrite ( > > IOMemoryDescriptor * buffer, > > UInt32 block, > > UInt32 nblks, > > IOStorageCompletion completion ); > > > > // more methods defined here > > > > }; > > > > H! ere is the implementation of method > > doAsyncReadWrite(): > > > > IOReturn > > MyIOBlockStorageServices :: doAsyncReadWrite ( > > IOMemoryDescriptor * buffer, > > UInt32 block, > > UInt32 nblks, > > IOStorageCompletion completion ) > > { > > // do some common stuff here > > > > // call parentObject's s! ame method > > > > return parentObject->doAsyncReadWrite (buffer, block, > > nblks, completion); > > } > > > > > > People may ask why I don't implentment my own method > > using super::doAsyncReadWrite(). I want to do so, but > > for my special purpose, I can't do it. > > > > > > My question is: in order to implement my subclass like > > what I described above, what should I > > do(initialization, attach, registration, or something > > else) to make sure when parentObject is referenced for > > calling its methods, everything is valid? > >
|