⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filesys_8c-source.html

📁 MP3播放器源代码, VS1003B
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="l00303"></a><a class="code" href="filesys_8c.html#a18">00303</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="filesys_8c.html#a18">GetNextSector</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> currentSector){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 -&gt; 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> &amp; 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> &gt;&gt;= 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> &amp; 0x7f); <span class="comment">/* 128 entries/page in FAT32 tbl */</span>00335     fatSector.<a class="code" href="unionAddress.html#o0">l</a> &gt;&gt;= 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) &amp;&amp; (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] &amp; 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>&amp;0x08) <span class="comment">//Quick test</span>00364         &amp;&amp; (fatSector.<a class="code" href="unionAddress.html#o0">l</a>&gt;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 }00381 00382 <a name="l00401"></a><a class="code" href="filesys_8h.html#a10">00401</a> <a class="code" href="board_8h.html#a47">Public</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="filesys_8c.html#a19">BuildFragmentTable</a>(){00402 00403   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c=0;00404   <a class="code" href="unionAddress.html">addressType</a> <span class="keyword">this</span>,next;00405   <a class="code" href="unionAddress.html">addressType</a> fatSector;00406   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> entryNumber;00407 00408 00409   <span class="keywordflow">if</span> (<a class="code" href="filesys_8c.html#a12">IS_FAT_12</a>){00410     ConsoleWrite(<span class="stringliteral">"Single fragment support for FAT12"</span>);00411     <a class="code" href="filesys_8c.html#a6">fragment</a>[0].<a class="code" href="structfragmentEntry.html#o0">start</a> = <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>;00412     <a class="code" href="filesys_8c.html#a6">fragment</a>[0].<a class="code" href="structfragmentEntry.html#o1">length</a> = <a class="code" href="filesys_8c.html#a7">fileSize</a>/512;00413     <span class="keywordflow">return</span>(1); <span class="comment">//Return 1 fragment</span>00414   }00415 00416 00417   <span class="comment">//as long as the sectorAddress is "sane"...</span>00418   <span class="keywordflow">while</span> (!(<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o3">b3</a> &amp; 0x80)){00419         00420     <a class="code" href="filesys_8c.html#a6">fragment</a>[c].<a class="code" href="structfragmentEntry.html#o0">start</a> = <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>;00421     <a class="code" href="filesys_8c.html#a6">fragment</a>[c].<a class="code" href="structfragmentEntry.html#o1">length</a> = <a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>;00422     00423     <span class="comment">/* Find cluster entry for the current sector */</span>00424     00425     <span class="comment">/* in how manyth sector from start of data area are we? -&gt;this */</span>00426     <span class="keyword">this</span>.l = <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> - <a class="code" href="filesys_8c.html#a4">dataStart</a>;00427     <span class="comment">/* convert from CurrentSectorN to currentClusterN */</span>00428     <span class="keyword">this</span>.l /= <a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>;00429     <span class="comment">/* this.l is now the current cluster number */</span>00430     00431     00432     <span class="comment">/* now let's find the FAT entry for this.l cluster */</span>00433     <span class="keywordflow">if</span> (!<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){ <span class="comment">//FAT16</span>00434       entryNumber = <span class="keyword">this</span>.b.b0; <span class="comment">/* 256 entries / page in FAT16 table */</span>00435       fatSector.<a class="code" href="unionAddress.html#o0">l</a> = <span class="keyword">this</span>.l &gt;&gt; 8; <span class="comment">/* Div by n of entries/page in FAT16 tbl*/</span>00436     }<span class="keywordflow">else</span>{ <span class="comment">//FAT32</span>00437       entryNumber = (<span class="keyword">this</span>.b.b0 &amp; 0x7f); <span class="comment">/* 128 entries/page in FAT32 table */</span>00438       fatSector.<a class="code" href="unionAddress.html#o0">l</a> = <span class="keyword">this</span>.l &gt;&gt; 7; <span class="comment">/* Div by n of entries/page in FAT32 tbl*/</span>00439     }00440     fatSector.<a class="code" href="unionAddress.html#o0">l</a> += <a class="code" href="filesys_8c.html#a2">fatStart</a>;00441     <span class="comment">/* fatSector.l is now the DISK SECTOR NUMBER CONTAINING THE FAT table */</span>00442     <span class="comment">/* read this page into memory */</span>00443     <a class="code" href="storage_8h.html#a2">ReadDiskSector</a>(fatSector.<a class="code" href="unionAddress.html#o0">l</a>);    00444     00445     <span class="keywordflow">if</span> (!<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){ <span class="comment">//FAT16</span>00446       next.<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]; <span class="comment">/* get next cluster n */</span>00447       <span class="comment">/* Check for FAT16 end-of-file condition */</span>00448       <span class="keywordflow">if</span> ((next.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o1">b1</a> == 0xff) &amp;&amp; (next.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o0">b0</a> == 0xff)){00449         <span class="comment">/* FAT16 End of file */</span>00450         next.<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>00451       }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -