ZealOS/docs/Kernel/BlkDev/DiskCDDVD.CC.html
2021-10-27 03:28:16 -04:00

319 lines
32 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V1.04">
<style type="text/css">
body {background-color:#1f1f1f;}
.cF0{color:#e3e3e3;background-color:#1f1f1f;}
.cF1{color:#4f84a6;background-color:#1f1f1f;}
.cF2{color:#73a255;background-color:#1f1f1f;}
.cF3{color:#297582;background-color:#1f1f1f;}
.cF4{color:#b34f4b;background-color:#1f1f1f;}
.cF5{color:#8a52c3;background-color:#1f1f1f;}
.cF6{color:#b7822f;background-color:#1f1f1f;}
.cF7{color:#444444;background-color:#1f1f1f;}
.cF8{color:#6d6d6d;background-color:#1f1f1f;}
.cF9{color:#94bfde;background-color:#1f1f1f;}
.cFA{color:#a1ce97;background-color:#1f1f1f;}
.cFB{color:#6db4be;background-color:#1f1f1f;}
.cFC{color:#e88e88;background-color:#1f1f1f;}
.cFD{color:#ca94e8;background-color:#1f1f1f;}
.cFE{color:#d4b475;background-color:#1f1f1f;}
.cFF{color:#1f1f1f;background-color:#1f1f1f;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<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>CDrive</span><span class=cF0> *drive, </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 = drive-&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 = </span><span class=cFE>0</span><span class=cF0>;
<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[</span><span class=cFE>8</span><span class=cF0>];
<a name="l9"></a>
<a name="l10"></a> </span><span class=cF1>try</span><span class=cF0>
<a name="l11"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l12"></a> unlock = </span><span class=cF5>DriveLock</span><span class=cF0>(drive);
<a name="l13"></a> drive-&gt;fs_type = </span><span class=cF3>FSt_ISO9660</span><span class=cF0>;
<a name="l14"></a> drive-&gt;spc = spc;
<a name="l15"></a> drive-&gt;data_area = drive-&gt;root_clus = drive-&gt;drv_offset = bd-&gt;drv_offset = drive-&gt;size = </span><span class=cFE>0</span><span class=cF0>;
<a name="l16"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l17"></a> {
<a name="l18"></a> drive-&gt;size = </span><span class=cF5>MaxI64</span><span class=cF0>(drive-&gt;size, </span><span class=cF7>(</span><span class=cF0>i + </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> * spc);
<a name="l19"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(drive, iso, i * spc, spc);
<a name="l20"></a> buf[</span><span class=cFE>0</span><span class=cF0>](</span><span class=cF9>U32</span><span class=cF0>) = iso-&gt;id[</span><span class=cFE>0</span><span class=cF0>](</span><span class=cF9>U32</span><span class=cF0>);
<a name="l21"></a> buf[</span><span class=cFE>4</span><span class=cF0>](</span><span class=cF9>U16</span><span class=cF0>) = iso-&gt;id[</span><span class=cFE>4</span><span class=cF0>](</span><span class=cF1>U8</span><span class=cF0>);
<a name="l22"></a> </span><span class=cF1>switch</span><span class=cF0> (</span><span class=cF5>ListMatch</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>, </span><span class=cF3>LMF_EXACT</span><span class=cF7>)</span><span class=cF0>)
<a name="l23"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l24"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>:
<a name="l25"></a> </span><span class=cF1>switch</span><span class=cF0> (iso-&gt;type)
<a name="l26"></a> {
<a name="l27"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>ISOT_BOOT_RECORD</span><span class=cF0>:
<a name="l28"></a> drv_offset += (</span><span class=cFE>2</span><span class=cF0> * </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="l29"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l30"></a>
<a name="l31"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>ISOT_SUPPLEMENTARY_DESC</span><span class=cF0>:
<a name="l32"></a> de = &amp;iso-&gt;root_dir_record;
<a name="l33"></a> drive-&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="l34"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF0>iso-&gt;publisher_id, </span><span class=cF6>&quot;ZealOS RedSea&quot;</span><span class=cF7>)</span><span class=cF0> ||
<a name="l35"></a> !</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF0>iso-&gt;publisher_id - </span><span class=cFE>4</span><span class=cF0>, </span><span class=cF6>&quot;ZenithOS RedSea&quot;</span><span class=cF7>)</span><span class=cF0> ||
<a name="l36"></a> !</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF0>iso-&gt;publisher_id - </span><span class=cFE>4</span><span class=cF0>, </span><span class=cF6>&quot;TempleOS RedSea&quot;</span><span class=cF7>)</span><span class=cF0>)
<a name="l37"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l38"></a> drive-&gt;fs_type = </span><span class=cF3>FSt_REDSEA</span><span class=cF0>;
<a name="l39"></a> bd-&gt;drv_offset = drive-&gt;drv_offset = </span><span class=cFE>19</span><span class=cF0> &lt;&lt; </span><span class=cFE>2</span><span class=cF0> + drv_offset;
<a name="l40"></a> bd-&gt;max_blk = drive-&gt;size - </span><span class=cFE>1</span><span class=cF0>;
<a name="l41"></a> drive-&gt;size -= bd-&gt;drv_offset;
<a name="l42"></a> </span><span class=cFD>RedSeaInit</span><span class=cF0>(drive);
<a name="l43"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l44"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l45"></a> drive-&gt;root_clus = de-&gt;loc.little;
<a name="l46"></a> res = </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l47"></a> </span><span class=cF1>goto</span><span class=cF0> di_done;
<a name="l48"></a>
<a name="l49"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>ISOT_TERMINATOR</span><span class=cF0>:
<a name="l50"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drive'</span><span class=cF0>);
<a name="l51"></a> }
<a name="l52"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l53"></a>
<a name="l54"></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="l55"></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="l56"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drive'</span><span class=cF0>);
<a name="l57"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l58"></a> i++;
<a name="l59"></a> }
<a name="l60"></a>di_done:
<a name="l61"></a> </span><span class=cF5>Free</span><span class=cF0>(iso);
<a name="l62"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l63"></a> </span><span class=cF5>DriveUnlock</span><span class=cF0>(drive);
<a name="l64"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l65"></a> </span><span class=cF1>catch</span><span class=cF0>
<a name="l66"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l67"></a> drive-&gt;fs_type = </span><span class=cF3>FSt_ISO9660</span><span class=cF0>;
<a name="l68"></a> drive-&gt;spc = spc;
<a name="l69"></a> drive-&gt;drv_offset = bd-&gt;drv_offset = drive-&gt;data_area = drive-&gt;root_clus = </span><span class=cFE>0</span><span class=cF0>;
<a name="l70"></a> </span><span class=cF5>Free</span><span class=cF0>(iso);
<a name="l71"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
<a name="l72"></a> </span><span class=cF5>DriveUnlock</span><span class=cF0>(drive);
<a name="l73"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l74"></a>
<a name="l75"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l76"></a>}
<a name="l77"></a>
<a name="l78"></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_drive_let, </span><span class=cF1>U8</span><span class=cF0> *out_name)
<a name="l79"></a>{</span><span class=cF2>//Read entire CD/DVD image into ISO file.</span><span class=cF0>
<a name="l80"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive = </span><span class=cF5>Letter2Drive</span><span class=cF0>(dvd_drive_let);
<a name="l81"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd = drive-&gt;bd;
<a name="l82"></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>), *out_name2 = </span><span class=cF5>ExtDefault</span><span class=cF0>(out_name, </span><span class=cF6>&quot;ISO&quot;</span><span class=cF0>);
<a name="l83"></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="l84"></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 = </span><span class=cFE>0</span><span class=cF0>, count, retry;
<a name="l85"></a>
<a name="l86"></a> </span><span class=cFD>BlkDevInit</span><span class=cF0>(bd);
<a name="l87"></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="l88"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'BlkDev'</span><span class=cF0>);
<a name="l89"></a> </span><span class=cF1>if</span><span class=cF0> (!out_name)
<a name="l90"></a> out_name = </span><span class=cFB>blkdev</span><span class=cF0>.default_iso_filename;
<a name="l91"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>count = CeilU64(drive-&gt;size, spc);</span><span class=cF0>
<a name="l92"></a> count = bd-&gt;max_blk + </span><span class=cFE>1</span><span class=cF0>;
<a name="l93"></a> </span><span class=cFB>progress1</span><span class=cF0> = </span><span class=cFE>0</span><span class=cF0>;
<a name="l94"></a> </span><span class=cFB>progress1_max</span><span class=cF0> = count;
<a name="l95"></a> </span><span class=cF1>while</span><span class=cF0> (count &gt; </span><span class=cFE>0</span><span class=cF0>)
<a name="l96"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l97"></a> </span><span class=cF1>if</span><span class=cF0> (count &gt; COPY_BUF_BLKS)
<a name="l98"></a> n = COPY_BUF_BLKS;
<a name="l99"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l100"></a> n = count;
<a name="l101"></a> </span><span class=cF1>if</span><span class=cF0> (n &gt; bd-&gt;max_reads)
<a name="l102"></a> n = bd-&gt;max_reads;
<a name="l103"></a>
<a name="l104"></a> retry = </span><span class=cFE>4</span><span class=cF0>;
<a name="l105"></a> </span><span class=cF1>while</span><span class=cF0> (--retry)
<a name="l106"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>AHCIAtapiBlksRead</span><span class=cF7>(</span><span class=cF0>bd, buf, blk / spc, n / spc</span><span class=cF7>)</span><span class=cF0>)
<a name="l107"></a></span><span class=cF2>//n is 0x800 if max_reads.</span><span class=cF0> </span><span class=cF2>Up to 8 additional seconds</span><span class=cF0>
<a name="l108"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l109"></a>
<a name="l110"></a> </span><span class=cF1>if</span><span class=cF0> (!retry)
<a name="l111"></a> </span><span class=cF5>AHCIAtapiBlksRead</span><span class=cF0>(bd, buf, blk / spc, n / spc);
<a name="l112"></a>
<a name="l113"></a> </span><span class=cF5>FBlkWrite</span><span class=cF0>(f, buf, blk, n);
<a name="l114"></a> count -= n;
<a name="l115"></a> blk += n;
<a name="l116"></a> </span><span class=cFB>progress1</span><span class=cF0> += n;
<a name="l117"></a>
<a name="l118"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l119"></a> </span><span class=cFB>progress1</span><span class=cF0> = </span><span class=cFB>progress1_max</span><span class=cF0> = </span><span class=cFE>0</span><span class=cF0>;
<a name="l120"></a> </span><span class=cF5>FClose</span><span class=cF0>(f);
<a name="l121"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l122"></a> </span><span class=cF5>Free</span><span class=cF0>(out_name2);
<a name="l123"></a>}
<a name="l124"></a>
<a name="l125"></a></span><span class=cF1>class</span><span class=cF0> CDualBuf
<a name="l126"></a>{
<a name="l127"></a> </span><span class=cF1>U8</span><span class=cF0> *buf0, *buf1;
<a name="l128"></a> </span><span class=cF9>I64</span><span class=cF0> in_buf, out_buf, count;
<a name="l129"></a> </span><span class=cF1>U8</span><span class=cF0> *filename;
<a name="l130"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *dvd_bd;
<a name="l131"></a>};
<a name="l132"></a>
<a name="l133"></a>#</span><span class=cF1>define</span><span class=cF0> DVD_WRITE_BLKS </span><span class=cFE>0xFFFFF</span><span class=cF0>
<a name="l134"></a></span><span class=cF2>/*</span><span class=cF0>
<a name="l135"></a></span><span class=cF2>U0 DVDImageWriteTask(CDualBuf *d)</span><span class=cF0>
<a name="l136"></a></span><span class=cF2>{</span><span class=cF0>
<a name="l137"></a> </span><span class=cF2>U8</span><span class=cF0> </span><span class=cF2>*buf;</span><span class=cF0>
<a name="l138"></a> </span><span class=cF2>I64</span><span class=cF0> </span><span class=cF2> n, blk = 0, count = d-&gt;count;</span><span class=cF0>
<a name="l139"></a> </span><span class=cF2>CFile</span><span class=cF0> </span><span class=cF2>*f;</span><span class=cF0>
<a name="l140"></a>
<a name="l141"></a> </span><span class=cF2>if (FileAttr(d-&gt;filename) &amp; RS_ATTR_CONTIGUOUS)</span><span class=cF0>
<a name="l142"></a> </span><span class=cF2>f = FOpen(d-&gt;filename, &quot;rc&quot;);</span><span class=cF0>
<a name="l143"></a> </span><span class=cF2>else</span><span class=cF0>
<a name="l144"></a> </span><span class=cF2>f = FOpen(d-&gt;filename, &quot;r&quot;);</span><span class=cF0>
<a name="l145"></a> </span><span class=cF2>while (count &gt; 0)</span><span class=cF0>
<a name="l146"></a> </span><span class=cF2>{</span><span class=cF0>
<a name="l147"></a> </span><span class=cF2>if (count &gt; DVD_WRITE_BLKS)</span><span class=cF0>
<a name="l148"></a> </span><span class=cF2>n = DVD_WRITE_BLKS;</span><span class=cF0>
<a name="l149"></a> </span><span class=cF2>else</span><span class=cF0>
<a name="l150"></a> </span><span class=cF2>n = count;</span><span class=cF0>
<a name="l151"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>if (n &gt; d-&gt;dvd_bd-&gt;max_writes)</span><span class=cF0>
<a name="l152"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>n = d-&gt;dvd_bd-&gt;max_writes;</span><span class=cF0>
<a name="l153"></a> </span><span class=cF2>if (d-&gt;in_buf &amp; 1)</span><span class=cF0>
<a name="l154"></a> </span><span class=cF2>buf = d-&gt;buf1;</span><span class=cF0>
<a name="l155"></a> </span><span class=cF2>else</span><span class=cF0>
<a name="l156"></a> </span><span class=cF2>buf = d-&gt;buf0;</span><span class=cF0>
<a name="l157"></a> </span><span class=cF2>while (d-&gt;in_buf&gt;d-&gt;out_buf + 1)</span><span class=cF0>
<a name="l158"></a> </span><span class=cF2>Yield;</span><span class=cF0>
<a name="l159"></a> </span><span class=cF2>FBlkRead(f, buf, blk, n);</span><span class=cF0>
<a name="l160"></a> </span><span class=cF2>d-&gt;in_buf++;</span><span class=cF0>
<a name="l161"></a> </span><span class=cF2>count -= n;</span><span class=cF0>
<a name="l162"></a> </span><span class=cF2>blk += n;</span><span class=cF0>
<a name="l163"></a> </span><span class=cF2>}</span><span class=cF0>
<a name="l164"></a> </span><span class=cF2>FClose(f);</span><span class=cF0>
<a name="l165"></a></span><span class=cF2>}</span><span class=cF0>
<a name="l166"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l167"></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_drive_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="l168"></a>{</span><span class=cF2>//Write CD/DVD ISO file to disk.</span><span class=cF0>
<a name="l169"></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="l170"></a> </span><span class=cF1>U8</span><span class=cF0> *buf, *in_name2, *in_name3;
<a name="l171"></a> </span><span class=cF9>I64</span><span class=cF0> </span><span class=cF2>/*n,*/</span><span class=cF0> spc, blk = </span><span class=cFE>0</span><span class=cF0>, count;
<a name="l172"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive = </span><span class=cF5>Letter2Drive</span><span class=cF0>(dvd_drive_let);
<a name="l173"></a> </span><span class=cF9>CBlkDev</span><span class=cF0> *bd = drive-&gt;bd, *bd2;
<a name="l174"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>CTask</span><span class=cF0> </span><span class=cF2>*task;</span><span class=cF0>
<a name="l175"></a> </span><span class=cF9>CFile</span><span class=cF0> *f;
<a name="l176"></a>
<a name="l177"></a> </span><span class=cF1>if</span><span class=cF0> (!in_name)
<a name="l178"></a> in_name = </span><span class=cFB>blkdev</span><span class=cF0>.default_iso_filename;
<a name="l179"></a> in_name3 = </span><span class=cF5>ExtDefault</span><span class=cF0>(in_name, </span><span class=cF6>&quot;ISO&quot;</span><span class=cF0>);
<a name="l180"></a> in_name2 = </span><span class=cF5>FileNameAbs</span><span class=cF0>(in_name3);
<a name="l181"></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="l182"></a> </span><span class=cF1>if</span><span class=cF0> (!f)
<a name="l183"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l184"></a> </span><span class=cF5>Free</span><span class=cF0>(d);
<a name="l185"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l186"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l187"></a> count = (</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> - </span><span class=cFE>1</span><span class=cF0>) &gt;&gt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l188"></a> </span><span class=cF5>FClose</span><span class=cF0>(f);
<a name="l189"></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="l190"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'BlkDev'</span><span class=cF0>);
<a name="l191"></a> bd2 = </span><span class=cF5>Letter2BlkDev</span><span class=cF0>(*in_name2);
<a name="l192"></a> </span><span class=cF1>while</span><span class=cF0> (bd2-&gt;lock_fwding)
<a name="l193"></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="l194"></a> </span><span class=cF1>if</span><span class=cF0> (bd2-&gt;port_num == bd-&gt;port_num)
<a name="l195"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l196"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;Can't burn CD/DVD on same SATA port as file.\n\n&quot;</span><span class=cF0>);
<a name="l197"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'BlkDev'</span><span class=cF0>);
<a name="l198"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l199"></a>
<a name="l200"></a> bd-&gt;flags |= </span><span class=cF3>BDF_READ_ONLY_OVERRIDE</span><span class=cF0>;
<a name="l201"></a> </span><span class=cFD>BlkDevInit</span><span class=cF0>(bd);
<a name="l202"></a> spc = bd-&gt;blk_size &gt;&gt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l203"></a> </span><span class=cF1>if</span><span class=cF0> (drive-&gt;size &lt; count)
<a name="l204"></a> drive-&gt;size = count;
<a name="l205"></a></span><span class=cF2>/*</span><span class=cF0>
<a name="l206"></a> </span><span class=cF2>d-&gt;filename = in_name2;</span><span class=cF0>
<a name="l207"></a> </span><span class=cF2>d-&gt;dvd_bd = bd;</span><span class=cF0>
<a name="l208"></a> </span><span class=cF2>d-&gt;buf0 = MAlloc(DVD_WRITE_BLKS &lt;&lt; BLK_SIZE_BITS);</span><span class=cF0>
<a name="l209"></a> </span><span class=cF2>d-&gt;buf1 = MAlloc(DVD_WRITE_BLKS &lt;&lt; BLK_SIZE_BITS);</span><span class=cF0>
<a name="l210"></a> </span><span class=cF2>d-&gt;count = count;</span><span class=cF0>
<a name="l211"></a>
<a name="l212"></a>
<a name="l213"></a> </span><span class=cF2>task = Spawn(&amp;DVDImageWriteTask, d, &quot;Write CD/DVD&quot;);</span><span class=cF0>
<a name="l214"></a> </span><span class=cF2>while (d-&gt;in_buf &lt;= d-&gt;out_buf)</span><span class=cF0>
<a name="l215"></a> </span><span class=cF2>Yield;</span><span class=cF0>
<a name="l216"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l217"></a>
<a name="l218"></a> buf = </span><span class=cF5>MAlloc</span><span class=cF0>(DVD_WRITE_BLKS &lt;&lt; </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
<a name="l219"></a> </span><span class=cF5>FBlkRead</span><span class=cF0>(f, buf, blk, count);
<a name="l220"></a>
<a name="l221"></a> </span><span class=cFB>progress1</span><span class=cF0> = </span><span class=cFE>0</span><span class=cF0>;
<a name="l222"></a> </span><span class=cFB>progress1_max</span><span class=cF0> = </span><span class=cFE>1</span><span class=cF0>;
<a name="l223"></a> </span><span class=cF5>StrCopy</span><span class=cF0>(</span><span class=cFB>progress1_desc</span><span class=cF0>, </span><span class=cF6>&quot;Blanking&quot;</span><span class=cF0>);
<a name="l224"></a>
<a name="l225"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>BlkDevLock(bd);</span><span class=cF0>
<a name="l226"></a> </span><span class=cFD>AHCIPortWait</span><span class=cF0>(bd-&gt;port_num, </span><span class=cF5>tS</span><span class=cF0> + </span><span class=cFE>2</span><span class=cF0>);
<a name="l227"></a> </span><span class=cF5>AHCIAtapiBlank</span><span class=cF0>(bd);
<a name="l228"></a> bd-&gt;flags |= </span><span class=cF3>BDF_LAST_WAS_WRITE</span><span class=cF0>;
<a name="l229"></a>
<a name="l230"></a> </span><span class=cFD>AHCIAtapiModeWriteSelect</span><span class=cF0>(bd);
<a name="l231"></a>
<a name="l232"></a> </span><span class=cF5>StrCopy</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="l233"></a> </span><span class=cFD>AHCIAtapiBlksWrite</span><span class=cF0>(bd, buf, blk / spc, </span><span class=cF7>(</span><span class=cF0>count + spc - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> / spc, </span><span class=cF3>FALSE</span><span class=cF0>);
<a name="l234"></a> </span><span class=cFB>progress1</span><span class=cF0>++;
<a name="l235"></a>
<a name="l236"></a></span><span class=cF2>/*</span><span class=cF0>
<a name="l237"></a> </span><span class=cF2>while (count &gt; 0)</span><span class=cF0>
<a name="l238"></a> </span><span class=cF2>{</span><span class=cF0>
<a name="l239"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>if (count &gt; DVD_WRITE_BLKS)</span><span class=cF0>
<a name="l240"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>n = DVD_WRITE_BLKS;</span><span class=cF0>
<a name="l241"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>else</span><span class=cF0>
<a name="l242"></a> </span><span class=cF2>n = count;</span><span class=cF0>
<a name="l243"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>if (n &gt; bd-&gt;max_writes)</span><span class=cF0>
<a name="l244"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>n = bd-&gt;max_writes;</span><span class=cF0>
<a name="l245"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>if (d-&gt;out_buf &amp; 1)</span><span class=cF0>
<a name="l246"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>buf = d-&gt;buf1;</span><span class=cF0>
<a name="l247"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>else</span><span class=cF0>
<a name="l248"></a> </span><span class=cF2>buf = d-&gt;buf0;</span><span class=cF0>
<a name="l249"></a> </span><span class=cF2>while (d-&gt;in_buf &lt;= d-&gt;out_buf)</span><span class=cF0>
<a name="l250"></a> </span><span class=cF2>Yield;</span><span class=cF0>
<a name="l251"></a> </span><span class=cF2>&quot;AHCIAtapiBlksWrite(bd, 0x%0X, 0x%0X, %d, FALSE);\n&quot;, buf, blk / spc, (n + spc - 1) / spc;</span><span class=cF0>
<a name="l252"></a> </span><span class=cF2>AHCIAtapiBlksWrite(bd, buf, blk / spc, (n + spc - 1) / spc, FALSE);</span><span class=cF0>
<a name="l253"></a> </span><span class=cF2>d-&gt;out_buf++;</span><span class=cF0>
<a name="l254"></a> </span><span class=cF2>count -= n;</span><span class=cF0>
<a name="l255"></a> </span><span class=cF2>blk += n;</span><span class=cF0>
<a name="l256"></a> </span><span class=cF2>progress1 += n;</span><span class=cF0>
<a name="l257"></a> </span><span class=cF2>}</span><span class=cF0>
<a name="l258"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l259"></a> </span><span class=cFD>AHCIAtapiSync</span><span class=cF0>(bd);
<a name="l260"></a>
<a name="l261"></a> </span><span class=cFB>progress1</span><span class=cF0> = </span><span class=cFE>0</span><span class=cF0>;
<a name="l262"></a> </span><span class=cFB>progress1_max</span><span class=cF0> = </span><span class=cFE>2</span><span class=cF0>;
<a name="l263"></a> </span><span class=cF5>StrCopy</span><span class=cF0>(</span><span class=cFB>progress1_desc</span><span class=cF0>, </span><span class=cF6>&quot;Closing track&quot;</span><span class=cF0>);
<a name="l264"></a> </span><span class=cFD>AHCIAtapiClose</span><span class=cF0>(bd, </span><span class=cFE>0x100</span><span class=cF0>, </span><span class=cFE>0xFF</span><span class=cF0>); </span><span class=cF2>//Close track</span><span class=cF0>
<a name="l265"></a> </span><span class=cFB>progress1</span><span class=cF0>++;
<a name="l266"></a>
<a name="l267"></a> </span><span class=cFD>AHCIAtapiSync</span><span class=cF0>(bd);
<a name="l268"></a>
<a name="l269"></a> </span><span class=cF5>StrCopy</span><span class=cF0>(</span><span class=cFB>progress1_desc</span><span class=cF0>, </span><span class=cF6>&quot;Closing session&quot;</span><span class=cF0>);
<a name="l270"></a> </span><span class=cFD>AHCIAtapiClose</span><span class=cF0>(bd, </span><span class=cFE>0x200</span><span class=cF0>); </span><span class=cF2>//close disk</span><span class=cF0>
<a name="l271"></a> </span><span class=cFB>progress1</span><span class=cF0>++;
<a name="l272"></a>
<a name="l273"></a> </span><span class=cFD>AHCIAtapiSync</span><span class=cF0>(bd);
<a name="l274"></a> </span><span class=cF1>if</span><span class=cF0> (media_type == </span><span class=cF3>MT_DVD</span><span class=cF0>)
<a name="l275"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l276"></a> </span><span class=cFD>AHCIAtapiClose</span><span class=cF0>(bd, </span><span class=cFE>0x300</span><span class=cF0>);
<a name="l277"></a> </span><span class=cFD>AHCIAtapiSync</span><span class=cF0>(bd);
<a name="l278"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l279"></a>
<a name="l280"></a> *</span><span class=cFB>progress1_desc</span><span class=cF0> = </span><span class=cFE>0</span><span class=cF0>;
<a name="l281"></a> </span><span class=cFB>progress1</span><span class=cF0> = </span><span class=cFB>progress1_max</span><span class=cF0> = </span><span class=cFE>0</span><span class=cF0>;
<a name="l282"></a>
<a name="l283"></a> bd-&gt;flags &amp;= ~</span><span class=cF3>BDF_READ_ONLY_OVERRIDE</span><span class=cF0>;
<a name="l284"></a> </span><span class=cF5>BlkDevUnlock</span><span class=cF0>(bd);
<a name="l285"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>Free(d-&gt;buf0);</span><span class=cF0>
<a name="l286"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>Free(d-&gt;buf1);</span><span class=cF0>
<a name="l287"></a> </span><span class=cF5>Free</span><span class=cF0>(in_name2);
<a name="l288"></a> </span><span class=cF5>Free</span><span class=cF0>(in_name3);
<a name="l289"></a> </span><span class=cF5>Free</span><span class=cF0>(d);
<a name="l290"></a>}
</span></pre></body>
</html>