📄 fat_8c-source.html
字号:
00183 00184 <span class="keywordflow">if</span>(count == 0)00185 {00186 entrycount = 0;00187 DirNameBuffer = 0;00188 }00189 00190 <span class="comment">// read dir data</span>00191 sector = fatClustToSect(FirstDirSector);00192 00193 hasBuffer = 0;00194 00195 index = 16; <span class="comment">// crank it up</span>00196 <span class="keywordflow">do</span> 00197 {00198 <span class="keywordflow">if</span>(index == 16) <span class="comment">// time for next sector ?</span>00199 {00200 ataReadSectors( DRIVE0, sector++, 1, SectorBuffer);00201 de = (<span class="keyword">struct </span>direntry *) SectorBuffer;00202 index = 0;00203 } 00204 00205 <span class="keywordflow">if</span>(*de->deName != 0xE5)00206 {00207 <span class="comment">// if not a deleted entry</span>00208 <span class="keywordflow">if</span>(de->deAttributes == ATTR_LONG_FILENAME)00209 {00210 <span class="comment">// we have a long name entry</span>00211 we = (<span class="keyword">struct </span>winentry *) de;00212 b = 13 *( (we->weCnt-1) & 0x0f); <span class="comment">// index into string</span>00213 p = &LongNameBuffer[b];00214 <span class="keywordflow">for</span> (i=0;i<5;i++) *p++ = we->wePart1[i*2]; <span class="comment">// copy first part </span>00215 <span class="keywordflow">for</span> (i=0;i<6;i++) *p++ = we->wePart2[i*2]; <span class="comment">// second part</span>00216 <span class="keywordflow">for</span> (i=0;i<2;i++) *p++ = we->wePart3[i*2]; <span class="comment">// and third part</span>00217 <span class="keywordflow">if</span> (we->weCnt & 0x40) *p = 0; <span class="comment">// in case dirnamelength is multiple of 13</span>00218 if ((we->weCnt & 0x0f) == 1) hasBuffer = 1; <span class="comment">// mark that we have a long entry</span>00219 }00220 <span class="keywordflow">else</span>00221 {00222 <span class="comment">// we have a short name entry</span>00223 <span class="comment">// check if this is the end of a multi-part long name entry</span>00224 <span class="keywordflow">if</span>(hasBuffer)00225 {00226 <span class="comment">// a long entry name has been collected</span>00227 <span class="comment">// is it a directory ?</span>00228 <span class="keywordflow">if</span>(de->deAttributes == ATTR_DIRECTORY)00229 {00230 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> save = FirstDirSector;00231 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> save2 = baseentry;00232 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> rval;00233 00234 strcpy(DirNameBuffer,LongNameBuffer);00235 strcat(DirNameBuffer,<span class="stringliteral">"/"</span>);00236 00237 <span class="comment">// rprintfStr(LongNameBuffer); rprintfProgStrM("/"); //EOL();</span>00238 00239 <span class="comment">// call recursively</span>00240 FirstDirSector = ((<span class="keywordtype">unsigned</span> long)de->deHighClust << 16) + de->deStartCluster;00241 rval = fatGetDirEntry(entry,1);00242 FirstDirSector = save;00243 baseentry = save2;00244 <span class="keywordflow">if</span> (rval)00245 <span class="keywordflow">return</span> rval;00246 <span class="keywordflow">else</span> 00247 {00248 <span class="comment">// reload original sector</span>00249 ataReadSectors( DRIVE0, sector-1, 1, SectorBuffer);00250 entrycount--; <span class="comment">// decrement entry counter </span>00251 *DirNameBuffer = 0;00252 }00253 }00254 <span class="keywordflow">else</span> <span class="comment">// normal file entry</span>00255 <span class="keywordflow">if</span>(entrycount == entry) 00256 <span class="keywordflow">break</span>;00257 hasBuffer = 0; <span class="comment">// clear buffer </span>00258 entrycount++; <span class="comment">// increment entry counter </span>00259 }00260 <span class="comment">// else ignore short_name_only entries</span>00261 }00262 }00263 de++;00264 index++;00265 } <span class="keywordflow">while</span> (*de->deName || index == 16); <span class="comment">// 0 in de->deName[0] if no more entries</span>00266 00267 <span class="keywordflow">if</span> (hasBuffer == 0) <span class="comment">// end of entries</span>00268 <span class="keywordflow">return</span> 0;00269 00270 FileSize = de->deFileSize;00271 <span class="keywordflow">return</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>) ((<span class="keywordtype">unsigned</span> long)de->deHighClust << 16) + de->deStartCluster;00272 }00273 00274 00275 <span class="comment">// return the size of the last directory entry</span>00276 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> fatGetFilesize(<span class="keywordtype">void</span>)00277 {00278 <span class="keywordflow">return</span> FileSize;00279 }00280 00281 00282 <span class="comment">// return the long name of the last directory entry</span>00283 <span class="keywordtype">char</span>* fatGetFilename(<span class="keywordtype">void</span>)00284 { 00285 <span class="keywordflow">return</span> LongNameBuffer;00286 }00287 00288 00289 <span class="comment">// return the directory of the last directory entry</span>00290 <span class="keywordtype">char</span>* fatGetDirname(<span class="keywordtype">void</span>)00291 { 00292 <span class="keywordflow">return</span> DirNameBuffer;00293 }00294 00295 00296 <span class="comment">// load a clusterfull of data</span>00297 <span class="keywordtype">void</span> fatLoadCluster(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> cluster, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *buffer)00298 {00299 <span class="keyword">register</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> i;00300 <span class="comment">// read cluster</span>00301 <span class="comment">//while ( ataReadSectors( DRIVE0, clust2sect(cluster), SectorsPerCluster, buffer) != 0);</span>00302 <span class="keywordflow">for</span>(i=0; i<SectorsPerCluster; i++)00303 {00304 <span class="comment">// ataReadSectors( DRIVE0, clust2sect(cluster)+i, 1, buffer+(i<<9) );</span>00305 <span class="comment">// temporary fix for wierd misaligned cluster problem</span>00306 <span class="comment">// (only when using FAT16?)</span>00307 ataReadSectors( DRIVE0, fatClustToSect(cluster+8)+i, 1, buffer+(i<<9) );00308 }00309 }00310 00311 00312 <span class="comment">// find next cluster in the FAT chain</span>00313 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> fatNextCluster(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> cluster)00314 {00315 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> nextCluster;00316 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> fatMask;00317 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> fatOffset;00318 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> sector;00319 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> offset;00320 00321 <span class="comment">// get fat offset in bytes</span>00322 <span class="keywordflow">if</span>(Fat32Enabled)00323 {00324 <span class="comment">// four FAT bytes (32 bits) for every cluster</span>00325 fatOffset = cluster << 2;00326 <span class="comment">// set the FAT bit mask</span>00327 fatMask = FAT32_MASK;00328 }00329 <span class="keywordflow">else</span>00330 {00331 <span class="comment">// two FAT bytes (16 bits) for every cluster</span>00332 fatOffset = cluster << 1;00333 <span class="comment">// set the FAT bit mask</span>00334 fatMask = FAT16_MASK;00335 }00336 00337 <span class="comment">// calculate the FAT sector that we're interested in</span>00338 sector = FirstFATSector + (fatOffset / BytesPerSector);00339 <span class="comment">// calculate offset of the our entry within that FAT sector</span>00340 offset = fatOffset % BytesPerSector;00341 00342 <span class="comment">// if we don't already have this FAT chunk loaded, go get it</span>00343 <span class="keywordflow">if</span> (sector != FatInCache)00344 {00345 <span class="comment">// read sector of FAT table</span>00346 <span class="keywordflow">while</span> (ataReadSectors( DRIVE0, sector, 1, (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)FAT_CACHE_ADDR) != 0);00347 FatInCache = sector;00348 }00349 00350 <span class="comment">// read the nextCluster value</span>00351 nextCluster = (*((<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>*) &((<span class="keywordtype">char</span>*)FAT_CACHE_ADDR)[offset])) & fatMask;00352 00353 <span class="comment">// check to see if we're at the end of the chain</span>00354 <span class="keywordflow">if</span> (nextCluster == (CLUST_EOFE & fatMask))00355 nextCluster = 0;00356 00357 <span class="preprocessor">#ifdef DEBUG_FAT</span>00358 <span class="preprocessor"></span> <a class="code" href="group__rprintf.html#ga15">rprintfProgStrM</a>(<span class="stringliteral">">"</span>);00359 <a class="code" href="group__rprintf.html#ga9">rprintfu32</a>(nextCluster);00360 <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>();00361 <span class="preprocessor">#endif</span>00362 <span class="preprocessor"></span> 00363 <span class="keywordflow">return</span> nextCluster;00364 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Aug 22 04:29:27 2005 for Procyon AVRlib by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -