You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ad...@apache.org on 2016/03/04 09:40:18 UTC

[1/4] incubator-mynewt-site git commit: File system documentation.

Repository: incubator-mynewt-site
Updated Branches:
  refs/heads/master fbf4af7a9 -> 1c504eb43


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/nffs/nffs_internals.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/nffs/nffs_internals.md b/docs/os/modules/fs/nffs/nffs_internals.md
new file mode 100644
index 0000000..bc0d797
--- /dev/null
+++ b/docs/os/modules/fs/nffs/nffs_internals.md
@@ -0,0 +1,318 @@
+# Internals of nffs
+### Disk structure
+On disk, each area is prefixed with the following header:
+
+```no-highlight
+/** On-disk representation of an area header. */
+struct nffs_disk_area {
+    uint32_t nda_magic[4];  /* NFFS_AREA_MAGIC{0,1,2,3} */
+    uint32_t nda_length;    /* Total size of area, in bytes. */
+    uint8_t nda_ver;        /* Current nffs version: 0 */
+    uint8_t nda_gc_seq;     /* Garbage collection count. */
+    uint8_t reserved8;
+    uint8_t nda_id;         /* 0xff if scratch area. */
+};
+```
+
+Beyond its header, an area contains a sequence of disk objects, representing the contents of the file system.  There are two types of objects: *inodes* and *data blocks*.  An inode represents a file or directory; a data block represents part of a file's contents.
+
+```no-highlight
+/** On-disk representation of an inode (file or directory). */
+struct nffs_disk_inode {
+    uint32_t ndi_magic;         /* NFFS_INODE_MAGIC */
+    uint32_t ndi_id;            /* Unique object ID. */
+    uint32_t ndi_seq;           /* Sequence number; greater supersedes
+                                   lesser. */
+    uint32_t ndi_parent_id;     /* Object ID of parent directory inode. */
+    uint8_t reserved8;
+    uint8_t ndi_filename_len;   /* Length of filename, in bytes. */
+    uint16_t ndi_crc16;         /* Covers rest of header and filename. */
+    /* Followed by filename. */
+};
+```
+
+An inode filename's length cannot exceed 256 bytes.  The filename is not null-terminated.  The following ASCII characters are not allowed in a filename:
+
+* /  (slash character)
+* \0 (NUL character)
+
+```no-highlight
+/** On-disk representation of a data block. */
+struct nffs_disk_block {
+    uint32_t ndb_magic;     /* NFFS_BLOCK_MAGIC */
+    uint32_t ndb_id;        /* Unique object ID. */
+    uint32_t ndb_seq;       /* Sequence number; greater supersedes lesser. */
+    uint32_t ndb_inode_id;  /* Object ID of owning inode. */
+    uint32_t ndb_prev_id;   /* Object ID of previous block in file;
+                               NFFS_ID_NONE if this is the first block. */
+    uint16_t ndb_data_len;  /* Length of data contents, in bytes. */
+    uint16_t ndb_crc16;     /* Covers rest of header and data. */
+    /* Followed by 'ndb_data_len' bytes of data. */
+};
+```
+
+Each data block contains the ID of the previous data block in the file.  Together, the set of blocks in a file form a reverse singly-linked list.
+
+The maximum number of data bytes that a block can contain is determined at initialization-time.  The result is the greatest number which satisfies all of the following restrictions:
+
+* No more than 2048.
+* At least two maximum-sized blocks can fit in the smallest area.
+
+The 2048 number was chosen somewhat arbitrarily, and may change in the future.
+
+### ID space
+
+All disk objects have a unique 32-bit ID.  The ID space is partitioned as
+follows:
+
+| ID range                          | Node type                 |
+|-----------------------------------|---------------------------|
+| 0x00000000 - 0x0fffffff           | Directory inodes          |
+| 0x10000000 - 0x7fffffff           | File inodes               |
+| 0x80000000 - 0xfffffffe           | Data blocks               |
+| 0xffffffff                        | Reserved (NFFS_ID_NONE)   |
+
+### Scratch area
+
+A valid nffs file system must contain a single "scratch area."  The scratch area does not contain any objects of its own, and is only used during garbage collection.  The scratch area must have a size greater than or equal to each of the other areas in flash.
+
+### RAM representation 
+
+Every object in the file system is stored in a 256-entry hash table.  An object's hash key is derived from its 32-bit ID.  Each list in the hash table is sorted by time of use; most-recently-used is at the front of the list. All objects are represented by the following structure:
+
+```no-highlight
+/**
+ * What gets stored in the hash table.  Each entry represents a data block or
+ * an inode.
+ */
+struct nffs_hash_entry {
+    SLIST_ENTRY(nffs_hash_entry) nhe_next;
+    uint32_t nhe_id;        /* 0 - 0x7fffffff if inode; else if block. */
+    uint32_t nhe_flash_loc; /* Upper-byte = area idx; rest = area offset. */
+};
+```
+
+For each data block, the above structure is all that is stored in RAM.  To acquire more information about a data block, the block header must be read from flash.
+
+Inodes require a fuller RAM representation to capture the structure of the file system.  There are two types of inodes: *files* and *directories*.  Each inode hash entry is actually an instance of the following structure:
+
+```no-highlight
+/** Each inode hash entry is actually one of these. */
+struct nffs_inode_entry {
+    struct nffs_hash_entry nie_hash_entry;
+    SLIST_ENTRY(nffs_inode_entry) nie_sibling_next;
+    union {
+        struct nffs_inode_list nie_child_list;           /* If directory */
+        struct nffs_hash_entry *nie_last_block_entry;    /* If file */
+    };
+    uint8_t nie_refcnt;
+};
+```
+
+A directory inode contains a list of its child files and directories (*fie\_child\_list*).  These entries are sorted alphabetically using the ASCII character set.
+
+A file inode contains a pointer to the last data block in the file (*nie\_last\_block\_entry*).  For most file operations, the reversed block list must be walked backwards.  This introduces a number of speed inefficiencies:
+
+* All data blocks must be read to determine the length of the file.
+* Data blocks often need to be processed sequentially.  The reversed nature of the block list transforms this from linear time to an O(n^2) operation.
+
+Furthermore, obtaining information about any constituent data block requires a separate flash read.
+
+### Inode cache and Data Block cache
+
+The speed issues are addressed by a pair of caches.  Cached inodes entries contain the file length and a much more convenient doubly-linked list of cached data blocks.  The benefit of using caches is that the size of the caches need not be proportional to the size of the file system.  In other words, caches can address speed efficiency concerns without negatively impacting the file system's scalability.
+
+nffs requires both caches during normal operation, so it is not possible to disable them.  However, the cache sizes are configurable, and both caches can be configured with a size of one if RAM usage must be minimized.
+
+The following data structures are used in the inode and data block caches.
+
+```no-highlight
+/** Full data block representation; not stored permanently in RAM. */
+struct nffs_block {
+    struct nffs_hash_entry *nb_hash_entry;   /* Points to real block entry. */
+    uint32_t nb_seq;                         /* Sequence number; greater
+                                                supersedes lesser. */
+    struct nffs_inode_entry *nb_inode_entry; /* Owning inode. */
+    struct nffs_hash_entry *nb_prev;         /* Previous block in file. */
+    uint16_t nb_data_len;                    /* # of data bytes in block. */
+    uint16_t reserved16;
+};
+```
+
+```no-highlight
+/** Represents a single cached data block. */
+struct nffs_cache_block {
+    TAILQ_ENTRY(nffs_cache_block) ncb_link; /* Next / prev cached block. */
+    struct nffs_block ncb_block;            /* Full data block. */
+    uint32_t ncb_file_offset;               /* File offset of this block. */
+};
+```
+
+```no-highlight
+/** Full inode representation; not stored permanently in RAM. */
+struct nffs_inode {
+    struct nffs_inode_entry *ni_inode_entry; /* Points to real inode entry. */
+    uint32_t ni_seq;                         /* Sequence number; greater
+                                                supersedes lesser. */
+    struct nffs_inode_entry *ni_parent;      /* Points to parent directory. */
+    uint8_t ni_filename_len;                 /* # chars in filename. */
+    uint8_t ni_filename[NFFS_SHORT_FILENAME_LEN]; /* First 3 bytes. */
+};
+```
+
+```no-highlight
+/** Doubly-linked tail queue of cached blocks; contained in cached inodes. */
+TAILQ_HEAD(nffs_block_cache_list, nffs_block_cache_entry);
+
+/** Represents a single cached file inode. */
+struct nffs_cache_inode {
+    TAILQ_ENTRY(nffs_cache_inode) nci_link;        /* Sorted; LRU at tail. */
+    struct nffs_inode nci_inode;                   /* Full inode. */
+    struct nffs_cache_block_list nci_block_list;   /* List of cached blocks. */
+    uint32_t nci_file_size;                        /* Total file size. */
+};
+```
+
+Only file inodes are cached; directory inodes are never cached.
+
+Within a cached inode, all cached data blocks are contiguous.  E.g., if the start and end of a file are cached, then the middle must also be cached.  A data block is only cached if its owning file is also cached.
+
+Internally, cached inodes are stored in a singly-linked list, ordered by time of use.  The most-recently-used entry is the first element in the list.  If a new inode needs to be cached, but the inode cache is full, the least-recently-used entry is freed to make room for the new one.  The following operations cause an inode to be cached:
+
+* Querying a file's length.
+* Seeking within a file.
+* Reading from a file.
+* Writing to a file.
+
+The following operations cause a data block to be cached:
+
+* Reading from the block.
+* Writing to the block.
+
+If one of the above operations is applied to a data block that is not currently cached, nffs uses the following procedure to cache the necessary block:
+
+1. If none of the owning inode's blocks are currently cached, allocate a cached block entry corresponding to the requested block and insert it into the inode's list.
+2. Else if the requested file offset is less than that of the first cached block, bridge the gap between the inode's sequence of cached blocks and the block that now needs to be cached.  This is accomplished by caching each block in the gap, finishing with the requested block.
+3. Else (the requested offset is beyond the end of the cache),
+    1. If the requested offset belongs to the block that immediately follows the end of the cache, cache the block and append it to the list.
+    2. Else, clear the cache, and populate it with the single entry corresponding to the requested block.
+ 
+If the system is unable to allocate a cached block entry at any point during the above procedure, the system frees up other blocks currently in the cache. This is accomplished as follows:
+
+* Iterate the inode cache in reverse (i.e., start with the least-recently-used entry).  For each entry:
+    1. If the entry's cached block list is empty, advance to the next entry.
+    2. Else, free all the cached blocks in the entry's list.
+
+Because the system imposes a minimum block cache size of one, the above procedure will always reclaim at least one cache block entry.  The above procedure may result in the freeing of the block list that belongs to the very inode being operated on.  This is OK, as the final block to get cached is always the block being requested.
+
+# Detection
+
+The file system detection process consists of scanning a specified set of flash regions for valid nffs areas, and then populating the RAM representation of the file system with the detected objects.  Detection is initiated with the [nffs_detect()](nffs_detect.md) function.
+
+Not every area descriptor passed to `nffs_detect()` needs to reference a valid nffs area.  Detection is successful as long as a complete file system is detected somewhere in the specified regions of flash.  If an application is unsure where a file system might be located, it can initiate detection across the entire flash region.
+
+A detected file system is valid if:
+
+1. At least one non-scratch area is present.
+2. At least one scratch area is present (only the first gets used if there is more than one).
+3. The root directory inode is present.
+
+During detection, each indicated region of flash is checked for a valid area header.  The contents of each valid non-scratch area are then restored into the nffs RAM representation.  The following procedure is applied to each object in the area:
+
+1. Verify the object's integrity via a crc16 check.  If invalid, the object is discarded and the procedure restarts on the next object in the area.
+2. Convert the disk object into its corresponding RAM representation and insert it into the hash table.  If the object is an inode, its reference count is initialized to 1, indicating ownership by its parent directory.
+3. If an object with the same ID is already present, then one supersedes the other.  Accept the object with the greater sequence number and discard the other.
+4. If the object references a nonexistant inode (parent directory in the case of an inode; owning file in the case of a data block), insert a temporary "dummy" inode into the hash table so that inter-object links can be maintained until the absent inode is eventually restored.  Dummy inodes are identified by a reference count of 0.
+5. If a delete record for an inode is encountered, the inode's parent pointer is set to null to indicate that it should be removed from RAM.
+
+If nffs encounters an object that cannot be identified (i.e., its magic number is not valid), it scans the remainder of the flash area for the next valid magic number.  Upon encountering a valid object, nffs resumes the procedure described above.
+
+After all areas have been restored, a sweep is performed across the entire RAM representation so that invalid inodes can be deleted from memory.
+
+For each directory inode:
+
+* If its reference count is 0 (i.e., it is a dummy), migrate its children to the */lost+found* directory, and delete it from the RAM representation. This should only happen in the case of file system corruption.
+* If its parent reference is null (i.e., it was deleted), delete it and all its children from the RAM representation.
+
+For each file inode:
+
+* If its reference count is 0 (i.e., it is a dummy), delete it from the RAM representation.  This should only happen in the case of file system corruption.  (We should try to migrate the file to the lost+found directory in this case, as mentioned in the todo section).
+
+When an object is deleted during this sweep, it is only deleted from the RAM representation; nothing is written to disk.
+
+When objects are migrated to the lost+found directory, their parent inode reference is permanently updated on the disk.
+
+In addition, a single scratch area is identified during the detection process.  The first area whose *fda\_id* value is set to 0xff is designated as the file system scratch area.  If no valid scratch area is found, the cause could be that the system was restarted while a garbage collection cycle was in progress.  Such a condition is identified by the presence of two areas with the same ID.  In such a case, the shorter of the two areas is erased and designated as the scratch area.
+
+# Formatting
+
+A new nffs file system is created via formatting.  Formatting is achieved via the [nffs\_format()](nffs_format.md) function.
+
+During a successful format, an area header is written to each of the specified locations.  One of the areas in the set is designated as the initial scratch area.
+
+# Flash writes
+
+The nffs implementation always writes in a strictly sequential fashion within an area.  For each area, the system keeps track of the current offset.  Whenever an object gets written to an area, it gets written to that area's current offset, and the offset is increased by the object's disk size.
+
+When a write needs to be performed, the nffs implementation selects the appropriate destination area by iterating though each area until one with sufficient free space is encountered.
+
+There is no write buffering.  Each call to a write function results in a write operation being sent to the flash hardware.
+
+### New objects
+
+Whenever a new object is written to disk, it is assigned the following properties:
+
+* *ID:* A unique value is selected from the 32-bit ID space, as appropriate for the object's type.
+* *Sequence number:* 0
+
+When a new file or directory is created, a corresponding inode is written to flash.  Likewise, a new data block also results in the writing of a corresponding disk object.
+
+### Moving/Renaming files and directories 
+
+When a file or directory is moved or renamed, its corresponding inode is rewritten to flash with the following properties:
+
+* *ID:* Unchanged
+* *Sequence number:* Previous value plus one.
+* *Parent inode:* As specified by the move / rename operation.
+* *Filename:* As specified by the move / rename operation.
+
+Because the inode's ID is unchanged, all dependent objects remain valid.
+
+### Unlinking files and directories
+
+When a file or directory is unlinked from its parent directory, a deletion record for the unlinked inode gets written to flash.  The deletion record is an inode with the following properties:
+
+* *ID:* Unchanged
+* *Sequence number:* Previous value plus one.
+* *Parent inode ID:* NFFS\_ID\_NONE
+
+When an inode is unlinked, no deletion records need to be written for the inode's dependent objects (constituent data blocks or child inodes).  During the next file system detection, it is recognized that the objects belong to a deleted inode, so they are not restored into the RAM representation.
+
+If a file has an open handle at the time it gets unlinked, application code can continued to use the file handle to read and write data.  All files retain a reference count, and a file isn't deleted from the RAM representation until its reference code drops to 0.  Any attempt to open an unlinked file fails, even if the file is referenced by other file handles.
+
+### Writing to a file
+
+The following procedure is used whenever the application code writes to a file.  First, if the write operation specifies too much data to fit into a single block, the operation is split into several separate write operations.  Then, for each write operation:
+
+1. Determine which existing blocks the write operation overlaps (n = number of overwritten blocks).
+2. If *n = 0*, this is an append operation.  Write a data block with the following properties:
+    * *ID:* New unique value.
+    * *Sequence number:* 0.
+3. Else *(n > 1)*, this write overlaps existing data.
+    1. For each block in *[1, 2, ... n-1]*, write a new block containing the updated contents.  Each new block supersedes the block it overwrites.  That is, each block has the following properties:
+        * *ID:* Unchanged
+        * *Sequence number:* Previous value plus one.
+    2. Write the nth block.  The nth block includes all appended data, if any.  As with the other blocks, its ID is unchanged and its sequence number is incremented.
+
+Appended data can only be written to the end of the file.  That is, "holes" are not supported.
+
+# Garbage collection
+
+When the file system is too full to accomodate a write operation, the system must perform garbage collection to make room.  The garbage collection procedure is described below:
+
+* The non-scratch area with the lowest garbage collection sequence number is selected as the "source area."  If there are other areas with the same sequence number, the one with the smallest flash offset is selected. 
+* The source area's ID is written to the scratch area's header, transforming it into a non-scratch ID.  This former scratch area is now known as the "destination area."
+* The RAM representation is exhaustively searched for collectible objects.  The following procedure is applied to each inode in the system:
+    * If the inode is resident in the source area, copy the inode record to the destination area.
+    * If the inode is a file inode, walk the inode's list of data blocks, starting with the last block in the file.  Each block that is resident in the source area is copied to the destination area.  If there is a run of two or more blocks that are resident in the source area, they are consolidated and copied to the destination area as a single new block (subject to the maximum block size restriction).
+* The source area is reformatted as a scratch sector (i.e., is is fully erased, and its header is rewritten with an ID of 0xff).  The area's garbage collection sequence number is incremented prior to rewriting the header.  This area is now the new scratch sector.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/otherfs.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/otherfs.md b/docs/os/modules/fs/otherfs.md
new file mode 100644
index 0000000..fe82b3a
--- /dev/null
+++ b/docs/os/modules/fs/otherfs.md
@@ -0,0 +1,63 @@
+# Other File Systems
+
+Libraries use Mynewt's file system abstraction layer (`fs/fs`) for all file operations.  Because clients use an abstraction layer, the underlying file system can be swapped out without affecting client code.  This page documents the procedure for plugging a custom file system into the Mynewt file system abstraction layer.
+
+### 1. Specify `fs/fs` as a dependency of your file system package.
+
+The file system package must register itself with the `fs/fs` package, so it must specify `fs/fs` as a dependency.  As an example, part of the Newtron Flash File System (nffs) `pkg.yml` is reproduced below.   Notice the first item in the `pkg.deps` list.
+
+```no-highlight
+pkg.name: fs/nffs
+pkg.deps:
+    - fs/fs
+    - hw/hal
+    - libs/os
+    - libs/testutil
+    - sys/log
+```
+
+### 2. Register your package's API with the `fs/fs` interface.
+
+The `fs/fs` package calls into the underlying file system via a collection of function pointers.  To plug your file system into the `fs/fs` API, you must assign these function pointers to the corresponding routines in your file system package.
+
+For example, `nffs` registers itself with `fs/fs` as follows (from `fs/nffs/src/nffs.c`):
+
+```no-highlight
+static const struct fs_ops nffs_ops = {
+    .f_open = nffs_open,
+    .f_close = nffs_close,
+    .f_read = nffs_read,
+    .f_write = nffs_write,
+
+    .f_seek = nffs_seek,
+    .f_getpos = nffs_getpos,
+    .f_filelen = nffs_file_len,
+
+    .f_unlink = nffs_unlink,
+    .f_rename = nffs_rename,
+    .f_mkdir = nffs_mkdir,
+
+    .f_opendir = nffs_opendir,
+    .f_readdir = nffs_readdir,
+    .f_closedir = nffs_closedir,
+
+    .f_dirent_name = nffs_dirent_name,
+    .f_dirent_is_dir = nffs_dirent_is_dir,
+
+    .f_name = "nffs"
+};
+
+int
+nffs_init(void)
+{
+    /* [...] */
+    fs_register(&nffs_ops);
+}
+```
+
+## Header Files 
+To gain access to `fs/fs`'s registration interface, include the following header:
+
+```no-highlight
+#include "fs/fs_if.h"
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/nffs.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/nffs.md b/docs/os/modules/nffs.md
deleted file mode 100644
index 97ff43d..0000000
--- a/docs/os/modules/nffs.md
+++ /dev/null
@@ -1,564 +0,0 @@
-# Newtron Flash Filesystem (nffs)
-
-Mynewt comes with the flash file system called the Newtron Flash File System (nffs) which is designed with two priorities that makes it suitable for embedded use: 
-
-* Minimal RAM usage
-* Reliability
-
-Mynewt also provides an abstraction layer API (fs) to allow you to swap out nffs with a different file system of your choice.
-
-## Description
-
-Describe module here, special features, how pieces fit together etc.
-
-## Disk and data structures
-
-At the top level, an nffs disk is partitioned into areas.  An area is a region
-of disk with the following properties:
-
-1. An area can be fully erased without affecting any other areas.
-2. A write to one area does not restrict writes to other areas.
-
-   **Note**: Some flash hardware divides its memory space into "blocks."  Writes within a block must be sequential, but writes to one block have no effect on what parts of other blocks can be written.  Thus, for flash hardware with such a restriction, each area must comprise a discrete number of blocks.
-
-While not strictly necessary, it is recommended that all areas have the same
-size.
-
-On disk, each area is prefixed with the following header:
-
-```no-highlight
-/** On-disk representation of an area header. */
-struct nffs_disk_area {
-    uint32_t nda_magic[4];  /* NFFS_AREA_MAGIC{0,1,2,3} */
-    uint32_t nda_length;    /* Total size of area, in bytes. */
-    uint8_t nda_ver;        /* Current nffs version: 0 */
-    uint8_t nda_gc_seq;     /* Garbage collection count. */
-    uint8_t reserved8;
-    uint8_t nda_id;         /* 0xff if scratch area. */
-};
-```
-
-Beyond its header, an area contains a sequence of disk objects, representing
-the contents of the file system.  There are two types of objects: **inodes** and
-**data blocks**.  An inode represents a file or directory; a data block represents
-part of a file's contents.
-
-```no-highlight
-/** On-disk representation of an inode (file or directory). */
-struct nffs_disk_inode {
-    uint32_t ndi_magic;         /* NFFS_INODE_MAGIC */
-    uint32_t ndi_id;            /* Unique object ID. */
-    uint32_t ndi_seq;           /* Sequence number; greater supersedes
-                                   lesser. */
-    uint32_t ndi_parent_id;     /* Object ID of parent directory inode. */
-    uint8_t reserved8;
-    uint8_t ndi_filename_len;   /* Length of filename, in bytes. */
-    uint16_t ndi_crc16;         /* Covers rest of header and filename. */
-    /* Followed by filename. */
-};
-```
-
-An inode filename's length cannot exceed 256 bytes.  The filename is not
-null-terminated.  The following ASCII characters are not allowed in a
-filename:
-    * /  (slash character)
-    * \0 (NUL character)
-
-```no-highlight
-/** On-disk representation of a data block. */
-struct nffs_disk_block {
-    uint32_t ndb_magic;     /* NFFS_BLOCK_MAGIC */
-    uint32_t ndb_id;        /* Unique object ID. */
-    uint32_t ndb_seq;       /* Sequence number; greater supersedes lesser. */
-    uint32_t ndb_inode_id;  /* Object ID of owning inode. */
-    uint32_t ndb_prev_id;   /* Object ID of previous block in file;
-                               NFFS_ID_NONE if this is the first block. */
-    uint16_t ndb_data_len;  /* Length of data contents, in bytes. */
-    uint16_t ndb_crc16;     /* Covers rest of header and data. */
-    /* Followed by 'ndb_data_len' bytes of data. */
-};
-```
-
-Each data block contains the ID of the previous data block in the file.
-Together, the set of blocks in a file form a reverse singly-linked list.
-
-The maximum number of data bytes that a block can contain is determined at
-initialization-time.  The result is the greatest number which satisfies all of
-the following restrictions:
-    o No more than 2048.
-    o At least two maximum-sized blocks can fit in the smallest area.
-
-The 2048 number was chosen somewhat arbitrarily, and may change in the future.
-
-### ID space
-
-All disk objects have a unique 32-bit ID.  The ID space is partitioned as
-follows:
-      * 0x00000000 - 0x0fffffff: Directory inodes.
-      * 0x10000000 - 0x7fffffff: File inodes.
-      * 0x80000000 - 0xfffffffe: Data blocks.
-      * 0xffffffff             : Reserved (NFFS_ID_NONE)
-
-### Scratch area
-
-A valid nffs file system must contain a single "scratch area."  The scratch
-area does not contain any objects of its own, and is only used during garbage
-collection.  The scratch area must have a size greater than or equal to each
-of the other areas in flash.
-
-
-### RAM representation 
-
-Every object in the file system is stored in a 256-entry hash table.  An
-object's hash key is derived from its 32-bit ID.  Each list in the hash table
-is sorted by time of use; most-recently-used is at the front of the list. All
-objects are represented by the following structure:
-
-```no-highlight
-/**
- * What gets stored in the hash table.  Each entry represents a data block or
- * an inode.
- */
-struct nffs_hash_entry {
-    SLIST_ENTRY(nffs_hash_entry) nhe_next;
-    uint32_t nhe_id;        /* 0 - 0x7fffffff if inode; else if block. */
-    uint32_t nhe_flash_loc; /* Upper-byte = area idx; rest = area offset. */
-};
-```
-
-For each data block, the above structure is all that is stored in RAM.  To
-acquire more information about a data block, the block header must be read
-from flash.
-
-Inodes require a fuller RAM representation to capture the structure of the
-file system.  There are two types of inodes: **files** and **directories**.  Each
-inode hash entry is actually an instance of the following structure:
-
-```no-highlight
-/** Each inode hash entry is actually one of these. */
-struct nffs_inode_entry {
-    struct nffs_hash_entry nie_hash_entry;
-    SLIST_ENTRY(nffs_inode_entry) nie_sibling_next;
-    union {
-        struct nffs_inode_list nie_child_list;           /* If directory */
-        struct nffs_hash_entry *nie_last_block_entry;    /* If file */
-    };
-    uint8_t nie_refcnt;
-};
-```
-
-A directory inode contains a list of its child files and directories
-(fie_child_list).  These entries are sorted alphabetically using the ASCII
-character set.
-
-A file inode contains a pointer to the last data block in the file
-(nie_last_block_entry).  For most file operations, the reversed block list must
-be walked backwards.  This introduces a number of speed inefficiencies:
-    * All data blocks must be read to determine the length of the file.
-    * Data blocks often need to be processed sequentially.  The reversed
-      nature of the block list transforms this from linear time to an O(n^2)
-      operation.
-
-Furthermore, obtaining information about any constituent data block requires a
-separate flash read.
-
-### Inode cache and Data Block cache
-
-The speed issues are addressed by a pair of caches.  Cached inodes entries
-contain the file length and a much more convenient doubly-linked list of
-cached data blocks.  The benefit of using caches is that the size of the
-caches need not be proportional to the size of the file system.  In other
-words, caches can address speed efficiency concerns without negatively
-impacting the file system's scalability.
-
-nffs requires both caches during normal operation, so it is not possible to
-disable them.  However, the cache sizes are configurable, and both caches can
-be configured with a size of one if RAM usage must be minimized.
-
-The following data structures are used in the inode and data block caches.
-
-```no-highlight
-/** Full data block representation; not stored permanently in RAM. */
-struct nffs_block {
-    struct nffs_hash_entry *nb_hash_entry;   /* Points to real block entry. */
-    uint32_t nb_seq;                         /* Sequence number; greater
-                                                supersedes lesser. */
-    struct nffs_inode_entry *nb_inode_entry; /* Owning inode. */
-    struct nffs_hash_entry *nb_prev;         /* Previous block in file. */
-    uint16_t nb_data_len;                    /* # of data bytes in block. */
-    uint16_t reserved16;
-};
-
-/** Represents a single cached data block. */
-struct nffs_cache_block {
-    TAILQ_ENTRY(nffs_cache_block) ncb_link; /* Next / prev cached block. */
-    struct nffs_block ncb_block;            /* Full data block. */
-    uint32_t ncb_file_offset;               /* File offset of this block. */
-};
-
-/** Full inode representation; not stored permanently in RAM. */
-struct nffs_inode {
-    struct nffs_inode_entry *ni_inode_entry; /* Points to real inode entry. */
-    uint32_t ni_seq;                         /* Sequence number; greater
-                                                supersedes lesser. */
-    struct nffs_inode_entry *ni_parent;      /* Points to parent directory. */
-    uint8_t ni_filename_len;                 /* # chars in filename. */
-    uint8_t ni_filename[NFFS_SHORT_FILENAME_LEN]; /* First 3 bytes. */
-};
-
-/** Doubly-linked tail queue of cached blocks; contained in cached inodes. */
-TAILQ_HEAD(nffs_block_cache_list, nffs_block_cache_entry);
-
-/** Represents a single cached file inode. */
-struct nffs_cache_inode {
-    TAILQ_ENTRY(nffs_cache_inode) nci_link;        /* Sorted; LRU at tail. */
-    struct nffs_inode nci_inode;                   /* Full inode. */
-    struct nffs_cache_block_list nci_block_list;   /* List of cached blocks. */
-    uint32_t nci_file_size;                        /* Total file size. */
-};
-```
-
-Only file inodes are cached; directory inodes are never cached.
-
-Within a cached inode, all cached data blocks are contiguous.  E.g., if the
-start and end of a file are cached, then the middle must also be cached.  A
-data block is only cached if its owning file is also cached.
-
-Internally, cached inodes are stored in a singly-linked list, ordered by time
-of use.  The most-recently-used entry is the first element in the list.  If a
-new inode needs to be cached, but the inode cache is full, the
-least-recently-used entry is freed to make room for the new one.  The
-following operations cause an inode to be cached:
-
-* Querying a file's length.
-* Seeking within a file.
-* Reading from a file.
-* Writing to a file.
-
-The following operations cause a data block to be cached:
-
-* Reading from the block.
-* Writing to the block.
-
-If one of the above operations is applied to a data block that is not currently
-cached, nffs uses the following procedure to cache the necessary block:
-
-1. If none of the owning inode's blocks are currently cached, allocate a
-       cached block entry corresponding to the requested block and insert it
-       into the inode's list.
-2. Else if the requested file offset is less than that of the first cached
-       block, bridge the gap between the inode's sequence of cached blocks and
-       the block that now needs to be cached.  This is accomplished by caching
-       each block in the gap, finishing with the requested block.
-3. Else (the requested offset is beyond the end of the cache),
-   a. If the requested offset belongs to the block that immediately follows the end of the cache, cache the block and append it to the list.
-   b. Else, clear the cache, and populate it with the single entry corresponding to the requested block.
-
-If the system is unable to allocate a cached block entry at any point during
-the above procedure, the system frees up other blocks currently in the cache. This is accomplished as follows:
-
-* Iterate the inode cache in reverse (i.e., start with the least-recently-used entry).  For each entry:
-   a. If the entry's cached block list is empty, advance to the next entry.
-   b. Else, free all the cached blocks in the entry's list.
-
-Because the system imposes a minimum block cache size of one, the above
-procedure will always reclaim at least one cache block entry.  The above
-procedure may result in the freeing of the block list that belongs to the very
-inode being operated on.  This is OK, as the final block to get cached is
-always the block being requested.
-
-
-## Configuration
-
-The file system is configured by populating fields in a global structure.
-Each field in the structure corresponds to a setting.  All configuration must
-be done prior to calling nffs_init().  The configuration structure is defined
-as follows:
-
-```no-highlight
-
-struct nffs_config {
-    /** Maximum number of inodes; default=1024. */
-    uint32_t nc_num_inodes;
-
-    /** Maximum number of data blocks; default=4096. */
-    uint32_t nc_num_blocks;
-
-    /** Maximum number of open files; default=4. */
-    uint32_t nc_num_files;
-
-    /** Inode cache size; default=4. */
-    uint32_t nc_num_cache_inodes;
-
-    /** Data block cache size; default=64. */
-    uint32_t nc_num_cache_blocks;
-    };
-
-extern struct nffs_config nffs_config;
-```
-
-Any fields that are set to 0 (or not set at all) inherit the corresponding
-default value.  This means that it is impossible to configure any setting with
-a value of zero.
-
-
-## Initialization
-
-There are two means of initializing an nffs file system:
-
-1. Restore an existing file system via detection.
-2. Create a new file system via formatting.
-
-Both methods require the user to describe how the flash memory is divided into
-areas.  This is accomplished with an array of struct nffs_area_desc, defined as
-follows:
-
-```no-highlight
-struct nffs_area_desc {
-    uint32_t nad_offset;    /* Flash offset of start of area. */
-    uint32_t nad_length;    /* Size of area, in bytes. */
-};
-```
-
-An array of area descriptors is terminated by an entry with a fad_length field
-of 0.
-
-One common initialization sequence is the following:
-
-1. Detect an nffs file system anywhere in flash.
-2. If no file system detected, format a new file system in a specific
-        region of flash.
-
-
-## Detection
-
-The file system detection process consists of scanning a specified set of
-flash regions for valid nffs areas, and then populating the RAM representation
-of the file system with the detected objects.  Detection is initiated with the
-following function:
-
-```no-highlight
-/**
- * Searches for a valid nffs file system among the specified areas.  This
- * function succeeds if a file system is detected among any subset of the
- * supplied areas.  If the area set does not contain a valid file system,
- * a new one can be created via a separate call to nffs_format().
- *
- * @param area_descs        The area set to search.  This array must be
- *                              terminated with a 0-length area.
- *
- * @return                  0 on success;
- *                          NFFS_ECORRUPT if no valid file system was detected;
- *                          other nonzero on error.
- */
-int nffs_detect(const struct nffs_area_desc *area_descs);
-```
-As indicated, not every area descriptor needs to reference a valid nffs area.
-Detection is successful as long as a complete file system is detected
-somewhere in the specified regions of flash.  If an application is unsure
-where a file system might be located, it can initiate detection across the
-entire flash region.
-
-A detected file system is valid if:
-
-1. At least one non-scratch area is present.
-2. At least one scratch area is present (only the first gets used if there is more than one).
-3. The root directory inode is present.
-
-During detection, each indicated region of flash is checked for a valid area
-header.  The contents of each valid non-scratch area are then restored into
-the nffs RAM representation.  The following procedure is applied to each object
-in the area:
-
-1. Verify the object's integrity via a crc16 check.  If invalid, the object is discarded and the procedure restarts on the next object in the area.
-
-2. Convert the disk object into its corresponding RAM representation and insert it into the hash table.  If the object is an inode, its reference count is initialized to 1, indicating ownership by its parent directory.
-
-3. If an object with the same ID is already present, then one supersedes the other.  Accept the object with the greater sequence number and discard the other.
-
-4. If the object references a nonexistant inode (parent directory in the case of an inode; owning file in the case of a data block), insert a temporary "dummy" inode into the hash table so that inter-object links can be maintained until the absent inode is eventually restored.  Dummy inodes are identified by a reference count of 0.
-
-5. If a delete record for an inode is encountered, the inode's parent pointer is set to null to indicate that it should be removed from RAM.
-
-If nffs encounters an object that cannot be identified (i.e., its magic number
-is not valid), it scans the remainder of the flash area for the next valid
-magic number.  Upon encountering a valid object, nffs resumes the procedure
-described above.
-
-After all areas have been restored, a sweep is performed across the entire RAM
-representation so that invalid inodes can be deleted from memory.
-
-For each directory inode:
-
-* If its reference count is 0 (i.e., it is a dummy), migrate its children to the /lost+found directory, and delete it from the RAM representation. This should only happen in the case of file system corruption.
- * If its parent reference is null (i.e., it was deleted), delete it and all its children from the RAM representation.
-
-For each file inode:
-
-* If its reference count is 0 (i.e., it is a dummy), delete it from the RAM representation.  This should only happen in the case of file system corruption.  (We should try to migrate the file to the lost+found directory in this case, as mentioned in the todo section).
-
-When an object is deleted during this sweep, it is only deleted from the RAM
-representation; nothing is written to disk.
-
-When objects are migrated to the lost+found directory, their parent inode
-reference is permanently updated on the disk.
-
-In addition, a single scratch area is identified during the detection process.
-The first area whose 'fda_id' value is set to 0xff is designated as the file
-system scratch area.  If no valid scratch area is found, the cause could be
-that the system was restarted while a garbage collection cycle was in progress.
-Such a condition is identified by the presence of two areas with the same ID.
-In such a case, the shorter of the two areas is erased and designated as the
-scratch area.
-
-
-## Formatting
-
-A new file system is created via formatting.  Formatting is achieved via the
-following function:
-
-```no-highlight
-/**
- * Erases all the specified areas and initializes them with a clean nffs
- * file system.
- *
- * @param area_descs        The set of areas to format.
- *
- * @return                  0 on success;
- *                          nonzero on failure.
- */
-int nffs_format(const struct nffs_area_desc *area_descs);
-```
-
-On success, an area header is written to each of the specified locations.  The
-largest area in the set is designated as the initial scratch area.
-
-
-## Flash writes
-
-The nffs implementation always writes in a strictly sequential fashion within an
-area.  For each area, the system keeps track of the current offset.  Whenever
-an object gets written to an area, it gets written to that area's current
-offset, and the offset is increased by the object's disk size.
-
-When a write needs to be performed, the nffs implementation selects the
-appropriate destination area by iterating though each area until one with
-sufficient free space is encountered.
-
-There is no write buffering.  Each call to a write function results in a write
-operation being sent to the flash hardware.
-
-
-### New objects
-
-Whenever a new object is written to disk, it is assigned the following
-properties:
-    * ID: A unique value is selected from the 32-bit ID space, as appropriate
-      for the object's type.
-    * Sequence number: 0
-
-When a new file or directory is created, a corresponding inode is written to
-flash.  Likewise, a new data block also results in the writing of a
-corresponding disk object.
-
-
-### Moving/Renaming files and directories 
-
-When a file or directory is moved or renamed, its corresponding inode is
-rewritten to flash with the following properties:
-
-* ID: Unchanged
-* Sequence number: Previous value plus one.
-* Parent inode: As specified by the move / rename operation.
-* Filename: As specified by the move / rename operation.
-
-Because the inode's ID is unchanged, all dependent objects remain valid.
-
-
-### Unlinking files and directories
-
-When a file or directory is unlinked from its parent directory, a deletion
-record for the unlinked inode gets written to flash.  The deletion record is an
-inode with the following properties:
-
-* ID: Unchanged
-* Sequence number: Previous value plus one.
-* Parent inode ID: NFFS_ID_NONE
-
-When an inode is unlinked, no deletion records need to be written for the
-inode's dependent objects (constituent data blocks or child inodes).  During
-the next file system detection, it is recognized that the objects belong to
-a deleted inode, so they are not restored into the RAM representation.
-
-If a file has an open handle at the time it gets unlinked, application code
-can continued to use the file handle to read and write data.  All files retain
-a reference count, and a file isn't deleted from the RAM representation until
-its reference code drops to 0.  Any attempt to open an unlinked file fails,
-even if the file is referenced by other file handles.
-
-
-### Writing to a file
-
-The following procedure is used whenever the application code writes to a file.
-First, if the write operation specifies too much data to fit into a single
-block, the operation is split into several separate write operations.  Then,
-for each write operation:
-
-1\. Determine which existing blocks the write operation overlaps (n = number of overwritten blocks).
-
-2\. If n = 0, this is an append operation.  Write a data block with the following properties:
-
-   * ID: New unique value.
-   * Sequence number: 0.
-
-3\. Else (n > 1), this write overlaps existing data.
-
-  (a) For each block in [1, 2, ... n-1], write a new block containing the updated contents.  Each new block supersedes the block it overwrites.  That is, each block has the following properties:
-   
-   * ID: Unchanged
-   * Sequence number: Previous value plus one.
-
-   (b) Write the nth block.  The nth block includes all appended data, if any.  As with the other blocks, its ID is unchanged and its sequence number is incremented.
-
-Appended data can only be written to the end of the file.  That is, "holes" are
-not supported.
-
-
-## Garbage collection
-
-When the file system is too full to accomodate a write operation, the system
-must perform garbage collection to make room.  The garbage collection
-procedure is described below:
-
-* The non-scratch area with the lowest garbage collection sequence number is selected as the "source area."  If there are other areas with the same sequence number, the one with the smallest flash offset is selected. 
-
-* The source area's ID is written to the scratch area's header, transforming it into a non-scratch ID.  This former scratch area is now known as the "destination area."
-
-* The RAM representation is exhaustively searched for collectible objects.  The following procedure is applied to each inode in the system:
-    * If the inode is resident in the source area, copy the inode record to the destination area.
-    * If the inode is a file inode, walk the inode's list of data blocks, starting with the last block in the file.  Each block that is resident in the source area is copied to the destination area.  If there is a run of two or more blocks that are resident in the source area, they are consolidated and copied to the destination area as a single new block (subject to the maximum block size restriction).
-
-* The source area is reformatted as a scratch sector (i.e., is is fully erased, and its header is rewritten with an ID of 0xff).  The area's garbage collection sequence number is incremented prior to rewriting the header.  This area is now the new scratch sector.
-
-
-## Miscellaneous measures
-
-* RAM usage:
-    * 24 bytes per inode
-    * 12 bytes per data block
-    * 36 bytes per inode cache entry
-    * 32 bytes per data block cache entry
-    
-* Maximum filename size: 256 characters (no null terminator required)
-* Disallowed filename characters: '/' and '\0'
-
-
-## Future enhancements
-
-* API function to traverse a directory.
-* Migrate corrupt files to the /lost+found directory during restore, rather than discarding them from RAM.
-* Error correction.
-* Encryption.
-* Compression.
-
-

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/mkdocs.yml
----------------------------------------------------------------------
diff --git a/mkdocs.yml b/mkdocs.yml
index 04e07c7..ec72d16 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -193,8 +193,42 @@ pages:
                 - 'boot_vect_read_one': 'os/modules/bootloader/boot_vect_read_one.md'
                 - 'boot_vect_read_test': 'os/modules/bootloader/boot_vect_read_test.md'
                 - 'boot_write_status': 'os/modules/bootloader/boot_write_status.md'
-        - 'File System Abstraction': 'os/modules/filesystem.md'
-        - 'Newtron Flash File System': 'os/modules/nffs.md'
+        - File System:
+            - 'File System Abstraction':
+                - 'Overview': 'os/modules/fs/fs/fs.md'
+                - 'Return Codes': 'os/modules/fs/fs/fs_return_codes.md'
+                - 'Data Structures':
+                    - 'struct fs_ops': 'os/modules/fs/fs/fs_ops.md'
+                - 'Functions':
+                    - 'fs_close': 'os/modules/fs/fs/fs_close.md'
+                    - 'fs_closedir': 'os/modules/fs/fs/fs_closedir.md'
+                    - 'fs_dirent_is_dir': 'os/modules/fs/fs/fs_dirent_is_dir.md'
+                    - 'fs_dirent_name': 'os/modules/fs/fs/fs_dirent_name.md'
+                    - 'fs_filelen': 'os/modules/fs/fs/fs_filelen.md'
+                    - 'fs_getpos': 'os/modules/fs/fs/fs_getpos.md'
+                    - 'fs_mkdir': 'os/modules/fs/fs/fs_mkdir.md'
+                    - 'fs_open': 'os/modules/fs/fs/fs_open.md'
+                    - 'fs_opendir': 'os/modules/fs/fs/fs_opendir.md'
+                    - 'fs_read': 'os/modules/fs/fs/fs_read.md'
+                    - 'fs_readdir': 'os/modules/fs/fs/fs_readdir.md'
+                    - 'fs_register': 'os/modules/fs/fs/fs_register.md'
+                    - 'fs_rename': 'os/modules/fs/fs/fs_rename.md'
+                    - 'fs_seek': 'os/modules/fs/fs/fs_seek.md'
+                    - 'fs_unlink': 'os/modules/fs/fs/fs_unlink.md'
+                    - 'fs_write': 'os/modules/fs/fs/fs_write.md'
+                    - 'fsutil_read_file': 'os/modules/fs/fs/fsutil_read_file.md'
+                    - 'fsutil_write_file': 'os/modules/fs/fs/fsutil_write_file.md'
+            - 'Newtron Flash File System':
+                - 'Overview':               'os/modules/fs/nffs/nffs.md'
+                - 'Data Structures':
+                    - 'struct nffs_area_desc': 'os/modules/fs/nffs/nffs_area_desc.md'
+                    - 'struct nffs_config': 'os/modules/fs/nffs/nffs_config.md'
+                - 'Functions':
+                    - 'nffs_detect': 'os/modules/fs/nffs/nffs_detect.md'
+                    - 'nffs_format': 'os/modules/fs/nffs/nffs_format.md'
+                    - 'nffs_init': 'os/modules/fs/nffs/nffs_init.md'
+                - 'Internals': 'os/modules/fs/nffs/nffs_internals.md'
+            - 'Other File Systems': 'os/modules/fs/otherfs.md'
         - Test Utilities:
             - 'Overview': 'os/modules/testutil/testutil.md'
             - 'Functions/Macros':


[4/4] incubator-mynewt-site git commit: File system documentation added. This closes #27.

Posted by ad...@apache.org.
File system documentation added. This closes #27.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/commit/1c504eb4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/tree/1c504eb4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/diff/1c504eb4

Branch: refs/heads/master
Commit: 1c504eb4385f96213d3e324e3ae19fad56ecfe8e
Parents: fbf4af7 2a19afb
Author: aditihilbert <ad...@runtime.io>
Authored: Fri Mar 4 00:39:56 2016 -0800
Committer: aditihilbert <ad...@runtime.io>
Committed: Fri Mar 4 00:39:56 2016 -0800

----------------------------------------------------------------------
 docs/os/modules/filesystem.md              | 750 ------------------------
 docs/os/modules/fs/fs/fs.md                | 108 ++++
 docs/os/modules/fs/fs/fs_close.md          |  61 ++
 docs/os/modules/fs/fs/fs_closedir.md       |  77 +++
 docs/os/modules/fs/fs/fs_dirent_is_dir.md  |  75 +++
 docs/os/modules/fs/fs/fs_dirent_name.md    |  83 +++
 docs/os/modules/fs/fs/fs_filelen.md        |  58 ++
 docs/os/modules/fs/fs/fs_getpos.md         |  27 +
 docs/os/modules/fs/fs/fs_mkdir.md          |  60 ++
 docs/os/modules/fs/fs/fs_open.md           |  78 +++
 docs/os/modules/fs/fs/fs_opendir.md        |  83 +++
 docs/os/modules/fs/fs/fs_ops.md            |  40 ++
 docs/os/modules/fs/fs/fs_read.md           |  61 ++
 docs/os/modules/fs/fs/fs_readdir.md        |  78 +++
 docs/os/modules/fs/fs/fs_register.md       |  28 +
 docs/os/modules/fs/fs/fs_rename.md         |  66 +++
 docs/os/modules/fs/fs/fs_return_codes.md   |  26 +
 docs/os/modules/fs/fs/fs_seek.md           |  62 ++
 docs/os/modules/fs/fs/fs_unlink.md         |  56 ++
 docs/os/modules/fs/fs/fs_write.md          |  61 ++
 docs/os/modules/fs/fs/fsutil_read_file.md  |  60 ++
 docs/os/modules/fs/fs/fsutil_write_file.md |  52 ++
 docs/os/modules/fs/nffs/nffs.md            | 136 +++++
 docs/os/modules/fs/nffs/nffs_area_desc.md  |  32 +
 docs/os/modules/fs/nffs/nffs_config.md     |  38 ++
 docs/os/modules/fs/nffs/nffs_detect.md     |  73 +++
 docs/os/modules/fs/nffs/nffs_format.md     |  72 +++
 docs/os/modules/fs/nffs/nffs_init.md       |  18 +
 docs/os/modules/fs/nffs/nffs_internals.md  | 318 ++++++++++
 docs/os/modules/fs/otherfs.md              |  63 ++
 docs/os/modules/nffs.md                    | 564 ------------------
 mkdocs.yml                                 |  41 +-
 32 files changed, 2088 insertions(+), 1317 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/1c504eb4/mkdocs.yml
----------------------------------------------------------------------
diff --cc mkdocs.yml
index 9a1c3ab,ec72d16..0bc8875
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@@ -195,16 -193,42 +195,51 @@@ pages
                  - 'boot_vect_read_one': 'os/modules/bootloader/boot_vect_read_one.md'
                  - 'boot_vect_read_test': 'os/modules/bootloader/boot_vect_read_test.md'
                  - 'boot_write_status': 'os/modules/bootloader/boot_write_status.md'
-         - 'File System Abstraction': 'os/modules/filesystem.md'
-         - 'Newtron Flash File System': 'os/modules/nffs.md'
+         - File System:
+             - 'File System Abstraction':
+                 - 'Overview': 'os/modules/fs/fs/fs.md'
+                 - 'Return Codes': 'os/modules/fs/fs/fs_return_codes.md'
+                 - 'Data Structures':
+                     - 'struct fs_ops': 'os/modules/fs/fs/fs_ops.md'
+                 - 'Functions':
+                     - 'fs_close': 'os/modules/fs/fs/fs_close.md'
+                     - 'fs_closedir': 'os/modules/fs/fs/fs_closedir.md'
+                     - 'fs_dirent_is_dir': 'os/modules/fs/fs/fs_dirent_is_dir.md'
+                     - 'fs_dirent_name': 'os/modules/fs/fs/fs_dirent_name.md'
+                     - 'fs_filelen': 'os/modules/fs/fs/fs_filelen.md'
+                     - 'fs_getpos': 'os/modules/fs/fs/fs_getpos.md'
+                     - 'fs_mkdir': 'os/modules/fs/fs/fs_mkdir.md'
+                     - 'fs_open': 'os/modules/fs/fs/fs_open.md'
+                     - 'fs_opendir': 'os/modules/fs/fs/fs_opendir.md'
+                     - 'fs_read': 'os/modules/fs/fs/fs_read.md'
+                     - 'fs_readdir': 'os/modules/fs/fs/fs_readdir.md'
+                     - 'fs_register': 'os/modules/fs/fs/fs_register.md'
+                     - 'fs_rename': 'os/modules/fs/fs/fs_rename.md'
+                     - 'fs_seek': 'os/modules/fs/fs/fs_seek.md'
+                     - 'fs_unlink': 'os/modules/fs/fs/fs_unlink.md'
+                     - 'fs_write': 'os/modules/fs/fs/fs_write.md'
+                     - 'fsutil_read_file': 'os/modules/fs/fs/fsutil_read_file.md'
+                     - 'fsutil_write_file': 'os/modules/fs/fs/fsutil_write_file.md'
+             - 'Newtron Flash File System':
+                 - 'Overview':               'os/modules/fs/nffs/nffs.md'
+                 - 'Data Structures':
+                     - 'struct nffs_area_desc': 'os/modules/fs/nffs/nffs_area_desc.md'
+                     - 'struct nffs_config': 'os/modules/fs/nffs/nffs_config.md'
+                 - 'Functions':
+                     - 'nffs_detect': 'os/modules/fs/nffs/nffs_detect.md'
+                     - 'nffs_format': 'os/modules/fs/nffs/nffs_format.md'
+                     - 'nffs_init': 'os/modules/fs/nffs/nffs_init.md'
+                 - 'Internals': 'os/modules/fs/nffs/nffs_internals.md'
+             - 'Other File Systems': 'os/modules/fs/otherfs.md'
 +        - Hardware Abstraction Layer:
 +            - 'Overview': 'os/modules/hal/hal.md'
 +            - API:
 +                - 'GPIO': 'os/modules/hal/hal_gpio.md'
 +                - 'Flash memory': 'os/modules/hal/hal_flash.md'
 +                - 'CPU timer': 'os/modules/hal/hal_cpu_timer.md'
 +                - 'UART': 'os/modules/hal/hal_uart.md'
-                 - 'System': 'os/modules/hal/hal_sys.md' 
++                - 'System': 'os/modules/hal/hal_sys.md'
++
          - Test Utilities:
              - 'Overview': 'os/modules/testutil/testutil.md'
              - 'Functions/Macros':


[2/4] incubator-mynewt-site git commit: File system documentation.

Posted by ad...@apache.org.
File system documentation.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/commit/ea47c5b6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/tree/ea47c5b6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/diff/ea47c5b6

Branch: refs/heads/master
Commit: ea47c5b69bb5d160fe3d1ae012b6b43d3b2b4dc2
Parents: 55a0951
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Mar 2 17:01:54 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Mar 3 14:29:13 2016 -0800

----------------------------------------------------------------------
 docs/os/modules/filesystem.md              | 750 ------------------------
 docs/os/modules/fs/fs/fs.md                | 108 ++++
 docs/os/modules/fs/fs/fs_close.md          |  61 ++
 docs/os/modules/fs/fs/fs_closedir.md       |  77 +++
 docs/os/modules/fs/fs/fs_dirent_is_dir.md  |  75 +++
 docs/os/modules/fs/fs/fs_dirent_name.md    |  83 +++
 docs/os/modules/fs/fs/fs_filelen.md        |  58 ++
 docs/os/modules/fs/fs/fs_getpos.md         |  27 +
 docs/os/modules/fs/fs/fs_mkdir.md          |  60 ++
 docs/os/modules/fs/fs/fs_open.md           |  78 +++
 docs/os/modules/fs/fs/fs_opendir.md        |  83 +++
 docs/os/modules/fs/fs/fs_ops.md            |  40 ++
 docs/os/modules/fs/fs/fs_read.md           |  61 ++
 docs/os/modules/fs/fs/fs_readdir.md        |  78 +++
 docs/os/modules/fs/fs/fs_register.md       |  28 +
 docs/os/modules/fs/fs/fs_rename.md         |  66 +++
 docs/os/modules/fs/fs/fs_return_codes.md   |  26 +
 docs/os/modules/fs/fs/fs_seek.md           |  62 ++
 docs/os/modules/fs/fs/fs_unlink.md         |  56 ++
 docs/os/modules/fs/fs/fs_write.md          |  61 ++
 docs/os/modules/fs/fs/fsutil_read_file.md  |  60 ++
 docs/os/modules/fs/fs/fsutil_write_file.md |  52 ++
 docs/os/modules/fs/nffs/nffs.md            | 136 +++++
 docs/os/modules/fs/nffs/nffs_area_desc.md  |  32 +
 docs/os/modules/fs/nffs/nffs_config.md     |  38 ++
 docs/os/modules/fs/nffs/nffs_detect.md     |  73 +++
 docs/os/modules/fs/nffs/nffs_format.md     |  72 +++
 docs/os/modules/fs/nffs/nffs_init.md       |  18 +
 docs/os/modules/fs/nffs/nffs_internals.md  | 318 ++++++++++
 docs/os/modules/fs/otherfs.md              |  63 ++
 docs/os/modules/nffs.md                    | 564 ------------------
 mkdocs.yml                                 |  38 +-
 32 files changed, 2086 insertions(+), 1316 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/filesystem.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/filesystem.md b/docs/os/modules/filesystem.md
deleted file mode 100644
index 6f40d4c..0000000
--- a/docs/os/modules/filesystem.md
+++ /dev/null
@@ -1,750 +0,0 @@
-# Filesystem
-
-Mynewt provides a Flash File System abstraction layer (fs) to allow you to swap out the default Newtron File System (nffs) with a different file system of your choice. 
-
-## Description
-
-The default file system used in the Mynewt OS is the Newtron Flash File System (nffs). Hence the `nffs` egg description lists `libs/fs` as a dependency. 
-
-```no-highlight
-egg.name: libs/nffs
-egg.vers: 0.1
-egg.identities: NFFS
-egg.deps:
-    - libs/os
-    - libs/fs
-    - libs/testutil
-    - hw/hal
-```
-
-If the user wishes to use a different flash file system (say, "ownffs"), the directory containing "ownffs" code must include the `egg.yml` file stating the dependency on `libs/fs` listed as shown above. "ownffs" uses the `libs/fs` API available in mynewt, thus minimizing changes to other parts of the project.
-
-Note that this generic file system (`fs`) API does not expose any file system detection, initialization, and formatting functions. These function calls remain specific to the chosen file system. For example, Project Slinky uses the default Newtron File System (nffs) and therefore calls nffs_init() to initialize the nffs memory and data structures before any other file system operations are attempted. As shown below, the egg for Project Slinky includes the `libs/imgmgr` egg which in turn includes the `libs/bootutil ` egg. The egg description for `libs/bootutil` specifies `fs/nffs` as a dependency.
-
-```no-highlight
-
-    egg.name: project/slinky
-    egg.vers: 0.1
-    egg.deps:
-        - libs/os
-        - libs/console/full
-        - libs/shell
-        - libs/newtmgr
-        - libs/imgmgr
-        - sys/config
-        - sys/log
-        - sys/stats
-```
-
-```no-highlight
-
-    egg.name: libs/imgmgr
-    egg.vers: 0.1
-    egg.deps:
-        - libs/newtmgr
-        - libs/bootutil
-    egg.deps.FS:
-        - fs/fs
-    egg.cflags.FS: -DFS_PRESENT
-```
-
-```no-highlight
- 
-    egg.name: libs/bootutil
-    egg.vers: 0.1 
-    egg.deps: 
-        - fs/nffs
-        - libs/os 
-        - libs/testutil
-        - hw/hal
-```
-        
-## Data Structures
-
-
-## API
-
-```no-highlight
-   struct fs_file;
-```
-
-The functions available in this OS feature are:
-
-* [fs_open](#fs_open)
-* [fs_close](#fs_close)
-* [fs_read](#fs_read)
-* [fs_write](#fs_write)
-* [fs_seek](#fs_seek)
-* [fs_getpos](#fs_getpos)
-* [fs_filelen](#fs_filelen)
-* [fs_unlink](#fs_unlink)
-* [fs_rename](#fs_rename)
-* [fs_mkdir](#fs_mkdir)
-* [fs_opendir](#fs_opendir)
-* [fs_readdir](#fs_readdir)
-* [fs_closedir](#fs_closedir)
-* [fs_dirent_name](#fs_dirent_name)
-* [fs_dirent_is_dir](#fs_dirent_is_dir)
-
-Additional file system utilities that bundle some of the basic functions above are:
-
-* [fsutil_read_file](#fsutil_read_file)
-* [fsutil_write_file](#fsutil_write_file)
-
-
-## API Reference
-
-------------------
-
-## <font color="F2853F" style="font-size:24pt"> fs_open </font>
-
-```no-highlight
-    int
-    fs_open(const char *filename, uint8_t access_flags, struct fs_file **out_file);
-```
-
-Opens a file at the specified path.  The result of opening a nonexistent file depends on the access flags specified.  All intermediate directories must already exist.
-
-The mode strings passed to fopen() map to fs_open()'s access flags as follows:
-
-```no-highlight
-    "r"  -  FS_ACCESS_READ
-    "r+" -  FS_ACCESS_READ | FS_ACCESS_WRITE
-    "w"  -  FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE
-    "w+" -  FS_ACCESS_READ | FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE
-    "a"  -  FS_ACCESS_WRITE | FS_ACCESS_APPEND
-    "a+" -  FS_ACCESS_READ | FS_ACCESS_WRITE | FS_ACCESS_APPEND
-```
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| filename |  Pointer to the file created at the path of the specified filename    |
-| access_flags |  Flags controlling file access; see above table   |
-| out_file | On success, a pointer to the newly-created file handle gets written here|
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure
-
-#### Notes 
-
-There is no concept of current working directory. Therefore all file names should start with '/'.
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-
-<Insert the code snippet here>
-
-```
-
----------------------
-   
-## <font color="#F2853F" style="font-size:24pt"> fs_close </font>
-
-```no-highlight
-   int
-   fs_close(struct fs_file *file)
-```
-
-Closes the specified file and invalidates the file handle.  If the file has already been unlinked, and this is the last open handle to the file, this operation causes the file to be deleted from disk.
-
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| file |  Pointer to the file to close  |
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure
-
-#### Notes 
-
-Don't use file handle after closing the file.
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-
-<Insert the code snippet here>
-
-```
-
----------------------
-   
-## <font color="#F2853F" style="font-size:24pt"> fs_read </font>
-
-```no-highlight
-   int
-   fs_read(struct fs_file *file, uint32_t len, void *out_data, 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. Function returns in `out_len` the actual number of bytes read (less or equal to `len`).
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| file |  Pointer to the the file to read from  |
-| len |  The number of bytes to attempt to read |
-| out_data | The destination buffer to read into
-| out_len  | On success, the number of bytes actually read gets written here.  Pass null if you don't care. |
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure
-
-#### Notes
-
-This type of short read results in a success return code.
-
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fs_write </font>
-
-```no-highlight
-   int
-   fs_write(struct fs_file *file, const void *data, int len);
-```
-
-Writes the supplied data to the current offset of the specified file handle.  
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| file |  Pointer to the file to write to |
-| data |  The data to write |
-| len | The number of bytes to write |
-
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure
-
-#### Notes 
-
-<any notes?>
-
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fs_seek </font>
-
-```no-highlight
-   int
-   fs_seek(struct fs_file *file, uint32_t offset);
-```
-
-Positions a file's read and write pointer at the specified offset.  The offset is expressed as the number of bytes from the start of the file (i.e., seeking to offset 0 places the pointer at the first byte in the file). 
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| file |  Pointer to the file to reposition |
-| offset |  The 0-based file offset to seek to |
-
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure
-
-#### Notes 
-
-<any notes?>
-
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fs_getpos </font>
-
-```no-highlight
-   uint32_t
-   fs_getpos(const struct fs_file *file);
-```
-
-Retrieves the current read and write position of the specified open file. 
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| file |  Pointer to the file to query |
-
-
-#### Returned values
-
-* The file offset, in bytes
-
-#### Notes 
-
-<any notes?>
-
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fs_filelen </font>
-
-```no-highlight
-   int
-   fs_filelen(const struct fs_file *file, uint32_t *out_len);
-
-```
-
-Retrieves the current length of the specified open file.
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| file |  Pointer to the file to query |
-| out_len |  On success, the number of bytes in the file gets written here |
-
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure
-
-#### Notes 
-
-<any notes?>
-
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fs_unlink </font>
-
-```no-highlight
-   int
-   fs_unlink(const char *filename);
-
-```
-
-Unlinks the file or directory at the specified path.  If the path refers to a directory, all the directory's descendants are recursively unlinked.  Any open file handles refering to an unlinked file remain valid, and can be read from and written to.
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| filename |  The path of the file or directory to unlink |
-
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure
-
-#### Notes 
-
-<any notes?>
-
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fs_rename </font>
-
-```no-highlight
-   int
-   fs_rename(const char *from, const char *to);
-
-```
-
-Performs a rename and / or move of the specified source path to the specified destination.  
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| from |  The source path |
-| to   | The destination path |
-
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure
-
-#### Notes 
-
-The source path can refer to either a file or a directory.  All intermediate directories in the destination path must already exist.  If the source path refers to a file, the destination path must contain a full filename path, rather than just the new parent directory.  If an object already exists at the specified destination path, this function causes it to be unlinked prior to the rename (i.e., the destination gets clobbered).
-
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fs_mkdir </font>
-
-```no-highlight
-   int
-   fs_mkdir(const char *path);
-
-```
-
-Creates the directory represented by the specified path.  
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| path |  Pointer to the directory to create |
-
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure.
-
-#### Notes 
-
-All intermediate directories must already exist.  The specified path must start with a '/' character.
-
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fs_opendir </font>
-
-```no-highlight
-
-   int
-   fs_opendir(const char *path, struct fs_dir **out_dir);
-
-```
-
-Opens the directory at the specified path.  The directory's contents can be read with subsequent calls to fs_readdir().  When you are done with the directory handle, close it with fs_closedir(). 
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| path |  Pointer to the directory to create |
-| out_dir  | On success, points to the directory handle |
-
-
-#### Returned values
-
-* 0 on success
-* FS_ENOENT if the specified directory does not exist (no such file)
-* Other nonzero on error.
-
-#### Notes 
-
-Unlinking files from the directory while it is open may result in unpredictable behavior.  New files can be created inside the directory.
-
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fs_readdir </font>
-
-```no-highlight
-   int
-   fs_readdir(struct fs_dir *dir, struct fs_dirent **out_dirent);
-
-```
-
-Reads the next entry in an open directory. 
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| dir |  The directory handle to read from |
-| out_dirent  | On success, points to the next child entry in the specified directory |
-
-
-#### Returned values
-
-* 0 on success
-* FS_ENOENT if there are no more entries in the parent directory
-* Other nonzero on error.
-
-#### Notes 
-
-<any notes?>
-
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fs_closedir </font>
-
-```no-highlight
-   int
-   fs_closedir(struct fs_dir *dir);
-
-```
-
-Closes the specified directory handle. 
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| dir |  Pointer to the directory to close |
-
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure
-
-#### Notes 
-
-<any notes?>
-
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fs_dirent_name </font>
-
-```no-highlight
-   int
-   fs_dirent_name(const struct fs_dirent *dirent, size_t max_len,
-     char *out_name, uint8_t *out_name_len);
-
-```
-
-Retrieves the filename of the specified directory entry. 
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| dirent |  Pointer to the directory entry to query |
-| max_len | Size of the "out_name" character buffer  |
-| out_name | On success, the entry's filename is written here; always null-terminated   |
-| out_name_len |  On success, contains the actual length of the filename, NOT including the null-terminator | 
-
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure
-
-#### Notes 
-
-The retrieved filename is always null-terminated.  To ensure enough space to hold the full filename plus a null-termintor, a destination buffer of size  (filename max length + 1) should be used.
-
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fs_dirent_is_dir </font>
-
-```no-highlight
-   int
-   fs_dirent_is_dir(const struct fs_dirent *dirent);
-
-```
-
-Tells you whether the specified directory entry is a sub-directory or a regular file. 
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| dirent |  Pointer to the directory entry to query |
-
-
-#### Returned values
-
-* 1: The entry is a directory
-* 0: The entry is a regular file.
-
-#### Notes 
-
-<any notes?>
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fsutil_read_file </font>
-
-```no-highlight
-   int
-   fsutil_read_file(const char *path, uint32_t offset, uint32_t len, void *dst,
-                    uint32_t *out_len);
-```
-
-Calls fs_open(), fs_read(), and fs_close() to open a file at the specified path, retrieve data from the file starting from the specified offset, and close the file and invalidate the file handle.
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| path |  Pointer to the directory entry to query |
-| offset |  Position of the file's read pointer |
-| len |  Number of bytes to attempt to read |
-| dst |  Destination buffer to read into |
-| out_len |  On success, the number of bytes actually read gets written here.  Pass null if you don't care. |
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure
-
-#### Notes 
-
-This is a convenience function. You can use it if the file is small (caller has enough buffer space to hold all the file contents in memory).
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------
-
-## <font color="#F2853F" style="font-size:24pt"> fsutil_write_file </font>
-
-```no-highlight
-   int
-   fsutil_write_file(const char *path, const void *data, uint32_t len);
-```
-
-Calls fs_open(), fs_write(), and fs_close() to open a file at the specified path, write the supplied data to the current offset of the specified file handle, and close the file and invalidate the file handle.
-
-#### Arguments
-
-| Arguments | Description |
-|-----------|-------------|
-| path |  Pointer to the file to write to |
-| data |  The data to write |
-| len |  The number of bytes to write |
-
-#### Returned values
-
-* 0 on success
-* nonzero on failure
-
-#### Notes 
-
-<any notes?>
-
-#### Example
-
-<Add text to set up the context for the example here>
-
-```no-highlight
-<Insert the code snippet here>
-```
-
----------------------

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs.md b/docs/os/modules/fs/fs/fs.md
new file mode 100644
index 0000000..f4a39bd
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs.md
@@ -0,0 +1,108 @@
+# File System Abstraction
+
+Mynewt provides a file system abstraction layer (`fs/fs`) to allow client code to be file system agnostic.  By accessing the file system via the `fs/fs` API, client code can perform file system operations without being tied to a particular implementation.  When possible, library code should use the `fs/fs` API rather than accessing the underlying file system directly.
+
+## Description
+
+Applications should aim to minimize the amount of code which depends on a particular file system implementation.  When possible, only depend on the `fs/fs` package.  In the simplest case, the only code which needs to know which file system is in use is the code which initializes the file system.  In terms of the Mynewt hierarchy, the **project** package must depend on a specific file system package, while **library** packages should only depend on `fs/fs`.
+
+The following example illustrates how file system dependencies should be managed.  In the slinky application, the project is responsible for initializing the file system, so it depends on a concrete file system package called `fs/nffs` (Newtron Flash File System). The project explicitly initializes nffs via calls to `nffs_init()`, `nffs_detect()` and `nffs_format()`.
+
+```no-highlight
+# project/slinky/pkg.yml
+
+pkg.name: project/slinky
+pkg.vers: 0.8.0
+pkg.deps:
+    - fs/nffs
+
+# [...]
+```
+
+```no-highlight
+// project/slinky/src/main.c
+
+#include "nffs/nffs.h"
+
+int
+main(int argc, char **argv)
+{
+    int rc;
+    int cnt;
+    struct nffs_area_desc descs[NFFS_AREA_MAX];
+
+    rc = nffs_init();
+    assert(rc == 0);
+
+    cnt = NFFS_AREA_MAX;
+    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, descs);
+    assert(rc == 0);
+    if (nffs_detect(descs) == FS_ECORRUPT) {
+        rc = nffs_format(descs);
+        assert(rc == 0);
+    }
+    // [...]
+}
+```
+
+On the other hand, code which uses the file system after it has been initialized need only depend on `fs/fs`.  For example, the `libs/imgmgr` package is a library which provides firmware upload and download functionality via the use of a file system.  This library is only used after the main project has initialized the file system, and therefore only depends on the `fs/fs` package.
+
+```no-highlight
+# libs/imgmgr/pkg.yml
+pkg.name: libs/imgmgr
+pkg.vers: 0.8.0
+pkg.deps:
+    - fs/fs
+
+# [...]
+```
+
+The `libs/imgmgr` package uses the `fs/fs` API for all file system operations.
+
+## Thread Safety
+All `fs/fs` functions are thread safe.
+
+## Header Files 
+All code which uses the `fs/fs` package needs to include the following header:
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+## Data Structures
+All `fs/fs` data structures are opaque to client code.
+
+```no-highlight
+struct fs_file;
+struct fs_dir;
+struct fs_dirent;
+```
+
+## API
+
+Functions in `fs/fs` that indicate success or failure do so with the following set of return codes:
+
+* [Return Codes](fs_return_codes.md)
+
+The functions available in this OS feature are:
+
+* [fs\_close](fs_close.md)
+* [fs\_closedir](fs_closedir.md)
+* [fs\_dirent\_is\_dir](fs_dirent_is_dir.md)
+* [fs\_dirent\_name](fs_dirent_name.md)
+* [fs\_filelen](fs_filelen.md)
+* [fs\_getpos](fs_getpos.md)
+* [fs\_mkdir](fs_mkdir.md)
+* [fs\_open](fs_open.md)
+* [fs\_opendir](fs_opendir.md)
+* [fs\_read](fs_read.md)
+* [fs\_readdir](fs_readdir.md)
+* [fs\_rename](fs_rename.md)
+* [fs\_seek](fs_seek.md)
+* [fs\_unlink](fs_unlink.md)
+* [fs\_write](fs_write.md)
+
+Additional file system utilities that bundle some of the basic functions above are:
+
+* [fsutil\_read\_file](fsutil_read_file.md)
+* [fsutil\_write\_file](fsutil_write_file.md)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_close.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_close.md b/docs/os/modules/fs/fs/fs_close.md
new file mode 100644
index 0000000..765cc48
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_close.md
@@ -0,0 +1,61 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_close</font>
+
+```no-highlight
+int fs_close(struct fs_file *file)
+```
+
+Closes the specified file and invalidates the file handle.
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| file      |  Pointer to the file to close  |
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure
+
+#### Notes 
+
+If the file has already been unlinked, and the file has no other open handles, the `fs_close()` function causes the file to be deleted from the disk.
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+The below code opens the file `/settings/config.txt` for reading, reads some data, and then closes the file.
+
+```no-highlight
+int
+read_config(void)
+{
+    struct fs_file *file;
+    uint32_t bytes_read;
+    uint8_t buf[16];
+    int rc;
+
+    /* Open the file for reading. */
+    rc = fs_open("/settings/config.txt", FS_ACCESS_READ, &file);
+    if (rc != 0) {
+        return -1;
+    }
+
+    /* Read up to 16 bytes from the file. */
+    rc = fs_read(file, sizeof buf, buf, &bytes_read);
+    if (rc == 0) {
+        /* buf now contains up to 16 bytes of file data. */
+        console_printf("read %u bytes\n", bytes_read)
+    }
+
+    /* Close the file. */
+    fs_close(file);
+
+    return rc == 0 ? 0 : -1;
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_closedir.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_closedir.md b/docs/os/modules/fs/fs/fs_closedir.md
new file mode 100644
index 0000000..faa9ff8
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_closedir.md
@@ -0,0 +1,77 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_closedir</font>
+
+```no-highlight
+int fs_closedir(struct fs_dir *dir)
+```
+
+Closes the specified directory handle. 
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| dir       |  The name of the directory to close |
+
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+This example iterates through the contents of a directory, printing the name of each child node.  When the traversal is complete, the code closes the directory handle.
+
+```no-highlight
+int
+traverse_dir(const char *dirname)
+{
+    struct fs_dirent *dirent;
+    struct fs_dir *dir;
+    char buf[64];
+    uint8_t name_len;
+    int rc;
+
+    rc = fs_opendir(dirname, &dir);
+    if (rc != 0) {
+        return -1;
+    }
+
+    /* Iterate through the parent directory, printing the name of each child
+     * entry.  The loop only terminates via a function return.
+     */
+    while (1) {
+        /* Retrieve the next child node. */
+        rc = fs_readdir(dir, &dirent); 
+        if (rc == FS_ENOENT) {
+            /* Traversal complete. */
+            return 0;
+        } else if (rc != 0) {
+            /* Unexpected error. */
+            return -1;
+        }
+
+        /* Read the child node's name from the file system. */
+        rc = fs_dirent_name(dirent, sizeof buf, buf, &name_len);
+        if (rc != 0) {
+            return -1;
+        }
+
+        /* Print the child node's name to the console. */
+        if (fs_dirent_is_dir(dirent)) {
+            console_printf(" dir: ");
+        } else {
+            console_printf("file: ");
+        }
+        console_printf("%s\n", buf);
+    }
+}
+```
+
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_dirent_is_dir.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_dirent_is_dir.md b/docs/os/modules/fs/fs/fs_dirent_is_dir.md
new file mode 100644
index 0000000..965a0d8
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_dirent_is_dir.md
@@ -0,0 +1,75 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_dirent\_is\_dir</font>
+
+```no-highlight
+int fs_dirent_is_dir(const struct fs_dirent *dirent)
+```
+
+Tells you whether the specified directory entry is a sub-directory or a regular file. 
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| dirent    |  Pointer to the directory entry to query |
+
+
+#### Returned values
+
+* 1: The entry is a directory
+* 0: The entry is a regular file.
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+This example iterates through the contents of a directory, printing the name of each child node.  When the traversal is complete, the code closes the directory handle.
+
+```no-highlight
+int
+traverse_dir(const char *dirname)
+{
+    struct fs_dirent *dirent;
+    struct fs_dir *dir;
+    char buf[64];
+    uint8_t name_len;
+    int rc;
+
+    rc = fs_opendir(dirname, &dir);
+    if (rc != 0) {
+        return -1;
+    }
+
+    /* Iterate through the parent directory, printing the name of each child
+     * entry.  The loop only terminates via a function return.
+     */
+    while (1) {
+        /* Retrieve the next child node. */
+        rc = fs_readdir(dir, &dirent); 
+        if (rc == FS_ENOENT) {
+            /* Traversal complete. */
+            return 0;
+        } else if (rc != 0) {
+            /* Unexpected error. */
+            return -1;
+        }
+
+        /* Read the child node's name from the file system. */
+        rc = fs_dirent_name(dirent, sizeof buf, buf, &name_len);
+        if (rc != 0) {
+            return -1;
+        }
+
+        /* Print the child node's name to the console. */
+        if (fs_dirent_is_dir(dirent)) {
+            console_printf(" dir: ");
+        } else {
+            console_printf("file: ");
+        }
+        console_printf("%s\n", buf);
+    }
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_dirent_name.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_dirent_name.md b/docs/os/modules/fs/fs/fs_dirent_name.md
new file mode 100644
index 0000000..8057d1f
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_dirent_name.md
@@ -0,0 +1,83 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_dirent\_name</font>
+
+```no-highlight
+int fs_dirent_name(const struct fs_dirent *dirent, size_t max_len,
+                   char *out_name, uint8_t *out_name_len)
+```
+
+Retrieves the filename of the specified directory entry. 
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| dirent |  Pointer to the directory entry to query |
+| max\_len | Size of the "out\_name" character buffer  |
+| out\_name | On success, the entry's filename is written here; always null-terminated   |
+| out\_name\_len |  On success, contains the actual length of the filename, NOT including the null-terminator | 
+
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure
+
+#### Notes 
+
+The retrieved filename is always null-terminated.  To ensure enough space to hold the full filename plus a null-termintor, a destination buffer of size _filename-max-length + 1_ should be used.
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+This example iterates through the contents of a directory, printing the name of each child node.  When the traversal is complete, the code closes the directory handle.
+
+```no-highlight
+int
+traverse_dir(const char *dirname)
+{
+    struct fs_dirent *dirent;
+    struct fs_dir *dir;
+    char buf[64];
+    uint8_t name_len;
+    int rc;
+
+    rc = fs_opendir(dirname, &dir);
+    if (rc != 0) {
+        return -1;
+    }
+
+    /* Iterate through the parent directory, printing the name of each child
+     * entry.  The loop only terminates via a function return.
+     */
+    while (1) {
+        /* Retrieve the next child node. */
+        rc = fs_readdir(dir, &dirent); 
+        if (rc == FS_ENOENT) {
+            /* Traversal complete. */
+            return 0;
+        } else if (rc != 0) {
+            /* Unexpected error. */
+            return -1;
+        }
+
+        /* Read the child node's name from the file system. */
+        rc = fs_dirent_name(dirent, sizeof buf, buf, &name_len);
+        if (rc != 0) {
+            return -1;
+        }
+
+        /* Print the child node's name to the console. */
+        if (fs_dirent_is_dir(dirent)) {
+            console_printf(" dir: ");
+        } else {
+            console_printf("file: ");
+        }
+        console_printf("%s\n", buf);
+    }
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_filelen.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_filelen.md b/docs/os/modules/fs/fs/fs_filelen.md
new file mode 100644
index 0000000..43f97e9
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_filelen.md
@@ -0,0 +1,58 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_filelen</font>
+
+```no-highlight
+int fs_filelen(const struct fs_file *file, uint32_t *out_len)
+```
+
+Retrieves the current length of the specified open file.
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| file |  Pointer to the file to query |
+| out\_len |  On success, the number of bytes in the file gets written here |
+
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+```no-highlight
+int
+write_config(void)
+{
+    struct fs_file *file;
+    int rc;
+
+    /* If the file doesn't exist, create it.  If it does exist, truncate it to
+     * zero bytes.
+     */
+    rc = fs_open("/settings/config.txt", FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE,
+                 &file);
+    if (rc == 0) {
+        /* Write 5 bytes of data to the file. */
+        rc = fs_write(file, "hello", 5);
+        if (rc == 0) {
+            /* The file should now contain exactly five bytes. */
+            assert(fs_filelen(file) == 5);
+        }
+
+        /* Close the file. */
+        fs_close(file);
+    }
+
+    return rc == 0 ? 0 : -1;
+}
+```
+
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_getpos.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_getpos.md b/docs/os/modules/fs/fs/fs_getpos.md
new file mode 100644
index 0000000..426b7f0
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_getpos.md
@@ -0,0 +1,27 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_getpos</font>
+
+```no-highlight
+uint32_t fs_getpos(const struct fs_file *file)
+```
+
+Retrieves the current read and write position of the specified open file. 
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| file |  Pointer to the file to query |
+
+#### Returned values
+
+* The file offset, in bytes
+
+#### Notes 
+
+If a file is opened in append mode, its write pointer is always positioned at the end of the file.  Calling this function on such a file only indicates the read position.
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_mkdir.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_mkdir.md b/docs/os/modules/fs/fs/fs_mkdir.md
new file mode 100644
index 0000000..07f8654
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_mkdir.md
@@ -0,0 +1,60 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_mkdir</font>
+
+```no-highlight
+int fs_mkdir(const char *path)
+```
+
+Creates the directory represented by the specified path.  
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| path      |  The name of the directory to create |
+
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure.
+
+#### Notes 
+
+All intermediate directories must already exist.  The specified path must start with a '/' character.
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+This example demonstrates creating a series of nested directories.
+
+```no-highlight
+int
+create_path(void)
+{
+    int rc;
+
+    rc = fs_mkdir("/data");
+    if (rc != 0) goto err;
+
+    rc = fs_mkdir("/data/logs");
+    if (rc != 0) goto err;
+
+    rc = fs_mkdir("/data/logs/temperature");
+    if (rc != 0) goto err;
+
+    rc = fs_mkdir("/data/logs/temperature/current");
+    if (rc != 0) goto err;
+
+    return 0;
+
+err:
+    /* Clean up the incomplete directory tree, if any. */
+    fs_unlink("/data");
+    return -1;
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_open.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_open.md b/docs/os/modules/fs/fs/fs_open.md
new file mode 100644
index 0000000..9bd0090
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_open.md
@@ -0,0 +1,78 @@
+## <font color="F2853F" style="font-size:24pt">fs\_open</font>
+
+```no-highlight
+int fs_open(const char *filename, uint8_t access_flags,
+            struct fs_file **out_file)
+```
+
+Opens a file at the specified path.  The result of opening a nonexistent file depends on the access flags specified.  All intermediate directories must already exist.
+
+The access flags are best understood by comparing them to their equivalent mode strings accepted by the C standard library function `fopen()`.
+The mode strings passed to `fopen()` map to `fs_open()`'s access flags as follows:
+
+```no-highlight
+"r"  -  FS_ACCESS_READ
+"r+" -  FS_ACCESS_READ  | FS_ACCESS_WRITE
+"w"  -  FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE
+"w+" -  FS_ACCESS_READ  | FS_ACCESS_WRITE    | FS_ACCESS_TRUNCATE
+"a"  -  FS_ACCESS_WRITE | FS_ACCESS_APPEND
+"a+" -  FS_ACCESS_READ  | FS_ACCESS_WRITE    | FS_ACCESS_APPEND
+```
+
+#### Arguments
+
+| Argument | Description |
+|----------|-------------|
+| filename | Null-terminated string indicating the full path of the file to open |
+| access\_flags | Flags controlling file access; see above table   |
+ out\_file | On success, a pointer to the newly-created file handle gets written here |
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure
+
+#### Notes 
+
+* There is no concept of current working directory. Therefore all file names should start with '/'.
+
+* Always close files when you are done using them.  If you forget to close a file, the file stays open forever.  Do this too many times, and the underlying file system will run out of file handles, causing subsequent open operations to fail.  This type of bug is known as a file handle leak or a file descriptor leak.
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+The below code opens the file `/settings/config.txt` for reading, reads some data, and then closes the file.
+
+```no-highlight
+int
+read_config(void)
+{
+    struct fs_file *file;
+    uint32_t bytes_read;
+    uint8_t buf[16];
+    int rc;
+
+    /* Open the file for reading. */
+    rc = fs_open("/settings/config.txt", FS_ACCESS_READ, &file);
+    if (rc != 0) {
+        return -1;
+    }
+
+    /* Read up to 16 bytes from the file. */
+    rc = fs_read(file, sizeof buf, buf, &bytes_read);
+    if (rc == 0) {
+        /* buf now contains up to 16 bytes of file data. */
+        console_printf("read %u bytes\n", bytes_read)
+    }
+
+    /* Close the file. */
+    fs_close(file);
+
+    return rc == 0 ? 0 : -1;
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_opendir.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_opendir.md b/docs/os/modules/fs/fs/fs_opendir.md
new file mode 100644
index 0000000..eb9b7ec
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_opendir.md
@@ -0,0 +1,83 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_opendir</font>
+
+```no-highlight
+int fs_opendir(const char *path, struct fs_dir **out_dir)
+```
+
+Opens the directory at the specified path.  The directory's contents can be read with subsequent calls to fs\_readdir().  When you are done with the directory handle, close it with fs\_closedir(). 
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| path      | The name of the directory to open |
+| out\_dir  | On success, points to the directory handle |
+
+
+#### Returned values
+
+* 0 on success
+* FS\_ENOENT if the specified directory does not exist
+* Other [FS error code](fs_return_codes.md) on error.
+
+#### Notes 
+
+* Unlinking files from the directory while it is open may result in unpredictable behavior during subsequent calls to `fs_readdir()`.  New files can be created inside the directory without causing problems.
+
+* Always close a directory when you are done reading from it.  If you forget to close a directory, the directory stays open forever.  Do this too many times, and the underlying file system will run out of directory handles, causing subsequent open operations to fail.  This type of bug is known as a file handle leak or a file descriptor leak.
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+This example iterates through the contents of a directory, printing the name of each child node.  When the traversal is complete, the code closes the directory handle.
+
+```no-highlight
+int
+traverse_dir(const char *dirname)
+{
+    struct fs_dirent *dirent;
+    struct fs_dir *dir;
+    char buf[64];
+    uint8_t name_len;
+    int rc;
+
+    rc = fs_opendir(dirname, &dir);
+    if (rc != 0) {
+        return -1;
+    }
+
+    /* Iterate through the parent directory, printing the name of each child
+     * entry.  The loop only terminates via a function return.
+     */
+    while (1) {
+        /* Retrieve the next child node. */
+        rc = fs_readdir(dir, &dirent); 
+        if (rc == FS_ENOENT) {
+            /* Traversal complete. */
+            return 0;
+        } else if (rc != 0) {
+            /* Unexpected error. */
+            return -1;
+        }
+
+        /* Read the child node's name from the file system. */
+        rc = fs_dirent_name(dirent, sizeof buf, buf, &name_len);
+        if (rc != 0) {
+            return -1;
+        }
+
+        /* Print the child node's name to the console. */
+        if (fs_dirent_is_dir(dirent)) {
+            console_printf(" dir: ");
+        } else {
+            console_printf("file: ");
+        }
+        console_printf("%s\n", buf);
+    }
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_ops.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_ops.md b/docs/os/modules/fs/fs/fs_ops.md
new file mode 100644
index 0000000..874f920
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_ops.md
@@ -0,0 +1,40 @@
+## <font color="F2853F" style="font-size:24pt">struct fs\_ops</font>
+
+```no-highlight
+struct fs_ops {
+    int (*f_open)(const char *filename, uint8_t access_flags,
+              struct fs_file **out_file);
+    int (*f_close)(struct fs_file *file);
+    int (*f_read)(struct fs_file *file, uint32_t len, void *out_data,
+      uint32_t *out_len);
+    int (*f_write)(struct fs_file *file, const void *data, int len);
+
+    int (*f_seek)(struct fs_file *file, uint32_t offset);
+    uint32_t (*f_getpos)(const struct fs_file *file);
+    int (*f_filelen)(const struct fs_file *file, uint32_t *out_len);
+
+    int (*f_unlink)(const char *filename);
+    int (*f_rename)(const char *from, const char *to);
+    int (*f_mkdir)(const char *path);
+
+    int (*f_opendir)(const char *path, struct fs_dir **out_dir);
+    int (*f_readdir)(struct fs_dir *dir, struct fs_dirent **out_dirent);
+    int (*f_closedir)(struct fs_dir *dir);
+
+    int (*f_dirent_name)(const struct fs_dirent *dirent, size_t max_len,
+      char *out_name, uint8_t *out_name_len);
+    int (*f_dirent_is_dir)(const struct fs_dirent *dirent);
+
+    const char *f_name;
+};
+```
+
+This data structure consists of a set of function pointers.  Each function pointer corresponds to a file system operation.  When registering a file system with the abstraction layer, each function pointer must be pointed at the corresponding routine in the custom file system package.
+
+The required behavior of each corresponding function is documented in the [file system abstraction layer API](fs/fs.md#api).
+
+#### Header file
+
+```no-highlight
+#include "fs/fs_if.h"
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_read.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_read.md b/docs/os/modules/fs/fs/fs_read.md
new file mode 100644
index 0000000..9b044d9
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_read.md
@@ -0,0 +1,61 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_read</font>
+
+```no-highlight
+int fs_read(struct fs_file *file, uint32_t len, void *out_data, 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 and a success code is returned.
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| file |  Pointer to the the file to read from  |
+| len |  The number of bytes to attempt to read |
+| out\_data | The destination buffer to read into
+| out\_len  | On success, the number of bytes actually read gets written here.  Pass null if you don't care. |
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+The below code opens the file `/settings/config.txt` for reading, reads some data, and then closes the file.
+
+```no-highlight
+int
+read_config(void)
+{
+    struct fs_file *file;
+    uint32_t bytes_read;
+    uint8_t buf[16];
+    int rc;
+
+    /* Open the file for reading. */
+    rc = fs_open("/settings/config.txt", FS_ACCESS_READ, &file);
+    if (rc != 0) {
+        return -1;
+    }
+
+    /* Read up to 16 bytes from the file. */
+    rc = fs_read(file, sizeof buf, buf, &bytes_read);
+    if (rc == 0) {
+        /* buf now contains up to 16 bytes of file data. */
+        console_printf("read %u bytes\n", bytes_read)
+    }
+
+    /* Close the file. */
+    fs_close(file);
+
+    return rc == 0 ? 0 : -1;
+}
+```
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_readdir.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_readdir.md b/docs/os/modules/fs/fs/fs_readdir.md
new file mode 100644
index 0000000..976ee56
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_readdir.md
@@ -0,0 +1,78 @@
+## <font color="#F2853F" style="font-size:24pt">fs_readdir</font>
+
+```no-highlight
+int fs_readdir(struct fs_dir *dir, struct fs_dirent **out_dirent);
+```
+
+Reads the next entry in an open directory. 
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| dir |  The directory handle to read from |
+| out\_dirent  | On success, points to the next child entry in the specified directory |
+
+
+#### Returned values
+
+* 0 on success
+* FS\_ENOENT if there are no more entries in the parent directory
+* Other [FS error code](fs_return_codes.md) on error.
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+This example iterates through the contents of a directory, printing the name of each child node.  When the traversal is complete, the code closes the directory handle.
+
+```no-highlight
+int
+traverse_dir(const char *dirname)
+{
+    struct fs_dirent *dirent;
+    struct fs_dir *dir;
+    char buf[64];
+    uint8_t name_len;
+    int rc;
+
+    rc = fs_opendir(dirname, &dir);
+    if (rc != 0) {
+        return -1;
+    }
+
+    /* Iterate through the parent directory, printing the name of each child
+     * entry.  The loop only terminates via a function return.
+     */
+    while (1) {
+        /* Retrieve the next child node. */
+        rc = fs_readdir(dir, &dirent); 
+        if (rc == FS_ENOENT) {
+            /* Traversal complete. */
+            return 0;
+        } else if (rc != 0) {
+            /* Unexpected error. */
+            return -1;
+        }
+
+        /* Read the child node's name from the file system. */
+        rc = fs_dirent_name(dirent, sizeof buf, buf, &name_len);
+        if (rc != 0) {
+            return -1;
+        }
+
+        /* Print the child node's name to the console. */
+        if (fs_dirent_is_dir(dirent)) {
+            console_printf(" dir: ");
+        } else {
+            console_printf("file: ");
+        }
+        console_printf("%s\n", buf);
+    }
+}
+```
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_register.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_register.md b/docs/os/modules/fs/fs/fs_register.md
new file mode 100644
index 0000000..7681065
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_register.md
@@ -0,0 +1,28 @@
+## <font color="F2853F" style="font-size:24pt">fs\_register</font>
+
+```no-highlight
+int fs_register(const struct fs_ops *fops)
+```
+
+Registers a file system with the abstraction layer.  On success, all calls into `fs/fs` will use the registered file system.
+
+#### Arguments
+
+| Argument | Description |
+|----------|-------------|
+| fops     | A pointer to const [struct fs\_ops](fs_ops.md). Specifies which file system routines get mapped to the `fs/fs` API.  All function pointers must be filled in. |
+
+#### Returned values
+
+* 0 on success
+* *FS\_EEXIST* if a file system has already been registered
+
+#### Notes 
+
+Only one file system can be registered.  The registered file system is mounted in the root directory (*/*).
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_rename.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_rename.md b/docs/os/modules/fs/fs/fs_rename.md
new file mode 100644
index 0000000..bf26ddc
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_rename.md
@@ -0,0 +1,66 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_rename</font>
+
+```no-highlight
+int fs_rename(const char *from, const char *to)
+```
+
+Performs a rename and / or move of the specified source path to the specified destination.  The source path can refer to a file or a directory.
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| from |  The source path |
+| to   | The destination path |
+
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure
+
+#### Notes 
+
+The source path can refer to either a file or a directory.  All intermediate directories in the destination path must already exist.  If the source path refers to a file, the destination path must contain a full filename path, rather than just the new parent directory.  If an object already exists at the specified destination path, this function causes it to be unlinked prior to the rename (i.e., the destination gets clobbered).
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+This example demonstrates how to use fs\_rename() to perform a log rotation.  In this example, there is one primary log and three archived logs.  `FS_ENOENT` errors returned by `fs_rename()` are ignored; it is not an error if an archived log was never created.
+
+```no-highlight
+int
+rotate_logs(void)
+{
+    struct fs_file *file;
+    int rc;
+
+    /* Rotate each of the log files. */
+    rc = fs_rename("/var/log/messages.2", "/var/log/messages.3")
+    if (rc != 0 && rc != FS_ENOENT) return -1;
+
+    rc = fs_rename("/var/log/messages.1", "/var/log/messages.2")
+    if (rc != 0 && rc != FS_ENOENT) return -1;
+
+    rc = fs_rename("/var/log/messages.0", "/var/log/messages.1")
+    if (rc != 0 && rc != FS_ENOENT) return -1;
+
+    rc = fs_rename("/var/log/messages", "/var/log/messages.0")
+    if (rc != 0 && rc != FS_ENOENT) return -1;
+
+    /* Now create the new log file. */
+    rc = fs_open("/var/log/messages", FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE,
+                 &file);
+    if (rc != 0) return -1;
+
+    rc = fs_write(file, "Creating new log file.\n", 23);
+    fs_close(file);
+
+    return rc == 0 ? 0 : -1;
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_return_codes.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_return_codes.md b/docs/os/modules/fs/fs/fs_return_codes.md
new file mode 100644
index 0000000..f268dde
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_return_codes.md
@@ -0,0 +1,26 @@
+## <font color="F2853F" style="font-size:24pt">fs/fs Return Codes</font>
+
+Functions in `fs/fs` that indicate success or failure do so with the following set of return codes:
+
+| Return code    | Description                                  |
+|----------------|----------------------------------------------|
+| FS\_EOK        | Success                                      |
+| FS\_ECORRUPT   | File system corrupt                          |
+| FS\_EHW        | Error accessing storage medium               |
+| FS\_EOFFSET    | Invalid offset                               |
+| FS\_EINVAL     | Invalid argument                             |
+| FS\_ENOMEM     | Insufficient memory                          |
+| FS\_ENOENT     | No such file or directory                    |
+| FS\_EEMPTY     | Specified region is empty (internal only)    |
+| FS\_EFULL      | Disk full                                    |
+| FS\_EUNEXP     | Disk contains unexpected metadata            |
+| FS\_EOS        | OS error                                     |
+| FS\_EEXIST     | File or directory already exists             |
+| FS\_EACCESS    | Operation prohibited by file open mode       |
+| FS\_EUNINIT    | File system not initialized                  |
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_seek.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_seek.md b/docs/os/modules/fs/fs/fs_seek.md
new file mode 100644
index 0000000..bc36ce5
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_seek.md
@@ -0,0 +1,62 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_seek</font>
+
+```no-highlight
+int fs_seek(struct fs_file *file, uint32_t offset)
+```
+Positions a file's read and write pointer at the specified offset.  The offset is expressed as the number of bytes from the start of the file (i.e., seeking to offset 0 places the pointer at the first byte in the file).
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| file |  Pointer to the file to reposition |
+| offset |  The 0-based file offset to seek to |
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure
+
+#### Notes 
+
+If a file is opened in append mode, its write pointer is always positioned at the end of the file.  Calling this function on such a file only affects the read pointer.
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+The following example reads four bytes from a file, starting at an offset of eight.
+
+```no-highlight
+int
+read_part1_middle(void)
+{
+    struct fs_file *file;
+    uint32_t bytes_read;
+    uint8_t buf[4];
+    int rc;
+
+    rc = fs_open("/data/parts/1.bin", FS_ACCESS_READ, &file);
+    if (rc == 0) {
+        /* Advance to offset 8. */
+        rc = fs_seek(file, 8);
+        if (rc == 0) {
+            /* Read bytes 8, 9, 10, and 11. */
+            rc = fs_read(file, 4, buf, &bytes_read);
+            if (rc == 0) {
+                /* buf now contains up to 4 bytes of file data. */
+                console_printf("read %u bytes\n", bytes_read)
+            }
+        }
+
+        /* Close the file. */
+        fs_close(file);
+    }
+
+    return rc == 0 ? 0 : -1;
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_unlink.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_unlink.md b/docs/os/modules/fs/fs/fs_unlink.md
new file mode 100644
index 0000000..0183b6e
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_unlink.md
@@ -0,0 +1,56 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_unlink</font>
+
+```no-highlight
+int fs_unlink(const char *filename)
+```
+
+Unlinks the file or directory at the specified path.  This is the function to use if you want to delete a file or directory from the disk.  If the path refers to a directory, all the directory's descendants are recursively unlinked.  Any open file handles refering to an unlinked file remain valid, and can be read from and written to as long as they remain open.
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| filename  |  The path of the file or directory to unlink |
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+The following example creates a file and then immediately unlinks it.  By unlinking the file, this function prevents other OS tasks from accessing it.  When the function closes the file, it is deleted from the disk.
+
+```no-highlight
+int
+process_data(void)
+{
+    struct fs_file *file;
+    int rc;
+
+    /* If the file doesn't exist, create it.  If it does exist, truncate it to
+     * zero bytes.
+     */
+    rc = fs_open("/tmp/buffer.bin", FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE, &file);
+    if (rc == 0) {
+        /* Unlink the file so that other tasks cannot access it. */
+        fs_unlink("/tmp/buffer.bin")
+
+        /* <use the file as a data buffer> */
+
+        /* Close the file.  This operation causes the file to be deleted from
+         * the disk because it was unlinked earlier (and it has no other open
+         * file handles).
+         */
+        fs_close(file);
+    }
+
+    return rc == 0 ? 0 : -1;
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fs_write.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_write.md b/docs/os/modules/fs/fs/fs_write.md
new file mode 100644
index 0000000..4442b84
--- /dev/null
+++ b/docs/os/modules/fs/fs/fs_write.md
@@ -0,0 +1,61 @@
+## <font color="#F2853F" style="font-size:24pt">fs\_write</font>
+
+```no-highlight
+int fs_write(struct fs_file *file, const void *data, int len)
+```
+
+Writes the supplied data to the current offset of the specified file handle.  
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| file |  Pointer to the file to write to |
+| data |  The data to write |
+| len | The number of bytes to write |
+
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure
+
+#### Notes 
+
+For files opened in append mode, the specified data is always written to the end.
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+```no-highlight
+int
+write_config(void)
+{
+    struct fs_file *file;
+    int rc;
+
+    /* If the file doesn't exist, create it.  If it does exist, truncate it to
+     * zero bytes.
+     */
+    rc = fs_open("/settings/config.txt", FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE,
+                 &file);
+    if (rc == 0) {
+        /* Write 5 bytes of data to the file. */
+        rc = fs_write(file, "hello", 5);
+        if (rc == 0) {
+            /* The file should now contain exactly five bytes. */
+            assert(fs_filelen(file) == 5);
+        }
+
+        /* Close the file. */
+        fs_close(file);
+    }
+
+    return rc == 0 ? 0 : -1;
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fsutil_read_file.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fsutil_read_file.md b/docs/os/modules/fs/fs/fsutil_read_file.md
new file mode 100644
index 0000000..5301633
--- /dev/null
+++ b/docs/os/modules/fs/fs/fsutil_read_file.md
@@ -0,0 +1,60 @@
+## <font color="#F2853F" style="font-size:24pt">fsutil\_read\_file</font>
+
+```no-highlight
+int fsutil_read_file(const char *path, uint32_t offset, uint32_t len,
+                     void *dst, uint32_t *out_len)
+```
+
+Calls fs\_open(), fs\_read(), and fs\_close() to open a file at the specified path, retrieve data from the file starting from the specified offset, and close the file and invalidate the file handle.
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| path |  Pointer to the directory entry to query |
+| offset |  Position of the file's read pointer |
+| len |  Number of bytes to attempt to read |
+| dst |  Destination buffer to read into |
+| out\_len |  On success, the number of bytes actually read gets written here.  Pass null if you don't care. |
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure
+
+#### Notes 
+
+This is a convenience function. It is useful when the amount of data to be read from the file is small (i.e., all the data read can easily fit in a single buffer).
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+This example demonstrates reading a small text file in its entirety and printing its contents to the console.
+
+```no-highlight
+int
+print_status(void)
+{
+    uint32_t bytes_read;
+    uint8_t buf[16];
+    int rc;
+
+    /* Read up to 15 bytes from the start of the file. */
+    rc = fsutil_read_file("/cfg/status.txt", 0, sizeof buf - 1, buf,
+                          &bytes_read);
+    if (rc != 0) return -1;
+
+    /* Null-terminate the string just read. */
+    buf[bytes_read] = '\0';
+
+    /* Print the file contents to the console. */
+    console_printf("%s\n", buf);
+
+    return 0;
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/fs/fsutil_write_file.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fsutil_write_file.md b/docs/os/modules/fs/fs/fsutil_write_file.md
new file mode 100644
index 0000000..4d89b5f
--- /dev/null
+++ b/docs/os/modules/fs/fs/fsutil_write_file.md
@@ -0,0 +1,52 @@
+## <font color="#F2853F" style="font-size:24pt">fsutil\_write\_file</font>
+
+```no-highlight
+int fsutil_write_file(const char *path, const void *data, uint32_t len)
+```
+
+Calls fs\_open(), fs\_write(), and fs\_close() to open a file at the specified path, write the supplied data to the current offset of the specified file handle, and close the file and invalidate the file handle.  If the specified file already exists, it is truncated and overwritten with the specified data.
+
+#### Arguments
+
+| Arguments | Description |
+|-----------|-------------|
+| path |  Pointer to the file to write to |
+| data |  The data to write |
+| len |  The number of bytes to write |
+
+#### Returned values
+
+* 0 on success
+* [FS error code](fs_return_codes.md) on failure
+
+#### Header file
+
+```no-highlight
+#include "fs/fs.h"
+```
+
+#### Example
+
+This example creates a 4-byte file.
+
+```no-highlight
+int
+write_id(void)
+{
+    int rc;
+
+    /* Create the parent directory. */
+    rc = fs_mkdir("/cfg");
+    if (rc != 0 && rc != FS_EALREADY) {
+        return -1;
+    }
+
+    /* Create a file and write four bytes to it. */
+    rc = fsutil_write_file("/cfg/id.txt", "1234", 4);
+    if (rc != 0) {
+        return -1;
+    }
+
+    return 0;
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/nffs/nffs.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/nffs/nffs.md b/docs/os/modules/fs/nffs/nffs.md
new file mode 100644
index 0000000..7832264
--- /dev/null
+++ b/docs/os/modules/fs/nffs/nffs.md
@@ -0,0 +1,136 @@
+# Newtron Flash Filesystem (nffs)
+
+Mynewt includes the Newtron Flash File System (nffs).  This file system is designed with two priorities that makes it suitable for embedded use: 
+
+* Minimal RAM usage
+* Reliability
+
+Mynewt also provides an abstraction layer API (fs) to allow you to swap out nffs with a different file system of your choice.
+
+## Description
+
+### Areas
+
+At the top level, an nffs disk is partitioned into *areas*.  An area is a region of disk with the following properties:
+
+1. An area can be fully erased without affecting any other areas.
+2. Writing to one area does not restrict writes to other areas.
+
+**Regarding property 1:** Generally, flash hardware divides its memory space into "blocks."  When erasing flash, entire blocks must be erased in a single operation; partial erases are not possible.
+
+**Regarding property 2:** Furthermore, some flash hardware imposes a restriction with regards to writes: writes within a block must be strictly sequential.  For example, if you wish to write to the first 16 bytes of a block, you must write bytes 1 through 15 before writing byte 16.  This restriction only applies at the block level; writes to one block have no effect on what parts of other blocks can be written.
+
+Thus, each area must comprise a discrete number of blocks.
+
+### Initialization
+
+Before nffs can be used, it must be initialized.  There are two means of initializing an nffs file system:
+
+1. Restore an existing file system via detection.
+2. Create a new file system via formatting.
+
+A typical initialization sequence is the following:
+
+1. Detect an nffs file system in a specific region of flash.
+2. If no file system was detected, format a new file system in the same flash region.
+
+Both methods require the user to describe how the flash memory should be divided into nffs areas.  This is accomplished with an array of [struct nffs\_area\_desc](nffs_area_desc.md).
+
+Typically, a product's flash layout is exposed via its BSP-specific `bsp_flash_dev()` function.  This function retrieves the layout of the specified flash device resident in the BSP.  The result of this function can then be converted into the `struct nffs_area_desc[]` that nffs requires.  The below example, taken from the slinky project, illustrates the nffs initialization procedure.
+
+```no-highlight
+/*** hw/hal/include/hal/flash_map.h */
+
+/*
+ * Flash area types
+ */
+#define FLASH_AREA_BOOTLOADER           0
+#define FLASH_AREA_IMAGE_0              1
+#define FLASH_AREA_IMAGE_1              2
+#define FLASH_AREA_IMAGE_SCRATCH        3
+#define FLASH_AREA_NFFS                 4
+```
+
+```no-highlight
+/*** project/slinky/src/main.c */
+
+int
+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];
+
+    /* 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);
+    }
+    /* [ ... ] */
+}
+```
+
+After nffs has been initialized, the application can access the file system via the [file system abstraction layer](../fs/fs.md).
+
+## Configuration
+
+The nffs file system is configured by populating fields in a global [struct nffs\_config](nffs_config.md) instance.  Each field in the structure corresponds to a setting.  All configuration must be done prior to calling nffs\_init().
+
+
+The global `struct nffs_config` instance is exposed in `nffs/nffs.h` as follows:
+
+```no-highlight
+extern struct nffs_config nffs_config;
+```
+
+## Data Structures
+
+The `fs/nffs` package exposes the following data structures:
+
+* [struct nffs\_area\_desc](nffs_area_desc.md)
+* [struct nffs\_config](nffs_config.md)
+
+## API
+
+The functions available in this OS feature are:
+
+* [nffs\_detect](nffs_detect.md)
+* [nffs\_format](nffs_format.md)
+* [nffs\_init](nffs_init.md)
+
+# Miscellaneous measures
+
+* RAM usage:
+    * 24 bytes per inode
+    * 12 bytes per data block
+    * 36 bytes per inode cache entry
+    * 32 bytes per data block cache entry
+    
+* Maximum filename size: 256 characters (no null terminator required)
+* Disallowed filename characters: '/' and '\0'
+
+## Internals
+
+nffs implementation details can be found here:
+
+* [nffs\_internals](nffs_internals.md)
+
+## Future enhancements
+
+* Error correction.
+* Encryption.
+* Compression.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/nffs/nffs_area_desc.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/nffs/nffs_area_desc.md b/docs/os/modules/fs/nffs/nffs_area_desc.md
new file mode 100644
index 0000000..e46cd20
--- /dev/null
+++ b/docs/os/modules/fs/nffs/nffs_area_desc.md
@@ -0,0 +1,32 @@
+## <font color="F2853F" style="font-size:24pt">struct nffs\_area\_desc</font>
+
+```no-highlight
+struct nffs_area_desc {
+    uint32_t nad_offset;    /* Flash offset of start of area. */
+    uint32_t nad_length;    /* Size of area, in bytes. */
+    uint8_t nad_flash_id;   /* Logical flash id */
+};
+```
+
+Descriptor for a single nffs area.  An area is a region of disk with the following properties:
+
+1. An area can be fully erased without affecting any other areas.
+2. Writing to one area does not restrict writes to other areas.
+
+**Regarding property 1:** Generally, flash hardware divides its memory space into "blocks."  When erasing flash, entire blocks must be erased in a single operation; partial erases are not possible.
+
+**Regarding property 2:** Furthermore, some flash hardware imposes a restriction with regards to writes: writes within a block must be strictly sequential.  For example, if you wish to write to the first 16 bytes of a block, you must write bytes 1 through 15 before writing byte 16.  This restriction only applies at the block level; writes to one block have no effect on what parts of other blocks can be written.
+
+Thus, each area must comprise a discrete number of blocks.
+
+An array of area descriptors is terminated by an entry with a *nad_length* value of 0.
+
+#### Notes
+
+Typically, a product's flash layout is exposed via its BSP-specific `bsp_flash_dev()` function.  This function retrieves the layout of the specified flash device resident in the BSP.  The result of this function can then be converted into the `struct nffs_area_desc[]` that nffs requires.
+
+#### Header file
+
+```no-highlight
+#include "nffs/nffs.h"
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/nffs/nffs_config.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/nffs/nffs_config.md b/docs/os/modules/fs/nffs/nffs_config.md
new file mode 100644
index 0000000..e1fc705
--- /dev/null
+++ b/docs/os/modules/fs/nffs/nffs_config.md
@@ -0,0 +1,38 @@
+## <font color="F2853F" style="font-size:24pt">struct nffs\_config</font>
+
+```no-highlight
+struct nffs_config {
+    /** Maximum number of inodes; default=1024. */
+    uint32_t nc_num_inodes;
+
+    /** Maximum number of data blocks; default=4096. */
+    uint32_t nc_num_blocks;
+
+    /** Maximum number of open files; default=4. */
+    uint32_t nc_num_files;
+
+    /** Inode cache size; default=4. */
+    uint32_t nc_num_cache_inodes;
+
+    /** Data block cache size; default=64. */
+    uint32_t nc_num_cache_blocks;
+};
+```
+
+The file system is configured by populating fields in a global `struct nffs_config` instance.  Each field in the structure corresponds to a setting.  All configuration must be done prior to calling nffs\_init().
+
+Any fields that are set to 0 (or not set at all) inherit the corresponding default value.  This means that it is impossible to configure any setting with a value of zero.
+
+#### Notes
+
+The global `struct nffs_config` instance is exposed in `nffs/nffs.h` as follows:
+
+```no-highlight
+extern struct nffs_config nffs_config;
+```
+
+#### Header file
+
+```no-highlight
+#include "nffs/nffs.h"
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/nffs/nffs_detect.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/nffs/nffs_detect.md b/docs/os/modules/fs/nffs/nffs_detect.md
new file mode 100644
index 0000000..a7f0ee7
--- /dev/null
+++ b/docs/os/modules/fs/nffs/nffs_detect.md
@@ -0,0 +1,73 @@
+## <font color="F2853F" style="font-size:24pt">nffs\_detect</font>
+
+```no-highlight
+int nffs_detect(const struct nffs_area_desc *area_descs)
+```
+
+Searches for a valid nffs file system among the specified areas.  This function succeeds if a file system is detected among any subset of the supplied areas.  If the area set does not contain a valid file system, a new one can be created via a separate call to nffs\_format().
+
+#### Arguments
+
+| Arguments     | Description                   |
+|---------------|-------------------------------|
+| area\_descs   | The set of areas to search.  This array must be terminated with a 0-length area. |
+
+#### Returned values
+
+* 0 on success
+* FS\_ECORRUPT if no valid file system was detected
+* Other [FS error code](../fs/fs_return_codes.md) on failure
+
+#### Header file
+
+```no-highlight
+#include "nffs/nffs.h"
+```
+
+#### Example
+
+```no-highlight
+/*** hw/hal/include/hal/flash_map.h */
+
+/*
+ * Flash area types
+ */
+#define FLASH_AREA_BOOTLOADER           0
+#define FLASH_AREA_IMAGE_0              1
+#define FLASH_AREA_IMAGE_1              2
+#define FLASH_AREA_IMAGE_SCRATCH        3
+#define FLASH_AREA_NFFS                 4
+```
+
+```no-highlight
+/*** project/slinky/src/main.c */
+
+int
+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];
+
+    /* 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);
+    }
+    /* [ ... ] */
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/nffs/nffs_format.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/nffs/nffs_format.md b/docs/os/modules/fs/nffs/nffs_format.md
new file mode 100644
index 0000000..411ce36
--- /dev/null
+++ b/docs/os/modules/fs/nffs/nffs_format.md
@@ -0,0 +1,72 @@
+## <font color="F2853F" style="font-size:24pt">nffs\_format</font>
+
+```no-highlight
+int nffs_format(const struct nffs_area_desc *area_descs)
+```
+
+Erases all the specified areas and initializes them with a clean nffs file system.
+
+#### Arguments
+
+| Arguments     | Description                   |
+|---------------|-------------------------------|
+| area\_descs   | The set of areas to format    |
+
+#### Returned values
+
+* 0 on success
+* [FS error code](../fs/fs_return_codes.md) on failure.
+
+#### Header file
+
+```no-highlight
+#include "nffs/nffs.h"
+```
+
+#### Example
+
+```no-highlight
+/*** hw/hal/include/hal/flash_map.h */
+
+/*
+ * Flash area types
+ */
+#define FLASH_AREA_BOOTLOADER           0
+#define FLASH_AREA_IMAGE_0              1
+#define FLASH_AREA_IMAGE_1              2
+#define FLASH_AREA_IMAGE_SCRATCH        3
+#define FLASH_AREA_NFFS                 4
+```
+
+```no-highlight
+/*** project/slinky/src/main.c */
+
+int
+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];
+
+    /* 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);
+    }
+    /* [ ... ] */
+}
+```

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/ea47c5b6/docs/os/modules/fs/nffs/nffs_init.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/nffs/nffs_init.md b/docs/os/modules/fs/nffs/nffs_init.md
new file mode 100644
index 0000000..65f1524
--- /dev/null
+++ b/docs/os/modules/fs/nffs/nffs_init.md
@@ -0,0 +1,18 @@
+## <font color="F2853F" style="font-size:24pt">nffs\_init</font>
+
+```no-highlight
+int nffs_init(void)
+```
+
+Initializes internal nffs memory and data structures.  This must be called before any nffs operations are attempted.
+
+#### Returned values
+
+* 0 on success
+* [FS error code](../fs/fs_return_codes.md) on failure
+
+#### Header file
+
+```no-highlight
+#include "nffs/nffs.h"
+```


[3/4] incubator-mynewt-site git commit: Fix broken link in fs documentation.

Posted by ad...@apache.org.
Fix broken link in fs documentation.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/commit/2a19afbe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/tree/2a19afbe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/diff/2a19afbe

Branch: refs/heads/master
Commit: 2a19afbebda02d4fd186b3fa6732e9f3facb3a1b
Parents: ea47c5b
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Mar 3 15:32:02 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Mar 3 15:32:02 2016 -0800

----------------------------------------------------------------------
 docs/os/modules/fs/fs/fs_ops.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/2a19afbe/docs/os/modules/fs/fs/fs_ops.md
----------------------------------------------------------------------
diff --git a/docs/os/modules/fs/fs/fs_ops.md b/docs/os/modules/fs/fs/fs_ops.md
index 874f920..69069f8 100644
--- a/docs/os/modules/fs/fs/fs_ops.md
+++ b/docs/os/modules/fs/fs/fs_ops.md
@@ -31,7 +31,7 @@ struct fs_ops {
 
 This data structure consists of a set of function pointers.  Each function pointer corresponds to a file system operation.  When registering a file system with the abstraction layer, each function pointer must be pointed at the corresponding routine in the custom file system package.
 
-The required behavior of each corresponding function is documented in the [file system abstraction layer API](fs/fs.md#api).
+The required behavior of each corresponding function is documented in the [file system abstraction layer API](fs.md#api).
 
 #### Header file