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

219 lines
23 KiB
Plaintext
Raw Normal View History

2024-03-24 21:24:44 +00:00
<!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=cF1>Bool</span><span class=cF0> </span><span class=cF5>BlkDevLock</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd)
<a name="l2"></a>{</span><span class=cF2>//Make this task have exclusive access to BlkDev.</span><span class=cF0>
<a name="l3"></a> </span><span class=cF5>BlkDevChk</span><span class=cF0>(bd);
<a name="l4"></a> </span><span class=cF1>while</span><span class=cF0> (bd-&gt;lock_fwding)
<a name="l5"></a> bd=bd-&gt;lock_fwding; </span><span class=cF2>//If two blkdevs on same controller, use just one lock</span><span class=cF0>
<a name="l6"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;bd-&gt;locked_flags,</span><span class=cF3>BDlf_LOCKED</span><span class=cF7>)</span><span class=cF0> || bd-&gt;owning_task!=</span><span class=cF5>Fs</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l7"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;bd-&gt;locked_flags,</span><span class=cF3>BDlf_LOCKED</span><span class=cF7>)</span><span class=cF0>)
<a name="l8"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l9"></a> bd-&gt;owning_task=</span><span class=cF5>Fs</span><span class=cF0>;
<a name="l10"></a> </span><span class=cF1>return</span><span class=cF0> </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> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l13"></a>}
<a name="l14"></a>
<a name="l15"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>Bool</span><span class=cF0> rst=</span><span class=cF3>FALSE</span><span class=cF0>)
<a name="l16"></a>{</span><span class=cF2>//Release exclusive lock on access to BlkDev.</span><span class=cF0>
<a name="l17"></a> </span><span class=cF5>BlkDevChk</span><span class=cF0>(bd);
<a name="l18"></a> </span><span class=cF1>while</span><span class=cF0> (bd-&gt;lock_fwding)
<a name="l19"></a> bd=bd-&gt;lock_fwding; </span><span class=cF2>//If two blkdevs on same controller, use just one lock</span><span class=cF0>
<a name="l20"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;bd-&gt;locked_flags,</span><span class=cF3>BDlf_LOCKED</span><span class=cF7>)</span><span class=cF0> &amp;&amp; bd-&gt;owning_task==</span><span class=cF5>Fs</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l21"></a> </span><span class=cF1>if</span><span class=cF0> (rst)
<a name="l22"></a> bd-&gt;flags&amp;=~(</span><span class=cF3>BDF_INITIALIZED</span><span class=cF0>|</span><span class=cF3>BDF_INIT_IN_PROGRESS</span><span class=cF0>);
<a name="l23"></a> bd-&gt;owning_task=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l24"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;bd-&gt;locked_flags,</span><span class=cF3>BDlf_LOCKED</span><span class=cF0>);
<a name="l25"></a> </span><span class=cF5>Yield</span><span class=cF0>; </span><span class=cF2>//Prevent deadlock</span><span class=cF0>
<a name="l26"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l27"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l28"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</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=cFD>BlkDevInit</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd)
<a name="l32"></a>{
<a name="l33"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> de;
<a name="l34"></a> </span><span class=cF1>U8</span><span class=cF0> buf[</span><span class=cF3>STR_LEN</span><span class=cF0>];
<a name="l35"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv=</span><span class=cF5>Let2Drv</span><span class=cF0>(bd-&gt;first_drv_let);
<a name="l36"></a> </span><span class=cF1>Bool</span><span class=cF0> res=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l37"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;bd-&gt;flags,</span><span class=cF3>BDf_INITIALIZED</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l38"></a> bd-&gt;flags|=</span><span class=cF3>BDF_INIT_IN_PROGRESS</span><span class=cF0>;
<a name="l39"></a> </span><span class=cF1>switch</span><span class=cF0> (bd-&gt;type) {
<a name="l40"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_RAM</span><span class=cF0>:
<a name="l41"></a> </span><span class=cF1>if</span><span class=cF0> (!bd-&gt;RAM_dsk) </span><span class=cF7>{</span><span class=cF0>
<a name="l42"></a> bd-&gt;RAM_dsk=</span><span class=cF5>AMAlloc</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>bd-&gt;max_blk+1</span><span class=cF7>)</span><span class=cF0>&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l43"></a> bd-&gt;max_blk=</span><span class=cF5>MSize</span><span class=cF0>(bd-&gt;RAM_dsk)&gt;&gt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>-1;
<a name="l44"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l45"></a> dv-&gt;fs_type=</span><span class=cF3>FSt_REDSEA</span><span class=cF0>;
<a name="l46"></a> dv-&gt;size=bd-&gt;max_blk+1-bd-&gt;drv_offset;
<a name="l47"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>RedSeaValidate</span><span class=cF7>(</span><span class=cF0>bd-&gt;first_drv_let</span><span class=cF7>)</span><span class=cF0>)
<a name="l48"></a> </span><span class=cFD>RedSeaInit</span><span class=cF0>(dv);
<a name="l49"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l50"></a> </span><span class=cFD>RedSeaFmt</span><span class=cF0>(bd-&gt;first_drv_let);
<a name="l51"></a> res=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l52"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l53"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ISO_FILE_READ</span><span class=cF0>:
<a name="l54"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>FileFind</span><span class=cF7>(</span><span class=cF0>bd-&gt;file_dsk_name,&amp;de,</span><span class=cF3>FUF_JUST_FILES</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l55"></a> bd-&gt;max_blk=de.size&gt;&gt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>-1;
<a name="l56"></a> </span><span class=cF1>try</span><span class=cF0> bd-&gt;file_dsk=</span><span class=cF5>FOpen</span><span class=cF0>(bd-&gt;file_dsk_name,</span><span class=cF6>&quot;rc&quot;</span><span class=cF0>,bd-&gt;max_blk+1);
<a name="l57"></a> </span><span class=cF1>catch</span><span class=cF0> {
<a name="l58"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Fs</span><span class=cF0>-&gt;except_ch==</span><span class=cF6>'File'</span><span class=cF0>)
<a name="l59"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Not Contiguous. Move file to filename.ISO.C.\n&quot;</span><span class=cF0>);
<a name="l60"></a> </span><span class=cF5>Fs</span><span class=cF0>-&gt;catch_except=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l61"></a> }
<a name="l62"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;file_dsk) {
<a name="l63"></a> dv-&gt;fs_type=</span><span class=cF3>FSt_REDSEA</span><span class=cF0>;
<a name="l64"></a> dv-&gt;size=bd-&gt;max_blk+1-bd-&gt;drv_offset;
<a name="l65"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>RedSeaValidate</span><span class=cF7>(</span><span class=cF0>bd-&gt;first_drv_let</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l66"></a> </span><span class=cFD>RedSeaInit</span><span class=cF0>(dv);
<a name="l67"></a> res=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l68"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l69"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Not RedSea\n&quot;</span><span class=cF0>);
<a name="l70"></a> }
<a name="l71"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l72"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l73"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ISO_FILE_WRITE</span><span class=cF0>:
<a name="l74"></a> </span><span class=cF1>if</span><span class=cF0> (!bd-&gt;file_dsk_name) </span><span class=cF7>{</span><span class=cF0>
<a name="l75"></a> </span><span class=cF5>StrPrint</span><span class=cF0>(buf,</span><span class=cF6>&quot;%C:/Drv%C.ISO.C&quot;</span><span class=cF0>,
<a name="l76"></a> </span><span class=cFB>blkdev</span><span class=cF0>.boot_drv_let,bd-&gt;first_drv_let);
<a name="l77"></a> bd-&gt;file_dsk_name=</span><span class=cF5>AStrNew</span><span class=cF0>(buf);
<a name="l78"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l79"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;max_blk&lt;7)
<a name="l80"></a> bd-&gt;max_blk=7;
<a name="l81"></a> bd-&gt;file_dsk=</span><span class=cF5>FOpen</span><span class=cF0>(bd-&gt;file_dsk_name,</span><span class=cF6>&quot;wc&quot;</span><span class=cF0>,bd-&gt;max_blk+1);
<a name="l82"></a> dv-&gt;fs_type=</span><span class=cF3>FSt_REDSEA</span><span class=cF0>;
<a name="l83"></a> dv-&gt;size=bd-&gt;max_blk+1-bd-&gt;drv_offset;
<a name="l84"></a> </span><span class=cFD>RedSeaFmt</span><span class=cF0>(bd-&gt;first_drv_let);
<a name="l85"></a> </span><span class=cF5>CallExtStr</span><span class=cF0>(</span><span class=cF6>&quot;RedSeaISO9660&quot;</span><span class=cF0>,bd-&gt;file_dsk_name,bd-&gt;first_drv_let);
<a name="l86"></a> res=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l87"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l88"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ATA</span><span class=cF0>:
<a name="l89"></a> bd-&gt;max_reads=128;
<a name="l90"></a> bd-&gt;max_writes=1;
<a name="l91"></a> res=</span><span class=cFD>ATAInit</span><span class=cF0>(bd);
<a name="l92"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l93"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ATAPI</span><span class=cF0>:
<a name="l94"></a></span><span class=cF2>//0xFFFF*4 is too big for my taste</span><span class=cF0>
<a name="l95"></a> bd-&gt;max_reads=0x800*4;
<a name="l96"></a></span><span class=cF2>//max of maybe a quarter of disk cache</span><span class=cF0>
<a name="l97"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;max_reads&gt;</span><span class=cFB>blkdev</span><span class=cF0>.cache_size/</span><span class=cF3>BLK_SIZE</span><span class=cF0>/4)
<a name="l98"></a> bd-&gt;max_reads=</span><span class=cFB>blkdev</span><span class=cF0>.cache_size/</span><span class=cF3>BLK_SIZE</span><span class=cF0>/4 &amp; ~3;
<a name="l99"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;max_reads&lt;128)
<a name="l100"></a> bd-&gt;max_reads=128;
<a name="l101"></a> bd-&gt;max_writes=0xFFFF*4;
<a name="l102"></a> </span><span class=cF1>if</span><span class=cF0> (res=</span><span class=cFD>ATAInit</span><span class=cF7>(</span><span class=cF0>bd</span><span class=cF7>)</span><span class=cF0>)
<a name="l103"></a> dv-&gt;size=bd-&gt;max_blk+1;
<a name="l104"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l105"></a> }
<a name="l106"></a> </span><span class=cF1>if</span><span class=cF0> (res &amp;&amp; bd-&gt;flags &amp; </span><span class=cF3>BDF_READ_CACHE</span><span class=cF0>)
<a name="l107"></a> </span><span class=cF5>DskCacheInvalidate</span><span class=cF0>(dv);
<a name="l108"></a> bd-&gt;flags&amp;=~</span><span class=cF3>BDF_INIT_IN_PROGRESS</span><span class=cF0>;
<a name="l109"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l110"></a> res=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l111"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l112"></a>}
<a name="l113"></a>
<a name="l114"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>BlkDevsRelease</span><span class=cF0>()
<a name="l115"></a>{</span><span class=cF2>//When task dies, release all owned BlkDevs.</span><span class=cF0>
<a name="l116"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l117"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd;
<a name="l118"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;</span><span class=cF3>BLKDEVS_NUM</span><span class=cF0>;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l119"></a> bd=&amp;</span><span class=cFB>blkdev</span><span class=cF0>.blkdevs[i];
<a name="l120"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;owning_task==</span><span class=cF5>Fs</span><span class=cF0> &amp;&amp; bd-&gt;bd_signature==</span><span class=cF3>BD_SIGNATURE_VAL</span><span class=cF0>)
<a name="l121"></a> </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd,</span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l122"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l123"></a>}
<a name="l124"></a>
<a name="l125"></a></span><span class=cF9>CBlkDev</span><span class=cF0> *</span><span class=cF5>BlkDevNextFreeSlot</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> first_drv_let,</span><span class=cF9>I64</span><span class=cF0> type)
<a name="l126"></a>{</span><span class=cF2>//Locate free slot for new BlkDev, like during </span><a href="/Wb/Adam/ABlkDev/Mount.HC.HTML#l138"><span class=cF4>Mount</span></a><span class=cF2>().</span><span class=cF0>
<a name="l127"></a> </span><span class=cF9>I64</span><span class=cF0> i=0;
<a name="l128"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *res;
<a name="l129"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Let2BlkDevType</span><span class=cF7>(</span><span class=cF0>first_drv_let</span><span class=cF7>)</span><span class=cF0>!=type)
<a name="l130"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'BlkDev'</span><span class=cF0>);
<a name="l131"></a> </span><span class=cF1>do</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l132"></a> res=&amp;</span><span class=cFB>blkdev</span><span class=cF0>.blkdevs[i];
<a name="l133"></a> </span><span class=cF1>if</span><span class=cF0> (res-&gt;bd_signature!=</span><span class=cF3>BD_SIGNATURE_VAL</span><span class=cF0>) {
<a name="l134"></a> </span><span class=cF5>MemSet</span><span class=cF0>(res,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CBlkDev</span><span class=cF7>)</span><span class=cF0>);
<a name="l135"></a> res-&gt;first_drv_let=first_drv_let;
<a name="l136"></a> res-&gt;type=type;
<a name="l137"></a> res-&gt;flags=</span><span class=cF3>BDF_READ_CACHE</span><span class=cF0>;
<a name="l138"></a> res-&gt;blk_size=</span><span class=cF3>BLK_SIZE</span><span class=cF0>;
<a name="l139"></a> res-&gt;max_blk=0xEFFFFFFF;
<a name="l140"></a> </span><span class=cF1>switch</span><span class=cF0> (type) </span><span class=cF7>{</span><span class=cF0>
<a name="l141"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_RAM</span><span class=cF0>:
<a name="l142"></a> res-&gt;flags&amp;=~</span><span class=cF3>BDF_READ_CACHE</span><span class=cF0>;
<a name="l143"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l144"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ISO_FILE_READ</span><span class=cF0>:
<a name="l145"></a> res-&gt;flags|=</span><span class=cF3>BDF_READ_ONLY</span><span class=cF0>;
<a name="l146"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l147"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>BDT_ATAPI</span><span class=cF0>:
<a name="l148"></a> res-&gt;flags|=</span><span class=cF3>BDF_REMOVABLE</span><span class=cF0>|</span><span class=cF3>BDF_READ_ONLY</span><span class=cF0>;
<a name="l149"></a> res-&gt;blk_size=</span><span class=cF3>DVD_BLK_SIZE</span><span class=cF0>;
<a name="l150"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l151"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l152"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l153"></a> }
<a name="l154"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>while</span><span class=cF0> (++i&lt;</span><span class=cF3>BLKDEVS_NUM</span><span class=cF0>);
<a name="l155"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'BlkDev'</span><span class=cF0>);
<a name="l156"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>; </span><span class=cF2>//never gets here</span><span class=cF0>
<a name="l157"></a>}
<a name="l158"></a>
<a name="l159"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>BlkDevDel</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd)
<a name="l160"></a>{</span><span class=cF2>//Delete BlkDev</span><span class=cF0>
<a name="l161"></a> </span><span class=cFD>DrvBlkDevDel</span><span class=cF0>(bd);
<a name="l162"></a> </span><span class=cF5>FClose</span><span class=cF0>(bd-&gt;file_dsk);
<a name="l163"></a> </span><span class=cF5>Free</span><span class=cF0>(bd-&gt;file_dsk_name);
<a name="l164"></a> </span><span class=cF5>Free</span><span class=cF0>(bd-&gt;dev_id_record);
<a name="l165"></a> </span><span class=cF5>MemSet</span><span class=cF0>(bd,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CBlkDev</span><span class=cF7>)</span><span class=cF0>);
<a name="l166"></a>}
<a name="l167"></a>
<a name="l168"></a></span><span class=cF9>CBlkDev</span><span class=cF0> *</span><span class=cF5>BlkDevChk</span><span class=cF0>(</span><span class=cF9>CBlkDev</span><span class=cF0> *bd,</span><span class=cF1>Bool</span><span class=cF0> except=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l169"></a>{</span><span class=cF2>//Check for valid BlkDev. Throw exception.</span><span class=cF0>
<a name="l170"></a> </span><span class=cF1>if</span><span class=cF0> (!bd || bd-&gt;bd_signature!=</span><span class=cF3>BD_SIGNATURE_VAL</span><span class=cF0> ||
<a name="l171"></a> !</span><span class=cF7>(</span><span class=cF3>BDT_NULL</span><span class=cF0>&lt;bd-&gt;type&lt;</span><span class=cF3>BDT_TYPES_NUM</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l172"></a> </span><span class=cF1>if</span><span class=cF0> (except)
<a name="l173"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'BlkDev'</span><span class=cF0>);
<a name="l174"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l175"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l176"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l177"></a> </span><span class=cF1>return</span><span class=cF0> bd;
<a name="l178"></a>}
<a name="l179"></a>
<a name="l180"></a></span><span class=cF9>CBlkDev</span><span class=cF0> *</span><span class=cF5>Let2BlkDev</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let=0,</span><span class=cF1>Bool</span><span class=cF0> except=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l181"></a>{</span><span class=cF2>//Drv letter to BlkDev ptr.</span><span class=cF0>
<a name="l182"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv;
<a name="l183"></a> </span><span class=cF1>if</span><span class=cF0> (dv=</span><span class=cF5>Let2Drv</span><span class=cF7>(</span><span class=cF0>drv_let,except</span><span class=cF7>)</span><span class=cF0>)
<a name="l184"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>BlkDevChk</span><span class=cF0>(dv-&gt;bd,except);
<a name="l185"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l186"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l187"></a>}
</span></pre></body>
</html>