You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/03/04 00:28:31 UTC
incubator-mynewt-larva git commit: Some changes to make doc examples
clearer.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/develop 9ad54b8d7 -> 6660ec0ce
Some changes to make doc examples clearer.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/6660ec0c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/6660ec0c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/6660ec0c
Branch: refs/heads/develop
Commit: 6660ec0ce2c81f6385298f173c1d60395b2958bb
Parents: 9ad54b8
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Mar 2 12:13:25 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Mar 3 15:28:02 2016 -0800
----------------------------------------------------------------------
fs/fs/include/fs/fs.h | 28 ++++++++++++++--------------
fs/nffs/include/nffs/nffs.h | 2 --
fs/nffs/pkg.yml | 4 ++--
fs/nffs/src/nffs.c | 37 ++++++++++++-------------------------
fs/nffs/src/nffs_block.c | 4 ++--
fs/nffs/src/nffs_file.c | 4 ++--
fs/nffs/src/nffs_flash.c | 10 +++++-----
fs/nffs/src/nffs_inode.c | 2 +-
fs/nffs/src/nffs_misc.c | 12 ++++++++++++
fs/nffs/src/nffs_priv.h | 1 +
fs/nffs/src/nffs_restore.c | 2 +-
project/slinky/pkg.yml | 5 +++--
project/slinky/src/main.c | 9 +++++++++
13 files changed, 64 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/fs/fs/include/fs/fs.h
----------------------------------------------------------------------
diff --git a/fs/fs/include/fs/fs.h b/fs/fs/include/fs/fs.h
index f304d88..e29f7f3 100644
--- a/fs/fs/include/fs/fs.h
+++ b/fs/fs/include/fs/fs.h
@@ -60,19 +60,19 @@ int fs_dirent_is_dir(const struct fs_dirent *);
/*
* File access return codes.
*/
-#define FS_EOK 0 /* OK */
-#define FS_ECORRUPT 1 /* Filesystem corrupt */
-#define FS_EHW 2 /* Error access storage medium */
-#define FS_ERANGE 3
-#define FS_EINVAL 4
-#define FS_ENOMEM 5 /* out of memory */
-#define FS_ENOENT 6 /* no such file */
-#define FS_EEMPTY 7
-#define FS_EFULL 8
-#define FS_EUNEXP 9
-#define FS_EOS 10
-#define FS_EEXIST 11
-#define FS_EACCESS 12
-#define FS_EUNINIT 13
+#define FS_EOK 0 /* Success */
+#define FS_ECORRUPT 1 /* File system corrupt */
+#define FS_EHW 2 /* Error accessing storage medium */
+#define FS_EOFFSET 3 /* Invalid offset */
+#define FS_EINVAL 4 /* Invalid argument */
+#define FS_ENOMEM 5 /* Insufficient memory */
+#define FS_ENOENT 6 /* No such file or directory */
+#define FS_EEMPTY 7 /* Specified region is empty (internal only) */
+#define FS_EFULL 8 /* Disk full */
+#define FS_EUNEXP 9 /* Disk contains unexpected metadata */
+#define FS_EOS 10 /* OS error */
+#define FS_EEXIST 11 /* File or directory already exists */
+#define FS_EACCESS 12 /* Operation prohibited by file open mode */
+#define FS_EUNINIT 13 /* File system not initialized */
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/fs/nffs/include/nffs/nffs.h
----------------------------------------------------------------------
diff --git a/fs/nffs/include/nffs/nffs.h b/fs/nffs/include/nffs/nffs.h
index 41519bd..73a0ec1 100644
--- a/fs/nffs/include/nffs/nffs.h
+++ b/fs/nffs/include/nffs/nffs.h
@@ -57,7 +57,5 @@ struct nffs_area_desc {
int nffs_init(void);
int nffs_detect(const struct nffs_area_desc *area_descs);
int nffs_format(const struct nffs_area_desc *area_descs);
-int nffs_ready(void);
-
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/fs/nffs/pkg.yml
----------------------------------------------------------------------
diff --git a/fs/nffs/pkg.yml b/fs/nffs/pkg.yml
index 3866598..d1878ac 100644
--- a/fs/nffs/pkg.yml
+++ b/fs/nffs/pkg.yml
@@ -30,8 +30,8 @@ pkg.keywords:
pkg.identities: NFFS
pkg.deps:
- - sys/log
- fs/fs
+ - hw/hal
- libs/os
- libs/testutil
- - hw/hal
+ - sys/log
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/fs/nffs/src/nffs.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs.c b/fs/nffs/src/nffs.c
index ede074b..c90c4ef 100644
--- a/fs/nffs/src/nffs.c
+++ b/fs/nffs/src/nffs.c
@@ -146,7 +146,7 @@ nffs_open(const char *path, uint8_t access_flags, struct fs_file **out_fs_file)
nffs_lock();
- if (!nffs_ready()) {
+ if (!nffs_misc_ready()) {
rc = FS_EUNINIT;
goto done;
}
@@ -257,8 +257,7 @@ nffs_file_len(const struct fs_file *fs_file, uint32_t *out_len)
/**
* Reads data from the specified file. If more data is requested than remains
- * in the file, all available data is retrieved. Note: this type of short read
- * results in a success return code.
+ * in the file, all available data is retrieved and a success code is returned.
*
* @param file The file to read from.
* @param len The number of bytes to attempt to read.
@@ -299,7 +298,7 @@ nffs_write(struct fs_file *fs_file, const void *data, int len)
nffs_lock();
- if (!nffs_ready()) {
+ if (!nffs_misc_ready()) {
rc = FS_EUNINIT;
goto done;
}
@@ -333,7 +332,7 @@ nffs_unlink(const char *path)
nffs_lock();
- if (!nffs_ready()) {
+ if (!nffs_misc_ready()) {
rc = FS_EUNINIT;
goto done;
}
@@ -373,7 +372,7 @@ nffs_rename(const char *from, const char *to)
nffs_lock();
- if (!nffs_ready()) {
+ if (!nffs_misc_ready()) {
rc = FS_EUNINIT;
goto done;
}
@@ -395,7 +394,7 @@ done:
* directories must already exist. The specified path must start with a '/'
* character.
*
- * @param path The directory to create.
+ * @param path The name of the directory to create.
*
* @return 0 on success;
* nonzero on failure.
@@ -407,7 +406,7 @@ nffs_mkdir(const char *path)
nffs_lock();
- if (!nffs_ready()) {
+ if (!nffs_misc_ready()) {
rc = FS_EUNINIT;
goto done;
}
@@ -430,7 +429,7 @@ done:
* Unlinking files from the directory while it is open may result in
* unpredictable behavior. New files can be created inside the directory.
*
- * @param path The directory to open.
+ * @param path The name of the directory to open.
* @param out_dir On success, points to the directory handle.
*
* @return 0 on success;
@@ -446,7 +445,7 @@ nffs_opendir(const char *path, struct fs_dir **out_fs_dir)
nffs_lock();
- if (!nffs_ready()) {
+ if (!nffs_misc_ready()) {
rc = FS_EUNINIT;
goto done;
}
@@ -487,7 +486,7 @@ nffs_readdir(struct fs_dir *fs_dir, struct fs_dirent **out_fs_dirent)
/**
* Closes the specified directory handle.
*
- * @param dir The directory to close.
+ * @param dir The name of the directory to close.
*
* @return 0 on success; nonzero on failure.
*/
@@ -610,20 +609,8 @@ nffs_detect(const struct nffs_area_desc *area_descs)
}
/**
- * Indicates whether a valid filesystem has been initialized, either via
- * detection or formatting.
- *
- * @return 1 if a file system is present; 0 otherwise.
- */
-int
-nffs_ready(void)
-{
- return nffs_root_dir != NULL;
-}
-
-/**
- * Initializes the nffs memory and data structures. This must be called before
- * any nffs operations are attempted.
+ * Initializes internal nffs memory and data structures. This must be called
+ * before any nffs operations are attempted.
*
* @return 0 on success; nonzero on error.
*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/fs/nffs/src/nffs_block.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_block.c b/fs/nffs/src/nffs_block.c
index 3244716..2186444 100644
--- a/fs/nffs/src/nffs_block.c
+++ b/fs/nffs/src/nffs_block.c
@@ -53,7 +53,7 @@ nffs_block_entry_free(struct nffs_hash_entry *entry)
* @param out_disk_block On success, the block header is writteh here.
*
* @return 0 on success;
- * FS_ERANGE on an attempt to read an invalid
+ * FS_EOFFSET on an attempt to read an invalid
* address range;
* FS_EHW on flash error;
* FS_EUNEXP if the specified disk location does
@@ -331,7 +331,7 @@ nffs_block_from_hash_entry_no_ptrs(struct nffs_block *out_block,
* @return 0 on success;
* FS_ECORRUPT if one or more pointers could not
* be filled in due to file system corruption;
- * FS_ERANGE on an attempt to read an invalid
+ * FS_EOFFSET on an attempt to read an invalid
* address range;
* FS_EHW on flash error;
* FS_EUNEXP if the specified disk location does
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/fs/nffs/src/nffs_file.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_file.c b/fs/nffs/src/nffs_file.c
index c0f02a6..40741df 100644
--- a/fs/nffs/src/nffs_file.c
+++ b/fs/nffs/src/nffs_file.c
@@ -272,7 +272,7 @@ nffs_file_seek(struct nffs_file *file, uint32_t offset)
}
if (offset > len) {
- return FS_ERANGE;
+ return FS_EOFFSET;
}
file->nf_offset = offset;
@@ -299,7 +299,7 @@ nffs_file_read(struct nffs_file *file, uint32_t len, void *out_data,
uint32_t bytes_read;
int rc;
- if (!nffs_ready()) {
+ if (!nffs_misc_ready()) {
return FS_EUNINIT;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/fs/nffs/src/nffs_flash.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_flash.c b/fs/nffs/src/nffs_flash.c
index 7fb98a0..2588cf2 100644
--- a/fs/nffs/src/nffs_flash.c
+++ b/fs/nffs/src/nffs_flash.c
@@ -35,7 +35,7 @@ uint8_t nffs_flash_buf[NFFS_FLASH_BUF_SZ];
* @param len The number of bytes to read.
*
* @return 0 on success;
- * FS_ERANGE on an attempt to read an invalid
+ * FS_EOFFSET on an attempt to read an invalid
* address range;
* FS_EHW on flash error.
*/
@@ -51,7 +51,7 @@ nffs_flash_read(uint8_t area_idx, uint32_t area_offset, void *data,
area = nffs_areas + area_idx;
if (area_offset + len > area->na_length) {
- return FS_ERANGE;
+ return FS_EOFFSET;
}
rc = hal_flash_read(area->na_flash_id, area->na_offset + area_offset, data,
@@ -72,7 +72,7 @@ nffs_flash_read(uint8_t area_idx, uint32_t area_offset, void *data,
* @param len The number of bytes to write.
*
* @return 0 on success;
- * FS_ERANGE on an attempt to write to an
+ * FS_EOFFSET on an attempt to write to an
* invalid address range, or on an attempt to
* perform a non-strictly-sequential write;
* FS_EFLASH_ERROR on flash error.
@@ -88,11 +88,11 @@ nffs_flash_write(uint8_t area_idx, uint32_t area_offset, const void *data,
area = nffs_areas + area_idx;
if (area_offset + len > area->na_length) {
- return FS_ERANGE;
+ return FS_EOFFSET;
}
if (area_offset < area->na_cur) {
- return FS_ERANGE;
+ return FS_EOFFSET;
}
rc = hal_flash_write(area->na_flash_id, area->na_offset + area_offset,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/fs/nffs/src/nffs_inode.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_inode.c b/fs/nffs/src/nffs_inode.c
index 7adb0c3..aa7accf 100644
--- a/fs/nffs/src/nffs_inode.c
+++ b/fs/nffs/src/nffs_inode.c
@@ -758,7 +758,7 @@ nffs_inode_seek(struct nffs_inode_entry *inode_entry, uint32_t offset,
}
if (offset > cache_inode->nci_file_size) {
- return FS_ERANGE;
+ return FS_EOFFSET;
}
if (offset == cache_inode->nci_file_size) {
memset(&out_seek_info->nsi_last_block, 0,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/fs/nffs/src/nffs_misc.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_misc.c b/fs/nffs/src/nffs_misc.c
index 03dd16f..e3e1dc7 100644
--- a/fs/nffs/src/nffs_misc.c
+++ b/fs/nffs/src/nffs_misc.c
@@ -353,3 +353,15 @@ nffs_misc_reset(void)
return 0;
}
+
+/**
+ * Indicates whether a valid filesystem has been initialized, either via
+ * detection or formatting.
+ *
+ * @return 1 if a file system is present; 0 otherwise.
+ */
+int
+nffs_misc_ready(void)
+{
+ return nffs_root_dir != NULL;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/fs/nffs/src/nffs_priv.h
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_priv.h b/fs/nffs/src/nffs_priv.h
index a89d042..7b1159a 100644
--- a/fs/nffs/src/nffs_priv.h
+++ b/fs/nffs/src/nffs_priv.h
@@ -407,6 +407,7 @@ int nffs_misc_validate_scratch(void);
int nffs_misc_create_lost_found_dir(void);
int nffs_misc_set_max_block_data_len(uint16_t min_data_len);
int nffs_misc_reset(void);
+int nffs_misc_ready(void);
/* @path */
int nffs_path_parse_next(struct nffs_path_parser *parser);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/fs/nffs/src/nffs_restore.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_restore.c b/fs/nffs/src/nffs_restore.c
index 35e8226..06ea613 100644
--- a/fs/nffs/src/nffs_restore.c
+++ b/fs/nffs/src/nffs_restore.c
@@ -840,7 +840,7 @@ nffs_restore_area_contents(int area_idx)
break;
case FS_EEMPTY:
- case FS_ERANGE:
+ case FS_EOFFSET:
/* End of disk encountered; area fully restored. */
return 0;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/project/slinky/pkg.yml
----------------------------------------------------------------------
diff --git a/project/slinky/pkg.yml b/project/slinky/pkg.yml
index 0935cf1..63d48c3 100644
--- a/project/slinky/pkg.yml
+++ b/project/slinky/pkg.yml
@@ -26,7 +26,10 @@ pkg.repository: https://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva
pkg.keywords:
pkg.deps:
+ - fs/nffs
+ - libs/baselibc
- libs/console/full
+ - libs/flash_test
- libs/imgmgr
- libs/newtmgr
- libs/os
@@ -35,5 +38,3 @@ pkg.deps:
- sys/config
- sys/log
- sys/stats
- - libs/baselibc
- - libs/flash_test
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/6660ec0c/project/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/project/slinky/src/main.c b/project/slinky/src/main.c
index d909cd5..edaad80 100755
--- a/project/slinky/src/main.c
+++ b/project/slinky/src/main.c
@@ -217,6 +217,8 @@ main(int argc, char **argv)
{
int rc;
int cnt;
+
+ /* NFFS_AREA_MAX is defined in the BSP-specified bsp.h header file. */
struct nffs_area_desc descs[NFFS_AREA_MAX];
#ifdef ARCH_sim
@@ -253,13 +255,20 @@ main(int argc, char **argv)
rc = hal_flash_init();
assert(rc == 0);
+ /* Initialize nffs's internal state. */
rc = nffs_init();
assert(rc == 0);
+ /* Convert the set of flash blocks we intend to use for nffs into an array
+ * of nffs area descriptors.
+ */
cnt = NFFS_AREA_MAX;
rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, descs);
assert(rc == 0);
+
+ /* Attempt to restore an existing nffs file system from flash. */
if (nffs_detect(descs) == FS_ECORRUPT) {
+ /* No valid nffs instance detected; format a new one. */
rc = nffs_format(descs);
assert(rc == 0);
}