+/*----------------------------------------------------------------------------/\r
+/ Petit FatFs - FAT file system module R0.02a (C)ChaN, 2010\r
+/-----------------------------------------------------------------------------/\r
+/ Petit FatFs module is an open source software to implement FAT file system to\r
+/ small embedded systems. This is a free software and is opened for education,\r
+/ research and commercial developments under license policy of following trems.\r
+/\r
+/ Copyright (C) 2010, ChaN, all right reserved.\r
+/\r
+/ * The Petit FatFs module is a free software and there is NO WARRANTY.\r
+/ * No restriction on use. You can use, modify and redistribute it for\r
+/ personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.\r
+/ * Redistributions of source code must retain the above copyright notice.\r
+/\r
+/-----------------------------------------------------------------------------/\r
+/ Jun 15,'09 R0.01a First release. (Branched from FatFs R0.07b.)\r
+/\r
+/ Dec 14,'09 R0.02 Added multiple code page support.\r
+/ Added write funciton.\r
+/ Changed stream read mode interface.\r
+/ Dec 07,'10 R0.02a Added some configuration options.\r
+/ Fixed fails to open objects with DBCS character.\r
+/----------------------------------------------------------------------------*/\r
+\r
+#include "pff.h" /* Petit FatFs configurations and declarations */\r
+#include "diskio.h" /* Declarations of low level disk I/O functions */\r
+\r
+\r
+\r
+/*--------------------------------------------------------------------------\r
+\r
+ Module Private Definitions\r
+\r
+---------------------------------------------------------------------------*/\r
+\r
+\r
+#if _FS_FAT32\r
+#define LD_CLUST(dir) (((DWORD)LD_WORD(dir+DIR_FstClusHI)<<16) | LD_WORD(dir+DIR_FstClusLO))\r
+#else\r
+#define LD_CLUST(dir) LD_WORD(dir+DIR_FstClusLO)\r
+#endif\r
+\r
+\r
+/*--------------------------------------------------------*/\r
+/* DBCS code ranges and SBCS extend char conversion table */\r
+\r
+#if _CODE_PAGE == 932 /* Japanese Shift-JIS */\r
+#define _DF1S 0x81 /* DBC 1st byte range 1 start */\r
+#define _DF1E 0x9F /* DBC 1st byte range 1 end */\r
+#define _DF2S 0xE0 /* DBC 1st byte range 2 start */\r
+#define _DF2E 0xFC /* DBC 1st byte range 2 end */\r
+#define _DS1S 0x40 /* DBC 2nd byte range 1 start */\r
+#define _DS1E 0x7E /* DBC 2nd byte range 1 end */\r
+#define _DS2S 0x80 /* DBC 2nd byte range 2 start */\r
+#define _DS2E 0xFC /* DBC 2nd byte range 2 end */\r
+\r
+#elif _CODE_PAGE == 936 /* Simplified Chinese GBK */\r
+#define _DF1S 0x81\r
+#define _DF1E 0xFE\r
+#define _DS1S 0x40\r
+#define _DS1E 0x7E\r
+#define _DS2S 0x80\r
+#define _DS2E 0xFE\r
+\r
+#elif _CODE_PAGE == 949 /* Korean */\r
+#define _DF1S 0x81\r
+#define _DF1E 0xFE\r
+#define _DS1S 0x41\r
+#define _DS1E 0x5A\r
+#define _DS2S 0x61\r
+#define _DS2E 0x7A\r
+#define _DS3S 0x81\r
+#define _DS3E 0xFE\r
+\r
+#elif _CODE_PAGE == 950 /* Traditional Chinese Big5 */\r
+#define _DF1S 0x81\r
+#define _DF1E 0xFE\r
+#define _DS1S 0x40\r
+#define _DS1E 0x7E\r
+#define _DS2S 0xA1\r
+#define _DS2E 0xFE\r
+\r
+#elif _CODE_PAGE == 437 /* U.S. (OEM) */\r
+#define _DF1S 0\r
+#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F,0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \\r
+ 0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0x21,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+ 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0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0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 874 /* Thai (OEM, Windows) */\r
+#define _DF1S 0\r
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \\r
+ 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+ 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+ 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 1250 /* Central Europe (Windows) */\r
+#define _DF1S 0\r
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x8A,0x9B,0x8C,0x8D,0x8E,0x8F, \\r
+ 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0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
+\r
+#else\r
+#error Unknown code page\r
+\r
+#endif\r
+\r
+\r
+\r
+/* Character code support macros */\r
+\r
+#define IsUpper(c) (((c)>='A')&&((c)<='Z'))\r
+#define IsLower(c) (((c)>='a')&&((c)<='z'))\r
+\r
+#if _DF1S /* DBCS configuration */\r
+\r
+#ifdef _DF2S /* Two 1st byte areas */\r
+#define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E))\r
+#else /* One 1st byte area */\r
+#define IsDBCS1(c) ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E)\r
+#endif\r
+\r
+#ifdef _DS3S /* Three 2nd byte areas */\r
+#define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E))\r
+#else /* Two 2nd byte areas */\r
+#define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E))\r
+#endif\r
+\r
+#else /* SBCS configuration */\r
+\r
+#define IsDBCS1(c) 0\r
+#define IsDBCS2(c) 0\r
+\r
+#endif /* _DF1S */\r
+\r
+\r
+/* FatFs refers the members in the FAT structures with byte offset instead\r
+/ of structure member because there are incompatibility of the packing option\r
+/ between various compilers. */\r
+\r
+#define BS_jmpBoot 0\r
+#define BS_OEMName 3\r
+#define BPB_BytsPerSec 11\r
+#define BPB_SecPerClus 13\r
+#define BPB_RsvdSecCnt 14\r
+#define BPB_NumFATs 16\r
+#define BPB_RootEntCnt 17\r
+#define BPB_TotSec16 19\r
+#define BPB_Media 21\r
+#define BPB_FATSz16 22\r
+#define BPB_SecPerTrk 24\r
+#define BPB_NumHeads 26\r
+#define BPB_HiddSec 28\r
+#define BPB_TotSec32 32\r
+#define BS_55AA 510\r
+\r
+#define BS_DrvNum 36\r
+#define BS_BootSig 38\r
+#define BS_VolID 39\r
+#define BS_VolLab 43\r
+#define BS_FilSysType 54\r
+\r
+#define BPB_FATSz32 36\r
+#define BPB_ExtFlags 40\r
+#define BPB_FSVer 42\r
+#define BPB_RootClus 44\r
+#define BPB_FSInfo 48\r
+#define BPB_BkBootSec 50\r
+#define BS_DrvNum32 64\r
+#define BS_BootSig32 66\r
+#define BS_VolID32 67\r
+#define BS_VolLab32 71\r
+#define BS_FilSysType32 82\r
+\r
+#define MBR_Table 446\r
+\r
+#define DIR_Name 0\r
+#define DIR_Attr 11\r
+#define DIR_NTres 12\r
+#define DIR_CrtTime 14\r
+#define DIR_CrtDate 16\r
+#define DIR_FstClusHI 20\r
+#define DIR_WrtTime 22\r
+#define DIR_WrtDate 24\r
+#define DIR_FstClusLO 26\r
+#define DIR_FileSize 28\r
+\r
+\r
+\r
+/*--------------------------------------------------------------------------\r
+\r
+ Private Functions\r
+\r
+---------------------------------------------------------------------------*/\r
+\r
+\r
+static\r
+FATFS *FatFs; /* Pointer to the file system object (logical drive) */\r
+\r
+\r
+/* Fill memory */\r
+static\r
+void mem_set (void* dst, int val, int cnt) {\r
+ char *d = (char*)dst;\r
+ while (cnt--) *d++ = (char)val;\r
+}\r
+\r
+/* Compare memory to memory */\r
+static\r
+int mem_cmp (const void* dst, const void* src, int cnt) {\r
+ const char *d = (const char *)dst, *s = (const char *)src;\r
+ int r = 0;\r
+ while (cnt-- && (r = *d++ - *s++) == 0) ;\r
+ return r;\r
+}\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* FAT access - Read value of a FAT entry */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+CLUST get_fat ( /* 1:IO error, Else:Cluster status */\r
+ CLUST clst /* Cluster# to get the link information */\r
+)\r
+{\r
+ WORD wc, bc, ofs;\r
+ BYTE buf[4];\r
+ FATFS *fs = FatFs;\r
+\r
+\r
+ if (clst < 2 || clst >= fs->n_fatent) /* Range check */\r
+ return 1;\r
+\r
+ switch (fs->fs_type) {\r
+#if _FS_FAT12\r
+ case FS_FAT12 :\r
+ bc = (WORD)clst; bc += bc / 2;\r
+ ofs = bc % 512; bc /= 512;\r
+ if (ofs != 511) {\r
+ if (disk_readp(buf, fs->fatbase + bc, ofs, 2)) break;\r
+ } else {\r
+ if (disk_readp(buf, fs->fatbase + bc, 511, 1)) break;\r
+ if (disk_readp(buf+1, fs->fatbase + bc + 1, 0, 1)) break;\r
+ }\r
+ wc = LD_WORD(buf);\r
+ return (clst & 1) ? (wc >> 4) : (wc & 0xFFF);\r
+#endif\r
+ case FS_FAT16 :\r
+ if (disk_readp(buf, fs->fatbase + clst / 256, (WORD)(((WORD)clst % 256) * 2), 2)) break;\r
+ return LD_WORD(buf);\r
+#if _FS_FAT32\r
+ case FS_FAT32 :\r
+ if (disk_readp(buf, fs->fatbase + clst / 128, (WORD)(((WORD)clst % 128) * 4), 4)) break;\r
+ return LD_DWORD(buf) & 0x0FFFFFFF;\r
+#endif\r
+ }\r
+\r
+ return 1; /* An error occured at the disk I/O layer */\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Get sector# from cluster# */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */\r
+ CLUST clst /* Cluster# to be converted */\r
+)\r
+{\r
+ FATFS *fs = FatFs;\r
+\r
+\r
+ clst -= 2;\r
+ if (clst >= (fs->n_fatent - 2)) return 0; /* Invalid cluster# */\r
+ return (DWORD)clst * fs->csize + fs->database;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Directory handling - Rewind directory index */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+FRESULT dir_rewind (\r
+ DIR *dj /* Pointer to directory object */\r
+)\r
+{\r
+ CLUST clst;\r
+ FATFS *fs = FatFs;\r
+\r
+\r
+ dj->index = 0;\r
+ clst = dj->sclust;\r
+ if (clst == 1 || clst >= fs->n_fatent) /* Check start cluster range */\r
+ return FR_DISK_ERR;\r
+ if (_FS_FAT32 && !clst && fs->fs_type == FS_FAT32) /* Replace cluster# 0 with root cluster# if in FAT32 */\r
+ clst = (CLUST)fs->dirbase;\r
+ dj->clust = clst; /* Current cluster */\r
+ dj->sect = clst ? clust2sect(clst) : fs->dirbase; /* Current sector */\r
+\r
+ return FR_OK; /* Seek succeeded */\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Directory handling - Move directory index next */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+FRESULT dir_next ( /* FR_OK:Succeeded, FR_NO_FILE:End of table */\r
+ DIR *dj /* Pointer to directory object */\r
+)\r
+{\r
+ CLUST clst;\r
+ WORD i;\r
+ FATFS *fs = FatFs;\r
+\r
+\r
+ i = dj->index + 1;\r
+ if (!i || !dj->sect) /* Report EOT when index has reached 65535 */\r
+ return FR_NO_FILE;\r
+\r
+ if (!(i % 16)) { /* Sector changed? */\r
+ dj->sect++; /* Next sector */\r
+\r
+ if (dj->clust == 0) { /* Static table */\r
+ if (i >= fs->n_rootdir) /* Report EOT when end of table */\r
+ return FR_NO_FILE;\r
+ }\r
+ else { /* Dynamic table */\r
+ if (((i / 16) & (fs->csize-1)) == 0) { /* Cluster changed? */\r
+ clst = get_fat(dj->clust); /* Get next cluster */\r
+ if (clst <= 1) return FR_DISK_ERR;\r
+ if (clst >= fs->n_fatent) /* When it reached end of dynamic table */\r
+ return FR_NO_FILE; /* Report EOT */\r
+ dj->clust = clst; /* Initialize data for new cluster */\r
+ dj->sect = clust2sect(clst);\r
+ }\r
+ }\r
+ }\r
+\r
+ dj->index = i;\r
+\r
+ return FR_OK;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Directory handling - Find an object in the directory */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+FRESULT dir_find (\r
+ DIR *dj, /* Pointer to the directory object linked to the file name */\r
+ BYTE *dir /* 32-byte working buffer */\r
+)\r
+{\r
+ FRESULT res;\r
+ BYTE c;\r
+\r
+\r
+ res = dir_rewind(dj); /* Rewind directory object */\r
+ if (res != FR_OK) return res;\r
+\r
+ do {\r
+ res = disk_readp(dir, dj->sect, (WORD)((dj->index % 16) * 32), 32) /* Read an entry */\r
+ ? FR_DISK_ERR : FR_OK;\r
+ if (res != FR_OK) break;\r
+ c = dir[DIR_Name]; /* First character */\r
+ if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */\r
+ if (!(dir[DIR_Attr] & AM_VOL) && !mem_cmp(dir, dj->fn, 11)) /* Is it a valid entry? */\r
+ break;\r
+ res = dir_next(dj); /* Next entry */\r
+ } while (res == FR_OK);\r
+\r
+ return res;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Read an object from the directory */\r
+/*-----------------------------------------------------------------------*/\r
+#if _USE_DIR\r
+static\r
+FRESULT dir_read (\r
+ DIR *dj, /* Pointer to the directory object to store read object name */\r
+ BYTE *dir /* 32-byte working buffer */\r
+)\r
+{\r
+ FRESULT res;\r
+ BYTE a, c;\r
+\r
+\r
+ res = FR_NO_FILE;\r
+ while (dj->sect) {\r
+ res = disk_readp(dir, dj->sect, (WORD)((dj->index % 16) * 32), 32) /* Read an entry */\r
+ ? FR_DISK_ERR : FR_OK;\r
+ if (res != FR_OK) break;\r
+ c = dir[DIR_Name];\r
+ if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */\r
+ a = dir[DIR_Attr] & AM_MASK;\r
+ if (c != 0xE5 && c != '.' && !(a & AM_VOL)) /* Is it a valid entry? */\r
+ break;\r
+ res = dir_next(dj); /* Next entry */\r
+ if (res != FR_OK) break;\r
+ }\r
+\r
+ if (res != FR_OK) dj->sect = 0;\r
+\r
+ return res;\r
+}\r
+#endif\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Pick a segment and create the object name in directory form */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+#ifdef _EXCVT\r
+ static const BYTE cvt[] = _EXCVT;\r
+#endif\r
+\r
+static\r
+FRESULT create_name (\r
+ DIR *dj, /* Pointer to the directory object */\r
+ const char **path /* Pointer to pointer to the segment in the path string */\r
+)\r
+{\r
+ BYTE c, d, ni, si, i, *sfn;\r
+ const char *p;\r
+\r
+ /* Create file name in directory form */\r
+ sfn = dj->fn;\r
+ mem_set(sfn, ' ', 11);\r
+ si = i = 0; ni = 8;\r
+ p = *path;\r
+ for (;;) {\r
+ c = p[si++];\r
+ if (c <= ' ' || c == '/') break; /* Break on end of segment */\r
+ if (c == '.' || i >= ni) {\r
+ if (ni != 8 || c != '.') break;\r
+ i = 8; ni = 11;\r
+ continue;\r
+ }\r
+#ifdef _EXCVT\r
+ if (c >= 0x80) /* To upper extended char (SBCS) */\r
+ c = cvt[c - 0x80];\r
+#endif\r
+ if (IsDBCS1(c) && i < ni - 1) { /* DBC 1st byte? */\r
+ d = p[si++]; /* Get 2nd byte */\r
+ sfn[i++] = c;\r
+ sfn[i++] = d;\r
+ } else { /* Single byte code */\r
+ if (IsLower(c)) c -= 0x20; /* toupper */\r
+ sfn[i++] = c;\r
+ }\r
+ }\r
+ *path = &p[si]; /* Rerurn pointer to the next segment */\r
+\r
+ sfn[11] = (c <= ' ') ? 1 : 0; /* Set last segment flag if end of path */\r
+\r
+ return FR_OK;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Get file information from directory entry */\r
+/*-----------------------------------------------------------------------*/\r
+#if _USE_DIR\r
+static\r
+void get_fileinfo ( /* No return code */\r
+ DIR *dj, /* Pointer to the directory object */\r
+ BYTE *dir, /* 32-byte working buffer */\r
+ FILINFO *fno /* Pointer to store the file information */\r
+)\r
+{\r
+ BYTE i, c;\r
+ char *p;\r
+\r
+\r
+ p = fno->fname;\r
+ if (dj->sect) {\r
+ for (i = 0; i < 8; i++) { /* Copy file name body */\r
+ c = dir[i];\r
+ if (c == ' ') break;\r
+ if (c == 0x05) c = 0xE5;\r
+ *p++ = c;\r
+ }\r
+ if (dir[8] != ' ') { /* Copy file name extension */\r
+ *p++ = '.';\r
+ for (i = 8; i < 11; i++) {\r
+ c = dir[i];\r
+ if (c == ' ') break;\r
+ *p++ = c;\r
+ }\r
+ }\r
+ fno->fattrib = dir[DIR_Attr]; /* Attribute */\r
+ fno->fsize = LD_DWORD(dir+DIR_FileSize); /* Size */\r
+ fno->fdate = LD_WORD(dir+DIR_WrtDate); /* Date */\r
+ fno->ftime = LD_WORD(dir+DIR_WrtTime); /* Time */\r
+ }\r
+ *p = 0;\r
+}\r
+#endif /* _USE_DIR */\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Follow a file path */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */\r
+ DIR *dj, /* Directory object to return last directory and found object */\r
+ BYTE *dir, /* 32-byte working buffer */\r
+ const char *path /* Full-path string to find a file or directory */\r
+)\r
+{\r
+ FRESULT res;\r
+\r
+\r
+ while (*path == ' ') path++; /* Skip leading spaces */\r
+ if (*path == '/') path++; /* Strip heading separator */\r
+ dj->sclust = 0; /* Set start directory (always root dir) */\r
+\r
+ if ((BYTE)*path <= ' ') { /* Null path means the root directory */\r
+ res = dir_rewind(dj);\r
+ dir[0] = 0;\r
+\r
+ } else { /* Follow path */\r
+ for (;;) {\r
+ res = create_name(dj, &path); /* Get a segment */\r
+ if (res != FR_OK) break;\r
+ res = dir_find(dj, dir); /* Find it */\r
+ if (res != FR_OK) { /* Could not find the object */\r
+ if (res == FR_NO_FILE && !*(dj->fn+11))\r
+ res = FR_NO_PATH;\r
+ break;\r
+ }\r
+ if (*(dj->fn+11)) break; /* Last segment match. Function completed. */\r
+ if (!(dir[DIR_Attr] & AM_DIR)) { /* Cannot follow because it is a file */\r
+ res = FR_NO_PATH; break;\r
+ }\r
+ dj->sclust = LD_CLUST(dir);\r
+ }\r
+ }\r
+\r
+ return res;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Check a sector if it is an FAT boot record */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+BYTE check_fs ( /* 0:The FAT boot record, 1:Valid boot record but not an FAT, 2:Not a boot record, 3:Error */\r
+ BYTE *buf, /* Working buffer */\r
+ DWORD sect /* Sector# (lba) to check if it is an FAT boot record or not */\r
+)\r
+{\r
+ if (disk_readp(buf, sect, 510, 2)) /* Read the boot sector */\r
+ return 3;\r
+ if (LD_WORD(buf) != 0xAA55) /* Check record signature */\r
+ return 2;\r
+\r
+ if (!disk_readp(buf, sect, BS_FilSysType, 2) && LD_WORD(buf) == 0x4146) /* Check FAT12/16 */\r
+ return 0;\r
+ if (_FS_FAT32 && !disk_readp(buf, sect, BS_FilSysType32, 2) && LD_WORD(buf) == 0x4146) /* Check FAT32 */\r
+ return 0;\r
+ return 1;\r
+}\r
+\r
+\r
+\r
+\r
+/*--------------------------------------------------------------------------\r
+\r
+ Public Functions\r
+\r
+--------------------------------------------------------------------------*/\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Mount/Unmount a Locical Drive */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT pf_mount (\r
+ FATFS *fs /* Pointer to new file system object (NULL: Unmount) */\r
+)\r
+{\r
+ BYTE fmt, buf[36];\r
+ DWORD bsect, fsize, tsect, mclst;\r
+\r
+\r
+ FatFs = 0;\r
+ if (!fs) return FR_OK; /* Unregister fs object */\r
+\r
+ if (disk_initialize() & STA_NOINIT) /* Check if the drive is ready or not */\r
+ return FR_NOT_READY;\r
+\r
+ /* Search FAT partition on the drive */\r
+ bsect = 0;\r
+ fmt = check_fs(buf, bsect); /* Check sector 0 as an SFD format */\r
+ if (fmt == 1) { /* Not an FAT boot record, it may be FDISK format */\r
+ /* Check a partition listed in top of the partition table */\r
+ if (disk_readp(buf, bsect, MBR_Table, 16)) { /* 1st partition entry */\r
+ fmt = 3;\r
+ } else {\r
+ if (buf[4]) { /* Is the partition existing? */\r
+ bsect = LD_DWORD(&buf[8]); /* Partition offset in LBA */\r
+ fmt = check_fs(buf, bsect); /* Check the partition */\r
+ }\r
+ }\r
+ }\r
+ if (fmt == 3) return FR_DISK_ERR;\r
+ if (fmt) return FR_NO_FILESYSTEM; /* No valid FAT patition is found */\r
+\r
+ /* Initialize the file system object */\r
+ if (disk_readp(buf, bsect, 13, sizeof(buf))) return FR_DISK_ERR;\r
+\r
+ fsize = LD_WORD(buf+BPB_FATSz16-13); /* Number of sectors per FAT */\r
+ if (!fsize) fsize = LD_DWORD(buf+BPB_FATSz32-13);\r
+\r
+ fsize *= buf[BPB_NumFATs-13]; /* Number of sectors in FAT area */\r
+ fs->fatbase = bsect + LD_WORD(buf+BPB_RsvdSecCnt-13); /* FAT start sector (lba) */\r
+ fs->csize = buf[BPB_SecPerClus-13]; /* Number of sectors per cluster */\r
+ fs->n_rootdir = LD_WORD(buf+BPB_RootEntCnt-13); /* Nmuber of root directory entries */\r
+ tsect = LD_WORD(buf+BPB_TotSec16-13); /* Number of sectors on the file system */\r
+ if (!tsect) tsect = LD_DWORD(buf+BPB_TotSec32-13);\r
+ mclst = (tsect /* Last cluster# + 1 */\r
+ - LD_WORD(buf+BPB_RsvdSecCnt-13) - fsize - fs->n_rootdir / 16\r
+ ) / fs->csize + 2;\r
+ fs->n_fatent = (CLUST)mclst;\r
+\r
+ fmt = FS_FAT16; /* Determine the FAT sub type */\r
+ if (mclst < 0xFF7) /* Number of clusters < 0xFF5 */\r
+#if _FS_FAT12\r
+ fmt = FS_FAT12;\r
+#else\r
+ return FR_NO_FILESYSTEM;\r
+#endif\r
+ if (mclst >= 0xFFF7) /* Number of clusters >= 0xFFF5 */\r
+#if _FS_FAT32\r
+ fmt = FS_FAT32;\r
+#else\r
+ return FR_NO_FILESYSTEM;\r
+#endif\r
+\r
+ fs->fs_type = fmt; /* FAT sub-type */\r
+ if (_FS_FAT32 && fmt == FS_FAT32)\r
+ fs->dirbase = LD_DWORD(buf+(BPB_RootClus-13)); /* Root directory start cluster */\r
+ else\r
+ fs->dirbase = fs->fatbase + fsize; /* Root directory start sector (lba) */\r
+ fs->database = fs->fatbase + fsize + fs->n_rootdir / 16; /* Data start sector (lba) */\r
+\r
+ fs->flag = 0;\r
+ FatFs = fs;\r
+\r
+ return FR_OK;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Open or Create a File */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT pf_open (\r
+ const char *path /* Pointer to the file name */\r
+)\r
+{\r
+ FRESULT res;\r
+ DIR dj;\r
+ BYTE sp[12], dir[32];\r
+ FATFS *fs = FatFs;\r
+\r
+\r
+ if (!fs) /* Check file system */\r
+ return FR_NOT_ENABLED;\r
+\r
+ fs->flag = 0;\r
+ dj.fn = sp;\r
+ res = follow_path(&dj, dir, path); /* Follow the file path */\r
+ if (res != FR_OK) return res; /* Follow failed */\r
+ if (!dir[0] || (dir[DIR_Attr] & AM_DIR)) /* It is a directory */\r
+ return FR_NO_FILE;\r
+\r
+ fs->org_clust = LD_CLUST(dir); /* File start cluster */\r
+ fs->fsize = LD_DWORD(dir+DIR_FileSize); /* File size */\r
+ fs->fptr = 0; /* File pointer */\r
+ fs->flag = FA_OPENED;\r
+\r
+ return FR_OK;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Read File */\r
+/*-----------------------------------------------------------------------*/\r
+#if _USE_READ\r
+\r
+FRESULT pf_read (\r
+ void* buff, /* Pointer to the read buffer (NULL:Forward data to the stream)*/\r
+ WORD btr, /* Number of bytes to read */\r
+ WORD* br /* Pointer to number of bytes read */\r
+)\r
+{\r
+ DRESULT dr;\r
+ CLUST clst;\r
+ DWORD sect, remain;\r
+ WORD rcnt;\r
+ BYTE cs, *rbuff = buff;\r
+ FATFS *fs = FatFs;\r
+\r
+\r
+ *br = 0;\r
+ if (!fs) return FR_NOT_ENABLED; /* Check file system */\r
+ if (!(fs->flag & FA_OPENED)) /* Check if opened */\r
+ return FR_NOT_OPENED;\r
+\r
+ remain = fs->fsize - fs->fptr;\r
+ if (btr > remain) btr = (WORD)remain; /* Truncate btr by remaining bytes */\r
+\r
+ while (btr) { /* Repeat until all data transferred */\r
+ if ((fs->fptr % 512) == 0) { /* On the sector boundary? */\r
+ cs = (BYTE)(fs->fptr / 512 & (fs->csize - 1)); /* Sector offset in the cluster */\r
+ if (!cs) { /* On the cluster boundary? */\r
+ clst = (fs->fptr == 0) ? /* On the top of the file? */\r
+ fs->org_clust : get_fat(fs->curr_clust);\r
+ if (clst <= 1) goto fr_abort;\r
+ fs->curr_clust = clst; /* Update current cluster */\r
+ }\r
+ sect = clust2sect(fs->curr_clust); /* Get current sector */\r
+ if (!sect) goto fr_abort;\r
+ fs->dsect = sect + cs;\r
+ }\r
+ rcnt = (WORD)(512 - (fs->fptr % 512)); /* Get partial sector data from sector buffer */\r
+ if (rcnt > btr) rcnt = btr;\r
+ dr = disk_readp(!buff ? 0 : rbuff, fs->dsect, (WORD)(fs->fptr % 512), rcnt);\r
+ if (dr) goto fr_abort;\r
+ fs->fptr += rcnt; rbuff += rcnt; /* Update pointers and counters */\r
+ btr -= rcnt; *br += rcnt;\r
+ }\r
+\r
+ return FR_OK;\r
+\r
+fr_abort:\r
+ fs->flag = 0;\r
+ return FR_DISK_ERR;\r
+}\r
+#endif\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Write File */\r
+/*-----------------------------------------------------------------------*/\r
+#if _USE_WRITE\r
+\r
+FRESULT pf_write (\r
+ const void* buff, /* Pointer to the data to be written */\r
+ WORD btw, /* Number of bytes to write (0:Finalize the current write operation) */\r
+ WORD* bw /* Pointer to number of bytes written */\r
+)\r
+{\r
+ CLUST clst;\r
+ DWORD sect, remain;\r
+ const BYTE *p = buff;\r
+ BYTE cs;\r
+ WORD wcnt;\r
+ FATFS *fs = FatFs;\r
+\r
+\r
+ *bw = 0;\r
+ if (!fs) return FR_NOT_ENABLED; /* Check file system */\r
+ if (!(fs->flag & FA_OPENED)) /* Check if opened */\r
+ return FR_NOT_OPENED;\r
+\r
+ if (!btw) { /* Finalize request */\r
+ if ((fs->flag & FA__WIP) && disk_writep(0, 0)) goto fw_abort;\r
+ fs->flag &= ~FA__WIP;\r
+ return FR_OK;\r
+ } else { /* Write data request */\r
+ if (!(fs->flag & FA__WIP)) /* Round-down fptr to the sector boundary */\r
+ fs->fptr &= 0xFFFFFE00;\r
+ }\r
+ remain = fs->fsize - fs->fptr;\r
+ if (btw > remain) btw = (WORD)remain; /* Truncate btw by remaining bytes */\r
+\r
+ while (btw) { /* Repeat until all data transferred */\r
+ if (((WORD)fs->fptr % 512) == 0) { /* On the sector boundary? */\r
+ cs = (BYTE)(fs->fptr / 512 & (fs->csize - 1)); /* Sector offset in the cluster */\r
+ if (!cs) { /* On the cluster boundary? */\r
+ clst = (fs->fptr == 0) ? /* On the top of the file? */\r
+ fs->org_clust : get_fat(fs->curr_clust);\r
+ if (clst <= 1) goto fw_abort;\r
+ fs->curr_clust = clst; /* Update current cluster */\r
+ }\r
+ sect = clust2sect(fs->curr_clust); /* Get current sector */\r
+ if (!sect) goto fw_abort;\r
+ fs->dsect = sect + cs;\r
+ if (disk_writep(0, fs->dsect)) goto fw_abort; /* Initiate a sector write operation */\r
+ fs->flag |= FA__WIP;\r
+ }\r
+ wcnt = 512 - ((WORD)fs->fptr % 512); /* Number of bytes to write to the sector */\r
+ if (wcnt > btw) wcnt = btw;\r
+ if (disk_writep(p, wcnt)) goto fw_abort; /* Send data to the sector */\r
+ fs->fptr += wcnt; p += wcnt; /* Update pointers and counters */\r
+ btw -= wcnt; *bw += wcnt;\r
+ if (((WORD)fs->fptr % 512) == 0) {\r
+ if (disk_writep(0, 0)) goto fw_abort; /* Finalize the currtent secter write operation */\r
+ fs->flag &= ~FA__WIP;\r
+ }\r
+ }\r
+\r
+ return FR_OK;\r
+\r
+fw_abort:\r
+ fs->flag = 0;\r
+ return FR_DISK_ERR;\r
+}\r
+#endif\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Seek File R/W Pointer */\r
+/*-----------------------------------------------------------------------*/\r
+#if _USE_LSEEK\r
+\r
+FRESULT pf_lseek (\r
+ DWORD ofs /* File pointer from top of file */\r
+)\r
+{\r
+ CLUST clst;\r
+ DWORD bcs, sect, ifptr;\r
+ FATFS *fs = FatFs;\r
+\r
+\r
+ if (!fs) return FR_NOT_ENABLED; /* Check file system */\r
+ if (!(fs->flag & FA_OPENED)) /* Check if opened */\r
+ return FR_NOT_OPENED;\r
+\r
+ if (ofs > fs->fsize) ofs = fs->fsize; /* Clip offset with the file size */\r
+ ifptr = fs->fptr;\r
+ fs->fptr = 0;\r
+ if (ofs > 0) {\r
+ bcs = (DWORD)fs->csize * 512; /* Cluster size (byte) */\r
+ if (ifptr > 0 &&\r
+ (ofs - 1) / bcs >= (ifptr - 1) / bcs) { /* When seek to same or following cluster, */\r
+ fs->fptr = (ifptr - 1) & ~(bcs - 1); /* start from the current cluster */\r
+ ofs -= fs->fptr;\r
+ clst = fs->curr_clust;\r
+ } else { /* When seek to back cluster, */\r
+ clst = fs->org_clust; /* start from the first cluster */\r
+ fs->curr_clust = clst;\r
+ }\r
+ while (ofs > bcs) { /* Cluster following loop */\r
+ clst = get_fat(clst); /* Follow cluster chain */\r
+ if (clst <= 1 || clst >= fs->n_fatent) goto fe_abort;\r
+ fs->curr_clust = clst;\r
+ fs->fptr += bcs;\r
+ ofs -= bcs;\r
+ }\r
+ fs->fptr += ofs;\r
+ sect = clust2sect(clst); /* Current sector */\r
+ if (!sect) goto fe_abort;\r
+ fs->dsect = sect + (fs->fptr / 512 & (fs->csize - 1));\r
+ }\r
+\r
+ return FR_OK;\r
+\r
+fe_abort:\r
+ fs->flag = 0;\r
+ return FR_DISK_ERR;\r
+}\r
+#endif\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Create a Directroy Object */\r
+/*-----------------------------------------------------------------------*/\r
+#if _USE_DIR\r
+\r
+FRESULT pf_opendir (\r
+ DIR *dj, /* Pointer to directory object to create */\r
+ const char *path /* Pointer to the directory path */\r
+)\r
+{\r
+ FRESULT res;\r
+ BYTE sp[12], dir[32];\r
+ FATFS *fs = FatFs;\r
+\r
+\r
+ if (!fs) { /* Check file system */\r
+ res = FR_NOT_ENABLED;\r
+ } else {\r
+ dj->fn = sp;\r
+ res = follow_path(dj, dir, path); /* Follow the path to the directory */\r
+ if (res == FR_OK) { /* Follow completed */\r
+ if (dir[0]) { /* It is not the root dir */\r
+ if (dir[DIR_Attr] & AM_DIR) /* The object is a directory */\r
+ dj->sclust = LD_CLUST(dir);\r
+ else /* The object is not a directory */\r
+ res = FR_NO_PATH;\r
+ }\r
+ if (res == FR_OK)\r
+ res = dir_rewind(dj); /* Rewind dir */\r
+ }\r
+ if (res == FR_NO_FILE) res = FR_NO_PATH;\r
+ }\r
+\r
+ return res;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Read Directory Entry in Sequense */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT pf_readdir (\r
+ DIR *dj, /* Pointer to the open directory object */\r
+ FILINFO *fno /* Pointer to file information to return */\r
+)\r
+{\r
+ FRESULT res;\r
+ BYTE sp[12], dir[32];\r
+ FATFS *fs = FatFs;\r
+\r
+\r
+ if (!fs) { /* Check file system */\r
+ res = FR_NOT_ENABLED;\r
+ } else {\r
+ dj->fn = sp;\r
+ if (!fno) {\r
+ res = dir_rewind(dj);\r
+ } else {\r
+ res = dir_read(dj, dir);\r
+ if (res == FR_NO_FILE) {\r
+ dj->sect = 0;\r
+ res = FR_OK;\r
+ }\r
+ if (res == FR_OK) { /* A valid entry is found */\r
+ get_fileinfo(dj, dir, fno); /* Get the object information */\r
+ res = dir_next(dj); /* Increment index for next */\r
+ if (res == FR_NO_FILE) {\r
+ dj->sect = 0;\r
+ res = FR_OK;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ return res;\r
+}\r
+\r
+#endif /* _USE_DIR */\r
+\r