硬盘支持(FAT32)

This commit is contained in:
2026-04-22 21:43:09 +08:00
parent 6b5a19a19d
commit 0fe34d9a09
22 changed files with 2768 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
#include <clks/boot.h>
#include <clks/disk.h>
#include <clks/fs.h>
#include <clks/heap.h>
#include <clks/log.h>
@@ -515,6 +516,14 @@ void clks_fs_init(void) {
clks_log_hex(CLKS_LOG_INFO, "FS", "NODE_COUNT", (u64)clks_fs_nodes_used);
clks_log_hex(CLKS_LOG_INFO, "FS", "FILE_COUNT", stats.file_count);
clks_disk_init();
if (clks_disk_present() == CLKS_TRUE) {
clks_log_hex(CLKS_LOG_INFO, "FS", "DISK_BYTES", clks_disk_size_bytes());
clks_log_hex(CLKS_LOG_INFO, "FS", "DISK_FAT32", (clks_disk_is_formatted_fat32() == CLKS_TRUE) ? 1ULL : 0ULL);
} else {
clks_log(CLKS_LOG_WARN, "FS", "DISK BACKEND NOT PRESENT");
}
if (clks_fs_require_directory("/system") == CLKS_FALSE) {
return;
}
@@ -545,11 +554,23 @@ clks_bool clks_fs_is_ready(void) {
clks_bool clks_fs_stat(const char *path, struct clks_fs_node_info *out_info) {
i32 node_index;
u64 disk_type = 0ULL;
u64 disk_size = 0ULL;
if (clks_fs_ready == CLKS_FALSE || out_info == CLKS_NULL) {
return CLKS_FALSE;
}
if (clks_disk_path_in_mount(path) == CLKS_TRUE) {
if (clks_disk_stat(path, &disk_type, &disk_size) == CLKS_FALSE) {
return CLKS_FALSE;
}
out_info->type = (disk_type == CLKS_DISK_NODE_DIR) ? CLKS_FS_NODE_DIR : CLKS_FS_NODE_FILE;
out_info->size = disk_size;
return CLKS_TRUE;
}
node_index = clks_fs_find_node_by_external(path);
if (node_index < 0) {
@@ -563,11 +584,17 @@ clks_bool clks_fs_stat(const char *path, struct clks_fs_node_info *out_info) {
const void *clks_fs_read_all(const char *path, u64 *out_size) {
i32 node_index;
const void *disk_data;
if (clks_fs_ready == CLKS_FALSE) {
return CLKS_NULL;
}
if (clks_disk_path_in_mount(path) == CLKS_TRUE) {
disk_data = clks_disk_read_all(path, out_size);
return disk_data;
}
node_index = clks_fs_find_node_by_external(path);
if (node_index < 0) {
@@ -598,6 +625,10 @@ u64 clks_fs_count_children(const char *dir_path) {
return 0ULL;
}
if (clks_disk_path_in_mount(dir_path) == CLKS_TRUE) {
return clks_disk_count_children(dir_path);
}
dir_index = clks_fs_find_node_by_external(dir_path);
if (dir_index < 0) {
@@ -634,6 +665,10 @@ clks_bool clks_fs_get_child_name(const char *dir_path, u64 index, char *out_name
return CLKS_FALSE;
}
if (clks_disk_path_in_mount(dir_path) == CLKS_TRUE) {
return clks_disk_get_child_name(dir_path, index, out_name, out_name_size);
}
dir_index = clks_fs_find_node_by_external(dir_path);
if (dir_index < 0 || clks_fs_nodes[(u16)dir_index].type != CLKS_FS_NODE_DIR) {
@@ -683,6 +718,10 @@ clks_bool clks_fs_mkdir(const char *path) {
return CLKS_FALSE;
}
if (clks_disk_path_in_mount(path) == CLKS_TRUE) {
return clks_disk_mkdir(path);
}
if (clks_fs_normalize_external_path(path, internal, sizeof(internal)) == CLKS_FALSE) {
return CLKS_FALSE;
}
@@ -720,6 +759,10 @@ clks_bool clks_fs_write_all(const char *path, const void *data, u64 size) {
return CLKS_FALSE;
}
if (clks_disk_path_in_mount(path) == CLKS_TRUE) {
return clks_disk_write_all(path, data, size);
}
if (clks_fs_normalize_external_path(path, internal, sizeof(internal)) == CLKS_FALSE) {
return CLKS_FALSE;
}
@@ -785,6 +828,10 @@ clks_bool clks_fs_append(const char *path, const void *data, u64 size) {
return CLKS_FALSE;
}
if (clks_disk_path_in_mount(path) == CLKS_TRUE) {
return clks_disk_append(path, data, size);
}
if (size > 0ULL && data == CLKS_NULL) {
return CLKS_FALSE;
}
@@ -851,6 +898,10 @@ clks_bool clks_fs_remove(const char *path) {
return CLKS_FALSE;
}
if (clks_disk_path_in_mount(path) == CLKS_TRUE) {
return clks_disk_remove(path);
}
if (clks_fs_normalize_external_path(path, internal, sizeof(internal)) == CLKS_FALSE) {
return CLKS_FALSE;
}
@@ -908,5 +959,9 @@ u64 clks_fs_node_count(void) {
}
}
if (clks_disk_is_mounted() == CLKS_TRUE) {
used += clks_disk_node_count();
}
return used;
}