2012-02-16 2 views
1

광 디스크를 사용하는 소프트웨어를 배포하고 있으며 기본 속도로는 너무 시끄 럽기 때문에 수용 할 수 없습니다. 내 목표는 ioctl을 사용하여 디스크의 속도를 줄이는 것이지만/Volumes/MyDisk/Application에서/dev/disk (n)을 찾는 방법을 모르겠습니다.OSX CD 속도 받기 (ioctl)

다음은 지금까지 가지고 있지만 디스크 경로를 하드 코딩하지 않으려 고합니다.

#include <stdio.h> 
#include <stdlib.h> 
#include <fcntl.h> 
#include <IOKit/storage/IOCDMediaBSDClient.h> 

int main() { 
    // ------------------------------------ 
    // Open Drive 
    // ------------------------------------ 
    int fd = open("/dev/disk1",O_RDONLY); 
    if (fd == -1) { 
     printf("Error opening drive \n"); 
     exit(1); 
    } 

    // ------------------------------------ 
    // Get Speed 
    // ------------------------------------ 
    unsigned int speed; 
    if (ioctl(fd,DKIOCCDGETSPEED,&speed)) { 
     printf("Must not be a CD \n"); 
    } 
    else { 
     printf("CD Speed: %d KB/s \n",speed); 
    } 

    // ------------------------------------ 
    // Close Drive 
    // ------------------------------------ 
    close(fd); 
    return 0; 
} 

답변

2

/dev에있는 디스크 항목을 열고 각각을 열고 다른 유형의 ioctl()을 사용하여 유형을 식별해야 할 수도 있습니다.

#include <stdio.h> 
#include <stdlib.h> 
#include <fcntl.h> 
#include <IOKit/storage/IOCDMediaBSDClient.h> 

int main(int argc, char *argv[]) 
{ 
    int i, fd; 
    unsigned short speed; 
    char disk[40]; 

    for (i = 0; i < 100; ++i) 
    { 
     sprintf(disk, "/dev/disk%u", i); 
     fd = open(disk, O_RDONLY); 
     if (fd != -1) 
     { 
      if (ioctl(fd, DKIOCCDGETSPEED, &speed)) 
      { 
       printf("%s is not a CD\n", disk); 
      } 
      else 
      { 
       printf("%s CD Speed is %u KB/s\n", disk, speed); 
      } 
      close(fd); 
     } 
    } 

    return 0; 
} 

DVD 드라이브에 디스크가없는 나의 구형 MacBook Pro에서는 disk0이나 disk1이 CD 드라이브가 아님을 알려줍니다. 디스크를로드하고 속도를 위해 부호없는 short를 사용하도록 코드를 고정하면/dev/disk2를 4234KB/s 속도의 CD로보고합니다.

+0

예제 코드를 제공해 주셔서 감사합니다! 이것은 최상의 솔루션 일 것 같은데. 나는 또한 볼륨에 statfs.f_mntfromname을 사용하는 방법을 찾고 있지만 ioctl에서는 작동하지 않는 것을 반환하고있다. 응답 주셔서 감사합니다! –