|
@@ -1,18 +1,18 @@
|
|
#define _FILE_OFFSET_BITS 64
|
|
#define _FILE_OFFSET_BITS 64
|
|
|
|
|
|
-#include "FileBackedBlockDevice.h"
|
|
|
|
|
|
+#include "FileBackedDiskDevice.h"
|
|
#include <cstring>
|
|
#include <cstring>
|
|
#include <sys/stat.h>
|
|
#include <sys/stat.h>
|
|
|
|
|
|
//#define FBBD_DEBUG
|
|
//#define FBBD_DEBUG
|
|
#define IGNORE_FILE_LENGTH // Useful for e.g /dev/hda2
|
|
#define IGNORE_FILE_LENGTH // Useful for e.g /dev/hda2
|
|
|
|
|
|
-RetainPtr<FileBackedBlockDevice> FileBackedBlockDevice::create(String&& imagePath, unsigned blockSize)
|
|
|
|
|
|
+RetainPtr<FileBackedDiskDevice> FileBackedDiskDevice::create(String&& imagePath, unsigned blockSize)
|
|
{
|
|
{
|
|
- return adopt(*new FileBackedBlockDevice(std::move(imagePath), blockSize));
|
|
|
|
|
|
+ return adopt(*new FileBackedDiskDevice(std::move(imagePath), blockSize));
|
|
}
|
|
}
|
|
|
|
|
|
-FileBackedBlockDevice::FileBackedBlockDevice(String&& imagePath, unsigned blockSize)
|
|
|
|
|
|
+FileBackedDiskDevice::FileBackedDiskDevice(String&& imagePath, unsigned blockSize)
|
|
: m_imagePath(std::move(imagePath))
|
|
: m_imagePath(std::move(imagePath))
|
|
, m_blockSize(blockSize)
|
|
, m_blockSize(blockSize)
|
|
{
|
|
{
|
|
@@ -23,35 +23,35 @@ FileBackedBlockDevice::FileBackedBlockDevice(String&& imagePath, unsigned blockS
|
|
m_file = fopen(m_imagePath.characters(), "r+");
|
|
m_file = fopen(m_imagePath.characters(), "r+");
|
|
}
|
|
}
|
|
|
|
|
|
-FileBackedBlockDevice::~FileBackedBlockDevice()
|
|
|
|
|
|
+FileBackedDiskDevice::~FileBackedDiskDevice()
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
-unsigned FileBackedBlockDevice::blockSize() const
|
|
|
|
|
|
+unsigned FileBackedDiskDevice::blockSize() const
|
|
{
|
|
{
|
|
return m_blockSize;
|
|
return m_blockSize;
|
|
}
|
|
}
|
|
|
|
|
|
-bool FileBackedBlockDevice::readBlock(unsigned index, byte* out) const
|
|
|
|
|
|
+bool FileBackedDiskDevice::readBlock(unsigned index, byte* out) const
|
|
{
|
|
{
|
|
qword offset = index * m_blockSize;
|
|
qword offset = index * m_blockSize;
|
|
return read(offset, blockSize(), out);
|
|
return read(offset, blockSize(), out);
|
|
}
|
|
}
|
|
|
|
|
|
-bool FileBackedBlockDevice::writeBlock(unsigned index, const byte* data)
|
|
|
|
|
|
+bool FileBackedDiskDevice::writeBlock(unsigned index, const byte* data)
|
|
{
|
|
{
|
|
qword offset = index * m_blockSize;
|
|
qword offset = index * m_blockSize;
|
|
return write(offset, blockSize(), data);
|
|
return write(offset, blockSize(), data);
|
|
}
|
|
}
|
|
|
|
|
|
-bool FileBackedBlockDevice::read(qword offset, unsigned length, byte* out) const
|
|
|
|
|
|
+bool FileBackedDiskDevice::read(qword offset, unsigned length, byte* out) const
|
|
{
|
|
{
|
|
#ifndef IGNORE_FILE_LENGTH
|
|
#ifndef IGNORE_FILE_LENGTH
|
|
if (offset + length >= m_fileLength)
|
|
if (offset + length >= m_fileLength)
|
|
return false;
|
|
return false;
|
|
#endif
|
|
#endif
|
|
#ifdef FBBD_DEBUG
|
|
#ifdef FBBD_DEBUG
|
|
- printf("[FileBackedBlockDevice] Read device @ offset %llx, length %u\n", offset, length);
|
|
|
|
|
|
+ printf("[FileBackedDiskDevice] Read device @ offset %llx, length %u\n", offset, length);
|
|
#endif
|
|
#endif
|
|
fseeko(m_file, offset, SEEK_SET);
|
|
fseeko(m_file, offset, SEEK_SET);
|
|
unsigned nread = fread(out, sizeof(byte), length, m_file);
|
|
unsigned nread = fread(out, sizeof(byte), length, m_file);
|
|
@@ -59,14 +59,14 @@ bool FileBackedBlockDevice::read(qword offset, unsigned length, byte* out) const
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
-bool FileBackedBlockDevice::write(qword offset, unsigned length, const byte* data)
|
|
|
|
|
|
+bool FileBackedDiskDevice::write(qword offset, unsigned length, const byte* data)
|
|
{
|
|
{
|
|
#ifndef IGNORE_FILE_LENGTH
|
|
#ifndef IGNORE_FILE_LENGTH
|
|
if (offset + length >= m_fileLength)
|
|
if (offset + length >= m_fileLength)
|
|
return false;
|
|
return false;
|
|
#endif
|
|
#endif
|
|
#ifdef FBBD_DEBUG
|
|
#ifdef FBBD_DEBUG
|
|
- printf("[FileBackedBlockDevice] Write device @ offset %llx, length %u\n", offset, length);
|
|
|
|
|
|
+ printf("[FileBackedDiskDevice] Write device @ offset %llx, length %u\n", offset, length);
|
|
#endif
|
|
#endif
|
|
fseeko(m_file, offset, SEEK_SET);
|
|
fseeko(m_file, offset, SEEK_SET);
|
|
// size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
|
|
// size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
|
|
@@ -75,8 +75,8 @@ bool FileBackedBlockDevice::write(qword offset, unsigned length, const byte* dat
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
-const char* FileBackedBlockDevice::className() const
|
|
|
|
|
|
+const char* FileBackedDiskDevice::className() const
|
|
{
|
|
{
|
|
- return "FileBackedBlockDevice";
|
|
|
|
|
|
+ return "FileBackedDiskDevice";
|
|
}
|
|
}
|
|
|
|
|