Wie finden Sie heraus, ob SCSI-Gerät (sagen/Dev/SDA) ist eine Festplatte oder nicht über ioctl Anrufe oder andere? Ich habe Folgendes versucht, aber die ioctl
Anruf schlägt fehl. Meine/dev/sda ist eine USB-Flash-Disk.Wie finde ich heraus, ob SCSI-Gerät (sagen wir/etc/sda) eine Festplatte ist oder nicht über ioctl Anrufe oder andere?
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <scsi/scsi.h>
#include <scsi/sg.h>
#include <sys/ioctl.h>
int main(int argc, char** argv) {
char *dev = "/dev/sda";
struct sg_scsi_id m_id;
int rc;
int fd;
fd = open(dev, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
perror(dev);
}
memset(&m_id, 0, sizeof (m_id));
rc = ioctl(fd, SG_GET_SCSI_ID, &m_id);
if (rc < 0) {
close(fd);
printf("FAIL: ioctl SG_GET_SCSI_ID, rc=%d, errno=%d\n", rc, errno);
} else {
if (m_id.scsi_type == TYPE_DISK || m_id.scsi_type == 14) {
printf("OK: is disk\n");
} else {
printf("OK: is NOT disk\n");
}
}
close(fd);
return (EXIT_SUCCESS);
}
// result is: FAIL: ioctl SG_GET_SCSI_ID, rc=-1, errno=22
ty, es hilft, ich werde mehr graben, um es über ioctl tough zu tun. [root @ localhost ~] # cat/proc/scsi/scsi Angeschlossene Geräte: Host: scsi1 Channel: 00 ID: 00 Lun: 00 Hersteller: SanDisk Modell: Cruzer Rev: 8.01 ** Typ: Direct- Access ** ANSI SCSI Revision: 02 – clyfe