|
-
- #include <SdFat.h>
-
- #if USE_SERIAL_FOR_STD_OUT || !defined(UDR0)
- Print* SdFat::m_stdOut = &Serial;
- #else
- #include <MinimumSerial.h>
- Print* SdFat::m_stdOut = &MiniSerial;
- #endif
-
-
- bool SdFat::begin(uint8_t chipSelectPin, uint8_t sckDivisor) {
- return m_card.begin(chipSelectPin, sckDivisor)
- && m_vol.init(&m_card) && chdir(1);
- }
-
-
- bool SdFat::chdir(bool set_cwd) {
- if (set_cwd) SdBaseFile::setCwd(&m_vwd);
- if (m_vwd.isOpen()) m_vwd.close();
- return m_vwd.openRoot(&m_vol);
- }
-
-
- bool SdFat::chdir(const char *path, bool set_cwd) {
- SdBaseFile dir;
- dir.open(&m_vwd, path, O_READ);
-
- if (!dir.isDir()) goto fail;
- m_vwd = dir;
- if (set_cwd) SdBaseFile::setCwd(&m_vwd);
- return true;
-
- fail:
- return false;
- }
-
-
- void SdFat::chvol() {
- SdBaseFile::setCwd(&m_vwd);
- }
-
-
- bool SdFat::exists(const char* name) {
- return m_vwd.exists(name);
- }
-
-
- void SdFat::ls(uint8_t flags) {
- m_vwd.ls(m_stdOut, flags);
- }
-
-
- void SdFat::ls(const char* path, uint8_t flags) {
- ls(m_stdOut, path, flags);
- }
-
-
- void SdFat::ls(Print* pr, uint8_t flags) {
- m_vwd.ls(pr, flags);
- }
-
- void SdFat::ls(Print* pr, const char* path, uint8_t flags) {
- SdBaseFile dir(path, O_READ);
- dir.ls(pr, flags);
- }
-
-
- bool SdFat::mkdir(const char* path, bool pFlag) {
- SdBaseFile sub;
- return sub.mkdir(&m_vwd, path, pFlag);
- }
-
-
- bool SdFat::remove(const char* path) {
- return SdBaseFile::remove(&m_vwd, path);
- }
-
-
- bool SdFat::rename(const char *oldPath, const char *newPath) {
- SdBaseFile file;
- if (!file.open(oldPath, O_READ)) return false;
- return file.rename(&m_vwd, newPath);
- }
-
-
- bool SdFat::rmdir(const char* path) {
- SdBaseFile sub;
- if (!sub.open(path, O_READ)) return false;
- return sub.rmdir();
- }
-
-
- bool SdFat::truncate(const char* path, uint32_t length) {
- SdBaseFile file;
- if (!file.open(path, O_WRITE)) return false;
- return file.truncate(length);
- }
|