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;
}
感謝您的示例代碼!這聽起來像是它可能是最好的解決方案。我也在研究在捲上使用statfs.f_mntfromname,但它返回的東西不適用於ioctl。感謝您的迴應! – 2012-02-17 06:32:19