Animation demo with MIP8F_SPI_Ver60
Dependencies: mbed MIP8F_SPI_Ver60 MIP8f_FRDM_LineBuffer_sample MIP8f_FRDM_TransferMode_sample
Introduction
Animation Demo. Some Goldfish swin in water, from left to right, from bottom to top. Color and monochrome version
Only for LPM027M128x (400x240) ,JDI DIsplay.
Other information , please refer to https://os.mbed.com/teams/JapanDisplayInc/code/MIP8f_FRDM_sample/
Usage
Copy Setting File and Image to micro SD-CARD. you can NOT use same sample color images of OTHER VERSION SAMPLE.
a) Download the following file corresponding to the target panel, and rename file identifier (.bin -> .zip), and unzip the file on micro SD Card's root directory.
LPM027M128x (400x240) :/media/uploads/JDI_Mbed_Team/goldfish_400x240.bin
b) Insert micro SD-CARD to FRDM-K64F. c) Upload binary file to FRDM-K64F.and push Reset Button.
Other information
refer to Usage on https://os.mbed.com/teams/JapanDisplayInc/code/MIP8f_FRDM_sample/
this Sample Code (.bin)
/media/uploads/JDI_Mbed_Team/mip8f_frdm_animation_sample.k64f.bin
SDFileSystem/FATFileSystem/ChaN/ff.cpp@0:33fe30a2b785, 2018-09-04 (annotated)
- Committer:
- JDI_Mbed_Team
- Date:
- Tue Sep 04 06:44:01 2018 +0000
- Revision:
- 0:33fe30a2b785
JDI_MIP8F sample
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JDI_Mbed_Team | 0:33fe30a2b785 | 1 | /*----------------------------------------------------------------------------/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2 | / FatFs - FAT file system module R0.11a (C)ChaN, 2015 / |
JDI_Mbed_Team | 0:33fe30a2b785 | 3 | /-----------------------------------------------------------------------------/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4 | / FatFs module is a free software that opened under license policy of |
JDI_Mbed_Team | 0:33fe30a2b785 | 5 | / following conditions. |
JDI_Mbed_Team | 0:33fe30a2b785 | 6 | / |
JDI_Mbed_Team | 0:33fe30a2b785 | 7 | / Copyright (C) 2015, ChaN, all right reserved. |
JDI_Mbed_Team | 0:33fe30a2b785 | 8 | / |
JDI_Mbed_Team | 0:33fe30a2b785 | 9 | / 1. Redistributions of source code must retain the above copyright notice, |
JDI_Mbed_Team | 0:33fe30a2b785 | 10 | / this condition and the following disclaimer. |
JDI_Mbed_Team | 0:33fe30a2b785 | 11 | / |
JDI_Mbed_Team | 0:33fe30a2b785 | 12 | / This software is provided by the copyright holder and contributors "AS IS" |
JDI_Mbed_Team | 0:33fe30a2b785 | 13 | / and any warranties related to this software are DISCLAIMED. |
JDI_Mbed_Team | 0:33fe30a2b785 | 14 | / The copyright owner or contributors be NOT LIABLE for any damages caused |
JDI_Mbed_Team | 0:33fe30a2b785 | 15 | / by use of this software. |
JDI_Mbed_Team | 0:33fe30a2b785 | 16 | /----------------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 17 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 18 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 19 | #include "ff.h" /* Declarations of FatFs API */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 20 | #include "diskio.h" /* Declarations of disk I/O functions */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 21 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 22 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 23 | /*-------------------------------------------------------------------------- |
JDI_Mbed_Team | 0:33fe30a2b785 | 24 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 25 | Module Private Definitions |
JDI_Mbed_Team | 0:33fe30a2b785 | 26 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 27 | ---------------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 28 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 29 | #if _FATFS != 64180 /* Revision ID */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 30 | #error Wrong include file (ff.h). |
JDI_Mbed_Team | 0:33fe30a2b785 | 31 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 32 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 33 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 34 | /* Reentrancy related */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 35 | #if _FS_REENTRANT |
JDI_Mbed_Team | 0:33fe30a2b785 | 36 | #if _USE_LFN == 1 |
JDI_Mbed_Team | 0:33fe30a2b785 | 37 | #error Static LFN work area cannot be used at thread-safe configuration |
JDI_Mbed_Team | 0:33fe30a2b785 | 38 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 39 | #define ENTER_FF(fs) { if (!lock_fs(fs)) return FR_TIMEOUT; } |
JDI_Mbed_Team | 0:33fe30a2b785 | 40 | #define LEAVE_FF(fs, res) { unlock_fs(fs, res); return res; } |
JDI_Mbed_Team | 0:33fe30a2b785 | 41 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 42 | #define ENTER_FF(fs) |
JDI_Mbed_Team | 0:33fe30a2b785 | 43 | #define LEAVE_FF(fs, res) return res |
JDI_Mbed_Team | 0:33fe30a2b785 | 44 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 45 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 46 | #define ABORT(fs, res) { fp->err = (BYTE)(res); LEAVE_FF(fs, res); } |
JDI_Mbed_Team | 0:33fe30a2b785 | 47 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 48 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 49 | /* Definitions of sector size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 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) |
JDI_Mbed_Team | 0:33fe30a2b785 | 51 | #error Wrong sector size configuration |
JDI_Mbed_Team | 0:33fe30a2b785 | 52 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 53 | #if _MAX_SS == _MIN_SS |
JDI_Mbed_Team | 0:33fe30a2b785 | 54 | #define SS(fs) ((UINT)_MAX_SS) /* Fixed sector size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 55 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 56 | #define SS(fs) ((fs)->ssize) /* Variable sector size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 57 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 58 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 59 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 60 | /* Timestamp feature */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 61 | #if _FS_NORTC == 1 |
JDI_Mbed_Team | 0:33fe30a2b785 | 62 | #if _NORTC_YEAR < 1980 || _NORTC_YEAR > 2107 || _NORTC_MON < 1 || _NORTC_MON > 12 || _NORTC_MDAY < 1 || _NORTC_MDAY > 31 |
JDI_Mbed_Team | 0:33fe30a2b785 | 63 | #error Invalid _FS_NORTC settings |
JDI_Mbed_Team | 0:33fe30a2b785 | 64 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 65 | #define GET_FATTIME() ((DWORD)(_NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16) |
JDI_Mbed_Team | 0:33fe30a2b785 | 66 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 67 | #define GET_FATTIME() get_fattime() |
JDI_Mbed_Team | 0:33fe30a2b785 | 68 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 69 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 70 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 71 | /* File access control feature */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 72 | #if _FS_LOCK |
JDI_Mbed_Team | 0:33fe30a2b785 | 73 | #if _FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 74 | #error _FS_LOCK must be 0 at read-only configuration |
JDI_Mbed_Team | 0:33fe30a2b785 | 75 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 76 | typedef struct { |
JDI_Mbed_Team | 0:33fe30a2b785 | 77 | FATFS *fs; /* Object ID 1, volume (NULL:blank entry) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 78 | DWORD clu; /* Object ID 2, directory (0:root) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 79 | WORD idx; /* Object ID 3, directory index */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 80 | WORD ctr; /* Object open counter, 0:none, 0x01..0xFF:read mode open count, 0x100:write mode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 81 | } FILESEM; |
JDI_Mbed_Team | 0:33fe30a2b785 | 82 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 83 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 84 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 85 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 86 | /* DBCS code ranges and SBCS upper conversion tables */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 87 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 88 | #if _CODE_PAGE == 932 /* Japanese Shift-JIS */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 89 | #define _DF1S 0x81 /* DBC 1st byte range 1 start */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 90 | #define _DF1E 0x9F /* DBC 1st byte range 1 end */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 91 | #define _DF2S 0xE0 /* DBC 1st byte range 2 start */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 92 | #define _DF2E 0xFC /* DBC 1st byte range 2 end */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 93 | #define _DS1S 0x40 /* DBC 2nd byte range 1 start */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 94 | #define _DS1E 0x7E /* DBC 2nd byte range 1 end */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 95 | #define _DS2S 0x80 /* DBC 2nd byte range 2 start */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 96 | #define _DS2E 0xFC /* DBC 2nd byte range 2 end */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 97 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 98 | #elif _CODE_PAGE == 936 /* Simplified Chinese GBK */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 99 | #define _DF1S 0x81 |
JDI_Mbed_Team | 0:33fe30a2b785 | 100 | #define _DF1E 0xFE |
JDI_Mbed_Team | 0:33fe30a2b785 | 101 | #define _DS1S 0x40 |
JDI_Mbed_Team | 0:33fe30a2b785 | 102 | #define _DS1E 0x7E |
JDI_Mbed_Team | 0:33fe30a2b785 | 103 | #define _DS2S 0x80 |
JDI_Mbed_Team | 0:33fe30a2b785 | 104 | #define _DS2E 0xFE |
JDI_Mbed_Team | 0:33fe30a2b785 | 105 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 106 | #elif _CODE_PAGE == 949 /* Korean */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 107 | #define _DF1S 0x81 |
JDI_Mbed_Team | 0:33fe30a2b785 | 108 | #define _DF1E 0xFE |
JDI_Mbed_Team | 0:33fe30a2b785 | 109 | #define _DS1S 0x41 |
JDI_Mbed_Team | 0:33fe30a2b785 | 110 | #define _DS1E 0x5A |
JDI_Mbed_Team | 0:33fe30a2b785 | 111 | #define _DS2S 0x61 |
JDI_Mbed_Team | 0:33fe30a2b785 | 112 | #define _DS2E 0x7A |
JDI_Mbed_Team | 0:33fe30a2b785 | 113 | #define _DS3S 0x81 |
JDI_Mbed_Team | 0:33fe30a2b785 | 114 | #define _DS3E 0xFE |
JDI_Mbed_Team | 0:33fe30a2b785 | 115 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 116 | #elif _CODE_PAGE == 950 /* Traditional Chinese Big5 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 117 | #define _DF1S 0x81 |
JDI_Mbed_Team | 0:33fe30a2b785 | 118 | #define _DF1E 0xFE |
JDI_Mbed_Team | 0:33fe30a2b785 | 119 | #define _DS1S 0x40 |
JDI_Mbed_Team | 0:33fe30a2b785 | 120 | #define _DS1E 0x7E |
JDI_Mbed_Team | 0:33fe30a2b785 | 121 | #define _DS2S 0xA1 |
JDI_Mbed_Team | 0:33fe30a2b785 | 122 | #define _DS2E 0xFE |
JDI_Mbed_Team | 0:33fe30a2b785 | 123 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 124 | #elif _CODE_PAGE == 437 /* U.S. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 125 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 126 | #define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 127 | 0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 128 | 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 129 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 130 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 131 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 132 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 133 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 134 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 135 | #elif _CODE_PAGE == 720 /* Arabic */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 136 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 137 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 138 | 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 139 | 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 140 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 141 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 142 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 143 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 144 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 145 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 146 | #elif _CODE_PAGE == 737 /* Greek */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 147 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 148 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 149 | 0x90,0x92,0x92,0x93,0x94,0x95,0x96,0x97,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 150 | 0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0xAA,0x92,0x93,0x94,0x95,0x96, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 151 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 152 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 153 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 154 | 0x97,0xEA,0xEB,0xEC,0xE4,0xED,0xEE,0xEF,0xF5,0xF0,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 155 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 156 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 157 | #elif _CODE_PAGE == 771 /* KBL */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 158 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 159 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 160 | 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 161 | 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 162 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 163 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 164 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDC,0xDE,0xDE, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 165 | 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 166 | 0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 167 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 168 | #elif _CODE_PAGE == 775 /* Baltic */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 169 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 170 | #define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 171 | 0x90,0x92,0x92,0xE2,0x99,0x95,0x96,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 172 | 0xA0,0xA1,0xE0,0xA3,0xA3,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 173 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 174 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 175 | 0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xA5,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 176 | 0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE3,0xE8,0xE8,0xEA,0xEA,0xEE,0xED,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 177 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 178 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 179 | #elif _CODE_PAGE == 850 /* Latin 1 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 180 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 181 | #define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x41,0x43,0x45,0x45,0x45,0x49,0x49,0x49,0x41,0x41, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 182 | 0x45,0x92,0x92,0x4F,0x4F,0x4F,0x55,0x55,0x59,0x4F,0x55,0x4F,0x9C,0x4F,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 183 | 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 184 | 0xB0,0xB1,0xB2,0xB3,0xB4,0x41,0x41,0x41,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 185 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0x41,0x41,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 186 | 0xD1,0xD1,0x45,0x45,0x45,0x49,0x49,0x49,0x49,0xD9,0xDA,0xDB,0xDC,0xDD,0x49,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 187 | 0x4F,0xE1,0x4F,0x4F,0x4F,0x4F,0xE6,0xE8,0xE8,0x55,0x55,0x55,0x59,0x59,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 188 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 189 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 190 | #elif _CODE_PAGE == 852 /* Latin 2 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 191 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 192 | #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xDE,0x8F,0x80,0x9D,0xD3,0x8A,0x8A,0xD7,0x8D,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 193 | 0x90,0x91,0x91,0xE2,0x99,0x95,0x95,0x97,0x97,0x99,0x9A,0x9B,0x9B,0x9D,0x9E,0xAC, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 194 | 0xB5,0xD6,0xE0,0xE9,0xA4,0xA4,0xA6,0xA6,0xA8,0xA8,0xAA,0x8D,0xAC,0xB8,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 195 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBD,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 196 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC6,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 197 | 0xD1,0xD1,0xD2,0xD3,0xD2,0xD5,0xD6,0xD7,0xB7,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 198 | 0xE0,0xE1,0xE2,0xE3,0xE3,0xD5,0xE6,0xE6,0xE8,0xE9,0xE8,0xEB,0xED,0xED,0xDD,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 199 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xEB,0xFC,0xFC,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 200 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 201 | #elif _CODE_PAGE == 855 /* Cyrillic */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 202 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 203 | #define _EXCVT {0x81,0x81,0x83,0x83,0x85,0x85,0x87,0x87,0x89,0x89,0x8B,0x8B,0x8D,0x8D,0x8F,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 204 | 0x91,0x91,0x93,0x93,0x95,0x95,0x97,0x97,0x99,0x99,0x9B,0x9B,0x9D,0x9D,0x9F,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 205 | 0xA1,0xA1,0xA3,0xA3,0xA5,0xA5,0xA7,0xA7,0xA9,0xA9,0xAB,0xAB,0xAD,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 206 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB6,0xB6,0xB8,0xB8,0xB9,0xBA,0xBB,0xBC,0xBE,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 207 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 208 | 0xD1,0xD1,0xD3,0xD3,0xD5,0xD5,0xD7,0xD7,0xDD,0xD9,0xDA,0xDB,0xDC,0xDD,0xE0,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 209 | 0xE0,0xE2,0xE2,0xE4,0xE4,0xE6,0xE6,0xE8,0xE8,0xEA,0xEA,0xEC,0xEC,0xEE,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 210 | 0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 211 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 212 | #elif _CODE_PAGE == 857 /* Turkish */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 213 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 214 | #define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0x49,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 215 | 0x90,0x92,0x92,0xE2,0x99,0xE3,0xEA,0xEB,0x98,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9E, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 216 | 0xB5,0xD6,0xE0,0xE9,0xA5,0xA5,0xA6,0xA6,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 217 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 218 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 219 | 0xD0,0xD1,0xD2,0xD3,0xD4,0x49,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 220 | 0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xDE,0xED,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 221 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 222 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 223 | #elif _CODE_PAGE == 860 /* Portuguese */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 224 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 225 | #define _EXCVT {0x80,0x9A,0x90,0x8F,0x8E,0x91,0x86,0x80,0x89,0x89,0x92,0x8B,0x8C,0x98,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 226 | 0x90,0x91,0x92,0x8C,0x99,0xA9,0x96,0x9D,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 227 | 0x86,0x8B,0x9F,0x96,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 228 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 229 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 230 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 231 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 232 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 233 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 234 | #elif _CODE_PAGE == 861 /* Icelandic */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 235 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 236 | #define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x8B,0x8B,0x8D,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 237 | 0x90,0x92,0x92,0x4F,0x99,0x8D,0x55,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 238 | 0xA4,0xA5,0xA6,0xA7,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 239 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 240 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 241 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 242 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 243 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 244 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 245 | #elif _CODE_PAGE == 862 /* Hebrew */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 246 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 247 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 248 | 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 249 | 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 250 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 251 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 252 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 253 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 254 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 255 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 256 | #elif _CODE_PAGE == 863 /* Canadian-French */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 257 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 258 | #define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x41,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 259 | 0x45,0x45,0x45,0x4F,0x45,0x49,0x55,0x55,0x98,0x4F,0x55,0x9B,0x9C,0x55,0x55,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 260 | 0xA0,0xA1,0x4F,0x55,0xA4,0xA5,0xA6,0xA7,0x49,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 261 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 262 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 263 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 264 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 265 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 266 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 267 | #elif _CODE_PAGE == 864 /* Arabic */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 268 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 269 | #define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 270 | 0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 271 | 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 272 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 273 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 274 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 275 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 276 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 277 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 278 | #elif _CODE_PAGE == 865 /* Nordic */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 279 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 280 | #define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 281 | 0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 282 | 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 283 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 284 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 285 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 286 | 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 287 | 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 288 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 289 | #elif _CODE_PAGE == 866 /* Russian */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 290 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 291 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 292 | 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 293 | 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 294 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 295 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 296 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 297 | 0x90,0x91,0x92,0x93,0x9d,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 298 | 0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 299 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 300 | #elif _CODE_PAGE == 869 /* Greek 2 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 301 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 302 | #define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 303 | 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x86,0x9C,0x8D,0x8F,0x90, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 304 | 0x91,0x90,0x92,0x95,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 305 | 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 306 | 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 307 | 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xA4,0xA5,0xA6,0xD9,0xDA,0xDB,0xDC,0xA7,0xA8,0xDF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 308 | 0xA9,0xAA,0xAC,0xAD,0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xCF,0xCF,0xD0,0xEF, \ |
JDI_Mbed_Team | 0:33fe30a2b785 | 309 | 0xF0,0xF1,0xD1,0xD2,0xD3,0xF5,0xD4,0xF7,0xF8,0xF9,0xD5,0x96,0x95,0x98,0xFE,0xFF} |
JDI_Mbed_Team | 0:33fe30a2b785 | 310 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 311 | #elif _CODE_PAGE == 1 /* ASCII (for only non-LFN cfg) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 312 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 313 | #error Cannot use LFN feature without valid code page. |
JDI_Mbed_Team | 0:33fe30a2b785 | 314 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 315 | #define _DF1S 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 316 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 317 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 318 | #error Unknown code page |
JDI_Mbed_Team | 0:33fe30a2b785 | 319 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 320 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 321 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 322 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 323 | /* Character code support macros */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 324 | #define IsUpper(c) (((c)>='A')&&((c)<='Z')) |
JDI_Mbed_Team | 0:33fe30a2b785 | 325 | #define IsLower(c) (((c)>='a')&&((c)<='z')) |
JDI_Mbed_Team | 0:33fe30a2b785 | 326 | #define IsDigit(c) (((c)>='0')&&((c)<='9')) |
JDI_Mbed_Team | 0:33fe30a2b785 | 327 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 328 | #if _DF1S /* Code page is DBCS */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 329 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 330 | #ifdef _DF2S /* Two 1st byte areas */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 331 | #define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E)) |
JDI_Mbed_Team | 0:33fe30a2b785 | 332 | #else /* One 1st byte area */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 333 | #define IsDBCS1(c) ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) |
JDI_Mbed_Team | 0:33fe30a2b785 | 334 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 335 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 336 | #ifdef _DS3S /* Three 2nd byte areas */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 337 | #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E)) |
JDI_Mbed_Team | 0:33fe30a2b785 | 338 | #else /* Two 2nd byte areas */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 339 | #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E)) |
JDI_Mbed_Team | 0:33fe30a2b785 | 340 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 341 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 342 | #else /* Code page is SBCS */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 343 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 344 | #define IsDBCS1(c) 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 345 | #define IsDBCS2(c) 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 346 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 347 | #endif /* _DF1S */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 348 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 349 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 350 | /* Name status flags */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 351 | #define NSFLAG 11 /* Index of name status byte in fn[] */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 352 | #define NS_LOSS 0x01 /* Out of 8.3 format */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 353 | #define NS_LFN 0x02 /* Force to create LFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 354 | #define NS_LAST 0x04 /* Last segment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 355 | #define NS_BODY 0x08 /* Lower case flag (body) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 356 | #define NS_EXT 0x10 /* Lower case flag (ext) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 357 | #define NS_DOT 0x20 /* Dot entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 358 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 359 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 360 | /* FAT sub-type boundaries (Differ from specs but correct for real DOS/Windows) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 361 | #define MIN_FAT16 4086U /* Minimum number of clusters of FAT16 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 362 | #define MIN_FAT32 65526U /* Minimum number of clusters of FAT32 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 363 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 364 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 365 | /* FatFs refers the members in the FAT structures as byte array instead of |
JDI_Mbed_Team | 0:33fe30a2b785 | 366 | / structure members because the structure is not binary compatible between |
JDI_Mbed_Team | 0:33fe30a2b785 | 367 | / different platforms */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 368 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 369 | #define BS_jmpBoot 0 /* x86 jump instruction (3) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 370 | #define BS_OEMName 3 /* OEM name (8) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 371 | #define BPB_BytsPerSec 11 /* Sector size [byte] (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 372 | #define BPB_SecPerClus 13 /* Cluster size [sector] (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 373 | #define BPB_RsvdSecCnt 14 /* Size of reserved area [sector] (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 374 | #define BPB_NumFATs 16 /* Number of FAT copies (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 375 | #define BPB_RootEntCnt 17 /* Number of root directory entries for FAT12/16 (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 376 | #define BPB_TotSec16 19 /* Volume size [sector] (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 377 | #define BPB_Media 21 /* Media descriptor (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 378 | #define BPB_FATSz16 22 /* FAT size [sector] (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 379 | #define BPB_SecPerTrk 24 /* Track size [sector] (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 380 | #define BPB_NumHeads 26 /* Number of heads (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 381 | #define BPB_HiddSec 28 /* Number of special hidden sectors (4) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 382 | #define BPB_TotSec32 32 /* Volume size [sector] (4) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 383 | #define BS_DrvNum 36 /* Physical drive number (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 384 | #define BS_NTres 37 /* Error flag (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 385 | #define BS_BootSig 38 /* Extended boot signature (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 386 | #define BS_VolID 39 /* Volume serial number (4) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 387 | #define BS_VolLab 43 /* Volume label (8) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 388 | #define BS_FilSysType 54 /* File system type (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 389 | #define BPB_FATSz32 36 /* FAT size [sector] (4) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 390 | #define BPB_ExtFlags 40 /* Extended flags (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 391 | #define BPB_FSVer 42 /* File system version (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 392 | #define BPB_RootClus 44 /* Root directory first cluster (4) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 393 | #define BPB_FSInfo 48 /* Offset of FSINFO sector (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 394 | #define BPB_BkBootSec 50 /* Offset of backup boot sector (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 395 | #define BS_DrvNum32 64 /* Physical drive number (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 396 | #define BS_NTres32 65 /* Error flag (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 397 | #define BS_BootSig32 66 /* Extended boot signature (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 398 | #define BS_VolID32 67 /* Volume serial number (4) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 399 | #define BS_VolLab32 71 /* Volume label (8) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 400 | #define BS_FilSysType32 82 /* File system type (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 401 | #define FSI_LeadSig 0 /* FSI: Leading signature (4) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 402 | #define FSI_StrucSig 484 /* FSI: Structure signature (4) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 403 | #define FSI_Free_Count 488 /* FSI: Number of free clusters (4) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 404 | #define FSI_Nxt_Free 492 /* FSI: Last allocated cluster (4) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 405 | #define MBR_Table 446 /* MBR: Partition table offset (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 406 | #define SZ_PTE 16 /* MBR: Size of a partition table entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 407 | #define BS_55AA 510 /* Signature word (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 408 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 409 | #define DIR_Name 0 /* Short file name (11) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 410 | #define DIR_Attr 11 /* Attribute (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 411 | #define DIR_NTres 12 /* Lower case flag (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 412 | #define DIR_CrtTimeTenth 13 /* Created time sub-second (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 413 | #define DIR_CrtTime 14 /* Created time (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 414 | #define DIR_CrtDate 16 /* Created date (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 415 | #define DIR_LstAccDate 18 /* Last accessed date (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 416 | #define DIR_FstClusHI 20 /* Higher 16-bit of first cluster (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 417 | #define DIR_WrtTime 22 /* Modified time (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 418 | #define DIR_WrtDate 24 /* Modified date (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 419 | #define DIR_FstClusLO 26 /* Lower 16-bit of first cluster (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 420 | #define DIR_FileSize 28 /* File size (4) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 421 | #define LDIR_Ord 0 /* LFN entry order and LLE flag (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 422 | #define LDIR_Attr 11 /* LFN attribute (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 423 | #define LDIR_Type 12 /* LFN type (1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 424 | #define LDIR_Chksum 13 /* Checksum of corresponding SFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 425 | #define LDIR_FstClusLO 26 /* Must be zero (0) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 426 | #define SZ_DIRE 32 /* Size of a directory entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 427 | #define LLEF 0x40 /* Last long entry flag in LDIR_Ord */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 428 | #define DDEM 0xE5 /* Deleted directory entry mark at DIR_Name[0] */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 429 | #define RDDEM 0x05 /* Replacement of the character collides with DDEM */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 430 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 431 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 432 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 433 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 434 | /*-------------------------------------------------------------------------- |
JDI_Mbed_Team | 0:33fe30a2b785 | 435 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 436 | Module Private Work Area |
JDI_Mbed_Team | 0:33fe30a2b785 | 437 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 438 | ---------------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 439 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 440 | /* Remark: Uninitialized variables with static duration are guaranteed |
JDI_Mbed_Team | 0:33fe30a2b785 | 441 | / zero/null at start-up. If not, either the linker or start-up routine |
JDI_Mbed_Team | 0:33fe30a2b785 | 442 | / being used is not compliance with ANSI-C standard. |
JDI_Mbed_Team | 0:33fe30a2b785 | 443 | */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 444 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 445 | #if _VOLUMES < 1 || _VOLUMES > 9 |
JDI_Mbed_Team | 0:33fe30a2b785 | 446 | #error Wrong _VOLUMES setting |
JDI_Mbed_Team | 0:33fe30a2b785 | 447 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 448 | static FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical drives) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 449 | static WORD Fsid; /* File system mount ID */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 450 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 451 | #if _FS_RPATH && _VOLUMES >= 2 |
JDI_Mbed_Team | 0:33fe30a2b785 | 452 | static BYTE CurrVol; /* Current drive */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 453 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 454 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 455 | #if _FS_LOCK |
JDI_Mbed_Team | 0:33fe30a2b785 | 456 | static FILESEM Files[_FS_LOCK]; /* Open object lock semaphores */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 457 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 458 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 459 | #if _USE_LFN == 0 /* Non LFN feature */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 460 | #define DEFINE_NAMEBUF BYTE sfn[12] |
JDI_Mbed_Team | 0:33fe30a2b785 | 461 | #define INIT_BUF(dobj) (dobj).fn = sfn |
JDI_Mbed_Team | 0:33fe30a2b785 | 462 | #define FREE_BUF() |
JDI_Mbed_Team | 0:33fe30a2b785 | 463 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 464 | #if _MAX_LFN < 12 || _MAX_LFN > 255 |
JDI_Mbed_Team | 0:33fe30a2b785 | 465 | #error Wrong _MAX_LFN setting |
JDI_Mbed_Team | 0:33fe30a2b785 | 466 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 467 | #if _USE_LFN == 1 /* LFN feature with static working buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 468 | static WCHAR LfnBuf[_MAX_LFN + 1]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 469 | #define DEFINE_NAMEBUF BYTE sfn[12] |
JDI_Mbed_Team | 0:33fe30a2b785 | 470 | #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = LfnBuf; } |
JDI_Mbed_Team | 0:33fe30a2b785 | 471 | #define FREE_BUF() |
JDI_Mbed_Team | 0:33fe30a2b785 | 472 | #elif _USE_LFN == 2 /* LFN feature with dynamic working buffer on the stack */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 473 | #define DEFINE_NAMEBUF BYTE sfn[12]; WCHAR lbuf[_MAX_LFN + 1] |
JDI_Mbed_Team | 0:33fe30a2b785 | 474 | #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = lbuf; } |
JDI_Mbed_Team | 0:33fe30a2b785 | 475 | #define FREE_BUF() |
JDI_Mbed_Team | 0:33fe30a2b785 | 476 | #elif _USE_LFN == 3 /* LFN feature with dynamic working buffer on the heap */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 477 | #define DEFINE_NAMEBUF BYTE sfn[12]; WCHAR *lfn |
JDI_Mbed_Team | 0:33fe30a2b785 | 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; } |
JDI_Mbed_Team | 0:33fe30a2b785 | 479 | #define FREE_BUF() ff_memfree(lfn) |
JDI_Mbed_Team | 0:33fe30a2b785 | 480 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 481 | #error Wrong _USE_LFN setting |
JDI_Mbed_Team | 0:33fe30a2b785 | 482 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 483 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 484 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 485 | #ifdef _EXCVT |
JDI_Mbed_Team | 0:33fe30a2b785 | 486 | static const BYTE ExCvt[] = _EXCVT; /* Upper conversion table for SBCS extended characters */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 487 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 488 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 489 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 490 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 491 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 492 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 493 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 494 | /*-------------------------------------------------------------------------- |
JDI_Mbed_Team | 0:33fe30a2b785 | 495 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 496 | Module Private Functions |
JDI_Mbed_Team | 0:33fe30a2b785 | 497 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 498 | ---------------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 499 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 500 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 501 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 502 | /* String functions */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 503 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 504 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 505 | /* Copy memory to memory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 506 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 507 | void mem_cpy (void* dst, const void* src, UINT cnt) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 508 | BYTE *d = (BYTE*)dst; |
JDI_Mbed_Team | 0:33fe30a2b785 | 509 | const BYTE *s = (const BYTE*)src; |
JDI_Mbed_Team | 0:33fe30a2b785 | 510 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 511 | #if _WORD_ACCESS == 1 |
JDI_Mbed_Team | 0:33fe30a2b785 | 512 | while (cnt >= sizeof (int)) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 513 | *(int*)d = *(int*)s; |
JDI_Mbed_Team | 0:33fe30a2b785 | 514 | d += sizeof (int); s += sizeof (int); |
JDI_Mbed_Team | 0:33fe30a2b785 | 515 | cnt -= sizeof (int); |
JDI_Mbed_Team | 0:33fe30a2b785 | 516 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 517 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 518 | while (cnt--) |
JDI_Mbed_Team | 0:33fe30a2b785 | 519 | *d++ = *s++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 520 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 521 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 522 | /* Fill memory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 523 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 524 | void mem_set (void* dst, int val, UINT cnt) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 525 | BYTE *d = (BYTE*)dst; |
JDI_Mbed_Team | 0:33fe30a2b785 | 526 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 527 | while (cnt--) |
JDI_Mbed_Team | 0:33fe30a2b785 | 528 | *d++ = (BYTE)val; |
JDI_Mbed_Team | 0:33fe30a2b785 | 529 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 530 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 531 | /* Compare memory to memory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 532 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 533 | int mem_cmp (const void* dst, const void* src, UINT cnt) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 534 | const BYTE *d = (const BYTE *)dst, *s = (const BYTE *)src; |
JDI_Mbed_Team | 0:33fe30a2b785 | 535 | int r = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 536 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 537 | while (cnt-- && (r = *d++ - *s++) == 0) ; |
JDI_Mbed_Team | 0:33fe30a2b785 | 538 | return r; |
JDI_Mbed_Team | 0:33fe30a2b785 | 539 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 540 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 541 | /* Check if chr is contained in the string */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 542 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 543 | int chk_chr (const char* str, int chr) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 544 | while (*str && *str != chr) str++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 545 | return *str; |
JDI_Mbed_Team | 0:33fe30a2b785 | 546 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 547 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 548 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 549 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 550 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 551 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 552 | /* Request/Release grant to access the volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 553 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 554 | #if _FS_REENTRANT |
JDI_Mbed_Team | 0:33fe30a2b785 | 555 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 556 | int lock_fs ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 557 | FATFS* fs /* File system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 558 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 559 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 560 | return ff_req_grant(fs->sobj); |
JDI_Mbed_Team | 0:33fe30a2b785 | 561 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 562 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 563 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 564 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 565 | void unlock_fs ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 566 | FATFS* fs, /* File system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 567 | FRESULT res /* Result code to be returned */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 568 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 569 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 570 | if (fs && |
JDI_Mbed_Team | 0:33fe30a2b785 | 571 | res != FR_NOT_ENABLED && |
JDI_Mbed_Team | 0:33fe30a2b785 | 572 | res != FR_INVALID_DRIVE && |
JDI_Mbed_Team | 0:33fe30a2b785 | 573 | res != FR_INVALID_OBJECT && |
JDI_Mbed_Team | 0:33fe30a2b785 | 574 | res != FR_TIMEOUT) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 575 | ff_rel_grant(fs->sobj); |
JDI_Mbed_Team | 0:33fe30a2b785 | 576 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 577 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 578 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 579 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 580 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 581 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 582 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 583 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 584 | /* File lock control functions */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 585 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 586 | #if _FS_LOCK |
JDI_Mbed_Team | 0:33fe30a2b785 | 587 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 588 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 589 | FRESULT chk_lock ( /* Check if the file can be accessed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 590 | FATFS_DIR* dp, /* Directory object pointing the file to be checked */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 591 | int acc /* Desired access type (0:Read, 1:Write, 2:Delete/Rename) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 592 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 593 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 594 | UINT i, be; |
JDI_Mbed_Team | 0:33fe30a2b785 | 595 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 596 | /* Search file semaphore table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 597 | for (i = be = 0; i < _FS_LOCK; i++) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 598 | if (Files[i].fs) { /* Existing entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 599 | if (Files[i].fs == dp->fs && /* Check if the object matched with an open object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 600 | Files[i].clu == dp->sclust && |
JDI_Mbed_Team | 0:33fe30a2b785 | 601 | Files[i].idx == dp->index) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 602 | } else { /* Blank entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 603 | be = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 604 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 605 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 606 | if (i == _FS_LOCK) /* The object is not opened */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 607 | return (be || acc == 2) ? FR_OK : FR_TOO_MANY_OPEN_FILES; /* Is there a blank entry for new object? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 608 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 609 | /* The object has been opened. Reject any open against writing file and all write mode open */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 610 | return (acc || Files[i].ctr == 0x100) ? FR_LOCKED : FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 611 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 612 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 613 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 614 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 615 | int enq_lock (void) /* Check if an entry is available for a new object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 616 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 617 | UINT i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 618 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 619 | for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ; |
JDI_Mbed_Team | 0:33fe30a2b785 | 620 | return (i == _FS_LOCK) ? 0 : 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 621 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 622 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 623 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 624 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 625 | UINT inc_lock ( /* Increment object open counter and returns its index (0:Internal error) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 626 | FATFS_DIR* dp, /* Directory object pointing the file to register or increment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 627 | int acc /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 628 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 629 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 630 | UINT i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 631 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 632 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 633 | for (i = 0; i < _FS_LOCK; i++) { /* Find the object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 634 | if (Files[i].fs == dp->fs && |
JDI_Mbed_Team | 0:33fe30a2b785 | 635 | Files[i].clu == dp->sclust && |
JDI_Mbed_Team | 0:33fe30a2b785 | 636 | Files[i].idx == dp->index) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 637 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 638 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 639 | if (i == _FS_LOCK) { /* Not opened. Register it as new. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 640 | for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ; |
JDI_Mbed_Team | 0:33fe30a2b785 | 641 | if (i == _FS_LOCK) return 0; /* No free entry to register (int err) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 642 | Files[i].fs = dp->fs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 643 | Files[i].clu = dp->sclust; |
JDI_Mbed_Team | 0:33fe30a2b785 | 644 | Files[i].idx = dp->index; |
JDI_Mbed_Team | 0:33fe30a2b785 | 645 | Files[i].ctr = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 646 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 647 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 648 | if (acc && Files[i].ctr) return 0; /* Access violation (int err) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 649 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 650 | Files[i].ctr = acc ? 0x100 : Files[i].ctr + 1; /* Set semaphore value */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 651 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 652 | return i + 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 653 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 654 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 655 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 656 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 657 | FRESULT dec_lock ( /* Decrement object open counter */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 658 | UINT i /* Semaphore index (1..) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 659 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 660 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 661 | WORD n; |
JDI_Mbed_Team | 0:33fe30a2b785 | 662 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 663 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 664 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 665 | if (--i < _FS_LOCK) { /* Shift index number origin from 0 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 666 | n = Files[i].ctr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 667 | if (n == 0x100) n = 0; /* If write mode open, delete the entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 668 | if (n) n--; /* Decrement read mode open count */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 669 | Files[i].ctr = n; |
JDI_Mbed_Team | 0:33fe30a2b785 | 670 | if (!n) Files[i].fs = 0; /* Delete the entry if open count gets zero */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 671 | res = FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 672 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 673 | res = FR_INT_ERR; /* Invalid index nunber */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 674 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 675 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 676 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 677 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 678 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 679 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 680 | void clear_lock ( /* Clear lock entries of the volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 681 | FATFS *fs |
JDI_Mbed_Team | 0:33fe30a2b785 | 682 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 683 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 684 | UINT i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 685 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 686 | for (i = 0; i < _FS_LOCK; i++) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 687 | if (Files[i].fs == fs) Files[i].fs = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 688 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 689 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 690 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 691 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 692 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 693 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 694 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 695 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 696 | /* Move/Flush disk access window in the file system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 697 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 698 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 699 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 700 | FRESULT sync_window ( /* FR_OK:succeeded, !=0:error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 701 | FATFS* fs /* File system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 702 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 703 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 704 | DWORD wsect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 705 | UINT nf; |
JDI_Mbed_Team | 0:33fe30a2b785 | 706 | FRESULT res = FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 707 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 708 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 709 | if (fs->wflag) { /* Write back the sector if it is dirty */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 710 | wsect = fs->winsect; /* Current sector number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 711 | if (disk_write(fs->drv, fs->win, wsect, 1) != RES_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 712 | res = FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 713 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 714 | fs->wflag = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 715 | if (wsect - fs->fatbase < fs->fsize) { /* Is it in the FAT area? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 716 | for (nf = fs->n_fats; nf >= 2; nf--) { /* Reflect the change to all FAT copies */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 717 | wsect += fs->fsize; |
JDI_Mbed_Team | 0:33fe30a2b785 | 718 | disk_write(fs->drv, fs->win, wsect, 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 719 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 720 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 721 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 722 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 723 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 724 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 725 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 726 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 727 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 728 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 729 | FRESULT move_window ( /* FR_OK(0):succeeded, !=0:error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 730 | FATFS* fs, /* File system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 731 | DWORD sector /* Sector number to make appearance in the fs->win[] */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 732 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 733 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 734 | FRESULT res = FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 735 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 736 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 737 | if (sector != fs->winsect) { /* Window offset changed? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 738 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 739 | res = sync_window(fs); /* Write-back changes */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 740 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 741 | if (res == FR_OK) { /* Fill sector window with new data */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 742 | if (disk_read(fs->drv, fs->win, sector, 1) != RES_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 743 | sector = 0xFFFFFFFF; /* Invalidate window if data is not reliable */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 744 | res = FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 745 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 746 | fs->winsect = sector; |
JDI_Mbed_Team | 0:33fe30a2b785 | 747 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 748 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 749 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 750 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 751 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 752 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 753 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 754 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 755 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 756 | /* Synchronize file system and strage device */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 757 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 758 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 759 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 760 | FRESULT sync_fs ( /* FR_OK:succeeded, !=0:error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 761 | FATFS* fs /* File system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 762 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 763 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 764 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 765 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 766 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 767 | res = sync_window(fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 768 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 769 | /* Update FSInfo sector if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 770 | if (fs->fs_type == FS_FAT32 && fs->fsi_flag == 1) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 771 | /* Create FSInfo structure */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 772 | mem_set(fs->win, 0, SS(fs)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 773 | ST_WORD(fs->win + BS_55AA, 0xAA55); |
JDI_Mbed_Team | 0:33fe30a2b785 | 774 | ST_DWORD(fs->win + FSI_LeadSig, 0x41615252); |
JDI_Mbed_Team | 0:33fe30a2b785 | 775 | ST_DWORD(fs->win + FSI_StrucSig, 0x61417272); |
JDI_Mbed_Team | 0:33fe30a2b785 | 776 | ST_DWORD(fs->win + FSI_Free_Count, fs->free_clust); |
JDI_Mbed_Team | 0:33fe30a2b785 | 777 | ST_DWORD(fs->win + FSI_Nxt_Free, fs->last_clust); |
JDI_Mbed_Team | 0:33fe30a2b785 | 778 | /* Write it into the FSInfo sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 779 | fs->winsect = fs->volbase + 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 780 | disk_write(fs->drv, fs->win, fs->winsect, 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 781 | fs->fsi_flag = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 782 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 783 | /* Make sure that no pending write process in the physical drive */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 784 | if (disk_ioctl(fs->drv, CTRL_SYNC, 0) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 785 | res = FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 786 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 787 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 788 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 789 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 790 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 791 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 792 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 793 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 794 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 795 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 796 | /* Get sector# from cluster# */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 797 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 798 | /* Hidden API for hacks and disk tools */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 799 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 800 | DWORD clust2sect ( /* !=0:Sector number, 0:Failed (invalid cluster#) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 801 | FATFS* fs, /* File system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 802 | DWORD clst /* Cluster# to be converted */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 803 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 804 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 805 | clst -= 2; |
JDI_Mbed_Team | 0:33fe30a2b785 | 806 | if (clst >= fs->n_fatent - 2) return 0; /* Invalid cluster# */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 807 | return clst * fs->csize + fs->database; |
JDI_Mbed_Team | 0:33fe30a2b785 | 808 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 809 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 810 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 811 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 812 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 813 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 814 | /* FAT access - Read value of a FAT entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 815 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 816 | /* Hidden API for hacks and disk tools */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 817 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 818 | DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x0FFFFFFF:Cluster status */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 819 | FATFS* fs, /* File system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 820 | DWORD clst /* FAT index number (cluster number) to get the value */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 821 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 822 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 823 | UINT wc, bc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 824 | BYTE *p; |
JDI_Mbed_Team | 0:33fe30a2b785 | 825 | DWORD val; |
JDI_Mbed_Team | 0:33fe30a2b785 | 826 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 827 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 828 | if (clst < 2 || clst >= fs->n_fatent) { /* Check if in valid range */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 829 | val = 1; /* Internal error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 830 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 831 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 832 | val = 0xFFFFFFFF; /* Default value falls on disk error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 833 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 834 | switch (fs->fs_type) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 835 | case FS_FAT12 : |
JDI_Mbed_Team | 0:33fe30a2b785 | 836 | bc = (UINT)clst; bc += bc / 2; |
JDI_Mbed_Team | 0:33fe30a2b785 | 837 | if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 838 | wc = fs->win[bc++ % SS(fs)]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 839 | if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 840 | wc |= fs->win[bc % SS(fs)] << 8; |
JDI_Mbed_Team | 0:33fe30a2b785 | 841 | val = clst & 1 ? wc >> 4 : (wc & 0xFFF); |
JDI_Mbed_Team | 0:33fe30a2b785 | 842 | break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 843 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 844 | case FS_FAT16 : |
JDI_Mbed_Team | 0:33fe30a2b785 | 845 | if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))) != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 846 | p = &fs->win[clst * 2 % SS(fs)]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 847 | val = LD_WORD(p); |
JDI_Mbed_Team | 0:33fe30a2b785 | 848 | break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 849 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 850 | case FS_FAT32 : |
JDI_Mbed_Team | 0:33fe30a2b785 | 851 | if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))) != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 852 | p = &fs->win[clst * 4 % SS(fs)]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 853 | val = LD_DWORD(p) & 0x0FFFFFFF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 854 | break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 855 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 856 | default: |
JDI_Mbed_Team | 0:33fe30a2b785 | 857 | val = 1; /* Internal error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 858 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 859 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 860 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 861 | return val; |
JDI_Mbed_Team | 0:33fe30a2b785 | 862 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 863 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 864 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 865 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 866 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 867 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 868 | /* FAT access - Change value of a FAT entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 869 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 870 | /* Hidden API for hacks and disk tools */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 871 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 872 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 873 | FRESULT put_fat ( /* FR_OK(0):succeeded, !=0:error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 874 | FATFS* fs, /* File system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 875 | DWORD clst, /* FAT index number (cluster number) to be changed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 876 | DWORD val /* New value to be set to the entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 877 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 878 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 879 | UINT bc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 880 | BYTE *p; |
JDI_Mbed_Team | 0:33fe30a2b785 | 881 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 882 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 883 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 884 | if (clst < 2 || clst >= fs->n_fatent) { /* Check if in valid range */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 885 | res = FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 886 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 887 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 888 | switch (fs->fs_type) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 889 | case FS_FAT12 : |
JDI_Mbed_Team | 0:33fe30a2b785 | 890 | bc = (UINT)clst; bc += bc / 2; |
JDI_Mbed_Team | 0:33fe30a2b785 | 891 | res = move_window(fs, fs->fatbase + (bc / SS(fs))); |
JDI_Mbed_Team | 0:33fe30a2b785 | 892 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 893 | p = &fs->win[bc++ % SS(fs)]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 894 | *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; |
JDI_Mbed_Team | 0:33fe30a2b785 | 895 | fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 896 | res = move_window(fs, fs->fatbase + (bc / SS(fs))); |
JDI_Mbed_Team | 0:33fe30a2b785 | 897 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 898 | p = &fs->win[bc % SS(fs)]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 899 | *p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 900 | fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 901 | break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 902 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 903 | case FS_FAT16 : |
JDI_Mbed_Team | 0:33fe30a2b785 | 904 | res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))); |
JDI_Mbed_Team | 0:33fe30a2b785 | 905 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 906 | p = &fs->win[clst * 2 % SS(fs)]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 907 | ST_WORD(p, (WORD)val); |
JDI_Mbed_Team | 0:33fe30a2b785 | 908 | fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 909 | break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 910 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 911 | case FS_FAT32 : |
JDI_Mbed_Team | 0:33fe30a2b785 | 912 | res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))); |
JDI_Mbed_Team | 0:33fe30a2b785 | 913 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 914 | p = &fs->win[clst * 4 % SS(fs)]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 915 | val |= LD_DWORD(p) & 0xF0000000; |
JDI_Mbed_Team | 0:33fe30a2b785 | 916 | ST_DWORD(p, val); |
JDI_Mbed_Team | 0:33fe30a2b785 | 917 | fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 918 | break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 919 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 920 | default : |
JDI_Mbed_Team | 0:33fe30a2b785 | 921 | res = FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 922 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 923 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 924 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 925 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 926 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 927 | #endif /* !_FS_READONLY */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 928 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 929 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 930 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 931 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 932 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 933 | /* FAT handling - Remove a cluster chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 934 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 935 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 936 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 937 | FRESULT remove_chain ( /* FR_OK(0):succeeded, !=0:error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 938 | FATFS* fs, /* File system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 939 | DWORD clst /* Cluster# to remove a chain from */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 940 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 941 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 942 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 943 | DWORD nxt; |
JDI_Mbed_Team | 0:33fe30a2b785 | 944 | #if _USE_TRIM |
JDI_Mbed_Team | 0:33fe30a2b785 | 945 | DWORD scl = clst, ecl = clst, rt[2]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 946 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 947 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 948 | if (clst < 2 || clst >= fs->n_fatent) { /* Check if in valid range */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 949 | res = FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 950 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 951 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 952 | res = FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 953 | while (clst < fs->n_fatent) { /* Not a last link? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 954 | nxt = get_fat(fs, clst); /* Get cluster status */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 955 | if (nxt == 0) break; /* Empty cluster? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 956 | if (nxt == 1) { res = FR_INT_ERR; break; } /* Internal error? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 957 | if (nxt == 0xFFFFFFFF) { res = FR_DISK_ERR; break; } /* Disk error? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 958 | res = put_fat(fs, clst, 0); /* Mark the cluster "empty" */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 959 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 960 | if (fs->free_clust != 0xFFFFFFFF) { /* Update FSINFO */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 961 | fs->free_clust++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 962 | fs->fsi_flag |= 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 963 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 964 | #if _USE_TRIM |
JDI_Mbed_Team | 0:33fe30a2b785 | 965 | if (ecl + 1 == nxt) { /* Is next cluster contiguous? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 966 | ecl = nxt; |
JDI_Mbed_Team | 0:33fe30a2b785 | 967 | } else { /* End of contiguous clusters */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 968 | rt[0] = clust2sect(fs, scl); /* Start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 969 | rt[1] = clust2sect(fs, ecl) + fs->csize - 1; /* End sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 970 | disk_ioctl(fs->drv, CTRL_TRIM, rt); /* Erase the block */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 971 | scl = ecl = nxt; |
JDI_Mbed_Team | 0:33fe30a2b785 | 972 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 973 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 974 | clst = nxt; /* Next cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 975 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 976 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 977 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 978 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 979 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 980 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 981 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 982 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 983 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 984 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 985 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 986 | /* FAT handling - Stretch or Create a cluster chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 987 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 988 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 989 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 990 | DWORD create_chain ( /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 991 | FATFS* fs, /* File system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 992 | DWORD clst /* Cluster# to stretch, 0:Create a new chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 993 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 994 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 995 | DWORD cs, ncl, scl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 996 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 997 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 998 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 999 | if (clst == 0) { /* Create a new chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1000 | scl = fs->last_clust; /* Get suggested start point */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1001 | if (!scl || scl >= fs->n_fatent) scl = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1002 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1003 | else { /* Stretch the current chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1004 | cs = get_fat(fs, clst); /* Check the cluster status */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1005 | if (cs < 2) return 1; /* Invalid value */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1006 | if (cs == 0xFFFFFFFF) return cs; /* A disk error occurred */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1007 | if (cs < fs->n_fatent) return cs; /* It is already followed by next cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1008 | scl = clst; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1009 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1010 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1011 | ncl = scl; /* Start cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1012 | for (;;) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1013 | ncl++; /* Next cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1014 | if (ncl >= fs->n_fatent) { /* Check wrap around */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1015 | ncl = 2; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1016 | if (ncl > scl) return 0; /* No free cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1017 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1018 | cs = get_fat(fs, ncl); /* Get the cluster status */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1019 | if (cs == 0) break; /* Found a free cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1020 | if (cs == 0xFFFFFFFF || cs == 1)/* An error occurred */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1021 | return cs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1022 | if (ncl == scl) return 0; /* No free cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1023 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1024 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1025 | res = put_fat(fs, ncl, 0x0FFFFFFF); /* Mark the new cluster "last link" */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1026 | if (res == FR_OK && clst != 0) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1027 | res = put_fat(fs, clst, ncl); /* Link it to the previous one if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1028 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1029 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1030 | fs->last_clust = ncl; /* Update FSINFO */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1031 | if (fs->free_clust != 0xFFFFFFFF) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1032 | fs->free_clust--; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1033 | fs->fsi_flag |= 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1034 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1035 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1036 | ncl = (res == FR_DISK_ERR) ? 0xFFFFFFFF : 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1037 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1038 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1039 | return ncl; /* Return new cluster number or error code */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1040 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1041 | #endif /* !_FS_READONLY */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1042 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1043 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1044 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1045 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1046 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1047 | /* FAT handling - Convert offset into cluster with link map table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1048 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1049 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1050 | #if _USE_FASTSEEK |
JDI_Mbed_Team | 0:33fe30a2b785 | 1051 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1052 | DWORD clmt_clust ( /* <2:Error, >=2:Cluster number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1053 | FIL* fp, /* Pointer to the file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1054 | DWORD ofs /* File offset to be converted to cluster# */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1055 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1056 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1057 | DWORD cl, ncl, *tbl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1058 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1059 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1060 | tbl = fp->cltbl + 1; /* Top of CLMT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1061 | cl = ofs / SS(fp->fs) / fp->fs->csize; /* Cluster order from top of the file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1062 | for (;;) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1063 | ncl = *tbl++; /* Number of cluters in the fragment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1064 | if (!ncl) return 0; /* End of table? (error) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1065 | if (cl < ncl) break; /* In this fragment? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1066 | cl -= ncl; tbl++; /* Next fragment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1067 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1068 | return cl + *tbl; /* Return the cluster number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1069 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1070 | #endif /* _USE_FASTSEEK */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1071 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1072 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1073 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1074 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1075 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1076 | /* Directory handling - Set directory index */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1077 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1078 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1079 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1080 | FRESULT dir_sdi ( /* FR_OK(0):succeeded, !=0:error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1081 | FATFS_DIR* dp, /* Pointer to directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1082 | UINT idx /* Index of directory table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1083 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1084 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1085 | DWORD clst, sect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1086 | UINT ic; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1087 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1088 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1089 | dp->index = (WORD)idx; /* Current index */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1090 | clst = dp->sclust; /* Table start cluster (0:root) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1091 | if (clst == 1 || clst >= dp->fs->n_fatent) /* Check start cluster range */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1092 | return FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1093 | if (!clst && dp->fs->fs_type == FS_FAT32) /* Replace cluster# 0 with root cluster# if in FAT32 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1094 | clst = dp->fs->dirbase; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1095 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1096 | if (clst == 0) { /* Static table (root-directory in FAT12/16) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1097 | if (idx >= dp->fs->n_rootdir) /* Is index out of range? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1098 | return FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1099 | sect = dp->fs->dirbase; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1100 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1101 | else { /* Dynamic table (root-directory in FAT32 or sub-directory) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1102 | ic = SS(dp->fs) / SZ_DIRE * dp->fs->csize; /* Entries per cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1103 | while (idx >= ic) { /* Follow cluster chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1104 | clst = get_fat(dp->fs, clst); /* Get next cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1105 | if (clst == 0xFFFFFFFF) return FR_DISK_ERR; /* Disk error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1106 | if (clst < 2 || clst >= dp->fs->n_fatent) /* Reached to end of table or internal error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1107 | return FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1108 | idx -= ic; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1109 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1110 | sect = clust2sect(dp->fs, clst); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1111 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1112 | dp->clust = clst; /* Current cluster# */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1113 | if (!sect) return FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1114 | dp->sect = sect + idx / (SS(dp->fs) / SZ_DIRE); /* Sector# of the directory entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1115 | dp->dir = dp->fs->win + (idx % (SS(dp->fs) / SZ_DIRE)) * SZ_DIRE; /* Ptr to the entry in the sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1116 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1117 | return FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1118 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1119 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1120 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1121 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1122 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1123 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1124 | /* Directory handling - Move directory table index next */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1125 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1126 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1127 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1128 | FRESULT dir_next ( /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DENIED:Could not stretch */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1129 | FATFS_DIR* dp, /* Pointer to the directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1130 | int stretch /* 0: Do not stretch table, 1: Stretch table if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1131 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1132 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1133 | DWORD clst; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1134 | UINT i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1135 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 1136 | UINT c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1137 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1138 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1139 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1140 | i = dp->index + 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1141 | if (!(i & 0xFFFF) || !dp->sect) /* Report EOT when index has reached 65535 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1142 | return FR_NO_FILE; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1143 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1144 | if (!(i % (SS(dp->fs) / SZ_DIRE))) { /* Sector changed? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1145 | dp->sect++; /* Next sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1146 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1147 | if (!dp->clust) { /* Static table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1148 | if (i >= dp->fs->n_rootdir) /* Report EOT if it reached end of static table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1149 | return FR_NO_FILE; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1150 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1151 | else { /* Dynamic table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1152 | if (((i / (SS(dp->fs) / SZ_DIRE)) & (dp->fs->csize - 1)) == 0) { /* Cluster changed? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1153 | clst = get_fat(dp->fs, dp->clust); /* Get next cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1154 | if (clst <= 1) return FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1155 | if (clst == 0xFFFFFFFF) return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1156 | if (clst >= dp->fs->n_fatent) { /* If it reached end of dynamic table, */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1157 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 1158 | if (!stretch) return FR_NO_FILE; /* If do not stretch, report EOT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1159 | clst = create_chain(dp->fs, dp->clust); /* Stretch cluster chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1160 | if (clst == 0) return FR_DENIED; /* No free cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1161 | if (clst == 1) return FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1162 | if (clst == 0xFFFFFFFF) return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1163 | /* Clean-up stretched table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1164 | if (sync_window(dp->fs)) return FR_DISK_ERR;/* Flush disk access window */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1165 | mem_set(dp->fs->win, 0, SS(dp->fs)); /* Clear window buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1166 | dp->fs->winsect = clust2sect(dp->fs, clst); /* Cluster start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1167 | for (c = 0; c < dp->fs->csize; c++) { /* Fill the new cluster with 0 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1168 | dp->fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1169 | if (sync_window(dp->fs)) return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1170 | dp->fs->winsect++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1171 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1172 | dp->fs->winsect -= c; /* Rewind window offset */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1173 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 1174 | if (!stretch) return FR_NO_FILE; /* If do not stretch, report EOT (this is to suppress warning) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1175 | return FR_NO_FILE; /* Report EOT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1176 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1177 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1178 | dp->clust = clst; /* Initialize data for new cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1179 | dp->sect = clust2sect(dp->fs, clst); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1180 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1181 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1182 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1183 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1184 | dp->index = (WORD)i; /* Current index */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1185 | dp->dir = dp->fs->win + (i % (SS(dp->fs) / SZ_DIRE)) * SZ_DIRE; /* Current entry in the window */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1186 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1187 | return FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1188 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1189 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1190 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1191 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1192 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1193 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1194 | /* Directory handling - Reserve directory entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1195 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1196 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1197 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 1198 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1199 | FRESULT dir_alloc ( /* FR_OK(0):succeeded, !=0:error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1200 | FATFS_DIR* dp, /* Pointer to the directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1201 | UINT nent /* Number of contiguous entries to allocate (1-21) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1202 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1203 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1204 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1205 | UINT n; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1206 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1207 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1208 | res = dir_sdi(dp, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1209 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1210 | n = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1211 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1212 | res = move_window(dp->fs, dp->sect); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1213 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1214 | if (dp->dir[0] == DDEM || dp->dir[0] == 0) { /* Is it a free entry? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1215 | if (++n == nent) break; /* A block of contiguous free entries is found */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1216 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1217 | n = 0; /* Not a blank entry. Restart to search */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1218 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1219 | res = dir_next(dp, 1); /* Next entry with table stretch enabled */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1220 | } while (res == FR_OK); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1221 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1222 | if (res == FR_NO_FILE) res = FR_DENIED; /* No directory entry to allocate */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1223 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1224 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1225 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1226 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1227 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1228 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1229 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1230 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1231 | /* Directory handling - Load/Store start cluster number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1232 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1233 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1234 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1235 | DWORD ld_clust ( /* Returns the top cluster value of the SFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1236 | FATFS* fs, /* Pointer to the fs object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1237 | const BYTE* dir /* Pointer to the SFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1238 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1239 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1240 | DWORD cl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1241 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1242 | cl = LD_WORD(dir + DIR_FstClusLO); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1243 | if (fs->fs_type == FS_FAT32) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1244 | cl |= (DWORD)LD_WORD(dir + DIR_FstClusHI) << 16; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1245 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1246 | return cl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1247 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1248 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1249 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1250 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 1251 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1252 | void st_clust ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 1253 | BYTE* dir, /* Pointer to the SFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1254 | DWORD cl /* Value to be set */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1255 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1256 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1257 | ST_WORD(dir + DIR_FstClusLO, cl); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1258 | ST_WORD(dir + DIR_FstClusHI, cl >> 16); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1259 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1260 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1261 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1262 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1263 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1264 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1265 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1266 | /* LFN handling - Test/Pick/Fit an LFN segment from/to directory entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1267 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1268 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 1269 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1270 | const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30}; /* Offset of LFN characters in the directory entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1271 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1272 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1273 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1274 | int cmp_lfn ( /* 1:matched, 0:not matched */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1275 | WCHAR* lfnbuf, /* Pointer to the LFN working buffer to be compared */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1276 | BYTE* dir /* Pointer to the directory entry containing the part of LFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1277 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1278 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1279 | UINT i, s; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1280 | WCHAR wc, uc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1281 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1282 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1283 | if (LD_WORD(dir + LDIR_FstClusLO) != 0) return 0; /* Check LDIR_FstClusLO */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1284 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1285 | i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13; /* Offset in the LFN buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1286 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1287 | for (wc = 1, s = 0; s < 13; s++) { /* Process all characters in the entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1288 | uc = LD_WORD(dir + LfnOfs[s]); /* Pick an LFN character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1289 | if (wc) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1290 | if (i >= _MAX_LFN || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++])) /* Compare it */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1291 | return 0; /* Not matched */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1292 | wc = uc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1293 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1294 | if (uc != 0xFFFF) return 0; /* Check filler */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1295 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1296 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1297 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1298 | if ((dir[LDIR_Ord] & LLEF) && wc && lfnbuf[i]) /* Last segment matched but different length */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1299 | return 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1300 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1301 | return 1; /* The part of LFN matched */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1302 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1303 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1304 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1305 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1306 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1307 | int pick_lfn ( /* 1:succeeded, 0:buffer overflow or invalid LFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1308 | WCHAR* lfnbuf, /* Pointer to the LFN working buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1309 | BYTE* dir /* Pointer to the LFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1310 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1311 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1312 | UINT i, s; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1313 | WCHAR wc, uc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1314 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1315 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1316 | if (LD_WORD(dir + LDIR_FstClusLO) != 0) return 0; /* Check LDIR_FstClusLO */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1317 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1318 | i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13; /* Offset in the LFN buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1319 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1320 | for (wc = 1, s = 0; s < 13; s++) { /* Process all characters in the entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1321 | uc = LD_WORD(dir + LfnOfs[s]); /* Pick an LFN character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1322 | if (wc) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1323 | if (i >= _MAX_LFN) return 0; /* Buffer overflow? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1324 | lfnbuf[i++] = wc = uc; /* Store it */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1325 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1326 | if (uc != 0xFFFF) return 0; /* Check filler */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1327 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1328 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1329 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1330 | if (dir[LDIR_Ord] & LLEF) { /* Put terminator if it is the last LFN part */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1331 | if (i >= _MAX_LFN) return 0; /* Buffer overflow? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1332 | lfnbuf[i] = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1333 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1334 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1335 | return 1; /* The part of LFN is valid */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1336 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1337 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1338 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1339 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 1340 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1341 | void fit_lfn ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 1342 | const WCHAR* lfnbuf, /* Pointer to the LFN working buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1343 | BYTE* dir, /* Pointer to the LFN entry to be processed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1344 | BYTE ord, /* LFN order (1-20) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1345 | BYTE sum /* Checksum of the corresponding SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1346 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1347 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1348 | UINT i, s; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1349 | WCHAR wc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1350 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1351 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1352 | dir[LDIR_Chksum] = sum; /* Set checksum */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1353 | dir[LDIR_Attr] = AM_LFN; /* Set attribute. LFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1354 | dir[LDIR_Type] = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1355 | ST_WORD(dir + LDIR_FstClusLO, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1356 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1357 | i = (ord - 1) * 13; /* Get offset in the LFN working buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1358 | s = wc = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1359 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1360 | if (wc != 0xFFFF) wc = lfnbuf[i++]; /* Get an effective character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1361 | ST_WORD(dir+LfnOfs[s], wc); /* Put it */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1362 | if (!wc) wc = 0xFFFF; /* Padding characters following last character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1363 | } while (++s < 13); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1364 | if (wc == 0xFFFF || !lfnbuf[i]) ord |= LLEF; /* Bottom LFN part is the start of LFN sequence */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1365 | dir[LDIR_Ord] = ord; /* Set the LFN order */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1366 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1367 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1368 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1369 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1370 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1371 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1372 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1373 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1374 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1375 | /* Create numbered name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1376 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1377 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 1378 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1379 | void gen_numname ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 1380 | BYTE* dst, /* Pointer to the buffer to store numbered SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1381 | const BYTE* src, /* Pointer to SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1382 | const WCHAR* lfn, /* Pointer to LFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1383 | UINT seq /* Sequence number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1384 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1385 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1386 | BYTE ns[8], c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1387 | UINT i, j; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1388 | WCHAR wc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1389 | DWORD sr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1390 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1391 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1392 | mem_cpy(dst, src, 11); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1393 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1394 | if (seq > 5) { /* On many collisions, generate a hash number instead of sequential number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1395 | sr = seq; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1396 | while (*lfn) { /* Create a CRC */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1397 | wc = *lfn++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1398 | for (i = 0; i < 16; i++) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1399 | sr = (sr << 1) + (wc & 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1400 | wc >>= 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1401 | if (sr & 0x10000) sr ^= 0x11021; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1402 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1403 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1404 | seq = (UINT)sr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1405 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1406 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1407 | /* itoa (hexdecimal) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1408 | i = 7; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1409 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1410 | c = (seq % 16) + '0'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1411 | if (c > '9') c += 7; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1412 | ns[i--] = c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1413 | seq /= 16; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1414 | } while (seq); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1415 | ns[i] = '~'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1416 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1417 | /* Append the number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1418 | for (j = 0; j < i && dst[j] != ' '; j++) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1419 | if (IsDBCS1(dst[j])) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1420 | if (j == i - 1) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1421 | j++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1422 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1423 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1424 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1425 | dst[j++] = (i < 8) ? ns[i++] : ' '; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1426 | } while (j < 8); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1427 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1428 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1429 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1430 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1431 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1432 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1433 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1434 | /* Calculate checksum of an SFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1435 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1436 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 1437 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1438 | BYTE sum_sfn ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 1439 | const BYTE* dir /* Pointer to the SFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1440 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1441 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1442 | BYTE sum = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1443 | UINT n = 11; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1444 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1445 | do sum = (sum >> 1) + (sum << 7) + *dir++; while (--n); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1446 | return sum; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1447 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1448 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1449 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1450 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1451 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1452 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1453 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1454 | /* Directory handling - Find an object in the directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1455 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1456 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1457 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1458 | FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1459 | FATFS_DIR* dp /* Pointer to the directory object linked to the file name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1460 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1461 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1462 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1463 | BYTE c, *dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1464 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 1465 | BYTE a, ord, sum; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1466 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1467 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1468 | res = dir_sdi(dp, 0); /* Rewind directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1469 | if (res != FR_OK) return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1470 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1471 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 1472 | ord = sum = 0xFF; dp->lfn_idx = 0xFFFF; /* Reset LFN sequence */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1473 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1474 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1475 | res = move_window(dp->fs, dp->sect); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1476 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1477 | dir = dp->dir; /* Ptr to the directory entry of current index */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1478 | c = dir[DIR_Name]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1479 | if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1480 | #if _USE_LFN /* LFN configuration */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1481 | a = dir[DIR_Attr] & AM_MASK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1482 | if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) { /* An entry without valid data */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1483 | ord = 0xFF; dp->lfn_idx = 0xFFFF; /* Reset LFN sequence */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1484 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1485 | if (a == AM_LFN) { /* An LFN entry is found */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1486 | if (dp->lfn) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1487 | if (c & LLEF) { /* Is it start of LFN sequence? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1488 | sum = dir[LDIR_Chksum]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1489 | c &= ~LLEF; ord = c; /* LFN start order */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1490 | dp->lfn_idx = dp->index; /* Start index of LFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1491 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1492 | /* Check validity of the LFN entry and compare it with given name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1493 | ord = (c == ord && sum == dir[LDIR_Chksum] && cmp_lfn(dp->lfn, dir)) ? ord - 1 : 0xFF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1494 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1495 | } else { /* An SFN entry is found */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1496 | if (!ord && sum == sum_sfn(dir)) break; /* LFN matched? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1497 | if (!(dp->fn[NSFLAG] & NS_LOSS) && !mem_cmp(dir, dp->fn, 11)) break; /* SFN matched? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1498 | ord = 0xFF; dp->lfn_idx = 0xFFFF; /* Reset LFN sequence */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1499 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1500 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1501 | #else /* Non LFN configuration */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1502 | if (!(dir[DIR_Attr] & AM_VOL) && !mem_cmp(dir, dp->fn, 11)) /* Is it a valid entry? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1503 | break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1504 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1505 | res = dir_next(dp, 0); /* Next entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1506 | } while (res == FR_OK); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1507 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1508 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1509 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1510 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1511 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1512 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1513 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1514 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1515 | /* Read an object from the directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1516 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1517 | #if _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2 |
JDI_Mbed_Team | 0:33fe30a2b785 | 1518 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1519 | FRESULT dir_read ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 1520 | FATFS_DIR* dp, /* Pointer to the directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1521 | int vol /* Filtered by 0:file/directory or 1:volume label */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1522 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1523 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1524 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1525 | BYTE a, c, *dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1526 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 1527 | BYTE ord = 0xFF, sum = 0xFF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1528 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1529 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1530 | res = FR_NO_FILE; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1531 | while (dp->sect) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1532 | res = move_window(dp->fs, dp->sect); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1533 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1534 | dir = dp->dir; /* Ptr to the directory entry of current index */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1535 | c = dir[DIR_Name]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1536 | if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1537 | a = dir[DIR_Attr] & AM_MASK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1538 | #if _USE_LFN /* LFN configuration */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1539 | if (c == DDEM || (!_FS_RPATH && c == '.') || (int)((a & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1540 | ord = 0xFF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1541 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1542 | if (a == AM_LFN) { /* An LFN entry is found */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1543 | if (c & LLEF) { /* Is it start of LFN sequence? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1544 | sum = dir[LDIR_Chksum]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1545 | c &= ~LLEF; ord = c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1546 | dp->lfn_idx = dp->index; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1547 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1548 | /* Check LFN validity and capture it */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1549 | ord = (c == ord && sum == dir[LDIR_Chksum] && pick_lfn(dp->lfn, dir)) ? ord - 1 : 0xFF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1550 | } else { /* An SFN entry is found */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1551 | if (ord || sum != sum_sfn(dir)) /* Is there a valid LFN? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1552 | dp->lfn_idx = 0xFFFF; /* It has no LFN. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1553 | break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1554 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1555 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1556 | #else /* Non LFN configuration */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1557 | if (c != DDEM && (_FS_RPATH || c != '.') && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol) /* Is it a valid entry? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1558 | break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1559 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1560 | res = dir_next(dp, 0); /* Next entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1561 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1562 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1563 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1564 | if (res != FR_OK) dp->sect = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1565 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1566 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1567 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1568 | #endif /* _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1569 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1570 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1571 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1572 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1573 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1574 | /* Register an object to the directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1575 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1576 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 1577 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1578 | FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too many SFN collision, FR_DISK_ERR:disk error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1579 | FATFS_DIR* dp /* Target directory with object name to be created */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1580 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1581 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1582 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1583 | #if _USE_LFN /* LFN configuration */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1584 | UINT n, nent; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1585 | BYTE sn[12], *fn, sum; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1586 | WCHAR *lfn; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1587 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1588 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1589 | fn = dp->fn; lfn = dp->lfn; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1590 | mem_cpy(sn, fn, 12); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1591 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1592 | if (_FS_RPATH && (sn[NSFLAG] & NS_DOT)) /* Cannot create dot entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1593 | return FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1594 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1595 | if (sn[NSFLAG] & NS_LOSS) { /* When LFN is out of 8.3 format, generate a numbered name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1596 | fn[NSFLAG] = 0; dp->lfn = 0; /* Find only SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1597 | for (n = 1; n < 100; n++) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1598 | gen_numname(fn, sn, lfn, n); /* Generate a numbered name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1599 | res = dir_find(dp); /* Check if the name collides with existing SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1600 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1601 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1602 | if (n == 100) return FR_DENIED; /* Abort if too many collisions */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1603 | if (res != FR_NO_FILE) return res; /* Abort if the result is other than 'not collided' */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1604 | fn[NSFLAG] = sn[NSFLAG]; dp->lfn = lfn; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1605 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1606 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1607 | if (sn[NSFLAG] & NS_LFN) { /* When LFN is to be created, allocate entries for an SFN + LFNs. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1608 | for (n = 0; lfn[n]; n++) ; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1609 | nent = (n + 25) / 13; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1610 | } else { /* Otherwise allocate an entry for an SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1611 | nent = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1612 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1613 | res = dir_alloc(dp, nent); /* Allocate entries */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1614 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1615 | if (res == FR_OK && --nent) { /* Set LFN entry if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1616 | res = dir_sdi(dp, dp->index - nent); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1617 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1618 | sum = sum_sfn(dp->fn); /* Checksum value of the SFN tied to the LFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1619 | do { /* Store LFN entries in bottom first */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1620 | res = move_window(dp->fs, dp->sect); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1621 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1622 | fit_lfn(dp->lfn, dp->dir, (BYTE)nent, sum); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1623 | dp->fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1624 | res = dir_next(dp, 0); /* Next entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1625 | } while (res == FR_OK && --nent); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1626 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1627 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1628 | #else /* Non LFN configuration */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1629 | res = dir_alloc(dp, 1); /* Allocate an entry for SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1630 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1631 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1632 | if (res == FR_OK) { /* Set SFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1633 | res = move_window(dp->fs, dp->sect); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1634 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1635 | mem_set(dp->dir, 0, SZ_DIRE); /* Clean the entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1636 | mem_cpy(dp->dir, dp->fn, 11); /* Put SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1637 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 1638 | dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT); /* Put NT flag */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1639 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1640 | dp->fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1641 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1642 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1643 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1644 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1645 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1646 | #endif /* !_FS_READONLY */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1647 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1648 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1649 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1650 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1651 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1652 | /* Remove an object from the directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1653 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1654 | #if !_FS_READONLY && !_FS_MINIMIZE |
JDI_Mbed_Team | 0:33fe30a2b785 | 1655 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1656 | FRESULT dir_remove ( /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1657 | FATFS_DIR* dp /* Directory object pointing the entry to be removed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1658 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1659 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1660 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1661 | #if _USE_LFN /* LFN configuration */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1662 | UINT i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1663 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1664 | i = dp->index; /* SFN index */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1665 | res = dir_sdi(dp, (dp->lfn_idx == 0xFFFF) ? i : dp->lfn_idx); /* Goto the SFN or top of the LFN entries */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1666 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1667 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1668 | res = move_window(dp->fs, dp->sect); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1669 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1670 | mem_set(dp->dir, 0, SZ_DIRE); /* Clear and mark the entry "deleted" */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1671 | *dp->dir = DDEM; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1672 | dp->fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1673 | if (dp->index >= i) break; /* When reached SFN, all entries of the object has been deleted. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1674 | res = dir_next(dp, 0); /* Next entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1675 | } while (res == FR_OK); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1676 | if (res == FR_NO_FILE) res = FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1677 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1678 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1679 | #else /* Non LFN configuration */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1680 | res = dir_sdi(dp, dp->index); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1681 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1682 | res = move_window(dp->fs, dp->sect); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1683 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1684 | mem_set(dp->dir, 0, SZ_DIRE); /* Clear and mark the entry "deleted" */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1685 | *dp->dir = DDEM; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1686 | dp->fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1687 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1688 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1689 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1690 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1691 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1692 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1693 | #endif /* !_FS_READONLY */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1694 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1695 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1696 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1697 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1698 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1699 | /* Get file information from directory entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1700 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1701 | #if _FS_MINIMIZE <= 1 || _FS_RPATH >= 2 |
JDI_Mbed_Team | 0:33fe30a2b785 | 1702 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1703 | void get_fileinfo ( /* No return code */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1704 | FATFS_DIR* dp, /* Pointer to the directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1705 | FILINFO* fno /* Pointer to the file information to be filled */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1706 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1707 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1708 | UINT i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1709 | TCHAR *p, c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1710 | BYTE *dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1711 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 1712 | WCHAR w, *lfn; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1713 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1714 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1715 | p = fno->fname; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1716 | if (dp->sect) { /* Get SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1717 | dir = dp->dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1718 | i = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1719 | while (i < 11) { /* Copy name body and extension */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1720 | c = (TCHAR)dir[i++]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1721 | if (c == ' ') continue; /* Skip padding spaces */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1722 | if (c == RDDEM) c = (TCHAR)DDEM; /* Restore replaced DDEM character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1723 | if (i == 9) *p++ = '.'; /* Insert a . if extension is exist */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1724 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 1725 | if (IsUpper(c) && (dir[DIR_NTres] & (i >= 9 ? NS_EXT : NS_BODY))) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1726 | c += 0x20; /* To lower */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1727 | #if _LFN_UNICODE |
JDI_Mbed_Team | 0:33fe30a2b785 | 1728 | if (IsDBCS1(c) && i != 8 && i != 11 && IsDBCS2(dir[i])) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1729 | c = c << 8 | dir[i++]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1730 | c = ff_convert(c, 1); /* OEM -> Unicode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1731 | if (!c) c = '?'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1732 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1733 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1734 | *p++ = c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1735 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1736 | fno->fattrib = dir[DIR_Attr]; /* Attribute */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1737 | fno->fsize = LD_DWORD(dir + DIR_FileSize); /* Size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1738 | fno->fdate = LD_WORD(dir + DIR_WrtDate); /* Date */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1739 | fno->ftime = LD_WORD(dir + DIR_WrtTime); /* Time */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1740 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1741 | *p = 0; /* Terminate SFN string by a \0 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1742 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1743 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 1744 | if (fno->lfname) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1745 | i = 0; p = fno->lfname; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1746 | if (dp->sect && fno->lfsize && dp->lfn_idx != 0xFFFF) { /* Get LFN if available */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1747 | lfn = dp->lfn; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1748 | while ((w = *lfn++) != 0) { /* Get an LFN character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1749 | #if !_LFN_UNICODE |
JDI_Mbed_Team | 0:33fe30a2b785 | 1750 | w = ff_convert(w, 0); /* Unicode -> OEM */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1751 | if (!w) { i = 0; break; } /* No LFN if it could not be converted */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1752 | if (_DF1S && w >= 0x100) /* Put 1st byte if it is a DBC (always false on SBCS cfg) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1753 | p[i++] = (TCHAR)(w >> 8); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1754 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1755 | if (i >= fno->lfsize - 1) { i = 0; break; } /* No LFN if buffer overflow */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1756 | p[i++] = (TCHAR)w; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1757 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1758 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1759 | p[i] = 0; /* Terminate LFN string by a \0 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1760 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1761 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1762 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1763 | #endif /* _FS_MINIMIZE <= 1 || _FS_RPATH >= 2 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1764 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1765 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1766 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1767 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1768 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1769 | /* Pattern matching */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1770 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1771 | #if _USE_FIND && _FS_MINIMIZE <= 1 |
JDI_Mbed_Team | 0:33fe30a2b785 | 1772 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1773 | WCHAR get_achar ( /* Get a character and advances ptr 1 or 2 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1774 | const TCHAR** ptr /* Pointer to pointer to the SBCS/DBCS/Unicode string */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1775 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1776 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1777 | WCHAR chr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1778 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1779 | #if !_LFN_UNICODE |
JDI_Mbed_Team | 0:33fe30a2b785 | 1780 | chr = (BYTE)*(*ptr)++; /* Get a byte */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1781 | if (IsLower(chr)) chr -= 0x20; /* To upper ASCII char */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1782 | if (IsDBCS1(chr) && IsDBCS2(**ptr)) /* Get DBC 2nd byte if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1783 | chr = chr << 8 | (BYTE)*(*ptr)++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1784 | #ifdef _EXCVT |
JDI_Mbed_Team | 0:33fe30a2b785 | 1785 | if (chr >= 0x80) chr = ExCvt[chr - 0x80]; /* To upper SBCS extended char */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1786 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1787 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 1788 | chr = ff_wtoupper(*(*ptr)++); /* Get a word and to upper */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1789 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1790 | return chr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1791 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1792 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1793 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1794 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1795 | int pattern_matching ( /* 0:mismatched, 1:matched */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1796 | const TCHAR* pat, /* Matching pattern */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1797 | const TCHAR* nam, /* String to be tested */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1798 | int skip, /* Number of pre-skip chars (number of ?s) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1799 | int inf /* Infinite search (* specified) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1800 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1801 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1802 | const TCHAR *pp, *np; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1803 | WCHAR pc, nc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1804 | int nm, nx; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1805 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1806 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1807 | while (skip--) { /* Pre-skip name chars */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1808 | if (!get_achar(&nam)) return 0; /* Branch mismatched if less name chars */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1809 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1810 | if (!*pat && inf) return 1; /* (short circuit) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1811 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1812 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1813 | pp = pat; np = nam; /* Top of pattern and name to match */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1814 | for (;;) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1815 | if (*pp == '?' || *pp == '*') { /* Wildcard? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1816 | nm = nx = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1817 | do { /* Analyze the wildcard chars */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1818 | if (*pp++ == '?') nm++; else nx = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1819 | } while (*pp == '?' || *pp == '*'); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1820 | if (pattern_matching(pp, np, nm, nx)) return 1; /* Test new branch (recurs upto number of wildcard blocks in the pattern) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1821 | nc = *np; break; /* Branch mismatched */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1822 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1823 | pc = get_achar(&pp); /* Get a pattern char */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1824 | nc = get_achar(&np); /* Get a name char */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1825 | if (pc != nc) break; /* Branch mismatched? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1826 | if (!pc) return 1; /* Branch matched? (matched at end of both strings) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1827 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1828 | get_achar(&nam); /* nam++ */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1829 | } while (inf && nc); /* Retry until end of name if infinite search is specified */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1830 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1831 | return 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1832 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1833 | #endif /* _USE_FIND && _FS_MINIMIZE <= 1 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1834 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1835 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1836 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1837 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1838 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1839 | /* Pick a top segment and create the object name in directory form */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1840 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1841 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1842 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 1843 | FRESULT create_name ( /* FR_OK: successful, FR_INVALID_NAME: could not create */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1844 | FATFS_DIR* dp, /* Pointer to the directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1845 | const TCHAR** path /* Pointer to pointer to the segment in the path string */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1846 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1847 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1848 | #if _USE_LFN /* LFN configuration */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1849 | BYTE b, cf; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1850 | WCHAR w, *lfn; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1851 | UINT i, ni, si, di; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1852 | const TCHAR *p; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1853 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1854 | /* Create LFN in Unicode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1855 | for (p = *path; *p == '/' || *p == '\\'; p++) ; /* Strip duplicated separator */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1856 | lfn = dp->lfn; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1857 | si = di = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1858 | for (;;) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1859 | w = p[si++]; /* Get a character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1860 | if (w < ' ' || w == '/' || w == '\\') break; /* Break on end of segment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1861 | if (di >= _MAX_LFN) /* Reject too long name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1862 | return FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1863 | #if !_LFN_UNICODE |
JDI_Mbed_Team | 0:33fe30a2b785 | 1864 | w &= 0xFF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1865 | if (IsDBCS1(w)) { /* Check if it is a DBC 1st byte (always false on SBCS cfg) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1866 | b = (BYTE)p[si++]; /* Get 2nd byte */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1867 | w = (w << 8) + b; /* Create a DBC */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1868 | if (!IsDBCS2(b)) |
JDI_Mbed_Team | 0:33fe30a2b785 | 1869 | return FR_INVALID_NAME; /* Reject invalid sequence */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1870 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1871 | w = ff_convert(w, 1); /* Convert ANSI/OEM to Unicode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1872 | if (!w) return FR_INVALID_NAME; /* Reject invalid code */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1873 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1874 | if (w < 0x80 && chk_chr("\"*:<>\?|\x7F", w)) /* Reject illegal characters for LFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1875 | return FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1876 | lfn[di++] = w; /* Store the Unicode character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1877 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1878 | *path = &p[si]; /* Return pointer to the next segment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1879 | cf = (w < ' ') ? NS_LAST : 0; /* Set last segment flag if end of path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1880 | #if _FS_RPATH |
JDI_Mbed_Team | 0:33fe30a2b785 | 1881 | if ((di == 1 && lfn[di - 1] == '.') || |
JDI_Mbed_Team | 0:33fe30a2b785 | 1882 | (di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) { /* Is this segment a dot entry? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1883 | lfn[di] = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1884 | for (i = 0; i < 11; i++) /* Create dot name for SFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1885 | dp->fn[i] = (i < di) ? '.' : ' '; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1886 | dp->fn[i] = cf | NS_DOT; /* This is a dot entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1887 | return FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1888 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1889 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1890 | while (di) { /* Snip off trailing spaces and dots if exist */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1891 | w = lfn[di - 1]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1892 | if (w != ' ' && w != '.') break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1893 | di--; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1894 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1895 | if (!di) return FR_INVALID_NAME; /* Reject nul string */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1896 | lfn[di] = 0; /* LFN is created */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1897 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1898 | /* Create SFN in directory form */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1899 | mem_set(dp->fn, ' ', 11); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1900 | for (si = 0; lfn[si] == ' ' || lfn[si] == '.'; si++) ; /* Strip leading spaces and dots */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1901 | if (si) cf |= NS_LOSS | NS_LFN; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1902 | while (di && lfn[di - 1] != '.') di--; /* Find extension (di<=si: no extension) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1903 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1904 | b = i = 0; ni = 8; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1905 | for (;;) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1906 | w = lfn[si++]; /* Get an LFN character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1907 | if (!w) break; /* Break on end of the LFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1908 | if (w == ' ' || (w == '.' && si != di)) { /* Remove spaces and dots */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1909 | cf |= NS_LOSS | NS_LFN; continue; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1910 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1911 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1912 | if (i >= ni || si == di) { /* Extension or end of SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1913 | if (ni == 11) { /* Long extension */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1914 | cf |= NS_LOSS | NS_LFN; break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1915 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1916 | if (si != di) cf |= NS_LOSS | NS_LFN; /* Out of 8.3 format */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1917 | if (si > di) break; /* No extension */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1918 | si = di; i = 8; ni = 11; /* Enter extension section */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1919 | b <<= 2; continue; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1920 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1921 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1922 | if (w >= 0x80) { /* Non ASCII character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1923 | #ifdef _EXCVT |
JDI_Mbed_Team | 0:33fe30a2b785 | 1924 | w = ff_convert(w, 0); /* Unicode -> OEM code */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1925 | if (w) w = ExCvt[w - 0x80]; /* Convert extended character to upper (SBCS) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1926 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 1927 | w = ff_convert(ff_wtoupper(w), 0); /* Upper converted Unicode -> OEM code */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1928 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1929 | cf |= NS_LFN; /* Force create LFN entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1930 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1931 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1932 | if (_DF1S && w >= 0x100) { /* Is this DBC? (always false at SBCS cfg) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1933 | if (i >= ni - 1) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1934 | cf |= NS_LOSS | NS_LFN; i = ni; continue; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1935 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1936 | dp->fn[i++] = (BYTE)(w >> 8); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1937 | } else { /* SBC */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1938 | if (!w || chk_chr("+,;=[]", w)) { /* Replace illegal characters for SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1939 | w = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1940 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1941 | if (IsUpper(w)) { /* ASCII large capital */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1942 | b |= 2; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1943 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1944 | if (IsLower(w)) { /* ASCII small capital */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1945 | b |= 1; w -= 0x20; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1946 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1947 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1948 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1949 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1950 | dp->fn[i++] = (BYTE)w; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1951 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1952 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1953 | if (dp->fn[0] == DDEM) dp->fn[0] = RDDEM; /* If the first character collides with DDEM, replace it with RDDEM */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1954 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1955 | if (ni == 8) b <<= 2; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1956 | if ((b & 0x0C) == 0x0C || (b & 0x03) == 0x03) /* Create LFN entry when there are composite capitals */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1957 | cf |= NS_LFN; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1958 | if (!(cf & NS_LFN)) { /* When LFN is in 8.3 format without extended character, NT flags are created */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1959 | if ((b & 0x03) == 0x01) cf |= NS_EXT; /* NT flag (Extension has only small capital) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1960 | if ((b & 0x0C) == 0x04) cf |= NS_BODY; /* NT flag (Filename has only small capital) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1961 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1962 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1963 | dp->fn[NSFLAG] = cf; /* SFN is created */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1964 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1965 | return FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1966 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1967 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1968 | #else /* Non-LFN configuration */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1969 | BYTE b, c, d, *sfn; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1970 | UINT ni, si, i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1971 | const char *p; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1972 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 1973 | /* Create file name in directory form */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1974 | for (p = *path; *p == '/' || *p == '\\'; p++) ; /* Skip duplicated separator */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1975 | sfn = dp->fn; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1976 | mem_set(sfn, ' ', 11); |
JDI_Mbed_Team | 0:33fe30a2b785 | 1977 | si = i = b = 0; ni = 8; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1978 | #if _FS_RPATH |
JDI_Mbed_Team | 0:33fe30a2b785 | 1979 | if (p[si] == '.') { /* Is this a dot entry? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1980 | for (;;) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1981 | c = (BYTE)p[si++]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1982 | if (c != '.' || si >= 3) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1983 | sfn[i++] = c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1984 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1985 | if (c != '/' && c != '\\' && c > ' ') return FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1986 | *path = &p[si]; /* Return pointer to the next segment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1987 | sfn[NSFLAG] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1988 | return FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1989 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1990 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 1991 | for (;;) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1992 | c = (BYTE)p[si++]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1993 | if (c <= ' ' || c == '/' || c == '\\') break; /* Break on end of segment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 1994 | if (c == '.' || i >= ni) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 1995 | if (ni != 8 || c != '.') return FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1996 | i = 8; ni = 11; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1997 | b <<= 2; continue; |
JDI_Mbed_Team | 0:33fe30a2b785 | 1998 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 1999 | if (c >= 0x80) { /* Extended character? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2000 | b |= 3; /* Eliminate NT flag */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2001 | #ifdef _EXCVT |
JDI_Mbed_Team | 0:33fe30a2b785 | 2002 | c = ExCvt[c - 0x80]; /* To upper extended characters (SBCS cfg) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2003 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2004 | #if !_DF1S |
JDI_Mbed_Team | 0:33fe30a2b785 | 2005 | return FR_INVALID_NAME; /* Reject extended characters (ASCII cfg) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2006 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2007 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2008 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2009 | if (IsDBCS1(c)) { /* Check if it is a DBC 1st byte (always false at SBCS cfg.) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2010 | d = (BYTE)p[si++]; /* Get 2nd byte */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2011 | if (!IsDBCS2(d) || i >= ni - 1) /* Reject invalid DBC */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2012 | return FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2013 | sfn[i++] = c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2014 | sfn[i++] = d; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2015 | } else { /* SBC */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2016 | if (chk_chr("\"*+,:;<=>\?[]|\x7F", c)) /* Reject illegal chrs for SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2017 | return FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2018 | if (IsUpper(c)) { /* ASCII large capital? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2019 | b |= 2; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2020 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2021 | if (IsLower(c)) { /* ASCII small capital? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2022 | b |= 1; c -= 0x20; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2023 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2024 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2025 | sfn[i++] = c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2026 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2027 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2028 | *path = &p[si]; /* Return pointer to the next segment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2029 | c = (c <= ' ') ? NS_LAST : 0; /* Set last segment flag if end of path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2030 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2031 | if (!i) return FR_INVALID_NAME; /* Reject nul string */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2032 | if (sfn[0] == DDEM) sfn[0] = RDDEM; /* When first character collides with DDEM, replace it with RDDEM */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2033 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2034 | if (ni == 8) b <<= 2; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2035 | if ((b & 0x03) == 0x01) c |= NS_EXT; /* NT flag (Name extension has only small capital) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2036 | if ((b & 0x0C) == 0x04) c |= NS_BODY; /* NT flag (Name body has only small capital) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2037 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2038 | sfn[NSFLAG] = c; /* Store NT flag, File name is created */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2039 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2040 | return FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2041 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2042 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2043 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2044 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2045 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2046 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2047 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2048 | /* Follow a file path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2049 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2050 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2051 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 2052 | FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2053 | FATFS_DIR* dp, /* Directory object to return last directory and found object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2054 | const TCHAR* path /* Full-path string to find a file or directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2055 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2056 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2057 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2058 | BYTE *dir, ns; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2059 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2060 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2061 | #if _FS_RPATH |
JDI_Mbed_Team | 0:33fe30a2b785 | 2062 | if (*path == '/' || *path == '\\') { /* There is a heading separator */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2063 | path++; dp->sclust = 0; /* Strip it and start from the root directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2064 | } else { /* No heading separator */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2065 | dp->sclust = dp->fs->cdir; /* Start from the current directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2066 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2067 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2068 | if (*path == '/' || *path == '\\') /* Strip heading separator if exist */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2069 | path++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2070 | dp->sclust = 0; /* Always start from the root directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2071 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2072 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2073 | if ((UINT)*path < ' ') { /* Null path name is the origin directory itself */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2074 | res = dir_sdi(dp, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2075 | dp->dir = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2076 | } else { /* Follow path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2077 | for (;;) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2078 | res = create_name(dp, &path); /* Get a segment name of the path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2079 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2080 | res = dir_find(dp); /* Find an object with the sagment name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2081 | ns = dp->fn[NSFLAG]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2082 | if (res != FR_OK) { /* Failed to find the object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2083 | if (res == FR_NO_FILE) { /* Object is not found */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2084 | if (_FS_RPATH && (ns & NS_DOT)) { /* If dot entry is not exist, */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2085 | dp->sclust = 0; dp->dir = 0; /* it is the root directory and stay there */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2086 | if (!(ns & NS_LAST)) continue; /* Continue to follow if not last segment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2087 | res = FR_OK; /* Ended at the root directroy. Function completed. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2088 | } else { /* Could not find the object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2089 | if (!(ns & NS_LAST)) res = FR_NO_PATH; /* Adjust error code if not last segment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2090 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2091 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2092 | break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2093 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2094 | if (ns & NS_LAST) break; /* Last segment matched. Function completed. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2095 | dir = dp->dir; /* Follow the sub-directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2096 | if (!(dir[DIR_Attr] & AM_DIR)) { /* It is not a sub-directory and cannot follow */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2097 | res = FR_NO_PATH; break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2098 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2099 | dp->sclust = ld_clust(dp->fs, dir); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2100 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2101 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2102 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2103 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2104 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2105 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2106 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2107 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2108 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2109 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2110 | /* Get logical drive number from path name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2111 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2112 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2113 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 2114 | int get_ldnumber ( /* Returns logical drive number (-1:invalid drive) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2115 | const TCHAR** path /* Pointer to pointer to the path name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2116 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2117 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2118 | const TCHAR *tp, *tt; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2119 | UINT i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2120 | int vol = -1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2121 | #if _STR_VOLUME_ID /* Find string drive id */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2122 | static const char* const str[] = {_VOLUME_STRS}; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2123 | const char *sp; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2124 | char c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2125 | TCHAR tc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2126 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2127 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2128 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2129 | if (*path) { /* If the pointer is not a null */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2130 | for (tt = *path; (UINT)*tt >= (_USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ; /* Find ':' in the path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2131 | if (*tt == ':') { /* If a ':' is exist in the path name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2132 | tp = *path; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2133 | i = *tp++ - '0'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2134 | if (i < 10 && tp == tt) { /* Is there a numeric drive id? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2135 | if (i < _VOLUMES) { /* If a drive id is found, get the value and strip it */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2136 | vol = (int)i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2137 | *path = ++tt; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2138 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2139 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2140 | #if _STR_VOLUME_ID |
JDI_Mbed_Team | 0:33fe30a2b785 | 2141 | else { /* No numeric drive number, find string drive id */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2142 | i = 0; tt++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2143 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2144 | sp = str[i]; tp = *path; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2145 | do { /* Compare a string drive id with path name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2146 | c = *sp++; tc = *tp++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2147 | if (IsLower(tc)) tc -= 0x20; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2148 | } while (c && (TCHAR)c == tc); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2149 | } while ((c || tp != tt) && ++i < _VOLUMES); /* Repeat for each id until pattern match */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2150 | if (i < _VOLUMES) { /* If a drive id is found, get the value and strip it */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2151 | vol = (int)i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2152 | *path = tt; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2153 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2154 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2155 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2156 | return vol; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2157 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2158 | #if _FS_RPATH && _VOLUMES >= 2 |
JDI_Mbed_Team | 0:33fe30a2b785 | 2159 | vol = CurrVol; /* Current drive */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2160 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2161 | vol = 0; /* Drive 0 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2162 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2163 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2164 | return vol; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2165 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2166 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2167 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2168 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2169 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2170 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2171 | /* Load a sector and check if it is an FAT boot sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2172 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2173 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2174 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 2175 | BYTE check_fs ( /* 0:Valid FAT-BS, 1:Valid BS but not FAT, 2:Not a BS, 3:Disk error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2176 | FATFS* fs, /* File system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2177 | DWORD sect /* Sector# (lba) to check if it is an FAT boot record or not */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2178 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2179 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2180 | fs->wflag = 0; fs->winsect = 0xFFFFFFFF; /* Invaidate window */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2181 | if (move_window(fs, sect) != FR_OK) /* Load boot record */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2182 | return 3; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2183 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2184 | if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check boot record signature (always placed at offset 510 even if the sector size is >512) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2185 | return 2; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2186 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2187 | if ((LD_DWORD(&fs->win[BS_FilSysType]) & 0xFFFFFF) == 0x544146) /* Check "FAT" string */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2188 | return 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2189 | if ((LD_DWORD(&fs->win[BS_FilSysType32]) & 0xFFFFFF) == 0x544146) /* Check "FAT" string */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2190 | return 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2191 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2192 | return 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2193 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2194 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2195 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2196 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2197 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2198 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2199 | /* Find logical drive and check if the volume is mounted */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2200 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2201 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2202 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 2203 | FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2204 | FATFS** rfs, /* Pointer to pointer to the found file system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2205 | const TCHAR** path, /* Pointer to pointer to the path name (drive number) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2206 | BYTE wmode /* !=0: Check write protection for write access */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2207 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2208 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2209 | BYTE fmt, *pt; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2210 | int vol; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2211 | DSTATUS stat; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2212 | DWORD bsect, fasize, tsect, sysect, nclst, szbfat, br[4]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2213 | WORD nrsv; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2214 | FATFS *fs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2215 | UINT i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2216 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2217 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2218 | /* Get logical drive number from the path name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2219 | *rfs = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2220 | vol = get_ldnumber(path); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2221 | if (vol < 0) return FR_INVALID_DRIVE; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2222 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2223 | /* Check if the file system object is valid or not */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2224 | fs = FatFs[vol]; /* Get pointer to the file system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2225 | if (!fs) return FR_NOT_ENABLED; /* Is the file system object available? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2226 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2227 | ENTER_FF(fs); /* Lock the volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2228 | *rfs = fs; /* Return pointer to the file system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2229 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2230 | if (fs->fs_type) { /* If the volume has been mounted */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2231 | stat = disk_status(fs->drv); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2232 | if (!(stat & STA_NOINIT)) { /* and the physical drive is kept initialized */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2233 | if (!_FS_READONLY && wmode && (stat & STA_PROTECT)) /* Check write protection if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2234 | return FR_WRITE_PROTECTED; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2235 | return FR_OK; /* The file system object is valid */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2236 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2237 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2238 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2239 | /* The file system object is not valid. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2240 | /* Following code attempts to mount the volume. (analyze BPB and initialize the fs object) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2241 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2242 | fs->fs_type = 0; /* Clear the file system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2243 | fs->drv = LD2PD(vol); /* Bind the logical drive and a physical drive */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2244 | stat = disk_initialize(fs->drv); /* Initialize the physical drive */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2245 | if (stat & STA_NOINIT) /* Check if the initialization succeeded */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2246 | return FR_NOT_READY; /* Failed to initialize due to no medium or hard error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2247 | if (!_FS_READONLY && wmode && (stat & STA_PROTECT)) /* Check disk write protection if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2248 | return FR_WRITE_PROTECTED; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2249 | #if _MAX_SS != _MIN_SS /* Get sector size (multiple sector size cfg only) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2250 | if (disk_ioctl(fs->drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK |
JDI_Mbed_Team | 0:33fe30a2b785 | 2251 | || SS(fs) < _MIN_SS || SS(fs) > _MAX_SS) return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2252 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2253 | /* Find an FAT partition on the drive. Supports only generic partitioning, FDISK and SFD. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2254 | bsect = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2255 | fmt = check_fs(fs, bsect); /* Load sector 0 and check if it is an FAT boot sector as SFD */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2256 | if (fmt == 1 || (!fmt && (LD2PT(vol)))) { /* Not an FAT boot sector or forced partition number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2257 | for (i = 0; i < 4; i++) { /* Get partition offset */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2258 | pt = fs->win + MBR_Table + i * SZ_PTE; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2259 | br[i] = pt[4] ? LD_DWORD(&pt[8]) : 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2260 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2261 | i = LD2PT(vol); /* Partition number: 0:auto, 1-4:forced */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2262 | if (i) i--; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2263 | do { /* Find an FAT volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2264 | bsect = br[i]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2265 | fmt = bsect ? check_fs(fs, bsect) : 2; /* Check the partition */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2266 | } while (!LD2PT(vol) && fmt && ++i < 4); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2267 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2268 | if (fmt == 3) return FR_DISK_ERR; /* An error occured in the disk I/O layer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2269 | if (fmt) return FR_NO_FILESYSTEM; /* No FAT volume is found */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2270 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2271 | /* An FAT volume is found. Following code initializes the file system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2272 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2273 | if (LD_WORD(fs->win + BPB_BytsPerSec) != SS(fs)) /* (BPB_BytsPerSec must be equal to the physical sector size) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2274 | return FR_NO_FILESYSTEM; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2275 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2276 | fasize = LD_WORD(fs->win + BPB_FATSz16); /* Number of sectors per FAT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2277 | if (!fasize) fasize = LD_DWORD(fs->win + BPB_FATSz32); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2278 | fs->fsize = fasize; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2279 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2280 | fs->n_fats = fs->win[BPB_NumFATs]; /* Number of FAT copies */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2281 | if (fs->n_fats != 1 && fs->n_fats != 2) /* (Must be 1 or 2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2282 | return FR_NO_FILESYSTEM; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2283 | fasize *= fs->n_fats; /* Number of sectors for FAT area */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2284 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2285 | fs->csize = fs->win[BPB_SecPerClus]; /* Number of sectors per cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2286 | if (!fs->csize || (fs->csize & (fs->csize - 1))) /* (Must be power of 2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2287 | return FR_NO_FILESYSTEM; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2288 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2289 | fs->n_rootdir = LD_WORD(fs->win + BPB_RootEntCnt); /* Number of root directory entries */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2290 | if (fs->n_rootdir % (SS(fs) / SZ_DIRE)) /* (Must be sector aligned) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2291 | return FR_NO_FILESYSTEM; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2292 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2293 | tsect = LD_WORD(fs->win + BPB_TotSec16); /* Number of sectors on the volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2294 | if (!tsect) tsect = LD_DWORD(fs->win + BPB_TotSec32); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2295 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2296 | nrsv = LD_WORD(fs->win + BPB_RsvdSecCnt); /* Number of reserved sectors */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2297 | if (!nrsv) return FR_NO_FILESYSTEM; /* (Must not be 0) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2298 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2299 | /* Determine the FAT sub type */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2300 | sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIRE); /* RSV + FAT + FATFS_DIR */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2301 | if (tsect < sysect) return FR_NO_FILESYSTEM; /* (Invalid volume size) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2302 | nclst = (tsect - sysect) / fs->csize; /* Number of clusters */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2303 | if (!nclst) return FR_NO_FILESYSTEM; /* (Invalid volume size) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2304 | fmt = FS_FAT12; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2305 | if (nclst >= MIN_FAT16) fmt = FS_FAT16; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2306 | if (nclst >= MIN_FAT32) fmt = FS_FAT32; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2307 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2308 | /* Boundaries and Limits */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2309 | fs->n_fatent = nclst + 2; /* Number of FAT entries */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2310 | fs->volbase = bsect; /* Volume start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2311 | fs->fatbase = bsect + nrsv; /* FAT start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2312 | fs->database = bsect + sysect; /* Data start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2313 | if (fmt == FS_FAT32) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2314 | if (fs->n_rootdir) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must be 0) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2315 | fs->dirbase = LD_DWORD(fs->win + BPB_RootClus); /* Root directory start cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2316 | szbfat = fs->n_fatent * 4; /* (Needed FAT size) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2317 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2318 | if (!fs->n_rootdir) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must not be 0) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2319 | fs->dirbase = fs->fatbase + fasize; /* Root directory start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2320 | szbfat = (fmt == FS_FAT16) ? /* (Needed FAT size) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2321 | fs->n_fatent * 2 : fs->n_fatent * 3 / 2 + (fs->n_fatent & 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2322 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2323 | if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) /* (BPB_FATSz must not be less than the size needed) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2324 | return FR_NO_FILESYSTEM; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2325 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2326 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2327 | /* Initialize cluster allocation information */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2328 | fs->last_clust = fs->free_clust = 0xFFFFFFFF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2329 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2330 | /* Get fsinfo if available */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2331 | fs->fsi_flag = 0x80; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2332 | #if (_FS_NOFSINFO & 3) != 3 |
JDI_Mbed_Team | 0:33fe30a2b785 | 2333 | if (fmt == FS_FAT32 /* Enable FSINFO only if FAT32 and BPB_FSInfo == 1 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2334 | && LD_WORD(fs->win + BPB_FSInfo) == 1 |
JDI_Mbed_Team | 0:33fe30a2b785 | 2335 | && move_window(fs, bsect + 1) == FR_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2336 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2337 | fs->fsi_flag = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2338 | if (LD_WORD(fs->win + BS_55AA) == 0xAA55 /* Load FSINFO data if available */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2339 | && LD_DWORD(fs->win + FSI_LeadSig) == 0x41615252 |
JDI_Mbed_Team | 0:33fe30a2b785 | 2340 | && LD_DWORD(fs->win + FSI_StrucSig) == 0x61417272) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2341 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2342 | #if (_FS_NOFSINFO & 1) == 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 2343 | fs->free_clust = LD_DWORD(fs->win + FSI_Free_Count); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2344 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2345 | #if (_FS_NOFSINFO & 2) == 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 2346 | fs->last_clust = LD_DWORD(fs->win + FSI_Nxt_Free); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2347 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2348 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2349 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2350 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2351 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2352 | fs->fs_type = fmt; /* FAT sub-type */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2353 | fs->id = ++Fsid; /* File system mount ID */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2354 | #if _FS_RPATH |
JDI_Mbed_Team | 0:33fe30a2b785 | 2355 | fs->cdir = 0; /* Set current directory to root */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2356 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2357 | #if _FS_LOCK /* Clear file lock semaphores */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2358 | clear_lock(fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2359 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2360 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2361 | return FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2362 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2363 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2364 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2365 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2366 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2367 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2368 | /* Check if the file/directory object is valid or not */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2369 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2370 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2371 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 2372 | FRESULT validate ( /* FR_OK(0): The object is valid, !=0: Invalid */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2373 | void* obj /* Pointer to the object FIL/FATFS_DIR to check validity */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2374 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2375 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2376 | FIL *fil = (FIL*)obj; /* Assuming offset of .fs and .id in the FIL/FATFS_DIR structure is identical */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2377 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2378 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2379 | if (!fil || !fil->fs || !fil->fs->fs_type || fil->fs->id != fil->id || (disk_status(fil->fs->drv) & STA_NOINIT)) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2380 | return FR_INVALID_OBJECT; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2381 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2382 | ENTER_FF(fil->fs); /* Lock file system */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2383 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2384 | return FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2385 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2386 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2387 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2388 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2389 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2390 | /*-------------------------------------------------------------------------- |
JDI_Mbed_Team | 0:33fe30a2b785 | 2391 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2392 | Public Functions |
JDI_Mbed_Team | 0:33fe30a2b785 | 2393 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2394 | ---------------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2395 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2396 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2397 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2398 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2399 | /* Mount/Unmount a Logical Drive */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2400 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2401 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2402 | FRESULT f_mount ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 2403 | FATFS* fs, /* Pointer to the file system object (NULL:unmount)*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2404 | const TCHAR* path, /* Logical drive number to be mounted/unmounted */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2405 | BYTE opt /* 0:Do not mount (delayed mount), 1:Mount immediately */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2406 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2407 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2408 | FATFS *cfs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2409 | int vol; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2410 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2411 | const TCHAR *rp = path; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2412 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2413 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2414 | vol = get_ldnumber(&rp); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2415 | if (vol < 0) return FR_INVALID_DRIVE; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2416 | cfs = FatFs[vol]; /* Pointer to fs object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2417 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2418 | if (cfs) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2419 | #if _FS_LOCK |
JDI_Mbed_Team | 0:33fe30a2b785 | 2420 | clear_lock(cfs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2421 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2422 | #if _FS_REENTRANT /* Discard sync object of the current volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2423 | if (!ff_del_syncobj(cfs->sobj)) return FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2424 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2425 | cfs->fs_type = 0; /* Clear old fs object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2426 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2427 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2428 | if (fs) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2429 | fs->fs_type = 0; /* Clear new fs object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2430 | #if _FS_REENTRANT /* Create sync object for the new volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2431 | if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2432 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2433 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2434 | FatFs[vol] = fs; /* Register new fs object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2435 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2436 | if (!fs || opt != 1) return FR_OK; /* Do not mount now, it will be mounted later */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2437 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2438 | res = find_volume(&fs, &path, 0); /* Force mounted the volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2439 | LEAVE_FF(fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2440 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2441 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2442 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2443 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2444 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2445 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2446 | /* Open or Create a File */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2447 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2448 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2449 | FRESULT f_open ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 2450 | FIL* fp, /* Pointer to the blank file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2451 | const TCHAR* path, /* Pointer to the file name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2452 | BYTE mode /* Access mode and file open mode flags */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2453 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2454 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2455 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2456 | FATFS_DIR dj; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2457 | BYTE *dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2458 | DEFINE_NAMEBUF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2459 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2460 | DWORD dw, cl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2461 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2462 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2463 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2464 | if (!fp) return FR_INVALID_OBJECT; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2465 | fp->fs = 0; /* Clear file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2466 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2467 | /* Get logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2468 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2469 | mode &= FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2470 | res = find_volume(&dj.fs, &path, (BYTE)(mode & ~FA_READ)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2471 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2472 | mode &= FA_READ; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2473 | res = find_volume(&dj.fs, &path, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2474 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2475 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2476 | INIT_BUF(dj); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2477 | res = follow_path(&dj, path); /* Follow the file path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2478 | dir = dj.dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2479 | #if !_FS_READONLY /* R/W configuration */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2480 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2481 | if (!dir) /* Default directory itself */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2482 | res = FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2483 | #if _FS_LOCK |
JDI_Mbed_Team | 0:33fe30a2b785 | 2484 | else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2485 | res = chk_lock(&dj, (mode & ~FA_READ) ? 1 : 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2486 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2487 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2488 | /* Create or Open a file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2489 | if (mode & (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW)) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2490 | if (res != FR_OK) { /* No file, create new */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2491 | if (res == FR_NO_FILE) /* There is no file to open, create a new entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2492 | #if _FS_LOCK |
JDI_Mbed_Team | 0:33fe30a2b785 | 2493 | res = enq_lock() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2494 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2495 | res = dir_register(&dj); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2496 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2497 | mode |= FA_CREATE_ALWAYS; /* File is created */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2498 | dir = dj.dir; /* New entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2499 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2500 | else { /* Any object is already existing */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2501 | if (dir[DIR_Attr] & (AM_RDO | AM_DIR)) { /* Cannot overwrite it (R/O or FATFS_DIR) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2502 | res = FR_DENIED; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2503 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2504 | if (mode & FA_CREATE_NEW) /* Cannot create as new file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2505 | res = FR_EXIST; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2506 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2507 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2508 | if (res == FR_OK && (mode & FA_CREATE_ALWAYS)) { /* Truncate it if overwrite mode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2509 | dw = GET_FATTIME(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2510 | ST_DWORD(dir + DIR_CrtTime, dw);/* Set created time */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2511 | ST_DWORD(dir + DIR_WrtTime, dw);/* Set modified time */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2512 | dir[DIR_Attr] = 0; /* Reset attribute */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2513 | ST_DWORD(dir + DIR_FileSize, 0);/* Reset file size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2514 | cl = ld_clust(dj.fs, dir); /* Get cluster chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2515 | st_clust(dir, 0); /* Reset cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2516 | dj.fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2517 | if (cl) { /* Remove the cluster chain if exist */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2518 | dw = dj.fs->winsect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2519 | res = remove_chain(dj.fs, cl); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2520 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2521 | dj.fs->last_clust = cl - 1; /* Reuse the cluster hole */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2522 | res = move_window(dj.fs, dw); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2523 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2524 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2525 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2526 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2527 | else { /* Open an existing file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2528 | if (res == FR_OK) { /* Following succeeded */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2529 | if (dir[DIR_Attr] & AM_DIR) { /* It is a directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2530 | res = FR_NO_FILE; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2531 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2532 | if ((mode & FA_WRITE) && (dir[DIR_Attr] & AM_RDO)) /* R/O violation */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2533 | res = FR_DENIED; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2534 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2535 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2536 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2537 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2538 | if (mode & FA_CREATE_ALWAYS) /* Set file change flag if created or overwritten */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2539 | mode |= FA__WRITTEN; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2540 | fp->dir_sect = dj.fs->winsect; /* Pointer to the directory entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2541 | fp->dir_ptr = dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2542 | #if _FS_LOCK |
JDI_Mbed_Team | 0:33fe30a2b785 | 2543 | fp->lockid = inc_lock(&dj, (mode & ~FA_READ) ? 1 : 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2544 | if (!fp->lockid) res = FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2545 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2546 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2547 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2548 | #else /* R/O configuration */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2549 | if (res == FR_OK) { /* Follow succeeded */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2550 | dir = dj.dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2551 | if (!dir) { /* Current directory itself */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2552 | res = FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2553 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2554 | if (dir[DIR_Attr] & AM_DIR) /* It is a directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2555 | res = FR_NO_FILE; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2556 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2557 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2558 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2559 | FREE_BUF(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2560 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2561 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2562 | fp->flag = mode; /* File access mode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2563 | fp->err = 0; /* Clear error flag */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2564 | fp->sclust = ld_clust(dj.fs, dir); /* File start cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2565 | fp->fsize = LD_DWORD(dir + DIR_FileSize); /* File size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2566 | fp->fptr = 0; /* File pointer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2567 | fp->dsect = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2568 | #if _USE_FASTSEEK |
JDI_Mbed_Team | 0:33fe30a2b785 | 2569 | fp->cltbl = 0; /* Normal seek mode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2570 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2571 | fp->fs = dj.fs; /* Validate file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2572 | fp->id = fp->fs->id; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2573 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2574 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2575 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2576 | LEAVE_FF(dj.fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2577 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2578 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2579 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2580 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2581 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2582 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2583 | /* Read File */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2584 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2585 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2586 | FRESULT f_read ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 2587 | FIL* fp, /* Pointer to the file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2588 | void* buff, /* Pointer to data buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2589 | UINT btr, /* Number of bytes to read */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2590 | UINT* br /* Pointer to number of bytes read */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2591 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2592 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2593 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2594 | DWORD clst, sect, remain; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2595 | UINT rcnt, cc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2596 | BYTE csect, *rbuff = (BYTE*)buff; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2597 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2598 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2599 | *br = 0; /* Clear read byte counter */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2600 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2601 | res = validate(fp); /* Check validity */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2602 | if (res != FR_OK) LEAVE_FF(fp->fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2603 | if (fp->err) /* Check error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2604 | LEAVE_FF(fp->fs, (FRESULT)fp->err); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2605 | if (!(fp->flag & FA_READ)) /* Check access mode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2606 | LEAVE_FF(fp->fs, FR_DENIED); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2607 | remain = fp->fsize - fp->fptr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2608 | if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2609 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2610 | for ( ; btr; /* Repeat until all data read */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2611 | rbuff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2612 | if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2613 | csect = (BYTE)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2614 | if (!csect) { /* On the cluster boundary? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2615 | if (fp->fptr == 0) { /* On the top of the file? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2616 | clst = fp->sclust; /* Follow from the origin */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2617 | } else { /* Middle or end of the file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2618 | #if _USE_FASTSEEK |
JDI_Mbed_Team | 0:33fe30a2b785 | 2619 | if (fp->cltbl) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2620 | clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2621 | else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2622 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2623 | clst = get_fat(fp->fs, fp->clust); /* Follow cluster chain on the FAT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2624 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2625 | if (clst < 2) ABORT(fp->fs, FR_INT_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2626 | if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2627 | fp->clust = clst; /* Update current cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2628 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2629 | sect = clust2sect(fp->fs, fp->clust); /* Get current sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2630 | if (!sect) ABORT(fp->fs, FR_INT_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2631 | sect += csect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2632 | cc = btr / SS(fp->fs); /* When remaining bytes >= sector size, */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2633 | if (cc) { /* Read maximum contiguous sectors directly */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2634 | if (csect + cc > fp->fs->csize) /* Clip at cluster boundary */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2635 | cc = fp->fs->csize - csect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2636 | if (disk_read(fp->fs->drv, rbuff, sect, cc) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2637 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2638 | #if !_FS_READONLY && _FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2639 | #if _FS_TINY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2640 | if (fp->fs->wflag && fp->fs->winsect - sect < cc) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2641 | mem_cpy(rbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), fp->fs->win, SS(fp->fs)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2642 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2643 | if ((fp->flag & FA__DIRTY) && fp->dsect - sect < cc) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2644 | mem_cpy(rbuff + ((fp->dsect - sect) * SS(fp->fs)), fp->buf, SS(fp->fs)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2645 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2646 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2647 | rcnt = SS(fp->fs) * cc; /* Number of bytes transferred */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2648 | continue; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2649 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2650 | #if !_FS_TINY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2651 | if (fp->dsect != sect) { /* Load data sector if not in cache */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2652 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2653 | if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2654 | if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2655 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2656 | fp->flag &= ~FA__DIRTY; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2657 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2658 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2659 | if (disk_read(fp->fs->drv, fp->buf, sect, 1) != RES_OK) /* Fill sector cache */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2660 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2661 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2662 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2663 | fp->dsect = sect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2664 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2665 | rcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs)); /* Get partial sector data from sector buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2666 | if (rcnt > btr) rcnt = btr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2667 | #if _FS_TINY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2668 | if (move_window(fp->fs, fp->dsect) != FR_OK) /* Move sector window */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2669 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2670 | mem_cpy(rbuff, &fp->fs->win[fp->fptr % SS(fp->fs)], rcnt); /* Pick partial sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2671 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2672 | mem_cpy(rbuff, &fp->buf[fp->fptr % SS(fp->fs)], rcnt); /* Pick partial sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2673 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2674 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2675 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2676 | LEAVE_FF(fp->fs, FR_OK); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2677 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2678 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2679 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2680 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2681 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2682 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2683 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2684 | /* Write File */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2685 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2686 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2687 | FRESULT f_write ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 2688 | FIL* fp, /* Pointer to the file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2689 | const void *buff, /* Pointer to the data to be written */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2690 | UINT btw, /* Number of bytes to write */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2691 | UINT* bw /* Pointer to number of bytes written */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2692 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2693 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2694 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2695 | DWORD clst, sect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2696 | UINT wcnt, cc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2697 | const BYTE *wbuff = (const BYTE*)buff; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2698 | BYTE csect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2699 | bool need_sync = false; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2700 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2701 | *bw = 0; /* Clear write byte counter */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2702 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2703 | res = validate(fp); /* Check validity */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2704 | if (res != FR_OK) LEAVE_FF(fp->fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2705 | if (fp->err) /* Check error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2706 | LEAVE_FF(fp->fs, (FRESULT)fp->err); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2707 | if (!(fp->flag & FA_WRITE)) /* Check access mode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2708 | LEAVE_FF(fp->fs, FR_DENIED); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2709 | if (fp->fptr + btw < fp->fptr) btw = 0; /* File size cannot reach 4GB */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2710 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2711 | for ( ; btw; /* Repeat until all data written */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2712 | wbuff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2713 | if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2714 | csect = (BYTE)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2715 | if (!csect) { /* On the cluster boundary? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2716 | if (fp->fptr == 0) { /* On the top of the file? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2717 | clst = fp->sclust; /* Follow from the origin */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2718 | if (clst == 0) /* When no cluster is allocated, */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2719 | clst = create_chain(fp->fs, 0); /* Create a new cluster chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2720 | } else { /* Middle or end of the file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2721 | #if _USE_FASTSEEK |
JDI_Mbed_Team | 0:33fe30a2b785 | 2722 | if (fp->cltbl) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2723 | clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2724 | else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2725 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2726 | clst = create_chain(fp->fs, fp->clust); /* Follow or stretch cluster chain on the FAT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2727 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2728 | if (clst == 0) break; /* Could not allocate a new cluster (disk full) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2729 | if (clst == 1) ABORT(fp->fs, FR_INT_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2730 | if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2731 | fp->clust = clst; /* Update current cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2732 | if (fp->sclust == 0) fp->sclust = clst; /* Set start cluster if the first write */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2733 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2734 | #if FLUSH_ON_NEW_CLUSTER |
JDI_Mbed_Team | 0:33fe30a2b785 | 2735 | // We do not need to flush for the first cluster |
JDI_Mbed_Team | 0:33fe30a2b785 | 2736 | if (fp->fptr != 0) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2737 | need_sync = true; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2738 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2739 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2740 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2741 | #if _FS_TINY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2742 | if (fp->fs->winsect == fp->dsect && sync_window(fp->fs)) /* Write-back sector cache */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2743 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2744 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2745 | if (fp->flag & FA__DIRTY) { /* Write-back sector cache */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2746 | if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2747 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2748 | fp->flag &= ~FA__DIRTY; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2749 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2750 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2751 | sect = clust2sect(fp->fs, fp->clust); /* Get current sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2752 | if (!sect) ABORT(fp->fs, FR_INT_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2753 | sect += csect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2754 | cc = btw / SS(fp->fs); /* When remaining bytes >= sector size, */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2755 | if (cc) { /* Write maximum contiguous sectors directly */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2756 | if (csect + cc > fp->fs->csize) /* Clip at cluster boundary */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2757 | cc = fp->fs->csize - csect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2758 | if (disk_write(fp->fs->drv, wbuff, sect, cc) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2759 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2760 | #if _FS_MINIMIZE <= 2 |
JDI_Mbed_Team | 0:33fe30a2b785 | 2761 | #if _FS_TINY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2762 | if (fp->fs->winsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2763 | mem_cpy(fp->fs->win, wbuff + ((fp->fs->winsect - sect) * SS(fp->fs)), SS(fp->fs)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2764 | fp->fs->wflag = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2765 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2766 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2767 | if (fp->dsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2768 | mem_cpy(fp->buf, wbuff + ((fp->dsect - sect) * SS(fp->fs)), SS(fp->fs)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2769 | fp->flag &= ~FA__DIRTY; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2770 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2771 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2772 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2773 | wcnt = SS(fp->fs) * cc; /* Number of bytes transferred */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2774 | #if FLUSH_ON_NEW_SECTOR |
JDI_Mbed_Team | 0:33fe30a2b785 | 2775 | need_sync = true; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2776 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2777 | continue; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2778 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2779 | #if _FS_TINY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2780 | if (fp->fptr >= fp->fsize) { /* Avoid silly cache filling at growing edge */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2781 | if (sync_window(fp->fs)) ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2782 | fp->fs->winsect = sect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2783 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2784 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2785 | if (fp->dsect != sect) { /* Fill sector cache with file data */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2786 | if (fp->fptr < fp->fsize && |
JDI_Mbed_Team | 0:33fe30a2b785 | 2787 | disk_read(fp->fs->drv, fp->buf, sect, 1) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2788 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2789 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2790 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2791 | fp->dsect = sect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2792 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2793 | wcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));/* Put partial sector into file I/O buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2794 | if (wcnt > btw) wcnt = btw; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2795 | #if _FS_TINY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2796 | if (move_window(fp->fs, fp->dsect) != FR_OK) /* Move sector window */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2797 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2798 | mem_cpy(&fp->fs->win[fp->fptr % SS(fp->fs)], wbuff, wcnt); /* Fit partial sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2799 | fp->fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2800 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2801 | mem_cpy(&fp->buf[fp->fptr % SS(fp->fs)], wbuff, wcnt); /* Fit partial sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2802 | fp->flag |= FA__DIRTY; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2803 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2804 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2805 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2806 | if (fp->fptr > fp->fsize) fp->fsize = fp->fptr; /* Update file size if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2807 | fp->flag |= FA__WRITTEN; /* Set file change flag */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2808 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2809 | if (need_sync) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2810 | f_sync (fp); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2811 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2812 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2813 | LEAVE_FF(fp->fs, FR_OK); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2814 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2815 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2816 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2817 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2818 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2819 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2820 | /* Synchronize the File */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2821 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2822 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2823 | FRESULT f_sync ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 2824 | FIL* fp /* Pointer to the file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2825 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2826 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2827 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2828 | DWORD tm; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2829 | BYTE *dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2830 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2831 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2832 | res = validate(fp); /* Check validity of the object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2833 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2834 | if (fp->flag & FA__WRITTEN) { /* Is there any change to the file? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2835 | #if !_FS_TINY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2836 | if (fp->flag & FA__DIRTY) { /* Write-back cached data if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2837 | if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2838 | LEAVE_FF(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2839 | fp->flag &= ~FA__DIRTY; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2840 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2841 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2842 | /* Update the directory entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2843 | res = move_window(fp->fs, fp->dir_sect); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2844 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2845 | dir = fp->dir_ptr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2846 | dir[DIR_Attr] |= AM_ARC; /* Set archive bit */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2847 | ST_DWORD(dir + DIR_FileSize, fp->fsize); /* Update file size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2848 | st_clust(dir, fp->sclust); /* Update start cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2849 | tm = GET_FATTIME(); /* Update modified time */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2850 | ST_DWORD(dir + DIR_WrtTime, tm); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2851 | ST_WORD(dir + DIR_LstAccDate, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2852 | fp->flag &= ~FA__WRITTEN; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2853 | fp->fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2854 | res = sync_fs(fp->fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2855 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2856 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2857 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2858 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2859 | LEAVE_FF(fp->fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2860 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2861 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2862 | #endif /* !_FS_READONLY */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2863 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2864 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2865 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2866 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2867 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2868 | /* Close File */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2869 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2870 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2871 | FRESULT f_close ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 2872 | FIL *fp /* Pointer to the file object to be closed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2873 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2874 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2875 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2876 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2877 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2878 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 2879 | res = f_sync(fp); /* Flush cached data */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2880 | if (res == FR_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2881 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2882 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2883 | res = validate(fp); /* Lock volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2884 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2885 | #if _FS_REENTRANT |
JDI_Mbed_Team | 0:33fe30a2b785 | 2886 | FATFS *fs = fp->fs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2887 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2888 | #if _FS_LOCK |
JDI_Mbed_Team | 0:33fe30a2b785 | 2889 | res = dec_lock(fp->lockid); /* Decrement file open counter */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2890 | if (res == FR_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2891 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2892 | fp->fs = 0; /* Invalidate file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2893 | #if _FS_REENTRANT |
JDI_Mbed_Team | 0:33fe30a2b785 | 2894 | unlock_fs(fs, FR_OK); /* Unlock volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2895 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2896 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2897 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2898 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2899 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2900 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2901 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2902 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2903 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2904 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2905 | /* Change Current Directory or Current Drive, Get Current Directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2906 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2907 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2908 | #if _FS_RPATH >= 1 |
JDI_Mbed_Team | 0:33fe30a2b785 | 2909 | #if _VOLUMES >= 2 |
JDI_Mbed_Team | 0:33fe30a2b785 | 2910 | FRESULT f_chdrive ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 2911 | const TCHAR* path /* Drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2912 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2913 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2914 | int vol; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2915 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2916 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2917 | vol = get_ldnumber(&path); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2918 | if (vol < 0) return FR_INVALID_DRIVE; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2919 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2920 | CurrVol = (BYTE)vol; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2921 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2922 | return FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2923 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2924 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 2925 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2926 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2927 | FRESULT f_chdir ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 2928 | const TCHAR* path /* Pointer to the directory path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2929 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2930 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2931 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2932 | FATFS_DIR dj; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2933 | DEFINE_NAMEBUF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2934 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2935 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2936 | /* Get logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2937 | res = find_volume(&dj.fs, &path, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2938 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2939 | INIT_BUF(dj); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2940 | res = follow_path(&dj, path); /* Follow the path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2941 | FREE_BUF(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2942 | if (res == FR_OK) { /* Follow completed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2943 | if (!dj.dir) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2944 | dj.fs->cdir = dj.sclust; /* Start directory itself */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2945 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2946 | if (dj.dir[DIR_Attr] & AM_DIR) /* Reached to the directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2947 | dj.fs->cdir = ld_clust(dj.fs, dj.dir); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2948 | else |
JDI_Mbed_Team | 0:33fe30a2b785 | 2949 | res = FR_NO_PATH; /* Reached but a file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2950 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2951 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2952 | if (res == FR_NO_FILE) res = FR_NO_PATH; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2953 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2954 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2955 | LEAVE_FF(dj.fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2956 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 2957 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2958 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2959 | #if _FS_RPATH >= 2 |
JDI_Mbed_Team | 0:33fe30a2b785 | 2960 | FRESULT f_getcwd ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 2961 | TCHAR* buff, /* Pointer to the directory path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2962 | UINT len /* Size of path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2963 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 2964 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2965 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2966 | FATFS_DIR dj; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2967 | UINT i, n; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2968 | DWORD ccl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2969 | TCHAR *tp; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2970 | FILINFO fno; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2971 | DEFINE_NAMEBUF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2972 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2973 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 2974 | *buff = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2975 | /* Get logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2976 | res = find_volume(&dj.fs, (const TCHAR**)&buff, 0); /* Get current volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2977 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 2978 | INIT_BUF(dj); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2979 | i = len; /* Bottom of buffer (directory stack base) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2980 | dj.sclust = dj.fs->cdir; /* Start to follow upper directory from current directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2981 | while ((ccl = dj.sclust) != 0) { /* Repeat while current directory is a sub-directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2982 | res = dir_sdi(&dj, 1); /* Get parent directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2983 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2984 | res = dir_read(&dj, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2985 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2986 | dj.sclust = ld_clust(dj.fs, dj.dir); /* Goto parent directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2987 | res = dir_sdi(&dj, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2988 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2989 | do { /* Find the entry links to the child directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2990 | res = dir_read(&dj, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2991 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2992 | if (ccl == ld_clust(dj.fs, dj.dir)) break; /* Found the entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2993 | res = dir_next(&dj, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2994 | } while (res == FR_OK); |
JDI_Mbed_Team | 0:33fe30a2b785 | 2995 | if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 2996 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2997 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 2998 | fno.lfname = buff; |
JDI_Mbed_Team | 0:33fe30a2b785 | 2999 | fno.lfsize = i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3000 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3001 | get_fileinfo(&dj, &fno); /* Get the directory name and push it to the buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3002 | tp = fno.fname; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3003 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 3004 | if (*buff) tp = buff; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3005 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3006 | for (n = 0; tp[n]; n++) ; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3007 | if (i < n + 3) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3008 | res = FR_NOT_ENOUGH_CORE; break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3009 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3010 | while (n) buff[--i] = tp[--n]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3011 | buff[--i] = '/'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3012 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3013 | tp = buff; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3014 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3015 | #if _VOLUMES >= 2 |
JDI_Mbed_Team | 0:33fe30a2b785 | 3016 | *tp++ = '0' + CurrVol; /* Put drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3017 | *tp++ = ':'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3018 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3019 | if (i == len) { /* Root-directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3020 | *tp++ = '/'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3021 | } else { /* Sub-directroy */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3022 | do /* Add stacked path str */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3023 | *tp++ = buff[i++]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3024 | while (i < len); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3025 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3026 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3027 | *tp = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3028 | FREE_BUF(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3029 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3030 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3031 | LEAVE_FF(dj.fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3032 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3033 | #endif /* _FS_RPATH >= 2 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3034 | #endif /* _FS_RPATH >= 1 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3035 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3036 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3037 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3038 | #if _FS_MINIMIZE <= 2 |
JDI_Mbed_Team | 0:33fe30a2b785 | 3039 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3040 | /* Seek File R/W Pointer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3041 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3042 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3043 | FRESULT f_lseek ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3044 | FIL* fp, /* Pointer to the file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3045 | DWORD ofs /* File pointer from top of file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3046 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3047 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3048 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3049 | DWORD clst, bcs, nsect, ifptr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3050 | #if _USE_FASTSEEK |
JDI_Mbed_Team | 0:33fe30a2b785 | 3051 | DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3052 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3053 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3054 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3055 | res = validate(fp); /* Check validity of the object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3056 | if (res != FR_OK) LEAVE_FF(fp->fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3057 | if (fp->err) /* Check error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3058 | LEAVE_FF(fp->fs, (FRESULT)fp->err); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3059 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3060 | #if _USE_FASTSEEK |
JDI_Mbed_Team | 0:33fe30a2b785 | 3061 | if (fp->cltbl) { /* Fast seek */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3062 | if (ofs == CREATE_LINKMAP) { /* Create CLMT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3063 | tbl = fp->cltbl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3064 | tlen = *tbl++; ulen = 2; /* Given table size and required table size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3065 | cl = fp->sclust; /* Top of the chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3066 | if (cl) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3067 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3068 | /* Get a fragment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3069 | tcl = cl; ncl = 0; ulen += 2; /* Top, length and used items */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3070 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3071 | pcl = cl; ncl++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3072 | cl = get_fat(fp->fs, cl); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3073 | if (cl <= 1) ABORT(fp->fs, FR_INT_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3074 | if (cl == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3075 | } while (cl == pcl + 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3076 | if (ulen <= tlen) { /* Store the length and top of the fragment */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3077 | *tbl++ = ncl; *tbl++ = tcl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3078 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3079 | } while (cl < fp->fs->n_fatent); /* Repeat until end of chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3080 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3081 | *fp->cltbl = ulen; /* Number of items used */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3082 | if (ulen <= tlen) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3083 | *tbl = 0; /* Terminate table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3084 | else |
JDI_Mbed_Team | 0:33fe30a2b785 | 3085 | res = FR_NOT_ENOUGH_CORE; /* Given table size is smaller than required */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3086 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3087 | } else { /* Fast seek */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3088 | if (ofs > fp->fsize) /* Clip offset at the file size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3089 | ofs = fp->fsize; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3090 | fp->fptr = ofs; /* Set file pointer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3091 | if (ofs) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3092 | fp->clust = clmt_clust(fp, ofs - 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3093 | dsc = clust2sect(fp->fs, fp->clust); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3094 | if (!dsc) ABORT(fp->fs, FR_INT_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3095 | dsc += (ofs - 1) / SS(fp->fs) & (fp->fs->csize - 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3096 | if (fp->fptr % SS(fp->fs) && dsc != fp->dsect) { /* Refill sector cache if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3097 | #if !_FS_TINY |
JDI_Mbed_Team | 0:33fe30a2b785 | 3098 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 3099 | if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3100 | if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3101 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3102 | fp->flag &= ~FA__DIRTY; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3103 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3104 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3105 | if (disk_read(fp->fs->drv, fp->buf, dsc, 1) != RES_OK) /* Load current sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3106 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3107 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3108 | fp->dsect = dsc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3109 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3110 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3111 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3112 | } else |
JDI_Mbed_Team | 0:33fe30a2b785 | 3113 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3114 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3115 | /* Normal Seek */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3116 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3117 | if (ofs > fp->fsize /* In read-only mode, clip offset with the file size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3118 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 3119 | && !(fp->flag & FA_WRITE) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3120 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3121 | ) ofs = fp->fsize; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3122 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3123 | ifptr = fp->fptr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3124 | fp->fptr = nsect = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3125 | if (ofs) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3126 | bcs = (DWORD)fp->fs->csize * SS(fp->fs); /* Cluster size (byte) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3127 | if (ifptr > 0 && |
JDI_Mbed_Team | 0:33fe30a2b785 | 3128 | (ofs - 1) / bcs >= (ifptr - 1) / bcs) { /* When seek to same or following cluster, */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3129 | fp->fptr = (ifptr - 1) & ~(bcs - 1); /* start from the current cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3130 | ofs -= fp->fptr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3131 | clst = fp->clust; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3132 | } else { /* When seek to back cluster, */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3133 | clst = fp->sclust; /* start from the first cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3134 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 3135 | if (clst == 0) { /* If no cluster chain, create a new chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3136 | clst = create_chain(fp->fs, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3137 | if (clst == 1) ABORT(fp->fs, FR_INT_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3138 | if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3139 | fp->sclust = clst; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3140 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3141 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3142 | fp->clust = clst; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3143 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3144 | if (clst != 0) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3145 | while (ofs > bcs) { /* Cluster following loop */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3146 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 3147 | if (fp->flag & FA_WRITE) { /* Check if in write mode or not */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3148 | clst = create_chain(fp->fs, clst); /* Force stretch if in write mode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3149 | if (clst == 0) { /* When disk gets full, clip file size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3150 | ofs = bcs; break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3151 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3152 | } else |
JDI_Mbed_Team | 0:33fe30a2b785 | 3153 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3154 | clst = get_fat(fp->fs, clst); /* Follow cluster chain if not in write mode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3155 | if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3156 | if (clst <= 1 || clst >= fp->fs->n_fatent) ABORT(fp->fs, FR_INT_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3157 | fp->clust = clst; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3158 | fp->fptr += bcs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3159 | ofs -= bcs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3160 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3161 | fp->fptr += ofs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3162 | if (ofs % SS(fp->fs)) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3163 | nsect = clust2sect(fp->fs, clst); /* Current sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3164 | if (!nsect) ABORT(fp->fs, FR_INT_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3165 | nsect += ofs / SS(fp->fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3166 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3167 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3168 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3169 | if (fp->fptr % SS(fp->fs) && nsect != fp->dsect) { /* Fill sector cache if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3170 | #if !_FS_TINY |
JDI_Mbed_Team | 0:33fe30a2b785 | 3171 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 3172 | if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3173 | if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3174 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3175 | fp->flag &= ~FA__DIRTY; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3176 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3177 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3178 | if (disk_read(fp->fs->drv, fp->buf, nsect, 1) != RES_OK) /* Fill sector cache */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3179 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3180 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3181 | fp->dsect = nsect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3182 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3183 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 3184 | if (fp->fptr > fp->fsize) { /* Set file change flag if the file size is extended */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3185 | fp->fsize = fp->fptr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3186 | fp->flag |= FA__WRITTEN; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3187 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3188 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3189 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3190 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3191 | LEAVE_FF(fp->fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3192 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3193 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3194 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3195 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3196 | #if _FS_MINIMIZE <= 1 |
JDI_Mbed_Team | 0:33fe30a2b785 | 3197 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3198 | /* Create a Directory Object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3199 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3200 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3201 | FRESULT f_opendir ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3202 | FATFS_DIR* dp, /* Pointer to directory object to create */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3203 | const TCHAR* path /* Pointer to the directory path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3204 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3205 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3206 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3207 | FATFS* fs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3208 | DEFINE_NAMEBUF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3209 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3210 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3211 | if (!dp) return FR_INVALID_OBJECT; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3212 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3213 | /* Get logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3214 | res = find_volume(&fs, &path, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3215 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3216 | dp->fs = fs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3217 | INIT_BUF(*dp); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3218 | res = follow_path(dp, path); /* Follow the path to the directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3219 | FREE_BUF(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3220 | if (res == FR_OK) { /* Follow completed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3221 | if (dp->dir) { /* It is not the origin directory itself */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3222 | if (dp->dir[DIR_Attr] & AM_DIR) /* The object is a sub directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3223 | dp->sclust = ld_clust(fs, dp->dir); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3224 | else /* The object is a file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3225 | res = FR_NO_PATH; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3226 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3227 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3228 | dp->id = fs->id; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3229 | res = dir_sdi(dp, 0); /* Rewind directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3230 | #if _FS_LOCK |
JDI_Mbed_Team | 0:33fe30a2b785 | 3231 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3232 | if (dp->sclust) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3233 | dp->lockid = inc_lock(dp, 0); /* Lock the sub directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3234 | if (!dp->lockid) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3235 | res = FR_TOO_MANY_OPEN_FILES; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3236 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3237 | dp->lockid = 0; /* Root directory need not to be locked */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3238 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3239 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3240 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3241 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3242 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3243 | if (res == FR_NO_FILE) res = FR_NO_PATH; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3244 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3245 | if (res != FR_OK) dp->fs = 0; /* Invalidate the directory object if function faild */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3246 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3247 | LEAVE_FF(fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3248 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3249 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3250 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3251 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3252 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3253 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3254 | /* Close Directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3255 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3256 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3257 | FRESULT f_closedir ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3258 | FATFS_DIR *dp /* Pointer to the directory object to be closed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3259 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3260 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3261 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3262 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3263 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3264 | res = validate(dp); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3265 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3266 | #if _FS_REENTRANT |
JDI_Mbed_Team | 0:33fe30a2b785 | 3267 | FATFS *fs = dp->fs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3268 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3269 | #if _FS_LOCK |
JDI_Mbed_Team | 0:33fe30a2b785 | 3270 | if (dp->lockid) /* Decrement sub-directory open counter */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3271 | res = dec_lock(dp->lockid); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3272 | if (res == FR_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3273 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3274 | dp->fs = 0; /* Invalidate directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3275 | #if _FS_REENTRANT |
JDI_Mbed_Team | 0:33fe30a2b785 | 3276 | unlock_fs(fs, FR_OK); /* Unlock volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3277 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3278 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3279 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3280 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3281 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3282 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3283 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3284 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3285 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3286 | /* Read Directory Entries in Sequence */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3287 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3288 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3289 | FRESULT f_readdir ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3290 | FATFS_DIR* dp, /* Pointer to the open directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3291 | FILINFO* fno /* Pointer to file information to return */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3292 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3293 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3294 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3295 | DEFINE_NAMEBUF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3296 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3297 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3298 | res = validate(dp); /* Check validity of the object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3299 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3300 | if (!fno) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3301 | res = dir_sdi(dp, 0); /* Rewind the directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3302 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3303 | INIT_BUF(*dp); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3304 | res = dir_read(dp, 0); /* Read an item */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3305 | if (res == FR_NO_FILE) { /* Reached end of directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3306 | dp->sect = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3307 | res = FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3308 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3309 | if (res == FR_OK) { /* A valid entry is found */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3310 | get_fileinfo(dp, fno); /* Get the object information */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3311 | res = dir_next(dp, 0); /* Increment index for next */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3312 | if (res == FR_NO_FILE) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3313 | dp->sect = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3314 | res = FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3315 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3316 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3317 | FREE_BUF(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3318 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3319 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3320 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3321 | LEAVE_FF(dp->fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3322 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3323 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3324 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3325 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3326 | #if _USE_FIND |
JDI_Mbed_Team | 0:33fe30a2b785 | 3327 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3328 | /* Find next file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3329 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3330 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3331 | FRESULT f_findnext ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3332 | FATFS_DIR* dp, /* Pointer to the open directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3333 | FILINFO* fno /* Pointer to the file information structure */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3334 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3335 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3336 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3337 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3338 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3339 | for (;;) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3340 | res = f_readdir(dp, fno); /* Get a directory item */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3341 | if (res != FR_OK || !fno || !fno->fname[0]) break; /* Terminate if any error or end of directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3342 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 3343 | if (fno->lfname && pattern_matching(dp->pat, fno->lfname, 0, 0)) break; /* Test for LFN if exist */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3344 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3345 | if (pattern_matching(dp->pat, fno->fname, 0, 0)) break; /* Test for SFN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3346 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3347 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3348 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3349 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3350 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3351 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3352 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3353 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3354 | /* Find first file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3355 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3356 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3357 | FRESULT f_findfirst ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3358 | FATFS_DIR* dp, /* Pointer to the blank directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3359 | FILINFO* fno, /* Pointer to the file information structure */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3360 | const TCHAR* path, /* Pointer to the directory to open */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3361 | const TCHAR* pattern /* Pointer to the matching pattern */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3362 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3363 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3364 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3365 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3366 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3367 | dp->pat = pattern; /* Save pointer to pattern string */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3368 | res = f_opendir(dp, path); /* Open the target directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3369 | if (res == FR_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3370 | res = f_findnext(dp, fno); /* Find the first item */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3371 | return res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3372 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3373 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3374 | #endif /* _USE_FIND */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3375 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3376 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3377 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3378 | #if _FS_MINIMIZE == 0 |
JDI_Mbed_Team | 0:33fe30a2b785 | 3379 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3380 | /* Get File Status */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3381 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3382 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3383 | FRESULT f_stat ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3384 | const TCHAR* path, /* Pointer to the file path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3385 | FILINFO* fno /* Pointer to file information to return */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3386 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3387 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3388 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3389 | FATFS_DIR dj; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3390 | DEFINE_NAMEBUF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3391 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3392 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3393 | /* Get logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3394 | res = find_volume(&dj.fs, &path, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3395 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3396 | INIT_BUF(dj); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3397 | res = follow_path(&dj, path); /* Follow the file path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3398 | if (res == FR_OK) { /* Follow completed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3399 | if (dj.dir) { /* Found an object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3400 | if (fno) get_fileinfo(&dj, fno); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3401 | } else { /* It is root directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3402 | res = FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3403 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3404 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3405 | FREE_BUF(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3406 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3407 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3408 | LEAVE_FF(dj.fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3409 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3410 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3411 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3412 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3413 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 3414 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3415 | /* Get Number of Free Clusters */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3416 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3417 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3418 | FRESULT f_getfree ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3419 | const TCHAR* path, /* Path name of the logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3420 | DWORD* nclst, /* Pointer to a variable to return number of free clusters */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3421 | FATFS** fatfs /* Pointer to return pointer to corresponding file system object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3422 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3423 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3424 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3425 | FATFS *fs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3426 | DWORD nfree, clst, sect, stat; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3427 | UINT i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3428 | BYTE fat, *p; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3429 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3430 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3431 | /* Get logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3432 | res = find_volume(fatfs, &path, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3433 | fs = *fatfs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3434 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3435 | /* If free_clust is valid, return it without full cluster scan */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3436 | if (fs->free_clust <= fs->n_fatent - 2) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3437 | *nclst = fs->free_clust; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3438 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3439 | /* Get number of free clusters */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3440 | fat = fs->fs_type; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3441 | nfree = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3442 | if (fat == FS_FAT12) { /* Sector unalighed entries: Search FAT via regular routine. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3443 | clst = 2; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3444 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3445 | stat = get_fat(fs, clst); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3446 | if (stat == 0xFFFFFFFF) { res = FR_DISK_ERR; break; } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3447 | if (stat == 1) { res = FR_INT_ERR; break; } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3448 | if (stat == 0) nfree++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3449 | } while (++clst < fs->n_fatent); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3450 | } else { /* Sector alighed entries: Accelerate the FAT search. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3451 | clst = fs->n_fatent; sect = fs->fatbase; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3452 | i = 0; p = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3453 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3454 | if (!i) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3455 | res = move_window(fs, sect++); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3456 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3457 | p = fs->win; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3458 | i = SS(fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3459 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3460 | if (fat == FS_FAT16) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3461 | if (LD_WORD(p) == 0) nfree++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3462 | p += 2; i -= 2; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3463 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3464 | if ((LD_DWORD(p) & 0x0FFFFFFF) == 0) nfree++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3465 | p += 4; i -= 4; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3466 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3467 | } while (--clst); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3468 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3469 | fs->free_clust = nfree; /* free_clust is valid */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3470 | fs->fsi_flag |= 1; /* FSInfo is to be updated */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3471 | *nclst = nfree; /* Return the free clusters */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3472 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3473 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3474 | LEAVE_FF(fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3475 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3476 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3477 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3478 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3479 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3480 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3481 | /* Truncate File */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3482 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3483 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3484 | FRESULT f_truncate ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3485 | FIL* fp /* Pointer to the file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3486 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3487 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3488 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3489 | DWORD ncl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3490 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3491 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3492 | res = validate(fp); /* Check validity of the object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3493 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3494 | if (fp->err) { /* Check error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3495 | res = (FRESULT)fp->err; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3496 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3497 | if (!(fp->flag & FA_WRITE)) /* Check access mode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3498 | res = FR_DENIED; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3499 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3500 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3501 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3502 | if (fp->fsize > fp->fptr) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3503 | fp->fsize = fp->fptr; /* Set file size to current R/W point */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3504 | fp->flag |= FA__WRITTEN; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3505 | if (fp->fptr == 0) { /* When set file size to zero, remove entire cluster chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3506 | res = remove_chain(fp->fs, fp->sclust); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3507 | fp->sclust = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3508 | } else { /* When truncate a part of the file, remove remaining clusters */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3509 | ncl = get_fat(fp->fs, fp->clust); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3510 | res = FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3511 | if (ncl == 0xFFFFFFFF) res = FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3512 | if (ncl == 1) res = FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3513 | if (res == FR_OK && ncl < fp->fs->n_fatent) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3514 | res = put_fat(fp->fs, fp->clust, 0x0FFFFFFF); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3515 | if (res == FR_OK) res = remove_chain(fp->fs, ncl); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3516 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3517 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3518 | #if !_FS_TINY |
JDI_Mbed_Team | 0:33fe30a2b785 | 3519 | if (res == FR_OK && (fp->flag & FA__DIRTY)) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3520 | if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3521 | res = FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3522 | else |
JDI_Mbed_Team | 0:33fe30a2b785 | 3523 | fp->flag &= ~FA__DIRTY; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3524 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3525 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3526 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3527 | if (res != FR_OK) fp->err = (FRESULT)res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3528 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3529 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3530 | LEAVE_FF(fp->fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3531 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3532 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3533 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3534 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3535 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3536 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3537 | /* Delete a File or Directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3538 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3539 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3540 | FRESULT f_unlink ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3541 | const TCHAR* path /* Pointer to the file or directory path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3542 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3543 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3544 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3545 | FATFS_DIR dj, sdj; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3546 | BYTE *dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3547 | DWORD dclst = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3548 | DEFINE_NAMEBUF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3549 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3550 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3551 | /* Get logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3552 | res = find_volume(&dj.fs, &path, 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3553 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3554 | INIT_BUF(dj); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3555 | res = follow_path(&dj, path); /* Follow the file path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3556 | if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3557 | res = FR_INVALID_NAME; /* Cannot remove dot entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3558 | #if _FS_LOCK |
JDI_Mbed_Team | 0:33fe30a2b785 | 3559 | if (res == FR_OK) res = chk_lock(&dj, 2); /* Cannot remove open object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3560 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3561 | if (res == FR_OK) { /* The object is accessible */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3562 | dir = dj.dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3563 | if (!dir) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3564 | res = FR_INVALID_NAME; /* Cannot remove the origin directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3565 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3566 | if (dir[DIR_Attr] & AM_RDO) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3567 | res = FR_DENIED; /* Cannot remove R/O object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3568 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3569 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3570 | dclst = ld_clust(dj.fs, dir); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3571 | if (dclst && (dir[DIR_Attr] & AM_DIR)) { /* Is it a sub-directory ? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3572 | #if _FS_RPATH |
JDI_Mbed_Team | 0:33fe30a2b785 | 3573 | if (dclst == dj.fs->cdir) { /* Is it the current directory? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3574 | res = FR_DENIED; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3575 | } else |
JDI_Mbed_Team | 0:33fe30a2b785 | 3576 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3577 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3578 | mem_cpy(&sdj, &dj, sizeof (FATFS_DIR)); /* Open the sub-directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3579 | sdj.sclust = dclst; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3580 | res = dir_sdi(&sdj, 2); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3581 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3582 | res = dir_read(&sdj, 0); /* Read an item (excluding dot entries) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3583 | if (res == FR_OK) res = FR_DENIED; /* Not empty? (cannot remove) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3584 | if (res == FR_NO_FILE) res = FR_OK; /* Empty? (can remove) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3585 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3586 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3587 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3588 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3589 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3590 | res = dir_remove(&dj); /* Remove the directory entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3591 | if (res == FR_OK && dclst) /* Remove the cluster chain if exist */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3592 | res = remove_chain(dj.fs, dclst); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3593 | if (res == FR_OK) res = sync_fs(dj.fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3594 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3595 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3596 | FREE_BUF(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3597 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3598 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3599 | LEAVE_FF(dj.fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3600 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3601 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3602 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3603 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3604 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3605 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3606 | /* Create a Directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3607 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3608 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3609 | FRESULT f_mkdir ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3610 | const TCHAR* path /* Pointer to the directory path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3611 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3612 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3613 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3614 | FATFS_DIR dj; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3615 | BYTE *dir, n; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3616 | DWORD dsc, dcl, pcl, tm = GET_FATTIME(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3617 | DEFINE_NAMEBUF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3618 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3619 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3620 | /* Get logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3621 | res = find_volume(&dj.fs, &path, 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3622 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3623 | INIT_BUF(dj); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3624 | res = follow_path(&dj, path); /* Follow the file path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3625 | if (res == FR_OK) res = FR_EXIST; /* Any object with same name is already existing */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3626 | if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT)) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3627 | res = FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3628 | if (res == FR_NO_FILE) { /* Can create a new directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3629 | dcl = create_chain(dj.fs, 0); /* Allocate a cluster for the new directory table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3630 | res = FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3631 | if (dcl == 0) res = FR_DENIED; /* No space to allocate a new cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3632 | if (dcl == 1) res = FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3633 | if (dcl == 0xFFFFFFFF) res = FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3634 | if (res == FR_OK) /* Flush FAT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3635 | res = sync_window(dj.fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3636 | if (res == FR_OK) { /* Initialize the new directory table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3637 | dsc = clust2sect(dj.fs, dcl); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3638 | dir = dj.fs->win; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3639 | mem_set(dir, 0, SS(dj.fs)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3640 | mem_set(dir + DIR_Name, ' ', 11); /* Create "." entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3641 | dir[DIR_Name] = '.'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3642 | dir[DIR_Attr] = AM_DIR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3643 | ST_DWORD(dir + DIR_WrtTime, tm); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3644 | st_clust(dir, dcl); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3645 | mem_cpy(dir + SZ_DIRE, dir, SZ_DIRE); /* Create ".." entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3646 | dir[SZ_DIRE + 1] = '.'; pcl = dj.sclust; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3647 | if (dj.fs->fs_type == FS_FAT32 && pcl == dj.fs->dirbase) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3648 | pcl = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3649 | st_clust(dir + SZ_DIRE, pcl); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3650 | for (n = dj.fs->csize; n; n--) { /* Write dot entries and clear following sectors */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3651 | dj.fs->winsect = dsc++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3652 | dj.fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3653 | res = sync_window(dj.fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3654 | if (res != FR_OK) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3655 | mem_set(dir, 0, SS(dj.fs)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3656 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3657 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3658 | if (res == FR_OK) res = dir_register(&dj); /* Register the object to the directoy */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3659 | if (res != FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3660 | remove_chain(dj.fs, dcl); /* Could not register, remove cluster chain */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3661 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3662 | dir = dj.dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3663 | dir[DIR_Attr] = AM_DIR; /* Attribute */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3664 | ST_DWORD(dir + DIR_WrtTime, tm); /* Created time */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3665 | st_clust(dir, dcl); /* Table start cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3666 | dj.fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3667 | res = sync_fs(dj.fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3668 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3669 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3670 | FREE_BUF(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3671 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3672 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3673 | LEAVE_FF(dj.fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3674 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3675 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3676 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3677 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3678 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3679 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3680 | /* Change Attribute */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3681 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3682 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3683 | FRESULT f_chmod ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3684 | const TCHAR* path, /* Pointer to the file path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3685 | BYTE attr, /* Attribute bits */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3686 | BYTE mask /* Attribute mask to change */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3687 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3688 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3689 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3690 | FATFS_DIR dj; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3691 | BYTE *dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3692 | DEFINE_NAMEBUF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3693 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3694 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3695 | res = find_volume(&dj.fs, &path, 1); /* Get logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3696 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3697 | INIT_BUF(dj); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3698 | res = follow_path(&dj, path); /* Follow the file path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3699 | FREE_BUF(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3700 | if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3701 | res = FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3702 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3703 | dir = dj.dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3704 | if (!dir) { /* Is it a root directory? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3705 | res = FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3706 | } else { /* File or sub directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3707 | mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC; /* Valid attribute mask */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3708 | dir[DIR_Attr] = (attr & mask) | (dir[DIR_Attr] & (BYTE)~mask); /* Apply attribute change */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3709 | dj.fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3710 | res = sync_fs(dj.fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3711 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3712 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3713 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3714 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3715 | LEAVE_FF(dj.fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3716 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3717 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3718 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3719 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3720 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3721 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3722 | /* Rename File/Directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3723 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3724 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3725 | FRESULT f_rename ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3726 | const TCHAR* path_old, /* Pointer to the object to be renamed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3727 | const TCHAR* path_new /* Pointer to the new name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3728 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3729 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3730 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3731 | FATFS_DIR djo, djn; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3732 | BYTE buf[21], *dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3733 | DWORD dw; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3734 | DEFINE_NAMEBUF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3735 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3736 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3737 | /* Get logical drive number of the source object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3738 | res = find_volume(&djo.fs, &path_old, 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3739 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3740 | djn.fs = djo.fs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3741 | INIT_BUF(djo); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3742 | res = follow_path(&djo, path_old); /* Check old object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3743 | if (_FS_RPATH && res == FR_OK && (djo.fn[NSFLAG] & NS_DOT)) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3744 | res = FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3745 | #if _FS_LOCK |
JDI_Mbed_Team | 0:33fe30a2b785 | 3746 | if (res == FR_OK) res = chk_lock(&djo, 2); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3747 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3748 | if (res == FR_OK) { /* Old object is found */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3749 | if (!djo.dir) { /* Is root dir? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3750 | res = FR_NO_FILE; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3751 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3752 | mem_cpy(buf, djo.dir + DIR_Attr, 21); /* Save information about object except name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3753 | mem_cpy(&djn, &djo, sizeof (FATFS_DIR)); /* Duplicate the directory object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3754 | if (get_ldnumber(&path_new) >= 0) /* Snip drive number off and ignore it */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3755 | res = follow_path(&djn, path_new); /* and make sure if new object name is not conflicting */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3756 | else |
JDI_Mbed_Team | 0:33fe30a2b785 | 3757 | res = FR_INVALID_DRIVE; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3758 | if (res == FR_OK) res = FR_EXIST; /* The new object name is already existing */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3759 | if (res == FR_NO_FILE) { /* It is a valid path and no name collision */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3760 | res = dir_register(&djn); /* Register the new entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3761 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3762 | /* Start of critical section where any interruption can cause a cross-link */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3763 | dir = djn.dir; /* Copy information about object except name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3764 | mem_cpy(dir + 13, buf + 2, 19); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3765 | dir[DIR_Attr] = buf[0] | AM_ARC; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3766 | djo.fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3767 | if ((dir[DIR_Attr] & AM_DIR) && djo.sclust != djn.sclust) { /* Update .. entry in the sub-directory if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3768 | dw = clust2sect(djo.fs, ld_clust(djo.fs, dir)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3769 | if (!dw) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3770 | res = FR_INT_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3771 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3772 | res = move_window(djo.fs, dw); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3773 | dir = djo.fs->win + SZ_DIRE * 1; /* Ptr to .. entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3774 | if (res == FR_OK && dir[1] == '.') { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3775 | st_clust(dir, djn.sclust); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3776 | djo.fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3777 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3778 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3779 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3780 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3781 | res = dir_remove(&djo); /* Remove old entry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3782 | if (res == FR_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3783 | res = sync_fs(djo.fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3784 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3785 | /* End of critical section */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3786 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3787 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3788 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3789 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3790 | FREE_BUF(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3791 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3792 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3793 | LEAVE_FF(djo.fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3794 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3795 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3796 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3797 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3798 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3799 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3800 | /* Change Timestamp */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3801 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3802 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3803 | FRESULT f_utime ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3804 | const TCHAR* path, /* Pointer to the file/directory name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3805 | const FILINFO* fno /* Pointer to the time stamp to be set */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3806 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3807 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3808 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3809 | FATFS_DIR dj; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3810 | BYTE *dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3811 | DEFINE_NAMEBUF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3812 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3813 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3814 | /* Get logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3815 | res = find_volume(&dj.fs, &path, 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3816 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3817 | INIT_BUF(dj); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3818 | res = follow_path(&dj, path); /* Follow the file path */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3819 | FREE_BUF(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3820 | if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3821 | res = FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3822 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3823 | dir = dj.dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3824 | if (!dir) { /* Root directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3825 | res = FR_INVALID_NAME; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3826 | } else { /* File or sub-directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3827 | ST_WORD(dir + DIR_WrtTime, fno->ftime); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3828 | ST_WORD(dir + DIR_WrtDate, fno->fdate); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3829 | dj.fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3830 | res = sync_fs(dj.fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3831 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3832 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3833 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3834 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3835 | LEAVE_FF(dj.fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3836 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3837 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3838 | #endif /* !_FS_READONLY */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3839 | #endif /* _FS_MINIMIZE == 0 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3840 | #endif /* _FS_MINIMIZE <= 1 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3841 | #endif /* _FS_MINIMIZE <= 2 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3842 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3843 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3844 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3845 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3846 | #if _USE_LABEL |
JDI_Mbed_Team | 0:33fe30a2b785 | 3847 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3848 | /* Get volume label */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3849 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3850 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3851 | FRESULT f_getlabel ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3852 | const TCHAR* path, /* Path name of the logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3853 | TCHAR* label, /* Pointer to a buffer to return the volume label */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3854 | DWORD* vsn /* Pointer to a variable to return the volume serial number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3855 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3856 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3857 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3858 | FATFS_DIR dj; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3859 | UINT i, j; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3860 | #if _USE_LFN && _LFN_UNICODE |
JDI_Mbed_Team | 0:33fe30a2b785 | 3861 | WCHAR w; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3862 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3863 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3864 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3865 | /* Get logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3866 | res = find_volume(&dj.fs, &path, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3867 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3868 | /* Get volume label */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3869 | if (res == FR_OK && label) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3870 | dj.sclust = 0; /* Open root directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3871 | res = dir_sdi(&dj, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3872 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3873 | res = dir_read(&dj, 1); /* Get an entry with AM_VOL */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3874 | if (res == FR_OK) { /* A volume label is exist */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3875 | #if _USE_LFN && _LFN_UNICODE |
JDI_Mbed_Team | 0:33fe30a2b785 | 3876 | i = j = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3877 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3878 | w = (i < 11) ? dj.dir[i++] : ' '; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3879 | if (IsDBCS1(w) && i < 11 && IsDBCS2(dj.dir[i])) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3880 | w = w << 8 | dj.dir[i++]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3881 | label[j++] = ff_convert(w, 1); /* OEM -> Unicode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3882 | } while (j < 11); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3883 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 3884 | mem_cpy(label, dj.dir, 11); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3885 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3886 | j = 11; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3887 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3888 | label[j] = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3889 | if (!j) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3890 | } while (label[--j] == ' '); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3891 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3892 | if (res == FR_NO_FILE) { /* No label, return nul string */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3893 | label[0] = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3894 | res = FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3895 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3896 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3897 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3898 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3899 | /* Get volume serial number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3900 | if (res == FR_OK && vsn) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3901 | res = move_window(dj.fs, dj.fs->volbase); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3902 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3903 | i = dj.fs->fs_type == FS_FAT32 ? BS_VolID32 : BS_VolID; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3904 | *vsn = LD_DWORD(&dj.fs->win[i]); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3905 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3906 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3907 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3908 | LEAVE_FF(dj.fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3909 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3910 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3911 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3912 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3913 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 3914 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3915 | /* Set volume label */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3916 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3917 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3918 | FRESULT f_setlabel ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 3919 | const TCHAR* label /* Pointer to the volume label to set */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3920 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3921 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3922 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3923 | FATFS_DIR dj; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3924 | BYTE vn[11]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3925 | UINT i, j, sl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3926 | WCHAR w; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3927 | DWORD tm; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3928 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3929 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3930 | /* Get logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3931 | res = find_volume(&dj.fs, &label, 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3932 | if (res) LEAVE_FF(dj.fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3933 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3934 | /* Create a volume label in directory form */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3935 | vn[0] = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3936 | for (sl = 0; label[sl]; sl++) ; /* Get name length */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3937 | for ( ; sl && label[sl - 1] == ' '; sl--) ; /* Remove trailing spaces */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3938 | if (sl) { /* Create volume label in directory form */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3939 | i = j = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3940 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3941 | #if _USE_LFN && _LFN_UNICODE |
JDI_Mbed_Team | 0:33fe30a2b785 | 3942 | w = ff_convert(ff_wtoupper(label[i++]), 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3943 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 3944 | w = (BYTE)label[i++]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3945 | if (IsDBCS1(w)) |
JDI_Mbed_Team | 0:33fe30a2b785 | 3946 | w = (j < 10 && i < sl && IsDBCS2(label[i])) ? w << 8 | (BYTE)label[i++] : 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3947 | #if _USE_LFN |
JDI_Mbed_Team | 0:33fe30a2b785 | 3948 | w = ff_convert(ff_wtoupper(ff_convert(w, 1)), 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3949 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 3950 | if (IsLower(w)) w -= 0x20; /* To upper ASCII characters */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3951 | #ifdef _EXCVT |
JDI_Mbed_Team | 0:33fe30a2b785 | 3952 | if (w >= 0x80) w = ExCvt[w - 0x80]; /* To upper extended characters (SBCS cfg) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3953 | #else |
JDI_Mbed_Team | 0:33fe30a2b785 | 3954 | if (!_DF1S && w >= 0x80) w = 0; /* Reject extended characters (ASCII cfg) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3955 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3956 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3957 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 3958 | if (!w || chk_chr("\"*+,.:;<=>\?[]|\x7F", w) || j >= (UINT)((w >= 0x100) ? 10 : 11)) /* Reject invalid characters for volume label */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3959 | LEAVE_FF(dj.fs, FR_INVALID_NAME); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3960 | if (w >= 0x100) vn[j++] = (BYTE)(w >> 8); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3961 | vn[j++] = (BYTE)w; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3962 | } while (i < sl); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3963 | while (j < 11) vn[j++] = ' '; /* Fill remaining name field */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3964 | if (vn[0] == DDEM) LEAVE_FF(dj.fs, FR_INVALID_NAME); /* Reject illegal name (heading DDEM) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3965 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3966 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 3967 | /* Set volume label */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3968 | dj.sclust = 0; /* Open root directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3969 | res = dir_sdi(&dj, 0); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3970 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3971 | res = dir_read(&dj, 1); /* Get an entry with AM_VOL */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3972 | if (res == FR_OK) { /* A volume label is found */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3973 | if (vn[0]) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3974 | mem_cpy(dj.dir, vn, 11); /* Change the volume label name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3975 | tm = GET_FATTIME(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3976 | ST_DWORD(dj.dir + DIR_WrtTime, tm); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3977 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3978 | dj.dir[0] = DDEM; /* Remove the volume label */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3979 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3980 | dj.fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3981 | res = sync_fs(dj.fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3982 | } else { /* No volume label is found or error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3983 | if (res == FR_NO_FILE) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3984 | res = FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3985 | if (vn[0]) { /* Create volume label as new */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3986 | res = dir_alloc(&dj, 1); /* Allocate an entry for volume label */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3987 | if (res == FR_OK) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 3988 | mem_set(dj.dir, 0, SZ_DIRE); /* Set volume label */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 3989 | mem_cpy(dj.dir, vn, 11); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3990 | dj.dir[DIR_Attr] = AM_VOL; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3991 | tm = GET_FATTIME(); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3992 | ST_DWORD(dj.dir + DIR_WrtTime, tm); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3993 | dj.fs->wflag = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 3994 | res = sync_fs(dj.fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 3995 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3996 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3997 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3998 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 3999 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4000 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4001 | LEAVE_FF(dj.fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4002 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4003 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4004 | #endif /* !_FS_READONLY */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4005 | #endif /* _USE_LABEL */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4006 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4007 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4008 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4009 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4010 | /* Forward data to the stream directly (available on only tiny cfg) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4011 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4012 | #if _USE_FORWARD && _FS_TINY |
JDI_Mbed_Team | 0:33fe30a2b785 | 4013 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4014 | FRESULT f_forward ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 4015 | FIL* fp, /* Pointer to the file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4016 | UINT (*func)(const BYTE*,UINT), /* Pointer to the streaming function */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4017 | UINT btf, /* Number of bytes to forward */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4018 | UINT* bf /* Pointer to number of bytes forwarded */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4019 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4020 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4021 | FRESULT res; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4022 | DWORD remain, clst, sect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4023 | UINT rcnt; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4024 | BYTE csect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4025 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4026 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4027 | *bf = 0; /* Clear transfer byte counter */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4028 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4029 | res = validate(fp); /* Check validity of the object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4030 | if (res != FR_OK) LEAVE_FF(fp->fs, res); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4031 | if (fp->err) /* Check error */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4032 | LEAVE_FF(fp->fs, (FRESULT)fp->err); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4033 | if (!(fp->flag & FA_READ)) /* Check access mode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4034 | LEAVE_FF(fp->fs, FR_DENIED); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4035 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4036 | remain = fp->fsize - fp->fptr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4037 | if (btf > remain) btf = (UINT)remain; /* Truncate btf by remaining bytes */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4038 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4039 | for ( ; btf && (*func)(0, 0); /* Repeat until all data transferred or stream becomes busy */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4040 | fp->fptr += rcnt, *bf += rcnt, btf -= rcnt) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4041 | csect = (BYTE)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4042 | if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4043 | if (!csect) { /* On the cluster boundary? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4044 | clst = (fp->fptr == 0) ? /* On the top of the file? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4045 | fp->sclust : get_fat(fp->fs, fp->clust); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4046 | if (clst <= 1) ABORT(fp->fs, FR_INT_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4047 | if (clst == 0xFFFFFFFF) ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4048 | fp->clust = clst; /* Update current cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4049 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4050 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4051 | sect = clust2sect(fp->fs, fp->clust); /* Get current data sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4052 | if (!sect) ABORT(fp->fs, FR_INT_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4053 | sect += csect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4054 | if (move_window(fp->fs, sect) != FR_OK) /* Move sector window */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4055 | ABORT(fp->fs, FR_DISK_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4056 | fp->dsect = sect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4057 | rcnt = SS(fp->fs) - (WORD)(fp->fptr % SS(fp->fs)); /* Forward data from sector window */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4058 | if (rcnt > btf) rcnt = btf; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4059 | rcnt = (*func)(&fp->fs->win[(WORD)fp->fptr % SS(fp->fs)], rcnt); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4060 | if (!rcnt) ABORT(fp->fs, FR_INT_ERR); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4061 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4062 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4063 | LEAVE_FF(fp->fs, FR_OK); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4064 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4065 | #endif /* _USE_FORWARD */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4066 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4067 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4068 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4069 | #if _USE_MKFS && !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 4070 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4071 | /* Create file system on the logical drive */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4072 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4073 | #define N_ROOTDIR 512 /* Number of root directory entries for FAT12/16 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4074 | #define N_FATS 1 /* Number of FATs (1 or 2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4075 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4076 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4077 | FRESULT f_mkfs ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 4078 | const TCHAR* path, /* Logical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4079 | BYTE sfd, /* Partitioning rule 0:FDISK, 1:SFD */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4080 | UINT au /* Size of allocation unit in unit of byte or sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4081 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4082 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4083 | static const WORD vst[] = { 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 0}; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4084 | static const WORD cst[] = {32768, 16384, 8192, 4096, 2048, 16384, 8192, 4096, 2048, 1024, 512}; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4085 | int vol; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4086 | BYTE fmt, md, sys, *tbl, pdrv, part; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4087 | DWORD n_clst, vs, n, wsect; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4088 | UINT i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4089 | DWORD b_vol, b_fat, b_dir, b_data; /* LBA */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4090 | DWORD n_vol, n_rsv, n_fat, n_dir; /* Size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4091 | FATFS *fs; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4092 | DSTATUS stat; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4093 | #if _USE_TRIM |
JDI_Mbed_Team | 0:33fe30a2b785 | 4094 | DWORD eb[2]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4095 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 4096 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4097 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4098 | /* Check mounted drive and clear work area */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4099 | if (sfd > 1) return FR_INVALID_PARAMETER; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4100 | vol = get_ldnumber(&path); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4101 | if (vol < 0) return FR_INVALID_DRIVE; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4102 | fs = FatFs[vol]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4103 | if (!fs) return FR_NOT_ENABLED; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4104 | fs->fs_type = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4105 | pdrv = LD2PD(vol); /* Physical drive */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4106 | part = LD2PT(vol); /* Partition (0:auto detect, 1-4:get from partition table)*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4107 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4108 | /* Get disk statics */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4109 | stat = disk_initialize(pdrv); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4110 | if (stat & STA_NOINIT) return FR_NOT_READY; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4111 | if (stat & STA_PROTECT) return FR_WRITE_PROTECTED; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4112 | #if _MAX_SS != _MIN_SS /* Get disk sector size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4113 | if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > _MAX_SS || SS(fs) < _MIN_SS) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4114 | return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4115 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 4116 | if (_MULTI_PARTITION && part) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4117 | /* Get partition information from partition table in the MBR */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4118 | if (disk_read(pdrv, fs->win, 0, 1) != RES_OK) return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4119 | if (LD_WORD(fs->win + BS_55AA) != 0xAA55) return FR_MKFS_ABORTED; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4120 | tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4121 | if (!tbl[4]) return FR_MKFS_ABORTED; /* No partition? */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4122 | b_vol = LD_DWORD(tbl + 8); /* Volume start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4123 | n_vol = LD_DWORD(tbl + 12); /* Volume size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4124 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4125 | /* Create a partition in this function */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4126 | if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &n_vol) != RES_OK || n_vol < 128) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4127 | return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4128 | b_vol = (sfd) ? 0 : 63; /* Volume start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4129 | n_vol -= b_vol; /* Volume size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4130 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4131 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4132 | if (au & (au - 1)) au = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4133 | if (!au) { /* AU auto selection */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4134 | vs = n_vol / (2000 / (SS(fs) / 512)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4135 | for (i = 0; vs < vst[i]; i++) ; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4136 | au = cst[i]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4137 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4138 | if (au >= _MIN_SS) au /= SS(fs); /* Number of sectors per cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4139 | if (!au) au = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4140 | if (au > 128) au = 128; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4141 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4142 | /* Pre-compute number of clusters and FAT sub-type */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4143 | n_clst = n_vol / au; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4144 | fmt = FS_FAT12; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4145 | if (n_clst >= MIN_FAT16) fmt = FS_FAT16; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4146 | if (n_clst >= MIN_FAT32) fmt = FS_FAT32; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4147 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4148 | /* Determine offset and size of FAT structure */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4149 | if (fmt == FS_FAT32) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4150 | n_fat = ((n_clst * 4) + 8 + SS(fs) - 1) / SS(fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4151 | n_rsv = 32; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4152 | n_dir = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4153 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4154 | n_fat = (fmt == FS_FAT12) ? (n_clst * 3 + 1) / 2 + 3 : (n_clst * 2) + 4; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4155 | n_fat = (n_fat + SS(fs) - 1) / SS(fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4156 | n_rsv = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4157 | n_dir = (DWORD)N_ROOTDIR * SZ_DIRE / SS(fs); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4158 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4159 | b_fat = b_vol + n_rsv; /* FAT area start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4160 | b_dir = b_fat + n_fat * N_FATS; /* Directory area start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4161 | b_data = b_dir + n_dir; /* Data area start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4162 | if (n_vol < b_data + au - b_vol) return FR_MKFS_ABORTED; /* Too small volume */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4163 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4164 | /* Align data start sector to erase block boundary (for flash memory media) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4165 | if (disk_ioctl(pdrv, GET_BLOCK_SIZE, &n) != RES_OK || !n || n > 32768) n = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4166 | n = (b_data + n - 1) & ~(n - 1); /* Next nearest erase block from current data start */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4167 | n = (n - b_data) / N_FATS; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4168 | if (fmt == FS_FAT32) { /* FAT32: Move FAT offset */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4169 | n_rsv += n; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4170 | b_fat += n; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4171 | } else { /* FAT12/16: Expand FAT size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4172 | n_fat += n; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4173 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4174 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4175 | /* Determine number of clusters and final check of validity of the FAT sub-type */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4176 | n_clst = (n_vol - n_rsv - n_fat * N_FATS - n_dir) / au; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4177 | if ( (fmt == FS_FAT16 && n_clst < MIN_FAT16) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4178 | || (fmt == FS_FAT32 && n_clst < MIN_FAT32)) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4179 | return FR_MKFS_ABORTED; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4180 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4181 | /* Determine system ID in the partition table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4182 | if (fmt == FS_FAT32) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4183 | sys = 0x0C; /* FAT32X */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4184 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4185 | if (fmt == FS_FAT12 && n_vol < 0x10000) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4186 | sys = 0x01; /* FAT12(<65536) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4187 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4188 | sys = (n_vol < 0x10000) ? 0x04 : 0x06; /* FAT16(<65536) : FAT12/16(>=65536) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4189 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4190 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4191 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4192 | if (_MULTI_PARTITION && part) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4193 | /* Update system ID in the partition table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4194 | tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4195 | tbl[4] = sys; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4196 | if (disk_write(pdrv, fs->win, 0, 1) != RES_OK) /* Write it to teh MBR */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4197 | return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4198 | md = 0xF8; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4199 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4200 | if (sfd) { /* No partition table (SFD) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4201 | md = 0xF0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4202 | } else { /* Create partition table (FDISK) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4203 | mem_set(fs->win, 0, SS(fs)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4204 | tbl = fs->win + MBR_Table; /* Create partition table for single partition in the drive */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4205 | tbl[1] = 1; /* Partition start head */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4206 | tbl[2] = 1; /* Partition start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4207 | tbl[3] = 0; /* Partition start cylinder */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4208 | tbl[4] = sys; /* System type */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4209 | tbl[5] = 254; /* Partition end head */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4210 | n = (b_vol + n_vol) / 63 / 255; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4211 | tbl[6] = (BYTE)(n >> 2 | 63); /* Partition end sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4212 | tbl[7] = (BYTE)n; /* End cylinder */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4213 | ST_DWORD(tbl + 8, 63); /* Partition start in LBA */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4214 | ST_DWORD(tbl + 12, n_vol); /* Partition size in LBA */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4215 | ST_WORD(fs->win + BS_55AA, 0xAA55); /* MBR signature */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4216 | if (disk_write(pdrv, fs->win, 0, 1) != RES_OK) /* Write it to the MBR */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4217 | return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4218 | md = 0xF8; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4219 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4220 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4221 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4222 | /* Create BPB in the VBR */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4223 | tbl = fs->win; /* Clear sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4224 | mem_set(tbl, 0, SS(fs)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4225 | mem_cpy(tbl, "\xEB\xFE\x90" "MSDOS5.0", 11);/* Boot jump code, OEM name */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4226 | i = SS(fs); /* Sector size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4227 | ST_WORD(tbl + BPB_BytsPerSec, i); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4228 | tbl[BPB_SecPerClus] = (BYTE)au; /* Sectors per cluster */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4229 | ST_WORD(tbl + BPB_RsvdSecCnt, n_rsv); /* Reserved sectors */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4230 | tbl[BPB_NumFATs] = N_FATS; /* Number of FATs */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4231 | i = (fmt == FS_FAT32) ? 0 : N_ROOTDIR; /* Number of root directory entries */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4232 | ST_WORD(tbl + BPB_RootEntCnt, i); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4233 | if (n_vol < 0x10000) { /* Number of total sectors */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4234 | ST_WORD(tbl + BPB_TotSec16, n_vol); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4235 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4236 | ST_DWORD(tbl + BPB_TotSec32, n_vol); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4237 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4238 | tbl[BPB_Media] = md; /* Media descriptor */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4239 | ST_WORD(tbl + BPB_SecPerTrk, 63); /* Number of sectors per track */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4240 | ST_WORD(tbl + BPB_NumHeads, 255); /* Number of heads */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4241 | ST_DWORD(tbl + BPB_HiddSec, b_vol); /* Hidden sectors */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4242 | n = GET_FATTIME(); /* Use current time as VSN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4243 | if (fmt == FS_FAT32) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4244 | ST_DWORD(tbl + BS_VolID32, n); /* VSN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4245 | ST_DWORD(tbl + BPB_FATSz32, n_fat); /* Number of sectors per FAT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4246 | ST_DWORD(tbl + BPB_RootClus, 2); /* Root directory start cluster (2) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4247 | ST_WORD(tbl + BPB_FSInfo, 1); /* FSINFO record offset (VBR + 1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4248 | ST_WORD(tbl + BPB_BkBootSec, 6); /* Backup boot record offset (VBR + 6) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4249 | tbl[BS_DrvNum32] = 0x80; /* Drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4250 | tbl[BS_BootSig32] = 0x29; /* Extended boot signature */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4251 | mem_cpy(tbl + BS_VolLab32, "NO NAME " "FAT32 ", 19); /* Volume label, FAT signature */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4252 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4253 | ST_DWORD(tbl + BS_VolID, n); /* VSN */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4254 | ST_WORD(tbl + BPB_FATSz16, n_fat); /* Number of sectors per FAT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4255 | tbl[BS_DrvNum] = 0x80; /* Drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4256 | tbl[BS_BootSig] = 0x29; /* Extended boot signature */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4257 | mem_cpy(tbl + BS_VolLab, "NO NAME " "FAT ", 19); /* Volume label, FAT signature */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4258 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4259 | ST_WORD(tbl + BS_55AA, 0xAA55); /* Signature (Offset is fixed here regardless of sector size) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4260 | if (disk_write(pdrv, tbl, b_vol, 1) != RES_OK) /* Write it to the VBR sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4261 | return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4262 | if (fmt == FS_FAT32) /* Write it to the backup VBR if needed (VBR + 6) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4263 | disk_write(pdrv, tbl, b_vol + 6, 1); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4264 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4265 | /* Initialize FAT area */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4266 | wsect = b_fat; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4267 | for (i = 0; i < N_FATS; i++) { /* Initialize each FAT copy */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4268 | mem_set(tbl, 0, SS(fs)); /* 1st sector of the FAT */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4269 | n = md; /* Media descriptor byte */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4270 | if (fmt != FS_FAT32) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4271 | n |= (fmt == FS_FAT12) ? 0x00FFFF00 : 0xFFFFFF00; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4272 | ST_DWORD(tbl + 0, n); /* Reserve cluster #0-1 (FAT12/16) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4273 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4274 | n |= 0xFFFFFF00; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4275 | ST_DWORD(tbl + 0, n); /* Reserve cluster #0-1 (FAT32) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4276 | ST_DWORD(tbl + 4, 0xFFFFFFFF); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4277 | ST_DWORD(tbl + 8, 0x0FFFFFFF); /* Reserve cluster #2 for root directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4278 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4279 | if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4280 | return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4281 | mem_set(tbl, 0, SS(fs)); /* Fill following FAT entries with zero */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4282 | for (n = 1; n < n_fat; n++) { /* This loop may take a time on FAT32 volume due to many single sector writes */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4283 | if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4284 | return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4285 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4286 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4287 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4288 | /* Initialize root directory */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4289 | i = (fmt == FS_FAT32) ? au : (UINT)n_dir; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4290 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4291 | if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4292 | return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4293 | } while (--i); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4294 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4295 | #if _USE_TRIM /* Erase data area if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4296 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4297 | eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt == FS_FAT32) ? 1 : 0)) * au - 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4298 | disk_ioctl(pdrv, CTRL_TRIM, eb); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4299 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4300 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 4301 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4302 | /* Create FSINFO if needed */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4303 | if (fmt == FS_FAT32) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4304 | ST_DWORD(tbl + FSI_LeadSig, 0x41615252); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4305 | ST_DWORD(tbl + FSI_StrucSig, 0x61417272); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4306 | ST_DWORD(tbl + FSI_Free_Count, n_clst - 1); /* Number of free clusters */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4307 | ST_DWORD(tbl + FSI_Nxt_Free, 2); /* Last allocated cluster# */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4308 | ST_WORD(tbl + BS_55AA, 0xAA55); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4309 | disk_write(pdrv, tbl, b_vol + 1, 1); /* Write original (VBR + 1) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4310 | disk_write(pdrv, tbl, b_vol + 7, 1); /* Write backup (VBR + 7) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4311 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4312 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4313 | return (disk_ioctl(pdrv, CTRL_SYNC, 0) == RES_OK) ? FR_OK : FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4314 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4315 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4316 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4317 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4318 | #if _MULTI_PARTITION |
JDI_Mbed_Team | 0:33fe30a2b785 | 4319 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4320 | /* Create partition table on the physical drive */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4321 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4322 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4323 | FRESULT f_fdisk ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 4324 | BYTE pdrv, /* Physical drive number */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4325 | const DWORD szt[], /* Pointer to the size table for each partitions */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4326 | void* work /* Pointer to the working buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4327 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4328 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4329 | UINT i, n, sz_cyl, tot_cyl, b_cyl, e_cyl, p_cyl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4330 | BYTE s_hd, e_hd, *p, *buf = (BYTE*)work; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4331 | DSTATUS stat; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4332 | DWORD sz_disk, sz_part, s_part; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4333 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4334 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4335 | stat = disk_initialize(pdrv); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4336 | if (stat & STA_NOINIT) return FR_NOT_READY; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4337 | if (stat & STA_PROTECT) return FR_WRITE_PROTECTED; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4338 | if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_disk)) return FR_DISK_ERR; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4339 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4340 | /* Determine CHS in the table regardless of the drive geometry */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4341 | for (n = 16; n < 256 && sz_disk / n / 63 > 1024; n *= 2) ; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4342 | if (n == 256) n--; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4343 | e_hd = n - 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4344 | sz_cyl = 63 * n; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4345 | tot_cyl = sz_disk / sz_cyl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4346 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4347 | /* Create partition table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4348 | mem_set(buf, 0, _MAX_SS); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4349 | p = buf + MBR_Table; b_cyl = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4350 | for (i = 0; i < 4; i++, p += SZ_PTE) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4351 | p_cyl = (szt[i] <= 100U) ? (DWORD)tot_cyl * szt[i] / 100 : szt[i] / sz_cyl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4352 | if (!p_cyl) continue; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4353 | s_part = (DWORD)sz_cyl * b_cyl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4354 | sz_part = (DWORD)sz_cyl * p_cyl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4355 | if (i == 0) { /* Exclude first track of cylinder 0 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4356 | s_hd = 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4357 | s_part += 63; sz_part -= 63; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4358 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4359 | s_hd = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4360 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4361 | e_cyl = b_cyl + p_cyl - 1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4362 | if (e_cyl >= tot_cyl) return FR_INVALID_PARAMETER; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4363 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4364 | /* Set partition table */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4365 | p[1] = s_hd; /* Start head */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4366 | p[2] = (BYTE)((b_cyl >> 2) + 1); /* Start sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4367 | p[3] = (BYTE)b_cyl; /* Start cylinder */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4368 | p[4] = 0x06; /* System type (temporary setting) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4369 | p[5] = e_hd; /* End head */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4370 | p[6] = (BYTE)((e_cyl >> 2) + 63); /* End sector */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4371 | p[7] = (BYTE)e_cyl; /* End cylinder */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4372 | ST_DWORD(p + 8, s_part); /* Start sector in LBA */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4373 | ST_DWORD(p + 12, sz_part); /* Partition size */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4374 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4375 | /* Next partition */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4376 | b_cyl += p_cyl; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4377 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4378 | ST_WORD(p, 0xAA55); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4379 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4380 | /* Write it to the MBR */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4381 | return (disk_write(pdrv, buf, 0, 1) != RES_OK || disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) ? FR_DISK_ERR : FR_OK; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4382 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4383 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4384 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4385 | #endif /* _MULTI_PARTITION */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4386 | #endif /* _USE_MKFS && !_FS_READONLY */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4387 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4388 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4389 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4390 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4391 | #if _USE_STRFUNC |
JDI_Mbed_Team | 0:33fe30a2b785 | 4392 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4393 | /* Get a string from the file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4394 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4395 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4396 | TCHAR* f_gets ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 4397 | TCHAR* buff, /* Pointer to the string buffer to read */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4398 | int len, /* Size of string buffer (characters) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4399 | FIL* fp /* Pointer to the file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4400 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4401 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4402 | int n = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4403 | TCHAR c, *p = buff; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4404 | BYTE s[2]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4405 | UINT rc; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4406 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4407 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4408 | while (n < len - 1) { /* Read characters until buffer gets filled */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4409 | #if _USE_LFN && _LFN_UNICODE |
JDI_Mbed_Team | 0:33fe30a2b785 | 4410 | #if _STRF_ENCODE == 3 /* Read a character in UTF-8 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4411 | f_read(fp, s, 1, &rc); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4412 | if (rc != 1) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4413 | c = s[0]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4414 | if (c >= 0x80) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4415 | if (c < 0xC0) continue; /* Skip stray trailer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4416 | if (c < 0xE0) { /* Two-byte sequence */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4417 | f_read(fp, s, 1, &rc); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4418 | if (rc != 1) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4419 | c = (c & 0x1F) << 6 | (s[0] & 0x3F); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4420 | if (c < 0x80) c = '?'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4421 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4422 | if (c < 0xF0) { /* Three-byte sequence */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4423 | f_read(fp, s, 2, &rc); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4424 | if (rc != 2) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4425 | c = c << 12 | (s[0] & 0x3F) << 6 | (s[1] & 0x3F); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4426 | if (c < 0x800) c = '?'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4427 | } else { /* Reject four-byte sequence */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4428 | c = '?'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4429 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4430 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4431 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4432 | #elif _STRF_ENCODE == 2 /* Read a character in UTF-16BE */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4433 | f_read(fp, s, 2, &rc); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4434 | if (rc != 2) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4435 | c = s[1] + (s[0] << 8); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4436 | #elif _STRF_ENCODE == 1 /* Read a character in UTF-16LE */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4437 | f_read(fp, s, 2, &rc); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4438 | if (rc != 2) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4439 | c = s[0] + (s[1] << 8); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4440 | #else /* Read a character in ANSI/OEM */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4441 | f_read(fp, s, 1, &rc); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4442 | if (rc != 1) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4443 | c = s[0]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4444 | if (IsDBCS1(c)) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4445 | f_read(fp, s, 1, &rc); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4446 | if (rc != 1) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4447 | c = (c << 8) + s[0]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4448 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4449 | c = ff_convert(c, 1); /* OEM -> Unicode */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4450 | if (!c) c = '?'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4451 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 4452 | #else /* Read a character without conversion */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4453 | f_read(fp, s, 1, &rc); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4454 | if (rc != 1) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4455 | c = s[0]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4456 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 4457 | if (_USE_STRFUNC == 2 && c == '\r') continue; /* Strip '\r' */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4458 | *p++ = c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4459 | n++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4460 | if (c == '\n') break; /* Break on EOL */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4461 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4462 | *p = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4463 | return n ? buff : 0; /* When no data read (eof or error), return with error. */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4464 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4465 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4466 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4467 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4468 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4469 | #if !_FS_READONLY |
JDI_Mbed_Team | 0:33fe30a2b785 | 4470 | #include <stdarg.h> |
JDI_Mbed_Team | 0:33fe30a2b785 | 4471 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4472 | /* Put a character to the file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4473 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4474 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4475 | typedef struct { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4476 | FIL* fp; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4477 | int idx, nchr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4478 | BYTE buf[64]; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4479 | } putbuff; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4480 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4481 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4482 | static |
JDI_Mbed_Team | 0:33fe30a2b785 | 4483 | void putc_bfd ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 4484 | putbuff* pb, |
JDI_Mbed_Team | 0:33fe30a2b785 | 4485 | TCHAR c |
JDI_Mbed_Team | 0:33fe30a2b785 | 4486 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4487 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4488 | UINT bw; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4489 | int i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4490 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4491 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4492 | if (_USE_STRFUNC == 2 && c == '\n') /* LF -> CRLF conversion */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4493 | putc_bfd(pb, '\r'); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4494 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4495 | i = pb->idx; /* Buffer write index (-1:error) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4496 | if (i < 0) return; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4497 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4498 | #if _USE_LFN && _LFN_UNICODE |
JDI_Mbed_Team | 0:33fe30a2b785 | 4499 | #if _STRF_ENCODE == 3 /* Write a character in UTF-8 */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4500 | if (c < 0x80) { /* 7-bit */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4501 | pb->buf[i++] = (BYTE)c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4502 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4503 | if (c < 0x800) { /* 11-bit */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4504 | pb->buf[i++] = (BYTE)(0xC0 | c >> 6); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4505 | } else { /* 16-bit */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4506 | pb->buf[i++] = (BYTE)(0xE0 | c >> 12); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4507 | pb->buf[i++] = (BYTE)(0x80 | (c >> 6 & 0x3F)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4508 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4509 | pb->buf[i++] = (BYTE)(0x80 | (c & 0x3F)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4510 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4511 | #elif _STRF_ENCODE == 2 /* Write a character in UTF-16BE */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4512 | pb->buf[i++] = (BYTE)(c >> 8); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4513 | pb->buf[i++] = (BYTE)c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4514 | #elif _STRF_ENCODE == 1 /* Write a character in UTF-16LE */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4515 | pb->buf[i++] = (BYTE)c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4516 | pb->buf[i++] = (BYTE)(c >> 8); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4517 | #else /* Write a character in ANSI/OEM */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4518 | c = ff_convert(c, 0); /* Unicode -> OEM */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4519 | if (!c) c = '?'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4520 | if (c >= 0x100) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4521 | pb->buf[i++] = (BYTE)(c >> 8); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4522 | pb->buf[i++] = (BYTE)c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4523 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 4524 | #else /* Write a character without conversion */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4525 | pb->buf[i++] = (BYTE)c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4526 | #endif |
JDI_Mbed_Team | 0:33fe30a2b785 | 4527 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4528 | if (i >= (int)(sizeof pb->buf) - 3) { /* Write buffered characters to the file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4529 | f_write(pb->fp, pb->buf, (UINT)i, &bw); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4530 | i = (bw == (UINT)i) ? 0 : -1; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4531 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4532 | pb->idx = i; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4533 | pb->nchr++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4534 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4535 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4536 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4537 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4538 | int f_putc ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 4539 | TCHAR c, /* A character to be output */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4540 | FIL* fp /* Pointer to the file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4541 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4542 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4543 | putbuff pb; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4544 | UINT nw; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4545 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4546 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4547 | pb.fp = fp; /* Initialize output buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4548 | pb.nchr = pb.idx = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4549 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4550 | putc_bfd(&pb, c); /* Put a character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4551 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4552 | if ( pb.idx >= 0 /* Flush buffered characters to the file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4553 | && f_write(pb.fp, pb.buf, (UINT)pb.idx, &nw) == FR_OK |
JDI_Mbed_Team | 0:33fe30a2b785 | 4554 | && (UINT)pb.idx == nw) return pb.nchr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4555 | return EOF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4556 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4557 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4558 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4559 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4560 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4561 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4562 | /* Put a string to the file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4563 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4564 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4565 | int f_puts ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 4566 | const TCHAR* str, /* Pointer to the string to be output */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4567 | FIL* fp /* Pointer to the file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4568 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4569 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4570 | putbuff pb; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4571 | UINT nw; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4572 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4573 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4574 | pb.fp = fp; /* Initialize output buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4575 | pb.nchr = pb.idx = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4576 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4577 | while (*str) /* Put the string */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4578 | putc_bfd(&pb, *str++); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4579 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4580 | if ( pb.idx >= 0 /* Flush buffered characters to the file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4581 | && f_write(pb.fp, pb.buf, (UINT)pb.idx, &nw) == FR_OK |
JDI_Mbed_Team | 0:33fe30a2b785 | 4582 | && (UINT)pb.idx == nw) return pb.nchr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4583 | return EOF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4584 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4585 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4586 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4587 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4588 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4589 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4590 | /* Put a formatted string to the file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4591 | /*-----------------------------------------------------------------------*/ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4592 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4593 | int f_printf ( |
JDI_Mbed_Team | 0:33fe30a2b785 | 4594 | FIL* fp, /* Pointer to the file object */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4595 | const TCHAR* fmt, /* Pointer to the format string */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4596 | ... /* Optional arguments... */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4597 | ) |
JDI_Mbed_Team | 0:33fe30a2b785 | 4598 | { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4599 | va_list arp; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4600 | BYTE f, r; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4601 | UINT nw, i, j, w; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4602 | DWORD v; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4603 | TCHAR c, d, s[16], *p; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4604 | putbuff pb; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4605 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4606 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4607 | pb.fp = fp; /* Initialize output buffer */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4608 | pb.nchr = pb.idx = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4609 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4610 | va_start(arp, fmt); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4611 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4612 | for (;;) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4613 | c = *fmt++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4614 | if (c == 0) break; /* End of string */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4615 | if (c != '%') { /* Non escape character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4616 | putc_bfd(&pb, c); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4617 | continue; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4618 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4619 | w = f = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4620 | c = *fmt++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4621 | if (c == '0') { /* Flag: '0' padding */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4622 | f = 1; c = *fmt++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4623 | } else { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4624 | if (c == '-') { /* Flag: left justified */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4625 | f = 2; c = *fmt++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4626 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4627 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4628 | while (IsDigit(c)) { /* Precision */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4629 | w = w * 10 + c - '0'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4630 | c = *fmt++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4631 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4632 | if (c == 'l' || c == 'L') { /* Prefix: Size is long int */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4633 | f |= 4; c = *fmt++; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4634 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4635 | if (!c) break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4636 | d = c; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4637 | if (IsLower(d)) d -= 0x20; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4638 | switch (d) { /* Type is... */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4639 | case 'S' : /* String */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4640 | p = va_arg(arp, TCHAR*); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4641 | for (j = 0; p[j]; j++) ; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4642 | if (!(f & 2)) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4643 | while (j++ < w) putc_bfd(&pb, ' '); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4644 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4645 | while (*p) putc_bfd(&pb, *p++); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4646 | while (j++ < w) putc_bfd(&pb, ' '); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4647 | continue; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4648 | case 'C' : /* Character */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4649 | putc_bfd(&pb, (TCHAR)va_arg(arp, int)); continue; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4650 | case 'B' : /* Binary */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4651 | r = 2; break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4652 | case 'O' : /* Octal */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4653 | r = 8; break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4654 | case 'D' : /* Signed decimal */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4655 | case 'U' : /* Unsigned decimal */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4656 | r = 10; break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4657 | case 'X' : /* Hexdecimal */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4658 | r = 16; break; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4659 | default: /* Unknown type (pass-through) */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4660 | putc_bfd(&pb, c); continue; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4661 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4662 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4663 | /* Get an argument and put it in numeral */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4664 | v = (f & 4) ? (DWORD)va_arg(arp, long) : ((d == 'D') ? (DWORD)(long)va_arg(arp, int) : (DWORD)va_arg(arp, unsigned int)); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4665 | if (d == 'D' && (v & 0x80000000)) { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4666 | v = 0 - v; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4667 | f |= 8; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4668 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4669 | i = 0; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4670 | do { |
JDI_Mbed_Team | 0:33fe30a2b785 | 4671 | d = (TCHAR)(v % r); v /= r; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4672 | if (d > 9) d += (c == 'x') ? 0x27 : 0x07; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4673 | s[i++] = d + '0'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4674 | } while (v && i < sizeof s / sizeof s[0]); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4675 | if (f & 8) s[i++] = '-'; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4676 | j = i; d = (f & 1) ? '0' : ' '; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4677 | while (!(f & 2) && j++ < w) putc_bfd(&pb, d); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4678 | do putc_bfd(&pb, s[--i]); while (i); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4679 | while (j++ < w) putc_bfd(&pb, d); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4680 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4681 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4682 | va_end(arp); |
JDI_Mbed_Team | 0:33fe30a2b785 | 4683 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4684 | if ( pb.idx >= 0 /* Flush buffered characters to the file */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4685 | && f_write(pb.fp, pb.buf, (UINT)pb.idx, &nw) == FR_OK |
JDI_Mbed_Team | 0:33fe30a2b785 | 4686 | && (UINT)pb.idx == nw) return pb.nchr; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4687 | return EOF; |
JDI_Mbed_Team | 0:33fe30a2b785 | 4688 | } |
JDI_Mbed_Team | 0:33fe30a2b785 | 4689 | |
JDI_Mbed_Team | 0:33fe30a2b785 | 4690 | #endif /* !_FS_READONLY */ |
JDI_Mbed_Team | 0:33fe30a2b785 | 4691 | #endif /* _USE_STRFUNC */ |