110 #error Wrong include file (ff.h).
115 #if _MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096
116 #error Wrong sector size.
119 #define SS(fs) ((fs)->ssize)
128 #error Static LFN work area must not be used in re-entrant configuration.
130 #define ENTER_FF(fs) { if (!lock_fs(fs)) return FR_TIMEOUT; }
131 #define LEAVE_FF(fs, res) { unlock_fs(fs, res); return res; }
134 #define LEAVE_FF(fs, res) return res
137 #define ABORT(fs, res) { fp->flag |= FA__ERROR; LEAVE_FF(fs, res); }
143 #error _FS_LOCK must be 0 on read-only cfg.
157 #if _CODE_PAGE == 932
167 #elif _CODE_PAGE == 936
175 #elif _CODE_PAGE == 949
185 #elif _CODE_PAGE == 950
193 #elif _CODE_PAGE == 437
195 #define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F,0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
196 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
197 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
198 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
200 #elif _CODE_PAGE == 720
202 #define _EXCVT {0x80,0x81,0x45,0x41,0x84,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x8E,0x8F,0x90,0x92,0x92,0x93,0x94,0x95,0x49,0x49,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
203 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
204 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
205 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
207 #elif _CODE_PAGE == 737
209 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x92,0x92,0x93,0x94,0x95,0x96,0x97,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, \
210 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0xAA,0x92,0x93,0x94,0x95,0x96,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
211 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0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9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
331 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xFF}
333 #elif _CODE_PAGE == 1258
335 #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0xAC,0x9D,0x9E,0x9F, \
336 0xA0,0x21,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
337 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
338 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xEC,0xCD,0xCE,0xCF,0xD0,0xD1,0xF2,0xD3,0xD4,0xD5,0xD6,0xF7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xFE,0x9F}
340 #elif _CODE_PAGE == 1
342 #error Cannot use LFN feature without valid code page.
347 #error Unknown code page
353 #define IsUpper(c) (((c)>='A')&&((c)<='Z'))
354 #define IsLower(c) (((c)>='a')&&((c)<='z'))
355 #define IsDigit(c) (((c)>='0')&&((c)<='9'))
360 #define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E))
362 #define IsDBCS1(c) ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E)
366 #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E))
368 #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E))
391 #define MIN_FAT16 4086
392 #define MIN_FAT32 65526
401 #define BPB_BytsPerSec 11
402 #define BPB_SecPerClus 13
403 #define BPB_RsvdSecCnt 14
404 #define BPB_NumFATs 16
405 #define BPB_RootEntCnt 17
406 #define BPB_TotSec16 19
408 #define BPB_FATSz16 22
409 #define BPB_SecPerTrk 24
410 #define BPB_NumHeads 26
411 #define BPB_HiddSec 28
412 #define BPB_TotSec32 32
414 #define BS_BootSig 38
417 #define BS_FilSysType 54
418 #define BPB_FATSz32 36
419 #define BPB_ExtFlags 40
421 #define BPB_RootClus 44
422 #define BPB_FSInfo 48
423 #define BPB_BkBootSec 50
424 #define BS_DrvNum32 64
425 #define BS_BootSig32 66
426 #define BS_VolID32 67
427 #define BS_VolLab32 71
428 #define BS_FilSysType32 82
429 #define FSI_LeadSig 0
430 #define FSI_StrucSig 484
431 #define FSI_Free_Count 488
432 #define FSI_Nxt_Free 492
433 #define MBR_Table 446
440 #define DIR_CrtTimeTenth 13
441 #define DIR_CrtTime 14
442 #define DIR_CrtDate 16
443 #define DIR_LstAccDate 18
444 #define DIR_FstClusHI 20
445 #define DIR_WrtTime 22
446 #define DIR_WrtDate 24
447 #define DIR_FstClusLO 26
448 #define DIR_FileSize 28
452 #define LDIR_Chksum 13
453 #define LDIR_FstClusLO 26
472 #error Number of volumes must not be 0.
489 #define DEF_NAMEBUF BYTE sfn[12]
490 #define INIT_BUF(dobj) (dobj).fn = sfn
495 #define DEF_NAMEBUF BYTE sfn[12]
496 #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = LfnBuf; }
500 #define DEF_NAMEBUF BYTE sfn[12]; WCHAR lbuf[_MAX_LFN+1]
501 #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = lbuf; }
505 #define DEF_NAMEBUF BYTE sfn[12]; WCHAR *lfn
506 #define INIT_BUF(dobj) { lfn = ff_memalloc((_MAX_LFN + 1) * 2); \
507 if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); \
508 (dobj).lfn = lfn; (dobj).fn = sfn; }
509 #define FREE_BUF() ff_memfree(lfn)
512 #error Wrong LFN configuration.
518 const BYTE ExCvt[] = _EXCVT;
543 #if _WORD_ACCESS == 1
544 while (cnt >=
sizeof (
int)) {
546 d +=
sizeof (int); s +=
sizeof (int);
566 const BYTE *d = (
const BYTE *)dst, *s = (
const BYTE *)src;
569 while (cnt-- && (r = *d++ - *s++) == 0) ;
576 while (*str && *str != chr) str++;
592 return ff_req_grant(fs->sobj);
607 ff_rel_grant(fs->sobj);
628 for (i = be = 0; i <
_FS_LOCK; i++) {
630 if (Files[i].fs == dj->
fs &&
631 Files[i].clu == dj->
sclust &&
632 Files[i].idx == dj->
index)
break;
650 for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ;
651 return (i == _FS_LOCK) ? 0 : 1;
665 if (Files[i].fs == dj->
fs &&
666 Files[i].clu == dj->
sclust &&
667 Files[i].idx == dj->
index)
break;
671 for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ;
672 if (i == _FS_LOCK)
return 0;
673 Files[i].fs = dj->
fs;
674 Files[i].clu = dj->
sclust;
675 Files[i].idx = dj->
index;
679 if (acc && Files[i].ctr)
return 0;
681 Files[i].ctr = acc ? 0x100 : Files[i].ctr + 1;
696 if (--i < _FS_LOCK) {
698 if (n == 0x100) n = 0;
701 if (!n) Files[i].fs = 0;
718 if (Files[i].fs == fs) Files[i].fs = 0;
746 for (nf = fs->
n_fats; nf >= 2; nf--) {
830 if (clst >= (fs->
n_fatent - 2))
return 0;
851 if (clst < 2 || clst >= fs->
n_fatent)
856 bc = (
UINT)clst; bc += bc / 2;
858 wc = fs->
win[bc %
SS(fs)]; bc++;
860 wc |= fs->
win[bc %
SS(fs)] << 8;
861 return (clst & 1) ? (wc >> 4) : (wc & 0xFFF);
865 p = &fs->
win[clst * 2 %
SS(fs)];
870 p = &fs->
win[clst * 4 %
SS(fs)];
896 if (clst < 2 || clst >= fs->
n_fatent) {
902 bc = (
UINT)clst; bc += bc / 2;
904 if (res !=
FR_OK)
break;
905 p = &fs->
win[bc %
SS(fs)];
906 *p = (clst & 1) ? ((*p & 0x0F) | ((
BYTE)val << 4)) : (
BYTE)val;
910 if (res !=
FR_OK)
break;
911 p = &fs->
win[bc %
SS(fs)];
912 *p = (clst & 1) ? (
BYTE)(val >> 4) : ((*p & 0xF0) | ((
BYTE)(val >> 8) & 0x0F));
917 if (res !=
FR_OK)
break;
918 p = &fs->
win[clst * 2 %
SS(fs)];
924 if (res !=
FR_OK)
break;
925 p = &fs->
win[clst * 4 %
SS(fs)];
956 DWORD scl = clst, ecl = clst, rt[2];
959 if (clst < 2 || clst >= fs->
n_fatent) {
964 while (clst < fs->n_fatent) {
968 if (nxt == 0xFFFFFFFF) { res =
FR_DISK_ERR;
break; }
970 if (res !=
FR_OK)
break;
976 if (ecl + 1 == nxt) {
1012 if (!scl || scl >= fs->
n_fatent) scl = 1;
1016 if (cs < 2)
return 1;
1017 if (cs < fs->n_fatent)
return cs;
1026 if (ncl > scl)
return 0;
1030 if (cs == 0xFFFFFFFF || cs == 1)
1032 if (ncl == scl)
return 0;
1035 res =
put_fat(fs, ncl, 0x0FFFFFFF);
1036 if (res ==
FR_OK && clst != 0) {
1066 DWORD cl, ncl, *tbl;
1069 tbl = fp->cltbl + 1;
1074 if (cl < ncl)
break;
1147 if (!i || !dj->
sect)
1153 if (dj->
clust == 0) {
1174 for (c = 0; c < dj->
fs->
csize; c++) {
1219 if (res !=
FR_OK)
break;
1220 if (dj->
dir[0] ==
DDE || dj->
dir[0] == 0) {
1221 if (++n == nent)
break;
1226 }
while (res ==
FR_OK);
1273 const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30};
1295 if (uc != 0xFFFF)
return 0;
1317 i = ((dir[
LDIR_Ord] & 0x3F) - 1) * 13;
1324 lfnbuf[i++] = wc = uc;
1326 if (uc != 0xFFFF)
return 0;
1342 const WCHAR *lfnbuf,
1360 if (wc != 0xFFFF) wc = lfnbuf[i++];
1362 if (!wc) wc = 0xFFFF;
1364 if (wc == 0xFFFF || !lfnbuf[i]) ord |=
LLE;
1391 do seq = (seq >> 1) + (seq << 15) + (
WORD)*lfn++;
while (*lfn);
1397 c = (seq % 16) +
'0';
1398 if (c >
'9') c += 7;
1405 for (j = 0; j < i && dst[j] !=
' '; j++) {
1407 if (j == i - 1)
break;
1412 dst[j++] = (i < 8) ? ns[i++] :
' ';
1432 do sum = (sum >> 1) + (sum << 7) + *dir++;
while (--n);
1456 if (res !=
FR_OK)
return res;
1463 if (res !=
FR_OK)
break;
1477 dj->lfn_idx = dj->
index;
1480 ord = (c == ord && sum == dir[
LDIR_Chksum] && cmp_lfn(dj->lfn, dir)) ? ord - 1 : 0xFF;
1483 if (!ord && sum == sum_sfn(dir))
break;
1484 ord = 0xFF; dj->lfn_idx = 0xFFFF;
1493 }
while (res ==
FR_OK);
1504 #if _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2
1514 BYTE ord = 0xFF, sum = 0xFF;
1520 if (res !=
FR_OK)
break;
1533 dj->lfn_idx = dj->
index;
1536 ord = (c == ord && sum == dir[
LDIR_Chksum] && pick_lfn(dj->lfn, dir)) ? ord - 1 : 0xFF;
1538 if (ord || sum != sum_sfn(dir))
1539 dj->lfn_idx = 0xFFFF;
1548 if (res !=
FR_OK)
break;
1571 BYTE sn[12], *fn, sum;
1575 fn = dj->
fn; lfn = dj->lfn;
1582 fn[
NS] = 0; dj->lfn = 0;
1583 for (n = 1; n < 100; n++) {
1584 gen_numname(fn, sn, lfn, n);
1586 if (res !=
FR_OK)
break;
1590 fn[
NS] = sn[
NS]; dj->lfn = lfn;
1594 for (n = 0; lfn[n]; n++) ;
1601 if (res ==
FR_OK && --ne) {
1604 sum = sum_sfn(dj->
fn);
1607 if (res !=
FR_OK)
break;
1608 fit_lfn(dj->lfn, dj->
dir, (
BYTE)ne, sum);
1611 }
while (res ==
FR_OK && --ne);
1640 #if !_FS_READONLY && !_FS_MINIMIZE
1651 res =
dir_sdi(dj, (
WORD)((dj->lfn_idx == 0xFFFF) ? i : dj->lfn_idx));
1655 if (res !=
FR_OK)
break;
1658 if (dj->
index >= i)
break;
1660 }
while (res ==
FR_OK);
1699 for (p = *path; *p ==
'/' || *p ==
'\\'; p++) ;
1704 if (w <
' ' || w ==
'/' || w ==
'\\')
break;
1718 if (w < 0x80 &&
chk_chr(
"\"*:<>\?|\x7F", w))
1725 if ((di == 1 && lfn[di-1] ==
'.') ||
1726 (di == 2 && lfn[di-1] ==
'.' && lfn[di-2] ==
'.')) {
1728 for (i = 0; i < 11; i++)
1729 dj->
fn[i] = (i < di) ?
'.' :
' ';
1736 if (w !=
' ' && w !=
'.')
break;
1745 for (si = 0; lfn[si] ==
' ' || lfn[si] ==
'.'; si++) ;
1747 while (di && lfn[di - 1] !=
'.') di--;
1753 if (w ==
' ' || (w ==
'.' && si != di)) {
1757 if (i >= ni || si == di) {
1763 si = di; i = 8; ni = 11;
1770 if (w) w = ExCvt[w - 0x80];
1777 if (_DF1S && w >= 0x100) {
1781 dj->
fn[i++] = (
BYTE)(w >> 8);
1783 if (!w ||
chk_chr(
"+,;=[]", w)) {
1800 if (ni == 8) b <<= 2;
1801 if ((b & 0x0C) == 0x0C || (b & 0x03) == 0x03)
1804 if ((b & 0x03) == 0x01) cf |=
NS_EXT;
1805 if ((b & 0x0C) == 0x04) cf |=
NS_BODY;
1819 for (p = *path; *p ==
'/' || *p ==
'\\'; p++) ;
1822 si = i = b = 0; ni = 8;
1827 if (c !=
'.' || si >= 3)
break;
1838 if (c <=
' ' || c ==
'/' || c ==
'\\')
break;
1839 if (c ==
'.' || i >= ni) {
1847 c = ExCvt[c - 0x80];
1856 if (!
IsDBCS2(d) || i >= ni - 1)
1861 if (
chk_chr(
"\"*+,:;<=>\?[]|\x7F", c))
1877 if (sfn[0] ==
DDE) sfn[0] =
NDDE;
1879 if (ni == 8) b <<= 2;
1880 if ((b & 0x03) == 0x01) c |=
NS_EXT;
1881 if ((b & 0x0C) == 0x04) c |=
NS_BODY;
1895 #if _FS_MINIMIZE <= 1 || _FS_RPATH >= 2
1911 for (i = 0; i < 8; i++) {
1913 if (c ==
' ')
break;
1918 c = (c << 8) | dir[++i];
1924 if (dir[8] !=
' ') {
1926 for (i = 8; i < 11; i++) {
1928 if (c ==
' ')
break;
1932 c = (c << 8) | dir[++i];
1947 if (fno->lfname && fno->lfsize) {
1948 TCHAR *tp = fno->lfname;
1952 if (dj->
sect && dj->lfn_idx != 0xFFFF) {
1954 while ((w = *lfn++) != 0) {
1957 if (!w) { i = 0;
break; }
1958 if (_DF1S && w >= 0x100)
1959 tp[i++] = (
TCHAR)(w >> 8);
1961 if (i >= fno->lfsize - 1) { i = 0;
break; }
1989 if (*path ==
'/' || *path ==
'\\') {
1995 if (*path ==
'/' || *path ==
'\\')
2000 if ((
UINT)*path <
' ') {
2006 if (res !=
FR_OK)
break;
2015 if (!(ns &
NS_LAST))
continue;
2073 BYTE fmt, b, pi, *tbl;
2076 DWORD bsect, fasize, tsect, sysect, nclst, szbfat;
2078 const TCHAR *p = *path;
2084 if (vol <= 9 && p[1] ==
':') {
2129 if (
LD2PT(vol) && !fmt) fmt = 1;
2171 nclst = (tsect - sysect) / fs->
csize;
2192 if (fs->
fsize < (szbfat + (
SS(fs) - 1)) /
SS(fs))
2285 if (!ff_del_syncobj(rfs->sobj))
return FR_INT_ERR;
2293 if (!ff_cre_syncobj(vol, &fs->sobj))
return FR_INT_ERR;
2340 res = chk_lock(&dj, (mode & ~
FA_READ) ? 1 : 0);
2399 fp->lockid = inc_lock(&dj, (mode & ~
FA_READ) ? 1 : 0);
2448 DWORD clst, sect, remain;
2462 if (btr > remain) btr = (
UINT)remain;
2465 rbuff += rcnt, fp->
fptr += rcnt, *br += rcnt, btr -= rcnt) {
2466 if ((fp->
fptr %
SS(fp->
fs)) == 0) {
2469 if (fp->
fptr == 0) {
2474 clst = clmt_clust(fp, fp->
fptr);
2486 cc = btr /
SS(fp->
fs);
2488 if (csect + cc > fp->
fs->
csize)
2492 #if !_FS_READONLY && _FS_MINIMIZE <= 2
2501 rcnt =
SS(fp->
fs) * cc;
2505 if (fp->
dsect != sect) {
2520 if (rcnt > btr) rcnt = btr;
2551 const BYTE *wbuff = (
const BYTE*)buff;
2566 wbuff += wcnt, fp->
fptr += wcnt, *bw += wcnt, btw -= wcnt) {
2567 if ((fp->
fptr %
SS(fp->
fs)) == 0) {
2570 if (fp->
fptr == 0) {
2577 clst = clmt_clust(fp, fp->
fptr);
2582 if (clst == 0)
break;
2600 cc = btw /
SS(fp->
fs);
2602 if (csect + cc > fp->
fs->
csize)
2612 if (fp->
dsect - sect < cc) {
2617 wcnt =
SS(fp->
fs) * cc;
2626 if (fp->
dsect != sect) {
2635 if (wcnt > btw) wcnt = btw;
2732 res = dec_lock(fp->lockid);
2733 unlock_fs(fs,
FR_OK);
2736 res = dec_lock(fp->lockid);
2819 while ((ccl = dj.
sclust) != 0) {
2821 if (res !=
FR_OK)
break;
2823 if (res !=
FR_OK)
break;
2826 if (res !=
FR_OK)
break;
2829 if (res !=
FR_OK)
break;
2832 }
while (res ==
FR_OK);
2834 if (res !=
FR_OK)
break;
2842 for (n = 0; tp[n]; n++) ;
2846 while (n) buff[--i] = tp[--n];
2851 *tp++ =
'0' + CurrVol;
2872 #if _FS_MINIMIZE <= 2
2892 DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl;
2896 tlen = *tbl++; ulen = 2;
2901 tcl = cl; ncl = 0; ulen += 2;
2907 }
while (cl == pcl + 1);
2909 *tbl++ = ncl; *tbl++ = tcl;
2920 if (ofs > fp->
fsize)
2924 fp->
clust = clmt_clust(fp, ofs - 1);
2927 dsc += (ofs - 1) /
SS(fp->
fs) & (fp->
fs->
csize - 1);
2949 DWORD clst, bcs, nsect, ifptr;
2958 fp->
fptr = nsect = 0;
2962 (ofs - 1) / bcs >= (ifptr - 1) / bcs) {
2963 fp->
fptr = (ifptr - 1) & ~(bcs - 1);
2996 if (ofs %
SS(fp->
fs)) {
2999 nsect += ofs /
SS(fp->
fs);
3030 #if _FS_MINIMIZE <= 1
3119 #if _FS_MINIMIZE == 0
3165 DWORD n, clst, sect, stat;
3185 if (stat == 0xFFFFFFFF) { res =
FR_DISK_ERR;
break; }
3188 }
while (++clst < fs->n_fatent);
3196 if (res !=
FR_OK)
break;
3204 if ((
LD_DWORD(p) & 0x0FFFFFFF) == 0) n++;
3245 if (fp->
fptr == 0) {
3290 if (res ==
FR_OK) res = chk_lock(&dj, 2);
3312 || dclst == dj.
fs->cdir
3377 dir[33] =
'.'; pcl = dj.
sclust;
3381 for (n = dj.
fs->
csize; n; n--) {
3385 if (res !=
FR_OK)
break;
3498 const TCHAR *path_old,
3499 const TCHAR *path_new
3517 if (res ==
FR_OK) res = chk_lock(&djo, 2);
3542 if (res ==
FR_OK && dir[1] ==
'.') {
3592 if (res ==
FR_OK && label) {
3602 w = (i < 11) ? dj.
dir[i++] :
' ';
3604 w = (w << 8) | dj.
dir[i++];
3614 }
while (label[--j] ==
' ');
3624 if (res ==
FR_OK && sn) {
3660 for (sl = 0; label[sl]; sl++) ;
3661 for ( ; sl && label[sl-1] ==
' '; sl--) ;
3668 w = (
BYTE)label[i++];
3670 w = (j < 10 && i < sl &&
IsDBCS2(label[i])) ? (w << 8) | (
BYTE)label[i++] : 0;
3676 if (w >= 0x80) w = ExCvt[w - 0x80];
3678 if (!_DF1S && w >= 0x80) w = 0;
3682 if (!w ||
chk_chr(
"\"*+,.:;<=>\?[]|\x7F", w) || j >= (
UINT)((w >= 0x100) ? 10 : 11))
3684 if (w >= 0x100) vn[j++] = (
BYTE)(w >> 8);
3687 while (j < 11) vn[j++] =
' ';
3735 #if _USE_FORWARD && _FS_TINY
3745 DWORD remain, clst, sect;
3760 if (btf > remain) btf = (
UINT)remain;
3762 for ( ; btf && (*func)(0, 0);
3763 fp->
fptr += rcnt, *bf += rcnt, btf -= rcnt) {
3765 if ((fp->
fptr %
SS(fp->
fs)) == 0) {
3767 clst = (fp->
fptr == 0) ?
3781 if (rcnt > btf) rcnt = btf;
3792 #if _USE_MKFS && !_FS_READONLY
3796 #define N_ROOTDIR 512
3806 static const WORD vst[] = { 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 0};
3807 static const WORD cst[] = {32768, 16384, 8192, 4096, 2048, 16384, 8192, 4096, 2048, 1024, 512};
3808 BYTE fmt, md, sys, *tbl, pdrv, part;
3809 DWORD n_clst, vs, n, wsect;
3811 DWORD b_vol, b_fat, b_dir, b_data;
3812 DWORD n_vol, n_rsv, n_fat, n_dir;
3847 b_vol = (sfd) ? 0 : 63;
3852 vs = n_vol / (2000 / (
SS(fs) / 512));
3853 for (i = 0; vs < vst[i]; i++) ;
3857 if (au == 0) au = 1;
3858 if (au > 128) au = 128;
3861 n_clst = n_vol / au;
3868 n_fat = ((n_clst * 4) + 8 +
SS(fs) - 1) /
SS(fs);
3872 n_fat = (fmt ==
FS_FAT12) ? (n_clst * 3 + 1) / 2 + 3 : (n_clst * 2) + 4;
3873 n_fat = (n_fat +
SS(fs) - 1) /
SS(fs);
3877 b_fat = b_vol + n_rsv;
3878 b_dir = b_fat + n_fat * N_FATS;
3879 b_data = b_dir + n_dir;
3884 n = (b_data + n - 1) & ~(n - 1);
3885 n = (n - b_data) / N_FATS;
3894 n_clst = (n_vol - n_rsv - n_fat * N_FATS - n_dir) / au;
3901 case FS_FAT16: sys = (n_vol < 0x10000) ? 0x04 : 0x06;
break;
3902 default: sys = 0x0C;
3922 n = (b_vol + n_vol) / 63 / 255;
3923 tbl[6] = (
BYTE)((n >> 2) | 63);
3937 mem_cpy(tbl,
"\xEB\xFE\x90" "MSDOS5.0", 11);
3943 i = (fmt ==
FS_FAT32) ? 0 : N_ROOTDIR;
3945 if (n_vol < 0x10000) {
3979 for (i = 0; i < N_FATS; i++) {
3983 n |= (fmt ==
FS_FAT12) ? 0x00FFFF00 : 0xFFFFFF00;
3994 for (n = 1; n < n_fat; n++) {
4001 i = (fmt ==
FS_FAT32) ? au : n_dir;
4011 eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt ==
FS_FAT32) ? 1 : 0)) * au - 1;
4031 #if _MULTI_PARTITION
4042 UINT i, n, sz_cyl, tot_cyl, b_cyl, e_cyl, p_cyl;
4043 BYTE s_hd, e_hd, *p, *buf = (
BYTE*)work;
4045 DWORD sz_disk, sz_part, s_part;
4054 for (n = 16; n < 256 && sz_disk / n / 63 > 1024; n *= 2) ;
4058 tot_cyl = sz_disk / sz_cyl;
4063 for (i = 0; i < 4; i++, p +=
SZ_PTE) {
4064 p_cyl = (szt[i] <= 100) ? (
DWORD)tot_cyl * szt[i] / 100 : szt[i] / sz_cyl;
4065 if (!p_cyl)
continue;
4066 s_part = (
DWORD)sz_cyl * b_cyl;
4067 sz_part = (
DWORD)sz_cyl * p_cyl;
4070 s_part += 63; sz_part -= 63;
4074 e_cyl = b_cyl + p_cyl - 1;
4079 p[2] = (
BYTE)((b_cyl >> 2) + 1);
4083 p[6] = (
BYTE)((e_cyl >> 2) + 63);
4121 while (n < len - 1) {
4127 if (c < 0xC0)
continue;
4131 c = ((c & 0x1F) << 6) | (s[0] & 0x3F);
4132 if (c < 0x80) c =
'?';
4137 c = (c << 12) | ((s[0] & 0x3F) << 6) | (s[1] & 0x3F);
4138 if (c < 0x800) c =
'?';
4145 #if _USE_STRFUNC >= 2
4146 if (c ==
'\r')
continue;
4150 if (c ==
'\n')
break;
4153 return n ? buff : 0;
4173 #if _USE_STRFUNC >= 2
4174 if (c ==
'\n')
f_putc (
'\r', fp);
4183 s[0] = (
BYTE)(0xC0 | (c >> 6));
4184 s[1] = (
BYTE)(0x80 | (c & 0x3F));
4187 s[0] = (
BYTE)(0xE0 | (c >> 12));
4188 s[1] = (
BYTE)(0x80 | ((c >> 6) & 0x3F));
4189 s[2] = (
BYTE)(0x80 | (c & 0x3F));
4198 return (bw == btw) ? 1 :
EOF;
4216 for (n = 0; *str; str++, n++) {
4239 TCHAR c, d, s[16], *p;
4245 for (cc = res = 0; cc !=
EOF; res += cc) {
4250 if (cc !=
EOF) cc = 1;
4263 w = w * 10 + c -
'0';
4266 if (c ==
'l' || c ==
'L') {
4274 p = va_arg(arp,
TCHAR*);
4275 for (j = 0; p[j]; j++) ;
4278 while (j++ < w) chc += (cc =
f_putc(
' ', fp));
4280 chc += (cc =
f_puts(p, fp));
4281 while (j++ < w) chc += (cc =
f_putc(
' ', fp));
4282 if (cc !=
EOF) cc = chc;
4285 cc =
f_putc((
TCHAR)va_arg(arp,
int), fp);
continue;
4296 cc =
f_putc(c, fp);
continue;
4300 v = (f & 4) ? (
ULONG)va_arg(arp,
long) : ((d ==
'D') ? (
ULONG)(long)va_arg(arp, int) : (
ULONG)va_arg(arp, unsigned int));
4301 if (d ==
'D' && (v & 0x80000000)) {
4307 d = (
TCHAR)(v % r); v /= r;
4308 if (d > 9) d += (c ==
'x') ? 0x27 : 0x07;
4310 }
while (v && i <
sizeof s /
sizeof s[0]);
4311 if (f & 8) s[i++] =
'-';
4312 j = i; d = (f & 1) ?
'0' :
' ';
4314 while (!(f & 2) && j++ < w) chc += (cc =
f_putc(d, fp));
4315 do chc += (cc =
f_putc(s[--i], fp));
while(i);
4316 while (j++ < w) chc += (cc =
f_putc(
' ', fp));
4317 if (cc !=
EOF) cc = chc;
4321 return (cc ==
EOF) ? cc : res;