mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
Some coding style fixes. I'm getting more comfortable with this style.
This commit is contained in:
parent
7d13432b55
commit
407bb3e76e
13 changed files with 207 additions and 207 deletions
|
@ -240,7 +240,7 @@ ByteBuffer procfs$mounts()
|
|||
VFS::the().for_each_mount([&ptr] (auto& mount) {
|
||||
auto& fs = mount.guest_fs();
|
||||
ptr += ksprintf(ptr, "%s @ ", fs.class_name());
|
||||
if (!mount.host().isValid())
|
||||
if (!mount.host().is_valid())
|
||||
ptr += ksprintf(ptr, "/\n", fs.class_name());
|
||||
else
|
||||
ptr += ksprintf(ptr, "%u:%u\n", mount.host().fsid(), mount.host().index());
|
||||
|
|
|
@ -25,7 +25,7 @@ Ext2FS::~Ext2FS()
|
|||
{
|
||||
}
|
||||
|
||||
ByteBuffer Ext2FS::readSuperBlock() const
|
||||
ByteBuffer Ext2FS::read_super_block() const
|
||||
{
|
||||
auto buffer = ByteBuffer::createUninitialized(1024);
|
||||
device().readBlock(2, buffer.pointer());
|
||||
|
@ -33,7 +33,7 @@ ByteBuffer Ext2FS::readSuperBlock() const
|
|||
return buffer;
|
||||
}
|
||||
|
||||
bool Ext2FS::writeSuperBlock(const ext2_super_block& sb)
|
||||
bool Ext2FS::write_super_block(const ext2_super_block& sb)
|
||||
{
|
||||
const byte* raw = (const byte*)&sb;
|
||||
bool success;
|
||||
|
@ -42,42 +42,42 @@ bool Ext2FS::writeSuperBlock(const ext2_super_block& sb)
|
|||
success = device().writeBlock(3, raw + 512);
|
||||
ASSERT(success);
|
||||
// FIXME: This is an ugly way to refresh the superblock cache. :-|
|
||||
superBlock();
|
||||
super_block();
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned Ext2FS::firstBlockOfGroup(unsigned groupIndex) const
|
||||
unsigned Ext2FS::first_block_of_group(unsigned groupIndex) const
|
||||
{
|
||||
return superBlock().s_first_data_block + (groupIndex * superBlock().s_blocks_per_group);
|
||||
return super_block().s_first_data_block + (groupIndex * super_block().s_blocks_per_group);
|
||||
}
|
||||
|
||||
const ext2_super_block& Ext2FS::superBlock() const
|
||||
const ext2_super_block& Ext2FS::super_block() const
|
||||
{
|
||||
if (!m_cachedSuperBlock)
|
||||
m_cachedSuperBlock = readSuperBlock();
|
||||
return *reinterpret_cast<ext2_super_block*>(m_cachedSuperBlock.pointer());
|
||||
if (!m_cached_super_block)
|
||||
m_cached_super_block = read_super_block();
|
||||
return *reinterpret_cast<ext2_super_block*>(m_cached_super_block.pointer());
|
||||
}
|
||||
|
||||
const ext2_group_desc& Ext2FS::blockGroupDescriptor(unsigned groupIndex) const
|
||||
const ext2_group_desc& Ext2FS::group_descriptor(unsigned groupIndex) const
|
||||
{
|
||||
// FIXME: Should this fail gracefully somehow?
|
||||
ASSERT(groupIndex <= m_blockGroupCount);
|
||||
|
||||
if (!m_cachedBlockGroupDescriptorTable) {
|
||||
if (!m_cached_group_descriptor_table) {
|
||||
unsigned blocksToRead = ceilDiv(m_blockGroupCount * (unsigned)sizeof(ext2_group_desc), blockSize());
|
||||
unsigned firstBlockOfBGDT = blockSize() == 1024 ? 2 : 1;
|
||||
#ifdef EXT2_DEBUG
|
||||
kprintf("ext2fs: block group count: %u, blocks-to-read: %u\n", m_blockGroupCount, blocksToRead);
|
||||
kprintf("ext2fs: first block of BGDT: %u\n", firstBlockOfBGDT);
|
||||
#endif
|
||||
m_cachedBlockGroupDescriptorTable = readBlocks(firstBlockOfBGDT, blocksToRead);
|
||||
m_cached_group_descriptor_table = readBlocks(firstBlockOfBGDT, blocksToRead);
|
||||
}
|
||||
return reinterpret_cast<ext2_group_desc*>(m_cachedBlockGroupDescriptorTable.pointer())[groupIndex - 1];
|
||||
return reinterpret_cast<ext2_group_desc*>(m_cached_group_descriptor_table.pointer())[groupIndex - 1];
|
||||
}
|
||||
|
||||
bool Ext2FS::initialize()
|
||||
{
|
||||
auto& superBlock = this->superBlock();
|
||||
auto& superBlock = this->super_block();
|
||||
#ifdef EXT2_DEBUG
|
||||
kprintf("ext2fs: super block magic: %x (super block size: %u)\n", superBlock.s_magic, sizeof(ext2_super_block));
|
||||
#endif
|
||||
|
@ -105,7 +105,7 @@ bool Ext2FS::initialize()
|
|||
}
|
||||
|
||||
// Preheat the BGD cache.
|
||||
blockGroupDescriptor(0);
|
||||
group_descriptor(0);
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
for (unsigned i = 1; i <= m_blockGroupCount; ++i) {
|
||||
|
@ -126,7 +126,7 @@ const char* Ext2FS::class_name() const
|
|||
return "ext2fs";
|
||||
}
|
||||
|
||||
InodeIdentifier Ext2FS::rootInode() const
|
||||
InodeIdentifier Ext2FS::root_inode() const
|
||||
{
|
||||
return { id(), EXT2_ROOT_INO };
|
||||
}
|
||||
|
@ -143,9 +143,9 @@ static void dumpExt2Inode(const ext2_inode& inode)
|
|||
}
|
||||
#endif
|
||||
|
||||
ByteBuffer Ext2FS::readBlockContainingInode(unsigned inode, unsigned& blockIndex, unsigned& offset) const
|
||||
ByteBuffer Ext2FS::read_block_containing_inode(unsigned inode, unsigned& blockIndex, unsigned& offset) const
|
||||
{
|
||||
auto& superBlock = this->superBlock();
|
||||
auto& superBlock = this->super_block();
|
||||
|
||||
if (inode != EXT2_ROOT_INO && inode < EXT2_FIRST_INO(&superBlock))
|
||||
return { };
|
||||
|
@ -153,26 +153,26 @@ ByteBuffer Ext2FS::readBlockContainingInode(unsigned inode, unsigned& blockIndex
|
|||
if (inode > superBlock.s_inodes_count)
|
||||
return { };
|
||||
|
||||
auto& bgd = blockGroupDescriptor(groupIndexFromInode(inode));
|
||||
auto& bgd = group_descriptor(group_index_from_inode(inode));
|
||||
|
||||
offset = ((inode - 1) % inodesPerGroup()) * inodeSize();
|
||||
offset = ((inode - 1) % inodes_per_group()) * inode_size();
|
||||
blockIndex = bgd.bg_inode_table + (offset >> EXT2_BLOCK_SIZE_BITS(&superBlock));
|
||||
offset &= blockSize() - 1;
|
||||
|
||||
return readBlock(blockIndex);
|
||||
}
|
||||
|
||||
OwnPtr<ext2_inode> Ext2FS::lookupExt2Inode(unsigned inode) const
|
||||
OwnPtr<ext2_inode> Ext2FS::lookup_ext2_inode(unsigned inode) const
|
||||
{
|
||||
unsigned blockIndex;
|
||||
unsigned offset;
|
||||
auto block = readBlockContainingInode(inode, blockIndex, offset);
|
||||
auto block = read_block_containing_inode(inode, blockIndex, offset);
|
||||
|
||||
if (!block)
|
||||
return { };
|
||||
|
||||
auto* e2inode = reinterpret_cast<ext2_inode*>(kmalloc(inodeSize()));
|
||||
memcpy(e2inode, reinterpret_cast<ext2_inode*>(block.offsetPointer(offset)), inodeSize());
|
||||
auto* e2inode = reinterpret_cast<ext2_inode*>(kmalloc(inode_size()));
|
||||
memcpy(e2inode, reinterpret_cast<ext2_inode*>(block.offsetPointer(offset)), inode_size());
|
||||
#ifdef EXT2_DEBUG
|
||||
dumpExt2Inode(*e2inode);
|
||||
#endif
|
||||
|
@ -180,11 +180,11 @@ OwnPtr<ext2_inode> Ext2FS::lookupExt2Inode(unsigned inode) const
|
|||
return OwnPtr<ext2_inode>(e2inode);
|
||||
}
|
||||
|
||||
InodeMetadata Ext2FS::inodeMetadata(InodeIdentifier inode) const
|
||||
InodeMetadata Ext2FS::inode_metadata(InodeIdentifier inode) const
|
||||
{
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
||||
auto e2inode = lookupExt2Inode(inode.index());
|
||||
auto e2inode = lookup_ext2_inode(inode.index());
|
||||
if (!e2inode)
|
||||
return InodeMetadata();
|
||||
|
||||
|
@ -211,9 +211,9 @@ InodeMetadata Ext2FS::inodeMetadata(InodeIdentifier inode) const
|
|||
return metadata;
|
||||
}
|
||||
|
||||
Vector<unsigned> Ext2FS::blockListForInode(const ext2_inode& e2inode) const
|
||||
Vector<unsigned> Ext2FS::block_list_for_inode(const ext2_inode& e2inode) const
|
||||
{
|
||||
unsigned entriesPerBlock = EXT2_ADDR_PER_BLOCK(&superBlock());
|
||||
unsigned entriesPerBlock = EXT2_ADDR_PER_BLOCK(&super_block());
|
||||
|
||||
// NOTE: i_blocks is number of 512-byte blocks, not number of fs-blocks.
|
||||
unsigned blockCount = e2inode.i_blocks / (blockSize() / 512);
|
||||
|
@ -313,7 +313,7 @@ RetainPtr<CoreInode> Ext2FS::get_inode(InodeIdentifier inode) const
|
|||
if (it != m_inode_cache.end())
|
||||
return (*it).value;
|
||||
}
|
||||
auto raw_inode = lookupExt2Inode(inode.index());
|
||||
auto raw_inode = lookup_ext2_inode(inode.index());
|
||||
if (!raw_inode)
|
||||
return nullptr;
|
||||
LOCKER(m_inode_cache_lock);
|
||||
|
@ -341,7 +341,7 @@ ssize_t Ext2FSInode::read_bytes(Unix::off_t offset, size_t count, byte* buffer,
|
|||
}
|
||||
|
||||
if (m_block_list.isEmpty()) {
|
||||
auto block_list = fs().blockListForInode(m_raw_inode);
|
||||
auto block_list = fs().block_list_for_inode(m_raw_inode);
|
||||
LOCKER(m_lock);
|
||||
if (m_block_list.size() != block_list.size())
|
||||
m_block_list = move(block_list);
|
||||
|
@ -392,7 +392,7 @@ ssize_t Ext2FS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset, size
|
|||
ASSERT(offset >= 0);
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
||||
auto e2inode = lookupExt2Inode(inode.index());
|
||||
auto e2inode = lookup_ext2_inode(inode.index());
|
||||
if (!e2inode) {
|
||||
kprintf("ext2fs: readInodeBytes: metadata lookup for inode %u failed\n", inode.index());
|
||||
return -EIO;
|
||||
|
@ -418,7 +418,7 @@ ssize_t Ext2FS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset, size
|
|||
|
||||
// FIXME: It's grossly inefficient to fetch the blocklist on every call to readInodeBytes().
|
||||
// It needs to be cached!
|
||||
auto list = blockListForInode(*e2inode);
|
||||
auto list = block_list_for_inode(*e2inode);
|
||||
if (list.isEmpty()) {
|
||||
kprintf("ext2fs: readInodeBytes: empty block list for inode %u\n", inode.index());
|
||||
return -EIO;
|
||||
|
@ -463,11 +463,11 @@ ssize_t Ext2FS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset, size
|
|||
return nread;
|
||||
}
|
||||
|
||||
bool Ext2FS::writeInode(InodeIdentifier inode, const ByteBuffer& data)
|
||||
bool Ext2FS::write_inode(InodeIdentifier inode, const ByteBuffer& data)
|
||||
{
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
||||
auto e2inode = lookupExt2Inode(inode.index());
|
||||
auto e2inode = lookup_ext2_inode(inode.index());
|
||||
if (!e2inode) {
|
||||
kprintf("ext2fs: writeInode: metadata lookup for inode %u failed\n", inode.index());
|
||||
return false;
|
||||
|
@ -482,7 +482,7 @@ bool Ext2FS::writeInode(InodeIdentifier inode, const ByteBuffer& data)
|
|||
// FIXME: Support growing or shrinking the block list.
|
||||
ASSERT(blocksNeededBefore == blocksNeededAfter);
|
||||
|
||||
auto list = blockListForInode(*e2inode);
|
||||
auto list = block_list_for_inode(*e2inode);
|
||||
if (list.isEmpty()) {
|
||||
kprintf("ext2fs: writeInode: empty block list for inode %u\n", inode.index());
|
||||
return false;
|
||||
|
@ -526,13 +526,13 @@ bool Ext2FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)
|
|||
bool Ext2FS::deprecated_enumerateDirectoryInode(InodeIdentifier inode, Function<bool(const DirectoryEntry&)> callback) const
|
||||
{
|
||||
ASSERT(inode.fsid() == id());
|
||||
ASSERT(isDirectoryInode(inode.index()));
|
||||
ASSERT(is_directory_inode(inode.index()));
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
kprintf("ext2fs: Enumerating directory contents of inode %u:\n", inode.index());
|
||||
#endif
|
||||
|
||||
auto buffer = readEntireInode(inode);
|
||||
auto buffer = read_entire_inode(inode);
|
||||
ASSERT(buffer);
|
||||
auto* entry = reinterpret_cast<ext2_dir_entry_2*>(buffer.pointer());
|
||||
|
||||
|
@ -549,9 +549,9 @@ bool Ext2FS::deprecated_enumerateDirectoryInode(InodeIdentifier inode, Function<
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Ext2FS::addInodeToDirectory(unsigned directoryInode, unsigned inode, const String& name, byte fileType, int& error)
|
||||
bool Ext2FS::add_inode_to_directory(unsigned directoryInode, unsigned inode, const String& name, byte fileType, int& error)
|
||||
{
|
||||
auto e2inodeForDirectory = lookupExt2Inode(directoryInode);
|
||||
auto e2inodeForDirectory = lookup_ext2_inode(directoryInode);
|
||||
ASSERT(e2inodeForDirectory);
|
||||
ASSERT(isDirectory(e2inodeForDirectory->i_mode));
|
||||
|
||||
|
@ -576,10 +576,10 @@ bool Ext2FS::addInodeToDirectory(unsigned directoryInode, unsigned inode, const
|
|||
}
|
||||
|
||||
entries.append({ name.characters(), name.length(), { id(), inode }, fileType });
|
||||
return writeDirectoryInode(directoryInode, move(entries));
|
||||
return write_directory_inode(directoryInode, move(entries));
|
||||
}
|
||||
|
||||
bool Ext2FS::writeDirectoryInode(unsigned directoryInode, Vector<DirectoryEntry>&& entries)
|
||||
bool Ext2FS::write_directory_inode(unsigned directoryInode, Vector<DirectoryEntry>&& entries)
|
||||
{
|
||||
dbgprintf("Ext2FS: New directory inode %u contents to write:\n", directoryInode);
|
||||
|
||||
|
@ -637,37 +637,37 @@ bool Ext2FS::writeDirectoryInode(unsigned directoryInode, Vector<DirectoryEntry>
|
|||
kprintf("\n");
|
||||
#endif
|
||||
|
||||
writeInode({ id(), directoryInode }, directoryData);
|
||||
write_inode({ id(), directoryInode }, directoryData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned Ext2FS::inodesPerBlock() const
|
||||
unsigned Ext2FS::inodes_per_block() const
|
||||
{
|
||||
return EXT2_INODES_PER_BLOCK(&superBlock());
|
||||
return EXT2_INODES_PER_BLOCK(&super_block());
|
||||
}
|
||||
|
||||
unsigned Ext2FS::inodesPerGroup() const
|
||||
unsigned Ext2FS::inodes_per_group() const
|
||||
{
|
||||
return EXT2_INODES_PER_GROUP(&superBlock());
|
||||
return EXT2_INODES_PER_GROUP(&super_block());
|
||||
}
|
||||
|
||||
unsigned Ext2FS::inodeSize() const
|
||||
unsigned Ext2FS::inode_size() const
|
||||
{
|
||||
return EXT2_INODE_SIZE(&superBlock());
|
||||
return EXT2_INODE_SIZE(&super_block());
|
||||
|
||||
}
|
||||
unsigned Ext2FS::blocksPerGroup() const
|
||||
unsigned Ext2FS::blocks_per_group() const
|
||||
{
|
||||
return EXT2_BLOCKS_PER_GROUP(&superBlock());
|
||||
return EXT2_BLOCKS_PER_GROUP(&super_block());
|
||||
}
|
||||
|
||||
void Ext2FS::dumpBlockBitmap(unsigned groupIndex) const
|
||||
void Ext2FS::dump_block_bitmap(unsigned groupIndex) const
|
||||
{
|
||||
ASSERT(groupIndex <= m_blockGroupCount);
|
||||
auto& bgd = blockGroupDescriptor(groupIndex);
|
||||
auto& bgd = group_descriptor(groupIndex);
|
||||
|
||||
unsigned blocksInGroup = min(blocksPerGroup(), superBlock().s_blocks_count);
|
||||
unsigned blocksInGroup = min(blocks_per_group(), super_block().s_blocks_count);
|
||||
unsigned blockCount = ceilDiv(blocksInGroup, 8u);
|
||||
|
||||
auto bitmapBlocks = readBlocks(bgd.bg_block_bitmap, blockCount);
|
||||
|
@ -682,9 +682,9 @@ void Ext2FS::dumpBlockBitmap(unsigned groupIndex) const
|
|||
kprintf("\n");
|
||||
}
|
||||
|
||||
void Ext2FS::dumpInodeBitmap(unsigned groupIndex) const
|
||||
void Ext2FS::dump_inode_bitmap(unsigned groupIndex) const
|
||||
{
|
||||
traverseInodeBitmap(groupIndex, [] (unsigned, const Bitmap& bitmap) {
|
||||
traverse_inode_bitmap(groupIndex, [] (unsigned, const Bitmap& bitmap) {
|
||||
for (unsigned i = 0; i < bitmap.size(); ++i)
|
||||
kprintf("%c", bitmap.get(i) ? '1' : '0');
|
||||
return true;
|
||||
|
@ -692,12 +692,12 @@ void Ext2FS::dumpInodeBitmap(unsigned groupIndex) const
|
|||
}
|
||||
|
||||
template<typename F>
|
||||
void Ext2FS::traverseInodeBitmap(unsigned groupIndex, F callback) const
|
||||
void Ext2FS::traverse_inode_bitmap(unsigned groupIndex, F callback) const
|
||||
{
|
||||
ASSERT(groupIndex <= m_blockGroupCount);
|
||||
auto& bgd = blockGroupDescriptor(groupIndex);
|
||||
auto& bgd = group_descriptor(groupIndex);
|
||||
|
||||
unsigned inodesInGroup = min(inodesPerGroup(), superBlock().s_inodes_count);
|
||||
unsigned inodesInGroup = min(inodes_per_group(), super_block().s_inodes_count);
|
||||
unsigned blockCount = ceilDiv(inodesInGroup, 8u);
|
||||
|
||||
for (unsigned i = 0; i < blockCount; ++i) {
|
||||
|
@ -710,12 +710,12 @@ void Ext2FS::traverseInodeBitmap(unsigned groupIndex, F callback) const
|
|||
}
|
||||
|
||||
template<typename F>
|
||||
void Ext2FS::traverseBlockBitmap(unsigned groupIndex, F callback) const
|
||||
void Ext2FS::traverse_block_bitmap(unsigned groupIndex, F callback) const
|
||||
{
|
||||
ASSERT(groupIndex <= m_blockGroupCount);
|
||||
auto& bgd = blockGroupDescriptor(groupIndex);
|
||||
auto& bgd = group_descriptor(groupIndex);
|
||||
|
||||
unsigned blocksInGroup = min(blocksPerGroup(), superBlock().s_blocks_count);
|
||||
unsigned blocksInGroup = min(blocks_per_group(), super_block().s_blocks_count);
|
||||
unsigned blockCount = ceilDiv(blocksInGroup, 8u);
|
||||
|
||||
for (unsigned i = 0; i < blockCount; ++i) {
|
||||
|
@ -727,10 +727,10 @@ void Ext2FS::traverseBlockBitmap(unsigned groupIndex, F callback) const
|
|||
}
|
||||
}
|
||||
|
||||
bool Ext2FS::modifyLinkCount(InodeIndex inode, int delta)
|
||||
bool Ext2FS::modify_link_count(InodeIndex inode, int delta)
|
||||
{
|
||||
ASSERT(inode);
|
||||
auto e2inode = lookupExt2Inode(inode);
|
||||
auto e2inode = lookup_ext2_inode(inode);
|
||||
if (!e2inode)
|
||||
return false;
|
||||
|
||||
|
@ -738,28 +738,28 @@ bool Ext2FS::modifyLinkCount(InodeIndex inode, int delta)
|
|||
dbgprintf("Ext2FS: changing inode %u link count from %u to %u\n", inode, e2inode->i_links_count, newLinkCount);
|
||||
e2inode->i_links_count = newLinkCount;
|
||||
|
||||
return writeExt2Inode(inode, *e2inode);
|
||||
return write_ext2_inode(inode, *e2inode);
|
||||
}
|
||||
|
||||
bool Ext2FS::set_mtime(InodeIdentifier inode, dword timestamp)
|
||||
{
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
||||
auto e2inode = lookupExt2Inode(inode.index());
|
||||
auto e2inode = lookup_ext2_inode(inode.index());
|
||||
if (!e2inode)
|
||||
return false;
|
||||
|
||||
kprintf("changing inode %u mtime from %u to %u\n", inode.index(), e2inode->i_mtime, timestamp);
|
||||
e2inode->i_mtime = timestamp;
|
||||
|
||||
return writeExt2Inode(inode.index(), *e2inode);
|
||||
return write_ext2_inode(inode.index(), *e2inode);
|
||||
}
|
||||
|
||||
bool Ext2FS::writeExt2Inode(unsigned inode, const ext2_inode& e2inode)
|
||||
bool Ext2FS::write_ext2_inode(unsigned inode, const ext2_inode& e2inode)
|
||||
{
|
||||
unsigned blockIndex;
|
||||
unsigned offset;
|
||||
auto block = readBlockContainingInode(inode, blockIndex, offset);
|
||||
auto block = read_block_containing_inode(inode, blockIndex, offset);
|
||||
if (!block)
|
||||
return false;
|
||||
{
|
||||
|
@ -774,23 +774,23 @@ bool Ext2FS::writeExt2Inode(unsigned inode, const ext2_inode& e2inode)
|
|||
cached_inode.m_lookup_cache.clear();
|
||||
}
|
||||
}
|
||||
memcpy(reinterpret_cast<ext2_inode*>(block.offsetPointer(offset)), &e2inode, inodeSize());
|
||||
memcpy(reinterpret_cast<ext2_inode*>(block.offsetPointer(offset)), &e2inode, inode_size());
|
||||
writeBlock(blockIndex, block);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ext2FS::isDirectoryInode(unsigned inode) const
|
||||
bool Ext2FS::is_directory_inode(unsigned inode) const
|
||||
{
|
||||
if (auto e2inode = lookupExt2Inode(inode))
|
||||
if (auto e2inode = lookup_ext2_inode(inode))
|
||||
return isDirectory(e2inode->i_mode);
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector<Ext2FS::BlockIndex> Ext2FS::allocateBlocks(unsigned group, unsigned count)
|
||||
Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(unsigned group, unsigned count)
|
||||
{
|
||||
dbgprintf("Ext2FS: allocateBlocks(group: %u, count: %u)\n", group, count);
|
||||
|
||||
auto& bgd = blockGroupDescriptor(group);
|
||||
auto& bgd = group_descriptor(group);
|
||||
if (bgd.bg_free_blocks_count < count) {
|
||||
kprintf("ExtFS: allocateBlocks can't allocate out of group %u, wanted %u but only %u available\n", group, count, bgd.bg_free_blocks_count);
|
||||
return { };
|
||||
|
@ -798,7 +798,7 @@ Vector<Ext2FS::BlockIndex> Ext2FS::allocateBlocks(unsigned group, unsigned count
|
|||
|
||||
// FIXME: Implement a scan that finds consecutive blocks if possible.
|
||||
Vector<BlockIndex> blocks;
|
||||
traverseBlockBitmap(group, [&blocks, count] (unsigned firstBlockInBitmap, const Bitmap& bitmap) {
|
||||
traverse_block_bitmap(group, [&blocks, count] (unsigned firstBlockInBitmap, const Bitmap& bitmap) {
|
||||
for (unsigned i = 0; i < bitmap.size(); ++i) {
|
||||
if (!bitmap.get(i)) {
|
||||
blocks.append(firstBlockInBitmap + i);
|
||||
|
@ -816,7 +816,7 @@ Vector<Ext2FS::BlockIndex> Ext2FS::allocateBlocks(unsigned group, unsigned count
|
|||
return blocks;
|
||||
}
|
||||
|
||||
unsigned Ext2FS::allocateInode(unsigned preferredGroup, unsigned expectedSize)
|
||||
unsigned Ext2FS::allocate_inode(unsigned preferredGroup, unsigned expectedSize)
|
||||
{
|
||||
dbgprintf("Ext2FS: allocateInode(preferredGroup: %u, expectedSize: %u)\n", preferredGroup, expectedSize);
|
||||
|
||||
|
@ -827,7 +827,7 @@ unsigned Ext2FS::allocateInode(unsigned preferredGroup, unsigned expectedSize)
|
|||
unsigned groupIndex = 0;
|
||||
|
||||
auto isSuitableGroup = [this, neededBlocks] (unsigned groupIndex) {
|
||||
auto& bgd = blockGroupDescriptor(groupIndex);
|
||||
auto& bgd = group_descriptor(groupIndex);
|
||||
return bgd.bg_free_inodes_count && bgd.bg_free_blocks_count >= neededBlocks;
|
||||
};
|
||||
|
||||
|
@ -848,7 +848,7 @@ unsigned Ext2FS::allocateInode(unsigned preferredGroup, unsigned expectedSize)
|
|||
dbgprintf("Ext2FS: allocateInode: found suitable group [%u] for new inode with %u blocks needed :^)\n", groupIndex, neededBlocks);
|
||||
|
||||
unsigned firstFreeInodeInGroup = 0;
|
||||
traverseInodeBitmap(groupIndex, [&firstFreeInodeInGroup] (unsigned firstInodeInBitmap, const Bitmap& bitmap) {
|
||||
traverse_inode_bitmap(groupIndex, [&firstFreeInodeInGroup] (unsigned firstInodeInBitmap, const Bitmap& bitmap) {
|
||||
for (unsigned i = 0; i < bitmap.size(); ++i) {
|
||||
if (!bitmap.get(i)) {
|
||||
firstFreeInodeInGroup = firstInodeInBitmap + i;
|
||||
|
@ -871,16 +871,16 @@ unsigned Ext2FS::allocateInode(unsigned preferredGroup, unsigned expectedSize)
|
|||
return inode;
|
||||
}
|
||||
|
||||
unsigned Ext2FS::groupIndexFromInode(unsigned inode) const
|
||||
unsigned Ext2FS::group_index_from_inode(unsigned inode) const
|
||||
{
|
||||
if (!inode)
|
||||
return 0;
|
||||
return (inode - 1) / inodesPerGroup() + 1;
|
||||
return (inode - 1) / inodes_per_group() + 1;
|
||||
}
|
||||
|
||||
bool Ext2FS::setInodeAllocationState(unsigned inode, bool newState)
|
||||
bool Ext2FS::set_inode_allocation_state(unsigned inode, bool newState)
|
||||
{
|
||||
auto& bgd = blockGroupDescriptor(groupIndexFromInode(inode));
|
||||
auto& bgd = group_descriptor(group_index_from_inode(inode));
|
||||
|
||||
// Update inode bitmap
|
||||
unsigned inodesPerBitmapBlock = blockSize() * 8;
|
||||
|
@ -899,13 +899,13 @@ bool Ext2FS::setInodeAllocationState(unsigned inode, bool newState)
|
|||
writeBlock(bgd.bg_inode_bitmap + bitmapBlockIndex, block);
|
||||
|
||||
// Update superblock
|
||||
auto& sb = *reinterpret_cast<ext2_super_block*>(m_cachedSuperBlock.pointer());
|
||||
auto& sb = *reinterpret_cast<ext2_super_block*>(m_cached_super_block.pointer());
|
||||
dbgprintf("Ext2FS: superblock free inode count %u -> %u\n", sb.s_free_inodes_count, sb.s_free_inodes_count - 1);
|
||||
if (newState)
|
||||
--sb.s_free_inodes_count;
|
||||
else
|
||||
++sb.s_free_inodes_count;
|
||||
writeSuperBlock(sb);
|
||||
write_super_block(sb);
|
||||
|
||||
// Update BGD
|
||||
auto& mutableBGD = const_cast<ext2_group_desc&>(bgd);
|
||||
|
@ -917,14 +917,14 @@ bool Ext2FS::setInodeAllocationState(unsigned inode, bool newState)
|
|||
|
||||
unsigned blocksToWrite = ceilDiv(m_blockGroupCount * (unsigned)sizeof(ext2_group_desc), blockSize());
|
||||
unsigned firstBlockOfBGDT = blockSize() == 1024 ? 2 : 1;
|
||||
writeBlocks(firstBlockOfBGDT, blocksToWrite, m_cachedBlockGroupDescriptorTable);
|
||||
writeBlocks(firstBlockOfBGDT, blocksToWrite, m_cached_group_descriptor_table);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ext2FS::setBlockAllocationState(GroupIndex group, BlockIndex bi, bool newState)
|
||||
bool Ext2FS::set_block_allocation_state(GroupIndex group, BlockIndex bi, bool newState)
|
||||
{
|
||||
auto& bgd = blockGroupDescriptor(group);
|
||||
auto& bgd = group_descriptor(group);
|
||||
|
||||
// Update block bitmap
|
||||
unsigned blocksPerBitmapBlock = blockSize() * 8;
|
||||
|
@ -943,13 +943,13 @@ bool Ext2FS::setBlockAllocationState(GroupIndex group, BlockIndex bi, bool newSt
|
|||
writeBlock(bgd.bg_block_bitmap + bitmapBlockIndex, block);
|
||||
|
||||
// Update superblock
|
||||
auto& sb = *reinterpret_cast<ext2_super_block*>(m_cachedSuperBlock.pointer());
|
||||
auto& sb = *reinterpret_cast<ext2_super_block*>(m_cached_super_block.pointer());
|
||||
dbgprintf("Ext2FS: superblock free block count %u -> %u\n", sb.s_free_blocks_count, sb.s_free_blocks_count - 1);
|
||||
if (newState)
|
||||
--sb.s_free_blocks_count;
|
||||
else
|
||||
++sb.s_free_blocks_count;
|
||||
writeSuperBlock(sb);
|
||||
write_super_block(sb);
|
||||
|
||||
// Update BGD
|
||||
auto& mutableBGD = const_cast<ext2_group_desc&>(bgd);
|
||||
|
@ -961,7 +961,7 @@ bool Ext2FS::setBlockAllocationState(GroupIndex group, BlockIndex bi, bool newSt
|
|||
|
||||
unsigned blocksToWrite = ceilDiv(m_blockGroupCount * (unsigned)sizeof(ext2_group_desc), blockSize());
|
||||
unsigned firstBlockOfBGDT = blockSize() == 1024 ? 2 : 1;
|
||||
writeBlocks(firstBlockOfBGDT, blocksToWrite, m_cachedBlockGroupDescriptorTable);
|
||||
writeBlocks(firstBlockOfBGDT, blocksToWrite, m_cached_group_descriptor_table);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -969,7 +969,7 @@ bool Ext2FS::setBlockAllocationState(GroupIndex group, BlockIndex bi, bool newSt
|
|||
InodeIdentifier Ext2FS::create_directory(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, int& error)
|
||||
{
|
||||
ASSERT(parentInode.fsid() == id());
|
||||
ASSERT(isDirectoryInode(parentInode.index()));
|
||||
ASSERT(is_directory_inode(parentInode.index()));
|
||||
|
||||
// Fix up the mode to definitely be a directory.
|
||||
// FIXME: This is a bit on the hackish side.
|
||||
|
@ -979,7 +979,7 @@ InodeIdentifier Ext2FS::create_directory(InodeIdentifier parentInode, const Stri
|
|||
// NOTE: When creating a new directory, make the size 1 block.
|
||||
// There's probably a better strategy here, but this works for now.
|
||||
auto inode = create_inode(parentInode, name, mode, blockSize(), error);
|
||||
if (!inode.isValid())
|
||||
if (!inode.is_valid())
|
||||
return { };
|
||||
|
||||
dbgprintf("Ext2FS: create_directory: created new directory named '%s' with inode %u\n", name.characters(), inode.index());
|
||||
|
@ -988,19 +988,19 @@ InodeIdentifier Ext2FS::create_directory(InodeIdentifier parentInode, const Stri
|
|||
entries.append({ ".", inode, EXT2_FT_DIR });
|
||||
entries.append({ "..", parentInode, EXT2_FT_DIR });
|
||||
|
||||
bool success = writeDirectoryInode(inode.index(), move(entries));
|
||||
bool success = write_directory_inode(inode.index(), move(entries));
|
||||
ASSERT(success);
|
||||
|
||||
success = modifyLinkCount(parentInode.index(), 1);
|
||||
success = modify_link_count(parentInode.index(), 1);
|
||||
ASSERT(success);
|
||||
|
||||
auto& bgd = const_cast<ext2_group_desc&>(blockGroupDescriptor(groupIndexFromInode(inode.index())));
|
||||
auto& bgd = const_cast<ext2_group_desc&>(group_descriptor(group_index_from_inode(inode.index())));
|
||||
++bgd.bg_used_dirs_count;
|
||||
dbgprintf("Ext2FS: incremented bg_used_dirs_count %u -> %u\n", bgd.bg_used_dirs_count - 1, bgd.bg_used_dirs_count);
|
||||
|
||||
unsigned blocksToWrite = ceilDiv(m_blockGroupCount * (unsigned)sizeof(ext2_group_desc), blockSize());
|
||||
unsigned firstBlockOfBGDT = blockSize() == 1024 ? 2 : 1;
|
||||
writeBlocks(firstBlockOfBGDT, blocksToWrite, m_cachedBlockGroupDescriptorTable);
|
||||
writeBlocks(firstBlockOfBGDT, blocksToWrite, m_cached_group_descriptor_table);
|
||||
|
||||
error = 0;
|
||||
return inode;
|
||||
|
@ -1009,19 +1009,19 @@ InodeIdentifier Ext2FS::create_directory(InodeIdentifier parentInode, const Stri
|
|||
InodeIdentifier Ext2FS::create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t mode, unsigned size, int& error)
|
||||
{
|
||||
ASSERT(parentInode.fsid() == id());
|
||||
ASSERT(isDirectoryInode(parentInode.index()));
|
||||
ASSERT(is_directory_inode(parentInode.index()));
|
||||
|
||||
dbgprintf("Ext2FS: Adding inode '%s' (mode %u) to parent directory %u:\n", name.characters(), mode, parentInode.index());
|
||||
|
||||
// NOTE: This doesn't commit the inode allocation just yet!
|
||||
auto inode = allocateInode(0, 0);
|
||||
auto inode = allocate_inode(0, 0);
|
||||
if (!inode) {
|
||||
kprintf("Ext2FS: createInode: allocateInode failed\n");
|
||||
error = -ENOSPC;
|
||||
return { };
|
||||
}
|
||||
|
||||
auto blocks = allocateBlocks(groupIndexFromInode(inode), ceilDiv(size, blockSize()));
|
||||
auto blocks = allocate_blocks(group_index_from_inode(inode), ceilDiv(size, blockSize()));
|
||||
if (blocks.isEmpty()) {
|
||||
kprintf("Ext2FS: createInode: allocateBlocks failed\n");
|
||||
error = -ENOSPC;
|
||||
|
@ -1045,16 +1045,16 @@ InodeIdentifier Ext2FS::create_inode(InodeIdentifier parentInode, const String&
|
|||
fileType = EXT2_FT_SYMLINK;
|
||||
|
||||
// Try adding it to the directory first, in case the name is already in use.
|
||||
bool success = addInodeToDirectory(parentInode.index(), inode, name, fileType, error);
|
||||
bool success = add_inode_to_directory(parentInode.index(), inode, name, fileType, error);
|
||||
if (!success)
|
||||
return { };
|
||||
|
||||
// Looks like we're good, time to update the inode bitmap and group+global inode counters.
|
||||
success = setInodeAllocationState(inode, true);
|
||||
success = set_inode_allocation_state(inode, true);
|
||||
ASSERT(success);
|
||||
|
||||
for (auto bi : blocks) {
|
||||
success = setBlockAllocationState(groupIndexFromInode(inode), bi, true);
|
||||
success = set_block_allocation_state(group_index_from_inode(inode), bi, true);
|
||||
ASSERT(success);
|
||||
}
|
||||
|
||||
|
@ -1087,7 +1087,7 @@ InodeIdentifier Ext2FS::create_inode(InodeIdentifier parentInode, const String&
|
|||
}
|
||||
|
||||
e2inode->i_flags = 0;
|
||||
success = writeExt2Inode(inode, *e2inode);
|
||||
success = write_ext2_inode(inode, *e2inode);
|
||||
ASSERT(success);
|
||||
|
||||
return { id(), inode };
|
||||
|
@ -1098,12 +1098,12 @@ InodeIdentifier Ext2FS::find_parent_of_inode(InodeIdentifier inode_id) const
|
|||
auto inode = get_inode(inode_id);
|
||||
ASSERT(inode);
|
||||
|
||||
unsigned groupIndex = groupIndexFromInode(inode->index());
|
||||
unsigned firstInodeInGroup = inodesPerGroup() * (groupIndex - 1);
|
||||
unsigned groupIndex = group_index_from_inode(inode->index());
|
||||
unsigned firstInodeInGroup = inodes_per_group() * (groupIndex - 1);
|
||||
|
||||
Vector<RetainPtr<Ext2FSInode>> directories_in_group;
|
||||
|
||||
for (unsigned i = 0; i < inodesPerGroup(); ++i) {
|
||||
for (unsigned i = 0; i < inodes_per_group(); ++i) {
|
||||
auto group_member = get_inode({ id(), firstInodeInGroup + i });
|
||||
if (!group_member)
|
||||
continue;
|
||||
|
|
|
@ -53,25 +53,25 @@ private:
|
|||
typedef unsigned InodeIndex;
|
||||
explicit Ext2FS(RetainPtr<DiskDevice>&&);
|
||||
|
||||
const ext2_super_block& superBlock() const;
|
||||
const ext2_group_desc& blockGroupDescriptor(unsigned groupIndex) const;
|
||||
unsigned firstBlockOfGroup(unsigned groupIndex) const;
|
||||
unsigned inodesPerBlock() const;
|
||||
unsigned inodesPerGroup() const;
|
||||
unsigned blocksPerGroup() const;
|
||||
unsigned inodeSize() const;
|
||||
const ext2_super_block& super_block() const;
|
||||
const ext2_group_desc& group_descriptor(unsigned groupIndex) const;
|
||||
unsigned first_block_of_group(unsigned groupIndex) const;
|
||||
unsigned inodes_per_block() const;
|
||||
unsigned inodes_per_group() const;
|
||||
unsigned blocks_per_group() const;
|
||||
unsigned inode_size() const;
|
||||
|
||||
OwnPtr<ext2_inode> lookupExt2Inode(unsigned) const;
|
||||
bool writeExt2Inode(unsigned, const ext2_inode&);
|
||||
ByteBuffer readBlockContainingInode(unsigned inode, unsigned& blockIndex, unsigned& offset) const;
|
||||
OwnPtr<ext2_inode> lookup_ext2_inode(unsigned) const;
|
||||
bool write_ext2_inode(unsigned, const ext2_inode&);
|
||||
ByteBuffer read_block_containing_inode(unsigned inode, unsigned& blockIndex, unsigned& offset) const;
|
||||
|
||||
ByteBuffer readSuperBlock() const;
|
||||
bool writeSuperBlock(const ext2_super_block&);
|
||||
ByteBuffer read_super_block() const;
|
||||
bool write_super_block(const ext2_super_block&);
|
||||
|
||||
virtual const char* class_name() const override;
|
||||
virtual InodeIdentifier rootInode() const override;
|
||||
virtual bool writeInode(InodeIdentifier, const ByteBuffer&) override;
|
||||
virtual InodeMetadata inodeMetadata(InodeIdentifier) const override;
|
||||
virtual InodeIdentifier root_inode() const override;
|
||||
virtual bool write_inode(InodeIdentifier, const ByteBuffer&) override;
|
||||
virtual InodeMetadata inode_metadata(InodeIdentifier) const override;
|
||||
virtual bool set_mtime(InodeIdentifier, dword timestamp) override;
|
||||
virtual InodeIdentifier create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size, int& error) override;
|
||||
virtual ssize_t read_inode_bytes(InodeIdentifier, Unix::off_t offset, size_t count, byte* buffer, FileDescriptor*) const override;
|
||||
|
@ -79,32 +79,32 @@ private:
|
|||
virtual InodeIdentifier find_parent_of_inode(InodeIdentifier) const override;
|
||||
virtual RetainPtr<CoreInode> get_inode(InodeIdentifier) const override;
|
||||
|
||||
bool isDirectoryInode(unsigned) const;
|
||||
unsigned allocateInode(unsigned preferredGroup, unsigned expectedSize);
|
||||
Vector<BlockIndex> allocateBlocks(unsigned group, unsigned count);
|
||||
unsigned groupIndexFromInode(unsigned) const;
|
||||
bool is_directory_inode(unsigned) const;
|
||||
unsigned allocate_inode(unsigned preferredGroup, unsigned expectedSize);
|
||||
Vector<BlockIndex> allocate_blocks(unsigned group, unsigned count);
|
||||
unsigned group_index_from_inode(unsigned) const;
|
||||
|
||||
Vector<unsigned> blockListForInode(const ext2_inode&) const;
|
||||
Vector<unsigned> block_list_for_inode(const ext2_inode&) const;
|
||||
|
||||
void dumpBlockBitmap(unsigned groupIndex) const;
|
||||
void dumpInodeBitmap(unsigned groupIndex) const;
|
||||
void dump_block_bitmap(unsigned groupIndex) const;
|
||||
void dump_inode_bitmap(unsigned groupIndex) const;
|
||||
|
||||
template<typename F> void traverseInodeBitmap(unsigned groupIndex, F) const;
|
||||
template<typename F> void traverseBlockBitmap(unsigned groupIndex, F) const;
|
||||
template<typename F> void traverse_inode_bitmap(unsigned groupIndex, F) const;
|
||||
template<typename F> void traverse_block_bitmap(unsigned groupIndex, F) const;
|
||||
|
||||
bool addInodeToDirectory(unsigned directoryInode, unsigned inode, const String& name, byte fileType, int& error);
|
||||
bool writeDirectoryInode(unsigned directoryInode, Vector<DirectoryEntry>&&);
|
||||
bool setInodeAllocationState(unsigned inode, bool);
|
||||
bool setBlockAllocationState(GroupIndex, BlockIndex, bool);
|
||||
bool add_inode_to_directory(unsigned directoryInode, unsigned inode, const String& name, byte fileType, int& error);
|
||||
bool write_directory_inode(unsigned directoryInode, Vector<DirectoryEntry>&&);
|
||||
bool set_inode_allocation_state(unsigned inode, bool);
|
||||
bool set_block_allocation_state(GroupIndex, BlockIndex, bool);
|
||||
|
||||
bool modifyLinkCount(InodeIndex, int delta);
|
||||
bool modify_link_count(InodeIndex, int delta);
|
||||
|
||||
unsigned m_blockGroupCount { 0 };
|
||||
|
||||
bool deprecated_enumerateDirectoryInode(InodeIdentifier, Function<bool(const DirectoryEntry&)>) const;
|
||||
|
||||
mutable ByteBuffer m_cachedSuperBlock;
|
||||
mutable ByteBuffer m_cachedBlockGroupDescriptorTable;
|
||||
mutable ByteBuffer m_cached_super_block;
|
||||
mutable ByteBuffer m_cached_group_descriptor_table;
|
||||
|
||||
mutable SpinLock m_inode_cache_lock;
|
||||
mutable HashMap<BlockIndex, RetainPtr<Ext2FSInode>> m_inode_cache;
|
||||
|
|
|
@ -196,7 +196,7 @@ ByteBuffer FileDescriptor::readEntireFile()
|
|||
|
||||
if (m_vnode->core_inode())
|
||||
return m_vnode->core_inode()->read_entire(this);
|
||||
return m_vnode->fileSystem()->readEntireInode(m_vnode->inode, this);
|
||||
return m_vnode->fileSystem()->read_entire_inode(m_vnode->inode, this);
|
||||
}
|
||||
|
||||
bool FileDescriptor::isDirectory() const
|
||||
|
|
|
@ -19,17 +19,17 @@ void FS::initializeGlobals()
|
|||
}
|
||||
|
||||
FS::FS()
|
||||
: m_id(++s_lastFileSystemID)
|
||||
: m_fsid(++s_lastFileSystemID)
|
||||
{
|
||||
fileSystems().set(m_id, this);
|
||||
fileSystems().set(m_fsid, this);
|
||||
}
|
||||
|
||||
FS::~FS()
|
||||
{
|
||||
fileSystems().remove(m_id);
|
||||
fileSystems().remove(m_fsid);
|
||||
}
|
||||
|
||||
FS* FS::fromID(dword id)
|
||||
FS* FS::from_fsid(dword id)
|
||||
{
|
||||
auto it = fileSystems().find(id);
|
||||
if (it != fileSystems().end())
|
||||
|
@ -39,7 +39,7 @@ FS* FS::fromID(dword id)
|
|||
|
||||
ByteBuffer CoreInode::read_entire(FileDescriptor* descriptor)
|
||||
{
|
||||
return fs().readEntireInode(identifier(), descriptor);
|
||||
return fs().read_entire_inode(identifier(), descriptor);
|
||||
/*
|
||||
size_t initial_size = metadata().size ? metadata().size : 4096;
|
||||
auto contents = ByteBuffer::createUninitialized(initial_size);
|
||||
|
@ -69,11 +69,11 @@ ByteBuffer CoreInode::read_entire(FileDescriptor* descriptor)
|
|||
*/
|
||||
}
|
||||
|
||||
ByteBuffer FS::readEntireInode(InodeIdentifier inode, FileDescriptor* handle) const
|
||||
ByteBuffer FS::read_entire_inode(InodeIdentifier inode, FileDescriptor* handle) const
|
||||
{
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
||||
auto metadata = inodeMetadata(inode);
|
||||
auto metadata = inode_metadata(inode);
|
||||
if (!metadata.isValid()) {
|
||||
kprintf("[fs] readInode: metadata lookup for inode %u failed\n", inode.index());
|
||||
return nullptr;
|
||||
|
|
|
@ -24,14 +24,14 @@ public:
|
|||
static void initializeGlobals();
|
||||
virtual ~FS();
|
||||
|
||||
dword id() const { return m_id; }
|
||||
static FS* fromID(dword);
|
||||
dword id() const { return m_fsid; }
|
||||
static FS* from_fsid(dword);
|
||||
|
||||
virtual bool initialize() = 0;
|
||||
virtual const char* class_name() const = 0;
|
||||
virtual InodeIdentifier rootInode() const = 0;
|
||||
virtual bool writeInode(InodeIdentifier, const ByteBuffer&) = 0;
|
||||
virtual InodeMetadata inodeMetadata(InodeIdentifier) const = 0;
|
||||
virtual InodeIdentifier root_inode() const = 0;
|
||||
virtual bool write_inode(InodeIdentifier, const ByteBuffer&) = 0;
|
||||
virtual InodeMetadata inode_metadata(InodeIdentifier) const = 0;
|
||||
|
||||
virtual ssize_t read_inode_bytes(InodeIdentifier, Unix::off_t offset, size_t count, byte* buffer, FileDescriptor*) const = 0;
|
||||
|
||||
|
@ -52,13 +52,13 @@ public:
|
|||
|
||||
virtual RetainPtr<CoreInode> get_inode(InodeIdentifier) const = 0;
|
||||
|
||||
ByteBuffer readEntireInode(InodeIdentifier, FileDescriptor* = nullptr) const;
|
||||
ByteBuffer read_entire_inode(InodeIdentifier, FileDescriptor* = nullptr) const;
|
||||
|
||||
protected:
|
||||
FS();
|
||||
|
||||
private:
|
||||
dword m_id { 0 };
|
||||
dword m_fsid { 0 };
|
||||
};
|
||||
|
||||
class CoreInode : public Retainable<CoreInode> {
|
||||
|
@ -100,26 +100,26 @@ private:
|
|||
unsigned m_index { 0 };
|
||||
};
|
||||
|
||||
inline FS* InodeIdentifier::fileSystem()
|
||||
inline FS* InodeIdentifier::fs()
|
||||
{
|
||||
return FS::fromID(m_fileSystemID);
|
||||
return FS::from_fsid(m_fsid);
|
||||
}
|
||||
|
||||
inline const FS* InodeIdentifier::fileSystem() const
|
||||
inline const FS* InodeIdentifier::fs() const
|
||||
{
|
||||
return FS::fromID(m_fileSystemID);
|
||||
return FS::from_fsid(m_fsid);
|
||||
}
|
||||
|
||||
inline InodeMetadata InodeIdentifier::metadata() const
|
||||
{
|
||||
if (!isValid())
|
||||
if (!is_valid())
|
||||
return InodeMetadata();
|
||||
return fileSystem()->inodeMetadata(*this);
|
||||
return fs()->inode_metadata(*this);
|
||||
}
|
||||
|
||||
inline bool InodeIdentifier::isRootInode() const
|
||||
inline bool InodeIdentifier::is_root_inode() const
|
||||
{
|
||||
return (*this) == fileSystem()->rootInode();
|
||||
return (*this) == fs()->root_inode();
|
||||
}
|
||||
|
||||
inline unsigned CoreInode::fsid() const
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "InodeIdentifier.h"
|
||||
#include "FileSystem.h"
|
||||
|
||||
ByteBuffer InodeIdentifier::readEntireFile() const
|
||||
ByteBuffer InodeIdentifier::read_entire_file() const
|
||||
{
|
||||
if (!fileSystem())
|
||||
if (!fs())
|
||||
return { };
|
||||
return fileSystem()->readEntireInode(*this, nullptr);
|
||||
return fs()->read_entire_inode(*this, nullptr);
|
||||
}
|
||||
|
|
|
@ -10,36 +10,36 @@ class InodeIdentifier {
|
|||
public:
|
||||
InodeIdentifier() { }
|
||||
InodeIdentifier(dword fileSystemID, dword inode)
|
||||
: m_fileSystemID(fileSystemID)
|
||||
: m_fsid(fileSystemID)
|
||||
, m_index(inode)
|
||||
{
|
||||
}
|
||||
|
||||
bool isValid() const { return m_fileSystemID != 0 && m_index != 0; }
|
||||
bool is_valid() const { return m_fsid != 0 && m_index != 0; }
|
||||
|
||||
dword fsid() const { return m_fileSystemID; }
|
||||
dword fsid() const { return m_fsid; }
|
||||
dword index() const { return m_index; }
|
||||
|
||||
FS* fileSystem();
|
||||
const FS* fileSystem() const;
|
||||
FS* fs();
|
||||
const FS* fs() const;
|
||||
|
||||
bool operator==(const InodeIdentifier& other) const
|
||||
{
|
||||
return m_fileSystemID == other.m_fileSystemID && m_index == other.m_index;
|
||||
return m_fsid == other.m_fsid && m_index == other.m_index;
|
||||
}
|
||||
|
||||
bool operator!=(const InodeIdentifier& other) const
|
||||
{
|
||||
return m_fileSystemID != other.m_fileSystemID || m_index != other.m_index;
|
||||
return m_fsid != other.m_fsid || m_index != other.m_index;
|
||||
}
|
||||
|
||||
InodeMetadata metadata() const;
|
||||
bool isRootInode() const;
|
||||
bool is_root_inode() const;
|
||||
|
||||
ByteBuffer readEntireFile() const;
|
||||
ByteBuffer read_entire_file() const;
|
||||
|
||||
private:
|
||||
dword m_fileSystemID { 0 };
|
||||
dword m_fsid { 0 };
|
||||
dword m_index { 0 };
|
||||
};
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ inline bool isSetUID(Unix::mode_t mode) { return mode & 04000; }
|
|||
inline bool isSetGID(Unix::mode_t mode) { return mode & 02000; }
|
||||
|
||||
struct InodeMetadata {
|
||||
bool isValid() const { return inode.isValid(); }
|
||||
bool isValid() const { return inode.is_valid(); }
|
||||
|
||||
bool mayExecute(uid_t u, const HashTable<gid_t>& g) const
|
||||
{
|
||||
|
|
|
@ -127,12 +127,12 @@ const char* SynthFS::class_name() const
|
|||
return "synthfs";
|
||||
}
|
||||
|
||||
InodeIdentifier SynthFS::rootInode() const
|
||||
InodeIdentifier SynthFS::root_inode() const
|
||||
{
|
||||
return { id(), 1 };
|
||||
}
|
||||
|
||||
InodeMetadata SynthFS::inodeMetadata(InodeIdentifier inode) const
|
||||
InodeMetadata SynthFS::inode_metadata(InodeIdentifier inode) const
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
@ -164,7 +164,7 @@ InodeIdentifier SynthFS::create_inode(InodeIdentifier parentInode, const String&
|
|||
return { };
|
||||
}
|
||||
|
||||
bool SynthFS::writeInode(InodeIdentifier, const ByteBuffer&)
|
||||
bool SynthFS::write_inode(InodeIdentifier, const ByteBuffer&)
|
||||
{
|
||||
kprintf("FIXME: Implement SyntheticFileSystem::writeInode().\n");
|
||||
return false;
|
||||
|
|
|
@ -13,9 +13,9 @@ public:
|
|||
|
||||
virtual bool initialize() override;
|
||||
virtual const char* class_name() const override;
|
||||
virtual InodeIdentifier rootInode() const override;
|
||||
virtual bool writeInode(InodeIdentifier, const ByteBuffer&) override;
|
||||
virtual InodeMetadata inodeMetadata(InodeIdentifier) const override;
|
||||
virtual InodeIdentifier root_inode() const override;
|
||||
virtual bool write_inode(InodeIdentifier, const ByteBuffer&) override;
|
||||
virtual InodeMetadata inode_metadata(InodeIdentifier) const override;
|
||||
virtual bool set_mtime(InodeIdentifier, dword timestamp) override;
|
||||
virtual InodeIdentifier create_inode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size, int& error) override;
|
||||
virtual ssize_t read_inode_bytes(InodeIdentifier, Unix::off_t offset, size_t count, byte* buffer, FileDescriptor*) const override;
|
||||
|
|
|
@ -51,7 +51,7 @@ auto VFS::makeNode(InodeIdentifier inode) -> RetainPtr<Vnode>
|
|||
if (!metadata.isValid())
|
||||
return nullptr;
|
||||
|
||||
auto core_inode = inode.fileSystem()->get_inode(inode);
|
||||
auto core_inode = inode.fs()->get_inode(inode);
|
||||
if (core_inode)
|
||||
core_inode->m_metadata = metadata;
|
||||
|
||||
|
@ -71,7 +71,7 @@ auto VFS::makeNode(InodeIdentifier inode) -> RetainPtr<Vnode>
|
|||
auto vnode = allocateNode();
|
||||
ASSERT(vnode);
|
||||
|
||||
FS* fileSystem = inode.fileSystem();
|
||||
FS* fileSystem = inode.fs();
|
||||
fileSystem->retain();
|
||||
|
||||
vnode->inode = inode;
|
||||
|
@ -136,7 +136,7 @@ bool VFS::mount(RetainPtr<FS>&& fileSystem, const String& path)
|
|||
ASSERT(fileSystem);
|
||||
int error;
|
||||
auto inode = resolve_path(path, root_inode_id(), error);
|
||||
if (!inode.isValid()) {
|
||||
if (!inode.is_valid()) {
|
||||
kprintf("VFS: mount can't resolve mount point '%s'\n", path.characters());
|
||||
return false;
|
||||
}
|
||||
|
@ -196,9 +196,9 @@ void VFS::freeNode(Vnode* node)
|
|||
InterruptDisabler disabler;
|
||||
ASSERT(node);
|
||||
ASSERT(node->inUse());
|
||||
if (node->inode.isValid()) {
|
||||
if (node->inode.is_valid()) {
|
||||
m_inode2vnode.remove(node->inode);
|
||||
node->inode.fileSystem()->release();
|
||||
node->inode.fs()->release();
|
||||
node->inode = InodeIdentifier();
|
||||
}
|
||||
if (node->m_characterDevice) {
|
||||
|
@ -242,7 +242,7 @@ void VFS::traverse_directory_inode(CoreInode& dir_inode, Function<bool(const FS:
|
|||
else
|
||||
resolvedInode = entry.inode;
|
||||
|
||||
if (dir_inode.identifier().isRootInode() && !is_vfs_root(dir_inode.identifier()) && !strcmp(entry.name, "..")) {
|
||||
if (dir_inode.identifier().is_root_inode() && !is_vfs_root(dir_inode.identifier()) && !strcmp(entry.name, "..")) {
|
||||
auto mount = find_mount_for_guest(entry.inode);
|
||||
ASSERT(mount);
|
||||
resolvedInode = mount->host();
|
||||
|
@ -256,9 +256,9 @@ bool VFS::touch(const String& path)
|
|||
{
|
||||
int error;
|
||||
auto inode = resolve_path(path, root_inode_id(), error);
|
||||
if (!inode.isValid())
|
||||
if (!inode.is_valid())
|
||||
return false;
|
||||
return inode.fileSystem()->set_mtime(inode, ktime(nullptr));
|
||||
return inode.fs()->set_mtime(inode, ktime(nullptr));
|
||||
}
|
||||
|
||||
RetainPtr<FileDescriptor> VFS::open(CharacterDevice& device, int options)
|
||||
|
@ -274,7 +274,7 @@ RetainPtr<FileDescriptor> VFS::open(CharacterDevice& device, int options)
|
|||
RetainPtr<FileDescriptor> VFS::open(const String& path, int& error, int options, InodeIdentifier base)
|
||||
{
|
||||
auto inode = resolve_path(path, base, error, options);
|
||||
if (!inode.isValid())
|
||||
if (!inode.is_valid())
|
||||
return nullptr;
|
||||
auto vnode = get_or_create_node(inode);
|
||||
if (!vnode)
|
||||
|
@ -287,7 +287,7 @@ RetainPtr<FileDescriptor> VFS::create(const String& path, InodeIdentifier base,
|
|||
// FIXME: Do the real thing, not just this fake thing!
|
||||
(void) path;
|
||||
(void) base;
|
||||
m_root_vnode->fileSystem()->create_inode(m_root_vnode->fileSystem()->rootInode(), "empty", 0100644, 0, error);
|
||||
m_root_vnode->fileSystem()->create_inode(m_root_vnode->fileSystem()->root_inode(), "empty", 0100644, 0, error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -303,11 +303,11 @@ bool VFS::mkdir(const String& path, mode_t mode, InodeIdentifier base, int& erro
|
|||
|
||||
InodeIdentifier parent_dir;
|
||||
auto existing_dir = resolve_path(path, base, error, 0, &parent_dir);
|
||||
if (existing_dir.isValid()) {
|
||||
if (existing_dir.is_valid()) {
|
||||
error = -EEXIST;
|
||||
return false;
|
||||
}
|
||||
if (!parent_dir.isValid()) {
|
||||
if (!parent_dir.is_valid()) {
|
||||
error = -ENOENT;
|
||||
return false;
|
||||
}
|
||||
|
@ -315,8 +315,8 @@ bool VFS::mkdir(const String& path, mode_t mode, InodeIdentifier base, int& erro
|
|||
return false;
|
||||
}
|
||||
dbgprintf("VFS::mkdir: '%s' in %u:%u\n", p.basename().characters(), parent_dir.fsid(), parent_dir.index());
|
||||
auto new_dir = base.fileSystem()->create_directory(parent_dir, p.basename(), mode, error);
|
||||
if (new_dir.isValid()) {
|
||||
auto new_dir = base.fs()->create_directory(parent_dir, p.basename(), mode, error);
|
||||
if (new_dir.is_valid()) {
|
||||
error = 0;
|
||||
return true;
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ bool VFS::mkdir(const String& path, mode_t mode, InodeIdentifier base, int& erro
|
|||
|
||||
InodeIdentifier VFS::resolveSymbolicLink(InodeIdentifier base, InodeIdentifier symlinkInode, int& error)
|
||||
{
|
||||
auto symlinkContents = symlinkInode.readEntireFile();
|
||||
auto symlinkContents = symlinkInode.read_entire_file();
|
||||
if (!symlinkContents)
|
||||
return { };
|
||||
auto linkee = String((const char*)symlinkContents.pointer(), symlinkContents.size());
|
||||
|
@ -337,9 +337,9 @@ InodeIdentifier VFS::resolveSymbolicLink(InodeIdentifier base, InodeIdentifier s
|
|||
|
||||
RetainPtr<CoreInode> VFS::get_inode(InodeIdentifier inode_id)
|
||||
{
|
||||
if (!inode_id.isValid())
|
||||
if (!inode_id.is_valid())
|
||||
return nullptr;
|
||||
return inode_id.fileSystem()->get_inode(inode_id);
|
||||
return inode_id.fs()->get_inode(inode_id);
|
||||
}
|
||||
|
||||
String VFS::absolute_path(CoreInode& core_inode)
|
||||
|
@ -359,7 +359,7 @@ String VFS::absolute_path(CoreInode& core_inode)
|
|||
} else {
|
||||
parent_id = inode->fs().find_parent_of_inode(inode->identifier());
|
||||
}
|
||||
ASSERT(parent_id.isValid());
|
||||
ASSERT(parent_id.is_valid());
|
||||
inode = get_inode(parent_id);
|
||||
}
|
||||
if (lineage.isEmpty())
|
||||
|
@ -391,13 +391,13 @@ InodeIdentifier VFS::resolve_path(const String& path, InodeIdentifier base, int&
|
|||
if (path[0] == '/')
|
||||
crumb_id = m_root_vnode->inode;
|
||||
else
|
||||
crumb_id = base.isValid() ? base : m_root_vnode->inode;
|
||||
crumb_id = base.is_valid() ? base : m_root_vnode->inode;
|
||||
|
||||
if (deepest_dir)
|
||||
*deepest_dir = crumb_id;
|
||||
|
||||
for (unsigned i = 0; i < parts.size(); ++i) {
|
||||
bool inode_was_root_at_head_of_loop = crumb_id.isRootInode();
|
||||
bool inode_was_root_at_head_of_loop = crumb_id.is_root_inode();
|
||||
auto& part = parts[i];
|
||||
if (part.isEmpty())
|
||||
break;
|
||||
|
@ -419,7 +419,7 @@ InodeIdentifier VFS::resolve_path(const String& path, InodeIdentifier base, int&
|
|||
auto parent = crumb_id;
|
||||
auto dir_inode = get_inode(crumb_id);
|
||||
crumb_id = dir_inode->lookup(part);
|
||||
if (!crumb_id.isValid()) {
|
||||
if (!crumb_id.is_valid()) {
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf("child <%s>(%u) not found in directory, %02u:%08u\n", part.characters(), part.length(), parent.fsid(), parent.index());
|
||||
#endif
|
||||
|
@ -435,7 +435,7 @@ InodeIdentifier VFS::resolve_path(const String& path, InodeIdentifier base, int&
|
|||
#endif
|
||||
crumb_id = mount->guest();
|
||||
}
|
||||
if (inode_was_root_at_head_of_loop && crumb_id.isRootInode() && !is_vfs_root(crumb_id) && part == "..") {
|
||||
if (inode_was_root_at_head_of_loop && crumb_id.is_root_inode() && !is_vfs_root(crumb_id) && part == "..") {
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf(" -- is guest\n");
|
||||
#endif
|
||||
|
@ -458,7 +458,7 @@ InodeIdentifier VFS::resolve_path(const String& path, InodeIdentifier base, int&
|
|||
return crumb_id;
|
||||
}
|
||||
crumb_id = resolveSymbolicLink(parent, crumb_id, error);
|
||||
if (!crumb_id.isValid()) {
|
||||
if (!crumb_id.is_valid()) {
|
||||
kprintf("Symbolic link resolution failed :(\n");
|
||||
return { };
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ const InodeMetadata& Vnode::metadata() const
|
|||
|
||||
VFS::Mount::Mount(InodeIdentifier host, RetainPtr<FS>&& guest_fs)
|
||||
: m_host(host)
|
||||
, m_guest(guest_fs->rootInode())
|
||||
, m_guest(guest_fs->root_inode())
|
||||
, m_guest_fs(move(guest_fs))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
InodeIdentifier inode;
|
||||
const InodeMetadata& metadata() const;
|
||||
|
||||
bool inUse() const { return inode.isValid() || m_characterDevice; }
|
||||
bool inUse() const { return inode.is_valid() || m_characterDevice; }
|
||||
|
||||
bool isCharacterDevice() const { return m_characterDevice; }
|
||||
CharacterDevice* characterDevice() { return m_characterDevice; }
|
||||
|
@ -49,8 +49,8 @@ public:
|
|||
void retain();
|
||||
void release();
|
||||
|
||||
FS* fileSystem() { return inode.fileSystem(); }
|
||||
const FS* fileSystem() const { return inode.fileSystem(); }
|
||||
FS* fileSystem() { return inode.fs(); }
|
||||
const FS* fileSystem() const { return inode.fs(); }
|
||||
|
||||
VFS* vfs() { return m_vfs; }
|
||||
const VFS* vfs() const { return m_vfs; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue