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

141 lines
13 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=cF0>#</span><span class=cF1>define</span><span class=cF0> ZERO_BUF_SIZE 2048
<a name="l2"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>BlkWriteZero</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF9>I64</span><span class=cF0> blk,</span><span class=cF9>I64</span><span class=cF0> cnt)
<a name="l3"></a>{</span><span class=cF2>//Fill blk cnt with zeros in Drv.</span><span class=cF0>
<a name="l4"></a> </span><span class=cF9>I64</span><span class=cF0> n;
<a name="l5"></a> </span><span class=cF1>U8</span><span class=cF0> *z=</span><span class=cF5>CAlloc</span><span class=cF0>(ZERO_BUF_SIZE&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l6"></a> </span><span class=cF1>Bool</span><span class=cF0> show_progress;
<a name="l7"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&gt;ZERO_BUF_SIZE &amp;&amp; dv-&gt;bd-&gt;type!=</span><span class=cF3>BDT_RAM</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l8"></a> </span><span class=cFB>progress1</span><span class=cF0>=0; </span><span class=cFB>progress1_max</span><span class=cF0>=cnt;
<a name="l9"></a> </span><span class=cF5>StrCpy</span><span class=cF0>(</span><span class=cFB>progress1_desc</span><span class=cF0>,</span><span class=cF6>&quot;Zeroing&quot;</span><span class=cF0>);
<a name="l10"></a> show_progress=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l11"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l12"></a> show_progress=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l13"></a> </span><span class=cF1>while</span><span class=cF0> (cnt&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l14"></a> n=cnt;
<a name="l15"></a> </span><span class=cF1>if</span><span class=cF0> (n&gt;ZERO_BUF_SIZE)
<a name="l16"></a> n=ZERO_BUF_SIZE;
<a name="l17"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,z,blk,n);
<a name="l18"></a> blk+=n;
<a name="l19"></a> cnt-=n;
<a name="l20"></a> </span><span class=cF1>if</span><span class=cF0> (show_progress)
<a name="l21"></a> </span><span class=cFB>progress1</span><span class=cF0>+=n;
<a name="l22"></a> </span><span class=cF5>Yield</span><span class=cF0>; </span><span class=cF2>//Prevent locking</span><span class=cF0>
<a name="l23"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l24"></a> </span><span class=cF5>Free</span><span class=cF0>(z);
<a name="l25"></a> </span><span class=cF1>if</span><span class=cF0> (show_progress) </span><span class=cF7>{</span><span class=cF0>
<a name="l26"></a> *</span><span class=cFB>progress1_desc</span><span class=cF0>=0;
<a name="l27"></a> </span><span class=cFB>progress1</span><span class=cF0>=</span><span class=cFB>progress1_max</span><span class=cF0>=0;
<a name="l28"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l29"></a>}
<a name="l30"></a>
<a name="l31"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>BlkRead</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> blk, </span><span class=cF9>I64</span><span class=cF0> cnt)
<a name="l32"></a>{</span><span class=cF2>//Read blk cnt from Drv to buf.</span><span class=cF0>
<a name="l33"></a> </span><span class=cF1>Bool</span><span class=cF0> res=</span><span class=cF3>TRUE</span><span class=cF0>,unlock;
<a name="l34"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd=dv-&gt;bd;
<a name="l35"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&lt;=0) </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l36"></a> </span><span class=cF5>DrvChk</span><span class=cF0>(dv);
<a name="l37"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l38"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
<a name="l39"></a> </span><span class=cFD>BlkDevInit</span><span class=cF0>(bd);
<a name="l40"></a> </span><span class=cF1>if</span><span class=cF0> (dv-&gt;drv_offset &amp;&amp; blk&lt;dv-&gt;drv_offset ||
<a name="l41"></a> blk+cnt&gt;dv-&gt;drv_offset+dv-&gt;size)
<a name="l42"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
<a name="l43"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_READ_CACHE</span><span class=cF0>)
<a name="l44"></a> </span><span class=cFD>RCache</span><span class=cF0>(dv,&amp;buf,&amp;blk,&amp;cnt);
<a name="l45"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&gt;0) {
<a name="l46"></a> </span><span class=cF1>switch</span><span class=cF0> (bd-&gt;type) </span><span class=cF7>{</span><span class=cF0>
<a name="l47"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_RAM</span><span class=cF0>:
<a name="l48"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(buf,bd-&gt;RAM_dsk+blk&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>,cnt&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l49"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l50"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ISO_FILE_READ</span><span class=cF0>:
<a name="l51"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ISO_FILE_WRITE</span><span class=cF0>:
<a name="l52"></a> </span><span class=cF5>FBlkRead</span><span class=cF0>(bd-&gt;file_dsk,buf,blk,cnt);
<a name="l53"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l54"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ATA</span><span class=cF0>:
<a name="l55"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ATAPI</span><span class=cF0>:
<a name="l56"></a> res=</span><span class=cFD>ATARBlks</span><span class=cF0>(dv,buf,blk,cnt);
<a name="l57"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l58"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l59"></a> bd-&gt;last_time=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l60"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_READ_CACHE</span><span class=cF0>)
<a name="l61"></a> </span><span class=cFD>DskCacheAdd</span><span class=cF0>(dv,buf,blk,cnt);
<a name="l62"></a> }
<a name="l63"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l64"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
<a name="l65"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l66"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l67"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
<a name="l68"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l69"></a>}
<a name="l70"></a>
<a name="l71"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>BlkWrite</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> blk, </span><span class=cF9>I64</span><span class=cF0> cnt)
<a name="l72"></a>{</span><span class=cF2>//Write blk cnt from buf to Drv.</span><span class=cF0>
<a name="l73"></a> </span><span class=cF1>Bool</span><span class=cF0> res=</span><span class=cF3>TRUE</span><span class=cF0>,unlock;
<a name="l74"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd=dv-&gt;bd;
<a name="l75"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&lt;=0) </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l76"></a> </span><span class=cF5>DrvChk</span><span class=cF0>(dv);
<a name="l77"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l78"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
<a name="l79"></a> </span><span class=cFD>BlkDevInit</span><span class=cF0>(bd);
<a name="l80"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags&amp;</span><span class=cF3>BDF_READ_ONLY</span><span class=cF0> &amp;&amp; !</span><span class=cF7>(</span><span class=cF0>bd-&gt;flags &amp; </span><span class=cF3>BDF_READ_ONLY_OVERRIDE</span><span class=cF7>)</span><span class=cF0>)
<a name="l81"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'BlkDev'</span><span class=cF0>);
<a name="l82"></a> </span><span class=cF1>if</span><span class=cF0> (dv-&gt;drv_offset &amp;&amp; blk&lt;dv-&gt;drv_offset ||
<a name="l83"></a> blk+cnt&gt;dv-&gt;drv_offset+dv-&gt;size)
<a name="l84"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
<a name="l85"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&gt;0) {
<a name="l86"></a> </span><span class=cF1>switch</span><span class=cF0> (bd-&gt;type) </span><span class=cF7>{</span><span class=cF0>
<a name="l87"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_RAM</span><span class=cF0>:
<a name="l88"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(bd-&gt;RAM_dsk+blk&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>,buf,cnt&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l89"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l90"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ISO_FILE_READ</span><span class=cF0>:
<a name="l91"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ISO_FILE_WRITE</span><span class=cF0>:
<a name="l92"></a> </span><span class=cF5>FBlkWrite</span><span class=cF0>(bd-&gt;file_dsk,buf,blk,cnt);
<a name="l93"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l94"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ATA</span><span class=cF0>:
<a name="l95"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ATAPI</span><span class=cF0>:
<a name="l96"></a> res=</span><span class=cFD>ATAWBlks</span><span class=cF0>(dv,buf,blk,cnt);
<a name="l97"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l98"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l99"></a> bd-&gt;last_time=</span><span class=cF5>tS</span><span class=cF0>;
<a name="l100"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;flags &amp; </span><span class=cF3>BDF_READ_CACHE</span><span class=cF0>)
<a name="l101"></a> </span><span class=cFD>DskCacheAdd</span><span class=cF0>(dv,buf,blk,cnt);
<a name="l102"></a> }
<a name="l103"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l104"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
<a name="l105"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
<a name="l106"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l107"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
<a name="l108"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l109"></a>}
</span></pre></body>
</html>