diff --git a/configs/sim/src/sim_bringup.c b/configs/sim/src/sim_bringup.c index 7206458368..22351f6270 100644 --- a/configs/sim/src/sim_bringup.c +++ b/configs/sim/src/sim_bringup.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -151,6 +152,15 @@ int sim_bringup(void) */ smart_initialize(0, mtd, NULL); +#elif defined(CONFIG_FS_NXFFS) + /* Initialize to provide NXFFS on the MTD interface */ + + ret = nxffs_initialize(mtd); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: NXFFS initialization failed: %d\n", + ret); + } #endif } } diff --git a/fs/nxffs/nxffs.h b/fs/nxffs/nxffs.h index d59e30f202..bc979a3050 100644 --- a/fs/nxffs/nxffs.h +++ b/fs/nxffs/nxffs.h @@ -888,8 +888,10 @@ int nxffs_updateinode(FAR struct nxffs_volume_s *volume, * ****************************************************************************/ +#ifdef __NO_TRUNCATE_SUPPORT__ int nxffs_wrextend(FAR struct nxffs_volume_s *volume, FAR struct nxffs_wrfile_s *wrfile, off_t length); +#endif /**************************************************************************** * Name: nxffs_wrreserve @@ -1115,7 +1117,9 @@ int nxffs_ioctl(FAR struct file *filep, int cmd, unsigned long arg); int nxffs_dup(FAR const struct file *oldp, FAR struct file *newp); int nxffs_fstat(FAR const struct file *filep, FAR struct stat *buf); +#ifdef __NO_TRUNCATE_SUPPORT__ int nxffs_truncate(FAR struct file *filep, off_t length); +#endif int nxffs_opendir(FAR struct inode *mountpt, FAR const char *relpath, FAR struct fs_dirent_s *dir); diff --git a/fs/nxffs/nxffs_initialize.c b/fs/nxffs/nxffs_initialize.c index b3a897210f..0bd5aab2f5 100644 --- a/fs/nxffs/nxffs_initialize.c +++ b/fs/nxffs/nxffs_initialize.c @@ -75,7 +75,11 @@ const struct mountpt_operations nxffs_operations = NULL, /* sync -- No buffered data */ nxffs_dup, /* dup */ nxffs_fstat, /* fstat */ +#ifdef __NO_TRUNCATE_SUPPORT__ nxffs_truncate, /* truncate */ +#else + NULL, /* truncate */ +#endif nxffs_opendir, /* opendir */ NULL, /* closedir */ diff --git a/fs/nxffs/nxffs_truncate.c b/fs/nxffs/nxffs_truncate.c index c8e92c0b48..e4b1cbeaae 100644 --- a/fs/nxffs/nxffs_truncate.c +++ b/fs/nxffs/nxffs_truncate.c @@ -50,6 +50,8 @@ #include "nxffs.h" +#ifdef __NO_TRUNCATE_SUPPORT__ + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -136,3 +138,4 @@ errout: return ret; } +#endif /* __NO_TRUNCATE_SUPPORT__ */ diff --git a/fs/nxffs/nxffs_write.c b/fs/nxffs/nxffs_write.c index 308ef6914a..1fd761e440 100644 --- a/fs/nxffs/nxffs_write.c +++ b/fs/nxffs/nxffs_write.c @@ -290,7 +290,7 @@ static inline int nxffs_wralloc(FAR struct nxffs_volume_s *volume, ****************************************************************************/ static inline int nxffs_reverify(FAR struct nxffs_volume_s *volume, - FAR struct nxffs_wrfile_s *wrfile) + FAR struct nxffs_wrfile_s *wrfile) { uint32_t crc; off_t offset; @@ -300,13 +300,13 @@ static inline int nxffs_reverify(FAR struct nxffs_volume_s *volume, /* Get the offset to the start of the data */ offset = volume->iooffset + SIZEOF_NXFFS_DATA_HDR; - DEBUGASSERT(offset + wrfile->datlen < volume->geo.blocksize); + DEBUGASSERT(offset + wrfile->datlen <= volume->geo.blocksize); /* Calculate the CRC of the partial data block */ crc = crc32(&volume->cache[offset], wrfile->datlen); - /* It must match the previoulsy calculated CRC value */ + /* It must match the previously calculated CRC value */ if (crc != wrfile->crc) { @@ -427,18 +427,19 @@ static inline ssize_t nxffs_wrappend(FAR struct nxffs_volume_s *volume, * nzeros - The number of bytes of zeroed data to be written * * Returned Value: - * The number of bytes written is returned on success. Otherwise, a + * The number of zero bytes written is returned on success. Otherwise, a * negated errno value is returned indicating the nature of the failure. * ****************************************************************************/ +#ifdef __NO_TRUNCATE_SUPPORT__ static inline ssize_t nxffs_zappend(FAR struct nxffs_volume_s *volume, FAR struct nxffs_wrfile_s *wrfile, off_t nzeros) { ssize_t maxsize; size_t nbytestoclear; - ssize_t remaining; + ssize_t nbytesleft; off_t offset; int ret; @@ -456,11 +457,11 @@ static inline ssize_t nxffs_zappend(FAR struct nxffs_volume_s *volume, /* Write as many bytes as we can into the data buffer */ nbytestoclear = MIN(maxsize, nzeros); - remaining = maxsize - nbytestoclear; + nbytesleft = maxsize - nbytestoclear; if (nbytestoclear > 0) { - /* Copy the data into the volume write cache */ + /* Zero the data into the volume write cache */ memset(&volume->cache[offset], 0, nbytestoclear); @@ -477,7 +478,7 @@ static inline ssize_t nxffs_zappend(FAR struct nxffs_volume_s *volume, * block is full. In that case, the block will be written below. */ - if (remaining > 0) + if (nbytesleft > 0) { ret = nxffs_wrcache(volume); if (ret < 0) @@ -490,7 +491,7 @@ static inline ssize_t nxffs_zappend(FAR struct nxffs_volume_s *volume, /* Check if the data block is now full */ - if (remaining <= 0) + if (nbytesleft <= 0) { /* The data block is full, write the block to FLASH */ @@ -502,8 +503,9 @@ static inline ssize_t nxffs_zappend(FAR struct nxffs_volume_s *volume, } } - return 0; + return nbytestoclear; } +#endif /**************************************************************************** * Public Functions @@ -642,6 +644,7 @@ errout: * ****************************************************************************/ +#ifdef __NO_TRUNCATE_SUPPORT__ int nxffs_wrextend(FAR struct nxffs_volume_s *volume, FAR struct nxffs_wrfile_s *wrfile, off_t length) { @@ -709,6 +712,7 @@ int nxffs_wrextend(FAR struct nxffs_volume_s *volume, return OK; } +#endif /**************************************************************************** * Name: nxffs_wrreserve