forked from Bananymous/banan-os
Kernel: Device dev and rdev number is done more properly
Also hd* partitions are now 1 indexed instead of 0
This commit is contained in:
@@ -7,6 +7,7 @@ namespace Kernel
|
||||
|
||||
Device::Device()
|
||||
: m_create_time({ BAN::to_unix_time(RTC::get_current_time()), 0 })
|
||||
, m_ino_t(DeviceManager::get().get_next_ino())
|
||||
{ }
|
||||
|
||||
}
|
||||
@@ -76,6 +76,24 @@ namespace Kernel
|
||||
return *s_instance;
|
||||
}
|
||||
|
||||
ino_t DeviceManager::get_next_ino() const
|
||||
{
|
||||
static ino_t next_ino = 1;
|
||||
return next_ino++;
|
||||
}
|
||||
|
||||
dev_t DeviceManager::get_next_rdev() const
|
||||
{
|
||||
static dev_t next_dev = 1;
|
||||
return next_dev++;
|
||||
}
|
||||
|
||||
uint8_t DeviceManager::get_next_input_dev() const
|
||||
{
|
||||
static uint8_t next_dev = 0;
|
||||
return next_dev++;
|
||||
}
|
||||
|
||||
void DeviceManager::update()
|
||||
{
|
||||
LockGuard _(m_lock);
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Kernel
|
||||
auto partition_inode = TRY(DeviceManager::get().read_directory_inode(root));
|
||||
s_instance->m_root_fs = TRY(Ext2FS::create(*(Partition*)partition_inode.ptr()));
|
||||
|
||||
DeviceManager::get().set_blksize(s_instance->m_root_fs->root_inode()->blksize());
|
||||
TRY(s_instance->mount(&DeviceManager::get(), "/dev"));
|
||||
|
||||
guard.disable();
|
||||
|
||||
@@ -302,7 +302,7 @@ namespace Kernel::Input
|
||||
|
||||
// MF2 Keyboard
|
||||
if (index == 2 && (bytes[0] == 0xAB && bytes[1] == 0x83))
|
||||
m_devices[device] = TRY(PS2Keyboard::create(*this, device));
|
||||
m_devices[device] = TRY(PS2Keyboard::create(*this));
|
||||
|
||||
if (m_devices[device])
|
||||
return {};
|
||||
@@ -332,10 +332,4 @@ namespace Kernel::Input
|
||||
return {};
|
||||
}
|
||||
|
||||
PS2Device::PS2Device(dev_t dev)
|
||||
{
|
||||
m_dev = dev;
|
||||
m_ino = dev & 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,9 +37,9 @@ namespace Kernel::Input
|
||||
|
||||
}
|
||||
|
||||
BAN::ErrorOr<PS2Keyboard*> PS2Keyboard::create(PS2Controller& controller, dev_t device)
|
||||
BAN::ErrorOr<PS2Keyboard*> PS2Keyboard::create(PS2Controller& controller)
|
||||
{
|
||||
PS2Keyboard* keyboard = new PS2Keyboard(controller, device);
|
||||
PS2Keyboard* keyboard = new PS2Keyboard(controller);
|
||||
if (keyboard == nullptr)
|
||||
return BAN::Error::from_errno(ENOMEM);
|
||||
BAN::ScopeGuard guard([keyboard] { delete keyboard; });
|
||||
@@ -48,6 +48,12 @@ namespace Kernel::Input
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
PS2Keyboard::PS2Keyboard(PS2Controller& controller)
|
||||
: m_controller(controller)
|
||||
, m_name(BAN::String::formatted("input{}", DeviceManager::get().get_next_input_dev()))
|
||||
, m_rdev(makedev(DeviceManager::get().get_next_rdev(), 0))
|
||||
{ }
|
||||
|
||||
void PS2Keyboard::on_byte(uint8_t byte)
|
||||
{
|
||||
// NOTE: This implementation does not allow using commands
|
||||
|
||||
@@ -455,9 +455,9 @@ argument_done:
|
||||
|
||||
TTY_PRINTLN(" File: {}", arguments[1]);
|
||||
TTY_PRINTLN(" Size: {}\tBlocks: {}\tIO Block: {}\t {}", st.st_size, st.st_blocks, st.st_blksize, type);
|
||||
TTY_PRINT("Device: {},{}\tInode: {}\tLinks: {}", st.st_dev >> 8, st.st_dev & 0xFF, st.st_ino, st.st_nlink);
|
||||
TTY_PRINT("Device: {},{}\tInode: {}\tLinks: {}", major(st.st_dev), minor(st.st_dev), st.st_ino, st.st_nlink);
|
||||
if (st.st_rdev)
|
||||
TTY_PRINT("\tDevice type: {},{}", st.st_rdev >> 8, st.st_rdev & 0xFF);
|
||||
TTY_PRINT("\tDevice type: {},{}", major(st.st_rdev), minor(st.st_rdev));
|
||||
TTY_PRINTLN("");
|
||||
TTY_PRINTLN("Access: ({4O}/{})\tUid: {}\tGid: {}", mode.mode & 0777, mode_string(mode), st.st_uid, st.st_gid);
|
||||
TTY_PRINTLN("Access: {}", BAN::from_unix_time(st.st_atime));
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace Kernel
|
||||
entry.ending_lba,
|
||||
entry.attributes,
|
||||
utf8_name,
|
||||
i
|
||||
i + 1
|
||||
);
|
||||
ASSERT(partition != nullptr);
|
||||
MUST(m_partitions.push_back(partition));
|
||||
@@ -211,6 +211,11 @@ namespace Kernel
|
||||
memcpy(m_label, label, sizeof(m_label));
|
||||
}
|
||||
|
||||
dev_t Partition::rdev() const
|
||||
{
|
||||
return makedev(major(m_device.rdev()), m_index);
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> Partition::read_sectors(uint64_t lba, uint8_t sector_count, uint8_t* buffer)
|
||||
{
|
||||
const uint32_t sectors_in_partition = m_lba_end - m_lba_start;
|
||||
@@ -229,16 +234,6 @@ namespace Kernel
|
||||
return {};
|
||||
}
|
||||
|
||||
blksize_t Partition::blksize() const
|
||||
{
|
||||
return m_device.blksize();
|
||||
}
|
||||
|
||||
dev_t Partition::dev() const
|
||||
{
|
||||
return m_device.dev();
|
||||
}
|
||||
|
||||
BAN::ErrorOr<size_t> Partition::read(size_t offset, void* buffer, size_t bytes)
|
||||
{
|
||||
if (offset % m_device.sector_size() || bytes % m_device.sector_size())
|
||||
|
||||
Reference in New Issue
Block a user