IAIK/sweb

RamFSFile read/write does not update file seek offset

Woazboat opened this issue · 1 comments

The code for RamFSFile::read/write should be identical to MinixFSFile::read/write, which correctly updates the file seek offset after read/write.

RamFSFile:
return (f_inode_->readData(offset_ + offset, count, buffer));

MinixFSFile:

int32 read_bytes = f_inode_->readData(offset_ + offset, count, buffer);
offset_ += read_bytes;
return read_bytes;

The cleanest solution would be to move the implementation to the shared 'File' base class, since it's identical for all file systems.

Additionally, the update of the file seek offset is not safe for concurrent calls to read/write/lseek using the same file descriptor.

offset_ = 0

  1. readData(offset_ = 0, 5 bytes, ...)
  2. readData(offset_ = 0, 5 bytes, ...)
  3. offset_ += 5
  4. offset_ += 5

=> offset_ = 10, but bytes 5-9 were never read