Added a function for setting the I/O semantics on a Coffee file descriptor. Changed the configuration parameters slightly and updated the platform definitions to reflect this change.

This commit is contained in:
Nicolas Tsiftes 2011-02-09 15:03:57 +01:00
parent 8d55a68ebe
commit 39ea9405bb
4 changed files with 108 additions and 12 deletions

View file

@ -32,7 +32,13 @@
/**
* \file
* Coffee: A flash file system for memory-constrained sensor systems.
* Coffee: A file system for a variety of storage types in
* memory-constrained devices.
*
* For further information, see "Enabling Large-Scale Storage in
* Sensor Networks with the Coffee File System" in the proceedings
* of ACM/IEEE IPSN 2009.
*
* \author
* Nicolas Tsiftes <nvt@sics.se>
*/
@ -53,14 +59,35 @@
#include "cfs-coffee-arch.h"
#include "cfs/cfs-coffee.h"
#ifndef COFFEE_CONF_APPEND_ONLY
#define COFFEE_APPEND_ONLY 0
#else
#define COFFEE_APPEND_ONLY COFFEE_CONF_APPEND_ONLY
#if COFFEE_MICRO_LOGS
#error "Cannot have COFFEE_APPEND_ONLY when COFFEE_MICRO_LOGS is set."
/* Micro logs enable modifications on storage types that do not support
in-place updates. This applies primarily to flash memories. */
#ifndef COFFEE_MICRO_LOGS
#define COFFEE_MICRO_LOGS 1
#endif
#define COFFEE_MICRO_LOGS 0
/* If the files are expected to be appended to only, this parameter
can be set to save some code space. */
#ifndef COFFEE_APPEND_ONLY
#define COFFEE_APPEND_ONLY 0
#endif
#if COFFEE_MICRO_LOGS && COFFEE_APPEND_ONLY
#error "Cannot have COFFEE_APPEND_ONLY set when COFFEE_MICRO_LOGS is set."
#endif
/* I/O semantics can be set on file descriptors in order to optimize
file access on certain storage types. */
#ifndef COFFEE_IO_SEMANTICS
#define COFFEE_IO_SEMANTICS 0
#endif
/*
* Prevent sectors from being erased directly after file removal.
* This will level the wear across sectors better, but may lead
* to longer garbage collection procedures.
*/
#ifndef COFFEE_EXTENDED_WEAR_LEVELLING
#define COFFEE_EXTENDED_WEAR_LEVELLING 1
#endif
#if COFFEE_START & (COFFEE_SECTOR_SIZE - 1)
@ -149,6 +176,9 @@ struct file_desc {
cfs_offset_t offset;
struct file *file;
uint8_t flags;
#ifdef COFFEE_IO_SEMANTICS
uint8_t io_flags;
#endif
};
/* The file header structure mimics the representation of file headers
@ -579,7 +609,7 @@ remove_by_page(coffee_page_t page, int remove_log, int close_fds,
}
}
#if !COFFEE_CONF_EXTENDED_WEAR_LEVELLING
#if !COFFEE_EXTENDED_WEAR_LEVELLING
if(gc_allowed) {
collect_garbage(GC_RELUCTANT);
}
@ -1137,6 +1167,9 @@ cfs_write(int fd, const void *buf, unsigned size)
file = fdp->file;
/* Attempt to extend the file if we try to write past the end. */
#ifdef COFFEE_IO_SEMANTICS
if(!(fdp->io_flags & CFS_COFFEE_IO_FIRM_SIZE)) {
#endif
while(size + fdp->offset + sizeof(struct file_header) >
(file->max_pages * COFFEE_PAGE_SIZE)) {
if(merge_log(file->page, 1) < 0) {
@ -1145,9 +1178,17 @@ cfs_write(int fd, const void *buf, unsigned size)
file = fdp->file;
PRINTF("Extended the file at page %u\n", (unsigned)file->page);
}
#ifdef COFFEE_IO_SEMANTICS
}
#endif
#if COFFEE_MICRO_LOGS
#if COFFEE_IO_SEMANTICS
if(!(fdp->io_flags & CFS_COFFEE_IO_TOGGLE_ONLY) &&
(FILE_MODIFIED(file) || fdp->offset < file->end)) {
#else
if(FILE_MODIFIED(file) || fdp->offset < file->end) {
#endif
for(bytes_left = size; bytes_left > 0;) {
lp.offset = fdp->offset;
lp.buf = buf;
@ -1280,6 +1321,20 @@ cfs_coffee_configure_log(const char *filename, unsigned log_size,
return 0;
}
/*---------------------------------------------------------------------------*/
#ifdef COFFEE_IO_SEMANTICS
int
cfs_coffee_set_io_semantics(int fd, unsigned flags)
{
if(!FD_VALID(fd)) {
return -1;
}
coffee_fd_set[fd].io_flags |= flags;
return 0;
}
#endif
/*---------------------------------------------------------------------------*/
int
cfs_coffee_format(void)
{