📄 ff.lst
字号:
wc = LD_WORD(dir+LfnOfs[s]); /* Get an LFN char */
if (!wc) break; /* End of LFN? */
lfnbuf[i++] = wc; /* Store it */
} while (++s < 13); /* Repeat until last char is copied */
if (dir[LDIR_Ord] & 0x40) { /* Put terminator if it is the last LFN part */
if (i >= _MAX_LFN) return FALSE; /* Buffer overflow? */
lfnbuf[i] = 0;
}
return TRUE;
}
#if !_FS_READONLY
static
void fit_lfn (
const WCHAR *lfnbuf, /* Pointer to the LFN buffer */
BYTE *dir, /* Pointer to the directory entry */
BYTE ord, /* LFN order (1-20) */
BYTE sum /* SFN sum */
)
{
int i, s;
WCHAR wc;
dir[LDIR_Chksum] = sum; /* Set check sum */
dir[LDIR_Attr] = AM_LFN; /* Set attribute. LFN entry */
dir[LDIR_Type] = 0;
ST_WORD(dir+LDIR_FstClusLO, 0);
i = (ord - 1) * 13; /* Get offset in the LFN buffer */
s = wc = 0;
do {
if (wc != 0xFFFF) wc = lfnbuf[i++]; /* Get an effective char */
ST_WORD(dir+LfnOfs[s], wc); /* Put it */
if (!wc) wc = 0xFFFF; /* Padding chars following last char */
} while (++s < 13);
if (wc == 0xFFFF || !lfnbuf[i]) ord |= 0x40; /* Bottom LFN part is the start of LFN sequence */
dir[LDIR_Ord] = ord; /* Set the LFN order */
}
#endif
#endif
732
733
734
C51 COMPILER V7.06 FF 03/06/2010 17:37:27 PAGE 13
735 /*-----------------------------------------------------------------------*/
736 /* Create numbered name */
737 /*-----------------------------------------------------------------------*/
738 #if _USE_LFN
void gen_numname (
BYTE *dst, /* Pointer to genartated SFN */
const BYTE *src, /* Pointer to source SFN to be modified */
const WCHAR *lfn, /* Pointer to LFN */
WORD num /* Sequense number */
)
{
char ns[8];
int i, j;
mem_cpy(dst, src, 11);
if (num > 5) { /* On many collisions, generate a hash number instead of sequencial number */
do num = (num >> 1) + (num << 15) + (WORD)*lfn++; while (*lfn);
}
/* itoa */
i = 7;
do {
ns[i--] = (num % 10) + '0';
num /= 10;
} while (num);
ns[i] = '~';
/* Append the number */
for (j = 0; j < i && dst[j] != ' '; j++) {
if (IsDBCS1(dst[j])) {
if (j == i - 1) break;
j++;
}
}
do {
dst[j++] = (i < 8) ? ns[i++] : ' ';
} while (j < 8);
}
#endif
776
777
778
779
780 /*-----------------------------------------------------------------------*/
781 /* Calculate sum of an SFN */
782 /*-----------------------------------------------------------------------*/
783 #if _USE_LFN
static
BYTE sum_sfn (
const BYTE *dir /* Ptr to directory entry */
)
{
BYTE sum = 0;
int n = 11;
do sum = (sum >> 1) + (sum << 7) + *dir++; while (--n);
return sum;
}
#endif
796
C51 COMPILER V7.06 FF 03/06/2010 17:37:27 PAGE 14
797
798
799
800 /*-----------------------------------------------------------------------*/
801 /* Directory handling - Find an object in the directory */
802 /*-----------------------------------------------------------------------*/
803
804 static
805 FRESULT dir_find (
806 DIR *dj /* Pointer to the directory object linked to the file name */
807 )
808 {
809 1 FRESULT res;
810 1 BYTE c, *dir;
811 1 #if _USE_LFN
BYTE a, lfen, ord, sum;
#endif
814 1
815 1 res = dir_seek(dj, 0); /* Rewind directory object */
816 1 if (res != FR_OK) return res;
817 1
818 1 #if _USE_LFN
ord = sum = 0xFF; lfen = *(dj->fn+11) & NS_LOSS;
#endif
821 1 do {
822 2 res = move_window(dj->fs, dj->sect);
823 2 if (res != FR_OK) break;
824 2 dir = dj->dir; /* Ptr to the directory entry of current index */
825 2 c = dir[DIR_Name];
826 2 if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */
827 2 #if _USE_LFN /* LFN configuration */
a = dir[DIR_Attr] & AM_MASK;
if (c == 0xE5 || ((a & AM_VOL) && a != AM_LFN)) { /* An entry without valid data */
ord = 0xFF;
} else {
if (a == AM_LFN) { /* An LFN entry is found */
if (dj->lfn) {
if (c & 0x40) { /* Is it start of LFN sequence? */
sum = dir[LDIR_Chksum];
c &= 0xBF; ord = c; /* LFN start order */
dj->lfn_idx = dj->index;
}
/* Check LFN validity. Compare LFN if it is out of 8.3 format */
ord = (c == ord && sum == dir[LDIR_Chksum] && (!lfen || cmp_lfn(dj->lfn, dir))) ? ord - 1 : 0xFF;
}
} else { /* An SFN entry is found */
if (ord || sum != sum_sfn(dir)) /* Did not LFN match? */
dj->lfn_idx = 0xFFFF;
if (lfen) { /* Match LFN if it is out of 8.3 format */
if (ord == 0) break;
} else { /* Match SFN if LFN is in 8.3 format */
if (!mem_cmp(dir, dj->fn, 11)) break;
}
ord = 0xFF;
}
}
#else /* Non LFN configuration */
854 2 if (!(dir[DIR_Attr] & AM_VOL) && !mem_cmp(dir, dj->fn, 11)) /* Is it a valid entry? */
855 2 break;
856 2 #endif
857 2 res = dir_next(dj, FALSE); /* Next entry */
858 2 } while (res == FR_OK);
C51 COMPILER V7.06 FF 03/06/2010 17:37:27 PAGE 15
859 1
860 1 return res;
861 1 }
862
863
864
865
866 /*-----------------------------------------------------------------------*/
867 /* Read an object from the directory */
868 /*-----------------------------------------------------------------------*/
869 #if _FS_MINIMIZE <= 1
870 static
871 FRESULT dir_read (
872 DIR *dj /* Pointer to the directory object that pointing the entry to be read */
873 )
874 {
875 1 FRESULT res;
876 1 BYTE c, *dir;
877 1 #if _USE_LFN
BYTE a, ord = 0xFF, sum = 0xFF;
#endif
880 1
881 1 res = FR_NO_FILE;
882 1 while (dj->sect) {
883 2 res = move_window(dj->fs, dj->sect);
884 2 if (res != FR_OK) break;
885 2 dir = dj->dir; /* Ptr to the directory entry of current index */
886 2 c = dir[DIR_Name];
887 2 if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */
888 2 #if _USE_LFN /* LFN configuration */
a = dir[DIR_Attr] & AM_MASK;
if (c == 0xE5 || (!_FS_RPATH && c == '.') || ((a & AM_VOL) && a != AM_LFN)) { /* An entry without valid
-data */
ord = 0xFF;
} else {
if (a == AM_LFN) { /* An LFN entry is found */
if (c & 0x40) { /* Is it start of LFN sequence? */
sum = dir[LDIR_Chksum];
c &= 0xBF; ord = c;
dj->lfn_idx = dj->index;
}
/* Check LFN validity and capture it */
ord = (c == ord && sum == dir[LDIR_Chksum] && pick_lfn(dj->lfn, dir)) ? ord - 1 : 0xFF;
} else { /* An SFN entry is found */
if (ord || sum != sum_sfn(dir)) /* Is there a valid LFN entry? */
dj->lfn_idx = 0xFFFF; /* No LFN. */
break;
}
}
#else /* Non LFN configuration */
908 2 if (c != 0xE5 && (_FS_RPATH || c != '.') && !(dir[DIR_Attr] & AM_VOL)) /* Is it a valid entry? */
909 2 break;
910 2 #endif
911 2 res = dir_next(dj, FALSE); /* Next entry */
912 2 if (res != FR_OK) break;
913 2 }
914 1
915 1 if (res != FR_OK) dj->sect = 0;
916 1
917 1 return res;
918 1 }
919 #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -