How can we open a hard drive using kernel extension in Mac OSx?

172 views Asked by At

I am trying to open(access) a volume of hard drive using below code in app.

  int mode=0;
  int hd_h=-1;
  const char* device  =   "/dev/rdisk1”
  mode=O_RDWR|mode_basic;
  hd_h = open(device, mode);

When I executed above code it returns error "Operation not permitted". Then I searched how it can be achieved and found one answer using kext we can achieve it. I created a sample kext(driver) to access harddrive in kernel space. can anybody assist how can I open volume in kext and return to user space. I have created a IOUserClient subclass and calling IOServiceOpen() in user space .

CFDictionaryRef     matchingDict = NULL;
    io_iterator_t       iter = 0;
    io_service_t        service = 0;
    kern_return_t       kr;
    
    // Create a matching dictionary that will find any USB device
    matchingDict = IOServiceMatching("com_osxkernel_driver_IOKitTest");
    
    // Create an iterator for all IO Registry objects that match the dictionary
    kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter);
    if (kr != KERN_SUCCESS)
        return -1;    
0

There are 0 answers