ZealOS/docs/Kernel/BlkDev/DiskFind.CC.html
2021-09-21 23:45:45 -04:00

177 lines
19 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.01">
<style type="text/css">
body {background-color:#fef1f0;}
.cF0{color:#000000;background-color:#fef1f0;}
.cF1{color:#0148a4;background-color:#fef1f0;}
.cF2{color:#3b7901;background-color:#fef1f0;}
.cF3{color:#057c7e;background-color:#fef1f0;}
.cF4{color:#bb2020;background-color:#fef1f0;}
.cF5{color:#9e42ae;background-color:#fef1f0;}
.cF6{color:#b57901;background-color:#fef1f0;}
.cF7{color:#b2b6af;background-color:#fef1f0;}
.cF8{color:#555753;background-color:#fef1f0;}
.cF9{color:#678fbb;background-color:#fef1f0;}
.cFA{color:#82bc49;background-color:#fef1f0;}
.cFB{color:#0097a2;background-color:#fef1f0;}
.cFC{color:#e26a6a;background-color:#fef1f0;}
.cFD{color:#c671bc;background-color:#fef1f0;}
.cFE{color:#c7ab00;background-color:#fef1f0;}
.cFF{color:#fef1f0;background-color:#fef1f0;}
</style>
</head>
<body>
<pre style="font-family:monospace;font-size:12pt">
<a name="l1"></a><span class=cF9>CDirEntry</span><span class=cF0> *</span><span class=cFD>FilesFind2</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *files_find_mask, </span><span class=cF9>I64</span><span class=cF0> fuf_flags)
<a name="l2"></a>{
<a name="l3"></a> </span><span class=cF9>CDrive</span><span class=cF0> *drive = </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv;
<a name="l4"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *res = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l5"></a>
<a name="l6"></a> </span><span class=cF5>DriveCheck</span><span class=cF0>(drive);
<a name="l7"></a> </span><span class=cF1>switch</span><span class=cF0> (drive-&gt;fs_type)
<a name="l8"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l9"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l10"></a> res = </span><span class=cFD>RedSeaFilesFind</span><span class=cF0>(files_find_mask, fuf_flags);
<a name="l11"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l12"></a>
<a name="l13"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l14"></a> res = </span><span class=cFD>FAT32FilesFind</span><span class=cF0>(files_find_mask, fuf_flags);
<a name="l15"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l16"></a>
<a name="l17"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l18"></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="l19"></a> res = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l20"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l21"></a> </span><span class=cF1>if</span><span class=cF0> (res)
<a name="l22"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l23"></a> </span><span class=cFD>DirFilesSort</span><span class=cF0>(&amp;res, SK_NAME);
<a name="l24"></a> </span><span class=cF1>if</span><span class=cF0> (fuf_flags &amp; </span><span class=cF7>(</span><span class=cF3>FUF_FLATTEN_TREE</span><span class=cF0> | </span><span class=cF3>FUF_JUST_FILES</span><span class=cF7>)</span><span class=cF0>)
<a name="l25"></a> </span><span class=cFD>DirFilesFlatten</span><span class=cF0>(res, &amp;res, fuf_flags);
<a name="l26"></a> </span><span class=cF1>if</span><span class=cF0> (fuf_flags &amp; </span><span class=cF3>FUF_CLUS_ORDER</span><span class=cF0>)
<a name="l27"></a> </span><span class=cFD>DirFilesSort</span><span class=cF0>(&amp;res, SK_CLUS);
<a name="l28"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l29"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l30"></a>}
<a name="l31"></a>
<a name="l32"></a></span><span class=cF9>CDirEntry</span><span class=cF0> *</span><span class=cF5>FilesFind</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *files_find_mask, </span><span class=cF9>I64</span><span class=cF0> fuf_flags=</span><span class=cFE>0</span><span class=cF0>)
<a name="l33"></a>{</span><span class=cF2>/* See </span><a href="https://zeal-operating-system.github.io/ZealOS/Doc/FileUtils.DD.html#l1"><span class=cF4>::/Doc/FileUtils.DD</span></a><span class=cF2>.</span><span class=cF0>
<a name="l34"></a>
<a name="l35"></a></span><span class=cF2>Find files and make a directory tree in memory.</span><span class=cF0>
<a name="l36"></a>
<a name="l37"></a></span><span class=cF2>When done, you free with </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/BlkDev/DiskDirA.CC.html#l17"><span class=cF4>DirEntryDel</span></a><span class=cF2>(), </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/BlkDev/DiskDirA.CC.html#l27"><span class=cF4>DirEntryDel2</span></a><span class=cF2>(), </span><span class=cF4>
<a name="l38"></a></span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/BlkDev/DiskDirA.CC.html#l38"><span class=cF4>DirTreeDel</span></a><span class=cF2>() or </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/BlkDev/DiskDirA.CC.html#l53"><span class=cF4>DirTreeDel2</span></a><span class=cF2>().</span><span class=cF0>
<a name="l39"></a>
<a name="l40"></a></span><span class=cF2>*/</span><span class=cF0>
<a name="l41"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *res;
<a name="l42"></a> </span><span class=cF9>CDirContext</span><span class=cF0> *dirc;
<a name="l43"></a>
<a name="l44"></a> </span><span class=cF1>if</span><span class=cF0> (fuf_flags &amp; ~</span><span class=cF3>FUG_FILES_FIND</span><span class=cF0>)
<a name="l45"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'FUF'</span><span class=cF0>);
<a name="l46"></a> </span><span class=cF1>if</span><span class=cF0> (fuf_flags &amp; </span><span class=cF3>FUF_SINGLE</span><span class=cF0>)
<a name="l47"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l48"></a> res = </span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDirEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l49"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>FileFind</span><span class=cF7>(</span><span class=cF0>files_find_mask, res</span><span class=cF7>)</span><span class=cF0>)
<a name="l50"></a> {
<a name="l51"></a> </span><span class=cF5>Free</span><span class=cF0>(res);
<a name="l52"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l53"></a> }
<a name="l54"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l55"></a> </span><span class=cF1>else</span><span class=cF0> </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, </span><span class=cF3>TRUE</span><span class=cF7>)</span><span class=cF0>)
<a name="l56"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l57"></a> res = </span><span class=cFD>FilesFind2</span><span class=cF0>(dirc-&gt;mask, fuf_flags);
<a name="l58"></a> </span><span class=cF5>DirContextDel</span><span class=cF0>(dirc);
<a name="l59"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l60"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l61"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</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>Bool</span><span class=cF0> </span><span class=cF5>FileFind</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *filename, </span><span class=cF9>CDirEntry</span><span class=cF0> *_de=</span><span class=cF3>NULL</span><span class=cF0>, </span><span class=cF9>I64</span><span class=cF0> fuf_flags=</span><span class=cFE>0</span><span class=cF0>)
<a name="l66"></a>{</span><span class=cF2>//</span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l3256"><span class=cF4>FUF_JUST_DIRS</span></a><span class=cF2>, </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l3257"><span class=cF4>FUF_JUST_FILES</span></a><span class=cF2>, </span><a href="https://zeal-operating-system.github.io/ZealOS/Kernel/KernelA.HH.html#l3265"><span class=cF4>FUF_SCAN_PARENTS</span></a><span class=cF0>
<a name="l67"></a></span><span class=cF2>//If you pass _de, you must Free(_de-&gt;full_name);</span><span class=cF0>
<a name="l68"></a> </span><span class=cF9>I64</span><span class=cF0> cur_dir_clus;
<a name="l69"></a> </span><span class=cF1>U8</span><span class=cF0> *full_name = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l70"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> de;
<a name="l71"></a> </span><span class=cF9>CDirContext</span><span class=cF0> *dirc;
<a name="l72"></a> </span><span class=cF1>Bool</span><span class=cF0> res = </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l73"></a>
<a name="l74"></a> </span><span class=cF1>if</span><span class=cF0> (fuf_flags &amp; ~</span><span class=cF3>FUG_FILE_FIND</span><span class=cF0>)
<a name="l75"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'FUF'</span><span class=cF0>);
<a name="l76"></a> </span><span class=cF1>if</span><span class=cF0> (!filename || *filename &amp;&amp; filename[</span><span class=cFE>1</span><span class=cF0>] == </span><span class=cF6>':'</span><span class=cF0> &amp;&amp; !</span><span class=cF5>Letter2Drive</span><span class=cF7>(</span><span class=cF0>*filename, </span><span class=cF3>FALSE</span><span class=cF7>)</span><span class=cF0>)
<a name="l77"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l78"></a>
<a name="l79"></a> </span><span class=cF1>if</span><span class=cF0> (dirc = </span><span class=cF5>DirContextNew</span><span class=cF7>(</span><span class=cF0>filename</span><span class=cF7>)</span><span class=cF0>)
<a name="l80"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l81"></a> cur_dir_clus = </span><span class=cF5>Name2DirClus</span><span class=cF0>(dirc-&gt;drive, </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir);
<a name="l82"></a> </span><span class=cF1>switch</span><span class=cF0> (dirc-&gt;drive-&gt;fs_type)
<a name="l83"></a> {
<a name="l84"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l85"></a> res = </span><span class=cFD>RedSeaFileFind</span><span class=cF0>(dirc-&gt;drive, cur_dir_clus, dirc-&gt;mask, &amp;de, fuf_flags);
<a name="l86"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l87"></a>
<a name="l88"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l89"></a> res = </span><span class=cFD>FAT32FileFind</span><span class=cF0>(dirc-&gt;drive, cur_dir_clus, dirc-&gt;mask, &amp;de, fuf_flags);
<a name="l90"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l91"></a>
<a name="l92"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l93"></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="l94"></a> }
<a name="l95"></a> </span><span class=cF1>if</span><span class=cF0> (res &amp;&amp; _de)
<a name="l96"></a> {
<a name="l97"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir, </span><span class=cF6>&quot;/&quot;</span><span class=cF7>)</span><span class=cF0>)
<a name="l98"></a> full_name = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>&quot;%C:%s/%s&quot;</span><span class=cF0>, </span><span class=cF5>Drive2Letter</span><span class=cF7>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv</span><span class=cF7>)</span><span class=cF0>, </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir, de.name);
<a name="l99"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l100"></a> full_name = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>&quot;%C:/%s&quot;</span><span class=cF0>, </span><span class=cF5>Drive2Letter</span><span class=cF7>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv</span><span class=cF7>)</span><span class=cF0>, de.name);
<a name="l101"></a> }
<a name="l102"></a> </span><span class=cF5>DirContextDel</span><span class=cF0>(dirc);
<a name="l103"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l104"></a> </span><span class=cF1>if</span><span class=cF0> (!res &amp;&amp; fuf_flags &amp; </span><span class=cF3>FUF_SCAN_PARENTS</span><span class=cF0>)
<a name="l105"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l106"></a> </span><span class=cF1>if</span><span class=cF0> (dirc = </span><span class=cF5>DirContextNew</span><span class=cF7>(</span><span class=cF0>filename</span><span class=cF7>)</span><span class=cF0>)
<a name="l107"></a> {
<a name="l108"></a> cur_dir_clus = </span><span class=cF5>Name2DirClus</span><span class=cF0>(dirc-&gt;drive, </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir);
<a name="l109"></a> </span><span class=cF1>while</span><span class=cF0> (!res &amp;&amp; </span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir, </span><span class=cF6>&quot;/&quot;</span><span class=cF7>)</span><span class=cF0>)
<a name="l110"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l111"></a> </span><span class=cF5>Cd</span><span class=cF0>(</span><span class=cF6>&quot;..&quot;</span><span class=cF0>);
<a name="l112"></a> cur_dir_clus = </span><span class=cF5>Name2DirClus</span><span class=cF0>(dirc-&gt;drive, </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir);
<a name="l113"></a> </span><span class=cF1>switch</span><span class=cF0> (dirc-&gt;drive-&gt;fs_type)
<a name="l114"></a> {
<a name="l115"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_REDSEA</span><span class=cF0>:
<a name="l116"></a> res = </span><span class=cFD>RedSeaFileFind</span><span class=cF0>(dirc-&gt;drive, cur_dir_clus, dirc-&gt;mask, &amp;de, fuf_flags);
<a name="l117"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l118"></a>
<a name="l119"></a> </span><span class=cF1>case</span><span class=cF0> </span><span class=cF3>FSt_FAT32</span><span class=cF0>:
<a name="l120"></a> res = </span><span class=cFD>FAT32FileFind</span><span class=cF0>(dirc-&gt;drive, cur_dir_clus, dirc-&gt;mask, &amp;de, fuf_flags);
<a name="l121"></a> </span><span class=cF1>break</span><span class=cF0>;
<a name="l122"></a>
<a name="l123"></a> </span><span class=cF1>default</span><span class=cF0>:
<a name="l124"></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="l125"></a> }
<a name="l126"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l127"></a> </span><span class=cF1>if</span><span class=cF0> (res &amp;&amp; _de)
<a name="l128"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l129"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrCompare</span><span class=cF7>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir, </span><span class=cF6>&quot;/&quot;</span><span class=cF7>)</span><span class=cF0>)
<a name="l130"></a> full_name = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>&quot;%C:%s/%s&quot;</span><span class=cF0>, </span><span class=cF5>Drive2Letter</span><span class=cF7>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv</span><span class=cF7>)</span><span class=cF0>, </span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dir, de.name);
<a name="l131"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l132"></a> full_name = </span><span class=cF5>MStrPrint</span><span class=cF0>(</span><span class=cF6>&quot;%C:/%s&quot;</span><span class=cF0>, </span><span class=cF5>Drive2Letter</span><span class=cF7>(</span><span class=cF5>Fs</span><span class=cF0>-&gt;cur_dv</span><span class=cF7>)</span><span class=cF0>, de.name);
<a name="l133"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l134"></a> </span><span class=cF5>DirContextDel</span><span class=cF0>(dirc);
<a name="l135"></a> }
<a name="l136"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l137"></a> </span><span class=cF1>if</span><span class=cF0> (_de)
<a name="l138"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l139"></a> </span><span class=cF1>if</span><span class=cF0> (res)
<a name="l140"></a> {
<a name="l141"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(_de, &amp;de, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDirEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l142"></a> _de-&gt;full_name = full_name;
<a name="l143"></a> }
<a name="l144"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l145"></a> </span><span class=cF5>MemSet</span><span class=cF0>(_de, </span><span class=cFE>0</span><span class=cF0>, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDirEntry</span><span class=cF7>)</span><span class=cF0>);
<a name="l146"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l147"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l148"></a>}
</span></pre></body>
</html>