📄 filesys_8c.html
字号:
Referenced by <a class="el" href="filesys_8c-source.html#l00248">ScanForFreeSector()</a>.<p><pre class="fragment"><div>00085 {00086 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> entryNumber; <span class="comment">/* entry number inside page */</span>00087 00088 <span class="keywordflow">if</span> (!<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){ <span class="comment">//FAT16</span>00089 entryNumber = clusterNumber & 0xff; 00090 clusterNumber >>= 8; 00091 }<span class="keywordflow">else</span>{ <span class="comment">//FAT32</span>00092 entryNumber = clusterNumber & 0x7f;00093 clusterNumber >>= 7; 00094 }00095 clusterNumber += <a class="code" href="filesys_8c.html#a2">fatStart</a>;00096 <span class="keywordflow">if</span> (<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> != clusterNumber){00097 <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> = clusterNumber;00098 <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>);00099 }00100 <span class="keywordflow">if</span> (<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){00101 clusterNumber=<a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o4">Fat32Table</a>[entryNumber];00102 <span class="keywordflow">return</span> clusterNumber;00103 }00104 <span class="keywordflow">if</span> ((clusterNumber=<a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o3">Fat16Table</a>[entryNumber])==0xffff) <span class="keywordflow">return</span> 0xffffffff;00105 <span class="keywordflow">return</span> clusterNumber;00106 }</div></pre><p>Here is the call graph for this function:<p><center><img src="filesys_8c_a15_cgraph.png" border="0" usemap="#filesys_8c_a15_cgraph_map" alt=""></center><map name="filesys_8c_a15_cgraph_map"><area href="storage_8h.html#a2" shape="rect" coords="146,31,248,54" alt=""><area href="mmc_8c.html#a9" shape="rect" coords="298,7,424,31" alt=""><area href="mmc_8h.html#a2" shape="rect" coords="322,54,400,78" alt=""></map> </td> </tr></table><a class="anchor" name="a18" doxytag="filesys.c::GetNextSector" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top"> unsigned long GetNextSector </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">unsigned long </td> <td class="mdname1" valign="top" nowrap> <em>currentSector</em> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing=5 cellpadding=0 border=0> <tr> <td> </td> <td><p>Calculate next sector from currentSector. <p>Return sector address with MSB set if end of file.<p>This is the essence of FAT filesystem: traversing through the file allocation table to scan for cluster chains. <p>Definition at line <a class="el" href="filesys_8c-source.html#l00303">303</a> of file <a class="el" href="filesys_8c-source.html">filesys.c</a>.<p>References <a class="el" href="unionAddress.html#o1">Address::b</a>, <a class="el" href="buffer_8h-source.html#l00131">Address::B::b0</a>, <a class="el" href="buffer_8h-source.html#l00132">Address::B::b1</a>, <a class="el" href="buffer_8h-source.html#l00134">Address::B::b3</a>, <a class="el" href="filesys_8c-source.html#l00029">dataStart</a>, <a class="el" href="buffer_8c-source.html#l00010">diskSect</a>, <a class="el" href="buffer_8h-source.html#l00114">DiskBlock::Fat16Table</a>, <a class="el" href="buffer_8h-source.html#l00117">DiskBlock::Fat32Table</a>, <a class="el" href="filesys_8c-source.html#l00032">fatSectorsPerCluster</a>, <a class="el" href="filesys_8c-source.html#l00021">fatStart</a>, <a class="el" href="filesys_8h-source.html#l00015">IS_FAT_32</a>, <a class="el" href="buffer_8h-source.html#l00129">Address::l</a>, <a class="el" href="storage_8c-source.html#l00110">ReadDiskSector()</a>, and <a class="el" href="buffer_8c-source.html#l00015">sectorAddress</a>.<p>Referenced by <a class="el" href="filesys_8c-source.html#l00541">LoadNextSector()</a>, and <a class="el" href="filesys_8c-source.html#l00610">OpenFile()</a>.<p><pre class="fragment"><div>00303 {00304 <a class="code" href="unionAddress.html">addressType</a> fatSector;00305 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> entryNumber;00306 00307 <span class="comment">/* how manyth sector from start of data area -> fatsector */</span>00308 fatSector.<a class="code" href="unionAddress.html#o0">l</a> = currentSector - <a class="code" href="filesys_8c.html#a4">dataStart</a>;00309 00310 <span class="comment">/* Check for cluster boundary */</span>00311 <span class="comment">/* if we're not in cluster boundary then return currentsector + 1 */</span>00312 <span class="keywordflow">if</span> ((fatSector.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o0">b0</a> + 1) % <a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>){00313 <span class="keywordflow">return</span> currentSector + 1;00314 }00315 00316 <span class="comment">/* is the value negative? then return currentSector + 1 */</span>00317 <span class="keywordflow">if</span> (fatSector.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o3">b3</a> & 0x80) {00318 <span class="keywordflow">return</span> currentSector + 1;00319 } 00320 00321 <span class="comment">/* The trivial conditions are not met, we actually do need to </span>00322 <span class="comment"> look up the next sector info from FAT tables in the disk.*/</span>00323 00324 <span class="comment">/* convert fatSector from CurrentSectorN to currentClusterN */</span>00325 fatSector.<a class="code" href="unionAddress.html#o0">l</a> /= <a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>;00326 00327 <span class="comment">/* calculate which page (fatSector) and entry of FAT table correspond</span>00328 <span class="comment"> to current sector */</span>00329 00330 <span class="keywordflow">if</span> (!<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){ <span class="comment">//FAT16</span>00331 entryNumber = fatSector.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o0">b0</a>; <span class="comment">/* 256 entries / page in FAT16 table */</span>00332 fatSector.<a class="code" href="unionAddress.html#o0">l</a> >>= 8; <span class="comment">/* Divide by 256 (n of entries/page in FAT32 table */</span>00333 }<span class="keywordflow">else</span>{ <span class="comment">//FAT32</span>00334 entryNumber =(fatSector.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o0">b0</a> & 0x7f); <span class="comment">/* 128 entries/page in FAT32 tbl */</span>00335 fatSector.<a class="code" href="unionAddress.html#o0">l</a> >>= 7; <span class="comment">/* Divide by 128 (n of entries/sector in FAT32 table */</span>00336 }00337 00338 <span class="comment">/* Get sector address for the needed page */</span>00339 fatSector.<a class="code" href="unionAddress.html#o0">l</a> += <a class="code" href="filesys_8c.html#a2">fatStart</a>;00340 00341 <span class="comment">/* Load (if needed) table page from disk */</span>00342 <span class="keywordflow">if</span> (<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> != fatSector.<a class="code" href="unionAddress.html#o0">l</a>){00343 <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> = fatSector.<a class="code" href="unionAddress.html#o0">l</a>; <span class="comment">/* (not needed because mmc.c does this) */</span>00344 <a class="code" href="storage_8h.html#a2">ReadDiskSector</a>(fatSector.<a class="code" href="unionAddress.html#o0">l</a>);00345 00346 ConsolePutChar(<span class="charliteral">'n'</span>);00347 00348 00349 }00350 <span class="comment">/* Now there should be correct FAT entry page in memory... */</span>00351 00352 <span class="keywordflow">if</span> (!<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){ <span class="comment">//FAT16</span>00353 fatSector.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o3">Fat16Table</a>[entryNumber];00354 <span class="comment">/* Check for FAT16 end-of-file condition */</span>00355 <span class="keywordflow">if</span> ((fatSector.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o1">b1</a> == 0xff) && (fatSector.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o0">b0</a> == 0xff)){00356 <span class="comment">/* End of file */</span>00357 fatSector.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o3">b3</a> = 0xff; <span class="comment">/* return a large value (fat32 compatible) */</span>00358 <span class="keywordflow">return</span> fatSector.<a class="code" href="unionAddress.html#o0">l</a>;00359 }00360 }<span class="keywordflow">else</span>{ <span class="comment">//FAT32</span>00361 fatSector.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o4">Fat32Table</a>[entryNumber] & 0x0fffffff;00362 <span class="comment">/* Check for FAT32 end-of-file condition */</span>00363 <span class="keywordflow">if</span> ((fatSector.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o3">b3</a>&0x08) <span class="comment">//Quick test</span>00364 && (fatSector.<a class="code" href="unionAddress.html#o0">l</a>>0x0ffffff0)){ <span class="comment">//Complete test</span>00365 <span class="comment">/* End of file */</span>00366 <span class="keywordflow">return</span> 0xffffffff; <span class="comment">/* return EOF*/</span>00367 }00368 }00369 00370 00371 <span class="comment">/* now fatSector.l contains the proper next cluster value */</span>00372 00373 fatSector.<a class="code" href="unionAddress.html#o0">l</a> *= <a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>;00374 <span class="comment">/* now fatSector.l contains the next sector value */</span>00375 00376 fatSector.<a class="code" href="unionAddress.html#o0">l</a> += <a class="code" href="filesys_8c.html#a4">dataStart</a>;00377 <span class="comment">/* now fatSector.l contains the proper absolute sector address */</span>00378 00379 <span class="keywordflow">return</span> fatSector.<a class="code" href="unionAddress.html#o0">l</a>;00380 }</div></pre><p>Here is the call graph for this function:<p><center><img src="filesys_8c_a18_cgraph.png" border="0" usemap="#filesys_8c_a18_cgraph_map" alt=""></center><map name="filesys_8c_a18_cgraph_map"><area href="storage_8h.html#a2" shape="rect" coords="162,31,264,54" alt=""><area href="mmc_8c.html#a9" shape="rect" coords="314,7,440,31" alt=""><area hr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -