[fs][fat32] trivially convert to C++

This commit is contained in:
Travis Geiselbrecht
2022-04-18 22:24:27 -07:00
parent fdb027fe7b
commit d4969ccb3c
3 changed files with 24 additions and 9 deletions

View File

@@ -41,7 +41,7 @@ status_t fat32_mount(bdev_t *dev, fscookie **cookie) {
if (!dev)
return ERR_NOT_VALID;
uint8_t *bs = malloc(512);
uint8_t *bs = (uint8_t *)malloc(512);
int err = bio_read(dev, bs, 1024, 512);
if (err < 0) {
result = ERR_GENERIC;
@@ -54,7 +54,8 @@ status_t fat32_mount(bdev_t *dev, fscookie **cookie) {
goto end;
}
fat_fs_t *fat = malloc(sizeof(fat_fs_t));
fat_fs_t *fat;
fat = (fat_fs_t *)malloc(sizeof(fat_fs_t));
fat->lba_start = 1024;
fat->dev = dev;
@@ -165,12 +166,26 @@ status_t fat32_unmount(fscookie *cookie) {
}
static const struct fs_api fat32_api = {
.format = nullptr,
.fs_stat = nullptr,
.mount = fat32_mount,
.unmount = fat32_unmount,
.open = fat32_open_file,
.create = nullptr,
.remove = nullptr,
.truncate = nullptr,
.stat = fat32_stat_file,
.read = fat32_read_file,
.write = nullptr,
.close = fat32_close_file,
.mkdir = nullptr,
.opendir = nullptr,
.readdir = nullptr,
.closedir = nullptr,
.file_ioctl = nullptr,
};
STATIC_FS_IMPL(fat32, &fat32_api);

View File

@@ -64,7 +64,7 @@ static inline off_t fat32_offset_for_cluster(fat_fs_t *fat, uint32_t cluster) {
static char *fat32_dir_get_filename(uint8_t *dir, off_t offset, int lfn_sequences) {
int result_len = 1 + (lfn_sequences == 0 ? 12 : (lfn_sequences * 26));
char *result = malloc(result_len);
char *result = (char *)malloc(result_len);
int j = 0;
memset(result, 0x00, result_len);
@@ -119,7 +119,7 @@ status_t fat32_open_file(fscookie *cookie, const char *path, filecookie **fcooki
fat_fs_t *fat = (fat_fs_t *)cookie;
status_t result = ERR_GENERIC;
uint8_t *dir = malloc(fat->bytes_per_cluster);
uint8_t *dir = (uint8_t *)malloc(fat->bytes_per_cluster);
uint32_t dir_cluster = fat->root_cluster;
fat_file_t *file = NULL;
@@ -169,7 +169,7 @@ status_t fat32_open_file(fscookie *cookie, const char *path, filecookie **fcooki
if (matched) {
uint16_t target_cluster = fat_read16(dir, offset + 0x1a);
if (done == true) {
file = malloc(sizeof(fat_file_t));
file = (fat_file_t *)malloc(sizeof(fat_file_t));
file->fat_fs = fat;
file->start_cluster = target_cluster;
file->length = fat_read32(dir, offset + 0x1c);
@@ -212,10 +212,11 @@ out:
return result;
}
ssize_t fat32_read_file(filecookie *fcookie, void *buf, off_t offset, size_t len) {
ssize_t fat32_read_file(filecookie *fcookie, void *_buf, off_t offset, size_t len) {
fat_file_t *file = (fat_file_t *)fcookie;
fat_fs_t *fat = file->fat_fs;
bdev_t *dev = fat->dev;
uint8_t *buf = (uint8_t *)_buf;
uint32_t cluster = 0;
if (offset <= fat->bytes_per_cluster) {

View File

@@ -7,8 +7,7 @@ MODULE_DEPS += \
lib/bcache \
lib/bio
MODULE_SRCS += \
$(LOCAL_DIR)/fat.c \
$(LOCAL_DIR)/file.c
MODULE_SRCS += $(LOCAL_DIR)/fat.cpp
MODULE_SRCS += $(LOCAL_DIR)/file.cpp
include make/module.mk