[spifs][fs] Trivial changes from previous PR comments.
This commit is contained in:
@@ -427,6 +427,7 @@ status_t fs_stat_fs(const char* mountpoint, struct fs_stat* stat)
|
||||
}
|
||||
|
||||
if (!mount->api->fs_stat){
|
||||
put_mount(mount);
|
||||
return ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
@@ -460,8 +461,12 @@ ssize_t fs_load_file(const char *path, void *ptr, size_t maxlen)
|
||||
|
||||
const char *trim_name(const char *_name)
|
||||
{
|
||||
// chew up leading slashes
|
||||
const char *name = &_name[0];
|
||||
// chew up leading spaces
|
||||
while (*name == ' ')
|
||||
name++;
|
||||
|
||||
// chew up leading slashes
|
||||
while (*name == '/')
|
||||
name++;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ typedef struct filehandle filehandle;
|
||||
typedef struct dirhandle dirhandle;
|
||||
|
||||
|
||||
status_t fs_format_device(const char *fsname, const char *device, const void *args);
|
||||
status_t fs_format_device(const char *fsname, const char *device, const void *args) __NONNULL((1));
|
||||
status_t fs_mount(const char *path, const char *fs, const char *device) __NONNULL((1)) __NONNULL((2));
|
||||
status_t fs_unmount(const char *path) __NONNULL();
|
||||
|
||||
@@ -70,7 +70,7 @@ status_t fs_open_dir(const char *path, dirhandle **handle) __NONNULL();
|
||||
status_t fs_read_dir(dirhandle *handle, struct dirent *ent) __NONNULL();
|
||||
status_t fs_close_dir(dirhandle *handle) __NONNULL();
|
||||
|
||||
status_t fs_stat_fs(const char* mountpoint, struct fs_stat* stat);
|
||||
status_t fs_stat_fs(const char* mountpoint, struct fs_stat* stat) __NONNULL((1)) __NONNULL((2));
|
||||
|
||||
/* convenience routines */
|
||||
ssize_t fs_load_file(const char *path, void *ptr, size_t maxlen) __NONNULL();
|
||||
@@ -78,7 +78,7 @@ ssize_t fs_load_file(const char *path, void *ptr, size_t maxlen) __NONNULL();
|
||||
/* walk through a path string, removing duplicate path seperators, flattening . and .. references */
|
||||
void fs_normalize_path(char *path) __NONNULL();
|
||||
|
||||
/* Remove any leading spaces */
|
||||
/* Remove any leading spaces or slashes */
|
||||
const char *trim_name(const char *_name);
|
||||
|
||||
/* file system api */
|
||||
|
||||
@@ -3,6 +3,9 @@ LOCAL_DIR := $(GET_LOCAL_DIR)
|
||||
MODULE := $(LOCAL_DIR)
|
||||
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/spifs.c
|
||||
$(LOCAL_DIR)/spifs.c \
|
||||
lib/fs \
|
||||
lib/cksum \
|
||||
lib/bio
|
||||
|
||||
include make/module.mk
|
||||
|
||||
@@ -207,8 +207,10 @@ static uint32_t find_open_run(spifs_t *spifs, uint32_t requested_length)
|
||||
spifs_file_t *file;
|
||||
list_for_every_entry(&spifs->files, file, spifs_file_t, node) {
|
||||
// Number of pages that this file occupies
|
||||
uint32_t page_size_shift = log2_uint(file->fs_handle->page_size);
|
||||
|
||||
uint32_t file_page_length =
|
||||
file->metadata.capacity / file->fs_handle->page_size;
|
||||
divpow2(file->metadata.capacity, page_size_shift);
|
||||
|
||||
// Index of the page immediately following the last page of this file.
|
||||
uint32_t file_end_page = file->metadata.page_idx + file_page_length;
|
||||
@@ -747,6 +749,10 @@ static status_t spifs_create(fscookie *cookie, const char *name, filecookie **fc
|
||||
if (strnlen(name, MAX_FILENAME_LENGTH) == MAX_FILENAME_LENGTH)
|
||||
return ERR_BAD_PATH;
|
||||
|
||||
// Length is bigger than 4GB?
|
||||
if (len > 0xFFFFFFFF)
|
||||
return ERR_TOO_BIG;
|
||||
|
||||
mutex_acquire(&spifs->lock);
|
||||
|
||||
if (find_file(spifs, name)) {
|
||||
@@ -939,7 +945,9 @@ static ssize_t spifs_write(filecookie *fcookie, const void *buf, off_t off, size
|
||||
|
||||
uint32_t start_addr =
|
||||
off + (file->metadata.page_idx * spifs->page_size);
|
||||
uint32_t target_page_id = start_addr / spifs->page_size;
|
||||
|
||||
uint32_t page_shift = log2_uint(spifs->page_size);
|
||||
uint32_t target_page_id = divpow2(start_addr, page_shift);
|
||||
|
||||
// Are we growing the file?
|
||||
if (off + len > file->metadata.length) {
|
||||
|
||||
@@ -44,17 +44,17 @@ typedef struct {
|
||||
uint32_t toc_pages;
|
||||
} test;
|
||||
|
||||
bool test_empty_after_format(const char *);
|
||||
bool test_double_create_file(const char *);
|
||||
bool test_write_read_normal(const char *);
|
||||
bool test_write_past_eof(const char *);
|
||||
bool test_full_toc(const char *);
|
||||
bool test_full_fs(const char *);
|
||||
bool test_write_past_end_of_capacity(const char *);
|
||||
bool test_rm_reclaim(const char *);
|
||||
bool test_corrupt_toc(const char *);
|
||||
bool test_write_with_offset(const char *);
|
||||
bool test_read_write_big(const char *);
|
||||
static bool test_empty_after_format(const char *);
|
||||
static bool test_double_create_file(const char *);
|
||||
static bool test_write_read_normal(const char *);
|
||||
static bool test_write_past_eof(const char *);
|
||||
static bool test_full_toc(const char *);
|
||||
static bool test_full_fs(const char *);
|
||||
static bool test_write_past_end_of_capacity(const char *);
|
||||
static bool test_rm_reclaim(const char *);
|
||||
static bool test_corrupt_toc(const char *);
|
||||
static bool test_write_with_offset(const char *);
|
||||
static bool test_read_write_big(const char *);
|
||||
|
||||
static test tests[] = {
|
||||
{&test_empty_after_format, "Test no files in ToC after format.", 1},
|
||||
@@ -103,7 +103,7 @@ bool test_teardown(void)
|
||||
return true;;
|
||||
}
|
||||
|
||||
bool test_empty_after_format(const char *dev_name)
|
||||
static bool test_empty_after_format(const char *dev_name)
|
||||
{
|
||||
dirhandle *dhandle;
|
||||
status_t err = fs_open_dir(MNT_PATH, &dhandle);
|
||||
@@ -121,7 +121,7 @@ bool test_empty_after_format(const char *dev_name)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_double_create_file(const char *dev_name)
|
||||
static bool test_double_create_file(const char *dev_name)
|
||||
{
|
||||
status_t status;
|
||||
|
||||
@@ -162,7 +162,7 @@ err:
|
||||
return status == NO_ERROR ? num_files == 1 : false;
|
||||
}
|
||||
|
||||
bool test_write_read_normal(const char *dev_name)
|
||||
static bool test_write_read_normal(const char *dev_name)
|
||||
{
|
||||
char test_message[] = "spifs test";
|
||||
char test_buf[sizeof(test_message)];
|
||||
@@ -213,7 +213,7 @@ bool test_write_read_normal(const char *dev_name)
|
||||
return strncmp(test_message, test_buf, sizeof(test_message)) == 0;
|
||||
}
|
||||
|
||||
bool test_write_past_eof(const char *dev_name)
|
||||
static bool test_write_past_eof(const char *dev_name)
|
||||
{
|
||||
char test_message[] = "spifs test";
|
||||
|
||||
@@ -242,7 +242,7 @@ bool test_write_past_eof(const char *dev_name)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_full_toc(const char *dev_name)
|
||||
static bool test_full_toc(const char *dev_name)
|
||||
{
|
||||
struct fs_stat stat;
|
||||
|
||||
@@ -284,7 +284,7 @@ bool test_full_toc(const char *dev_name)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_rm_reclaim(const char *dev_name)
|
||||
static bool test_rm_reclaim(const char *dev_name)
|
||||
{
|
||||
// Create some number of files that's a power of 2;
|
||||
size_t n_files = 4;
|
||||
@@ -356,7 +356,7 @@ bool test_rm_reclaim(const char *dev_name)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_full_fs(const char *dev_name)
|
||||
static bool test_full_fs(const char *dev_name)
|
||||
{
|
||||
struct fs_stat stat;
|
||||
|
||||
@@ -385,7 +385,7 @@ bool test_full_fs(const char *dev_name)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_write_past_end_of_capacity(const char *dev_name)
|
||||
static bool test_write_past_end_of_capacity(const char *dev_name)
|
||||
{
|
||||
filehandle *handle;
|
||||
status_t status = fs_create_file(TEST_FILE_PATH, &handle, 0);
|
||||
@@ -413,7 +413,7 @@ finish:
|
||||
return status == NO_ERROR;
|
||||
}
|
||||
|
||||
bool test_corrupt_toc(const char *dev_name)
|
||||
static bool test_corrupt_toc(const char *dev_name)
|
||||
{
|
||||
// Create a zero byte file.
|
||||
filehandle *handle;
|
||||
@@ -490,7 +490,7 @@ bool test_corrupt_toc(const char *dev_name)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_write_with_offset(const char *dev_name)
|
||||
static bool test_write_with_offset(const char *dev_name)
|
||||
{
|
||||
size_t repeats = 3;
|
||||
char test_message[] = "test";
|
||||
@@ -530,7 +530,7 @@ bool test_write_with_offset(const char *dev_name)
|
||||
return success;
|
||||
}
|
||||
|
||||
bool test_read_write_big(const char *dev_name)
|
||||
static bool test_read_write_big(const char *dev_name)
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ include project/virtual/test.mk
|
||||
include project/virtual/minip.mk
|
||||
|
||||
MODULES += \
|
||||
lib/fs \
|
||||
app/loader
|
||||
|
||||
include project/virtual/fs.mk
|
||||
|
||||
Reference in New Issue
Block a user