worked on FAT stuff and tests
This commit is contained in:
@@ -15,63 +15,73 @@ public:
|
||||
|
||||
Log::addInfo(NAME, "init @ Cluster %d", curCluster);
|
||||
|
||||
// ".." folders point to cluster 0 if they point to the root folder -> adjust here
|
||||
if (clusterNr == 0) {
|
||||
clusterNr = fs.desc.rootDirFirstCluster;
|
||||
}
|
||||
|
||||
// read the first sector in the first cluster
|
||||
read(curCluster, 0);
|
||||
|
||||
}
|
||||
|
||||
DirIterator(FS& fs, DirHandle dh) : DirIterator(fs, dh.getFirstCluster()) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/** get the next usable entry within the current directory */
|
||||
DirEntryAt nextUsable() {
|
||||
DirHandle nextUsable() {
|
||||
|
||||
while(true) {
|
||||
|
||||
DirEntryAt dea = next(false);
|
||||
DirHandle h = next(false);
|
||||
|
||||
// check it
|
||||
if (!dea.isValid()) {return DirEntryAt::invalid();}
|
||||
if (dea.isLongFileName()) {continue;}
|
||||
if (dea.isUnused()) {continue;}
|
||||
if (dea.isEndOfDirectory()) {return DirEntryAt::invalid();}
|
||||
if (!h.isValid()) {return DirHandle::invalid();}
|
||||
if (h.isLongFileName()) {continue;}
|
||||
if (h.isUnused()) {continue;}
|
||||
if (h.isEndOfDirectory()) {return DirHandle::invalid();}
|
||||
|
||||
// usable!
|
||||
return dea;
|
||||
return h;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** get (or create) a free entry within the current directory */
|
||||
DirEntryAt nextFree() {
|
||||
DirHandle nextFree() {
|
||||
|
||||
while(true) {
|
||||
|
||||
DirEntryAt dea = next(true);
|
||||
DirHandle h = next(true);
|
||||
|
||||
// check it
|
||||
if (!dea.isValid()) {return DirEntryAt::invalid();}
|
||||
if (!h.isValid()) {return DirHandle::invalid();}
|
||||
|
||||
if (dea.isUnused()) {
|
||||
if (h.isUnused()) {
|
||||
|
||||
// switch from "unused" to something usable
|
||||
//dea.setName("NEW.ONE");
|
||||
//dea.entry.attr.raw = 0;
|
||||
//h.setName("NEW.ONE");
|
||||
//h.entry.attr.raw = 0;
|
||||
//return dea;
|
||||
|
||||
}
|
||||
|
||||
if (dea.isEndOfDirectory()) {
|
||||
if (h.isEndOfDirectory()) {
|
||||
|
||||
// add a new EndOfDirectory entry afterwards
|
||||
DirEntryAt dea2 = next(true);
|
||||
dea2.setEndOfDirectory();
|
||||
fs.write(dea2);
|
||||
DirHandle h2 = next(true);
|
||||
h2.setEndOfDirectory();
|
||||
fs.write(h2);
|
||||
|
||||
// switch from "end of directory" to something usable
|
||||
dea.setName("NEW.ONE");
|
||||
dea.entry.attr.raw = 0;
|
||||
return dea;
|
||||
h.setName("NEW.ONE");
|
||||
h.entry.attr.raw = 0;
|
||||
return h;
|
||||
|
||||
}
|
||||
|
||||
@@ -80,15 +90,19 @@ public:
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
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);
|
||||
DirHandle next() {
|
||||
return next(false);
|
||||
}
|
||||
|
||||
DirEntryAt next(bool allocIfNeeded) {
|
||||
private:
|
||||
|
||||
DirHandle cur() {
|
||||
AbsPos pos = fs.clusterToAbsPos(curCluster) + (curSectorInCluster * fs.desc.bytesPerSector) + (curEntryInSector * sizeof(DirEntry));
|
||||
DirEntry* dirEntry = reinterpret_cast<DirEntry*>(buf + (curEntryInSector * sizeof(DirEntry)));
|
||||
return DirHandle(pos, dirEntry);
|
||||
}
|
||||
|
||||
DirHandle next(bool allocIfNeeded) {
|
||||
|
||||
while(true) {
|
||||
|
||||
@@ -110,7 +124,7 @@ private:
|
||||
|
||||
// do not alloc new entries? -> done here
|
||||
if (!allocIfNeeded) {
|
||||
return DirEntryAt::invalid();
|
||||
return DirHandle::invalid();
|
||||
} else {
|
||||
curCluster = fs.allocFreeCluster(curCluster);
|
||||
}
|
||||
@@ -129,10 +143,10 @@ private:
|
||||
}
|
||||
|
||||
// the current entry
|
||||
DirEntryAt dea = cur();
|
||||
DirHandle h = cur();
|
||||
++curEntryInSector;
|
||||
|
||||
return dea;
|
||||
return h;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user