📄 filesys_8c-source.html
字号:
00161 ConsoleWrite(<span class="stringliteral">"Writing clusterchain from: "</span>); ConsolePutUInt(currentCluster);00162 ConsoleWrite(<span class="stringliteral">"Fragment size (sectors): "</span>); ConsolePutUInt(fragSize);00163 ConsoleWrite(<span class="stringliteral">"FatPageSector: "</span>); ConsolePutUInt(fatPageSector);00164 ConsoleWrite(<span class="stringliteral">"EntryNumber: "</span>); ConsolePutUInt(entryNumber);00165 00166 00167 <span class="comment">// WRITE CLUSTER CHAIN TO FIRST FAT</span>00168 00169 <span class="keywordflow">while</span> (fragSize><a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>){ 00170 <span class="comment">// while more than 1 cluster left...</span>00171 00172 <span class="comment">// is the FAT clusterchain page changed?</span>00173 <span class="keywordflow">if</span> (<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> != fatPageSector){00174 <span class="comment">// Yes, have we advanced by 1 sector?</span>00175 <span class="keywordflow">if</span> (<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> == (fatPageSector - 1)){00176 <span class="comment">//Yes, we must save the edited sector</span>00177 <a class="code" href="storage_8h.html#a4">WriteDiskSector</a> (<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>);00179 }00180 <span class="comment">// at least we need to load the new clusterchain page</span>00181 <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> = fatPageSector;00182 <a class="code" href="storage_8h.html#a2">ReadDiskSector</a>(<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>);00183 }<span class="comment">//Load/Save FAT sector</span>00184 00185 00186 <span class="comment">// Register Middle Entry</span>00187 currentCluster++; <span class="comment">//advancce to next cluster</span>00188 00189 <span class="comment">//fragSize-=fatSectorsPerCluster; //we will register one cluster</span>00190 <span class="comment">//to avoid memory spill in C compiler, the preceding line is written as:</span>00191 <span class="keywordflow">for</span> (<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o0">c</a> = <a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>;<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o0">c</a>;<a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o0">c</a>--){00192 fragSize--;00193 }00194 00195 <span class="keywordflow">if</span> (<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){00196 <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o4">Fat32Table</a>[entryNumber]=currentCluster;00197 }<span class="keywordflow">else</span>{00198 <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o3">Fat16Table</a>[entryNumber]=(currentCluster&0xffff);00199 } 00200 00201 <span class="comment">// Calculate next entry position in FAT records</span>00202 fatPageSector = currentCluster;00203 <span class="keywordflow">if</span> (!<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){ <span class="comment">//FAT16</span>00204 entryNumber = fatPageSector & 0xff; 00205 fatPageSector >>= 8; 00206 }<span class="keywordflow">else</span>{ <span class="comment">//FAT32</span>00207 entryNumber = fatPageSector & 0x7f;00208 fatPageSector >>= 7; 00209 }00210 fatPageSector += <a class="code" href="filesys_8c.html#a2">fatStart</a>;00211 00212 }<span class="comment">//while</span>00213 00214 00215 <span class="comment">// WRITE THE FINAL ENTRY TO FAT CLUSTERCHAIN</span>00216 00217 <span class="comment">// is the FAT clusterchain page changed?</span>00218 <span class="keywordflow">if</span> (<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> != fatPageSector){00219 <span class="comment">// Yes, have we advanced by 1 sector?</span>00220 <span class="keywordflow">if</span> (<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> == (fatPageSector - 1)){00221 <span class="comment">//Yes, we must save the edited sector</span>00222 <a class="code" href="storage_8h.html#a4">WriteDiskSector</a> (<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>);00224 }00225 <span class="comment">// at least we need to load the new clusterchain page</span>00226 <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> = fatPageSector;00227 <a class="code" href="storage_8h.html#a2">ReadDiskSector</a>(<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>);00228 }<span class="comment">//Load/Save FAT sector</span>00229 00230 00231 <span class="comment">//Write the Last entry</span>00232 <span class="keywordflow">if</span> (<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){00233 <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o4">Fat32Table</a>[entryNumber]=<a class="code" href="filesys_8c.html#a6">fragment</a>[1].<a class="code" href="structfragmentEntry.html#o0">start</a>;00234 }<span class="keywordflow">else</span>{00235 <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o3">Fat16Table</a>[entryNumber]=(<a class="code" href="filesys_8c.html#a6">fragment</a>[1].<a class="code" href="structfragmentEntry.html#o0">start</a> & 0xffff);00236 } 00237 <a class="code" href="storage_8h.html#a4">WriteDiskSector</a>(<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>); <span class="comment">//Write last sector</span>00238 00239 <a class="code" href="filesys_8h.html#a8">OpenFile</a>(0); <span class="comment">//Register FAT entry</span>00240 00241 }00242 00243 00244 00245 <a name="l00248"></a><a class="code" href="filesys_8h.html#a11">00248</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="filesys_8c.html#a17">ScanForFreeSector</a>(){00249 00250 <span class="comment">//ConsoleWrite("\rLooking for free space starting from ");</span>00251 00252 <span class="keywordflow">if</span> ((<a class="code" href="filesys_8c.html#a10">freeSector</a>) && (<a class="code" href="filesys_8c.html#a10">freeSector</a>-<a class="code" href="filesys_8c.html#a4">dataStart</a>+1)%<a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>){00253 <span class="comment">//Still room in current cluster...</span>00254 <a class="code" href="filesys_8c.html#a10">freeSector</a>++;00255 00256 <span class="comment">//ConsoleWrite("free at sector ");</span>00257 <span class="comment">//ConsolePutUInt(freeSector);</span>00258 00259 <span class="keywordflow">return</span> 1;00260 } 00261 00262 <span class="keywordflow">if</span> (<a class="code" href="filesys_8c.html#a10">freeSector</a>){00263 <span class="comment">//Advance to next sector</span>00264 <a class="code" href="filesys_8c.html#a10">freeSector</a>++;00265 <span class="comment">//switch from using sectors to using clusters</span>00266 <a class="code" href="filesys_8c.html#a13">PConvertSectorToCluster</a>(&<a class="code" href="filesys_8c.html#a10">freeSector</a>);00267 }<span class="keywordflow">else</span>{00268 <a class="code" href="filesys_8c.html#a10">freeSector</a>=3; <span class="comment">//starting cluster entry (should be 2?)</span>00269 }00270 00271 00272 <span class="comment">//scan until free entry is found</span>00273 <span class="comment">//freeSector actually counts clusters here.</span>00274 <span class="keywordflow">while</span>(<a class="code" href="filesys_8c.html#a15">GetFatEntry</a>(<a class="code" href="filesys_8c.html#a10">freeSector</a>)){ 00275 <a class="code" href="filesys_8c.html#a10">freeSector</a>++;00276 }00277 00278 ConsoleWrite(<span class="stringliteral">"F"</span>);00279 ConsolePutUInt(<a class="code" href="filesys_8c.html#a10">freeSector</a>);00280 00281 00282 <span class="comment">//while (!KEY_BUTTON);</span>00283 <span class="comment">//ConsoleWrite("free at cluster ");</span>00284 <span class="comment">//ConsolePutUInt(freeSector);</span>00285 00286 <span class="comment">//switch back from using clusters to using sectors.</span>00287 <a class="code" href="filesys_8c.html#a14">PConvertClusterToSector</a>(&<a class="code" href="filesys_8c.html#a10">freeSector</a>);00288 00289 <span class="comment">//ConsoleWrite("sector ");</span>00290 <span class="comment">//ConsolePutUInt(freeSector);</span>00291 00292 <span class="keywordflow">return</span> 1;00293 }00294 00295
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -