📄 fat.lst
字号:
501 2 entry_pos++;
502 2
503 2 fat_last_file = index; /* update last file number */
504 2 /* For sub-directory, there is no logical limit for the number of entries */
505 2 /* In order to detect the last file, we check gl_buffer[0] */
506 2 /* We can put in the chain directory MAX_DIRECTORY_FILE selected file */
507 2 if ( (dir_is_root == FALSE) && (gl_buffer[0] == FILE_NOT_EXIST))
508 2 index = MAX_DIRECTORY_FILE;
509 2 /* Overflow of entry_pos */
510 2 if (entry_pos > MAX_DIRECTORY_GAP_FILE)
511 2 index = MAX_DIRECTORY_FILE;
512 2 /* For Root directory, the maximum entries is 512! */
513 2 if ( (dir_is_root == TRUE) && (counter_entry == MAX_DIRECTORY_FILE))
514 2 index = MAX_DIRECTORY_FILE;
515 2 }
516 1 while (index < MAX_DIRECTORY_FILE);
517 1
518 1 fat_current_sector = fat_directory_base;
519 1 Hard_read_close();
520 1 }
521
522 /*F**************************************************************************
523 * NAME: fat_get_root_directory
524 *----------------------------------------------------------------------------
525 * PARAMS:
526 * id: file extension to select
527 *
528 * return:
529 * - OK if file available
530 * - KO if file not found or file erased
531 * - KO if low_level memory failed
532 *----------------------------------------------------------------------------
533 * PURPOSE:
534 * Select first available file/dir in root diretory
535 *----------------------------------------------------------------------------
536 * EXAMPLE:
537 *----------------------------------------------------------------------------
538 * NOTE:
539 * Fill all the cache information for the first time
540 *----------------------------------------------------------------------------
541 * REQUIREMENTS:
542 *****************************************************************************/
543 bit fat_get_root_directory (Byte id)
544 {
545 1 /* select first root dir entry */
546 1 fat_current_sector = fat_ptr_rdir;
547 1
548 1 fat_current_byte_counter = 0;
549 1 dir_is_root = TRUE;
550 1
C51 COMPILER V6.20c FAT 07/10/2002 15:17:46 PAGE 10
551 1 fat_get_directory_chain(id);
552 1 if (fat_last_file == 0) /* No file/dir */
553 1 return KO;
554 1 /* Open the root directory on the first entry */
555 1 fat_file_ptr = 0;
556 1
557 1 /* extract info from table */
558 1 if ( fat_dseek(fat_directory_chain[fat_file_ptr] * 32) == OK)
559 1 {
560 2 fat_fetch_directory_info(&fat_cache.info);
561 2 /* parent dir is also root */
562 2 fat_cache.parent.start_cluster = 0;
563 2 fat_cache.parent.attributes = ATTR_DIRECTORY;
564 2 return OK;
565 2 }
566 1 else
567 1 {
568 2 return KO;
569 2 }
570 1 }
571
572
573 /*F**************************************************************************
574 * NAME: fat_goto_next
575 *----------------------------------------------------------------------------
576 * PARAMS:
577 *
578 * return:
579 *----------------------------------------------------------------------------
580 * PURPOSE:
581 * Fetch the next dir/file info in cache
582 *----------------------------------------------------------------------------
583 * EXAMPLE:
584 * Search for the next file in current directory
585 *----------------------------------------------------------------------------
586 * NOTE:
587 *----------------------------------------------------------------------------
588 * REQUIREMENTS:
589 *****************************************************************************/
590 bit fat_goto_next (void)
591 {
592 1 if (fat_file_ptr < (fat_last_file - 1))
593 1 {
594 2 fat_file_ptr++;
595 2
596 2 if ( fat_dseek((Int16)(fat_directory_chain[fat_file_ptr] * 32)) == OK)
597 2 {
598 3 fat_fetch_directory_info(&fat_cache.info);
599 3 return OK;
600 3 }
601 2 else
602 2 return KO;
603 2 }
604 1 else
605 1 return KO;
606 1 }
607
608
609 /*F**************************************************************************
610 * NAME: fat_goto_prev
611 *----------------------------------------------------------------------------
612 * PARAMS:
C51 COMPILER V6.20c FAT 07/10/2002 15:17:46 PAGE 11
613 *
614 * return:
615 * - OK: previous file found
616 * - KO: - previous file not found
617 * - low level error
618 *----------------------------------------------------------------------------
619 * PURPOSE:
620 * Fetch the previous directory info in cache
621 *----------------------------------------------------------------------------
622 * EXAMPLE:
623 *----------------------------------------------------------------------------
624 * NOTE:
625 * Search for the previous directory entry in current directory
626 *----------------------------------------------------------------------------
627 * REQUIREMENTS:
628 *****************************************************************************/
629 bit fat_goto_prev (void)
630 {
631 1 Byte min;
632 1
633 1 if (dir_is_root)
634 1 min = 0;
635 1 else
636 1 min = 2;
637 1
638 1 if (fat_file_ptr != min) /* Check if it's the first file of the directory */
639 1 {
640 2 if ( fat_dseek((Int16)(fat_directory_chain[fat_file_ptr] * (-32))) == OK)
641 2 { /* go to previous file */
642 3 fat_file_ptr--; /* update the file pointer */
643 3 fat_fetch_directory_info(&fat_cache.info); /* construct the file table */
644 3 return OK;
645 3 }
646 2 else
647 2 return KO;
648 2 }
649 1 else
650 1 return KO;
651 1
652 1 }
653
654 /*F**************************************************************************
655 * NAME: fat_seek_last
656 *----------------------------------------------------------------------------
657 * PARAMS:
658 *
659 * return:
660 * - OK: last file found
661 * - KO: - last file not found
662 * - low level error
663 *----------------------------------------------------------------------------
664 * PURPOSE:
665 * Fetch the last directory info in cache
666 *----------------------------------------------------------------------------
667 * EXAMPLE:
668 *----------------------------------------------------------------------------
669 * NOTE:
670 *
671 *----------------------------------------------------------------------------
672 * REQUIREMENTS:
673 *****************************************************************************/
674 bit fat_seek_last (void)
C51 COMPILER V6.20c FAT 07/10/2002 15:17:46 PAGE 12
675 {
676 1 Uint16 gl_offset;
677 1 Uint16 i;
678 1
679 1 for (i = fat_file_ptr + 1, gl_offset = 0; i < fat_last_file; fat_file_ptr++, i++)
680 1 gl_offset += fat_directory_chain[i];
681 1
682 1 if ( fat_dseek(gl_offset * 32) == OK)
683 1 {
684 2 fat_fetch_directory_info(&fat_cache.info);
685 2 return OK;
686 2 }
687 1 else
688 1 {
689 2 return KO;
690 2 }
691 1 }
692
693 /*F**************************************************************************
694 * NAME: fat_seek_first
695 *----------------------------------------------------------------------------
696 * PARAMS:
697 *
698 * return:
699 * - OK: first file found
700 * - KO: - first file not found
701 * - low level error
702 *----------------------------------------------------------------------------
703 * PURPOSE:
704 * Fetch the first directory info in cache
705 *----------------------------------------------------------------------------
706 * EXAMPLE:
707 *----------------------------------------------------------------------------
708 * NOTE:
709 *
710 *----------------------------------------------------------------------------
711 * REQUIREMENTS:
712 *****************************************************************************/
713 bit fat_seek_first (void)
714 {
715 1 fat_directory_pos = 0; /* Reset the global offset */
716 1
717 1 if (dir_is_root == TRUE) /* Root diretory ? */
718 1 {
719 2 fat_file_ptr = 0; /* Reset the file pointer */
720 2 if (fat_dseek((Int16)(fat_directory_chain[fat_file_ptr] * 32)) == OK)
721 2 {
722 3 fat_fetch_directory_info(&fat_cache.info);
723 3 return OK;
724 3 }
725 2 else
726 2 {
727 3 return KO;
728 3 }
729 2 }
730 1 else
731 1 {
732 2 fat_file_ptr = 1;
733 2 if (fat_dseek((Int16)(fat_directory_chain[fat_file_ptr] * 32)) == OK)
734 2 {
735 3 /* update parent info in ".." entry*/
736 3 fat_fetch_directory_info(&fat_cache.parent);
C51 COMPILER V6.20c FAT 07/10/2002 15:17:46 PAGE 13
737 3 /* point next file */
738 3 return fat_goto_next();
739 3 }
740 2 else
741 2 {
742 3 return KO;
743 3 }
744 2 }
745 1
746 1 }
747
748
749 /*F**************************************************************************
750 * NAME: fat_goto_subdir
751 *----------------------------------------------------------------------------
752 * PARAMS:
753 * id: file extension to select
754 *
755 * return:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -