templeos-info/public/Wb/Kernel/BlkDev/DskClus.HC.HTML

177 lines
16 KiB
HTML
Executable File

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="generator" content="TempleOS V5.03">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/style/templeos.css">
<script src="/script/templeos.js"></script>
<style type="text/css">
.cF0{color:#000000;background-color:#ffffff;}
.cF1{color:#0000aa;background-color:#ffffff;}
.cF2{color:#00aa00;background-color:#ffffff;}
.cF3{color:#00aaaa;background-color:#ffffff;}
.cF4{color:#aa0000;background-color:#ffffff;}
.cF5{color:#aa00aa;background-color:#ffffff;}
.cF6{color:#aa5500;background-color:#ffffff;}
.cF7{color:#aaaaaa;background-color:#ffffff;}
.cF8{color:#555555;background-color:#ffffff;}
.cF9{color:#5555ff;background-color:#ffffff;}
.cFA{color:#55ff55;background-color:#ffffff;}
.cFB{color:#55ffff;background-color:#ffffff;}
.cFC{color:#ff5555;background-color:#ffffff;}
.cFD{color:#ff55ff;background-color:#ffffff;}
.cFE{color:#ffff55;background-color:#ffffff;}
.cFF{color:#ffffff;background-color:#ffffff;}
</style>
</head>
<body>
<pre id="content">
<a name="l1"></a><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ClusNumNext</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF9>I64</span><span class=cF0> c,</span><span class=cF9>I64</span><span class=cF0> cnt=1)
<a name="l2"></a>{</span><span class=cF2>//Return next cnt'th clus in chain.</span><span class=cF0>
<a name="l3"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock;
<a name="l4"></a> </span><span class=cF5>DrvChk</span><span class=cF0>(dv);
<a name="l5"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&lt;=0) </span><span class=cF1>return</span><span class=cF0> c;
<a name="l6"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l7"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
<a name="l8"></a> </span><span class=cF1>switch</span><span class=cF0> (dv-&gt;fs_type) {
<a name="l9"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l10"></a> c+=cnt;
<a name="l11"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l12"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l13"></a> </span><span class=cF1>while</span><span class=cF0> (cnt--&gt;0 &amp;&amp; 0&lt;c&lt;0x0FFFFFF8) </span><span class=cF7>{</span><span class=cF0>
<a name="l14"></a> </span><span class=cFD>DrvFATBlkSet</span><span class=cF0>(dv,c);
<a name="l15"></a> c=dv-&gt;cur_fat_blk[c &amp; (</span><span class=cF3>BLK_SIZE</span><span class=cF0>/4-1)];
<a name="l16"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l17"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>0&lt;c&lt;0x0FFFFFF8</span><span class=cF7>)</span><span class=cF0>)
<a name="l18"></a> c=</span><span class=cF3>INVALID_CLUS</span><span class=cF0>;
<a name="l19"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l20"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l21"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
<a name="l22"></a> }
<a name="l23"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l24"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
<a name="l25"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l26"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l27"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
<a name="l28"></a> </span><span class=cF1>return</span><span class=cF0> c;
<a name="l29"></a>}
<a name="l30"></a>
<a name="l31"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>Clus2Blk</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF9>I64</span><span class=cF0> c)
<a name="l32"></a>{</span><span class=cF2>//Drv clus num to blk num.</span><span class=cF0>
<a name="l33"></a> </span><span class=cF5>DrvChk</span><span class=cF0>(dv);
<a name="l34"></a> </span><span class=cF1>switch</span><span class=cF0> (dv-&gt;fs_type) </span><span class=cF7>{</span><span class=cF0>
<a name="l35"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l36"></a> </span><span class=cF1>return</span><span class=cF0> c;
<a name="l37"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l38"></a> </span><span class=cF1>return</span><span class=cF0> dv-&gt;data_area+c*dv-&gt;spc;
<a name="l39"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l40"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
<a name="l41"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l42"></a>}
<a name="l43"></a>
<a name="l44"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ClusBlkRead</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF1>U8</span><span class=cF0> *buf,</span><span class=cF9>I64</span><span class=cF0> c,</span><span class=cF9>I64</span><span class=cF0> blks)
<a name="l45"></a>{</span><span class=cF2>//Accepts blk count, so padding on last clus is not read.</span><span class=cF0>
<a name="l46"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l47"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock;
<a name="l48"></a> </span><span class=cF5>DrvChk</span><span class=cF0>(dv);
<a name="l49"></a> </span><span class=cF1>if</span><span class=cF0> (blks&lt;=0) </span><span class=cF1>return</span><span class=cF0> c;
<a name="l50"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l51"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
<a name="l52"></a> </span><span class=cF1>switch</span><span class=cF0> (dv-&gt;fs_type) {
<a name="l53"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l54"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,buf,c,blks);
<a name="l55"></a> c+=blks;
<a name="l56"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l57"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l58"></a> </span><span class=cF1>while</span><span class=cF0> (blks &amp;&amp; 0&lt;c&lt;0x0FFFFFF8) </span><span class=cF7>{</span><span class=cF0>
<a name="l59"></a> i=blks;
<a name="l60"></a> </span><span class=cF1>if</span><span class=cF0> (i&gt;dv-&gt;spc)
<a name="l61"></a> i=dv-&gt;spc;
<a name="l62"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,buf,dv-&gt;data_area+c*dv-&gt;spc,i);
<a name="l63"></a> buf+=i&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l64"></a> c=</span><span class=cF5>ClusNumNext</span><span class=cF0>(dv,c,1);
<a name="l65"></a> blks-=i;
<a name="l66"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l67"></a> </span><span class=cF1>if</span><span class=cF0> (blks)
<a name="l68"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
<a name="l69"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l70"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l71"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
<a name="l72"></a> }
<a name="l73"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l74"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
<a name="l75"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l76"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l77"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
<a name="l78"></a> </span><span class=cF1>return</span><span class=cF0> c;
<a name="l79"></a>}
<a name="l80"></a>
<a name="l81"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ClusRead</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF1>U8</span><span class=cF0> *buf,</span><span class=cF9>I64</span><span class=cF0> c,</span><span class=cF9>I64</span><span class=cF0> cnt)
<a name="l82"></a>{</span><span class=cF2>//Read clus cnt from drv to buf.</span><span class=cF0>
<a name="l83"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>ClusBlkRead</span><span class=cF0>(dv,buf,c,cnt*dv-&gt;spc);
<a name="l84"></a>}
<a name="l85"></a>
<a name="l86"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ClusBlkWrite</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF1>U8</span><span class=cF0> *buf,</span><span class=cF9>I64</span><span class=cF0> c,</span><span class=cF9>I64</span><span class=cF0> blks)
<a name="l87"></a>{</span><span class=cF2>//Accepts blk count, so padding on last clus is not written.</span><span class=cF0>
<a name="l88"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l89"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock;
<a name="l90"></a> </span><span class=cF5>DrvChk</span><span class=cF0>(dv);
<a name="l91"></a> </span><span class=cF1>if</span><span class=cF0> (blks&lt;=0) </span><span class=cF1>return</span><span class=cF0> c;
<a name="l92"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l93"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
<a name="l94"></a> </span><span class=cF1>switch</span><span class=cF0> (dv-&gt;fs_type) {
<a name="l95"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l96"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,buf,c,blks);
<a name="l97"></a> c=0;
<a name="l98"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l99"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l100"></a> </span><span class=cF1>while</span><span class=cF0> (blks) </span><span class=cF7>{</span><span class=cF0>
<a name="l101"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>0&lt;c&lt;0x0FFFFFF8</span><span class=cF7>)</span><span class=cF0>)
<a name="l102"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
<a name="l103"></a> i=blks;
<a name="l104"></a> </span><span class=cF1>if</span><span class=cF0> (i&gt;dv-&gt;spc)
<a name="l105"></a> i=dv-&gt;spc;
<a name="l106"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,buf,dv-&gt;data_area+c*dv-&gt;spc,i);
<a name="l107"></a> buf+=i&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l108"></a> c=</span><span class=cF5>ClusNumNext</span><span class=cF0>(dv,c);
<a name="l109"></a> blks-=i;
<a name="l110"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l111"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l112"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l113"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
<a name="l114"></a> }
<a name="l115"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l116"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
<a name="l117"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l118"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l119"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
<a name="l120"></a> </span><span class=cF1>return</span><span class=cF0> c;
<a name="l121"></a>}
<a name="l122"></a>
<a name="l123"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ClusWrite</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF1>U8</span><span class=cF0> *buf,</span><span class=cF9>I64</span><span class=cF0> c,</span><span class=cF9>I64</span><span class=cF0> cnt)
<a name="l124"></a>{</span><span class=cF2>//Write clus cnt from buf to drv.</span><span class=cF0>
<a name="l125"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>ClusBlkWrite</span><span class=cF0>(dv,buf,c,cnt*dv-&gt;spc);
<a name="l126"></a>}
<a name="l127"></a>
<a name="l128"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ClusAlloc</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF9>I64</span><span class=cF0> c=0,</span><span class=cF9>I64</span><span class=cF0> cnt=1,</span><span class=cF1>Bool</span><span class=cF0> contiguous=</span><span class=cF3>FALSE</span><span class=cF0>)
<a name="l129"></a>{</span><span class=cF2>//Alloc clus cnt into chain.</span><span class=cF0>
<a name="l130"></a></span><span class=cF2>//c=0 means first clus in chain</span><span class=cF0>
<a name="l131"></a> </span><span class=cF5>DrvChk</span><span class=cF0>(dv);
<a name="l132"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&lt;=0) </span><span class=cF1>return</span><span class=cF0> c;
<a name="l133"></a> </span><span class=cF1>switch</span><span class=cF0> (dv-&gt;fs_type) </span><span class=cF7>{</span><span class=cF0>
<a name="l134"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l135"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>RedSeaAllocClus</span><span class=cF0>(dv,cnt);
<a name="l136"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l137"></a> </span><span class=cF1>if</span><span class=cF0> (contiguous) {
<a name="l138"></a> </span><span class=cF1>if</span><span class=cF0> (c) </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'File'</span><span class=cF0>);
<a name="l139"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>FAT32AllocContiguousClus</span><span class=cF0>(dv,cnt);
<a name="l140"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l141"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>FAT32AllocClus</span><span class=cF0>(dv,c,cnt);
<a name="l142"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l143"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
<a name="l144"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l145"></a>}
</span></pre></body>
</html>