[fs][fat32] Adapt modern LK conventions
This commit is contained in:
@@ -24,13 +24,13 @@
|
||||
#include <err.h>
|
||||
#include <lib/bio.h>
|
||||
#include <lib/fs.h>
|
||||
#include <lib/fs/fat32.h>
|
||||
#include <trace.h>
|
||||
#include <debug.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <endian.h>
|
||||
|
||||
#include "fat32_priv.h"
|
||||
#include "fat_fs.h"
|
||||
|
||||
void fat32_dump(fat_fs_t *fat) {
|
||||
@@ -50,11 +50,15 @@ void fat32_dump(fat_fs_t *fat) {
|
||||
printf("root_start=%i\n", fat->root_start);
|
||||
}
|
||||
|
||||
int fat32_mount(bdev_t *dev, fscookie *cookie) {
|
||||
int result = NO_ERROR;
|
||||
status_t fat32_mount(bdev_t *dev, fscookie **cookie) {
|
||||
status_t result = NO_ERROR;
|
||||
|
||||
uint8_t *bs = malloc(512);
|
||||
int err = bio_read(dev, bs, 1024, 512);
|
||||
if (err < 0) {
|
||||
result = ERR_GENERIC;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (((bs[0x1fe] != 0x55) || (bs[0x1ff] != 0xaa)) && (bs[0x15] == 0xf8)) {
|
||||
printf("missing boot signature\n");
|
||||
@@ -160,15 +164,26 @@ int fat32_mount(bdev_t *dev, fscookie *cookie) {
|
||||
fat->bytes_per_cluster = fat->sectors_per_cluster * fat->bytes_per_sector;
|
||||
fat->cache = bcache_create(fat->dev, fat->bytes_per_sector, 4);
|
||||
|
||||
*cookie = fat;
|
||||
*cookie = (fscookie *)fat;
|
||||
end:
|
||||
free(bs);
|
||||
return result;
|
||||
}
|
||||
|
||||
int fat32_unmount(fscookie cookie) {
|
||||
status_t fat32_unmount(fscookie *cookie) {
|
||||
fat_fs_t *fat = (fat_fs_t *)cookie;
|
||||
bcache_destroy(fat->cache);
|
||||
free(fat);
|
||||
return NO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct fs_api fat32_api = {
|
||||
.mount = fat32_mount,
|
||||
.unmount = fat32_unmount,
|
||||
.open = fat32_open_file,
|
||||
.stat = fat32_stat_file,
|
||||
.read = fat32_read_file,
|
||||
.close = fat32_close_file,
|
||||
};
|
||||
|
||||
STATIC_FS_IMPL(fat32, &fat32_api);
|
||||
|
||||
@@ -21,14 +21,22 @@
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#ifndef __FAT32_H
|
||||
#define __FAT32_H
|
||||
|
||||
#include <lib/bio.h>
|
||||
#include <lib/fs.h>
|
||||
#include <lib/fs/fat32.h>
|
||||
#include <trace.h>
|
||||
|
||||
int fat32_make_dir(fscookie cookie, const char *name) {
|
||||
TRACE;
|
||||
return ERR_NOT_ALLOWED;
|
||||
}
|
||||
typedef void *fsfilecookie;
|
||||
|
||||
status_t fat32_mount(bdev_t *dev, fscookie **cookie);
|
||||
status_t fat32_unmount(fscookie *cookie);
|
||||
|
||||
/* file api */
|
||||
status_t fat32_open_file(fscookie *cookie, const char *path, filecookie **fcookie);
|
||||
ssize_t fat32_read_file(filecookie *fcookie, void *buf, off_t offset, size_t len);
|
||||
status_t fat32_close_file(filecookie *fcookie);
|
||||
status_t fat32_stat_file(filecookie *fcookie, struct file_stat *stat);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include <err.h>
|
||||
#include <lib/bio.h>
|
||||
#include <lib/fs.h>
|
||||
#include <lib/fs/fat32.h>
|
||||
#include <trace.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
@@ -32,6 +31,7 @@
|
||||
#include <debug.h>
|
||||
|
||||
#include "fat_fs.h"
|
||||
#include "fat32_priv.h"
|
||||
|
||||
#define DIR_ENTRY_LENGTH 32
|
||||
#define USE_CACHE 1
|
||||
@@ -136,15 +136,15 @@ char *fat32_dir_get_filename(uint8_t *dir, off_t offset, int lfn_sequences) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int fat32_open_file(fscookie cookie, const char *path, fsfilecookie *fcookie) {
|
||||
status_t fat32_open_file(fscookie *cookie, const char *path, filecookie **fcookie) {
|
||||
fat_fs_t *fat = (fat_fs_t *)cookie;
|
||||
int result = ERR_GENERIC;
|
||||
status_t result = ERR_GENERIC;
|
||||
|
||||
uint8_t *dir = malloc(fat->bytes_per_cluster);
|
||||
uint32_t dir_cluster = fat->root_cluster;
|
||||
fat_file_t *file = NULL;
|
||||
|
||||
char *ptr;
|
||||
const char *ptr;
|
||||
/* chew up leading slashes */
|
||||
ptr = &path[0];
|
||||
while (*ptr == '/') {
|
||||
@@ -233,12 +233,12 @@ int fat32_open_file(fscookie cookie, const char *path, fsfilecookie *fcookie) {
|
||||
} while(true);
|
||||
|
||||
out:
|
||||
*fcookie = file;
|
||||
*fcookie = (filecookie *)file;
|
||||
free(dir);
|
||||
return result;
|
||||
}
|
||||
|
||||
int fat32_read_file(fsfilecookie 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;
|
||||
@@ -250,7 +250,7 @@ int fat32_read_file(fsfilecookie fcookie, void *buf, off_t offset, size_t len) {
|
||||
else {
|
||||
// XXX: support non-0 offsets
|
||||
TRACE;
|
||||
return ERR_GENERIC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t length = file->length;
|
||||
@@ -285,29 +285,18 @@ int fat32_read_file(fsfilecookie fcookie, void *buf, off_t offset, size_t len) {
|
||||
}
|
||||
while(amount_read < length);
|
||||
|
||||
return NO_ERROR;
|
||||
return amount_read;
|
||||
}
|
||||
|
||||
int fat32_close_file(fsfilecookie fcookie) {
|
||||
status_t fat32_close_file(filecookie *fcookie) {
|
||||
fat_file_t *file = (fat_file_t *)fcookie;
|
||||
free(file);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int fat32_stat_file(fsfilecookie cookie, struct file_stat *stat) {
|
||||
fat_file_t *file = (fat_file_t *)cookie;
|
||||
status_t fat32_stat_file(filecookie *fcookie, struct file_stat *stat) {
|
||||
fat_file_t *file = (fat_file_t *)fcookie;
|
||||
stat->size = file->length;
|
||||
stat->is_dir = (file->attributes == fat_attribute_directory);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int fat32_create_file(fscookie cookie, const char *path, filecookie *fcookie) {
|
||||
TRACE;
|
||||
return ERR_NOT_ALLOWED;
|
||||
}
|
||||
|
||||
int fat32_write_file(filecookie fcookie, const void *buf, off_t offset, size_t len) {
|
||||
TRACE;
|
||||
return ERR_NOT_ALLOWED;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ MODULE_DEPS += \
|
||||
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/fat.c \
|
||||
$(LOCAL_DIR)/dir.c \
|
||||
$(LOCAL_DIR)/file.c
|
||||
|
||||
include make/module.mk
|
||||
|
||||
Reference in New Issue
Block a user