我正在分发使用光盘的软件,并且在默认全速下它太嘈杂而无法接受。我的目标是使用 ioctl 降低磁盘的速度,但我不知道如何从 /Volumes/MyDisk/Application 中找到 /dev/disk(n)。
以下是我到目前为止所拥有的,但我不希望磁盘路径硬编码。
#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;
}