forked from Bananymous/banan-os
Kernel: Inode::Mode is now a struct so we can have functions in it
This commit is contained in:
@@ -252,7 +252,7 @@ namespace Kernel
|
||||
{
|
||||
// FIXME: update atime if needed
|
||||
|
||||
if (ifdir())
|
||||
if (mode().ifdir())
|
||||
return BAN::Error::from_errno(EISDIR);
|
||||
|
||||
if (offset >= m_inode.size)
|
||||
@@ -286,7 +286,7 @@ namespace Kernel
|
||||
|
||||
BAN::ErrorOr<BAN::Vector<BAN::String>> Ext2Inode::read_directory_entries(size_t index)
|
||||
{
|
||||
if (!ifdir())
|
||||
if (!mode().ifdir())
|
||||
return BAN::Error::from_errno(ENOTDIR);
|
||||
|
||||
uint32_t data_block_count = blocks();
|
||||
@@ -318,7 +318,7 @@ namespace Kernel
|
||||
|
||||
BAN::ErrorOr<void> Ext2Inode::create_file(BAN::StringView name, mode_t mode)
|
||||
{
|
||||
if (!ifdir())
|
||||
if (!this->mode().ifdir())
|
||||
return BAN::Error::from_errno(ENOTDIR);
|
||||
|
||||
if (name.size() > 255)
|
||||
@@ -403,7 +403,7 @@ namespace Kernel
|
||||
|
||||
BAN::ErrorOr<BAN::RefPtr<Inode>> Ext2Inode::read_directory_inode(BAN::StringView file_name)
|
||||
{
|
||||
if (!ifdir())
|
||||
if (!mode().ifdir())
|
||||
return BAN::Error::from_errno(ENOTDIR);
|
||||
|
||||
uint32_t block_size = m_fs.block_size();
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Kernel
|
||||
BAN::ErrorOr<void> VirtualFileSystem::mount(FileSystem* file_system, BAN::StringView path)
|
||||
{
|
||||
auto file = TRY(file_from_absolute_path(path));
|
||||
if (!file.inode->ifdir())
|
||||
if (!file.inode->mode().ifdir())
|
||||
return BAN::Error::from_errno(ENOTDIR);
|
||||
TRY(m_mount_points.push_back({ file, file_system }));
|
||||
return {};
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace Kernel
|
||||
|
||||
out->st_dev = open_fd.inode->dev();
|
||||
out->st_ino = open_fd.inode->ino();
|
||||
out->st_mode = open_fd.inode->mode();
|
||||
out->st_mode = open_fd.inode->mode().mode;
|
||||
out->st_nlink = open_fd.inode->nlink();
|
||||
out->st_uid = open_fd.inode->uid();
|
||||
out->st_gid = open_fd.inode->gid();
|
||||
@@ -153,7 +153,7 @@ namespace Kernel
|
||||
BAN::String absolute_path = TRY(absolute_path_of(path));
|
||||
|
||||
auto file = TRY(VirtualFileSystem::get().file_from_absolute_path(absolute_path));
|
||||
if (!file.inode->ifdir())
|
||||
if (!file.inode->mode().ifdir())
|
||||
return BAN::Error::from_errno(ENOTDIR);
|
||||
|
||||
m_working_directory = BAN::move(file.canonical_path);
|
||||
|
||||
@@ -22,22 +22,24 @@ namespace Kernel
|
||||
|
||||
static auto s_default_prompt = "\\[\e[32m\\]user\\[\e[m\\]:\\[\e[34m\\]\\w\\[\e[m\\]# "sv;
|
||||
|
||||
static const char* mode_string(mode_t mode)
|
||||
static const char* mode_string(Inode::Mode mode)
|
||||
{
|
||||
static char buffer[11] {};
|
||||
buffer[0] =
|
||||
(mode & Inode::Mode::IFDIR) ? 'd' :
|
||||
(mode & Inode::Mode::IFCHR) ? 'c' :
|
||||
'-';
|
||||
buffer[1] = (mode & Inode::Mode::IRUSR) ? 'r' : '-';
|
||||
buffer[2] = (mode & Inode::Mode::IWUSR) ? 'w' : '-';
|
||||
buffer[3] = (mode & Inode::Mode::IXUSR) ? 'x' : '-';
|
||||
buffer[4] = (mode & Inode::Mode::IRGRP) ? 'r' : '-';
|
||||
buffer[5] = (mode & Inode::Mode::IWGRP) ? 'w' : '-';
|
||||
buffer[6] = (mode & Inode::Mode::IXGRP) ? 'x' : '-';
|
||||
buffer[7] = (mode & Inode::Mode::IROTH) ? 'r' : '-';
|
||||
buffer[8] = (mode & Inode::Mode::IWOTH) ? 'w' : '-';
|
||||
buffer[9] = (mode & Inode::Mode::IXOTH) ? 'x' : '-';
|
||||
mode.ifdir() ? 'd' :
|
||||
mode.ifblk() ? 'b' :
|
||||
mode.ifchr() ? 'c' :
|
||||
'-';
|
||||
|
||||
buffer[1] = (mode.mode & Inode::Mode::IRUSR) ? 'r' : '-';
|
||||
buffer[2] = (mode.mode & Inode::Mode::IWUSR) ? 'w' : '-';
|
||||
buffer[3] = (mode.mode & Inode::Mode::IXUSR) ? 'x' : '-';
|
||||
buffer[4] = (mode.mode & Inode::Mode::IRGRP) ? 'r' : '-';
|
||||
buffer[5] = (mode.mode & Inode::Mode::IWGRP) ? 'w' : '-';
|
||||
buffer[6] = (mode.mode & Inode::Mode::IXGRP) ? 'x' : '-';
|
||||
buffer[7] = (mode.mode & Inode::Mode::IROTH) ? 'r' : '-';
|
||||
buffer[8] = (mode.mode & Inode::Mode::IWOTH) ? 'w' : '-';
|
||||
buffer[9] = (mode.mode & Inode::Mode::IXOTH) ? 'x' : '-';
|
||||
return (const char*)buffer;
|
||||
};
|
||||
|
||||
@@ -404,13 +406,15 @@ argument_done:
|
||||
TRY(entry_path.append(entry));
|
||||
TRY(Process::current()->stat(entry_path, &st));
|
||||
|
||||
Inode::Mode mode { st.st_mode };
|
||||
|
||||
const char* color =
|
||||
(st.st_mode & Inode::Mode::IFDIR) ? "34" :
|
||||
(st.st_mode & Inode::Mode::IFCHR) ? "33" :
|
||||
(st.st_mode & Inode::Mode::IXUSR) ? "32" :
|
||||
"";
|
||||
mode.ifdir() ? "34" :
|
||||
mode.ifchr() || mode.ifblk() ? "33" :
|
||||
(mode.mode & Inode::Mode::IXUSR) ? "32" :
|
||||
"";
|
||||
|
||||
TTY_PRINTLN(" {} {7} \e[{}m{}\e[m", mode_string(st.st_mode), st.st_size, color, entry);
|
||||
TTY_PRINTLN(" {} {7} \e[{}m{}\e[m", mode_string(mode), st.st_size, color, entry);
|
||||
}
|
||||
}
|
||||
else if (arguments.front() == "cat")
|
||||
@@ -439,11 +443,14 @@ argument_done:
|
||||
stat st;
|
||||
TRY(Process::current()->stat(arguments[1], &st));
|
||||
|
||||
Inode::Mode mode { st.st_mode };
|
||||
|
||||
const char* type =
|
||||
(st.st_mode & Inode::Mode::IFREG) ? "regular file" :
|
||||
(st.st_mode & Inode::Mode::IFDIR) ? "directory" :
|
||||
(st.st_mode & Inode::Mode::IFCHR) ? "character device" :
|
||||
"other";
|
||||
mode.ifreg() ? "regular file" :
|
||||
mode.ifdir() ? "directory" :
|
||||
mode.ifchr() ? "character device" :
|
||||
mode.ifblk() ? "block device" :
|
||||
"other";
|
||||
|
||||
TTY_PRINTLN(" File: {}", arguments[1]);
|
||||
TTY_PRINTLN(" Size: {}\tBlocks: {}\tIO Block: {}\t {}", st.st_size, st.st_blocks, st.st_blksize, type);
|
||||
@@ -451,7 +458,7 @@ argument_done:
|
||||
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: ({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));
|
||||
TTY_PRINTLN("Modify: {}", BAN::from_unix_time(st.st_mtime));
|
||||
TTY_PRINTLN("Change: {}", BAN::from_unix_time(st.st_ctime));
|
||||
|
||||
Reference in New Issue
Block a user