<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=US-ASCII"> <meta name="generator" content="ZealOS V1.09"> <style type="text/css"> body {background-color:#1f1f1f;} .cF0{color:#e3e3e3;background-color:#1f1f1f;} .cF1{color:#4f84a6;background-color:#1f1f1f;} .cF2{color:#73a255;background-color:#1f1f1f;} .cF3{color:#297582;background-color:#1f1f1f;} .cF4{color:#b34f4b;background-color:#1f1f1f;} .cF5{color:#8a52c3;background-color:#1f1f1f;} .cF6{color:#b7822f;background-color:#1f1f1f;} .cF7{color:#444444;background-color:#1f1f1f;} .cF8{color:#6d6d6d;background-color:#1f1f1f;} .cF9{color:#94bfde;background-color:#1f1f1f;} .cFA{color:#a1ce97;background-color:#1f1f1f;} .cFB{color:#6db4be;background-color:#1f1f1f;} .cFC{color:#e88e88;background-color:#1f1f1f;} .cFD{color:#ca94e8;background-color:#1f1f1f;} .cFE{color:#d4b475;background-color:#1f1f1f;} .cFF{color:#1f1f1f;background-color:#1f1f1f;} </style> </head> <body> <pre style="font-family:monospace;font-size:12pt"> <a name="l1"></a><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>DiskCacheInit</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> size_in_U8s) <a name="l2"></a>{ <a name="l3"></a> </span><span class=cF9>CCacheBlk</span><span class=cF0> *tmpc; <a name="l4"></a> </span><span class=cF9>I64</span><span class=cF0> i, count; <a name="l5"></a> <a name="l6"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_DISK_CACHE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>) <a name="l7"></a> </span><span class=cF5>Yield</span><span class=cF0>; <a name="l8"></a> </span><span class=cF5>Free</span><span class=cF0>(</span><span class=cFB>blkdev</span><span class=cF0>.cache_ctrl); <a name="l9"></a> </span><span class=cF5>Free</span><span class=cF0>(</span><span class=cFB>blkdev</span><span class=cF0>.cache_base); <a name="l10"></a> </span><span class=cF5>Free</span><span class=cF0>(</span><span class=cFB>blkdev</span><span class=cF0>.cache_hash_table); <a name="l11"></a> </span><span class=cF1>if</span><span class=cF0> (size_in_U8s < </span><span class=cFE>0x2000</span><span class=cF0>) <a name="l12"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l13"></a> </span><span class=cFB>blkdev</span><span class=cF0>.cache_ctrl = </span><span class=cF3>NULL</span><span class=cF0>; <a name="l14"></a> </span><span class=cFB>blkdev</span><span class=cF0>.cache_base = </span><span class=cF3>NULL</span><span class=cF0>; <a name="l15"></a> </span><span class=cFB>blkdev</span><span class=cF0>.cache_hash_table = </span><span class=cF3>NULL</span><span class=cF0>; <a name="l16"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l17"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l18"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l19"></a> </span><span class=cFB>blkdev</span><span class=cF0>.cache_ctrl = </span><span class=cF5>SysCAlloc</span><span class=cF0>(</span><span class=cF1>offset</span><span class=cF7>(</span><span class=cF9>CCacheBlk</span><span class=cF0>.body</span><span class=cF7>)</span><span class=cF0>); <a name="l20"></a> </span><span class=cFB>blkdev</span><span class=cF0>.cache_base = </span><span class=cF5>SysMAlloc</span><span class=cF0>(size_in_U8s); <a name="l21"></a> </span><span class=cF5>QueueInit</span><span class=cF0>(</span><span class=cFB>blkdev</span><span class=cF0>.cache_ctrl); <a name="l22"></a> <a name="l23"></a> count = </span><span class=cF5>MSize</span><span class=cF0>(</span><span class=cFB>blkdev</span><span class=cF0>.cache_base) / </span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF9>CCacheBlk</span><span class=cF0>); <a name="l24"></a> </span><span class=cFB>blkdev</span><span class=cF0>.cache_size = count * </span><span class=cF3>BLK_SIZE</span><span class=cF0>; <a name="l25"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < count; i++) <a name="l26"></a> { <a name="l27"></a> tmpc = </span><span class=cFB>blkdev</span><span class=cF0>.cache_base+i; <a name="l28"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(tmpc, </span><span class=cFB>blkdev</span><span class=cF0>.cache_ctrl->last_lru); <a name="l29"></a> tmpc->next_hash = tmpc->last_hash = tmpc; <a name="l30"></a> tmpc->drive = </span><span class=cF3>NULL</span><span class=cF0>; <a name="l31"></a> tmpc->blk = </span><span class=cFE>0</span><span class=cF0>; <a name="l32"></a> } <a name="l33"></a> <a name="l34"></a> </span><span class=cFB>blkdev</span><span class=cF0>.cache_hash_table = </span><span class=cF5>SysMAlloc</span><span class=cF0>(</span><span class=cF3>DISK_CACHE_HASH_SIZE</span><span class=cF0> * </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0> * </span><span class=cFE>2</span><span class=cF0>); <a name="l35"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i < </span><span class=cF3>DISK_CACHE_HASH_SIZE</span><span class=cF0>; i++) <a name="l36"></a> { <a name="l37"></a> tmpc = </span><span class=cFB>blkdev</span><span class=cF0>.cache_hash_table(</span><span class=cF1>U8</span><span class=cF0> *) + i * </span><span class=cF1>sizeof</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *) * </span><span class=cFE>2</span><span class=cF0> - </span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CCacheBlk</span><span class=cF0>.next_hash); <a name="l38"></a> tmpc->next_hash = tmpc->last_hash = tmpc; <a name="l39"></a> } <a name="l40"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l41"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_DISK_CACHE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>); <a name="l42"></a>} <a name="l43"></a> <a name="l44"></a></span><span class=cF9>I64</span><span class=cF0> </span><span class=cFD>DiskCacheHash</span><span class=cF0>(</span><span class=cF9>I64</span><span class=cF0> blk) <a name="l45"></a>{ <a name="l46"></a> </span><span class=cF9>I64</span><span class=cF0> i = blk & (</span><span class=cF3>DISK_CACHE_HASH_SIZE</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>); <a name="l47"></a> <a name="l48"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFB>blkdev</span><span class=cF0>.cache_hash_table(</span><span class=cF1>U8</span><span class=cF0> *) + i << </span><span class=cFE>4</span><span class=cF0> - </span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CCacheBlk</span><span class=cF0>.next_hash); <a name="l49"></a>} <a name="l50"></a> <a name="l51"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>DiskCacheQueueRemove</span><span class=cF0>(</span><span class=cF9>CCacheBlk</span><span class=cF0> *tmpc) <a name="l52"></a>{ <a name="l53"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(tmpc); <a name="l54"></a> tmpc->next_hash->last_hash = tmpc->last_hash; <a name="l55"></a> tmpc->last_hash->next_hash = tmpc->next_hash; <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>DiskCacheQueueIns</span><span class=cF0>(</span><span class=cF9>CCacheBlk</span><span class=cF0> *tmpc) <a name="l59"></a>{ <a name="l60"></a> </span><span class=cF9>CCacheBlk</span><span class=cF0> *tmp_n, *tmp_l; <a name="l61"></a> <a name="l62"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(tmpc, </span><span class=cFB>blkdev</span><span class=cF0>.cache_ctrl->last_lru); <a name="l63"></a> tmp_l = </span><span class=cFD>DiskCacheHash</span><span class=cF0>(tmpc->blk); <a name="l64"></a> tmp_n = tmp_l->next_hash; <a name="l65"></a> tmpc->last_hash = tmp_l; <a name="l66"></a> tmpc->next_hash = tmp_n; <a name="l67"></a> tmp_l->next_hash = tmp_n->last_hash = tmpc; <a name="l68"></a>} <a name="l69"></a> <a name="l70"></a></span><span class=cF9>CCacheBlk</span><span class=cF0> *</span><span class=cFD>DiskCacheFind</span><span class=cF0>(</span><span class=cF9>CDrive</span><span class=cF0> *drive, </span><span class=cF9>I64</span><span class=cF0> blk) <a name="l71"></a>{ <a name="l72"></a> </span><span class=cF9>CCacheBlk</span><span class=cF0> *tmpc, *tmpc1 = </span><span class=cFD>DiskCacheHash</span><span class=cF0>(blk); <a name="l73"></a> <a name="l74"></a> tmpc = tmpc1->next_hash; <a name="l75"></a> </span><span class=cF1>while</span><span class=cF0> (tmpc != tmpc1) <a name="l76"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l77"></a> </span><span class=cF1>if</span><span class=cF0> (tmpc->drive == drive && tmpc->blk == blk) <a name="l78"></a> </span><span class=cF1>return</span><span class=cF0> tmpc; <a name="l79"></a> tmpc = tmpc->next_hash; <a name="l80"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l81"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>NULL</span><span class=cF0>; <a name="l82"></a>} <a name="l83"></a> <a name="l84"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>DiskCacheAdd</span><span class=cF0>(</span><span class=cF9>CDrive</span><span class=cF0> *drive, </span><span class=cF1>U8</span><span class=cF0> *buf, </span><span class=cF9>I64</span><span class=cF0> blk, </span><span class=cF9>I64</span><span class=cF0> count) <a name="l85"></a>{ <a name="l86"></a> </span><span class=cF9>CCacheBlk</span><span class=cF0> *tmpc; <a name="l87"></a> <a name="l88"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>blkdev</span><span class=cF0>.cache_base) <a name="l89"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l90"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_DISK_CACHE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>) <a name="l91"></a> </span><span class=cF5>Yield</span><span class=cF0>; <a name="l92"></a> </span><span class=cF1>while</span><span class=cF0> (count-- > </span><span class=cFE>0</span><span class=cF0>) <a name="l93"></a> { <a name="l94"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF7>(</span><span class=cF0>tmpc = </span><span class=cFD>DiskCacheFind</span><span class=cF0>(drive, blk)</span><span class=cF7>)</span><span class=cF0>) <a name="l95"></a> tmpc = </span><span class=cFB>blkdev</span><span class=cF0>.cache_ctrl->next_lru; <a name="l96"></a> </span><span class=cFD>DiskCacheQueueRemove</span><span class=cF0>(tmpc); <a name="l97"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(&tmpc->body, buf, </span><span class=cF3>BLK_SIZE</span><span class=cF0>); <a name="l98"></a> tmpc->drive = drive; <a name="l99"></a> tmpc->blk = blk; <a name="l100"></a> </span><span class=cFD>DiskCacheQueueIns</span><span class=cF0>(tmpc); <a name="l101"></a> blk++; <a name="l102"></a> buf += </span><span class=cF3>BLK_SIZE</span><span class=cF0>; <a name="l103"></a> } <a name="l104"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_DISK_CACHE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>); <a name="l105"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l106"></a>} <a name="l107"></a> <a name="l108"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>DiskCacheInvalidate2</span><span class=cF0>(</span><span class=cF9>CDrive</span><span class=cF0> *drive) <a name="l109"></a>{ <a name="l110"></a> </span><span class=cF9>CCacheBlk</span><span class=cF0> *tmpc, *tmpc1; <a name="l111"></a> <a name="l112"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>blkdev</span><span class=cF0>.cache_base) <a name="l113"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l114"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_DISK_CACHE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>) <a name="l115"></a> </span><span class=cF5>Yield</span><span class=cF0>; <a name="l116"></a> tmpc = </span><span class=cFB>blkdev</span><span class=cF0>.cache_ctrl->last_lru; <a name="l117"></a> </span><span class=cF1>while</span><span class=cF0> (tmpc != </span><span class=cFB>blkdev</span><span class=cF0>.cache_ctrl) <a name="l118"></a> { <a name="l119"></a> tmpc1 = tmpc->last_lru; <a name="l120"></a> </span><span class=cF1>if</span><span class=cF0> (tmpc->drive == drive) <a name="l121"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l122"></a> </span><span class=cFD>DiskCacheQueueRemove</span><span class=cF0>(tmpc); <a name="l123"></a> tmpc->drive = </span><span class=cF3>NULL</span><span class=cF0>; <a name="l124"></a> tmpc->blk = </span><span class=cFE>0</span><span class=cF0>; <a name="l125"></a> tmpc->next_hash = tmpc->last_hash = tmpc; <a name="l126"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(tmpc, </span><span class=cFB>blkdev</span><span class=cF0>.cache_ctrl->last_lru); <a name="l127"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l128"></a> tmpc = tmpc1; <a name="l129"></a> } <a name="l130"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_DISK_CACHE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>); <a name="l131"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l132"></a>} <a name="l133"></a> <a name="l134"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cFD>RCache</span><span class=cF0>(</span><span class=cF9>CDrive</span><span class=cF0> *drive, </span><span class=cF1>U8</span><span class=cF0> **_buf, </span><span class=cF9>I64</span><span class=cF0> *_blk, </span><span class=cF9>I64</span><span class=cF0> *_count) <a name="l135"></a>{ <a name="l136"></a> </span><span class=cF9>CCacheBlk</span><span class=cF0> *tmpc; <a name="l137"></a> <a name="l138"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cFB>blkdev</span><span class=cF0>.cache_base) <a name="l139"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l140"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_DISK_CACHE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>) <a name="l141"></a> </span><span class=cF5>Yield</span><span class=cF0>; <a name="l142"></a></span><span class=cF2>//fetch leading blocks from cache</span><span class=cF0> <a name="l143"></a> </span><span class=cF1>while</span><span class=cF0> (*_count > </span><span class=cFE>0</span><span class=cF0>) <a name="l144"></a> { <a name="l145"></a> </span><span class=cF1>if</span><span class=cF0> (tmpc = </span><span class=cFD>DiskCacheFind</span><span class=cF7>(</span><span class=cF0>drive, *_blk</span><span class=cF7>)</span><span class=cF0>) <a name="l146"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l147"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(*_buf, &tmpc->body, </span><span class=cF3>BLK_SIZE</span><span class=cF0>); <a name="l148"></a> *_count -= </span><span class=cFE>1</span><span class=cF0>; <a name="l149"></a> *_buf += </span><span class=cF3>BLK_SIZE</span><span class=cF0>; <a name="l150"></a> *_blk += </span><span class=cFE>1</span><span class=cF0>; <a name="l151"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l152"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l153"></a> </span><span class=cF1>break</span><span class=cF0>; <a name="l154"></a> } <a name="l155"></a></span><span class=cF2>//fetch trailing blocks from cache</span><span class=cF0> <a name="l156"></a> </span><span class=cF1>while</span><span class=cF0> (*_count > </span><span class=cFE>0</span><span class=cF0>) <a name="l157"></a> { <a name="l158"></a> </span><span class=cF1>if</span><span class=cF0> (tmpc = </span><span class=cFD>DiskCacheFind</span><span class=cF7>(</span><span class=cF0>drive, *_blk + *_count - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0>) <a name="l159"></a> </span><span class=cF7>{</span><span class=cF0> <a name="l160"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(*_buf + </span><span class=cF7>(</span><span class=cF0>*_count - </span><span class=cFE>1</span><span class=cF7>)</span><span class=cF0> << </span><span class=cF3>BLK_SIZE_BITS</span><span class=cF0>, &tmpc->body, </span><span class=cF3>BLK_SIZE</span><span class=cF0>); <a name="l161"></a> *_count -= </span><span class=cFE>1</span><span class=cF0>; <a name="l162"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l163"></a> </span><span class=cF1>else</span><span class=cF0> <a name="l164"></a> </span><span class=cF1>break</span><span class=cF0>; <a name="l165"></a> } <a name="l166"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_DISK_CACHE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>); <a name="l167"></a> </span><span class=cF7>}</span><span class=cF0> <a name="l168"></a>} </span></pre></body> </html>