Skip to content

Commit ead5f94

Browse files
authored
Correctly using fs:: namespace in SD & SDFS (#8493)
Remove `using namespace fs;` from SDFS.h Fix everything that depended on it
1 parent fd53a08 commit ead5f94

File tree

2 files changed

+32
-35
lines changed

2 files changed

+32
-35
lines changed

libraries/SD/src/SD.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
class SDClass {
3434
public:
35-
boolean begin(uint8_t csPin, uint32_t cfg = SPI_HALF_SPEED) {
36-
SDFS.setConfig(SDFSConfig(csPin, cfg));
35+
bool begin(uint8_t csPin, uint32_t cfg = SPI_HALF_SPEED) {
36+
SDFS.setConfig(SDFSConfig(csPin, cfg));
3737
return (boolean)SDFS.begin();
3838
}
3939

@@ -44,19 +44,19 @@ class SDClass {
4444
}
4545
}
4646

47-
File open(const char *filename, uint8_t mode = FILE_READ) {
47+
fs::File open(const char *filename, uint8_t mode = FILE_READ) {
4848
return SDFS.open(filename, getMode(mode));
4949
}
5050

51-
File open(const char *filename, const char *mode) {
51+
fs::File open(const char *filename, const char *mode) {
5252
return SDFS.open(filename, mode);
5353
}
5454

55-
File open(const String &filename, uint8_t mode = FILE_READ) {
55+
fs::File open(const String &filename, uint8_t mode = FILE_READ) {
5656
return open(filename.c_str(), mode);
5757
}
5858

59-
File open(const String &filename, const char *mode) {
59+
fs::File open(const String &filename, const char *mode) {
6060
return open(filename.c_str(), mode);
6161
}
6262

libraries/SDFS/src/SDFS.h

+26-29
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,17 @@
2929
*/
3030
#include <limits>
3131
#include <assert.h>
32-
#include "FS.h"
33-
#include "FSImpl.h"
32+
#include <FSImpl.h>
3433
#include "debug.h"
3534
#include <SPI.h>
3635
#include <SdFat.h>
3736
#include <FS.h>
3837

39-
using namespace fs;
40-
4138
namespace sdfs {
4239

4340
class SDFSFileImpl;
4441
class SDFSDirImpl;
45-
class SDFSConfig : public FSConfig
42+
class SDFSConfig : public fs::FSConfig
4643
{
4744
public:
4845
static constexpr uint32_t FSId = 0x53444653;
@@ -72,26 +69,26 @@ class SDFSConfig : public FSConfig
7269
uint32_t _spiSettings;
7370
};
7471

75-
class SDFSImpl : public FSImpl
72+
class SDFSImpl : public fs::FSImpl
7673
{
7774
public:
7875
SDFSImpl() : _mounted(false)
7976
{
8077
}
8178

82-
FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) override;
79+
fs::FileImplPtr open(const char* path, fs::OpenMode openMode, fs::AccessMode accessMode) override;
8380

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

88-
DirImplPtr openDir(const char* path) override;
85+
fs::DirImplPtr openDir(const char* path) override;
8986

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

94-
bool info64(FSInfo64& info) override {
91+
bool info64(fs::FSInfo64& info) override {
9592
if (!_mounted) {
9693
DEBUGV("SDFS::info: FS not mounted\n");
9794
return false;
@@ -105,8 +102,8 @@ class SDFSImpl : public FSImpl
105102
return true;
106103
}
107104

108-
bool info(FSInfo& info) override {
109-
FSInfo64 i;
105+
bool info(fs::FSInfo& info) override {
106+
fs::FSInfo64 i;
110107
if (!info64(i)) {
111108
return false;
112109
}
@@ -137,7 +134,7 @@ class SDFSImpl : public FSImpl
137134
return _mounted ?_fs.rmdir(path) : false;
138135
}
139136

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

236233

237-
static uint8_t _getFlags(OpenMode openMode, AccessMode accessMode) {
234+
static uint8_t _getFlags(fs::OpenMode openMode, fs::AccessMode accessMode) {
238235
uint8_t mode = 0;
239-
if (openMode & OM_CREATE) {
236+
if (openMode & fs::OM_CREATE) {
240237
mode |= O_CREAT;
241238
}
242-
if (openMode & OM_APPEND) {
239+
if (openMode & fs::OM_APPEND) {
243240
mode |= O_AT_END;
244241
}
245-
if (openMode & OM_TRUNCATE) {
242+
if (openMode & fs::OM_TRUNCATE) {
246243
mode |= O_TRUNC;
247244
}
248-
if ((accessMode & (AM_READ | AM_WRITE)) == (AM_READ | AM_WRITE)) {
245+
if ((accessMode & (fs::AM_READ | fs::AM_WRITE)) == (fs::AM_READ | fs::AM_WRITE)) {
249246
mode |= O_RDWR;
250-
} else if (accessMode & AM_READ) {
247+
} else if (accessMode & fs::AM_READ) {
251248
mode |= O_READ;
252-
} else if (accessMode & AM_WRITE) {
249+
} else if (accessMode & fs::AM_WRITE) {
253250
mode |= O_WRITE;
254251
}
255252
return mode;
@@ -261,7 +258,7 @@ class SDFSImpl : public FSImpl
261258
};
262259

263260

264-
class SDFSFileImpl : public FileImpl
261+
class SDFSFileImpl : public fs::FileImpl
265262
{
266263
public:
267264
SDFSFileImpl(SDFSImpl *fs, std::shared_ptr<File32> fd, const char *name)
@@ -299,22 +296,22 @@ class SDFSFileImpl : public FileImpl
299296
}
300297
}
301298

302-
bool seek(uint32_t pos, SeekMode mode) override
299+
bool seek(uint32_t pos, fs::SeekMode mode) override
303300
{
304301
if (!_opened) {
305302
return false;
306303
}
307304
switch (mode) {
308-
case SeekSet:
305+
case fs::SeekSet:
309306
return _fd->seekSet(pos);
310-
case SeekEnd:
307+
case fs::SeekEnd:
311308
return _fd->seekEnd(-pos); // TODO again, odd from POSIX
312-
case SeekCur:
309+
case fs::SeekCur:
313310
return _fd->seekCur(pos);
314311
default:
315312
// Should not be hit, we've got an invalid seek mode
316313
DEBUGV("SDFSFileImpl::seek: invalid seek mode %d\n", mode);
317-
assert((mode==SeekSet) || (mode==SeekEnd) || (mode==SeekCur)); // Will fail and give meaningful assert message
314+
assert((mode==fs::SeekSet) || (mode==fs::SeekEnd) || (mode==fs::SeekCur)); // Will fail and give meaningful assert message
318315
return false;
319316
}
320317
}
@@ -406,7 +403,7 @@ class SDFSFileImpl : public FileImpl
406403
bool _opened;
407404
};
408405

409-
class SDFSDirImpl : public DirImpl
406+
class SDFSDirImpl : public fs::DirImpl
410407
{
411408
public:
412409
SDFSDirImpl(const String& pattern, SDFSImpl* fs, std::shared_ptr<File32> dir, const char *dirPath = nullptr)
@@ -423,10 +420,10 @@ class SDFSDirImpl : public DirImpl
423420
_dir->close();
424421
}
425422

426-
FileImplPtr openFile(OpenMode openMode, AccessMode accessMode) override
423+
fs::FileImplPtr openFile(fs::OpenMode openMode, fs::AccessMode accessMode) override
427424
{
428425
if (!_valid) {
429-
return FileImplPtr();
426+
return fs::FileImplPtr();
430427
}
431428
// MAX_PATH on FAT32 is potentially 260 bytes per most implementations
432429
char tmpName[260];
@@ -532,7 +529,7 @@ class SDFSDirImpl : public DirImpl
532529
}; // namespace sdfs
533530

534531
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SDFS)
535-
extern FS SDFS;
532+
extern fs::FS SDFS;
536533
using sdfs::SDFSConfig;
537534
#endif
538535

0 commit comments

Comments
 (0)