blkdev.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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_MMC } blk_kind_t;
  6. typedef struct {
  7. const char *name; /* "floppy0","floppy1","ide0".."ide3",
  8. * "sata0".., "mmc0" */
  9. blk_kind_t kind;
  10. unsigned int bus; /* floppy: drive #; ide: 0=primary,1=secondary;
  11. * sata: controller index (0) */
  12. unsigned int unit; /* ide: 0=master,1=slave; sata: AHCI port */
  13. int present; /* set by IDENTIFY/probe; floppy: media present */
  14. unsigned int total_sectors;/* 0 if unknown (floppy) */
  15. char model[41]; /* IDE/SATA model string */
  16. } blk_dev_t;
  17. #define BLKDEV_MAX 16
  18. extern blk_dev_t blk_devs[BLKDEV_MAX];
  19. extern unsigned int blk_dev_count;
  20. /* Probe devices and populate the registry. */
  21. void blk_scan(void);
  22. /* Find a device by name (NULL if not found). */
  23. blk_dev_t *blk_find(const char *name);
  24. /* Read/write count sectors at lba. Return 0 on success, -1 on error. */
  25. int blk_read(blk_dev_t *d, unsigned int lba, void *buf, unsigned int count);
  26. int blk_write(blk_dev_t *d, unsigned int lba, const void *buf, unsigned int count);
  27. /* Flush the device's write cache. Floppies have none and return 0. */
  28. int blk_flush(blk_dev_t *d);
  29. #endif