worked on FileSystem, started to migrate logging class
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
#include "Structs.h"
|
||||
|
||||
// https://www.pjrc.com/tech/8051/ide/fat32.html
|
||||
@@ -23,6 +25,9 @@ namespace FAT32 {
|
||||
|
||||
#include "File.h"
|
||||
#include "DirIterator.h"
|
||||
#include "WriteFile.h"
|
||||
#include "FreeClusterIterator.h"
|
||||
|
||||
|
||||
/** ctor with the absolute offset addr (in bytes) */
|
||||
FS(BlockDev& dev, AbsOffset offset) : dev(dev), offset(offset) {
|
||||
@@ -41,14 +46,25 @@ namespace FAT32 {
|
||||
|
||||
/** open the given file for reading*/
|
||||
File open(const DirEntry& de) {
|
||||
return File(*this, de.getFirstCluster(), de.size);
|
||||
return File(*this, de.size, de.getFirstCluster());
|
||||
}
|
||||
|
||||
// /** create a new file for writing, in the given directory */
|
||||
// WriteFile newFile(DirEntry& de, const uint32_t size) {
|
||||
// if (!de.isDirectory()) {return nullptr;}
|
||||
// uint32_t allocSize = 0;
|
||||
// FreeClusterIterator fci(*this);
|
||||
// while(allocSize < size) {
|
||||
// ClusterNr = fci.next();
|
||||
// }
|
||||
// }
|
||||
|
||||
private:
|
||||
|
||||
void init() {
|
||||
|
||||
debugMod3(NAME")
|
||||
Log::addInfo(NAME, "init @ %d", offset);
|
||||
|
||||
uint8_t buf[512];
|
||||
dev.read(offset, 512, buf);
|
||||
|
||||
@@ -68,6 +84,8 @@ namespace FAT32 {
|
||||
tmp.startOfFirstRootDirCluster = clusterToAbsPos(desc.rootDirFirstCluster);
|
||||
tmp.dirEntriesPerSector = desc.bytesPerSector / sizeof(DirEntry);
|
||||
|
||||
Log::addInfo(NAME, "Bytes/Sector: %d, Sector/Cluster: %d, FATs: %d, RootDir: %d", desc.bytesPerSector, desc.sectorsPerCluster, desc.numberOfFATs, desc.rootDirFirstCluster);
|
||||
|
||||
/*
|
||||
std::cout << (int)desc.bytesPerSector << std::endl;
|
||||
std::cout << (int)desc.sectorsPerCluster << std::endl;
|
||||
@@ -86,8 +104,9 @@ namespace FAT32 {
|
||||
/** determine the ClusterNr following the given ClusterNr */
|
||||
ClusterNr getNextCluster(ClusterNr clusterNr) {
|
||||
const AbsPos pos = tmp.startOfFAT + ((clusterNr) * sizeof(uint32_t));
|
||||
ClusterNr next;
|
||||
int read = dev.read(pos, 4, reinterpret_cast<uint8_t*>(&next));
|
||||
ClusterNr next = 0;
|
||||
dev.read(pos, 4, reinterpret_cast<uint8_t*>(&next));
|
||||
Log::addInfo(NAME, "nextCluster(%d) -> %d", clusterNr, next);
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user