297 lines
28 KiB
Plaintext
297 lines
28 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=cF9>I64</span><span class=cF0> </span><span class=cF5>FSize</span><span class=cF0>(</span><span class=cF9>CFile</span><span class=cF0> *f)
|
||
|
<a name="l2"></a>{</span><span class=cF2>//Report size of opened file in bytes.</span><span class=cF0>
|
||
|
<a name="l3"></a> </span><span class=cF1>if</span><span class=cF0> (f)
|
||
|
<a name="l4"></a> </span><span class=cF1>return</span><span class=cF0> f->de.size;
|
||
|
<a name="l5"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l6"></a> </span><span class=cF1>return</span><span class=cF0> 0;
|
||
|
<a name="l7"></a>}
|
||
|
<a name="l8"></a>
|
||
|
<a name="l9"></a></span><span class=cF9>CFile</span><span class=cF0> *</span><span class=cF5>FOpen</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *filename,</span><span class=cF1>U8</span><span class=cF0> *flags,</span><span class=cF9>I64</span><span class=cF0> cnt=0)
|
||
|
<a name="l10"></a>{</span><span class=cF2>//Allows flags "r","w","w+". "c" for contiguous.</span><span class=cF0>
|
||
|
<a name="l11"></a></span><span class=cF2>//(It uses </span><a href="/Wb/Kernel/StrA.HC.HTML#l462"><span class=cF4>StrOcc</span></a><span class=cF2>() for 'w', 'r', '+', 'c')</span><span class=cF0>
|
||
|
<a name="l12"></a> </span><span class=cF9>CFile</span><span class=cF0> *f=</span><span class=cF5>CAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CFile</span><span class=cF7>)</span><span class=cF0>);
|
||
|
<a name="l13"></a> </span><span class=cF9>CDirContext</span><span class=cF0> *dirc;
|
||
|
<a name="l14"></a> </span><span class=cF1>U8</span><span class=cF0> *full_name;
|
||
|
<a name="l15"></a> </span><span class=cF1>Bool</span><span class=cF0> contiguous=</span><span class=cF5>StrOcc</span><span class=cF0>(flags,</span><span class=cF6>'c'</span><span class=cF0>);
|
||
|
<a name="l16"></a>
|
||
|
<a name="l17"></a> f->clus=</span><span class=cF3>INVALID_CLUS</span><span class=cF0>;
|
||
|
<a name="l18"></a> f->fblk_num=0;
|
||
|
<a name="l19"></a> </span><span class=cF1>if</span><span class=cF0> (cnt>0)
|
||
|
<a name="l20"></a> f->max_blk=cnt-1;
|
||
|
<a name="l21"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l22"></a> f->max_blk=</span><span class=cF3>I64_MAX</span><span class=cF0>;
|
||
|
<a name="l23"></a> f->file_clus_num=</span><span class=cF3>INVALID_CLUS</span><span class=cF0>;
|
||
|
<a name="l24"></a> full_name=</span><span class=cF5>FileNameAbs</span><span class=cF0>(filename);
|
||
|
<a name="l25"></a> f->dv=</span><span class=cF5>Let2Drv</span><span class=cF0>(*full_name);
|
||
|
<a name="l26"></a> </span><span class=cF1>if</span><span class=cF0> (f->dv->fs_type==</span><span class=cF3>FSt_REDSEA</span><span class=cF0>)
|
||
|
<a name="l27"></a> contiguous=</span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l28"></a> </span><span class=cF1>if</span><span class=cF0> (contiguous) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l29"></a> f->flags|=</span><span class=cF3>FF_CONTIGUOUS</span><span class=cF0>;
|
||
|
<a name="l30"></a> </span><span class=cF1>if</span><span class=cF0> (f->dv->fs_type!=</span><span class=cF3>FSt_REDSEA</span><span class=cF0> &&
|
||
|
<a name="l31"></a> !</span><span class=cF7>(</span><span class=cF5>FileAttr</span><span class=cF0>(filename) & </span><span class=cF3>RS_ATTR_CONTIGUOUS</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l32"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'File'</span><span class=cF0>);
|
||
|
<a name="l33"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l34"></a> f->clus_buf=</span><span class=cF5>CAlloc</span><span class=cF0>(f->dv->spc<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l35"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrOcc</span><span class=cF7>(</span><span class=cF0>flags,</span><span class=cF6>'w'</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l36"></a> f->flags=f->flags|</span><span class=cF3>FF_WRITE</span><span class=cF0>|</span><span class=cF3>FF_NEEDS_WRITE</span><span class=cF0>;
|
||
|
<a name="l37"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>StrOcc</span><span class=cF7>(</span><span class=cF0>flags,</span><span class=cF6>'+'</span><span class=cF7>)</span><span class=cF0>) {
|
||
|
<a name="l38"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>FileFind</span><span class=cF7>(</span><span class=cF0>full_name,&f->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="l39"></a> </span><span class=cF5>Free</span><span class=cF0>(full_name);
|
||
|
<a name="l40"></a> </span><span class=cF1>if</span><span class=cF0> (contiguous)
|
||
|
<a name="l41"></a> f->max_blk=(</span><span class=cF5>FSize</span><span class=cF7>(</span><span class=cF0>f</span><span class=cF7>)</span><span class=cF0>+</span><span class=cF3>BLK_SIZE</span><span class=cF0>-1)>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>-1;
|
||
|
<a name="l42"></a> </span><span class=cF1>return</span><span class=cF0> f;
|
||
|
<a name="l43"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l44"></a> } </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l45"></a> </span><span class=cF5>Del</span><span class=cF0>(full_name,,,</span><span class=cF3>FALSE</span><span class=cF0>);
|
||
|
<a name="l46"></a> f->de.full_name=full_name;
|
||
|
<a name="l47"></a> f->flags|=</span><span class=cF3>FF_NEW_FILE</span><span class=cF0>;
|
||
|
<a name="l48"></a> </span><span class=cF1>if</span><span class=cF0> (dirc=</span><span class=cF5>DirContextNew</span><span class=cF7>(</span><span class=cF0>full_name</span><span class=cF7>)</span><span class=cF0>) {
|
||
|
<a name="l49"></a> </span><span class=cF5>StrCpy</span><span class=cF0>(f->de.name,dirc->mask);
|
||
|
<a name="l50"></a> </span><span class=cF1>if</span><span class=cF0> (cnt>0) </span><span class=cF7>{</span><span class=cF2>//We pre-alloc the whole thing.</span><span class=cF0>
|
||
|
<a name="l51"></a> f->de.clus=</span><span class=cF5>ClusAlloc</span><span class=cF0>(f->dv,0,
|
||
|
<a name="l52"></a> </span><span class=cF7>(</span><span class=cF0>cnt+f->dv->spc-1</span><span class=cF7>)</span><span class=cF0>/f->dv->spc,contiguous);
|
||
|
<a name="l53"></a> f->de.size=cnt<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
|
||
|
<a name="l54"></a> </span><span class=cF5>DirNew</span><span class=cF0>(dirc->dv,</span><span class=cF5>Fs</span><span class=cF0>->cur_dir,&f->de,</span><span class=cF3>TRUE</span><span class=cF0>);
|
||
|
<a name="l55"></a> f->flags&=~</span><span class=cF3>FF_NEW_FILE</span><span class=cF0>;
|
||
|
<a name="l56"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l57"></a> </span><span class=cF5>DirContextDel</span><span class=cF0>(dirc);
|
||
|
<a name="l58"></a> </span><span class=cF1>return</span><span class=cF0> f;
|
||
|
<a name="l59"></a> }
|
||
|
<a name="l60"></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="l61"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>FileFind</span><span class=cF7>(</span><span class=cF0>full_name,&f->de,</span><span class=cF3>FUF_JUST_FILES</span><span class=cF7>)</span><span class=cF0>) {
|
||
|
<a name="l62"></a> </span><span class=cF5>Free</span><span class=cF0>(full_name);
|
||
|
<a name="l63"></a> f->max_blk=(</span><span class=cF5>FSize</span><span class=cF7>(</span><span class=cF0>f</span><span class=cF7>)</span><span class=cF0>+</span><span class=cF3>BLK_SIZE</span><span class=cF0>-1)>></span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>-1;
|
||
|
<a name="l64"></a> </span><span class=cF1>return</span><span class=cF0> f;
|
||
|
<a name="l65"></a> }
|
||
|
<a name="l66"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l67"></a> </span><span class=cF5>Free</span><span class=cF0>(f->clus_buf);
|
||
|
<a name="l68"></a> </span><span class=cF5>Free</span><span class=cF0>(full_name);
|
||
|
<a name="l69"></a> </span><span class=cF5>Free</span><span class=cF0>(f);
|
||
|
<a name="l70"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>;
|
||
|
<a name="l71"></a>}
|
||
|
<a name="l72"></a>
|
||
|
<a name="l73"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>FClose</span><span class=cF0>(</span><span class=cF9>CFile</span><span class=cF0> *f)
|
||
|
<a name="l74"></a>{</span><span class=cF2>//Close CFile, updating directory.</span><span class=cF0>
|
||
|
<a name="l75"></a> </span><span class=cF9>CDirContext</span><span class=cF0> *dirc;
|
||
|
<a name="l76"></a> </span><span class=cF1>if</span><span class=cF0> (f) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l77"></a> </span><span class=cF1>if</span><span class=cF0> (f->flags & </span><span class=cF3>FF_BUF_DIRTY</span><span class=cF0>) {
|
||
|
<a name="l78"></a> </span><span class=cF5>ClusWrite</span><span class=cF0>(f->dv,f->clus_buf,f->clus,1);
|
||
|
<a name="l79"></a> f->flags&=~</span><span class=cF3>FF_BUF_DIRTY</span><span class=cF0>;
|
||
|
<a name="l80"></a> }
|
||
|
<a name="l81"></a> </span><span class=cF1>if</span><span class=cF0> (f->flags & </span><span class=cF3>FF_NEEDS_WRITE</span><span class=cF0>) {
|
||
|
<a name="l82"></a> </span><span class=cF1>if</span><span class=cF0> (dirc=</span><span class=cF5>DirContextNew</span><span class=cF7>(</span><span class=cF0>f->de.full_name</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l83"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>f->flags & </span><span class=cF3>FF_USE_OLD_DATETIME</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l84"></a> f->de.datetime=</span><span class=cF5>Now</span><span class=cF0>;
|
||
|
<a name="l85"></a> </span><span class=cF1>if</span><span class=cF0> (f->flags & </span><span class=cF3>FF_NEW_FILE</span><span class=cF0>)
|
||
|
<a name="l86"></a> </span><span class=cF5>DirNew</span><span class=cF0>(dirc->dv,</span><span class=cF5>Fs</span><span class=cF0>->cur_dir,&f->de,</span><span class=cF3>TRUE</span><span class=cF0>);
|
||
|
<a name="l87"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l88"></a> </span><span class=cF5>DirNew</span><span class=cF0>(dirc->dv,</span><span class=cF5>Fs</span><span class=cF0>->cur_dir,&f->de,</span><span class=cF3>FALSE</span><span class=cF0>);
|
||
|
<a name="l89"></a> </span><span class=cF5>DirContextDel</span><span class=cF0>(dirc);
|
||
|
<a name="l90"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l91"></a> </span><span class=cF5>throw</span><span class=cF0>(</span><span class=cF6>'File'</span><span class=cF0>);
|
||
|
<a name="l92"></a> }
|
||
|
<a name="l93"></a> </span><span class=cF5>Free</span><span class=cF0>(f->clus_buf);
|
||
|
<a name="l94"></a> </span><span class=cF5>Free</span><span class=cF0>(f->de.full_name);
|
||
|
<a name="l95"></a> </span><span class=cF5>Free</span><span class=cF0>(f);
|
||
|
<a name="l96"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l97"></a>}
|
||
|
<a name="l98"></a>
|
||
|
<a name="l99"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFD>FSetClus</span><span class=cF0>(</span><span class=cF9>CFile</span><span class=cF0> *f,</span><span class=cF9>I64</span><span class=cF0> c,</span><span class=cF9>I64</span><span class=cF0> blk,</span><span class=cF1>Bool</span><span class=cF0> read)
|
||
|
<a name="l100"></a>{
|
||
|
<a name="l101"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv=f->dv;
|
||
|
<a name="l102"></a> </span><span class=cF9>I64</span><span class=cF0> i;
|
||
|
<a name="l103"></a> </span><span class=cF1>if</span><span class=cF0> (f->clus!=c) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l104"></a> </span><span class=cF1>if</span><span class=cF0> (f->flags & </span><span class=cF3>FF_BUF_DIRTY</span><span class=cF0>) {
|
||
|
<a name="l105"></a> i=dv->spc;
|
||
|
<a name="l106"></a> </span><span class=cF1>if</span><span class=cF0> (f->max_blk!=</span><span class=cF3>I64_MAX</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l107"></a> i=f->max_blk+1-f->file_clus_num*dv->spc;
|
||
|
<a name="l108"></a> </span><span class=cF1>if</span><span class=cF0> (i>dv->spc)
|
||
|
<a name="l109"></a> i=dv->spc;
|
||
|
<a name="l110"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l111"></a> </span><span class=cF5>ClusBlkWrite</span><span class=cF0>(dv,f->clus_buf,f->clus,i);
|
||
|
<a name="l112"></a> f->flags=f->flags & ~</span><span class=cF3>FF_BUF_DIRTY</span><span class=cF0>;
|
||
|
<a name="l113"></a> }
|
||
|
<a name="l114"></a> f->clus=c;
|
||
|
<a name="l115"></a> f->file_clus_num=blk/dv->spc;
|
||
|
<a name="l116"></a> </span><span class=cF1>if</span><span class=cF0> (read) {
|
||
|
<a name="l117"></a> i=dv->spc;
|
||
|
<a name="l118"></a> </span><span class=cF1>if</span><span class=cF0> (f->max_blk!=</span><span class=cF3>I64_MAX</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l119"></a> i=f->max_blk+1-f->file_clus_num*dv->spc;
|
||
|
<a name="l120"></a> </span><span class=cF1>if</span><span class=cF0> (i>dv->spc)
|
||
|
<a name="l121"></a> i=dv->spc;
|
||
|
<a name="l122"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l123"></a> c=</span><span class=cF5>ClusBlkRead</span><span class=cF0>(dv,f->clus_buf,c,i);
|
||
|
<a name="l124"></a> }
|
||
|
<a name="l125"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l126"></a> </span><span class=cF1>return</span><span class=cF0> c;
|
||
|
<a name="l127"></a>}
|
||
|
<a name="l128"></a>
|
||
|
<a name="l129"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>FBlkRead</span><span class=cF0>(</span><span class=cF9>CFile</span><span class=cF0> *f,</span><span class=cF1>U8</span><span class=cF0> *buf,</span><span class=cF9>I64</span><span class=cF0> blk=</span><span class=cF3>FFB_NEXT_BLK</span><span class=cF0>,</span><span class=cF9>I64</span><span class=cF0> cnt=1)
|
||
|
<a name="l130"></a>{</span><span class=cF2>//Read [nth,n+cnt) blks of file.</span><span class=cF0>
|
||
|
<a name="l131"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv=f->dv;
|
||
|
<a name="l132"></a> </span><span class=cF9>I64</span><span class=cF0> spc=dv->spc,i,j,c=f->de.clus;
|
||
|
<a name="l133"></a> </span><span class=cF1>if</span><span class=cF0> (!f || !dv) </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l134"></a> </span><span class=cF1>if</span><span class=cF0> (blk==</span><span class=cF3>FFB_NEXT_BLK</span><span class=cF0>)
|
||
|
<a name="l135"></a> blk=f->fblk_num;
|
||
|
<a name="l136"></a> </span><span class=cF1>if</span><span class=cF0> (blk+cnt-1>f->max_blk)
|
||
|
<a name="l137"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l138"></a> </span><span class=cF1>if</span><span class=cF0> (cnt<=0) </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l139"></a>
|
||
|
<a name="l140"></a> </span><span class=cF1>if</span><span class=cF0> (f->flags & </span><span class=cF3>FF_CONTIGUOUS</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l141"></a> </span><span class=cF5>BlkRead</span><span class=cF0>(dv,buf,</span><span class=cF5>Clus2Blk</span><span class=cF7>(</span><span class=cF0>dv,c</span><span class=cF7>)</span><span class=cF0>+blk,cnt);
|
||
|
<a name="l142"></a> blk+=cnt;
|
||
|
<a name="l143"></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="l144"></a> i=blk/spc;
|
||
|
<a name="l145"></a> </span><span class=cF1>if</span><span class=cF0> (0<=f->file_clus_num<=i) {
|
||
|
<a name="l146"></a> c=f->clus;
|
||
|
<a name="l147"></a> i-=f->file_clus_num;
|
||
|
<a name="l148"></a> }
|
||
|
<a name="l149"></a> </span><span class=cF1>if</span><span class=cF0> (i>0)
|
||
|
<a name="l150"></a> c=</span><span class=cF5>ClusNumNext</span><span class=cF0>(dv,c,i);
|
||
|
<a name="l151"></a>
|
||
|
<a name="l152"></a> </span><span class=cF1>if</span><span class=cF0> (i=blk%spc) {
|
||
|
<a name="l153"></a> c=</span><span class=cFD>FSetClus</span><span class=cF0>(f,c,blk,</span><span class=cF3>TRUE</span><span class=cF0>);
|
||
|
<a name="l154"></a> </span><span class=cF1>if</span><span class=cF0> (cnt<spc-i)
|
||
|
<a name="l155"></a> j=cnt;
|
||
|
<a name="l156"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l157"></a> j=spc-i;
|
||
|
<a name="l158"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(buf,f->clus_buf+i<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>,j<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l159"></a> buf+=j<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
|
||
|
<a name="l160"></a> cnt-=j;
|
||
|
<a name="l161"></a> blk+=j;
|
||
|
<a name="l162"></a> }
|
||
|
<a name="l163"></a> </span><span class=cF1>while</span><span class=cF0> (cnt>=spc) {
|
||
|
<a name="l164"></a> c=</span><span class=cFD>FSetClus</span><span class=cF0>(f,c,blk,</span><span class=cF3>TRUE</span><span class=cF0>);
|
||
|
<a name="l165"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(buf,f->clus_buf,spc<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l166"></a> buf+=spc<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
|
||
|
<a name="l167"></a> cnt-=spc;
|
||
|
<a name="l168"></a> blk+=spc;
|
||
|
<a name="l169"></a> }
|
||
|
<a name="l170"></a> </span><span class=cF1>if</span><span class=cF0> (cnt>0) {
|
||
|
<a name="l171"></a> c=</span><span class=cFD>FSetClus</span><span class=cF0>(f,c,blk,</span><span class=cF3>TRUE</span><span class=cF0>);
|
||
|
<a name="l172"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(buf,f->clus_buf,cnt<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l173"></a> buf+=cnt<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
|
||
|
<a name="l174"></a> blk+=cnt;
|
||
|
<a name="l175"></a> }
|
||
|
<a name="l176"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l177"></a> f->fblk_num=blk;
|
||
|
<a name="l178"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l179"></a>}
|
||
|
<a name="l180"></a>
|
||
|
<a name="l181"></a></span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>FBlkWrite</span><span class=cF0>(</span><span class=cF9>CFile</span><span class=cF0> *f,</span><span class=cF1>U8</span><span class=cF0> *buf,</span><span class=cF9>I64</span><span class=cF0> blk=</span><span class=cF3>FFB_NEXT_BLK</span><span class=cF0>,</span><span class=cF9>I64</span><span class=cF0> cnt=1)
|
||
|
<a name="l182"></a>{</span><span class=cF2>//Write [nth,n+cnt) blks of file.</span><span class=cF0>
|
||
|
<a name="l183"></a> </span><span class=cF9>CDrv</span><span class=cF0> *dv=f->dv;
|
||
|
<a name="l184"></a> </span><span class=cF9>I64</span><span class=cF0> spc=dv->spc,i,j,c=f->de.clus,c1;
|
||
|
<a name="l185"></a> </span><span class=cF1>if</span><span class=cF0> (!f || !dv) </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l186"></a> </span><span class=cF1>if</span><span class=cF0> (blk==</span><span class=cF3>FFB_NEXT_BLK</span><span class=cF0>)
|
||
|
<a name="l187"></a> blk=f->fblk_num;
|
||
|
<a name="l188"></a> </span><span class=cF1>if</span><span class=cF0> (blk+cnt-1>f->max_blk)
|
||
|
<a name="l189"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l190"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>f->flags & </span><span class=cF3>FF_WRITE</span><span class=cF7>)</span><span class=cF0>)
|
||
|
<a name="l191"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
|
||
|
<a name="l192"></a> </span><span class=cF1>if</span><span class=cF0> (cnt<=0) </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l193"></a> </span><span class=cF1>if</span><span class=cF0> (f->flags & </span><span class=cF3>FF_CONTIGUOUS</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l194"></a> </span><span class=cF5>BlkWrite</span><span class=cF0>(dv,buf,</span><span class=cF5>Clus2Blk</span><span class=cF7>(</span><span class=cF0>dv,c</span><span class=cF7>)</span><span class=cF0>+blk,cnt);
|
||
|
<a name="l195"></a> blk+=cnt;
|
||
|
<a name="l196"></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="l197"></a> </span><span class=cF1>if</span><span class=cF0> (!c) {
|
||
|
<a name="l198"></a> c=</span><span class=cF5>ClusAlloc</span><span class=cF0>(dv,0,1,</span><span class=cF3>FALSE</span><span class=cF0>);
|
||
|
<a name="l199"></a> f->file_clus_num=0;
|
||
|
<a name="l200"></a> f->clus=c;
|
||
|
<a name="l201"></a> f->de.clus=c;
|
||
|
<a name="l202"></a> f->flags|=</span><span class=cF3>FF_NEEDS_WRITE</span><span class=cF0>|</span><span class=cF3>FF_NEW_FILE</span><span class=cF0>;
|
||
|
<a name="l203"></a> }
|
||
|
<a name="l204"></a> i=blk/spc;
|
||
|
<a name="l205"></a> </span><span class=cF1>if</span><span class=cF0> (0<=f->file_clus_num<=i) {
|
||
|
<a name="l206"></a> c=f->clus;
|
||
|
<a name="l207"></a> i-=f->file_clus_num;
|
||
|
<a name="l208"></a> }
|
||
|
<a name="l209"></a> </span><span class=cF1>while</span><span class=cF0> (i>0) {
|
||
|
<a name="l210"></a> c1=c;
|
||
|
<a name="l211"></a> c=</span><span class=cF5>ClusNumNext</span><span class=cF0>(dv,c1,1);
|
||
|
<a name="l212"></a> </span><span class=cF1>if</span><span class=cF0> (c==</span><span class=cF3>INVALID_CLUS</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l213"></a> c=</span><span class=cF5>ClusAlloc</span><span class=cF0>(dv,c1,i,</span><span class=cF3>FALSE</span><span class=cF0>);
|
||
|
<a name="l214"></a> </span><span class=cF1>if</span><span class=cF0> (i>1)
|
||
|
<a name="l215"></a> c=</span><span class=cF5>ClusNumNext</span><span class=cF0>(dv,c,i-1);
|
||
|
<a name="l216"></a> </span><span class=cF1>break</span><span class=cF0>;
|
||
|
<a name="l217"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l218"></a> i--;
|
||
|
<a name="l219"></a> }
|
||
|
<a name="l220"></a>
|
||
|
<a name="l221"></a> </span><span class=cF1>if</span><span class=cF0> (i=blk%spc) {
|
||
|
<a name="l222"></a> </span><span class=cFD>FSetClus</span><span class=cF0>(f,c,blk,</span><span class=cF3>TRUE</span><span class=cF0>);
|
||
|
<a name="l223"></a> </span><span class=cF1>if</span><span class=cF0> (cnt<spc-i)
|
||
|
<a name="l224"></a> j=cnt;
|
||
|
<a name="l225"></a> </span><span class=cF1>else</span><span class=cF0>
|
||
|
<a name="l226"></a> j=spc-i;
|
||
|
<a name="l227"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(f->clus_buf+</span><span class=cF3>BLK_SIZE</span><span class=cF0>*i,buf,j<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l228"></a> f->flags|=</span><span class=cF3>FF_BUF_DIRTY</span><span class=cF0>;
|
||
|
<a name="l229"></a> buf+=j<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
|
||
|
<a name="l230"></a> cnt-=j;
|
||
|
<a name="l231"></a> blk+=j;
|
||
|
<a name="l232"></a> </span><span class=cF1>if</span><span class=cF0> (cnt>0) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l233"></a> c1=c;
|
||
|
<a name="l234"></a> c=</span><span class=cF5>ClusNumNext</span><span class=cF0>(dv,c1,1);
|
||
|
<a name="l235"></a> </span><span class=cF1>if</span><span class=cF0> (c==</span><span class=cF3>INVALID_CLUS</span><span class=cF0>)
|
||
|
<a name="l236"></a> c=</span><span class=cF5>ClusAlloc</span><span class=cF0>(dv,c1,1,</span><span class=cF3>FALSE</span><span class=cF0>);
|
||
|
<a name="l237"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l238"></a> }
|
||
|
<a name="l239"></a> </span><span class=cF1>while</span><span class=cF0> (cnt>=spc) {
|
||
|
<a name="l240"></a> </span><span class=cFD>FSetClus</span><span class=cF0>(f,c,blk,</span><span class=cF3>FALSE</span><span class=cF0>);
|
||
|
<a name="l241"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(f->clus_buf,buf,spc<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l242"></a> f->flags|=</span><span class=cF3>FF_BUF_DIRTY</span><span class=cF0>;
|
||
|
<a name="l243"></a> buf+=spc<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
|
||
|
<a name="l244"></a> cnt-=spc;
|
||
|
<a name="l245"></a> blk+=spc;
|
||
|
<a name="l246"></a> </span><span class=cF1>if</span><span class=cF0> (cnt>0) </span><span class=cF7>{</span><span class=cF0>
|
||
|
<a name="l247"></a> c1=c;
|
||
|
<a name="l248"></a> c=</span><span class=cF5>ClusNumNext</span><span class=cF0>(dv,c1,1);
|
||
|
<a name="l249"></a> </span><span class=cF1>if</span><span class=cF0> (c==</span><span class=cF3>INVALID_CLUS</span><span class=cF0>)
|
||
|
<a name="l250"></a> c=</span><span class=cF5>ClusAlloc</span><span class=cF0>(dv,c1,1,</span><span class=cF3>FALSE</span><span class=cF0>);
|
||
|
<a name="l251"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l252"></a> }
|
||
|
<a name="l253"></a> </span><span class=cF1>if</span><span class=cF0> (cnt>0) {
|
||
|
<a name="l254"></a> </span><span class=cFD>FSetClus</span><span class=cF0>(f,c,blk,</span><span class=cF3>TRUE</span><span class=cF0>);
|
||
|
<a name="l255"></a> </span><span class=cF5>MemCpy</span><span class=cF0>(f->clus_buf,buf,cnt<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>);
|
||
|
<a name="l256"></a> f->flags|=</span><span class=cF3>FF_BUF_DIRTY</span><span class=cF0>;
|
||
|
<a name="l257"></a> buf+=cnt<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
|
||
|
<a name="l258"></a> blk+=cnt;
|
||
|
<a name="l259"></a> }
|
||
|
<a name="l260"></a> </span><span class=cF1>if</span><span class=cF0> (f->de.size<blk<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>)
|
||
|
<a name="l261"></a> f->de.size=blk<<</span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>;
|
||
|
<a name="l262"></a> </span><span class=cF7>}</span><span class=cF0>
|
||
|
<a name="l263"></a> f->fblk_num=blk;
|
||
|
<a name="l264"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
|
||
|
<a name="l265"></a>}
|
||
|
</span></pre></body>
|
||
|
</html>
|