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

275 lines
24 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=cFD>ISOInit</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF9>I64</span><span class=cF0> blk)
<a name="l2"></a>{
<a name="l3"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd=dv-&gt;bd;
<a name="l4"></a> </span><span class=cF9>I64</span><span class=cF0> spc=bd-&gt;blk_size&gt;&gt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>,i=blk/spc,drv_offset=0;
<a name="l5"></a> </span><span class=cF9>CISOPriDesc</span><span class=cF0> *iso=</span><span class=cF5>MAlloc</span><span class=cF0>(bd-&gt;blk_size);
<a name="l6"></a> </span><span class=cF9>CISODirEntry</span><span class=cF0> *de;
<a name="l7"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock,res=</span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l8"></a> </span><span class=cF1>U8</span><span class=cF0> buf[8];
<a name="l9"></a>
<a name="l10"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l11"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
<a name="l12"></a> dv-&gt;fs_type=</span><span class=cF3>FSt_ISO9660</span><span class=cF0>;
<a name="l13"></a> dv-&gt;spc=spc;
<a name="l14"></a> dv-&gt;data_area=dv-&gt;root_clus=dv-&gt;drv_offset=bd-&gt;drv_offset=dv-&gt;size=0;
<a name="l15"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
<a name="l16"></a> dv-&gt;size=</span><span class=cF5>MaxI64</span><span class=cF0>(dv-&gt;size,</span><span class=cF7>(</span><span class=cF0>i+1</span><span class=cF7>)</span><span class=cF0>*spc);
<a name="l17"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,iso,i*spc,spc);
<a name="l18"></a> buf[0](</span><span class=cF9>U32</span><span class=cF0>)=iso-&gt;id[0](</span><span class=cF9>U32</span><span class=cF0>);
<a name="l19"></a> buf[4](</span><span class=cF9>U16</span><span class=cF0>)=iso-&gt;id[4](</span><span class=cF1>U8</span><span class=cF0>);
<a name="l20"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>LstMatch</span><span class=cF7>(</span><span class=cF0>buf,</span><span class=cF6>&quot;CD001\0CDW02\0BEA01\0BOOT2\0NSR02\0NSR03\0TEA01\0&quot;</span><span class=cF0>,
<a name="l21"></a> </span><span class=cF3>LMF_EXACT</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l22"></a> </span><span class=cF1>case</span><span class=cF0> 0:
<a name="l23"></a> </span><span class=cF1>switch</span><span class=cF0> (iso-&gt;type) {
<a name="l24"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>ISOT_BOOT_RECORD</span><span class=cF0>:
<a name="l25"></a> drv_offset+=(2*</span><span class=cF3>DVD_BLK_SIZE</span><span class=cF0>+</span><span class=cF3>DVD_BLK_SIZE</span><span class=cF0>)/</span><span class=cF3>BLK_SIZE</span><span class=cF0>;
<a name="l26"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l27"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>ISOT_SUPPLEMENTARY_DESC</span><span class=cF0>:
<a name="l28"></a> de=&amp;iso-&gt;root_dir_record;
<a name="l29"></a> dv-&gt;size=iso-&gt;vol_space_size.little*bd-&gt;blk_size&gt;&gt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l30"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrCmp</span><span class=cF7>(</span><span class=cF0>iso-&gt;publisher_id,</span><span class=cF6>&quot;TempleOS RedSea&quot;</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l31"></a> dv-&gt;fs_type=</span><span class=cF3>FSt_REDSEA</span><span class=cF0>;
<a name="l32"></a> bd-&gt;drv_offset=dv-&gt;drv_offset=19&lt;&lt;2+drv_offset;
<a name="l33"></a> bd-&gt;max_blk=dv-&gt;size-1;
<a name="l34"></a> dv-&gt;size-=bd-&gt;drv_offset;
<a name="l35"></a> </span><span class=cFD>RedSeaInit</span><span class=cF0>(dv);
<a name="l36"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l37"></a> dv-&gt;root_clus=de-&gt;loc.little;
<a name="l38"></a> res=</span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l39"></a> </span><span class=cF1>goto</span><span class=cF0> di_done;
<a name="l40"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>ISOT_TERMINATOR</span><span class=cF0>:
<a name="l41"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
<a name="l42"></a> }
<a name="l43"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l44"></a> </span><span class=cF1>default</span><span class=cF0>: </span><span class=cF2>//Its normal for ISO3346 to read NULL blk as terminator</span><span class=cF0>
<a name="l45"></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="l46"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
<a name="l47"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l48"></a> i++;
<a name="l49"></a> }
<a name="l50"></a>di_done:
<a name="l51"></a> </span><span class=cF5>Free</span><span class=cF0>(iso);
<a name="l52"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l53"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
<a name="l54"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
<a name="l55"></a> dv-&gt;fs_type=</span><span class=cF3>FSt_ISO9660</span><span class=cF0>;
<a name="l56"></a> dv-&gt;spc=spc;
<a name="l57"></a> dv-&gt;drv_offset=bd-&gt;drv_offset=dv-&gt;data_area=dv-&gt;root_clus=0;
<a name="l58"></a> </span><span class=cF5>Free</span><span class=cF0>(iso);
<a name="l59"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l60"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
<a name="l61"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l62"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l63"></a>}
<a name="l64"></a>
<a name="l65"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DVDImageRead</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> dvd_drv_let,</span><span class=cF1>U8</span><span class=cF0> *out_name)
<a name="l66"></a>{</span><span class=cF2>//Read entire CD/DVD image into ISO file.</span><span class=cF0>
<a name="l67"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv=</span><span class=cF5>Let2Drv</span><span class=cF0>(dvd_drv_let);
<a name="l68"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd=dv-&gt;bd;
<a name="l69"></a> </span><span class=cF1>U8</span><span class=cF0> *buf=</span><span class=cF5>MAlloc</span><span class=cF0>(COPY_BUF_BLKS&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>),
<a name="l70"></a> *out_name2=</span><span class=cF5>ExtDft</span><span class=cF0>(out_name,</span><span class=cF6>&quot;ISO&quot;</span><span class=cF0>);
<a name="l71"></a> </span><span class=cF9>CFile</span><span class=cF0> *f=</span><span class=cF5>FOpen</span><span class=cF0>(out_name2,</span><span class=cF6>&quot;w&quot;</span><span class=cF0>);
<a name="l72"></a> </span><span class=cF9>I64</span><span class=cF0> n,spc=bd-&gt;blk_size&gt;&gt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>,blk=0,cnt,retry;
<a name="l73"></a> </span><span class=cFD>BlkDevInit</span><span class=cF0>(bd);
<a name="l74"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;type!=</span><span class=cF3>BDT_ATAPI</span><span class=cF0>)
<a name="l75"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'BlkDev'</span><span class=cF0>);
<a name="l76"></a> </span><span class=cF1>if</span><span class=cF0> (!out_name)
<a name="l77"></a> out_name=</span><span class=cFB>blkdev</span><span class=cF0>.dft_iso_filename;
<a name="l78"></a> cnt=</span><span class=cF5>CeilU64</span><span class=cF0>(dv-&gt;size,spc);
<a name="l79"></a> </span><span class=cF1>while</span><span class=cF0> (cnt&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l80"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&gt;COPY_BUF_BLKS)
<a name="l81"></a> n=COPY_BUF_BLKS;
<a name="l82"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l83"></a> n=cnt;
<a name="l84"></a> </span><span class=cF1>if</span><span class=cF0> (n&gt;bd-&gt;max_reads)
<a name="l85"></a> n=bd-&gt;max_reads;
<a name="l86"></a>
<a name="l87"></a> retry=4;
<a name="l88"></a> </span><span class=cF1>while</span><span class=cF0> (--retry)
<a name="l89"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>ATAPIReadBlks2</span><span class=cF7>(</span><span class=cF0>bd,</span><span class=cF5>tS</span><span class=cF0>+7.0+0.004*n/spc,buf,blk/spc,n/spc,</span><span class=cF3>TRUE</span><span class=cF7>)</span><span class=cF0>)
<a name="l90"></a></span><span class=cF2>//n is 0x800 if max_reads. Up to 8 additional seconds</span><span class=cF0>
<a name="l91"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l92"></a>
<a name="l93"></a> </span><span class=cF1>if</span><span class=cF0> (!retry)
<a name="l94"></a> </span><span class=cFD>ATAPIReadBlks2</span><span class=cF0>(bd,0,buf,blk/spc,n/spc,</span><span class=cF3>TRUE</span><span class=cF0>);
<a name="l95"></a>
<a name="l96"></a> </span><span class=cF5>FBlkWrite</span><span class=cF0>(f,buf,blk,n);
<a name="l97"></a> cnt-=n;
<a name="l98"></a> blk+=n;
<a name="l99"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l100"></a> </span><span class=cF5>FClose</span><span class=cF0>(f);
<a name="l101"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l102"></a> </span><span class=cF5>Free</span><span class=cF0>(out_name2);
<a name="l103"></a>}
<a name="l104"></a>
<a name="l105"></a></span><span class=cF1>class</span><span class=cF0> CDualBuf
<a name="l106"></a>{
<a name="l107"></a> </span><span class=cF1>U8</span><span class=cF0> *buf0,*buf1;
<a name="l108"></a> </span><span class=cF9>I64</span><span class=cF0> in_buf,out_buf,cnt;
<a name="l109"></a> </span><span class=cF1>U8</span><span class=cF0> *filename;
<a name="l110"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *dvd_bd;
<a name="l111"></a>};
<a name="l112"></a>
<a name="l113"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>DVDImageWriteTask</span><span class=cF0>(CDualBuf *d)
<a name="l114"></a>{
<a name="l115"></a> </span><span class=cF1>U8</span><span class=cF0> *buf;
<a name="l116"></a> </span><span class=cF9>I64</span><span class=cF0> n,blk=0,cnt=d-&gt;cnt;
<a name="l117"></a> </span><span class=cF9>CFile</span><span class=cF0> *f;
<a name="l118"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>FileAttr</span><span class=cF7>(</span><span class=cF0>d-&gt;filename</span><span class=cF7>)</span><span class=cF0>&amp;</span><span class=cF3>RS_ATTR_CONTIGUOUS</span><span class=cF0>)
<a name="l119"></a> f=</span><span class=cF5>FOpen</span><span class=cF0>(d-&gt;filename,</span><span class=cF6>&quot;rc&quot;</span><span class=cF0>);
<a name="l120"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l121"></a> f=</span><span class=cF5>FOpen</span><span class=cF0>(d-&gt;filename,</span><span class=cF6>&quot;r&quot;</span><span class=cF0>);
<a name="l122"></a> </span><span class=cF1>while</span><span class=cF0> (cnt&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l123"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&gt;COPY_BUF_BLKS)
<a name="l124"></a> n=COPY_BUF_BLKS;
<a name="l125"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l126"></a> n=cnt;
<a name="l127"></a> </span><span class=cF1>if</span><span class=cF0> (n&gt;d-&gt;dvd_bd-&gt;max_writes)
<a name="l128"></a> n=d-&gt;dvd_bd-&gt;max_writes;
<a name="l129"></a> </span><span class=cF1>if</span><span class=cF0> (d-&gt;in_buf&amp;1)
<a name="l130"></a> buf=d-&gt;buf1;
<a name="l131"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l132"></a> buf=d-&gt;buf0;
<a name="l133"></a> </span><span class=cF1>while</span><span class=cF0> (d-&gt;in_buf&gt;d-&gt;out_buf+1)
<a name="l134"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l135"></a> </span><span class=cF5>FBlkRead</span><span class=cF0>(f,buf,blk,n);
<a name="l136"></a> d-&gt;in_buf++;
<a name="l137"></a> cnt-=n;
<a name="l138"></a> blk+=n;
<a name="l139"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l140"></a> </span><span class=cF5>FClose</span><span class=cF0>(f);
<a name="l141"></a>}
<a name="l142"></a>
<a name="l143"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DVDImageWrite</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> dvd_drv_let,</span><span class=cF1>U8</span><span class=cF0> *in_name=</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF9>I64</span><span class=cF0> media_type=</span><span class=cF3>MT_DVD</span><span class=cF0>)
<a name="l144"></a>{</span><span class=cF2>//Write CD/DVD ISO file to disk.</span><span class=cF0>
<a name="l145"></a> CDualBuf *d=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CDualBuf</span><span class=cF7>)</span><span class=cF0>);
<a name="l146"></a> </span><span class=cF1>U8</span><span class=cF0> *buf,*in_name2,*in_name3;
<a name="l147"></a> </span><span class=cF9>I64</span><span class=cF0> i,n,spc,blk=0,cnt;
<a name="l148"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv=</span><span class=cF5>Let2Drv</span><span class=cF0>(dvd_drv_let);
<a name="l149"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd=dv-&gt;bd,*bd2;
<a name="l150"></a> </span><span class=cF9>CTask</span><span class=cF0> *task;
<a name="l151"></a> </span><span class=cF9>CFile</span><span class=cF0> *f;
<a name="l152"></a>
<a name="l153"></a> </span><span class=cF1>if</span><span class=cF0> (!in_name)
<a name="l154"></a> in_name=</span><span class=cFB>blkdev</span><span class=cF0>.dft_iso_filename;
<a name="l155"></a> in_name3=</span><span class=cF5>ExtDft</span><span class=cF0>(in_name,</span><span class=cF6>&quot;ISO&quot;</span><span class=cF0>);
<a name="l156"></a> in_name2=</span><span class=cF5>FileNameAbs</span><span class=cF0>(in_name3);
<a name="l157"></a> f=</span><span class=cF5>FOpen</span><span class=cF0>(in_name2,</span><span class=cF6>&quot;r&quot;</span><span class=cF0>);
<a name="l158"></a> </span><span class=cF1>if</span><span class=cF0> (!f) </span><span class=cF7>{</span><span class=cF0>
<a name="l159"></a> </span><span class=cF5>Free</span><span class=cF0>(d);
<a name="l160"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l161"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l162"></a> cnt=(</span><span class=cF5>FSize</span><span class=cF7>(</span><span class=cF0>f</span><span class=cF7>)</span><span class=cF0>+</span><span class=cF3>BLK_SIZE</span><span class=cF0>-1)&gt;&gt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l163"></a> </span><span class=cF5>FClose</span><span class=cF0>(f);
<a name="l164"></a> </span><span class=cF1>if</span><span class=cF0> (bd-&gt;type!=</span><span class=cF3>BDT_ATAPI</span><span class=cF0>)
<a name="l165"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'BlkDev'</span><span class=cF0>);
<a name="l166"></a> bd2=</span><span class=cF5>Let2BlkDev</span><span class=cF0>(*in_name2);
<a name="l167"></a> </span><span class=cF1>while</span><span class=cF0> (bd2-&gt;lock_fwding)
<a name="l168"></a> bd2=bd2-&gt;lock_fwding; </span><span class=cF2>//If two blkdevs on same controller, use one lock</span><span class=cF0>
<a name="l169"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>bd2-&gt;type==</span><span class=cF3>BDT_ATA</span><span class=cF0> || bd2-&gt;type==</span><span class=cF3>BDT_ATAPI</span><span class=cF7>)</span><span class=cF0> &amp;&amp;
<a name="l170"></a> bd2-&gt;base0==bd-&gt;base0) </span><span class=cF7>{</span><span class=cF0>
<a name="l171"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Can't burn CD/DVD on same ATA controller as file.\n\n&quot;</span><span class=cF0>);
<a name="l172"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'BlkDev'</span><span class=cF0>);
<a name="l173"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l174"></a>
<a name="l175"></a> bd-&gt;flags|=</span><span class=cF3>BDF_READ_ONLY_OVERRIDE</span><span class=cF0>;
<a name="l176"></a> </span><span class=cFD>BlkDevInit</span><span class=cF0>(bd);
<a name="l177"></a> spc=bd-&gt;blk_size&gt;&gt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l178"></a> </span><span class=cF1>if</span><span class=cF0> (dv-&gt;size&lt;cnt)
<a name="l179"></a> dv-&gt;size=cnt;
<a name="l180"></a>
<a name="l181"></a> d-&gt;filename=in_name2;
<a name="l182"></a> d-&gt;dvd_bd=bd;
<a name="l183"></a> d-&gt;buf0=</span><span class=cF5>MAlloc</span><span class=cF0>(COPY_BUF_BLKS&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l184"></a> d-&gt;buf1=</span><span class=cF5>MAlloc</span><span class=cF0>(COPY_BUF_BLKS&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l185"></a> d-&gt;cnt=cnt;
<a name="l186"></a>
<a name="l187"></a> task=</span><span class=cF5>Spawn</span><span class=cF0>(&amp;</span><span class=cFD>DVDImageWriteTask</span><span class=cF0>,d,</span><span class=cF6>&quot;Write CD/DVD&quot;</span><span class=cF0>);
<a name="l188"></a> </span><span class=cF1>while</span><span class=cF0> (d-&gt;in_buf&lt;=d-&gt;out_buf)
<a name="l189"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l190"></a>
<a name="l191"></a> </span><span class=cF5>BlkDevLock</span><span class=cF0>(bd);
<a name="l192"></a> </span><span class=cFD>ATAPIWaitReady</span><span class=cF0>(bd,0);
<a name="l193"></a>
<a name="l194"></a> </span><span class=cFB>progress1</span><span class=cF0>=0; </span><span class=cFB>progress1_max</span><span class=cF0>=cnt;
<a name="l195"></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;Writing&quot;</span><span class=cF0>);
<a name="l196"></a> </span><span class=cF1>while</span><span class=cF0> (cnt&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l197"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&gt;COPY_BUF_BLKS)
<a name="l198"></a> n=COPY_BUF_BLKS;
<a name="l199"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l200"></a> n=cnt;
<a name="l201"></a> </span><span class=cF1>if</span><span class=cF0> (n&gt;bd-&gt;max_writes)
<a name="l202"></a> n=bd-&gt;max_writes;
<a name="l203"></a> </span><span class=cF1>if</span><span class=cF0> (d-&gt;out_buf&amp;1)
<a name="l204"></a> buf=d-&gt;buf1;
<a name="l205"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l206"></a> buf=d-&gt;buf0;
<a name="l207"></a> </span><span class=cF1>while</span><span class=cF0> (d-&gt;in_buf&lt;=d-&gt;out_buf)
<a name="l208"></a> </span><span class=cF5>Yield</span><span class=cF0>;
<a name="l209"></a> </span><span class=cFD>ATAPIWriteBlks</span><span class=cF0>(bd,buf,blk/spc,</span><span class=cF7>(</span><span class=cF0>n+spc-1</span><span class=cF7>)</span><span class=cF0>/spc);
<a name="l210"></a> d-&gt;out_buf++;
<a name="l211"></a> cnt-=n;
<a name="l212"></a> blk+=n;
<a name="l213"></a> </span><span class=cFB>progress1</span><span class=cF0>+=n;
<a name="l214"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l215"></a> </span><span class=cFD>ATAPISync</span><span class=cF0>(bd);
<a name="l216"></a>
<a name="l217"></a> </span><span class=cFB>progress1</span><span class=cF0>=0; </span><span class=cFB>progress1_max</span><span class=cF0>=2;
<a name="l218"></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;Closing&quot;</span><span class=cF0>);
<a name="l219"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;2;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l220"></a> </span><span class=cFD>ATAPIClose</span><span class=cF0>(bd,0x100,i); </span><span class=cF2>//Close tracks</span><span class=cF0>
<a name="l221"></a> </span><span class=cFB>progress1</span><span class=cF0>++;
<a name="l222"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l223"></a>
<a name="l224"></a> </span><span class=cFD>ATAPISync</span><span class=cF0>(bd);
<a name="l225"></a>
<a name="l226"></a> </span><span class=cFD>ATAPIClose</span><span class=cF0>(bd,0x200); </span><span class=cF2>//close disk</span><span class=cF0>
<a name="l227"></a> </span><span class=cFD>ATAPISync</span><span class=cF0>(bd);
<a name="l228"></a> </span><span class=cF1>if</span><span class=cF0> (media_type==</span><span class=cF3>MT_DVD</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l229"></a> </span><span class=cFD>ATAPIClose</span><span class=cF0>(bd,0x300);
<a name="l230"></a> </span><span class=cFD>ATAPISync</span><span class=cF0>(bd);
<a name="l231"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l232"></a>
<a name="l233"></a> *</span><span class=cFB>progress1_desc</span><span class=cF0>=0;
<a name="l234"></a> </span><span class=cFB>progress1</span><span class=cF0>=</span><span class=cFB>progress1_max</span><span class=cF0>=0;
<a name="l235"></a>
<a name="l236"></a> bd-&gt;flags&amp;=~</span><span class=cF3>BDF_READ_ONLY_OVERRIDE</span><span class=cF0>;
<a name="l237"></a> </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
<a name="l238"></a> </span><span class=cF5>Free</span><span class=cF0>(d-&gt;buf0);
<a name="l239"></a> </span><span class=cF5>Free</span><span class=cF0>(d-&gt;buf1);
<a name="l240"></a> </span><span class=cF5>Free</span><span class=cF0>(in_name2);
<a name="l241"></a> </span><span class=cF5>Free</span><span class=cF0>(in_name3);
<a name="l242"></a> </span><span class=cF5>Free</span><span class=cF0>(d);
<a name="l243"></a>}
</span></pre></body>
</html>