Lots of hacking to make a very simple "ls" utility.

I added a dead-simple malloc that only allows allocations < 4096 bytes.
It just forwards the request to mmap() every time.

I also added simplified versions of opendir() and readdir().
This commit is contained in:
Andreas Kling 2018-10-24 12:43:52 +02:00
parent 0c5bbac86e
commit bca4b71bfa
Notes: sideshowbarker 2024-07-19 18:39:29 +09:00
19 changed files with 277 additions and 67 deletions

View file

@ -6,6 +6,7 @@
#include <AK/kmalloc.h>
#include <AK/ktime.h>
#include <AK/kstdio.h>
#include <AK/BufferStream.h>
#include "sys-errno.h"
//#define EXT2_DEBUG
@ -431,49 +432,6 @@ bool Ext2FileSystem::addInodeToDirectory(unsigned directoryInode, unsigned inode
return writeDirectoryInode(directoryInode, move(entries));
}
class BufferStream {
public:
explicit BufferStream(ByteBuffer& buffer)
: m_buffer(buffer)
{
}
void operator<<(byte value)
{
m_buffer[m_offset++] = value & 0xffu;
}
void operator<<(word value)
{
m_buffer[m_offset++] = value & 0xffu;
m_buffer[m_offset++] = (byte)(value >> 8) & 0xffu;
}
void operator<<(dword value)
{
m_buffer[m_offset++] = value & 0xffu;
m_buffer[m_offset++] = (byte)(value >> 8) & 0xffu;
m_buffer[m_offset++] = (byte)(value >> 16) & 0xffu;
m_buffer[m_offset++] = (byte)(value >> 24) & 0xffu;
}
void operator<<(const String& value)
{
for (unsigned i = 0; i < value.length(); ++i)
m_buffer[m_offset++] = value[i];
}
void fillToEnd(byte ch)
{
while (m_offset < m_buffer.size())
m_buffer[m_offset++] = ch;
}
private:
ByteBuffer& m_buffer;
Unix::size_t m_offset { 0 };
};
bool Ext2FileSystem::writeDirectoryInode(unsigned directoryInode, Vector<DirectoryEntry>&& entries)
{
kprintf("[ext2fs] New directory inode %u contents to write:\n", directoryInode);