fs/spiffs: Fix an error in write operation. examples/fstest now gets further before errors occur, but still does not work correctly.

This commit is contained in:
Gregory Nutt 2018-09-26 18:00:46 -06:00
parent 31e6fb561b
commit b4488a0549
3 changed files with 19 additions and 18 deletions

View file

@ -173,6 +173,7 @@ Using MSYS
pacman -S git pacman -S git
pacman -S make pacman -S make
pacman -S gcc pacman -S gcc
pacman -S gdb
And possibly others depending upon your usage. Then you will need to And possibly others depending upon your usage. Then you will need to
build and install kconfig-frontends per the instructions of the top-level build and install kconfig-frontends per the instructions of the top-level

View file

@ -1713,7 +1713,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
if (offset > fobj->size) if (offset > fobj->size)
{ {
finfo("Offset replaced with size\n"); finfo("Offset replaced with size\n");
offset = fobj->size; offset = fobj->size < 0 ? 0 : fobj->size;
} }
/* Add an extra page of data worth for meta */ /* Add an extra page of data worth for meta */
@ -1869,7 +1869,7 @@ int spiffs_object_append(FAR struct spiffs_s *fs,
{ {
/* load object index header page, must always exist */ /* load object index header page, must always exist */
finfo("append: %04x load objndxhdr page %04x:%04x\n", finfo("objid=%04x load objndxhdr page %04x:%04x\n",
fobj->objid, cur_objndx_pgndx, cur_objndx_spndx); fobj->objid, cur_objndx_pgndx, cur_objndx_spndx);
ret = spiffs_cache_read(fs, ret = spiffs_cache_read(fs,

View file

@ -348,7 +348,7 @@ static int spiffs_open(FAR struct file *filep, FAR const char *relpath,
int16_t pgndx; int16_t pgndx;
int ret; int ret;
finfo("relpath: %s oflags; %04x\n", relpath, oflags); finfo("relpath=%s oflags; %04x\n", relpath, oflags);
DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL); DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL);
/* Get the mountpoint inode reference from the file structure and the /* Get the mountpoint inode reference from the file structure and the
@ -500,7 +500,7 @@ static int spiffs_close(FAR struct file *filep)
FAR struct spiffs_s *fs; FAR struct spiffs_s *fs;
FAR struct spiffs_file_s *fobj; FAR struct spiffs_file_s *fobj;
finfo("filep: %p\n", filep); finfo("filep=%p\n", filep);
DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
/* Get the mountpoint inode reference from the file structure and the /* Get the mountpoint inode reference from the file structure and the
@ -562,7 +562,7 @@ static ssize_t spiffs_read(FAR struct file *filep, FAR char *buffer,
FAR struct spiffs_file_s *fobj; FAR struct spiffs_file_s *fobj;
ssize_t nread; ssize_t nread;
finfo("filep: %p buffer: %p buflen: %lu\n", finfo("filep=%p buffer=%p buflen=%lu\n",
filep, buffer, (unsigned long)buflen); filep, buffer, (unsigned long)buflen);
DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
@ -610,7 +610,7 @@ static ssize_t spiffs_write(FAR struct file *filep, FAR const char *buffer,
off_t offset; off_t offset;
int ret; int ret;
finfo("filep: %p buffer: %p buflen: %lu\n", finfo("filep=%p buffer=%p buflen=%lu\n",
filep, buffer, (unsigned long)buflen); filep, buffer, (unsigned long)buflen);
DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
@ -1142,7 +1142,7 @@ static int spiffs_truncate(FAR struct file *filep, off_t length)
off_t fsize; off_t fsize;
int ret; int ret;
finfo("filep: %p length: %ld\n", filep, (long)length); finfo("filep=%p length=%ld\n", filep, (long)length);
DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL && length >= 0); DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL && length >= 0);
/* Get the mountpoint inode reference from the file structure and the /* Get the mountpoint inode reference from the file structure and the
@ -1194,7 +1194,7 @@ static int spiffs_truncate(FAR struct file *filep, off_t length)
static int spiffs_opendir(FAR struct inode *mountpt, FAR const char *relpath, static int spiffs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
FAR struct fs_dirent_s *dir) FAR struct fs_dirent_s *dir)
{ {
finfo("mountpt: %p relpath: %s dir: %p\n", finfo("mountpt=%p relpath=%s dir=%p\n",
mountpt, relpath, dir); mountpt, relpath, dir);
DEBUGASSERT(mountpt != NULL && relpath != NULL && dir != NULL); DEBUGASSERT(mountpt != NULL && relpath != NULL && dir != NULL);
@ -1213,7 +1213,7 @@ static int spiffs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
static int spiffs_closedir(FAR struct inode *mountpt, static int spiffs_closedir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir) FAR struct fs_dirent_s *dir)
{ {
finfo("mountpt: %p dir: %p\n", mountpt, dir); finfo("mountpt=%p dir=%p\n", mountpt, dir);
DEBUGASSERT(mountpt != NULL && dir != NULL); DEBUGASSERT(mountpt != NULL && dir != NULL);
/* There is nothing to be done */ /* There is nothing to be done */
@ -1233,7 +1233,7 @@ static int spiffs_readdir(FAR struct inode *mountpt,
int entry; int entry;
int ret; int ret;
finfo("mountpt: %p dir: %p\n", mountpt, dir); finfo("mountpt=%p dir=%p\n", mountpt, dir);
DEBUGASSERT(mountpt != NULL && dir != NULL); DEBUGASSERT(mountpt != NULL && dir != NULL);
/* Get the mountpoint private data from the inode structure */ /* Get the mountpoint private data from the inode structure */
@ -1269,7 +1269,7 @@ static int spiffs_readdir(FAR struct inode *mountpt,
static int spiffs_rewinddir(FAR struct inode *mountpt, static int spiffs_rewinddir(FAR struct inode *mountpt,
FAR struct fs_dirent_s *dir) FAR struct fs_dirent_s *dir)
{ {
finfo("mountpt: %p dir: %p\n", mountpt, dir); finfo("mountpt=%p dir=%p\n", mountpt, dir);
DEBUGASSERT(mountpt != NULL && dir != NULL); DEBUGASSERT(mountpt != NULL && dir != NULL);
/* Reset as when opendir() was called. */ /* Reset as when opendir() was called. */
@ -1296,7 +1296,7 @@ static int spiffs_bind(FAR struct inode *mtdinode, FAR const void *data,
size_t addrmask; size_t addrmask;
int ret; int ret;
finfo("mtdinode: %p data: %p handle: %p\n", mtdinode, data, handle); finfo("mtdinode=%p data=%p handle=%p\n", mtdinode, data, handle);
DEBUGASSERT(mtdinode != NULL && handle != NULL); DEBUGASSERT(mtdinode != NULL && handle != NULL);
/* Extract the MTD interface reference */ /* Extract the MTD interface reference */
@ -1437,7 +1437,7 @@ static int spiffs_unbind(FAR void *handle, FAR struct inode **mtdinode,
FAR struct spiffs_file_s *fobj; FAR struct spiffs_file_s *fobj;
int ret; int ret;
finfo("handle: %p mtdinode: %p flags: %02x\n", finfo("handle=%p mtdinode=%p flags=%02x\n",
handle, mtdinode, flags); handle, mtdinode, flags);
DEBUGASSERT(fs != NULL); DEBUGASSERT(fs != NULL);
@ -1502,7 +1502,7 @@ static int spiffs_statfs(FAR struct inode *mountpt, FAR struct statfs *buf)
uint32_t nfile_objs; uint32_t nfile_objs;
uint32_t used; uint32_t used;
finfo("mountpt: %p buf: %p\n", mountpt, buf); finfo("mountpt=%p buf=%p\n", mountpt, buf);
DEBUGASSERT(mountpt != NULL && buf != NULL); DEBUGASSERT(mountpt != NULL && buf != NULL);
/* Get the mountpoint private data from the inode structure */ /* Get the mountpoint private data from the inode structure */
@ -1564,7 +1564,7 @@ static int spiffs_unlink(FAR struct inode *mountpt, FAR const char *relpath)
int16_t pgndx; int16_t pgndx;
int ret; int ret;
finfo("mountpt: %p relpath: %s\n", mountpt, relpath); finfo("mountpt=%p relpath=%s\n", mountpt, relpath);
DEBUGASSERT(mountpt != NULL && relpath != NULL); DEBUGASSERT(mountpt != NULL && relpath != NULL);
if (strlen(relpath) > CONFIG_SPIFFS_NAME_MAX - 1) if (strlen(relpath) > CONFIG_SPIFFS_NAME_MAX - 1)
@ -1661,7 +1661,7 @@ errout_with_lock:
static int spiffs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, static int spiffs_mkdir(FAR struct inode *mountpt, FAR const char *relpath,
mode_t mode) mode_t mode)
{ {
finfo("mountpt: %p relpath: %s mode: %04x\n", mountpt, relpath, mode); finfo("mountpt=%p relpath=%s mode=%04x\n", mountpt, relpath, mode);
DEBUGASSERT(mountpt != NULL && relpath != NULL); DEBUGASSERT(mountpt != NULL && relpath != NULL);
/* Directories are not supported */ /* Directories are not supported */
@ -1675,7 +1675,7 @@ static int spiffs_mkdir(FAR struct inode *mountpt, FAR const char *relpath,
static int spiffs_rmdir(FAR struct inode *mountpt, FAR const char *relpath) static int spiffs_rmdir(FAR struct inode *mountpt, FAR const char *relpath)
{ {
finfo("mountpt: %p relpath: %s\n", mountpt, relpath); finfo("mountpt=%p relpath=%s\n", mountpt, relpath);
DEBUGASSERT(mountpt != NULL && relpath != NULL); DEBUGASSERT(mountpt != NULL && relpath != NULL);
/* Directories are not supported */ /* Directories are not supported */
@ -1696,7 +1696,7 @@ static int spiffs_rename(FAR struct inode *mountpt, FAR const char *oldrelpath,
int16_t newpgndx; int16_t newpgndx;
int ret; int ret;
finfo("mountpt: %p oldrelpath: %s newrelpath: %s\n", finfo("mountpt=%p oldrelpath=%s newrelpath=%s\n",
mountpt, oldrelpath, newrelpath); mountpt, oldrelpath, newrelpath);
DEBUGASSERT(mountpt != NULL && oldrelpath != NULL && newrelpath != NULL); DEBUGASSERT(mountpt != NULL && oldrelpath != NULL && newrelpath != NULL);