Skip to content

Commit

Permalink
Start to track start/end file offsets.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlewallen committed Mar 30, 2018
1 parent 20503bd commit 6c668fe
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fkfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ uint8_t fkfs_initialize_file(fkfs_t *fs, uint8_t fileNumber, uint8_t priority, u
strncpy(file->name, name, sizeof(file->name));
file->version = random(UINT16_MAX);
file->startBlock = FKFS_FIRST_BLOCK;
file->startOffset = 0;
file->endOffset = 0;

return true;
}
Expand Down Expand Up @@ -217,7 +219,9 @@ uint8_t fkfs_initialize(fkfs_t *fs, bool wipe) {
fs->header.files[i].version = random(UINT16_MAX);
fs->header.files[i].size = 0;
fs->header.files[i].startBlock = fs->header.block;
fs->header.files[i].startOffset = 0;
fs->header.files[i].endBlock = fs->header.block;
fs->header.files[i].endOffset = 0;

fkfs_log("file[%d] sync=%d pri=%d sb=%d eb=%d version=%d size=%d '%s'", i,
fs->files[i].sync,
Expand Down Expand Up @@ -517,6 +521,7 @@ uint8_t fkfs_file_append(fkfs_t *fs, uint8_t fileNumber, uint16_t size, uint8_t
fs->cachedBlockDirty = true;
fs->header.offset += required;
fs->header.files[fileNumber].endBlock = fs->header.block;
fs->header.files[fileNumber].endOffset = fs->header.offset;
fs->header.files[fileNumber].size += size;

// If this file is configured to be fsync'd after every write that go ahead
Expand All @@ -543,6 +548,8 @@ uint8_t fkfs_file_truncate(fkfs_t *fs, uint8_t fileNumber) {
file->version++;
file->startBlock = fs->header.block;
file->endBlock = file->startBlock;
file->startOffset = 0;
file->endOffset = 0;
file->size = 0;

return true;
Expand Down

0 comments on commit 6c668fe

Please sign in to comment.