Made the use of micro logs configurable to make file modifications

more efficient on storage types that support inline updates.

The sky platform uses logs, and the native platform uses no logs.
This commit is contained in:
nvt-se 2009-06-29 13:30:16 +00:00
parent 828439c922
commit 1e0ca9ceac
3 changed files with 29 additions and 1 deletions

View file

@ -40,7 +40,7 @@
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
#define DEBUG 0 #define DEBUG 1
#if DEBUG #if DEBUG
#include <stdio.h> #include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__) #define PRINTF(...) printf(__VA_ARGS__)
@ -570,6 +570,7 @@ reserve(const char *name, coffee_page_t pages,
return file; return file;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if COFFEE_MICRO_LOGS
static void static void
adjust_log_config(struct file_header *hdr, adjust_log_config(struct file_header *hdr,
uint16_t *log_record_size, uint16_t *log_records) uint16_t *log_record_size, uint16_t *log_records)
@ -579,7 +580,9 @@ adjust_log_config(struct file_header *hdr,
*log_records = hdr->log_records == 0 ? *log_records = hdr->log_records == 0 ?
COFFEE_LOG_SIZE / *log_record_size : hdr->log_records; COFFEE_LOG_SIZE / *log_record_size : hdr->log_records;
} }
#endif /* COFFEE_MICRO_LOGS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if COFFEE_MICRO_LOGS
static uint16_t static uint16_t
modify_log_buffer(uint16_t log_record_size, modify_log_buffer(uint16_t log_record_size,
cfs_offset_t *offset, uint16_t *size) cfs_offset_t *offset, uint16_t *size)
@ -593,7 +596,9 @@ modify_log_buffer(uint16_t log_record_size,
} }
return region; return region;
} }
#endif /* COFFEE_MICRO_LOGS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if COFFEE_MICRO_LOGS
static int static int
get_record_index(coffee_page_t log_page, uint16_t search_records, get_record_index(coffee_page_t log_page, uint16_t search_records,
uint16_t region) uint16_t region)
@ -633,7 +638,9 @@ get_record_index(coffee_page_t log_page, uint16_t search_records,
return match_index; return match_index;
} }
#endif /* COFFEE_MICRO_LOGS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if COFFEE_MICRO_LOGS
static int static int
read_log_page(struct file_header *hdr, int16_t last_record, struct log_param *lp) read_log_page(struct file_header *hdr, int16_t last_record, struct log_param *lp)
{ {
@ -660,7 +667,9 @@ read_log_page(struct file_header *hdr, int16_t last_record, struct log_param *lp
return lp->size; return lp->size;
} }
#endif /* COFFEE_MICRO_LOGS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if COFFEE_MICRO_LOGS
static coffee_page_t static coffee_page_t
create_log(struct file *file, struct file_header *hdr) create_log(struct file *file, struct file_header *hdr)
{ {
@ -687,6 +696,7 @@ create_log(struct file *file, struct file_header *hdr)
file->flags |= COFFEE_FILE_MODIFIED; file->flags |= COFFEE_FILE_MODIFIED;
return log_page; return log_page;
} }
#endif /* COFFEE_MICRO_LOGS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
merge_log(coffee_page_t file_page, int extend) merge_log(coffee_page_t file_page, int extend)
@ -764,6 +774,7 @@ merge_log(coffee_page_t file_page, int extend)
return 0; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if COFFEE_MICRO_LOGS
static int static int
find_next_record(struct file *file, coffee_page_t log_page, find_next_record(struct file *file, coffee_page_t log_page,
int log_records) int log_records)
@ -800,7 +811,9 @@ find_next_record(struct file *file, coffee_page_t log_page,
return log_record; return log_record;
} }
#endif /* COFFEE_MICRO_LOGS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if COFFEE_MICRO_LOGS
static int static int
write_log_page(struct file *file, struct log_param *lp) write_log_page(struct file *file, struct log_param *lp)
{ {
@ -868,6 +881,7 @@ write_log_page(struct file *file, struct log_param *lp)
return lp->size; return lp->size;
} }
#endif /* COFFEE_MICRO_LOGS */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
get_available_fd(void) get_available_fd(void)
@ -987,7 +1001,9 @@ cfs_read(int fd, void *buf, unsigned size)
struct file *file; struct file *file;
unsigned bytes_left; unsigned bytes_left;
int r; int r;
#if COFFEE_MICRO_LOGS
struct log_param lp; struct log_param lp;
#endif
if(!(FD_VALID(fd) && FD_READABLE(fd))) { if(!(FD_VALID(fd) && FD_READABLE(fd))) {
return -1; return -1;
@ -1011,12 +1027,14 @@ cfs_read(int fd, void *buf, unsigned size)
while(bytes_left) { while(bytes_left) {
watchdog_periodic(); watchdog_periodic();
r = -1; r = -1;
#if COFFEE_MICRO_LOGS
if(FILE_MODIFIED(file)) { if(FILE_MODIFIED(file)) {
lp.offset = fdp->offset; lp.offset = fdp->offset;
lp.buf = buf; lp.buf = buf;
lp.size = bytes_left; lp.size = bytes_left;
r = read_log_page(&hdr, file->next_log_record, &lp); r = read_log_page(&hdr, file->next_log_record, &lp);
} }
#endif /* COFFEE_MICRO_LOGS */
/* Read from the original file if we cannot find the data in the log. */ /* Read from the original file if we cannot find the data in the log. */
if(r < 0) { if(r < 0) {
r = bytes_left; r = bytes_left;
@ -1034,10 +1052,12 @@ cfs_write(int fd, const void *buf, unsigned size)
{ {
struct file_desc *fdp; struct file_desc *fdp;
struct file *file; struct file *file;
#if COFFEE_MICRO_LOGS
int i; int i;
struct log_param lp; struct log_param lp;
cfs_offset_t bytes_left; cfs_offset_t bytes_left;
const char dummy[1] = { 0xff }; const char dummy[1] = { 0xff };
#endif
if(!(FD_VALID(fd) && FD_WRITABLE(fd))) { if(!(FD_VALID(fd) && FD_WRITABLE(fd))) {
return -1; return -1;
@ -1056,6 +1076,7 @@ cfs_write(int fd, const void *buf, unsigned size)
PRINTF("Extended the file at page %u\n", (unsigned)file->page); PRINTF("Extended the file at page %u\n", (unsigned)file->page);
} }
#if COFFEE_MICRO_LOGS
if(FILE_MODIFIED(file) || fdp->offset < file->end) { if(FILE_MODIFIED(file) || fdp->offset < file->end) {
bytes_left = size; bytes_left = size;
while(bytes_left) { while(bytes_left) {
@ -1085,9 +1106,12 @@ cfs_write(int fd, const void *buf, unsigned size)
COFFEE_WRITE(dummy, 1, absolute_offset(file->page, fdp->offset)); COFFEE_WRITE(dummy, 1, absolute_offset(file->page, fdp->offset));
} }
} else { } else {
#endif /* COFFEE_MICRO_LOGS */
COFFEE_WRITE(buf, size, absolute_offset(file->page, fdp->offset)); COFFEE_WRITE(buf, size, absolute_offset(file->page, fdp->offset));
fdp->offset += size; fdp->offset += size;
#if COFFEE_MICRO_LOGS
} }
#endif /* COFFEE_MICRO_LOGS */
if(fdp->offset > file->end) { if(fdp->offset > file->end) {
file->end = fdp->offset; file->end = fdp->offset;

View file

@ -56,6 +56,8 @@
#define COFFEE_LOG_TABLE_LIMIT 256 #define COFFEE_LOG_TABLE_LIMIT 256
#define COFFEE_DIR_CACHE_ENTRIES 16 #define COFFEE_DIR_CACHE_ENTRIES 16
#define COFFEE_MICRO_LOGS 0
#define COFFEE_WRITE(buf, size, offset) \ #define COFFEE_WRITE(buf, size, offset) \
xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset)) xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset))

View file

@ -56,6 +56,8 @@
#define COFFEE_DYN_SIZE 4*1024 #define COFFEE_DYN_SIZE 4*1024
#define COFFEE_LOG_SIZE 1024 #define COFFEE_LOG_SIZE 1024
#define COFFEE_MICRO_LOGS 1
/* Flash operations. */ /* Flash operations. */
#define COFFEE_WRITE(buf, size, offset) \ #define COFFEE_WRITE(buf, size, offset) \
xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset)) xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset))