diff --git a/src/apps/bin/Jamfile b/src/apps/bin/Jamfile index 2f2fdb4beb..4e59e206ac 100644 --- a/src/apps/bin/Jamfile +++ b/src/apps/bin/Jamfile @@ -40,6 +40,7 @@ StdBinCommands StdBinCommands chop.c + driveinfo.c echo.c eject.c hd.c diff --git a/src/apps/bin/driveinfo.c b/src/apps/bin/driveinfo.c new file mode 100644 index 0000000000..e9cc4f0ce4 --- /dev/null +++ b/src/apps/bin/driveinfo.c @@ -0,0 +1,92 @@ +#include +#include +#include +#include + +void dump_dev_size(int dev) +{ + size_t sz; + if (ioctl(dev, B_GET_DEVICE_SIZE, &sz, sizeof(sz)) < 0) { + perror("ioctl(B_GET_DEVICE_SIZE)"); + return; + } + printf("size: %ld bytes\n", sz); + puts(""); +} + +void dump_bios_id(int dev) +{ + uint8 id; + if (ioctl(dev, B_GET_BIOS_DRIVE_ID, &id, sizeof(id)) < 0) { + perror("ioctl(B_GET_BIOS_DRIVE_ID)"); + return; + } + printf("bios id: %d, 0x%x\n", id, id); + puts(""); +} + +void dump_media_status(int dev) +{ + uint32 st; + if (ioctl(dev, B_GET_MEDIA_STATUS, &st, sizeof(st)) < 0) { + perror("ioctl(B_GET_MEDIA_STATUS)"); + return; + } + printf("media status: %s\n", strerror(st)); + puts(""); +} + +const char *device_type(uint32 type) +{ + if (type == B_DISK) return "disk"; + if (type == B_TAPE) return "tape"; + if (type == B_PRINTER) return "printer"; + if (type == B_CPU) return "cpu"; + if (type == B_WORM) return "worm"; + if (type == B_CD) return "cd"; + if (type == B_SCANNER) return "scanner"; + if (type == B_OPTICAL) return "optical"; + if (type == B_JUKEBOX) return "jukebox"; + if (type == B_NETWORK) return "network"; + return ""; +} + +void dump_geom(int dev, bool bios) +{ + device_geometry geom; + + if (ioctl(dev, bios?B_GET_BIOS_GEOMETRY:B_GET_GEOMETRY, &geom, sizeof(geom)) < 0) { + perror("ioctl(B_GET_(BIOS_)GEOMETRY)"); + return; + } + printf("%sgeometry:\n", bios?"bios ":""); + printf("bytes_per_sector:\t%ld\n", geom.bytes_per_sector); + printf("sectors_per_track:\t%ld\n", geom.sectors_per_track); + printf("cylinder_count:\t%ld\n", geom.cylinder_count); + printf("head_count:\t%ld\n", geom.head_count); + printf("device_type:\t%d, %s\n", geom.device_type, device_type(geom.device_type)); + printf("%sremovable.\n", geom.removable?"":"not "); + printf("%sread_only.\n", geom.read_only?"":"not "); + printf("%swrite_once.\n", geom.write_once?"":"not "); + puts(""); +} + +int main(int argc, char **argv) +{ + int dev; + if (argc < 2) { + printf("%s device\n", argv[0]); + return 1; + } + dev = open(argv[1], O_RDONLY); + if (dev < 0) { + perror("open"); + return 1; + } + dump_dev_size(dev); + dump_bios_id(dev); + dump_media_status(dev); + dump_geom(dev, false); + dump_geom(dev, true); + return 0; +}