1

光ディスクを使用するソフトウェアを配布していますが、デフォルトのフルスピードではノイズが多すぎて許容できません。私の目標は、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;
}
4

1 に答える 1

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;
}

私の古い MacBook Pro では、DVD ドライブにディスクがないため、disk0 も disk1 も CD ドライブではないと表示されます。ディスクがロードされている (そして速度の符号なし省略形を使用するようにコードが修正されている) と、/dev/disk2 は 4234 KB/秒の速度の CD として報告されます。

于 2012-02-17T00:29:10.490 に答える