diff --git a/kernel/include/kernel/BootInfo.h b/kernel/include/kernel/BootInfo.h index 62760da6..452f9b3d 100644 --- a/kernel/include/kernel/BootInfo.h +++ b/kernel/include/kernel/BootInfo.h @@ -55,5 +55,6 @@ namespace Kernel BAN::StringView get_early_boot_command_line(uint32_t magic, uint32_t info); extern BootInfo g_boot_info; + extern bool g_disable_disk_write; } diff --git a/kernel/kernel/BootInfo.cpp b/kernel/kernel/BootInfo.cpp index 73a9cdd4..d9712783 100644 --- a/kernel/kernel/BootInfo.cpp +++ b/kernel/kernel/BootInfo.cpp @@ -6,6 +6,7 @@ namespace Kernel { BootInfo g_boot_info; + bool g_disable_disk_write { false }; static MemoryMapEntry::Type bios_number_to_memory_type(uint32_t number) { diff --git a/kernel/kernel/Storage/DiskCache.cpp b/kernel/kernel/Storage/DiskCache.cpp index f88ffb0f..b958db83 100644 --- a/kernel/kernel/Storage/DiskCache.cpp +++ b/kernel/kernel/Storage/DiskCache.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -105,6 +106,9 @@ namespace Kernel BAN::ErrorOr DiskCache::sync() { + if (g_disable_disk_write) + return {}; + for (auto& cache : m_cache) { if (cache.dirty_mask == 0) diff --git a/kernel/kernel/Storage/StorageDevice.cpp b/kernel/kernel/Storage/StorageDevice.cpp index 624fa8ac..2cd7eded 100644 --- a/kernel/kernel/Storage/StorageDevice.cpp +++ b/kernel/kernel/Storage/StorageDevice.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -265,6 +266,13 @@ namespace Kernel LockGuard _(m_mutex); + if (g_disable_disk_write) + { + if (!m_disk_cache.has_value()) + return BAN::Error::from_errno(EIO); + return m_disk_cache->write_to_cache(lba, buffer, true); + } + if (!m_disk_cache.has_value()) return write_sectors_impl(lba, sector_count, buffer); diff --git a/kernel/kernel/kernel.cpp b/kernel/kernel/kernel.cpp index 51ff6e9a..4b951702 100644 --- a/kernel/kernel/kernel.cpp +++ b/kernel/kernel/kernel.cpp @@ -85,6 +85,8 @@ static void parse_command_line() cmdline.disable_usb = true; else if (argument == "noacpi") cmdline.disable_acpi = true; + else if (argument == "readonly") + Kernel::g_disable_disk_write = true; else if (argument == "nodebug") g_disable_debug = true; else if (argument.starts_with("ps2="))