diff options
29 files changed, 76 insertions, 69 deletions
diff --git a/Kernel/Console.h b/Kernel/Console.h index 55ae0f1b54..7c15631e92 100644 --- a/Kernel/Console.h +++ b/Kernel/Console.h @@ -53,6 +53,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0666; } + virtual String device_name() const override { return "console"; } private: CircularQueue<char, 16384> m_logbuffer; diff --git a/Kernel/Devices/BXVGADevice.cpp b/Kernel/Devices/BXVGADevice.cpp index 3c5d71a9f3..e7a58859a2 100644 --- a/Kernel/Devices/BXVGADevice.cpp +++ b/Kernel/Devices/BXVGADevice.cpp @@ -192,6 +192,11 @@ KResultOr<Region*> BXVGADevice::mmap(Process& process, FileDescription&, Virtual shared); } +String BXVGADevice::device_name() const +{ + return String::formatted("fb{}", minor()); +} + int BXVGADevice::ioctl(FileDescription&, unsigned request, FlatPtr arg) { REQUIRE_PROMISE(video); diff --git a/Kernel/Devices/BXVGADevice.h b/Kernel/Devices/BXVGADevice.h index 9c24c107da..4e54649284 100644 --- a/Kernel/Devices/BXVGADevice.h +++ b/Kernel/Devices/BXVGADevice.h @@ -46,6 +46,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0660; } + virtual String device_name() const override; private: virtual const char* class_name() const override { return "BXVGA"; } diff --git a/Kernel/Devices/Device.h b/Kernel/Devices/Device.h index 1ef8bcfa89..6c101ddd46 100644 --- a/Kernel/Devices/Device.h +++ b/Kernel/Devices/Device.h @@ -58,6 +58,7 @@ public: uid_t gid() const { return m_gid; } virtual mode_t required_mode() const = 0; + virtual String device_name() const = 0; virtual bool is_device() const override { return true; } virtual bool is_disk_device() const { return false; } diff --git a/Kernel/Devices/FullDevice.h b/Kernel/Devices/FullDevice.h index 8c7a9668d7..b25996a07d 100644 --- a/Kernel/Devices/FullDevice.h +++ b/Kernel/Devices/FullDevice.h @@ -38,6 +38,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0600; } + virtual String device_name() const override { return "full"; } private: // ^CharacterDevice diff --git a/Kernel/Devices/KeyboardDevice.h b/Kernel/Devices/KeyboardDevice.h index ba1749e82d..3bd98c9619 100644 --- a/Kernel/Devices/KeyboardDevice.h +++ b/Kernel/Devices/KeyboardDevice.h @@ -76,6 +76,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0440; } + virtual String device_name() const override { return "keyboard"; } private: // ^IRQHandler diff --git a/Kernel/Devices/MBVGADevice.cpp b/Kernel/Devices/MBVGADevice.cpp index 38ee00f047..2335eb952c 100644 --- a/Kernel/Devices/MBVGADevice.cpp +++ b/Kernel/Devices/MBVGADevice.cpp @@ -114,4 +114,9 @@ int MBVGADevice::ioctl(FileDescription&, unsigned request, FlatPtr arg) }; } +String MBVGADevice::device_name() const +{ + return String::formatted("fb{}", minor()); +} + } diff --git a/Kernel/Devices/MBVGADevice.h b/Kernel/Devices/MBVGADevice.h index 16685cc9a4..d89134f6b8 100644 --- a/Kernel/Devices/MBVGADevice.h +++ b/Kernel/Devices/MBVGADevice.h @@ -45,6 +45,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0660; } + virtual String device_name() const override; private: virtual const char* class_name() const override { return "MBVGA"; } diff --git a/Kernel/Devices/NullDevice.h b/Kernel/Devices/NullDevice.h index 11e98b567c..36bf0035ba 100644 --- a/Kernel/Devices/NullDevice.h +++ b/Kernel/Devices/NullDevice.h @@ -41,6 +41,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0666; } + virtual String device_name() const override { return "null"; } private: // ^CharacterDevice diff --git a/Kernel/Devices/PS2MouseDevice.h b/Kernel/Devices/PS2MouseDevice.h index a0e0eb0db5..1eabfb8918 100644 --- a/Kernel/Devices/PS2MouseDevice.h +++ b/Kernel/Devices/PS2MouseDevice.h @@ -63,6 +63,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0440; } + virtual String device_name() const override { return "mouse"; } private: // ^IRQHandler diff --git a/Kernel/Devices/RandomDevice.h b/Kernel/Devices/RandomDevice.h index fbf5bbaf7b..04ba907cf1 100644 --- a/Kernel/Devices/RandomDevice.h +++ b/Kernel/Devices/RandomDevice.h @@ -38,6 +38,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0666; } + virtual String device_name() const override { return "random"; } private: // ^CharacterDevice diff --git a/Kernel/Devices/SB16.h b/Kernel/Devices/SB16.h index 5c0df448f2..fd53065d21 100644 --- a/Kernel/Devices/SB16.h +++ b/Kernel/Devices/SB16.h @@ -55,6 +55,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0220; } + virtual String device_name() const override { return "audio"; } private: // ^IRQHandler diff --git a/Kernel/Devices/SerialDevice.cpp b/Kernel/Devices/SerialDevice.cpp index 9801c6b83d..ef60b42d6b 100644 --- a/Kernel/Devices/SerialDevice.cpp +++ b/Kernel/Devices/SerialDevice.cpp @@ -87,6 +87,11 @@ KResultOr<size_t> SerialDevice::write(FileDescription&, size_t, const UserOrKern return (size_t)nread; } +String SerialDevice::device_name() const +{ + return String::formatted("ttyS{}", minor() - 64); +} + void SerialDevice::initialize() { set_interrupts(0); diff --git a/Kernel/Devices/SerialDevice.h b/Kernel/Devices/SerialDevice.h index fb5785284c..d85e25b6a1 100644 --- a/Kernel/Devices/SerialDevice.h +++ b/Kernel/Devices/SerialDevice.h @@ -125,6 +125,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0620; } + virtual String device_name() const override; private: // ^CharacterDevice diff --git a/Kernel/Devices/ZeroDevice.h b/Kernel/Devices/ZeroDevice.h index 8140174e16..517955aafb 100644 --- a/Kernel/Devices/ZeroDevice.h +++ b/Kernel/Devices/ZeroDevice.h @@ -38,6 +38,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0666; } + virtual String device_name() const override { return "zero"; } private: // ^CharacterDevice diff --git a/Kernel/FileSystem/DevFS.cpp b/Kernel/FileSystem/DevFS.cpp index 379d538bc7..f12b5b66d3 100644 --- a/Kernel/FileSystem/DevFS.cpp +++ b/Kernel/FileSystem/DevFS.cpp @@ -350,79 +350,12 @@ KResult DevFSDeviceInode::chown(uid_t uid, gid_t gid) String DevFSDeviceInode::name() const { + LOCKER(m_lock); if (m_cached_name.is_null() || m_cached_name.is_empty()) - const_cast<DevFSDeviceInode&>(*this).m_cached_name = determine_name(); + const_cast<DevFSDeviceInode&>(*this).m_cached_name = m_attached_device->device_name(); return m_cached_name; } -String DevFSDeviceInode::determine_name() const -{ - LOCKER(m_lock); - if (m_attached_device->is_character_device()) { - switch (m_attached_device->major()) { - case 85: - if (m_attached_device->minor() == 1) - return "keyboard"; - ASSERT_NOT_REACHED(); - case 10: - if (m_attached_device->minor() == 1) - return "mouse"; - ASSERT_NOT_REACHED(); - case 42: - if (m_attached_device->minor() == 42) - return "audio"; - ASSERT_NOT_REACHED(); - case 1: - switch (m_attached_device->minor()) { - case 8: - return "random"; - case 3: - return "null"; - case 5: - return "zero"; - case 7: - return "full"; - default: - ASSERT_NOT_REACHED(); - } - case 5: - if (m_attached_device->minor() == 1) - return "console"; - if (m_attached_device->minor() == 2) - return "ptmx"; - ASSERT_NOT_REACHED(); - - case 4: - if (m_attached_device->minor() >= 64) - return String::formatted("ttyS{}", m_attached_device->minor() - 64); - return String::formatted("tty{}", m_attached_device->minor()); - - default: - ASSERT_NOT_REACHED(); - } - } else { - switch (m_attached_device->major()) { - case 29: - return String::formatted("fb{}", m_attached_device->minor()); - case 3: { - size_t drive_index = (u8)'a' + m_attached_device->minor(); - char drive_letter = (u8)drive_index; - return String::format("hd%c", drive_letter); - } - case 6: { - return String::formatted("ramdisk{}", m_attached_device->minor()); - } - - case 100: - // FIXME: Try to not hardcode a maximum of 16 partitions per drive! - size_t drive_index = (u8)'a' + (m_attached_device->minor() / 16); - char drive_letter = (u8)drive_index; - return String::formatted("hd{:c}{}", drive_letter, m_attached_device->minor() + 1); - } - } - - ASSERT_NOT_REACHED(); -} ssize_t DevFSDeviceInode::read_bytes(off_t offset, ssize_t count, UserOrKernelBuffer& buffer, FileDescription* description) const { LOCKER(m_lock); diff --git a/Kernel/Storage/PATADiskDevice.cpp b/Kernel/Storage/PATADiskDevice.cpp index 21ee558eef..8065585902 100644 --- a/Kernel/Storage/PATADiskDevice.cpp +++ b/Kernel/Storage/PATADiskDevice.cpp @@ -65,6 +65,13 @@ void PATADiskDevice::start_request(AsyncBlockDeviceRequest& request) m_channel.start_request(request, use_dma, is_slave()); } +String PATADiskDevice::device_name() const +{ + // FIXME: Try to not hardcode a maximum of 16 partitions per drive! + size_t drive_index = minor() / 16; + return String::formatted("hd{:c}{}", 'a' + drive_index, minor() + 1); +} + size_t PATADiskDevice::max_addressable_block() const { return m_cylinders * m_heads * m_sectors_per_track; diff --git a/Kernel/Storage/PATADiskDevice.h b/Kernel/Storage/PATADiskDevice.h index fa19186c6a..f3eeef60bf 100644 --- a/Kernel/Storage/PATADiskDevice.h +++ b/Kernel/Storage/PATADiskDevice.h @@ -61,6 +61,7 @@ public: // ^BlockDevice virtual void start_request(AsyncBlockDeviceRequest&) override; + virtual String device_name() const override; private: PATADiskDevice(const IDEController&, IDEChannel&, DriveType, u8, u8, u8, int major, int minor); diff --git a/Kernel/Storage/Partition/DiskPartition.cpp b/Kernel/Storage/Partition/DiskPartition.cpp index e1600834ca..2e35690ff0 100644 --- a/Kernel/Storage/Partition/DiskPartition.cpp +++ b/Kernel/Storage/Partition/DiskPartition.cpp @@ -102,6 +102,13 @@ bool DiskPartition::can_write(const FileDescription& fd, size_t offset) const return m_device->can_write(fd, offset + adjust); } +String DiskPartition::device_name() const +{ + // FIXME: Try to not hardcode a maximum of 16 partitions per drive! + size_t partition_index = minor() % 16; + return String::formatted("{}{}", m_device->device_name(), partition_index + 1); +} + const char* DiskPartition::class_name() const { return "DiskPartition"; diff --git a/Kernel/Storage/Partition/DiskPartition.h b/Kernel/Storage/Partition/DiskPartition.h index e2d244c3b4..ebb59707f1 100644 --- a/Kernel/Storage/Partition/DiskPartition.h +++ b/Kernel/Storage/Partition/DiskPartition.h @@ -47,6 +47,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0600; } + virtual String device_name() const override; const DiskPartitionMetadata& metadata() const; diff --git a/Kernel/Storage/RamdiskDevice.cpp b/Kernel/Storage/RamdiskDevice.cpp index 1c407f80b8..c73e47b431 100644 --- a/Kernel/Storage/RamdiskDevice.cpp +++ b/Kernel/Storage/RamdiskDevice.cpp @@ -82,4 +82,11 @@ void RamdiskDevice::start_request(AsyncBlockDeviceRequest& request) } } +String RamdiskDevice::device_name() const +{ + // FIXME: Try to not hardcode a maximum of 16 partitions per drive! + size_t drive_index = minor() / 16; + return String::formatted("ramdisk{}", drive_index); +} + } diff --git a/Kernel/Storage/RamdiskDevice.h b/Kernel/Storage/RamdiskDevice.h index 85662769ea..1846b09dce 100644 --- a/Kernel/Storage/RamdiskDevice.h +++ b/Kernel/Storage/RamdiskDevice.h @@ -50,6 +50,7 @@ public: // ^DiskDevice virtual const char* class_name() const override; + virtual String device_name() const override; bool is_slave() const; diff --git a/Kernel/TTY/MasterPTY.cpp b/Kernel/TTY/MasterPTY.cpp index 79512b40a2..dbb7e0f2da 100644 --- a/Kernel/TTY/MasterPTY.cpp +++ b/Kernel/TTY/MasterPTY.cpp @@ -141,4 +141,9 @@ String MasterPTY::absolute_path(const FileDescription&) const return String::formatted("ptm:{}", m_pts_name); } +String MasterPTY::device_name() const +{ + return String::formatted("{}", minor()); +} + } diff --git a/Kernel/TTY/MasterPTY.h b/Kernel/TTY/MasterPTY.h index 7744a58cdb..8c2bb54739 100644 --- a/Kernel/TTY/MasterPTY.h +++ b/Kernel/TTY/MasterPTY.h @@ -50,6 +50,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0640; } + virtual String device_name() const override; private: // ^CharacterDevice diff --git a/Kernel/TTY/PTYMultiplexer.h b/Kernel/TTY/PTYMultiplexer.h index 9402ae1136..79a6f1d2bf 100644 --- a/Kernel/TTY/PTYMultiplexer.h +++ b/Kernel/TTY/PTYMultiplexer.h @@ -57,6 +57,7 @@ public: // ^Device virtual mode_t required_mode() const override { return 0666; } + virtual String device_name() const override { return "ptmx"; } private: // ^CharacterDevice diff --git a/Kernel/TTY/SlavePTY.cpp b/Kernel/TTY/SlavePTY.cpp index a4704616dd..401b6b9ed2 100644 --- a/Kernel/TTY/SlavePTY.cpp +++ b/Kernel/TTY/SlavePTY.cpp @@ -106,6 +106,11 @@ KResult SlavePTY::close() return KSuccess; } +String SlavePTY::device_name() const +{ + return String::formatted("{}", minor()); +} + FileBlockCondition& SlavePTY::block_condition() { return m_master->block_condition(); diff --git a/Kernel/TTY/SlavePTY.h b/Kernel/TTY/SlavePTY.h index a37e7f741e..fc9c46311f 100644 --- a/Kernel/TTY/SlavePTY.h +++ b/Kernel/TTY/SlavePTY.h @@ -57,6 +57,9 @@ private: virtual const char* class_name() const override { return "SlavePTY"; } virtual KResult close() override; + // ^Device + virtual String device_name() const override; + friend class MasterPTY; SlavePTY(MasterPTY&, unsigned index); diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp index 4f87c49fd5..bdeb917450 100644 --- a/Kernel/TTY/VirtualConsole.cpp +++ b/Kernel/TTY/VirtualConsole.cpp @@ -338,6 +338,11 @@ void VirtualConsole::emit(const u8* data, size_t size) TTY::emit(data[i]); } +String VirtualConsole::device_name() const +{ + return String::formatted("tty{}", minor()); +} + void VirtualConsole::echo(u8 ch) { if (should_echo_input()) { diff --git a/Kernel/TTY/VirtualConsole.h b/Kernel/TTY/VirtualConsole.h index f9f4665be1..20fe63c821 100644 --- a/Kernel/TTY/VirtualConsole.h +++ b/Kernel/TTY/VirtualConsole.h @@ -69,6 +69,9 @@ private: // ^CharacterDevice virtual const char* class_name() const override { return "VirtualConsole"; } + // ^Device + virtual String device_name() const override; + void set_active(bool); void flush_vga_cursor(); |