DiskBackedFileSystem.h 826 B

123456789101112131415161718192021222324252627282930313233
  1. #pragma once
  2. #include "FileSystem.h"
  3. #include <AK/ByteBuffer.h>
  4. class DiskBackedFS : public FS {
  5. public:
  6. virtual ~DiskBackedFS() override;
  7. DiskDevice& device() { return *m_device; }
  8. const DiskDevice& device() const { return *m_device; }
  9. int block_size() const { return m_block_size; }
  10. virtual void flush_writes() override;
  11. protected:
  12. explicit DiskBackedFS(NonnullRefPtr<DiskDevice>&&);
  13. void set_block_size(int);
  14. ByteBuffer read_block(unsigned index) const;
  15. ByteBuffer read_blocks(unsigned index, unsigned count) const;
  16. bool write_block(unsigned index, const ByteBuffer&);
  17. bool write_blocks(unsigned index, unsigned count, const ByteBuffer&);
  18. private:
  19. int m_block_size { 0 };
  20. NonnullRefPtr<DiskDevice> m_device;
  21. HashMap<unsigned, ByteBuffer> m_write_cache;
  22. };