worked on FileSystem, started to migrate logging class

This commit is contained in:
2021-02-14 15:29:21 +01:00
parent faf6e55bc5
commit 6aa951190e
19 changed files with 612 additions and 241 deletions

View File

@@ -1,6 +1,7 @@
class File {
static constexpr const int32_t F_EOF = -1;
static constexpr const char* NAME = "FAT32_File";
static constexpr const uint32_t F_EOF = 0xFFFFFFFF;
FS& fs;
uint32_t totalSize;
@@ -12,23 +13,33 @@ class File {
public:
File(FS& fs, uint32_t firstCluster, uint32_t size) : fs(fs), totalSize(size), curCluster(firstCluster) {
File(FS& fs, uint32_t size, uint32_t firstCluster) : fs(fs), totalSize(size), curCluster(firstCluster) {
Log::addInfo(NAME, "init @ cluster %d", firstCluster);
}
/** the file's size */
uint32_t getSize() const {return totalSize;}
uint32_t read(uint32_t size, uint8_t* dst) {
uint32_t total = 0;
while(true) {
const uint32_t read = _read(size, dst);
if (read == F_EOF) {break;}
size -= read;
uint32_t read(uint32_t size, uint8_t* dst, std::function<void(int)> callback) {
Log::addInfo(NAME, "read %d bytes", size);
uint32_t remaining = size;
uint32_t totalRead = 0;
while(remaining) {
const uint32_t read = _read(remaining, dst);
if (read == F_EOF) {
Log::addInfo(NAME, "EOF"); break;
}
remaining -= read;
dst += read;
total += read;
totalRead += read;
callback(totalRead*100/size);
}
return total;
return totalRead;
}
private:
@@ -44,6 +55,7 @@ private:
if (posInCluster == fs.tmp.bytesPerCluster) {
curCluster = fs.getNextCluster(curCluster);
posInCluster = 0;
Log::addInfo(NAME, "next cluster %d", curCluster);
}
// how many bytes are left in the current cluster?