worked on FAT32 stuff

This commit is contained in:
2021-02-21 09:33:08 +01:00
parent da12992ae8
commit 4ac72c678f
13 changed files with 494 additions and 148 deletions

View File

@@ -38,7 +38,7 @@ public:
if (offset || size < SEC_SIZE) { // non-aligned / non-full-block write
// read the whole sector
if (!readSingleBlock(addrLBA, buf)) {return written;}
if (!readBlock(addrLBA, buf)) {return written;}
// merge in the new data
const uint32_t toModify = min(SEC_SIZE-offset, size);
@@ -46,7 +46,7 @@ public:
offset = 0;
// write back the modified sector
if (!writeSingleBlock(addrLBA, buf)) {return written;}
if (!writeBlock(addrLBA, buf)) {return written;}
++addrLBA;
size -= toModify;
@@ -55,7 +55,7 @@ public:
} else {
// write a full block
if (!writeSingleBlock(addrLBA, &src[written])) {return written;}
if (!writeBlock(addrLBA, &src[written])) {return written;}
++addrLBA;
size -= SEC_SIZE;
@@ -83,7 +83,7 @@ public:
if (offset || size < SEC_SIZE) { // non-aligned read / non-full-block read
const uint32_t toRead = min(SEC_SIZE-offset, size);
if (!readSingleBlock(addrLBA, &dst[read], offset, toRead)) {return read;}
if (!readBlock(addrLBA, &dst[read], offset, toRead)) {return read;}
offset = 0; // all following reads are aligned
++addrLBA;
@@ -92,7 +92,7 @@ public:
} else { // full block read
if (!readSingleBlock(addrLBA, &dst[read])) {return read;}
if (!readBlock(addrLBA, &dst[read])) {return read;}
++addrLBA;
size -= SEC_SIZE;
read += SEC_SIZE;
@@ -106,14 +106,14 @@ public:
}
/** read a single block of SEC_SIZE bytes. addr = byteAddr/512 */
bool readSingleBlock(LBA512 addr, uint8_t* dst) {
return dev.readSingleBlock(addr, dst);
bool readBlock(LBA512 addr, uint8_t* dst) {
return dev.readBlock(addr, dst);
}
/** read a single block of SEC_SIZE bytes. addr = byteAddr/512, write only a fraction of the 512 bytes into dst (skip+len) */
bool readSingleBlock(LBA512 addr, uint8_t* dst, uint16_t skip, uint16_t len) {
bool readBlock(LBA512 addr, uint8_t* dst, uint16_t skip, uint16_t len) {
uint8_t buf[SEC_SIZE];
if (!dev.readSingleBlock(addr, buf)) {return false;}
if (!dev.readBlock(addr, buf)) {return false;}
for (int i = 0; i < len; ++i) {
*dst = buf[i+skip];
++dst;
@@ -122,8 +122,8 @@ public:
}
/** write a single block of 512 bytes. addr = byteAddr/512 */
bool writeSingleBlock(LBA512 addr, const uint8_t* src) {
return dev.writeSingleBlock(addr, src);
bool writeBlock(LBA512 addr, const uint8_t* src) {
return dev.writeBlock(addr, src);
}