mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-26 00:52:50 +00:00
feat(fs): Complete full FAT32 storage filesystem driver, auto-mount at /mnt/fat32, and add df & mkfs.vfat tools
This commit is contained in:
1 parent
7c620e86e7
commit
125a891621
5 files changed
+279
-20
No files matched your search
+34
-3
@@ -5,8 +5,22 @@
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <fs/vfs.h>
|
||||
#include <block/block.h>
|
||||
|
||||
/* FAT32 Extended BIOS Parameter Block */
|
||||
#define FAT_ATTR_READ_ONLY 0x01
|
||||
#define FAT_ATTR_HIDDEN 0x02
|
||||
#define FAT_ATTR_SYSTEM 0x04
|
||||
#define FAT_ATTR_VOLUME_ID 0x08
|
||||
#define FAT_ATTR_DIRECTORY 0x10
|
||||
#define FAT_ATTR_ARCHIVE 0x20
|
||||
#define FAT_ATTR_LFN 0x0F
|
||||
|
||||
#define FAT32_EOC_MIN 0x0FFFFFF8
|
||||
#define FAT32_EOC_MAX 0x0FFFFFFF
|
||||
#define FAT32_BAD_CLUSTER 0x0FFFFFF7
|
||||
#define FAT32_FREE_CLUSTER 0x00000000
|
||||
|
||||
/* FAT32 Extended BIOS Parameter Block (BPB) */
|
||||
typedef struct {
|
||||
uint8_t jmp[3];
|
||||
char oem[8];
|
||||
@@ -23,7 +37,7 @@ typedef struct {
|
||||
uint32_t hidden_sectors;
|
||||
uint32_t total_sectors_32;
|
||||
|
||||
// FAT32 Extended
|
||||
// FAT32 Extended Fields
|
||||
uint32_t table_size_32;
|
||||
uint16_t extended_flags;
|
||||
uint16_t fat_version;
|
||||
@@ -39,6 +53,7 @@ typedef struct {
|
||||
char fat_type_label[8];
|
||||
} __attribute__((packed)) fat32_bpb_t;
|
||||
|
||||
/* Standard 32-byte FAT Directory Entry */
|
||||
typedef struct {
|
||||
char name[11];
|
||||
uint8_t attr;
|
||||
@@ -54,7 +69,23 @@ typedef struct {
|
||||
uint32_t file_size;
|
||||
} __attribute__((packed)) fat32_dirent_t;
|
||||
|
||||
/* In-Memory Mounted FAT32 Filesystem Descriptor */
|
||||
typedef struct {
|
||||
block_device_t* dev;
|
||||
fat32_bpb_t bpb;
|
||||
uint32_t fat_begin_lba;
|
||||
uint32_t cluster_begin_lba;
|
||||
uint32_t sectors_per_cluster;
|
||||
uint32_t root_cluster;
|
||||
uint32_t total_clusters;
|
||||
uint32_t free_clusters;
|
||||
char mountpoint[64];
|
||||
bool mounted;
|
||||
} fat32_fs_t;
|
||||
|
||||
void fat32_init(void);
|
||||
vfs_node_t* fat32_mount(const char* block_device_name);
|
||||
vfs_node_t* fat32_mount(const char* block_device_name, const char* mountpoint);
|
||||
int fat32_format(const char* block_device_name, const char* volume_label);
|
||||
const fat32_fs_t* fat32_get_fs_info(void);
|
||||
|
||||
#endif // _FS_FAT32_H
|
||||
Reference in new issue
Block a user