36 #if defined(BOARD_SDCARD_CS_PIN) || defined(BOARD_DATAFLASH_FATFS) 53 #define O_RDONLY FA_READ 54 #define O_WRITE FA_WRITE 55 #define O_RDWR FA_WRITE 56 #define O_CREAT FA_CREATE_NEW // создать новый, если существует то ошибка 57 #define O_TRUNC FA_CREATE_ALWAYS // переписать старый 59 #define O_CLOEXEC 0x40 66 #define EEXIST FR_EXIST 67 #define EACCES FR_DENIED 68 #define EISDIR FR_IS_DIR 69 #define ENOENT FR_NO_FILE 73 uint8_t
const LS_DATE = 1;
75 uint8_t
const LS_SIZE = 2;
77 uint8_t
const LS_R = 4;
79 typedef void (*
cb_putc)(
char c);
85 File(
const char*
name);
86 size_t write(uint8_t);
87 size_t write(
const uint8_t *buf,
size_t size);
88 size_t write(
const char *buf,
size_t size);
95 int read(
void* buf,
size_t len);
96 uint8_t seek(uint32_t pos);
100 inline operator bool()
const {
return (_name ==
NULL)? FALSE : TRUE; }
103 char* fullname(
void) {
return _name;};
104 uint8_t isDirectory();
105 File openNextFile(uint8_t mode = FILE_READ);
106 void rewindDirectory(
void);
108 size_t print(
const char* data);
110 size_t println(
const char* data);
113 void ls(
cb_putc cb, uint8_t flags, uint8_t indent = 0);
114 static void printFatDate(uint16_t fatDate,
cb_putc cb);
115 static void printFatTime(uint16_t fatTime,
cb_putc cb);
116 static void printTwoDigits(uint8_t
v,
cb_putc cb);
117 static void printNumber(int16_t n,
cb_putc cb);
118 static void printStr(
const char *s,
cb_putc cb);
122 inline uint32_t firstCluster(){
return is_dir ? _d.dir.obj.sclust : _d.fil.obj.sclust; }
124 static void syncAll();
125 static void addOpenFile(
FIL *
f);
126 static void removeOpenFile(
FIL *
f);
147 static FIL* openFiles[16];
148 static uint8_t num_openFiles;
158 static File
open(
const char *filepath, uint8_t mode);
159 static File
open(
const char *filepath);
160 static uint8_t exists(
const char *filepath);
161 static uint8_t
mkdir(
const char *filepath);
162 static uint8_t
remove(
const char *filepath);
163 static uint8_t
rmdir(
const char *filepath);
165 static uint32_t getfree(
const char *filepath, uint32_t * fssize);
166 static uint8_t
stat(
const char *filepath,
FILINFO* fno);
167 static uint8_t format(
const char *filepath);
171 void inline sync() { File::syncAll(); };
175 static inline Sd2Card *getCard() {
return &_card; }
176 static inline SdFatFs *getVolume() {
return &_fatFs; }
180 static const char * strError(
FRESULT err){
return SdFatFs::strError(err); }
183 static Sd2Card _card;
184 static SdFatFs _fatFs;
void(* cb_putc)(uint8_t c)
int open(const char *pathname, int flags)
POSIX Open a file with integer mode flags.
ssize_t write(int fd, const void *buf, size_t count)
POSIX Write count bytes from *buf to fileno fd.
int rmdir(const char *pathname)
POSIX delete a directory.
ssize_t read(int fd, void *buf, size_t count)
POSIX read count bytes from *buf to fileno fd.
int close(int fileno)
POSIX Close a file with fileno handel.
void sync(void)
POSIX Sync all pending file changes and metadata on ALL files.
Miscellaneous utility macros and procedures.
int mkdir(const char *pathname, mode_t mode)
POSIX make a directory.
static int is_dir(const char *path)
int stat(const char *name, struct stat *buf)
Display struct stat, from POSIX stat(0 or fstat(), in ASCII. NOT POSIX.