mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
More coding style changes.
This commit is contained in:
parent
d824442e3e
commit
f6e27c2abe
Notes:
sideshowbarker
2024-07-19 16:09:08 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/f6e27c2abe9
39 changed files with 216 additions and 216 deletions
|
@ -14,7 +14,7 @@ public:
|
||||||
m_elements[i] = T();
|
m_elements[i] = T();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isEmpty() const { return !m_size; }
|
bool is_empty() const { return !m_size; }
|
||||||
size_t size() const { return m_size; }
|
size_t size() const { return m_size; }
|
||||||
|
|
||||||
size_t capacity() const { return Capacity; }
|
size_t capacity() const { return Capacity; }
|
||||||
|
@ -39,7 +39,7 @@ public:
|
||||||
|
|
||||||
T dequeue()
|
T dequeue()
|
||||||
{
|
{
|
||||||
ASSERT(!isEmpty());
|
ASSERT(!is_empty());
|
||||||
T value = m_elements[m_head];
|
T value = m_elements[m_head];
|
||||||
m_head = (m_head + 1) % Capacity;
|
m_head = (m_head + 1) % Capacity;
|
||||||
--m_size;
|
--m_size;
|
||||||
|
|
|
@ -67,7 +67,7 @@ int main(int c, char** v)
|
||||||
queue.enqueue(3);
|
queue.enqueue(3);
|
||||||
queue.dump();
|
queue.dump();
|
||||||
queue.enqueue(4);
|
queue.enqueue(4);
|
||||||
ASSERT(!queue.isEmpty());
|
ASSERT(!queue.is_empty());
|
||||||
ASSERT(queue.size() == 4);
|
ASSERT(queue.size() == 4);
|
||||||
ASSERT(queue.dequeue() == 1);
|
ASSERT(queue.dequeue() == 1);
|
||||||
queue.dump();
|
queue.dump();
|
||||||
|
@ -77,7 +77,7 @@ int main(int c, char** v)
|
||||||
queue.dump();
|
queue.dump();
|
||||||
ASSERT(queue.dequeue() == 4);
|
ASSERT(queue.dequeue() == 4);
|
||||||
queue.dump();
|
queue.dump();
|
||||||
ASSERT(queue.isEmpty());
|
ASSERT(queue.is_empty());
|
||||||
queue.enqueue(1);
|
queue.enqueue(1);
|
||||||
queue.enqueue(2);
|
queue.enqueue(2);
|
||||||
queue.enqueue(3);
|
queue.enqueue(3);
|
||||||
|
@ -89,7 +89,7 @@ int main(int c, char** v)
|
||||||
ASSERT(queue.dequeue() == 5);
|
ASSERT(queue.dequeue() == 5);
|
||||||
ASSERT(queue.dequeue() == 6);
|
ASSERT(queue.dequeue() == 6);
|
||||||
ASSERT(queue.dequeue() == 7);
|
ASSERT(queue.dequeue() == 7);
|
||||||
ASSERT(queue.isEmpty());
|
ASSERT(queue.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@ Console::~Console()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Console::hasDataAvailableForRead() const
|
bool Console::has_data_available_for_reading() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ void Console::putChar(char ch)
|
||||||
IO::out8(0xe9, ch);
|
IO::out8(0xe9, ch);
|
||||||
#endif
|
#endif
|
||||||
if (m_implementation)
|
if (m_implementation)
|
||||||
m_implementation->onConsoleReceive(ch);
|
m_implementation->on_sysconsole_receive(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsoleImplementation::~ConsoleImplementation()
|
ConsoleImplementation::~ConsoleImplementation()
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
class ConsoleImplementation {
|
class ConsoleImplementation {
|
||||||
public:
|
public:
|
||||||
virtual ~ConsoleImplementation();
|
virtual ~ConsoleImplementation();
|
||||||
virtual void onConsoleReceive(byte) = 0;
|
virtual void on_sysconsole_receive(byte) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Console final : public CharacterDevice {
|
class Console final : public CharacterDevice {
|
||||||
|
@ -18,7 +18,7 @@ public:
|
||||||
Console();
|
Console();
|
||||||
virtual ~Console() override;
|
virtual ~Console() override;
|
||||||
|
|
||||||
virtual bool hasDataAvailableForRead() const override;
|
virtual bool has_data_available_for_reading() const override;
|
||||||
virtual ssize_t read(byte* buffer, size_t size) override;
|
virtual ssize_t read(byte* buffer, size_t size) override;
|
||||||
virtual ssize_t write(const byte* data, size_t size) override;
|
virtual ssize_t write(const byte* data, size_t size) override;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ void FIFO::close(Direction direction)
|
||||||
|
|
||||||
bool FIFO::can_read() const
|
bool FIFO::can_read() const
|
||||||
{
|
{
|
||||||
return !m_queue.isEmpty() || !m_writers;
|
return !m_queue.is_empty() || !m_writers;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FIFO::can_write() const
|
bool FIFO::can_write() const
|
||||||
|
@ -59,7 +59,7 @@ bool FIFO::can_write() const
|
||||||
|
|
||||||
ssize_t FIFO::read(byte* buffer, size_t size)
|
ssize_t FIFO::read(byte* buffer, size_t size)
|
||||||
{
|
{
|
||||||
if (!m_writers && m_queue.isEmpty())
|
if (!m_writers && m_queue.is_empty())
|
||||||
return 0;
|
return 0;
|
||||||
#ifdef FIFO_DEBUG
|
#ifdef FIFO_DEBUG
|
||||||
dbgprintf("fifo: read(%u)\n",size);
|
dbgprintf("fifo: read(%u)\n",size);
|
||||||
|
|
|
@ -100,7 +100,7 @@ bool IDEDiskDevice::wait_for_irq()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDEDiskDevice::handleIRQ()
|
void IDEDiskDevice::handle_irq()
|
||||||
{
|
{
|
||||||
#ifdef DISK_DEBUG
|
#ifdef DISK_DEBUG
|
||||||
byte status = IO::in8(0x1f7);
|
byte status = IO::in8(0x1f7);
|
||||||
|
@ -123,13 +123,13 @@ void IDEDiskDevice::initialize()
|
||||||
|
|
||||||
while (IO::in8(IDE0_STATUS) & BUSY);
|
while (IO::in8(IDE0_STATUS) & BUSY);
|
||||||
|
|
||||||
enableIRQ();
|
enable_irq();
|
||||||
|
|
||||||
IO::out8(0x1F6, 0xA0); // 0xB0 for 2nd device
|
IO::out8(0x1F6, 0xA0); // 0xB0 for 2nd device
|
||||||
IO::out8(0x3F6, 0xA0); // 0xB0 for 2nd device
|
IO::out8(0x3F6, 0xA0); // 0xB0 for 2nd device
|
||||||
IO::out8(IDE0_COMMAND, IDENTIFY_DRIVE);
|
IO::out8(IDE0_COMMAND, IDENTIFY_DRIVE);
|
||||||
|
|
||||||
enableIRQ();
|
enable_irq();
|
||||||
wait_for_irq();
|
wait_for_irq();
|
||||||
|
|
||||||
ByteBuffer wbuf = ByteBuffer::createUninitialized(512);
|
ByteBuffer wbuf = ByteBuffer::createUninitialized(512);
|
||||||
|
@ -180,7 +180,7 @@ bool IDEDiskDevice::read_sectors(dword start_sector, word count, byte* outbuf)
|
||||||
count,
|
count,
|
||||||
start_sector);
|
start_sector);
|
||||||
#endif
|
#endif
|
||||||
disableIRQ();
|
disable_irq();
|
||||||
|
|
||||||
auto chs = lba_to_chs(start_sector);
|
auto chs = lba_to_chs(start_sector);
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ bool IDEDiskDevice::read_sectors(dword start_sector, word count, byte* outbuf)
|
||||||
|
|
||||||
IO::out8(IDE0_COMMAND, READ_SECTORS);
|
IO::out8(IDE0_COMMAND, READ_SECTORS);
|
||||||
m_interrupted = false;
|
m_interrupted = false;
|
||||||
enableIRQ();
|
enable_irq();
|
||||||
wait_for_irq();
|
wait_for_irq();
|
||||||
|
|
||||||
byte status = IO::in8(0x1f7);
|
byte status = IO::in8(0x1f7);
|
||||||
|
@ -228,7 +228,7 @@ bool IDEDiskDevice::write_sectors(dword start_sector, word count, const byte* da
|
||||||
current->pid(),
|
current->pid(),
|
||||||
count,
|
count,
|
||||||
start_sector);
|
start_sector);
|
||||||
disableIRQ();
|
disable_irq();
|
||||||
|
|
||||||
auto chs = lba_to_chs(start_sector);
|
auto chs = lba_to_chs(start_sector);
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ bool IDEDiskDevice::write_sectors(dword start_sector, word count, const byte* da
|
||||||
}
|
}
|
||||||
|
|
||||||
m_interrupted = false;
|
m_interrupted = false;
|
||||||
enableIRQ();
|
enable_irq();
|
||||||
wait_for_irq();
|
wait_for_irq();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -20,7 +20,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^IRQHandler
|
// ^IRQHandler
|
||||||
virtual void handleIRQ() override;
|
virtual void handle_irq() override;
|
||||||
|
|
||||||
// ^DiskDevice
|
// ^DiskDevice
|
||||||
virtual const char* class_name() const override;
|
virtual const char* class_name() const override;
|
||||||
|
|
|
@ -3,23 +3,23 @@
|
||||||
#include "PIC.h"
|
#include "PIC.h"
|
||||||
|
|
||||||
IRQHandler::IRQHandler(byte irq)
|
IRQHandler::IRQHandler(byte irq)
|
||||||
: m_irqNumber(irq)
|
: m_irq_number(irq)
|
||||||
{
|
{
|
||||||
registerIRQHandler(m_irqNumber, *this);
|
register_irq_handler(m_irq_number, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
IRQHandler::~IRQHandler()
|
IRQHandler::~IRQHandler()
|
||||||
{
|
{
|
||||||
unregisterIRQHandler(m_irqNumber, *this);
|
unregister_irq_handler(m_irq_number, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRQHandler::enableIRQ()
|
void IRQHandler::enable_irq()
|
||||||
{
|
{
|
||||||
PIC::enable(m_irqNumber);
|
PIC::enable(m_irq_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRQHandler::disableIRQ()
|
void IRQHandler::disable_irq()
|
||||||
{
|
{
|
||||||
PIC::disable(m_irqNumber);
|
PIC::disable(m_irq_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,17 +5,17 @@
|
||||||
class IRQHandler {
|
class IRQHandler {
|
||||||
public:
|
public:
|
||||||
virtual ~IRQHandler();
|
virtual ~IRQHandler();
|
||||||
virtual void handleIRQ() = 0;
|
virtual void handle_irq() = 0;
|
||||||
|
|
||||||
byte irqNumber() const { return m_irqNumber; }
|
byte irq_number() const { return m_irq_number; }
|
||||||
|
|
||||||
void enableIRQ();
|
void enable_irq();
|
||||||
void disableIRQ();
|
void disable_irq();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit IRQHandler(byte irq);
|
explicit IRQHandler(byte irq);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
byte m_irqNumber { 0 };
|
byte m_irq_number { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -43,11 +43,11 @@ void Keyboard::emit(byte ch)
|
||||||
key.character = ch;
|
key.character = ch;
|
||||||
key.modifiers = m_modifiers;
|
key.modifiers = m_modifiers;
|
||||||
if (m_client)
|
if (m_client)
|
||||||
m_client->onKeyPress(key);
|
m_client->on_key_pressed(key);
|
||||||
m_queue.enqueue(key);
|
m_queue.enqueue(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Keyboard::handleIRQ()
|
void Keyboard::handle_irq()
|
||||||
{
|
{
|
||||||
while (IO::in8(0x64) & 1) {
|
while (IO::in8(0x64) & 1) {
|
||||||
byte ch = IO::in8(0x60);
|
byte ch = IO::in8(0x60);
|
||||||
|
@ -107,23 +107,23 @@ Keyboard::Keyboard()
|
||||||
while (IO::in8(I8042_STATUS ) & DATA_AVAILABLE)
|
while (IO::in8(I8042_STATUS ) & DATA_AVAILABLE)
|
||||||
IO::in8(I8042_BUFFER);
|
IO::in8(I8042_BUFFER);
|
||||||
|
|
||||||
enableIRQ();
|
enable_irq();
|
||||||
}
|
}
|
||||||
|
|
||||||
Keyboard::~Keyboard()
|
Keyboard::~Keyboard()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Keyboard::hasDataAvailableForRead() const
|
bool Keyboard::has_data_available_for_reading() const
|
||||||
{
|
{
|
||||||
return !m_queue.isEmpty();
|
return !m_queue.is_empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t Keyboard::read(byte* buffer, size_t size)
|
ssize_t Keyboard::read(byte* buffer, size_t size)
|
||||||
{
|
{
|
||||||
ssize_t nread = 0;
|
ssize_t nread = 0;
|
||||||
while ((size_t)nread < size) {
|
while ((size_t)nread < size) {
|
||||||
if (m_queue.isEmpty())
|
if (m_queue.is_empty())
|
||||||
break;
|
break;
|
||||||
buffer[nread++] = m_queue.dequeue().character;
|
buffer[nread++] = m_queue.dequeue().character;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,16 +30,16 @@ public:
|
||||||
virtual ~Keyboard() override;
|
virtual ~Keyboard() override;
|
||||||
Keyboard();
|
Keyboard();
|
||||||
|
|
||||||
void setClient(KeyboardClient* client) { m_client = client; }
|
void set_client(KeyboardClient* client) { m_client = client; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^IRQHandler
|
// ^IRQHandler
|
||||||
virtual void handleIRQ() override;
|
virtual void handle_irq() override;
|
||||||
|
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual ssize_t read(byte* buffer, size_t) override;
|
virtual ssize_t read(byte* buffer, size_t) override;
|
||||||
virtual ssize_t write(const byte* buffer, size_t) override;
|
virtual ssize_t write(const byte* buffer, size_t) override;
|
||||||
virtual bool hasDataAvailableForRead() const override;
|
virtual bool has_data_available_for_reading() const override;
|
||||||
|
|
||||||
void emit(byte);
|
void emit(byte);
|
||||||
|
|
||||||
|
@ -51,5 +51,5 @@ private:
|
||||||
class KeyboardClient {
|
class KeyboardClient {
|
||||||
public:
|
public:
|
||||||
virtual ~KeyboardClient();
|
virtual ~KeyboardClient();
|
||||||
virtual void onKeyPress(Keyboard::Key) = 0;
|
virtual void on_key_pressed(Keyboard::Key) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -167,30 +167,30 @@ ByteBuffer procfs$pid_cwd(Process& process)
|
||||||
return VFS::the().absolute_path(*inode).toByteBuffer();
|
return VFS::the().absolute_path(*inode).toByteBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcFS::addProcess(Process& process)
|
void ProcFS::add_process(Process& process)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
char buf[16];
|
char buf[16];
|
||||||
ksprintf(buf, "%d", process.pid());
|
ksprintf(buf, "%d", process.pid());
|
||||||
auto dir = addFile(create_directory(buf));
|
auto dir = add_file(create_directory(buf));
|
||||||
m_pid2inode.set(process.pid(), dir.index());
|
m_pid2inode.set(process.pid(), dir.index());
|
||||||
addFile(create_generated_file("vm", [&process] { return procfs$pid_vm(process); }), dir.index());
|
add_file(create_generated_file("vm", [&process] { return procfs$pid_vm(process); }), dir.index());
|
||||||
addFile(create_generated_file("vmo", [&process] { return procfs$pid_vmo(process); }), dir.index());
|
add_file(create_generated_file("vmo", [&process] { return procfs$pid_vmo(process); }), dir.index());
|
||||||
addFile(create_generated_file("stack", [&process] { return procfs$pid_stack(process); }), dir.index());
|
add_file(create_generated_file("stack", [&process] { return procfs$pid_stack(process); }), dir.index());
|
||||||
addFile(create_generated_file("regs", [&process] { return procfs$pid_regs(process); }), dir.index());
|
add_file(create_generated_file("regs", [&process] { return procfs$pid_regs(process); }), dir.index());
|
||||||
addFile(create_generated_file("fds", [&process] { return procfs$pid_fds(process); }), dir.index());
|
add_file(create_generated_file("fds", [&process] { return procfs$pid_fds(process); }), dir.index());
|
||||||
if (process.executable_inode())
|
if (process.executable_inode())
|
||||||
addFile(create_generated_file("exe", [&process] { return procfs$pid_exe(process); }, 00120777), dir.index());
|
add_file(create_generated_file("exe", [&process] { return procfs$pid_exe(process); }, 00120777), dir.index());
|
||||||
addFile(create_generated_file("cwd", [&process] { return procfs$pid_cwd(process); }, 00120777), dir.index());
|
add_file(create_generated_file("cwd", [&process] { return procfs$pid_cwd(process); }, 00120777), dir.index());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcFS::removeProcess(Process& process)
|
void ProcFS::remove_process(Process& process)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
auto pid = process.pid();
|
auto pid = process.pid();
|
||||||
auto it = m_pid2inode.find(pid);
|
auto it = m_pid2inode.find(pid);
|
||||||
ASSERT(it != m_pid2inode.end());
|
ASSERT(it != m_pid2inode.end());
|
||||||
bool success = removeFile((*it).value);
|
bool success = remove_file((*it).value);
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
m_pid2inode.remove(pid);
|
m_pid2inode.remove(pid);
|
||||||
}
|
}
|
||||||
|
@ -341,7 +341,7 @@ ByteBuffer procfs$summary()
|
||||||
process->ppid(),
|
process->ppid(),
|
||||||
process->timesScheduled(),
|
process->timesScheduled(),
|
||||||
process->number_of_open_file_descriptors(),
|
process->number_of_open_file_descriptors(),
|
||||||
process->tty() ? strrchr(process->tty()->ttyName().characters(), '/') + 1 : "n/a",
|
process->tty() ? strrchr(process->tty()->tty_name().characters(), '/') + 1 : "n/a",
|
||||||
process->name().characters());
|
process->name().characters());
|
||||||
}
|
}
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
|
@ -364,8 +364,8 @@ ByteBuffer procfs$vnodes()
|
||||||
path = vfs.absolute_path(*vnode.core_inode());
|
path = vfs.absolute_path(*vnode.core_inode());
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
if (auto* dev = vnode.characterDevice()) {
|
if (auto* dev = vnode.characterDevice()) {
|
||||||
if (dev->isTTY())
|
if (dev->is_tty())
|
||||||
path = static_cast<const TTY*>(dev)->ttyName();
|
path = static_cast<const TTY*>(dev)->tty_name();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ptr += ksprintf(ptr, "vnode %03u: %02u:%08u (%u) %s\n", i, vnode.inode.fsid(), vnode.inode.index(), vnode.retain_count(), path.characters());
|
ptr += ksprintf(ptr, "vnode %03u: %02u:%08u (%u) %s\n", i, vnode.inode.fsid(), vnode.inode.index(), vnode.retain_count(), path.characters());
|
||||||
|
@ -378,13 +378,13 @@ ByteBuffer procfs$vnodes()
|
||||||
bool ProcFS::initialize()
|
bool ProcFS::initialize()
|
||||||
{
|
{
|
||||||
SynthFS::initialize();
|
SynthFS::initialize();
|
||||||
addFile(create_generated_file("mm", procfs$mm));
|
add_file(create_generated_file("mm", procfs$mm));
|
||||||
addFile(create_generated_file("regions", procfs$regions));
|
add_file(create_generated_file("regions", procfs$regions));
|
||||||
addFile(create_generated_file("mounts", procfs$mounts));
|
add_file(create_generated_file("mounts", procfs$mounts));
|
||||||
addFile(create_generated_file("kmalloc", procfs$kmalloc));
|
add_file(create_generated_file("kmalloc", procfs$kmalloc));
|
||||||
addFile(create_generated_file("summary", procfs$summary));
|
add_file(create_generated_file("summary", procfs$summary));
|
||||||
addFile(create_generated_file("cpuinfo", procfs$cpuinfo));
|
add_file(create_generated_file("cpuinfo", procfs$cpuinfo));
|
||||||
addFile(create_generated_file("vnodes", procfs$vnodes));
|
add_file(create_generated_file("vnodes", procfs$vnodes));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ public:
|
||||||
virtual bool initialize() override;
|
virtual bool initialize() override;
|
||||||
virtual const char* class_name() const override;
|
virtual const char* class_name() const override;
|
||||||
|
|
||||||
void addProcess(Process&);
|
void add_process(Process&);
|
||||||
void removeProcess(Process&);
|
void remove_process(Process&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProcFS();
|
ProcFS();
|
||||||
|
|
|
@ -255,7 +255,7 @@ Process* Process::fork(RegisterDump& regs)
|
||||||
dbgprintf("fork: child will begin executing at %w:%x with stack %w:%x\n", child->m_tss.cs, child->m_tss.eip, child->m_tss.ss, child->m_tss.esp);
|
dbgprintf("fork: child will begin executing at %w:%x with stack %w:%x\n", child->m_tss.cs, child->m_tss.eip, child->m_tss.ss, child->m_tss.esp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ProcFS::the().addProcess(*child);
|
ProcFS::the().add_process(*child);
|
||||||
|
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
|
@ -491,7 +491,7 @@ Process* Process::create_user_process(const String& path, uid_t uid, gid_t gid,
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
ProcFS::the().addProcess(*process);
|
ProcFS::the().add_process(*process);
|
||||||
|
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
|
@ -554,7 +554,7 @@ Process* Process::create_kernel_process(void (*e)(), String&& name)
|
||||||
g_processes->prepend(process);
|
g_processes->prepend(process);
|
||||||
system.nprocess++;
|
system.nprocess++;
|
||||||
}
|
}
|
||||||
ProcFS::the().addProcess(*process);
|
ProcFS::the().add_process(*process);
|
||||||
#ifdef TASK_DEBUG
|
#ifdef TASK_DEBUG
|
||||||
kprintf("Kernel process %u (%s) spawned @ %p\n", process->pid(), process->name().characters(), process->m_tss.eip);
|
kprintf("Kernel process %u (%s) spawned @ %p\n", process->pid(), process->name().characters(), process->m_tss.eip);
|
||||||
#endif
|
#endif
|
||||||
|
@ -684,7 +684,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
|
||||||
Process::~Process()
|
Process::~Process()
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
ProcFS::the().removeProcess(*this);
|
ProcFS::the().remove_process(*this);
|
||||||
system.nprocess--;
|
system.nprocess--;
|
||||||
|
|
||||||
gdt_free_entry(selector());
|
gdt_free_entry(selector());
|
||||||
|
@ -976,9 +976,9 @@ int Process::sys$ttyname_r(int fd, char* buffer, size_t size)
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_descriptor(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->isTTY())
|
if (!descriptor->is_tty())
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
auto ttyName = descriptor->tty()->ttyName();
|
auto ttyName = descriptor->tty()->tty_name();
|
||||||
if (size < ttyName.length() + 1)
|
if (size < ttyName.length() + 1)
|
||||||
return -ERANGE;
|
return -ERANGE;
|
||||||
strcpy(buffer, ttyName.characters());
|
strcpy(buffer, ttyName.characters());
|
||||||
|
@ -996,7 +996,7 @@ ssize_t Process::sys$write(int fd, const void* data, size_t size)
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
ssize_t nwritten = 0;
|
ssize_t nwritten = 0;
|
||||||
if (descriptor->isBlocking()) {
|
if (descriptor->is_blocking()) {
|
||||||
while (nwritten < (ssize_t)size) {
|
while (nwritten < (ssize_t)size) {
|
||||||
#ifdef IO_DEBUG
|
#ifdef IO_DEBUG
|
||||||
dbgprintf("while %u < %u\n", nwritten, size);
|
dbgprintf("while %u < %u\n", nwritten, size);
|
||||||
|
@ -1053,8 +1053,8 @@ ssize_t Process::sys$read(int fd, void* outbuf, size_t nread)
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_descriptor(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (descriptor->isBlocking()) {
|
if (descriptor->is_blocking()) {
|
||||||
if (!descriptor->hasDataAvailableForRead()) {
|
if (!descriptor->has_data_available_for_reading()) {
|
||||||
m_fdBlockedOnRead = fd;
|
m_fdBlockedOnRead = fd;
|
||||||
block(BlockedRead);
|
block(BlockedRead);
|
||||||
sched_yield();
|
sched_yield();
|
||||||
|
@ -1180,7 +1180,7 @@ int Process::sys$readlink(const char* path, char* buffer, size_t size)
|
||||||
if (!descriptor->metadata().isSymbolicLink())
|
if (!descriptor->metadata().isSymbolicLink())
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
auto contents = descriptor->readEntireFile();
|
auto contents = descriptor->read_entire_file();
|
||||||
if (!contents)
|
if (!contents)
|
||||||
return -EIO; // FIXME: Get a more detailed error from VFS.
|
return -EIO; // FIXME: Get a more detailed error from VFS.
|
||||||
|
|
||||||
|
@ -1198,7 +1198,7 @@ int Process::sys$chdir(const char* path)
|
||||||
auto descriptor = VFS::the().open(path, error, 0, cwd_inode()->identifier());
|
auto descriptor = VFS::the().open(path, error, 0, cwd_inode()->identifier());
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return error;
|
return error;
|
||||||
if (!descriptor->isDirectory())
|
if (!descriptor->is_directory())
|
||||||
return -ENOTDIR;
|
return -ENOTDIR;
|
||||||
m_cwd = descriptor->vnode();
|
m_cwd = descriptor->vnode();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1241,7 +1241,7 @@ int Process::sys$open(const char* path, int options)
|
||||||
auto descriptor = VFS::the().open(path, error, options, cwd_inode()->identifier());
|
auto descriptor = VFS::the().open(path, error, options, cwd_inode()->identifier());
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return error;
|
return error;
|
||||||
if (options & O_DIRECTORY && !descriptor->isDirectory())
|
if (options & O_DIRECTORY && !descriptor->is_directory())
|
||||||
return -ENOTDIR; // FIXME: This should be handled by VFS::open.
|
return -ENOTDIR; // FIXME: This should be handled by VFS::open.
|
||||||
|
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
|
@ -1326,7 +1326,7 @@ int Process::sys$isatty(int fd)
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_descriptor(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->isTTY())
|
if (!descriptor->is_tty())
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ bool Scheduler::pick_next()
|
||||||
if (process.state() == Process::BlockedRead) {
|
if (process.state() == Process::BlockedRead) {
|
||||||
ASSERT(process.m_fdBlockedOnRead != -1);
|
ASSERT(process.m_fdBlockedOnRead != -1);
|
||||||
// FIXME: Block until the amount of data wanted is available.
|
// FIXME: Block until the amount of data wanted is available.
|
||||||
if (process.m_fds[process.m_fdBlockedOnRead].descriptor->hasDataAvailableForRead())
|
if (process.m_fds[process.m_fdBlockedOnRead].descriptor->has_data_available_for_reading())
|
||||||
process.unblock();
|
process.unblock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -167,9 +167,9 @@ void Scheduler::pick_next_and_switch_now()
|
||||||
|
|
||||||
void Scheduler::switch_now()
|
void Scheduler::switch_now()
|
||||||
{
|
{
|
||||||
Descriptor& descriptor = getGDTEntry(current->selector());
|
Descriptor& descriptor = get_gdt_entry(current->selector());
|
||||||
descriptor.type = 9;
|
descriptor.type = 9;
|
||||||
flushGDT();
|
flush_gdt();
|
||||||
asm("sti\n"
|
asm("sti\n"
|
||||||
"ljmp *(%%eax)\n"
|
"ljmp *(%%eax)\n"
|
||||||
::"a"(¤t->farPtr())
|
::"a"(¤t->farPtr())
|
||||||
|
@ -204,7 +204,7 @@ bool Scheduler::context_switch(Process& process)
|
||||||
|
|
||||||
if (!process.selector()) {
|
if (!process.selector()) {
|
||||||
process.setSelector(gdt_alloc_entry());
|
process.setSelector(gdt_alloc_entry());
|
||||||
auto& descriptor = getGDTEntry(process.selector());
|
auto& descriptor = get_gdt_entry(process.selector());
|
||||||
descriptor.setBase(&process.tss());
|
descriptor.setBase(&process.tss());
|
||||||
descriptor.setLimit(0xffff);
|
descriptor.setLimit(0xffff);
|
||||||
descriptor.dpl = 0;
|
descriptor.dpl = 0;
|
||||||
|
@ -215,9 +215,9 @@ bool Scheduler::context_switch(Process& process)
|
||||||
descriptor.descriptor_type = 0;
|
descriptor.descriptor_type = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& descriptor = getGDTEntry(process.selector());
|
auto& descriptor = get_gdt_entry(process.selector());
|
||||||
descriptor.type = 11; // Busy TSS
|
descriptor.type = 11; // Busy TSS
|
||||||
flushGDT();
|
flush_gdt();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ int sched_yield()
|
||||||
|
|
||||||
static void initialize_redirection()
|
static void initialize_redirection()
|
||||||
{
|
{
|
||||||
auto& descriptor = getGDTEntry(s_redirection.selector);
|
auto& descriptor = get_gdt_entry(s_redirection.selector);
|
||||||
descriptor.setBase(&s_redirection.tss);
|
descriptor.setBase(&s_redirection.tss);
|
||||||
descriptor.setLimit(0xffff);
|
descriptor.setLimit(0xffff);
|
||||||
descriptor.dpl = 0;
|
descriptor.dpl = 0;
|
||||||
|
@ -238,12 +238,12 @@ static void initialize_redirection()
|
||||||
descriptor.operation_size = 1;
|
descriptor.operation_size = 1;
|
||||||
descriptor.descriptor_type = 0;
|
descriptor.descriptor_type = 0;
|
||||||
descriptor.type = 9;
|
descriptor.type = 9;
|
||||||
flushGDT();
|
flush_gdt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::prepare_for_iret_to_new_process()
|
void Scheduler::prepare_for_iret_to_new_process()
|
||||||
{
|
{
|
||||||
auto& descriptor = getGDTEntry(s_redirection.selector);
|
auto& descriptor = get_gdt_entry(s_redirection.selector);
|
||||||
descriptor.type = 9;
|
descriptor.type = 9;
|
||||||
s_redirection.tss.backlink = current->selector();
|
s_redirection.tss.backlink = current->selector();
|
||||||
load_task_register(s_redirection.selector);
|
load_task_register(s_redirection.selector);
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace Syscall {
|
||||||
|
|
||||||
void initialize()
|
void initialize()
|
||||||
{
|
{
|
||||||
registerUserCallableInterruptHandler(0x80, syscall_ISR);
|
register_user_callable_interrupt_handler(0x80, syscall_ISR);
|
||||||
kprintf("syscall: int 0x80 handler installed\n");
|
kprintf("syscall: int 0x80 handler installed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,11 +55,11 @@ ssize_t TTY::write(const byte* buffer, size_t size)
|
||||||
#ifdef TTY_DEBUG
|
#ifdef TTY_DEBUG
|
||||||
dbgprintf("TTY::write %b {%u}\n", buffer[0], size);
|
dbgprintf("TTY::write %b {%u}\n", buffer[0], size);
|
||||||
#endif
|
#endif
|
||||||
onTTYWrite(buffer, size);
|
on_tty_write(buffer, size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TTY::hasDataAvailableForRead() const
|
bool TTY::has_data_available_for_reading() const
|
||||||
{
|
{
|
||||||
return !m_buffer.is_empty();
|
return !m_buffer.is_empty();
|
||||||
}
|
}
|
||||||
|
@ -68,12 +68,12 @@ void TTY::emit(byte ch)
|
||||||
{
|
{
|
||||||
if (should_generate_signals()) {
|
if (should_generate_signals()) {
|
||||||
if (ch == m_termios.c_cc[VINTR]) {
|
if (ch == m_termios.c_cc[VINTR]) {
|
||||||
dbgprintf("%s: VINTR pressed!\n", ttyName().characters());
|
dbgprintf("%s: VINTR pressed!\n", tty_name().characters());
|
||||||
generate_signal(SIGINT);
|
generate_signal(SIGINT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ch == m_termios.c_cc[VQUIT]) {
|
if (ch == m_termios.c_cc[VQUIT]) {
|
||||||
dbgprintf("%s: VQUIT pressed!\n", ttyName().characters());
|
dbgprintf("%s: VQUIT pressed!\n", tty_name().characters());
|
||||||
generate_signal(SIGQUIT);
|
generate_signal(SIGQUIT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -85,10 +85,10 @@ void TTY::generate_signal(int signal)
|
||||||
{
|
{
|
||||||
if (!pgid())
|
if (!pgid())
|
||||||
return;
|
return;
|
||||||
dbgprintf("%s: Send signal %d to everyone in pgrp %d\n", ttyName().characters(), signal, pgid());
|
dbgprintf("%s: Send signal %d to everyone in pgrp %d\n", tty_name().characters(), signal, pgid());
|
||||||
InterruptDisabler disabler; // FIXME: Iterate over a set of process handles instead?
|
InterruptDisabler disabler; // FIXME: Iterate over a set of process handles instead?
|
||||||
Process::for_each_in_pgrp(pgid(), [&] (auto& process) {
|
Process::for_each_in_pgrp(pgid(), [&] (auto& process) {
|
||||||
dbgprintf("%s: Send signal %d to %d\n", ttyName().characters(), signal, process.pid());
|
dbgprintf("%s: Send signal %d to %d\n", tty_name().characters(), signal, process.pid());
|
||||||
process.send_signal(signal, nullptr);
|
process.send_signal(signal, nullptr);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -98,7 +98,7 @@ void TTY::set_termios(const Unix::termios& t)
|
||||||
{
|
{
|
||||||
m_termios = t;
|
m_termios = t;
|
||||||
dbgprintf("%s set_termios: IECHO? %u, ISIG? %u, ICANON? %u\n",
|
dbgprintf("%s set_termios: IECHO? %u, ISIG? %u, ICANON? %u\n",
|
||||||
ttyName().characters(),
|
tty_name().characters(),
|
||||||
should_echo_input(),
|
should_echo_input(),
|
||||||
should_generate_signals(),
|
should_generate_signals(),
|
||||||
in_canonical_mode()
|
in_canonical_mode()
|
||||||
|
|
|
@ -34,10 +34,10 @@ public:
|
||||||
|
|
||||||
virtual ssize_t read(byte*, size_t) override;
|
virtual ssize_t read(byte*, size_t) override;
|
||||||
virtual ssize_t write(const byte*, size_t) override;
|
virtual ssize_t write(const byte*, size_t) override;
|
||||||
virtual bool hasDataAvailableForRead() const override;
|
virtual bool has_data_available_for_reading() const override;
|
||||||
virtual int ioctl(Process&, unsigned request, unsigned arg) override final;
|
virtual int ioctl(Process&, unsigned request, unsigned arg) override final;
|
||||||
|
|
||||||
virtual String ttyName() const = 0;
|
virtual String tty_name() const = 0;
|
||||||
|
|
||||||
unsigned short rows() const { return m_rows; }
|
unsigned short rows() const { return m_rows; }
|
||||||
unsigned short columns() const { return m_columns; }
|
unsigned short columns() const { return m_columns; }
|
||||||
|
@ -52,7 +52,7 @@ public:
|
||||||
bool in_canonical_mode() const { return m_termios.c_lflag & ICANON; }
|
bool in_canonical_mode() const { return m_termios.c_lflag & ICANON; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void onTTYWrite(const byte*, size_t) = 0;
|
virtual void on_tty_write(const byte*, size_t) = 0;
|
||||||
void set_size(unsigned short columns, unsigned short rows);
|
void set_size(unsigned short columns, unsigned short rows);
|
||||||
|
|
||||||
TTY(unsigned major, unsigned minor);
|
TTY(unsigned major, unsigned minor);
|
||||||
|
@ -60,7 +60,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual bool isTTY() const final override { return true; }
|
virtual bool is_tty() const final override { return true; }
|
||||||
|
|
||||||
void generate_signal(int signal);
|
void generate_signal(int signal);
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ void VirtualConsole::set_active(bool b)
|
||||||
set_vga_start_row(0);
|
set_vga_start_row(0);
|
||||||
flush_vga_cursor();
|
flush_vga_cursor();
|
||||||
|
|
||||||
Keyboard::the().setClient(this);
|
Keyboard::the().set_client(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool is_valid_parameter_character(byte ch)
|
inline bool is_valid_parameter_character(byte ch)
|
||||||
|
@ -441,7 +441,7 @@ void VirtualConsole::on_char(byte ch)
|
||||||
set_cursor(m_cursor_row, m_cursor_column);
|
set_cursor(m_cursor_row, m_cursor_column);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualConsole::onKeyPress(Keyboard::Key key)
|
void VirtualConsole::on_key_pressed(Keyboard::Key key)
|
||||||
{
|
{
|
||||||
if (key.ctrl()) {
|
if (key.ctrl()) {
|
||||||
if (key.character >= 'a' && key.character <= 'z') {
|
if (key.character >= 'a' && key.character <= 'z') {
|
||||||
|
@ -455,7 +455,7 @@ void VirtualConsole::onKeyPress(Keyboard::Key key)
|
||||||
emit(key.character);
|
emit(key.character);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualConsole::onConsoleReceive(byte ch)
|
void VirtualConsole::on_sysconsole_receive(byte ch)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
auto old_attribute = m_current_attribute;
|
auto old_attribute = m_current_attribute;
|
||||||
|
@ -464,14 +464,14 @@ void VirtualConsole::onConsoleReceive(byte ch)
|
||||||
m_current_attribute = old_attribute;
|
m_current_attribute = old_attribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualConsole::onTTYWrite(const byte* data, size_t size)
|
void VirtualConsole::on_tty_write(const byte* data, size_t size)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
for (size_t i = 0; i < size; ++i)
|
for (size_t i = 0; i < size; ++i)
|
||||||
on_char(data[i]);
|
on_char(data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
String VirtualConsole::ttyName() const
|
String VirtualConsole::tty_name() const
|
||||||
{
|
{
|
||||||
char buf[16];
|
char buf[16];
|
||||||
ksprintf(buf, "/dev/tty%u", m_index);
|
ksprintf(buf, "/dev/tty%u", m_index);
|
||||||
|
|
|
@ -17,14 +17,14 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^KeyboardClient
|
// ^KeyboardClient
|
||||||
virtual void onKeyPress(Keyboard::Key) override;
|
virtual void on_key_pressed(Keyboard::Key) override;
|
||||||
|
|
||||||
// ^ConsoleImplementation
|
// ^ConsoleImplementation
|
||||||
virtual void onConsoleReceive(byte) override;
|
virtual void on_sysconsole_receive(byte) override;
|
||||||
|
|
||||||
// ^TTY
|
// ^TTY
|
||||||
virtual void onTTYWrite(const byte*, size_t) override;
|
virtual void on_tty_write(const byte*, size_t) override;
|
||||||
virtual String ttyName() const override;
|
virtual String tty_name() const override;
|
||||||
|
|
||||||
void set_active(bool);
|
void set_active(bool);
|
||||||
void on_char(byte);
|
void on_char(byte);
|
||||||
|
|
|
@ -297,18 +297,18 @@ static void writeRawGDTEntry(word selector, dword low, dword high)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeGDTEntry(word selector, Descriptor& descriptor)
|
void write_gdt_entry(word selector, Descriptor& descriptor)
|
||||||
{
|
{
|
||||||
writeRawGDTEntry(selector, descriptor.low, descriptor.high);
|
writeRawGDTEntry(selector, descriptor.low, descriptor.high);
|
||||||
}
|
}
|
||||||
|
|
||||||
Descriptor& getGDTEntry(word selector)
|
Descriptor& get_gdt_entry(word selector)
|
||||||
{
|
{
|
||||||
word i = (selector & 0xfffc) >> 3;
|
word i = (selector & 0xfffc) >> 3;
|
||||||
return *(Descriptor*)(&s_gdt[i]);
|
return *(Descriptor*)(&s_gdt[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void flushGDT()
|
void flush_gdt()
|
||||||
{
|
{
|
||||||
s_gdtr.address = s_gdt;
|
s_gdtr.address = s_gdt;
|
||||||
s_gdtr.size = (s_gdtLength * 8) - 1;
|
s_gdtr.size = (s_gdtLength * 8) - 1;
|
||||||
|
@ -335,7 +335,7 @@ void gdt_init()
|
||||||
writeRawGDTEntry(0x0018, 0x0000ffff, 0x00cffa00);
|
writeRawGDTEntry(0x0018, 0x0000ffff, 0x00cffa00);
|
||||||
writeRawGDTEntry(0x0020, 0x0000ffff, 0x00cff200);
|
writeRawGDTEntry(0x0020, 0x0000ffff, 0x00cff200);
|
||||||
|
|
||||||
flushGDT();
|
flush_gdt();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unimp_trap()
|
static void unimp_trap()
|
||||||
|
@ -344,34 +344,34 @@ static void unimp_trap()
|
||||||
HANG;
|
HANG;
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerIRQHandler(byte irq, IRQHandler& handler)
|
void register_irq_handler(byte irq, IRQHandler& handler)
|
||||||
{
|
{
|
||||||
ASSERT(!s_irqHandler[irq]);
|
ASSERT(!s_irqHandler[irq]);
|
||||||
s_irqHandler[irq] = &handler;
|
s_irqHandler[irq] = &handler;
|
||||||
registerInterruptHandler(IRQ_VECTOR_BASE + irq, asm_irq_entry);
|
register_interrupt_handler(IRQ_VECTOR_BASE + irq, asm_irq_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregisterIRQHandler(byte irq, IRQHandler& handler)
|
void unregister_irq_handler(byte irq, IRQHandler& handler)
|
||||||
{
|
{
|
||||||
ASSERT(s_irqHandler[irq] == &handler);
|
ASSERT(s_irqHandler[irq] == &handler);
|
||||||
s_irqHandler[irq] = nullptr;
|
s_irqHandler[irq] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerInterruptHandler(byte index, void (*f)())
|
void register_interrupt_handler(byte index, void (*f)())
|
||||||
{
|
{
|
||||||
s_idt[index].low = 0x00080000 | LSW((f));
|
s_idt[index].low = 0x00080000 | LSW((f));
|
||||||
s_idt[index].high = ((dword)(f) & 0xffff0000) | 0x8e00;
|
s_idt[index].high = ((dword)(f) & 0xffff0000) | 0x8e00;
|
||||||
flushIDT();
|
flush_idt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerUserCallableInterruptHandler(byte index, void (*f)())
|
void register_user_callable_interrupt_handler(byte index, void (*f)())
|
||||||
{
|
{
|
||||||
s_idt[index].low = 0x00080000 | LSW((f));
|
s_idt[index].low = 0x00080000 | LSW((f));
|
||||||
s_idt[index].high = ((dword)(f) & 0xffff0000) | 0xef00;
|
s_idt[index].high = ((dword)(f) & 0xffff0000) | 0xef00;
|
||||||
flushIDT();
|
flush_idt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void flushIDT()
|
void flush_idt()
|
||||||
{
|
{
|
||||||
asm("lidt %0"::"m"(s_idtr));
|
asm("lidt %0"::"m"(s_idtr));
|
||||||
}
|
}
|
||||||
|
@ -396,34 +396,34 @@ void idt_init()
|
||||||
s_idtr.size = 0x100 * 8;
|
s_idtr.size = 0x100 * 8;
|
||||||
|
|
||||||
for (byte i = 0xff; i > 0x10; --i)
|
for (byte i = 0xff; i > 0x10; --i)
|
||||||
registerInterruptHandler(i, unimp_trap);
|
register_interrupt_handler(i, unimp_trap);
|
||||||
|
|
||||||
registerInterruptHandler(0x00, _exception0);
|
register_interrupt_handler(0x00, _exception0);
|
||||||
registerInterruptHandler(0x01, _exception1);
|
register_interrupt_handler(0x01, _exception1);
|
||||||
registerInterruptHandler(0x02, _exception2);
|
register_interrupt_handler(0x02, _exception2);
|
||||||
registerInterruptHandler(0x03, _exception3);
|
register_interrupt_handler(0x03, _exception3);
|
||||||
registerInterruptHandler(0x04, _exception4);
|
register_interrupt_handler(0x04, _exception4);
|
||||||
registerInterruptHandler(0x05, _exception5);
|
register_interrupt_handler(0x05, _exception5);
|
||||||
registerInterruptHandler(0x06, exception_6_entry);
|
register_interrupt_handler(0x06, exception_6_entry);
|
||||||
registerInterruptHandler(0x07, _exception7);
|
register_interrupt_handler(0x07, _exception7);
|
||||||
registerInterruptHandler(0x08, _exception8);
|
register_interrupt_handler(0x08, _exception8);
|
||||||
registerInterruptHandler(0x09, _exception9);
|
register_interrupt_handler(0x09, _exception9);
|
||||||
registerInterruptHandler(0x0a, _exception10);
|
register_interrupt_handler(0x0a, _exception10);
|
||||||
registerInterruptHandler(0x0b, _exception11);
|
register_interrupt_handler(0x0b, _exception11);
|
||||||
registerInterruptHandler(0x0c, _exception12);
|
register_interrupt_handler(0x0c, _exception12);
|
||||||
registerInterruptHandler(0x0d, exception_13_entry);
|
register_interrupt_handler(0x0d, exception_13_entry);
|
||||||
registerInterruptHandler(0x0e, exception_14_entry);
|
register_interrupt_handler(0x0e, exception_14_entry);
|
||||||
registerInterruptHandler(0x0f, _exception15);
|
register_interrupt_handler(0x0f, _exception15);
|
||||||
registerInterruptHandler(0x10, _exception16);
|
register_interrupt_handler(0x10, _exception16);
|
||||||
|
|
||||||
registerInterruptHandler(0x57, irq7_handler);
|
register_interrupt_handler(0x57, irq7_handler);
|
||||||
|
|
||||||
s_irqHandler = static_cast<IRQHandler**>(kmalloc_eternal(sizeof(IRQHandler*) * 16));
|
s_irqHandler = static_cast<IRQHandler**>(kmalloc_eternal(sizeof(IRQHandler*) * 16));
|
||||||
for (byte i = 0; i < 16; ++i) {
|
for (byte i = 0; i < 16; ++i) {
|
||||||
s_irqHandler[i] = nullptr;
|
s_irqHandler[i] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
flushIDT();
|
flush_idt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_task_register(word selector)
|
void load_task_register(word selector)
|
||||||
|
@ -450,7 +450,7 @@ void handle_irq()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_irqHandler[irq])
|
if (s_irqHandler[irq])
|
||||||
s_irqHandler[irq]->handleIRQ();
|
s_irqHandler[irq]->handle_irq();
|
||||||
PIC::eoi(irq);
|
PIC::eoi(irq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,17 +61,17 @@ class IRQHandler;
|
||||||
|
|
||||||
void gdt_init();
|
void gdt_init();
|
||||||
void idt_init();
|
void idt_init();
|
||||||
void registerInterruptHandler(byte number, void (*f)());
|
void register_interrupt_handler(byte number, void (*f)());
|
||||||
void registerUserCallableInterruptHandler(byte number, void (*f)());
|
void register_user_callable_interrupt_handler(byte number, void (*f)());
|
||||||
void registerIRQHandler(byte number, IRQHandler&);
|
void register_irq_handler(byte number, IRQHandler&);
|
||||||
void unregisterIRQHandler(byte number, IRQHandler&);
|
void unregister_irq_handler(byte number, IRQHandler&);
|
||||||
void flushIDT();
|
void flush_idt();
|
||||||
void flushGDT();
|
void flush_gdt();
|
||||||
void load_task_register(word selector);
|
void load_task_register(word selector);
|
||||||
word gdt_alloc_entry();
|
word gdt_alloc_entry();
|
||||||
void gdt_free_entry(word);
|
void gdt_free_entry(word);
|
||||||
Descriptor& getGDTEntry(word selector);
|
Descriptor& get_gdt_entry(word selector);
|
||||||
void writeGDTEntry(word selector, Descriptor&);
|
void write_gdt_entry(word selector, Descriptor&);
|
||||||
|
|
||||||
#define HANG asm volatile( "cli; hlt" );
|
#define HANG asm volatile( "cli; hlt" );
|
||||||
#define LSW(x) ((dword)(x) & 0xFFFF)
|
#define LSW(x) ((dword)(x) & 0xFFFF)
|
||||||
|
@ -82,7 +82,7 @@ void writeGDTEntry(word selector, Descriptor&);
|
||||||
#define cli() asm volatile("cli")
|
#define cli() asm volatile("cli")
|
||||||
#define sti() asm volatile("sti")
|
#define sti() asm volatile("sti")
|
||||||
|
|
||||||
static inline dword cpuFlags()
|
static inline dword cpu_flags()
|
||||||
{
|
{
|
||||||
dword flags;
|
dword flags;
|
||||||
asm volatile(
|
asm volatile(
|
||||||
|
@ -95,14 +95,14 @@ static inline dword cpuFlags()
|
||||||
|
|
||||||
inline bool are_interrupts_enabled()
|
inline bool are_interrupts_enabled()
|
||||||
{
|
{
|
||||||
return cpuFlags() & 0x200;
|
return cpu_flags() & 0x200;
|
||||||
}
|
}
|
||||||
|
|
||||||
class InterruptDisabler {
|
class InterruptDisabler {
|
||||||
public:
|
public:
|
||||||
InterruptDisabler()
|
InterruptDisabler()
|
||||||
{
|
{
|
||||||
m_flags = cpuFlags();
|
m_flags = cpu_flags();
|
||||||
cli();
|
cli();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ void initialize()
|
||||||
IO::out8(TIMER0_CTL, LSB(timer_reload));
|
IO::out8(TIMER0_CTL, LSB(timer_reload));
|
||||||
IO::out8(TIMER0_CTL, MSB(timer_reload));
|
IO::out8(TIMER0_CTL, MSB(timer_reload));
|
||||||
|
|
||||||
registerInterruptHandler(IRQ_VECTOR_BASE + IRQ_TIMER, tick_ISR);
|
register_interrupt_handler(IRQ_VECTOR_BASE + IRQ_TIMER, tick_ISR);
|
||||||
|
|
||||||
PIC::enable(IRQ_TIMER);
|
PIC::enable(IRQ_TIMER);
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,7 +207,7 @@ static void init_stage2()
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
kprintf("Failed to open /kernel.map\n");
|
kprintf("Failed to open /kernel.map\n");
|
||||||
} else {
|
} else {
|
||||||
auto buffer = descriptor->readEntireFile();
|
auto buffer = descriptor->read_entire_file();
|
||||||
ASSERT(buffer);
|
ASSERT(buffer);
|
||||||
loadKsyms(buffer);
|
loadKsyms(buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,5 @@ void __assertion_failed(const char* msg, const char* file, unsigned line, const
|
||||||
#define CRASH() do { asm volatile("ud2"); } while(0)
|
#define CRASH() do { asm volatile("ud2"); } while(0)
|
||||||
#define RELEASE_ASSERT(x) do { if (!(x)) CRASH(); } while(0)
|
#define RELEASE_ASSERT(x) do { if (!(x)) CRASH(); } while(0)
|
||||||
#define ASSERT_NOT_REACHED() ASSERT(false)
|
#define ASSERT_NOT_REACHED() ASSERT(false)
|
||||||
#define ASSERT_INTERRUPTS_DISABLED() ASSERT(!(cpuFlags() & 0x200))
|
#define ASSERT_INTERRUPTS_DISABLED() ASSERT(!(cpu_flags() & 0x200))
|
||||||
#define ASSERT_INTERRUPTS_ENABLED() ASSERT(cpuFlags() & 0x200)
|
#define ASSERT_INTERRUPTS_ENABLED() ASSERT(cpu_flags() & 0x200)
|
||||||
|
|
|
@ -12,7 +12,7 @@ public:
|
||||||
|
|
||||||
RetainPtr<FileDescriptor> open(int options);
|
RetainPtr<FileDescriptor> open(int options);
|
||||||
|
|
||||||
virtual bool hasDataAvailableForRead() const = 0;
|
virtual bool has_data_available_for_reading() const = 0;
|
||||||
|
|
||||||
virtual ssize_t read(byte* buffer, size_t bufferSize) = 0;
|
virtual ssize_t read(byte* buffer, size_t bufferSize) = 0;
|
||||||
virtual ssize_t write(const byte* buffer, size_t bufferSize) = 0;
|
virtual ssize_t write(const byte* buffer, size_t bufferSize) = 0;
|
||||||
|
@ -20,7 +20,7 @@ public:
|
||||||
unsigned major() const { return m_major; }
|
unsigned major() const { return m_major; }
|
||||||
unsigned minor() const { return m_minor; }
|
unsigned minor() const { return m_minor; }
|
||||||
|
|
||||||
virtual bool isTTY() const { return false; }
|
virtual bool is_tty() const { return false; }
|
||||||
|
|
||||||
virtual int ioctl(Process&, unsigned request, unsigned arg);
|
virtual int ioctl(Process&, unsigned request, unsigned arg);
|
||||||
|
|
||||||
|
|
|
@ -48,9 +48,9 @@ RetainPtr<FileDescriptor> FileDescriptor::clone()
|
||||||
}
|
}
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
descriptor->m_currentOffset = m_currentOffset;
|
descriptor->m_current_offset = m_current_offset;
|
||||||
#ifdef SERENITY
|
#ifdef SERENITY
|
||||||
descriptor->m_isBlocking = m_isBlocking;
|
descriptor->m_is_blocking = m_is_blocking;
|
||||||
descriptor->m_file_flags = m_file_flags;
|
descriptor->m_file_flags = m_file_flags;
|
||||||
#endif
|
#endif
|
||||||
return descriptor;
|
return descriptor;
|
||||||
|
@ -113,7 +113,7 @@ Unix::off_t FileDescriptor::seek(Unix::off_t offset, int whence)
|
||||||
newOffset = offset;
|
newOffset = offset;
|
||||||
break;
|
break;
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
newOffset = m_currentOffset + offset;
|
newOffset = m_current_offset + offset;
|
||||||
#ifndef SERENITY
|
#ifndef SERENITY
|
||||||
if (additionWouldOverflow(m_currentOffset, offset))
|
if (additionWouldOverflow(m_currentOffset, offset))
|
||||||
return -EOVERFLOW;
|
return -EOVERFLOW;
|
||||||
|
@ -129,8 +129,8 @@ Unix::off_t FileDescriptor::seek(Unix::off_t offset, int whence)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_currentOffset = newOffset;
|
m_current_offset = newOffset;
|
||||||
return m_currentOffset;
|
return m_current_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FileDescriptor::read(byte* buffer, size_t count)
|
ssize_t FileDescriptor::read(byte* buffer, size_t count)
|
||||||
|
@ -143,8 +143,8 @@ ssize_t FileDescriptor::read(byte* buffer, size_t count)
|
||||||
// FIXME: What should happen to m_currentOffset?
|
// FIXME: What should happen to m_currentOffset?
|
||||||
return m_vnode->characterDevice()->read(buffer, count);
|
return m_vnode->characterDevice()->read(buffer, count);
|
||||||
}
|
}
|
||||||
ssize_t nread = m_vnode->fileSystem()->read_inode_bytes(m_vnode->inode, m_currentOffset, count, buffer, this);
|
ssize_t nread = m_vnode->fileSystem()->read_inode_bytes(m_vnode->inode, m_current_offset, count, buffer, this);
|
||||||
m_currentOffset += nread;
|
m_current_offset += nread;
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,18 +172,18 @@ bool FileDescriptor::can_write()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDescriptor::hasDataAvailableForRead()
|
bool FileDescriptor::has_data_available_for_reading()
|
||||||
{
|
{
|
||||||
if (is_fifo()) {
|
if (is_fifo()) {
|
||||||
ASSERT(fifo_direction() == FIFO::Reader);
|
ASSERT(fifo_direction() == FIFO::Reader);
|
||||||
return m_fifo->can_read();
|
return m_fifo->can_read();
|
||||||
}
|
}
|
||||||
if (m_vnode->isCharacterDevice())
|
if (m_vnode->isCharacterDevice())
|
||||||
return m_vnode->characterDevice()->hasDataAvailableForRead();
|
return m_vnode->characterDevice()->has_data_available_for_reading();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer FileDescriptor::readEntireFile()
|
ByteBuffer FileDescriptor::read_entire_file()
|
||||||
{
|
{
|
||||||
ASSERT(!is_fifo());
|
ASSERT(!is_fifo());
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ ByteBuffer FileDescriptor::readEntireFile()
|
||||||
return m_vnode->fileSystem()->read_entire_inode(m_vnode->inode, this);
|
return m_vnode->fileSystem()->read_entire_inode(m_vnode->inode, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDescriptor::isDirectory() const
|
bool FileDescriptor::is_directory() const
|
||||||
{
|
{
|
||||||
ASSERT(!is_fifo());
|
ASSERT(!is_fifo());
|
||||||
return m_vnode->metadata().isDirectory();
|
return m_vnode->metadata().isDirectory();
|
||||||
|
@ -232,12 +232,12 @@ ssize_t FileDescriptor::get_dir_entries(byte* buffer, size_t size)
|
||||||
}
|
}
|
||||||
\
|
\
|
||||||
#ifdef SERENITY
|
#ifdef SERENITY
|
||||||
bool FileDescriptor::isTTY() const
|
bool FileDescriptor::is_tty() const
|
||||||
{
|
{
|
||||||
if (is_fifo())
|
if (is_fifo())
|
||||||
return false;
|
return false;
|
||||||
if (auto* device = m_vnode->characterDevice())
|
if (auto* device = m_vnode->characterDevice())
|
||||||
return device->isTTY();
|
return device->is_tty();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,8 +269,8 @@ String FileDescriptor::absolute_path()
|
||||||
{
|
{
|
||||||
Stopwatch sw("absolute_path");
|
Stopwatch sw("absolute_path");
|
||||||
#ifdef SERENITY
|
#ifdef SERENITY
|
||||||
if (isTTY())
|
if (is_tty())
|
||||||
return tty()->ttyName();
|
return tty()->tty_name();
|
||||||
#endif
|
#endif
|
||||||
if (is_fifo()) {
|
if (is_fifo()) {
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
@ -282,7 +282,7 @@ String FileDescriptor::absolute_path()
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDescriptor::FileDescriptor(FIFO& fifo, FIFO::Direction direction)
|
FileDescriptor::FileDescriptor(FIFO& fifo, FIFO::Direction direction)
|
||||||
: m_isBlocking(true)
|
: m_is_blocking(true)
|
||||||
, m_fifo(fifo)
|
, m_fifo(fifo)
|
||||||
, m_fifo_direction(direction)
|
, m_fifo_direction(direction)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,22 +27,22 @@ public:
|
||||||
ssize_t write(const byte* data, size_t);
|
ssize_t write(const byte* data, size_t);
|
||||||
int stat(Unix::stat*);
|
int stat(Unix::stat*);
|
||||||
|
|
||||||
bool hasDataAvailableForRead();
|
bool has_data_available_for_reading();
|
||||||
bool can_write();
|
bool can_write();
|
||||||
|
|
||||||
ssize_t get_dir_entries(byte* buffer, size_t);
|
ssize_t get_dir_entries(byte* buffer, size_t);
|
||||||
|
|
||||||
ByteBuffer readEntireFile();
|
ByteBuffer read_entire_file();
|
||||||
|
|
||||||
String absolute_path();
|
String absolute_path();
|
||||||
|
|
||||||
bool isDirectory() const;
|
bool is_directory() const;
|
||||||
|
|
||||||
bool is_character_device() const { return m_vnode && m_vnode->isCharacterDevice(); }
|
bool is_character_device() const { return m_vnode && m_vnode->isCharacterDevice(); }
|
||||||
CharacterDevice* character_device() { return m_vnode ? m_vnode->characterDevice() : nullptr; }
|
CharacterDevice* character_device() { return m_vnode ? m_vnode->characterDevice() : nullptr; }
|
||||||
|
|
||||||
#ifdef SERENITY
|
#ifdef SERENITY
|
||||||
bool isTTY() const;
|
bool is_tty() const;
|
||||||
const TTY* tty() const;
|
const TTY* tty() const;
|
||||||
TTY* tty();
|
TTY* tty();
|
||||||
#endif
|
#endif
|
||||||
|
@ -52,8 +52,8 @@ public:
|
||||||
Vnode* vnode() { return m_vnode.ptr(); }
|
Vnode* vnode() { return m_vnode.ptr(); }
|
||||||
|
|
||||||
#ifdef SERENITY
|
#ifdef SERENITY
|
||||||
bool isBlocking() const { return m_isBlocking; }
|
bool is_blocking() const { return m_is_blocking; }
|
||||||
void setBlocking(bool b) { m_isBlocking = b; }
|
void set_blocking(bool b) { m_is_blocking = b; }
|
||||||
|
|
||||||
dword file_flags() const { return m_file_flags; }
|
dword file_flags() const { return m_file_flags; }
|
||||||
void set_file_flags(dword flags) { m_file_flags = flags; }
|
void set_file_flags(dword flags) { m_file_flags = flags; }
|
||||||
|
@ -62,7 +62,7 @@ public:
|
||||||
FIFO::Direction fifo_direction() { return m_fifo_direction; }
|
FIFO::Direction fifo_direction() { return m_fifo_direction; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ByteBuffer& generatorCache() { return m_generatorCache; }
|
ByteBuffer& generator_cache() { return m_generator_cache; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class VFS;
|
friend class VFS;
|
||||||
|
@ -72,12 +72,12 @@ private:
|
||||||
RetainPtr<Vnode> m_vnode;
|
RetainPtr<Vnode> m_vnode;
|
||||||
RetainPtr<CoreInode> m_inode;
|
RetainPtr<CoreInode> m_inode;
|
||||||
|
|
||||||
Unix::off_t m_currentOffset { 0 };
|
Unix::off_t m_current_offset { 0 };
|
||||||
|
|
||||||
ByteBuffer m_generatorCache;
|
ByteBuffer m_generator_cache;
|
||||||
|
|
||||||
#ifdef SERENITY
|
#ifdef SERENITY
|
||||||
bool m_isBlocking { true };
|
bool m_is_blocking { true };
|
||||||
dword m_file_flags { 0 };
|
dword m_file_flags { 0 };
|
||||||
|
|
||||||
RetainPtr<FIFO> m_fifo;
|
RetainPtr<FIFO> m_fifo;
|
||||||
|
|
|
@ -13,7 +13,7 @@ FullDevice::~FullDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FullDevice::hasDataAvailableForRead() const
|
bool FullDevice::has_data_available_for_reading() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@ public:
|
||||||
|
|
||||||
virtual ssize_t read(byte* buffer, size_t bufferSize) override;
|
virtual ssize_t read(byte* buffer, size_t bufferSize) override;
|
||||||
virtual ssize_t write(const byte* buffer, size_t bufferSize) override;
|
virtual ssize_t write(const byte* buffer, size_t bufferSize) override;
|
||||||
virtual bool hasDataAvailableForRead() const override;
|
virtual bool has_data_available_for_reading() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ NullDevice::~NullDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NullDevice::hasDataAvailableForRead() const
|
bool NullDevice::has_data_available_for_reading() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@ public:
|
||||||
|
|
||||||
virtual ssize_t read(byte* buffer, size_t bufferSize) override;
|
virtual ssize_t read(byte* buffer, size_t bufferSize) override;
|
||||||
virtual ssize_t write(const byte* buffer, size_t bufferSize) override;
|
virtual ssize_t write(const byte* buffer, size_t bufferSize) override;
|
||||||
virtual bool hasDataAvailableForRead() const override;
|
virtual bool has_data_available_for_reading() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ static void mysrand(unsigned seed)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool RandomDevice::hasDataAvailableForRead() const
|
bool RandomDevice::has_data_available_for_reading() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@ public:
|
||||||
|
|
||||||
virtual ssize_t read(byte* buffer, size_t bufferSize) override;
|
virtual ssize_t read(byte* buffer, size_t bufferSize) override;
|
||||||
virtual ssize_t write(const byte* buffer, size_t bufferSize) override;
|
virtual ssize_t write(const byte* buffer, size_t bufferSize) override;
|
||||||
virtual bool hasDataAvailableForRead() const override;
|
virtual bool has_data_available_for_reading() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ bool SynthFS::initialize()
|
||||||
|
|
||||||
RetainPtr<SynthFSInode> SynthFS::create_directory(String&& name)
|
RetainPtr<SynthFSInode> SynthFS::create_directory(String&& name)
|
||||||
{
|
{
|
||||||
auto file = adopt(*new SynthFSInode(*this, generateInodeIndex()));
|
auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
|
||||||
file->m_name = move(name);
|
file->m_name = move(name);
|
||||||
file->m_metadata.size = 0;
|
file->m_metadata.size = 0;
|
||||||
file->m_metadata.uid = 0;
|
file->m_metadata.uid = 0;
|
||||||
|
@ -58,7 +58,7 @@ RetainPtr<SynthFSInode> SynthFS::create_directory(String&& name)
|
||||||
|
|
||||||
RetainPtr<SynthFSInode> SynthFS::create_text_file(String&& name, ByteBuffer&& contents, Unix::mode_t mode)
|
RetainPtr<SynthFSInode> SynthFS::create_text_file(String&& name, ByteBuffer&& contents, Unix::mode_t mode)
|
||||||
{
|
{
|
||||||
auto file = adopt(*new SynthFSInode(*this, generateInodeIndex()));
|
auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
|
||||||
file->m_data = contents;
|
file->m_data = contents;
|
||||||
file->m_name = move(name);
|
file->m_name = move(name);
|
||||||
file->m_metadata.size = file->m_data.size();
|
file->m_metadata.size = file->m_data.size();
|
||||||
|
@ -71,7 +71,7 @@ RetainPtr<SynthFSInode> SynthFS::create_text_file(String&& name, ByteBuffer&& co
|
||||||
|
|
||||||
RetainPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<ByteBuffer()>&& generator, Unix::mode_t mode)
|
RetainPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<ByteBuffer()>&& generator, Unix::mode_t mode)
|
||||||
{
|
{
|
||||||
auto file = adopt(*new SynthFSInode(*this, generateInodeIndex()));
|
auto file = adopt(*new SynthFSInode(*this, generate_inode_index()));
|
||||||
file->m_generator = move(generator);
|
file->m_generator = move(generator);
|
||||||
file->m_name = move(name);
|
file->m_name = move(name);
|
||||||
file->m_metadata.size = 0;
|
file->m_metadata.size = 0;
|
||||||
|
@ -82,7 +82,7 @@ RetainPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<B
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
InodeIdentifier SynthFS::addFile(RetainPtr<SynthFSInode>&& file, InodeIndex parent)
|
InodeIdentifier SynthFS::add_file(RetainPtr<SynthFSInode>&& file, InodeIndex parent)
|
||||||
{
|
{
|
||||||
ASSERT_INTERRUPTS_DISABLED();
|
ASSERT_INTERRUPTS_DISABLED();
|
||||||
ASSERT(file);
|
ASSERT(file);
|
||||||
|
@ -96,7 +96,7 @@ InodeIdentifier SynthFS::addFile(RetainPtr<SynthFSInode>&& file, InodeIndex pare
|
||||||
return new_inode_id;
|
return new_inode_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SynthFS::removeFile(InodeIndex inode)
|
bool SynthFS::remove_file(InodeIndex inode)
|
||||||
{
|
{
|
||||||
ASSERT_INTERRUPTS_DISABLED();
|
ASSERT_INTERRUPTS_DISABLED();
|
||||||
auto it = m_inodes.find(inode);
|
auto it = m_inodes.find(inode);
|
||||||
|
@ -117,7 +117,7 @@ bool SynthFS::removeFile(InodeIndex inode)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& child : file.m_children)
|
for (auto& child : file.m_children)
|
||||||
removeFile(child->m_metadata.inode.index());
|
remove_file(child->m_metadata.inode.index());
|
||||||
m_inodes.remove(inode);
|
m_inodes.remove(inode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -193,17 +193,17 @@ ssize_t SynthFS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset, siz
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
generatedData = file.m_generator();
|
generatedData = file.m_generator();
|
||||||
} else {
|
} else {
|
||||||
if (!handle->generatorCache())
|
if (!handle->generator_cache())
|
||||||
handle->generatorCache() = file.m_generator();
|
handle->generator_cache() = file.m_generator();
|
||||||
generatedData = handle->generatorCache();
|
generatedData = handle->generator_cache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* data = generatedData ? &generatedData : &file.m_data;
|
auto* data = generatedData ? &generatedData : &file.m_data;
|
||||||
ssize_t nread = min(static_cast<Unix::off_t>(data->size() - offset), static_cast<Unix::off_t>(count));
|
ssize_t nread = min(static_cast<Unix::off_t>(data->size() - offset), static_cast<Unix::off_t>(count));
|
||||||
memcpy(buffer, data->pointer() + offset, nread);
|
memcpy(buffer, data->pointer() + offset, nread);
|
||||||
if (nread == 0 && handle && handle->generatorCache())
|
if (nread == 0 && handle && handle->generator_cache())
|
||||||
handle->generatorCache().clear();
|
handle->generator_cache().clear();
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,9 +213,9 @@ InodeIdentifier SynthFS::create_directory(InodeIdentifier, const String&, Unix::
|
||||||
return { };
|
return { };
|
||||||
}
|
}
|
||||||
|
|
||||||
auto SynthFS::generateInodeIndex() -> InodeIndex
|
auto SynthFS::generate_inode_index() -> InodeIndex
|
||||||
{
|
{
|
||||||
return m_nextInodeIndex++;
|
return m_next_inode_index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
InodeIdentifier SynthFS::find_parent_of_inode(InodeIdentifier inode) const
|
InodeIdentifier SynthFS::find_parent_of_inode(InodeIdentifier inode) const
|
||||||
|
@ -262,17 +262,17 @@ ssize_t SynthFSInode::read_bytes(Unix::off_t offset, size_t count, byte* buffer,
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
generatedData = m_generator();
|
generatedData = m_generator();
|
||||||
} else {
|
} else {
|
||||||
if (!descriptor->generatorCache())
|
if (!descriptor->generator_cache())
|
||||||
descriptor->generatorCache() = m_generator();
|
descriptor->generator_cache() = m_generator();
|
||||||
generatedData = descriptor->generatorCache();
|
generatedData = descriptor->generator_cache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* data = generatedData ? &generatedData : &m_data;
|
auto* data = generatedData ? &generatedData : &m_data;
|
||||||
ssize_t nread = min(static_cast<Unix::off_t>(data->size() - offset), static_cast<Unix::off_t>(count));
|
ssize_t nread = min(static_cast<Unix::off_t>(data->size() - offset), static_cast<Unix::off_t>(count));
|
||||||
memcpy(buffer, data->pointer() + offset, nread);
|
memcpy(buffer, data->pointer() + offset, nread);
|
||||||
if (nread == 0 && descriptor && descriptor->generatorCache())
|
if (nread == 0 && descriptor && descriptor->generator_cache())
|
||||||
descriptor->generatorCache().clear();
|
descriptor->generator_cache().clear();
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
typedef unsigned InodeIndex;
|
typedef unsigned InodeIndex;
|
||||||
|
|
||||||
InodeIndex generateInodeIndex();
|
InodeIndex generate_inode_index();
|
||||||
static constexpr InodeIndex RootInodeIndex = 1;
|
static constexpr InodeIndex RootInodeIndex = 1;
|
||||||
|
|
||||||
SynthFS();
|
SynthFS();
|
||||||
|
@ -35,11 +35,11 @@ protected:
|
||||||
RetainPtr<SynthFSInode> create_text_file(String&& name, ByteBuffer&&, Unix::mode_t = 0010644);
|
RetainPtr<SynthFSInode> create_text_file(String&& name, ByteBuffer&&, Unix::mode_t = 0010644);
|
||||||
RetainPtr<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer()>&&, Unix::mode_t = 0100644);
|
RetainPtr<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer()>&&, Unix::mode_t = 0100644);
|
||||||
|
|
||||||
InodeIdentifier addFile(RetainPtr<SynthFSInode>&&, InodeIndex parent = RootInodeIndex);
|
InodeIdentifier add_file(RetainPtr<SynthFSInode>&&, InodeIndex parent = RootInodeIndex);
|
||||||
bool removeFile(InodeIndex);
|
bool remove_file(InodeIndex);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
InodeIndex m_nextInodeIndex { 2 };
|
InodeIndex m_next_inode_index { 2 };
|
||||||
HashMap<InodeIndex, RetainPtr<SynthFSInode>> m_inodes;
|
HashMap<InodeIndex, RetainPtr<SynthFSInode>> m_inodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ ZeroDevice::~ZeroDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZeroDevice::hasDataAvailableForRead() const
|
bool ZeroDevice::has_data_available_for_reading() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@ public:
|
||||||
|
|
||||||
virtual ssize_t read(byte* buffer, size_t bufferSize) override;
|
virtual ssize_t read(byte* buffer, size_t bufferSize) override;
|
||||||
virtual ssize_t write(const byte* buffer, size_t bufferSize) override;
|
virtual ssize_t write(const byte* buffer, size_t bufferSize) override;
|
||||||
virtual bool hasDataAvailableForRead() const override;
|
virtual bool has_data_available_for_reading() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ int main(int c, char** v)
|
||||||
printf("failed to open %s inside fs image\n", v[2]);
|
printf("failed to open %s inside fs image\n", v[2]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
auto contents = descriptor->readEntireFile();
|
auto contents = descriptor->read_entire_file();
|
||||||
|
|
||||||
FILE* fout = fopen(v[3], "w");
|
FILE* fout = fopen(v[3], "w");
|
||||||
if (!fout) {
|
if (!fout) {
|
||||||
|
@ -142,7 +142,7 @@ int main(int c, char** v)
|
||||||
}
|
}
|
||||||
int error;
|
int error;
|
||||||
auto new_cwd = vfs.open(new_path.string(), error, 0, cwd);
|
auto new_cwd = vfs.open(new_path.string(), error, 0, cwd);
|
||||||
if (new_cwd && new_cwd->isDirectory()) {
|
if (new_cwd && new_cwd->is_directory()) {
|
||||||
currentDirectory = new_path.string();
|
currentDirectory = new_path.string();
|
||||||
cwd = new_cwd->metadata().inode;
|
cwd = new_cwd->metadata().inode;
|
||||||
} else {
|
} else {
|
||||||
|
@ -198,7 +198,7 @@ int main(int c, char** v)
|
||||||
printf("failed to open %s\n", pathbuf);
|
printf("failed to open %s\n", pathbuf);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto contents = descriptor->readEntireFile();
|
auto contents = descriptor->read_entire_file();
|
||||||
fwrite(contents.pointer(), sizeof(char), contents.size(), stdout);
|
fwrite(contents.pointer(), sizeof(char), contents.size(), stdout);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue