1 #pragma once
2 #include <common/sys/types.h>
3 
4 /**
5  * @brief 根据簇号计算该簇的起始扇区号(LBA地址)
6  *
7  * @param first_data_sector 数据区的其实扇区号
8  * @param sec_per_clus 每个簇的扇区数量
9  * @param cluster 簇号
10  * @return uint32_t LBA地址
11  */
__fat32_calculate_LBA(uint32_t first_data_sector,uint32_t sec_per_clus,uint32_t cluster)12 static inline uint32_t __fat32_calculate_LBA(uint32_t first_data_sector, uint32_t sec_per_clus, uint32_t cluster)
13 {
14     return first_data_sector + (cluster - 2) * sec_per_clus;
15 }
16 
17 /**
18  * @brief 计算LBA地址所在的簇
19  *
20  * @param first_data_sector 数据区的其实扇区号
21  * @param sec_per_clus 每个簇的扇区数量
22  * @param LBA LBA地址
23  * @return uint32_t 所在的簇
24  */
__fat32_LBA_to_cluster(uint32_t first_data_sector,uint32_t sec_per_clus,uint32_t LBA)25 static inline uint32_t __fat32_LBA_to_cluster(uint32_t first_data_sector, uint32_t sec_per_clus, uint32_t LBA)
26 {
27     return ((LBA - first_data_sector) / sec_per_clus) + 2;
28 }