Added file removal function to the CFS API. Only cfs-coffee and cfs-posix

implements this, whereas the others just return -1.
This commit is contained in:
nvt-se 2008-11-24 10:56:55 +00:00
parent 3b8f6af71c
commit 15e8675ab9
7 changed files with 50 additions and 20 deletions

View file

@ -766,18 +766,19 @@ find_next_record(struct file_desc *fdp, coffee_page_t log_page,
uint16_t batch_size; uint16_t batch_size;
log_record = log_records; log_record = log_records;
for(processed = 0; processed < log_records;) { for(processed = 0; processed < log_records; processed += batch_size) {
batch_size = log_records - processed >= preferred_batch_size ? batch_size = log_records - processed >= preferred_batch_size ?
preferred_batch_size : log_records - processed; preferred_batch_size : log_records - processed;
COFFEE_READ(&indices, batch_size * sizeof(indices[0]), COFFEE_READ(&indices, batch_size * sizeof(indices[0]),
ABS_OFFSET(log_page, processed * sizeof(indices[0]))); ABS_OFFSET(log_page, processed * sizeof(indices[0])));
for(i = 0; i < batch_size && indices[i] != 0; i++); for(i = 0; i < batch_size && indices[i] != 0; i++);
log_record = i; log_record = i;
if(log_record < batch_size) { if(log_record < batch_size) {
log_record += processed; log_record += processed;
break; break;
} }
processed += batch_size;
} }
} else { } else {
log_record = fdp->next_log_record; log_record = fdp->next_log_record;
@ -944,10 +945,17 @@ cfs_seek(int fd, unsigned offset)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
cfs_coffee_remove(const char *name) cfs_remove(const char *name)
{ {
int page; int page;
/*
* Coffee removes files by marking them as obsolete. The space
* is not guaranteed to be reclaimed immediately, but must be
* sweeped by the garbage collector. The garbage collector is
* called once a file reservation request cannot be granted.
*/
page = find_file(name); page = find_file(name);
if(page < 0) { if(page < 0) {
return -1; return -1;

View file

@ -48,18 +48,6 @@
* @{ * @{
*/ */
/**
* \brief Remove a file.
* \param name The filename.
* \return 0 on success, -1 on failure.
*
* Coffee removes files by marking them as obsolete. Therefore, the
* space is not guaranteed to be reclaimed immediately, but must be
* sweeped by the garbage collector. The garbage collector is called
* once a file reservation request cannot be granted.
*/
int cfs_coffee_remove(const char *name);
/** /**
* \brief Reserve space for a file. * \brief Reserve space for a file.
* \param name The filename. * \param name The filename.

View file

@ -30,7 +30,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $Id: cfs-eeprom.c,v 1.7 2008/01/24 13:08:35 adamdunkels Exp $ * $Id: cfs-eeprom.c,v 1.8 2008/11/24 10:56:55 nvt-se Exp $
*/ */
#include "cfs/cfs.h" #include "cfs/cfs.h"
@ -117,6 +117,12 @@ cfs_seek(int f, unsigned int o)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
cfs_remove(const char *name)
{
return -1;
}
/*---------------------------------------------------------------------------*/
int
cfs_opendir(struct cfs_dir *p, const char *n) cfs_opendir(struct cfs_dir *p, const char *n)
{ {
return -1; return -1;

View file

@ -30,7 +30,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $Id: cfs-posix.c,v 1.11 2008/07/06 11:08:07 oliverschmidt Exp $ * $Id: cfs-posix.c,v 1.12 2008/11/24 10:56:55 nvt-se Exp $
*/ */
#include <stdio.h> #include <stdio.h>
@ -90,3 +90,9 @@ cfs_seek(int f, unsigned int o)
return lseek(f, o, SEEK_SET); return lseek(f, o, SEEK_SET);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int
cfs_remove(const char *name)
{
return remove(name);
}
/*---------------------------------------------------------------------------*/

View file

@ -30,7 +30,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $Id: cfs-ram.c,v 1.8 2008/01/24 23:07:05 adamdunkels Exp $ * $Id: cfs-ram.c,v 1.9 2008/11/24 10:56:55 nvt-se Exp $
*/ */
#include <string.h> #include <string.h>
@ -142,6 +142,12 @@ cfs_seek(int f, unsigned int o)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
cfs_remove(const char *name)
{
return -1;
}
/*---------------------------------------------------------------------------*/
int
cfs_opendir(struct cfs_dir *p, const char *n) cfs_opendir(struct cfs_dir *p, const char *n)
{ {
return -1; return -1;

View file

@ -30,7 +30,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $Id: cfs-xmem.c,v 1.8 2008/01/24 13:08:35 adamdunkels Exp $ * $Id: cfs-xmem.c,v 1.9 2008/11/24 10:56:55 nvt-se Exp $
*/ */
#include "cfs/cfs.h" #include "cfs/cfs.h"
@ -148,6 +148,12 @@ cfs_seek(int f, unsigned int o)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
cfs_remove(const char *name)
{
return -1;
}
/*---------------------------------------------------------------------------*/
int
cfs_opendir(struct cfs_dir *p, const char *n) cfs_opendir(struct cfs_dir *p, const char *n)
{ {
return -1; return -1;

View file

@ -54,7 +54,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $Id: cfs.h,v 1.11 2008/01/24 13:08:35 adamdunkels Exp $ * $Id: cfs.h,v 1.12 2008/11/24 10:56:55 nvt-se Exp $
*/ */
#ifndef __CFS_H__ #ifndef __CFS_H__
#define __CFS_H__ #define __CFS_H__
@ -190,6 +190,16 @@ CCIF int cfs_write(int fd, const void *buf, unsigned int len);
CCIF unsigned int cfs_seek(int fd, unsigned int offset); CCIF unsigned int cfs_seek(int fd, unsigned int offset);
#endif #endif
/**
* \brief Remove a file.
* \param name The name of the file.
* \retval 0 If the file was removed.
* \return -1 If the file could not be removed or if it doesn't exist.
*/
#ifndef cfs_remove
CCIF int cfs_remove(const char *name);
#endif
/** /**
* \brief Open a directory for reading directory entries. * \brief Open a directory for reading directory entries.
* \param dirp A pointer to a struct cfs_dir that is filled in by the function. * \param dirp A pointer to a struct cfs_dir that is filled in by the function.