1 #include <stdio.h> 2 #include <string.h> 3 #include <fcntl.h> 4 #include <sys/ioctl.h> 5 #include <Drivers.h> 6 7 static void dump_dev_size(int dev) 8 { 9 size_t sz; 10 if (ioctl(dev, B_GET_DEVICE_SIZE, &sz, sizeof(sz)) < 0) { 11 perror("ioctl(B_GET_DEVICE_SIZE)"); 12 return; 13 } 14 printf("size: %ld bytes\n", sz); 15 puts(""); 16 } 17 18 static void dump_bios_id(int dev) 19 { 20 uint8 id; 21 if (ioctl(dev, B_GET_BIOS_DRIVE_ID, &id, sizeof(id)) < 0) { 22 perror("ioctl(B_GET_BIOS_DRIVE_ID)"); 23 return; 24 } 25 printf("bios id: %d, 0x%x\n", id, id); 26 puts(""); 27 } 28 29 static void dump_media_status(int dev) 30 { 31 uint32 st; 32 if (ioctl(dev, B_GET_MEDIA_STATUS, &st, sizeof(st)) < 0) { 33 perror("ioctl(B_GET_MEDIA_STATUS)"); 34 return; 35 } 36 printf("media status: %s\n", strerror(st)); 37 puts(""); 38 } 39 40 static const char *device_type(uint32 type) 41 { 42 if (type == B_DISK) return "disk"; 43 if (type == B_TAPE) return "tape"; 44 if (type == B_PRINTER) return "printer"; 45 if (type == B_CPU) return "cpu"; 46 if (type == B_WORM) return "worm"; 47 if (type == B_CD) return "cd"; 48 if (type == B_SCANNER) return "scanner"; 49 if (type == B_OPTICAL) return "optical"; 50 if (type == B_JUKEBOX) return "jukebox"; 51 if (type == B_NETWORK) return "network"; 52 return "<unknown>"; 53 } 54 55 static void dump_geom(int dev, bool bios) 56 { 57 device_geometry geom; 58 59 if (ioctl(dev, bios?B_GET_BIOS_GEOMETRY:B_GET_GEOMETRY, &geom, sizeof(geom)) < 0) { 60 perror("ioctl(B_GET_(BIOS_)GEOMETRY)"); 61 return; 62 } 63 printf("%sgeometry:\n", bios?"bios ":""); 64 printf("bytes_per_sector:\t%ld\n", geom.bytes_per_sector); 65 printf("sectors_per_track:\t%ld\n", geom.sectors_per_track); 66 printf("cylinder_count:\t%ld\n", geom.cylinder_count); 67 printf("head_count:\t%ld\n", geom.head_count); 68 printf("device_type:\t%d, %s\n", geom.device_type, device_type(geom.device_type)); 69 printf("%sremovable.\n", geom.removable?"":"not "); 70 printf("%sread_only.\n", geom.read_only?"":"not "); 71 printf("%swrite_once.\n", geom.write_once?"":"not "); 72 puts(""); 73 } 74 75 int main(int argc, char **argv) 76 { 77 int dev; 78 if (argc < 2) { 79 printf("%s device\n", argv[0]); 80 return 1; 81 } 82 dev = open(argv[1], O_RDONLY); 83 if (dev < 0) { 84 perror("open"); 85 return 1; 86 } 87 dump_dev_size(dev); 88 dump_bios_id(dev); 89 dump_media_status(dev); 90 dump_geom(dev, false); 91 dump_geom(dev, true); 92 return 0; 93 } 94