summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/FileSystem/BlockBasedFileSystem.cpp10
-rw-r--r--Kernel/FileSystem/BlockBasedFileSystem.h2
-rw-r--r--Kernel/FileSystem/DevFS.cpp4
-rw-r--r--Kernel/FileSystem/DevFS.h2
-rw-r--r--Kernel/FileSystem/DevPtsFS.cpp10
-rw-r--r--Kernel/FileSystem/DevPtsFS.h2
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp24
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.h2
-rw-r--r--Kernel/FileSystem/FileSystem.h2
-rw-r--r--Kernel/FileSystem/ISO9660FileSystem.cpp21
-rw-r--r--Kernel/FileSystem/ISO9660FileSystem.h2
-rw-r--r--Kernel/FileSystem/Plan9FileSystem.cpp10
-rw-r--r--Kernel/FileSystem/Plan9FileSystem.h2
-rw-r--r--Kernel/FileSystem/ProcFS.cpp4
-rw-r--r--Kernel/FileSystem/ProcFS.h2
-rw-r--r--Kernel/FileSystem/SysFS.cpp4
-rw-r--r--Kernel/FileSystem/SysFS.h2
-rw-r--r--Kernel/FileSystem/TmpFS.cpp6
-rw-r--r--Kernel/FileSystem/TmpFS.h2
-rw-r--r--Kernel/Storage/StorageManagement.cpp4
-rw-r--r--Kernel/Syscalls/mount.cpp4
21 files changed, 62 insertions, 59 deletions
diff --git a/Kernel/FileSystem/BlockBasedFileSystem.cpp b/Kernel/FileSystem/BlockBasedFileSystem.cpp
index c417c24c64..56197f72ab 100644
--- a/Kernel/FileSystem/BlockBasedFileSystem.cpp
+++ b/Kernel/FileSystem/BlockBasedFileSystem.cpp
@@ -114,26 +114,26 @@ BlockBasedFileSystem::~BlockBasedFileSystem()
{
}
-bool BlockBasedFileSystem::initialize()
+KResult BlockBasedFileSystem::initialize()
{
VERIFY(block_size() != 0);
auto cached_block_data = KBuffer::try_create_with_size(DiskCache::EntryCount * block_size());
if (!cached_block_data)
- return false;
+ return ENOMEM;
auto entries_data = KBuffer::try_create_with_size(DiskCache::EntryCount * sizeof(CacheEntry));
if (!entries_data)
- return false;
+ return ENOMEM;
auto disk_cache = adopt_own_if_nonnull(new (nothrow) DiskCache(*this, cached_block_data.release_nonnull(), entries_data.release_nonnull()));
if (!disk_cache)
- return false;
+ return ENOMEM;
m_cache.with_exclusive([&](auto& cache) {
cache = move(disk_cache);
});
- return true;
+ return KSuccess;
}
KResult BlockBasedFileSystem::write_block(BlockIndex index, const UserOrKernelBuffer& data, size_t count, size_t offset, bool allow_cache)
diff --git a/Kernel/FileSystem/BlockBasedFileSystem.h b/Kernel/FileSystem/BlockBasedFileSystem.h
index ccb0ec4a0b..2efbaf93b2 100644
--- a/Kernel/FileSystem/BlockBasedFileSystem.h
+++ b/Kernel/FileSystem/BlockBasedFileSystem.h
@@ -16,7 +16,7 @@ public:
TYPEDEF_DISTINCT_ORDERED_ID(u64, BlockIndex);
virtual ~BlockBasedFileSystem() override;
- virtual bool initialize() override;
+ virtual KResult initialize() override;
u64 logical_block_size() const { return m_logical_block_size; };
diff --git a/Kernel/FileSystem/DevFS.cpp b/Kernel/FileSystem/DevFS.cpp
index ed4c595900..dd168196c5 100644
--- a/Kernel/FileSystem/DevFS.cpp
+++ b/Kernel/FileSystem/DevFS.cpp
@@ -56,9 +56,9 @@ DevFS::~DevFS()
{
}
-bool DevFS::initialize()
+KResult DevFS::initialize()
{
- return true;
+ return KSuccess;
}
Inode& DevFS::root_inode()
diff --git a/Kernel/FileSystem/DevFS.h b/Kernel/FileSystem/DevFS.h
index 0f81af6394..a28ee5dde2 100644
--- a/Kernel/FileSystem/DevFS.h
+++ b/Kernel/FileSystem/DevFS.h
@@ -22,7 +22,7 @@ public:
virtual ~DevFS() override;
static NonnullRefPtr<DevFS> create();
- virtual bool initialize() override;
+ virtual KResult initialize() override;
virtual StringView class_name() const override { return "DevFS"sv; }
void notify_new_device(Device&);
diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS.cpp
index ee5c2a4b46..2290449b29 100644
--- a/Kernel/FileSystem/DevPtsFS.cpp
+++ b/Kernel/FileSystem/DevPtsFS.cpp
@@ -27,17 +27,19 @@ DevPtsFS::~DevPtsFS()
static Singleton<HashTable<unsigned>> s_ptys;
-bool DevPtsFS::initialize()
+KResult DevPtsFS::initialize()
{
- m_root_inode = adopt_ref(*new DevPtsFSInode(*this, 1, nullptr));
+ m_root_inode = adopt_ref_if_nonnull(new (nothrow) DevPtsFSInode(*this, 1, nullptr));
+ if (!m_root_inode)
+ return ENOMEM;
+
m_root_inode->m_metadata.inode = { fsid(), 1 };
m_root_inode->m_metadata.mode = 0040555;
m_root_inode->m_metadata.uid = 0;
m_root_inode->m_metadata.gid = 0;
m_root_inode->m_metadata.size = 0;
m_root_inode->m_metadata.mtime = mepoch;
-
- return true;
+ return KSuccess;
}
static unsigned inode_index_to_pty_index(InodeIndex inode_index)
diff --git a/Kernel/FileSystem/DevPtsFS.h b/Kernel/FileSystem/DevPtsFS.h
index 68c539bb42..9efbb3ba00 100644
--- a/Kernel/FileSystem/DevPtsFS.h
+++ b/Kernel/FileSystem/DevPtsFS.h
@@ -22,7 +22,7 @@ public:
virtual ~DevPtsFS() override;
static NonnullRefPtr<DevPtsFS> create();
- virtual bool initialize() override;
+ virtual KResult initialize() override;
virtual StringView class_name() const override { return "DevPtsFS"sv; }
virtual Inode& root_inode() override;
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp
index b34582c934..9acb591a0f 100644
--- a/Kernel/FileSystem/Ext2FileSystem.cpp
+++ b/Kernel/FileSystem/Ext2FileSystem.cpp
@@ -86,7 +86,7 @@ const ext2_group_desc& Ext2FS::group_descriptor(GroupIndex group_index) const
return block_group_descriptors()[group_index.value() - 1];
}
-bool Ext2FS::initialize()
+KResult Ext2FS::initialize()
{
MutexLocker locker(m_lock);
@@ -99,8 +99,10 @@ bool Ext2FS::initialize()
if constexpr (EXT2_DEBUG) {
dmesgln("Ext2FS: super block magic: {:04x} (super block size: {})", super_block.s_magic, sizeof(ext2_super_block));
}
- if (super_block.s_magic != EXT2_SUPER_MAGIC)
- return false;
+ if (super_block.s_magic != EXT2_SUPER_MAGIC) {
+ dmesgln("Ext2FS: Bad super block magic");
+ return EINVAL;
+ }
if constexpr (EXT2_DEBUG) {
dmesgln("Ext2FS: {} inodes, {} blocks", super_block.s_inodes_count, super_block.s_blocks_count);
@@ -117,9 +119,8 @@ bool Ext2FS::initialize()
set_fragment_size(EXT2_FRAG_SIZE(&super_block));
// Note: This depends on the block size being available.
- auto baseclass_result = BlockBasedFileSystem::initialize();
- if (!baseclass_result)
- return baseclass_result;
+ if (auto result = BlockBasedFileSystem::initialize(); result.is_error())
+ return result;
VERIFY(block_size() <= (int)max_block_size);
@@ -127,7 +128,7 @@ bool Ext2FS::initialize()
if (m_block_group_count == 0) {
dmesgln("Ext2FS: no block groups :(");
- return false;
+ return EINVAL;
}
auto blocks_to_read = ceil_div(m_block_group_count * sizeof(ext2_group_desc), block_size());
@@ -135,13 +136,12 @@ bool Ext2FS::initialize()
m_cached_group_descriptor_table = KBuffer::try_create_with_size(block_size() * blocks_to_read, Memory::Region::Access::ReadWrite, "Ext2FS: Block group descriptors");
if (!m_cached_group_descriptor_table) {
dbgln("Ext2FS: Failed to allocate memory for group descriptor table");
- return false;
+ return ENOMEM;
}
auto buffer = UserOrKernelBuffer::for_kernel_buffer(m_cached_group_descriptor_table->data());
if (auto result = read_blocks(first_block_of_bgdt, blocks_to_read, buffer); result.is_error()) {
- // FIXME: Propagate the error
dbgln("Ext2FS: initialize had error: {}", result.error());
- return false;
+ return result;
}
if constexpr (EXT2_DEBUG) {
@@ -154,10 +154,10 @@ bool Ext2FS::initialize()
m_root_inode = static_ptr_cast<Ext2FSInode>(get_inode({ fsid(), EXT2_ROOT_INO }));
if (!m_root_inode) {
dbgln("Ext2FS: failed to acquire root inode");
- return false;
+ return EINVAL;
}
- return true;
+ return KSuccess;
}
Ext2FSInode& Ext2FS::root_inode()
diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h
index b434f63a15..8ef16a05f2 100644
--- a/Kernel/FileSystem/Ext2FileSystem.h
+++ b/Kernel/FileSystem/Ext2FileSystem.h
@@ -92,7 +92,7 @@ public:
static NonnullRefPtr<Ext2FS> create(FileDescription&);
virtual ~Ext2FS() override;
- virtual bool initialize() override;
+ virtual KResult initialize() override;
virtual unsigned total_block_count() const override;
virtual unsigned free_block_count() const override;
diff --git a/Kernel/FileSystem/FileSystem.h b/Kernel/FileSystem/FileSystem.h
index 04cce7d878..2f511d6daf 100644
--- a/Kernel/FileSystem/FileSystem.h
+++ b/Kernel/FileSystem/FileSystem.h
@@ -31,7 +31,7 @@ public:
static void sync();
static void lock_all();
- virtual bool initialize() = 0;
+ virtual KResult initialize() = 0;
virtual StringView class_name() const = 0;
virtual Inode& root_inode() = 0;
virtual bool supports_watchers() const { return false; }
diff --git a/Kernel/FileSystem/ISO9660FileSystem.cpp b/Kernel/FileSystem/ISO9660FileSystem.cpp
index 3d2b852f0c..127efe9a47 100644
--- a/Kernel/FileSystem/ISO9660FileSystem.cpp
+++ b/Kernel/FileSystem/ISO9660FileSystem.cpp
@@ -202,18 +202,15 @@ ISO9660FS::~ISO9660FS()
{
}
-bool ISO9660FS::initialize()
-{
- if (!BlockBasedFileSystem::initialize())
- return false;
-
- // FIXME: Fix the FileSystem::initialize contract to be able to return a
- // KResult.
- if (parse_volume_set().is_error())
- return false;
- if (create_root_inode().is_error())
- return false;
- return true;
+KResult ISO9660FS::initialize()
+{
+ if (auto result = BlockBasedFileSystem::initialize(); result.is_error())
+ return result;
+ if (auto result = parse_volume_set(); result.is_error())
+ return result;
+ if (auto result = create_root_inode(); result.is_error())
+ return result;
+ return KSuccess;
}
Inode& ISO9660FS::root_inode()
diff --git a/Kernel/FileSystem/ISO9660FileSystem.h b/Kernel/FileSystem/ISO9660FileSystem.h
index e4a46d3f32..9d6e35df3f 100644
--- a/Kernel/FileSystem/ISO9660FileSystem.h
+++ b/Kernel/FileSystem/ISO9660FileSystem.h
@@ -312,7 +312,7 @@ public:
static KResultOr<NonnullRefPtr<ISO9660FS>> try_create(FileDescription&);
virtual ~ISO9660FS() override;
- virtual bool initialize() override;
+ virtual KResult initialize() override;
virtual StringView class_name() const override { return "ISO9660FS"; }
virtual Inode& root_inode() override;
diff --git a/Kernel/FileSystem/Plan9FileSystem.cpp b/Kernel/FileSystem/Plan9FileSystem.cpp
index 657ba67a5e..163e69d6bd 100644
--- a/Kernel/FileSystem/Plan9FileSystem.cpp
+++ b/Kernel/FileSystem/Plan9FileSystem.cpp
@@ -195,7 +195,7 @@ private:
bool m_have_been_built { false };
};
-bool Plan9FS::initialize()
+KResult Plan9FS::initialize()
{
ensure_thread();
@@ -204,7 +204,7 @@ bool Plan9FS::initialize()
auto result = post_message_and_wait_for_a_reply(version_message);
if (result.is_error())
- return false;
+ return result;
u32 msize;
StringView remote_protocol_version;
@@ -227,11 +227,13 @@ bool Plan9FS::initialize()
result = post_message_and_wait_for_a_reply(attach_message);
if (result.is_error()) {
dbgln("Attaching failed");
- return false;
+ return result;
}
m_root_inode = Plan9FSInode::create(*this, root_fid);
- return true;
+ if (!m_root_inode)
+ return ENOMEM;
+ return KSuccess;
}
Plan9FS::ProtocolVersion Plan9FS::parse_protocol_version(const StringView& s) const
diff --git a/Kernel/FileSystem/Plan9FileSystem.h b/Kernel/FileSystem/Plan9FileSystem.h
index 9301fca091..95e9a5d059 100644
--- a/Kernel/FileSystem/Plan9FileSystem.h
+++ b/Kernel/FileSystem/Plan9FileSystem.h
@@ -22,7 +22,7 @@ public:
virtual ~Plan9FS() override;
static NonnullRefPtr<Plan9FS> create(FileDescription&);
- virtual bool initialize() override;
+ virtual KResult initialize() override;
virtual bool supports_watchers() const override { return false; }
diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp
index 59c0864fe8..b92200ea6d 100644
--- a/Kernel/FileSystem/ProcFS.cpp
+++ b/Kernel/FileSystem/ProcFS.cpp
@@ -51,9 +51,9 @@ ProcFS::~ProcFS()
{
}
-bool ProcFS::initialize()
+KResult ProcFS::initialize()
{
- return true;
+ return KSuccess;
}
Inode& ProcFS::root_inode()
diff --git a/Kernel/FileSystem/ProcFS.h b/Kernel/FileSystem/ProcFS.h
index d03eb57c71..1aaa2b1512 100644
--- a/Kernel/FileSystem/ProcFS.h
+++ b/Kernel/FileSystem/ProcFS.h
@@ -30,7 +30,7 @@ public:
virtual ~ProcFS() override;
static RefPtr<ProcFS> create();
- virtual bool initialize() override;
+ virtual KResult initialize() override;
virtual StringView class_name() const override { return "ProcFS"sv; }
virtual Inode& root_inode() override;
diff --git a/Kernel/FileSystem/SysFS.cpp b/Kernel/FileSystem/SysFS.cpp
index 77488554c5..54503162e5 100644
--- a/Kernel/FileSystem/SysFS.cpp
+++ b/Kernel/FileSystem/SysFS.cpp
@@ -75,9 +75,9 @@ SysFS::~SysFS()
{
}
-bool SysFS::initialize()
+KResult SysFS::initialize()
{
- return true;
+ return KSuccess;
}
Inode& SysFS::root_inode()
diff --git a/Kernel/FileSystem/SysFS.h b/Kernel/FileSystem/SysFS.h
index 836a0220c9..94f4ed8e65 100644
--- a/Kernel/FileSystem/SysFS.h
+++ b/Kernel/FileSystem/SysFS.h
@@ -62,7 +62,7 @@ public:
virtual ~SysFS() override;
static NonnullRefPtr<SysFS> create();
- virtual bool initialize() override;
+ virtual KResult initialize() override;
virtual StringView class_name() const override { return "SysFS"sv; }
virtual Inode& root_inode() override;
diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp
index ba62609c79..da72fb1ac2 100644
--- a/Kernel/FileSystem/TmpFS.cpp
+++ b/Kernel/FileSystem/TmpFS.cpp
@@ -23,10 +23,12 @@ TmpFS::~TmpFS()
{
}
-bool TmpFS::initialize()
+KResult TmpFS::initialize()
{
m_root_inode = TmpFSInode::create_root(*this);
- return !m_root_inode.is_null();
+ if (!m_root_inode)
+ return ENOMEM;
+ return KSuccess;
}
Inode& TmpFS::root_inode()
diff --git a/Kernel/FileSystem/TmpFS.h b/Kernel/FileSystem/TmpFS.h
index 9aa96aea18..611a59d293 100644
--- a/Kernel/FileSystem/TmpFS.h
+++ b/Kernel/FileSystem/TmpFS.h
@@ -20,7 +20,7 @@ class TmpFS final : public FileSystem {
public:
virtual ~TmpFS() override;
static RefPtr<TmpFS> create();
- virtual bool initialize() override;
+ virtual KResult initialize() override;
virtual StringView class_name() const override { return "TmpFS"sv; }
diff --git a/Kernel/Storage/StorageManagement.cpp b/Kernel/Storage/StorageManagement.cpp
index b61854690d..45f83cf56b 100644
--- a/Kernel/Storage/StorageManagement.cpp
+++ b/Kernel/Storage/StorageManagement.cpp
@@ -183,8 +183,8 @@ NonnullRefPtr<FileSystem> StorageManagement::root_filesystem() const
PANIC("StorageManagement: Couldn't find a suitable device to boot from");
}
auto e2fs = Ext2FS::create(FileDescription::create(boot_device_description.release_nonnull()).value());
- if (!e2fs->initialize()) {
- PANIC("StorageManagement: Couldn't open root filesystem");
+ if (auto result = e2fs->initialize(); result.is_error()) {
+ PANIC("StorageManagement: Couldn't open root filesystem: {}", result);
}
return e2fs;
}
diff --git a/Kernel/Syscalls/mount.cpp b/Kernel/Syscalls/mount.cpp
index 2591aa9976..f8a6d8f30b 100644
--- a/Kernel/Syscalls/mount.cpp
+++ b/Kernel/Syscalls/mount.cpp
@@ -121,9 +121,9 @@ KResultOr<FlatPtr> Process::sys$mount(Userspace<const Syscall::SC_mount_params*>
if (!fs)
return ENOMEM;
- if (!fs->initialize()) {
+ if (auto result = fs->initialize(); result.is_error()) {
dbgln("mount: failed to initialize {} filesystem, fd={}", fs_type, source_fd);
- return ENODEV;
+ return result;
}
auto result = VirtualFileSystem::the().mount(fs.release_nonnull(), target_custody, params.flags);