mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:57:45 +00:00
Big, possibly complete sweep of naming changes.
This commit is contained in:
parent
27fa09aee4
commit
ffab6897aa
93 changed files with 830 additions and 885 deletions
|
@ -26,7 +26,7 @@ public:
|
|||
virtual ssize_t write(Process&, const byte* data, size_t size) override;
|
||||
virtual const char* class_name() const override { return "Console"; }
|
||||
|
||||
void setImplementation(ConsoleImplementation* implementation) { m_implementation = implementation; }
|
||||
void set_implementation(ConsoleImplementation* implementation) { m_implementation = implementation; }
|
||||
|
||||
void put_char(char);
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ RetainPtr<SynthFSInode> DevPtsFS::create_slave_pty_device_file(unsigned index)
|
|||
|
||||
StringBuilder builder;
|
||||
builder.appendf("%u", index);
|
||||
file->m_name = builder.build();
|
||||
file->m_name = builder.to_string();
|
||||
|
||||
auto* device = VFS::the().get_device(11, index);
|
||||
ASSERT(device);
|
||||
|
@ -51,8 +51,8 @@ RetainPtr<SynthFSInode> DevPtsFS::create_slave_pty_device_file(unsigned index)
|
|||
file->m_metadata.uid = device->uid();
|
||||
file->m_metadata.gid = device->gid();
|
||||
file->m_metadata.mode = 0020644;
|
||||
file->m_metadata.majorDevice = device->major();
|
||||
file->m_metadata.minorDevice = device->minor();
|
||||
file->m_metadata.major_device = device->major();
|
||||
file->m_metadata.minor_device = device->minor();
|
||||
file->m_metadata.mtime = mepoch;
|
||||
return file;
|
||||
}
|
||||
|
|
|
@ -13,63 +13,63 @@ DiskBackedFS::~DiskBackedFS()
|
|||
{
|
||||
}
|
||||
|
||||
bool DiskBackedFS::writeBlock(unsigned index, const ByteBuffer& data)
|
||||
bool DiskBackedFS::write_block(unsigned index, const ByteBuffer& data)
|
||||
{
|
||||
#ifdef DBFS_DEBUG
|
||||
kprintf("DiskBackedFileSystem::writeBlock %u, size=%u\n", index, data.size());
|
||||
kprintf("DiskBackedFileSystem::write_block %u, size=%u\n", index, data.size());
|
||||
#endif
|
||||
ASSERT(data.size() == blockSize());
|
||||
DiskOffset baseOffset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(blockSize());
|
||||
return device().write(baseOffset, blockSize(), data.pointer());
|
||||
ASSERT(data.size() == block_size());
|
||||
DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
|
||||
return device().write(base_offset, block_size(), data.pointer());
|
||||
}
|
||||
|
||||
bool DiskBackedFS::writeBlocks(unsigned index, unsigned count, const ByteBuffer& data)
|
||||
bool DiskBackedFS::write_blocks(unsigned index, unsigned count, const ByteBuffer& data)
|
||||
{
|
||||
#ifdef DBFS_DEBUG
|
||||
kprintf("DiskBackedFileSystem::writeBlocks %u x%u\n", index, count);
|
||||
kprintf("DiskBackedFileSystem::write_blocks %u x%u\n", index, count);
|
||||
#endif
|
||||
DiskOffset baseOffset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(blockSize());
|
||||
return device().write(baseOffset, count * blockSize(), data.pointer());
|
||||
DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
|
||||
return device().write(base_offset, count * block_size(), data.pointer());
|
||||
}
|
||||
|
||||
ByteBuffer DiskBackedFS::readBlock(unsigned index) const
|
||||
ByteBuffer DiskBackedFS::read_block(unsigned index) const
|
||||
{
|
||||
#ifdef DBFS_DEBUG
|
||||
kprintf("DiskBackedFileSystem::readBlock %u\n", index);
|
||||
kprintf("DiskBackedFileSystem::read_block %u\n", index);
|
||||
#endif
|
||||
auto buffer = ByteBuffer::create_uninitialized(blockSize());
|
||||
//kprintf("created block buffer with size %u\n", blockSize());
|
||||
DiskOffset baseOffset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(blockSize());
|
||||
auto* bufferPointer = buffer.pointer();
|
||||
bool success = device().read(baseOffset, blockSize(), bufferPointer);
|
||||
auto buffer = ByteBuffer::create_uninitialized(block_size());
|
||||
//kprintf("created block buffer with size %u\n", block_size());
|
||||
DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
|
||||
auto* buffer_pointer = buffer.pointer();
|
||||
bool success = device().read(base_offset, block_size(), buffer_pointer);
|
||||
ASSERT(success);
|
||||
ASSERT(buffer.size() == blockSize());
|
||||
ASSERT(buffer.size() == block_size());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
ByteBuffer DiskBackedFS::readBlocks(unsigned index, unsigned count) const
|
||||
ByteBuffer DiskBackedFS::read_blocks(unsigned index, unsigned count) const
|
||||
{
|
||||
if (!count)
|
||||
return nullptr;
|
||||
if (count == 1)
|
||||
return readBlock(index);
|
||||
auto blocks = ByteBuffer::create_uninitialized(count * blockSize());
|
||||
return read_block(index);
|
||||
auto blocks = ByteBuffer::create_uninitialized(count * block_size());
|
||||
byte* out = blocks.pointer();
|
||||
|
||||
for (unsigned i = 0; i < count; ++i) {
|
||||
auto block = readBlock(index + i);
|
||||
auto block = read_block(index + i);
|
||||
if (!block)
|
||||
return nullptr;
|
||||
memcpy(out, block.pointer(), block.size());
|
||||
out += blockSize();
|
||||
out += block_size();
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
void DiskBackedFS::setBlockSize(unsigned blockSize)
|
||||
void DiskBackedFS::set_block_size(unsigned block_size)
|
||||
{
|
||||
if (blockSize == m_blockSize)
|
||||
if (block_size == m_block_size)
|
||||
return;
|
||||
m_blockSize = blockSize;
|
||||
m_block_size = block_size;
|
||||
}
|
||||
|
|
|
@ -10,20 +10,20 @@ public:
|
|||
DiskDevice& device() { return *m_device; }
|
||||
const DiskDevice& device() const { return *m_device; }
|
||||
|
||||
size_t blockSize() const { return m_blockSize; }
|
||||
size_t block_size() const { return m_block_size; }
|
||||
|
||||
protected:
|
||||
explicit DiskBackedFS(RetainPtr<DiskDevice>&&);
|
||||
|
||||
void setBlockSize(unsigned);
|
||||
void set_block_size(unsigned);
|
||||
|
||||
ByteBuffer readBlock(unsigned index) const;
|
||||
ByteBuffer readBlocks(unsigned index, unsigned count) const;
|
||||
ByteBuffer read_block(unsigned index) const;
|
||||
ByteBuffer read_blocks(unsigned index, unsigned count) const;
|
||||
|
||||
bool writeBlock(unsigned index, const ByteBuffer&);
|
||||
bool writeBlocks(unsigned index, unsigned count, const ByteBuffer&);
|
||||
bool write_block(unsigned index, const ByteBuffer&);
|
||||
bool write_blocks(unsigned index, unsigned count, const ByteBuffer&);
|
||||
|
||||
private:
|
||||
size_t m_blockSize { 0 };
|
||||
size_t m_block_size { 0 };
|
||||
RetainPtr<DiskDevice> m_device;
|
||||
};
|
||||
|
|
|
@ -13,10 +13,10 @@ bool DiskDevice::read(DiskOffset offset, unsigned length, byte* out) const
|
|||
//kprintf("DD::read %u x%u\n", offset, length);
|
||||
ASSERT((offset % block_size()) == 0);
|
||||
ASSERT((length % block_size()) == 0);
|
||||
dword firstBlock = offset / block_size();
|
||||
dword endBlock = (offset + length) / block_size();
|
||||
dword first_block = offset / block_size();
|
||||
dword end_block = (offset + length) / block_size();
|
||||
byte* outptr = out;
|
||||
for (unsigned bi = firstBlock; bi < endBlock; ++bi) {
|
||||
for (unsigned bi = first_block; bi < end_block; ++bi) {
|
||||
if (!read_block(bi, outptr))
|
||||
return false;
|
||||
outptr += block_size();
|
||||
|
@ -28,12 +28,12 @@ bool DiskDevice::write(DiskOffset offset, unsigned length, const byte* in)
|
|||
{
|
||||
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);
|
||||
dword first_block = offset / block_size();
|
||||
dword end_block = (offset + length) / block_size();
|
||||
ASSERT(first_block <= 0xffffffff);
|
||||
ASSERT(end_block <= 0xffffffff);
|
||||
const byte* inptr = in;
|
||||
for (unsigned bi = firstBlock; bi < endBlock; ++bi) {
|
||||
for (unsigned bi = first_block; bi < end_block; ++bi) {
|
||||
if (!write_block(bi, inptr))
|
||||
return false;
|
||||
inptr += block_size();
|
||||
|
|
|
@ -11,7 +11,7 @@ ELFImage::~ELFImage()
|
|||
{
|
||||
}
|
||||
|
||||
static const char* objectFileTypeToString(Elf32_Half type)
|
||||
static const char* object_file_type_to_string(Elf32_Half type)
|
||||
{
|
||||
switch (type) {
|
||||
case ET_NONE: return "None";
|
||||
|
@ -40,14 +40,14 @@ unsigned ELFImage::symbol_count() const
|
|||
void ELFImage::dump()
|
||||
{
|
||||
kprintf("ELFImage{%p} {\n", this);
|
||||
kprintf(" isValid: %u\n", is_valid());
|
||||
kprintf(" is_valid: %u\n", is_valid());
|
||||
|
||||
if (!is_valid()) {
|
||||
kprintf("}\n");
|
||||
return;
|
||||
}
|
||||
|
||||
kprintf(" type: %s\n", objectFileTypeToString(header().e_type));
|
||||
kprintf(" type: %s\n", object_file_type_to_string(header().e_type));
|
||||
kprintf(" machine: %u\n", header().e_machine);
|
||||
kprintf(" entry: %x\n", header().e_entry);
|
||||
kprintf(" shoff: %u\n", header().e_shoff);
|
||||
|
@ -158,8 +158,8 @@ const Elf32_Shdr& ELFImage::section_header(unsigned index) const
|
|||
const ELFImage::Symbol ELFImage::symbol(unsigned index) const
|
||||
{
|
||||
ASSERT(index < symbol_count());
|
||||
auto* rawSyms = reinterpret_cast<const Elf32_Sym*>(raw_data(section(m_symbol_table_section_index).offset()));
|
||||
return Symbol(*this, index, rawSyms[index]);
|
||||
auto* raw_syms = reinterpret_cast<const Elf32_Sym*>(raw_data(section(m_symbol_table_section_index).offset()));
|
||||
return Symbol(*this, index, raw_syms[index]);
|
||||
}
|
||||
|
||||
const ELFImage::Section ELFImage::section(unsigned index) const
|
||||
|
@ -185,23 +185,23 @@ const ELFImage::Relocation ELFImage::RelocationSection::relocation(unsigned inde
|
|||
const ELFImage::RelocationSection ELFImage::Section::relocations() const
|
||||
{
|
||||
// FIXME: This is ugly.
|
||||
char relocationSectionName[128];
|
||||
ksprintf(relocationSectionName, ".rel%s", name());
|
||||
char relocation_sectionName[128];
|
||||
ksprintf(relocation_sectionName, ".rel%s", name());
|
||||
|
||||
#ifdef ELFIMAGE_DEBUG
|
||||
kprintf("looking for '%s'\n", relocationSectionName);
|
||||
kprintf("looking for '%s'\n", relocation_sectionName);
|
||||
#endif
|
||||
auto relocationSection = m_image.lookupSection(relocationSectionName);
|
||||
if (relocationSection.type() != SHT_REL)
|
||||
auto relocation_section = m_image.lookup_section(relocation_sectionName);
|
||||
if (relocation_section.type() != SHT_REL)
|
||||
return static_cast<const RelocationSection>(m_image.section(0));
|
||||
|
||||
#ifdef ELFIMAGE_DEBUG
|
||||
kprintf("Found relocations for %s in %s\n", name(), relocationSection.name());
|
||||
kprintf("Found relocations for %s in %s\n", name(), relocation_section.name());
|
||||
#endif
|
||||
return static_cast<const RelocationSection>(relocationSection);
|
||||
return static_cast<const RelocationSection>(relocation_section);
|
||||
}
|
||||
|
||||
const ELFImage::Section ELFImage::lookupSection(const char* name) const
|
||||
const ELFImage::Section ELFImage::lookup_section(const char* name) const
|
||||
{
|
||||
if (auto it = m_sections.find(name); it != m_sections.end())
|
||||
return section((*it).value);
|
||||
|
|
|
@ -150,7 +150,7 @@ public:
|
|||
|
||||
// NOTE: Returns section(0) if section with name is not found.
|
||||
// FIXME: I don't love this API.
|
||||
const Section lookupSection(const char* name) const;
|
||||
const Section lookup_section(const char* name) const;
|
||||
|
||||
bool is_executable() const { return header().e_type == ET_EXEC; }
|
||||
bool is_relocatable() const { return header().e_type == ET_REL; }
|
||||
|
@ -158,7 +158,7 @@ public:
|
|||
LinearAddress entry() const { return LinearAddress(header().e_entry); }
|
||||
|
||||
private:
|
||||
bool parseHeader();
|
||||
bool parse_header();
|
||||
const char* raw_data(unsigned offset) const;
|
||||
const Elf32_Ehdr& header() const;
|
||||
const Elf32_Shdr& section_header(unsigned) const;
|
||||
|
|
|
@ -142,7 +142,7 @@ bool ELFLoader::perform_relocations()
|
|||
failed = true;
|
||||
return false;
|
||||
}
|
||||
ptrdiff_t relativeOffset = (char*)target_ptr - ((char*)&patch_ptr + 4);
|
||||
ptrdiff_t relative_offset = (char*)target_ptr - ((char*)&patch_ptr + 4);
|
||||
#ifdef ELFLOADER_DEBUG
|
||||
kprintf("ELFLoader: Relocate PC32: offset=%x, symbol=%u(%s) value=%x target=%p, offset=%d\n",
|
||||
relocation.offset(),
|
||||
|
@ -150,10 +150,10 @@ bool ELFLoader::perform_relocations()
|
|||
symbol.name(),
|
||||
symbol.value(),
|
||||
target_ptr,
|
||||
relativeOffset
|
||||
relative_offset
|
||||
);
|
||||
#endif
|
||||
patch_ptr = relativeOffset;
|
||||
patch_ptr = relative_offset;
|
||||
break;
|
||||
}
|
||||
case R_386_32: {
|
||||
|
|
|
@ -62,45 +62,45 @@ const ext2_super_block& Ext2FS::super_block() const
|
|||
const ext2_group_desc& Ext2FS::group_descriptor(unsigned groupIndex) const
|
||||
{
|
||||
// FIXME: Should this fail gracefully somehow?
|
||||
ASSERT(groupIndex <= m_blockGroupCount);
|
||||
ASSERT(groupIndex <= m_block_group_count);
|
||||
|
||||
if (!m_cached_group_descriptor_table) {
|
||||
unsigned blocksToRead = ceilDiv(m_blockGroupCount * (unsigned)sizeof(ext2_group_desc), blockSize());
|
||||
unsigned firstBlockOfBGDT = blockSize() == 1024 ? 2 : 1;
|
||||
unsigned blocks_to_read = ceil_div(m_block_group_count * (unsigned)sizeof(ext2_group_desc), block_size());
|
||||
unsigned first_block_of_bgdt = block_size() == 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);
|
||||
kprintf("ext2fs: block group count: %u, blocks-to-read: %u\n", m_block_group_count, blocks_to_read);
|
||||
kprintf("ext2fs: first block of BGDT: %u\n", first_block_of_bgdt);
|
||||
#endif
|
||||
m_cached_group_descriptor_table = readBlocks(firstBlockOfBGDT, blocksToRead);
|
||||
m_cached_group_descriptor_table = read_blocks(first_block_of_bgdt, blocks_to_read);
|
||||
}
|
||||
return reinterpret_cast<ext2_group_desc*>(m_cached_group_descriptor_table.pointer())[groupIndex - 1];
|
||||
}
|
||||
|
||||
bool Ext2FS::initialize()
|
||||
{
|
||||
auto& superBlock = this->super_block();
|
||||
auto& super_block = this->super_block();
|
||||
#ifdef EXT2_DEBUG
|
||||
kprintf("ext2fs: super block magic: %x (super block size: %u)\n", superBlock.s_magic, sizeof(ext2_super_block));
|
||||
kprintf("ext2fs: super block magic: %x (super block size: %u)\n", super_block.s_magic, sizeof(ext2_super_block));
|
||||
#endif
|
||||
if (superBlock.s_magic != EXT2_SUPER_MAGIC)
|
||||
if (super_block.s_magic != EXT2_SUPER_MAGIC)
|
||||
return false;
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
kprintf("ext2fs: %u inodes, %u blocks\n", superBlock.s_inodes_count, superBlock.s_blocks_count);
|
||||
kprintf("ext2fs: block size = %u\n", EXT2_BLOCK_SIZE(&superBlock));
|
||||
kprintf("ext2fs: first data block = %u\n", superBlock.s_first_data_block);
|
||||
kprintf("ext2fs: %u inodes, %u blocks\n", super_block.s_inodes_count, super_block.s_blocks_count);
|
||||
kprintf("ext2fs: block size = %u\n", EXT2_BLOCK_SIZE(&super_block));
|
||||
kprintf("ext2fs: first data block = %u\n", super_block.s_first_data_block);
|
||||
kprintf("ext2fs: inodes per block = %u\n", inodes_per_block());
|
||||
kprintf("ext2fs: inodes per group = %u\n", inodes_per_group());
|
||||
kprintf("ext2fs: free inodes = %u\n", superBlock.s_free_inodes_count);
|
||||
kprintf("ext2fs: desc per block = %u\n", EXT2_DESC_PER_BLOCK(&superBlock));
|
||||
kprintf("ext2fs: desc size = %u\n", EXT2_DESC_SIZE(&superBlock));
|
||||
kprintf("ext2fs: free inodes = %u\n", super_block.s_free_inodes_count);
|
||||
kprintf("ext2fs: desc per block = %u\n", EXT2_DESC_PER_BLOCK(&super_block));
|
||||
kprintf("ext2fs: desc size = %u\n", EXT2_DESC_SIZE(&super_block));
|
||||
#endif
|
||||
|
||||
setBlockSize(EXT2_BLOCK_SIZE(&superBlock));
|
||||
set_block_size(EXT2_BLOCK_SIZE(&super_block));
|
||||
|
||||
m_blockGroupCount = ceilDiv(superBlock.s_blocks_count, superBlock.s_blocks_per_group);
|
||||
m_block_group_count = ceil_div(super_block.s_blocks_count, super_block.s_blocks_per_group);
|
||||
|
||||
if (m_blockGroupCount == 0) {
|
||||
if (m_block_group_count == 0) {
|
||||
kprintf("ext2fs: no block groups :(\n");
|
||||
return false;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ bool Ext2FS::initialize()
|
|||
group_descriptor(0);
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
for (unsigned i = 1; i <= m_blockGroupCount; ++i) {
|
||||
for (unsigned i = 1; i <= m_block_group_count; ++i) {
|
||||
auto& group = group_descriptor(i);
|
||||
kprintf("ext2fs: group[%u] { block_bitmap: %u, inode_bitmap: %u, inode_table: %u }\n",
|
||||
i,
|
||||
|
@ -132,23 +132,23 @@ InodeIdentifier Ext2FS::root_inode() const
|
|||
return { fsid(), EXT2_ROOT_INO };
|
||||
}
|
||||
|
||||
ByteBuffer Ext2FS::read_block_containing_inode(unsigned inode, unsigned& blockIndex, unsigned& offset) const
|
||||
ByteBuffer Ext2FS::read_block_containing_inode(unsigned inode, unsigned& block_index, unsigned& offset) const
|
||||
{
|
||||
auto& superBlock = this->super_block();
|
||||
auto& super_block = this->super_block();
|
||||
|
||||
if (inode != EXT2_ROOT_INO && inode < EXT2_FIRST_INO(&superBlock))
|
||||
if (inode != EXT2_ROOT_INO && inode < EXT2_FIRST_INO(&super_block))
|
||||
return { };
|
||||
|
||||
if (inode > superBlock.s_inodes_count)
|
||||
if (inode > super_block.s_inodes_count)
|
||||
return { };
|
||||
|
||||
auto& bgd = group_descriptor(group_index_from_inode(inode));
|
||||
|
||||
offset = ((inode - 1) % inodes_per_group()) * inode_size();
|
||||
blockIndex = bgd.bg_inode_table + (offset >> EXT2_BLOCK_SIZE_BITS(&superBlock));
|
||||
offset &= blockSize() - 1;
|
||||
block_index = bgd.bg_inode_table + (offset >> EXT2_BLOCK_SIZE_BITS(&super_block));
|
||||
offset &= block_size() - 1;
|
||||
|
||||
return readBlock(blockIndex);
|
||||
return read_block(block_index);
|
||||
}
|
||||
|
||||
Ext2FS::BlockListShape Ext2FS::compute_block_list_shape(unsigned blocks)
|
||||
|
@ -192,7 +192,7 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in
|
|||
set_block_allocation_state(group_index_from_inode(inode_index), bi, true);
|
||||
}
|
||||
|
||||
e2inode.i_blocks = (blocks.size() + new_shape.meta_blocks) * (blockSize() / 512);
|
||||
e2inode.i_blocks = (blocks.size() + new_shape.meta_blocks) * (block_size() / 512);
|
||||
|
||||
unsigned output_block_index = 0;
|
||||
unsigned remaining_blocks = blocks.size();
|
||||
|
@ -212,7 +212,7 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in
|
|||
|
||||
{
|
||||
dbgprintf("Ext2FS: Writing out indirect blockptr block for inode %u\n", inode_index);
|
||||
auto block_contents = ByteBuffer::create_uninitialized(blockSize());
|
||||
auto block_contents = ByteBuffer::create_uninitialized(block_size());
|
||||
BufferStream stream(block_contents);
|
||||
ASSERT(new_shape.indirect_blocks <= EXT2_ADDR_PER_BLOCK(&super_block()));
|
||||
for (unsigned i = 0; i < new_shape.indirect_blocks; ++i) {
|
||||
|
@ -220,7 +220,7 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in
|
|||
--remaining_blocks;
|
||||
}
|
||||
stream.fill_to_end(0);
|
||||
writeBlock(e2inode.i_block[EXT2_IND_BLOCK], block_contents);
|
||||
write_block(e2inode.i_block[EXT2_IND_BLOCK], block_contents);
|
||||
}
|
||||
|
||||
if (!remaining_blocks)
|
||||
|
@ -232,11 +232,11 @@ bool Ext2FS::write_block_list_for_inode(InodeIndex inode_index, ext2_inode& e2in
|
|||
|
||||
Vector<unsigned> Ext2FS::block_list_for_inode(const ext2_inode& e2inode, bool include_block_list_blocks) const
|
||||
{
|
||||
unsigned entriesPerBlock = EXT2_ADDR_PER_BLOCK(&super_block());
|
||||
unsigned entries_per_block = 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);
|
||||
unsigned blocksRemaining = blockCount;
|
||||
unsigned block_count = e2inode.i_blocks / (block_size() / 512);
|
||||
unsigned blocksRemaining = block_count;
|
||||
Vector<unsigned> list;
|
||||
if (include_block_list_blocks) {
|
||||
// This seems like an excessive over-estimate but w/e.
|
||||
|
@ -245,8 +245,8 @@ Vector<unsigned> Ext2FS::block_list_for_inode(const ext2_inode& e2inode, bool in
|
|||
list.ensure_capacity(blocksRemaining);
|
||||
}
|
||||
|
||||
unsigned directCount = min(blockCount, (unsigned)EXT2_NDIR_BLOCKS);
|
||||
for (unsigned i = 0; i < directCount; ++i) {
|
||||
unsigned direct_count = min(block_count, (unsigned)EXT2_NDIR_BLOCKS);
|
||||
for (unsigned i = 0; i < direct_count; ++i) {
|
||||
list.unchecked_append(e2inode.i_block[i]);
|
||||
--blocksRemaining;
|
||||
}
|
||||
|
@ -254,13 +254,13 @@ Vector<unsigned> Ext2FS::block_list_for_inode(const ext2_inode& e2inode, bool in
|
|||
if (!blocksRemaining)
|
||||
return list;
|
||||
|
||||
auto processBlockArray = [&] (unsigned arrayBlockIndex, auto&& callback) {
|
||||
auto process_block_array = [&] (unsigned array_block_index, auto&& callback) {
|
||||
if (include_block_list_blocks)
|
||||
callback(arrayBlockIndex);
|
||||
auto arrayBlock = readBlock(arrayBlockIndex);
|
||||
ASSERT(arrayBlock);
|
||||
auto* array = reinterpret_cast<const __u32*>(arrayBlock.pointer());
|
||||
unsigned count = min(blocksRemaining, entriesPerBlock);
|
||||
callback(array_block_index);
|
||||
auto array_block = read_block(array_block_index);
|
||||
ASSERT(array_block);
|
||||
auto* array = reinterpret_cast<const __u32*>(array_block.pointer());
|
||||
unsigned count = min(blocksRemaining, entries_per_block);
|
||||
for (unsigned i = 0; i < count; ++i) {
|
||||
if (!array[i]) {
|
||||
blocksRemaining = 0;
|
||||
|
@ -271,15 +271,15 @@ Vector<unsigned> Ext2FS::block_list_for_inode(const ext2_inode& e2inode, bool in
|
|||
}
|
||||
};
|
||||
|
||||
processBlockArray(e2inode.i_block[EXT2_IND_BLOCK], [&] (unsigned entry) {
|
||||
process_block_array(e2inode.i_block[EXT2_IND_BLOCK], [&] (unsigned entry) {
|
||||
list.unchecked_append(entry);
|
||||
});
|
||||
|
||||
if (!blocksRemaining)
|
||||
return list;
|
||||
|
||||
processBlockArray(e2inode.i_block[EXT2_DIND_BLOCK], [&] (unsigned entry) {
|
||||
processBlockArray(entry, [&] (unsigned entry) {
|
||||
process_block_array(e2inode.i_block[EXT2_DIND_BLOCK], [&] (unsigned entry) {
|
||||
process_block_array(entry, [&] (unsigned entry) {
|
||||
list.unchecked_append(entry);
|
||||
});
|
||||
});
|
||||
|
@ -287,9 +287,9 @@ Vector<unsigned> Ext2FS::block_list_for_inode(const ext2_inode& e2inode, bool in
|
|||
if (!blocksRemaining)
|
||||
return list;
|
||||
|
||||
processBlockArray(e2inode.i_block[EXT2_TIND_BLOCK], [&] (unsigned entry) {
|
||||
processBlockArray(entry, [&] (unsigned entry) {
|
||||
processBlockArray(entry, [&] (unsigned entry) {
|
||||
process_block_array(e2inode.i_block[EXT2_TIND_BLOCK], [&] (unsigned entry) {
|
||||
process_block_array(entry, [&] (unsigned entry) {
|
||||
process_block_array(entry, [&] (unsigned entry) {
|
||||
list.unchecked_append(entry);
|
||||
});
|
||||
});
|
||||
|
@ -324,9 +324,9 @@ void Ext2FS::free_inode(Ext2FSInode& inode)
|
|||
|
||||
void Ext2FS::flush_block_group_descriptor_table()
|
||||
{
|
||||
unsigned blocks_to_write = ceilDiv(m_blockGroupCount * (unsigned)sizeof(ext2_group_desc), blockSize());
|
||||
unsigned first_block_of_bgdt = blockSize() == 1024 ? 2 : 1;
|
||||
writeBlocks(first_block_of_bgdt, blocks_to_write, m_cached_group_descriptor_table);
|
||||
unsigned blocks_to_write = ceil_div(m_block_group_count * (unsigned)sizeof(ext2_group_desc), block_size());
|
||||
unsigned first_block_of_bgdt = block_size() == 1024 ? 2 : 1;
|
||||
write_blocks(first_block_of_bgdt, blocks_to_write, m_cached_group_descriptor_table);
|
||||
}
|
||||
|
||||
Ext2FSInode::Ext2FSInode(Ext2FS& fs, unsigned index, const ext2_inode& raw_inode)
|
||||
|
@ -349,18 +349,18 @@ InodeMetadata Ext2FSInode::metadata() const
|
|||
metadata.mode = m_raw_inode.i_mode;
|
||||
metadata.uid = m_raw_inode.i_uid;
|
||||
metadata.gid = m_raw_inode.i_gid;
|
||||
metadata.linkCount = m_raw_inode.i_links_count;
|
||||
metadata.link_count = m_raw_inode.i_links_count;
|
||||
metadata.atime = m_raw_inode.i_atime;
|
||||
metadata.ctime = m_raw_inode.i_ctime;
|
||||
metadata.mtime = m_raw_inode.i_mtime;
|
||||
metadata.dtime = m_raw_inode.i_dtime;
|
||||
metadata.blockSize = fs().blockSize();
|
||||
metadata.blockCount = m_raw_inode.i_blocks;
|
||||
metadata.block_size = fs().block_size();
|
||||
metadata.block_count = m_raw_inode.i_blocks;
|
||||
|
||||
if (isBlockDevice(m_raw_inode.i_mode) || isCharacterDevice(m_raw_inode.i_mode)) {
|
||||
if (::is_block_device(m_raw_inode.i_mode) || ::is_character_device(m_raw_inode.i_mode)) {
|
||||
unsigned dev = m_raw_inode.i_block[0];
|
||||
metadata.majorDevice = (dev & 0xfff00) >> 8;
|
||||
metadata.minorDevice = (dev & 0xff) | ((dev >> 12) & 0xfff00);
|
||||
metadata.major_device = (dev & 0xfff00) >> 8;
|
||||
metadata.minor_device = (dev & 0xff) | ((dev >> 12) & 0xfff00);
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
|
@ -414,7 +414,7 @@ RetainPtr<Inode> Ext2FS::get_inode(InodeIdentifier inode) const
|
|||
if (it != m_inode_cache.end())
|
||||
return (*it).value;
|
||||
auto new_inode = adopt(*new Ext2FSInode(const_cast<Ext2FS&>(*this), inode.index(), *raw_inode));
|
||||
m_inode_cache.set(inode.index(), new_inode.copyRef());
|
||||
m_inode_cache.set(inode.index(), new_inode.copy_ref());
|
||||
return new_inode;
|
||||
}
|
||||
|
||||
|
@ -445,7 +445,7 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDe
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
const size_t block_size = fs().blockSize();
|
||||
const size_t block_size = fs().block_size();
|
||||
|
||||
dword first_block_logical_index = offset / block_size;
|
||||
dword last_block_logical_index = (offset + count) / block_size;
|
||||
|
@ -464,9 +464,9 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileDe
|
|||
#endif
|
||||
|
||||
for (dword bi = first_block_logical_index; remaining_count && bi <= last_block_logical_index; ++bi) {
|
||||
auto block = fs().readBlock(m_block_list[bi]);
|
||||
auto block = fs().read_block(m_block_list[bi]);
|
||||
if (!block) {
|
||||
kprintf("ext2fs: read_bytes: readBlock(%u) failed (lbi: %u)\n", m_block_list[bi], bi);
|
||||
kprintf("ext2fs: read_bytes: read_block(%u) failed (lbi: %u)\n", m_block_list[bi], bi);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
@ -490,11 +490,11 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, size_t count, const byte* data, F
|
|||
|
||||
ASSERT(offset >= 0);
|
||||
|
||||
const size_t block_size = fs().blockSize();
|
||||
const size_t block_size = fs().block_size();
|
||||
size_t new_size = max(static_cast<size_t>(offset) + count, size());
|
||||
|
||||
unsigned blocks_needed_before = ceilDiv(size(), block_size);
|
||||
unsigned blocks_needed_after = ceilDiv(new_size, block_size);
|
||||
unsigned blocks_needed_before = ceil_div(size(), block_size);
|
||||
unsigned blocks_needed_after = ceil_div(new_size, block_size);
|
||||
|
||||
auto block_list = fs().block_list_for_inode(m_raw_inode);
|
||||
if (blocks_needed_after > blocks_needed_before) {
|
||||
|
@ -529,9 +529,9 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, size_t count, const byte* data, F
|
|||
|
||||
ByteBuffer block;
|
||||
if (offset_into_block != 0) {
|
||||
block = fs().readBlock(block_list[bi]);
|
||||
block = fs().read_block(block_list[bi]);
|
||||
if (!block) {
|
||||
kprintf("Ext2FSInode::write_bytes: readBlock(%u) failed (lbi: %u)\n", block_list[bi], bi);
|
||||
kprintf("Ext2FSInode::write_bytes: read_block(%u) failed (lbi: %u)\n", block_list[bi], bi);
|
||||
return -EIO;
|
||||
}
|
||||
} else
|
||||
|
@ -543,9 +543,9 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, size_t count, const byte* data, F
|
|||
#ifdef EXT2_DEBUG
|
||||
dbgprintf("Ext2FSInode::write_bytes: writing block %u (offset_into_block: %u)\n", block_list[bi], offset_into_block);
|
||||
#endif
|
||||
bool success = fs().writeBlock(block_list[bi], block);
|
||||
bool success = fs().write_block(block_list[bi], block);
|
||||
if (!success) {
|
||||
kprintf("Ext2FSInode::write_bytes: writeBlock(%u) failed (lbi: %u)\n", block_list[bi], bi);
|
||||
kprintf("Ext2FSInode::write_bytes: write_block(%u) failed (lbi: %u)\n", block_list[bi], bi);
|
||||
return -EIO;
|
||||
}
|
||||
remaining_count -= num_bytes_to_copy;
|
||||
|
@ -569,7 +569,7 @@ ssize_t Ext2FSInode::write_bytes(off_t offset, size_t count, const byte* data, F
|
|||
|
||||
bool Ext2FSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)> callback) const
|
||||
{
|
||||
ASSERT(metadata().isDirectory());
|
||||
ASSERT(metadata().is_directory());
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
kprintf("Ext2Inode::traverse_as_directory: inode=%u:\n", index());
|
||||
|
@ -676,40 +676,40 @@ bool Ext2FS::write_directory_inode(unsigned directoryInode, Vector<DirectoryEntr
|
|||
{
|
||||
dbgprintf("Ext2FS: New directory inode %u contents to write:\n", directoryInode);
|
||||
|
||||
unsigned directorySize = 0;
|
||||
unsigned directory_size = 0;
|
||||
for (auto& entry : entries) {
|
||||
//kprintf(" - %08u %s\n", entry.inode.index(), entry.name);
|
||||
directorySize += EXT2_DIR_REC_LEN(entry.name_length);
|
||||
directory_size += EXT2_DIR_REC_LEN(entry.name_length);
|
||||
}
|
||||
|
||||
unsigned blocksNeeded = ceilDiv(directorySize, blockSize());
|
||||
unsigned occupiedSize = blocksNeeded * blockSize();
|
||||
unsigned blocks_needed = ceil_div(directory_size, block_size());
|
||||
unsigned occupied_size = blocks_needed * block_size();
|
||||
|
||||
dbgprintf("Ext2FS: directory size: %u (occupied: %u)\n", directorySize, occupiedSize);
|
||||
dbgprintf("Ext2FS: directory size: %u (occupied: %u)\n", directory_size, occupied_size);
|
||||
|
||||
auto directoryData = ByteBuffer::create_uninitialized(occupiedSize);
|
||||
auto directory_data = ByteBuffer::create_uninitialized(occupied_size);
|
||||
|
||||
BufferStream stream(directoryData);
|
||||
BufferStream stream(directory_data);
|
||||
for (unsigned i = 0; i < entries.size(); ++i) {
|
||||
auto& entry = entries[i];
|
||||
|
||||
unsigned recordLength = EXT2_DIR_REC_LEN(entry.name_length);
|
||||
unsigned record_length = EXT2_DIR_REC_LEN(entry.name_length);
|
||||
if (i == entries.size() - 1)
|
||||
recordLength += occupiedSize - directorySize;
|
||||
record_length += occupied_size - directory_size;
|
||||
|
||||
dbgprintf("* inode: %u", entry.inode.index());
|
||||
dbgprintf(", name_len: %u", word(entry.name_length));
|
||||
dbgprintf(", rec_len: %u", word(recordLength));
|
||||
dbgprintf(", file_type: %u", byte(entry.fileType));
|
||||
dbgprintf(", rec_len: %u", word(record_length));
|
||||
dbgprintf(", file_type: %u", byte(entry.file_type));
|
||||
dbgprintf(", name: %s\n", entry.name);
|
||||
|
||||
stream << dword(entry.inode.index());
|
||||
stream << word(recordLength);
|
||||
stream << word(record_length);
|
||||
stream << byte(entry.name_length);
|
||||
stream << byte(entry.fileType);
|
||||
stream << byte(entry.file_type);
|
||||
stream << entry.name;
|
||||
|
||||
unsigned padding = recordLength - entry.name_length - 8;
|
||||
unsigned padding = record_length - entry.name_length - 8;
|
||||
//dbgprintf(" *** pad %u bytes\n", padding);
|
||||
for (unsigned j = 0; j < padding; ++j) {
|
||||
stream << byte(0);
|
||||
|
@ -719,9 +719,9 @@ bool Ext2FS::write_directory_inode(unsigned directoryInode, Vector<DirectoryEntr
|
|||
stream.fill_to_end(0);
|
||||
|
||||
#if 0
|
||||
kprintf("data to write (%u):\n", directoryData.size());
|
||||
for (unsigned i = 0; i < directoryData.size(); ++i) {
|
||||
kprintf("%02x ", directoryData[i]);
|
||||
kprintf("data to write (%u):\n", directory_data.size());
|
||||
for (unsigned i = 0; i < directory_data.size(); ++i) {
|
||||
kprintf("%02x ", directory_data[i]);
|
||||
if ((i + 1) % 8 == 0)
|
||||
kprintf(" ");
|
||||
if ((i + 1) % 16 == 0)
|
||||
|
@ -731,8 +731,8 @@ bool Ext2FS::write_directory_inode(unsigned directoryInode, Vector<DirectoryEntr
|
|||
#endif
|
||||
|
||||
auto directory_inode = get_inode({ fsid(), directoryInode });
|
||||
ssize_t nwritten = directory_inode->write_bytes(0, directoryData.size(), directoryData.pointer(), nullptr);
|
||||
return nwritten == directoryData.size();
|
||||
ssize_t nwritten = directory_inode->write_bytes(0, directory_data.size(), directory_data.pointer(), nullptr);
|
||||
return nwritten == directory_data.size();
|
||||
}
|
||||
|
||||
unsigned Ext2FS::inodes_per_block() const
|
||||
|
@ -757,19 +757,19 @@ unsigned Ext2FS::blocks_per_group() const
|
|||
|
||||
void Ext2FS::dump_block_bitmap(unsigned groupIndex) const
|
||||
{
|
||||
ASSERT(groupIndex <= m_blockGroupCount);
|
||||
ASSERT(groupIndex <= m_block_group_count);
|
||||
auto& bgd = group_descriptor(groupIndex);
|
||||
|
||||
unsigned blocksInGroup = min(blocks_per_group(), super_block().s_blocks_count);
|
||||
unsigned blockCount = ceilDiv(blocksInGroup, 8u);
|
||||
unsigned blocks_in_group = min(blocks_per_group(), super_block().s_blocks_count);
|
||||
unsigned block_count = ceil_div(blocks_in_group, 8u);
|
||||
|
||||
auto bitmapBlocks = readBlocks(bgd.bg_block_bitmap, blockCount);
|
||||
ASSERT(bitmapBlocks);
|
||||
auto bitmap_blocks = read_blocks(bgd.bg_block_bitmap, block_count);
|
||||
ASSERT(bitmap_blocks);
|
||||
|
||||
kprintf("ext2fs: group[%u] block bitmap (bitmap occupies %u blocks):\n", groupIndex, blockCount);
|
||||
kprintf("ext2fs: group[%u] block bitmap (bitmap occupies %u blocks):\n", groupIndex, block_count);
|
||||
|
||||
auto bitmap = Bitmap::wrap(bitmapBlocks.pointer(), blocksInGroup);
|
||||
for (unsigned i = 0; i < blocksInGroup; ++i) {
|
||||
auto bitmap = Bitmap::wrap(bitmap_blocks.pointer(), blocks_in_group);
|
||||
for (unsigned i = 0; i < blocks_in_group; ++i) {
|
||||
kprintf("%c", bitmap.get(i) ? '1' : '0');
|
||||
}
|
||||
kprintf("\n");
|
||||
|
@ -787,17 +787,17 @@ void Ext2FS::dump_inode_bitmap(unsigned groupIndex) const
|
|||
template<typename F>
|
||||
void Ext2FS::traverse_inode_bitmap(unsigned groupIndex, F callback) const
|
||||
{
|
||||
ASSERT(groupIndex <= m_blockGroupCount);
|
||||
ASSERT(groupIndex <= m_block_group_count);
|
||||
auto& bgd = group_descriptor(groupIndex);
|
||||
|
||||
unsigned inodesInGroup = min(inodes_per_group(), super_block().s_inodes_count);
|
||||
unsigned blockCount = ceilDiv(inodesInGroup, 8u);
|
||||
unsigned inodes_in_group = min(inodes_per_group(), super_block().s_inodes_count);
|
||||
unsigned block_count = ceil_div(inodes_in_group, 8u);
|
||||
|
||||
for (unsigned i = 0; i < blockCount; ++i) {
|
||||
auto block = readBlock(bgd.bg_inode_bitmap + i);
|
||||
for (unsigned i = 0; i < block_count; ++i) {
|
||||
auto block = read_block(bgd.bg_inode_bitmap + i);
|
||||
ASSERT(block);
|
||||
bool shouldContinue = callback(i * (blockSize() / 8) + 1, Bitmap::wrap(block.pointer(), inodesInGroup));
|
||||
if (!shouldContinue)
|
||||
bool should_continue = callback(i * (block_size() / 8) + 1, Bitmap::wrap(block.pointer(), inodes_in_group));
|
||||
if (!should_continue)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -805,30 +805,30 @@ void Ext2FS::traverse_inode_bitmap(unsigned groupIndex, F callback) const
|
|||
template<typename F>
|
||||
void Ext2FS::traverse_block_bitmap(unsigned groupIndex, F callback) const
|
||||
{
|
||||
ASSERT(groupIndex <= m_blockGroupCount);
|
||||
ASSERT(groupIndex <= m_block_group_count);
|
||||
auto& bgd = group_descriptor(groupIndex);
|
||||
|
||||
unsigned blocksInGroup = min(blocks_per_group(), super_block().s_blocks_count);
|
||||
unsigned blockCount = ceilDiv(blocksInGroup, 8u);
|
||||
unsigned blocks_in_group = min(blocks_per_group(), super_block().s_blocks_count);
|
||||
unsigned block_count = ceil_div(blocks_in_group, 8u);
|
||||
|
||||
for (unsigned i = 0; i < blockCount; ++i) {
|
||||
auto block = readBlock(bgd.bg_block_bitmap + i);
|
||||
for (unsigned i = 0; i < block_count; ++i) {
|
||||
auto block = read_block(bgd.bg_block_bitmap + i);
|
||||
ASSERT(block);
|
||||
bool shouldContinue = callback(i * (blockSize() / 8) + 1, Bitmap::wrap(block.pointer(), blocksInGroup));
|
||||
if (!shouldContinue)
|
||||
bool should_continue = callback(i * (block_size() / 8) + 1, Bitmap::wrap(block.pointer(), blocks_in_group));
|
||||
if (!should_continue)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool Ext2FS::write_ext2_inode(unsigned inode, const ext2_inode& e2inode)
|
||||
{
|
||||
unsigned blockIndex;
|
||||
unsigned block_index;
|
||||
unsigned offset;
|
||||
auto block = read_block_containing_inode(inode, blockIndex, offset);
|
||||
auto block = read_block_containing_inode(inode, block_index, offset);
|
||||
if (!block)
|
||||
return false;
|
||||
memcpy(reinterpret_cast<ext2_inode*>(block.offset_pointer(offset)), &e2inode, inode_size());
|
||||
writeBlock(blockIndex, block);
|
||||
write_block(block_index, block);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -864,36 +864,36 @@ Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(unsigned group, unsigned coun
|
|||
return blocks;
|
||||
}
|
||||
|
||||
unsigned Ext2FS::allocate_inode(unsigned preferredGroup, unsigned expectedSize)
|
||||
unsigned Ext2FS::allocate_inode(unsigned preferred_group, unsigned expected_size)
|
||||
{
|
||||
dbgprintf("Ext2FS: allocate_inode(preferredGroup: %u, expectedSize: %u)\n", preferredGroup, expectedSize);
|
||||
dbgprintf("Ext2FS: allocate_inode(preferredGroup: %u, expectedSize: %u)\n", preferred_group, expected_size);
|
||||
|
||||
unsigned neededBlocks = ceilDiv(expectedSize, blockSize());
|
||||
unsigned needed_blocks = ceil_div(expected_size, block_size());
|
||||
|
||||
dbgprintf("Ext2FS: minimum needed blocks: %u\n", neededBlocks);
|
||||
dbgprintf("Ext2FS: minimum needed blocks: %u\n", needed_blocks);
|
||||
|
||||
unsigned groupIndex = 0;
|
||||
|
||||
auto isSuitableGroup = [this, neededBlocks] (unsigned groupIndex) {
|
||||
auto is_suitable_group = [this, needed_blocks] (unsigned groupIndex) {
|
||||
auto& bgd = group_descriptor(groupIndex);
|
||||
return bgd.bg_free_inodes_count && bgd.bg_free_blocks_count >= neededBlocks;
|
||||
return bgd.bg_free_inodes_count && bgd.bg_free_blocks_count >= needed_blocks;
|
||||
};
|
||||
|
||||
if (preferredGroup && isSuitableGroup(preferredGroup)) {
|
||||
groupIndex = preferredGroup;
|
||||
if (preferred_group && is_suitable_group(preferred_group)) {
|
||||
groupIndex = preferred_group;
|
||||
} else {
|
||||
for (unsigned i = 1; i <= m_blockGroupCount; ++i) {
|
||||
if (isSuitableGroup(i))
|
||||
for (unsigned i = 1; i <= m_block_group_count; ++i) {
|
||||
if (is_suitable_group(i))
|
||||
groupIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (!groupIndex) {
|
||||
kprintf("Ext2FS: allocate_inode: no suitable group found for new inode with %u blocks needed :(\n", neededBlocks);
|
||||
kprintf("Ext2FS: allocate_inode: no suitable group found for new inode with %u blocks needed :(\n", needed_blocks);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dbgprintf("Ext2FS: allocate_inode: found suitable group [%u] for new inode with %u blocks needed :^)\n", groupIndex, neededBlocks);
|
||||
dbgprintf("Ext2FS: allocate_inode: found suitable group [%u] for new inode with %u blocks needed :^)\n", groupIndex, needed_blocks);
|
||||
|
||||
unsigned firstFreeInodeInGroup = 0;
|
||||
traverse_inode_bitmap(groupIndex, [&firstFreeInodeInGroup] (unsigned firstInodeInBitmap, const Bitmap& bitmap) {
|
||||
|
@ -931,10 +931,10 @@ bool Ext2FS::get_inode_allocation_state(InodeIndex index) const
|
|||
if (index == 0)
|
||||
return true;
|
||||
auto& bgd = group_descriptor(group_index_from_inode(index));
|
||||
unsigned inodes_per_bitmap_block = blockSize() * 8;
|
||||
unsigned inodes_per_bitmap_block = block_size() * 8;
|
||||
unsigned bitmap_block_index = (index - 1) / inodes_per_bitmap_block;
|
||||
unsigned bit_index = (index - 1) % inodes_per_bitmap_block;
|
||||
auto block = readBlock(bgd.bg_inode_bitmap + bitmap_block_index);
|
||||
auto block = read_block(bgd.bg_inode_bitmap + bitmap_block_index);
|
||||
ASSERT(block);
|
||||
auto bitmap = Bitmap::wrap(block.pointer(), block.size());
|
||||
return bitmap.get(bit_index);
|
||||
|
@ -945,20 +945,20 @@ bool Ext2FS::set_inode_allocation_state(unsigned index, bool newState)
|
|||
auto& bgd = group_descriptor(group_index_from_inode(index));
|
||||
|
||||
// Update inode bitmap
|
||||
unsigned inodes_per_bitmap_block = blockSize() * 8;
|
||||
unsigned inodes_per_bitmap_block = block_size() * 8;
|
||||
unsigned bitmap_block_index = (index - 1) / inodes_per_bitmap_block;
|
||||
unsigned bit_index = (index - 1) % inodes_per_bitmap_block;
|
||||
auto block = readBlock(bgd.bg_inode_bitmap + bitmap_block_index);
|
||||
auto block = read_block(bgd.bg_inode_bitmap + bitmap_block_index);
|
||||
ASSERT(block);
|
||||
auto bitmap = Bitmap::wrap(block.pointer(), block.size());
|
||||
bool currentState = bitmap.get(bit_index);
|
||||
dbgprintf("Ext2FS: set_inode_allocation_state(%u) %u -> %u\n", index, currentState, newState);
|
||||
bool current_state = bitmap.get(bit_index);
|
||||
dbgprintf("Ext2FS: set_inode_allocation_state(%u) %u -> %u\n", index, current_state, newState);
|
||||
|
||||
if (currentState == newState)
|
||||
if (current_state == newState)
|
||||
return true;
|
||||
|
||||
bitmap.set(bit_index, newState);
|
||||
writeBlock(bgd.bg_inode_bitmap + bitmap_block_index, block);
|
||||
write_block(bgd.bg_inode_bitmap + bitmap_block_index, block);
|
||||
|
||||
// Update superblock
|
||||
auto& sb = *reinterpret_cast<ext2_super_block*>(m_cached_super_block.pointer());
|
||||
|
@ -970,53 +970,53 @@ bool Ext2FS::set_inode_allocation_state(unsigned index, bool newState)
|
|||
write_super_block(sb);
|
||||
|
||||
// Update BGD
|
||||
auto& mutableBGD = const_cast<ext2_group_desc&>(bgd);
|
||||
auto& mutable_bgd = const_cast<ext2_group_desc&>(bgd);
|
||||
if (newState)
|
||||
--mutableBGD.bg_free_inodes_count;
|
||||
--mutable_bgd.bg_free_inodes_count;
|
||||
else
|
||||
++mutableBGD.bg_free_inodes_count;
|
||||
++mutable_bgd.bg_free_inodes_count;
|
||||
dbgprintf("Ext2FS: group free inode count %u -> %u\n", bgd.bg_free_inodes_count, bgd.bg_free_inodes_count - 1);
|
||||
|
||||
flush_block_group_descriptor_table();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ext2FS::set_block_allocation_state(GroupIndex group, BlockIndex bi, bool newState)
|
||||
bool Ext2FS::set_block_allocation_state(GroupIndex group, BlockIndex bi, bool new_state)
|
||||
{
|
||||
dbgprintf("Ext2FS: set_block_allocation_state(group=%u, block=%u, state=%u)\n", group, bi, newState);
|
||||
dbgprintf("Ext2FS: set_block_allocation_state(group=%u, block=%u, state=%u)\n", group, bi, new_state);
|
||||
auto& bgd = group_descriptor(group);
|
||||
|
||||
// Update block bitmap
|
||||
unsigned blocksPerBitmapBlock = blockSize() * 8;
|
||||
unsigned bitmapBlockIndex = (bi - 1) / blocksPerBitmapBlock;
|
||||
unsigned bitIndex = (bi - 1) % blocksPerBitmapBlock;
|
||||
auto block = readBlock(bgd.bg_block_bitmap + bitmapBlockIndex);
|
||||
unsigned blocks_per_bitmap_block = block_size() * 8;
|
||||
unsigned bitmap_block_index = (bi - 1) / blocks_per_bitmap_block;
|
||||
unsigned bit_index = (bi - 1) % blocks_per_bitmap_block;
|
||||
auto block = read_block(bgd.bg_block_bitmap + bitmap_block_index);
|
||||
ASSERT(block);
|
||||
auto bitmap = Bitmap::wrap(block.pointer(), blocksPerBitmapBlock);
|
||||
bool currentState = bitmap.get(bitIndex);
|
||||
dbgprintf("Ext2FS: block %u state: %u -> %u\n", bi, currentState, newState);
|
||||
auto bitmap = Bitmap::wrap(block.pointer(), blocks_per_bitmap_block);
|
||||
bool current_state = bitmap.get(bit_index);
|
||||
dbgprintf("Ext2FS: block %u state: %u -> %u\n", bi, current_state, new_state);
|
||||
|
||||
if (currentState == newState)
|
||||
if (current_state == new_state)
|
||||
return true;
|
||||
|
||||
bitmap.set(bitIndex, newState);
|
||||
writeBlock(bgd.bg_block_bitmap + bitmapBlockIndex, block);
|
||||
bitmap.set(bit_index, new_state);
|
||||
write_block(bgd.bg_block_bitmap + bitmap_block_index, block);
|
||||
|
||||
// Update superblock
|
||||
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)
|
||||
if (new_state)
|
||||
--sb.s_free_blocks_count;
|
||||
else
|
||||
++sb.s_free_blocks_count;
|
||||
write_super_block(sb);
|
||||
|
||||
// Update BGD
|
||||
auto& mutableBGD = const_cast<ext2_group_desc&>(bgd);
|
||||
if (newState)
|
||||
--mutableBGD.bg_free_blocks_count;
|
||||
auto& mutable_bgd = const_cast<ext2_group_desc&>(bgd);
|
||||
if (new_state)
|
||||
--mutable_bgd.bg_free_blocks_count;
|
||||
else
|
||||
++mutableBGD.bg_free_blocks_count;
|
||||
++mutable_bgd.bg_free_blocks_count;
|
||||
dbgprintf("Ext2FS: group free block count %u -> %u\n", bgd.bg_free_blocks_count, bgd.bg_free_blocks_count - 1);
|
||||
|
||||
flush_block_group_descriptor_table();
|
||||
|
@ -1034,7 +1034,7 @@ RetainPtr<Inode> Ext2FS::create_directory(InodeIdentifier parent_id, const Strin
|
|||
|
||||
// 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(parent_id, name, mode, blockSize(), error);
|
||||
auto inode = create_inode(parent_id, name, mode, block_size(), error);
|
||||
if (!inode)
|
||||
return nullptr;
|
||||
|
||||
|
@ -1077,7 +1077,7 @@ RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& n
|
|||
return { };
|
||||
}
|
||||
|
||||
auto needed_blocks = ceilDiv(size, blockSize());
|
||||
auto needed_blocks = ceil_div(size, block_size());
|
||||
auto blocks = allocate_blocks(group_index_from_inode(inode_id), needed_blocks);
|
||||
if (blocks.size() != needed_blocks) {
|
||||
kprintf("Ext2FS: create_inode: allocate_blocks failed\n");
|
||||
|
@ -1085,24 +1085,24 @@ RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& n
|
|||
return { };
|
||||
}
|
||||
|
||||
byte fileType = 0;
|
||||
if (isRegularFile(mode))
|
||||
fileType = EXT2_FT_REG_FILE;
|
||||
else if (isDirectory(mode))
|
||||
fileType = EXT2_FT_DIR;
|
||||
else if (isCharacterDevice(mode))
|
||||
fileType = EXT2_FT_CHRDEV;
|
||||
else if (isBlockDevice(mode))
|
||||
fileType = EXT2_FT_BLKDEV;
|
||||
else if (isFIFO(mode))
|
||||
fileType = EXT2_FT_FIFO;
|
||||
else if (isSocket(mode))
|
||||
fileType = EXT2_FT_SOCK;
|
||||
else if (isSymbolicLink(mode))
|
||||
fileType = EXT2_FT_SYMLINK;
|
||||
byte file_type = 0;
|
||||
if (is_regular_file(mode))
|
||||
file_type = EXT2_FT_REG_FILE;
|
||||
else if (is_directory(mode))
|
||||
file_type = EXT2_FT_DIR;
|
||||
else if (is_character_device(mode))
|
||||
file_type = EXT2_FT_CHRDEV;
|
||||
else if (is_block_device(mode))
|
||||
file_type = EXT2_FT_BLKDEV;
|
||||
else if (is_fifo(mode))
|
||||
file_type = EXT2_FT_FIFO;
|
||||
else if (is_socket(mode))
|
||||
file_type = EXT2_FT_SOCK;
|
||||
else if (is_symlink(mode))
|
||||
file_type = EXT2_FT_SYMLINK;
|
||||
|
||||
// Try adding it to the directory first, in case the name is already in use.
|
||||
bool success = parent_inode->add_child({ fsid(), inode_id }, name, fileType, error);
|
||||
bool success = parent_inode->add_child({ fsid(), inode_id }, name, file_type, error);
|
||||
if (!success)
|
||||
return { };
|
||||
|
||||
|
@ -1115,11 +1115,11 @@ RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& n
|
|||
ASSERT(success);
|
||||
}
|
||||
|
||||
unsigned initialLinksCount;
|
||||
if (isDirectory(mode))
|
||||
initialLinksCount = 2; // (parent directory + "." entry in self)
|
||||
unsigned initial_links_count;
|
||||
if (is_directory(mode))
|
||||
initial_links_count = 2; // (parent directory + "." entry in self)
|
||||
else
|
||||
initialLinksCount = 1;
|
||||
initial_links_count = 1;
|
||||
|
||||
auto timestamp = RTC::now();
|
||||
ext2_inode e2inode;
|
||||
|
@ -1132,7 +1132,7 @@ RetainPtr<Inode> Ext2FS::create_inode(InodeIdentifier parent_id, const String& n
|
|||
e2inode.i_mtime = timestamp;
|
||||
e2inode.i_dtime = 0;
|
||||
e2inode.i_gid = 0;
|
||||
e2inode.i_links_count = initialLinksCount;
|
||||
e2inode.i_links_count = initial_links_count;
|
||||
|
||||
success = write_block_list_for_inode(inode_id, e2inode, blocks);
|
||||
ASSERT(success);
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
virtual ~Ext2FSInode() override;
|
||||
|
||||
size_t size() const { return m_raw_inode.i_size; }
|
||||
bool is_symlink() const { return isSymbolicLink(m_raw_inode.i_mode); }
|
||||
bool is_symlink() const { return ::is_symlink(m_raw_inode.i_mode); }
|
||||
|
||||
// ^Inode (Retainable magic)
|
||||
virtual void one_retain_left() override;
|
||||
|
@ -78,7 +78,7 @@ private:
|
|||
unsigned inode_size() const;
|
||||
|
||||
bool write_ext2_inode(unsigned, const ext2_inode&);
|
||||
ByteBuffer read_block_containing_inode(unsigned inode, unsigned& blockIndex, unsigned& offset) const;
|
||||
ByteBuffer read_block_containing_inode(unsigned inode, unsigned& block_index, unsigned& offset) const;
|
||||
|
||||
ByteBuffer read_super_block() const;
|
||||
bool write_super_block(const ext2_super_block&);
|
||||
|
@ -102,7 +102,7 @@ private:
|
|||
template<typename F> void traverse_inode_bitmap(unsigned groupIndex, F) const;
|
||||
template<typename F> void traverse_block_bitmap(unsigned groupIndex, F) const;
|
||||
|
||||
bool add_inode_to_directory(InodeIndex parent, InodeIndex child, const String& name, byte fileType, int& error);
|
||||
bool add_inode_to_directory(InodeIndex parent, InodeIndex child, const String& name, byte file_type, int& error);
|
||||
bool write_directory_inode(unsigned directoryInode, Vector<DirectoryEntry>&&);
|
||||
bool get_inode_allocation_state(InodeIndex) const;
|
||||
bool set_inode_allocation_state(unsigned inode, bool);
|
||||
|
@ -121,7 +121,7 @@ private:
|
|||
|
||||
BlockListShape compute_block_list_shape(unsigned blocks);
|
||||
|
||||
unsigned m_blockGroupCount { 0 };
|
||||
unsigned m_block_group_count { 0 };
|
||||
|
||||
mutable ByteBuffer m_cached_super_block;
|
||||
mutable ByteBuffer m_cached_group_descriptor_table;
|
||||
|
|
|
@ -47,7 +47,7 @@ bool FileBackedDiskDevice::write_block(unsigned index, const byte* data)
|
|||
bool FileBackedDiskDevice::read_internal(DiskOffset offset, unsigned length, byte* out) const
|
||||
{
|
||||
#ifndef IGNORE_FILE_LENGTH
|
||||
if (offset + length >= m_fileLength)
|
||||
if (offset + length >= m_file_length)
|
||||
return false;
|
||||
#endif
|
||||
#ifdef FBBD_DEBUG
|
||||
|
@ -62,7 +62,7 @@ bool FileBackedDiskDevice::read_internal(DiskOffset offset, unsigned length, byt
|
|||
bool FileBackedDiskDevice::write_internal(DiskOffset offset, unsigned length, const byte* data)
|
||||
{
|
||||
#ifndef IGNORE_FILE_LENGTH
|
||||
if (offset + length >= m_fileLength)
|
||||
if (offset + length >= m_file_length)
|
||||
return false;
|
||||
#endif
|
||||
#ifdef FBBD_DEBUG
|
||||
|
|
|
@ -60,10 +60,10 @@ RetainPtr<FileDescriptor> FileDescriptor::clone()
|
|||
: FileDescriptor::create_pipe_writer(*m_fifo);
|
||||
} else {
|
||||
if (m_device) {
|
||||
descriptor = FileDescriptor::create(m_device.copyRef());
|
||||
descriptor->m_inode = m_inode.copyRef();
|
||||
descriptor = FileDescriptor::create(m_device.copy_ref());
|
||||
descriptor->m_inode = m_inode.copy_ref();
|
||||
} else {
|
||||
descriptor = FileDescriptor::create(m_inode.copyRef());
|
||||
descriptor = FileDescriptor::create(m_inode.copy_ref());
|
||||
}
|
||||
}
|
||||
if (!descriptor)
|
||||
|
@ -74,7 +74,7 @@ RetainPtr<FileDescriptor> FileDescriptor::clone()
|
|||
return descriptor;
|
||||
}
|
||||
|
||||
bool additionWouldOverflow(off_t a, off_t b)
|
||||
bool addition_would_overflow(off_t a, off_t b)
|
||||
{
|
||||
ASSERT(a > 0);
|
||||
uint64_t ua = a;
|
||||
|
@ -88,19 +88,19 @@ int FileDescriptor::fstat(stat* buffer)
|
|||
return -EBADF;
|
||||
|
||||
auto metadata = this->metadata();
|
||||
if (!metadata.isValid())
|
||||
if (!metadata.is_valid())
|
||||
return -EIO;
|
||||
|
||||
buffer->st_dev = encodedDevice(metadata.majorDevice, metadata.minorDevice);
|
||||
buffer->st_dev = encoded_device(metadata.major_device, metadata.minor_device);
|
||||
buffer->st_ino = metadata.inode.index();
|
||||
buffer->st_mode = metadata.mode;
|
||||
buffer->st_nlink = metadata.linkCount;
|
||||
buffer->st_nlink = metadata.link_count;
|
||||
buffer->st_uid = metadata.uid;
|
||||
buffer->st_gid = metadata.gid;
|
||||
buffer->st_rdev = 0; // FIXME
|
||||
buffer->st_size = metadata.size;
|
||||
buffer->st_blksize = metadata.blockSize;
|
||||
buffer->st_blocks = metadata.blockCount;
|
||||
buffer->st_blksize = metadata.block_size;
|
||||
buffer->st_blocks = metadata.block_count;
|
||||
buffer->st_atime = metadata.atime;
|
||||
buffer->st_mtime = metadata.mtime;
|
||||
buffer->st_ctime = metadata.ctime;
|
||||
|
@ -116,10 +116,10 @@ off_t FileDescriptor::seek(off_t offset, int whence)
|
|||
// FIXME: The file type should be cached on the vnode.
|
||||
// It's silly that we have to do a full metadata lookup here.
|
||||
auto metadata = this->metadata();
|
||||
if (!metadata.isValid())
|
||||
if (!metadata.is_valid())
|
||||
return -EIO;
|
||||
|
||||
if (metadata.isSocket() || metadata.isFIFO())
|
||||
if (metadata.is_socket() || metadata.is_fifo())
|
||||
return -ESPIPE;
|
||||
|
||||
off_t newOffset;
|
||||
|
@ -217,23 +217,23 @@ ByteBuffer FileDescriptor::read_entire_file(Process& process)
|
|||
bool FileDescriptor::is_directory() const
|
||||
{
|
||||
ASSERT(!is_fifo());
|
||||
return metadata().isDirectory();
|
||||
return metadata().is_directory();
|
||||
}
|
||||
|
||||
ssize_t FileDescriptor::get_dir_entries(byte* buffer, size_t size)
|
||||
{
|
||||
auto metadata = this->metadata();
|
||||
if (!metadata.isValid())
|
||||
if (!metadata.is_valid())
|
||||
return -EIO;
|
||||
if (!metadata.isDirectory())
|
||||
if (!metadata.is_directory())
|
||||
return -ENOTDIR;
|
||||
|
||||
// FIXME: Compute the actual size needed.
|
||||
auto tempBuffer = ByteBuffer::create_uninitialized(2048);
|
||||
BufferStream stream(tempBuffer);
|
||||
auto temp_buffer = ByteBuffer::create_uninitialized(2048);
|
||||
BufferStream stream(temp_buffer);
|
||||
VFS::the().traverse_directory_inode(*m_inode, [&stream] (auto& entry) {
|
||||
stream << (dword)entry.inode.index();
|
||||
stream << (byte)entry.fileType;
|
||||
stream << (byte)entry.file_type;
|
||||
stream << (dword)entry.name_length;
|
||||
stream << entry.name;
|
||||
return true;
|
||||
|
@ -242,7 +242,7 @@ ssize_t FileDescriptor::get_dir_entries(byte* buffer, size_t size)
|
|||
if (size < stream.offset())
|
||||
return -1;
|
||||
|
||||
memcpy(buffer, tempBuffer.pointer(), stream.offset());
|
||||
memcpy(buffer, temp_buffer.pointer(), stream.offset());
|
||||
return stream.offset();
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ ByteBuffer Inode::read_entire(FileDescriptor* descriptor) const
|
|||
FS::DirectoryEntry::DirectoryEntry(const char* n, InodeIdentifier i, byte ft)
|
||||
: name_length(strlen(n))
|
||||
, inode(i)
|
||||
, fileType(ft)
|
||||
, file_type(ft)
|
||||
{
|
||||
memcpy(name, n, name_length);
|
||||
name[name_length] = '\0';
|
||||
|
@ -85,7 +85,7 @@ FS::DirectoryEntry::DirectoryEntry(const char* n, InodeIdentifier i, byte ft)
|
|||
FS::DirectoryEntry::DirectoryEntry(const char* n, size_t nl, InodeIdentifier i, byte ft)
|
||||
: name_length(nl)
|
||||
, inode(i)
|
||||
, fileType(ft)
|
||||
, file_type(ft)
|
||||
{
|
||||
memcpy(name, n, nl);
|
||||
name[nl] = '\0';
|
||||
|
|
|
@ -37,12 +37,12 @@ public:
|
|||
bool is_readonly() const { return m_readonly; }
|
||||
|
||||
struct DirectoryEntry {
|
||||
DirectoryEntry(const char* name, InodeIdentifier, byte fileType);
|
||||
DirectoryEntry(const char* name, size_t name_length, InodeIdentifier, byte fileType);
|
||||
DirectoryEntry(const char* name, InodeIdentifier, byte file_type);
|
||||
DirectoryEntry(const char* name, size_t name_length, InodeIdentifier, byte file_type);
|
||||
char name[256];
|
||||
size_t name_length { 0 };
|
||||
InodeIdentifier inode;
|
||||
byte fileType { 0 };
|
||||
byte file_type { 0 };
|
||||
};
|
||||
|
||||
virtual RetainPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, unsigned size, int& error) = 0;
|
||||
|
@ -71,9 +71,9 @@ public:
|
|||
unsigned index() const { return m_index; }
|
||||
|
||||
size_t size() const { return metadata().size; }
|
||||
bool is_symlink() const { return metadata().isSymbolicLink(); }
|
||||
bool is_directory() const { return metadata().isDirectory(); }
|
||||
bool is_character_device() const { return metadata().isCharacterDevice(); }
|
||||
bool is_symlink() const { return metadata().is_symlink(); }
|
||||
bool is_directory() const { return metadata().is_directory(); }
|
||||
bool is_character_device() const { return metadata().is_character_device(); }
|
||||
mode_t mode() const { return metadata().mode; }
|
||||
|
||||
InodeIdentifier identifier() const { return { fsid(), index() }; }
|
||||
|
|
|
@ -9,8 +9,8 @@ struct InodeMetadata;
|
|||
class InodeIdentifier {
|
||||
public:
|
||||
InodeIdentifier() { }
|
||||
InodeIdentifier(dword fileSystemID, dword inode)
|
||||
: m_fsid(fileSystemID)
|
||||
InodeIdentifier(dword fsid, dword inode)
|
||||
: m_fsid(fsid)
|
||||
, m_index(inode)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -4,21 +4,21 @@
|
|||
#include "UnixTypes.h"
|
||||
#include <AK/HashTable.h>
|
||||
|
||||
inline bool isDirectory(mode_t mode) { return (mode & 0170000) == 0040000; }
|
||||
inline bool isCharacterDevice(mode_t mode) { return (mode & 0170000) == 0020000; }
|
||||
inline bool isBlockDevice(mode_t mode) { return (mode & 0170000) == 0060000; }
|
||||
inline bool isRegularFile(mode_t mode) { return (mode & 0170000) == 0100000; }
|
||||
inline bool isFIFO(mode_t mode) { return (mode & 0170000) == 0010000; }
|
||||
inline bool isSymbolicLink(mode_t mode) { return (mode & 0170000) == 0120000; }
|
||||
inline bool isSocket(mode_t mode) { return (mode & 0170000) == 0140000; }
|
||||
inline bool isSticky(mode_t mode) { return mode & 01000; }
|
||||
inline bool isSetUID(mode_t mode) { return mode & 04000; }
|
||||
inline bool isSetGID(mode_t mode) { return mode & 02000; }
|
||||
inline bool is_directory(mode_t mode) { return (mode & 0170000) == 0040000; }
|
||||
inline bool is_character_device(mode_t mode) { return (mode & 0170000) == 0020000; }
|
||||
inline bool is_block_device(mode_t mode) { return (mode & 0170000) == 0060000; }
|
||||
inline bool is_regular_file(mode_t mode) { return (mode & 0170000) == 0100000; }
|
||||
inline bool is_fifo(mode_t mode) { return (mode & 0170000) == 0010000; }
|
||||
inline bool is_symlink(mode_t mode) { return (mode & 0170000) == 0120000; }
|
||||
inline bool is_socket(mode_t mode) { return (mode & 0170000) == 0140000; }
|
||||
inline bool is_sticky(mode_t mode) { return mode & 01000; }
|
||||
inline bool is_setuid(mode_t mode) { return mode & 04000; }
|
||||
inline bool is_setgid(mode_t mode) { return mode & 02000; }
|
||||
|
||||
struct InodeMetadata {
|
||||
bool isValid() const { return inode.is_valid(); }
|
||||
bool is_valid() const { return inode.is_valid(); }
|
||||
|
||||
bool mayExecute(uid_t u, const HashTable<gid_t>& g) const
|
||||
bool may_execute(uid_t u, const HashTable<gid_t>& g) const
|
||||
{
|
||||
if (uid == u)
|
||||
return mode & 0100;
|
||||
|
@ -27,31 +27,31 @@ struct InodeMetadata {
|
|||
return mode & 0001;
|
||||
}
|
||||
|
||||
bool isDirectory() const { return ::isDirectory(mode); }
|
||||
bool isCharacterDevice() const { return ::isCharacterDevice(mode); }
|
||||
bool isBlockDevice() const { return ::isBlockDevice(mode); }
|
||||
bool isRegularFile() const { return ::isRegularFile(mode); }
|
||||
bool isFIFO() const { return ::isFIFO(mode); }
|
||||
bool isSymbolicLink() const { return ::isSymbolicLink(mode); }
|
||||
bool isSocket() const { return ::isSocket(mode); }
|
||||
bool isSticky() const { return ::isSticky(mode); }
|
||||
bool isSetUID() const { return ::isSetUID(mode); }
|
||||
bool isSetGID() const { return ::isSetGID(mode); }
|
||||
bool is_directory() const { return ::is_directory(mode); }
|
||||
bool is_character_device() const { return ::is_character_device(mode); }
|
||||
bool is_block_device() const { return ::is_block_device(mode); }
|
||||
bool is_regular_file() const { return ::is_regular_file(mode); }
|
||||
bool is_fifo() const { return ::is_fifo(mode); }
|
||||
bool is_symlink() const { return ::is_symlink(mode); }
|
||||
bool is_socket() const { return ::is_socket(mode); }
|
||||
bool is_sticky() const { return ::is_sticky(mode); }
|
||||
bool is_setuid() const { return ::is_setuid(mode); }
|
||||
bool is_setgid() const { return ::is_setgid(mode); }
|
||||
|
||||
InodeIdentifier inode;
|
||||
off_t size { 0 };
|
||||
mode_t mode { 0 };
|
||||
uid_t uid { 0 };
|
||||
gid_t gid { 0 };
|
||||
nlink_t linkCount { 0 };
|
||||
nlink_t link_count { 0 };
|
||||
time_t atime { 0 };
|
||||
time_t ctime { 0 };
|
||||
time_t mtime { 0 };
|
||||
time_t dtime { 0 };
|
||||
blkcnt_t blockCount { 0 };
|
||||
blksize_t blockSize { 0 };
|
||||
unsigned majorDevice { 0 };
|
||||
unsigned minorDevice { 0 };
|
||||
blkcnt_t block_count { 0 };
|
||||
blksize_t block_size { 0 };
|
||||
unsigned major_device { 0 };
|
||||
unsigned minor_device { 0 };
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -89,21 +89,21 @@ void dump_backtrace(bool use_ksyms)
|
|||
};
|
||||
Vector<RecognizedSymbol> recognized_symbols;
|
||||
if (use_ksyms) {
|
||||
for (dword* stackPtr = (dword*)&use_ksyms; current->validate_read_from_kernel(LinearAddress((dword)stackPtr)); stackPtr = (dword*)*stackPtr) {
|
||||
dword retaddr = stackPtr[1];
|
||||
for (dword* stack_ptr = (dword*)&use_ksyms; current->validate_read_from_kernel(LinearAddress((dword)stack_ptr)); stack_ptr = (dword*)*stack_ptr) {
|
||||
dword retaddr = stack_ptr[1];
|
||||
if (auto* ksym = ksymbolicate(retaddr))
|
||||
recognized_symbols.append({ retaddr, ksym });
|
||||
}
|
||||
} else{
|
||||
for (dword* stackPtr = (dword*)&use_ksyms; current->validate_read_from_kernel(LinearAddress((dword)stackPtr)); stackPtr = (dword*)*stackPtr) {
|
||||
dword retaddr = stackPtr[1];
|
||||
kprintf("%x (next: %x)\n", retaddr, stackPtr ? (dword*)*stackPtr : 0);
|
||||
for (dword* stack_ptr = (dword*)&use_ksyms; current->validate_read_from_kernel(LinearAddress((dword)stack_ptr)); stack_ptr = (dword*)*stack_ptr) {
|
||||
dword retaddr = stack_ptr[1];
|
||||
kprintf("%x (next: %x)\n", retaddr, stack_ptr ? (dword*)*stack_ptr : 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
size_t bytesNeeded = 0;
|
||||
size_t bytes_needed = 0;
|
||||
for (auto& symbol : recognized_symbols) {
|
||||
bytesNeeded += strlen(symbol.ksym->name) + 8 + 16;
|
||||
bytes_needed += strlen(symbol.ksym->name) + 8 + 16;
|
||||
}
|
||||
for (auto& symbol : recognized_symbols) {
|
||||
unsigned offset = symbol.address - symbol.ksym->address;
|
||||
|
|
|
@ -112,7 +112,7 @@ RetainPtr<PhysicalPage> MemoryManager::allocate_page_table(PageDirectory& page_d
|
|||
auto physical_page = allocate_supervisor_physical_page();
|
||||
if (!physical_page)
|
||||
return nullptr;
|
||||
page_directory.m_physical_pages.set(index, physical_page.copyRef());
|
||||
page_directory.m_physical_pages.set(index, physical_page.copy_ref());
|
||||
return physical_page;
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ auto MemoryManager::ensure_pte(PageDirectory& page_directory, LinearAddress ladd
|
|||
#endif
|
||||
if (page_directory_index == 0) {
|
||||
ASSERT(&page_directory == m_kernel_page_directory.ptr());
|
||||
pde.setPageTableBase((dword)m_page_table_zero);
|
||||
pde.set_page_table_base((dword)m_page_table_zero);
|
||||
pde.set_user_allowed(false);
|
||||
pde.set_present(true);
|
||||
pde.set_writable(true);
|
||||
|
@ -161,14 +161,14 @@ auto MemoryManager::ensure_pte(PageDirectory& page_directory, LinearAddress ladd
|
|||
page_table->paddr().get());
|
||||
#endif
|
||||
|
||||
pde.setPageTableBase(page_table->paddr().get());
|
||||
pde.set_page_table_base(page_table->paddr().get());
|
||||
pde.set_user_allowed(true);
|
||||
pde.set_present(true);
|
||||
pde.set_writable(true);
|
||||
page_directory.m_physical_pages.set(page_directory_index, move(page_table));
|
||||
}
|
||||
}
|
||||
return PageTableEntry(&pde.pageTableBase()[page_table_index]);
|
||||
return PageTableEntry(&pde.page_table_base()[page_table_index]);
|
||||
}
|
||||
|
||||
void MemoryManager::map_protected(LinearAddress laddr, size_t length)
|
||||
|
@ -176,13 +176,13 @@ void MemoryManager::map_protected(LinearAddress laddr, size_t length)
|
|||
InterruptDisabler disabler;
|
||||
// FIXME: ASSERT(linearAddress is 4KB aligned);
|
||||
for (dword offset = 0; offset < length; offset += PAGE_SIZE) {
|
||||
auto pteAddress = laddr.offset(offset);
|
||||
auto pte = ensure_pte(kernel_page_directory(), pteAddress);
|
||||
pte.set_physical_page_base(pteAddress.get());
|
||||
auto pte_address = laddr.offset(offset);
|
||||
auto pte = ensure_pte(kernel_page_directory(), pte_address);
|
||||
pte.set_physical_page_base(pte_address.get());
|
||||
pte.set_user_allowed(false);
|
||||
pte.set_present(false);
|
||||
pte.set_writable(false);
|
||||
flush_tlb(pteAddress);
|
||||
flush_tlb(pte_address);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,13 +191,13 @@ void MemoryManager::create_identity_mapping(PageDirectory& page_directory, Linea
|
|||
InterruptDisabler disabler;
|
||||
ASSERT((laddr.get() & ~PAGE_MASK) == 0);
|
||||
for (dword offset = 0; offset < size; offset += PAGE_SIZE) {
|
||||
auto pteAddress = laddr.offset(offset);
|
||||
auto pte = ensure_pte(page_directory, pteAddress);
|
||||
pte.set_physical_page_base(pteAddress.get());
|
||||
auto pte_address = laddr.offset(offset);
|
||||
auto pte = ensure_pte(page_directory, pte_address);
|
||||
pte.set_physical_page_base(pte_address.get());
|
||||
pte.set_user_allowed(false);
|
||||
pte.set_present(true);
|
||||
pte.set_writable(true);
|
||||
page_directory.flush(pteAddress);
|
||||
page_directory.flush(pte_address);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -560,7 +560,7 @@ RetainPtr<Region> Region::clone()
|
|||
|
||||
if (m_shared || (m_readable && !m_writable)) {
|
||||
// Create a new region backed by the same VMObject.
|
||||
return adopt(*new Region(laddr(), size(), m_vmo.copyRef(), m_offset_in_vmo, String(m_name), m_readable, m_writable));
|
||||
return adopt(*new Region(laddr(), size(), m_vmo.copy_ref(), m_offset_in_vmo, String(m_name), m_readable, m_writable));
|
||||
}
|
||||
|
||||
dbgprintf("%s<%u> Region::clone(): cowing %s (L%x)\n",
|
||||
|
@ -647,7 +647,7 @@ RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode, size_
|
|||
InterruptDisabler disabler;
|
||||
if (inode->vmo())
|
||||
return static_cast<VMObject*>(inode->vmo());
|
||||
size = ceilDiv(size, PAGE_SIZE) * PAGE_SIZE;
|
||||
size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
|
||||
auto vmo = adopt(*new VMObject(move(inode), size));
|
||||
vmo->inode()->set_vmo(vmo.ptr());
|
||||
return vmo;
|
||||
|
@ -655,13 +655,13 @@ RetainPtr<VMObject> VMObject::create_file_backed(RetainPtr<Inode>&& inode, size_
|
|||
|
||||
RetainPtr<VMObject> VMObject::create_anonymous(size_t size)
|
||||
{
|
||||
size = ceilDiv(size, PAGE_SIZE) * PAGE_SIZE;
|
||||
size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
|
||||
return adopt(*new VMObject(size));
|
||||
}
|
||||
|
||||
RetainPtr<VMObject> VMObject::create_framebuffer_wrapper(PhysicalAddress paddr, size_t size)
|
||||
{
|
||||
size = ceilDiv(size, PAGE_SIZE) * PAGE_SIZE;
|
||||
size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
|
||||
return adopt(*new VMObject(paddr, size));
|
||||
}
|
||||
|
||||
|
|
|
@ -264,8 +264,8 @@ private:
|
|||
struct PageDirectoryEntry {
|
||||
explicit PageDirectoryEntry(dword* pde) : m_pde(pde) { }
|
||||
|
||||
dword* pageTableBase() { return reinterpret_cast<dword*>(raw() & 0xfffff000u); }
|
||||
void setPageTableBase(dword value)
|
||||
dword* page_table_base() { return reinterpret_cast<dword*>(raw() & 0xfffff000u); }
|
||||
void set_page_table_base(dword value)
|
||||
{
|
||||
*m_pde &= 0xfff;
|
||||
*m_pde |= value & 0xfffff000;
|
||||
|
|
|
@ -90,7 +90,7 @@ void initialize()
|
|||
#endif
|
||||
}
|
||||
|
||||
word getISR()
|
||||
word get_isr()
|
||||
{
|
||||
IO::out8(PIC0_CTL, 0x0b);
|
||||
IO::out8(PIC1_CTL, 0x0b);
|
||||
|
|
|
@ -8,7 +8,7 @@ void enable(byte number);
|
|||
void disable(byte number);
|
||||
void eoi(byte number);
|
||||
void initialize();
|
||||
word getISR();
|
||||
word get_isr();
|
||||
word get_irr();
|
||||
|
||||
}
|
||||
|
|
|
@ -94,21 +94,21 @@ ByteBuffer procfs$pid_vmo(Process& process)
|
|||
ByteBuffer procfs$pid_stack(Process& process)
|
||||
{
|
||||
ProcessInspectionHandle handle(process);
|
||||
ProcessPagingScope pagingScope(process);
|
||||
ProcessPagingScope paging_scope(process);
|
||||
struct RecognizedSymbol {
|
||||
dword address;
|
||||
const KSym* ksym;
|
||||
};
|
||||
Vector<RecognizedSymbol> recognizedSymbols;
|
||||
if (auto* eipKsym = ksymbolicate(process.tss().eip))
|
||||
recognizedSymbols.append({ process.tss().eip, eipKsym });
|
||||
for (dword* stackPtr = (dword*)process.framePtr(); process.validate_read_from_kernel(LinearAddress((dword)stackPtr)); stackPtr = (dword*)*stackPtr) {
|
||||
dword retaddr = stackPtr[1];
|
||||
Vector<RecognizedSymbol> recognized_symbols;
|
||||
if (auto* eip_ksym = ksymbolicate(process.tss().eip))
|
||||
recognized_symbols.append({ process.tss().eip, eip_ksym });
|
||||
for (dword* stack_ptr = (dword*)process.frame_ptr(); process.validate_read_from_kernel(LinearAddress((dword)stack_ptr)); stack_ptr = (dword*)*stack_ptr) {
|
||||
dword retaddr = stack_ptr[1];
|
||||
if (auto* ksym = ksymbolicate(retaddr))
|
||||
recognizedSymbols.append({ retaddr, ksym });
|
||||
recognized_symbols.append({ retaddr, ksym });
|
||||
}
|
||||
StringBuilder builder;
|
||||
for (auto& symbol : recognizedSymbols) {
|
||||
for (auto& symbol : recognized_symbols) {
|
||||
unsigned offset = symbol.address - symbol.ksym->address;
|
||||
builder.appendf("%p %s +%u\n", symbol.address, symbol.ksym->name, offset);
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ ByteBuffer procfs$kmalloc(SynthFSInode&)
|
|||
ByteBuffer procfs$summary(SynthFSInode&)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
auto processes = Process::allProcesses();
|
||||
auto processes = Process::all_processes();
|
||||
StringBuilder builder;
|
||||
builder.appendf("PID TPG PGP SID OWNER STATE PPID NSCHED FDS TTY NAME\n");
|
||||
for (auto* process : processes) {
|
||||
|
@ -316,9 +316,9 @@ ByteBuffer procfs$summary(SynthFSInode&)
|
|||
process->pgid(),
|
||||
process->sid(),
|
||||
process->uid(),
|
||||
toString(process->state()),
|
||||
to_string(process->state()),
|
||||
process->ppid(),
|
||||
process->timesScheduled(),
|
||||
process->times_scheduled(),
|
||||
process->number_of_open_file_descriptors(),
|
||||
process->tty() ? strrchr(process->tty()->tty_name().characters(), '/') + 1 : "n/a",
|
||||
process->name().characters());
|
||||
|
|
|
@ -19,7 +19,6 @@ public:
|
|||
void remove_process(Process&);
|
||||
|
||||
void add_sys_file(String&&, Function<ByteBuffer(SynthFSInode&)>&& read_callback, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&& write_callback);
|
||||
|
||||
void add_sys_bool(String&&, bool*, Function<void()>&& change_callback = nullptr);
|
||||
|
||||
private:
|
||||
|
|
|
@ -27,22 +27,22 @@
|
|||
#define SIGNAL_DEBUG
|
||||
#define MAX_PROCESS_GIDS 32
|
||||
|
||||
static const dword defaultStackSize = 16384;
|
||||
static const dword default_stack_size = 16384;
|
||||
|
||||
static pid_t next_pid;
|
||||
InlineLinkedList<Process>* g_processes;
|
||||
static String* s_hostname;
|
||||
|
||||
static String& hostnameStorage(InterruptDisabler&)
|
||||
static String& hostname_storage(InterruptDisabler&)
|
||||
{
|
||||
ASSERT(s_hostname);
|
||||
return *s_hostname;
|
||||
}
|
||||
|
||||
static String getHostname()
|
||||
static String get_hostname()
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
return hostnameStorage(disabler).isolated_copy();
|
||||
return hostname_storage(disabler).isolated_copy();
|
||||
}
|
||||
|
||||
CoolGlobals* g_cool_globals;
|
||||
|
@ -59,7 +59,7 @@ void Process::initialize()
|
|||
initialize_gui_statics();
|
||||
}
|
||||
|
||||
Vector<Process*> Process::allProcesses()
|
||||
Vector<Process*> Process::all_processes()
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
Vector<Process*> processes;
|
||||
|
@ -74,8 +74,8 @@ Region* Process::allocate_region(LinearAddress laddr, size_t size, String&& name
|
|||
size = PAGE_ROUND_UP(size);
|
||||
// FIXME: This needs sanity checks. What if this overlaps existing regions?
|
||||
if (laddr.is_null()) {
|
||||
laddr = m_nextRegion;
|
||||
m_nextRegion = m_nextRegion.offset(size).offset(PAGE_SIZE);
|
||||
laddr = m_next_region;
|
||||
m_next_region = m_next_region.offset(size).offset(PAGE_SIZE);
|
||||
}
|
||||
laddr.mask(0xfffff000);
|
||||
m_regions.append(adopt(*new Region(laddr, size, move(name), is_readable, is_writable)));
|
||||
|
@ -90,8 +90,8 @@ Region* Process::allocate_file_backed_region(LinearAddress laddr, size_t size, R
|
|||
size = PAGE_ROUND_UP(size);
|
||||
// FIXME: This needs sanity checks. What if this overlaps existing regions?
|
||||
if (laddr.is_null()) {
|
||||
laddr = m_nextRegion;
|
||||
m_nextRegion = m_nextRegion.offset(size).offset(PAGE_SIZE);
|
||||
laddr = m_next_region;
|
||||
m_next_region = m_next_region.offset(size).offset(PAGE_SIZE);
|
||||
}
|
||||
laddr.mask(0xfffff000);
|
||||
m_regions.append(adopt(*new Region(laddr, size, move(inode), move(name), is_readable, is_writable)));
|
||||
|
@ -105,12 +105,12 @@ Region* Process::allocate_region_with_vmo(LinearAddress laddr, size_t size, Reta
|
|||
size = PAGE_ROUND_UP(size);
|
||||
// FIXME: This needs sanity checks. What if this overlaps existing regions?
|
||||
if (laddr.is_null()) {
|
||||
laddr = m_nextRegion;
|
||||
m_nextRegion = m_nextRegion.offset(size).offset(PAGE_SIZE);
|
||||
laddr = m_next_region;
|
||||
m_next_region = m_next_region.offset(size).offset(PAGE_SIZE);
|
||||
}
|
||||
laddr.mask(0xfffff000);
|
||||
offset_in_vmo &= PAGE_MASK;
|
||||
size = ceilDiv(size, PAGE_SIZE) * PAGE_SIZE;
|
||||
size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
|
||||
m_regions.append(adopt(*new Region(laddr, size, move(vmo), offset_in_vmo, move(name), is_readable, is_writable)));
|
||||
MM.map_region(*this, *m_regions.last());
|
||||
return m_regions.last().ptr();
|
||||
|
@ -129,7 +129,7 @@ bool Process::deallocate_region(Region& region)
|
|||
return false;
|
||||
}
|
||||
|
||||
Region* Process::regionFromRange(LinearAddress laddr, size_t size)
|
||||
Region* Process::region_from_range(LinearAddress laddr, size_t size)
|
||||
{
|
||||
for (auto& region : m_regions) {
|
||||
if (region->laddr() == laddr && region->size() == size)
|
||||
|
@ -142,7 +142,7 @@ int Process::sys$set_mmap_name(void* addr, size_t size, const char* name)
|
|||
{
|
||||
if (!validate_read_str(name))
|
||||
return -EFAULT;
|
||||
auto* region = regionFromRange(LinearAddress((dword)addr), size);
|
||||
auto* region = region_from_range(LinearAddress((dword)addr), size);
|
||||
if (!region)
|
||||
return -EINVAL;
|
||||
region->set_name(String(name));
|
||||
|
@ -193,7 +193,7 @@ void* Process::sys$mmap(const Syscall::SC_mmap_params* params)
|
|||
int Process::sys$munmap(void* addr, size_t size)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
auto* region = regionFromRange(LinearAddress((dword)addr), size);
|
||||
auto* region = region_from_range(LinearAddress((dword)addr), size);
|
||||
if (!region)
|
||||
return -1;
|
||||
if (!deallocate_region(*region))
|
||||
|
@ -205,7 +205,7 @@ int Process::sys$gethostname(char* buffer, size_t size)
|
|||
{
|
||||
if (!validate_write(buffer, size))
|
||||
return -EFAULT;
|
||||
auto hostname = getHostname();
|
||||
auto hostname = get_hostname();
|
||||
if (size < (hostname.length() + 1))
|
||||
return -ENAMETOOLONG;
|
||||
memcpy(buffer, hostname.characters(), size);
|
||||
|
@ -214,7 +214,7 @@ int Process::sys$gethostname(char* buffer, size_t size)
|
|||
|
||||
Process* Process::fork(RegisterDump& regs)
|
||||
{
|
||||
auto* child = new Process(String(m_name), m_uid, m_gid, m_pid, m_ring, m_cwd.copyRef(), m_executable.copyRef(), m_tty, this);
|
||||
auto* child = new Process(String(m_name), m_uid, m_gid, m_pid, m_ring, m_cwd.copy_ref(), m_executable.copy_ref(), m_tty, this);
|
||||
if (!child)
|
||||
return nullptr;
|
||||
|
||||
|
@ -235,7 +235,7 @@ Process* Process::fork(RegisterDump& regs)
|
|||
child->m_regions.append(move(cloned_region));
|
||||
MM.map_region(*child, *child->m_regions.last());
|
||||
if (region.ptr() == m_display_framebuffer_region.ptr())
|
||||
child->m_display_framebuffer_region = child->m_regions.last().copyRef();
|
||||
child->m_display_framebuffer_region = child->m_regions.last().copy_ref();
|
||||
}
|
||||
|
||||
for (auto gid : m_gids)
|
||||
|
@ -298,7 +298,7 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
|
|||
return error;
|
||||
}
|
||||
|
||||
if (!descriptor->metadata().mayExecute(m_euid, m_gids))
|
||||
if (!descriptor->metadata().may_execute(m_euid, m_gids))
|
||||
return -EACCES;
|
||||
|
||||
if (!descriptor->metadata().size) {
|
||||
|
@ -317,7 +317,7 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
|
|||
|
||||
auto vmo = VMObject::create_file_backed(descriptor->inode(), descriptor->metadata().size);
|
||||
vmo->set_name(descriptor->absolute_path());
|
||||
auto* region = allocate_region_with_vmo(LinearAddress(), descriptor->metadata().size, vmo.copyRef(), 0, "helper", true, false);
|
||||
auto* region = allocate_region_with_vmo(LinearAddress(), descriptor->metadata().size, vmo.copy_ref(), 0, "helper", true, false);
|
||||
|
||||
// FIXME: Should we consider doing on-demand paging here? Is it actually useful?
|
||||
bool success = region->page_in();
|
||||
|
@ -332,7 +332,7 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
|
|||
ASSERT(size);
|
||||
ASSERT(alignment == PAGE_SIZE);
|
||||
size = ((size / 4096) + 1) * 4096; // FIXME: Use ceil_div?
|
||||
(void) allocate_region_with_vmo(laddr, size, vmo.copyRef(), offset_in_image, String(name), is_readable, is_writable);
|
||||
(void) allocate_region_with_vmo(laddr, size, vmo.copy_ref(), offset_in_image, String(name), is_readable, is_writable);
|
||||
return laddr.as_ptr();
|
||||
};
|
||||
loader.alloc_section_hook = [&] (LinearAddress laddr, size_t size, size_t alignment, bool is_readable, bool is_writable, const String& name) {
|
||||
|
@ -400,10 +400,10 @@ int Process::do_exec(const String& path, Vector<String>&& arguments, Vector<Stri
|
|||
m_tss.gs = 0x23;
|
||||
m_tss.ss = 0x23;
|
||||
m_tss.cr3 = page_directory().cr3();
|
||||
m_stack_region = allocate_region(LinearAddress(), defaultStackSize, "stack");
|
||||
m_stack_region = allocate_region(LinearAddress(), default_stack_size, "stack");
|
||||
ASSERT(m_stack_region);
|
||||
m_stackTop3 = m_stack_region->laddr().offset(defaultStackSize).get();
|
||||
m_tss.esp = m_stackTop3;
|
||||
m_stack_top3 = m_stack_region->laddr().offset(default_stack_size).get();
|
||||
m_tss.esp = m_stack_top3;
|
||||
m_tss.ss0 = 0x10;
|
||||
m_tss.esp0 = old_esp0;
|
||||
m_tss.ss2 = m_pid;
|
||||
|
@ -490,7 +490,7 @@ Process* Process::create_user_process(const String& path, uid_t uid, gid_t gid,
|
|||
{
|
||||
InterruptDisabler disabler;
|
||||
if (auto* parent = Process::from_pid(parent_pid))
|
||||
cwd = parent->m_cwd.copyRef();
|
||||
cwd = parent->m_cwd.copy_ref();
|
||||
}
|
||||
|
||||
if (!cwd)
|
||||
|
@ -634,9 +634,9 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
|
|||
}
|
||||
|
||||
if (fork_parent)
|
||||
m_nextRegion = fork_parent->m_nextRegion;
|
||||
m_next_region = fork_parent->m_next_region;
|
||||
else
|
||||
m_nextRegion = LinearAddress(0x10000000);
|
||||
m_next_region = LinearAddress(0x10000000);
|
||||
|
||||
if (fork_parent) {
|
||||
memcpy(&m_tss, &fork_parent->m_tss, sizeof(m_tss));
|
||||
|
@ -647,7 +647,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
|
|||
m_tss.eflags = 0x0202;
|
||||
word cs, ds, ss;
|
||||
|
||||
if (isRing0()) {
|
||||
if (is_ring0()) {
|
||||
cs = 0x08;
|
||||
ds = 0x10;
|
||||
ss = 0x10;
|
||||
|
@ -667,34 +667,34 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
|
|||
|
||||
m_tss.cr3 = page_directory().cr3();
|
||||
|
||||
if (isRing0()) {
|
||||
if (is_ring0()) {
|
||||
// FIXME: This memory is leaked.
|
||||
// But uh, there's also no kernel process termination, so I guess it's not technically leaked...
|
||||
dword stackBottom = (dword)kmalloc_eternal(defaultStackSize);
|
||||
m_stackTop0 = (stackBottom + defaultStackSize) & 0xffffff8;
|
||||
m_tss.esp = m_stackTop0;
|
||||
dword stack_bottom = (dword)kmalloc_eternal(default_stack_size);
|
||||
m_stack_top0 = (stack_bottom + default_stack_size) & 0xffffff8;
|
||||
m_tss.esp = m_stack_top0;
|
||||
} else {
|
||||
if (fork_parent) {
|
||||
m_stackTop3 = fork_parent->m_stackTop3;
|
||||
m_stack_top3 = fork_parent->m_stack_top3;
|
||||
} else {
|
||||
auto* region = allocate_region(LinearAddress(), defaultStackSize, "stack");
|
||||
auto* region = allocate_region(LinearAddress(), default_stack_size, "stack");
|
||||
ASSERT(region);
|
||||
m_stackTop3 = region->laddr().offset(defaultStackSize).get();
|
||||
m_tss.esp = m_stackTop3;
|
||||
m_stack_top3 = region->laddr().offset(default_stack_size).get();
|
||||
m_tss.esp = m_stack_top3;
|
||||
}
|
||||
}
|
||||
|
||||
if (isRing3()) {
|
||||
if (is_ring3()) {
|
||||
// Ring3 processes need a separate stack for Ring0.
|
||||
m_kernelStack = kmalloc(defaultStackSize);
|
||||
m_stackTop0 = ((dword)m_kernelStack + defaultStackSize) & 0xffffff8;
|
||||
m_kernel_stack = kmalloc(default_stack_size);
|
||||
m_stack_top0 = ((dword)m_kernel_stack + default_stack_size) & 0xffffff8;
|
||||
m_tss.ss0 = 0x10;
|
||||
m_tss.esp0 = m_stackTop0;
|
||||
m_tss.esp0 = m_stack_top0;
|
||||
}
|
||||
|
||||
// HACK: Ring2 SS in the TSS is the current PID.
|
||||
m_tss.ss2 = m_pid;
|
||||
m_farPtr.offset = 0x98765432;
|
||||
m_far_ptr.offset = 0x98765432;
|
||||
}
|
||||
|
||||
Process::~Process()
|
||||
|
@ -709,13 +709,13 @@ Process::~Process()
|
|||
if (selector())
|
||||
gdt_free_entry(selector());
|
||||
|
||||
if (m_kernelStack) {
|
||||
kfree(m_kernelStack);
|
||||
m_kernelStack = nullptr;
|
||||
if (m_kernel_stack) {
|
||||
kfree(m_kernel_stack);
|
||||
m_kernel_stack = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Process::dumpRegions()
|
||||
void Process::dump_regions()
|
||||
{
|
||||
kprintf("Process %s(%u) regions:\n", name().characters(), pid());
|
||||
kprintf("BEGIN END SIZE NAME\n");
|
||||
|
@ -818,7 +818,7 @@ bool Process::dispatch_signal(byte signal)
|
|||
|
||||
bool interrupting_in_kernel = (ret_cs & 3) == 0;
|
||||
if (interrupting_in_kernel) {
|
||||
dbgprintf("dispatch_signal to %s(%u) in state=%s with return to %w:%x\n", name().characters(), pid(), toString(state()), ret_cs, ret_eip);
|
||||
dbgprintf("dispatch_signal to %s(%u) in state=%s with return to %w:%x\n", name().characters(), pid(), to_string(state()), ret_cs, ret_eip);
|
||||
ASSERT(is_blocked());
|
||||
m_tss_to_resume_kernel = m_tss;
|
||||
#ifdef SIGNAL_DEBUG
|
||||
|
@ -826,19 +826,19 @@ bool Process::dispatch_signal(byte signal)
|
|||
#endif
|
||||
}
|
||||
|
||||
ProcessPagingScope pagingScope(*this);
|
||||
ProcessPagingScope paging_scope(*this);
|
||||
|
||||
if (interrupting_in_kernel) {
|
||||
if (!m_signal_stack_user_region) {
|
||||
m_signal_stack_user_region = allocate_region(LinearAddress(), defaultStackSize, "signal stack (user)");
|
||||
m_signal_stack_user_region = allocate_region(LinearAddress(), default_stack_size, "signal stack (user)");
|
||||
ASSERT(m_signal_stack_user_region);
|
||||
m_signal_stack_kernel_region = allocate_region(LinearAddress(), defaultStackSize, "signal stack (kernel)");
|
||||
m_signal_stack_kernel_region = allocate_region(LinearAddress(), default_stack_size, "signal stack (kernel)");
|
||||
ASSERT(m_signal_stack_user_region);
|
||||
}
|
||||
m_tss.ss = 0x23;
|
||||
m_tss.esp = m_signal_stack_user_region->laddr().offset(defaultStackSize).get() & 0xfffffff8;
|
||||
m_tss.esp = m_signal_stack_user_region->laddr().offset(default_stack_size).get() & 0xfffffff8;
|
||||
m_tss.ss0 = 0x10;
|
||||
m_tss.esp0 = m_signal_stack_kernel_region->laddr().offset(defaultStackSize).get() & 0xfffffff8;
|
||||
m_tss.esp0 = m_signal_stack_kernel_region->laddr().offset(default_stack_size).get() & 0xfffffff8;
|
||||
push_value_on_stack(ret_eflags);
|
||||
push_value_on_stack(ret_cs);
|
||||
push_value_on_stack(ret_eip);
|
||||
|
@ -903,7 +903,7 @@ bool Process::dispatch_signal(byte signal)
|
|||
set_state(Skip1SchedulerPass);
|
||||
|
||||
#ifdef SIGNAL_DEBUG
|
||||
dbgprintf("signal: Okay, %s(%u) {%s} has been primed with signal handler %w:%x\n", name().characters(), pid(), toString(state()), m_tss.cs, m_tss.eip);
|
||||
dbgprintf("signal: Okay, %s(%u) {%s} has been primed with signal handler %w:%x\n", name().characters(), pid(), to_string(state()), m_tss.cs, m_tss.eip);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -935,7 +935,7 @@ void Process::crash()
|
|||
ASSERT_INTERRUPTS_DISABLED();
|
||||
ASSERT(state() != Dead);
|
||||
m_termination_signal = SIGSEGV;
|
||||
dumpRegions();
|
||||
dump_regions();
|
||||
die();
|
||||
Scheduler::pick_next_and_switch_now();
|
||||
ASSERT_NOT_REACHED();
|
||||
|
@ -996,10 +996,10 @@ int Process::sys$ttyname_r(int fd, char* buffer, size_t size)
|
|||
return -EBADF;
|
||||
if (!descriptor->is_tty())
|
||||
return -ENOTTY;
|
||||
auto ttyName = descriptor->tty()->tty_name();
|
||||
if (size < ttyName.length() + 1)
|
||||
auto tty_name = descriptor->tty()->tty_name();
|
||||
if (size < tty_name.length() + 1)
|
||||
return -ERANGE;
|
||||
strcpy(buffer, ttyName.characters());
|
||||
strcpy(buffer, tty_name.characters());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1246,7 +1246,7 @@ int Process::sys$readlink(const char* path, char* buffer, size_t size)
|
|||
if (!descriptor)
|
||||
return error;
|
||||
|
||||
if (!descriptor->metadata().isSymbolicLink())
|
||||
if (!descriptor->metadata().is_symlink())
|
||||
return -EINVAL;
|
||||
|
||||
auto contents = descriptor->read_entire_file(*this);
|
||||
|
@ -1389,7 +1389,7 @@ int Process::sys$uname(utsname* buf)
|
|||
strcpy(buf->release, "1.0-dev");
|
||||
strcpy(buf->version, "FIXME");
|
||||
strcpy(buf->machine, "i386");
|
||||
strcpy(buf->nodename, getHostname().characters());
|
||||
strcpy(buf->nodename, get_hostname().characters());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1427,9 +1427,9 @@ int Process::sys$sleep(unsigned seconds)
|
|||
if (!seconds)
|
||||
return 0;
|
||||
sleep(seconds * TICKS_PER_SECOND);
|
||||
if (m_wakeupTime > system.uptime) {
|
||||
if (m_wakeup_time > system.uptime) {
|
||||
ASSERT(m_was_interrupted_while_blocked);
|
||||
dword ticks_left_until_original_wakeup_time = m_wakeupTime - system.uptime;
|
||||
dword ticks_left_until_original_wakeup_time = m_wakeup_time - system.uptime;
|
||||
return ticks_left_until_original_wakeup_time / TICKS_PER_SECOND;
|
||||
}
|
||||
return 0;
|
||||
|
@ -1496,7 +1496,7 @@ int Process::reap(Process& process)
|
|||
}
|
||||
}
|
||||
|
||||
dbgprintf("reap: %s(%u) {%s}\n", process.name().characters(), process.pid(), toString(process.state()));
|
||||
dbgprintf("reap: %s(%u) {%s}\n", process.name().characters(), process.pid(), to_string(process.state()));
|
||||
ASSERT(process.state() == Dead);
|
||||
g_processes->remove(&process);
|
||||
delete &process;
|
||||
|
@ -1576,7 +1576,7 @@ void Process::unblock()
|
|||
void Process::block(Process::State new_state)
|
||||
{
|
||||
if (state() != Process::Running) {
|
||||
kprintf("Process::block: %s(%u) block(%u/%s) with state=%u/%s\n", name().characters(), pid(), new_state, toString(new_state), state(), toString(state()));
|
||||
kprintf("Process::block: %s(%u) block(%u/%s) with state=%u/%s\n", name().characters(), pid(), new_state, to_string(new_state), state(), to_string(state()));
|
||||
}
|
||||
ASSERT(state() == Process::Running);
|
||||
system.nblocked++;
|
||||
|
@ -1593,7 +1593,7 @@ void block(Process::State state)
|
|||
void sleep(dword ticks)
|
||||
{
|
||||
ASSERT(current->state() == Process::Running);
|
||||
current->setWakeupTime(system.uptime + ticks);
|
||||
current->set_wakeup_time(system.uptime + ticks);
|
||||
current->block(Process::BlockedSleep);
|
||||
sched_yield();
|
||||
}
|
||||
|
@ -1619,7 +1619,7 @@ bool Process::validate_read_from_kernel(LinearAddress laddr) const
|
|||
|
||||
bool Process::validate_read(const void* address, size_t size) const
|
||||
{
|
||||
if (isRing0()) {
|
||||
if (is_ring0()) {
|
||||
if (is_inside_kernel_code(LinearAddress((dword)address)))
|
||||
return true;
|
||||
if (is_kmalloc_address(address))
|
||||
|
@ -1639,7 +1639,7 @@ bool Process::validate_read(const void* address, size_t size) const
|
|||
|
||||
bool Process::validate_write(void* address, size_t size) const
|
||||
{
|
||||
if (isRing0()) {
|
||||
if (is_ring0()) {
|
||||
if (is_kmalloc_address(address))
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
static Process* create_user_process(const String& path, uid_t, gid_t, pid_t ppid, int& error, Vector<String>&& arguments = Vector<String>(), Vector<String>&& environment = Vector<String>(), TTY* = nullptr);
|
||||
~Process();
|
||||
|
||||
static Vector<Process*> allProcesses();
|
||||
static Vector<Process*> all_processes();
|
||||
|
||||
enum State {
|
||||
Invalid = 0,
|
||||
|
@ -78,8 +78,8 @@ public:
|
|||
Ring3 = 3,
|
||||
};
|
||||
|
||||
bool isRing0() const { return m_ring == Ring0; }
|
||||
bool isRing3() const { return m_ring == Ring3; }
|
||||
bool is_ring0() const { return m_ring == Ring0; }
|
||||
bool is_ring3() const { return m_ring == Ring3; }
|
||||
|
||||
bool is_blocked() const
|
||||
{
|
||||
|
@ -98,7 +98,7 @@ public:
|
|||
pid_t sid() const { return m_sid; }
|
||||
pid_t pgid() const { return m_pgid; }
|
||||
dword ticks() const { return m_ticks; }
|
||||
word selector() const { return m_farPtr.selector; }
|
||||
word selector() const { return m_far_ptr.selector; }
|
||||
TSS32& tss() { return m_tss; }
|
||||
State state() const { return m_state; }
|
||||
uid_t uid() const { return m_uid; }
|
||||
|
@ -107,7 +107,7 @@ public:
|
|||
gid_t egid() const { return m_egid; }
|
||||
pid_t ppid() const { return m_ppid; }
|
||||
|
||||
const FarPtr& farPtr() const { return m_farPtr; }
|
||||
const FarPtr& far_ptr() const { return m_far_ptr; }
|
||||
|
||||
FileDescriptor* file_descriptor(int fd);
|
||||
const FileDescriptor* file_descriptor(int fd) const;
|
||||
|
@ -115,8 +115,8 @@ public:
|
|||
void block(Process::State);
|
||||
void unblock();
|
||||
|
||||
void setWakeupTime(dword t) { m_wakeupTime = t; }
|
||||
dword wakeupTime() const { return m_wakeupTime; }
|
||||
void set_wakeup_time(dword t) { m_wakeup_time = t; }
|
||||
dword wakeup_time() const { return m_wakeup_time; }
|
||||
|
||||
template<typename Callback> static void for_each(Callback);
|
||||
template<typename Callback> static void for_each_in_pgrp(pid_t, Callback);
|
||||
|
@ -124,10 +124,10 @@ public:
|
|||
template<typename Callback> static void for_each_not_in_state(State, Callback);
|
||||
template<typename Callback> void for_each_child(Callback);
|
||||
|
||||
bool tick() { ++m_ticks; return --m_ticksLeft; }
|
||||
void set_ticks_left(dword t) { m_ticksLeft = t; }
|
||||
bool tick() { ++m_ticks; return --m_ticks_left; }
|
||||
void set_ticks_left(dword t) { m_ticks_left = t; }
|
||||
|
||||
void setSelector(word s) { m_farPtr.selector = s; }
|
||||
void set_selector(word s) { m_far_ptr.selector = s; }
|
||||
void set_state(State s) { m_state = s; }
|
||||
void die();
|
||||
|
||||
|
@ -225,12 +225,12 @@ public:
|
|||
const TTY* tty() const { return m_tty; }
|
||||
void set_tty(TTY* tty) { m_tty = tty; }
|
||||
|
||||
size_t regionCount() const { return m_regions.size(); }
|
||||
size_t region_count() const { return m_regions.size(); }
|
||||
const Vector<RetainPtr<Region>>& regions() const { return m_regions; }
|
||||
void dumpRegions();
|
||||
void dump_regions();
|
||||
|
||||
void did_schedule() { ++m_timesScheduled; }
|
||||
dword timesScheduled() const { return m_timesScheduled; }
|
||||
void did_schedule() { ++m_times_scheduled; }
|
||||
dword times_scheduled() const { return m_times_scheduled; }
|
||||
|
||||
dword m_ticks_in_user { 0 };
|
||||
dword m_ticks_in_kernel { 0 };
|
||||
|
@ -240,9 +240,9 @@ public:
|
|||
|
||||
pid_t waitee_pid() const { return m_waitee_pid; }
|
||||
|
||||
dword framePtr() const { return m_tss.ebp; }
|
||||
dword stackPtr() const { return m_tss.esp; }
|
||||
dword stackTop() const { return m_tss.ss == 0x10 ? m_stackTop0 : m_stackTop3; }
|
||||
dword frame_ptr() const { return m_tss.ebp; }
|
||||
dword stack_ptr() const { return m_tss.esp; }
|
||||
dword stack_top() const { return m_tss.ss == 0x10 ? m_stack_top0 : m_stack_top3; }
|
||||
|
||||
bool validate_read_from_kernel(LinearAddress) const;
|
||||
|
||||
|
@ -306,12 +306,12 @@ private:
|
|||
pid_t m_sid { 0 };
|
||||
pid_t m_pgid { 0 };
|
||||
dword m_ticks { 0 };
|
||||
dword m_ticksLeft { 0 };
|
||||
dword m_stackTop0 { 0 };
|
||||
dword m_stackTop3 { 0 };
|
||||
FarPtr m_farPtr;
|
||||
dword m_ticks_left { 0 };
|
||||
dword m_stack_top0 { 0 };
|
||||
dword m_stack_top3 { 0 };
|
||||
FarPtr m_far_ptr;
|
||||
State m_state { Invalid };
|
||||
dword m_wakeupTime { 0 };
|
||||
dword m_wakeup_time { 0 };
|
||||
TSS32 m_tss;
|
||||
TSS32 m_tss_to_resume_kernel;
|
||||
FPUState m_fpu_state;
|
||||
|
@ -325,8 +325,8 @@ private:
|
|||
Vector<FileDescriptorAndFlags> m_fds;
|
||||
RingLevel m_ring { Ring0 };
|
||||
int m_error { 0 };
|
||||
void* m_kernelStack { nullptr };
|
||||
dword m_timesScheduled { 0 };
|
||||
void* m_kernel_stack { nullptr };
|
||||
dword m_times_scheduled { 0 };
|
||||
pid_t m_waitee_pid { -1 };
|
||||
int m_blocked_fd { -1 };
|
||||
Vector<int> m_select_read_fds;
|
||||
|
@ -349,12 +349,12 @@ private:
|
|||
Region* allocate_region_with_vmo(LinearAddress, size_t, RetainPtr<VMObject>&&, size_t offset_in_vmo, String&& name, bool is_readable, bool is_writable);
|
||||
bool deallocate_region(Region& region);
|
||||
|
||||
Region* regionFromRange(LinearAddress, size_t);
|
||||
Region* region_from_range(LinearAddress, size_t);
|
||||
|
||||
Vector<RetainPtr<Region>> m_regions;
|
||||
|
||||
// FIXME: Implement some kind of ASLR?
|
||||
LinearAddress m_nextRegion;
|
||||
LinearAddress m_next_region;
|
||||
|
||||
LinearAddress m_return_to_ring3_from_signal_trampoline;
|
||||
LinearAddress m_return_to_ring0_from_signal_trampoline;
|
||||
|
@ -411,7 +411,7 @@ private:
|
|||
Process::State m_original_state { Process::Invalid };
|
||||
};
|
||||
|
||||
static inline const char* toString(Process::State state)
|
||||
static inline const char* to_string(Process::State state)
|
||||
{
|
||||
switch (state) {
|
||||
case Process::Invalid: return "Invalid";
|
||||
|
|
|
@ -81,7 +81,7 @@ int Process::gui$destroy_window(int window_id)
|
|||
if (it == m_windows.end())
|
||||
return -EBADWINDOW;
|
||||
auto message = make<WSMessage>(WSMessage::WM_DestroyWindow);
|
||||
WSMessageLoop::the().post_message((*it).value.leakPtr(), move(message), true);
|
||||
WSMessageLoop::the().post_message((*it).value.leak_ptr(), move(message), true);
|
||||
m_windows.remove(window_id);
|
||||
return 0;
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ void Process::destroy_all_windows()
|
|||
{
|
||||
for (auto& it : m_windows) {
|
||||
auto message = make<WSMessage>(WSMessage::WM_DestroyWindow);
|
||||
WSMessageLoop::the().post_message(it.value.leakPtr(), move(message), true);
|
||||
WSMessageLoop::the().post_message(it.value.leak_ptr(), move(message), true);
|
||||
}
|
||||
m_windows.clear();
|
||||
}
|
||||
|
|
|
@ -18,21 +18,21 @@ public:
|
|||
Queue() { }
|
||||
~Queue()
|
||||
{
|
||||
while (!isEmpty())
|
||||
while (!is_empty())
|
||||
dequeue();
|
||||
}
|
||||
|
||||
bool isEmpty() const { return !m_head; }
|
||||
bool is_empty() const { return !m_head; }
|
||||
void enqueue(T&& item)
|
||||
{
|
||||
auto* newNode = new Node(move(item));
|
||||
auto* new_node = new Node(move(item));
|
||||
if (!m_head) {
|
||||
m_head = newNode;
|
||||
m_tail = newNode;
|
||||
m_head = new_node;
|
||||
m_tail = new_node;
|
||||
} else if (m_tail) {
|
||||
newNode->prev = m_tail;
|
||||
m_tail->next = newNode;
|
||||
m_tail = newNode;
|
||||
new_node->prev = m_tail;
|
||||
m_tail->next = new_node;
|
||||
m_tail = new_node;
|
||||
}
|
||||
dump("enqueue");
|
||||
}
|
||||
|
|
|
@ -4,34 +4,34 @@
|
|||
|
||||
namespace RTC {
|
||||
|
||||
static time_t s_bootTime;
|
||||
static time_t s_boot_time;
|
||||
|
||||
void initialize()
|
||||
{
|
||||
byte cmosMode = CMOS::read(0x0b);
|
||||
cmosMode |= 2; // 24 hour mode
|
||||
cmosMode |= 4; // No BCD mode
|
||||
CMOS::write(0x0b, cmosMode);
|
||||
byte cmos_mode = CMOS::read(0x0b);
|
||||
cmos_mode |= 2; // 24 hour mode
|
||||
cmos_mode |= 4; // No BCD mode
|
||||
CMOS::write(0x0b, cmos_mode);
|
||||
|
||||
s_bootTime = now();
|
||||
s_boot_time = now();
|
||||
}
|
||||
|
||||
time_t bootTime()
|
||||
time_t boot_time()
|
||||
{
|
||||
return s_bootTime;
|
||||
return s_boot_time;
|
||||
}
|
||||
|
||||
static bool updateInProgress()
|
||||
static bool update_in_progress()
|
||||
{
|
||||
return CMOS::read(0x0a) & 0x80;
|
||||
}
|
||||
|
||||
inline bool isLeapYear(unsigned year)
|
||||
inline bool is_leap_year(unsigned year)
|
||||
{
|
||||
return ((year % 4 == 0) && ((year % 100 != 0) || (year % 400) == 0));
|
||||
}
|
||||
|
||||
static unsigned daysInMonthsSinceStartOfYear(unsigned month, unsigned year)
|
||||
static unsigned days_in_months_since_start_of_year(unsigned month, unsigned year)
|
||||
{
|
||||
switch (month) {
|
||||
case 11: return 30;
|
||||
|
@ -44,7 +44,7 @@ static unsigned daysInMonthsSinceStartOfYear(unsigned month, unsigned year)
|
|||
case 4: return 30;
|
||||
case 3: return 31;
|
||||
case 2:
|
||||
if (isLeapYear(year))
|
||||
if (is_leap_year(year))
|
||||
return 29;
|
||||
return 28;
|
||||
case 1: return 31;
|
||||
|
@ -52,12 +52,12 @@ static unsigned daysInMonthsSinceStartOfYear(unsigned month, unsigned year)
|
|||
}
|
||||
}
|
||||
|
||||
static unsigned daysInYearsSinceEpoch(unsigned year)
|
||||
static unsigned days_in_years_since_epoch(unsigned year)
|
||||
{
|
||||
unsigned days = 0;
|
||||
while (year > 1969) {
|
||||
days += 365;
|
||||
if (isLeapYear(year))
|
||||
if (is_leap_year(year))
|
||||
++days;
|
||||
--year;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ time_t now()
|
|||
// FIXME: We should probably do something more robust here.
|
||||
// Perhaps read all the values twice and verify that they were identical.
|
||||
// We don't want to be caught in the middle of an RTC register update.
|
||||
while (updateInProgress())
|
||||
while (update_in_progress())
|
||||
;
|
||||
|
||||
unsigned year = (CMOS::read(0x32) * 100) + CMOS::read(0x09);
|
||||
|
@ -81,8 +81,8 @@ time_t now()
|
|||
|
||||
ASSERT(year >= 2018);
|
||||
|
||||
return daysInYearsSinceEpoch(year - 1) * 86400
|
||||
+ daysInMonthsSinceStartOfYear(month - 1, year) * 86400
|
||||
return days_in_years_since_epoch(year - 1) * 86400
|
||||
+ days_in_months_since_start_of_year(month - 1, year) * 86400
|
||||
+ day * 86400
|
||||
+ hour * 3600
|
||||
+ minute * 60
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace RTC {
|
|||
|
||||
void initialize();
|
||||
time_t now();
|
||||
time_t bootTime();
|
||||
time_t boot_time();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ bool Scheduler::pick_next()
|
|||
// Check and unblock processes whose wait conditions have been met.
|
||||
Process::for_each([] (auto& process) {
|
||||
if (process.state() == Process::BlockedSleep) {
|
||||
if (process.wakeupTime() <= system.uptime)
|
||||
if (process.wakeup_time() <= system.uptime)
|
||||
process.unblock();
|
||||
return true;
|
||||
}
|
||||
|
@ -139,11 +139,11 @@ bool Scheduler::pick_next()
|
|||
for (auto* process = g_processes->head(); process; process = process->next()) {
|
||||
//if (process->state() == Process::BlockedWait || process->state() == Process::BlockedSleep)
|
||||
// continue;
|
||||
dbgprintf("[K%x] % 12s %s(%u) @ %w:%x\n", process, toString(process->state()), process->name().characters(), process->pid(), process->tss().cs, process->tss().eip);
|
||||
dbgprintf("[K%x] % 12s %s(%u) @ %w:%x\n", process, to_string(process->state()), process->name().characters(), process->pid(), process->tss().cs, process->tss().eip);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto* prevHead = g_processes->head();
|
||||
auto* previous_head = g_processes->head();
|
||||
for (;;) {
|
||||
// Move head to tail.
|
||||
g_processes->append(g_processes->remove_head());
|
||||
|
@ -156,7 +156,7 @@ bool Scheduler::pick_next()
|
|||
return context_switch(*process);
|
||||
}
|
||||
|
||||
if (process == prevHead) {
|
||||
if (process == previous_head) {
|
||||
// Back at process_head, nothing wants to run. Send in the colonel!
|
||||
return context_switch(*s_colonel_process);
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ bool Scheduler::yield()
|
|||
}
|
||||
|
||||
s_in_yield = false;
|
||||
//dbgprintf("yield() jumping to new process: %x (%s)\n", current->farPtr().selector, current->name().characters());
|
||||
//dbgprintf("yield() jumping to new process: %x (%s)\n", current->far_ptr().selector, current->name().characters());
|
||||
switch_now();
|
||||
return 0;
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ void Scheduler::switch_now()
|
|||
flush_gdt();
|
||||
asm("sti\n"
|
||||
"ljmp *(%%eax)\n"
|
||||
::"a"(¤t->farPtr())
|
||||
::"a"(¤t->far_ptr())
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -238,10 +238,10 @@ bool Scheduler::context_switch(Process& process)
|
|||
#endif
|
||||
|
||||
if (!process.selector()) {
|
||||
process.setSelector(gdt_alloc_entry());
|
||||
process.set_selector(gdt_alloc_entry());
|
||||
auto& descriptor = get_gdt_entry(process.selector());
|
||||
descriptor.setBase(&process.tss());
|
||||
descriptor.setLimit(0xffff);
|
||||
descriptor.set_base(&process.tss());
|
||||
descriptor.set_limit(0xffff);
|
||||
descriptor.dpl = 0;
|
||||
descriptor.segment_present = 1;
|
||||
descriptor.granularity = 1;
|
||||
|
@ -264,8 +264,8 @@ int sched_yield()
|
|||
static void initialize_redirection()
|
||||
{
|
||||
auto& descriptor = get_gdt_entry(s_redirection.selector);
|
||||
descriptor.setBase(&s_redirection.tss);
|
||||
descriptor.setLimit(0xffff);
|
||||
descriptor.set_base(&s_redirection.tss);
|
||||
descriptor.set_limit(0xffff);
|
||||
descriptor.dpl = 0;
|
||||
descriptor.segment_present = 1;
|
||||
descriptor.granularity = 1;
|
||||
|
|
|
@ -202,18 +202,18 @@ ssize_t SynthFSInode::read_bytes(off_t offset, size_t count, byte* buffer, FileD
|
|||
ASSERT(offset >= 0);
|
||||
ASSERT(buffer);
|
||||
|
||||
ByteBuffer generatedData;
|
||||
ByteBuffer generated_data;
|
||||
if (m_generator) {
|
||||
if (!descriptor) {
|
||||
generatedData = m_generator(const_cast<SynthFSInode&>(*this));
|
||||
generated_data = m_generator(const_cast<SynthFSInode&>(*this));
|
||||
} else {
|
||||
if (!descriptor->generator_cache())
|
||||
descriptor->generator_cache() = m_generator(const_cast<SynthFSInode&>(*this));
|
||||
generatedData = descriptor->generator_cache();
|
||||
generated_data = descriptor->generator_cache();
|
||||
}
|
||||
}
|
||||
|
||||
auto* data = generatedData ? &generatedData : &m_data;
|
||||
auto* data = generated_data ? &generated_data : &m_data;
|
||||
ssize_t nread = min(static_cast<off_t>(data->size() - offset), static_cast<off_t>(count));
|
||||
memcpy(buffer, data->pointer() + offset, nread);
|
||||
if (nread == 0 && descriptor && descriptor->generator_cache())
|
||||
|
@ -228,14 +228,14 @@ bool SynthFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&
|
|||
kprintf("SynthFS: traverse_as_directory %u\n", index());
|
||||
#endif
|
||||
|
||||
if (!m_metadata.isDirectory())
|
||||
if (!m_metadata.is_directory())
|
||||
return false;
|
||||
|
||||
callback({ ".", 1, m_metadata.inode, 2 });
|
||||
callback({ "..", 2, m_parent, 2 });
|
||||
|
||||
for (auto& child : m_children)
|
||||
callback({ child->m_name.characters(), child->m_name.length(), child->m_metadata.inode, child->m_metadata.isDirectory() ? (byte)2 : (byte)1 });
|
||||
callback({ child->m_name.characters(), child->m_name.length(), child->m_metadata.inode, child->m_metadata.is_directory() ? (byte)2 : (byte)1 });
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
#include "Console.h"
|
||||
#include "Scheduler.h"
|
||||
|
||||
extern "C" void syscall_entry(RegisterDump&);
|
||||
extern "C" void syscall_ISR();
|
||||
extern "C" void syscall_trap_entry(RegisterDump&);
|
||||
extern "C" void syscall_trap_handler();
|
||||
extern volatile RegisterDump* syscallRegDump;
|
||||
|
||||
asm(
|
||||
".globl syscall_ISR \n"
|
||||
"syscall_ISR:\n"
|
||||
".globl syscall_trap_handler \n"
|
||||
"syscall_trap_handler:\n"
|
||||
" pusha\n"
|
||||
" pushw %ds\n"
|
||||
" pushw %es\n"
|
||||
|
@ -26,7 +26,7 @@ asm(
|
|||
" popw %fs\n"
|
||||
" popw %gs\n"
|
||||
" mov %esp, %eax\n"
|
||||
" call syscall_entry\n"
|
||||
" call syscall_trap_entry\n"
|
||||
" popw %gs\n"
|
||||
" popw %gs\n"
|
||||
" popw %fs\n"
|
||||
|
@ -40,7 +40,7 @@ namespace Syscall {
|
|||
|
||||
void initialize()
|
||||
{
|
||||
register_user_callable_interrupt_handler(0x80, syscall_ISR);
|
||||
register_user_callable_interrupt_handler(0x80, syscall_trap_handler);
|
||||
kprintf("syscall: int 0x80 handler installed\n");
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
|
|||
|
||||
}
|
||||
|
||||
void syscall_entry(RegisterDump& regs)
|
||||
void syscall_trap_entry(RegisterDump& regs)
|
||||
{
|
||||
dword function = regs.eax;
|
||||
dword arg1 = regs.edx;
|
||||
|
|
|
@ -99,7 +99,7 @@ enum Function {
|
|||
#undef __ENUMERATE_SYSCALL
|
||||
};
|
||||
|
||||
inline constexpr const char* toString(Function function)
|
||||
inline constexpr const char* to_string(Function function)
|
||||
{
|
||||
switch (function) {
|
||||
#undef __ENUMERATE_SYSCALL
|
||||
|
|
|
@ -88,7 +88,7 @@ void VirtualConsole::switch_to(unsigned index)
|
|||
s_consoles[s_active_console]->set_active(false);
|
||||
s_active_console = index;
|
||||
s_consoles[s_active_console]->set_active(true);
|
||||
Console::the().setImplementation(s_consoles[s_active_console]);
|
||||
Console::the().set_implementation(s_consoles[s_active_console]);
|
||||
}
|
||||
|
||||
void VirtualConsole::set_active(bool b)
|
||||
|
@ -128,7 +128,7 @@ inline bool is_valid_final_character(byte ch)
|
|||
return ch >= 0x40 && ch <= 0x7e;
|
||||
}
|
||||
|
||||
unsigned parseUInt(const String& str, bool& ok)
|
||||
unsigned parse_uint(const String& str, bool& ok)
|
||||
{
|
||||
unsigned value = 0;
|
||||
for (size_t i = 0; i < str.length(); ++i) {
|
||||
|
@ -302,11 +302,11 @@ void VirtualConsole::escape$J(const Vector<unsigned>& params)
|
|||
switch (mode) {
|
||||
case 0:
|
||||
// FIXME: Clear from cursor to end of screen.
|
||||
notImplemented();
|
||||
not_implemented();
|
||||
break;
|
||||
case 1:
|
||||
// FIXME: Clear from cursor to beginning of screen.
|
||||
notImplemented();
|
||||
not_implemented();
|
||||
break;
|
||||
case 2:
|
||||
clear();
|
||||
|
@ -324,7 +324,7 @@ void VirtualConsole::execute_escape_sequence(byte final)
|
|||
Vector<unsigned> params;
|
||||
for (auto& parampart : paramparts) {
|
||||
bool ok;
|
||||
unsigned value = parseUInt(parampart, ok);
|
||||
unsigned value = parse_uint(parampart, ok);
|
||||
if (!ok) {
|
||||
// FIXME: Should we do something else?
|
||||
return;
|
||||
|
|
|
@ -43,9 +43,9 @@ InodeIdentifier VFS::root_inode_id() const
|
|||
return m_root_inode->identifier();
|
||||
}
|
||||
|
||||
bool VFS::mount(RetainPtr<FS>&& fileSystem, const String& path)
|
||||
bool VFS::mount(RetainPtr<FS>&& file_system, const String& path)
|
||||
{
|
||||
ASSERT(fileSystem);
|
||||
ASSERT(file_system);
|
||||
int error;
|
||||
auto inode = resolve_path(path, root_inode_id(), error);
|
||||
if (!inode.is_valid()) {
|
||||
|
@ -53,21 +53,21 @@ bool VFS::mount(RetainPtr<FS>&& fileSystem, const String& path)
|
|||
return false;
|
||||
}
|
||||
|
||||
kprintf("VFS: mounting %s{%p} at %s (inode: %u)\n", fileSystem->class_name(), fileSystem.ptr(), path.characters(), inode.index());
|
||||
kprintf("VFS: mounting %s{%p} at %s (inode: %u)\n", file_system->class_name(), file_system.ptr(), path.characters(), inode.index());
|
||||
// FIXME: check that this is not already a mount point
|
||||
auto mount = make<Mount>(inode, move(fileSystem));
|
||||
auto mount = make<Mount>(inode, move(file_system));
|
||||
m_mounts.append(move(mount));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VFS::mount_root(RetainPtr<FS>&& fileSystem)
|
||||
bool VFS::mount_root(RetainPtr<FS>&& file_system)
|
||||
{
|
||||
if (m_root_inode) {
|
||||
kprintf("VFS: mount_root can't mount another root\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto mount = make<Mount>(InodeIdentifier(), move(fileSystem));
|
||||
auto mount = make<Mount>(InodeIdentifier(), move(file_system));
|
||||
|
||||
auto root_inode_id = mount->guest().fs()->root_inode();
|
||||
auto root_inode = mount->guest().fs()->get_inode(root_inode_id);
|
||||
|
@ -112,18 +112,18 @@ bool VFS::is_vfs_root(InodeIdentifier inode) const
|
|||
void VFS::traverse_directory_inode(Inode& dir_inode, Function<bool(const FS::DirectoryEntry&)> callback)
|
||||
{
|
||||
dir_inode.traverse_as_directory([&] (const FS::DirectoryEntry& entry) {
|
||||
InodeIdentifier resolvedInode;
|
||||
InodeIdentifier resolved_inode;
|
||||
if (auto mount = find_mount_for_host(entry.inode))
|
||||
resolvedInode = mount->guest();
|
||||
resolved_inode = mount->guest();
|
||||
else
|
||||
resolvedInode = entry.inode;
|
||||
resolved_inode = entry.inode;
|
||||
|
||||
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();
|
||||
resolved_inode = mount->host();
|
||||
}
|
||||
callback(FS::DirectoryEntry(entry.name, entry.name_length, resolvedInode, entry.fileType));
|
||||
callback(FS::DirectoryEntry(entry.name, entry.name_length, resolved_inode, entry.file_type));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@ -146,10 +146,10 @@ RetainPtr<FileDescriptor> VFS::open(const String& path, int& error, int options,
|
|||
return nullptr;
|
||||
}
|
||||
auto metadata = inode->metadata();
|
||||
if (!(options & O_DONT_OPEN_DEVICE) && metadata.isCharacterDevice()) {
|
||||
auto it = m_character_devices.find(encodedDevice(metadata.majorDevice, metadata.minorDevice));
|
||||
if (!(options & O_DONT_OPEN_DEVICE) && metadata.is_character_device()) {
|
||||
auto it = m_character_devices.find(encoded_device(metadata.major_device, metadata.minor_device));
|
||||
if (it == m_character_devices.end()) {
|
||||
kprintf("VFS::open: no such character device %u,%u\n", metadata.majorDevice, metadata.minorDevice);
|
||||
kprintf("VFS::open: no such character device %u,%u\n", metadata.major_device, metadata.minor_device);
|
||||
return nullptr;
|
||||
}
|
||||
auto descriptor = (*it).value->open(error, options);
|
||||
|
@ -164,7 +164,7 @@ RetainPtr<FileDescriptor> VFS::create(const String& path, int& error, int option
|
|||
(void) options;
|
||||
error = -EWHYTHO;
|
||||
|
||||
if (!isSocket(mode) && !isFIFO(mode) && !isBlockDevice(mode) && !isCharacterDevice(mode)) {
|
||||
if (!is_socket(mode) && !is_fifo(mode) && !is_block_device(mode) && !is_character_device(mode)) {
|
||||
// Turn it into a regular file. (This feels rather hackish.)
|
||||
mode |= 0100000;
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ String VFS::absolute_path(Inode& core_inode)
|
|||
auto parent_inode = get_inode(parent);
|
||||
builder.append(parent_inode->reverse_lookup(child));
|
||||
}
|
||||
return builder.build();
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
InodeIdentifier VFS::resolve_path(const String& path, InodeIdentifier base, int& error, int options, InodeIdentifier* parent_id)
|
||||
|
@ -447,7 +447,7 @@ InodeIdentifier VFS::resolve_path(const String& path, InodeIdentifier base, int&
|
|||
return { };
|
||||
}
|
||||
auto metadata = crumb_inode->metadata();
|
||||
if (!metadata.isDirectory()) {
|
||||
if (!metadata.is_directory()) {
|
||||
#ifdef VFS_DEBUG
|
||||
kprintf("parent of <%s> not directory, it's inode %u:%u / %u:%u, mode: %u, size: %u\n", part.characters(), inode.fsid(), inode.index(), metadata.inode.fsid(), metadata.inode.index(), metadata.mode, metadata.size);
|
||||
#endif
|
||||
|
@ -482,13 +482,13 @@ InodeIdentifier VFS::resolve_path(const String& path, InodeIdentifier base, int&
|
|||
}
|
||||
crumb_inode = get_inode(crumb_id);
|
||||
metadata = crumb_inode->metadata();
|
||||
if (metadata.isDirectory()) {
|
||||
if (metadata.is_directory()) {
|
||||
if (i != parts.size() - 1) {
|
||||
if (parent_id)
|
||||
*parent_id = crumb_id;
|
||||
}
|
||||
}
|
||||
if (metadata.isSymbolicLink()) {
|
||||
if (metadata.is_symlink()) {
|
||||
if (i == parts.size() - 1) {
|
||||
if (options & O_NOFOLLOW) {
|
||||
error = -ELOOP;
|
||||
|
@ -517,17 +517,17 @@ VFS::Mount::Mount(InodeIdentifier host, RetainPtr<FS>&& guest_fs)
|
|||
|
||||
void VFS::register_character_device(CharacterDevice& device)
|
||||
{
|
||||
m_character_devices.set(encodedDevice(device.major(), device.minor()), &device);
|
||||
m_character_devices.set(encoded_device(device.major(), device.minor()), &device);
|
||||
}
|
||||
|
||||
void VFS::unregister_character_device(CharacterDevice& device)
|
||||
{
|
||||
m_character_devices.remove(encodedDevice(device.major(), device.minor()));
|
||||
m_character_devices.remove(encoded_device(device.major(), device.minor()));
|
||||
}
|
||||
|
||||
CharacterDevice* VFS::get_device(unsigned major, unsigned minor)
|
||||
{
|
||||
auto it = m_character_devices.find(encodedDevice(major, minor));
|
||||
auto it = m_character_devices.find(encoded_device(major, minor));
|
||||
if (it == m_character_devices.end())
|
||||
return nullptr;
|
||||
return (*it).value;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
class CharacterDevice;
|
||||
class FileDescriptor;
|
||||
|
||||
inline constexpr dword encodedDevice(unsigned major, unsigned minor)
|
||||
inline constexpr dword encoded_device(unsigned major, unsigned minor)
|
||||
{
|
||||
return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ static DescriptorTablePointer s_gdtr;
|
|||
static Descriptor* s_idt;
|
||||
static Descriptor* s_gdt;
|
||||
|
||||
static IRQHandler** s_irqHandler;
|
||||
static IRQHandler** s_irq_handler;
|
||||
|
||||
static Vector<word, KmallocEternalAllocator>* s_gdt_freelist;
|
||||
|
||||
|
@ -125,11 +125,11 @@ asm( \
|
|||
EH_ENTRY_NO_CODE(6);
|
||||
void exception_6_handler(RegisterDump& regs)
|
||||
{
|
||||
kprintf("%s invalid opcode: %u(%s)\n", current->isRing0() ? "Kernel" : "Process", current->pid(), current->name().characters());
|
||||
kprintf("%s invalid opcode: %u(%s)\n", current->is_ring0() ? "Kernel" : "Process", current->pid(), current->name().characters());
|
||||
|
||||
word ss;
|
||||
dword esp;
|
||||
if (current->isRing0()) {
|
||||
if (current->is_ring0()) {
|
||||
ss = regs.ds;
|
||||
esp = regs.esp;
|
||||
} else {
|
||||
|
@ -142,7 +142,7 @@ void exception_6_handler(RegisterDump& regs)
|
|||
kprintf("eax=%x ebx=%x ecx=%x edx=%x\n", regs.eax, regs.ebx, regs.ecx, regs.edx);
|
||||
kprintf("ebp=%x esp=%x esi=%x edi=%x\n", regs.ebp, esp, regs.esi, regs.edi);
|
||||
|
||||
if (current->isRing0()) {
|
||||
if (current->is_ring0()) {
|
||||
kprintf("Oh shit, we've crashed in ring 0 :(\n");
|
||||
HANG;
|
||||
}
|
||||
|
@ -175,11 +175,11 @@ void exception_7_handler(RegisterDump& regs)
|
|||
}
|
||||
|
||||
#ifdef FPU_EXCEPTION_DEBUG
|
||||
kprintf("%s FPU not available exception: %u(%s)\n", current->isRing0() ? "Kernel" : "Process", current->pid(), current->name().characters());
|
||||
kprintf("%s FPU not available exception: %u(%s)\n", current->is_ring0() ? "Kernel" : "Process", current->pid(), current->name().characters());
|
||||
|
||||
word ss;
|
||||
dword esp;
|
||||
if (current->isRing0()) {
|
||||
if (current->is_ring0()) {
|
||||
ss = regs.ds;
|
||||
esp = regs.esp;
|
||||
} else {
|
||||
|
@ -199,11 +199,11 @@ void exception_7_handler(RegisterDump& regs)
|
|||
EH_ENTRY(13);
|
||||
void exception_13_handler(RegisterDumpWithExceptionCode& regs)
|
||||
{
|
||||
kprintf("%s GPF: %u(%s)\n", current->isRing0() ? "Kernel" : "User", current->pid(), current->name().characters());
|
||||
kprintf("%s GPF: %u(%s)\n", current->is_ring0() ? "Kernel" : "User", current->pid(), current->name().characters());
|
||||
|
||||
word ss;
|
||||
dword esp;
|
||||
if (current->isRing0()) {
|
||||
if (current->is_ring0()) {
|
||||
ss = regs.ds;
|
||||
esp = regs.esp;
|
||||
} else {
|
||||
|
@ -217,7 +217,7 @@ void exception_13_handler(RegisterDumpWithExceptionCode& regs)
|
|||
kprintf("eax=%x ebx=%x ecx=%x edx=%x\n", regs.eax, regs.ebx, regs.ecx, regs.edx);
|
||||
kprintf("ebp=%x esp=%x esi=%x edi=%x\n", regs.ebp, esp, regs.esi, regs.edi);
|
||||
|
||||
if (current->isRing0()) {
|
||||
if (current->is_ring0()) {
|
||||
kprintf("Oh shit, we've crashed in ring 0 :(\n");
|
||||
HANG;
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
|
|||
|
||||
word ss;
|
||||
dword esp;
|
||||
if (current->isRing0()) {
|
||||
if (current->is_ring0()) {
|
||||
ss = regs.ds;
|
||||
esp = regs.esp;
|
||||
} else {
|
||||
|
@ -278,9 +278,9 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
|
|||
}
|
||||
};
|
||||
|
||||
if (current->isRing0()) {
|
||||
if (current->is_ring0()) {
|
||||
dump_registers_and_code();
|
||||
current->dumpRegions();
|
||||
current->dump_regions();
|
||||
HANG;
|
||||
}
|
||||
|
||||
|
@ -335,7 +335,7 @@ EH(12, "Stack exception")
|
|||
EH(15, "Unknown error")
|
||||
EH(16, "Coprocessor error")
|
||||
|
||||
static void writeRawGDTEntry(word selector, dword low, dword high)
|
||||
static void write_raw_gdt_entry(word selector, dword low, dword high)
|
||||
{
|
||||
word i = (selector & 0xfffc) >> 3;
|
||||
s_gdt[i].low = low;
|
||||
|
@ -348,7 +348,7 @@ static void writeRawGDTEntry(word selector, dword low, dword high)
|
|||
|
||||
void write_gdt_entry(word selector, Descriptor& descriptor)
|
||||
{
|
||||
writeRawGDTEntry(selector, descriptor.low, descriptor.high);
|
||||
write_raw_gdt_entry(selector, descriptor.low, descriptor.high);
|
||||
}
|
||||
|
||||
Descriptor& get_gdt_entry(word selector)
|
||||
|
@ -378,11 +378,11 @@ void gdt_init()
|
|||
s_gdtr.address = s_gdt;
|
||||
s_gdtr.size = (s_gdtLength * 8) - 1;
|
||||
|
||||
writeRawGDTEntry(0x0000, 0x00000000, 0x00000000);
|
||||
writeRawGDTEntry(0x0008, 0x0000ffff, 0x00cf9a00);
|
||||
writeRawGDTEntry(0x0010, 0x0000ffff, 0x00cf9200);
|
||||
writeRawGDTEntry(0x0018, 0x0000ffff, 0x00cffa00);
|
||||
writeRawGDTEntry(0x0020, 0x0000ffff, 0x00cff200);
|
||||
write_raw_gdt_entry(0x0000, 0x00000000, 0x00000000);
|
||||
write_raw_gdt_entry(0x0008, 0x0000ffff, 0x00cf9a00);
|
||||
write_raw_gdt_entry(0x0010, 0x0000ffff, 0x00cf9200);
|
||||
write_raw_gdt_entry(0x0018, 0x0000ffff, 0x00cffa00);
|
||||
write_raw_gdt_entry(0x0020, 0x0000ffff, 0x00cff200);
|
||||
|
||||
flush_gdt();
|
||||
}
|
||||
|
@ -395,15 +395,15 @@ static void unimp_trap()
|
|||
|
||||
void register_irq_handler(byte irq, IRQHandler& handler)
|
||||
{
|
||||
ASSERT(!s_irqHandler[irq]);
|
||||
s_irqHandler[irq] = &handler;
|
||||
ASSERT(!s_irq_handler[irq]);
|
||||
s_irq_handler[irq] = &handler;
|
||||
register_interrupt_handler(IRQ_VECTOR_BASE + irq, asm_irq_entry);
|
||||
}
|
||||
|
||||
void unregister_irq_handler(byte irq, IRQHandler& handler)
|
||||
{
|
||||
ASSERT(s_irqHandler[irq] == &handler);
|
||||
s_irqHandler[irq] = nullptr;
|
||||
ASSERT(s_irq_handler[irq] == &handler);
|
||||
s_irq_handler[irq] = nullptr;
|
||||
}
|
||||
|
||||
void register_interrupt_handler(byte index, void (*f)())
|
||||
|
@ -467,9 +467,9 @@ void idt_init()
|
|||
|
||||
register_interrupt_handler(0x57, irq7_handler);
|
||||
|
||||
s_irqHandler = static_cast<IRQHandler**>(kmalloc_eternal(sizeof(IRQHandler*) * 16));
|
||||
s_irq_handler = static_cast<IRQHandler**>(kmalloc_eternal(sizeof(IRQHandler*) * 16));
|
||||
for (byte i = 0; i < 16; ++i) {
|
||||
s_irqHandler[i] = nullptr;
|
||||
s_irq_handler[i] = nullptr;
|
||||
}
|
||||
|
||||
flush_idt();
|
||||
|
@ -482,7 +482,7 @@ void load_task_register(word selector)
|
|||
|
||||
void handle_irq()
|
||||
{
|
||||
word isr = PIC::getISR();
|
||||
word isr = PIC::get_isr();
|
||||
if (!isr) {
|
||||
kprintf("Spurious IRQ\n");
|
||||
return;
|
||||
|
@ -498,8 +498,8 @@ void handle_irq()
|
|||
}
|
||||
}
|
||||
|
||||
if (s_irqHandler[irq])
|
||||
s_irqHandler[irq]->handle_irq();
|
||||
if (s_irq_handler[irq])
|
||||
s_irq_handler[irq]->handle_irq();
|
||||
PIC::eoi(irq);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,14 +43,14 @@ union Descriptor {
|
|||
TrapGate_32bit = 0xf,
|
||||
};
|
||||
|
||||
void setBase(void* b)
|
||||
void set_base(void* b)
|
||||
{
|
||||
base_lo = (dword)(b) & 0xffff;
|
||||
base_hi = ((dword)(b) >> 16) & 0xff;
|
||||
base_hi2 = ((dword)(b) >> 24) & 0xff;
|
||||
}
|
||||
|
||||
void setLimit(dword l)
|
||||
void set_limit(dword l)
|
||||
{
|
||||
limit_lo = (dword)l & 0xffff;
|
||||
limit_hi = ((dword)l >> 16) & 0xff;
|
||||
|
@ -220,7 +220,7 @@ struct FPUState {
|
|||
dword st[20];
|
||||
};
|
||||
|
||||
inline constexpr dword pageBaseOf(dword address)
|
||||
inline constexpr dword page_base_of(dword address)
|
||||
{
|
||||
return address & 0xfffff000;
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
#include "PIC.h"
|
||||
#include "Scheduler.h"
|
||||
|
||||
#define IRQ_TIMER 0
|
||||
#define IRQ_TIMER 0
|
||||
|
||||
extern "C" void tick_ISR();
|
||||
extern "C" void clock_handle(RegisterDump&);
|
||||
extern "C" void timer_interrupt_entry();
|
||||
extern "C" void timer_interrupt_handler(RegisterDump&);
|
||||
|
||||
asm(
|
||||
".globl tick_ISR \n"
|
||||
"tick_ISR: \n"
|
||||
".globl timer_interrupt_entry \n"
|
||||
"timer_interrupt_entry: \n"
|
||||
" pusha\n"
|
||||
" pushw %ds\n"
|
||||
" pushw %es\n"
|
||||
|
@ -27,7 +27,7 @@ asm(
|
|||
" popw %fs\n"
|
||||
" popw %gs\n"
|
||||
" mov %esp, %eax\n"
|
||||
" call clock_handle\n"
|
||||
" call timer_interrupt_handler\n"
|
||||
" popw %gs\n"
|
||||
" popw %gs\n"
|
||||
" popw %fs\n"
|
||||
|
@ -53,12 +53,11 @@ asm(
|
|||
#define MODE_RATE 0x04
|
||||
#define MODE_SQUARE_WAVE 0x06
|
||||
|
||||
#define WRITE_word 0x30
|
||||
#define WRITE_WORD 0x30
|
||||
|
||||
/* Miscellaneous */
|
||||
#define BASE_FREQUENCY 1193182
|
||||
|
||||
void clock_handle(RegisterDump& regs)
|
||||
void timer_interrupt_handler(RegisterDump& regs)
|
||||
{
|
||||
IRQHandlerScope scope(IRQ_TIMER);
|
||||
Scheduler::timer_tick(regs);
|
||||
|
@ -70,7 +69,7 @@ void initialize()
|
|||
{
|
||||
word timer_reload;
|
||||
|
||||
IO::out8(PIT_CTL, TIMER0_SELECT | WRITE_word | MODE_SQUARE_WAVE);
|
||||
IO::out8(PIT_CTL, TIMER0_SELECT | WRITE_WORD | MODE_SQUARE_WAVE);
|
||||
|
||||
timer_reload = (BASE_FREQUENCY / TICKS_PER_SECOND);
|
||||
|
||||
|
@ -79,7 +78,7 @@ void initialize()
|
|||
IO::out8(TIMER0_CTL, LSB(timer_reload));
|
||||
IO::out8(TIMER0_CTL, MSB(timer_reload));
|
||||
|
||||
register_interrupt_handler(IRQ_VECTOR_BASE + IRQ_TIMER, tick_ISR);
|
||||
register_interrupt_handler(IRQ_VECTOR_BASE + IRQ_TIMER, timer_interrupt_entry);
|
||||
|
||||
PIC::enable(IRQ_TIMER);
|
||||
}
|
||||
|
|
|
@ -88,10 +88,10 @@ static void init_stage2()
|
|||
vfs->register_character_device(*tty3);
|
||||
|
||||
auto dev_hd0 = IDEDiskDevice::create();
|
||||
auto e2fs = Ext2FS::create(dev_hd0.copyRef());
|
||||
auto e2fs = Ext2FS::create(dev_hd0.copy_ref());
|
||||
e2fs->initialize();
|
||||
|
||||
vfs->mount_root(e2fs.copyRef());
|
||||
vfs->mount_root(e2fs.copy_ref());
|
||||
|
||||
load_ksyms();
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ int kprintf(const char* fmt, ...)
|
|||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int ret = printfInternal(console_putch, nullptr, fmt, ap);
|
||||
int ret = printf_internal(console_putch, nullptr, fmt, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ int ksprintf(char* buffer, const char* fmt, ...)
|
|||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int ret = printfInternal(buffer_putch, buffer, fmt, ap);
|
||||
int ret = printf_internal(buffer_putch, buffer, fmt, ap);
|
||||
buffer[ret] = '\0';
|
||||
va_end(ap);
|
||||
return ret;
|
||||
|
@ -44,7 +44,7 @@ extern "C" int dbgprintf(const char* fmt, ...)
|
|||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int ret = printfInternal(debugger_putch, nullptr, fmt, ap);
|
||||
int ret = printf_internal(debugger_putch, nullptr, fmt, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue