Soldered SD Card Arduino Library 1.0.0
Easily read and write files to and form the SD card breakout! A fork of the original SDFat library by Bill Greiman.
Loading...
Searching...
No Matches
FatVolume.h
Go to the documentation of this file.
1
25#ifndef FatVolume_h
26#define FatVolume_h
27#include "FatFile.h"
28#include "FatPartition.h"
33//------------------------------------------------------------------------------
38class FatVolume : public FatPartition
39{
40 public:
48 bool begin(BlockDevice *dev, bool setCwv = true, uint8_t part = 1)
49 {
50 if (!init(dev, part))
51 {
52 return false;
53 }
54 if (!chdir())
55 {
56 return false;
57 }
58 if (setCwv || !m_cwv)
59 {
60 m_cwv = this;
61 }
62 return true;
63 }
65 void chvol()
66 {
67 m_cwv = this;
68 }
69
74 bool chdir()
75 {
76 m_vwd.close();
77 return m_vwd.openRoot(this);
78 }
84 bool chdir(const char *path);
85
86 //----------------------------------------------------------------------------
94 bool exists(const char *path)
95 {
96 FatFile tmp;
97 return tmp.open(this, path, O_RDONLY);
98 }
99 //----------------------------------------------------------------------------
114 bool ls(print_t *pr, uint8_t flags = 0)
115 {
116 return m_vwd.ls(pr, flags);
117 }
118 //----------------------------------------------------------------------------
135 bool ls(print_t *pr, const char *path, uint8_t flags)
136 {
137 FatFile dir;
138 return dir.open(this, path, O_RDONLY) && dir.ls(pr, flags);
139 }
140 //----------------------------------------------------------------------------
149 bool mkdir(const char *path, bool pFlag = true)
150 {
151 FatFile sub;
152 return sub.mkdir(vwd(), path, pFlag);
153 }
154 //----------------------------------------------------------------------------
161 File32 open(const char *path, oflag_t oflag = O_RDONLY)
162 {
163 File32 tmpFile;
164 tmpFile.open(this, path, oflag);
165 return tmpFile;
166 }
167 //----------------------------------------------------------------------------
174 bool remove(const char *path)
175 {
176 FatFile tmp;
177 return tmp.open(this, path, O_WRONLY) && tmp.remove();
178 }
179 //----------------------------------------------------------------------------
194 bool rename(const char *oldPath, const char *newPath)
195 {
196 FatFile file;
197 return file.open(vwd(), oldPath, O_RDONLY) && file.rename(vwd(), newPath);
198 }
199 //----------------------------------------------------------------------------
208 bool rmdir(const char *path)
209 {
210 FatFile sub;
211 return sub.open(this, path, O_RDONLY) && sub.rmdir();
212 }
213 //----------------------------------------------------------------------------
222 bool truncate(const char *path, uint32_t length)
223 {
224 FatFile file;
225 return file.open(this, path, O_WRONLY) && file.truncate(length);
226 }
227#if ENABLE_ARDUINO_SERIAL
240 bool ls(uint8_t flags = 0)
241 {
242 return ls(&Serial, flags);
243 }
258 bool ls(const char *path, uint8_t flags = 0)
259 {
260 return ls(&Serial, path, flags);
261 }
262#endif // ENABLE_ARDUINO_SERIAL
263#if ENABLE_ARDUINO_STRING
264 //----------------------------------------------------------------------------
270 bool chdir(const String &path)
271 {
272 return chdir(path.c_str());
273 }
281 bool exists(const String &path)
282 {
283 return exists(path.c_str());
284 }
293 bool mkdir(const String &path, bool pFlag = true)
294 {
295 return mkdir(path.c_str(), pFlag);
296 }
303 File32 open(const String &path, oflag_t oflag = O_RDONLY)
304 {
305 return open(path.c_str(), oflag);
306 }
313 bool remove(const String &path)
314 {
315 return remove(path.c_str());
316 }
331 bool rename(const String &oldPath, const String &newPath)
332 {
333 return rename(oldPath.c_str(), newPath.c_str());
334 }
343 bool rmdir(const String &path)
344 {
345 return rmdir(path.c_str());
346 }
355 bool truncate(const String &path, uint32_t length)
356 {
357 return truncate(path.c_str(), length);
358 }
359#endif // ENABLE_ARDUINO_STRING
360
361 private:
362 friend FatFile;
363 static FatVolume *cwv()
364 {
365 return m_cwv;
366 }
368 {
369 return &m_vwd;
370 }
373};
374#endif // FatVolume_h
FatFile class.
FatPartition class.
int oflag_t
Definition FsApiConstants.h:45
Print print_t
Definition SysCall.h:66
BlockDeviceInterface class.
Definition BlockDeviceInterface.h:39
Basic file class.
Definition FatFile.h:112
bool rename(const char *newPath)
Definition FatFile.cpp:1070
bool ls(print_t *pr, uint8_t flags=0, uint8_t indent=0)
Definition FatFilePrint.cpp:91
bool truncate()
Definition FatFile.cpp:1519
bool openRoot(FatVolume *vol)
Definition FatFile.cpp:776
bool rmdir()
Definition FatFile.cpp:1198
bool mkdir(FatFile *dir, const char *path, bool pFlag=true)
Definition FatFile.cpp:364
bool remove()
Definition FatFileLFN.cpp:699
bool open(FatVolume *vol, const char *path, oflag_t oflag)
Definition FatFile.cpp:499
bool close()
Definition FatFile.cpp:124
Access FAT16 and FAT32 partitions on raw file devices.
Definition FatPartition.h:67
bool init(BlockDevice *dev, uint8_t part=1)
Definition FatPartition.cpp:468
Integration class for the FatLib library.
Definition FatVolume.h:39
File32 open(const String &path, oflag_t oflag=O_RDONLY)
Definition FatVolume.h:303
bool rmdir(const String &path)
Definition FatVolume.h:343
bool exists(const char *path)
Definition FatVolume.h:94
static FatVolume * m_cwv
Definition FatVolume.h:371
File32 open(const char *path, oflag_t oflag=O_RDONLY)
Definition FatVolume.h:161
void chvol()
Definition FatVolume.h:65
friend FatFile
Definition FatVolume.h:362
FatFile * vwd()
Definition FatVolume.h:367
bool ls(const char *path, uint8_t flags=0)
Definition FatVolume.h:258
bool rename(const char *oldPath, const char *newPath)
Definition FatVolume.h:194
bool chdir()
Definition FatVolume.h:74
static FatVolume * cwv()
Definition FatVolume.h:363
bool truncate(const char *path, uint32_t length)
Definition FatVolume.h:222
FatFile m_vwd
Definition FatVolume.h:372
bool truncate(const String &path, uint32_t length)
Definition FatVolume.h:355
bool remove(const String &path)
Definition FatVolume.h:313
bool rename(const String &oldPath, const String &newPath)
Definition FatVolume.h:331
bool mkdir(const String &path, bool pFlag=true)
Definition FatVolume.h:293
bool remove(const char *path)
Definition FatVolume.h:174
bool chdir(const String &path)
Definition FatVolume.h:270
bool ls(print_t *pr, const char *path, uint8_t flags)
Definition FatVolume.h:135
bool ls(uint8_t flags=0)
Definition FatVolume.h:240
bool mkdir(const char *path, bool pFlag=true)
Definition FatVolume.h:149
bool ls(print_t *pr, uint8_t flags=0)
Definition FatVolume.h:114
bool rmdir(const char *path)
Definition FatVolume.h:208
bool begin(BlockDevice *dev, bool setCwv=true, uint8_t part=1)
Definition FatVolume.h:48
bool exists(const String &path)
Definition FatVolume.h:281
FAT16/FAT32 file with Arduino Stream.
Definition FatFile.h:1104