• 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: Writing to disk using filter scheme driver
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing to disk using filter scheme driver


  • Subject: Re: Writing to disk using filter scheme driver
  • From: Yogesh P <email@hidden>
  • Date: 04 Apr 2005 19:29:44 +0530

Hi Dan,

I have make some changes in my code as follows.
UserkernelShared.h includes the following structure.
typedef struct  MySampleStruct
{
  UInt32 size;
  char* buff;
} MySampleStruct;

// these are the User Client method names
enum
{
    kMyUserClientOpen,
    kMyUserClientClose,
    kMyDoWrite,
    kMyDoRead,
    kMyNumberOfMethods
};
In main function of userspace application i am calling the MyDoWrite
function as follows
kernResult = MyDoWrite(dataPort);
if (kernResult != KERN_SUCCESS)
{
     printf("\n kMyDoWrite returned %d\n", kernResult);
     fflush(stdout);
}
The definition of MyDoWrite is as follows.
MyDoWrite(io_connect_t connect)
{   kern_return_t     kernResult;
    MySampleStruct    sampleStruct;
    char *buf;
    UInt32 size;
    size = kBufSize; //kBufSize = 512
    buf = malloc(sizeof(char) * kBufSize);
    bzero(buf, sizeof(char) * kBufSize);
    strcpy(buf, "Hello MAC.OS.X");
    sampleStruct.size = size;
    sampleStruct.buff = buf;

    IOByteCount structSize = sizeof(MySampleStruct);

    if (!connect)    {
        return kIOReturnNoDevice;
    }
    else    {        kernResult =
			IOConnectMethodScalarIStructureI(connect,
                                            kMyDoWrite,
                                            0,
                                            structSize,
                                            &sampleStruct
                                            );
    }
    if (kernResult == kIOReturnSuccess)
    {
        printf("\n kMyDoWrite was successful..........\n");
    }
    return kernResult;
}
My Userclient.h includes the following code.
class com_MySoftwareCompany_MyUserClient : public IOUserClient //derived
from IOUserClient

IOService*                  fProvider; //previously i was mentioned
					//com_MySoftwareCompany_driver_MyFilterSchemeheme


My Userclient.cpp includes the following code.
IOExternalMethod *
com_MySoftwareCompany_MyUserClient::getTargetAndMethodForIndex(IOService
** target, UInt32 index)
{
       { // kMyDoWrite
            NULL,
            (IOMethod) &com_MySoftwareCompany_MyUserClient::myDoWrite,
            kIOUCScalarIStructI,
            0,
            sizeof(MySampleStruct)
       },*/
}

IOReturn com_MySoftwareCompany_MyUserClient::myDoWrite(MySampleStruct *
vInStruct, UInt32 * structSize)
{   IOReturn retWrite = kIOReturnSuccess;
    char *buf;
    UInt32 Size;
    IOService* ffProvider;
    memset(buf, 0x0, 512);
    buf = vInStruct->buff;
    Size = vInStruct->size;

   if ( *structSize != sizeof(MySampleStruct))
                    return kIOReturnBadArgument;

     if (fProvider && !isInactive())
    {
          IOMemoryDescriptor *mem = IOMemoryDescriptor::withAddress(buf,
Size, kIODirectionOut, fTask);
          if (mem)
          {
                retWrite = mem->prepare();
                if(kIOReturnSuccess == retWrite)
                {
                   ffProvider =
OSDynamicCast(com_MySoftwareCompany_driver_MyFilterScheme, fProvider);
// is this a correct way of casting???

                    if (!ffProvider)
                    {
                           return false;
                    }
                    else
                    {
        		   //retWrite = ffProvider->write(provider, 512, mem,
completion);
                            retWrite = ffProvider->DoDriverWrite(mem);
                    }
                }
		mem->complete();
                mem->release();
          }
          else
          {
               retWrite = kIOReturnNoMemory;
          }
          release();
    }
    else
    {
         retWrite = kIOReturnNotAttached;
    }

    if (kIOReturnSuccess != retWrite)
    {
        IOLog("\n myDoWrite returned = %d\n", retWrite);
    }

    return retWrite;
}

But i am still facing the same problem that "no matching function
IOService::DoDriverWrite()"

And if i have to call driver routine from my userclient how should i
call them???

Thanks in Advance,
Yogesh Pahilwan


On Thu, 2005-03-31 at 02:44, Dan Markarian wrote:
> Hi Parav,
>
> I believe I see the disconnect.  I saw MySampleStruct and was under
> the impression that MySampleStruct is what carries the "buf" address
> and the "buf" size into the kernel.  It seems, rather, that it passes
> the "buf" address and "buf" size as a variable-size structure across
> the user client interface.  You might wish to note that technique is
> limited to 4 kB, I believe, and does involve a copy across the kernel
> boundary.  I am not sure what the problem is though offhand.  It
> might be one of:
>
> > > size = kBufSize;
>
> size = 1024;
>
> > > bzero(buf, sizeof(char) * 1048576);
>
> bzero(buf, sizeof(char) * 1024);
>
> > > IOMemoryDescriptor *mem = IOMemoryDescriptor::withAddress(buf,
> > > 1024,
> > > kIODirectionOut);
>
> IOMemoryDescriptor *mem = IOMemoryDescriptor::withAddress(buf,
> size,
> kIODirectionOut);
>
> Dan
>
> On 30 Mar 2005, at 12:44 PM, Parav Pandit wrote:
>
> > > com_MySoftwareCompany_driver_MyFilterScheme*        fProvider;
> >
> > I am sorry, I haven't look the code properly.
> > you have fProvider of your filterScheme class.
> >
> > fTask would tell to map in kernel userClient context for calling
> > task - fTask but than how this would solve the problem of calling
> > the driver function?
> >
> > Please help me to understand.
> > fTask is the application task which has made the code to driver. is
> > this correct?
> > We need to share memory between kernel task and user space, so why
> > to give fTask rather than kernel_task?
> > I couldn't find the answer from the Writing custom user client
> > docuement.
> >
> > Regards,
> > Parav Pandit
> >
> >
> >
> > Dan Markarian <email@hidden> wrote:
> > Hi Yogesh,
> >
> > > IOMemoryDescriptor *mem = IOMemoryDescriptor::withAddress(buf,
> > > 1024, kIODirectionOut);
> >
> > IOMemoryDescriptor *mem = IOMemoryDescriptor::withAddress(buf,
> > 1024, kIODirectionOut, fTask);
> >
> > Dan
> >
> > On 30 Mar 2005, at 7:54 AM, Yogesh P wrote:
> >
> > > Hi folks,
> > > I have written a filter scheme driver,userclient and userspace
> > > application tool for doing read/write operations on IOMedia
> > > partitions.
> > >
> > > I have successfully send a structure from userspace to kernelspace
> > > through userclient.But when i try to read/write a buffer from
> > > userspace
> > > to kernel space,i am not able to map userspace buffer to kernel
> > > address
> > > space.
> > > I am specifying my code here.
> > > UserkernelShared.h includes the following structure.
> > > typedef struct MySampleStruct
> > >! { UInt32 size;
> > > void* buff;
> > > } MySampleStruct;
> > > In main function of userspace application i am calling the
> > > SPSOFT_Write
> > > function as follows.
> > > char *buf;
> > > UInt32 size;
> > > size = kBufSize;
> > > buf = malloc(sizeof(char) * 1024);
> > > bzero(buf, sizeof(char) * 1048576);
> > > strcpy(buf, " Hello MACOSX");
> > >
> > > I want to write this "buf" to the disk through userclient.
> > >
> > > // This shows an example of calling a user client's open method.
> > > kernResult = MyDoWrite(dataPort, buf, size);
> > > if (kernResult != KERN_SUCCESS)
> > > { printf("\n kMyDoWrite returned %d\n", kernResult);
> > > // This closes the connection to our user client and destroys the
> > > connect handle.
> > > IOServiceClose(dataPort);
> > > return 0;
> > > }
> > >
> > > The definition of MyDoWrite is as follows.
> > > kern_return_t
> > > MyDoWrite(io_connect_t connect, void *buf, UInt32 size)
> > > { kern_return_t kernResult;
> > > if (!connect){
> > > return kIOReturnNoDevice;
> > > }
> > > else {
> > > kernResult = IOConnectMethodScalarIStructureI(connect,
> > > kMyDoWrite,
> > > 0,
> > > size,
> > > buf
> > > );
> > > }
> > > if (kernResult == kIOReturnSuccess){
> > > printf("\n kMyDoWrite was successful..........\n");
> > > }
> > > return kernResult;
> > > }
> > > My Userclient.h and Userclient.cpp includes the following code.
> > >
> > > com_MySoftwareCompany_driver_MyFilterScheme* fProvider;
> > >
> > > IOExternalMethod *
> > > com_MySoftwareCompany_MyUserClient::getTargetAndMethodForIndex
> > > (IOService
> > > ** target, UInt32 index)
> > > {
> > > { // kMyDoWrite
> > > NULL,
> > > (IOMethod) &com_MySoftwareCompany_MyUserClient::myDoWrite,
> > > kIOUCScalarIStructI,
> > > 0,
> > > 0xffffffff
> > > },
> > > }
> > > IOReturn com_MySoftwareCompany_MyUserClient::myDoWrite(void* buf,
> > > UInt32
> > > size)
> > > { IOReturn retWrite = kIOReturnSuccess;
> > > UInt32 Size = size;
> > > if (fProvider && !isInactive()){
> > > IOMemoryDescriptor *mem = IOMemoryDescriptor::withAddress(buf,
> > > 1024,
> > > kIODirectionOut);
> > > if (mem){
> > > retWrite = mem->prepare();
> > > if(kIOReturnSuccess == retWrite){
> > > retWrite = fProvider->myDoWrite
> > > (mem,Size); //when i
> > > call this driver function it gives me the error as
> > > IOService::fProvider
> > > has no function myDoWrite.
> > > }
> > > mem->complete();
> > > mem->release();
> > > }else{
> > > retWrite = kIOReturnNoMemory;
> > > }
> > > release();
> > > }
> > >
> > > How should i call the filter scheme driver read/write routines
> > from my
> > > userclient?? Or is there any sample code of read/write for filter
> > > scheme
> > > driver???
> > >
> > > Any help, certainly help me in solving this problem.
> > > Thanks! in advance.
> > > Yogesh Pahilwan
> > >
> > >
> > >
> > >
> > >
> > >
> > > _______________________________________________
> > > Do not post admin requests to the list. They will be ignored.
> > > Darwin-kernel mailing list (email@hidden)
> > > Help/Unsubscribe/Update your Subscription:
> > > 40apple.com
> > >
> > > This email sent to email@hidden
> >
> >
> > _______________________________________________
> > Do not post admin requests to the list. They will be ignored.
> > Darwin-kernel mailing list (email@hidden)
> > Help/Unsubscribe/Update your Subscription:
> > 40yahoo.co.in
> >
> > This email sent to email@hidden
> > Yahoo! India Matrimony: Find your life partner online.
>
> ----
>

>  _______________________________________________
> 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


 _______________________________________________
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

  • Follow-Ups:
    • Re: Writing to disk using filter scheme driver
      • From: Parav Pandit <email@hidden>
References: 
 >Re: Writing to disk using filter scheme driver (From: Dan Markarian <email@hidden>)

  • Prev by Date: dlil_attah_interface_filter
  • Next by Date: m_devget
  • Previous by thread: Re: Writing to disk using filter scheme driver
  • Next by thread: Re: Writing to disk using filter scheme driver
  • Index(es):
    • Date
    • Thread