diff --git a/kernel/common/blk_types.h b/kernel/common/blk_types.h new file mode 100644 index 00000000..8acdd9fe --- /dev/null +++ b/kernel/common/blk_types.h @@ -0,0 +1,79 @@ +#pragma once + +#include +#include "stdint.h" +#include +#include + +#define BLK_TYPE_AHCI 0 + +#define DISK_NAME_LEN 32 // 磁盘名称的最大长度 + +struct blk_gendisk; + +struct block_device_operation +{ + long (*open)(); + long (*close)(); + long (*ioctl)(long cmd, long arg); + long (*transfer)(long cmd, ul LBA_start, ul count, uint64_t buffer, uint8_t arg0, uint8_t arg1); +}; + +/** + * @brief 块设备请求队列内的packet + * + */ +struct block_device_request_packet +{ + uchar cmd; + uint64_t LBA_start; + uint32_t count; + uint64_t buffer_vaddr; + + uint8_t device_type; // 0: ahci + void (*end_handler)(ul num, ul arg); + + wait_queue_node_t wait_queue; +}; + +/** + * @brief 块设备的请求队列 + * + */ +struct block_device_request_queue +{ + wait_queue_node_t wait_queue_list; + struct block_device_request_packet *in_service; // 正在请求的结点 + ul request_count; +}; + +/** + * @brief 块设备结构体(对应磁盘的一个分区) + * + */ +struct block_device +{ + sector_t bd_start_sector; // 该分区的起始扇区 + sector_t bd_sectors_num; // 该分区的扇区数 + struct vfs_superblock_t *bd_superblock; // 执行超级块的指针 + struct blk_gendisk *bd_disk; // 当前分区所属的磁盘 + struct block_device_request_queue *bd_queue; // 请求队列 + uint16_t bd_partno; // 在磁盘上的分区号 +}; + +/** + * @brief 磁盘设备结构体 + * + */ +struct blk_gendisk +{ + char disk_name[DISK_NAME_LEN]; // 磁盘驱动器名称 + uint16_t part_cnt; // 磁盘分区计数 + uint16_t flags; + struct block_device *partition; // 磁盘分区数组 + const struct block_device_operation *fops; // 磁盘操作 + struct block_device_request_queue *request_queue; // 磁盘请求队列 + void *private_data; + + mutex_t open_mutex; // open()/close()操作的互斥锁 +}; \ No newline at end of file diff --git a/kernel/common/sys/types.h b/kernel/common/sys/types.h index d4a8f9c6..ee9c7244 100644 --- a/kernel/common/sys/types.h +++ b/kernel/common/sys/types.h @@ -13,7 +13,7 @@ typedef uint32_t gid_t; typedef long long ssize_t; typedef int __pid_t; -#define pid_t __pid_t +#define pid_t uint64_t typedef __SIZE_TYPE__ size_t; typedef char *caddr_t; @@ -37,6 +37,8 @@ typedef uint32_t clock_t; typedef uint64_t fsblkcnt_t; typedef uint64_t fsfilcnt_t; +typedef uint64_t sector_t; + #define __socklen_t_defined #define __socklen_t uint32_t typedef __socklen_t socklen_t; diff --git a/kernel/driver/disk/ahci/ahci.h b/kernel/driver/disk/ahci/ahci.h index f60908d1..40112e95 100644 --- a/kernel/driver/disk/ahci/ahci.h +++ b/kernel/driver/disk/ahci/ahci.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include diff --git a/kernel/driver/disk/block_device.h b/kernel/driver/disk/block_device.h deleted file mode 100644 index dfe3e42a..00000000 --- a/kernel/driver/disk/block_device.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include -#include "stdint.h" -#include - -#define BLK_TYPE_AHCI 0 -struct block_device_operation -{ - long (*open)(); - long (*close)(); - long (*ioctl)(long cmd, long arg); - long (*transfer)(long cmd, ul LBA_start, ul count, uint64_t buffer, uint8_t arg0, uint8_t arg1); -}; - -/** - * @brief 块设备请求队列内的packet - * - */ -struct block_device_request_packet -{ - uchar cmd; - uint64_t LBA_start; - uint32_t count; - uint64_t buffer_vaddr; - - uint8_t device_type; // 0: ahci - void (*end_handler)(ul num, ul arg); - - wait_queue_node_t wait_queue; -}; - -/** - * @brief 块设备的请求队列 - * - */ -struct block_device_request_queue -{ - wait_queue_node_t wait_queue_list; - struct block_device_request_packet * in_service; // 正在请求的结点 - ul request_count; -}; \ No newline at end of file