<?xml version='1.0' encoding='iso-8859-1' standalone='no'?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.4.7">
  <compounddef id="ubixfs_8cpp" kind="file">
    <compoundname>ubixfs.cpp</compoundname>
    <includes local="no">stddef.h</includes>
    <includes local="no">stdlib.h</includes>
    <includes local="no">unistd.h</includes>
    <includes refid="string_8h" local="no">string.h</includes>
    <includes refid="assert_8h" local="no">assert.h</includes>
    <includes local="no">iostream</includes>
    <includes refid="ubixfsv2_2ubixfs_8h" local="yes">ubixfs.h</includes>
    <includes refid="btree_8h" local="yes">btree.h</includes>
    <incdepgraph>
      <node id="4602">
        <label>src/sys/ubixfsv2/ubixfs.cpp</label>
        <link refid="ubixfs.cpp"/>
        <childnode refid="4603" relation="include">
        </childnode>
        <childnode refid="4604" relation="include">
        </childnode>
        <childnode refid="4605" relation="include">
        </childnode>
        <childnode refid="4606" relation="include">
        </childnode>
        <childnode refid="4609" relation="include">
        </childnode>
        <childnode refid="4610" relation="include">
        </childnode>
        <childnode refid="4611" relation="include">
        </childnode>
        <childnode refid="4619" relation="include">
        </childnode>
      </node>
      <node id="4619">
        <label>btree.h</label>
        <link refid="btree_8h"/>
        <childnode refid="4614" relation="include">
        </childnode>
        <childnode refid="4611" relation="include">
        </childnode>
        <childnode refid="4620" relation="include">
        </childnode>
        <childnode refid="4618" relation="include">
        </childnode>
      </node>
      <node id="4604">
        <label>stdlib.h</label>
      </node>
      <node id="4611">
        <label>ubixfs.h</label>
        <link refid="ubixfsv2_2ubixfs_8h"/>
        <childnode refid="4612" relation="include">
        </childnode>
        <childnode refid="4605" relation="include">
        </childnode>
        <childnode refid="4613" relation="include">
        </childnode>
        <childnode refid="4617" relation="include">
        </childnode>
        <childnode refid="4618" relation="include">
        </childnode>
      </node>
      <node id="4607">
        <label>ubixos/types.h</label>
        <link refid="include_2ubixos_2types_8h"/>
        <childnode refid="4608" relation="include">
        </childnode>
      </node>
      <node id="4608">
        <label>sys/_types.h</label>
        <link refid="__types_8h"/>
      </node>
      <node id="4603">
        <label>stddef.h</label>
      </node>
      <node id="4606">
        <label>string.h</label>
        <link refid="string_8h"/>
        <childnode refid="4607" relation="include">
        </childnode>
      </node>
      <node id="4620">
        <label>btreeheader.h</label>
        <link refid="btreeheader_8h"/>
      </node>
      <node id="4618">
        <label>file.h</label>
        <link refid="ubixfsv2_2file_8h"/>
        <childnode refid="4611" relation="include">
        </childnode>
      </node>
      <node id="4612">
        <label>sys/types.h</label>
      </node>
      <node id="4613">
        <label>fsAbstract.h</label>
        <link refid="fsAbstract_8h"/>
        <childnode refid="4614" relation="include">
        </childnode>
        <childnode refid="4615" relation="include">
        </childnode>
        <childnode refid="4612" relation="include">
        </childnode>
        <childnode refid="4616" relation="include">
        </childnode>
        <childnode refid="4618" relation="include">
        </childnode>
      </node>
      <node id="4617">
        <label>types.h</label>
        <link refid="ubixfsv2_2types_8h"/>
      </node>
      <node id="4605">
        <label>unistd.h</label>
      </node>
      <node id="4616">
        <label>device.h</label>
        <link refid="ubixfsv2_2device_8h"/>
        <childnode refid="4612" relation="include">
        </childnode>
        <childnode refid="4617" relation="include">
        </childnode>
      </node>
      <node id="4609">
        <label>assert.h</label>
        <link refid="assert_8h"/>
      </node>
      <node id="4610">
        <label>iostream</label>
      </node>
      <node id="4614">
        <label>stdio.h</label>
      </node>
      <node id="4615">
        <label>dirent.h</label>
      </node>
    </incdepgraph>
    <briefdescription>
    </briefdescription>
    <detaileddescription>
    </detaileddescription>
    <programlisting>
<codeline lineno="1"><highlight class="preprocessor">#include<sp/>&lt;stddef.h&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="2"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;stdlib.h&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="3"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;unistd.h&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="4"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;<ref refid="string_8h" kindref="compound">string.h</ref>&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="5"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;<ref refid="assert_8h" kindref="compound">assert.h</ref>&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="6"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;iostream&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="7"><highlight class="normal"></highlight></codeline>
<codeline lineno="8"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;<ref refid="ubixfsv2_2ubixfs_8h" kindref="compound">ubixfs.h</ref>&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="9"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;<ref refid="btree_8h" kindref="compound">btree.h</ref>&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="10"><highlight class="normal"></highlight></codeline>
<codeline lineno="11"><highlight class="normal"></highlight><highlight class="keyword">using<sp/>namespace<sp/></highlight><highlight class="normal">std;</highlight></codeline>
<codeline lineno="12"><highlight class="normal"></highlight></codeline>
<codeline lineno="13" refid="classUbixFS_1a8411daf956e8ba4e129b3f26d7ecb45" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1a8411daf956e8ba4e129b3f26d7ecb45" kindref="member">UbixFS::UbixFS</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">)<sp/>{<sp/></highlight></codeline>
<codeline lineno="14"><highlight class="normal"><sp/><sp/><ref refid="structdevice" kindref="compound">device</ref><sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="15"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="16"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref><sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="17"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref><sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="18"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::UbixFS</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="19"><highlight class="normal"></highlight></codeline>
<codeline lineno="20"><highlight class="normal"></highlight></codeline>
<codeline lineno="21" refid="classUbixFS_115d6d564145f65baba56b5e721a72c8b" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1a8411daf956e8ba4e129b3f26d7ecb45" kindref="member">UbixFS::UbixFS</ref>(<ref refid="structdevice__t" kindref="compound">device_t</ref><sp/>*<sp/><ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>)<sp/>{</highlight></codeline>
<codeline lineno="22"><highlight class="normal"><sp/><sp/><ref refid="structdevice" kindref="compound">device</ref><sp/>=<sp/><ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>;</highlight></codeline>
<codeline lineno="23"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="24"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref><sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="25"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref><sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="26"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::UbixFS</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="27"><highlight class="normal"></highlight></codeline>
<codeline lineno="28"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="29" refid="classUbixFS_12303eac53dcf539ad1db595b09e1568a" refkind="member"><highlight class="normal"><ref refid="classUbixFS_12303eac53dcf539ad1db595b09e1568a" kindref="member">UbixFS::printSuperBlock</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="30"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;name...........<sp/>%s\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;name);</highlight></codeline>
<codeline lineno="31"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;magic1.........<sp/>%X\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;magic1);</highlight></codeline>
<codeline lineno="32"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;fsByteOrder....<sp/>%d\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;fsByteOrder);</highlight></codeline>
<codeline lineno="33"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;blockSize......<sp/>%d\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blockSize);</highlight></codeline>
<codeline lineno="34"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;blockShift.....<sp/>%d\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blockShift);</highlight></codeline>
<codeline lineno="35"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;numBlocks......<sp/>%lld\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;numBlocks);</highlight></codeline>
<codeline lineno="36"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;usedBlocks.....<sp/>%lld\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;usedBlocks);</highlight></codeline>
<codeline lineno="37"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;batSectors.....<sp/>%d\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;batSectors);</highlight></codeline>
<codeline lineno="38"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;inodeCount.....<sp/>%d\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;inodeCount);</highlight></codeline>
<codeline lineno="39"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;magic2.........<sp/>%X\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;magic2);</highlight></codeline>
<codeline lineno="40"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;blocksPerAG....<sp/>%d\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blocksPerAG);</highlight></codeline>
<codeline lineno="41"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;AGShift........<sp/>%d\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;AGShift);</highlight></codeline>
<codeline lineno="42"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;numAGs.........<sp/>%d\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;numAGs);</highlight></codeline>
<codeline lineno="43"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;lastUsedAG.....<sp/>%d\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;lastUsedAG);</highlight></codeline>
<codeline lineno="44"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;flags..........<sp/>%X\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;flags);</highlight></codeline>
<codeline lineno="45"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;superBlock-&gt;magic3.........<sp/>%X\n&quot;</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;magic3);</highlight></codeline>
<codeline lineno="46"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="47"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::printSuperBlock</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="48"><highlight class="normal"></highlight></codeline>
<codeline lineno="49"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/></highlight></codeline>
<codeline lineno="50" refid="classUbixFS_1148aae4eb2ceb35ffcad9ff22b2f7309" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1148aae4eb2ceb35ffcad9ff22b2f7309" kindref="member">UbixFS::vfs_init</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="51"><highlight class="normal"><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="structdevice" kindref="compound">device</ref>);</highlight></codeline>
<codeline lineno="52"><highlight class="normal"><sp/><sp/><ref refid="include_2ubixos_2types_8h_17619b847aeded8a6d14cbfa212b2cdfb" kindref="member">size_t</ref><sp/>result;</highlight></codeline>
<codeline lineno="53"><highlight class="normal"><sp/><sp/>cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;vfs_init()&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="54"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="structdevice" kindref="compound">device</ref>);</highlight></codeline>
<codeline lineno="55"><highlight class="normal"></highlight></codeline>
<codeline lineno="56"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structdevice" kindref="compound">device</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="57"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref><sp/>!=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal"><sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>;</highlight></codeline>
<codeline lineno="58"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref><sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structdiskSuperBlock" kindref="compound">diskSuperBlock</ref>;</highlight></codeline>
<codeline lineno="59"><highlight class="normal"><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>);</highlight></codeline>
<codeline lineno="60"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="61"><highlight class="normal"></highlight></codeline>
<codeline lineno="62"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>read<sp/>in<sp/>the<sp/>superBlock.<sp/>It&apos;s<sp/>always<sp/>the<sp/>last<sp/>block<sp/>on<sp/>the<sp/>partition<sp/></highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="63"><highlight class="normal">cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;reading<sp/>in<sp/>superBlock&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="64"><highlight class="normal"><sp/><sp/><ref refid="structdevice" kindref="compound">device</ref>-&gt;read(<ref refid="structdevice" kindref="compound">device</ref>,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>,<sp/><ref refid="structdevice" kindref="compound">device</ref>-&gt;sectors-1,<sp/>1);</highlight></codeline>
<codeline lineno="65"><highlight class="normal">cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;done&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="66"><highlight class="normal"></highlight></codeline>
<codeline lineno="67"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;magic1<sp/>==<sp/><ref refid="ubixfsv2_2ubixfs_8h_1b5c389bfe61bb5707916f2ac6d4d0c6a" kindref="member">UBIXFS_MAGIC1</ref>);</highlight></codeline>
<codeline lineno="68"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;magic2<sp/>==<sp/><ref refid="ubixfsv2_2ubixfs_8h_15dd83bc90fdb21a43a412d90b99f5704" kindref="member">UBIXFS_MAGIC2</ref>);</highlight></codeline>
<codeline lineno="69"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;magic3<sp/>==<sp/><ref refid="ubixfsv2_2ubixfs_8h_17bc7bdfbc69287525c62286f77443b97" kindref="member">UBIXFS_MAGIC3</ref>);</highlight></codeline>
<codeline lineno="70"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="lib_2string_8h_16f3dcb20ff11ff9db5904c3cfb61a38c" kindref="member">strcmp</ref>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;name,<sp/></highlight><highlight class="stringliteral">&quot;UbixFS&quot;</highlight><highlight class="normal">)<sp/>==<sp/>0);</highlight></codeline>
<codeline lineno="71"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>((1<sp/>&lt;&lt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blockShift)<sp/>==<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blockSize);</highlight></codeline>
<codeline lineno="72"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>((</highlight><highlight class="keywordtype">unsigned</highlight><highlight class="normal">)(1<sp/>&lt;&lt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;AGShift)<sp/>==<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blocksPerAG);</highlight></codeline>
<codeline lineno="73"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;flags<sp/>==<sp/><ref refid="ubixfsv2_2ubixfs_8h_149a8f9142d94b4472956c6d8f446d2ce" kindref="member">UBIXFS_CLEAN</ref>);</highlight></codeline>
<codeline lineno="74"><highlight class="normal"></highlight></codeline>
<codeline lineno="75"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>!=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal"><sp/>[]<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref>;</highlight></codeline>
<codeline lineno="76"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">signed</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal">[<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;batSectors*512];</highlight></codeline>
<codeline lineno="77"><highlight class="normal"><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref>);</highlight></codeline>
<codeline lineno="78"><highlight class="normal"><sp/><sp/><ref refid="lib_2string_8h_1ce4b911463887af5e748326323e99a23" kindref="member">memset</ref>(<ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref>,<sp/>0,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;batSectors*512);</highlight></codeline>
<codeline lineno="79"><highlight class="normal"></highlight></codeline>
<codeline lineno="80"><highlight class="normal"><sp/><sp/><ref refid="structdevice" kindref="compound">device</ref>-&gt;read(<ref refid="structdevice" kindref="compound">device</ref>,<sp/></highlight></codeline>
<codeline lineno="81"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref>,<sp/></highlight></codeline>
<codeline lineno="82"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structdevice" kindref="compound">device</ref>-&gt;sectors<sp/>-<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;batSectors-1,</highlight></codeline>
<codeline lineno="83"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;batSectors</highlight></codeline>
<codeline lineno="84"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>);<sp/></highlight><highlight class="comment">//<sp/>device-&gt;read()</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="85"><highlight class="normal"></highlight></codeline>
<codeline lineno="86"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref><sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structfileDescriptor" kindref="compound">fileDescriptor</ref>;</highlight></codeline>
<codeline lineno="87"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref>);</highlight></codeline>
<codeline lineno="88"><highlight class="normal"><sp/><sp/><ref refid="lib_2string_8h_1ce4b911463887af5e748326323e99a23" kindref="member">memset</ref>(<ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref>,<sp/>0,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structfileDescriptor" kindref="compound">fileDescriptor</ref>));</highlight></codeline>
<codeline lineno="89"><highlight class="normal">cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;allocating<sp/>root<sp/>dir<sp/>inode&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="90"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref>-&gt;<ref refid="structfileDescriptor_1d6e69b4726ce93464490201390a9d922" kindref="member">inode</ref><sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref>;</highlight></codeline>
<codeline lineno="91"><highlight class="normal"><sp/><sp/><ref refid="lib_2string_8h_1ce4b911463887af5e748326323e99a23" kindref="member">memset</ref>(<ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref>-&gt;<ref refid="structfileDescriptor_1d6e69b4726ce93464490201390a9d922" kindref="member">inode</ref>,<sp/>0,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref>));</highlight></codeline>
<codeline lineno="92"><highlight class="normal">cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;root<sp/>dir<sp/>inode<sp/>starting<sp/>sector:<sp/>&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/></highlight></codeline>
<codeline lineno="93"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>((<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;rootDir.AG<sp/>&lt;&lt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;AGShift)<sp/></highlight></codeline>
<codeline lineno="94"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>+<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;rootDir.start)<sp/>*<sp/>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blockSize<sp/>/<sp/>512)</highlight></codeline>
<codeline lineno="95"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="96"><highlight class="normal"></highlight></codeline>
<codeline lineno="97"><highlight class="normal">cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;reading<sp/>in<sp/>root<sp/>dir<sp/>inode&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="98"><highlight class="normal"><sp/><sp/></highlight></codeline>
<codeline lineno="99"><highlight class="normal"><sp/><sp/><ref refid="structdevice" kindref="compound">device</ref>-&gt;read(<ref refid="structdevice" kindref="compound">device</ref>,</highlight></codeline>
<codeline lineno="100"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref>-&gt;<ref refid="structfileDescriptor_1d6e69b4726ce93464490201390a9d922" kindref="member">inode</ref>,</highlight></codeline>
<codeline lineno="101"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>((<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;rootDir.AG<sp/>&lt;&lt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;AGShift)<sp/></highlight></codeline>
<codeline lineno="102"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>+<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;rootDir.start)<sp/>*<sp/>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blockSize<sp/>/<sp/>512),</highlight></codeline>
<codeline lineno="103"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(ubixfsInode)<sp/>/<sp/>512</highlight></codeline>
<codeline lineno="104"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>);</highlight></codeline>
<codeline lineno="105"><highlight class="normal">cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;done&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="106"><highlight class="normal"><sp/><sp/>ubixfsInode<sp/>*<sp/>rootInode<sp/>=<sp/>static_cast&lt;ubixfsInode<sp/>*&gt;(<ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref>-&gt;<ref refid="structfileDescriptor_1d6e69b4726ce93464490201390a9d922" kindref="member">inode</ref>);</highlight></codeline>
<codeline lineno="107"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(rootInode);</highlight></codeline>
<codeline lineno="108"><highlight class="normal"></highlight></codeline>
<codeline lineno="109"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*<sp/>the<sp/>bTree<sp/>constructor<sp/>now<sp/>loads<sp/>in<sp/>the<sp/>header<sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="110"><highlight class="normal"></highlight></codeline>
<codeline lineno="111"><highlight class="normal"><sp/><sp/>rootInode-&gt;data.btPtr<sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="classUbixFS_1d8e9bf5a5c42eabcce4ea4ab71c95528" kindref="member">bTree</ref>(</highlight><highlight class="keyword">this</highlight><highlight class="normal">,<sp/><ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref>);</highlight></codeline>
<codeline lineno="112"><highlight class="normal"><sp/><sp/>rootInode-&gt;data.btPtr-&gt;Info();</highlight></codeline>
<codeline lineno="113"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_12303eac53dcf539ad1db595b09e1568a" kindref="member">printSuperBlock</ref>();</highlight></codeline>
<codeline lineno="114"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="115"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::init</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="116"><highlight class="normal"></highlight></codeline>
<codeline lineno="117"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="118" refid="classUbixFS_1e1266337d259778b1404601184d75028" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1e1266337d259778b1404601184d75028" kindref="member">UbixFS::vfs_format</ref>(<ref refid="structdevice__t" kindref="compound">device_t</ref><sp/>*<sp/><ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>)<sp/>{</highlight></codeline>
<codeline lineno="119"><highlight class="normal"><sp/><sp/>cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;vfs_format()&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="120"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>sector[512];</highlight></codeline>
<codeline lineno="121"><highlight class="normal"><sp/><sp/><ref refid="include_2ubixos_2types_8h_15847ea0262a5aa61eee48cbe95544a78" kindref="member">uInt32</ref><sp/>blocks,<sp/>batSect,<sp/>batSize;</highlight></codeline>
<codeline lineno="122"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;<sp/></highlight></codeline>
<codeline lineno="123"><highlight class="normal"></highlight></codeline>
<codeline lineno="124"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>zero<sp/>out<sp/>the<sp/>sector</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="125"><highlight class="normal"><sp/><sp/><ref refid="lib_2string_8h_1ce4b911463887af5e748326323e99a23" kindref="member">memset</ref>(&amp;sector,<sp/>0x0,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(sector));</highlight></codeline>
<codeline lineno="126"><highlight class="normal"><sp/></highlight></codeline>
<codeline lineno="127"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>fill<sp/>the<sp/>drive<sp/>in<sp/>with<sp/>zeroed<sp/>out<sp/>sectors</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="128"><highlight class="normal"><sp/><sp/>cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;dev-&gt;sectors:<sp/>&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/><ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>-&gt;sectors<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="129"><highlight class="normal"><sp/><sp/>cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;clearing<sp/>device...&quot;</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="130"><highlight class="normal"></highlight></codeline>
<codeline lineno="131"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keywordtype">unsigned</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/><ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>-&gt;sectors;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="132"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>-&gt;write(<ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>,<sp/>&amp;sector,<sp/>i,<sp/>1);</highlight></codeline>
<codeline lineno="133"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>for<sp/>i</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="134"><highlight class="normal"></highlight></codeline>
<codeline lineno="135"><highlight class="normal"><sp/><sp/>cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;done&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="136"><highlight class="normal"></highlight></codeline>
<codeline lineno="137"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>allocate<sp/>a<sp/>new<sp/>superBlock<sp/>and<sp/>clear<sp/>it</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="138"><highlight class="normal"></highlight></codeline>
<codeline lineno="139"><highlight class="normal"><sp/><sp/><ref refid="structdiskSuperBlock" kindref="compound">diskSuperBlock</ref><sp/>*sb<sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structdiskSuperBlock" kindref="compound">diskSuperBlock</ref>;</highlight></codeline>
<codeline lineno="140"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(sb<sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="141"><highlight class="normal"><sp/><sp/><ref refid="lib_2string_8h_1ce4b911463887af5e748326323e99a23" kindref="member">memset</ref>(sb,<sp/>0,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structdiskSuperBlock" kindref="compound">diskSuperBlock</ref>));</highlight></codeline>
<codeline lineno="142"><highlight class="normal"></highlight></codeline>
<codeline lineno="143"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>dev-&gt;sectors<sp/>is<sp/>the<sp/>number<sp/>of<sp/>512<sp/>byte<sp/>sectors</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="144"><highlight class="normal"></highlight></codeline>
<codeline lineno="145"><highlight class="normal"><sp/><sp/>blocks<sp/>=<sp/>(<ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>-&gt;sectors-1)<sp/>/<sp/>8;<sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>4k<sp/>blocks</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="146"><highlight class="normal"><sp/><sp/>batSize<sp/>=<sp/>(<ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>-&gt;sectors-1)<sp/>%<sp/>8;<sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>remainder</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="147"><highlight class="normal"><sp/><sp/></highlight></codeline>
<codeline lineno="148"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>compute<sp/>the<sp/>BAT<sp/>size</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="149"><highlight class="normal"></highlight></codeline>
<codeline lineno="150"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>((batSize<sp/>*<sp/>4096)<sp/>&lt;<sp/>blocks)<sp/>{</highlight></codeline>
<codeline lineno="151"><highlight class="normal"><sp/><sp/><sp/><sp/>batSize<sp/>+=<sp/>8;</highlight></codeline>
<codeline lineno="152"><highlight class="normal"><sp/><sp/><sp/><sp/>--blocks;</highlight></codeline>
<codeline lineno="153"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>while</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="154"><highlight class="normal"><sp/></highlight></codeline>
<codeline lineno="155"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>batSize<sp/>is<sp/>in<sp/>sectors</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="156"><highlight class="normal"><sp/><sp/>batSect<sp/>=<sp/>blocks<sp/>*<sp/>8;</highlight></codeline>
<codeline lineno="157"><highlight class="normal"></highlight></codeline>
<codeline lineno="158"><highlight class="normal"><sp/><sp/><ref refid="strcpy_8S_19132520cc79236b654666f4ddc1b516c" kindref="member">strcpy</ref>(sb-&gt;name,<sp/></highlight><highlight class="stringliteral">&quot;UbixFS&quot;</highlight><highlight class="normal">);</highlight></codeline>
<codeline lineno="159"><highlight class="normal"><sp/><sp/>sb-&gt;magic1<sp/>=<sp/><ref refid="ubixfsv2_2ubixfs_8h_1b5c389bfe61bb5707916f2ac6d4d0c6a" kindref="member">UBIXFS_MAGIC1</ref>;</highlight></codeline>
<codeline lineno="160"><highlight class="normal"><sp/><sp/>sb-&gt;fsByteOrder<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="161"><highlight class="normal"><sp/><sp/>sb-&gt;blockSize<sp/>=<sp/>4096;</highlight></codeline>
<codeline lineno="162"><highlight class="normal"><sp/><sp/>sb-&gt;blockShift<sp/>=<sp/>12;</highlight></codeline>
<codeline lineno="163"><highlight class="normal"><sp/><sp/>sb-&gt;numBlocks<sp/>=<sp/>blocks;</highlight></codeline>
<codeline lineno="164"><highlight class="normal"><sp/><sp/>sb-&gt;usedBlocks<sp/>=<sp/>2;<sp/><sp/></highlight><highlight class="comment">//<sp/>root<sp/>dir<sp/>takes<sp/>two<sp/>blocks<sp/>(inode<sp/>+<sp/>bTree<sp/>header)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="165"><highlight class="normal"><sp/><sp/>sb-&gt;inodeCount<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="166"><highlight class="normal"><sp/><sp/>sb-&gt;inodeSize<sp/>=<sp/>4096;</highlight></codeline>
<codeline lineno="167"><highlight class="normal"><sp/><sp/>sb-&gt;magic2<sp/>=<sp/><ref refid="ubixfsv2_2ubixfs_8h_15dd83bc90fdb21a43a412d90b99f5704" kindref="member">UBIXFS_MAGIC2</ref>;</highlight></codeline>
<codeline lineno="168"><highlight class="normal"><sp/><sp/>sb-&gt;blocksPerAG<sp/>=<sp/>2048;</highlight></codeline>
<codeline lineno="169"><highlight class="normal"><sp/><sp/>sb-&gt;AGShift<sp/>=<sp/>11;</highlight></codeline>
<codeline lineno="170"><highlight class="normal"><sp/><sp/>sb-&gt;numAGs<sp/>=<sp/>(sb-&gt;numBlocks+2047)<sp/>/<sp/>2048;</highlight></codeline>
<codeline lineno="171"><highlight class="normal"><sp/><sp/>sb-&gt;lastUsedAG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="172"><highlight class="normal"></highlight></codeline>
<codeline lineno="173"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>the<sp/>BAT<sp/>exists<sp/>outside<sp/>our<sp/>official<sp/>block<sp/>count,<sp/>so<sp/>no<sp/></highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="174"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>entries<sp/>in<sp/>the<sp/>BAT<sp/>need<sp/>to<sp/>be<sp/>set<sp/>for<sp/>it</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="175"><highlight class="normal"><sp/><sp/>sb-&gt;batSectors<sp/>=<sp/>batSize;</highlight></codeline>
<codeline lineno="176"><highlight class="normal"></highlight></codeline>
<codeline lineno="177"><highlight class="normal"><sp/><sp/>sb-&gt;flags<sp/>=<sp/>0x434C454E;<sp/></highlight><highlight class="comment">//<sp/>CLEN</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="178"><highlight class="normal"><sp/><sp/>sb-&gt;logBlocks.AG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="179"><highlight class="normal"><sp/><sp/>sb-&gt;logBlocks.start<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="180"><highlight class="normal"><sp/><sp/>sb-&gt;logBlocks.len<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="181"><highlight class="normal"><sp/><sp/>sb-&gt;logStart<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="182"><highlight class="normal"><sp/><sp/>sb-&gt;logEnd<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="183"><highlight class="normal"><sp/><sp/>sb-&gt;magic3<sp/>=<sp/><ref refid="ubixfsv2_2ubixfs_8h_17bc7bdfbc69287525c62286f77443b97" kindref="member">UBIXFS_MAGIC3</ref>;</highlight></codeline>
<codeline lineno="184"><highlight class="normal"><sp/><sp/>sb-&gt;indicies.AG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="185"><highlight class="normal"><sp/><sp/>sb-&gt;indicies.start<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="186"><highlight class="normal"><sp/><sp/>sb-&gt;indicies.len<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="187"><highlight class="normal"></highlight></codeline>
<codeline lineno="188"><highlight class="normal"><sp/><sp/>sb-&gt;rootDir.AG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="189"><highlight class="normal"><sp/><sp/>sb-&gt;rootDir.start<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="190"><highlight class="normal"><sp/><sp/>sb-&gt;rootDir.len<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="191"><highlight class="normal"></highlight></codeline>
<codeline lineno="192"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>write<sp/>out<sp/>the<sp/>superBlock</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="193"><highlight class="normal"></highlight></codeline>
<codeline lineno="194"><highlight class="normal"><sp/><sp/><ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>-&gt;write(<ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>,<sp/>sb,<sp/><ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>-&gt;sectors-1,<sp/>1);</highlight></codeline>
<codeline lineno="195"><highlight class="normal"></highlight></codeline>
<codeline lineno="196"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>mark<sp/>the<sp/>first<sp/>two<sp/>4k<sp/>blocks<sp/>used</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="197"><highlight class="normal"><sp/><sp/><ref refid="lib_2string_8h_1ce4b911463887af5e748326323e99a23" kindref="member">memset</ref>(&amp;sector,<sp/>0,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(sector));</highlight></codeline>
<codeline lineno="198"><highlight class="normal"><sp/><sp/>sector[0]<sp/>=<sp/>(1<sp/>&lt;&lt;<sp/>7)<sp/>|<sp/>(1<sp/>&lt;&lt;<sp/>6);</highlight></codeline>
<codeline lineno="199"><highlight class="normal"></highlight></codeline>
<codeline lineno="200"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>write<sp/>out<sp/>the<sp/>first<sp/>sector<sp/>of<sp/>the<sp/>BAT<sp/></highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="201"><highlight class="normal"></highlight></codeline>
<codeline lineno="202"><highlight class="normal"><sp/><sp/><ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>-&gt;write(<ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>,<sp/>&amp;sector,<sp/>batSect,<sp/>1);</highlight></codeline>
<codeline lineno="203"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>clear<sp/>the<sp/>rest</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="204"><highlight class="normal"><sp/><sp/>sector[0]<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="205"><highlight class="normal"></highlight></codeline>
<codeline lineno="206"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>write<sp/>out<sp/>the<sp/>rest<sp/>of<sp/>the<sp/>BAT</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="207"><highlight class="normal"></highlight></codeline>
<codeline lineno="208"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keywordtype">unsigned</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i<sp/>=<sp/>1;<sp/>i<sp/>&lt;<sp/>batSize;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="209"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>-&gt;write(<ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>,<sp/>&amp;sector,<sp/>(batSect)+i,<sp/>1);</highlight></codeline>
<codeline lineno="210"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>for<sp/>i</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="211"><highlight class="normal"></highlight></codeline>
<codeline lineno="212"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*<sp/>allocate<sp/>part<sp/>of<sp/>the<sp/>root<sp/>dir<sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="213"><highlight class="normal"></highlight></codeline>
<codeline lineno="214"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>sanity<sp/>checks</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="215"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(sb-&gt;blockSize);</highlight></codeline>
<codeline lineno="216"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>((</highlight><highlight class="keywordtype">unsigned</highlight><highlight class="normal">)sb-&gt;blockSize<sp/>&gt;=<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structbTreeHeader" kindref="compound">bTreeHeader</ref>));</highlight></codeline>
<codeline lineno="217"><highlight class="normal"></highlight></codeline>
<codeline lineno="218"><highlight class="normal"><sp/><sp/>bTreeHeader<sp/>*<sp/>bth<sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/>bTreeHeader;</highlight></codeline>
<codeline lineno="219"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(bth);</highlight></codeline>
<codeline lineno="220"><highlight class="normal"><sp/><sp/><ref refid="lib_2string_8h_1ce4b911463887af5e748326323e99a23" kindref="member">memset</ref>(bth,<sp/>0,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(bTreeHeader));</highlight></codeline>
<codeline lineno="221"><highlight class="normal"></highlight></codeline>
<codeline lineno="222"><highlight class="normal"><sp/><sp/>bth-&gt;<ref refid="structbTreeHeader_160d3496f588d01ff12f9e74288494f3b" kindref="member">firstDeleted</ref><sp/>=<sp/>-1;</highlight></codeline>
<codeline lineno="223"><highlight class="normal"><sp/><sp/>bth-&gt;<ref refid="structbTreeHeader_1fa2951c3806f5b1990da9f4f34d9fc10" kindref="member">firstNodeOffset</ref><sp/>=<sp/>-1;</highlight></codeline>
<codeline lineno="224"><highlight class="normal"><sp/><sp/>bth-&gt;<ref refid="structbTreeHeader_1ca6e142166a274565291bc425b80549f" kindref="member">treeDepth</ref><sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="225"><highlight class="normal"><sp/><sp/>bth-&gt;<ref refid="structbTreeHeader_1d072fd3a177d2aa12a2ff3ebf1ccbcb7" kindref="member">treeWidth</ref><sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="226"><highlight class="normal"><sp/><sp/>bth-&gt;<ref refid="structbTreeHeader_1a9518218d48b68f08aa2406268faf8da" kindref="member">treeLeafCount</ref><sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="227"><highlight class="normal"></highlight></codeline>
<codeline lineno="228"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*<sp/>create<sp/>the<sp/>root<sp/>dir<sp/>inode<sp/>here<sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="229"><highlight class="normal"></highlight></codeline>
<codeline lineno="230"><highlight class="normal"><sp/><sp/><ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref><sp/>*<sp/>inode<sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref>;</highlight></codeline>
<codeline lineno="231"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(inode);</highlight></codeline>
<codeline lineno="232"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(inode<sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="233"><highlight class="normal"><sp/><sp/><ref refid="lib_2string_8h_1ce4b911463887af5e748326323e99a23" kindref="member">memset</ref>(inode,<sp/>0,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref>));</highlight></codeline>
<codeline lineno="234"><highlight class="normal"></highlight></codeline>
<codeline lineno="235"><highlight class="normal"><sp/><sp/>inode-&gt;magic1<sp/>=<sp/><ref refid="ubixfsv2_2ubixfs_8h_1c88e98d44093495af57d4a956b095b9d" kindref="member">UBIXFS_INODE_MAGIC</ref>;</highlight></codeline>
<codeline lineno="236"><highlight class="normal"></highlight></codeline>
<codeline lineno="237"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>inodes<sp/>point<sp/>to<sp/>themselves</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="238"><highlight class="normal"><sp/><sp/>inode-&gt;inodeNum.AG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="239"><highlight class="normal"><sp/><sp/>inode-&gt;inodeNum.start<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="240"><highlight class="normal"><sp/><sp/>inode-&gt;inodeNum.len<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="241"><highlight class="normal"></highlight></codeline>
<codeline lineno="242"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>root<sp/>dir<sp/>has<sp/>no<sp/>parent<sp/>directory</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="243"><highlight class="normal"><sp/><sp/>inode-&gt;parent.iAddr.AG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="244"><highlight class="normal"><sp/><sp/>inode-&gt;parent.iAddr.start<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="245"><highlight class="normal"><sp/><sp/>inode-&gt;parent.iAddr.len<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="246"><highlight class="normal"></highlight></codeline>
<codeline lineno="247"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*<sp/>this<sp/>is<sp/>part<sp/>of<sp/>the<sp/>root<sp/>dir<sp/>structure<sp/>(the<sp/>bTreeHeader)<sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="248"><highlight class="normal"><sp/><sp/>inode-&gt;blocks.direct[0].AG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="249"><highlight class="normal"><sp/><sp/>inode-&gt;blocks.direct[0].start<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="250"><highlight class="normal"><sp/><sp/>inode-&gt;blocks.direct[0].len<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="251"><highlight class="normal"><sp/><sp/><sp/></highlight></codeline>
<codeline lineno="252"><highlight class="normal"><sp/><sp/>inode-&gt;blocks.maxDirectRange<sp/>=<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(bTreeHeader);</highlight></codeline>
<codeline lineno="253"><highlight class="normal"><sp/><sp/>inode-&gt;blocks.size<sp/>=<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(bTreeHeader);</highlight></codeline>
<codeline lineno="254"><highlight class="normal"></highlight></codeline>
<codeline lineno="255"><highlight class="normal"><sp/><sp/><ref refid="strcpy_8S_19132520cc79236b654666f4ddc1b516c" kindref="member">strcpy</ref>(inode-&gt;name,<sp/></highlight><highlight class="stringliteral">&quot;/&quot;</highlight><highlight class="normal">);</highlight></codeline>
<codeline lineno="256"><highlight class="normal"><sp/><sp/>inode-&gt;uid<sp/>=<sp/><ref refid="gen__calls_8h_1b2bf044f6f20a60f7c4139b527c4bd6c" kindref="member">getuid</ref>();</highlight></codeline>
<codeline lineno="257"><highlight class="normal"><sp/><sp/>inode-&gt;gid<sp/>=<sp/><ref refid="gen__calls_8h_1d78d6c02154727f556f78cca62020c83" kindref="member">getgid</ref>();</highlight></codeline>
<codeline lineno="258"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>inode-&gt;mode</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="259"><highlight class="normal"><sp/><sp/>inode-&gt;flags<sp/>=<sp/><ref refid="ubixfsv2_2ubixfs_8h_103a6b271b2413595574aab2babfa1460" kindref="member">INODE_DIRECTORY</ref>;</highlight></codeline>
<codeline lineno="260"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>inode-&gt;createTime</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="261"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>inode-&gt;lastModifiedTime</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="262"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>inode-&gt;type</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="263"><highlight class="normal"></highlight></codeline>
<codeline lineno="264"><highlight class="normal"><sp/><sp/>inode-&gt;attributes.AG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="265"><highlight class="normal"><sp/><sp/>inode-&gt;attributes.start<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="266"><highlight class="normal"><sp/><sp/>inode-&gt;attributes.len<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="267"><highlight class="normal"></highlight></codeline>
<codeline lineno="268"><highlight class="normal"><sp/><sp/>inode-&gt;inodeSize<sp/>=<sp/>sb-&gt;inodeSize;</highlight></codeline>
<codeline lineno="269"><highlight class="normal"></highlight></codeline>
<codeline lineno="270"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="271"><highlight class="comment"><sp/><sp/><sp/>*<sp/>next<sp/>and<sp/>prev<sp/>are<sp/>used<sp/>in<sp/>memory<sp/>to<sp/>hold<sp/>pointers<sp/>to<sp/>the<sp/>next/prev</highlight></codeline>
<codeline lineno="272"><highlight class="comment"><sp/><sp/><sp/>*<sp/>inodes<sp/>in<sp/>this<sp/>dir.<sp/><sp/>On<sp/>disk<sp/>they<sp/>may<sp/>have<sp/>another<sp/>value,<sp/>but<sp/>for</highlight></codeline>
<codeline lineno="273"><highlight class="comment"><sp/><sp/><sp/>*<sp/>now<sp/>they<sp/>should<sp/>be<sp/>set<sp/>to<sp/>null.</highlight></codeline>
<codeline lineno="274"><highlight class="comment"><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="275"><highlight class="normal"></highlight></codeline>
<codeline lineno="276"><highlight class="normal"><sp/><sp/>inode-&gt;next.offset<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="277"><highlight class="normal"><sp/><sp/>inode-&gt;prev.offset<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="278"><highlight class="normal"></highlight></codeline>
<codeline lineno="279"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>write<sp/>out<sp/>the<sp/>&quot;root&quot;<sp/>dir<sp/>inode</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="280"><highlight class="normal"></highlight></codeline>
<codeline lineno="281"><highlight class="normal"><sp/><sp/><ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>-&gt;write(<ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>,<sp/></highlight></codeline>
<codeline lineno="282"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode,<sp/></highlight></codeline>
<codeline lineno="283"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>((inode-&gt;inodeNum.AG<sp/>&lt;&lt;<sp/>sb-&gt;AGShift)<sp/>+</highlight></codeline>
<codeline lineno="284"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;inodeNum.start)<sp/>*<sp/>(sb-&gt;blockSize<sp/>/<sp/>512),</highlight></codeline>
<codeline lineno="285"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sb-&gt;inodeSize<sp/>/<sp/>512</highlight></codeline>
<codeline lineno="286"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>);<sp/></highlight><highlight class="comment">//<sp/>dev-&gt;write</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="287"><highlight class="normal"></highlight></codeline>
<codeline lineno="288"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>write<sp/>out<sp/>the<sp/>&quot;root&quot;<sp/>dir</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="289"><highlight class="normal"></highlight></codeline>
<codeline lineno="290"><highlight class="normal"><sp/><sp/><ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>-&gt;write(<ref refid="ethernetif_8c_1cf6a82c73e7a9d99293d9ce0b8837faf" kindref="member">dev</ref>,<sp/></highlight></codeline>
<codeline lineno="291"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>bth,<sp/></highlight></codeline>
<codeline lineno="292"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>((inode-&gt;blocks.direct[0].AG<sp/>&lt;&lt;<sp/>sb-&gt;AGShift)<sp/>+<sp/></highlight></codeline>
<codeline lineno="293"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;blocks.direct[0].start)<sp/>*<sp/>(sb-&gt;blockSize<sp/>/<sp/>512),</highlight></codeline>
<codeline lineno="294"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sb-&gt;blockSize<sp/>/<sp/>512</highlight></codeline>
<codeline lineno="295"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>);<sp/></highlight><highlight class="comment">//<sp/>dev-&gt;write</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="296"><highlight class="normal"></highlight></codeline>
<codeline lineno="297"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal"><sp/>inode;</highlight></codeline>
<codeline lineno="298"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal"><sp/>bth;</highlight></codeline>
<codeline lineno="299"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal"><sp/>sb;</highlight></codeline>
<codeline lineno="300"><highlight class="normal"><sp/><sp/>cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;format<sp/>complete&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="301"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="302"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::vfs_format</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="303"><highlight class="normal"></highlight></codeline>
<codeline lineno="304"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*</highlight></codeline>
<codeline lineno="305" refid="classUbixFS_1b1422145c6575f723179b60421a494aa" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1b1422145c6575f723179b60421a494aa" kindref="member">UbixFS::vfs_mknod</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*path,<sp/><ref refid="kern__descrip_8h_1e9f148ba55d84268ecb6f8031ab45076" kindref="member">mode_t</ref><sp/>mode)<sp/>{</highlight></codeline>
<codeline lineno="306"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="classUbixFS_194e296e37c8176b5f5ba88a2251b70ab" kindref="member">mknod</ref>(path,<sp/>0,<sp/>mode);<sp/><sp/></highlight><highlight class="comment">//<sp/>&lt;-<sp/>this<sp/>probably<sp/>isn&apos;t<sp/>correct</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="307"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::vfs_mknod</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="308"><highlight class="normal"></highlight></codeline>
<codeline lineno="309"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="310" refid="classUbixFS_1d3e28ccdb5cd84d63e5d6e9db2fc3e65" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1d3e28ccdb5cd84d63e5d6e9db2fc3e65" kindref="member">UbixFS::vfs_open</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*<sp/>filename,<sp/><ref refid="structfileDescriptor" kindref="compound">fileDescriptor</ref><sp/>*<sp/>fd,<sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>flags,<sp/>...)<sp/>{</highlight></codeline>
<codeline lineno="311"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(filename<sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/>fd<sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="312"><highlight class="normal"><sp/><sp/>flags<sp/>=<sp/>flags;</highlight></codeline>
<codeline lineno="313"><highlight class="normal"><sp/><sp/>fd-&gt;<ref refid="structfileDescriptor_1d6e69b4726ce93464490201390a9d922" kindref="member">inode</ref><sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="314"><highlight class="normal"><sp/><sp/>fd-&gt;<ref refid="structfileDescriptor_109c5cd0d4979a70b8d7098319cd00b7c" kindref="member">offset</ref><sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="315"><highlight class="normal"><sp/><sp/>fd-&gt;<ref refid="structfileDescriptor_12967356da3f80c5df1405f4e2fb4272b" kindref="member">size</ref><sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="316"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>look<sp/>up<sp/>the<sp/>file<sp/>here</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="317"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="318"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::vfs_open</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="319"><highlight class="normal"></highlight></codeline>
<codeline lineno="320"><highlight class="normal"><ref refid="include_2ubixos_2types_8h_17619b847aeded8a6d14cbfa212b2cdfb" kindref="member">size_t</ref></highlight></codeline>
<codeline lineno="321" refid="classUbixFS_10fce9a3abd07c65fa9af38e51517310a" refkind="member"><highlight class="normal"><ref refid="classUbixFS_10fce9a3abd07c65fa9af38e51517310a" kindref="member">UbixFS::vfs_read</ref>(<ref refid="structfileDescriptor" kindref="compound">fileDescriptor</ref><sp/>*<sp/>fd,<sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*<sp/>data,<sp/><ref refid="include_2ubixos_2types_8h_1fa178be408981cc5edd64227b6332fc6" kindref="member">off_t</ref><sp/>offset,<sp/><ref refid="include_2ubixos_2types_8h_17619b847aeded8a6d14cbfa212b2cdfb" kindref="member">size_t</ref><sp/>size)<sp/>{</highlight></codeline>
<codeline lineno="322"><highlight class="normal"><sp/><sp/></highlight></codeline>
<codeline lineno="323"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">unsigned</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i;</highlight></codeline>
<codeline lineno="324"><highlight class="normal"><sp/><sp/><ref refid="include_2ubixos_2types_8h_1fa178be408981cc5edd64227b6332fc6" kindref="member">off_t</ref><sp/>sum,<sp/>startingBlock;</highlight></codeline>
<codeline lineno="325"><highlight class="normal"><sp/><sp/><ref refid="include_2ubixos_2types_8h_17619b847aeded8a6d14cbfa212b2cdfb" kindref="member">size_t</ref><sp/>runSize,<sp/>sectorCount,<sp/>totalSize,<sp/>bSize;<sp/></highlight><highlight class="comment">//<sp/>blockSize</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="326"><highlight class="normal"><sp/><sp/><ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref><sp/>*<sp/>inode<sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="327"><highlight class="normal"></highlight></codeline>
<codeline lineno="328"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(fd<sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/>data<sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>~0;</highlight></codeline>
<codeline lineno="329"><highlight class="normal"></highlight></codeline>
<codeline lineno="330"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(size<sp/>==<sp/>0)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;<sp/></highlight><highlight class="comment">//<sp/>don&apos;t<sp/>fail<sp/>if<sp/>size<sp/>is<sp/>0?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="331"><highlight class="normal"><sp/><sp/><sp/></highlight></codeline>
<codeline lineno="332"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="structdevice" kindref="compound">device</ref>);</highlight></codeline>
<codeline lineno="333"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>);</highlight></codeline>
<codeline lineno="334"><highlight class="normal"></highlight></codeline>
<codeline lineno="335"><highlight class="normal"><sp/><sp/>inode<sp/>=<sp/>static_cast&lt;ubixfsInode<sp/>*&gt;(fd-&gt;<ref refid="structfileDescriptor_1d6e69b4726ce93464490201390a9d922" kindref="member">inode</ref>);</highlight></codeline>
<codeline lineno="336"><highlight class="normal"></highlight></codeline>
<codeline lineno="337"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(inode);</highlight></codeline>
<codeline lineno="338"><highlight class="normal"></highlight></codeline>
<codeline lineno="339"><highlight class="normal"><sp/><sp/>bSize<sp/>=<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blockSize;</highlight></codeline>
<codeline lineno="340"><highlight class="normal"></highlight></codeline>
<codeline lineno="341"><highlight class="normal"><sp/><sp/>totalSize<sp/>=<sp/>sum<sp/>=<sp/>i<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="342"><highlight class="normal"><sp/><sp/></highlight></codeline>
<codeline lineno="343"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(size<sp/>&gt;<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="344"><highlight class="normal"></highlight></codeline>
<codeline lineno="345"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="346"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>place<sp/>check<sp/>here<sp/>to<sp/>see<sp/>which<sp/>set<sp/>of<sp/>blocks<sp/>we&apos;re<sp/>looking<sp/>through</highlight></codeline>
<codeline lineno="347"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="348"><highlight class="normal"></highlight></codeline>
<codeline lineno="349"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>scan<sp/>through<sp/>direct<sp/>blocks</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="350"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">do</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="351"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(offset<sp/>&gt;=<sp/>sum<sp/>&amp;&amp;<sp/>offset<sp/>&lt;<sp/>sum<sp/>+<sp/>inode-&gt;blocks.direct[i].len<sp/>*<sp/>bSize)<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="352"><highlight class="normal"></highlight></codeline>
<codeline lineno="353"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>sum<sp/>+=<sp/>inode-&gt;blocks.direct[i++].len<sp/>*<sp/>bSize;</highlight></codeline>
<codeline lineno="354"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/></highlight></codeline>
<codeline lineno="355"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(i<sp/>&lt;<sp/><ref refid="ubixfsv2_2ubixfs_8h_130ca66da1223315f426910bd6de581f7" kindref="member">NUM_DIRECT_BLOCKS</ref>);</highlight></codeline>
<codeline lineno="356"><highlight class="normal"></highlight></codeline>
<codeline lineno="357"><highlight class="normal"><sp/><sp/><sp/><sp/>startingBlock<sp/>=<sp/>(inode-&gt;blocks.direct[i].AG<sp/>&lt;&lt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;AGShift)<sp/>+<sp/></highlight></codeline>
<codeline lineno="358"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;blocks.direct[i].start<sp/>+<sp/>((offset<sp/>-<sp/>sum)<sp/>/<sp/>bSize);</highlight></codeline>
<codeline lineno="359"><highlight class="normal"></highlight></codeline>
<codeline lineno="360"><highlight class="normal"><sp/><sp/><sp/><sp/>runSize<sp/>=<sp/>inode-&gt;blocks.direct[i].len<sp/>*<sp/>bSize;</highlight></codeline>
<codeline lineno="361"><highlight class="normal"></highlight></codeline>
<codeline lineno="362"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>startingBlock<sp/>is<sp/>in<sp/>4k<sp/>blocks</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="363"><highlight class="normal"><sp/><sp/><sp/><sp/>startingBlock<sp/>*=<sp/>(bSize<sp/>/<sp/>512);</highlight></codeline>
<codeline lineno="364"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>startingBlock<sp/>is<sp/>now<sp/>in<sp/>sectors</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="365"><highlight class="normal"></highlight></codeline>
<codeline lineno="366"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(runSize<sp/>&gt;=<sp/>size)<sp/>{</highlight></codeline>
<codeline lineno="367"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>runSize<sp/>=<sp/>size;</highlight></codeline>
<codeline lineno="368"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>size<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="369"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{<sp/></highlight></codeline>
<codeline lineno="370"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>size<sp/>-=<sp/>runSize;</highlight></codeline>
<codeline lineno="371"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="372"><highlight class="normal"></highlight></codeline>
<codeline lineno="373"><highlight class="normal"><sp/><sp/><sp/><sp/>sectorCount<sp/>=<sp/>runSize<sp/>/<sp/>512;</highlight></codeline>
<codeline lineno="374"><highlight class="normal"><sp/><sp/></highlight></codeline>
<codeline lineno="375"><highlight class="normal"><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;device-&gt;read(device,<sp/>data,<sp/>&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>startingBlock<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;,<sp/>&quot;</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="376"><highlight class="normal"><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>sectorCount<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;);&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>endl;<sp/></highlight></codeline>
<codeline lineno="377"><highlight class="normal"></highlight></codeline>
<codeline lineno="378"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structdevice" kindref="compound">device</ref>-&gt;read(<ref refid="structdevice" kindref="compound">device</ref>,<sp/>data,<sp/>startingBlock,<sp/>sectorCount);</highlight></codeline>
<codeline lineno="379"><highlight class="normal"></highlight></codeline>
<codeline lineno="380"><highlight class="normal"><sp/><sp/><sp/><sp/>(<ref refid="include_2ubixos_2types_8h_1a4e0f27a9aca905e340c06d2dcae843c" kindref="member">uInt8</ref><sp/>*)data<sp/>+=<sp/>runSize;</highlight></codeline>
<codeline lineno="381"><highlight class="normal"><sp/><sp/><sp/><sp/>totalSize<sp/>+=<sp/>runSize;</highlight></codeline>
<codeline lineno="382"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>while<sp/><sp/></highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="383"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>totalSize;</highlight></codeline>
<codeline lineno="384"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::vfs_read</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="385"><highlight class="normal"></highlight></codeline>
<codeline lineno="386"><highlight class="normal"><ref refid="include_2ubixos_2types_8h_17619b847aeded8a6d14cbfa212b2cdfb" kindref="member">size_t</ref></highlight></codeline>
<codeline lineno="387" refid="classUbixFS_1551d3daae6a65555a220de05eb619930" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1551d3daae6a65555a220de05eb619930" kindref="member">UbixFS::vfs_write</ref>(<ref refid="structfileDescriptor" kindref="compound">fileDescriptor</ref><sp/>*<sp/>fd,<sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*<sp/>data,<sp/><ref refid="include_2ubixos_2types_8h_1fa178be408981cc5edd64227b6332fc6" kindref="member">off_t</ref><sp/>offset,<sp/><ref refid="include_2ubixos_2types_8h_17619b847aeded8a6d14cbfa212b2cdfb" kindref="member">size_t</ref><sp/>size)<sp/>{</highlight></codeline>
<codeline lineno="388"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>char<sp/>*<sp/>sector[512];<sp/><sp/>//<sp/>used<sp/>to<sp/>pad</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="389"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">unsigned</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i,<sp/>whichBlocks;</highlight></codeline>
<codeline lineno="390"><highlight class="normal"><sp/><sp/><ref refid="include_2ubixos_2types_8h_1fa178be408981cc5edd64227b6332fc6" kindref="member">off_t</ref><sp/>sum,<sp/>startingBlock,<sp/>EORPos,<sp/>maxRange;</highlight></codeline>
<codeline lineno="391"><highlight class="normal"><sp/><sp/><ref refid="include_2ubixos_2types_8h_17619b847aeded8a6d14cbfa212b2cdfb" kindref="member">size_t</ref><sp/>runSize,<sp/>runRemainder,<sp/>sectorCount,<sp/>totalSize,<sp/>bSize;<sp/></highlight><highlight class="comment">//<sp/>blockSize</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="392"><highlight class="normal"><sp/><sp/><ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref><sp/>*<sp/>inode<sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="393"><highlight class="normal"><sp/><sp/><ref refid="structblockRun" kindref="compound">blockRun</ref><sp/>br;</highlight></codeline>
<codeline lineno="394"><highlight class="normal"></highlight></codeline>
<codeline lineno="395"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(fd<sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/>data<sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>~0;</highlight></codeline>
<codeline lineno="396"><highlight class="normal"></highlight></codeline>
<codeline lineno="397"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(size<sp/>==<sp/>0)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;<sp/></highlight><highlight class="comment">//<sp/>don&apos;t<sp/>fail<sp/>if<sp/>size<sp/>is<sp/>0?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="398"><highlight class="normal"></highlight></codeline>
<codeline lineno="399"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="structdevice" kindref="compound">device</ref>);</highlight></codeline>
<codeline lineno="400"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>);</highlight></codeline>
<codeline lineno="401"><highlight class="normal"></highlight></codeline>
<codeline lineno="402"><highlight class="normal"><sp/><sp/>inode<sp/>=<sp/>static_cast&lt;ubixfsInode<sp/>*&gt;(fd-&gt;<ref refid="structfileDescriptor_1d6e69b4726ce93464490201390a9d922" kindref="member">inode</ref>);</highlight></codeline>
<codeline lineno="403"><highlight class="normal"></highlight></codeline>
<codeline lineno="404"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(inode);</highlight></codeline>
<codeline lineno="405"><highlight class="normal"></highlight></codeline>
<codeline lineno="406"><highlight class="normal"><sp/><sp/>bSize<sp/>=<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blockSize;</highlight></codeline>
<codeline lineno="407"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(bSize<sp/>!=<sp/>0);</highlight></codeline>
<codeline lineno="408"><highlight class="normal"></highlight></codeline>
<codeline lineno="409"><highlight class="normal"><sp/><sp/>totalSize<sp/>=<sp/>sum<sp/>=<sp/>i<sp/>=<sp/>whichBlocks<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="410"><highlight class="normal"></highlight></codeline>
<codeline lineno="411"><highlight class="normal"><sp/><sp/>EORPos<sp/>=<sp/>offset<sp/>+<sp/>size;<sp/><sp/></highlight><highlight class="comment">//<sp/>compute<sp/>End<sp/>Of<sp/>Run<sp/>Position</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="412"><highlight class="normal"><sp/><sp/>maxRange<sp/>=<sp/>inode-&gt;blocks.maxDirectRange;</highlight></codeline>
<codeline lineno="413"><highlight class="normal"></highlight></codeline>
<codeline lineno="414"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(inode-&gt;blocks.maxIndirectRange<sp/>&gt;<sp/>maxRange)<sp/>{</highlight></codeline>
<codeline lineno="415"><highlight class="normal"><sp/><sp/><sp/><sp/>maxRange<sp/>=<sp/>inode-&gt;blocks.maxIndirectRange;</highlight></codeline>
<codeline lineno="416"><highlight class="normal"><sp/><sp/><sp/><sp/>whichBlocks<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="417"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="418"><highlight class="normal"></highlight></codeline>
<codeline lineno="419"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(inode-&gt;blocks.maxDoubleIndirectRange<sp/>&gt;<sp/>maxRange)<sp/>{</highlight></codeline>
<codeline lineno="420"><highlight class="normal"><sp/><sp/><sp/><sp/>maxRange<sp/>=<sp/>inode-&gt;blocks.maxDoubleIndirectRange;</highlight></codeline>
<codeline lineno="421"><highlight class="normal"><sp/><sp/><sp/><sp/>whichBlocks<sp/>=<sp/>2;</highlight></codeline>
<codeline lineno="422"><highlight class="normal"><sp/><sp/>}<sp/></highlight></codeline>
<codeline lineno="423"><highlight class="normal"><sp/><sp/></highlight></codeline>
<codeline lineno="424"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(EORPos<sp/>&gt;<sp/>maxRange)<sp/>{</highlight></codeline>
<codeline lineno="425"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">/*<sp/></highlight></codeline>
<codeline lineno="426"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>The<sp/>offset+size<sp/>is<sp/>greater<sp/>than<sp/>the<sp/>size<sp/>of<sp/>the<sp/>file,<sp/>so<sp/>we<sp/>need<sp/>to</highlight></codeline>
<codeline lineno="427"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>extend<sp/>out<sp/>the<sp/>file.<sp/>Scan<sp/>through<sp/>the<sp/>direct<sp/>blocks<sp/>(FIX<sp/>LATER)</highlight></codeline>
<codeline lineno="428"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>to<sp/>find<sp/>out<sp/>where<sp/>we<sp/>need<sp/>to<sp/>extend</highlight></codeline>
<codeline lineno="429"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="430"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">switch</highlight><highlight class="normal"><sp/>(whichBlocks)<sp/>{</highlight></codeline>
<codeline lineno="431"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/>0:</highlight></codeline>
<codeline lineno="432"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(i<sp/>&lt;<sp/>NUM_DIRECT_BLOCKS<sp/>&amp;&amp;<sp/>inode-&gt;blocks.direct[i].len<sp/>!=<sp/>0)<sp/>++i;</highlight></codeline>
<codeline lineno="433"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>i<sp/>holds<sp/>which<sp/>direct<sp/>block<sp/>we&apos;re<sp/>going<sp/>to<sp/>add<sp/>to</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="434"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="435"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/>1:</highlight></codeline>
<codeline lineno="436"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/>2:</highlight></codeline>
<codeline lineno="437"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(</highlight><highlight class="keyword">false</highlight><highlight class="normal">);<sp/><sp/></highlight><highlight class="comment">//<sp/>UNFINISHED</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="438"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="439"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">default</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="440"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(</highlight><highlight class="keyword">false</highlight><highlight class="normal">);<sp/><sp/></highlight><highlight class="comment">//<sp/>sanity<sp/>check</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="441"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>switch</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="442"><highlight class="normal"></highlight></codeline>
<codeline lineno="443"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="444"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>NOTE:<sp/>it&apos;s<sp/>possible<sp/>that<sp/>if<sp/>we<sp/>scan<sp/>through<sp/>to<sp/>find<sp/>where<sp/>the</highlight></codeline>
<codeline lineno="445"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>run<sp/>goes,<sp/>we<sp/>might<sp/>be<sp/>able<sp/>to<sp/>extend<sp/>the<sp/>previous<sp/>block<sp/>extent.</highlight></codeline>
<codeline lineno="446"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>This<sp/>will<sp/>require<sp/>that<sp/>we<sp/>set<sp/>up<sp/>br.start<sp/>to<sp/>be<sp/>where<sp/>we&apos;d<sp/>like<sp/>to</highlight></codeline>
<codeline lineno="447"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>start<sp/>looking<sp/>through<sp/>the<sp/>free<sp/>block<sp/>list,<sp/>and<sp/>then<sp/>modifying</highlight></codeline>
<codeline lineno="448"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>getFreeBlock()<sp/>to<sp/>honour<sp/>that.</highlight></codeline>
<codeline lineno="449"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="450"><highlight class="normal"></highlight></codeline>
<codeline lineno="451"><highlight class="normal"><sp/><sp/><sp/><sp/>br.AG<sp/>=<sp/>inode-&gt;inodeNum.AG;<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>request<sp/>a<sp/>sane<sp/>allocation<sp/>group</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="452"><highlight class="normal"><sp/><sp/><sp/><sp/>br.start<sp/>=<sp/>0;<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>getFreeBlock()<sp/>will<sp/>ignore<sp/>this</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="453"><highlight class="normal"></highlight></codeline>
<codeline lineno="454"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="455"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>The<sp/>length<sp/>that<sp/>we<sp/>need<sp/>is<sp/>determined<sp/>by<sp/>how<sp/>much<sp/>extra<sp/>slack<sp/>we<sp/></highlight></codeline>
<codeline lineno="456"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>already<sp/>have<sp/>in<sp/>the<sp/>pre-allocated<sp/>blocks.</highlight></codeline>
<codeline lineno="457"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>e.g.<sp/>(assumes<sp/>4k<sp/>blocks)</highlight></codeline>
<codeline lineno="458"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>bSize<sp/>=<sp/>4096</highlight></codeline>
<codeline lineno="459"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>maxRange<sp/>=<sp/>4096</highlight></codeline>
<codeline lineno="460"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>size<sp/>=<sp/>3000</highlight></codeline>
<codeline lineno="461"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>offset<sp/>=<sp/>3000</highlight></codeline>
<codeline lineno="462"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>size<sp/>=<sp/>4000</highlight></codeline>
<codeline lineno="463"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>[---<sp/>data<sp/>block<sp/>---][---<sp/>data<sp/>block<sp/>---]<sp/><sp/>&lt;----<sp/>blocks<sp/>on<sp/>disk</highlight></codeline>
<codeline lineno="464"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>&lt;-file<sp/>data-&gt;<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&lt;----<sp/>actual<sp/>file<sp/>size</highlight></codeline>
<codeline lineno="465"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&lt;-----&gt;<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&lt;----<sp/>slack</highlight></codeline>
<codeline lineno="466"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>[<sp/><sp/>data<sp/>block<sp/>size<sp/>]<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&lt;----<sp/>maxRange</highlight></codeline>
<codeline lineno="467"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>|<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&lt;----<sp/>offset</highlight></codeline>
<codeline lineno="468"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>*****************<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&lt;----<sp/>new<sp/>data</highlight></codeline>
<codeline lineno="469"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*</highlight></codeline>
<codeline lineno="470"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>In<sp/>the<sp/>above<sp/>example,<sp/>you&apos;d<sp/>need<sp/>at<sp/>least<sp/>one<sp/>more<sp/>block<sp/>to<sp/>write</highlight></codeline>
<codeline lineno="471"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>out<sp/>the<sp/>data.<sp/><sp/></highlight></codeline>
<codeline lineno="472"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>((offset<sp/>+<sp/>size)<sp/>-<sp/>maxRange<sp/>+<sp/>(bSize-1))<sp/>/<sp/>bSize</highlight></codeline>
<codeline lineno="473"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>((3000<sp/>+<sp/>4000)<sp/>-<sp/>4096<sp/>+<sp/>(4095))<sp/>/<sp/>4096<sp/>==<sp/>1<sp/>(rounded<sp/>down)</highlight></codeline>
<codeline lineno="474"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>And<sp/>then<sp/>we<sp/>expand<sp/>it<sp/>by<sp/>a<sp/>little<sp/>extra<sp/>so<sp/>we<sp/>don&apos;t<sp/>have<sp/>to<sp/>keep<sp/></highlight></codeline>
<codeline lineno="475"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>looking<sp/>for<sp/>more<sp/>blocks.<sp/>Currently<sp/>we<sp/>use<sp/>32k<sp/>of<sp/>slack<sp/>(or<sp/>8<sp/>blocks)</highlight></codeline>
<codeline lineno="476"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="477"><highlight class="normal"></highlight></codeline>
<codeline lineno="478"><highlight class="normal"><sp/><sp/><sp/><sp/>br.len<sp/>=<sp/>((EORPos<sp/>-<sp/>maxRange<sp/>+<sp/>(bSize-1))<sp/>/<sp/>bSize);</highlight></codeline>
<codeline lineno="479"><highlight class="normal"></highlight></codeline>
<codeline lineno="480"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(br.len<sp/>&lt;<sp/>8)<sp/>br.len<sp/>=<sp/>8;<sp/><sp/></highlight><highlight class="comment">//<sp/>we<sp/>allocate<sp/>32k<sp/>if<sp/>the<sp/>file<sp/>needs<sp/>to<sp/>grow</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="481"><highlight class="normal"></highlight></codeline>
<codeline lineno="482"><highlight class="normal"><sp/><sp/><sp/><sp/>br<sp/>=<sp/><ref refid="classUbixFS_1092741c58dade79091213126d592be65" kindref="member">getFreeBlock</ref>(br);</highlight></codeline>
<codeline lineno="483"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(br.len<sp/>&gt;<sp/>0);</highlight></codeline>
<codeline lineno="484"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">switch</highlight><highlight class="normal"><sp/>(whichBlocks)<sp/>{</highlight></codeline>
<codeline lineno="485"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/>0:</highlight></codeline>
<codeline lineno="486"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;blocks.direct[i]<sp/>=<sp/>br;</highlight></codeline>
<codeline lineno="487"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;blocks.maxDirectRange<sp/>+=<sp/>br.len<sp/>*<sp/>bSize;</highlight></codeline>
<codeline lineno="488"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="489"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/>1:</highlight></codeline>
<codeline lineno="490"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(</highlight><highlight class="keyword">false</highlight><highlight class="normal">);<sp/></highlight><highlight class="comment">//<sp/>UNFINISHED</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="491"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;blocks.maxIndirectRange<sp/>+=<sp/>br.len<sp/>*<sp/>bSize;</highlight></codeline>
<codeline lineno="492"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="493"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">case</highlight><highlight class="normal"><sp/>2:</highlight></codeline>
<codeline lineno="494"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(</highlight><highlight class="keyword">false</highlight><highlight class="normal">);<sp/></highlight><highlight class="comment">//<sp/>UNFINISHED</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="495"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;blocks.maxDoubleIndirectRange<sp/>+=<sp/>br.len<sp/>*<sp/>bSize;</highlight></codeline>
<codeline lineno="496"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="497"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">default</highlight><highlight class="normal">:<sp/><sp/><sp/></highlight></codeline>
<codeline lineno="498"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(</highlight><highlight class="keyword">false</highlight><highlight class="normal">);<sp/></highlight><highlight class="comment">//<sp/>sanity<sp/>check</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="499"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>switch</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="500"><highlight class="normal"></highlight></codeline>
<codeline lineno="501"><highlight class="normal"><sp/><sp/><sp/><sp/>inode-&gt;blocks.size<sp/>=<sp/>EORPos;</highlight></codeline>
<codeline lineno="502"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>if</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="503"><highlight class="normal"></highlight></codeline>
<codeline lineno="504"><highlight class="normal"></highlight></codeline>
<codeline lineno="505"><highlight class="normal"><sp/><sp/>runRemainder<sp/>=<sp/>size<sp/>%<sp/>512;</highlight></codeline>
<codeline lineno="506"><highlight class="normal"><sp/><sp/>size<sp/>-=<sp/>runRemainder;</highlight></codeline>
<codeline lineno="507"><highlight class="normal"></highlight></codeline>
<codeline lineno="508"><highlight class="normal"><sp/><sp/>totalSize<sp/>=<sp/>sum<sp/>=<sp/>i<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="509"><highlight class="normal"></highlight></codeline>
<codeline lineno="510"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(size<sp/>&gt;<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="511"><highlight class="normal"></highlight></codeline>
<codeline lineno="512"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="513"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>place<sp/>check<sp/>here<sp/>to<sp/>see<sp/>which<sp/>set<sp/>of<sp/>blocks<sp/>we&apos;re<sp/>looking<sp/>through</highlight></codeline>
<codeline lineno="514"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="515"><highlight class="normal"></highlight></codeline>
<codeline lineno="516"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>scan<sp/>through<sp/>direct<sp/>blocks</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="517"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">do</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="518"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(offset<sp/>&gt;=<sp/>sum<sp/>&amp;&amp;<sp/>offset<sp/>&lt;<sp/>sum<sp/>+<sp/>inode-&gt;blocks.direct[i].len<sp/>*<sp/>bSize)</highlight></codeline>
<codeline lineno="519"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="520"><highlight class="normal"></highlight></codeline>
<codeline lineno="521"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>sum<sp/>+=<sp/>inode-&gt;blocks.direct[i++].len<sp/>*<sp/>bSize;</highlight></codeline>
<codeline lineno="522"><highlight class="normal"></highlight></codeline>
<codeline lineno="523"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(i<sp/>&lt;<sp/><ref refid="ubixfsv2_2ubixfs_8h_130ca66da1223315f426910bd6de581f7" kindref="member">NUM_DIRECT_BLOCKS</ref>);</highlight></codeline>
<codeline lineno="524"><highlight class="normal"></highlight></codeline>
<codeline lineno="525"><highlight class="normal"><sp/><sp/><sp/><sp/>startingBlock<sp/>=<sp/>(inode-&gt;blocks.direct[i].AG<sp/>&lt;&lt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;AGShift)<sp/>+</highlight></codeline>
<codeline lineno="526"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;blocks.direct[i].start<sp/>+<sp/>((offset<sp/>-<sp/>sum)<sp/>/<sp/>bSize);</highlight></codeline>
<codeline lineno="527"><highlight class="normal"></highlight></codeline>
<codeline lineno="528"><highlight class="normal"><sp/><sp/><sp/><sp/>runSize<sp/>=<sp/>inode-&gt;blocks.direct[i].len<sp/>*<sp/>bSize;</highlight></codeline>
<codeline lineno="529"><highlight class="normal"></highlight></codeline>
<codeline lineno="530"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>startingBlock<sp/>is<sp/>in<sp/>4k<sp/>blocks</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="531"><highlight class="normal"><sp/><sp/><sp/><sp/>startingBlock<sp/>*=<sp/>(bSize<sp/>/<sp/>512);</highlight></codeline>
<codeline lineno="532"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>startingBlock<sp/>is<sp/>now<sp/>in<sp/>sectors</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="533"><highlight class="normal"></highlight></codeline>
<codeline lineno="534"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(runSize<sp/>&gt;=<sp/>size)<sp/>{</highlight></codeline>
<codeline lineno="535"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>runSize<sp/>=<sp/>size;</highlight></codeline>
<codeline lineno="536"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>size<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="537"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="538"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>size<sp/>-=<sp/>runSize;</highlight></codeline>
<codeline lineno="539"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="540"><highlight class="normal"></highlight></codeline>
<codeline lineno="541"><highlight class="normal"><sp/><sp/><sp/><sp/>sectorCount<sp/>=<sp/>runSize<sp/>/<sp/>512;</highlight></codeline>
<codeline lineno="542"><highlight class="normal"></highlight></codeline>
<codeline lineno="543"><highlight class="normal"><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;device-&gt;write(device,<sp/>data,<sp/>&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>startingBlock<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;,<sp/>&quot;</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="544"><highlight class="normal"><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>sectorCount<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;);&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="545"><highlight class="normal"></highlight></codeline>
<codeline lineno="546"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structdevice" kindref="compound">device</ref>-&gt;write(<ref refid="structdevice" kindref="compound">device</ref>,<sp/>data,<sp/>startingBlock,<sp/>sectorCount);</highlight></codeline>
<codeline lineno="547"><highlight class="normal"></highlight></codeline>
<codeline lineno="548"><highlight class="normal"><sp/><sp/><sp/><sp/>(<ref refid="include_2ubixos_2types_8h_1a4e0f27a9aca905e340c06d2dcae843c" kindref="member">uInt8</ref><sp/>*)data<sp/>+=<sp/>runSize;</highlight></codeline>
<codeline lineno="549"><highlight class="normal"><sp/><sp/><sp/><sp/>totalSize<sp/>+=<sp/>runSize;</highlight></codeline>
<codeline lineno="550"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>while</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="551"><highlight class="normal"></highlight></codeline>
<codeline lineno="552"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(runRemainder<sp/>!=<sp/>0);<sp/><sp/></highlight><highlight class="comment">//<sp/>UNFINISHED</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="553"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>totalSize;</highlight></codeline>
<codeline lineno="554"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::vfs_write</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="555"><highlight class="normal"></highlight></codeline>
<codeline lineno="556"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="557" refid="classUbixFS_1c2ccea3f574eaa7d4700748d0b4bde71" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1c2ccea3f574eaa7d4700748d0b4bde71" kindref="member">UbixFS::vfs_stop</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="558"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classUbixFS_15610078343779a3c5e3046283d482766" kindref="member">vfs_sync</ref>()<sp/>!=<sp/>0)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="559"><highlight class="normal"></highlight></codeline>
<codeline lineno="560"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>you<sp/>must<sp/>delete<sp/>the<sp/>root<sp/>dir<sp/>first,<sp/>in<sp/>case<sp/>it<sp/>needs<sp/>to</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="561"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>still<sp/>write<sp/>anything<sp/>out</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="562"><highlight class="normal"></highlight></codeline>
<codeline lineno="563"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref><sp/>!=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/>{</highlight></codeline>
<codeline lineno="564"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref><sp/>*<sp/>rootInode<sp/>=<sp/>static_cast&lt;ubixfsInode<sp/>*&gt;(<ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref>-&gt;<ref refid="structfileDescriptor_1d6e69b4726ce93464490201390a9d922" kindref="member">inode</ref>);</highlight></codeline>
<codeline lineno="565"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal"><sp/>rootInode-&gt;data.btPtr;<sp/></highlight></codeline>
<codeline lineno="566"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal"><sp/>rootInode;</highlight></codeline>
<codeline lineno="567"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref>-&gt;<ref refid="structfileDescriptor_1d6e69b4726ce93464490201390a9d922" kindref="member">inode</ref><sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="568"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight></codeline>
<codeline lineno="569"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>if</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="570"><highlight class="normal"></highlight></codeline>
<codeline lineno="571"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal"><sp/><ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref>;</highlight></codeline>
<codeline lineno="572"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal"><sp/>[]<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref>;</highlight></codeline>
<codeline lineno="573"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal"><sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>;</highlight></codeline>
<codeline lineno="574"><highlight class="normal"></highlight></codeline>
<codeline lineno="575"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="576"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref><sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;<sp/></highlight></codeline>
<codeline lineno="577"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref><sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="578"><highlight class="normal"></highlight></codeline>
<codeline lineno="579"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*<sp/></highlight></codeline>
<codeline lineno="580"><highlight class="comment"><sp/><sp/><sp/>*<sp/>The<sp/>device<sp/>isn&apos;t<sp/>null<sp/>at<sp/>this<sp/>point,<sp/>allowing<sp/>for<sp/>people<sp/>to<sp/>restart</highlight></codeline>
<codeline lineno="581"><highlight class="comment"><sp/><sp/><sp/>*<sp/>the<sp/>mount<sp/>point.<sp/>Or,<sp/>alternatively,<sp/>to<sp/>blow<sp/>things<sp/>up.</highlight></codeline>
<codeline lineno="582"><highlight class="comment"><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="583"><highlight class="normal"><sp/><sp/></highlight></codeline>
<codeline lineno="584"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="585"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::vfs_stop</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="586"><highlight class="normal"></highlight></codeline>
<codeline lineno="587"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="588" refid="classUbixFS_15610078343779a3c5e3046283d482766" refkind="member"><highlight class="normal"><ref refid="classUbixFS_15610078343779a3c5e3046283d482766" kindref="member">UbixFS::vfs_sync</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="589"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structdevice" kindref="compound">device</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>-1;</highlight></codeline>
<codeline lineno="590"><highlight class="normal"><sp/><sp/><ref refid="structdevice" kindref="compound">device</ref>-&gt;write(<ref refid="structdevice" kindref="compound">device</ref>,<sp/></highlight></codeline>
<codeline lineno="591"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref>,<sp/></highlight></codeline>
<codeline lineno="592"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structdevice" kindref="compound">device</ref>-&gt;sectors<sp/>-<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;batSectors<sp/>-<sp/>1,<sp/></highlight></codeline>
<codeline lineno="593"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;batSectors</highlight></codeline>
<codeline lineno="594"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>);</highlight></codeline>
<codeline lineno="595"><highlight class="normal"><sp/><sp/><ref refid="structdevice" kindref="compound">device</ref>-&gt;write(<ref refid="structdevice" kindref="compound">device</ref>,<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>,<sp/><ref refid="structdevice" kindref="compound">device</ref>-&gt;sectors-1,<sp/>1);</highlight></codeline>
<codeline lineno="596"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="597"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::vfs_sync</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="598"><highlight class="normal"></highlight></codeline>
<codeline lineno="599"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="600" refid="classUbixFS_10fe83377d78fbdc768054870fc8d4f3d" refkind="member"><highlight class="normal"><ref refid="classUbixFS_10fe83377d78fbdc768054870fc8d4f3d" kindref="member">UbixFS::setFreeBlock</ref>(<ref refid="structblockRun" kindref="compound">blockRun</ref><sp/>ibr)<sp/>{</highlight></codeline>
<codeline lineno="601"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">signed</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*<sp/>ptr;</highlight></codeline>
<codeline lineno="602"><highlight class="normal"><sp/><sp/></highlight></codeline>
<codeline lineno="603"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="604"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(ibr.len<sp/>==<sp/>0)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="605"><highlight class="normal"><sp/><sp/>ptr<sp/>=<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>+<sp/>((ibr.AG<sp/>&lt;&lt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;AGShift)<sp/>&gt;&gt;<sp/>3);</highlight></codeline>
<codeline lineno="606"><highlight class="normal"><sp/><sp/>ptr<sp/>+=<sp/>ibr.start<sp/>&gt;&gt;<sp/>3;</highlight></codeline>
<codeline lineno="607"><highlight class="normal"></highlight></codeline>
<codeline lineno="608"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(ibr.start<sp/>%<sp/>8<sp/>!=<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="609"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight></codeline>
<codeline lineno="610"><highlight class="normal"><sp/><sp/><sp/><sp/>ibr.len<sp/>-=<sp/>ibr.start<sp/>%<sp/>8;</highlight></codeline>
<codeline lineno="611"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>if</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="612"><highlight class="normal"></highlight></codeline>
<codeline lineno="613"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::setFreeBlock</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="614"><highlight class="normal"></highlight></codeline>
<codeline lineno="615"><highlight class="normal"><ref refid="structblockRun" kindref="compound">blockRun</ref></highlight></codeline>
<codeline lineno="616" refid="classUbixFS_1038f1a28d415b5198717466215edde0f" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1092741c58dade79091213126d592be65" kindref="member">UbixFS::getFreeBlock</ref>(<ref refid="structblockRun" kindref="compound">blockRun</ref><sp/>ibr)<sp/>{</highlight></codeline>
<codeline lineno="617"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">signed</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*<sp/>ptr;</highlight></codeline>
<codeline lineno="618"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">signed</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*<sp/>holdPtr;</highlight></codeline>
<codeline lineno="619"><highlight class="normal"><sp/><sp/><ref refid="ubixfsv2_2types_8h_156f1a81c92849566ae864511088eb7e8" kindref="member">int32</ref><sp/>count,<sp/>holdCount;</highlight></codeline>
<codeline lineno="620"><highlight class="normal"></highlight></codeline>
<codeline lineno="621"><highlight class="normal"><sp/><sp/><ref refid="structblockRun" kindref="compound">blockRun</ref><sp/>obr<sp/>=<sp/>{0,<sp/>0,<sp/>0};<sp/><sp/></highlight><highlight class="comment">//<sp/>output<sp/>block<sp/>run</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="622"><highlight class="normal"></highlight></codeline>
<codeline lineno="623"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>to<sp/>make<sp/>sure<sp/>none<sp/>of<sp/>these<sp/>are<sp/>null</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="624"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structdevice" kindref="compound">device</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>obr;</highlight></codeline>
<codeline lineno="625"><highlight class="normal"></highlight></codeline>
<codeline lineno="626"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(ibr.len<sp/>==<sp/>0)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>obr;</highlight></codeline>
<codeline lineno="627"><highlight class="normal"></highlight></codeline>
<codeline lineno="628"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(ibr.len<sp/>&gt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;numBlocks)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>obr;</highlight></codeline>
<codeline lineno="629"><highlight class="normal"></highlight></codeline>
<codeline lineno="630"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(ibr.len<sp/>==<sp/>1)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="classUbixFS_1092741c58dade79091213126d592be65" kindref="member">getFreeBlock</ref>(ibr.AG);</highlight></codeline>
<codeline lineno="631"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="632"><highlight class="comment"><sp/><sp/><sp/>*<sp/>count<sp/>is<sp/>the<sp/>block<sp/>from<sp/>the<sp/>base<sp/>of<sp/>the<sp/>list.</highlight></codeline>
<codeline lineno="633"><highlight class="comment"><sp/><sp/><sp/>*<sp/>Since<sp/>we&apos;re<sp/>given<sp/>a<sp/>specific<sp/>AG<sp/>to<sp/>look<sp/>through,<sp/>we<sp/>start<sp/>the<sp/>count<sp/>at</highlight></codeline>
<codeline lineno="634"><highlight class="comment"><sp/><sp/><sp/>*<sp/>AG<sp/>&lt;&lt;<sp/>AGShift,<sp/>where<sp/>AGShift<sp/>is<sp/>the<sp/>shift<sp/>value<sp/>of<sp/>the<sp/>number<sp/>of<sp/>blocks</highlight></codeline>
<codeline lineno="635"><highlight class="comment"><sp/><sp/><sp/>*<sp/>in<sp/>an<sp/>AG</highlight></codeline>
<codeline lineno="636"><highlight class="comment"><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="637"><highlight class="normal"></highlight></codeline>
<codeline lineno="638"><highlight class="normal"><sp/><sp/>count<sp/>=<sp/>(ibr.AG<sp/>&lt;&lt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;AGShift);</highlight></codeline>
<codeline lineno="639"><highlight class="normal"></highlight></codeline>
<codeline lineno="640"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="641"><highlight class="comment"><sp/><sp/><sp/>*<sp/>The<sp/>freeBlockList<sp/>is<sp/>a<sp/>bit<sp/>map<sp/>of<sp/>the<sp/>free/used<sp/>blocks.</highlight></codeline>
<codeline lineno="642"><highlight class="comment"><sp/><sp/><sp/>*<sp/>Used<sp/>=<sp/>on<sp/>bit</highlight></codeline>
<codeline lineno="643"><highlight class="comment"><sp/><sp/><sp/>*<sp/>Unused<sp/>=<sp/>off<sp/>bit</highlight></codeline>
<codeline lineno="644"><highlight class="comment"><sp/><sp/><sp/>*<sp/>There<sp/>are<sp/>8<sp/>bits<sp/>per<sp/>byte<sp/>(hopefully)<sp/>and<sp/>so<sp/>we<sp/>have<sp/>to<sp/>divide<sp/>the<sp/>count</highlight></codeline>
<codeline lineno="645"><highlight class="comment"><sp/><sp/><sp/>*<sp/>by<sp/>8<sp/>to<sp/>get<sp/>our<sp/>starting<sp/>byte<sp/>offset<sp/>to<sp/>look<sp/>from</highlight></codeline>
<codeline lineno="646"><highlight class="comment"><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="647"><highlight class="normal"></highlight></codeline>
<codeline lineno="648"><highlight class="normal"><sp/><sp/>ptr<sp/>=<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>+<sp/>(count<sp/>&gt;&gt;<sp/>3);</highlight></codeline>
<codeline lineno="649"><highlight class="normal"></highlight></codeline>
<codeline lineno="650"><highlight class="normal">rescan:</highlight></codeline>
<codeline lineno="651"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>look<sp/>for<sp/>the<sp/>first<sp/>free<sp/>8<sp/>blocks<sp/>(this<sp/>may<sp/>create<sp/>holes)</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="652"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(*ptr<sp/>!=<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="653"><highlight class="normal"><sp/><sp/><sp/><sp/>++ptr;</highlight></codeline>
<codeline lineno="654"><highlight class="normal"><sp/><sp/><sp/><sp/>count<sp/>+=<sp/>8;</highlight></codeline>
<codeline lineno="655"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(count+8<sp/>&gt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;numBlocks)<sp/>{</highlight></codeline>
<codeline lineno="656"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>ptr<sp/>=<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref>;</highlight></codeline>
<codeline lineno="657"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>count<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="658"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>if<sp/></highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="659"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>while<sp/>*ptr<sp/>!=<sp/>0</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="660"><highlight class="normal"></highlight></codeline>
<codeline lineno="661"><highlight class="normal"><sp/><sp/>holdPtr<sp/>=<sp/>ptr;</highlight></codeline>
<codeline lineno="662"><highlight class="normal"><sp/><sp/>holdCount<sp/>=<sp/>count;</highlight></codeline>
<codeline lineno="663"><highlight class="normal"></highlight></codeline>
<codeline lineno="664"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keywordtype">unsigned</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">short</highlight><highlight class="normal"><sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/>((ibr.len+7)<sp/>/<sp/>8);<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="665"><highlight class="normal"><sp/><sp/><sp/><sp/>++ptr;</highlight></codeline>
<codeline lineno="666"><highlight class="normal"><sp/><sp/><sp/><sp/>count<sp/>+=<sp/>8;</highlight></codeline>
<codeline lineno="667"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(count+8<sp/>&gt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;numBlocks)<sp/>{</highlight></codeline>
<codeline lineno="668"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>ptr<sp/>=<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref>;</highlight></codeline>
<codeline lineno="669"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>count<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="670"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">goto</highlight><highlight class="normal"><sp/>rescan;</highlight></codeline>
<codeline lineno="671"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>if</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="672"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(*ptr<sp/>!=<sp/>0)<sp/></highlight><highlight class="keywordflow">goto</highlight><highlight class="normal"><sp/>rescan;</highlight></codeline>
<codeline lineno="673"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>for<sp/>i</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="674"><highlight class="normal"></highlight></codeline>
<codeline lineno="675"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>we<sp/>have<sp/>found<sp/>a<sp/>range<sp/>of<sp/>blocks<sp/>that<sp/>work<sp/>for<sp/>us</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="676"><highlight class="normal"></highlight></codeline>
<codeline lineno="677"><highlight class="normal"><sp/><sp/>obr.AG<sp/>=<sp/>holdCount<sp/>/<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blocksPerAG;</highlight></codeline>
<codeline lineno="678"><highlight class="normal"><sp/><sp/>obr.start<sp/>=<sp/>holdCount<sp/>%<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blocksPerAG;</highlight></codeline>
<codeline lineno="679"><highlight class="normal"><sp/><sp/>obr.len<sp/>=<sp/>ibr.len;</highlight></codeline>
<codeline lineno="680"><highlight class="normal"></highlight></codeline>
<codeline lineno="681"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keywordtype">unsigned</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">short</highlight><highlight class="normal"><sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/>(ibr.len<sp/>/<sp/>8);<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="682"><highlight class="normal"><sp/><sp/><sp/><sp/>*holdPtr<sp/>=<sp/>-1;</highlight></codeline>
<codeline lineno="683"><highlight class="normal"><sp/><sp/><sp/><sp/>++holdPtr;</highlight></codeline>
<codeline lineno="684"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>for</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="685"><highlight class="normal"></highlight></codeline>
<codeline lineno="686"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(ibr.len<sp/>%<sp/>8<sp/>!=<sp/>0)<sp/>*holdPtr<sp/>=<sp/>(-1<sp/>&lt;&lt;<sp/>(8-(ibr.len<sp/>%<sp/>8)));</highlight></codeline>
<codeline lineno="687"><highlight class="normal"></highlight></codeline>
<codeline lineno="688"><highlight class="normal"><sp/><sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;usedBlocks<sp/>+=<sp/>ibr.len;<sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>increment<sp/>the<sp/>number<sp/>of<sp/>used<sp/>blocks</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="689"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>obr;</highlight></codeline>
<codeline lineno="690"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::getFreeBlock</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="691"><highlight class="normal"></highlight></codeline>
<codeline lineno="692"><highlight class="normal"><ref refid="structblockRun" kindref="compound">blockRun</ref></highlight></codeline>
<codeline lineno="693" refid="classUbixFS_1c104fac0637432050288cd612f33f5cf" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1092741c58dade79091213126d592be65" kindref="member">UbixFS::getFreeBlock</ref>(<ref refid="include_2ubixos_2types_8h_15847ea0262a5aa61eee48cbe95544a78" kindref="member">uInt32</ref><sp/>AG)<sp/>{</highlight></codeline>
<codeline lineno="694"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>AG<sp/>==<sp/>AllocationGroup</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="695"><highlight class="normal"><sp/><sp/><ref refid="structblockRun" kindref="compound">blockRun</ref><sp/>br;</highlight></codeline>
<codeline lineno="696"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">signed</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*<sp/>ptr;</highlight></codeline>
<codeline lineno="697"><highlight class="normal"><sp/><sp/><ref refid="ubixfsv2_2types_8h_156f1a81c92849566ae864511088eb7e8" kindref="member">int32</ref><sp/>count;</highlight></codeline>
<codeline lineno="698"><highlight class="normal"><sp/><sp/><ref refid="ubixfsv2_2types_8h_156f1a81c92849566ae864511088eb7e8" kindref="member">int32</ref><sp/>subCount<sp/>=<sp/>128;</highlight></codeline>
<codeline lineno="699"><highlight class="normal"></highlight></codeline>
<codeline lineno="700"><highlight class="normal"><sp/><sp/>br.AG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="701"><highlight class="normal"><sp/><sp/>br.start<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="702"><highlight class="normal"><sp/><sp/>br.len<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="703"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Check<sp/>to<sp/>make<sp/>sure<sp/>neither<sp/>of<sp/>these<sp/>are<sp/>null</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="704"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structdevice" kindref="compound">device</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>br;</highlight></codeline>
<codeline lineno="705"><highlight class="normal"></highlight></codeline>
<codeline lineno="706"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Are<sp/>there<sp/>any<sp/>blocks<sp/>available?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="707"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;numBlocks<sp/>==<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;usedBlocks)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>br;</highlight></codeline>
<codeline lineno="708"><highlight class="normal"></highlight></codeline>
<codeline lineno="709"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*<sp/></highlight></codeline>
<codeline lineno="710"><highlight class="comment"><sp/><sp/><sp/>*<sp/>count<sp/>is<sp/>the<sp/>block<sp/>from<sp/>the<sp/>base<sp/>of<sp/>the<sp/>list.</highlight></codeline>
<codeline lineno="711"><highlight class="comment"><sp/><sp/><sp/>*<sp/>Since<sp/>we&apos;re<sp/>given<sp/>a<sp/>specific<sp/>AG<sp/>to<sp/>look<sp/>through,<sp/>we<sp/>start<sp/>the<sp/>count<sp/>at</highlight></codeline>
<codeline lineno="712"><highlight class="comment"><sp/><sp/><sp/>*<sp/>AG<sp/>&lt;&lt;<sp/>AGShift,<sp/>where<sp/>AGShift<sp/>is<sp/>the<sp/>shift<sp/>value<sp/>of<sp/>the<sp/>number<sp/>of<sp/>blocks</highlight></codeline>
<codeline lineno="713"><highlight class="comment"><sp/><sp/><sp/>*<sp/>in<sp/>an<sp/>AG<sp/></highlight></codeline>
<codeline lineno="714"><highlight class="comment"><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="715"><highlight class="normal"></highlight></codeline>
<codeline lineno="716"><highlight class="normal"><sp/><sp/>count<sp/>=<sp/>(AG<sp/>&lt;&lt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;AGShift);</highlight></codeline>
<codeline lineno="717"><highlight class="normal"></highlight></codeline>
<codeline lineno="718"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="719"><highlight class="comment"><sp/><sp/><sp/>*<sp/>The<sp/>freeBlockList<sp/>is<sp/>a<sp/>bit<sp/>map<sp/>of<sp/>the<sp/>free/used<sp/>blocks.<sp/></highlight></codeline>
<codeline lineno="720"><highlight class="comment"><sp/><sp/><sp/>*<sp/>Used<sp/>=<sp/>on<sp/>bit</highlight></codeline>
<codeline lineno="721"><highlight class="comment"><sp/><sp/><sp/>*<sp/>Unused<sp/>=<sp/>off<sp/>bit</highlight></codeline>
<codeline lineno="722"><highlight class="comment"><sp/><sp/><sp/>*<sp/>There<sp/>are<sp/>8<sp/>bits<sp/>per<sp/>byte<sp/>(hopefully)<sp/>and<sp/>so<sp/>we<sp/>have<sp/>to<sp/>divide<sp/>the<sp/>count</highlight></codeline>
<codeline lineno="723"><highlight class="comment"><sp/><sp/><sp/>*<sp/>by<sp/>8<sp/>to<sp/>get<sp/>our<sp/>starting<sp/>byte<sp/>offset<sp/>to<sp/>look<sp/>from</highlight></codeline>
<codeline lineno="724"><highlight class="comment"><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="725"><highlight class="normal"></highlight></codeline>
<codeline lineno="726"><highlight class="normal"><sp/><sp/>ptr<sp/>=<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>+<sp/>(count<sp/>&gt;&gt;<sp/>3);</highlight></codeline>
<codeline lineno="727"><highlight class="normal"></highlight></codeline>
<codeline lineno="728"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Scan<sp/>through<sp/>the<sp/>freeBlockList<sp/></highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="729"><highlight class="normal"></highlight></codeline>
<codeline lineno="730"><highlight class="normal">rescan:</highlight></codeline>
<codeline lineno="731"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(*ptr<sp/>==<sp/>-1)<sp/>{<sp/></highlight></codeline>
<codeline lineno="732"><highlight class="normal"><sp/><sp/><sp/><sp/>++ptr;</highlight></codeline>
<codeline lineno="733"><highlight class="normal"><sp/><sp/><sp/><sp/>count<sp/>+=<sp/>8;</highlight></codeline>
<codeline lineno="734"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(count+8<sp/>&gt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;numBlocks)<sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="735"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>while<sp/>*ptr<sp/>==<sp/>-1</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="736"><highlight class="normal"></highlight></codeline>
<codeline lineno="737"><highlight class="normal"><sp/><sp/>subCount<sp/>=<sp/>128;</highlight></codeline>
<codeline lineno="738"><highlight class="normal"></highlight></codeline>
<codeline lineno="739"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">do</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="740"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>((*ptr<sp/>&amp;<sp/>subCount)<sp/>==<sp/>0)<sp/></highlight><highlight class="keywordflow">break</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="741"><highlight class="normal"><sp/><sp/><sp/><sp/>subCount<sp/>&gt;&gt;=<sp/>1;</highlight></codeline>
<codeline lineno="742"><highlight class="normal"><sp/><sp/><sp/><sp/>++count;</highlight></codeline>
<codeline lineno="743"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(count<sp/>==<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;numBlocks)<sp/>{</highlight></codeline>
<codeline lineno="744"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>count<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="745"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>ptr<sp/>=<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref>;</highlight></codeline>
<codeline lineno="746"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">goto</highlight><highlight class="normal"><sp/>rescan;</highlight></codeline>
<codeline lineno="747"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>if</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="748"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal">(subCount<sp/>&gt;<sp/>1);</highlight></codeline>
<codeline lineno="749"><highlight class="normal"></highlight></codeline>
<codeline lineno="750"><highlight class="normal"><sp/><sp/>*ptr<sp/>|=<sp/>subCount;<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>mark<sp/>this<sp/>block<sp/>as<sp/>used</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="751"><highlight class="normal"><sp/><sp/>++<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;usedBlocks;<sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>increment<sp/>the<sp/>number<sp/>of<sp/>used<sp/>blocks</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="752"><highlight class="normal"></highlight></codeline>
<codeline lineno="753"><highlight class="normal"><sp/><sp/>br.AG<sp/>=<sp/>count<sp/>/<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blocksPerAG;<sp/></highlight></codeline>
<codeline lineno="754"><highlight class="normal"><sp/><sp/>br.start<sp/>=<sp/>count<sp/>%<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blocksPerAG;</highlight></codeline>
<codeline lineno="755"><highlight class="normal"><sp/><sp/>br.len<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="756"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>br;<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>return<sp/>the<sp/>allocated<sp/>block<sp/>number</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="757"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>Ubixfs::getFreeBlock</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="758"><highlight class="normal"></highlight></codeline>
<codeline lineno="759"><highlight class="normal"><ref refid="include_2ubixos_2types_8h_15847ea0262a5aa61eee48cbe95544a78" kindref="member">uInt32</ref></highlight></codeline>
<codeline lineno="760" refid="classUbixFS_1f16cc9199d1b438ccb1dae81974f6865" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1f16cc9199d1b438ccb1dae81974f6865" kindref="member">UbixFS::getNextAG</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="761"><highlight class="normal"></highlight></codeline>
<codeline lineno="762"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;lastUsedAG<sp/>==<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;numAGs)<sp/></highlight></codeline>
<codeline lineno="763"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;lastUsedAG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="764"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="765"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;lastUsedAG++;</highlight></codeline>
<codeline lineno="766"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;lastUsedAG;</highlight></codeline>
<codeline lineno="767"><highlight class="normal"></highlight></codeline>
<codeline lineno="768"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::getNextAG</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="769"><highlight class="normal"></highlight></codeline>
<codeline lineno="770"><highlight class="normal"></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="771"><highlight class="comment"><sp/>*<sp/>UbixFS::getFreeBlock(void)</highlight></codeline>
<codeline lineno="772"><highlight class="comment"><sp/>*<sp/>upon<sp/>success<sp/>returns<sp/>a<sp/>free<sp/>block<sp/>based<sp/>on<sp/>the<sp/>next<sp/>AG<sp/>after<sp/>the<sp/>lastUsedAG</highlight></codeline>
<codeline lineno="773"><highlight class="comment"><sp/>*<sp/>failure<sp/>returns<sp/>-1</highlight></codeline>
<codeline lineno="774"><highlight class="comment"><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="775"><highlight class="normal"></highlight></codeline>
<codeline lineno="776"><highlight class="normal"><ref refid="structblockRun" kindref="compound">blockRun</ref></highlight></codeline>
<codeline lineno="777" refid="classUbixFS_1092741c58dade79091213126d592be65" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1092741c58dade79091213126d592be65" kindref="member">UbixFS::getFreeBlock</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="778"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="classUbixFS_1092741c58dade79091213126d592be65" kindref="member">getFreeBlock</ref>(<ref refid="classUbixFS_1f16cc9199d1b438ccb1dae81974f6865" kindref="member">getNextAG</ref>());</highlight></codeline>
<codeline lineno="779"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::getFreeBlock</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="780"><highlight class="normal"></highlight></codeline>
<codeline lineno="781"><highlight class="normal"><ref refid="structblockRun" kindref="compound">blockRun</ref></highlight></codeline>
<codeline lineno="782" refid="classUbixFS_12e0acd2fb08df1df4645ab91a69dc048" refkind="member"><highlight class="normal"><ref refid="classUbixFS_12e0acd2fb08df1df4645ab91a69dc048" kindref="member">UbixFS::get8FreeBlocks</ref>(<ref refid="include_2ubixos_2types_8h_15847ea0262a5aa61eee48cbe95544a78" kindref="member">uInt32</ref><sp/>AG)<sp/>{</highlight></codeline>
<codeline lineno="783"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>AG<sp/>==<sp/>AllocationGroup</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="784"><highlight class="normal"><sp/><sp/><ref refid="structblockRun" kindref="compound">blockRun</ref><sp/>br;</highlight></codeline>
<codeline lineno="785"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">signed</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*<sp/>ptr;</highlight></codeline>
<codeline lineno="786"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">signed</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*<sp/>endPtr;</highlight></codeline>
<codeline lineno="787"><highlight class="normal"><sp/><sp/><ref refid="ubixfsv2_2types_8h_156f1a81c92849566ae864511088eb7e8" kindref="member">int32</ref><sp/>count;</highlight></codeline>
<codeline lineno="788"><highlight class="normal"></highlight></codeline>
<codeline lineno="789"><highlight class="normal"><sp/><sp/>br.AG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="790"><highlight class="normal"><sp/><sp/>br.start<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="791"><highlight class="normal"><sp/><sp/>br.len<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="792"><highlight class="normal"></highlight></codeline>
<codeline lineno="793"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="structdevice" kindref="compound">device</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>br;</highlight></codeline>
<codeline lineno="794"><highlight class="normal"></highlight></codeline>
<codeline lineno="795"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>Are<sp/>there<sp/>any<sp/>blocks<sp/>available?</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="796"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;usedBlocks+8<sp/>&gt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;numBlocks)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>br;</highlight></codeline>
<codeline lineno="797"><highlight class="normal"></highlight></codeline>
<codeline lineno="798"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="799"><highlight class="comment"><sp/><sp/><sp/>*<sp/>count<sp/>is<sp/>the<sp/>block<sp/>from<sp/>the<sp/>base<sp/>of<sp/>the<sp/>list.</highlight></codeline>
<codeline lineno="800"><highlight class="comment"><sp/><sp/><sp/>*<sp/>Since<sp/>we&apos;re<sp/>given<sp/>a<sp/>specific<sp/>AG<sp/>to<sp/>look<sp/>through,<sp/>we<sp/>start<sp/>the<sp/>count<sp/>at</highlight></codeline>
<codeline lineno="801"><highlight class="comment"><sp/><sp/><sp/>*<sp/>AG<sp/>&lt;&lt;<sp/>AGShift,<sp/>where<sp/>AGShift<sp/>is<sp/>the<sp/>shift<sp/>value<sp/>of<sp/>the<sp/>number<sp/>of<sp/>blocks</highlight></codeline>
<codeline lineno="802"><highlight class="comment"><sp/><sp/><sp/>*<sp/>in<sp/>an<sp/>AG</highlight></codeline>
<codeline lineno="803"><highlight class="comment"><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="804"><highlight class="normal"></highlight></codeline>
<codeline lineno="805"><highlight class="normal"><sp/><sp/>count<sp/>=<sp/>(AG<sp/>&lt;&lt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;AGShift);</highlight></codeline>
<codeline lineno="806"><highlight class="normal"></highlight></codeline>
<codeline lineno="807"><highlight class="normal"><sp/><sp/>ptr<sp/>=<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>+<sp/>(count<sp/>&gt;&gt;<sp/>3);</highlight></codeline>
<codeline lineno="808"><highlight class="normal"><sp/><sp/></highlight></codeline>
<codeline lineno="809"><highlight class="normal"><sp/><sp/>endPtr<sp/>=<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>+<sp/>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;numBlocks<sp/>&gt;&gt;<sp/>3);</highlight></codeline>
<codeline lineno="810"><highlight class="normal"></highlight></codeline>
<codeline lineno="811"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">bool</highlight><highlight class="normal"><sp/>secondTime<sp/>=<sp/></highlight><highlight class="keyword">false</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="812"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(*ptr<sp/>!=<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="813"><highlight class="normal"><sp/><sp/><sp/><sp/>++ptr;</highlight></codeline>
<codeline lineno="814"><highlight class="normal"><sp/><sp/><sp/><sp/>count<sp/>+=<sp/>8;</highlight></codeline>
<codeline lineno="815"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(ptr<sp/>==<sp/>endPtr)<sp/>{</highlight></codeline>
<codeline lineno="816"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(secondTime)<sp/></highlight></codeline>
<codeline lineno="817"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>br;<sp/></highlight></codeline>
<codeline lineno="818"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/></highlight></codeline>
<codeline lineno="819"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>secondTime<sp/>=<sp/></highlight><highlight class="keyword">true</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="820"><highlight class="normal"></highlight></codeline>
<codeline lineno="821"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>count<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="822"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>ptr<sp/>=<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref>;<sp/><sp/><sp/><sp/><sp/><sp/></highlight></codeline>
<codeline lineno="823"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>if</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="824"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>while<sp/></highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="825"><highlight class="normal"></highlight></codeline>
<codeline lineno="826"><highlight class="normal"><sp/><sp/>*ptr<sp/>=<sp/>-1;<sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>mark<sp/>8<sp/>blocks<sp/>as<sp/>taken</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="827"><highlight class="normal"></highlight></codeline>
<codeline lineno="828"><highlight class="normal"><sp/><sp/>br.AG<sp/>=<sp/>count<sp/>/<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blocksPerAG;</highlight></codeline>
<codeline lineno="829"><highlight class="normal"><sp/><sp/>br.start<sp/>=<sp/>count<sp/>%<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blocksPerAG;</highlight></codeline>
<codeline lineno="830"><highlight class="normal"><sp/><sp/>br.len<sp/>=<sp/>8;</highlight></codeline>
<codeline lineno="831"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>br;</highlight></codeline>
<codeline lineno="832"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::get8FreeBlocks</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="833"><highlight class="normal"></highlight></codeline>
<codeline lineno="834"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/>*</highlight></codeline>
<codeline lineno="835" refid="classUbixFS_194e296e37c8176b5f5ba88a2251b70ab" refkind="member"><highlight class="normal"><ref refid="classUbixFS_194e296e37c8176b5f5ba88a2251b70ab" kindref="member">UbixFS::mknod</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*filename,<sp/><ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref><sp/>*<sp/>parent,<sp/><ref refid="kern__descrip_8h_1e9f148ba55d84268ecb6f8031ab45076" kindref="member">mode_t</ref><sp/>mode)<sp/>{</highlight></codeline>
<codeline lineno="836"><highlight class="normal"><sp/><sp/><ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref><sp/>*<sp/>inode<sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="837"><highlight class="normal"></highlight></codeline>
<codeline lineno="838"><highlight class="normal"><sp/><sp/>inode<sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref>;</highlight></codeline>
<codeline lineno="839"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(inode);</highlight></codeline>
<codeline lineno="840"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(inode<sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="841"><highlight class="normal"><sp/><sp/><ref refid="lib_2string_8h_1ce4b911463887af5e748326323e99a23" kindref="member">memset</ref>(inode,<sp/>0,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(<ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref>));</highlight></codeline>
<codeline lineno="842"><highlight class="normal"></highlight></codeline>
<codeline lineno="843"><highlight class="normal"><sp/><sp/>inode-&gt;magic1<sp/>=<sp/><ref refid="ubixfsv2_2ubixfs_8h_1c88e98d44093495af57d4a956b095b9d" kindref="member">UBIXFS_INODE_MAGIC</ref>;</highlight></codeline>
<codeline lineno="844"><highlight class="normal"></highlight></codeline>
<codeline lineno="845"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*<sp/></highlight></codeline>
<codeline lineno="846"><highlight class="comment"><sp/><sp/><sp/>*<sp/>in<sp/>retrospect..<sp/>I&apos;m<sp/>not<sp/>sure<sp/>why<sp/>parent<sp/>would<sp/>be<sp/>null..<sp/>only<sp/>the</highlight></codeline>
<codeline lineno="847"><highlight class="comment"><sp/><sp/><sp/>*<sp/>root<sp/>directory<sp/>would<sp/>have<sp/>a<sp/>null<sp/>parent,<sp/>but<sp/>that&apos;s<sp/>manually<sp/>allocated</highlight></codeline>
<codeline lineno="848"><highlight class="comment"><sp/><sp/><sp/>*<sp/>in<sp/>vfs_format()</highlight></codeline>
<codeline lineno="849"><highlight class="comment"><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="850"><highlight class="normal"></highlight></codeline>
<codeline lineno="851"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(parent<sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/>{</highlight></codeline>
<codeline lineno="852"><highlight class="normal"><sp/><sp/><sp/><sp/>inode-&gt;inodeNum<sp/>=<sp/><ref refid="classUbixFS_1092741c58dade79091213126d592be65" kindref="member">getFreeBlock</ref>();</highlight></codeline>
<codeline lineno="853"><highlight class="normal"><sp/><sp/><sp/><sp/>inode-&gt;parent.iAddr.AG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="854"><highlight class="normal"><sp/><sp/><sp/><sp/>inode-&gt;parent.iAddr.start<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="855"><highlight class="normal"><sp/><sp/><sp/><sp/>inode-&gt;parent.iAddr.len<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="856"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="857"><highlight class="normal"><sp/><sp/><sp/><sp/>inode-&gt;inodeNum<sp/>=<sp/><ref refid="classUbixFS_1092741c58dade79091213126d592be65" kindref="member">getFreeBlock</ref>(parent-&gt;inodeNum.AG);</highlight></codeline>
<codeline lineno="858"><highlight class="normal"><sp/><sp/><sp/><sp/>inode-&gt;parent.iAddr<sp/>=<sp/>parent-&gt;inodeNum;</highlight></codeline>
<codeline lineno="859"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="860"><highlight class="normal"><sp/><sp/><sp/></highlight></codeline>
<codeline lineno="861"><highlight class="normal"><sp/><sp/><ref refid="lib_2string_8h_12a6bedbfab350cd17b80849f5f9234e9" kindref="member">strncpy</ref>(inode-&gt;name,<sp/>filename,<sp/><ref refid="ubixfsv2_2ubixfs_8h_16773b93f3093658c3dcb569de3b4bdb2" kindref="member">MAX_FILENAME_LENGTH</ref>);</highlight></codeline>
<codeline lineno="862"><highlight class="normal"></highlight></codeline>
<codeline lineno="863"><highlight class="normal"><sp/><sp/>inode-&gt;uid<sp/>=<sp/><ref refid="gen__calls_8h_1b2bf044f6f20a60f7c4139b527c4bd6c" kindref="member">getuid</ref>();</highlight></codeline>
<codeline lineno="864"><highlight class="normal"><sp/><sp/>inode-&gt;gid<sp/>=<sp/><ref refid="gen__calls_8h_1d78d6c02154727f556f78cca62020c83" kindref="member">getgid</ref>();</highlight></codeline>
<codeline lineno="865"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>inode-&gt;mode</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="866"><highlight class="normal"><sp/><sp/>inode-&gt;flags<sp/>=<sp/>mode;</highlight></codeline>
<codeline lineno="867"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>inode-&gt;createTime</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="868"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>inode-&gt;lastModifiedTime</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="869"><highlight class="normal"><sp/><sp/>inode-&gt;inodeSize<sp/>=<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;inodeSize;</highlight></codeline>
<codeline lineno="870"><highlight class="normal"></highlight></codeline>
<codeline lineno="871"><highlight class="normal"><sp/><sp/>inode-&gt;attributes.AG<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="872"><highlight class="normal"><sp/><sp/>inode-&gt;attributes.start<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="873"><highlight class="normal"><sp/><sp/>inode-&gt;attributes.len<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="874"><highlight class="normal"></highlight></codeline>
<codeline lineno="875"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>inode-&gt;type<sp/></highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="876"><highlight class="normal"></highlight></codeline>
<codeline lineno="877"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="878"><highlight class="comment"><sp/><sp/><sp/>*<sp/>next<sp/>and<sp/>prev<sp/>are<sp/>used<sp/>in<sp/>memory<sp/>to<sp/>hold<sp/>pointers<sp/>to<sp/>the<sp/>next/prev</highlight></codeline>
<codeline lineno="879"><highlight class="comment"><sp/><sp/><sp/>*<sp/>inodes<sp/>in<sp/>this<sp/>dir.<sp/><sp/>On<sp/>disk<sp/>they<sp/>may<sp/>have<sp/>another<sp/>value,<sp/>but<sp/>for</highlight></codeline>
<codeline lineno="880"><highlight class="comment"><sp/><sp/><sp/>*<sp/>now<sp/>they<sp/>should<sp/>be<sp/>set<sp/>to<sp/>null.</highlight></codeline>
<codeline lineno="881"><highlight class="comment"><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="882"><highlight class="normal"></highlight></codeline>
<codeline lineno="883"><highlight class="normal"><sp/><sp/>inode-&gt;next.offset<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="884"><highlight class="normal"><sp/><sp/>inode-&gt;prev.offset<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="885"><highlight class="normal"><sp/><sp/>inode-&gt;refCount<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="886"><highlight class="normal"><sp/><sp/>++<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;inodeCount;</highlight></codeline>
<codeline lineno="887"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>inode;</highlight></codeline>
<codeline lineno="888"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::mknod</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="889"><highlight class="normal"></highlight></codeline>
<codeline lineno="890"><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="891" refid="classUbixFS_1f93fcff0825ffcdaf05ceefaeb48fd7b" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1f93fcff0825ffcdaf05ceefaeb48fd7b" kindref="member">UbixFS::vfs_mkdir</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*<sp/>path,<sp/><ref refid="kern__descrip_8h_1e9f148ba55d84268ecb6f8031ab45076" kindref="member">mode_t</ref><sp/>mode)<sp/>{</highlight></codeline>
<codeline lineno="892"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/><ref refid="pci_8c_18f8f80d37794cde9472343e4487ba3eb" kindref="member">name</ref>[<ref refid="ubixfsv2_2ubixfs_8h_16773b93f3093658c3dcb569de3b4bdb2" kindref="member">MAX_FILENAME_LENGTH</ref>];</highlight></codeline>
<codeline lineno="893"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">unsigned</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>start,<sp/>end,<sp/>len,<sp/>nameStart;</highlight></codeline>
<codeline lineno="894"><highlight class="normal"><sp/><sp/><ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref><sp/>*<sp/>dir<sp/>=<sp/>static_cast&lt;ubixfsInode<sp/>*&gt;(<ref refid="classUbixFS_1d7a17314620c3031ee4d1868ea745222" kindref="member">root</ref>-&gt;<ref refid="structfileDescriptor_1d6e69b4726ce93464490201390a9d922" kindref="member">inode</ref>);</highlight></codeline>
<codeline lineno="895"><highlight class="normal"><sp/><sp/><ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref><sp/>*<sp/>inode<sp/>=<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>;</highlight></codeline>
<codeline lineno="896"><highlight class="normal"></highlight></codeline>
<codeline lineno="897"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(path);<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>bad<sp/>input:<sp/>vfs_mkdir(NULL);</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="898"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(*path);<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>bad<sp/>input:<sp/>vfs_mkdir(&quot;&quot;);</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="899"><highlight class="normal"></highlight></codeline>
<codeline lineno="900"><highlight class="normal"><sp/><sp/><ref refid="lib_2string_8h_1ce4b911463887af5e748326323e99a23" kindref="member">memset</ref>(&amp;name,<sp/>0,<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(name));</highlight></codeline>
<codeline lineno="901"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>find<sp/>the<sp/>dir<sp/>name</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="902"><highlight class="normal"><sp/><sp/>len<sp/>=<sp/><ref refid="strlen_8S_10bcafbeba7f59f157715cc462036b8d3" kindref="member">strlen</ref>(path);</highlight></codeline>
<codeline lineno="903"><highlight class="normal"></highlight></codeline>
<codeline lineno="904"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(path[0]<sp/>==<sp/></highlight><highlight class="charliteral">&apos;/&apos;</highlight><highlight class="normal">);<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>bad<sp/>input:<sp/>vfs<sp/>isn&apos;t<sp/>doing<sp/>its<sp/>job</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="905"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(len<sp/>&gt;<sp/>1);<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>bad<sp/>input:<sp/>mkdir<sp/>/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="906"><highlight class="normal"></highlight></codeline>
<codeline lineno="907"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>remove<sp/>trailing<sp/>&quot;/&quot;<sp/>if<sp/>present</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="908"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(path[len-1]<sp/>==<sp/></highlight><highlight class="charliteral">&apos;/&apos;</highlight><highlight class="normal">)<sp/>--len;</highlight></codeline>
<codeline lineno="909"><highlight class="normal"></highlight></codeline>
<codeline lineno="910"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(len<sp/>&gt;<sp/>1);<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>bad<sp/>input:<sp/>mkdir<sp/>//</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="911"><highlight class="normal"></highlight></codeline>
<codeline lineno="912"><highlight class="normal"><sp/><sp/>nameStart<sp/>=<sp/>len-1;</highlight></codeline>
<codeline lineno="913"><highlight class="normal"></highlight></codeline>
<codeline lineno="914"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(path[nameStart]<sp/>!=<sp/></highlight><highlight class="charliteral">&apos;/&apos;</highlight><highlight class="normal">);<sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>bad<sp/>input:<sp/>mkdir<sp/>/a//</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="915"><highlight class="normal"></highlight></codeline>
<codeline lineno="916"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="917"><highlight class="comment"><sp/><sp/><sp/>*<sp/>we&apos;re<sp/>guaranteed<sp/>by<sp/>the<sp/>assert()<sp/>above<sp/>that<sp/>there<sp/>is<sp/></highlight></codeline>
<codeline lineno="918"><highlight class="comment"><sp/><sp/><sp/>*<sp/>at<sp/>least<sp/>one<sp/>&quot;/&quot;<sp/>before<sp/>our<sp/>location.<sp/>If<sp/>you<sp/>remove<sp/>the<sp/>assert<sp/></highlight></codeline>
<codeline lineno="919"><highlight class="comment"><sp/><sp/><sp/>*<sp/>you<sp/>might<sp/>need<sp/>to<sp/>make<sp/>sure<sp/>nameStart<sp/>stays<sp/>above<sp/>0<sp/>in<sp/>the<sp/>following</highlight></codeline>
<codeline lineno="920"><highlight class="comment"><sp/><sp/><sp/>*<sp/>while</highlight></codeline>
<codeline lineno="921"><highlight class="comment"><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="922"><highlight class="normal"></highlight></codeline>
<codeline lineno="923"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(path[nameStart]<sp/>!=<sp/></highlight><highlight class="charliteral">&apos;/&apos;</highlight><highlight class="normal">)<sp/>--nameStart;</highlight></codeline>
<codeline lineno="924"><highlight class="normal"><sp/><sp/>++nameStart;</highlight></codeline>
<codeline lineno="925"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(len<sp/>-<sp/>nameStart<sp/>&gt;<sp/>0);</highlight></codeline>
<codeline lineno="926"><highlight class="normal"></highlight></codeline>
<codeline lineno="927"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*<sp/>e.g.</highlight></codeline>
<codeline lineno="928"><highlight class="comment"><sp/><sp/><sp/>*<sp/><sp/><sp/>v---------------------<sp/>start</highlight></codeline>
<codeline lineno="929"><highlight class="comment"><sp/><sp/><sp/>*<sp/><sp/><sp/><sp/><sp/><sp/>v------------------<sp/>end</highlight></codeline>
<codeline lineno="930"><highlight class="comment"><sp/><sp/><sp/>*<sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>v------<sp/>nameStart</highlight></codeline>
<codeline lineno="931"><highlight class="comment"><sp/><sp/><sp/>*<sp/><sp/>/usr/local/data/dirname/<sp/><sp/>&lt;---<sp/>ignores<sp/>trailing<sp/>/</highlight></codeline>
<codeline lineno="932"><highlight class="comment"><sp/><sp/><sp/>*<sp/><sp/>&lt;---------23----------&gt;<sp/>len</highlight></codeline>
<codeline lineno="933"><highlight class="comment"><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="934"><highlight class="normal"></highlight></codeline>
<codeline lineno="935"><highlight class="normal"><sp/><sp/>start<sp/>=<sp/>end<sp/>=<sp/>1;<sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>skip<sp/>leading<sp/>/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="936"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(end<sp/>&lt;<sp/>nameStart)<sp/>{</highlight></codeline>
<codeline lineno="937"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">do</highlight><highlight class="normal"><sp/>{<sp/>++end;<sp/>}<sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal">(path[end]<sp/>!=<sp/></highlight><highlight class="charliteral">&apos;/&apos;</highlight><highlight class="normal">);</highlight></codeline>
<codeline lineno="938"><highlight class="normal"></highlight></codeline>
<codeline lineno="939"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(end-start+1<sp/>&lt;<sp/></highlight><highlight class="keyword">sizeof</highlight><highlight class="normal">(name));</highlight></codeline>
<codeline lineno="940"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>this<sp/>is<sp/>probably<sp/>wrong:</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="941"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="lib_2string_8h_12a6bedbfab350cd17b80849f5f9234e9" kindref="member">strncpy</ref>(name,<sp/>&amp;path[start],<sp/>end-start+1);</highlight></codeline>
<codeline lineno="942"><highlight class="normal"><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>name<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="943"><highlight class="normal"><sp/><sp/><sp/><sp/>dir<sp/>=<sp/>dir-&gt;data.btPtr-&gt;Find(name);</highlight></codeline>
<codeline lineno="944"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(dir);</highlight></codeline>
<codeline lineno="945"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(dir-&gt;flags<sp/>&amp;<sp/><ref refid="ubixfsv2_2ubixfs_8h_103a6b271b2413595574aab2babfa1460" kindref="member">INODE_DIRECTORY</ref><sp/>==<sp/><ref refid="ubixfsv2_2ubixfs_8h_103a6b271b2413595574aab2babfa1460" kindref="member">INODE_DIRECTORY</ref>);</highlight></codeline>
<codeline lineno="946"><highlight class="normal"><sp/><sp/><sp/><sp/>start<sp/>=<sp/>++end;</highlight></codeline>
<codeline lineno="947"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="948"><highlight class="normal"></highlight></codeline>
<codeline lineno="949"><highlight class="normal"><sp/><sp/><ref refid="lib_2string_8h_12a6bedbfab350cd17b80849f5f9234e9" kindref="member">strncpy</ref>(name,<sp/>&amp;path[nameStart],<sp/>len<sp/>-<sp/>nameStart);</highlight></codeline>
<codeline lineno="950"><highlight class="normal"><sp/><sp/>inode<sp/>=<sp/>(<ref refid="structubixfsInode" kindref="compound">ubixfsInode</ref><sp/>*)<ref refid="classUbixFS_194e296e37c8176b5f5ba88a2251b70ab" kindref="member">mknod</ref>(name,<sp/>dir,<sp/>mode<sp/>|<sp/><ref refid="ubixfsv2_2ubixfs_8h_103a6b271b2413595574aab2babfa1460" kindref="member">INODE_DIRECTORY</ref>);</highlight></codeline>
<codeline lineno="951"><highlight class="normal"></highlight></codeline>
<codeline lineno="952"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">/*<sp/></highlight></codeline>
<codeline lineno="953"><highlight class="comment"><sp/><sp/><sp/>*<sp/>keep<sp/>in<sp/>mind<sp/>that<sp/>the<sp/>reason<sp/>for<sp/>passing<sp/>in<sp/>the<sp/>name<sp/>is<sp/>because</highlight></codeline>
<codeline lineno="954"><highlight class="comment"><sp/><sp/><sp/>*<sp/>we<sp/>thought<sp/>about<sp/>allowing<sp/>key<sp/>names<sp/>to<sp/>be<sp/>different<sp/>from<sp/>inode<sp/></highlight></codeline>
<codeline lineno="955"><highlight class="comment"><sp/><sp/><sp/>*<sp/>names.<sp/>In<sp/>retrospect,<sp/>I<sp/>don&apos;t<sp/>think<sp/>that&apos;s<sp/>a<sp/>good<sp/>idea<sp/>since<sp/>a<sp/>dir</highlight></codeline>
<codeline lineno="956"><highlight class="comment"><sp/><sp/><sp/>*<sp/>listing<sp/>will<sp/>print<sp/>the<sp/>actual<sp/>dir<sp/>name<sp/>instead<sp/>of<sp/>.<sp/>and<sp/>..</highlight></codeline>
<codeline lineno="957"><highlight class="comment"><sp/><sp/><sp/>*<sp/>Thus:<sp/>the<sp/>first<sp/>parameter<sp/>of<sp/>btPtr-&gt;Insert()<sp/>may<sp/>go<sp/>away.</highlight></codeline>
<codeline lineno="958"><highlight class="comment"><sp/><sp/><sp/>*/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="959"><highlight class="normal"></highlight></codeline>
<codeline lineno="960"><highlight class="normal"><sp/><sp/><ref refid="assert_8h_1d6d5aaa966ca7424f7cb9bd01f2c838b" kindref="member">assert</ref>(dir-&gt;data.btPtr-&gt;Insert(inode-&gt;name,<sp/>inode));</highlight></codeline>
<codeline lineno="961"><highlight class="normal"></highlight></codeline>
<codeline lineno="962"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="963"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::vfs_mkdir</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="964"><highlight class="normal"></highlight></codeline>
<codeline lineno="965"><highlight class="normal"></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/></highlight></codeline>
<codeline lineno="966" refid="classUbixFS_179445019036de9f0811426196299c46a" refkind="member"><highlight class="normal"><ref refid="classUbixFS_179445019036de9f0811426196299c46a" kindref="member">UbixFS::printFreeBlockList</ref>(<ref refid="include_2ubixos_2types_8h_15847ea0262a5aa61eee48cbe95544a78" kindref="member">uInt32</ref><sp/>AG)<sp/>{</highlight></codeline>
<codeline lineno="967"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">unsigned</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>j;</highlight></codeline>
<codeline lineno="968"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref><sp/>||<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref><sp/>==<sp/><ref refid="def_8h_1070d2ce7b6bb7e5c05602aa8c308d0c4" kindref="member">NULL</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="969"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;AG<sp/>=<sp/>%d\n&quot;</highlight><highlight class="normal">,<sp/>AG);</highlight></codeline>
<codeline lineno="970"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keywordtype">unsigned</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;blocksPerAG<sp/>/<sp/>8;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="971"><highlight class="normal"><sp/><sp/><sp/><sp/>j<sp/>=<sp/>128;</highlight></codeline>
<codeline lineno="972"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">signed</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>foo<sp/>=<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref>[(AG<sp/>&lt;&lt;<sp/><ref refid="classUbixFS_1e33fa6e8c047dfe567c22936460186f0" kindref="member">superBlock</ref>-&gt;AGShift)+i];</highlight></codeline>
<codeline lineno="973"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(j<sp/>&gt;<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="974"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>((foo<sp/>&amp;<sp/>j)<sp/>==<sp/>j)<sp/></highlight></codeline>
<codeline lineno="975"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;1&quot;</highlight><highlight class="normal">);</highlight></codeline>
<codeline lineno="976"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="977"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;0&quot;</highlight><highlight class="normal">);<sp/><sp/><sp/><sp/></highlight></codeline>
<codeline lineno="978"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>j<sp/>&gt;&gt;=<sp/>1;</highlight></codeline>
<codeline lineno="979"><highlight class="normal"><sp/></highlight></codeline>
<codeline lineno="980"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="981"><highlight class="normal"><sp/><sp/>}<sp/></highlight><highlight class="comment">//<sp/>for<sp/>i</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="982"><highlight class="normal"><sp/><sp/>printf(</highlight><highlight class="stringliteral">&quot;\n&quot;</highlight><highlight class="normal">);</highlight></codeline>
<codeline lineno="983"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="984"><highlight class="normal">}<sp/></highlight><highlight class="comment">//<sp/>UbixFS::printFreeBlockList</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="985"><highlight class="normal"></highlight></codeline>
<codeline lineno="986" refid="classUbixFS_1c607e8f35afa1aca552a1dc24e777998" refkind="member"><highlight class="normal"><ref refid="classUbixFS_1c607e8f35afa1aca552a1dc24e777998" kindref="member">UbixFS::~UbixFS</ref>(</highlight><highlight class="keywordtype">void</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="987"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal"><sp/>[]<sp/><ref refid="classUbixFS_1910425153882d145e2af0ae30bdec9a6" kindref="member">freeBlockList</ref>;</highlight></codeline>
<codeline lineno="988"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="989"><highlight class="normal">}</highlight></codeline>
    </programlisting>
    <location file="/usr/home/reddawg/source/ubix2/src/sys/ubixfsv2/ubixfs.cpp"/>
  </compounddef>
</doxygen>
