Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. /*---------------------------------------------------------------------------/
  2. /  Petit FatFs - FAT file system module include file  R0.03a
  3. /----------------------------------------------------------------------------/
  4. / Petit FatFs module is an open source software to implement FAT file system to
  5. / small embedded systems. This is a free software and is opened for education,
  6. / research and commercial developments under license policy of following trems.
  7. /
  8. /  Copyright (C) 2019, ChaN, all right reserved.
  9. /
  10. / * The Petit FatFs module is a free software and there is NO WARRANTY.
  11. / * No restriction on use. You can use, modify and redistribute it for
  12. /   personal, non-profit or commercial use UNDER YOUR RESPONSIBILITY.
  13. / * Redistributions of source code must retain the above copyright notice.
  14. /
  15. /----------------------------------------------------------------------------*/
  16.  
  17. #ifndef PF_DEFINED
  18. #define PF_DEFINED      8088    /* Revision ID */
  19.  
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23.  
  24. #include "pffconf.h"
  25.  
  26. #if PF_DEFINED != PFCONF_DEF
  27. #error Wrong configuration file (pffconf.h).
  28. #endif
  29.  
  30.  
  31. /* Integer types used for FatFs API */
  32.  
  33. #if defined(_WIN32)     /* Main development platform */
  34. #include <windows.h>
  35. #elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus)        /* C99 or later */
  36. #include <stdint.h>
  37. typedef unsigned int    UINT;   /* int must be 16-bit or 32-bit */
  38. typedef unsigned char   BYTE;   /* char must be 8-bit */
  39. typedef uint16_t                WORD;   /* 16-bit unsigned integer */
  40. typedef uint16_t                WCHAR;  /* 16-bit unsigned integer */
  41. typedef uint32_t                DWORD;  /* 32-bit unsigned integer */
  42. #else   /* Earlier than C99 */
  43. typedef unsigned int    UINT;   /* int must be 16-bit or 32-bit */
  44. typedef unsigned char   BYTE;   /* char must be 8-bit */
  45. typedef unsigned short  WORD;   /* 16-bit unsigned integer */
  46. typedef unsigned short  WCHAR;  /* 16-bit unsigned integer */
  47. typedef unsigned long   DWORD;  /* 32-bit unsigned integer */
  48. #endif
  49. #define PF_INTDEF 1
  50.  
  51.  
  52. #if PF_FS_FAT32
  53. #define CLUST   DWORD
  54. #else
  55. #define CLUST   WORD
  56. #endif
  57.  
  58.  
  59. /* File system object structure */
  60.  
  61. typedef struct {
  62.         BYTE    fs_type;        /* FAT sub type */
  63.         BYTE    flag;           /* File status flags */
  64.         BYTE    csize;          /* Number of sectors per cluster */
  65.         BYTE    pad1;
  66.         WORD    n_rootdir;      /* Number of root directory entries (0 on FAT32) */
  67.         CLUST   n_fatent;       /* Number of FAT entries (= number of clusters + 2) */
  68.         DWORD   fatbase;        /* FAT start sector */
  69.         DWORD   dirbase;        /* Root directory start sector (Cluster# on FAT32) */
  70.         DWORD   database;       /* Data start sector */
  71.         DWORD   fptr;           /* File R/W pointer */
  72.         DWORD   fsize;          /* File size */
  73.         CLUST   org_clust;      /* File start cluster */
  74.         CLUST   curr_clust;     /* File current cluster */
  75.         DWORD   dsect;          /* File current data sector */
  76. } FATFS;
  77.  
  78.  
  79.  
  80. /* Directory object structure */
  81.  
  82. typedef struct {
  83.         WORD    index;          /* Current read/write index number */
  84.         BYTE*   fn;                     /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
  85.         CLUST   sclust;         /* Table start cluster (0:Static table) */
  86.         CLUST   clust;          /* Current cluster */
  87.         DWORD   sect;           /* Current sector */
  88. } DIR;
  89.  
  90.  
  91.  
  92. /* File status structure */
  93.  
  94. typedef struct {
  95.         DWORD   fsize;          /* File size */
  96.         WORD    fdate;          /* Last modified date */
  97.         WORD    ftime;          /* Last modified time */
  98.         BYTE    fattrib;        /* Attribute */
  99.         char    fname[13];      /* File name */
  100. } FILINFO;
  101.  
  102.  
  103.  
  104. /* File function return code (FRESULT) */
  105.  
  106. typedef enum {
  107.         FR_OK = 0,                      /* 0 */
  108.         FR_DISK_ERR,            /* 1 */
  109.         FR_NOT_READY,           /* 2 */
  110.         FR_NO_FILE,                     /* 3 */
  111.         FR_NOT_OPENED,          /* 4 */
  112.         FR_NOT_ENABLED,         /* 5 */
  113.         FR_NO_FILESYSTEM        /* 6 */
  114. } FRESULT;
  115.  
  116.  
  117.  
  118. /*--------------------------------------------------------------*/
  119. /* Petit FatFs module application interface                     */
  120.  
  121. FRESULT pf_mount (FATFS* fs);                                                           /* Mount/Unmount a logical drive */
  122. FRESULT pf_open (const char* path);                                                     /* Open a file */
  123. FRESULT pf_read (void* buff, UINT btr, UINT* br);                       /* Read data from the open file */
  124. FRESULT pf_write (const void* buff, UINT btw, UINT* bw);        /* Write data to the open file */
  125. FRESULT pf_lseek (DWORD ofs);                                                           /* Move file pointer of the open file */
  126. FRESULT pf_opendir (DIR* dj, const char* path);                         /* Open a directory */
  127. FRESULT pf_readdir (DIR* dj, FILINFO* fno);                                     /* Read a directory item from the open directory */
  128.  
  129.  
  130.  
  131. /*--------------------------------------------------------------*/
  132. /* Flags and offset address                                     */
  133.  
  134.  
  135. /* File status flag (FATFS.flag) */
  136. #define FA_OPENED       0x01
  137. #define FA_WPRT         0x02
  138. #define FA__WIP         0x40
  139.  
  140.  
  141. /* FAT sub type (FATFS.fs_type) */
  142. #define FS_FAT12        1
  143. #define FS_FAT16        2
  144. #define FS_FAT32        3
  145.  
  146.  
  147. /* File attribute bits for directory entry */
  148.  
  149. #define AM_RDO  0x01    /* Read only */
  150. #define AM_HID  0x02    /* Hidden */
  151. #define AM_SYS  0x04    /* System */
  152. #define AM_VOL  0x08    /* Volume label */
  153. #define AM_LFN  0x0F    /* LFN entry */
  154. #define AM_DIR  0x10    /* Directory */
  155. #define AM_ARC  0x20    /* Archive */
  156. #define AM_MASK 0x3F    /* Mask of defined bits */
  157.  
  158.  
  159. #ifdef __cplusplus
  160. }
  161. #endif
  162.  
  163. #endif /* _PFATFS */
  164.