ZealOS/docs/Kernel/BlkDev/DiskClus.ZC.html

207 lines
18 KiB
HTML
Raw Normal View History

2021-07-03 05:07:57 +01:00
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
2021-12-11 11:10:58 +00:00
<meta name="generator" content="ZealOS V1.07">
2021-07-03 05:07:57 +01:00
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
2021-07-03 05:07:57 +01:00
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
2021-07-03 05:07:57 +01:00
<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>CDrive</span><span class=cF0> *drive, </span><span class=cF9>I64</span><span class=cF0> c, </span><span class=cF9>I64</span><span class=cF0> count=</span><span class=cFE>1</span><span class=cF0>)
<a name="l2"></a>{</span><span class=cF2>//Return next count'th cluster in chain.</span><span class=cF0>
<a name="l3"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock;
2021-07-03 05:07:57 +01:00
<a name="l4"></a>
<a name="l5"></a> </span><span class=cF5>DriveCheck</span><span class=cF0>(drive);
<a name="l6"></a> </span><span class=cF1>if</span><span class=cF0> (count &lt;= </span><span class=cFE>0</span><span class=cF0>) </span><span class=cF1>return</span><span class=cF0> c;
<a name="l7"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l8"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l9"></a> unlock = </span><span class=cF5>DriveLock</span><span class=cF0>(drive);
<a name="l10"></a> </span><span class=cF1>switch</span><span class=cF0> (drive-&gt;fs_type)
<a name="l11"></a> {
<a name="l12"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l13"></a> c += count;
<a name="l14"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l15"></a>
<a name="l16"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l17"></a> </span><span class=cF1>while</span><span class=cF0> (count-- &gt; </span><span class=cFE>0</span><span class=cF0> &amp;&amp; </span><span class=cFE>0</span><span class=cF0> &lt; c &lt; </span><span class=cFE>0x0FFFFFF8</span><span class=cF0>)
<a name="l18"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l19"></a> </span><span class=cFD>DriveFATBlkSet</span><span class=cF0>(drive, c);
<a name="l20"></a> c = drive-&gt;cur_fat_blk[c &amp; (</span><span class=cF3>BLK_SIZE</span><span class=cF0> / </span><span class=cFE>4</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>)];
<a name="l21"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l22"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cFE>0</span><span class=cF0> &lt; c &lt; </span><span class=cFE>0x0FFFFFF8</span><span class=cF7>)</span><span class=cF0>)
<a name="l23"></a> c = </span><span class=cF3>INVALID_CLUS</span><span class=cF0>;
<a name="l24"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l25"></a>
<a name="l26"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l27"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drive'</span><span class=cF0>);
<a name="l28"></a> }
<a name="l29"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l30"></a> </span><span class=cF5>DriveUnlock</span><span class=cF0>(drive);
<a name="l31"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l32"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l33"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l34"></a> </span><span class=cF5>DriveUnlock</span><span class=cF0>(drive);
2021-07-03 05:07:57 +01:00
<a name="l35"></a>
<a name="l36"></a> </span><span class=cF1>return</span><span class=cF0> c;
2021-07-03 05:07:57 +01:00
<a name="l37"></a>}
<a name="l38"></a>
<a name="l39"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>Clus2Blk</span><span class=cF0>(</span><span class=cF9>CDrive</span><span class=cF0> *drive, </span><span class=cF9>I64</span><span class=cF0> c)
<a name="l40"></a>{</span><span class=cF2>//Drive cluster num to block num.</span><span class=cF0>
<a name="l41"></a> </span><span class=cF5>DriveCheck</span><span class=cF0>(drive);
<a name="l42"></a> </span><span class=cF1>switch</span><span class=cF0> (drive-&gt;fs_type)
<a name="l43"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l44"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l45"></a> </span><span class=cF1>return</span><span class=cF0> c;
2021-07-03 05:07:57 +01:00
<a name="l46"></a>
<a name="l47"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l48"></a> </span><span class=cF1>return</span><span class=cF0> drive-&gt;data_area + c * drive-&gt;spc;
2021-07-03 05:07:57 +01:00
<a name="l49"></a>
<a name="l50"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l51"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drive'</span><span class=cF0>);
<a name="l52"></a> </span><span class=cF7>}</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l53"></a>}
<a name="l54"></a>
<a name="l55"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ClusBlkRead</span><span class=cF0>(</span><span class=cF9>CDrive</span><span class=cF0> *drive, </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="l56"></a>{</span><span class=cF2>//Accepts block count, so padding on last cluster is not read.</span><span class=cF0>
<a name="l57"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l58"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock;
2021-07-03 05:07:57 +01:00
<a name="l59"></a>
<a name="l60"></a> </span><span class=cF5>DriveCheck</span><span class=cF0>(drive);
<a name="l61"></a> </span><span class=cF1>if</span><span class=cF0> (blks &lt;= </span><span class=cFE>0</span><span class=cF0>) </span><span class=cF1>return</span><span class=cF0> c;
<a name="l62"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l63"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l64"></a> unlock = </span><span class=cF5>DriveLock</span><span class=cF0>(drive);
<a name="l65"></a> </span><span class=cF1>switch</span><span class=cF0> (drive-&gt;fs_type)
<a name="l66"></a> {
<a name="l67"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l68"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(drive, buf, c, blks);
<a name="l69"></a> c += blks;
<a name="l70"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l71"></a>
<a name="l72"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l73"></a> </span><span class=cF1>while</span><span class=cF0> (blks &amp;&amp; </span><span class=cFE>0</span><span class=cF0> &lt; c &lt; </span><span class=cFE>0x0FFFFFF8</span><span class=cF0>)
<a name="l74"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l75"></a> i = blks;
<a name="l76"></a> </span><span class=cF1>if</span><span class=cF0> (i &gt; drive-&gt;spc)
<a name="l77"></a> i = drive-&gt;spc;
<a name="l78"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(drive, buf, drive-&gt;data_area + c * drive-&gt;spc, i);
2021-11-05 09:06:09 +00:00
<a name="l79"></a> buf += i &lt;&lt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l80"></a> c = </span><span class=cF5>ClusNumNext</span><span class=cF0>(drive, c, </span><span class=cFE>1</span><span class=cF0>);
<a name="l81"></a> blks -= i;
<a name="l82"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l83"></a> </span><span class=cF1>if</span><span class=cF0> (blks)
<a name="l84"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drive'</span><span class=cF0>);
<a name="l85"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l86"></a>
<a name="l87"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l88"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drive'</span><span class=cF0>);
<a name="l89"></a> }
<a name="l90"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l91"></a> </span><span class=cF5>DriveUnlock</span><span class=cF0>(drive);
<a name="l92"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l93"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l94"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l95"></a> </span><span class=cF5>DriveUnlock</span><span class=cF0>(drive);
2021-07-03 05:07:57 +01:00
<a name="l96"></a>
<a name="l97"></a> </span><span class=cF1>return</span><span class=cF0> c;
2021-07-03 05:07:57 +01:00
<a name="l98"></a>}
<a name="l99"></a>
<a name="l100"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ClusRead</span><span class=cF0>(</span><span class=cF9>CDrive</span><span class=cF0> *drive, </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> count)
<a name="l101"></a>{</span><span class=cF2>//Read cluster count from drive to buf.</span><span class=cF0>
<a name="l102"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>ClusBlkRead</span><span class=cF0>(drive, buf, c, count*drive-&gt;spc);
2021-07-03 05:07:57 +01:00
<a name="l103"></a>}
<a name="l104"></a>
<a name="l105"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ClusBlkWrite</span><span class=cF0>(</span><span class=cF9>CDrive</span><span class=cF0> *drive, </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="l106"></a>{</span><span class=cF2>//Accepts block count, so padding on last cluster is not written.</span><span class=cF0>
<a name="l107"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l108"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock;
2021-07-03 05:07:57 +01:00
<a name="l109"></a>
<a name="l110"></a> </span><span class=cF5>DriveCheck</span><span class=cF0>(drive);
<a name="l111"></a> </span><span class=cF1>if</span><span class=cF0> (blks &lt;= </span><span class=cFE>0</span><span class=cF0>) </span><span class=cF1>return</span><span class=cF0> c;
<a name="l112"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l113"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l114"></a> unlock = </span><span class=cF5>DriveLock</span><span class=cF0>(drive);
<a name="l115"></a> </span><span class=cF1>switch</span><span class=cF0> (drive-&gt;fs_type)
<a name="l116"></a> {
<a name="l117"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l118"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(drive, buf, c, blks);
<a name="l119"></a> c = </span><span class=cFE>0</span><span class=cF0>;
<a name="l120"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l121"></a>
<a name="l122"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l123"></a> </span><span class=cF1>while</span><span class=cF0> (blks)
<a name="l124"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l125"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cFE>0</span><span class=cF0> &lt; c &lt; </span><span class=cFE>0x0FFFFFF8</span><span class=cF7>)</span><span class=cF0>)
<a name="l126"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drive'</span><span class=cF0>);
<a name="l127"></a> i = blks;
<a name="l128"></a> </span><span class=cF1>if</span><span class=cF0> (i &gt; drive-&gt;spc)
<a name="l129"></a> i = drive-&gt;spc;
<a name="l130"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(drive, buf, drive-&gt;data_area + c * drive-&gt;spc, i);
<a name="l131"></a> buf += i &lt;&lt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l132"></a> c = </span><span class=cF5>ClusNumNext</span><span class=cF0>(drive, c);
<a name="l133"></a> blks -= i;
<a name="l134"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l135"></a> </span><span class=cF1>break</span><span class=cF0>;
2021-07-03 05:07:57 +01:00
<a name="l136"></a>
<a name="l137"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l138"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drive'</span><span class=cF0>);
<a name="l139"></a> }
<a name="l140"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l141"></a> </span><span class=cF5>DriveUnlock</span><span class=cF0>(drive);
<a name="l142"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l143"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l144"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l145"></a> </span><span class=cF5>DriveUnlock</span><span class=cF0>(drive);
2021-07-03 05:07:57 +01:00
<a name="l146"></a>
<a name="l147"></a> </span><span class=cF1>return</span><span class=cF0> c;
2021-07-03 05:07:57 +01:00
<a name="l148"></a>}
<a name="l149"></a>
<a name="l150"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ClusWrite</span><span class=cF0>(</span><span class=cF9>CDrive</span><span class=cF0> *drive, </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> count)
<a name="l151"></a>{</span><span class=cF2>//Write cluster count from buf to drive.</span><span class=cF0>
<a name="l152"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>ClusBlkWrite</span><span class=cF0>(drive, buf, c, count * drive-&gt;spc);
2021-07-03 05:07:57 +01:00
<a name="l153"></a>}
<a name="l154"></a>
<a name="l155"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>ClusAlloc</span><span class=cF0>(</span><span class=cF9>CDrive</span><span class=cF0> *drive, </span><span class=cF9>I64</span><span class=cF0> c=</span><span class=cFE>0</span><span class=cF0>, </span><span class=cF9>I64</span><span class=cF0> count=</span><span class=cFE>1</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> contiguous=</span><span class=cF3>FALSE</span><span class=cF0>)
<a name="l156"></a>{</span><span class=cF2>//Alloc cluster count into chain.</span><span class=cF0>
<a name="l157"></a></span><span class=cF2>//c=0 means first cluster in chain</span><span class=cF0>
<a name="l158"></a> </span><span class=cF5>DriveCheck</span><span class=cF0>(drive);
<a name="l159"></a> </span><span class=cF1>if</span><span class=cF0> (count &lt;= </span><span class=cFE>0</span><span class=cF0>) </span><span class=cF1>return</span><span class=cF0> c;
<a name="l160"></a> </span><span class=cF1>switch</span><span class=cF0> (drive-&gt;fs_type)
<a name="l161"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l162"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l163"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>RedSeaAllocClus</span><span class=cF0>(drive, count);
2021-07-03 05:07:57 +01:00
<a name="l164"></a>
<a name="l165"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l166"></a> </span><span class=cF1>if</span><span class=cF0> (contiguous)
<a name="l167"></a> {
<a name="l168"></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="l169"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>FAT32AllocContiguousClus</span><span class=cF0>(drive, count);
<a name="l170"></a> }
<a name="l171"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l172"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>FAT32AllocClus</span><span class=cF0>(drive, c, count);
2021-07-03 05:07:57 +01:00
<a name="l173"></a>
<a name="l174"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l175"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drive'</span><span class=cF0>);
<a name="l176"></a> </span><span class=cF7>}</span><span class=cF0>
2021-07-03 05:07:57 +01:00
<a name="l177"></a>}
</span></pre></body>
</html>