Newer
Older
UbixOS / doc / html / ubixfs_8cpp-source.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>UbixOS V2: src/sys/ubixfsv2/ubixfs.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.7 -->
<div class="tabs">
  <ul>
    <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="namespaces.html"><span>Namespaces</span></a></li>
    <li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
    <li id="current"><a href="files.html"><span>Files</span></a></li>
    <li><a href="dirs.html"><span>Directories</span></a></li>
    <li>
      <form action="search.php" method="get">
        <table cellspacing="0" cellpadding="0" border="0">
          <tr>
            <td><label>&nbsp;<u>S</u>earch&nbsp;for&nbsp;</label></td>
            <td><input type="text" name="query" value="" size="20" accesskey="s"/></td>
          </tr>
        </table>
      </form>
    </li>
  </ul></div>
<div class="tabs">
  <ul>
    <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    <li><a href="globals.html"><span>Globals</span></a></li>
  </ul></div>
<div class="nav">
<a class="el" href="dir_897b6a2d7bab147dd1db58381aad3984.html">src</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_832905b1f7f5feaf61a306b40c0ac817.html">sys</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_21e0927e9dd41d8ff1206ca4f0555726.html">ubixfsv2</a></div>
<h1>ubixfs.cpp</h1><a href="ubixfs_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &lt;stddef.h&gt;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;<a class="code" href="string_8h.html">string.h</a>&gt;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include &lt;<a class="code" href="assert_8h.html">assert.h</a>&gt;</span>
<a name="l00006"></a>00006 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="preprocessor">#include "<a class="code" href="ubixfsv2_2ubixfs_8h.html">ubixfs.h</a>"</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include "<a class="code" href="btree_8h.html">btree.h</a>"</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="keyword">using namespace </span>std;
<a name="l00012"></a>00012 
<a name="l00013"></a><a class="code" href="classUbixFS.html#a8411daf956e8ba4e129b3f26d7ecb45">00013</a> <a class="code" href="classUbixFS.html#a8411daf956e8ba4e129b3f26d7ecb45">UbixFS::UbixFS</a>(<span class="keywordtype">void</span>) { 
<a name="l00014"></a>00014   <a class="code" href="structdevice.html">device</a> = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00015"></a>00015   <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00016"></a>00016   <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a> = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00017"></a>00017   <a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a> = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00018"></a>00018 } <span class="comment">// UbixFS::UbixFS</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 
<a name="l00021"></a><a class="code" href="classUbixFS.html#15d6d564145f65baba56b5e721a72c8b">00021</a> <a class="code" href="classUbixFS.html#a8411daf956e8ba4e129b3f26d7ecb45">UbixFS::UbixFS</a>(<a class="code" href="structdevice__t.html">device_t</a> * <a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>) {
<a name="l00022"></a>00022   <a class="code" href="structdevice.html">device</a> = <a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>;
<a name="l00023"></a>00023   <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00024"></a>00024   <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a> = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00025"></a>00025   <a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a> = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00026"></a>00026 } <span class="comment">// UbixFS::UbixFS</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="keywordtype">void</span>
<a name="l00029"></a><a class="code" href="classUbixFS.html#2303eac53dcf539ad1db595b09e1568a">00029</a> <a class="code" href="classUbixFS.html#2303eac53dcf539ad1db595b09e1568a">UbixFS::printSuperBlock</a>(<span class="keywordtype">void</span>) {
<a name="l00030"></a>00030   printf(<span class="stringliteral">"superBlock-&gt;name........... %s\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;name);
<a name="l00031"></a>00031   printf(<span class="stringliteral">"superBlock-&gt;magic1......... %X\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;magic1);
<a name="l00032"></a>00032   printf(<span class="stringliteral">"superBlock-&gt;fsByteOrder.... %d\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;fsByteOrder);
<a name="l00033"></a>00033   printf(<span class="stringliteral">"superBlock-&gt;blockSize...... %d\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blockSize);
<a name="l00034"></a>00034   printf(<span class="stringliteral">"superBlock-&gt;blockShift..... %d\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blockShift);
<a name="l00035"></a>00035   printf(<span class="stringliteral">"superBlock-&gt;numBlocks...... %lld\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;numBlocks);
<a name="l00036"></a>00036   printf(<span class="stringliteral">"superBlock-&gt;usedBlocks..... %lld\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;usedBlocks);
<a name="l00037"></a>00037   printf(<span class="stringliteral">"superBlock-&gt;batSectors..... %d\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;batSectors);
<a name="l00038"></a>00038   printf(<span class="stringliteral">"superBlock-&gt;inodeCount..... %d\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;inodeCount);
<a name="l00039"></a>00039   printf(<span class="stringliteral">"superBlock-&gt;magic2......... %X\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;magic2);
<a name="l00040"></a>00040   printf(<span class="stringliteral">"superBlock-&gt;blocksPerAG.... %d\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blocksPerAG);
<a name="l00041"></a>00041   printf(<span class="stringliteral">"superBlock-&gt;AGShift........ %d\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;AGShift);
<a name="l00042"></a>00042   printf(<span class="stringliteral">"superBlock-&gt;numAGs......... %d\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;numAGs);
<a name="l00043"></a>00043   printf(<span class="stringliteral">"superBlock-&gt;lastUsedAG..... %d\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;lastUsedAG);
<a name="l00044"></a>00044   printf(<span class="stringliteral">"superBlock-&gt;flags.......... %X\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;flags);
<a name="l00045"></a>00045   printf(<span class="stringliteral">"superBlock-&gt;magic3......... %X\n"</span>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;magic3);
<a name="l00046"></a>00046   <span class="keywordflow">return</span>;
<a name="l00047"></a>00047 } <span class="comment">// UbixFS::printSuperBlock</span>
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <span class="keywordtype">int</span> 
<a name="l00050"></a><a class="code" href="classUbixFS.html#148aae4eb2ceb35ffcad9ff22b2f7309">00050</a> <a class="code" href="classUbixFS.html#148aae4eb2ceb35ffcad9ff22b2f7309">UbixFS::vfs_init</a>(<span class="keywordtype">void</span>) {
<a name="l00051"></a>00051 <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="structdevice.html">device</a>);
<a name="l00052"></a>00052   <a class="code" href="include_2ubixos_2types_8h.html#7619b847aeded8a6d14cbfa212b2cdfb">size_t</a> result;
<a name="l00053"></a>00053   cout &lt;&lt; <span class="stringliteral">"vfs_init()"</span> &lt;&lt; endl;
<a name="l00054"></a>00054   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="structdevice.html">device</a>);
<a name="l00055"></a>00055 
<a name="l00056"></a>00056   <span class="keywordflow">if</span> (<a class="code" href="structdevice.html">device</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> -1;
<a name="l00057"></a>00057   <span class="keywordflow">if</span> (<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a> != <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keyword">delete</span> <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>;
<a name="l00058"></a>00058   <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a> = <span class="keyword">new</span> <a class="code" href="structdiskSuperBlock.html">diskSuperBlock</a>;
<a name="l00059"></a>00059 <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>);
<a name="l00060"></a>00060   <span class="keywordflow">if</span> (<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> -1;
<a name="l00061"></a>00061 
<a name="l00062"></a>00062   <span class="comment">// read in the superBlock. It's always the last block on the partition </span>
<a name="l00063"></a>00063 cout &lt;&lt; <span class="stringliteral">"reading in superBlock"</span> &lt;&lt; endl;
<a name="l00064"></a>00064   <a class="code" href="structdevice.html">device</a>-&gt;read(<a class="code" href="structdevice.html">device</a>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>, <a class="code" href="structdevice.html">device</a>-&gt;sectors-1, 1);
<a name="l00065"></a>00065 cout &lt;&lt; <span class="stringliteral">"done"</span> &lt;&lt; endl;
<a name="l00066"></a>00066 
<a name="l00067"></a>00067   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;magic1 == <a class="code" href="ubixfsv2_2ubixfs_8h.html#b5c389bfe61bb5707916f2ac6d4d0c6a">UBIXFS_MAGIC1</a>);
<a name="l00068"></a>00068   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;magic2 == <a class="code" href="ubixfsv2_2ubixfs_8h.html#5dd83bc90fdb21a43a412d90b99f5704">UBIXFS_MAGIC2</a>);
<a name="l00069"></a>00069   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;magic3 == <a class="code" href="ubixfsv2_2ubixfs_8h.html#7bc7bdfbc69287525c62286f77443b97">UBIXFS_MAGIC3</a>);
<a name="l00070"></a>00070   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="lib_2string_8h.html#6f3dcb20ff11ff9db5904c3cfb61a38c">strcmp</a>(<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;name, <span class="stringliteral">"UbixFS"</span>) == 0);
<a name="l00071"></a>00071   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>((1 &lt;&lt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blockShift) == <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blockSize);
<a name="l00072"></a>00072   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>((<span class="keywordtype">unsigned</span>)(1 &lt;&lt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;AGShift) == <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blocksPerAG);
<a name="l00073"></a>00073   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;flags == <a class="code" href="ubixfsv2_2ubixfs_8h.html#49a8f9142d94b4472956c6d8f446d2ce">UBIXFS_CLEAN</a>);
<a name="l00074"></a>00074 
<a name="l00075"></a>00075   <span class="keywordflow">if</span> (<a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> != <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keyword">delete</span> [] <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a>;
<a name="l00076"></a>00076   <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> = <span class="keyword">new</span> <span class="keywordtype">signed</span> <span class="keywordtype">char</span>[<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;batSectors*512];
<a name="l00077"></a>00077 <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a>);
<a name="l00078"></a>00078   <a class="code" href="lib_2string_8h.html#ce4b911463887af5e748326323e99a23">memset</a>(<a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a>, 0, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;batSectors*512);
<a name="l00079"></a>00079 
<a name="l00080"></a>00080   <a class="code" href="structdevice.html">device</a>-&gt;read(<a class="code" href="structdevice.html">device</a>, 
<a name="l00081"></a>00081                <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a>, 
<a name="l00082"></a>00082                <a class="code" href="structdevice.html">device</a>-&gt;sectors - <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;batSectors-1,
<a name="l00083"></a>00083                <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;batSectors
<a name="l00084"></a>00084               ); <span class="comment">// device-&gt;read()</span>
<a name="l00085"></a>00085 
<a name="l00086"></a>00086   <a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a> = <span class="keyword">new</span> <a class="code" href="structfileDescriptor.html">fileDescriptor</a>;
<a name="l00087"></a>00087   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a>);
<a name="l00088"></a>00088   <a class="code" href="lib_2string_8h.html#ce4b911463887af5e748326323e99a23">memset</a>(<a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="structfileDescriptor.html">fileDescriptor</a>));
<a name="l00089"></a>00089 cout &lt;&lt; <span class="stringliteral">"allocating root dir inode"</span> &lt;&lt; endl;
<a name="l00090"></a>00090   <a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a>-&gt;<a class="code" href="structfileDescriptor.html#d6e69b4726ce93464490201390a9d922">inode</a> = <span class="keyword">new</span> <a class="code" href="structubixfsInode.html">ubixfsInode</a>;
<a name="l00091"></a>00091   <a class="code" href="lib_2string_8h.html#ce4b911463887af5e748326323e99a23">memset</a>(<a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a>-&gt;<a class="code" href="structfileDescriptor.html#d6e69b4726ce93464490201390a9d922">inode</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="structubixfsInode.html">ubixfsInode</a>));
<a name="l00092"></a>00092 cout &lt;&lt; <span class="stringliteral">"root dir inode starting sector: "</span> &lt;&lt; 
<a name="l00093"></a>00093                ((<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;rootDir.AG &lt;&lt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;AGShift) 
<a name="l00094"></a>00094                + <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;rootDir.start) * (<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blockSize / 512)
<a name="l00095"></a>00095      &lt;&lt; endl;
<a name="l00096"></a>00096 
<a name="l00097"></a>00097 cout &lt;&lt; <span class="stringliteral">"reading in root dir inode"</span> &lt;&lt; endl;
<a name="l00098"></a>00098   
<a name="l00099"></a>00099   <a class="code" href="structdevice.html">device</a>-&gt;read(<a class="code" href="structdevice.html">device</a>,
<a name="l00100"></a>00100                <a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a>-&gt;<a class="code" href="structfileDescriptor.html#d6e69b4726ce93464490201390a9d922">inode</a>,
<a name="l00101"></a>00101                ((<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;rootDir.AG &lt;&lt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;AGShift) 
<a name="l00102"></a>00102                  + <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;rootDir.start) * (<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blockSize / 512),
<a name="l00103"></a>00103                <span class="keyword">sizeof</span>(ubixfsInode) / 512
<a name="l00104"></a>00104               );
<a name="l00105"></a>00105 cout &lt;&lt; <span class="stringliteral">"done"</span> &lt;&lt; endl;
<a name="l00106"></a>00106   ubixfsInode * rootInode = static_cast&lt;ubixfsInode *&gt;(<a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a>-&gt;<a class="code" href="structfileDescriptor.html#d6e69b4726ce93464490201390a9d922">inode</a>);
<a name="l00107"></a>00107   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(rootInode);
<a name="l00108"></a>00108 
<a name="l00109"></a>00109   <span class="comment">/* the bTree constructor now loads in the header */</span>
<a name="l00110"></a>00110 
<a name="l00111"></a>00111   rootInode-&gt;data.btPtr = <span class="keyword">new</span> <a class="code" href="classUbixFS.html#d8e9bf5a5c42eabcce4ea4ab71c95528">bTree</a>(<span class="keyword">this</span>, <a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a>);
<a name="l00112"></a>00112   rootInode-&gt;data.btPtr-&gt;Info();
<a name="l00113"></a>00113   <a class="code" href="classUbixFS.html#2303eac53dcf539ad1db595b09e1568a">printSuperBlock</a>();
<a name="l00114"></a>00114   <span class="keywordflow">return</span> 0;
<a name="l00115"></a>00115 } <span class="comment">// UbixFS::init</span>
<a name="l00116"></a>00116 
<a name="l00117"></a>00117 <span class="keywordtype">int</span>
<a name="l00118"></a><a class="code" href="classUbixFS.html#e1266337d259778b1404601184d75028">00118</a> <a class="code" href="classUbixFS.html#e1266337d259778b1404601184d75028">UbixFS::vfs_format</a>(<a class="code" href="structdevice__t.html">device_t</a> * <a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>) {
<a name="l00119"></a>00119   cout &lt;&lt; <span class="stringliteral">"vfs_format()"</span> &lt;&lt; endl;
<a name="l00120"></a>00120   <span class="keywordtype">char</span> sector[512];
<a name="l00121"></a>00121   <a class="code" href="include_2ubixos_2types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> blocks, batSect, batSize;
<a name="l00122"></a>00122   <span class="keywordflow">if</span> (<a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> -1; 
<a name="l00123"></a>00123 
<a name="l00124"></a>00124   <span class="comment">// zero out the sector</span>
<a name="l00125"></a>00125   <a class="code" href="lib_2string_8h.html#ce4b911463887af5e748326323e99a23">memset</a>(&amp;sector, 0x0, <span class="keyword">sizeof</span>(sector));
<a name="l00126"></a>00126  
<a name="l00127"></a>00127   <span class="comment">// fill the drive in with zeroed out sectors</span>
<a name="l00128"></a>00128   cout &lt;&lt; <span class="stringliteral">"dev-&gt;sectors: "</span> &lt;&lt; <a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>-&gt;sectors &lt;&lt; endl;
<a name="l00129"></a>00129   cout &lt;&lt; <span class="stringliteral">"clearing device..."</span>;
<a name="l00130"></a>00130 
<a name="l00131"></a>00131   <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>-&gt;sectors; i++) {
<a name="l00132"></a>00132     <a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>-&gt;write(<a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>, &amp;sector, i, 1);
<a name="l00133"></a>00133   } <span class="comment">// for i</span>
<a name="l00134"></a>00134 
<a name="l00135"></a>00135   cout &lt;&lt; <span class="stringliteral">"done"</span> &lt;&lt; endl;
<a name="l00136"></a>00136 
<a name="l00137"></a>00137   <span class="comment">// allocate a new superBlock and clear it</span>
<a name="l00138"></a>00138 
<a name="l00139"></a>00139   <a class="code" href="structdiskSuperBlock.html">diskSuperBlock</a> *sb = <span class="keyword">new</span> <a class="code" href="structdiskSuperBlock.html">diskSuperBlock</a>;
<a name="l00140"></a>00140   <span class="keywordflow">if</span> (sb == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> -1;
<a name="l00141"></a>00141   <a class="code" href="lib_2string_8h.html#ce4b911463887af5e748326323e99a23">memset</a>(sb, 0, <span class="keyword">sizeof</span>(<a class="code" href="structdiskSuperBlock.html">diskSuperBlock</a>));
<a name="l00142"></a>00142 
<a name="l00143"></a>00143   <span class="comment">// dev-&gt;sectors is the number of 512 byte sectors</span>
<a name="l00144"></a>00144 
<a name="l00145"></a>00145   blocks = (<a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>-&gt;sectors-1) / 8;     <span class="comment">// 4k blocks</span>
<a name="l00146"></a>00146   batSize = (<a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>-&gt;sectors-1) % 8;    <span class="comment">// remainder</span>
<a name="l00147"></a>00147   
<a name="l00148"></a>00148   <span class="comment">// compute the BAT size</span>
<a name="l00149"></a>00149 
<a name="l00150"></a>00150   <span class="keywordflow">while</span> ((batSize * 4096) &lt; blocks) {
<a name="l00151"></a>00151     batSize += 8;
<a name="l00152"></a>00152     --blocks;
<a name="l00153"></a>00153   } <span class="comment">// while</span>
<a name="l00154"></a>00154  
<a name="l00155"></a>00155   <span class="comment">// batSize is in sectors</span>
<a name="l00156"></a>00156   batSect = blocks * 8;
<a name="l00157"></a>00157 
<a name="l00158"></a>00158   <a class="code" href="lib_2string_8h.html#55e123beb3d7f96e25e024a13582d987">strcpy</a>(sb-&gt;name, <span class="stringliteral">"UbixFS"</span>);
<a name="l00159"></a>00159   sb-&gt;magic1 = <a class="code" href="ubixfsv2_2ubixfs_8h.html#b5c389bfe61bb5707916f2ac6d4d0c6a">UBIXFS_MAGIC1</a>;
<a name="l00160"></a>00160   sb-&gt;fsByteOrder = 0;
<a name="l00161"></a>00161   sb-&gt;blockSize = 4096;
<a name="l00162"></a>00162   sb-&gt;blockShift = 12;
<a name="l00163"></a>00163   sb-&gt;numBlocks = blocks;
<a name="l00164"></a>00164   sb-&gt;usedBlocks = 2;  <span class="comment">// root dir takes two blocks (inode + bTree header)</span>
<a name="l00165"></a>00165   sb-&gt;inodeCount = 1;
<a name="l00166"></a>00166   sb-&gt;inodeSize = 4096;
<a name="l00167"></a>00167   sb-&gt;magic2 = <a class="code" href="ubixfsv2_2ubixfs_8h.html#5dd83bc90fdb21a43a412d90b99f5704">UBIXFS_MAGIC2</a>;
<a name="l00168"></a>00168   sb-&gt;blocksPerAG = 2048;
<a name="l00169"></a>00169   sb-&gt;AGShift = 11;
<a name="l00170"></a>00170   sb-&gt;numAGs = (sb-&gt;numBlocks+2047) / 2048;
<a name="l00171"></a>00171   sb-&gt;lastUsedAG = 0;
<a name="l00172"></a>00172 
<a name="l00173"></a>00173   <span class="comment">// the BAT exists outside our official block count, so no </span>
<a name="l00174"></a>00174   <span class="comment">// entries in the BAT need to be set for it</span>
<a name="l00175"></a>00175   sb-&gt;batSectors = batSize;
<a name="l00176"></a>00176 
<a name="l00177"></a>00177   sb-&gt;flags = 0x434C454E; <span class="comment">// CLEN</span>
<a name="l00178"></a>00178   sb-&gt;logBlocks.AG = 0;
<a name="l00179"></a>00179   sb-&gt;logBlocks.start = 0;
<a name="l00180"></a>00180   sb-&gt;logBlocks.len = 0;
<a name="l00181"></a>00181   sb-&gt;logStart = 0;
<a name="l00182"></a>00182   sb-&gt;logEnd = 0;
<a name="l00183"></a>00183   sb-&gt;magic3 = <a class="code" href="ubixfsv2_2ubixfs_8h.html#7bc7bdfbc69287525c62286f77443b97">UBIXFS_MAGIC3</a>;
<a name="l00184"></a>00184   sb-&gt;indicies.AG = 0;
<a name="l00185"></a>00185   sb-&gt;indicies.start = 0;
<a name="l00186"></a>00186   sb-&gt;indicies.len = 0;
<a name="l00187"></a>00187 
<a name="l00188"></a>00188   sb-&gt;rootDir.AG = 0;
<a name="l00189"></a>00189   sb-&gt;rootDir.start = 0;
<a name="l00190"></a>00190   sb-&gt;rootDir.len = 1;
<a name="l00191"></a>00191 
<a name="l00192"></a>00192   <span class="comment">// write out the superBlock</span>
<a name="l00193"></a>00193 
<a name="l00194"></a>00194   <a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>-&gt;write(<a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>, sb, <a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>-&gt;sectors-1, 1);
<a name="l00195"></a>00195 
<a name="l00196"></a>00196   <span class="comment">// mark the first two 4k blocks used</span>
<a name="l00197"></a>00197   <a class="code" href="lib_2string_8h.html#ce4b911463887af5e748326323e99a23">memset</a>(&amp;sector, 0, <span class="keyword">sizeof</span>(sector));
<a name="l00198"></a>00198   sector[0] = (1 &lt;&lt; 7) | (1 &lt;&lt; 6);
<a name="l00199"></a>00199 
<a name="l00200"></a>00200   <span class="comment">// write out the first sector of the BAT </span>
<a name="l00201"></a>00201 
<a name="l00202"></a>00202   <a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>-&gt;write(<a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>, &amp;sector, batSect, 1);
<a name="l00203"></a>00203   <span class="comment">// clear the rest</span>
<a name="l00204"></a>00204   sector[0] = 0;
<a name="l00205"></a>00205 
<a name="l00206"></a>00206   <span class="comment">// write out the rest of the BAT</span>
<a name="l00207"></a>00207 
<a name="l00208"></a>00208   <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 1; i &lt; batSize; i++) {
<a name="l00209"></a>00209     <a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>-&gt;write(<a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>, &amp;sector, (batSect)+i, 1);
<a name="l00210"></a>00210   } <span class="comment">// for i</span>
<a name="l00211"></a>00211 
<a name="l00212"></a>00212   <span class="comment">/* allocate part of the root dir */</span>
<a name="l00213"></a>00213 
<a name="l00214"></a>00214   <span class="comment">// sanity checks</span>
<a name="l00215"></a>00215   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(sb-&gt;blockSize);
<a name="l00216"></a>00216   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>((<span class="keywordtype">unsigned</span>)sb-&gt;blockSize &gt;= <span class="keyword">sizeof</span>(<a class="code" href="structbTreeHeader.html">bTreeHeader</a>));
<a name="l00217"></a>00217 
<a name="l00218"></a>00218   bTreeHeader * bth = <span class="keyword">new</span> bTreeHeader;
<a name="l00219"></a>00219   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(bth);
<a name="l00220"></a>00220   <a class="code" href="lib_2string_8h.html#ce4b911463887af5e748326323e99a23">memset</a>(bth, 0, <span class="keyword">sizeof</span>(bTreeHeader));
<a name="l00221"></a>00221 
<a name="l00222"></a>00222   bth-&gt;<a class="code" href="structbTreeHeader.html#60d3496f588d01ff12f9e74288494f3b">firstDeleted</a> = -1;
<a name="l00223"></a>00223   bth-&gt;<a class="code" href="structbTreeHeader.html#fa2951c3806f5b1990da9f4f34d9fc10">firstNodeOffset</a> = -1;
<a name="l00224"></a>00224   bth-&gt;<a class="code" href="structbTreeHeader.html#ca6e142166a274565291bc425b80549f">treeDepth</a> = 1;
<a name="l00225"></a>00225   bth-&gt;<a class="code" href="structbTreeHeader.html#d072fd3a177d2aa12a2ff3ebf1ccbcb7">treeWidth</a> = 0;
<a name="l00226"></a>00226   bth-&gt;<a class="code" href="structbTreeHeader.html#a9518218d48b68f08aa2406268faf8da">treeLeafCount</a> = 0;
<a name="l00227"></a>00227 
<a name="l00228"></a>00228   <span class="comment">/* create the root dir inode here */</span>
<a name="l00229"></a>00229 
<a name="l00230"></a>00230   <a class="code" href="structubixfsInode.html">ubixfsInode</a> * inode = <span class="keyword">new</span> <a class="code" href="structubixfsInode.html">ubixfsInode</a>;
<a name="l00231"></a>00231   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(inode);
<a name="l00232"></a>00232   <span class="keywordflow">if</span> (inode == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> -1;
<a name="l00233"></a>00233   <a class="code" href="lib_2string_8h.html#ce4b911463887af5e748326323e99a23">memset</a>(inode, 0, <span class="keyword">sizeof</span>(<a class="code" href="structubixfsInode.html">ubixfsInode</a>));
<a name="l00234"></a>00234 
<a name="l00235"></a>00235   inode-&gt;magic1 = <a class="code" href="ubixfsv2_2ubixfs_8h.html#c88e98d44093495af57d4a956b095b9d">UBIXFS_INODE_MAGIC</a>;
<a name="l00236"></a>00236 
<a name="l00237"></a>00237   <span class="comment">// inodes point to themselves</span>
<a name="l00238"></a>00238   inode-&gt;inodeNum.AG = 0;
<a name="l00239"></a>00239   inode-&gt;inodeNum.start = 0;
<a name="l00240"></a>00240   inode-&gt;inodeNum.len = 1;
<a name="l00241"></a>00241 
<a name="l00242"></a>00242   <span class="comment">// root dir has no parent directory</span>
<a name="l00243"></a>00243   inode-&gt;parent.iAddr.AG = 0;
<a name="l00244"></a>00244   inode-&gt;parent.iAddr.start = 0;
<a name="l00245"></a>00245   inode-&gt;parent.iAddr.len = 0;
<a name="l00246"></a>00246 
<a name="l00247"></a>00247   <span class="comment">/* this is part of the root dir structure (the bTreeHeader) */</span>
<a name="l00248"></a>00248   inode-&gt;blocks.direct[0].AG = 0;
<a name="l00249"></a>00249   inode-&gt;blocks.direct[0].start = 1;
<a name="l00250"></a>00250   inode-&gt;blocks.direct[0].len = 1;
<a name="l00251"></a>00251    
<a name="l00252"></a>00252   inode-&gt;blocks.maxDirectRange = <span class="keyword">sizeof</span>(bTreeHeader);
<a name="l00253"></a>00253   inode-&gt;blocks.size = <span class="keyword">sizeof</span>(bTreeHeader);
<a name="l00254"></a>00254 
<a name="l00255"></a>00255   <a class="code" href="lib_2string_8h.html#55e123beb3d7f96e25e024a13582d987">strcpy</a>(inode-&gt;name, <span class="stringliteral">"/"</span>);
<a name="l00256"></a>00256   inode-&gt;uid = <a class="code" href="gen__calls_8h.html#b2bf044f6f20a60f7c4139b527c4bd6c">getuid</a>();
<a name="l00257"></a>00257   inode-&gt;gid = <a class="code" href="gen__calls_8h.html#d78d6c02154727f556f78cca62020c83">getgid</a>();
<a name="l00258"></a>00258   <span class="comment">// inode-&gt;mode</span>
<a name="l00259"></a>00259   inode-&gt;flags = <a class="code" href="ubixfsv2_2ubixfs_8h.html#03a6b271b2413595574aab2babfa1460">INODE_DIRECTORY</a>;
<a name="l00260"></a>00260   <span class="comment">// inode-&gt;createTime</span>
<a name="l00261"></a>00261   <span class="comment">// inode-&gt;lastModifiedTime</span>
<a name="l00262"></a>00262   <span class="comment">// inode-&gt;type</span>
<a name="l00263"></a>00263 
<a name="l00264"></a>00264   inode-&gt;attributes.AG = 0;
<a name="l00265"></a>00265   inode-&gt;attributes.start = 0;
<a name="l00266"></a>00266   inode-&gt;attributes.len = 0;
<a name="l00267"></a>00267 
<a name="l00268"></a>00268   inode-&gt;inodeSize = sb-&gt;inodeSize;
<a name="l00269"></a>00269 
<a name="l00270"></a>00270   <span class="comment">/*</span>
<a name="l00271"></a>00271 <span class="comment">   * next and prev are used in memory to hold pointers to the next/prev</span>
<a name="l00272"></a>00272 <span class="comment">   * inodes in this dir.  On disk they may have another value, but for</span>
<a name="l00273"></a>00273 <span class="comment">   * now they should be set to null.</span>
<a name="l00274"></a>00274 <span class="comment">   */</span>
<a name="l00275"></a>00275 
<a name="l00276"></a>00276   inode-&gt;next.offset = 0;
<a name="l00277"></a>00277   inode-&gt;prev.offset = 0;
<a name="l00278"></a>00278 
<a name="l00279"></a>00279   <span class="comment">// write out the "root" dir inode</span>
<a name="l00280"></a>00280 
<a name="l00281"></a>00281   <a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>-&gt;write(<a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>, 
<a name="l00282"></a>00282              inode, 
<a name="l00283"></a>00283              ((inode-&gt;inodeNum.AG &lt;&lt; sb-&gt;AGShift) +
<a name="l00284"></a>00284               inode-&gt;inodeNum.start) * (sb-&gt;blockSize / 512),
<a name="l00285"></a>00285              sb-&gt;inodeSize / 512
<a name="l00286"></a>00286             ); <span class="comment">// dev-&gt;write</span>
<a name="l00287"></a>00287 
<a name="l00288"></a>00288   <span class="comment">// write out the "root" dir</span>
<a name="l00289"></a>00289 
<a name="l00290"></a>00290   <a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>-&gt;write(<a class="code" href="ethernetif_8c.html#cf6a82c73e7a9d99293d9ce0b8837faf">dev</a>, 
<a name="l00291"></a>00291              bth, 
<a name="l00292"></a>00292              ((inode-&gt;blocks.direct[0].AG &lt;&lt; sb-&gt;AGShift) + 
<a name="l00293"></a>00293               inode-&gt;blocks.direct[0].start) * (sb-&gt;blockSize / 512),
<a name="l00294"></a>00294              sb-&gt;blockSize / 512
<a name="l00295"></a>00295             ); <span class="comment">// dev-&gt;write</span>
<a name="l00296"></a>00296 
<a name="l00297"></a>00297   <span class="keyword">delete</span> inode;
<a name="l00298"></a>00298   <span class="keyword">delete</span> bth;
<a name="l00299"></a>00299   <span class="keyword">delete</span> sb;
<a name="l00300"></a>00300   cout &lt;&lt; <span class="stringliteral">"format complete"</span> &lt;&lt; endl;
<a name="l00301"></a>00301   <span class="keywordflow">return</span> 0;
<a name="l00302"></a>00302 } <span class="comment">// UbixFS::vfs_format</span>
<a name="l00303"></a>00303 
<a name="l00304"></a>00304 <span class="keywordtype">void</span> *
<a name="l00305"></a><a class="code" href="classUbixFS.html#b1422145c6575f723179b60421a494aa">00305</a> <a class="code" href="classUbixFS.html#b1422145c6575f723179b60421a494aa">UbixFS::vfs_mknod</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *path, <a class="code" href="kern__descrip_8h.html#e9f148ba55d84268ecb6f8031ab45076">mode_t</a> mode) {
<a name="l00306"></a>00306   <span class="keywordflow">return</span> <a class="code" href="classUbixFS.html#94e296e37c8176b5f5ba88a2251b70ab">mknod</a>(path, 0, mode);  <span class="comment">// &lt;- this probably isn't correct</span>
<a name="l00307"></a>00307 } <span class="comment">// UbixFS::vfs_mknod</span>
<a name="l00308"></a>00308 
<a name="l00309"></a>00309 <span class="keywordtype">int</span>
<a name="l00310"></a><a class="code" href="classUbixFS.html#d3e28ccdb5cd84d63e5d6e9db2fc3e65">00310</a> <a class="code" href="classUbixFS.html#d3e28ccdb5cd84d63e5d6e9db2fc3e65">UbixFS::vfs_open</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * filename, <a class="code" href="structfileDescriptor.html">fileDescriptor</a> * fd, <span class="keywordtype">int</span> flags, ...) {
<a name="l00311"></a>00311   <span class="keywordflow">if</span> (filename == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || fd == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> -1;
<a name="l00312"></a>00312   flags = flags;
<a name="l00313"></a>00313   fd-&gt;<a class="code" href="structfileDescriptor.html#d6e69b4726ce93464490201390a9d922">inode</a> = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00314"></a>00314   fd-&gt;<a class="code" href="structfileDescriptor.html#09c5cd0d4979a70b8d7098319cd00b7c">offset</a> = 0;
<a name="l00315"></a>00315   fd-&gt;<a class="code" href="structfileDescriptor.html#2967356da3f80c5df1405f4e2fb4272b">size</a> = 0;
<a name="l00316"></a>00316   <span class="comment">// look up the file here</span>
<a name="l00317"></a>00317   <span class="keywordflow">return</span> 0;
<a name="l00318"></a>00318 } <span class="comment">// UbixFS::vfs_open</span>
<a name="l00319"></a>00319 
<a name="l00320"></a>00320 <a class="code" href="include_2ubixos_2types_8h.html#7619b847aeded8a6d14cbfa212b2cdfb">size_t</a>
<a name="l00321"></a><a class="code" href="classUbixFS.html#0fce9a3abd07c65fa9af38e51517310a">00321</a> <a class="code" href="classUbixFS.html#0fce9a3abd07c65fa9af38e51517310a">UbixFS::vfs_read</a>(<a class="code" href="structfileDescriptor.html">fileDescriptor</a> * fd, <span class="keywordtype">void</span> * data, <a class="code" href="include_2ubixos_2types_8h.html#fa178be408981cc5edd64227b6332fc6">off_t</a> offset, <a class="code" href="include_2ubixos_2types_8h.html#7619b847aeded8a6d14cbfa212b2cdfb">size_t</a> size) {
<a name="l00322"></a>00322   
<a name="l00323"></a>00323   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;
<a name="l00324"></a>00324   <a class="code" href="include_2ubixos_2types_8h.html#fa178be408981cc5edd64227b6332fc6">off_t</a> sum, startingBlock;
<a name="l00325"></a>00325   <a class="code" href="include_2ubixos_2types_8h.html#7619b847aeded8a6d14cbfa212b2cdfb">size_t</a> runSize, sectorCount, totalSize, bSize; <span class="comment">// blockSize</span>
<a name="l00326"></a>00326   <a class="code" href="structubixfsInode.html">ubixfsInode</a> * inode = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00327"></a>00327 
<a name="l00328"></a>00328   <span class="keywordflow">if</span> (fd == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || data == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> ~0;
<a name="l00329"></a>00329 
<a name="l00330"></a>00330   <span class="keywordflow">if</span> (size == 0) <span class="keywordflow">return</span> 0; <span class="comment">// don't fail if size is 0?</span>
<a name="l00331"></a>00331    
<a name="l00332"></a>00332   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="structdevice.html">device</a>);
<a name="l00333"></a>00333   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>);
<a name="l00334"></a>00334 
<a name="l00335"></a>00335   inode = static_cast&lt;ubixfsInode *&gt;(fd-&gt;<a class="code" href="structfileDescriptor.html#d6e69b4726ce93464490201390a9d922">inode</a>);
<a name="l00336"></a>00336 
<a name="l00337"></a>00337   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(inode);
<a name="l00338"></a>00338 
<a name="l00339"></a>00339   bSize = <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blockSize;
<a name="l00340"></a>00340 
<a name="l00341"></a>00341   totalSize = sum = i = 0;
<a name="l00342"></a>00342   
<a name="l00343"></a>00343   <span class="keywordflow">while</span> (size &gt; 0) {
<a name="l00344"></a>00344 
<a name="l00345"></a>00345     <span class="comment">/*</span>
<a name="l00346"></a>00346 <span class="comment">     * place check here to see which set of blocks we're looking through</span>
<a name="l00347"></a>00347 <span class="comment">     */</span>
<a name="l00348"></a>00348 
<a name="l00349"></a>00349     <span class="comment">// scan through direct blocks</span>
<a name="l00350"></a>00350     <span class="keywordflow">do</span> {
<a name="l00351"></a>00351       <span class="keywordflow">if</span> (offset &gt;= sum &amp;&amp; offset &lt; sum + inode-&gt;blocks.direct[i].len * bSize)          <span class="keywordflow">break</span>;
<a name="l00352"></a>00352 
<a name="l00353"></a>00353       sum += inode-&gt;blocks.direct[i++].len * bSize;
<a name="l00354"></a>00354      
<a name="l00355"></a>00355     } <span class="keywordflow">while</span> (i &lt; <a class="code" href="ubixfsv2_2ubixfs_8h.html#30ca66da1223315f426910bd6de581f7">NUM_DIRECT_BLOCKS</a>);
<a name="l00356"></a>00356 
<a name="l00357"></a>00357     startingBlock = (inode-&gt;blocks.direct[i].AG &lt;&lt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;AGShift) + 
<a name="l00358"></a>00358                      inode-&gt;blocks.direct[i].start + ((offset - sum) / bSize);
<a name="l00359"></a>00359 
<a name="l00360"></a>00360     runSize = inode-&gt;blocks.direct[i].len * bSize;
<a name="l00361"></a>00361 
<a name="l00362"></a>00362     <span class="comment">// startingBlock is in 4k blocks</span>
<a name="l00363"></a>00363     startingBlock *= (bSize / 512);
<a name="l00364"></a>00364     <span class="comment">// startingBlock is now in sectors</span>
<a name="l00365"></a>00365 
<a name="l00366"></a>00366     <span class="keywordflow">if</span> (runSize &gt;= size) {
<a name="l00367"></a>00367       runSize = size;
<a name="l00368"></a>00368       size = 0;
<a name="l00369"></a>00369     } <span class="keywordflow">else</span> { 
<a name="l00370"></a>00370       size -= runSize;
<a name="l00371"></a>00371     } <span class="comment">// else</span>
<a name="l00372"></a>00372 
<a name="l00373"></a>00373     sectorCount = runSize / 512;
<a name="l00374"></a>00374   
<a name="l00375"></a>00375     cout &lt;&lt; <span class="stringliteral">"device-&gt;read(device, data, "</span> &lt;&lt; startingBlock &lt;&lt; <span class="stringliteral">", "</span>;
<a name="l00376"></a>00376     cout &lt;&lt; sectorCount &lt;&lt; <span class="stringliteral">");"</span> &lt;&lt; endl; 
<a name="l00377"></a>00377 
<a name="l00378"></a>00378     <a class="code" href="structdevice.html">device</a>-&gt;read(<a class="code" href="structdevice.html">device</a>, data, startingBlock, sectorCount);
<a name="l00379"></a>00379 
<a name="l00380"></a>00380     (<a class="code" href="include_2ubixos_2types_8h.html#a4e0f27a9aca905e340c06d2dcae843c">uInt8</a> *)data += runSize;
<a name="l00381"></a>00381     totalSize += runSize;
<a name="l00382"></a>00382   } <span class="comment">// while  </span>
<a name="l00383"></a>00383   <span class="keywordflow">return</span> totalSize;
<a name="l00384"></a>00384 } <span class="comment">// UbixFS::vfs_read</span>
<a name="l00385"></a>00385 
<a name="l00386"></a>00386 <a class="code" href="include_2ubixos_2types_8h.html#7619b847aeded8a6d14cbfa212b2cdfb">size_t</a>
<a name="l00387"></a><a class="code" href="classUbixFS.html#551d3daae6a65555a220de05eb619930">00387</a> <a class="code" href="classUbixFS.html#551d3daae6a65555a220de05eb619930">UbixFS::vfs_write</a>(<a class="code" href="structfileDescriptor.html">fileDescriptor</a> * fd, <span class="keywordtype">void</span> * data, <a class="code" href="include_2ubixos_2types_8h.html#fa178be408981cc5edd64227b6332fc6">off_t</a> offset, <a class="code" href="include_2ubixos_2types_8h.html#7619b847aeded8a6d14cbfa212b2cdfb">size_t</a> size) {
<a name="l00388"></a>00388   <span class="comment">// char * sector[512];  // used to pad</span>
<a name="l00389"></a>00389   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i, whichBlocks;
<a name="l00390"></a>00390   <a class="code" href="include_2ubixos_2types_8h.html#fa178be408981cc5edd64227b6332fc6">off_t</a> sum, startingBlock, EORPos, maxRange;
<a name="l00391"></a>00391   <a class="code" href="include_2ubixos_2types_8h.html#7619b847aeded8a6d14cbfa212b2cdfb">size_t</a> runSize, runRemainder, sectorCount, totalSize, bSize; <span class="comment">// blockSize</span>
<a name="l00392"></a>00392   <a class="code" href="structubixfsInode.html">ubixfsInode</a> * inode = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00393"></a>00393   <a class="code" href="structblockRun.html">blockRun</a> br;
<a name="l00394"></a>00394 
<a name="l00395"></a>00395   <span class="keywordflow">if</span> (fd == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || data == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> ~0;
<a name="l00396"></a>00396 
<a name="l00397"></a>00397   <span class="keywordflow">if</span> (size == 0) <span class="keywordflow">return</span> 0; <span class="comment">// don't fail if size is 0?</span>
<a name="l00398"></a>00398 
<a name="l00399"></a>00399   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="structdevice.html">device</a>);
<a name="l00400"></a>00400   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>);
<a name="l00401"></a>00401 
<a name="l00402"></a>00402   inode = static_cast&lt;ubixfsInode *&gt;(fd-&gt;<a class="code" href="structfileDescriptor.html#d6e69b4726ce93464490201390a9d922">inode</a>);
<a name="l00403"></a>00403 
<a name="l00404"></a>00404   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(inode);
<a name="l00405"></a>00405 
<a name="l00406"></a>00406   bSize = <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blockSize;
<a name="l00407"></a>00407   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(bSize != 0);
<a name="l00408"></a>00408 
<a name="l00409"></a>00409   totalSize = sum = i = whichBlocks = 0;
<a name="l00410"></a>00410 
<a name="l00411"></a>00411   EORPos = offset + size;  <span class="comment">// compute End Of Run Position</span>
<a name="l00412"></a>00412   maxRange = inode-&gt;blocks.maxDirectRange;
<a name="l00413"></a>00413 
<a name="l00414"></a>00414   <span class="keywordflow">if</span> (inode-&gt;blocks.maxIndirectRange &gt; maxRange) {
<a name="l00415"></a>00415     maxRange = inode-&gt;blocks.maxIndirectRange;
<a name="l00416"></a>00416     whichBlocks = 1;
<a name="l00417"></a>00417   }
<a name="l00418"></a>00418 
<a name="l00419"></a>00419   <span class="keywordflow">if</span> (inode-&gt;blocks.maxDoubleIndirectRange &gt; maxRange) {
<a name="l00420"></a>00420     maxRange = inode-&gt;blocks.maxDoubleIndirectRange;
<a name="l00421"></a>00421     whichBlocks = 2;
<a name="l00422"></a>00422   } 
<a name="l00423"></a>00423   
<a name="l00424"></a>00424   <span class="keywordflow">if</span> (EORPos &gt; maxRange) {
<a name="l00425"></a>00425     <span class="comment">/* </span>
<a name="l00426"></a>00426 <span class="comment">     * The offset+size is greater than the size of the file, so we need to</span>
<a name="l00427"></a>00427 <span class="comment">     * extend out the file. Scan through the direct blocks (FIX LATER)</span>
<a name="l00428"></a>00428 <span class="comment">     * to find out where we need to extend</span>
<a name="l00429"></a>00429 <span class="comment">     */</span>
<a name="l00430"></a>00430     <span class="keywordflow">switch</span> (whichBlocks) {
<a name="l00431"></a>00431       <span class="keywordflow">case</span> 0:
<a name="l00432"></a>00432         <span class="keywordflow">while</span> (i &lt; NUM_DIRECT_BLOCKS &amp;&amp; inode-&gt;blocks.direct[i].len != 0) ++i;
<a name="l00433"></a>00433         <span class="comment">// i holds which direct block we're going to add to</span>
<a name="l00434"></a>00434         <span class="keywordflow">break</span>;
<a name="l00435"></a>00435       <span class="keywordflow">case</span> 1:
<a name="l00436"></a>00436       <span class="keywordflow">case</span> 2:
<a name="l00437"></a>00437         <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<span class="keyword">false</span>);  <span class="comment">// UNFINISHED</span>
<a name="l00438"></a>00438         <span class="keywordflow">break</span>;
<a name="l00439"></a>00439       <span class="keywordflow">default</span>:
<a name="l00440"></a>00440         <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<span class="keyword">false</span>);  <span class="comment">// sanity check</span>
<a name="l00441"></a>00441     } <span class="comment">// switch</span>
<a name="l00442"></a>00442 
<a name="l00443"></a>00443     <span class="comment">/*</span>
<a name="l00444"></a>00444 <span class="comment">     * NOTE: it's possible that if we scan through to find where the</span>
<a name="l00445"></a>00445 <span class="comment">     * run goes, we might be able to extend the previous block extent.</span>
<a name="l00446"></a>00446 <span class="comment">     * This will require that we set up br.start to be where we'd like to</span>
<a name="l00447"></a>00447 <span class="comment">     * start looking through the free block list, and then modifying</span>
<a name="l00448"></a>00448 <span class="comment">     * getFreeBlock() to honour that.</span>
<a name="l00449"></a>00449 <span class="comment">     */</span>
<a name="l00450"></a>00450 
<a name="l00451"></a>00451     br.AG = inode-&gt;inodeNum.AG;        <span class="comment">// request a sane allocation group</span>
<a name="l00452"></a>00452     br.start = 0;                      <span class="comment">// getFreeBlock() will ignore this</span>
<a name="l00453"></a>00453 
<a name="l00454"></a>00454     <span class="comment">/*</span>
<a name="l00455"></a>00455 <span class="comment">     * The length that we need is determined by how much extra slack we </span>
<a name="l00456"></a>00456 <span class="comment">     * already have in the pre-allocated blocks.</span>
<a name="l00457"></a>00457 <span class="comment">     * e.g. (assumes 4k blocks)</span>
<a name="l00458"></a>00458 <span class="comment">     * bSize = 4096</span>
<a name="l00459"></a>00459 <span class="comment">     * maxRange = 4096</span>
<a name="l00460"></a>00460 <span class="comment">     * size = 3000</span>
<a name="l00461"></a>00461 <span class="comment">     * offset = 3000</span>
<a name="l00462"></a>00462 <span class="comment">     * size = 4000</span>
<a name="l00463"></a>00463 <span class="comment">     * [--- data block ---][--- data block ---]  &lt;---- blocks on disk</span>
<a name="l00464"></a>00464 <span class="comment">     * &lt;-file data-&gt;                             &lt;---- actual file size</span>
<a name="l00465"></a>00465 <span class="comment">     *              &lt;-----&gt;                      &lt;---- slack</span>
<a name="l00466"></a>00466 <span class="comment">     * [  data block size ]                      &lt;---- maxRange</span>
<a name="l00467"></a>00467 <span class="comment">     *              |                            &lt;---- offset</span>
<a name="l00468"></a>00468 <span class="comment">     *              *****************            &lt;---- new data</span>
<a name="l00469"></a>00469 <span class="comment">     *</span>
<a name="l00470"></a>00470 <span class="comment">     * In the above example, you'd need at least one more block to write</span>
<a name="l00471"></a>00471 <span class="comment">     * out the data.  </span>
<a name="l00472"></a>00472 <span class="comment">     * ((offset + size) - maxRange + (bSize-1)) / bSize</span>
<a name="l00473"></a>00473 <span class="comment">     * ((3000 + 4000) - 4096 + (4095)) / 4096 == 1 (rounded down)</span>
<a name="l00474"></a>00474 <span class="comment">     * And then we expand it by a little extra so we don't have to keep </span>
<a name="l00475"></a>00475 <span class="comment">     * looking for more blocks. Currently we use 32k of slack (or 8 blocks)</span>
<a name="l00476"></a>00476 <span class="comment">     */</span>
<a name="l00477"></a>00477 
<a name="l00478"></a>00478     br.len = ((EORPos - maxRange + (bSize-1)) / bSize);
<a name="l00479"></a>00479 
<a name="l00480"></a>00480     <span class="keywordflow">if</span> (br.len &lt; 8) br.len = 8;  <span class="comment">// we allocate 32k if the file needs to grow</span>
<a name="l00481"></a>00481 
<a name="l00482"></a>00482     br = <a class="code" href="classUbixFS.html#092741c58dade79091213126d592be65">getFreeBlock</a>(br);
<a name="l00483"></a>00483     <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(br.len &gt; 0);
<a name="l00484"></a>00484     <span class="keywordflow">switch</span> (whichBlocks) {
<a name="l00485"></a>00485       <span class="keywordflow">case</span> 0:
<a name="l00486"></a>00486         inode-&gt;blocks.direct[i] = br;
<a name="l00487"></a>00487         inode-&gt;blocks.maxDirectRange += br.len * bSize;
<a name="l00488"></a>00488         <span class="keywordflow">break</span>;
<a name="l00489"></a>00489       <span class="keywordflow">case</span> 1:
<a name="l00490"></a>00490         <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<span class="keyword">false</span>); <span class="comment">// UNFINISHED</span>
<a name="l00491"></a>00491         inode-&gt;blocks.maxIndirectRange += br.len * bSize;
<a name="l00492"></a>00492         <span class="keywordflow">break</span>;
<a name="l00493"></a>00493       <span class="keywordflow">case</span> 2:
<a name="l00494"></a>00494         <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<span class="keyword">false</span>); <span class="comment">// UNFINISHED</span>
<a name="l00495"></a>00495         inode-&gt;blocks.maxDoubleIndirectRange += br.len * bSize;
<a name="l00496"></a>00496         <span class="keywordflow">break</span>;
<a name="l00497"></a>00497       <span class="keywordflow">default</span>:   
<a name="l00498"></a>00498         <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(<span class="keyword">false</span>); <span class="comment">// sanity check</span>
<a name="l00499"></a>00499     } <span class="comment">// switch</span>
<a name="l00500"></a>00500 
<a name="l00501"></a>00501     inode-&gt;blocks.size = EORPos;
<a name="l00502"></a>00502   } <span class="comment">// if</span>
<a name="l00503"></a>00503 
<a name="l00504"></a>00504 
<a name="l00505"></a>00505   runRemainder = size % 512;
<a name="l00506"></a>00506   size -= runRemainder;
<a name="l00507"></a>00507 
<a name="l00508"></a>00508   totalSize = sum = i = 0;
<a name="l00509"></a>00509 
<a name="l00510"></a>00510   <span class="keywordflow">while</span> (size &gt; 0) {
<a name="l00511"></a>00511 
<a name="l00512"></a>00512     <span class="comment">/*</span>
<a name="l00513"></a>00513 <span class="comment">     * place check here to see which set of blocks we're looking through</span>
<a name="l00514"></a>00514 <span class="comment">     */</span>
<a name="l00515"></a>00515 
<a name="l00516"></a>00516     <span class="comment">// scan through direct blocks</span>
<a name="l00517"></a>00517     <span class="keywordflow">do</span> {
<a name="l00518"></a>00518       <span class="keywordflow">if</span> (offset &gt;= sum &amp;&amp; offset &lt; sum + inode-&gt;blocks.direct[i].len * bSize)
<a name="l00519"></a>00519         <span class="keywordflow">break</span>;
<a name="l00520"></a>00520 
<a name="l00521"></a>00521       sum += inode-&gt;blocks.direct[i++].len * bSize;
<a name="l00522"></a>00522 
<a name="l00523"></a>00523     } <span class="keywordflow">while</span> (i &lt; <a class="code" href="ubixfsv2_2ubixfs_8h.html#30ca66da1223315f426910bd6de581f7">NUM_DIRECT_BLOCKS</a>);
<a name="l00524"></a>00524 
<a name="l00525"></a>00525     startingBlock = (inode-&gt;blocks.direct[i].AG &lt;&lt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;AGShift) +
<a name="l00526"></a>00526                      inode-&gt;blocks.direct[i].start + ((offset - sum) / bSize);
<a name="l00527"></a>00527 
<a name="l00528"></a>00528     runSize = inode-&gt;blocks.direct[i].len * bSize;
<a name="l00529"></a>00529 
<a name="l00530"></a>00530     <span class="comment">// startingBlock is in 4k blocks</span>
<a name="l00531"></a>00531     startingBlock *= (bSize / 512);
<a name="l00532"></a>00532     <span class="comment">// startingBlock is now in sectors</span>
<a name="l00533"></a>00533 
<a name="l00534"></a>00534     <span class="keywordflow">if</span> (runSize &gt;= size) {
<a name="l00535"></a>00535       runSize = size;
<a name="l00536"></a>00536       size = 0;
<a name="l00537"></a>00537     } <span class="keywordflow">else</span> {
<a name="l00538"></a>00538       size -= runSize;
<a name="l00539"></a>00539     } <span class="comment">// else</span>
<a name="l00540"></a>00540 
<a name="l00541"></a>00541     sectorCount = runSize / 512;
<a name="l00542"></a>00542 
<a name="l00543"></a>00543     cout &lt;&lt; <span class="stringliteral">"device-&gt;write(device, data, "</span> &lt;&lt; startingBlock &lt;&lt; <span class="stringliteral">", "</span>;
<a name="l00544"></a>00544     cout &lt;&lt; sectorCount &lt;&lt; <span class="stringliteral">");"</span> &lt;&lt; endl;
<a name="l00545"></a>00545 
<a name="l00546"></a>00546     <a class="code" href="structdevice.html">device</a>-&gt;write(<a class="code" href="structdevice.html">device</a>, data, startingBlock, sectorCount);
<a name="l00547"></a>00547 
<a name="l00548"></a>00548     (<a class="code" href="include_2ubixos_2types_8h.html#a4e0f27a9aca905e340c06d2dcae843c">uInt8</a> *)data += runSize;
<a name="l00549"></a>00549     totalSize += runSize;
<a name="l00550"></a>00550   } <span class="comment">// while</span>
<a name="l00551"></a>00551 
<a name="l00552"></a>00552   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(runRemainder != 0);  <span class="comment">// UNFINISHED</span>
<a name="l00553"></a>00553   <span class="keywordflow">return</span> totalSize;
<a name="l00554"></a>00554 } <span class="comment">// UbixFS::vfs_write</span>
<a name="l00555"></a>00555 
<a name="l00556"></a>00556 <span class="keywordtype">int</span>
<a name="l00557"></a><a class="code" href="classUbixFS.html#c2ccea3f574eaa7d4700748d0b4bde71">00557</a> <a class="code" href="classUbixFS.html#c2ccea3f574eaa7d4700748d0b4bde71">UbixFS::vfs_stop</a>(<span class="keywordtype">void</span>) {
<a name="l00558"></a>00558   <span class="keywordflow">if</span> (<a class="code" href="classUbixFS.html#5610078343779a3c5e3046283d482766">vfs_sync</a>() != 0) <span class="keywordflow">return</span> -1;
<a name="l00559"></a>00559 
<a name="l00560"></a>00560   <span class="comment">// you must delete the root dir first, in case it needs to</span>
<a name="l00561"></a>00561   <span class="comment">// still write anything out</span>
<a name="l00562"></a>00562 
<a name="l00563"></a>00563   <span class="keywordflow">if</span> (<a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a> != <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) {
<a name="l00564"></a>00564     <a class="code" href="structubixfsInode.html">ubixfsInode</a> * rootInode = static_cast&lt;ubixfsInode *&gt;(<a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a>-&gt;<a class="code" href="structfileDescriptor.html#d6e69b4726ce93464490201390a9d922">inode</a>);
<a name="l00565"></a>00565     <span class="keyword">delete</span> rootInode-&gt;data.btPtr; 
<a name="l00566"></a>00566     <span class="keyword">delete</span> rootInode;
<a name="l00567"></a>00567     <a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a>-&gt;<a class="code" href="structfileDescriptor.html#d6e69b4726ce93464490201390a9d922">inode</a> = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00568"></a>00568     
<a name="l00569"></a>00569   } <span class="comment">// if</span>
<a name="l00570"></a>00570 
<a name="l00571"></a>00571   <span class="keyword">delete</span> <a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a>;
<a name="l00572"></a>00572   <span class="keyword">delete</span> [] <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a>;
<a name="l00573"></a>00573   <span class="keyword">delete</span> <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>;
<a name="l00574"></a>00574 
<a name="l00575"></a>00575   <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00576"></a>00576   <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a> = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>; 
<a name="l00577"></a>00577   <a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a> = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00578"></a>00578 
<a name="l00579"></a>00579   <span class="comment">/* </span>
<a name="l00580"></a>00580 <span class="comment">   * The device isn't null at this point, allowing for people to restart</span>
<a name="l00581"></a>00581 <span class="comment">   * the mount point. Or, alternatively, to blow things up.</span>
<a name="l00582"></a>00582 <span class="comment">   */</span>
<a name="l00583"></a>00583   
<a name="l00584"></a>00584   <span class="keywordflow">return</span> 0;
<a name="l00585"></a>00585 } <span class="comment">// UbixFS::vfs_stop</span>
<a name="l00586"></a>00586 
<a name="l00587"></a>00587 <span class="keywordtype">int</span>
<a name="l00588"></a><a class="code" href="classUbixFS.html#5610078343779a3c5e3046283d482766">00588</a> <a class="code" href="classUbixFS.html#5610078343779a3c5e3046283d482766">UbixFS::vfs_sync</a>(<span class="keywordtype">void</span>) {
<a name="l00589"></a>00589   <span class="keywordflow">if</span> (<a class="code" href="structdevice.html">device</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> -1;
<a name="l00590"></a>00590   <a class="code" href="structdevice.html">device</a>-&gt;write(<a class="code" href="structdevice.html">device</a>, 
<a name="l00591"></a>00591                 <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a>, 
<a name="l00592"></a>00592                 <a class="code" href="structdevice.html">device</a>-&gt;sectors - <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;batSectors - 1, 
<a name="l00593"></a>00593                 <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;batSectors
<a name="l00594"></a>00594                );
<a name="l00595"></a>00595   <a class="code" href="structdevice.html">device</a>-&gt;write(<a class="code" href="structdevice.html">device</a>, <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>, <a class="code" href="structdevice.html">device</a>-&gt;sectors-1, 1);
<a name="l00596"></a>00596   <span class="keywordflow">return</span> 0;
<a name="l00597"></a>00597 } <span class="comment">// UbixFS::vfs_sync</span>
<a name="l00598"></a>00598 
<a name="l00599"></a>00599 <span class="keywordtype">void</span>
<a name="l00600"></a><a class="code" href="classUbixFS.html#0fe83377d78fbdc768054870fc8d4f3d">00600</a> <a class="code" href="classUbixFS.html#0fe83377d78fbdc768054870fc8d4f3d">UbixFS::setFreeBlock</a>(<a class="code" href="structblockRun.html">blockRun</a> ibr) {
<a name="l00601"></a>00601   <span class="keywordtype">signed</span> <span class="keywordtype">char</span> * ptr;
<a name="l00602"></a>00602   
<a name="l00603"></a>00603   <span class="keywordflow">if</span> (<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span>;
<a name="l00604"></a>00604   <span class="keywordflow">if</span> (ibr.len == 0) <span class="keywordflow">return</span>;
<a name="l00605"></a>00605   ptr = <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> + ((ibr.AG &lt;&lt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;AGShift) &gt;&gt; 3);
<a name="l00606"></a>00606   ptr += ibr.start &gt;&gt; 3;
<a name="l00607"></a>00607 
<a name="l00608"></a>00608   <span class="keywordflow">if</span> (ibr.start % 8 != 0) {
<a name="l00609"></a>00609     
<a name="l00610"></a>00610     ibr.len -= ibr.start % 8;
<a name="l00611"></a>00611   } <span class="comment">// if</span>
<a name="l00612"></a>00612 
<a name="l00613"></a>00613 } <span class="comment">// UbixFS::setFreeBlock</span>
<a name="l00614"></a>00614 
<a name="l00615"></a>00615 <a class="code" href="structblockRun.html">blockRun</a>
<a name="l00616"></a><a class="code" href="classUbixFS.html#038f1a28d415b5198717466215edde0f">00616</a> <a class="code" href="classUbixFS.html#092741c58dade79091213126d592be65">UbixFS::getFreeBlock</a>(<a class="code" href="structblockRun.html">blockRun</a> ibr) {
<a name="l00617"></a>00617   <span class="keywordtype">signed</span> <span class="keywordtype">char</span> * ptr;
<a name="l00618"></a>00618   <span class="keywordtype">signed</span> <span class="keywordtype">char</span> * holdPtr;
<a name="l00619"></a>00619   <a class="code" href="ubixfsv2_2types_8h.html#56f1a81c92849566ae864511088eb7e8">int32</a> count, holdCount;
<a name="l00620"></a>00620 
<a name="l00621"></a>00621   <a class="code" href="structblockRun.html">blockRun</a> obr = {0, 0, 0};  <span class="comment">// output block run</span>
<a name="l00622"></a>00622 
<a name="l00623"></a>00623   <span class="comment">// Check to make sure none of these are null</span>
<a name="l00624"></a>00624   <span class="keywordflow">if</span> (<a class="code" href="structdevice.html">device</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> obr;
<a name="l00625"></a>00625 
<a name="l00626"></a>00626   <span class="keywordflow">if</span> (ibr.len == 0) <span class="keywordflow">return</span> obr;
<a name="l00627"></a>00627 
<a name="l00628"></a>00628   <span class="keywordflow">if</span> (ibr.len &gt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;numBlocks) <span class="keywordflow">return</span> obr;
<a name="l00629"></a>00629 
<a name="l00630"></a>00630   <span class="keywordflow">if</span> (ibr.len == 1) <span class="keywordflow">return</span> <a class="code" href="classUbixFS.html#092741c58dade79091213126d592be65">getFreeBlock</a>(ibr.AG);
<a name="l00631"></a>00631   <span class="comment">/*</span>
<a name="l00632"></a>00632 <span class="comment">   * count is the block from the base of the list.</span>
<a name="l00633"></a>00633 <span class="comment">   * Since we're given a specific AG to look through, we start the count at</span>
<a name="l00634"></a>00634 <span class="comment">   * AG &lt;&lt; AGShift, where AGShift is the shift value of the number of blocks</span>
<a name="l00635"></a>00635 <span class="comment">   * in an AG</span>
<a name="l00636"></a>00636 <span class="comment">   */</span>
<a name="l00637"></a>00637 
<a name="l00638"></a>00638   count = (ibr.AG &lt;&lt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;AGShift);
<a name="l00639"></a>00639 
<a name="l00640"></a>00640   <span class="comment">/*</span>
<a name="l00641"></a>00641 <span class="comment">   * The freeBlockList is a bit map of the free/used blocks.</span>
<a name="l00642"></a>00642 <span class="comment">   * Used = on bit</span>
<a name="l00643"></a>00643 <span class="comment">   * Unused = off bit</span>
<a name="l00644"></a>00644 <span class="comment">   * There are 8 bits per byte (hopefully) and so we have to divide the count</span>
<a name="l00645"></a>00645 <span class="comment">   * by 8 to get our starting byte offset to look from</span>
<a name="l00646"></a>00646 <span class="comment">   */</span>
<a name="l00647"></a>00647 
<a name="l00648"></a>00648   ptr = <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> + (count &gt;&gt; 3);
<a name="l00649"></a>00649 
<a name="l00650"></a>00650 rescan:
<a name="l00651"></a>00651   <span class="comment">// look for the first free 8 blocks (this may create holes)</span>
<a name="l00652"></a>00652   <span class="keywordflow">while</span> (*ptr != 0) {
<a name="l00653"></a>00653     ++ptr;
<a name="l00654"></a>00654     count += 8;
<a name="l00655"></a>00655     <span class="keywordflow">if</span> (count+8 &gt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;numBlocks) {
<a name="l00656"></a>00656       ptr = <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a>;
<a name="l00657"></a>00657       count = 0;
<a name="l00658"></a>00658     } <span class="comment">// if </span>
<a name="l00659"></a>00659   } <span class="comment">// while *ptr != 0</span>
<a name="l00660"></a>00660 
<a name="l00661"></a>00661   holdPtr = ptr;
<a name="l00662"></a>00662   holdCount = count;
<a name="l00663"></a>00663 
<a name="l00664"></a>00664   <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> i = 0; i &lt; ((ibr.len+7) / 8); i++) {
<a name="l00665"></a>00665     ++ptr;
<a name="l00666"></a>00666     count += 8;
<a name="l00667"></a>00667     <span class="keywordflow">if</span> (count+8 &gt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;numBlocks) {
<a name="l00668"></a>00668       ptr = <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a>;
<a name="l00669"></a>00669       count = 0;
<a name="l00670"></a>00670       <span class="keywordflow">goto</span> rescan;
<a name="l00671"></a>00671     } <span class="comment">// if</span>
<a name="l00672"></a>00672     <span class="keywordflow">if</span> (*ptr != 0) <span class="keywordflow">goto</span> rescan;
<a name="l00673"></a>00673   } <span class="comment">// for i</span>
<a name="l00674"></a>00674 
<a name="l00675"></a>00675   <span class="comment">// we have found a range of blocks that work for us</span>
<a name="l00676"></a>00676 
<a name="l00677"></a>00677   obr.AG = holdCount / <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blocksPerAG;
<a name="l00678"></a>00678   obr.start = holdCount % <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blocksPerAG;
<a name="l00679"></a>00679   obr.len = ibr.len;
<a name="l00680"></a>00680 
<a name="l00681"></a>00681   <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> i = 0; i &lt; (ibr.len / 8); i++) {
<a name="l00682"></a>00682     *holdPtr = -1;
<a name="l00683"></a>00683     ++holdPtr;
<a name="l00684"></a>00684   } <span class="comment">// for</span>
<a name="l00685"></a>00685 
<a name="l00686"></a>00686   <span class="keywordflow">if</span> (ibr.len % 8 != 0) *holdPtr = (-1 &lt;&lt; (8-(ibr.len % 8)));
<a name="l00687"></a>00687 
<a name="l00688"></a>00688   <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;usedBlocks += ibr.len;   <span class="comment">// increment the number of used blocks</span>
<a name="l00689"></a>00689   <span class="keywordflow">return</span> obr;
<a name="l00690"></a>00690 } <span class="comment">// UbixFS::getFreeBlock</span>
<a name="l00691"></a>00691 
<a name="l00692"></a>00692 <a class="code" href="structblockRun.html">blockRun</a>
<a name="l00693"></a><a class="code" href="classUbixFS.html#c104fac0637432050288cd612f33f5cf">00693</a> <a class="code" href="classUbixFS.html#092741c58dade79091213126d592be65">UbixFS::getFreeBlock</a>(<a class="code" href="include_2ubixos_2types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> AG) {
<a name="l00694"></a>00694   <span class="comment">// AG == AllocationGroup</span>
<a name="l00695"></a>00695   <a class="code" href="structblockRun.html">blockRun</a> br;
<a name="l00696"></a>00696   <span class="keywordtype">signed</span> <span class="keywordtype">char</span> * ptr;
<a name="l00697"></a>00697   <a class="code" href="ubixfsv2_2types_8h.html#56f1a81c92849566ae864511088eb7e8">int32</a> count;
<a name="l00698"></a>00698   <a class="code" href="ubixfsv2_2types_8h.html#56f1a81c92849566ae864511088eb7e8">int32</a> subCount = 128;
<a name="l00699"></a>00699 
<a name="l00700"></a>00700   br.AG = 0;
<a name="l00701"></a>00701   br.start = 0;
<a name="l00702"></a>00702   br.len = 0;
<a name="l00703"></a>00703   <span class="comment">// Check to make sure neither of these are null</span>
<a name="l00704"></a>00704   <span class="keywordflow">if</span> (<a class="code" href="structdevice.html">device</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> br;
<a name="l00705"></a>00705 
<a name="l00706"></a>00706   <span class="comment">// Are there any blocks available?</span>
<a name="l00707"></a>00707   <span class="keywordflow">if</span> (<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;numBlocks == <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;usedBlocks) <span class="keywordflow">return</span> br;
<a name="l00708"></a>00708 
<a name="l00709"></a>00709   <span class="comment">/* </span>
<a name="l00710"></a>00710 <span class="comment">   * count is the block from the base of the list.</span>
<a name="l00711"></a>00711 <span class="comment">   * Since we're given a specific AG to look through, we start the count at</span>
<a name="l00712"></a>00712 <span class="comment">   * AG &lt;&lt; AGShift, where AGShift is the shift value of the number of blocks</span>
<a name="l00713"></a>00713 <span class="comment">   * in an AG </span>
<a name="l00714"></a>00714 <span class="comment">   */</span>
<a name="l00715"></a>00715 
<a name="l00716"></a>00716   count = (AG &lt;&lt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;AGShift);
<a name="l00717"></a>00717 
<a name="l00718"></a>00718   <span class="comment">/*</span>
<a name="l00719"></a>00719 <span class="comment">   * The freeBlockList is a bit map of the free/used blocks. </span>
<a name="l00720"></a>00720 <span class="comment">   * Used = on bit</span>
<a name="l00721"></a>00721 <span class="comment">   * Unused = off bit</span>
<a name="l00722"></a>00722 <span class="comment">   * There are 8 bits per byte (hopefully) and so we have to divide the count</span>
<a name="l00723"></a>00723 <span class="comment">   * by 8 to get our starting byte offset to look from</span>
<a name="l00724"></a>00724 <span class="comment">   */</span>
<a name="l00725"></a>00725 
<a name="l00726"></a>00726   ptr = <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> + (count &gt;&gt; 3);
<a name="l00727"></a>00727 
<a name="l00728"></a>00728   <span class="comment">// Scan through the freeBlockList </span>
<a name="l00729"></a>00729 
<a name="l00730"></a>00730 rescan:
<a name="l00731"></a>00731   <span class="keywordflow">while</span> (*ptr == -1) { 
<a name="l00732"></a>00732     ++ptr;
<a name="l00733"></a>00733     count += 8;
<a name="l00734"></a>00734     <span class="keywordflow">if</span> (count+8 &gt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;numBlocks) <span class="keywordflow">break</span>;
<a name="l00735"></a>00735   } <span class="comment">// while *ptr == -1</span>
<a name="l00736"></a>00736 
<a name="l00737"></a>00737   subCount = 128;
<a name="l00738"></a>00738 
<a name="l00739"></a>00739   <span class="keywordflow">do</span> {
<a name="l00740"></a>00740     <span class="keywordflow">if</span> ((*ptr &amp; subCount) == 0) <span class="keywordflow">break</span>;
<a name="l00741"></a>00741     subCount &gt;&gt;= 1;
<a name="l00742"></a>00742     ++count;
<a name="l00743"></a>00743     <span class="keywordflow">if</span> (count == <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;numBlocks) {
<a name="l00744"></a>00744       count = 0;
<a name="l00745"></a>00745       ptr = <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a>;
<a name="l00746"></a>00746       <span class="keywordflow">goto</span> rescan;
<a name="l00747"></a>00747     } <span class="comment">// if</span>
<a name="l00748"></a>00748   } <span class="keywordflow">while</span>(subCount &gt; 1);
<a name="l00749"></a>00749 
<a name="l00750"></a>00750   *ptr |= subCount;           <span class="comment">// mark this block as used</span>
<a name="l00751"></a>00751   ++<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;usedBlocks;   <span class="comment">// increment the number of used blocks</span>
<a name="l00752"></a>00752 
<a name="l00753"></a>00753   br.AG = count / <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blocksPerAG; 
<a name="l00754"></a>00754   br.start = count % <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blocksPerAG;
<a name="l00755"></a>00755   br.len = 1;
<a name="l00756"></a>00756   <span class="keywordflow">return</span> br;               <span class="comment">// return the allocated block number</span>
<a name="l00757"></a>00757 } <span class="comment">// Ubixfs::getFreeBlock</span>
<a name="l00758"></a>00758 
<a name="l00759"></a>00759 <a class="code" href="include_2ubixos_2types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a>
<a name="l00760"></a><a class="code" href="classUbixFS.html#f16cc9199d1b438ccb1dae81974f6865">00760</a> <a class="code" href="classUbixFS.html#f16cc9199d1b438ccb1dae81974f6865">UbixFS::getNextAG</a>(<span class="keywordtype">void</span>) {
<a name="l00761"></a>00761 
<a name="l00762"></a>00762   <span class="keywordflow">if</span> (<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;lastUsedAG == <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;numAGs) 
<a name="l00763"></a>00763     <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;lastUsedAG = 0;
<a name="l00764"></a>00764   <span class="keywordflow">else</span>
<a name="l00765"></a>00765     <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;lastUsedAG++;
<a name="l00766"></a>00766   <span class="keywordflow">return</span> <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;lastUsedAG;
<a name="l00767"></a>00767 
<a name="l00768"></a>00768 } <span class="comment">// UbixFS::getNextAG</span>
<a name="l00769"></a>00769 
<a name="l00770"></a>00770 <span class="comment">/*</span>
<a name="l00771"></a>00771 <span class="comment"> * UbixFS::getFreeBlock(void)</span>
<a name="l00772"></a>00772 <span class="comment"> * upon success returns a free block based on the next AG after the lastUsedAG</span>
<a name="l00773"></a>00773 <span class="comment"> * failure returns -1</span>
<a name="l00774"></a>00774 <span class="comment"> */</span>
<a name="l00775"></a>00775 
<a name="l00776"></a>00776 <a class="code" href="structblockRun.html">blockRun</a>
<a name="l00777"></a><a class="code" href="classUbixFS.html#092741c58dade79091213126d592be65">00777</a> <a class="code" href="classUbixFS.html#092741c58dade79091213126d592be65">UbixFS::getFreeBlock</a>(<span class="keywordtype">void</span>) {
<a name="l00778"></a>00778   <span class="keywordflow">return</span> <a class="code" href="classUbixFS.html#092741c58dade79091213126d592be65">getFreeBlock</a>(<a class="code" href="classUbixFS.html#f16cc9199d1b438ccb1dae81974f6865">getNextAG</a>());
<a name="l00779"></a>00779 } <span class="comment">// UbixFS::getFreeBlock</span>
<a name="l00780"></a>00780 
<a name="l00781"></a>00781 <a class="code" href="structblockRun.html">blockRun</a>
<a name="l00782"></a><a class="code" href="classUbixFS.html#2e0acd2fb08df1df4645ab91a69dc048">00782</a> <a class="code" href="classUbixFS.html#2e0acd2fb08df1df4645ab91a69dc048">UbixFS::get8FreeBlocks</a>(<a class="code" href="include_2ubixos_2types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> AG) {
<a name="l00783"></a>00783   <span class="comment">// AG == AllocationGroup</span>
<a name="l00784"></a>00784   <a class="code" href="structblockRun.html">blockRun</a> br;
<a name="l00785"></a>00785   <span class="keywordtype">signed</span> <span class="keywordtype">char</span> * ptr;
<a name="l00786"></a>00786   <span class="keywordtype">signed</span> <span class="keywordtype">char</span> * endPtr;
<a name="l00787"></a>00787   <a class="code" href="ubixfsv2_2types_8h.html#56f1a81c92849566ae864511088eb7e8">int32</a> count;
<a name="l00788"></a>00788 
<a name="l00789"></a>00789   br.AG = 0;
<a name="l00790"></a>00790   br.start = 0;
<a name="l00791"></a>00791   br.len = 0;
<a name="l00792"></a>00792 
<a name="l00793"></a>00793   <span class="keywordflow">if</span> (<a class="code" href="structdevice.html">device</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> br;
<a name="l00794"></a>00794 
<a name="l00795"></a>00795   <span class="comment">// Are there any blocks available?</span>
<a name="l00796"></a>00796   <span class="keywordflow">if</span> (<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;usedBlocks+8 &gt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;numBlocks) <span class="keywordflow">return</span> br;
<a name="l00797"></a>00797 
<a name="l00798"></a>00798   <span class="comment">/*</span>
<a name="l00799"></a>00799 <span class="comment">   * count is the block from the base of the list.</span>
<a name="l00800"></a>00800 <span class="comment">   * Since we're given a specific AG to look through, we start the count at</span>
<a name="l00801"></a>00801 <span class="comment">   * AG &lt;&lt; AGShift, where AGShift is the shift value of the number of blocks</span>
<a name="l00802"></a>00802 <span class="comment">   * in an AG</span>
<a name="l00803"></a>00803 <span class="comment">   */</span>
<a name="l00804"></a>00804 
<a name="l00805"></a>00805   count = (AG &lt;&lt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;AGShift);
<a name="l00806"></a>00806 
<a name="l00807"></a>00807   ptr = <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> + (count &gt;&gt; 3);
<a name="l00808"></a>00808   
<a name="l00809"></a>00809   endPtr = <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> + (<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;numBlocks &gt;&gt; 3);
<a name="l00810"></a>00810 
<a name="l00811"></a>00811   <span class="keywordtype">bool</span> secondTime = <span class="keyword">false</span>;
<a name="l00812"></a>00812   <span class="keywordflow">while</span> (*ptr != 0) {
<a name="l00813"></a>00813     ++ptr;
<a name="l00814"></a>00814     count += 8;
<a name="l00815"></a>00815     <span class="keywordflow">if</span> (ptr == endPtr) {
<a name="l00816"></a>00816       <span class="keywordflow">if</span> (secondTime) 
<a name="l00817"></a>00817         <span class="keywordflow">return</span> br; 
<a name="l00818"></a>00818       <span class="keywordflow">else</span> 
<a name="l00819"></a>00819         secondTime = <span class="keyword">true</span>;
<a name="l00820"></a>00820 
<a name="l00821"></a>00821       count = 0;
<a name="l00822"></a>00822       ptr = <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a>;      
<a name="l00823"></a>00823     } <span class="comment">// if</span>
<a name="l00824"></a>00824   } <span class="comment">// while </span>
<a name="l00825"></a>00825 
<a name="l00826"></a>00826   *ptr = -1;   <span class="comment">// mark 8 blocks as taken</span>
<a name="l00827"></a>00827 
<a name="l00828"></a>00828   br.AG = count / <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blocksPerAG;
<a name="l00829"></a>00829   br.start = count % <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blocksPerAG;
<a name="l00830"></a>00830   br.len = 8;
<a name="l00831"></a>00831   <span class="keywordflow">return</span> br;
<a name="l00832"></a>00832 } <span class="comment">// UbixFS::get8FreeBlocks</span>
<a name="l00833"></a>00833 
<a name="l00834"></a>00834 <span class="keywordtype">void</span> *
<a name="l00835"></a><a class="code" href="classUbixFS.html#94e296e37c8176b5f5ba88a2251b70ab">00835</a> <a class="code" href="classUbixFS.html#94e296e37c8176b5f5ba88a2251b70ab">UbixFS::mknod</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *filename, <a class="code" href="structubixfsInode.html">ubixfsInode</a> * parent, <a class="code" href="kern__descrip_8h.html#e9f148ba55d84268ecb6f8031ab45076">mode_t</a> mode) {
<a name="l00836"></a>00836   <a class="code" href="structubixfsInode.html">ubixfsInode</a> * inode = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00837"></a>00837 
<a name="l00838"></a>00838   inode = <span class="keyword">new</span> <a class="code" href="structubixfsInode.html">ubixfsInode</a>;
<a name="l00839"></a>00839   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(inode);
<a name="l00840"></a>00840   <span class="keywordflow">if</span> (inode == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span> <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00841"></a>00841   <a class="code" href="lib_2string_8h.html#ce4b911463887af5e748326323e99a23">memset</a>(inode, 0, <span class="keyword">sizeof</span>(<a class="code" href="structubixfsInode.html">ubixfsInode</a>));
<a name="l00842"></a>00842 
<a name="l00843"></a>00843   inode-&gt;magic1 = <a class="code" href="ubixfsv2_2ubixfs_8h.html#c88e98d44093495af57d4a956b095b9d">UBIXFS_INODE_MAGIC</a>;
<a name="l00844"></a>00844 
<a name="l00845"></a>00845   <span class="comment">/* </span>
<a name="l00846"></a>00846 <span class="comment">   * in retrospect.. I'm not sure why parent would be null.. only the</span>
<a name="l00847"></a>00847 <span class="comment">   * root directory would have a null parent, but that's manually allocated</span>
<a name="l00848"></a>00848 <span class="comment">   * in vfs_format()</span>
<a name="l00849"></a>00849 <span class="comment">   */</span>
<a name="l00850"></a>00850 
<a name="l00851"></a>00851   <span class="keywordflow">if</span> (parent == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) {
<a name="l00852"></a>00852     inode-&gt;inodeNum = <a class="code" href="classUbixFS.html#092741c58dade79091213126d592be65">getFreeBlock</a>();
<a name="l00853"></a>00853     inode-&gt;parent.iAddr.AG = 0;
<a name="l00854"></a>00854     inode-&gt;parent.iAddr.start = 0;
<a name="l00855"></a>00855     inode-&gt;parent.iAddr.len = 0;
<a name="l00856"></a>00856   } <span class="keywordflow">else</span> {
<a name="l00857"></a>00857     inode-&gt;inodeNum = <a class="code" href="classUbixFS.html#092741c58dade79091213126d592be65">getFreeBlock</a>(parent-&gt;inodeNum.AG);
<a name="l00858"></a>00858     inode-&gt;parent.iAddr = parent-&gt;inodeNum;
<a name="l00859"></a>00859   } <span class="comment">// else</span>
<a name="l00860"></a>00860    
<a name="l00861"></a>00861   <a class="code" href="lib_2string_8h.html#2a6bedbfab350cd17b80849f5f9234e9">strncpy</a>(inode-&gt;name, filename, <a class="code" href="ubixfsv2_2ubixfs_8h.html#6773b93f3093658c3dcb569de3b4bdb2">MAX_FILENAME_LENGTH</a>);
<a name="l00862"></a>00862 
<a name="l00863"></a>00863   inode-&gt;uid = <a class="code" href="gen__calls_8h.html#b2bf044f6f20a60f7c4139b527c4bd6c">getuid</a>();
<a name="l00864"></a>00864   inode-&gt;gid = <a class="code" href="gen__calls_8h.html#d78d6c02154727f556f78cca62020c83">getgid</a>();
<a name="l00865"></a>00865   <span class="comment">// inode-&gt;mode</span>
<a name="l00866"></a>00866   inode-&gt;flags = mode;
<a name="l00867"></a>00867   <span class="comment">// inode-&gt;createTime</span>
<a name="l00868"></a>00868   <span class="comment">// inode-&gt;lastModifiedTime</span>
<a name="l00869"></a>00869   inode-&gt;inodeSize = <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;inodeSize;
<a name="l00870"></a>00870 
<a name="l00871"></a>00871   inode-&gt;attributes.AG = 0;
<a name="l00872"></a>00872   inode-&gt;attributes.start = 0;
<a name="l00873"></a>00873   inode-&gt;attributes.len = 0;
<a name="l00874"></a>00874 
<a name="l00875"></a>00875   <span class="comment">// inode-&gt;type </span>
<a name="l00876"></a>00876 
<a name="l00877"></a>00877   <span class="comment">/*</span>
<a name="l00878"></a>00878 <span class="comment">   * next and prev are used in memory to hold pointers to the next/prev</span>
<a name="l00879"></a>00879 <span class="comment">   * inodes in this dir.  On disk they may have another value, but for</span>
<a name="l00880"></a>00880 <span class="comment">   * now they should be set to null.</span>
<a name="l00881"></a>00881 <span class="comment">   */</span>
<a name="l00882"></a>00882 
<a name="l00883"></a>00883   inode-&gt;next.offset = 0;
<a name="l00884"></a>00884   inode-&gt;prev.offset = 0;
<a name="l00885"></a>00885   inode-&gt;refCount = 0;
<a name="l00886"></a>00886   ++<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;inodeCount;
<a name="l00887"></a>00887   <span class="keywordflow">return</span> inode;
<a name="l00888"></a>00888 } <span class="comment">// UbixFS::mknod</span>
<a name="l00889"></a>00889 
<a name="l00890"></a>00890 <span class="keywordtype">int</span>
<a name="l00891"></a><a class="code" href="classUbixFS.html#f93fcff0825ffcdaf05ceefaeb48fd7b">00891</a> <a class="code" href="classUbixFS.html#f93fcff0825ffcdaf05ceefaeb48fd7b">UbixFS::vfs_mkdir</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> * path, <a class="code" href="kern__descrip_8h.html#e9f148ba55d84268ecb6f8031ab45076">mode_t</a> mode) {
<a name="l00892"></a>00892   <span class="keywordtype">char</span> <a class="code" href="pci_8c.html#8f8f80d37794cde9472343e4487ba3eb">name</a>[<a class="code" href="ubixfsv2_2ubixfs_8h.html#6773b93f3093658c3dcb569de3b4bdb2">MAX_FILENAME_LENGTH</a>];
<a name="l00893"></a>00893   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> start, end, len, nameStart;
<a name="l00894"></a>00894   <a class="code" href="structubixfsInode.html">ubixfsInode</a> * dir = static_cast&lt;ubixfsInode *&gt;(<a class="code" href="classUbixFS.html#d7a17314620c3031ee4d1868ea745222">root</a>-&gt;<a class="code" href="structfileDescriptor.html#d6e69b4726ce93464490201390a9d922">inode</a>);
<a name="l00895"></a>00895   <a class="code" href="structubixfsInode.html">ubixfsInode</a> * inode = <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>;
<a name="l00896"></a>00896 
<a name="l00897"></a>00897   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(path);                     <span class="comment">// bad input: vfs_mkdir(NULL);</span>
<a name="l00898"></a>00898   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(*path);                    <span class="comment">// bad input: vfs_mkdir("");</span>
<a name="l00899"></a>00899 
<a name="l00900"></a>00900   <a class="code" href="lib_2string_8h.html#ce4b911463887af5e748326323e99a23">memset</a>(&amp;name, 0, <span class="keyword">sizeof</span>(name));
<a name="l00901"></a>00901   <span class="comment">// find the dir name</span>
<a name="l00902"></a>00902   len = <a class="code" href="lib_2string_8h.html#ce2e8f8b5db1119196eee36974d8b536">strlen</a>(path);
<a name="l00903"></a>00903 
<a name="l00904"></a>00904   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(path[0] == <span class="charliteral">'/'</span>);           <span class="comment">// bad input: vfs isn't doing its job</span>
<a name="l00905"></a>00905   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(len &gt; 1);                  <span class="comment">// bad input: mkdir /</span>
<a name="l00906"></a>00906 
<a name="l00907"></a>00907   <span class="comment">// remove trailing "/" if present</span>
<a name="l00908"></a>00908   <span class="keywordflow">if</span> (path[len-1] == <span class="charliteral">'/'</span>) --len;
<a name="l00909"></a>00909 
<a name="l00910"></a>00910   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(len &gt; 1);                  <span class="comment">// bad input: mkdir //</span>
<a name="l00911"></a>00911 
<a name="l00912"></a>00912   nameStart = len-1;
<a name="l00913"></a>00913 
<a name="l00914"></a>00914   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(path[nameStart] != <span class="charliteral">'/'</span>);   <span class="comment">// bad input: mkdir /a//</span>
<a name="l00915"></a>00915 
<a name="l00916"></a>00916   <span class="comment">/*</span>
<a name="l00917"></a>00917 <span class="comment">   * we're guaranteed by the assert() above that there is </span>
<a name="l00918"></a>00918 <span class="comment">   * at least one "/" before our location. If you remove the assert </span>
<a name="l00919"></a>00919 <span class="comment">   * you might need to make sure nameStart stays above 0 in the following</span>
<a name="l00920"></a>00920 <span class="comment">   * while</span>
<a name="l00921"></a>00921 <span class="comment">   */</span>
<a name="l00922"></a>00922 
<a name="l00923"></a>00923   <span class="keywordflow">while</span> (path[nameStart] != <span class="charliteral">'/'</span>) --nameStart;
<a name="l00924"></a>00924   ++nameStart;
<a name="l00925"></a>00925   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(len - nameStart &gt; 0);
<a name="l00926"></a>00926 
<a name="l00927"></a>00927   <span class="comment">/* e.g.</span>
<a name="l00928"></a>00928 <span class="comment">   *   v--------------------- start</span>
<a name="l00929"></a>00929 <span class="comment">   *      v------------------ end</span>
<a name="l00930"></a>00930 <span class="comment">   *                  v------ nameStart</span>
<a name="l00931"></a>00931 <span class="comment">   *  /usr/local/data/dirname/  &lt;--- ignores trailing /</span>
<a name="l00932"></a>00932 <span class="comment">   *  &lt;---------23----------&gt; len</span>
<a name="l00933"></a>00933 <span class="comment">   */</span>
<a name="l00934"></a>00934 
<a name="l00935"></a>00935   start = end = 1;   <span class="comment">// skip leading /</span>
<a name="l00936"></a>00936   <span class="keywordflow">while</span> (end &lt; nameStart) {
<a name="l00937"></a>00937     <span class="keywordflow">do</span> { ++end; } <span class="keywordflow">while</span>(path[end] != <span class="charliteral">'/'</span>);
<a name="l00938"></a>00938 
<a name="l00939"></a>00939     <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(end-start+1 &lt; <span class="keyword">sizeof</span>(name));
<a name="l00940"></a>00940     <span class="comment">// this is probably wrong:</span>
<a name="l00941"></a>00941     <a class="code" href="lib_2string_8h.html#2a6bedbfab350cd17b80849f5f9234e9">strncpy</a>(name, &amp;path[start], end-start+1);
<a name="l00942"></a>00942     cout &lt;&lt; name &lt;&lt; endl;
<a name="l00943"></a>00943     dir = dir-&gt;data.btPtr-&gt;Find(name);
<a name="l00944"></a>00944     <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(dir);
<a name="l00945"></a>00945     <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(dir-&gt;flags &amp; <a class="code" href="ubixfsv2_2ubixfs_8h.html#03a6b271b2413595574aab2babfa1460">INODE_DIRECTORY</a> == <a class="code" href="ubixfsv2_2ubixfs_8h.html#03a6b271b2413595574aab2babfa1460">INODE_DIRECTORY</a>);
<a name="l00946"></a>00946     start = ++end;
<a name="l00947"></a>00947   }
<a name="l00948"></a>00948 
<a name="l00949"></a>00949   <a class="code" href="lib_2string_8h.html#2a6bedbfab350cd17b80849f5f9234e9">strncpy</a>(name, &amp;path[nameStart], len - nameStart);
<a name="l00950"></a>00950   inode = (<a class="code" href="structubixfsInode.html">ubixfsInode</a> *)<a class="code" href="classUbixFS.html#94e296e37c8176b5f5ba88a2251b70ab">mknod</a>(name, dir, mode | <a class="code" href="ubixfsv2_2ubixfs_8h.html#03a6b271b2413595574aab2babfa1460">INODE_DIRECTORY</a>);
<a name="l00951"></a>00951 
<a name="l00952"></a>00952   <span class="comment">/* </span>
<a name="l00953"></a>00953 <span class="comment">   * keep in mind that the reason for passing in the name is because</span>
<a name="l00954"></a>00954 <span class="comment">   * we thought about allowing key names to be different from inode </span>
<a name="l00955"></a>00955 <span class="comment">   * names. In retrospect, I don't think that's a good idea since a dir</span>
<a name="l00956"></a>00956 <span class="comment">   * listing will print the actual dir name instead of . and ..</span>
<a name="l00957"></a>00957 <span class="comment">   * Thus: the first parameter of btPtr-&gt;Insert() may go away.</span>
<a name="l00958"></a>00958 <span class="comment">   */</span>
<a name="l00959"></a>00959 
<a name="l00960"></a>00960   <a class="code" href="assert_8h.html#d6d5aaa966ca7424f7cb9bd01f2c838b">assert</a>(dir-&gt;data.btPtr-&gt;Insert(inode-&gt;name, inode));
<a name="l00961"></a>00961 
<a name="l00962"></a>00962   <span class="keywordflow">return</span> 0;
<a name="l00963"></a>00963 } <span class="comment">// UbixFS::vfs_mkdir</span>
<a name="l00964"></a>00964 
<a name="l00965"></a>00965 <span class="keywordtype">void</span> 
<a name="l00966"></a><a class="code" href="classUbixFS.html#79445019036de9f0811426196299c46a">00966</a> <a class="code" href="classUbixFS.html#79445019036de9f0811426196299c46a">UbixFS::printFreeBlockList</a>(<a class="code" href="include_2ubixos_2types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> AG) {
<a name="l00967"></a>00967   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> j;
<a name="l00968"></a>00968   <span class="keywordflow">if</span> (<a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a> || <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a> == <a class="code" href="def_8h.html#070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>) <span class="keywordflow">return</span>;
<a name="l00969"></a>00969   printf(<span class="stringliteral">"AG = %d\n"</span>, AG);
<a name="l00970"></a>00970   <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;blocksPerAG / 8; i++) {
<a name="l00971"></a>00971     j = 128;
<a name="l00972"></a>00972     <span class="keywordtype">signed</span> <span class="keywordtype">char</span> foo = <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a>[(AG &lt;&lt; <a class="code" href="classUbixFS.html#e33fa6e8c047dfe567c22936460186f0">superBlock</a>-&gt;AGShift)+i];
<a name="l00973"></a>00973     <span class="keywordflow">while</span> (j &gt; 0) {
<a name="l00974"></a>00974       <span class="keywordflow">if</span> ((foo &amp; j) == j) 
<a name="l00975"></a>00975         printf(<span class="stringliteral">"1"</span>);
<a name="l00976"></a>00976       <span class="keywordflow">else</span>
<a name="l00977"></a>00977         printf(<span class="stringliteral">"0"</span>);    
<a name="l00978"></a>00978       j &gt;&gt;= 1;
<a name="l00979"></a>00979  
<a name="l00980"></a>00980     }
<a name="l00981"></a>00981   } <span class="comment">// for i</span>
<a name="l00982"></a>00982   printf(<span class="stringliteral">"\n"</span>);
<a name="l00983"></a>00983   <span class="keywordflow">return</span>;
<a name="l00984"></a>00984 } <span class="comment">// UbixFS::printFreeBlockList</span>
<a name="l00985"></a>00985 
<a name="l00986"></a><a class="code" href="classUbixFS.html#c607e8f35afa1aca552a1dc24e777998">00986</a> <a class="code" href="classUbixFS.html#c607e8f35afa1aca552a1dc24e777998">UbixFS::~UbixFS</a>(<span class="keywordtype">void</span>) {
<a name="l00987"></a>00987   <span class="keyword">delete</span> [] <a class="code" href="classUbixFS.html#910425153882d145e2af0ae30bdec9a6">freeBlockList</a>;
<a name="l00988"></a>00988   <span class="keywordflow">return</span>;
<a name="l00989"></a>00989 }
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Dec 5 23:34:59 2006 for UbixOS V2 by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
</body>
</html>