| |
| |
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| |
| |
| |
| |
| <title>File System Abstraction — Apache Mynewt latest documentation</title> |
| |
| |
| |
| |
| <link rel="shortcut icon" href="../../../../_static/mynewt-logo-only-newt32x32.png"/> |
| |
| |
| |
| |
| <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" /> |
| |
| |
| <link rel="stylesheet" href="../../../../_static/css/sphinx_theme.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../../../_static/css/bootstrap-3.0.3.min.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../../../_static/css/v2.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../../../_static/css/custom.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../../../_static/css/restructuredtext.css" type="text/css" /> |
| |
| |
| |
| |
| <link rel="stylesheet" href="../../../../_static/css/overrides.css" type="text/css" /> |
| <link rel="index" title="Index" |
| href="../../../../genindex.html"/> |
| <link rel="search" title="Search" href="../../../../search.html"/> |
| <link rel="top" title="Apache Mynewt latest documentation" href="../../../../index.html"/> |
| |
| |
| <script src="../../../../_static/js/modernizr.min.js"></script> |
| |
| |
| <script> |
| (function(i, s, o, g, r, a, m) { |
| i["GoogleAnalyticsObject"] = r; |
| (i[r] = |
| i[r] || |
| function() { |
| (i[r].q = i[r].q || []).push(arguments); |
| }), |
| (i[r].l = 1 * new Date()); |
| (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]); |
| a.async = 1; |
| a.src = g; |
| m.parentNode.insertBefore(a, m); |
| })(window, document, "script", "//www.google-analytics.com/analytics.js", "ga"); |
| |
| ga("create", "UA-72162311-1", "auto"); |
| ga("send", "pageview"); |
| </script> |
| |
| |
| </head> |
| |
| <body class="not-front page-documentation" role="document" > |
| <div id="wrapper"> |
| <div class="container"> |
| <div id="banner" class="row v2-main-banner"> |
| <a class="logo-cell" href="/"> |
| <img class="logo" src="../../../../_static/img/logo.png"> |
| </a> |
| <div class="tagline-cell"> |
| <h4 class="tagline">An OS to build, deploy and securely manage billions of devices</h4> |
| </div> |
| <div class="news-cell"> |
| <div class="well"> |
| <h4>Latest News:</h4> <a href="/download">Apache Mynewt 1.12.0, Apache NimBLE 1.7.0 </a> released April 4, 2024) |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| <header> |
| <nav id="navbar" class="navbar navbar-inverse" role="navigation"> |
| <div class="container"> |
| <!-- Collapsed navigation --> |
| <div class="navbar-header"> |
| <!-- Expander button --> |
| <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> |
| <span class="sr-only">Toggle navigation</span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </button> |
| |
| </div> |
| |
| <!-- Expanded navigation --> |
| <div class="navbar-collapse collapse"> |
| <!-- Main navigation --> |
| <ul class="nav navbar-nav navbar-right"> |
| <li> |
| <a href="/"><i class="fa fa-home" style="font-size: larger;"></i></a> |
| </li> |
| <li class="important"> |
| <a href="/quick-start/">Quick Start</a> |
| </li> |
| <li> |
| <a href="/about/">About</a> |
| </li> |
| <li> |
| <a href="/talks/">Talks</a> |
| </li> |
| <li class="active"> |
| <a href="/documentation/">Documentation</a> |
| </li> |
| <li> |
| <a href="/download/">Download</a> |
| </li> |
| <li> |
| <a href="/community/">Community</a> |
| </li> |
| <li> |
| <a href="/events/">Events</a> |
| </li> |
| </ul> |
| |
| <!-- Search, Navigation and Repo links --> |
| <ul class="nav navbar-nav navbar-right"> |
| |
| </ul> |
| </div> |
| </div> |
| </nav> |
| </header> |
| <!-- STARTS MAIN CONTENT --> |
| <div id="main-content"> |
| |
| |
| |
| |
| |
| |
| <div id="breadcrumb"> |
| <div class="container"> |
| <a href="/documentation/">Docs</a> / |
| |
| File System Abstraction |
| |
| <div class="sourcelink"> |
| <a href="https://github.com/apache/mynewt-core/edit/master/docs/os/modules/fs/fs/fs.rst" class="icon icon-github" |
| rel="nofollow"> Edit on GitHub</a> |
| </div> |
| </div> |
| </div> |
| <!-- STARTS CONTAINER --> |
| <div class="container"> |
| <!-- STARTS .content --> |
| <div id="content" class="row"> |
| |
| <!-- STARTS .container-sidebar --> |
| <div class="container-sidebar col-xs-12 col-sm-3"> |
| <div id="docSidebar" class="sticky-container"> |
| <div role="search" class="sphinx-search"> |
| <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get"> |
| <input type="text" name="q" placeholder="Search documentation" class="search-documentation" /> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </form> |
| </div> |
| <!-- Note: only works when deployed --> |
| <select class="form-control" onchange="if (this.value) window.location.href=this.value"> |
| <option value="/latest" selected> |
| Version: latest |
| </option> |
| <option value="/v1_12_0" > |
| Version: 1.12.0 |
| </option> |
| <option value="/v1_11_0" > |
| Version: 1.11.0 |
| </option> |
| <option value="/v1_10_0" > |
| Version: 1.10.0 |
| </option> |
| <option value="/v1_9_0" > |
| Version: 1.9.0 |
| </option> |
| <option value="/v1_8_0" > |
| Version: 1.8.0 |
| </option> |
| <option value="/v1_7_0" > |
| Version: 1.7.0 |
| </option> |
| <option value="/v1_6_0" > |
| Version: 1.6.0 |
| </option> |
| <option value="/v1_5_0" > |
| Version: 1.5.0 |
| </option> |
| <option value="/v1_4_0" selected="selected" > |
| Version: 1.4.0 |
| </option> |
| <option value="/v1_3_0/os/introduction" > |
| Version: 1.3.0 |
| </option> |
| <option value="/v1_2_0/os/introduction" > |
| Version: 1.2.0 |
| </option> |
| <option value="/v1_1_0/os/introduction" > |
| Version: 1.1.0 |
| </option> |
| <option value="/v1_0_0/os/introduction" > |
| Version: 1.0.0 |
| </option> |
| <option value="/v0_9_0/os/introduction" > |
| Version: 0.9.0 |
| </option> |
| </select> |
| <div class="region region-sidebar"> |
| <div class="docs-menu"> |
| |
| |
| |
| <ul> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../index.html">Introduction</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../get_started/index.html">Setup & Get Started</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../concepts.html">Concepts</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../tutorials/tutorials.html">Tutorials</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../external_links.html">Third-party Resources</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../os_user_guide.html">OS User Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../network/index.html">BLE User Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../newt/index.html">Newt Tool Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../newtmgr/index.html">Newt Manager Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../mynewt_faq/index.html">Mynewt FAQ</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../misc/index.html">Appendix</a></li> |
| </ul> |
| |
| |
| |
| </div> |
| </div> |
| </div> |
| <!-- ENDS STICKY CONTAINER --> |
| </div> |
| <!-- ENDS .container-sidebar --> |
| |
| <div class="col-xs-12 col-sm-9"> |
| |
| <div class="alert alert-warning"> |
| <p> |
| Version 1.4.0 is not the most recent version of the |
| Apache Mynewt documentation. Click <a href="/latest">here</a> to |
| read the latest version. |
| </p> |
| </div> |
| |
| |
| |
| <div class=""> |
| <div class="rst-content"> |
| <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> |
| <div itemprop="articleBody"> |
| |
| <div class="section" id="file-system-abstraction"> |
| <h1>File System Abstraction<a class="headerlink" href="#file-system-abstraction" title="Permalink to this headline">¶</a></h1> |
| <p>Mynewt provides a file system abstraction layer (<code class="docutils literal notranslate"><span class="pre">fs/fs</span></code>) to allow |
| client code to be file system agnostic. By accessing the file system via |
| the <code class="docutils literal notranslate"><span class="pre">fs/fs</span></code> API, client code can perform file system operations |
| without being tied to a particular implementation. When possible, |
| library code should use the <code class="docutils literal notranslate"><span class="pre">fs/fs</span></code> API rather than accessing the |
| underlying file system directly.</p> |
| <div class="section" id="description"> |
| <h2>Description<a class="headerlink" href="#description" title="Permalink to this headline">¶</a></h2> |
| <p>Applications should aim to minimize the amount of code which depends on |
| a particular file system implementation. When possible, only depend on |
| the <code class="docutils literal notranslate"><span class="pre">fs/fs</span></code> package. In terms of the Mynewt hierarchy, an <strong>app</strong> |
| package must depend on a specific file system package, while <strong>library</strong> |
| packages should only depend on <code class="docutils literal notranslate"><span class="pre">fs/fs</span></code>.</p> |
| <p>Applications wanting to access a filesystem are required to include the |
| necessary packages in their applications pkg.yml file. In the following |
| example, the <code class="docutils literal notranslate"><span class="pre">`Newtron</span> <span class="pre">Flash</span> <span class="pre">File</span> <span class="pre">System</span></code> <../nffs/nffs.html>`__ is |
| used.</p> |
| <div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp"># </span>repos/apache-mynewt-core/apps/slinky/pkg.yml |
| |
| <span class="go">pkg.name: repos/apache-mynewt-core/apps/slinky</span> |
| <span class="go">pkg.deps:</span> |
| <span class="go"> - fs/fs # include the file operations interfaces</span> |
| <span class="go"> - fs/nffs # include the NFFS filesystem implementation</span> |
| </pre></div> |
| </div> |
| <div class="highlight-none notranslate"><div class="highlight"><pre><span></span># repos/apache-mynewt-core/apps/slinky/syscfg.yml |
| # [...] |
| # Package: apps/<example app> |
| # [...] |
| CONFIG_NFFS: 1 # initialize and configure NFFS into the system |
| # NFFS_DETECT_FAIL: 1 # Ignore NFFS detection issues |
| # NFFS_DETECT_FAIL: 2 # Format a new NFFS file system on failure to detect |
| |
| # [...] |
| </pre></div> |
| </div> |
| <p>Consult the documentation for <code class="docutils literal notranslate"><span class="pre">`nffs</span></code> <../nffs/nffs.html>`__ for a more |
| detailed explanation of NFFS_DETECT_FAIL</p> |
| <p>Code which uses the file system after the system has been initialized |
| need only depend on <code class="docutils literal notranslate"><span class="pre">fs/fs</span></code>. For example, the <code class="docutils literal notranslate"><span class="pre">libs/imgmgr</span></code> 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 system |
| has been initialized, and therefore only depends on the <code class="docutils literal notranslate"><span class="pre">fs/fs</span></code> |
| package.</p> |
| <div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp"># </span>repos/apache-mynewt-core/libs/imgmgr/pkg.yml |
| <span class="go">pkg.name: libs/imgmgr</span> |
| <span class="go">pkg.deps:</span> |
| <span class="go"> - fs/fs</span> |
| |
| <span class="gp"># </span><span class="o">[</span>...<span class="o">]</span> |
| </pre></div> |
| </div> |
| <p>The <code class="docutils literal notranslate"><span class="pre">libs/imgmgr</span></code> package uses the <code class="docutils literal notranslate"><span class="pre">fs/fs</span></code> API for all file system |
| operations.</p> |
| </div> |
| <div class="section" id="support-for-multiple-filesystems"> |
| <h2>Support for multiple filesystems<a class="headerlink" href="#support-for-multiple-filesystems" title="Permalink to this headline">¶</a></h2> |
| <p>When using a single filesystem/disk, it is valid to provide paths in the |
| standard unix way, eg, <code class="docutils literal notranslate"><span class="pre">/<dir-name>/<file-name></span></code>. When trying to run |
| more than one filesystem or a single filesystem in multiple devices |
| simultaneosly, an extra name has to be given to the disk that is being |
| used. The abstraction for that was added as the <code class="docutils literal notranslate"><span class="pre">fs/disk</span></code> package |
| which is a dependency of <code class="docutils literal notranslate"><span class="pre">fs/fs</span></code>. It adds the following extra user |
| function:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="n">disk_register</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">disk_name</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">fs_name</span><span class="p">,</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">disk_ops</span><span class="w"> </span><span class="o">*</span><span class="n">dops</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>As an example os usage:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">disk_register</span><span class="p">(</span><span class="s">"mmc0"</span><span class="p">,</span><span class="w"> </span><span class="s">"fatfs"</span><span class="p">,</span><span class="w"> </span><span class="o">&</span><span class="n">mmc_ops</span><span class="p">);</span> |
| <span class="n">disk_register</span><span class="p">(</span><span class="s">"flash0"</span><span class="p">,</span><span class="w"> </span><span class="s">"nffs"</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span> |
| </pre></div> |
| </div> |
| <p>This registers the name <code class="docutils literal notranslate"><span class="pre">mmc0</span></code> to use <code class="docutils literal notranslate"><span class="pre">fatfs</span></code> as the filesystem and |
| <code class="docutils literal notranslate"><span class="pre">mmc_ops</span></code> for the low-level disk driver and also registers <code class="docutils literal notranslate"><span class="pre">flash0</span></code> |
| to use <code class="docutils literal notranslate"><span class="pre">nffs</span></code>. <code class="docutils literal notranslate"><span class="pre">nffs</span></code> is currently strongly bound to the |
| <code class="docutils literal notranslate"><span class="pre">hal_flash</span></code> interface, ignoring any other possible <code class="docutils literal notranslate"><span class="pre">disk_ops</span></code> given.</p> |
| <div class="section" id="struct-disk-ops"> |
| <h3>struct disk_ops<a class="headerlink" href="#struct-disk-ops" title="Permalink to this headline">¶</a></h3> |
| <p>To support a new low-level disk interface, the <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">disk_ops</span></code> |
| interface must be implemented by the low-level driver. Currently only |
| <code class="docutils literal notranslate"><span class="pre">read</span></code> and <code class="docutils literal notranslate"><span class="pre">write</span></code> are effectively used (by <code class="docutils literal notranslate"><span class="pre">fatfs</span></code>).</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">disk_ops</span><span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">read</span><span class="p">)(</span><span class="kt">uint8_t</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="p">);</span> |
| <span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">write</span><span class="p">)(</span><span class="kt">uint8_t</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="p">,</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="p">);</span> |
| <span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">ioctl</span><span class="p">)(</span><span class="kt">uint8_t</span><span class="p">,</span><span class="w"> </span><span class="kt">uint32_t</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="p">);</span> |
| <span class="w"> </span><span class="n">SLIST_ENTRY</span><span class="p">(</span><span class="n">disk_ops</span><span class="p">)</span><span class="w"> </span><span class="n">sc_next</span><span class="p">;</span> |
| <span class="p">}</span> |
| </pre></div> |
| </div> |
| </div> |
| </div> |
| <div class="section" id="thread-safety"> |
| <h2>Thread Safety<a class="headerlink" href="#thread-safety" title="Permalink to this headline">¶</a></h2> |
| <p>All <code class="docutils literal notranslate"><span class="pre">fs/fs</span></code> functions are thread safe.</p> |
| </div> |
| <div class="section" id="header-files"> |
| <h2>Header Files<a class="headerlink" href="#header-files" title="Permalink to this headline">¶</a></h2> |
| <p>All code which uses the <code class="docutils literal notranslate"><span class="pre">fs/fs</span></code> package needs to include the following |
| header:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf">"fs/fs.h"</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="data-structures"> |
| <h2>Data Structures<a class="headerlink" href="#data-structures" title="Permalink to this headline">¶</a></h2> |
| <p>All <code class="docutils literal notranslate"><span class="pre">fs/fs</span></code> data structures are opaque to client code.</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">fs_file</span><span class="p">;</span> |
| <span class="k">struct</span><span class="w"> </span><span class="nc">fs_dir</span><span class="p">;</span> |
| <span class="k">struct</span><span class="w"> </span><span class="nc">fs_dirent</span><span class="p">;</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="api"> |
| <h2>API<a class="headerlink" href="#api" title="Permalink to this headline">¶</a></h2> |
| <p>Functions in <code class="docutils literal notranslate"><span class="pre">fs/fs</span></code> that indicate success or failure do so with the |
| following set of return codes:</p> |
| <ul class="simple"> |
| <li><p><a class="reference external" href="fs_return_codes.html">Return Codes</a></p></li> |
| </ul> |
| <p>The functions available in this OS feature are:</p> |
| <p>Additional file system utilities that bundle some of the basic functions |
| above are:</p> |
| <table class="docutils align-default"> |
| <colgroup> |
| <col style="width: 43%" /> |
| <col style="width: 57%" /> |
| </colgroup> |
| <thead> |
| <tr class="row-odd"><th class="head"><p>Function</p></th> |
| <th class="head"><p>Description</p></th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr class="row-even"><td><p><a href="#id3"><span class="problematic" id="id4">`fsutil\_r |
| ead\_file |
| <fsutil_re |
| ad_file.md |
| >`__</span></a></p></td> |
| <td><p>Opens 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.</p></td> |
| </tr> |
| <tr class="row-odd"><td><p><a href="#id1"><span class="problematic" id="id2">`</span></a>fsutil_w |
| rite_file</p> |
| <blockquote> |
| <div><p><fsutil_w</p> |
| </div></blockquote> |
| <p>rite_file. |
| md>`__</p> |
| </td> |
| <td><p>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.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </div> |
| |
| |
| </div> |
| </div> |
| |
| </div> |
| </div> |
| </div> |
| <!-- ENDS CONTENT SECTION --> |
| </div> |
| <!-- ENDS .content --> |
| </div> |
| </div> |
| <footer> |
| <div class="container"> |
| <div class="row"> |
| <div class="col-xs-12"> |
| |
| <p class="copyright">Apache Mynewt is available under Apache License, version 2.0.</p> |
| |
| </div> |
| <div class="col-xs-12"> |
| <div class="logos"> |
| <img src="../../../../_static/img/asf_logo_wide_small.png" alt="Apache" title="Apache"> |
| <small class="footnote"> |
| Apache Mynewt, Mynewt, Apache, the Apache feather logo, and the Apache Mynewt project logo are either |
| registered trademarks or trademarks of the Apache Software Foundation in the United States and other countries. |
| </small> |
| <a href=""> |
| <img src="../../../../_static/img/add_to_slack.png" alt="Slack Icon" title="Join our Slack Community" /> |
| </a> |
| </div> |
| </div> |
| </div> |
| </div> |
| </footer> |
| </div> |
| <!-- ENDS #wrapper --> |
| |
| |
| |
| <script type="text/javascript"> |
| var DOCUMENTATION_OPTIONS = { |
| URL_ROOT:'../../../../', |
| VERSION:'latest', |
| COLLAPSE_INDEX:false, |
| FILE_SUFFIX:'.html', |
| HAS_SOURCE: true, |
| SOURCELINK_SUFFIX: '.txt', |
| LINK_SUFFIX: '.html' |
| }; |
| </script> |
| <script type="text/javascript" src="../../../../_static/jquery.js"></script> |
| <script type="text/javascript" src="../../../../_static/underscore.js"></script> |
| <script type="text/javascript" src="../../../../_static/doctools.js"></script> |
| <script type="text/javascript" src="../../../../_static/js/bootstrap-3.0.3.min.js"></script> |
| <script type="text/javascript" src="../../../../_static/js/affix.js"></script> |
| <script type="text/javascript" src="../../../../_static/js/main.js"></script> |
| |
| |
| |
| </body> |
| </html> |