]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - fatfs/src/ff.h
Import fatfs R0.10b
[z180-stamp.git] / fatfs / src / ff.h
diff --git a/fatfs/src/ff.h b/fatfs/src/ff.h
new file mode 100644 (file)
index 0000000..9894921
--- /dev/null
@@ -0,0 +1,342 @@
+/*---------------------------------------------------------------------------/\r
+/  FatFs - FAT file system module include file  R0.10b    (C)ChaN, 2014\r
+/----------------------------------------------------------------------------/\r
+/ FatFs module is a generic FAT file system module for small embedded systems.\r
+/ This is a free software that opened for education, research and commercial\r
+/ developments under license policy of following terms.\r
+/\r
+/  Copyright (C) 2014, ChaN, all right reserved.\r
+/\r
+/ * The 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 product UNDER YOUR RESPONSIBILITY.\r
+/ * Redistributions of source code must retain the above copyright notice.\r
+/\r
+/----------------------------------------------------------------------------*/\r
+\r
+#ifndef _FATFS\r
+#define _FATFS 8051    /* Revision ID */\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include "integer.h"   /* Basic integer types */\r
+#include "ffconf.h"            /* FatFs configuration options */\r
+\r
+#if _FATFS != _FFCONF\r
+#error Wrong configuration file (ffconf.h).\r
+#endif\r
+\r
+\r
+\r
+/* Definitions of volume management */\r
+\r
+#if _MULTI_PARTITION           /* Multiple partition configuration */\r
+typedef struct {\r
+       BYTE pd;        /* Physical drive number */\r
+       BYTE pt;        /* Partition: 0:Auto detect, 1-4:Forced partition) */\r
+} PARTITION;\r
+extern PARTITION VolToPart[];  /* Volume - Partition resolution table */\r
+#define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */\r
+#define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */\r
+\r
+#else                                                  /* Single partition configuration */\r
+#define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */\r
+#define LD2PT(vol) 0                   /* Find first valid partition or in SFD */\r
+\r
+#endif\r
+\r
+\r
+\r
+/* Type of path name strings on FatFs API */\r
+\r
+#if _LFN_UNICODE                       /* Unicode string */\r
+#if !_USE_LFN\r
+#error _LFN_UNICODE must be 0 at non-LFN cfg.\r
+#endif\r
+#ifndef _INC_TCHAR\r
+typedef WCHAR TCHAR;\r
+#define _T(x) L ## x\r
+#define _TEXT(x) L ## x\r
+#endif\r
+\r
+#else                                          /* ANSI/OEM string */\r
+#ifndef _INC_TCHAR\r
+typedef char TCHAR;\r
+#define _T(x) x\r
+#define _TEXT(x) x\r
+#endif\r
+\r
+#endif\r
+\r
+\r
+\r
+/* File system object structure (FATFS) */\r
+\r
+typedef struct {\r
+       BYTE    fs_type;                /* FAT sub-type (0:Not mounted) */\r
+       BYTE    drv;                    /* Physical drive number */\r
+       BYTE    csize;                  /* Sectors per cluster (1,2,4...128) */\r
+       BYTE    n_fats;                 /* Number of FAT copies (1 or 2) */\r
+       BYTE    wflag;                  /* win[] flag (b0:dirty) */\r
+       BYTE    fsi_flag;               /* FSINFO flags (b7:disabled, b0:dirty) */\r
+       WORD    id;                             /* File system mount ID */\r
+       WORD    n_rootdir;              /* Number of root directory entries (FAT12/16) */\r
+#if _MAX_SS != _MIN_SS\r
+       WORD    ssize;                  /* Bytes per sector (512, 1024, 2048 or 4096) */\r
+#endif\r
+#if _FS_REENTRANT\r
+       _SYNC_t sobj;                   /* Identifier of sync object */\r
+#endif\r
+#if !_FS_READONLY\r
+       DWORD   last_clust;             /* Last allocated cluster */\r
+       DWORD   free_clust;             /* Number of free clusters */\r
+#endif\r
+#if _FS_RPATH\r
+       DWORD   cdir;                   /* Current directory start cluster (0:root) */\r
+#endif\r
+       DWORD   n_fatent;               /* Number of FAT entries, = number of clusters + 2 */\r
+       DWORD   fsize;                  /* Sectors per FAT */\r
+       DWORD   volbase;                /* Volume start sector */\r
+       DWORD   fatbase;                /* FAT start sector */\r
+       DWORD   dirbase;                /* Root directory start sector (FAT32:Cluster#) */\r
+       DWORD   database;               /* Data start sector */\r
+       DWORD   winsect;                /* Current sector appearing in the win[] */\r
+       BYTE    win[_MAX_SS];   /* Disk access window for Directory, FAT (and file data at tiny cfg) */\r
+} FATFS;\r
+\r
+\r
+\r
+/* File object structure (FIL) */\r
+\r
+typedef struct {\r
+       FATFS*  fs;                             /* Pointer to the related file system object (**do not change order**) */\r
+       WORD    id;                             /* Owner file system mount ID (**do not change order**) */\r
+       BYTE    flag;                   /* Status flags */\r
+       BYTE    err;                    /* Abort flag (error code) */\r
+       DWORD   fptr;                   /* File read/write pointer (Zeroed on file open) */\r
+       DWORD   fsize;                  /* File size */\r
+       DWORD   sclust;                 /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */\r
+       DWORD   clust;                  /* Current cluster of fpter (not valid when fprt is 0) */\r
+       DWORD   dsect;                  /* Sector number appearing in buf[] (0:invalid) */\r
+#if !_FS_READONLY\r
+       DWORD   dir_sect;               /* Sector number containing the directory entry */\r
+       BYTE*   dir_ptr;                /* Pointer to the directory entry in the win[] */\r
+#endif\r
+#if _USE_FASTSEEK\r
+       DWORD*  cltbl;                  /* Pointer to the cluster link map table (Nulled on file open) */\r
+#endif\r
+#if _FS_LOCK\r
+       UINT    lockid;                 /* File lock ID origin from 1 (index of file semaphore table Files[]) */\r
+#endif\r
+#if !_FS_TINY\r
+       BYTE    buf[_MAX_SS];   /* File private data read/write window */\r
+#endif\r
+} FIL;\r
+\r
+\r
+\r
+/* Directory object structure (DIR) */\r
+\r
+typedef struct {\r
+       FATFS*  fs;                             /* Pointer to the owner file system object (**do not change order**) */\r
+       WORD    id;                             /* Owner file system mount ID (**do not change order**) */\r
+       WORD    index;                  /* Current read/write index number */\r
+       DWORD   sclust;                 /* Table start cluster (0:Root dir) */\r
+       DWORD   clust;                  /* Current cluster */\r
+       DWORD   sect;                   /* Current sector */\r
+       BYTE*   dir;                    /* Pointer to the current SFN entry in the win[] */\r
+       BYTE*   fn;                             /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */\r
+#if _FS_LOCK\r
+       UINT    lockid;                 /* File lock ID (index of file semaphore table Files[]) */\r
+#endif\r
+#if _USE_LFN\r
+       WCHAR*  lfn;                    /* Pointer to the LFN working buffer */\r
+       WORD    lfn_idx;                /* Last matched LFN index number (0xFFFF:No LFN) */\r
+#endif\r
+} DIR;\r
+\r
+\r
+\r
+/* File status structure (FILINFO) */\r
+\r
+typedef struct {\r
+       DWORD   fsize;                  /* File size */\r
+       WORD    fdate;                  /* Last modified date */\r
+       WORD    ftime;                  /* Last modified time */\r
+       BYTE    fattrib;                /* Attribute */\r
+       TCHAR   fname[13];              /* Short file name (8.3 format) */\r
+#if _USE_LFN\r
+       TCHAR*  lfname;                 /* Pointer to the LFN buffer */\r
+       UINT    lfsize;                 /* Size of LFN buffer in TCHAR */\r
+#endif\r
+} FILINFO;\r
+\r
+\r
+\r
+/* File function return code (FRESULT) */\r
+\r
+typedef enum {\r
+       FR_OK = 0,                              /* (0) Succeeded */\r
+       FR_DISK_ERR,                    /* (1) A hard error occurred in the low level disk I/O layer */\r
+       FR_INT_ERR,                             /* (2) Assertion failed */\r
+       FR_NOT_READY,                   /* (3) The physical drive cannot work */\r
+       FR_NO_FILE,                             /* (4) Could not find the file */\r
+       FR_NO_PATH,                             /* (5) Could not find the path */\r
+       FR_INVALID_NAME,                /* (6) The path name format is invalid */\r
+       FR_DENIED,                              /* (7) Access denied due to prohibited access or directory full */\r
+       FR_EXIST,                               /* (8) Access denied due to prohibited access */\r
+       FR_INVALID_OBJECT,              /* (9) The file/directory object is invalid */\r
+       FR_WRITE_PROTECTED,             /* (10) The physical drive is write protected */\r
+       FR_INVALID_DRIVE,               /* (11) The logical drive number is invalid */\r
+       FR_NOT_ENABLED,                 /* (12) The volume has no work area */\r
+       FR_NO_FILESYSTEM,               /* (13) There is no valid FAT volume */\r
+       FR_MKFS_ABORTED,                /* (14) The f_mkfs() aborted due to any parameter error */\r
+       FR_TIMEOUT,                             /* (15) Could not get a grant to access the volume within defined period */\r
+       FR_LOCKED,                              /* (16) The operation is rejected according to the file sharing policy */\r
+       FR_NOT_ENOUGH_CORE,             /* (17) LFN working buffer could not be allocated */\r
+       FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */\r
+       FR_INVALID_PARAMETER    /* (19) Given parameter is invalid */\r
+} FRESULT;\r
+\r
+\r
+\r
+/*--------------------------------------------------------------*/\r
+/* FatFs module application interface                           */\r
+\r
+FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode);                                /* Open or create a file */\r
+FRESULT f_close (FIL* fp);                                                                                     /* Close an open file object */\r
+FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br);                      /* Read data from a file */\r
+FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw);       /* Write data to a file */\r
+FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf);        /* Forward data to the stream */\r
+FRESULT f_lseek (FIL* fp, DWORD ofs);                                                          /* Move file pointer of a file object */\r
+FRESULT f_truncate (FIL* fp);                                                                          /* Truncate file */\r
+FRESULT f_sync (FIL* fp);                                                                                      /* Flush cached data of a writing file */\r
+FRESULT f_opendir (DIR* dp, const TCHAR* path);                                                /* Open a directory */\r
+FRESULT f_closedir (DIR* dp);                                                                          /* Close an open directory */\r
+FRESULT f_readdir (DIR* dp, FILINFO* fno);                                                     /* Read a directory item */\r
+FRESULT f_mkdir (const TCHAR* path);                                                           /* Create a sub directory */\r
+FRESULT f_unlink (const TCHAR* path);                                                          /* Delete an existing file or directory */\r
+FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new);       /* Rename/Move a file or directory */\r
+FRESULT f_stat (const TCHAR* path, FILINFO* fno);                                      /* Get file status */\r
+FRESULT f_chmod (const TCHAR* path, BYTE value, BYTE mask);                    /* Change attribute of the file/dir */\r
+FRESULT f_utime (const TCHAR* path, const FILINFO* fno);                       /* Change times-tamp of the file/dir */\r
+FRESULT f_chdir (const TCHAR* path);                                                           /* Change current directory */\r
+FRESULT f_chdrive (const TCHAR* path);                                                         /* Change current drive */\r
+FRESULT f_getcwd (TCHAR* buff, UINT len);                                                      /* Get current directory */\r
+FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs);    /* Get number of free clusters on the drive */\r
+FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn);      /* Get volume label */\r
+FRESULT f_setlabel (const TCHAR* label);                                                       /* Set volume label */\r
+FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt);                      /* Mount/Unmount a logical drive */\r
+FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au);                         /* Create a file system on the volume */\r
+FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work);                    /* Divide a physical drive into some partitions */\r
+int f_putc (TCHAR c, FIL* fp);                                                                         /* Put a character to the file */\r
+int f_puts (const TCHAR* str, FIL* cp);                                                                /* Put a string to the file */\r
+int f_printf (FIL* fp, const TCHAR* str, ...);                                         /* Put a formatted string to the file */\r
+TCHAR* f_gets (TCHAR* buff, int len, FIL* fp);                                         /* Get a string from the file */\r
+\r
+#define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)\r
+#define f_error(fp) ((fp)->err)\r
+#define f_tell(fp) ((fp)->fptr)\r
+#define f_size(fp) ((fp)->fsize)\r
+\r
+#ifndef EOF\r
+#define EOF (-1)\r
+#endif\r
+\r
+\r
+\r
+\r
+/*--------------------------------------------------------------*/\r
+/* Additional user defined functions                            */\r
+\r
+/* RTC function */\r
+#if !_FS_READONLY\r
+DWORD get_fattime (void);\r
+#endif\r
+\r
+/* Unicode support functions */\r
+#if _USE_LFN                                                   /* Unicode - OEM code conversion */\r
+WCHAR ff_convert (WCHAR chr, UINT dir);        /* OEM-Unicode bidirectional conversion */\r
+WCHAR ff_wtoupper (WCHAR chr);                 /* Unicode upper-case conversion */\r
+#if _USE_LFN == 3                                              /* Memory functions */\r
+void* ff_memalloc (UINT msize);                        /* Allocate memory block */\r
+void ff_memfree (void* mblock);                        /* Free memory block */\r
+#endif\r
+#endif\r
+\r
+/* Sync functions */\r
+#if _FS_REENTRANT\r
+int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj);  /* Create a sync object */\r
+int ff_req_grant (_SYNC_t sobj);                               /* Lock sync object */\r
+void ff_rel_grant (_SYNC_t sobj);                              /* Unlock sync object */\r
+int ff_del_syncobj (_SYNC_t sobj);                             /* Delete a sync object */\r
+#endif\r
+\r
+\r
+\r
+\r
+/*--------------------------------------------------------------*/\r
+/* Flags and offset address                                     */\r
+\r
+\r
+/* File access control and file status flags (FIL.flag) */\r
+\r
+#define        FA_READ                         0x01\r
+#define        FA_OPEN_EXISTING        0x00\r
+\r
+#if !_FS_READONLY\r
+#define        FA_WRITE                        0x02\r
+#define        FA_CREATE_NEW           0x04\r
+#define        FA_CREATE_ALWAYS        0x08\r
+#define        FA_OPEN_ALWAYS          0x10\r
+#define FA__WRITTEN                    0x20\r
+#define FA__DIRTY                      0x40\r
+#endif\r
+\r
+\r
+/* FAT sub type (FATFS.fs_type) */\r
+\r
+#define FS_FAT12       1\r
+#define FS_FAT16       2\r
+#define FS_FAT32       3\r
+\r
+\r
+/* File attribute bits for directory entry */\r
+\r
+#define        AM_RDO  0x01    /* Read only */\r
+#define        AM_HID  0x02    /* Hidden */\r
+#define        AM_SYS  0x04    /* System */\r
+#define        AM_VOL  0x08    /* Volume label */\r
+#define AM_LFN 0x0F    /* LFN entry */\r
+#define AM_DIR 0x10    /* Directory */\r
+#define AM_ARC 0x20    /* Archive */\r
+#define AM_MASK        0x3F    /* Mask of defined bits */\r
+\r
+\r
+/* Fast seek feature */\r
+#define CREATE_LINKMAP 0xFFFFFFFF\r
+\r
+\r
+\r
+/*--------------------------------*/\r
+/* Multi-byte word access macros  */\r
+\r
+#if _WORD_ACCESS == 1  /* Enable word access to the FAT structure */\r
+#define        LD_WORD(ptr)            (WORD)(*(WORD*)(BYTE*)(ptr))\r
+#define        LD_DWORD(ptr)           (DWORD)(*(DWORD*)(BYTE*)(ptr))\r
+#define        ST_WORD(ptr,val)        *(WORD*)(BYTE*)(ptr)=(WORD)(val)\r
+#define        ST_DWORD(ptr,val)       *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)\r
+#else                                  /* Use byte-by-byte access to the FAT structure */\r
+#define        LD_WORD(ptr)            (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))\r
+#define        LD_DWORD(ptr)           (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))\r
+#define        ST_WORD(ptr,val)        *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)\r
+#define        ST_DWORD(ptr,val)       *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* _FATFS */\r