mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:07:34 +00:00
Kernel: Move all code into the Kernel namespace
This commit is contained in:
parent
d42f0f4661
commit
a356e48150
201 changed files with 907 additions and 111 deletions
|
@ -30,6 +30,8 @@
|
|||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/Lock.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
static Lockable<InlineLinkedList<Custody>>& all_custodies()
|
||||
{
|
||||
static Lockable<InlineLinkedList<Custody>>* list;
|
||||
|
@ -109,3 +111,5 @@ void Custody::did_rename(Badge<VFS>, const String& name)
|
|||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include <AK/RefPtr.h>
|
||||
#include <AK/String.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Inode;
|
||||
class VFS;
|
||||
|
||||
|
@ -79,3 +81,5 @@ private:
|
|||
bool m_mounted_on { false };
|
||||
int m_mount_flags { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/TTY/SlavePTY.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullRefPtr<DevPtsFS> DevPtsFS::create()
|
||||
{
|
||||
return adopt(*new DevPtsFS);
|
||||
|
@ -206,3 +208,5 @@ KResult DevPtsFSInode::chown(uid_t, gid_t)
|
|||
{
|
||||
return KResult(-EPERM);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include <Kernel/FileSystem/FileSystem.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class SlavePTY;
|
||||
class DevPtsFSInode;
|
||||
|
||||
|
@ -57,6 +59,7 @@ private:
|
|||
|
||||
class DevPtsFSInode final : public Inode {
|
||||
friend class DevPtsFS;
|
||||
|
||||
public:
|
||||
virtual ~DevPtsFSInode() override;
|
||||
|
||||
|
@ -78,3 +81,5 @@ private:
|
|||
|
||||
InodeMetadata m_metadata;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
|
||||
//#define DBFS_DEBUG
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
struct CacheEntry {
|
||||
time_t timestamp { 0 };
|
||||
u32 block_index { 0 };
|
||||
|
@ -240,3 +242,5 @@ DiskCache& DiskBackedFS::cache() const
|
|||
m_cache = make<DiskCache>(const_cast<DiskBackedFS&>(*this));
|
||||
return *m_cache;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include "FileSystem.h"
|
||||
#include <AK/ByteBuffer.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class DiskCache;
|
||||
|
||||
class DiskBackedFS : public FS {
|
||||
|
@ -60,3 +62,5 @@ private:
|
|||
NonnullRefPtr<BlockDevice> m_device;
|
||||
mutable OwnPtr<DiskCache> m_cache;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
|
||||
//#define EXT2_DEBUG
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
static const size_t max_link_count = 65535;
|
||||
static const size_t max_block_size = 4096;
|
||||
static const ssize_t max_inline_symlink_length = 60;
|
||||
|
@ -573,7 +575,7 @@ InodeMetadata Ext2FSInode::metadata() const
|
|||
metadata.block_size = fs().block_size();
|
||||
metadata.block_count = m_raw_inode.i_blocks;
|
||||
|
||||
if (::is_character_device(m_raw_inode.i_mode) || ::is_block_device(m_raw_inode.i_mode)) {
|
||||
if (Kernel::is_character_device(m_raw_inode.i_mode) || Kernel::is_block_device(m_raw_inode.i_mode)) {
|
||||
unsigned dev = m_raw_inode.i_block[0];
|
||||
if (!dev)
|
||||
dev = m_raw_inode.i_block[1];
|
||||
|
@ -1646,3 +1648,5 @@ KResult Ext2FS::prepare_to_unmount() const
|
|||
m_inode_cache.clear();
|
||||
return KSuccess;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,16 +27,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Bitmap.h>
|
||||
#include <Kernel/KBuffer.h>
|
||||
#include <Kernel/FileSystem/DiskBackedFileSystem.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/FileSystem/ext2_fs.h>
|
||||
#include <Kernel/KBuffer.h>
|
||||
#include <Kernel/UnixTypes.h>
|
||||
|
||||
struct ext2_group_desc;
|
||||
struct ext2_inode;
|
||||
struct ext2_super_block;
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Ext2FS;
|
||||
|
||||
class Ext2FSInode final : public Inode {
|
||||
|
@ -46,8 +48,8 @@ public:
|
|||
virtual ~Ext2FSInode() override;
|
||||
|
||||
size_t size() const { return m_raw_inode.i_size; }
|
||||
bool is_symlink() const { return ::is_symlink(m_raw_inode.i_mode); }
|
||||
bool is_directory() const { return ::is_directory(m_raw_inode.i_mode); }
|
||||
bool is_symlink() const { return Kernel::is_symlink(m_raw_inode.i_mode); }
|
||||
bool is_directory() const { return Kernel::is_directory(m_raw_inode.i_mode); }
|
||||
|
||||
// ^Inode (RefCounted magic)
|
||||
virtual void one_ref_left() override;
|
||||
|
@ -171,7 +173,8 @@ private:
|
|||
CachedBitmap(BlockIndex bi, KBuffer&& buf)
|
||||
: bitmap_block_index(bi)
|
||||
, buffer(move(buf))
|
||||
{}
|
||||
{
|
||||
}
|
||||
BlockIndex bitmap_block_index { 0 };
|
||||
bool dirty { false };
|
||||
KBuffer buffer;
|
||||
|
@ -192,3 +195,5 @@ inline const Ext2FS& Ext2FSInode::fs() const
|
|||
{
|
||||
return static_cast<const Ext2FS&>(Inode::fs());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
|
||||
//#define FIFO_DEBUG
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
Lockable<HashTable<FIFO*>>& all_fifos()
|
||||
{
|
||||
static Lockable<HashTable<FIFO*>>* s_table;
|
||||
|
@ -143,3 +145,5 @@ String FIFO::absolute_path(const FileDescription&) const
|
|||
{
|
||||
return String::format("fifo:%u", m_fifo_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include <Kernel/FileSystem/File.h>
|
||||
#include <Kernel/UnixTypes.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class FileDescription;
|
||||
|
||||
class FIFO final : public File {
|
||||
|
@ -70,3 +72,5 @@ private:
|
|||
|
||||
int m_fifo_id { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <Kernel/FileSystem/File.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
File::File()
|
||||
{
|
||||
}
|
||||
|
@ -56,3 +58,5 @@ KResultOr<Region*> File::mmap(Process&, FileDescription&, VirtualAddress, size_t
|
|||
{
|
||||
return KResult(-ENODEV);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
#include <Kernel/UnixTypes.h>
|
||||
#include <LibBareMetal/Memory/VirtualAddress.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class FileDescription;
|
||||
class Process;
|
||||
class Region;
|
||||
|
@ -102,3 +104,5 @@ public:
|
|||
protected:
|
||||
File();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullRefPtr<FileDescription> FileDescription::create(Custody& custody)
|
||||
{
|
||||
auto description = adopt(*new FileDescription(InodeFile::create(custody.inode())));
|
||||
|
@ -170,7 +172,6 @@ ByteBuffer FileDescription::read_entire_file()
|
|||
return m_inode->read_entire(this);
|
||||
}
|
||||
|
||||
|
||||
ssize_t FileDescription::get_dir_entries(u8* buffer, ssize_t size)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
|
@ -340,3 +341,5 @@ KResult FileDescription::chown(uid_t uid, gid_t gid)
|
|||
LOCKER(m_lock);
|
||||
return m_file->chown(uid, gid);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,22 +28,23 @@
|
|||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/CircularQueue.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <Kernel/FileSystem/FIFO.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/FileSystem/InodeMetadata.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/KBuffer.h>
|
||||
#include <Kernel/Net/Socket.h>
|
||||
#include <LibBareMetal/Memory/VirtualAddress.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class CharacterDevice;
|
||||
class File;
|
||||
class TTY;
|
||||
class MasterPTY;
|
||||
class Process;
|
||||
class Region;
|
||||
class CharacterDevice;
|
||||
class Socket;
|
||||
class TTY;
|
||||
|
||||
class FileDescription : public RefCounted<FileDescription> {
|
||||
public:
|
||||
|
@ -161,3 +162,5 @@ private:
|
|||
|
||||
Lock m_lock { "FileDescription" };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
static u32 s_lastFileSystemID;
|
||||
static HashMap<u32, FS*>* s_fs_map;
|
||||
|
||||
|
@ -111,3 +113,5 @@ void FS::set_block_size(int block_size)
|
|||
return;
|
||||
m_block_size = block_size;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,8 @@
|
|||
#include <Kernel/Lock.h>
|
||||
#include <Kernel/UnixTypes.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
static const u32 mepoch = 476763780;
|
||||
|
||||
class Inode;
|
||||
|
@ -122,11 +124,13 @@ inline bool InodeIdentifier::is_root_inode() const
|
|||
return (*this) == fs()->root_inode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<>
|
||||
struct Traits<InodeIdentifier> : public GenericTraits<InodeIdentifier> {
|
||||
static unsigned hash(const InodeIdentifier& inode) { return pair_int_hash(inode.fsid(), inode.index()); }
|
||||
struct Traits<Kernel::InodeIdentifier> : public GenericTraits<Kernel::InodeIdentifier> {
|
||||
static unsigned hash(const Kernel::InodeIdentifier& inode) { return pair_int_hash(inode.fsid(), inode.index()); }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
InlineLinkedList<Inode>& all_inodes()
|
||||
{
|
||||
static InlineLinkedList<Inode>* list;
|
||||
|
@ -213,3 +215,5 @@ void Inode::set_metadata_dirty(bool metadata_dirty)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/InlineLinkedList.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <Kernel/FileSystem/FileSystem.h>
|
||||
#include <Kernel/FileSystem/InodeIdentifier.h>
|
||||
|
@ -37,6 +37,8 @@
|
|||
#include <Kernel/KResult.h>
|
||||
#include <Kernel/Lock.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class FileDescription;
|
||||
class InodeVMObject;
|
||||
class InodeWatcher;
|
||||
|
@ -132,3 +134,5 @@ private:
|
|||
HashTable<InodeWatcher*> m_watchers;
|
||||
bool m_metadata_dirty { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/Process.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
InodeFile::InodeFile(NonnullRefPtr<Inode>&& inode)
|
||||
: m_inode(move(inode))
|
||||
{
|
||||
|
@ -94,3 +96,5 @@ KResult InodeFile::chmod(mode_t mode)
|
|||
{
|
||||
return VFS::the().chmod(*m_inode, mode);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#include <Kernel/FileSystem/File.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Inode;
|
||||
|
||||
class InodeFile final : public File {
|
||||
|
@ -64,3 +66,5 @@ private:
|
|||
explicit InodeFile(NonnullRefPtr<Inode>&&);
|
||||
NonnullRefPtr<Inode> m_inode;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,10 +26,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class FS;
|
||||
struct InodeMetadata;
|
||||
|
||||
|
@ -75,3 +77,4 @@ inline const LogStream& operator<<(const LogStream& stream, const InodeIdentifie
|
|||
return stream;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <Kernel/KResult.h>
|
||||
#include <Kernel/UnixTypes.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Process;
|
||||
|
||||
inline constexpr u32 encoded_device(unsigned major, unsigned minor)
|
||||
|
@ -89,17 +91,17 @@ struct InodeMetadata {
|
|||
return mode & 0001;
|
||||
}
|
||||
|
||||
bool is_directory() const { return ::is_directory(mode); }
|
||||
bool is_character_device() const { return ::is_character_device(mode); }
|
||||
bool is_block_device() const { return ::is_block_device(mode); }
|
||||
bool is_directory() const { return Kernel::is_directory(mode); }
|
||||
bool is_character_device() const { return Kernel::is_character_device(mode); }
|
||||
bool is_block_device() const { return Kernel::is_block_device(mode); }
|
||||
bool is_device() const { return is_character_device() || is_block_device(); }
|
||||
bool is_regular_file() const { return ::is_regular_file(mode); }
|
||||
bool is_fifo() const { return ::is_fifo(mode); }
|
||||
bool is_symlink() const { return ::is_symlink(mode); }
|
||||
bool is_socket() const { return ::is_socket(mode); }
|
||||
bool is_sticky() const { return ::is_sticky(mode); }
|
||||
bool is_setuid() const { return ::is_setuid(mode); }
|
||||
bool is_setgid() const { return ::is_setgid(mode); }
|
||||
bool is_regular_file() const { return Kernel::is_regular_file(mode); }
|
||||
bool is_fifo() const { return Kernel::is_fifo(mode); }
|
||||
bool is_symlink() const { return Kernel::is_symlink(mode); }
|
||||
bool is_socket() const { return Kernel::is_socket(mode); }
|
||||
bool is_sticky() const { return Kernel::is_sticky(mode); }
|
||||
bool is_setuid() const { return Kernel::is_setuid(mode); }
|
||||
bool is_setgid() const { return Kernel::is_setgid(mode); }
|
||||
|
||||
KResult stat(stat& buffer) const
|
||||
{
|
||||
|
@ -136,3 +138,5 @@ struct InodeMetadata {
|
|||
unsigned major_device { 0 };
|
||||
unsigned minor_device { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/FileSystem/InodeWatcher.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullRefPtr<InodeWatcher> InodeWatcher::create(Inode& inode)
|
||||
{
|
||||
return adopt(*new InodeWatcher(inode));
|
||||
|
@ -84,3 +86,5 @@ void InodeWatcher::notify_inode_event(Badge<Inode>, Event::Type event_type)
|
|||
{
|
||||
m_queue.enqueue({ event_type });
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <AK/WeakPtr.h>
|
||||
#include <Kernel/FileSystem/File.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Inode;
|
||||
|
||||
class InodeWatcher final : public File {
|
||||
|
@ -62,3 +64,5 @@ private:
|
|||
WeakPtr<Inode> m_inode;
|
||||
CircularQueue<Event, 32> m_queue;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@
|
|||
#include <LibBareMetal/StdLib.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
enum ProcParentDirectory {
|
||||
PDI_AbstractRoot = 0,
|
||||
PDI_Root,
|
||||
|
@ -1219,7 +1221,7 @@ bool ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)
|
|||
dbgprintf("ProcFS: traverse_as_directory %u\n", index());
|
||||
#endif
|
||||
|
||||
if (!::is_directory(identifier()))
|
||||
if (!Kernel::is_directory(identifier()))
|
||||
return false;
|
||||
|
||||
auto pid = to_pid(identifier());
|
||||
|
@ -1622,3 +1624,5 @@ KResult ProcFSInode::chown(uid_t, gid_t)
|
|||
{
|
||||
return KResult(-EPERM);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include <Kernel/KBuffer.h>
|
||||
#include <Kernel/Lock.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class Process;
|
||||
|
||||
class ProcFSInode;
|
||||
|
@ -147,3 +149,5 @@ private:
|
|||
|
||||
NonnullRefPtr<FileDescription> m_fd;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Thread.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullRefPtr<TmpFS> TmpFS::create()
|
||||
{
|
||||
return adopt(*new TmpFS);
|
||||
|
@ -397,3 +399,5 @@ void TmpFSInode::one_ref_left()
|
|||
// Destroy ourselves.
|
||||
fs().unregister_inode(identifier());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/KBuffer.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class TmpFSInode;
|
||||
|
||||
class TmpFS final : public FS {
|
||||
|
@ -106,3 +108,5 @@ private:
|
|||
};
|
||||
HashMap<String, Child> m_children;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -32,11 +32,14 @@
|
|||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/FileSystem/FileSystem.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/KSyms.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
|
||||
//#define VFS_DEBUG
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
static VFS* s_the;
|
||||
static constexpr int symlink_recursion_limit { 5 }; // FIXME: increase?
|
||||
|
||||
|
@ -848,3 +851,5 @@ KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& ba
|
|||
*out_parent = custody->parent();
|
||||
return custody;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <Kernel/FileSystem/InodeMetadata.h>
|
||||
#include <Kernel/KResult.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
#define O_RDONLY (1 << 0)
|
||||
#define O_WRONLY (1 << 1)
|
||||
|
@ -159,3 +160,5 @@ private:
|
|||
|
||||
RefPtr<Custody> m_root_custody;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue