Performing read/write operations inside filter scheme drivers default write call
Performing read/write operations inside filter scheme drivers default write call
- Subject: Performing read/write operations inside filter scheme drivers default write call
- From: Yogesh P <email@hidden>
- Date: 29 Jun 2005 19:25:56 +0530
Hi folks,
I am implementing my own read/write calls in filter scheme driver.
When i load the filter scheme driver following two functions gets called
by default:
void com_My_driver::read(IOService* provider,
UInt64 byteStart,
IOMemoryDescriptor* buffer,
IOStorageCompletion completion)
{
getProvider()->read(this, byteStart, buffer, completion);
}
void com_My_driver::write(IOService* provider,
UInt64 byteStart,
IOMemoryDescriptor* buffer,
IOStorageCompletion completion)
{
getProvider()->write(this, byteStart, buffer, completion);
}
AFAIK,the IOMemoryDescriptor* buffer in write call contains the data
that user writes on any IOMedia which gets exposed after loading the
driver.
I have to do the following things:
1) I have to hold the buffer that comes in the IOMemoryDescriptor*
buffer in write call for few seconds.
2) Inside the above write call,i have to read the data on the disk from
the same byteStart that comes in the UInt64 byteStart parameter of the
write call.
3) After reading the data I have to write the same data returned by read
call, on some other exposed IOMedia partition.
4) Finally i have to write the IOMemoryDescriptor* buffer in above write
call at the UInt64 byteStart on the expose IOMedia partition.
I am able to do the step(2) i.e I am able to read the data from the disk
at specified byteStart,but the system is crashing when writing the same
data read from the disk on other IOMedia partition.
I have to perform read() then write operation inside drivers default
write call.
My code snippet for the read/write call is as follows:
void com_My_driver::write(IOService* provider,
UInt64 byteStart,
IOMemoryDescriptor* buffer,
IOStorageCompletion completion)
{
IOLog("\n Driver Write::....\n");
// Allocate buffer to read the data on the disk.
UInt32 BufferSize = 512;
IOBufferMemoryDescriptor *ReadBuffer;
ReadBuffer = IOBufferMemoryDescriptor::withCapacity(BufferSize,
kIODirectionIn);
if(!ReadBuffer)
{
IOLog("\n Inside if of Readbuffer..\n");
ReadBuffer->release();
ReadBuffer = 0;
}
else
{
IOLog("\n Inside else of Readbuffer..\n");
ReadBuffer->prepare();
_filteredMedia->IOStorage::read(this, 512, ReadBuffer);
IOByteCount bufLength = ReadBuffer->getLength();
IOLog("\n bufLength = %lu\n", bufLength);
IOByteCount readBytes;
char *ReadBuff = new char[bufLength];
readBytes = ReadBuffer->readBytes(0, ReadBuff, bufLength);
IOLog("\nAFTER Read** readBytes = %lu\n", (long) readBytes);
IOLog("\nAFTER Read** Readbuffer = %s\n", ReadBuff); /*ReadBuff
prints the data written on the disk*/
ReadBuffer->setDirection(kIODirectionOut);
char MediaName[MAX_MEDIANAME];
sprintf(MediaName, "%s", _media->getName());
IOLog("\n Name of media in driver write = %s\n", MediaName);
if(strcmp(MediaName, "VolName1") == 0) /*IOMedia VolName1*/
{
IOLog("\n Inside if of\n");
_filteredMedia->IOStorage::write(this, 0, ReadBuffer);
/*getting crash when calling IOStorage write call*/
IOLog("\n Inside if of After write\n");
}
ReadBuffer->complete();
ReadBuffer->release();
ReadBuffer = 0;
delete[] ReadBuff;
}
getProvider()->write(this, byteStart, buffer, completion);
}
Is am i doing something wrong in writting the data?
Thanks in advance.
YogeshP
_______________________________________________
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