667 lines
70 KiB
Plaintext
667 lines
70 KiB
Plaintext
|
<!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=cF2>// See </span><a href="/Wb/Doc/RedSea.DD.HTML#l1"><span class=cF4>RedSea File System</span></a><span class=cF0>
|
||
|
<a name="l2"></a>
|
||
|
<a name="l3"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>RedSeaFreeFreeLst</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv)
|
||
|
<a name="l4"></a>{
|
||
|
<a name="l5"></a> </span><span class=cF9>CFreeLst</span><span class=cF0> *tmpf,*tmpf1;
|
||
|
<a name="l6"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock;
|
||
|
<a name="l7"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l8"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
|
||
|
<a name="l9"></a> </span><span class=cF1>if</span><span class=cF0> (tmpf=dv->next_free) {
|
||
|
<a name="l10"></a> </span><span class=cF1>while</span><span class=cF0> (tmpf!=&dv->next_free) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l11"></a> tmpf1=tmpf->next;
|
||
|
<a name="l12"></a> </span><span class=cF5>Free</span><span class=cF0>(tmpf);
|
||
|
<a name="l13"></a> tmpf=tmpf1;
|
||
|
<a name="l14"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l15"></a> }
|
||
|
<a name="l16"></a> dv->next_free=</span><span class=cF3>NULL</span><span class=cF0>;
|
||
|
<a name="l17"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l18"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l19"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
|
||
|
<a name="l20"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l21"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l22"></a>}
|
||
|
<a name="l23"></a>
|
||
|
<a name="l24"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>RedSeaFreeLstBuild</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv)
|
||
|
<a name="l25"></a>{
|
||
|
<a name="l26"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock;
|
||
|
<a name="l27"></a> </span><span class=cF9>CFreeLst</span><span class=cF0> *tmpf;
|
||
|
<a name="l28"></a> </span><span class=cF9>I64</span><span class=cF0> i,first=dv->data_area,max_blk=dv->size+dv->drv_offset;
|
||
|
<a name="l29"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l30"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
|
||
|
<a name="l31"></a> </span><span class=cF1>if</span><span class=cF0> (dv->next_free)
|
||
|
<a name="l32"></a> </span><span class=cFD>RedSeaFreeFreeLst</span><span class=cF0>(dv);
|
||
|
<a name="l33"></a> </span><span class=cF5>QueInit</span><span class=cF0>(&dv->next_free);
|
||
|
<a name="l34"></a> </span><span class=cF1>while</span><span class=cF0> (first<max_blk) {
|
||
|
<a name="l35"></a> i=0; </span><span class=cF2>//count free clus</span><span class=cF0>
|
||
|
<a name="l36"></a> </span><span class=cF1>while</span><span class=cF0> (first+i<max_blk) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l37"></a> </span><span class=cFD>DrvFATBlkSet</span><span class=cF0>(dv,first+i);
|
||
|
<a name="l38"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>dv->cur_fat_blk,(first+i-dv->data_area)&(</span><span class=cF3>BLK_SIZE</span><span class=cF0><<3-1)</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l39"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l40"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l41"></a> i++;
|
||
|
<a name="l42"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l43"></a> </span><span class=cF1>if</span><span class=cF0> (i) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l44"></a> tmpf=</span><span class=cF5>AMAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CFreeLst</span><span class=cF7>)</span><span class=cF0>);
|
||
|
<a name="l45"></a> tmpf->size=i;
|
||
|
<a name="l46"></a> tmpf-></span><span class=cF1>start</span><span class=cF0>=first;
|
||
|
<a name="l47"></a> </span><span class=cF5>QueIns</span><span class=cF0>(tmpf,dv->last_free);
|
||
|
<a name="l48"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l49"></a> first+=i+1;
|
||
|
<a name="l50"></a> }
|
||
|
<a name="l51"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l52"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l53"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
|
||
|
<a name="l54"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l55"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l56"></a>}
|
||
|
<a name="l57"></a>
|
||
|
<a name="l58"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>RedSeaInit</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv)
|
||
|
<a name="l59"></a>{
|
||
|
<a name="l60"></a> </span><span class=cF9>CRedSeaBoot</span><span class=cF0> br;
|
||
|
<a name="l61"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock;
|
||
|
<a name="l62"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l63"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
|
||
|
<a name="l64"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,&br,dv->drv_offset,1);
|
||
|
<a name="l65"></a> </span><span class=cF1>if</span><span class=cF0> (br.signature!=</span><span class=cF3>MBR_PT_REDSEA</span><span class=cF0> || br.signature2!=0xAA55)
|
||
|
<a name="l66"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
|
||
|
<a name="l67"></a> dv->fs_type=</span><span class=cF3>FSt_REDSEA</span><span class=cF0>;
|
||
|
<a name="l68"></a> </span><span class=cFD>RedSeaFreeFreeLst</span><span class=cF0>(dv);
|
||
|
<a name="l69"></a> dv->spc=1;
|
||
|
<a name="l70"></a> dv->size=br.sects;
|
||
|
<a name="l71"></a> dv->data_area=dv->drv_offset+br.bitmap_sects;
|
||
|
<a name="l72"></a> dv->root_clus=br.root_clus;
|
||
|
<a name="l73"></a> dv->fat1=dv->fat2=dv->drv_offset+1;
|
||
|
<a name="l74"></a> </span><span class=cFD>DrvFATBlkAlloc</span><span class=cF0>(dv);
|
||
|
<a name="l75"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l76"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l77"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
|
||
|
<a name="l78"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l79"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l80"></a>}
|
||
|
<a name="l81"></a>
|
||
|
<a name="l82"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>RedSeaValidate</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let)
|
||
|
<a name="l83"></a>{
|
||
|
<a name="l84"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv;
|
||
|
<a name="l85"></a> </span><span class=cF9>CRedSeaBoot</span><span class=cF0> br;
|
||
|
<a name="l86"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>dv=</span><span class=cF5>Let2Drv</span><span class=cF0>(drv_let,</span><span class=cF3>FALSE</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0> && dv->fs_type==</span><span class=cF3>FSt_REDSEA</span><span class=cF0> &&
|
||
|
<a name="l87"></a> </span><span class=cF5>BlkRead</span><span class=cF7>(</span><span class=cF0>dv,&br,dv->drv_offset,1</span><span class=cF7>)</span><span class=cF0> && br.signature==</span><span class=cF3>MBR_PT_REDSEA</span><span class=cF0> &&
|
||
|
<a name="l88"></a> br.signature2==0xAA55)
|
||
|
<a name="l89"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l90"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l91"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l92"></a>}
|
||
|
<a name="l93"></a>
|
||
|
<a name="l94"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>RedSeaFmt</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> drv_let,</span><span class=cF1>Bool</span><span class=cF0> quick=</span><span class=cF3>TRUE</span><span class=cF0>)
|
||
|
<a name="l95"></a>{
|
||
|
<a name="l96"></a> </span><span class=cF1>U8</span><span class=cF0> *root_dir;
|
||
|
<a name="l97"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *d_native;
|
||
|
<a name="l98"></a> </span><span class=cF9>CRedSeaBoot</span><span class=cF0> *br=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF3>BLK_SIZE</span><span class=cF0>);
|
||
|
<a name="l99"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv=</span><span class=cF5>Let2Drv</span><span class=cF0>(drv_let);
|
||
|
<a name="l100"></a> </span><span class=cF9>I64</span><span class=cF0> i,n,root_dir_blks;
|
||
|
<a name="l101"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l102"></a> </span><span class=cF5>DrvLock</span><span class=cF0>(dv);
|
||
|
<a name="l103"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>DrvTypeSet(drv_let,FSt_REDSEA);</span><span class=cF0>
|
||
|
<a name="l104"></a> </span><span class=cFD>DrvTypeSet</span><span class=cF0>(drv_let,</span><span class=cF3>FSt_FAT32</span><span class=cF0>);
|
||
|
<a name="l105"></a> dv->fs_type=</span><span class=cF3>FSt_REDSEA</span><span class=cF0>;
|
||
|
<a name="l106"></a> br->signature=</span><span class=cF3>MBR_PT_REDSEA</span><span class=cF0>;
|
||
|
<a name="l107"></a> br->signature2=0xAA55;
|
||
|
<a name="l108"></a> br->drv_offset=dv->drv_offset; </span><span class=cF2>//For CD/DVD image copy.</span><span class=cF0>
|
||
|
<a name="l109"></a> br->sects=dv->size;
|
||
|
<a name="l110"></a> n=(br->sects+</span><span class=cF3>BLK_SIZE</span><span class=cF0><<3-1)/</span><span class=cF3>BLK_SIZE</span><span class=cF0><<3;
|
||
|
<a name="l111"></a> br->bitmap_sects=n;
|
||
|
<a name="l112"></a> br->unique_id=</span><span class=cF5>GetTSC</span><span class=cF0>^</span><span class=cF5>Now</span><span class=cF0>()(</span><span class=cF9>U64</span><span class=cF0>);
|
||
|
<a name="l113"></a> br->root_clus=0;
|
||
|
<a name="l114"></a>
|
||
|
<a name="l115"></a> </span><span class=cF1>if</span><span class=cF0> (quick)
|
||
|
<a name="l116"></a> i=n+1;
|
||
|
<a name="l117"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l118"></a> i=dv->size;
|
||
|
<a name="l119"></a> </span><span class=cF5>BlkWriteZero</span><span class=cF0>(dv,dv->drv_offset,i);
|
||
|
<a name="l120"></a>
|
||
|
<a name="l121"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,br,dv->drv_offset,1);
|
||
|
<a name="l122"></a> </span><span class=cFD>RedSeaInit</span><span class=cF0>(dv);
|
||
|
<a name="l123"></a> </span><span class=cF5>ClusAlloc</span><span class=cF0>(dv,0,1,</span><span class=cF3>FALSE</span><span class=cF0>); </span><span class=cF2>//Alloc #1</span><span class=cF0>
|
||
|
<a name="l124"></a>
|
||
|
<a name="l125"></a> root_dir_blks=</span><span class=cF5>MaxI64</span><span class=cF0>(1,dv->bd->init_root_dir_blks);
|
||
|
<a name="l126"></a> br->root_clus=</span><span class=cF5>ClusAlloc</span><span class=cF0>(dv,0,root_dir_blks,</span><span class=cF3>FALSE</span><span class=cF0>);
|
||
|
<a name="l127"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,br,dv->drv_offset,1);
|
||
|
<a name="l128"></a> root_dir=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF3>BLK_SIZE</span><span class=cF0>*root_dir_blks);
|
||
|
<a name="l129"></a>
|
||
|
<a name="l130"></a> d_native=root_dir-</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF0>);
|
||
|
<a name="l131"></a>
|
||
|
<a name="l132"></a> d_native->attr=</span><span class=cF3>RS_ATTR_DIR</span><span class=cF0>|</span><span class=cF3>RS_ATTR_CONTIGUOUS</span><span class=cF0>;
|
||
|
<a name="l133"></a> *d_native->name=</span><span class=cF6>'.'</span><span class=cF0>;
|
||
|
<a name="l134"></a> d_native->clus=br->root_clus;
|
||
|
<a name="l135"></a> d_native->size=</span><span class=cF3>BLK_SIZE</span><span class=cF0>*root_dir_blks;
|
||
|
<a name="l136"></a> d_native->datetime=</span><span class=cF5>Now</span><span class=cF0>;
|
||
|
<a name="l137"></a>
|
||
|
<a name="l138"></a> d_native(</span><span class=cF1>U8</span><span class=cF0> *)+=</span><span class=cF3>CDIR_SIZE</span><span class=cF0>;
|
||
|
<a name="l139"></a>
|
||
|
<a name="l140"></a> *d_native->name=</span><span class=cF6>'.'</span><span class=cF0>;
|
||
|
<a name="l141"></a> d_native->name[1]=</span><span class=cF6>'.'</span><span class=cF0>;
|
||
|
<a name="l142"></a> d_native->attr=</span><span class=cF3>RS_ATTR_DIR</span><span class=cF0>|</span><span class=cF3>RS_ATTR_CONTIGUOUS</span><span class=cF0>;
|
||
|
<a name="l143"></a> d_native->clus=br->root_clus;
|
||
|
<a name="l144"></a> d_native->datetime=</span><span class=cF5>Now</span><span class=cF0>;
|
||
|
<a name="l145"></a>
|
||
|
<a name="l146"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,root_dir,br->root_clus,root_dir_blks);
|
||
|
<a name="l147"></a> </span><span class=cFD>RedSeaInit</span><span class=cF0>(dv);
|
||
|
<a name="l148"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l149"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
|
||
|
<a name="l150"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l151"></a> </span><span class=cF5>Free</span><span class=cF0>(br);
|
||
|
<a name="l152"></a> </span><span class=cF5>Free</span><span class=cF0>(root_dir);
|
||
|
<a name="l153"></a>}
|
||
|
<a name="l154"></a>
|
||
|
<a name="l155"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>RedSeaFileFind</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF9>I64</span><span class=cF0> cur_dir_clus,</span><span class=cF1>U8</span><span class=cF0> *name,
|
||
|
<a name="l156"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *_res,</span><span class=cF9>I64</span><span class=cF0> fuf_flags=0)
|
||
|
<a name="l157"></a>{</span><span class=cF2>//</span><a href="/Wb/Kernel/KernelA.HH.HTML#l2577"><span class=cF4>FUF_JUST_DIRS</span></a><span class=cF2>, </span><a href="/Wb/Kernel/KernelA.HH.HTML#l2578"><span class=cF4>FUF_JUST_FILES</span></a><span class=cF0>
|
||
|
<a name="l158"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *buf,*buf2,*ptr;
|
||
|
<a name="l159"></a> </span><span class=cF1>U8</span><span class=cF0> dname[</span><span class=cF3>CDIR_FILENAME_LEN</span><span class=cF0>];
|
||
|
<a name="l160"></a> </span><span class=cF9>I64</span><span class=cF0> ch;
|
||
|
<a name="l161"></a> </span><span class=cF1>Bool</span><span class=cF0> res=</span><span class=cF3>FALSE</span><span class=cF0>,unlock;
|
||
|
<a name="l162"></a> </span><span class=cF1>if</span><span class=cF0> (fuf_flags&~</span><span class=cF3>FUG_FILE_FIND</span><span class=cF0>)
|
||
|
<a name="l163"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'FUF'</span><span class=cF0>);
|
||
|
<a name="l164"></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>CDirEntry</span><span class=cF7>)</span><span class=cF0>);
|
||
|
<a name="l165"></a> </span><span class=cF5>DrvChk</span><span class=cF0>(dv);
|
||
|
<a name="l166"></a> </span><span class=cF1>if</span><span class=cF0> (dv->fs_type!=</span><span class=cF3>FSt_REDSEA</span><span class=cF0>)
|
||
|
<a name="l167"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"Not RedSea Drv\n"</span><span class=cF0>);
|
||
|
<a name="l168"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFD>CFileNameTo</span><span class=cF7>(</span><span class=cF0>dname,name</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l169"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"Invalid FileName: \"%s\".\n"</span><span class=cF0>,name);
|
||
|
<a name="l170"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l171"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l172"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
|
||
|
<a name="l173"></a> buf2=</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF3>BLK_SIZE</span><span class=cF0>);
|
||
|
<a name="l174"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,buf2,cur_dir_clus,1);
|
||
|
<a name="l175"></a>
|
||
|
<a name="l176"></a> ptr=buf2(</span><span class=cF1>U8</span><span class=cF0> *)-</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF0>);
|
||
|
<a name="l177"></a> buf=</span><span class=cF5>MAlloc</span><span class=cF0>(ptr->size);
|
||
|
<a name="l178"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,buf,cur_dir_clus,ptr->size>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l179"></a> </span><span class=cF5>Free</span><span class=cF0>(buf2);
|
||
|
<a name="l180"></a>
|
||
|
<a name="l181"></a> ptr=buf(</span><span class=cF1>U8</span><span class=cF0> *)-</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF0>);
|
||
|
<a name="l182"></a> *ptr->name=</span><span class=cF6>'.'</span><span class=cF0>;
|
||
|
<a name="l183"></a> ptr->name[1]=0;
|
||
|
<a name="l184"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
|
||
|
<a name="l185"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>ch=*ptr->name</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l186"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l187"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>ptr->attr & </span><span class=cF3>RS_ATTR_DELETED</span><span class=cF7>)</span><span class=cF0> &&
|
||
|
<a name="l188"></a> !</span><span class=cF7>(</span><span class=cF0>fuf_flags&</span><span class=cF3>FUF_JUST_DIRS</span><span class=cF0> && !(ptr->attr & </span><span class=cF3>RS_ATTR_DIR</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0> &&
|
||
|
<a name="l189"></a> !</span><span class=cF7>(</span><span class=cF0>fuf_flags&</span><span class=cF3>FUF_JUST_FILES</span><span class=cF0> && ptr->attr & </span><span class=cF3>RS_ATTR_DIR</span><span class=cF7>)</span><span class=cF0> &&
|
||
|
<a name="l190"></a> !</span><span class=cF5>StrCmp</span><span class=cF7>(</span><span class=cF0>dname,ptr->name</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l191"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&_res->attr,&ptr->attr,</span><span class=cF3>CDIR_SIZE</span><span class=cF0>);
|
||
|
<a name="l192"></a> res=</span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l193"></a> </span><span class=cF1>goto</span><span class=cF0> rsff_done;
|
||
|
<a name="l194"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l195"></a> ptr(</span><span class=cF1>U8</span><span class=cF0> *)+=</span><span class=cF3>CDIR_SIZE</span><span class=cF0>;
|
||
|
<a name="l196"></a> }
|
||
|
<a name="l197"></a>rsff_done:
|
||
|
<a name="l198"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
|
||
|
<a name="l199"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l200"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l201"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
|
||
|
<a name="l202"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l203"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l204"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
||
|
<a name="l205"></a>}
|
||
|
<a name="l206"></a>
|
||
|
<a name="l207"></a></span><span class=cF1>U8</span><span class=cF0> *</span><span class=cFD>RedSeaFileRead</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF1>U8</span><span class=cF0> *cur_dir,</span><span class=cF1>U8</span><span class=cF0> *filename,</span><span class=cF9>I64</span><span class=cF0> *_size,</span><span class=cF9>I64</span><span class=cF0> *_attr)
|
||
|
<a name="l208"></a>{
|
||
|
<a name="l209"></a> </span><span class=cF1>U8</span><span class=cF0> *buf=</span><span class=cF3>NULL</span><span class=cF0>;
|
||
|
<a name="l210"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> de;
|
||
|
<a name="l211"></a> </span><span class=cF9>I64</span><span class=cF0> c,blk_cnt,cur_dir_clus;
|
||
|
<a name="l212"></a> </span><span class=cF5>DrvChk</span><span class=cF0>(dv);
|
||
|
<a name="l213"></a> *_size=0;
|
||
|
<a name="l214"></a> *_attr=0;
|
||
|
<a name="l215"></a> </span><span class=cF1>if</span><span class=cF0> (dv->fs_type!=</span><span class=cF3>FSt_REDSEA</span><span class=cF0>)
|
||
|
<a name="l216"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"Not RedSea Drv\n"</span><span class=cF0>);
|
||
|
<a name="l217"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l218"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l219"></a> </span><span class=cF5>DrvLock</span><span class=cF0>(dv);
|
||
|
<a name="l220"></a> cur_dir_clus=</span><span class=cF5>Name2DirClus</span><span class=cF0>(dv,cur_dir);
|
||
|
<a name="l221"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>RedSeaFileFind</span><span class=cF7>(</span><span class=cF0>dv,cur_dir_clus,filename,&de,</span><span class=cF3>FUF_JUST_FILES</span><span class=cF7>)</span><span class=cF0>) {
|
||
|
<a name="l222"></a> blk_cnt=(de.size+</span><span class=cF3>BLK_SIZE</span><span class=cF0>-1)>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
|
||
|
<a name="l223"></a> buf=</span><span class=cF5>MAlloc</span><span class=cF0>(blk_cnt<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>+1);
|
||
|
<a name="l224"></a> c=de.clus;
|
||
|
<a name="l225"></a> c=</span><span class=cF5>BlkRead</span><span class=cF0>(dv,buf,c,blk_cnt);
|
||
|
<a name="l226"></a> buf[de.size]=0; </span><span class=cF2>//Terminate</span><span class=cF0>
|
||
|
<a name="l227"></a> *_size=de.size;
|
||
|
<a name="l228"></a> *_attr=</span><span class=cF5>FileAttr</span><span class=cF0>(de.name,de.attr);
|
||
|
<a name="l229"></a> }
|
||
|
<a name="l230"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l231"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
|
||
|
<a name="l232"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l233"></a> </span><span class=cF1>return</span><span class=cF0> buf;
|
||
|
<a name="l234"></a>}
|
||
|
<a name="l235"></a>
|
||
|
<a name="l236"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>RedSeaCd</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *name,</span><span class=cF9>I64</span><span class=cF0> cur_dir_clus)
|
||
|
<a name="l237"></a>{
|
||
|
<a name="l238"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> de;
|
||
|
<a name="l239"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Fs</span><span class=cF0>->cur_dv->fs_type!=</span><span class=cF3>FSt_REDSEA</span><span class=cF0>)
|
||
|
<a name="l240"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"Not RedSea Drv\n"</span><span class=cF0>);
|
||
|
<a name="l241"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>RedSeaFileFind</span><span class=cF7>(</span><span class=cF5>Fs</span><span class=cF0>->cur_dv,cur_dir_clus,name,&de,</span><span class=cF3>FUF_JUST_DIRS</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l242"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l243"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l244"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"File not found: \"%s\".\n"</span><span class=cF0>,name);
|
||
|
<a name="l245"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l246"></a>}
|
||
|
<a name="l247"></a>
|
||
|
<a name="l248"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>RedSeaFreeClus</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF9>I64</span><span class=cF0> c,</span><span class=cF9>I64</span><span class=cF0> cnt)
|
||
|
<a name="l249"></a>{
|
||
|
<a name="l250"></a> </span><span class=cF9>CFreeLst</span><span class=cF0> *tmpf;
|
||
|
<a name="l251"></a> </span><span class=cF1>Bool</span><span class=cF0> found=</span><span class=cF3>FALSE</span><span class=cF0>,unlock,unlock_break;
|
||
|
<a name="l252"></a> </span><span class=cF5>DrvChk</span><span class=cF0>(dv);
|
||
|
<a name="l253"></a> </span><span class=cF1>if</span><span class=cF0> (!c) </span><span class=cF1>return</span><span class=cF0>;
|
||
|
<a name="l254"></a> </span><span class=cF1>if</span><span class=cF0> (dv->fs_type!=</span><span class=cF3>FSt_REDSEA</span><span class=cF0>)
|
||
|
<a name="l255"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"Not RedSea Drv\n"</span><span class=cF0>);
|
||
|
<a name="l256"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l257"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l258"></a> unlock_break=</span><span class=cF5>BreakLock</span><span class=cF0>;
|
||
|
<a name="l259"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
|
||
|
<a name="l260"></a> </span><span class=cF1>if</span><span class=cF0> (!dv->next_free)
|
||
|
<a name="l261"></a> </span><span class=cFD>RedSeaFreeLstBuild</span><span class=cF0>(dv);
|
||
|
<a name="l262"></a> tmpf=dv->next_free;
|
||
|
<a name="l263"></a> </span><span class=cF1>while</span><span class=cF0> (!found && tmpf!=&dv->next_free) {
|
||
|
<a name="l264"></a> </span><span class=cF1>if</span><span class=cF0> (tmpf-></span><span class=cF1>start</span><span class=cF0>+tmpf->size==c) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l265"></a> tmpf->size+=cnt;
|
||
|
<a name="l266"></a> found=</span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l267"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (c+cnt==tmpf-></span><span class=cF1>start</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l268"></a> tmpf->size+=cnt;
|
||
|
<a name="l269"></a> tmpf-></span><span class=cF1>start</span><span class=cF0>=c;
|
||
|
<a name="l270"></a> found=</span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l271"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l272"></a> tmpf=tmpf->next;
|
||
|
<a name="l273"></a> }
|
||
|
<a name="l274"></a> </span><span class=cF1>if</span><span class=cF0> (!found) {
|
||
|
<a name="l275"></a> tmpf=</span><span class=cF5>AMAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CFreeLst</span><span class=cF7>)</span><span class=cF0>);
|
||
|
<a name="l276"></a> tmpf->size=cnt;
|
||
|
<a name="l277"></a> tmpf-></span><span class=cF1>start</span><span class=cF0>=c;
|
||
|
<a name="l278"></a> </span><span class=cF5>QueIns</span><span class=cF0>(tmpf,dv->last_free);
|
||
|
<a name="l279"></a> }
|
||
|
<a name="l280"></a> </span><span class=cF1>while</span><span class=cF0> (cnt-->0) {
|
||
|
<a name="l281"></a> </span><span class=cFD>DrvFATBlkSet</span><span class=cF0>(dv,c);
|
||
|
<a name="l282"></a> </span><span class=cF5>LBtr</span><span class=cF0>(dv->cur_fat_blk,</span><span class=cF7>(</span><span class=cF0>c-dv->data_area</span><span class=cF7>)</span><span class=cF0>&</span><span class=cF7>(</span><span class=cF3>BLK_SIZE</span><span class=cF0><<3-1</span><span class=cF7>)</span><span class=cF0>);
|
||
|
<a name="l283"></a> </span><span class=cF5>LBts</span><span class=cF0>(&dv->fat_blk_dirty,0);
|
||
|
<a name="l284"></a> c++;
|
||
|
<a name="l285"></a> }
|
||
|
<a name="l286"></a> </span><span class=cFD>DrvFATBlkClean</span><span class=cF0>(dv);
|
||
|
<a name="l287"></a>
|
||
|
<a name="l288"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l289"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l290"></a> </span><span class=cF1>if</span><span class=cF0> (unlock_break)
|
||
|
<a name="l291"></a> </span><span class=cF5>BreakUnlock</span><span class=cF0>;
|
||
|
<a name="l292"></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="l293"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l294"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l295"></a> </span><span class=cF1>if</span><span class=cF0> (unlock_break)
|
||
|
<a name="l296"></a> </span><span class=cF5>BreakUnlock</span><span class=cF0>;
|
||
|
<a name="l297"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l298"></a>}
|
||
|
<a name="l299"></a>
|
||
|
<a name="l300"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFD>RedSeaAllocClus</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF9>I64</span><span class=cF0> cnt)
|
||
|
<a name="l301"></a>{
|
||
|
<a name="l302"></a> </span><span class=cF9>CFreeLst</span><span class=cF0> *tmpf,*best_free=</span><span class=cF3>NULL</span><span class=cF0>;
|
||
|
<a name="l303"></a> </span><span class=cF9>I64</span><span class=cF0> i,first,best_size=</span><span class=cF3>I64_MAX</span><span class=cF0>;
|
||
|
<a name="l304"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock,unlock_break;
|
||
|
<a name="l305"></a> </span><span class=cF1>if</span><span class=cF0> (cnt<=0)
|
||
|
<a name="l306"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
|
||
|
<a name="l307"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l308"></a> unlock_break=</span><span class=cF5>BreakLock</span><span class=cF0>;
|
||
|
<a name="l309"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
|
||
|
<a name="l310"></a> </span><span class=cF1>if</span><span class=cF0> (!dv->next_free)
|
||
|
<a name="l311"></a> </span><span class=cFD>RedSeaFreeLstBuild</span><span class=cF0>(dv);
|
||
|
<a name="l312"></a> tmpf=dv->next_free;
|
||
|
<a name="l313"></a> </span><span class=cF1>while</span><span class=cF0> (tmpf!=&dv->next_free) {
|
||
|
<a name="l314"></a> </span><span class=cF1>if</span><span class=cF0> (tmpf->size>=cnt && tmpf->size<best_size) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l315"></a> best_free=tmpf;
|
||
|
<a name="l316"></a> best_size=tmpf->size;
|
||
|
<a name="l317"></a> </span><span class=cF1>if</span><span class=cF0> (tmpf->size==cnt)
|
||
|
<a name="l318"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l319"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l320"></a> tmpf=tmpf->next;
|
||
|
<a name="l321"></a> }
|
||
|
<a name="l322"></a> </span><span class=cF1>if</span><span class=cF0> (!best_free)
|
||
|
<a name="l323"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
|
||
|
<a name="l324"></a> first=best_free-></span><span class=cF1>start</span><span class=cF0>;
|
||
|
<a name="l325"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i<cnt;i++) {
|
||
|
<a name="l326"></a> </span><span class=cFD>DrvFATBlkSet</span><span class=cF0>(dv,first+i);
|
||
|
<a name="l327"></a> </span><span class=cF5>LBts</span><span class=cF0>(dv->cur_fat_blk,</span><span class=cF7>(</span><span class=cF0>first+i-dv->data_area</span><span class=cF7>)</span><span class=cF0>&</span><span class=cF7>(</span><span class=cF3>BLK_SIZE</span><span class=cF0><<3-1</span><span class=cF7>)</span><span class=cF0>);
|
||
|
<a name="l328"></a> </span><span class=cF5>LBts</span><span class=cF0>(&dv->fat_blk_dirty,0);
|
||
|
<a name="l329"></a> }
|
||
|
<a name="l330"></a> </span><span class=cFD>DrvFATBlkClean</span><span class=cF0>(dv);
|
||
|
<a name="l331"></a> </span><span class=cF1>if</span><span class=cF0> (best_free->size-=cnt)
|
||
|
<a name="l332"></a> best_free-></span><span class=cF1>start</span><span class=cF0>+=cnt;
|
||
|
<a name="l333"></a> </span><span class=cF1>else</span><span class=cF0> {
|
||
|
<a name="l334"></a> </span><span class=cF5>QueRem</span><span class=cF0>(best_free);
|
||
|
<a name="l335"></a> </span><span class=cF5>Free</span><span class=cF0>(best_free);
|
||
|
<a name="l336"></a> }
|
||
|
<a name="l337"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l338"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l339"></a> </span><span class=cF1>if</span><span class=cF0> (unlock_break)
|
||
|
<a name="l340"></a> </span><span class=cF5>BreakUnlock</span><span class=cF0>;
|
||
|
<a name="l341"></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="l342"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l343"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l344"></a> </span><span class=cF1>if</span><span class=cF0> (unlock_break)
|
||
|
<a name="l345"></a> </span><span class=cF5>BreakUnlock</span><span class=cF0>;
|
||
|
<a name="l346"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l347"></a> </span><span class=cF1>return</span><span class=cF0> first;
|
||
|
<a name="l348"></a>}
|
||
|
<a name="l349"></a>
|
||
|
<a name="l350"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>RedSeaDirNew</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF1>U8</span><span class=cF0> *cur_dir,</span><span class=cF9>CDirEntry</span><span class=cF0> *tmpde,</span><span class=cF1>Bool</span><span class=cF0> free_old_chain)
|
||
|
<a name="l351"></a>{
|
||
|
<a name="l352"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *buf,*buf2,*ptr,de2;
|
||
|
<a name="l353"></a> </span><span class=cF9>CRedSeaBoot</span><span class=cF0> *br;
|
||
|
<a name="l354"></a> </span><span class=cF9>I64</span><span class=cF0> c,ch,i=1,j=0,n=</span><span class=cF3>BLK_SIZE</span><span class=cF0>/</span><span class=cF3>CDIR_SIZE</span><span class=cF0>,dir_size,cur_dir_clus;
|
||
|
<a name="l355"></a> </span><span class=cF1>Bool</span><span class=cF0> written=</span><span class=cF3>FALSE</span><span class=cF0>,unlock,unlock_break;
|
||
|
<a name="l356"></a> </span><span class=cF1>U8</span><span class=cF0> *tmp,*parent_dir;
|
||
|
<a name="l357"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l358"></a> unlock_break=</span><span class=cF5>BreakLock</span><span class=cF0>;
|
||
|
<a name="l359"></a> tmpde->attr|=</span><span class=cF3>RS_ATTR_CONTIGUOUS</span><span class=cF0>;
|
||
|
<a name="l360"></a> unlock=</span><span class=cF5>DrvLock</span><span class=cF0>(dv);
|
||
|
<a name="l361"></a> cur_dir_clus=</span><span class=cF5>Name2DirClus</span><span class=cF0>(dv,cur_dir);
|
||
|
<a name="l362"></a> buf2=</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF3>BLK_SIZE</span><span class=cF0>);
|
||
|
<a name="l363"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,buf2,cur_dir_clus,1);
|
||
|
<a name="l364"></a>
|
||
|
<a name="l365"></a> ptr=buf2(</span><span class=cF1>U8</span><span class=cF0> *)-</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF0>);
|
||
|
<a name="l366"></a> buf=</span><span class=cF5>MAlloc</span><span class=cF0>(ptr->size);
|
||
|
<a name="l367"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,buf,cur_dir_clus,ptr->size>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l368"></a>
|
||
|
<a name="l369"></a> dir_size=ptr->size;
|
||
|
<a name="l370"></a> ptr=buf(</span><span class=cF1>U8</span><span class=cF0> *)-</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF0>)+</span><span class=cF3>CDIR_SIZE</span><span class=cF0>;
|
||
|
<a name="l371"></a> </span><span class=cF5>Free</span><span class=cF0>(buf2);
|
||
|
<a name="l372"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
|
||
|
<a name="l373"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>ch=*ptr->name</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l374"></a> </span><span class=cF1>if</span><span class=cF0> (!written)
|
||
|
<a name="l375"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&ptr-></span><span class=cF1>start</span><span class=cF0>,&tmpde-></span><span class=cF1>start</span><span class=cF0>,</span><span class=cF3>CDIR_SIZE</span><span class=cF0>);
|
||
|
<a name="l376"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>i+1</span><span class=cF7>)</span><span class=cF0>*</span><span class=cF3>CDIR_SIZE</span><span class=cF0>+j<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0><dir_size)
|
||
|
<a name="l377"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,buf</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>+j<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>,cur_dir_clus+j,1);
|
||
|
<a name="l378"></a> </span><span class=cF1>else</span><span class=cF0> {
|
||
|
<a name="l379"></a> buf2=</span><span class=cF5>CAlloc</span><span class=cF0>(dir_size+</span><span class=cF3>BLK_SIZE</span><span class=cF0>);
|
||
|
<a name="l380"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(buf2,buf,dir_size);
|
||
|
<a name="l381"></a> </span><span class=cF5>RedSeaFreeClus</span><span class=cF0>(dv,cur_dir_clus,dir_size>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l382"></a> dir_size+=</span><span class=cF3>BLK_SIZE</span><span class=cF0>;
|
||
|
<a name="l383"></a> c=</span><span class=cF5>ClusAlloc</span><span class=cF0>(dv,0,dir_size>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>,</span><span class=cF3>TRUE</span><span class=cF0>);
|
||
|
<a name="l384"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
|
||
|
<a name="l385"></a> buf=buf2;
|
||
|
<a name="l386"></a> ptr=buf(</span><span class=cF1>U8</span><span class=cF0> *)-</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF0>);
|
||
|
<a name="l387"></a> ptr->size=dir_size;
|
||
|
<a name="l388"></a> ptr->clus=c;
|
||
|
<a name="l389"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,buf,c,dir_size>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l390"></a> </span><span class=cF1>if</span><span class=cF0> (cur_dir_clus==dv->root_clus) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l391"></a> br=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF3>BLK_SIZE</span><span class=cF0>);
|
||
|
<a name="l392"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,br,dv->drv_offset,1);
|
||
|
<a name="l393"></a> br->root_clus=c;
|
||
|
<a name="l394"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,br,dv->drv_offset,1);
|
||
|
<a name="l395"></a> </span><span class=cF5>Free</span><span class=cF0>(br);
|
||
|
<a name="l396"></a> dv->root_clus=c;
|
||
|
<a name="l397"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l398"></a> tmp=</span><span class=cF5>StrNew</span><span class=cF0>(cur_dir);
|
||
|
<a name="l399"></a> parent_dir=</span><span class=cF5>StrNew</span><span class=cF0>(cur_dir);
|
||
|
<a name="l400"></a> </span><span class=cF5>StrLastRem</span><span class=cF0>(parent_dir,</span><span class=cF6>"/"</span><span class=cF0>,tmp);
|
||
|
<a name="l401"></a> </span><span class=cF1>if</span><span class=cF0> (!*parent_dir) {
|
||
|
<a name="l402"></a> </span><span class=cF5>Free</span><span class=cF0>(parent_dir);
|
||
|
<a name="l403"></a> parent_dir=</span><span class=cF5>StrNew</span><span class=cF0>(</span><span class=cF6>"/"</span><span class=cF0>);
|
||
|
<a name="l404"></a> }
|
||
|
<a name="l405"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFD>RedSeaFileFind</span><span class=cF7>(</span><span class=cF0>dv,</span><span class=cF5>Name2DirClus</span><span class=cF0>(dv,parent_dir),
|
||
|
<a name="l406"></a> tmp,&de2,</span><span class=cF3>FUF_JUST_DIRS</span><span class=cF7>)</span><span class=cF0>) {
|
||
|
<a name="l407"></a> de2.clus=c;
|
||
|
<a name="l408"></a> de2.size=dir_size;
|
||
|
<a name="l409"></a> </span><span class=cFD>RedSeaDirNew</span><span class=cF0>(dv,parent_dir,&de2,</span><span class=cF3>FALSE</span><span class=cF0>);
|
||
|
<a name="l410"></a> } </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l411"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'Drv'</span><span class=cF0>);
|
||
|
<a name="l412"></a> </span><span class=cF5>Free</span><span class=cF0>(tmp);
|
||
|
<a name="l413"></a> </span><span class=cF5>Free</span><span class=cF0>(parent_dir);
|
||
|
<a name="l414"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l415"></a> }
|
||
|
<a name="l416"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l417"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (ptr->attr & </span><span class=cF3>RS_ATTR_DELETED</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l418"></a> </span><span class=cF1>if</span><span class=cF0> (!written) {
|
||
|
<a name="l419"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&ptr-></span><span class=cF1>start</span><span class=cF0>,&tmpde-></span><span class=cF1>start</span><span class=cF0>,</span><span class=cF3>CDIR_SIZE</span><span class=cF0>);
|
||
|
<a name="l420"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,buf</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>+j<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>,cur_dir_clus+j,1);
|
||
|
<a name="l421"></a> written=</span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l422"></a> }
|
||
|
<a name="l423"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l424"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>StrCmp</span><span class=cF7>(</span><span class=cF0>tmpde->name,ptr->name</span><span class=cF7>)</span><span class=cF0>) {
|
||
|
<a name="l425"></a> </span><span class=cF1>if</span><span class=cF0> (free_old_chain)
|
||
|
<a name="l426"></a> </span><span class=cF5>RedSeaFreeClus</span><span class=cF0>(dv,ptr->clus,
|
||
|
<a name="l427"></a> </span><span class=cF7>(</span><span class=cF0>ptr->size+</span><span class=cF3>BLK_SIZE</span><span class=cF0>-1</span><span class=cF7>)</span><span class=cF0>>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l428"></a> </span><span class=cF1>if</span><span class=cF0> (!written)
|
||
|
<a name="l429"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&ptr-></span><span class=cF1>start</span><span class=cF0>,&tmpde-></span><span class=cF1>start</span><span class=cF0>,</span><span class=cF3>CDIR_SIZE</span><span class=cF0>);
|
||
|
<a name="l430"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l431"></a> ptr->attr|=</span><span class=cF3>RS_ATTR_DELETED</span><span class=cF0>;
|
||
|
<a name="l432"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,buf</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>+j<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>,cur_dir_clus+j,1);
|
||
|
<a name="l433"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l434"></a> }
|
||
|
<a name="l435"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l436"></a> ptr(</span><span class=cF1>U8</span><span class=cF0> *)+=</span><span class=cF3>CDIR_SIZE</span><span class=cF0>;
|
||
|
<a name="l437"></a> </span><span class=cF1>if</span><span class=cF0> (++i>=n) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l438"></a> j++;
|
||
|
<a name="l439"></a> i=0;
|
||
|
<a name="l440"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l441"></a> }
|
||
|
<a name="l442"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
|
||
|
<a name="l443"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l444"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l445"></a> </span><span class=cF1>if</span><span class=cF0> (unlock_break)
|
||
|
<a name="l446"></a> </span><span class=cF5>BreakUnlock</span><span class=cF0>;
|
||
|
<a name="l447"></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="l448"></a> </span><span class=cF1>if</span><span class=cF0> (unlock)
|
||
|
<a name="l449"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l450"></a> </span><span class=cF1>if</span><span class=cF0> (unlock_break)
|
||
|
<a name="l451"></a> </span><span class=cF5>BreakUnlock</span><span class=cF0>;
|
||
|
<a name="l452"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l453"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l454"></a>}
|
||
|
<a name="l455"></a>
|
||
|
<a name="l456"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFD>RedSeaFilesDel</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF1>U8</span><span class=cF0> *cur_dir,</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="l457"></a> </span><span class=cF1>Bool</span><span class=cF0> del_dir,</span><span class=cF1>Bool</span><span class=cF0> print_msg)
|
||
|
<a name="l458"></a>{
|
||
|
<a name="l459"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *buf,*buf2,*ptr;
|
||
|
<a name="l460"></a> </span><span class=cF9>I64</span><span class=cF0> i=0,res=0,ch,j=0,n=</span><span class=cF3>BLK_SIZE</span><span class=cF0>/</span><span class=cF3>CDIR_SIZE</span><span class=cF0>,cur_dir_clus;
|
||
|
<a name="l461"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock_break;
|
||
|
<a name="l462"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l463"></a> unlock_break=</span><span class=cF5>BreakLock</span><span class=cF0>;
|
||
|
<a name="l464"></a> </span><span class=cF5>DrvLock</span><span class=cF0>(dv);
|
||
|
<a name="l465"></a> cur_dir_clus=</span><span class=cF5>Name2DirClus</span><span class=cF0>(dv,cur_dir);
|
||
|
<a name="l466"></a> buf2=</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF3>BLK_SIZE</span><span class=cF0>);
|
||
|
<a name="l467"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,buf2,cur_dir_clus,1);
|
||
|
<a name="l468"></a>
|
||
|
<a name="l469"></a> ptr=buf2(</span><span class=cF1>U8</span><span class=cF0> *)-</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF0>);
|
||
|
<a name="l470"></a> buf=</span><span class=cF5>MAlloc</span><span class=cF0>(ptr->size);
|
||
|
<a name="l471"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,buf,cur_dir_clus,ptr->size>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l472"></a> </span><span class=cF5>Free</span><span class=cF0>(buf2);
|
||
|
<a name="l473"></a>
|
||
|
<a name="l474"></a> ptr=buf(</span><span class=cF1>U8</span><span class=cF0> *)-</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF0>);
|
||
|
<a name="l475"></a> *ptr->name=</span><span class=cF6>'.'</span><span class=cF0>;
|
||
|
<a name="l476"></a> ptr->name[1]=0;
|
||
|
<a name="l477"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
|
||
|
<a name="l478"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>ch=*ptr->name</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l479"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l480"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>ptr->attr & </span><span class=cF3>RS_ATTR_DELETED</span><span class=cF7>)</span><span class=cF0> && ch!=</span><span class=cF6>'.'</span><span class=cF0> && </span><span class=cF7>(</span><span class=cF0>del_dir ||
|
||
|
<a name="l481"></a> !(ptr->attr & </span><span class=cF3>RS_ATTR_DIR</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0> &&
|
||
|
<a name="l482"></a> </span><span class=cF5>FilesFindMatch</span><span class=cF7>(</span><span class=cF0>ptr->name,files_find_mask,fuf_flags</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l483"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>ptr->attr & </span><span class=cF3>RS_ATTR_DIR</span><span class=cF7>)</span><span class=cF0>) res++;
|
||
|
<a name="l484"></a> </span><span class=cF1>if</span><span class=cF0> (print_msg)
|
||
|
<a name="l485"></a> </span><span class=cF6>"Del %s\n"</span><span class=cF0>,ptr->name;
|
||
|
<a name="l486"></a> ptr->attr|=</span><span class=cF3>RS_ATTR_DELETED</span><span class=cF0>;
|
||
|
<a name="l487"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,buf</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>+j<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>,cur_dir_clus+j,1);
|
||
|
<a name="l488"></a> </span><span class=cF5>RedSeaFreeClus</span><span class=cF0>(dv,ptr->clus,
|
||
|
<a name="l489"></a> </span><span class=cF7>(</span><span class=cF0>ptr->size+</span><span class=cF3>BLK_SIZE</span><span class=cF0>-1</span><span class=cF7>)</span><span class=cF0>>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l490"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l491"></a> ptr(</span><span class=cF1>U8</span><span class=cF0> *)+=</span><span class=cF3>CDIR_SIZE</span><span class=cF0>;
|
||
|
<a name="l492"></a> </span><span class=cF1>if</span><span class=cF0> (++i>=n) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l493"></a> j++;
|
||
|
<a name="l494"></a> i=0;
|
||
|
<a name="l495"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l496"></a> }
|
||
|
<a name="l497"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
|
||
|
<a name="l498"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l499"></a> </span><span class=cF1>if</span><span class=cF0> (unlock_break)
|
||
|
<a name="l500"></a> </span><span class=cF5>BreakUnlock</span><span class=cF0>;
|
||
|
<a name="l501"></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="l502"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l503"></a> </span><span class=cF1>if</span><span class=cF0> (unlock_break)
|
||
|
<a name="l504"></a> </span><span class=cF5>BreakUnlock</span><span class=cF0>;
|
||
|
<a name="l505"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l506"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
||
|
<a name="l507"></a>}
|
||
|
<a name="l508"></a>
|
||
|
<a name="l509"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFD>RedSeaFileWrite</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF1>U8</span><span class=cF0> *cur_dir,</span><span class=cF1>U8</span><span class=cF0> *name,</span><span class=cF1>U8</span><span class=cF0> *buf,</span><span class=cF9>I64</span><span class=cF0> size,
|
||
|
<a name="l510"></a> </span><span class=cF9>CDate</span><span class=cF0> cdt,</span><span class=cF9>I64</span><span class=cF0> attr)
|
||
|
<a name="l511"></a>{
|
||
|
<a name="l512"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> de;
|
||
|
<a name="l513"></a> </span><span class=cF9>I64</span><span class=cF0> c=0,blk_cnt;
|
||
|
<a name="l514"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&de,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CDirEntry</span><span class=cF7>)</span><span class=cF0>);
|
||
|
<a name="l515"></a> </span><span class=cF1>if</span><span class=cF0> (size<0) size=0;
|
||
|
<a name="l516"></a> </span><span class=cF1>if</span><span class=cF0> (dv->fs_type!=</span><span class=cF3>FSt_REDSEA</span><span class=cF0>)
|
||
|
<a name="l517"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"Not RedSea Drv\n"</span><span class=cF0>);
|
||
|
<a name="l518"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cFD>CFileNameTo</span><span class=cF7>(</span><span class=cF0>de.name,name</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l519"></a> </span><span class=cF5>PrintErr</span><span class=cF0>(</span><span class=cF6>"Invalid FileName: \"%s\".\n"</span><span class=cF0>,name);
|
||
|
<a name="l520"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l521"></a> </span><span class=cFD>RedSeaFilesDel</span><span class=cF0>(dv,cur_dir,de.name,0,</span><span class=cF3>FALSE</span><span class=cF0>,</span><span class=cF3>FALSE</span><span class=cF0>);
|
||
|
<a name="l522"></a> de.size=size;
|
||
|
<a name="l523"></a> </span><span class=cF1>if</span><span class=cF0> (blk_cnt=</span><span class=cF7>(</span><span class=cF0>size+</span><span class=cF3>BLK_SIZE</span><span class=cF0>-1</span><span class=cF7>)</span><span class=cF0>>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>)
|
||
|
<a name="l524"></a> c=</span><span class=cF5>ClusAlloc</span><span class=cF0>(dv,0,blk_cnt,</span><span class=cF3>TRUE</span><span class=cF0>); </span><span class=cF2>//Always contiguous</span><span class=cF0>
|
||
|
<a name="l525"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l526"></a> c=</span><span class=cF3>INVALID_CLUS</span><span class=cF0>;
|
||
|
<a name="l527"></a> de.clus=c;
|
||
|
<a name="l528"></a> de.attr=attr|</span><span class=cF3>RS_ATTR_CONTIGUOUS</span><span class=cF0>;
|
||
|
<a name="l529"></a> de.datetime=cdt;
|
||
|
<a name="l530"></a> </span><span class=cF1>if</span><span class=cF0> (blk_cnt)
|
||
|
<a name="l531"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,buf,c,blk_cnt);
|
||
|
<a name="l532"></a> </span><span class=cFD>RedSeaDirNew</span><span class=cF0>(dv,cur_dir,&de,</span><span class=cF3>TRUE</span><span class=cF0>);
|
||
|
<a name="l533"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l534"></a> </span><span class=cF1>return</span><span class=cF0> c;
|
||
|
<a name="l535"></a>}
|
||
|
<a name="l536"></a>
|
||
|
<a name="l537"></a></span><span class=cF9>CDirEntry</span><span class=cF0> *</span><span class=cFD>RedSeaFilesFind</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="l538"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *parent=</span><span class=cF3>NULL</span><span class=cF0>)
|
||
|
<a name="l539"></a>{
|
||
|
<a name="l540"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv=</span><span class=cF5>Fs</span><span class=cF0>->cur_dv;
|
||
|
<a name="l541"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *buf,*buf2,*ptr,*res=</span><span class=cF3>NULL</span><span class=cF0>,*tmpde;
|
||
|
<a name="l542"></a> </span><span class=cF9>I64</span><span class=cF0> ch,cur_dir_clus;
|
||
|
<a name="l543"></a> </span><span class=cF1>if</span><span class=cF0> (fuf_flags&~</span><span class=cF3>FUG_FILES_FIND</span><span class=cF0>)
|
||
|
<a name="l544"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'FUF'</span><span class=cF0>);
|
||
|
<a name="l545"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l546"></a> </span><span class=cF5>DrvLock</span><span class=cF0>(dv);
|
||
|
<a name="l547"></a> cur_dir_clus=</span><span class=cF5>Name2DirClus</span><span class=cF0>(dv,</span><span class=cF5>Fs</span><span class=cF0>->cur_dir);
|
||
|
<a name="l548"></a> buf2=</span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF3>BLK_SIZE</span><span class=cF0>);
|
||
|
<a name="l549"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,buf2,cur_dir_clus,1);
|
||
|
<a name="l550"></a>
|
||
|
<a name="l551"></a> ptr=buf2(</span><span class=cF1>U8</span><span class=cF0> *)-</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF0>);
|
||
|
<a name="l552"></a> buf=</span><span class=cF5>MAlloc</span><span class=cF0>(ptr->size);
|
||
|
<a name="l553"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,buf,cur_dir_clus,ptr->size>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l554"></a> </span><span class=cF5>Free</span><span class=cF0>(buf2);
|
||
|
<a name="l555"></a>
|
||
|
<a name="l556"></a> ptr=buf(</span><span class=cF1>U8</span><span class=cF0> *)-</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF0>);
|
||
|
<a name="l557"></a> *ptr->name=</span><span class=cF6>'.'</span><span class=cF0>;
|
||
|
<a name="l558"></a> ptr->name[1]=0;
|
||
|
<a name="l559"></a> ptr(</span><span class=cF1>U8</span><span class=cF0> *)+=</span><span class=cF3>CDIR_SIZE</span><span class=cF0>;
|
||
|
<a name="l560"></a> ptr->clus=</span><span class=cF5>Name2ParentDirClus</span><span class=cF0>(dv,</span><span class=cF5>Fs</span><span class=cF0>->cur_dir);
|
||
|
<a name="l561"></a> ptr(</span><span class=cF1>U8</span><span class=cF0> *)-=</span><span class=cF3>CDIR_SIZE</span><span class=cF0>;
|
||
|
<a name="l562"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF3>TRUE</span><span class=cF0>) {
|
||
|
<a name="l563"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>ch=*ptr->name</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l564"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l565"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>ptr->attr & </span><span class=cF3>RS_ATTR_DELETED</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l566"></a> tmpde=</span><span class=cF5>CAlloc</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="l567"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(&tmpde-></span><span class=cF1>start</span><span class=cF0>,&ptr-></span><span class=cF1>start</span><span class=cF0>,</span><span class=cF3>CDIR_SIZE</span><span class=cF0>);
|
||
|
<a name="l568"></a> tmpde->parent=parent;
|
||
|
<a name="l569"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&fuf_flags,</span><span class=cF3>FUf_RECURSE</span><span class=cF7>)</span><span class=cF0> && tmpde->attr&</span><span class=cF3>RS_ATTR_DIR</span><span class=cF0> &&
|
||
|
<a name="l570"></a> *tmpde->name!=</span><span class=cF6>'.'</span><span class=cF0>) {
|
||
|
<a name="l571"></a> tmpde->next=res;
|
||
|
<a name="l572"></a> res=tmpde;
|
||
|
<a name="l573"></a> tmpde->full_name=</span><span class=cF5>DirNameAbs</span><span class=cF0>(tmpde->name);
|
||
|
<a name="l574"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l575"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Cd</span><span class=cF7>(</span><span class=cF0>tmpde->name</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l576"></a> tmpde->sub=</span><span class=cFD>RedSeaFilesFind</span><span class=cF0>(files_find_mask,fuf_flags,tmpde);
|
||
|
<a name="l577"></a> </span><span class=cF5>Cd</span><span class=cF0>(</span><span class=cF6>".."</span><span class=cF0>);
|
||
|
<a name="l578"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l579"></a> </span><span class=cF5>DrvLock</span><span class=cF0>(dv);
|
||
|
<a name="l580"></a> } </span><span class=cF1>else</span><span class=cF0> {
|
||
|
<a name="l581"></a> tmpde->full_name=</span><span class=cF5>FileNameAbs</span><span class=cF0>(tmpde->name);
|
||
|
<a name="l582"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF7>(</span><span class=cF0>tmpde->attr&</span><span class=cF3>RS_ATTR_DIR</span><span class=cF0> ||
|
||
|
<a name="l583"></a> !</span><span class=cF5>Bt</span><span class=cF0>(&fuf_flags,</span><span class=cF3>FUf_JUST_DIRS</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0> &&
|
||
|
<a name="l584"></a> !</span><span class=cF7>(</span><span class=cF5>Bt</span><span class=cF0>(&fuf_flags,</span><span class=cF3>FUf_RECURSE</span><span class=cF0>) && *tmpde->name==</span><span class=cF6>'.'</span><span class=cF0> &&
|
||
|
<a name="l585"></a> tmpde->attr&</span><span class=cF3>RS_ATTR_DIR</span><span class=cF7>)</span><span class=cF0> &&
|
||
|
<a name="l586"></a> </span><span class=cF5>FilesFindMatch</span><span class=cF7>(</span><span class=cF0>tmpde->full_name,files_find_mask,fuf_flags</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l587"></a> tmpde->next=res;
|
||
|
<a name="l588"></a> res=tmpde;
|
||
|
<a name="l589"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l590"></a> </span><span class=cF5>DirEntryDel</span><span class=cF0>(tmpde);
|
||
|
<a name="l591"></a> }
|
||
|
<a name="l592"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l593"></a> ptr(</span><span class=cF1>U8</span><span class=cF0> *)+=</span><span class=cF3>CDIR_SIZE</span><span class=cF0>;
|
||
|
<a name="l594"></a> }
|
||
|
<a name="l595"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
|
||
|
<a name="l596"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l597"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
|
||
|
<a name="l598"></a> </span><span class=cF5>DrvUnlock</span><span class=cF0>(dv);
|
||
|
<a name="l599"></a> </span><span class=cF1>return</span><span class=cF0> res;
|
||
|
<a name="l600"></a>}
|
||
|
<a name="l601"></a>
|
||
|
<a name="l602"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cFD>RedSeaMkDir</span><span class=cF0>(</span><span class=cF9>CDrv</span><span class=cF0> *dv,</span><span class=cF1>U8</span><span class=cF0> *cur_dir,</span><span class=cF1>U8</span><span class=cF0> *name,</span><span class=cF9>I64</span><span class=cF0> entry_cnt)
|
||
|
<a name="l603"></a>{</span><span class=cF2>//entry_cnt is for preallocating dir blks.</span><span class=cF0>
|
||
|
<a name="l604"></a> </span><span class=cF9>I64</span><span class=cF0> c,cur_dir_clus=</span><span class=cF5>Name2DirClus</span><span class=cF0>(dv,cur_dir),
|
||
|
<a name="l605"></a> size=</span><span class=cF5>CeilU64</span><span class=cF0>(</span><span class=cF7>(</span><span class=cF0>entry_cnt+3</span><span class=cF7>)</span><span class=cF0><<6,</span><span class=cF3>BLK_SIZE</span><span class=cF0>);
|
||
|
<a name="l606"></a>#</span><span class=cF1>assert</span><span class=cF0> </span><span class=cF3>CDIR_SIZE</span><span class=cF0>==64
|
||
|
<a name="l607"></a> </span><span class=cF1>U8</span><span class=cF0> *buf=</span><span class=cF5>CAlloc</span><span class=cF0>(size);
|
||
|
<a name="l608"></a> </span><span class=cF9>CDirEntry</span><span class=cF0> *d_native=buf-</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CDirEntry</span><span class=cF0>.</span><span class=cF1>start</span><span class=cF0>);
|
||
|
<a name="l609"></a> </span><span class=cF1>Bool</span><span class=cF0> unlock_break;
|
||
|
<a name="l610"></a> </span><span class=cF1>try</span><span class=cF0> </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l611"></a> unlock_break=</span><span class=cF5>BreakLock</span><span class=cF0>;
|
||
|
<a name="l612"></a> c=</span><span class=cF5>FileWrite</span><span class=cF0>(name,buf,size,0,</span><span class=cF3>RS_ATTR_DIR</span><span class=cF0>);
|
||
|
<a name="l613"></a> d_native->attr=</span><span class=cF3>RS_ATTR_DIR</span><span class=cF0>|</span><span class=cF3>RS_ATTR_CONTIGUOUS</span><span class=cF0>;
|
||
|
<a name="l614"></a> </span><span class=cF5>StrCpy</span><span class=cF0>(d_native->name,name);
|
||
|
<a name="l615"></a> d_native->clus=c;
|
||
|
<a name="l616"></a> d_native->size=size;
|
||
|
<a name="l617"></a> d_native->datetime=</span><span class=cF5>Now</span><span class=cF0>;
|
||
|
<a name="l618"></a> d_native(</span><span class=cF1>U8</span><span class=cF0> *)+=</span><span class=cF3>CDIR_SIZE</span><span class=cF0>;
|
||
|
<a name="l619"></a>
|
||
|
<a name="l620"></a> d_native->attr=</span><span class=cF3>RS_ATTR_DIR</span><span class=cF0>|</span><span class=cF3>RS_ATTR_CONTIGUOUS</span><span class=cF0>;
|
||
|
<a name="l621"></a> *d_native->name=</span><span class=cF6>'.'</span><span class=cF0>;
|
||
|
<a name="l622"></a> d_native->name[1]=</span><span class=cF6>'.'</span><span class=cF0>;
|
||
|
<a name="l623"></a> d_native->name[2]=0;
|
||
|
<a name="l624"></a> d_native->clus=cur_dir_clus;
|
||
|
<a name="l625"></a> d_native->size=0;
|
||
|
<a name="l626"></a> d_native->datetime=</span><span class=cF5>Now</span><span class=cF0>;
|
||
|
<a name="l627"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,buf,c,1);
|
||
|
<a name="l628"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
|
||
|
<a name="l629"></a> </span><span class=cF1>if</span><span class=cF0> (unlock_break)
|
||
|
<a name="l630"></a> </span><span class=cF5>BreakUnlock</span><span class=cF0>;
|
||
|
<a name="l631"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>catch</span><span class=cF0>
|
||
|
<a name="l632"></a> </span><span class=cF1>if</span><span class=cF0> (unlock_break)
|
||
|
<a name="l633"></a> </span><span class=cF5>BreakUnlock</span><span class=cF0>;
|
||
|
<a name="l634"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l635"></a>}
|
||
|
</span></pre></body>
|
||
|
</html>
|