Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly using fs:: namespace in SD & SDFS #8493

Merged
merged 3 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions libraries/SD/src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

class SDClass {
public:
boolean begin(uint8_t csPin, uint32_t cfg = SPI_HALF_SPEED) {
SDFS.setConfig(SDFSConfig(csPin, cfg));
bool begin(uint8_t csPin, uint32_t cfg = SPI_HALF_SPEED) {
SDFS.setConfig(SDFSConfig(csPin, cfg));
return (boolean)SDFS.begin();
}

Expand All @@ -44,19 +44,19 @@ class SDClass {
}
}

File open(const char *filename, uint8_t mode = FILE_READ) {
fs::File open(const char *filename, uint8_t mode = FILE_READ) {
return SDFS.open(filename, getMode(mode));
}

File open(const char *filename, const char *mode) {
fs::File open(const char *filename, const char *mode) {
return SDFS.open(filename, mode);
}

File open(const String &filename, uint8_t mode = FILE_READ) {
fs::File open(const String &filename, uint8_t mode = FILE_READ) {
return open(filename.c_str(), mode);
}

File open(const String &filename, const char *mode) {
fs::File open(const String &filename, const char *mode) {
return open(filename.c_str(), mode);
}

Expand Down
55 changes: 26 additions & 29 deletions libraries/SDFS/src/SDFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,17 @@
*/
#include <limits>
#include <assert.h>
#include "FS.h"
#include "FSImpl.h"
#include <FSImpl.h>
#include "debug.h"
#include <SPI.h>
#include <SdFat.h>
#include <FS.h>

using namespace fs;

namespace sdfs {

class SDFSFileImpl;
class SDFSDirImpl;
class SDFSConfig : public FSConfig
class SDFSConfig : public fs::FSConfig
{
public:
static constexpr uint32_t FSId = 0x53444653;
Expand Down Expand Up @@ -72,26 +69,26 @@ class SDFSConfig : public FSConfig
uint32_t _spiSettings;
};

class SDFSImpl : public FSImpl
class SDFSImpl : public fs::FSImpl
{
public:
SDFSImpl() : _mounted(false)
{
}

FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) override;
fs::FileImplPtr open(const char* path, fs::OpenMode openMode, fs::AccessMode accessMode) override;

bool exists(const char* path) override {
return _mounted ? _fs.exists(path) : false;
}

DirImplPtr openDir(const char* path) override;
fs::DirImplPtr openDir(const char* path) override;

bool rename(const char* pathFrom, const char* pathTo) override {
return _mounted ? _fs.rename(pathFrom, pathTo) : false;
}

bool info64(FSInfo64& info) override {
bool info64(fs::FSInfo64& info) override {
if (!_mounted) {
DEBUGV("SDFS::info: FS not mounted\n");
return false;
Expand All @@ -105,8 +102,8 @@ class SDFSImpl : public FSImpl
return true;
}

bool info(FSInfo& info) override {
FSInfo64 i;
bool info(fs::FSInfo& info) override {
fs::FSInfo64 i;
if (!info64(i)) {
return false;
}
Expand Down Expand Up @@ -137,7 +134,7 @@ class SDFSImpl : public FSImpl
return _mounted ?_fs.rmdir(path) : false;
}

bool setConfig(const FSConfig &cfg) override
bool setConfig(const fs::FSConfig &cfg) override
{
if ((cfg._type != SDFSConfig::FSId) || _mounted) {
DEBUGV("SDFS::setConfig: invalid config or already mounted\n");
Expand Down Expand Up @@ -234,22 +231,22 @@ class SDFSImpl : public FSImpl
}


static uint8_t _getFlags(OpenMode openMode, AccessMode accessMode) {
static uint8_t _getFlags(fs::OpenMode openMode, fs::AccessMode accessMode) {
uint8_t mode = 0;
if (openMode & OM_CREATE) {
if (openMode & fs::OM_CREATE) {
mode |= O_CREAT;
}
if (openMode & OM_APPEND) {
if (openMode & fs::OM_APPEND) {
mode |= O_AT_END;
}
if (openMode & OM_TRUNCATE) {
if (openMode & fs::OM_TRUNCATE) {
mode |= O_TRUNC;
}
if ((accessMode & (AM_READ | AM_WRITE)) == (AM_READ | AM_WRITE)) {
if ((accessMode & (fs::AM_READ | fs::AM_WRITE)) == (fs::AM_READ | fs::AM_WRITE)) {
mode |= O_RDWR;
} else if (accessMode & AM_READ) {
} else if (accessMode & fs::AM_READ) {
mode |= O_READ;
} else if (accessMode & AM_WRITE) {
} else if (accessMode & fs::AM_WRITE) {
mode |= O_WRITE;
}
return mode;
Expand All @@ -261,7 +258,7 @@ class SDFSImpl : public FSImpl
};


class SDFSFileImpl : public FileImpl
class SDFSFileImpl : public fs::FileImpl
{
public:
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<File32> fd, const char *name)
Expand Down Expand Up @@ -299,22 +296,22 @@ class SDFSFileImpl : public FileImpl
}
}

bool seek(uint32_t pos, SeekMode mode) override
bool seek(uint32_t pos, fs::SeekMode mode) override
{
if (!_opened) {
return false;
}
switch (mode) {
case SeekSet:
case fs::SeekSet:
return _fd->seekSet(pos);
case SeekEnd:
case fs::SeekEnd:
return _fd->seekEnd(-pos); // TODO again, odd from POSIX
case SeekCur:
case fs::SeekCur:
return _fd->seekCur(pos);
default:
// Should not be hit, we've got an invalid seek mode
DEBUGV("SDFSFileImpl::seek: invalid seek mode %d\n", mode);
assert((mode==SeekSet) || (mode==SeekEnd) || (mode==SeekCur)); // Will fail and give meaningful assert message
assert((mode==fs::SeekSet) || (mode==fs::SeekEnd) || (mode==fs::SeekCur)); // Will fail and give meaningful assert message
return false;
}
}
Expand Down Expand Up @@ -406,7 +403,7 @@ class SDFSFileImpl : public FileImpl
bool _opened;
};

class SDFSDirImpl : public DirImpl
class SDFSDirImpl : public fs::DirImpl
{
public:
SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<File32> dir, const char *dirPath = nullptr)
Expand All @@ -423,10 +420,10 @@ class SDFSDirImpl : public DirImpl
_dir->close();
}

FileImplPtr openFile(OpenMode openMode, AccessMode accessMode) override
fs::FileImplPtr openFile(fs::OpenMode openMode, fs::AccessMode accessMode) override
{
if (!_valid) {
return FileImplPtr();
return fs::FileImplPtr();
}
// MAX_PATH on FAT32 is potentially 260 bytes per most implementations
char tmpName[260];
Expand Down Expand Up @@ -532,7 +529,7 @@ class SDFSDirImpl : public DirImpl
}; // namespace sdfs

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SDFS)
extern FS SDFS;
extern fs::FS SDFS;
using sdfs::SDFSConfig;
#endif

Expand Down