From 3508df67b142ab80f98726a7725c69503c5573be Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 30 Mar 2023 10:43:08 +0300 Subject: [PATCH] Kernel: fix stat command and device numbers --- kernel/include/kernel/Device.h | 2 +- kernel/include/kernel/Input/PS2Controller.h | 2 +- kernel/kernel/Process.cpp | 4 ++-- kernel/kernel/Shell.cpp | 7 +++++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/kernel/include/kernel/Device.h b/kernel/include/kernel/Device.h index 97d47c34..40ff7344 100644 --- a/kernel/include/kernel/Device.h +++ b/kernel/include/kernel/Device.h @@ -76,7 +76,7 @@ namespace Kernel virtual timespec ctime() const override { return { 0, 0 }; } virtual blksize_t blksize() const override { return 0; } virtual blkcnt_t blocks() const override { return 0; } - virtual dev_t dev() const override { return 0x4935; } + virtual dev_t dev() const override { return 0x4900; } virtual dev_t rdev() const override { return 0x7854; } virtual BAN::ErrorOr read(size_t, void*, size_t) { ASSERT_NOT_REACHED(); } diff --git a/kernel/include/kernel/Input/PS2Controller.h b/kernel/include/kernel/Input/PS2Controller.h index 6594b9fb..a3c236cb 100644 --- a/kernel/include/kernel/Input/PS2Controller.h +++ b/kernel/include/kernel/Input/PS2Controller.h @@ -13,7 +13,7 @@ namespace Kernel::Input virtual void on_byte(uint8_t) = 0; public: - virtual ino_t ino() const { return m_ino; } + virtual ino_t ino() const override { return m_ino; } virtual mode_t mode() const override { return Mode::IFCHR | Mode::IRUSR | Mode::IRGRP; } virtual nlink_t nlink() const override { return 1; } virtual uid_t uid() const override { return 0; } diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index 3af306f6..427dc2b4 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -104,13 +104,13 @@ namespace Kernel TRY(validate_fd(fd)); const auto& open_fd = open_file_description(fd); - out->st_dev = 0; + out->st_dev = open_fd.inode->dev(); out->st_ino = open_fd.inode->ino(); out->st_mode = open_fd.inode->mode(); out->st_nlink = open_fd.inode->nlink(); out->st_uid = open_fd.inode->uid(); out->st_gid = open_fd.inode->gid(); - out->st_rdev = 0; + out->st_rdev = open_fd.inode->rdev(); out->st_size = open_fd.inode->size(); out->st_atim = open_fd.inode->atime(); out->st_mtim = open_fd.inode->mtime(); diff --git a/kernel/kernel/Shell.cpp b/kernel/kernel/Shell.cpp index 988c9e5b..a0360f5f 100644 --- a/kernel/kernel/Shell.cpp +++ b/kernel/kernel/Shell.cpp @@ -447,8 +447,11 @@ 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_PRINTLN("Device: {},{}\tInode: {}\tLinks: {}", st.st_dev, st.st_rdev, st.st_ino, st.st_nlink); - TTY_PRINTLN("Access: ({}/{})\tUid: {}\tGid: {}", st.st_mode, mode_string(st.st_mode), st.st_uid, st.st_gid); + TTY_PRINT("Device: {},{}\tInode: {}\tLinks: {}", st.st_dev >> 8, st.st_dev & 0xFF, st.st_ino, st.st_nlink); + if (st.st_rdev) + TTY_PRINT("\tDevice type: {},{}", st.st_rdev >> 8, st.st_rdev & 0xFF); + TTY_PRINTLN(""); + TTY_PRINTLN("Access: ({4O}/{})\tUid: {}\tGid: {}", st.st_mode & 0777, mode_string(st.st_mode), st.st_uid, st.st_gid); TTY_PRINTLN("Access: {}", BAN::from_unix_time(st.st_atime)); TTY_PRINTLN("Modify: {}", BAN::from_unix_time(st.st_mtime)); TTY_PRINTLN("Change: {}", BAN::from_unix_time(st.st_ctime));