int main(int argc, char *argv[]) { int dr = 0; if (1 < argc) dr = toupper(*argv[1]) - '@'; printf ("drive_type(%d) = %d\n", dr, drive_type(dr)); return 0; }
drives_s* drives_available(){ CFMutableDictionaryRef main_dict = NULL; CFMutableDictionaryRef sec_dict = NULL; io_iterator_t itt = IO_OBJECT_NULL; io_name_t cls_name; io_service_t sd = IO_OBJECT_NULL; IOCFPlugInInterface **plg_in_intf = NULL; SCSITaskDeviceInterface **dev_intf = NULL; MMCDeviceInterface **mmc_intf = NULL; SInt32 score = 0; int count; int ret = 1; drive_s* d = 0; drives_s* dd = 0; if((main_dict = CFDictionaryCreateMutable(kCFAllocatorDefault,0,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks)) != NULL){ if((sec_dict = CFDictionaryCreateMutable(kCFAllocatorDefault,0,&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)) != NULL){ CFDictionarySetValue(sec_dict,CFSTR(kIOPropertySCSITaskDeviceCategory),CFSTR(kIOPropertySCSITaskAuthoringDevice)); CFDictionarySetValue(main_dict,CFSTR(kIOPropertyMatchKey),sec_dict); CFRelease(sec_dict); } } if(IOServiceGetMatchingServices(kIOMasterPortDefault,main_dict,&itt)){ printf("no matching services\n"); return 0; } count = 0; while((sd = IOIteratorNext(itt))) { if(!IOObjectGetClass(sd,cls_name)){ if(!IOCreatePlugInInterfaceForService(sd,kIOMMCDeviceUserClientTypeID,kIOCFPlugInInterfaceID,&plg_in_intf,&score) && !(*plg_in_intf)->QueryInterface(plg_in_intf,CFUUIDGetUUIDBytes(kIOMMCDeviceInterfaceID),(LPVOID*)&mmc_intf)) { dev_intf = (*mmc_intf)->GetSCSITaskDeviceInterface(mmc_intf); if(dev_intf){ drive_data_s dd; dd.mmc_intf = mmc_intf; dd.plg_in_intf = plg_in_intf; dd.itt = itt; dd.dev_intf = dev_intf; if(drive_type((int)&dd) == T_CDROM){ inquiry_s* inq; count++; d = (drive_s*)realloc(d,count*sizeof(drive_s)); inq = drive_inquiry((int)&dd); memcpy(&d[count-1].name,inq->p_id,sizeof(inq->p_id)); d[count-1].id = count; free(inq); } } } if(IOObjectRelease(sd)) ret = 0; } if(mmc_intf != NULL)(*mmc_intf)->Release(mmc_intf); if(plg_in_intf != NULL)IODestroyPlugInInterface(plg_in_intf); } IOObjectRelease(itt); dd = (drives_s*)malloc(sizeof(drives_s)); if(dd){ dd->drives = d; dd->number = count; }else{ free(d); return 0; } if(ret) return dd; else return 0; }