blk_types.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include <common/glib.h>
  3. #include "stdint.h"
  4. #include <common/semaphore.h>
  5. #include <common/mutex.h>
  6. #define BLK_TYPE_AHCI 0
  7. #define DISK_NAME_LEN 32 // 磁盘名称的最大长度
  8. struct blk_gendisk;
  9. struct block_device_operation
  10. {
  11. long (*open)();
  12. long (*close)();
  13. long (*ioctl)(long cmd, long arg);
  14. long (*transfer)(long cmd, ul LBA_start, ul count, uint64_t buffer, uint8_t arg0, uint8_t arg1);
  15. };
  16. /**
  17. * @brief 块设备请求队列内的packet
  18. *
  19. */
  20. struct block_device_request_packet
  21. {
  22. uchar cmd;
  23. uint64_t LBA_start;
  24. uint32_t count;
  25. uint64_t buffer_vaddr;
  26. uint8_t device_type; // 0: ahci
  27. void (*end_handler)(ul num, ul arg);
  28. wait_queue_node_t wait_queue;
  29. };
  30. /**
  31. * @brief 块设备的请求队列
  32. *
  33. */
  34. struct block_device_request_queue
  35. {
  36. wait_queue_node_t wait_queue_list;
  37. struct block_device_request_packet *in_service; // 正在请求的结点
  38. ul request_count;
  39. };
  40. /**
  41. * @brief 块设备结构体(对应磁盘的一个分区)
  42. *
  43. */
  44. struct block_device
  45. {
  46. sector_t bd_start_sector; // 该分区的起始扇区
  47. sector_t bd_sectors_num; // 该分区的扇区数
  48. struct vfs_superblock_t *bd_superblock; // 执行超级块的指针
  49. struct blk_gendisk *bd_disk; // 当前分区所属的磁盘
  50. struct block_device_request_queue *bd_queue; // 请求队列
  51. uint16_t bd_partno; // 在磁盘上的分区号
  52. };
  53. /**
  54. * @brief 磁盘设备结构体
  55. *
  56. */
  57. struct blk_gendisk
  58. {
  59. char disk_name[DISK_NAME_LEN]; // 磁盘驱动器名称
  60. uint16_t part_cnt; // 磁盘分区计数
  61. uint16_t flags;
  62. struct block_device *partition; // 磁盘分区数组
  63. const struct block_device_operation *fops; // 磁盘操作
  64. struct block_device_request_queue *request_queue; // 磁盘请求队列
  65. void *private_data;
  66. mutex_t open_mutex; // open()/close()操作的互斥锁
  67. };