mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
added FS libs
This commit is contained in:
@@ -1,10 +1,122 @@
|
|||||||
#ifndef FS_h
|
/*
|
||||||
#define FS_h
|
FS.h - file system wrapper
|
||||||
|
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
|
||||||
|
This file is part of the esp8266 core for Arduino environment.
|
||||||
|
|
||||||
class FS {
|
This library is free software; you can redistribute it and/or
|
||||||
bool open() {
|
modify it under the terms of the GNU Lesser General Public
|
||||||
return true;
|
License as published by the Free Software Foundation; either
|
||||||
};
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FS_H
|
||||||
|
#define FS_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
namespace fs {
|
||||||
|
|
||||||
|
#define FILE_READ "r"
|
||||||
|
#define FILE_WRITE "w"
|
||||||
|
#define FILE_APPEND "a"
|
||||||
|
|
||||||
|
class File;
|
||||||
|
|
||||||
|
enum SeekMode { SeekSet = 0, SeekCur = 1, SeekEnd = 2 };
|
||||||
|
|
||||||
|
class FS;
|
||||||
|
|
||||||
|
class File : public Stream {
|
||||||
|
public:
|
||||||
|
explicit File(FS & fs, FILE * f, std::string filename);
|
||||||
|
explicit File(FS & fs, DIR * d, std::string filename);
|
||||||
|
~File();
|
||||||
|
|
||||||
|
size_t write(uint8_t) override;
|
||||||
|
size_t write(const uint8_t * buf, size_t size) override;
|
||||||
|
int available() override;
|
||||||
|
int read() override;
|
||||||
|
int peek() override;
|
||||||
|
void flush() override;
|
||||||
|
size_t read(uint8_t * buf, size_t size);
|
||||||
|
size_t readBytes(char * buffer, size_t length) {
|
||||||
|
return read((uint8_t *)buffer, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool seek(uint32_t pos, SeekMode mode);
|
||||||
|
bool seek(uint32_t pos) {
|
||||||
|
return seek(pos, SeekSet);
|
||||||
|
}
|
||||||
|
size_t position() const;
|
||||||
|
size_t size() const;
|
||||||
|
bool setBufferSize(size_t size);
|
||||||
|
void close();
|
||||||
|
operator bool() const;
|
||||||
|
time_t getLastWrite();
|
||||||
|
const char * path() const;
|
||||||
|
const char * name() const;
|
||||||
|
|
||||||
|
boolean isDirectory(void);
|
||||||
|
File openNextFile(const char * mode = FILE_READ);
|
||||||
|
/* String */ std::string getNextFileName(void);
|
||||||
|
void rewindDirectory(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
FS & fs_;
|
||||||
|
FILE * f_{nullptr};
|
||||||
|
int peek_{-1};
|
||||||
|
std::string path_;
|
||||||
|
std::string name_;
|
||||||
|
DIR * d_{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
class FS {
|
||||||
|
public:
|
||||||
|
FS() {
|
||||||
|
}
|
||||||
|
|
||||||
|
File open(const char * path, const char * mode = FILE_READ, const bool create = false);
|
||||||
|
File open(const String & path, const char * mode = FILE_READ, const bool create = false);
|
||||||
|
|
||||||
|
bool exists(const char * path);
|
||||||
|
bool exists(const String & path);
|
||||||
|
|
||||||
|
bool remove(const char * path);
|
||||||
|
bool remove(const String & path);
|
||||||
|
|
||||||
|
bool rename(const char * pathFrom, const char * pathTo);
|
||||||
|
bool rename(const String & pathFrom, const String & pathTo);
|
||||||
|
|
||||||
|
bool mkdir(const char * path);
|
||||||
|
bool mkdir(const String & path);
|
||||||
|
|
||||||
|
bool rmdir(const char * path);
|
||||||
|
bool rmdir(const String & path);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace fs
|
||||||
|
|
||||||
|
#ifndef FS_NO_GLOBALS
|
||||||
|
using fs::File;
|
||||||
|
using fs::FS;
|
||||||
|
using fs::SeekCur;
|
||||||
|
using fs::SeekEnd;
|
||||||
|
using fs::SeekMode;
|
||||||
|
using fs::SeekSet;
|
||||||
|
#endif //FS_NO_GLOBALS
|
||||||
|
|
||||||
|
#endif //FS_H
|
||||||
|
|||||||
49
lib_standalone/LittleFS.cpp
Normal file
49
lib_standalone/LittleFS.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* mcu-app - Microcontroller application framework
|
||||||
|
* Copyright 2022 Simon Arlott
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifdef ENV_NATIVE
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <FS.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
|
|
||||||
|
fs::LittleFSFS LittleFS;
|
||||||
|
|
||||||
|
namespace fs {
|
||||||
|
|
||||||
|
LittleFSFS::LittleFSFS()
|
||||||
|
: FS() {
|
||||||
|
}
|
||||||
|
LittleFSFS::~LittleFSFS() {
|
||||||
|
}
|
||||||
|
bool LittleFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpenFiles, const char * partitionLabel) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool LittleFSFS::format() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
size_t LittleFSFS::totalBytes() {
|
||||||
|
return SIZE_MAX;
|
||||||
|
}
|
||||||
|
size_t LittleFSFS::usedBytes() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void LittleFSFS::end() {
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace fs
|
||||||
|
#endif
|
||||||
40
lib_standalone/LittleFS.h
Normal file
40
lib_standalone/LittleFS.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
#ifndef _LITTLEFS_H_
|
||||||
|
#define _LITTLEFS_H_
|
||||||
|
|
||||||
|
#include "FS.h"
|
||||||
|
|
||||||
|
namespace fs {
|
||||||
|
|
||||||
|
class LittleFSFS : public FS {
|
||||||
|
public:
|
||||||
|
LittleFSFS();
|
||||||
|
~LittleFSFS();
|
||||||
|
bool begin(bool formatOnFail = false, const char * basePath = "/littlefs", uint8_t maxOpenFiles = 10, const char * partitionLabel = "spiffs");
|
||||||
|
bool format();
|
||||||
|
size_t totalBytes();
|
||||||
|
size_t usedBytes();
|
||||||
|
void end();
|
||||||
|
|
||||||
|
private:
|
||||||
|
char * partitionLabel_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace fs
|
||||||
|
|
||||||
|
extern fs::LittleFSFS LittleFS;
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user