huge work on FAT32, initial support for writing
This commit is contained in:
@@ -20,8 +20,73 @@ public:
|
||||
|
||||
}
|
||||
|
||||
DirEntryAt cur() {
|
||||
AbsPos pos = fs.clusterToAbsPos(curCluster) + (curSectorInCluster * fs.desc.bytesPerSector) + (curEntryInSector * sizeof(DirEntry));
|
||||
DirEntry* dirEntry = reinterpret_cast<DirEntry*>(buf + (curEntryInSector * sizeof(DirEntry)));
|
||||
return DirEntryAt(pos, dirEntry);
|
||||
}
|
||||
|
||||
DirEntry* next() {
|
||||
/** get the next usable entry within the current directory */
|
||||
DirEntryAt nextUsable() {
|
||||
|
||||
while(true) {
|
||||
|
||||
DirEntryAt dea = next(false);
|
||||
|
||||
// check it
|
||||
if (!dea.isValid()) {return DirEntryAt::invalid();}
|
||||
if (dea.isLongFileName()) {continue;}
|
||||
if (dea.isUnused()) {continue;}
|
||||
if (dea.isEndOfDirectory()) {return DirEntryAt::invalid();}
|
||||
|
||||
// usable!
|
||||
return dea;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** get (or create) a free entry within the current directory */
|
||||
DirEntryAt nextFree() {
|
||||
|
||||
while(true) {
|
||||
|
||||
DirEntryAt dea = next(true);
|
||||
|
||||
// check it
|
||||
if (!dea.isValid()) {return DirEntryAt::invalid();}
|
||||
|
||||
if (dea.isUnused()) {
|
||||
|
||||
// switch from "unused" to something usable
|
||||
//dea.setName("NEW.ONE");
|
||||
//dea.entry.attr.raw = 0;
|
||||
//return dea;
|
||||
|
||||
}
|
||||
|
||||
if (dea.isEndOfDirectory()) {
|
||||
|
||||
// add a new EndOfDirectory entry afterwards
|
||||
DirEntryAt dea2 = next(true);
|
||||
dea2.setEndOfDirectory();
|
||||
fs.write(dea2);
|
||||
|
||||
// switch from "end of directory" to something usable
|
||||
dea.setName("NEW.ONE");
|
||||
dea.entry.attr.raw = 0;
|
||||
return dea;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
DirEntryAt next(bool allocIfNeeded) {
|
||||
|
||||
while(true) {
|
||||
|
||||
@@ -35,8 +100,23 @@ public:
|
||||
// end of cluster reached?
|
||||
if (curSectorInCluster >= fs.desc.sectorsPerCluster) {
|
||||
|
||||
// find next cluster
|
||||
curCluster = fs.getNextCluster(curCluster); // number of the next cluster (if any)
|
||||
// find next cluster (if any)
|
||||
const ClusterNr nextCluster = fs.getNextCluster(curCluster);
|
||||
|
||||
// reached end of clusters?
|
||||
if (nextCluster.isEndOfClusters()) {
|
||||
|
||||
// do not alloc new entries? -> done here
|
||||
if (!allocIfNeeded) {
|
||||
return DirEntryAt::invalid();
|
||||
} else {
|
||||
curCluster = fs.allocFreeCluster(curCluster);
|
||||
}
|
||||
|
||||
} else {
|
||||
curCluster = nextCluster;
|
||||
}
|
||||
|
||||
curSectorInCluster = 0;
|
||||
|
||||
}
|
||||
@@ -47,18 +127,10 @@ public:
|
||||
}
|
||||
|
||||
// the current entry
|
||||
DirEntry* dirEntry = reinterpret_cast<DirEntry*>(buf + (sizeof(DirEntry) * curEntryInSector));
|
||||
DirEntryAt dea = cur();
|
||||
++curEntryInSector;
|
||||
|
||||
// check it
|
||||
if (dirEntry->isLongFileName()) {continue;}
|
||||
if (dirEntry->isUnused()) {continue;}
|
||||
if (dirEntry->isEndOfDirectory()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// usable!
|
||||
return dirEntry;
|
||||
return dea;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user