Merge pull request #17 from Sani7/bugfix/mkllfs-llfs
Fix/improve llfs and the mkllfs utility
This commit is contained in:
@@ -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);
|
||||
@@ -41,6 +41,14 @@ int8_t llfs_init(void) {
|
||||
file_table[STDOUT_FILENO] = stdout;
|
||||
file_table[STDERR_FILENO] = stderr;
|
||||
|
||||
// Calculate the number of files in the filesystem and cache it
|
||||
const struct llfs_data_file* file = llfs_root;
|
||||
file_count = 0;
|
||||
while (file != NULL) {
|
||||
file_count++;
|
||||
file = file->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -57,7 +65,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)) {
|
||||
@@ -130,13 +138,6 @@ llfs_file_t* llfs_next_file(void** mem, char* filter) {
|
||||
}
|
||||
|
||||
size_t llfs_file_count(void) {
|
||||
if (file_count == 0) {
|
||||
const struct llfs_data_file* file = llfs_root;
|
||||
while (file != NULL) {
|
||||
file_count++;
|
||||
file = file->next;
|
||||
}
|
||||
}
|
||||
return file_count;
|
||||
}
|
||||
|
||||
@@ -218,7 +219,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 +257,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 +282,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 +311,7 @@ int _lseek(int file, int ptr, int dir) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return stream->_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,8 +410,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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user