📄 fat.lst
字号:
246 2 else
247 2 if (count_of_clusters <= MAX_CLUSTERS16)
248 2 fat_is_fat16 = TRUE;
249 2 /* else is FAT32 not supported */
250 2
251 2 /* compute data sector address */
252 2 fat_ptr_data += fat_ptr_rdir;
253 2 /* go to the signature field */
254 2 for (i= 237; i != 0; i--)
255 2 {
256 3 Hard_read_byte(); /* dummy reads */
257 3 Hard_read_byte();
258 3 }
259 2 /* check partition signature */
260 2 if ((Hard_read_byte() != LOW(BR_SIGNATURE)) &&
261 2 (Hard_read_byte() != HIGH(BR_SIGNATURE)))
262 2 {
263 3 Hard_read_close(); /* close physical read */
264 3 return KO;
265 3 }
266 2 Hard_read_close(); /* close physical read */
267 2 return OK;
268 2 }
269 1 else
270 1 { /* low level error */
271 2 return KO;
272 2 }
273 1 }
274
275
276 /*F**************************************************************************
277 * NAME: fat_fetch_directory_info
278 *----------------------------------------------------------------------------
279 * PARAMS:
280 * entry: directory entry structure
281 *
282 * return:
283 *----------------------------------------------------------------------------
284 * PURPOSE:
285 * Fetch from disk all information about a directory/file
286 *----------------------------------------------------------------------------
287 * EXAMPLE:
288 *----------------------------------------------------------------------------
289 * NOTE:
290 * This function reads directly datas from sectors
291 * It automaticaly computes difference between LFN and normal entries
292 *----------------------------------------------------------------------------
293 * REQUIREMENTS:
294 *****************************************************************************/
295 void fat_fetch_directory_info (fat_dir_entry *entry)
296 {
297 1 bit exit_flag = FALSE;
298 1 bit lfn_entry_found = FALSE;
299 1 Byte i;
300 1
301 1 /* clear the name buffer */
302 1 for (i = MAX_FILENAME_LEN; i != 0; lfn_name[--i] = '\0');
C51 COMPILER V6.20c FAT 07/10/2002 15:17:46 PAGE 6
303 1
304 1 while (!exit_flag)
305 1 /* loop while the entry is not a normal one. */
306 1 {
307 2 /* read the directory entry */
308 2 if (dir_is_root == TRUE)
309 2 {
310 3 for (i = 0; i < DIR_SIZE; i++)
311 3 {
312 4 gl_buffer[i] = Hard_read_byte();
313 4 }
314 3 }
315 2 else
316 2 {
317 3 for (i = 0; i < DIR_SIZE; i++)
318 3 {
319 4 gl_buffer[i] = fat_dgetc();
320 4 }
321 3 }
322 2
323 2 /*computes gathered data
324 2 /* check if we have a LFN entry */
325 2 if (gl_buffer[11] != ATTR_LFN_ENTRY)
326 2 {
327 3 if (!lfn_entry_found)
328 3 {
329 4 /* true DOS 8.3 entry format */
330 4 for (i = 0; i < 8; i++)
331 4 {
332 5 lfn_name[i] = gl_buffer[i];
333 5
334 5 if (lfn_name[i] == ' ')
335 5 { /* space is end of name */
336 6 break;
337 6 }
338 5 }
339 4 /* append extension */
340 4 lfn_name[i++] = '.';
341 4 lfn_name[i++] = gl_buffer[8];
342 4 lfn_name[i++] = gl_buffer[9];
343 4 lfn_name[i++] = gl_buffer[10];
344 4
345 4 for (; i != 14; i++)
346 4 {
347 5 lfn_name[i] = ' '; /* append spaces for display reason */
348 5 }
349 4 lfn_name[i] = '\0'; /* end of string */
350 4 }
351 3
352 3 else
353 3 { /* LFN name treatment */
354 4 i = 0;
355 4 /* search for the end of the string */
356 4 while (lfn_name[i] != '\0')
357 4 {
358 5 i++;
359 5 }
360 4 if (i <= 14)
361 4 { /* append spaces for display reason (no scrolling) */
362 5 while (i != 14)
363 5 {
364 6 lfn_name[i++] = ' ';
C51 COMPILER V6.20c FAT 07/10/2002 15:17:46 PAGE 7
365 6 }
366 5 }
367 4 else
368 4 { /* append beginning of name to ease scrolling display */
369 5 lfn_name[i++] = ' ';
370 5 lfn_name[i++] = ' ';
371 5 lfn_name[i++] = lfn_name[0];
372 5 lfn_name[i++] = lfn_name[1];
373 5 lfn_name[i++] = lfn_name[2];
374 5 lfn_name[i++] = lfn_name[3];
375 5 lfn_name[i++] = lfn_name[4];
376 5 lfn_name[i++] = lfn_name[5];
377 5 lfn_name[i++] = lfn_name[6];
378 5 lfn_name[i++] = lfn_name[7];
379 5 lfn_name[i++] = lfn_name[8];
380 5 lfn_name[i++] = lfn_name[9];
381 5 lfn_name[i++] = lfn_name[10];
382 5 lfn_name[i++] = lfn_name[11];
383 5 lfn_name[i++] = lfn_name[12];
384 5 }
385 4 lfn_name[i] = '\0'; /* end of name */
386 4 }
387 3
388 3 /* store extension */
389 3 ext[0]= gl_buffer[8];
390 3 ext[1]= gl_buffer[9];
391 3 ext[2]= gl_buffer[10];
392 3
393 3 /* standard computing for normal entry */
394 3 entry->attributes = gl_buffer[11];
395 3 entry->start_cluster = gl_buffer[26];
396 3 entry->start_cluster += ((Uint16) gl_buffer[27]) << 8;
397 3 entry->size = gl_buffer[28];
398 3 entry->size += ((Uint32) gl_buffer[29]) << 8;
399 3 entry->size += ((Uint32) gl_buffer[30]) << 16;
400 3 entry->size += ((Uint32) gl_buffer[31]) << 24;
401 3 /* now it's time to stop */
402 3 exit_flag = TRUE;
403 3 }
404 2 else
405 2 { /* LFN entry format */
406 3 lfn_entry_found = TRUE; /* a 8.3 name will follow */
407 3
408 3 if ( (gl_buffer[0] & LFN_SEQ_MASK) <= MAX_LFN_ENTRIES)
409 3 { /* Maximum number of entries for LFN? */
410 4 for (i = 0; i < 5; i++)
411 4 lfn_name[i + 13*((gl_buffer[0] & LFN_SEQ_MASK) - 1)] = gl_buffer[2*i + 1];
412 4 for (i = 0; i < 6; i++)
413 4 lfn_name[i + 5 + 13*((gl_buffer[0] & LFN_SEQ_MASK) - 1)] = gl_buffer[2*i + 14];
414 4 for (i = 0; i < 2; i++)
415 4 lfn_name[i + 11 + 13*((gl_buffer[0] & LFN_SEQ_MASK) - 1)] = gl_buffer[2*i + 28];
416 4 }
417 3 }
418 2 }
419 1 Hard_read_close(); /* close physical read */
420 1 }
421
422
423 /*F**************************************************************************
424 * NAME: fat_get_directory_chain
425 *----------------------------------------------------------------------------
426 * PARAMS:
C51 COMPILER V6.20c FAT 07/10/2002 15:17:46 PAGE 8
427 * id: file extension to select
428 *
429 * return:
430 *----------------------------------------------------------------------------
431 * PURPOSE:
432 * Construct the file directory chain
433 *----------------------------------------------------------------------------
434 * EXAMPLE:
435 *----------------------------------------------------------------------------
436 * NOTE:
437 * The value are relative position with the previous file.
438 *----------------------------------------------------------------------------
439 * REQUIREMENTS:
440 * Maximum of 256 entries between 2 authorized file (id extension)
441 * because the relative position is stored on one byte.
442 * To allow more than 256 entries (-> 32768), change type of
443 * fat_directory_chain[] from Byte to Uint16 (no overflow management)
444 * and change MAX_DIRECTORY_GAP_FILE from 255 to 32767
445 *****************************************************************************/
446 void fat_get_directory_chain (Byte id)
447 {
448 1 Uint16 index; /* chain index */
449 1 Uint16 counter_entry; /* entry counter: 0...MAX_DIRECTORY_FILE */
450 1 Uint16 entry_pos; /* relative entry position */
451 1 Uint16 entry_pos_saved; /* used when the file is not the id etension */
452 1 Byte i;
453 1
454 1 index = 0;
455 1 fat_last_file = 0;
456 1 counter_entry = 0;
457 1 entry_pos = 0;
458 1 fat_directory_base = fat_current_sector;
459 1 fat_directory_pos = 0;
460 1
461 1 Hard_read_open(fat_directory_base);
462 1
463 1 do /* scan all entries */
464 1 {
465 2 if (dir_is_root == TRUE)
466 2 for (i = 0; i < DIR_SIZE; i++) gl_buffer[i] = Hard_read_byte();
467 2 else
468 2 for (i = 0; i < DIR_SIZE; i++) gl_buffer[i] = fat_dgetc();
469 2 counter_entry++; /* increase the # entry */
470 2
471 2 if ((gl_buffer[0] != FILE_DELETED) && (gl_buffer[0] != FILE_NOT_EXIST))
472 2 { /* Existing file ? */
473 3 fat_directory_chain[index] = entry_pos; /* save the relative position */
474 3 entry_pos_saved = entry_pos; /* */
475 3 entry_pos = 1; /* reset the relative position */
476 3 index++; /* increase the index */
477 3
478 3 while (gl_buffer[11] == ATTR_LFN_ENTRY) /* LFN entry ? */
479 3 { /* then read all the LFN entry */
480 4 if (dir_is_root == TRUE)
481 4 for (i = 0; i < DIR_SIZE; i++) gl_buffer[i] = Hard_read_byte();
482 4 else
483 4 for (i = 0; i < DIR_SIZE; i++) gl_buffer[i] = fat_dgetc();
484 4 counter_entry++; /* increase the # entry */
485 4 entry_pos++; /* increase the relative position*/
486 4 /* for the next file */
487 4 }
488 3
C51 COMPILER V6.20c FAT 07/10/2002 15:17:46 PAGE 9
489 3 /* filter on the file type */
490 3 fat_cache.info.attributes = gl_buffer[11];
491 3 ext[0] = gl_buffer[8];
492 3 ext[1] = gl_buffer[9];
493 3 ext[2] = gl_buffer[10];
494 3 if ( (fat_check_ext() & id) == 0)
495 3 { /* Don't valid the entry */
496 4 index--;
497 4 entry_pos += entry_pos_saved;
498 4 }
499 3 }
500 2 else /* Not an existing file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -