mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:47:34 +00:00
Yet more coding style fixes.
This commit is contained in:
parent
f31e1ceab0
commit
aff89d2fd7
18 changed files with 197 additions and 199 deletions
|
@ -11,32 +11,32 @@ DiskDevice::~DiskDevice()
|
|||
bool DiskDevice::read(DiskOffset offset, unsigned length, byte* out) const
|
||||
{
|
||||
//kprintf("DD::read %u x%u\n", offset, length);
|
||||
ASSERT((offset % blockSize()) == 0);
|
||||
ASSERT((length % blockSize()) == 0);
|
||||
dword firstBlock = offset / blockSize();
|
||||
dword endBlock = (offset + length) / blockSize();
|
||||
ASSERT((offset % block_size()) == 0);
|
||||
ASSERT((length % block_size()) == 0);
|
||||
dword firstBlock = offset / block_size();
|
||||
dword endBlock = (offset + length) / block_size();
|
||||
byte* outptr = out;
|
||||
for (unsigned bi = firstBlock; bi < endBlock; ++bi) {
|
||||
if (!readBlock(bi, outptr))
|
||||
if (!read_block(bi, outptr))
|
||||
return false;
|
||||
outptr += blockSize();
|
||||
outptr += block_size();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DiskDevice::write(DiskOffset offset, unsigned length, const byte* in)
|
||||
{
|
||||
ASSERT((offset % blockSize()) == 0);
|
||||
ASSERT((length % blockSize()) == 0);
|
||||
dword firstBlock = offset / blockSize();
|
||||
dword endBlock = (offset + length) / blockSize();
|
||||
ASSERT((offset % block_size()) == 0);
|
||||
ASSERT((length % block_size()) == 0);
|
||||
dword firstBlock = offset / block_size();
|
||||
dword endBlock = (offset + length) / block_size();
|
||||
ASSERT(firstBlock <= 0xffffffff);
|
||||
ASSERT(endBlock <= 0xffffffff);
|
||||
const byte* inptr = in;
|
||||
for (unsigned bi = firstBlock; bi < endBlock; ++bi) {
|
||||
if (!writeBlock(bi, inptr))
|
||||
if (!write_block(bi, inptr))
|
||||
return false;
|
||||
inptr += blockSize();
|
||||
inptr += block_size();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ class DiskDevice : public Retainable<DiskDevice> {
|
|||
public:
|
||||
virtual ~DiskDevice();
|
||||
|
||||
virtual unsigned blockSize() const = 0;
|
||||
virtual bool readBlock(unsigned index, byte*) const = 0;
|
||||
virtual bool writeBlock(unsigned index, const byte*) = 0;
|
||||
virtual unsigned block_size() const = 0;
|
||||
virtual bool read_block(unsigned index, byte*) const = 0;
|
||||
virtual bool write_block(unsigned index, const byte*) = 0;
|
||||
virtual const char* class_name() const = 0;
|
||||
bool read(DiskOffset, unsigned length, byte*) const;
|
||||
bool write(DiskOffset, unsigned length, const byte*);
|
||||
|
|
|
@ -28,8 +28,8 @@ Ext2FS::~Ext2FS()
|
|||
ByteBuffer Ext2FS::read_super_block() const
|
||||
{
|
||||
auto buffer = ByteBuffer::createUninitialized(1024);
|
||||
device().readBlock(2, buffer.pointer());
|
||||
device().readBlock(3, buffer.offsetPointer(512));
|
||||
device().read_block(2, buffer.pointer());
|
||||
device().read_block(3, buffer.offsetPointer(512));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -37,9 +37,9 @@ bool Ext2FS::write_super_block(const ext2_super_block& sb)
|
|||
{
|
||||
const byte* raw = (const byte*)&sb;
|
||||
bool success;
|
||||
success = device().writeBlock(2, raw);
|
||||
success = device().write_block(2, raw);
|
||||
ASSERT(success);
|
||||
success = device().writeBlock(3, raw + 512);
|
||||
success = device().write_block(3, raw + 512);
|
||||
ASSERT(success);
|
||||
// FIXME: This is an ugly way to refresh the superblock cache. :-|
|
||||
super_block();
|
||||
|
|
|
@ -7,44 +7,44 @@
|
|||
//#define FBBD_DEBUG
|
||||
#define IGNORE_FILE_LENGTH // Useful for e.g /dev/hda2
|
||||
|
||||
RetainPtr<FileBackedDiskDevice> FileBackedDiskDevice::create(String&& imagePath, unsigned blockSize)
|
||||
RetainPtr<FileBackedDiskDevice> FileBackedDiskDevice::create(String&& image_path, unsigned block_size)
|
||||
{
|
||||
return adopt(*new FileBackedDiskDevice(std::move(imagePath), blockSize));
|
||||
return adopt(*new FileBackedDiskDevice(move(image_path), block_size));
|
||||
}
|
||||
|
||||
FileBackedDiskDevice::FileBackedDiskDevice(String&& imagePath, unsigned blockSize)
|
||||
: m_imagePath(std::move(imagePath))
|
||||
, m_blockSize(blockSize)
|
||||
FileBackedDiskDevice::FileBackedDiskDevice(String&& image_path, unsigned block_size)
|
||||
: m_image_path(move(image_path))
|
||||
, m_block_size(block_size)
|
||||
{
|
||||
struct stat st;
|
||||
int result = stat(m_imagePath.characters(), &st);
|
||||
int result = stat(m_image_path.characters(), &st);
|
||||
ASSERT(result != -1);
|
||||
m_fileLength = st.st_size;
|
||||
m_file = fopen(m_imagePath.characters(), "r+");
|
||||
m_file_length = st.st_size;
|
||||
m_file = fopen(m_image_path.characters(), "r+");
|
||||
}
|
||||
|
||||
FileBackedDiskDevice::~FileBackedDiskDevice()
|
||||
{
|
||||
}
|
||||
|
||||
unsigned FileBackedDiskDevice::blockSize() const
|
||||
unsigned FileBackedDiskDevice::block_size() const
|
||||
{
|
||||
return m_blockSize;
|
||||
return m_block_size;
|
||||
}
|
||||
|
||||
bool FileBackedDiskDevice::readBlock(unsigned index, byte* out) const
|
||||
bool FileBackedDiskDevice::read_block(unsigned index, byte* out) const
|
||||
{
|
||||
DiskOffset offset = index * m_blockSize;
|
||||
return readInternal(offset, blockSize(), out);
|
||||
DiskOffset offset = index * m_block_size;
|
||||
return read_internal(offset, block_size(), out);
|
||||
}
|
||||
|
||||
bool FileBackedDiskDevice::writeBlock(unsigned index, const byte* data)
|
||||
bool FileBackedDiskDevice::write_block(unsigned index, const byte* data)
|
||||
{
|
||||
DiskOffset offset = index * m_blockSize;
|
||||
return writeInternal(offset, blockSize(), data);
|
||||
DiskOffset offset = index * m_block_size;
|
||||
return write_internal(offset, block_size(), data);
|
||||
}
|
||||
|
||||
bool FileBackedDiskDevice::readInternal(DiskOffset offset, unsigned length, byte* out) const
|
||||
bool FileBackedDiskDevice::read_internal(DiskOffset offset, unsigned length, byte* out) const
|
||||
{
|
||||
#ifndef IGNORE_FILE_LENGTH
|
||||
if (offset + length >= m_fileLength)
|
||||
|
@ -59,7 +59,7 @@ bool FileBackedDiskDevice::readInternal(DiskOffset offset, unsigned length, byte
|
|||
return true;
|
||||
}
|
||||
|
||||
bool FileBackedDiskDevice::writeInternal(DiskOffset offset, unsigned length, const byte* data)
|
||||
bool FileBackedDiskDevice::write_internal(DiskOffset offset, unsigned length, const byte* data)
|
||||
{
|
||||
#ifndef IGNORE_FILE_LENGTH
|
||||
if (offset + length >= m_fileLength)
|
||||
|
|
|
@ -8,26 +8,26 @@
|
|||
|
||||
class FileBackedDiskDevice final : public DiskDevice {
|
||||
public:
|
||||
static RetainPtr<FileBackedDiskDevice> create(String&& imagePath, unsigned blockSize);
|
||||
static RetainPtr<FileBackedDiskDevice> create(String&& image_path, unsigned block_size);
|
||||
virtual ~FileBackedDiskDevice() override;
|
||||
|
||||
bool isValid() const { return m_file; }
|
||||
bool is_valid() const { return m_file; }
|
||||
|
||||
virtual unsigned blockSize() const override;
|
||||
virtual bool readBlock(unsigned index, byte* out) const override;
|
||||
virtual bool writeBlock(unsigned index, const byte*) override;
|
||||
virtual unsigned block_size() const override;
|
||||
virtual bool read_block(unsigned index, byte* out) const override;
|
||||
virtual bool write_block(unsigned index, const byte*) override;
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override;
|
||||
|
||||
bool readInternal(DiskOffset, unsigned length, byte* out) const;
|
||||
bool writeInternal(DiskOffset, unsigned length, const byte* data);
|
||||
bool read_internal(DiskOffset, unsigned length, byte* out) const;
|
||||
bool write_internal(DiskOffset, unsigned length, const byte* data);
|
||||
|
||||
FileBackedDiskDevice(String&& imagePath, unsigned blockSize);
|
||||
FileBackedDiskDevice(String&& imagePath, unsigned block_size);
|
||||
|
||||
String m_imagePath;
|
||||
String m_image_path;
|
||||
FILE* m_file { nullptr };
|
||||
DiskOffset m_fileLength { 0 };
|
||||
unsigned m_blockSize { 0 };
|
||||
DiskOffset m_file_length { 0 };
|
||||
unsigned m_block_size { 0 };
|
||||
};
|
||||
|
||||
|
|
|
@ -296,7 +296,7 @@ bool VFS::mkdir(const String& path, mode_t mode, InodeIdentifier base, int& erro
|
|||
error = EWHYTHO;
|
||||
// FIXME: This won't work nicely across mount boundaries.
|
||||
FileSystemPath p(path);
|
||||
if (!p.isValid()) {
|
||||
if (!p.is_valid()) {
|
||||
error = -EINVAL;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ int main(int c, char** v)
|
|||
RetainPtr<FS> makeFileSystem(const char* imagePath)
|
||||
{
|
||||
auto fsImage = FileBackedDiskDevice::create(imagePath, 512);
|
||||
if (!fsImage->isValid()) {
|
||||
if (!fsImage->is_valid()) {
|
||||
fprintf(stderr, "Failed to open fs image file '%s'\n", imagePath);
|
||||
exit(1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue