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

135 lines
12 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>CopySingleZ</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *f1,</span><span class=cF1>U8</span><span class=cF0> *f2) </span><span class=cF2>//Just one file</span><span class=cF0>
<a name="l2"></a>{
<a name="l3"></a> </span><span class=cF1>U8</span><span class=cF0> *file_buf=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l4"></a> </span><span class=cF9>I64</span><span class=cF0> size,attr=0,c;
<a name="l5"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> de;
<a name="l6"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>FileFind</span><span class=cF7>(</span><span class=cF0>f1,&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="l7"></a> </span><span class=cF5>Free</span><span class=cF0>(de.full_name);
<a name="l8"></a> file_buf=</span><span class=cF5>FileRead</span><span class=cF0>(f1,&amp;size,&amp;attr);
<a name="l9"></a> attr=</span><span class=cF5>FileAttr</span><span class=cF0>(f2,attr);
<a name="l10"></a> </span><span class=cF1>if</span><span class=cF0> (file_buf) {
<a name="l11"></a> </span><span class=cF6>&quot;Copying %s to %s\n&quot;</span><span class=cF0>,f1,f2;
<a name="l12"></a> c=</span><span class=cF5>FileWrite</span><span class=cF0>(f2,file_buf,size,de.datetime,attr);
<a name="l13"></a> </span><span class=cF5>Free</span><span class=cF0>(file_buf);
<a name="l14"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF5>ToBool</span><span class=cF0>(c);
<a name="l15"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l16"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;File not found: \&quot;%s\&quot;.\n&quot;</span><span class=cF0>,f1);
<a name="l17"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l18"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;File not found: \&quot;%s\&quot;.\n&quot;</span><span class=cF0>,f1);
<a name="l19"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l20"></a>}
<a name="l21"></a>
<a name="l22"></a>#</span><span class=cF1>define</span><span class=cF0> COPY_BUF_BLKS 0x80
<a name="l23"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>CopySingle</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *f1,</span><span class=cF1>U8</span><span class=cF0> *f2) </span><span class=cF2>//Just one file</span><span class=cF0>
<a name="l24"></a>{
<a name="l25"></a> </span><span class=cF1>U8</span><span class=cF0> *absf1=</span><span class=cF5>FileNameAbs</span><span class=cF0>(f1),*absf2=</span><span class=cF5>FileNameAbs</span><span class=cF0>(f2),*buf;
<a name="l26"></a> </span><span class=cF9>I64</span><span class=cF0> cnt,n,size,attr1=</span><span class=cF5>FileAttr</span><span class=cF0>(f1),attr2=</span><span class=cF5>FileAttr</span><span class=cF0>(f2),i,j;
<a name="l27"></a> </span><span class=cF9>CFile</span><span class=cF0> *in_file=</span><span class=cF3>NULL</span><span class=cF0>,*out_file=</span><span class=cF3>NULL</span><span class=cF0>;
<a name="l28"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrCmp</span><span class=cF7>(</span><span class=cF0>absf1,absf2</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF2>//onto self?</span><span class=cF0>
<a name="l29"></a> </span><span class=cF5>Free</span><span class=cF0>(absf1);
<a name="l30"></a> </span><span class=cF5>Free</span><span class=cF0>(absf2);
<a name="l31"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l32"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l33"></a> </span><span class=cF5>Free</span><span class=cF0>(absf1);
<a name="l34"></a> </span><span class=cF5>Free</span><span class=cF0>(absf2);
<a name="l35"></a> </span><span class=cF1>if</span><span class=cF0> (attr1!=attr2)
<a name="l36"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFD>CopySingleZ</span><span class=cF0>(f1,f2);
<a name="l37"></a> 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="l38"></a> </span><span class=cF1>if</span><span class=cF0> (attr1 &amp; </span><span class=cF3>RS_ATTR_CONTIGUOUS</span><span class=cF0>)
<a name="l39"></a> in_file=</span><span class=cF5>FOpen</span><span class=cF0>(f1,</span><span class=cF6>&quot;rc&quot;</span><span class=cF0>);
<a name="l40"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l41"></a> in_file=</span><span class=cF5>FOpen</span><span class=cF0>(f1,</span><span class=cF6>&quot;r&quot;</span><span class=cF0>);
<a name="l42"></a> </span><span class=cF1>if</span><span class=cF0> (in_file) </span><span class=cF7>{</span><span class=cF0>
<a name="l43"></a> size=</span><span class=cF5>FSize</span><span class=cF0>(in_file);
<a name="l44"></a> cnt=(size+</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="l45"></a> </span><span class=cF1>if</span><span class=cF0> (attr2 &amp; </span><span class=cF3>RS_ATTR_CONTIGUOUS</span><span class=cF0>)
<a name="l46"></a> out_file=</span><span class=cF5>FOpen</span><span class=cF0>(f2,</span><span class=cF6>&quot;wc&quot;</span><span class=cF0>,cnt);
<a name="l47"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l48"></a> out_file=</span><span class=cF5>FOpen</span><span class=cF0>(f2,</span><span class=cF6>&quot;w&quot;</span><span class=cF0>,cnt);
<a name="l49"></a> </span><span class=cF1>if</span><span class=cF0> (out_file) {
<a name="l50"></a> </span><span class=cF6>&quot;Copying %s to %s\n&quot;</span><span class=cF0>,f1,f2;
<a name="l51"></a> j=size;
<a name="l52"></a> </span><span class=cF1>while</span><span class=cF0> (cnt&gt;0) </span><span class=cF7>{</span><span class=cF0>
<a name="l53"></a> </span><span class=cF1>if</span><span class=cF0> (cnt&gt;COPY_BUF_BLKS) {
<a name="l54"></a> n=COPY_BUF_BLKS;
<a name="l55"></a> i=n&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l56"></a> } </span><span class=cF1>else</span><span class=cF0> {
<a name="l57"></a> n=cnt;
<a name="l58"></a> i=j;
<a name="l59"></a> }
<a name="l60"></a> </span><span class=cF5>FBlkRead</span><span class=cF0>(in_file, buf,</span><span class=cF3>FFB_NEXT_BLK</span><span class=cF0>,n);
<a name="l61"></a> </span><span class=cF5>FBlkWrite</span><span class=cF0>(out_file,buf,</span><span class=cF3>FFB_NEXT_BLK</span><span class=cF0>,n);
<a name="l62"></a> cnt-=n;
<a name="l63"></a> j-=n&lt;&lt;</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
<a name="l64"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l65"></a> out_file-&gt;flags|=</span><span class=cF3>FF_USE_OLD_DATETIME</span><span class=cF0>;
<a name="l66"></a> out_file-&gt;de.datetime=in_file-&gt;de.datetime;
<a name="l67"></a> out_file-&gt;de.size=size;
<a name="l68"></a> out_file-&gt;de.attr=</span><span class=cF5>FileAttr</span><span class=cF0>(f2,in_file-&gt;de.attr);
<a name="l69"></a> </span><span class=cF5>FClose</span><span class=cF0>(out_file);
<a name="l70"></a> </span><span class=cF5>FClose</span><span class=cF0>(in_file);
<a name="l71"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l72"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l73"></a> } </span><span class=cF1>else</span><span class=cF0>
<a name="l74"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;File not found: \&quot;%s\&quot;.\n&quot;</span><span class=cF0>,f2);
<a name="l75"></a> </span><span class=cF5>FClose</span><span class=cF0>(in_file);
<a name="l76"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l77"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>&quot;File not found: \&quot;%s\&quot;.\n&quot;</span><span class=cF0>,f1);
<a name="l78"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
<a name="l79"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l80"></a>}
<a name="l81"></a>
<a name="l82"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>Del</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *files_find_mask,</span><span class=cF1>Bool</span><span class=cF0> make_mask=</span><span class=cF3>FALSE</span><span class=cF0>,
<a name="l83"></a> </span><span class=cF1>Bool</span><span class=cF0> del_dir=</span><span class=cF3>FALSE</span><span class=cF0>,</span><span class=cF1>Bool</span><span class=cF0> print_msg=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l84"></a>{</span><span class=cF2>//Delete files.</span><span class=cF0>
<a name="l85"></a> </span><span class=cF9>I64</span><span class=cF0> res=0;
<a name="l86"></a> </span><span class=cF9>CDirContext</span><span class=cF0> *dirc;
<a name="l87"></a> </span><span class=cF1>if</span><span class=cF0> (dirc=</span><span class=cF5>DirContextNew</span><span class=cF7>(</span><span class=cF0>files_find_mask,make_mask</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l88"></a> </span><span class=cF1>switch</span><span class=cF0> (dirc-&gt;dv-&gt;fs_type) {
<a name="l89"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l90"></a> res=</span><span class=cFD>RedSeaFilesDel</span><span class=cF0>(dirc-&gt;dv,</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir,dirc-&gt;mask,
<a name="l91"></a> 0,del_dir,print_msg);
<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>FSt_FAT32</span><span class=cF0>:
<a name="l94"></a> res=</span><span class=cFD>FAT32FilesDel</span><span class=cF0>(dirc-&gt;dv,</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir,dirc-&gt;mask,
<a name="l95"></a> 0,del_dir,print_msg);
<a name="l96"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l97"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l98"></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="l99"></a> }
<a name="l100"></a> </span><span class=cF5>DirContextDel</span><span class=cF0>(dirc);
<a name="l101"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l102"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l103"></a>}
</span></pre></body>
</html>