blkdev.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* Block device registry: floppy + IDE. Shared by the `storage` and `format`
  2. * commands so they agree on device names and read/write paths. */
  3. #ifndef BLKDEV_H
  4. #define BLKDEV_H
  5. typedef enum { BLK_FLOPPY, BLK_IDE, BLK_SATA } blk_kind_t;
  6. typedef struct {
  7. const char *name; /* "floppy0","floppy1","ide0".."ide3","sata0".. */
  8. blk_kind_t kind;
  9. unsigned int bus; /* floppy: drive #; ide: 0=primary,1=secondary;
  10. * sata: controller index (0) */
  11. unsigned int unit; /* ide: 0=master,1=slave; sata: AHCI port */
  12. int present; /* set by IDENTIFY; floppy: always listed */
  13. unsigned int total_sectors;/* 0 if unknown (floppy) */
  14. char model[41]; /* IDE/SATA model string */
  15. } blk_dev_t;
  16. #define BLKDEV_MAX 16
  17. extern blk_dev_t blk_devs[BLKDEV_MAX];
  18. extern unsigned int blk_dev_count;
  19. /* Probe devices and populate the registry. */
  20. void blk_scan(void);
  21. /* Find a device by name (NULL if not found). */
  22. blk_dev_t *blk_find(const char *name);
  23. /* Read/write count sectors at lba. Return 0 on success, -1 on error. */
  24. int blk_read(blk_dev_t *d, unsigned int lba, void *buf, unsigned int count);
  25. int blk_write(blk_dev_t *d, unsigned int lba, const void *buf, unsigned int count);
  26. /* Flush the device's write cache. Floppies have none and return 0. */
  27. int blk_flush(blk_dev_t *d);
  28. #endif