30#error Wrong include file (ff.h).
37#error Static LFN work area cannot be used at thread-safe configuration
39#define ENTER_FF(fs) { if (!lock_fs(fs)) return FR_TIMEOUT; }
40#define LEAVE_FF(fs, res) { unlock_fs(fs, res); return res; }
43#define LEAVE_FF(fs, res) return res
46#define ABORT(fs, res) { fp->err = (BYTE)(res); LEAVE_FF(fs, res); }
50#if (_MAX_SS < _MIN_SS) || (_MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096) || (_MIN_SS != 512 && _MIN_SS != 1024 && _MIN_SS != 2048 && _MIN_SS != 4096)
51#error Wrong sector size configuration
54#define SS(fs) ((UINT)_MAX_SS)
56#define SS(fs) ((fs)->ssize)
62#if _NORTC_YEAR < 1980 || _NORTC_YEAR > 2107 || _NORTC_MON < 1 || _NORTC_MON > 12 || _NORTC_MDAY < 1 || _NORTC_MDAY > 31
63#error Invalid _FS_NORTC settings
65#define GET_FATTIME() ((DWORD)(_NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16)
67#define GET_FATTIME() get_fattime()
74#error _FS_LOCK must be 0 at read-only configuration
98#elif _CODE_PAGE == 936
106#elif _CODE_PAGE == 949
116#elif _CODE_PAGE == 950
124#elif _CODE_PAGE == 437
126#define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
127 0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
128 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
129 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
130 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0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86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
149 0x90,0x92,0x92,0x93,0x94,0x95,0x96,0x97,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, \
150 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0xAA,0x92,0x93,0x94,0x95,0x96, \
151 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
152 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
153 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
154 0x97,0xEA,0xEB,0xEC,0xE4,0xED,0xEE,0xEF,0xF5,0xF0,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
155 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
157#elif _CODE_PAGE == 771
159#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
160 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
161 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
162 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
163 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
164 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDC,0xDE,0xDE, \
165 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
166 0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFE,0xFF}
168#elif _CODE_PAGE == 775
170#define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F, \
171 0x90,0x92,0x92,0xE2,0x99,0x95,0x96,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \
172 0xA0,0xA1,0xE0,0xA3,0xA3,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
173 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
174 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
175 0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xA5,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
176 0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE3,0xE8,0xE8,0xEA,0xEA,0xEE,0xED,0xEE,0xEF, \
177 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
179#elif _CODE_PAGE == 850
181#define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x41,0x43,0x45,0x45,0x45,0x49,0x49,0x49,0x41,0x41, \
182 0x45,0x92,0x92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0xDB,0xDC,0xDD,0xDE,0xDF, \
231 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
232 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
234#elif _CODE_PAGE == 861
236#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x8B,0x8B,0x8D,0x8E,0x8F, \
237 0x90,0x92,0x92,0x4F,0x99,0x8D,0x55,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \
238 0xA4,0xA5,0xA6,0xA7,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
239 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
240 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
241 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
242 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
243 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
245#elif _CODE_PAGE == 862
247#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
248 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0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0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
265 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
267#elif _CODE_PAGE == 864
269#define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
270 0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
271 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
272 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
273 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
274 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \
275 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \
276 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
278#elif _CODE_PAGE == 865
280#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \
281 0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
282 0x41,0x49,0x4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0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \
298 0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}
300#elif _CODE_PAGE == 869
302#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \
303 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x86,0x9C,0x8D,0x8F,0x90, \
304 0x91,0x90,0x92,0x95,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \
305 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \
306 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \
307 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xA4,0xA5,0xA6,0xD9,0xDA,0xDB,0xDC,0xA7,0xA8,0xDF, \
308 0xA9,0xAA,0xAC,0xAD,0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xCF,0xCF,0xD0,0xEF, \
309 0xF0,0xF1,0xD1,0xD2,0xD3,0xF5,0xD4,0xF7,0xF8,0xF9,0xD5,0x96,0x95,0x98,0xFE,0xFF}
313#error Cannot use LFN feature without valid code page.
318#error Unknown code page
324#define IsUpper(c) (((c)>='A')&&((c)<='Z'))
325#define IsLower(c) (((c)>='a')&&((c)<='z'))
326#define IsDigit(c) (((c)>='0')&&((c)<='9'))
331#define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E))
333#define IsDBCS1(c) ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E)
337#define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E))
339#define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E))
361#define MIN_FAT16 4086U
362#define MIN_FAT32 65526U
371#define BPB_BytsPerSec 11
372#define BPB_SecPerClus 13
373#define BPB_RsvdSecCnt 14
374#define BPB_NumFATs 16
375#define BPB_RootEntCnt 17
376#define BPB_TotSec16 19
378#define BPB_FATSz16 22
379#define BPB_SecPerTrk 24
380#define BPB_NumHeads 26
381#define BPB_HiddSec 28
382#define BPB_TotSec32 32
388#define BS_FilSysType 54
389#define BPB_FATSz32 36
390#define BPB_ExtFlags 40
392#define BPB_RootClus 44
394#define BPB_BkBootSec 50
395#define BS_DrvNum32 64
397#define BS_BootSig32 66
399#define BS_VolLab32 71
400#define BS_FilSysType32 82
402#define FSI_StrucSig 484
403#define FSI_Free_Count 488
404#define FSI_Nxt_Free 492
412#define DIR_CrtTimeTenth 13
413#define DIR_CrtTime 14
414#define DIR_CrtDate 16
415#define DIR_LstAccDate 18
416#define DIR_FstClusHI 20
417#define DIR_WrtTime 22
418#define DIR_WrtDate 24
419#define DIR_FstClusLO 26
420#define DIR_FileSize 28
424#define LDIR_Chksum 13
425#define LDIR_FstClusLO 26
445#if _VOLUMES < 1 || _VOLUMES > 9
446#error Wrong _VOLUMES setting
451#if _FS_RPATH && _VOLUMES >= 2
460#define DEFINE_NAMEBUF BYTE sfn[12]
461#define INIT_BUF(dobj) (dobj).fn = sfn
464#if _MAX_LFN < 12 || _MAX_LFN > 255
465#error Wrong _MAX_LFN setting
469#define DEFINE_NAMEBUF BYTE sfn[12]
470#define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = LfnBuf; }
473#define DEFINE_NAMEBUF BYTE sfn[12]; WCHAR lbuf[_MAX_LFN + 1]
474#define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = lbuf; }
477#define DEFINE_NAMEBUF BYTE sfn[12]; WCHAR *lfn
478#define INIT_BUF(dobj) { lfn = ff_memalloc((_MAX_LFN + 1) * 2); if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); (dobj).lfn = lfn; (dobj).fn = sfn; }
479#define FREE_BUF() ff_memfree(lfn)
481#error Wrong _USE_LFN setting
512 while (cnt >=
sizeof (
int)) {
514 d +=
sizeof (
int);
s +=
sizeof (
int);
537 while (cnt-- && (
r = *
d++ - *
s++) == 0) ;
560 return ff_req_grant(
fs->sobj);
575 ff_rel_grant(
fs->sobj);
599 if (Files[
i].
fs == dp->
fs &&
601 Files[
i].idx == dp->
index)
break;
634 if (Files[
i].
fs == dp->
fs &&
636 Files[
i].idx == dp->
index)
break;
642 Files[
i].fs = dp->
fs;
648 if (acc && Files[
i].ctr)
return 0;
650 Files[
i].ctr = acc ? 0x100 : Files[
i].ctr + 1;
667 if (
n == 0x100)
n = 0;
670 if (!
n) Files[
i].fs = 0;
687 if (Files[
i].
fs ==
fs) Files[
i].fs = 0;
715 if (wsect -
fs->fatbase <
fs->fsize) {
716 for (nf =
fs->n_fats; nf >= 2; nf--) {
779 fs->winsect =
fs->volbase + 1;
806 if (clst >=
fs->n_fatent - 2)
return 0;
807 return clst *
fs->csize +
fs->database;
828 if (clst < 2 || clst >=
fs->n_fatent) {
834 switch (
fs->fs_type) {
841 val = clst & 1 ? wc >> 4 : (wc & 0xFFF);
846 p = &
fs->win[clst * 2 %
SS(
fs)];
852 p = &
fs->win[clst * 4 %
SS(
fs)];
884 if (clst < 2 || clst >=
fs->n_fatent) {
888 switch (
fs->fs_type) {
899 *
p = (clst & 1) ? (
BYTE)(
val >> 4) : ((*
p & 0xF0) | ((
BYTE)(
val >> 8) & 0x0F));
906 p = &
fs->win[clst * 2 %
SS(
fs)];
914 p = &
fs->win[clst * 4 %
SS(
fs)];
945 DWORD scl = clst, ecl = clst, rt[2];
948 if (clst < 2 || clst >=
fs->n_fatent) {
953 while (clst < fs->n_fatent) {
960 if (
fs->free_clust != 0xFFFFFFFF) {
965 if (ecl + 1 == nxt) {
1000 scl =
fs->last_clust;
1001 if (!scl || scl >=
fs->n_fatent) scl = 1;
1005 if (
cs < 2)
return 1;
1006 if (
cs == 0xFFFFFFFF)
return cs;
1007 if (cs < fs->n_fatent)
return cs;
1014 if (ncl >=
fs->n_fatent) {
1016 if (ncl > scl)
return 0;
1020 if (
cs == 0xFFFFFFFF ||
cs == 1)
1022 if (ncl == scl)
return 0;
1030 fs->last_clust = ncl;
1031 if (
fs->free_clust != 0xFFFFFFFF) {
1057 DWORD cl, ncl, *tbl;
1060 tbl = fp->cltbl + 1;
1065 if (cl < ncl)
break;
1141 if (!(
i & 0xFFFF) || !dp->
sect)
1215 if (++
n == nent)
break;
1270const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30};
1287 for (wc = 1,
s = 0;
s < 13;
s++) {
1294 if (uc != 0xFFFF)
return 0;
1320 for (wc = 1,
s = 0;
s < 13;
s++) {
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 |=
LLEF;
1398 for (
i = 0;
i < 16;
i++) {
1399 sr = (sr << 1) + (wc & 1);
1401 if (sr & 0x10000) sr ^= 0x11021;
1410 c = (seq % 16) +
'0';
1411 if (
c >
'9')
c += 7;
1418 for (
j = 0;
j <
i &&
dst[
j] !=
' ';
j++) {
1420 if (
j ==
i - 1)
break;
1425 dst[
j++] = (
i < 8) ?
ns[
i++] :
' ';
1483 ord = 0xFF; dp->
lfn_idx = 0xFFFF;
1489 c &= ~LLEF; ord =
c;
1498 ord = 0xFF; dp->
lfn_idx = 0xFFFF;
1517#if _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2
1545 c &= ~LLEF; ord =
c;
1597 for (
n = 1;
n < 100;
n++) {
1608 for (
n = 0; lfn[
n];
n++) ;
1609 nent = (
n + 25) / 13;
1654#if !_FS_READONLY && !_FS_MINIMIZE
1673 if (dp->
index >=
i)
break;
1701#if _FS_MINIMIZE <= 1 || _FS_RPATH >= 2
1721 if (
c ==
' ')
continue;
1723 if (
i == 9) *
p++ =
'.';
1748 while ((
w = *lfn++) != 0) {
1751 if (!
w) {
i = 0;
break; }
1755 if (
i >= fno->
lfsize - 1) {
i = 0;
break; }
1771#if _USE_FIND && _FS_MINIMIZE <= 1
1781 if (
IsLower(chr)) chr -= 0x20;
1783 chr = chr << 8 | (
BYTE)*(*ptr)++;
1785 if (chr >= 0x80) chr =
ExCvt[chr - 0x80];
1795int pattern_matching (
1802 const TCHAR *pp, *np;
1808 if (!get_achar(&nam))
return 0;
1810 if (!*pat && inf)
return 1;
1815 if (*pp ==
'?' || *pp ==
'*') {
1818 if (*pp++ ==
'?') nm++;
else nx = 1;
1819 }
while (*pp ==
'?' || *pp ==
'*');
1820 if (pattern_matching(pp, np, nm,
nx))
return 1;
1823 pc = get_achar(&pp);
1824 nc = get_achar(&np);
1825 if (pc != nc)
break;
1829 }
while (inf && nc);
1855 for (
p = *
path; *
p ==
'/' || *
p ==
'\\';
p++) ;
1860 if (
w <
' ' ||
w ==
'/' ||
w ==
'\\')
break;
1874 if (
w < 0x80 &&
chk_chr(
"\"*:<>\?|\x7F",
w))
1881 if ((di == 1 && lfn[di - 1] ==
'.') ||
1882 (di == 2 && lfn[di - 1] ==
'.' && lfn[di - 2] ==
'.')) {
1884 for (
i = 0;
i < 11;
i++)
1885 dp->
fn[
i] = (
i < di) ?
'.' :
' ';
1892 if (
w !=
' ' &&
w !=
'.')
break;
1900 for (si = 0; lfn[si] ==
' ' || lfn[si] ==
'.'; si++) ;
1902 while (di && lfn[di - 1] !=
'.') di--;
1908 if (
w ==
' ' || (
w ==
'.' && si != di)) {
1912 if (
i >=
ni || si == di) {
1918 si = di;
i = 8;
ni = 11;
1932 if (
_DF1S &&
w >= 0x100) {
1955 if (
ni == 8)
b <<= 2;
1956 if ((
b & 0x0C) == 0x0C || (
b & 0x03) == 0x03)
1974 for (
p = *
path; *
p ==
'/' || *
p ==
'\\';
p++) ;
1977 si =
i =
b = 0;
ni = 8;
1982 if (
c !=
'.' || si >= 3)
break;
1993 if (
c <=
' ' ||
c ==
'/' ||
c ==
'\\')
break;
1994 if (
c ==
'.' ||
i >=
ni) {
2016 if (
chk_chr(
"\"*+,:;<=>\?[]|\x7F",
c))
2034 if (
ni == 8)
b <<= 2;
2035 if ((
b & 0x03) == 0x01)
c |=
NS_EXT;
2062 if (*
path ==
'/' || *
path ==
'\\') {
2130 for (tt = *
path; (
UINT)*tt >= (
_USE_LFN ?
' ' :
'!') && *tt !=
':'; tt++) ;
2134 if (
i < 10 &&
tp == tt) {
2158#if _FS_RPATH && _VOLUMES >= 2
2180 fs->wflag = 0;
fs->winsect = 0xFFFFFFFF;
2212 DWORD bsect, fasize, tsect, sysect, nclst, szbfat, br[4];
2249#if _MAX_SS != _MIN_SS
2257 for (
i = 0;
i < 4;
i++) {
2266 }
while (!
LD2PT(vol) &&
fmt && ++
i < 4);
2281 if (
fs->n_fats != 1 &&
fs->n_fats != 2)
2283 fasize *=
fs->n_fats;
2286 if (!
fs->csize || (
fs->csize & (
fs->csize - 1)))
2300 sysect = nrsv + fasize +
fs->n_rootdir / (
SS(
fs) /
SZ_DIRE);
2302 nclst = (tsect - sysect) /
fs->csize;
2309 fs->n_fatent = nclst + 2;
2310 fs->volbase = bsect;
2311 fs->fatbase = bsect + nrsv;
2312 fs->database = bsect + sysect;
2316 szbfat =
fs->n_fatent * 4;
2319 fs->dirbase =
fs->fatbase + fasize;
2321 fs->n_fatent * 2 :
fs->n_fatent * 3 / 2 + (
fs->n_fatent & 1);
2323 if (
fs->fsize < (szbfat + (
SS(
fs) - 1)) /
SS(
fs))
2328 fs->last_clust =
fs->free_clust = 0xFFFFFFFF;
2331 fs->fsi_flag = 0x80;
2332#if (_FS_NOFSINFO & 3) != 3
2342#if (_FS_NOFSINFO & 1) == 0
2345#if (_FS_NOFSINFO & 2) == 0
2423 if (!ff_del_syncobj(cfs->sobj))
return FR_INT_ERR;
2436 if (!
fs || opt != 1)
return FR_OK;
2543 fp->lockid = inc_lock(&dj, (
mode & ~
FA_READ) ? 1 : 0);
2594 DWORD clst, sect, remain;
2608 if (btr > remain) btr = (
UINT)remain;
2611 rbuff += rcnt, fp->
fptr += rcnt, *br += rcnt, btr -= rcnt) {
2612 if ((fp->
fptr %
SS(fp->
fs)) == 0) {
2615 if (fp->
fptr == 0) {
2620 clst = clmt_clust(fp, fp->
fptr);
2638#if !_FS_READONLY && _FS_MINIMIZE <= 2
2651 if (fp->
dsect != sect) {
2656 fp->
flag &= ~FA__DIRTY;
2666 if (rcnt > btr) rcnt = btr;
2709 if (fp->
fptr + btw < fp->fptr) btw = 0;
2712 wbuff += wcnt, fp->
fptr += wcnt, *
bw += wcnt, btw -= wcnt) {
2713 if ((fp->
fptr %
SS(fp->
fs)) == 0) {
2716 if (fp->
fptr == 0) {
2723 clst = clmt_clust(fp, fp->
fptr);
2728 if (clst == 0)
break;
2741 fp->
flag &= ~FA__DIRTY;
2753#if _FS_MINIMIZE <= 2
2762 fp->
flag &= ~FA__DIRTY;
2775 if (fp->
dsect != sect) {
2784 if (wcnt > btw) wcnt = btw;
2825 fp->
flag &= ~FA__DIRTY;
2838 fp->
flag &= ~FA__WRITTEN;
2875 res = dec_lock(fp->lockid);
2906 CurrVol = (
BYTE)vol;
2967 while ((ccl = dj.
sclust) != 0) {
2992 for (
n = 0;
tp[
n];
n++) ;
3002 *
tp++ =
'0' + CurrVol;
3024#if _FS_MINIMIZE <= 2
3035 DWORD clst, bcs, nsect, ifptr;
3037 DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl;
3050 tlen = *tbl++; ulen = 2;
3055 tcl = cl; ncl = 0; ulen += 2;
3061 }
while (cl == pcl + 1);
3063 *tbl++ = ncl; *tbl++ = tcl;
3065 }
while (cl < fp->
fs->n_fatent);
3074 if (ofs > fp->
fsize)
3078 fp->
clust = clmt_clust(fp, ofs - 1);
3081 dsc += (ofs - 1) /
SS(fp->
fs) & (fp->
fs->
csize - 1);
3088 fp->
flag &= ~FA__DIRTY;
3110 fp->
fptr = nsect = 0;
3114 (ofs - 1) / bcs >= (ifptr - 1) / bcs) {
3115 fp->
fptr = (ifptr - 1) & ~(bcs - 1);
3148 if (ofs %
SS(fp->
fs)) {
3151 nsect += ofs /
SS(fp->
fs);
3161 fp->
flag &= ~FA__DIRTY;
3182#if _FS_MINIMIZE <= 1
3219 dp->lockid = inc_lock(dp, 0);
3257 res = dec_lock(dp->lockid);
3329 if (fno->
lfname && pattern_matching(dp->pat, fno->
lfname, 0, 0))
break;
3331 if (pattern_matching(dp->pat, fno->
fname, 0, 0))
break;
3364#if _FS_MINIMIZE == 0
3422 if (
fs->free_clust <=
fs->n_fatent - 2) {
3423 *nclst =
fs->free_clust;
3434 if (
stat == 0) nfree++;
3435 }
while (++clst < fs->n_fatent);
3437 clst =
fs->n_fatent; sect =
fs->fatbase;
3450 if ((
LD_DWORD(
p) & 0x0FFFFFFF) == 0) nfree++;
3455 fs->free_clust = nfree;
3491 if (fp->
fptr == 0) {
3499 if (
res ==
FR_OK && ncl < fp->
fs->n_fatent) {
3509 fp->
flag &= ~FA__DIRTY;
3559 if (dclst == dj.
fs->cdir) {
3714 const TCHAR* path_old,
3715 const TCHAR* path_new
3848#if _USE_LFN && _LFN_UNICODE
3863#if _USE_LFN && _LFN_UNICODE
3866 w = (
i < 11) ? dj.
dir[
i++] :
' ';
3868 w =
w << 8 | dj.
dir[
i++];
3878 }
while (
label[--
j] ==
' ');
3924 for (sl = 0;
label[sl]; sl++) ;
3925 for ( ; sl &&
label[sl - 1] ==
' '; sl--) ;
3929#if _USE_LFN && _LFN_UNICODE
3940 if (
w >= 0x80)
w =
ExCvt[
w - 0x80];
3942 if (!
_DF1S &&
w >= 0x80)
w = 0;
3946 if (!
w ||
chk_chr(
"\"*+,.:;<=>\?[]|\x7F",
w) ||
j >= (
UINT)((
w >= 0x100) ? 10 : 11))
3948 if (
w >= 0x100)
vn[
j++] = (
BYTE)(
w >> 8);
3951 while (
j < 11)
vn[
j++] =
' ';
4002#if _USE_FORWARD && _FS_TINY
4012 DWORD remain, clst, sect;
4027 if (btf > remain) btf = (
UINT)remain;
4029 for ( ; btf && (*func)(0, 0);
4030 fp->
fptr += rcnt, *bf += rcnt, btf -= rcnt) {