ZealOS/docs/System/BlkDev/DiskCheck.html
2021-07-03 02:47:45 -04:00

534 lines
61 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.05">
<style type="text/css">
body {background-color:#000000;}
.cF0{color:#ffffff;background-color:#000000;}
.cF1{color:#3465a4;background-color:#000000;}
.cF2{color:#4e9a06;background-color:#000000;}
.cF3{color:#06989a;background-color:#000000;}
.cF4{color:#a24444;background-color:#000000;}
.cF5{color:#75507b;background-color:#000000;}
.cF6{color:#ce982f;background-color:#000000;}
.cF7{color:#bcc0b9;background-color:#000000;}
.cF8{color:#555753;background-color:#000000;}
.cF9{color:#729fcf;background-color:#000000;}
.cFA{color:#82bc49;background-color:#000000;}
.cFB{color:#34e2e2;background-color:#000000;}
.cFC{color:#ac3535;background-color:#000000;}
.cFD{color:#ad7fa8;background-color:#000000;}
.cFE{color:#fce94f;background-color:#000000;}
.cFF{color:#000000;background-color:#000000;}
</style>
</head>
<body>
<pre style="font-family:courier;font-size:10pt">
<a name="l1"></a><span class=cF0>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>&quot;Info;File/Cmd Line (Typically);Cmd Line (Typically)&quot;</span><span class=cF0>
<a name="l2"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>CheckDiskConfirm</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> *_fix, </span><span class=cF1>Bool</span><span class=cF0> *_confirm)
<a name="l3"></a>{
<a name="l4"></a> </span><span class=cF1>if</span><span class=cF0> (*_fix &amp;&amp; *_confirm)
<a name="l5"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l6"></a> </span><span class=cF6>&quot;Fix &quot;</span><span class=cF0>;
<a name="l7"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>YorN</span><span class=cF0>)
<a name="l8"></a> *_fix = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l9"></a> *_confirm = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l10"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l11"></a> </span><span class=cF1>return</span><span class=cF0> *_fix;
<a name="l12"></a>}
<a name="l13"></a>
<a name="l14"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>RedSeaCheckDiskList</span><span class=cF0>(</span><span class=cF9>CDrive</span><span class=cF0> *drive, </span><span class=cF9>CDirEntry</span><span class=cF0> *tmpde1, </span><span class=cF1>U8</span><span class=cF0> *bits, </span><span class=cF1>U8</span><span class=cF0> *bits2, </span><span class=cF9>I64</span><span class=cF0> size, </span><span class=cF9>I64</span><span class=cF0> bpc)
<a name="l15"></a>{
<a name="l16"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *tmpde2;
<a name="l17"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, errs = </span><span class=cFE>0</span><span class=cF0>;
<a name="l18"></a>
<a name="l19"></a> </span><span class=cF1>while</span><span class=cF0> (tmpde1)
<a name="l20"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l21"></a> tmpde2 = tmpde1-&gt;next;
<a name="l22"></a> </span><span class=cF1>if</span><span class=cF0> (tmpde1-&gt;attr &amp; </span><span class=cF3>RS_ATTR_DIR</span><span class=cF0> &amp;&amp; tmpde1-&gt;sub)
<a name="l23"></a> errs += </span><span class=cF5>RedSeaCheckDiskList</span><span class=cF0>(drive, tmpde1-&gt;sub, bits, bits2, size, bpc);
<a name="l24"></a> j = (tmpde1-&gt;size + bpc - </span><span class=cFE>1</span><span class=cF0>) / bpc;
<a name="l25"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; j; i++)
<a name="l26"></a> {
<a name="l27"></a> </span><span class=cF1>if</span><span class=cF0> (i + tmpde1-&gt;clus-drive-&gt;data_area &gt; size)
<a name="l28"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l29"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Invalid Clus:%s Clus:%X\n&quot;</span><span class=cF0>, tmpde1-&gt;full_name, i + tmpde1-&gt;clus);
<a name="l30"></a> errs++;
<a name="l31"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l32"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l33"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>bits, i + tmpde1-&gt;clus-drive-&gt;data_area</span><span class=cF7>)</span><span class=cF0>)
<a name="l34"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l35"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Dbl Alloc:%s Clus:%X\n&quot;</span><span class=cF0>, tmpde1-&gt;full_name, i + tmpde1-&gt;clus);
<a name="l36"></a> errs++;
<a name="l37"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l38"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>LBtr</span><span class=cF7>(</span><span class=cF0>bits2, i + tmpde1-&gt;clus-drive-&gt;data_area</span><span class=cF7>)</span><span class=cF0>)
<a name="l39"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l40"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;UnAlloc:%s Clus:%X\n&quot;</span><span class=cF0>, tmpde1-&gt;full_name, i + tmpde1-&gt;clus);
<a name="l41"></a> errs++;
<a name="l42"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l43"></a> }
<a name="l44"></a> </span><span class=cF5>DirEntryDel</span><span class=cF0>(tmpde1);
<a name="l45"></a> tmpde1 = tmpde2;
<a name="l46"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l47"></a>
<a name="l48"></a> </span><span class=cF1>return</span><span class=cF0> errs;
<a name="l49"></a>}
<a name="l50"></a>
<a name="l51"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>RedSeaCheckDisk</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let, </span><span class=cF1>Bool</span><span class=cF0> *_fix, </span><span class=cF1>Bool</span><span class=cF0> *_confirm)
<a name="l52"></a>{
<a name="l53"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, bpc, size, errs = </span><span class=cFE>0</span><span class=cF0>;
<a name="l54"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive = </span><span class=cF5>Letter2Drive</span><span class=cF0>(drv_let), *old_dv = </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv;
<a name="l55"></a> </span><span class=cF1>U8</span><span class=cF0> *files_find_mask = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>&quot;%c:/*&quot;</span><span class=cF0>, </span><span class=cF5>Drive2Letter</span><span class=cF7>(</span><span class=cF0>drive</span><span class=cF7>)</span><span class=cF0>),
<a name="l56"></a> *old_dir = </span><span class=cF5>StrNew</span><span class=cF0>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir),
<a name="l57"></a> *bits, *bits2;
<a name="l58"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *ptr,*ptr2;
<a name="l59"></a>
<a name="l60"></a> </span><span class=cF5>Drive</span><span class=cF0>(drv_let);
<a name="l61"></a> </span><span class=cF6>&quot;Scanning...\n&quot;</span><span class=cF0>;
<a name="l62"></a> size = (drive-&gt;size - </span><span class=cF7>(</span><span class=cF0>drive-&gt;data_area - drive-&gt;drv_offset</span><span class=cF7>)</span><span class=cF0>) / drive-&gt;spc;
<a name="l63"></a> bpc = drive-&gt;spc &lt;&lt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l64"></a> bits = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>size + </span><span class=cFE>7</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>3</span><span class=cF0>);
<a name="l65"></a> bits2 = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>size + </span><span class=cFE>7</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>3</span><span class=cF0> + </span><span class=cF3>BLK_SIZE</span><span class=cF0>);
<a name="l66"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(drive, bits2, drive-&gt;fat1, </span><span class=cF7>(</span><span class=cF0>(size + </span><span class=cFE>7</span><span class=cF0>) &gt;&gt; </span><span class=cFE>3</span><span class=cF0> + </span><span class=cF3>BLK_SIZE</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l67"></a>
<a name="l68"></a> </span><span class=cF2>//Get Root Dir size</span><span class=cF0>
<a name="l69"></a> ptr2 = </span><span class=cF5>MAlloc</span><span class=cF0>(bpc);
<a name="l70"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(drive, ptr2, drive-&gt;root_clus, </span><span class=cFE>1</span><span class=cF0>);
<a name="l71"></a> ptr = ptr2(</span><span class=cF1>U8</span><span class=cF0> *) - </span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF0>);
<a name="l72"></a> j = (ptr-&gt;size + bpc - </span><span class=cFE>1</span><span class=cF0>) / bpc;
<a name="l73"></a> </span><span class=cF5>Free</span><span class=cF0>(ptr2);
<a name="l74"></a>
<a name="l75"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; j; i++)
<a name="l76"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l77"></a> </span><span class=cF1>if</span><span class=cF0> (i + drive-&gt;root_clus - drive-&gt;data_area &gt; size)
<a name="l78"></a> {
<a name="l79"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Invalid Clus: RootDir Clus:%X\n&quot;</span><span class=cF0>, i + drive-&gt;root_clus);
<a name="l80"></a> errs++;
<a name="l81"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l82"></a> }
<a name="l83"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>bits, i + drive-&gt;root_clus - drive-&gt;data_area</span><span class=cF7>)</span><span class=cF0>)
<a name="l84"></a> {
<a name="l85"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Dbl Alloc: RootDir Clus:%X\n&quot;</span><span class=cF0>, i + drive-&gt;root_clus);
<a name="l86"></a> errs++;
<a name="l87"></a> }
<a name="l88"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>LBtr</span><span class=cF7>(</span><span class=cF0>bits2, i + drive-&gt;root_clus - drive-&gt;data_area</span><span class=cF7>)</span><span class=cF0>)
<a name="l89"></a> {
<a name="l90"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;UnAlloc: RootDir Clus:%X\n&quot;</span><span class=cF0>, i + drive-&gt;root_clus);
<a name="l91"></a> errs++;
<a name="l92"></a> }
<a name="l93"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l94"></a>
<a name="l95"></a> errs += </span><span class=cF5>RedSeaCheckDiskList</span><span class=cF0>(drive, </span><span class=cF5>FilesFind</span><span class=cF7>(</span><span class=cF0>files_find_mask, </span><span class=cF3>FUF_RECURSE</span><span class=cF7>)</span><span class=cF0>, bits, bits2, size, bpc);
<a name="l96"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>1</span><span class=cF0>; i &lt; size; i++)
<a name="l97"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>bits2, i</span><span class=cF7>)</span><span class=cF0>)
<a name="l98"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l99"></a> </span><span class=cF5>PrintWarn</span><span class=cF0>(</span><span class=cF6>&quot;Shouldn't Alloc Clus:%0X\n&quot;</span><span class=cF0>, i + drive-&gt;data_area);
<a name="l100"></a> errs++;
<a name="l101"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>CheckDiskConfirm</span><span class=cF7>(</span><span class=cF0>_fix, _confirm</span><span class=cF7>)</span><span class=cF0>)
<a name="l102"></a> </span><span class=cF5>RedSeaFreeClus</span><span class=cF0>(drive, i + drive-&gt;data_area, </span><span class=cFE>1</span><span class=cF0>);
<a name="l103"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l104"></a>
<a name="l105"></a> </span><span class=cF5>Free</span><span class=cF0>(files_find_mask);
<a name="l106"></a> </span><span class=cF5>Free</span><span class=cF0>(bits);
<a name="l107"></a> </span><span class=cF5>Free</span><span class=cF0>(bits2);
<a name="l108"></a> </span><span class=cF5>Drive</span><span class=cF0>(</span><span class=cF5>Drive2Letter</span><span class=cF7>(</span><span class=cF0>old_dv</span><span class=cF7>)</span><span class=cF0>);
<a name="l109"></a> </span><span class=cF5>Cd</span><span class=cF0>(old_dir);
<a name="l110"></a> </span><span class=cF5>Free</span><span class=cF0>(old_dir);
<a name="l111"></a>
<a name="l112"></a> </span><span class=cF1>return</span><span class=cF0> errs;
<a name="l113"></a>}
<a name="l114"></a>
<a name="l115"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>FAT32CheckDiskList</span><span class=cF0>(</span><span class=cF9>CDrive</span><span class=cF0> *drive, </span><span class=cF9>CDirEntry</span><span class=cF0> *tmpde1, </span><span class=cF1>U8</span><span class=cF0> *bits, </span><span class=cF9>U32</span><span class=cF0> *bits2, </span><span class=cF9>I64</span><span class=cF0> size, </span><span class=cF9>I64</span><span class=cF0> bpc)
<a name="l116"></a>{
<a name="l117"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *tmpde2;
<a name="l118"></a> </span><span class=cF9>I64</span><span class=cF0> i, c, errs = </span><span class=cFE>0</span><span class=cF0>;
<a name="l119"></a>
<a name="l120"></a> </span><span class=cF1>while</span><span class=cF0> (tmpde1)
<a name="l121"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l122"></a> tmpde2 = tmpde1-&gt;next;
<a name="l123"></a> </span><span class=cF1>if</span><span class=cF0> (tmpde1-&gt;attr &amp; </span><span class=cF3>RS_ATTR_DIR</span><span class=cF0> &amp;&amp; tmpde1-&gt;sub)
<a name="l124"></a> errs += </span><span class=cF5>FAT32CheckDiskList</span><span class=cF0>(drive, tmpde1-&gt;sub, bits, bits2, size, bpc);
<a name="l125"></a> i = </span><span class=cFE>0</span><span class=cF0>;
<a name="l126"></a> c = tmpde1-&gt;clus;
<a name="l127"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cFE>0</span><span class=cF0> &lt; c &lt; </span><span class=cFE>0x0FFFFFF8</span><span class=cF0>)
<a name="l128"></a> {
<a name="l129"></a> </span><span class=cF1>if</span><span class=cF0> (c &gt; size)
<a name="l130"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l131"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Invalid Clus:%s Clus:%X\n&quot;</span><span class=cF0>, tmpde1-&gt;full_name, c);
<a name="l132"></a> errs++;
<a name="l133"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l134"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l135"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>bits, c</span><span class=cF7>)</span><span class=cF0>)
<a name="l136"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l137"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Dbl Alloc:%s Clus:%X\n&quot;</span><span class=cF0>, tmpde1-&gt;full_name, c);
<a name="l138"></a> errs++;
<a name="l139"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l140"></a> </span><span class=cF1>if</span><span class=cF0> (!bits2[c])
<a name="l141"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l142"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;UnAlloc:%s Clus:%X\n&quot;</span><span class=cF0>, tmpde1-&gt;full_name, c);
<a name="l143"></a> errs++;
<a name="l144"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l145"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l146"></a> bits2[c] = </span><span class=cFE>0</span><span class=cF0>;
<a name="l147"></a> c = </span><span class=cF5>ClusNumNext</span><span class=cF0>(drive, c);
<a name="l148"></a> i++;
<a name="l149"></a> }
<a name="l150"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>tmpde1-&gt;attr &amp; </span><span class=cF3>RS_ATTR_DIR</span><span class=cF7>)</span><span class=cF0>)
<a name="l151"></a> {
<a name="l152"></a> i *= bpc;
<a name="l153"></a> </span><span class=cF1>if</span><span class=cF0> (tmpde1-&gt;size&gt;i)
<a name="l154"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l155"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Alloced File Too Short:%s\n&quot;</span><span class=cF0>, tmpde1-&gt;full_name);
<a name="l156"></a> errs++;
<a name="l157"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l158"></a> </span><span class=cF1>if</span><span class=cF0> (i &gt; tmpde1-&gt;size + bpc - </span><span class=cFE>1</span><span class=cF0>)
<a name="l159"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l160"></a> </span><span class=cF5>PrintWarn</span><span class=cF0>(</span><span class=cF6>&quot;Alloced File Too Long:%s\n&quot;</span><span class=cF0>, tmpde1-&gt;full_name);
<a name="l161"></a> errs++;
<a name="l162"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l163"></a> }
<a name="l164"></a> </span><span class=cF5>DirEntryDel</span><span class=cF0>(tmpde1);
<a name="l165"></a> tmpde1 = tmpde2;
<a name="l166"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l167"></a> </span><span class=cF1>return</span><span class=cF0> errs;
<a name="l168"></a>}
<a name="l169"></a>
<a name="l170"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>FAT32CheckDisk</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let, </span><span class=cF1>Bool</span><span class=cF0> *_fix, </span><span class=cF1>Bool</span><span class=cF0> *_confirm)
<a name="l171"></a>{
<a name="l172"></a> </span><span class=cF9>I64</span><span class=cF0> i, bpc, size, c, errs = </span><span class=cFE>0</span><span class=cF0>;
<a name="l173"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive = </span><span class=cF5>Letter2Drive</span><span class=cF0>(drv_let), *old_dv = </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv;
<a name="l174"></a> </span><span class=cF1>U8</span><span class=cF0> *files_find_mask = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>&quot;%c:/*&quot;</span><span class=cF0>, </span><span class=cF5>Drive2Letter</span><span class=cF7>(</span><span class=cF0>drive</span><span class=cF7>)</span><span class=cF0>),
<a name="l175"></a> *old_dir = </span><span class=cF5>StrNew</span><span class=cF0>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir),
<a name="l176"></a> *bits;
<a name="l177"></a> </span><span class=cF9>U32</span><span class=cF0> *bits2;
<a name="l178"></a>
<a name="l179"></a> </span><span class=cF5>Drive</span><span class=cF0>(drv_let);
<a name="l180"></a> </span><span class=cF6>&quot;Scanning...\n&quot;</span><span class=cF0>;
<a name="l181"></a> size = (drive-&gt;size - </span><span class=cF7>(</span><span class=cF0>drive-&gt;data_area - drive-&gt;drv_offset</span><span class=cF7>)</span><span class=cF0>) / drive-&gt;spc;
<a name="l182"></a> bpc = drive-&gt;spc &lt;&lt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l183"></a> bits = </span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>size + </span><span class=cFE>7</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>3</span><span class=cF0>);
<a name="l184"></a> bits2 = </span><span class=cF5>CAlloc</span><span class=cF0>(size * </span><span class=cFE>4</span><span class=cF0> + </span><span class=cF3>BLK_SIZE</span><span class=cF0>);
<a name="l185"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(drive, bits2, drive-&gt;fat1, </span><span class=cF7>(</span><span class=cF0>size * </span><span class=cFE>4</span><span class=cF0> + </span><span class=cF3>BLK_SIZE</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l186"></a>
<a name="l187"></a> c = drive-&gt;root_clus;
<a name="l188"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cFE>0</span><span class=cF0> &lt; c &lt; </span><span class=cFE>0x0FFFFFF8</span><span class=cF0>)
<a name="l189"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l190"></a> </span><span class=cF1>if</span><span class=cF0> (c &gt; size)
<a name="l191"></a> {
<a name="l192"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Invalid Clus: RootDir Clus:%X\n&quot;</span><span class=cF0>, c);
<a name="l193"></a> errs++;
<a name="l194"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l195"></a> }
<a name="l196"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>bits, c</span><span class=cF7>)</span><span class=cF0>)
<a name="l197"></a> {
<a name="l198"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Dbl Alloc: RootDir Clus:%X\n&quot;</span><span class=cF0>, c);
<a name="l199"></a> errs++;
<a name="l200"></a> }
<a name="l201"></a> </span><span class=cF1>if</span><span class=cF0> (!bits2[c])
<a name="l202"></a> {
<a name="l203"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;UnAlloc: RootDir Clus:%X\n&quot;</span><span class=cF0>, c);
<a name="l204"></a> errs++;
<a name="l205"></a> }
<a name="l206"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l207"></a> bits2[c] = </span><span class=cFE>0</span><span class=cF0>;
<a name="l208"></a> c = </span><span class=cF5>ClusNumNext</span><span class=cF0>(drive, c);
<a name="l209"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l210"></a>
<a name="l211"></a> errs += </span><span class=cF5>FAT32CheckDiskList</span><span class=cF0>(drive, </span><span class=cF5>FilesFind</span><span class=cF7>(</span><span class=cF0>files_find_mask, </span><span class=cF3>FUF_RECURSE</span><span class=cF7>)</span><span class=cF0>, bits, bits2, size, bpc);
<a name="l212"></a>
<a name="l213"></a> bits2[</span><span class=cFE>1</span><span class=cF0>] = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>//See </span><a href="https://www.tomawezome.github.io/ZealOS/Kernel/BlkDev/FileSysFAT.html#l55"><span class=cF4>FAT32Format</span></a><span class=cF2>()</span><span class=cF0>
<a name="l214"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>1</span><span class=cF0>; i &lt; size; i++)
<a name="l215"></a> </span><span class=cF1>if</span><span class=cF0> (bits2[i])
<a name="l216"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l217"></a> </span><span class=cF5>PrintWarn</span><span class=cF0>(</span><span class=cF6>&quot;Shouldn't Alloc Clus:%0X\n&quot;</span><span class=cF0>, i);
<a name="l218"></a> errs++;
<a name="l219"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>CheckDiskConfirm</span><span class=cF7>(</span><span class=cF0>_fix, _confirm</span><span class=cF7>)</span><span class=cF0>)
<a name="l220"></a> </span><span class=cF5>FAT32FreeClus</span><span class=cF0>(drive, i);
<a name="l221"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l222"></a> </span><span class=cF5>Free</span><span class=cF0>(files_find_mask);
<a name="l223"></a> </span><span class=cF5>Free</span><span class=cF0>(bits);
<a name="l224"></a> </span><span class=cF5>Free</span><span class=cF0>(bits2);
<a name="l225"></a> </span><span class=cF5>Drive</span><span class=cF0>(</span><span class=cF5>Drive2Letter</span><span class=cF7>(</span><span class=cF0>old_dv</span><span class=cF7>)</span><span class=cF0>);
<a name="l226"></a> </span><span class=cF5>Cd</span><span class=cF0>(old_dir);
<a name="l227"></a> </span><span class=cF5>Free</span><span class=cF0>(old_dir);
<a name="l228"></a>
<a name="l229"></a> </span><span class=cF1>return</span><span class=cF0> errs;
<a name="l230"></a>}
<a name="l231"></a>
<a name="l232"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>DiskCheck</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let=</span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> fix=</span><span class=cF3>FALSE</span><span class=cF0>, </span><span class=cF1>Bool</span><span class=cF0> confirm=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l233"></a>{</span><span class=cF2>//Check disk for allocation errors and, optionally, fix.</span><span class=cF0>
<a name="l234"></a></span><span class=cF2>//You probably want to reformat and reinstall.</span><span class=cF0>
<a name="l235"></a> </span><span class=cF9>I64</span><span class=cF0> errs = </span><span class=cFE>0</span><span class=cF0>;
<a name="l236"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive = </span><span class=cF5>Letter2Drive</span><span class=cF0>(drv_let);
<a name="l237"></a>
<a name="l238"></a> </span><span class=cF1>switch</span><span class=cF0> (drive-&gt;fs_type)
<a name="l239"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l240"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l241"></a> errs = </span><span class=cF5>RedSeaCheckDisk</span><span class=cF0>(drv_let, &amp;fix, &amp;confirm);
<a name="l242"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l243"></a>
<a name="l244"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l245"></a> errs = </span><span class=cF5>FAT32CheckDisk</span><span class=cF0>(drv_let, &amp;fix, &amp;confirm);
<a name="l246"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l247"></a>
<a name="l248"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l249"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;File System Not Supported\n&quot;</span><span class=cF0>);
<a name="l250"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l251"></a> </span><span class=cF1>if</span><span class=cF0> (errs)
<a name="l252"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l253"></a> </span><span class=cF1>if</span><span class=cF0> (fix)
<a name="l254"></a> </span><span class=cF6>&quot;It might be a little better. &quot;</span><span class=cF0>;
<a name="l255"></a> </span><span class=cF6>&quot;Copy files to another partition or CD/DVD, &quot;</span><span class=cF0>
<a name="l256"></a> </span><span class=cF6>&quot;reformat, and copy back. &quot;</span><span class=cF0>
<a name="l257"></a> </span><span class=cF6>&quot;Or, copy from a back-up.\n&quot;</span><span class=cF0>;
<a name="l258"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l259"></a>
<a name="l260"></a> </span><span class=cF1>return</span><span class=cF0> errs;
<a name="l261"></a>}
<a name="l262"></a>
<a name="l263"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>RedSeaDriveView</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let=</span><span class=cFE>0</span><span class=cF0>)
<a name="l264"></a>{
<a name="l265"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive = </span><span class=cF5>Letter2Drive</span><span class=cF0>(drv_let);
<a name="l266"></a> </span><span class=cF9>I64</span><span class=cF0> lohi, c1, i, x, y,
<a name="l267"></a> l = (</span><span class=cF3>GR_HEIGHT</span><span class=cF0> - </span><span class=cFE>3</span><span class=cF0> * </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>) * (</span><span class=cF3>GR_WIDTH</span><span class=cF0> - </span><span class=cF3>FONT_WIDTH</span><span class=cF0> &lt;&lt; </span><span class=cFE>1</span><span class=cF0>),
<a name="l268"></a> s = drive-&gt;size + drive-&gt;drv_offset - drive-&gt;data_area;
<a name="l269"></a> </span><span class=cF1>U8</span><span class=cF0> *bitmap;
<a name="l270"></a> </span><span class=cF9>CDC</span><span class=cF0> *dc = </span><span class=cF5>DCAlias</span><span class=cF0>;
<a name="l271"></a>
<a name="l272"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="https://www.tomawezome.github.io/ZealOS/System/TaskSettings.html#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
<a name="l273"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l274"></a> </span><span class=cF5>WinBorder</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
<a name="l275"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l276"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l277"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
<a name="l278"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l279"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l280"></a> i = (</span><span class=cF7>(</span><span class=cF0>s + </span><span class=cFE>7</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>3</span><span class=cF0> + </span><span class=cF3>BLK_SIZE</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>) &gt;&gt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l281"></a> bitmap = </span><span class=cF5>MAlloc</span><span class=cF0>(i &lt;&lt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l282"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(drive, bitmap, drive-&gt;fat1, i);
<a name="l283"></a> i = </span><span class=cFE>0</span><span class=cF0>;
<a name="l284"></a> </span><span class=cF1>for</span><span class=cF0> (y = </span><span class=cFE>0</span><span class=cF0>; y &lt; </span><span class=cF3>GR_HEIGHT</span><span class=cF0> - </span><span class=cFE>3</span><span class=cF0> * </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>; y++)
<a name="l285"></a> {
<a name="l286"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>KeyScan</span><span class=cF0>)
<a name="l287"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l288"></a> </span><span class=cF1>for</span><span class=cF0> (x = </span><span class=cFE>0</span><span class=cF0>; x &lt; </span><span class=cF3>GR_WIDTH</span><span class=cF0> - </span><span class=cF3>FONT_WIDTH</span><span class=cF0> &lt;&lt; </span><span class=cFE>1</span><span class=cF0>; x++)
<a name="l289"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l290"></a> lohi = i * s;
<a name="l291"></a> c1 = lohi / l;
<a name="l292"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>bitmap, c1</span><span class=cF7>)</span><span class=cF0>)
<a name="l293"></a> dc-&gt;color = </span><span class=cF3>ROP_XOR</span><span class=cF0> + </span><span class=cF3>BLUE</span><span class=cF0> ^ </span><span class=cF3>TRANSPARENT</span><span class=cF0>;
<a name="l294"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l295"></a> dc-&gt;color = </span><span class=cF3>ROP_XOR</span><span class=cF0> + </span><span class=cF3>WHITE</span><span class=cF0> ^ </span><span class=cF3>TRANSPARENT</span><span class=cF0>;
<a name="l296"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(dc, x, y);
<a name="l297"></a> i++;
<a name="l298"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l299"></a> }
<a name="l300"></a> </span><span class=cF5>Free</span><span class=cF0>(bitmap);
<a name="l301"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l302"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l303"></a> </span><span class=cF5>DriveUnlock</span><span class=cF0>(drive);
<a name="l304"></a> </span><span class=cF5>CharGet</span><span class=cF0>;
<a name="l305"></a>
<a name="l306"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l307"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
<a name="l308"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc);
<a name="l309"></a>}
<a name="l310"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>FAT32DriveView</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let=</span><span class=cFE>0</span><span class=cF0>)
<a name="l311"></a>{
<a name="l312"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive = </span><span class=cF5>Letter2Drive</span><span class=cF0>(drv_let);
<a name="l313"></a> </span><span class=cF9>I64</span><span class=cF0> lohi, c1, i, x, y,
<a name="l314"></a> l = (</span><span class=cF3>GR_HEIGHT</span><span class=cF0> - </span><span class=cFE>3</span><span class=cF0> * </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>) * (</span><span class=cF3>GR_WIDTH</span><span class=cF0> - </span><span class=cF3>FONT_WIDTH</span><span class=cF0> &lt;&lt; </span><span class=cFE>1</span><span class=cF0>),
<a name="l315"></a> s = (drive-&gt;size + drive-&gt;spc - </span><span class=cFE>1</span><span class=cF0>) / drive-&gt;spc - (</span><span class=cFE>2</span><span class=cF0> + drive-&gt;data_area - drive-&gt;drv_offset);
<a name="l316"></a> </span><span class=cF9>U32</span><span class=cF0> *bitmap;
<a name="l317"></a> </span><span class=cF9>CDC</span><span class=cF0> *dc = </span><span class=cF5>DCAlias</span><span class=cF0>;
<a name="l318"></a>
<a name="l319"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="https://www.tomawezome.github.io/ZealOS/System/TaskSettings.html#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
<a name="l320"></a> </span><span class=cF5>WinMax</span><span class=cF0>;
<a name="l321"></a> </span><span class=cF5>WinBorder</span><span class=cF0>(</span><span class=cF3>ON</span><span class=cF0>);
<a name="l322"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l323"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l324"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
<a name="l325"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l326"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l327"></a> i = (s * </span><span class=cFE>4</span><span class=cF0> + </span><span class=cF3>BLK_SIZE</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>) &gt;&gt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l328"></a> bitmap = </span><span class=cF5>MAlloc</span><span class=cF0>(i &lt;&lt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l329"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(drive, bitmap, drive-&gt;fat1, i);
<a name="l330"></a> i = </span><span class=cFE>0</span><span class=cF0>;
<a name="l331"></a> </span><span class=cF1>for</span><span class=cF0> (y = </span><span class=cFE>0</span><span class=cF0>; y &lt; </span><span class=cF3>GR_HEIGHT</span><span class=cF0> - </span><span class=cFE>3</span><span class=cF0> * </span><span class=cF3>FONT_HEIGHT</span><span class=cF0>; y++)
<a name="l332"></a> {
<a name="l333"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>KeyScan</span><span class=cF0>)
<a name="l334"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l335"></a> </span><span class=cF1>for</span><span class=cF0> (x = </span><span class=cFE>0</span><span class=cF0>; x &lt; </span><span class=cF3>GR_WIDTH</span><span class=cF0> - </span><span class=cF3>FONT_WIDTH</span><span class=cF0> &lt;&lt; </span><span class=cFE>1</span><span class=cF0>; x++)
<a name="l336"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l337"></a> lohi = i * s;
<a name="l338"></a> c1 = lohi / l;
<a name="l339"></a> </span><span class=cF1>if</span><span class=cF0> (bitmap[c1])
<a name="l340"></a> dc-&gt;color = </span><span class=cF3>ROP_XOR</span><span class=cF0> + </span><span class=cF3>BLUE</span><span class=cF0> ^ </span><span class=cF3>TRANSPARENT</span><span class=cF0>;
<a name="l341"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l342"></a> dc-&gt;color = </span><span class=cF3>ROP_XOR</span><span class=cF0> + </span><span class=cF3>WHITE</span><span class=cF0> ^ </span><span class=cF3>TRANSPARENT</span><span class=cF0>;
<a name="l343"></a> </span><span class=cF5>GrPlot</span><span class=cF0>(dc, x, y);
<a name="l344"></a> i++;
<a name="l345"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l346"></a> }
<a name="l347"></a> </span><span class=cF5>Free</span><span class=cF0>(bitmap);
<a name="l348"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l349"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l350"></a> </span><span class=cF5>DriveUnlock</span><span class=cF0>(drive);
<a name="l351"></a> </span><span class=cF5>CharGet</span><span class=cF0>;
<a name="l352"></a>
<a name="l353"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l354"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
<a name="l355"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc);
<a name="l356"></a>}
<a name="l357"></a>
<a name="l358"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DriveView</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let=</span><span class=cFE>0</span><span class=cF0>)
<a name="l359"></a>{</span><span class=cF2>//Drive view. Graph the allocation map's fragmentation.</span><span class=cF0>
<a name="l360"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive = </span><span class=cF5>Letter2Drive</span><span class=cF0>(drv_let), *old_dv = </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv;
<a name="l361"></a>
<a name="l362"></a> </span><span class=cF5>Drive</span><span class=cF0>(drv_let);
<a name="l363"></a> </span><span class=cF1>switch</span><span class=cF0> (drive-&gt;fs_type)
<a name="l364"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l365"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l366"></a> </span><span class=cF5>RedSeaDriveView</span><span class=cF0>(drv_let);
<a name="l367"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l368"></a>
<a name="l369"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l370"></a> </span><span class=cF5>FAT32DriveView</span><span class=cF0>(drv_let);
<a name="l371"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l372"></a>
<a name="l373"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l374"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;File System Not Supported\n&quot;</span><span class=cF0>);
<a name="l375"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l376"></a> </span><span class=cF5>Drive</span><span class=cF0>(</span><span class=cF5>Drive2Letter</span><span class=cF7>(</span><span class=cF0>old_dv</span><span class=cF7>)</span><span class=cF0>);
<a name="l377"></a>}
<a name="l378"></a>
<a name="l379"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DiskView</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let=</span><span class=cFE>0</span><span class=cF0>)
<a name="l380"></a>{</span><span class=cF2>//Disk view. Pie chart of partition sizes.</span><span class=cF0>
<a name="l381"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, attr,
<a name="l382"></a> h = </span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_width,
<a name="l383"></a> v = </span><span class=cF5>Fs</span><span class=cF0>-&gt;pix_height,
<a name="l384"></a> radius;
<a name="l385"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive;
<a name="l386"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd = </span><span class=cF5>Letter2BlkDev</span><span class=cF0>(drv_let);
<a name="l387"></a> </span><span class=cF9>CDC</span><span class=cF0> *dc = </span><span class=cF5>DCAlias</span><span class=cF0>;
<a name="l388"></a> </span><span class=cF1>F64</span><span class=cF0> sect_start, sect_end;
<a name="l389"></a>
<a name="l390"></a> </span><span class=cF5>SettingsPush</span><span class=cF0>; </span><span class=cF2>//See </span><a href="https://www.tomawezome.github.io/ZealOS/System/TaskSettings.html#l3"><span class=cF4>SettingsPush</span></a><span class=cF0>
<a name="l391"></a> </span><span class=cF5>DocCursor</span><span class=cF0>;
<a name="l392"></a> </span><span class=cF5>DocClear</span><span class=cF0>;
<a name="l393"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
<a name="l394"></a> </span><span class=cF1>if</span><span class=cF0> (h &lt; v)
<a name="l395"></a> radius = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>4</span><span class=cF0> * h;
<a name="l396"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l397"></a> radius = </span><span class=cFE>0</span><span class=cF0>.</span><span class=cFE>4</span><span class=cF0> * v;
<a name="l398"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l399"></a> </span><span class=cF5>GrCircle</span><span class=cF0>(dc, h &gt;&gt; </span><span class=cFE>1</span><span class=cF0>, v &gt;&gt; </span><span class=cFE>1</span><span class=cF0>, radius);
<a name="l400"></a>
<a name="l401"></a> j = </span><span class=cFE>1</span><span class=cF0>;
<a name="l402"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cF3>DRIVES_NUM</span><span class=cF0>; i++)
<a name="l403"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l404"></a> drive = &amp;</span><span class=cFB>blkdev</span><span class=cF0>.drvs[i];
<a name="l405"></a> </span><span class=cF1>if</span><span class=cF0> (bd == drive-&gt;bd &amp;&amp; drive-&gt;fs_type)
<a name="l406"></a> {
<a name="l407"></a> sect_start = -(drive-&gt;drv_offset * </span><span class=cFE>2</span><span class=cF0> * </span><span class=cF3>pi</span><span class=cF0> / </span><span class=cF7>(</span><span class=cF0>bd-&gt;max_blk + </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0>);
<a name="l408"></a> sect_end = -(</span><span class=cF7>(</span><span class=cF0>drive-&gt;drv_offset + drive-&gt;size</span><span class=cF7>)</span><span class=cF0> * </span><span class=cFE>2</span><span class=cF0> * </span><span class=cF3>pi</span><span class=cF0> / </span><span class=cF7>(</span><span class=cF0>bd-&gt;max_blk + </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0>);
<a name="l409"></a> dc-&gt;color = </span><span class=cF3>BLACK</span><span class=cF0>;
<a name="l410"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, h &gt;&gt; </span><span class=cFE>1</span><span class=cF0>, v &gt;&gt; </span><span class=cFE>1</span><span class=cF0>,
<a name="l411"></a> h &gt;&gt; </span><span class=cFE>1</span><span class=cF0> + radius * </span><span class=cF5>Cos</span><span class=cF7>(</span><span class=cF0>sect_start</span><span class=cF7>)</span><span class=cF0>,
<a name="l412"></a> v &gt;&gt; </span><span class=cFE>1</span><span class=cF0> + radius * </span><span class=cF5>Sin</span><span class=cF7>(</span><span class=cF0>sect_start</span><span class=cF7>)</span><span class=cF0>);
<a name="l413"></a>
<a name="l414"></a> </span><span class=cF5>GrLine</span><span class=cF0>(dc, h &gt;&gt; </span><span class=cFE>1</span><span class=cF0>, v &gt;&gt; </span><span class=cFE>1</span><span class=cF0>,
<a name="l415"></a> h &gt;&gt; </span><span class=cFE>1</span><span class=cF0> + radius * </span><span class=cF5>Cos</span><span class=cF7>(</span><span class=cF0>sect_end</span><span class=cF7>)</span><span class=cF0>,
<a name="l416"></a> v &gt;&gt; </span><span class=cFE>1</span><span class=cF0> + radius * </span><span class=cF5>Sin</span><span class=cF7>(</span><span class=cF0>sect_end</span><span class=cF7>)</span><span class=cF0>);
<a name="l417"></a>
<a name="l418"></a> attr = </span><span class=cF5>DriveTextAttrGet</span><span class=cF0>(</span><span class=cF5>Drive2Letter</span><span class=cF7>(</span><span class=cF0>drive</span><span class=cF7>)</span><span class=cF0>);
<a name="l419"></a> dc-&gt;color = attr &amp; </span><span class=cFE>15</span><span class=cF0>;
<a name="l420"></a> </span><span class=cF5>GrPrint</span><span class=cF0>(dc, </span><span class=cFE>0</span><span class=cF0>, v - </span><span class=cF3>FONT_HEIGHT</span><span class=cF0> * j, </span><span class=cF6>&quot;%C %-8Z&quot;</span><span class=cF0>, </span><span class=cF5>Drive2Letter</span><span class=cF7>(</span><span class=cF0>drive</span><span class=cF7>)</span><span class=cF0>, drive-&gt;fs_type, </span><span class=cF6>&quot;ST_DRIVE_TYPES&quot;</span><span class=cF0>);
<a name="l421"></a> dc-&gt;color.c1 = attr &gt;&gt; </span><span class=cFE>4</span><span class=cF0>;
<a name="l422"></a> dc-&gt;color |= </span><span class=cF3>ROPF_DITHER</span><span class=cF0>;
<a name="l423"></a> </span><span class=cF5>GrFloodFill</span><span class=cF0>(dc,
<a name="l424"></a> h &gt;&gt; </span><span class=cFE>1</span><span class=cF0> + </span><span class=cF7>(</span><span class=cF0>radius - </span><span class=cFE>4</span><span class=cF7>)</span><span class=cF0> * </span><span class=cF5>Cos</span><span class=cF7>(</span><span class=cF0>(sect_start + sect_end) / </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0>,
<a name="l425"></a> v &gt;&gt; </span><span class=cFE>1</span><span class=cF0> + </span><span class=cF7>(</span><span class=cF0>radius - </span><span class=cFE>4</span><span class=cF7>)</span><span class=cF0> * </span><span class=cF5>Sin</span><span class=cF7>(</span><span class=cF0>(sect_start + sect_end) / </span><span class=cFE>2</span><span class=cF7>)</span><span class=cF0>, </span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l426"></a> j++;
<a name="l427"></a> }
<a name="l428"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l429"></a>
<a name="l430"></a> </span><span class=cF5>CharGet</span><span class=cF0>(,</span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l431"></a> </span><span class=cF5>SettingsPop</span><span class=cF0>;
<a name="l432"></a> </span><span class=cF5>DCFill</span><span class=cF0>;
<a name="l433"></a> </span><span class=cF5>DCDel</span><span class=cF0>(dc);
<a name="l434"></a>}
<a name="l435"></a>
<a name="l436"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>RedSeaUnusedDriveSpace</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let=</span><span class=cFE>0</span><span class=cF0>)
<a name="l437"></a>{
<a name="l438"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive = </span><span class=cF5>Letter2Drive</span><span class=cF0>(drv_let);
<a name="l439"></a> </span><span class=cF9>I64</span><span class=cF0> res = </span><span class=cFE>0</span><span class=cF0>, i, l;
<a name="l440"></a> </span><span class=cF1>U8</span><span class=cF0> *bitmap;
<a name="l441"></a>
<a name="l442"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l443"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l444"></a> l = drive-&gt;size + drive-&gt;drv_offset - drive-&gt;data_area;
<a name="l445"></a> i = (</span><span class=cF7>(</span><span class=cF0>l + </span><span class=cFE>7</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>3</span><span class=cF0> + </span><span class=cF3>BLK_SIZE</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>) &gt;&gt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l446"></a> bitmap = </span><span class=cF5>MAlloc</span><span class=cF0>(i &lt;&lt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l447"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(drive, bitmap, drive-&gt;fat1, i);
<a name="l448"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; l; i++)
<a name="l449"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>bitmap, i</span><span class=cF7>)</span><span class=cF0>)
<a name="l450"></a> res++;
<a name="l451"></a> </span><span class=cF5>Free</span><span class=cF0>(bitmap);
<a name="l452"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l453"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l454"></a> </span><span class=cF5>DriveUnlock</span><span class=cF0>(drive);
<a name="l455"></a>
<a name="l456"></a> </span><span class=cF1>return</span><span class=cF0> res * </span><span class=cF3>BLK_SIZE</span><span class=cF0> * drive-&gt;spc;
<a name="l457"></a>}
<a name="l458"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>FAT32UnusedDriveSpace</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let=</span><span class=cFE>0</span><span class=cF0>)
<a name="l459"></a>{
<a name="l460"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive = </span><span class=cF5>Letter2Drive</span><span class=cF0>(drv_let);
<a name="l461"></a> </span><span class=cF9>I64</span><span class=cF0> res = </span><span class=cFE>0</span><span class=cF0>, i, l;
<a name="l462"></a> </span><span class=cF9>U32</span><span class=cF0> *bitmap;
<a name="l463"></a>
<a name="l464"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l465"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l466"></a> l = (drive-&gt;size + drive-&gt;spc - </span><span class=cFE>1</span><span class=cF0>) / drive-&gt;spc - (</span><span class=cFE>2</span><span class=cF0> + drive-&gt;data_area - drive-&gt;drv_offset);
<a name="l467"></a> i = (l * </span><span class=cFE>4</span><span class=cF0> + </span><span class=cF3>BLK_SIZE</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>) &gt;&gt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l468"></a> bitmap = </span><span class=cF5>MAlloc</span><span class=cF0>(i &lt;&lt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l469"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(drive, bitmap, drive-&gt;fat1, i);
<a name="l470"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; l; i++)
<a name="l471"></a> </span><span class=cF1>if</span><span class=cF0> (!bitmap[i])
<a name="l472"></a> res++;
<a name="l473"></a> </span><span class=cF5>Free</span><span class=cF0>(bitmap);
<a name="l474"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l475"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l476"></a> </span><span class=cF5>DriveUnlock</span><span class=cF0>(drive);
<a name="l477"></a>
<a name="l478"></a> </span><span class=cF1>return</span><span class=cF0> res * </span><span class=cF3>BLK_SIZE</span><span class=cF0> * drive-&gt;spc;
<a name="l479"></a>}
<a name="l480"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>DriveUnused</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let=</span><span class=cFE>0</span><span class=cF0>)
<a name="l481"></a>{</span><span class=cF2>//Returns unused size in bytes.</span><span class=cF0>
<a name="l482"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive = </span><span class=cF5>Letter2Drive</span><span class=cF0>(drv_let), *old_dv = </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv;
<a name="l483"></a> </span><span class=cF1>U8</span><span class=cF0> *old_dir = </span><span class=cF5>StrNew</span><span class=cF0>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir);
<a name="l484"></a> </span><span class=cF9>I64</span><span class=cF0> res = </span><span class=cFE>0</span><span class=cF0>;
<a name="l485"></a>
<a name="l486"></a> </span><span class=cF5>Drive</span><span class=cF0>(drv_let);
<a name="l487"></a> </span><span class=cF1>switch</span><span class=cF0> (drive-&gt;fs_type)
<a name="l488"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l489"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l490"></a> res = </span><span class=cF5>RedSeaUnusedDriveSpace</span><span class=cF0>(drv_let);
<a name="l491"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l492"></a>
<a name="l493"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l494"></a> res = </span><span class=cF5>FAT32UnusedDriveSpace</span><span class=cF0>(drv_let);
<a name="l495"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l496"></a>
<a name="l497"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l498"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;File System Not Supported\n&quot;</span><span class=cF0>);
<a name="l499"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l500"></a> </span><span class=cF5>Drive</span><span class=cF0>(</span><span class=cF5>Drive2Letter</span><span class=cF7>(</span><span class=cF0>old_dv</span><span class=cF7>)</span><span class=cF0>);
<a name="l501"></a> </span><span class=cF5>Cd</span><span class=cF0>(old_dir);
<a name="l502"></a> </span><span class=cF5>Free</span><span class=cF0>(old_dir);
<a name="l503"></a>
<a name="l504"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l505"></a>}
</span></pre></body>
</html>