Commit 3b436505 authored by schneider's avatar schneider

Merge branch 'schneider/fat-locking' into 'master'

FS locking and FD counting

See merge request !370
parents 2b12800d 9b411213
Pipeline #4459 passed with stages
in 2 minutes and 23 seconds
#include "epicardium.h"
#include "modules/log.h"
#include "fs_util.h"
#include "fs/fs_util.h"
#include "wsf_types.h"
#include "wsf_buf.h"
#include "wsf_trace.h"
......
......@@ -17,7 +17,7 @@
#include <string.h>
#include "wsf_types.h"
#include "util/bstream.h"
#include "fs_util.h"
#include "fs/fs_util.h"
#include "wsf_msg.h"
#include "wsf_trace.h"
#include "hci_api.h"
......
......@@ -285,6 +285,7 @@ efs_get_new(EpicFileSystem *fs, uint32_t *idx, struct FatObject **obj, int *rc)
}
*obj = &fs->pool[index];
*idx = index;
return true;
}
......
#include "fs_util.h"
#include "ff.h"
#include "epicardium.h"
#include <stdint.h>
#include <string.h>
FATFS FatFs; /* File system object for logical drive */
FS_USAGE FsUsage;
int fs_read_file(char *filename, void *data, int len)
{
int fd = epic_file_open(filename, "r");
if (fd < 0) {
return fd;
}
int res = epic_file_read(fd, data, len);
epic_file_close(fd);
return res;
}
int fs_read_text_file(char *filename, char *data, int len)
{
int readbytes;
if (len < 1)
return -1;
readbytes = fs_read_file(filename, data, len - 1);
if (readbytes < 0) {
data[0] = 0;
return readbytes;
};
data[readbytes] = 0;
while (readbytes > 0 && data[readbytes - 1] < 0x20) {
data[--readbytes] = 0;
};
return readbytes;
}
int fs_write_file(char *filename, const void *data, int len)
{
int fd = epic_file_open(filename, "w");
if (fd < 0) {
return fd;
}
int res = epic_file_write(fd, data, len);
epic_file_close(fd);
return res;
}
int fs_get_file_size(char *filename)
{
struct epic_stat stat;
int res = epic_file_stat(filename, &stat);
return res < 0 ? res : (int)stat.size;
}
#if 0
#include "ff.h"
FATFS FatFs; /* File system object for logical drive */
FS_USAGE FsUsage;
/* TODO: Port functions from r0ket/rad10 libs */
int fs_info(FATFS *fs)
{
memcpy(fs, &FatFs, sizeof(FATFS));
......@@ -35,72 +89,4 @@ int fs_usage(FATFS *fs, FS_USAGE *fs_usage)
return 0;
}
int fs_read_file(char * filename, void * data, int len){
FIL file;
UINT readbytes;
int res;
res=f_open(&file, filename, FA_OPEN_EXISTING|FA_READ);
if(res){
return -1;
};
res = f_read(&file, data, len, &readbytes);
if(res){
return -1;
};
f_close(&file);
return readbytes;
}
int fs_read_text_file(char * filename, char * data, int len){
int readbytes;
if(len<1) return -1;
readbytes=fs_read_file(filename,data,len-1);
if(readbytes<0){
data[0]=0;
return readbytes;
};
data[readbytes]=0;
while(readbytes>0 && data[readbytes-1]<0x20){
data[--readbytes]=0;
};
return readbytes;
}
int fs_write_file(char * filename, const void * data, int len){
FIL file;
UINT writebytes;
int res;
res=f_open(&file, filename, FA_CREATE_ALWAYS|FA_WRITE);
if(res){
return -res;
};
res = f_write(&file, data, len, &writebytes);
if(res){
return -res;
};
f_close(&file);
return writebytes;
}
int fs_get_file_size(char * filename){
FILINFO finfo;
int res;
/// XXX: Untested
res=f_stat(filename, &finfo);
if(res){
return -1;
}
return finfo.fsize;
}
#endif
......@@ -86,6 +86,7 @@ elf = executable(
'main.c',
'support.c',
'fs/filesystem_fat.c',
'fs/fs_util.c',
module_sources,
l0der_sources,
ble_sources,
......
......@@ -272,10 +272,10 @@ void load_config(void)
char newline;
rc = epic_file_read(fd, &newline, 1);
if (rc < 0 || (newline != '\n' && newline != '\r')) {
LOG_ERR("card10.cfg", "seek failed, aborting");
LOG_ERR("card10.cfg", "read failed, aborting");
LOG_DEBUG(
"card10.cfg",
"seek failed at read-back of newline: rc: %d read: %d",
"read failed at read-back of newline: rc: %d read: %d",
rc,
(int)newline
);
......@@ -305,7 +305,7 @@ static size_t read_config_offset(size_t seek_offset, char *buf, size_t buf_len)
int rc = epic_file_seek(fd, seek_offset, SEEK_SET);
if (rc < 0) {
LOG_ERR("card10.cfg", "seek failed, aborting");
LOG_ERR("card10.cfg", "seek2 failed (%d), aborting", rc);
return 0;
}
......
includes = include_directories(
'./Source/',
'./util/',
)
sources = files(
......@@ -8,7 +7,6 @@ sources = files(
'./Source/ff.c',
'./Source/ffsystem.c',
'./Source/ffunicode.c',
'./util/fs_util.c',
)
lib = static_library(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment