Fix some minor bugs in llfs

This commit is contained in:
L-diy
2023-11-15 21:09:24 +01:00
parent 5eb7f36a5e
commit 96bc57fc3c

View File

@@ -10,8 +10,8 @@
#include <stdio.h>
#include <string.h>
#define LOGGER_LEVEL_WARN
#include "llfs.h"
#include "log.h"
#include "llfs.h"
/**
* @brief The maximum number of files that can be opened concurrently using the POSIX API
@@ -20,8 +20,8 @@
extern struct llfs_data_file* llfs_root;
const char* TAG = "llfs";
size_t file_count = 0;
FILE* file_table[POSIX_MAX_FILES];
static size_t file_count = 0; // Cache for the number of files in the filesystem
static FILE* file_table[POSIX_MAX_FILES];
static int new_file_table_entry(void);
static int free_file_table_entry(int file_id);
@@ -57,7 +57,7 @@ size_t llfs_file_list(llfs_file_t* file_list, size_t max_files, char* filter) {
}
// Iterate over all files in the filesystem
while (file != NULL && file_count < max_files) {
while (file != NULL && count < max_files) {
// Filter out files with a filename that does not match the filter
if (filter != NULL) {
if (!file_ext_cmp(file->name, filter)) {
@@ -218,7 +218,7 @@ int _close(int file_id) {
* @param len
* @return
*/
int _read(int file_id, char* ptr, int len) {
size_t _read(int file_id, char* ptr, int len) {
FILE* stream;
llfs_file_t* llfs_file;
size_t bytes_read;
@@ -256,7 +256,7 @@ int _read(int file_id, char* ptr, int len) {
memcpy(ptr, llfs_file->data + stream->_offset, bytes_read);
stream->_offset += (off_t)bytes_read;
return (int)bytes_read;
return bytes_read;
}
/**
@@ -281,7 +281,7 @@ int isatty(int file) {
* @param dir
* @return
*/
int _lseek(int file, int ptr, int dir) {
off_t _lseek(int file, int ptr, int dir) {
FILE* stream;
if (file == STDIN_FILENO || file == STDOUT_FILENO || file == STDERR_FILENO) {
@@ -310,7 +310,7 @@ int _lseek(int file, int ptr, int dir) {
return -1;
}
return 0;
return stream->_offset;
}
/**
@@ -409,8 +409,6 @@ static FILE* file_id_to_stream(int file_id) {
return file_table[file_id];
}
/**
* @brief Check if a filename ends with a given extension
*