
SysFS, ProcFS and DevPtsFS were all sending filetype 0 when traversing their directories, but it is actually very easy to send proper filetypes in these filesystems. This patch binds all RAM backed filesystems to use only one enum for their internal filetype, to simplify the implementation and allow sharing of code. Please note that the Plan9FS case is currently not solved as I am not familiar with this filesystem and its constructs. The ProcFS mostly keeps track of the filetype, and a fix was needed for the /proc root directory - all processes exhibit a directory inside it which makes it very easy to hardcode the directory filetype for them. There's also the `self` symlink inode which is now exposed as DT_LNK. As for SysFS, we could leverage the fact everything inherits from the SysFSComponent class, so we could have a virtual const method to return the proper filetype. Most of the files in SysFS are "regular" files though, so the base class has a non-pure virtual method. Lastly, the DevPtsFS simply hardcodes '.' and '..' as directory file type, and everything else is hardcoded to send the character device file type, as this filesystem is only exposing character pts device files.
71 lines
1.6 KiB
C++
71 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2024, Liav A. <liavalb@hotmail.co.il>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Types.h>
|
|
#include <Kernel/API/POSIX/sys/stat.h>
|
|
#include <Kernel/FileSystem/FileSystem.h>
|
|
|
|
namespace Kernel {
|
|
|
|
enum class RAMBackedFileType : u8 {
|
|
Directory,
|
|
Character,
|
|
Block,
|
|
Regular,
|
|
FIFO,
|
|
Link,
|
|
Socket,
|
|
Unknown,
|
|
};
|
|
|
|
inline RAMBackedFileType ram_backed_file_type_from_mode(mode_t mode)
|
|
{
|
|
switch (mode & S_IFMT) {
|
|
case S_IFDIR:
|
|
return RAMBackedFileType::Directory;
|
|
case S_IFCHR:
|
|
return RAMBackedFileType::Character;
|
|
case S_IFBLK:
|
|
return RAMBackedFileType::Block;
|
|
case S_IFREG:
|
|
return RAMBackedFileType::Regular;
|
|
case S_IFIFO:
|
|
return RAMBackedFileType::FIFO;
|
|
case S_IFLNK:
|
|
return RAMBackedFileType::Link;
|
|
case S_IFSOCK:
|
|
return RAMBackedFileType::Socket;
|
|
default:
|
|
return RAMBackedFileType::Unknown;
|
|
}
|
|
}
|
|
|
|
inline u8 ram_backed_file_type_to_directory_entry_type(FileSystem::DirectoryEntryView const& entry)
|
|
{
|
|
switch (static_cast<RAMBackedFileType>(entry.file_type)) {
|
|
case RAMBackedFileType::Directory:
|
|
return DT_DIR;
|
|
case RAMBackedFileType::Character:
|
|
return DT_CHR;
|
|
case RAMBackedFileType::Block:
|
|
return DT_BLK;
|
|
case RAMBackedFileType::Regular:
|
|
return DT_REG;
|
|
case RAMBackedFileType::FIFO:
|
|
return DT_FIFO;
|
|
case RAMBackedFileType::Link:
|
|
return DT_LNK;
|
|
case RAMBackedFileType::Socket:
|
|
return DT_SOCK;
|
|
case RAMBackedFileType::Unknown:
|
|
default:
|
|
return DT_UNKNOWN;
|
|
}
|
|
}
|
|
|
|
}
|