diff --git a/kernel/kernel/FS/FAT/FileSystem.cpp b/kernel/kernel/FS/FAT/FileSystem.cpp index a3ab8afc..3c1f701a 100644 --- a/kernel/kernel/FS/FAT/FileSystem.cpp +++ b/kernel/kernel/FS/FAT/FileSystem.cpp @@ -2,6 +2,7 @@ #include #include +#include namespace Kernel { @@ -73,7 +74,7 @@ namespace Kernel fsfilcnt_t FATFS::ffree() const { return 0; } // FIXME fsfilcnt_t FATFS::favail() const { return 0; } // FIXME unsigned long FATFS::fsid() const { return m_type == Type::FAT32 ? m_bpb.ext_32.volume_id : m_bpb.ext_12_16.volume_id; } - unsigned long FATFS::flag() const { return 0; } + unsigned long FATFS::flag() const { return ST_RDONLY; } unsigned long FATFS::namemax() const { return 255; } BAN::ErrorOr> FATFS::create(BAN::RefPtr block_device) diff --git a/kernel/kernel/FS/Inode.cpp b/kernel/kernel/FS/Inode.cpp index 8118b1b3..05563843 100644 --- a/kernel/kernel/FS/Inode.cpp +++ b/kernel/kernel/FS/Inode.cpp @@ -1,9 +1,11 @@ #include +#include #include #include #include #include +#include namespace Kernel { @@ -81,6 +83,8 @@ namespace Kernel return BAN::Error::from_errno(ENOTDIR); if (Mode(mode).ifdir()) return BAN::Error::from_errno(EINVAL); + if (auto* fs = filesystem(); fs && (fs->flag() & ST_RDONLY)) + return BAN::Error::from_errno(EROFS); return create_file_impl(name, mode, uid, gid); } @@ -91,6 +95,8 @@ namespace Kernel return BAN::Error::from_errno(ENOTDIR); if (!Mode(mode).ifdir()) return BAN::Error::from_errno(EINVAL); + if (auto* fs = filesystem(); fs && (fs->flag() & ST_RDONLY)) + return BAN::Error::from_errno(EROFS); return create_directory_impl(name, mode, uid, gid); } @@ -101,6 +107,8 @@ namespace Kernel return BAN::Error::from_errno(ENOTDIR); if (inode->mode().ifdir()) return BAN::Error::from_errno(EINVAL); + if (auto* fs = filesystem(); fs && (fs->flag() & ST_RDONLY)) + return BAN::Error::from_errno(EROFS); return link_inode_impl(name, inode); } @@ -111,6 +119,8 @@ namespace Kernel return BAN::Error::from_errno(ENOTDIR); if (name == "."_sv || name == ".."_sv) return BAN::Error::from_errno(EINVAL); + if (auto* fs = filesystem(); fs && (fs->flag() & ST_RDONLY)) + return BAN::Error::from_errno(EROFS); return unlink_impl(name); } @@ -127,6 +137,8 @@ namespace Kernel LockGuard _(m_mutex); if (!mode().iflnk()) return BAN::Error::from_errno(EINVAL); + if (auto* fs = filesystem(); fs && (fs->flag() & ST_RDONLY)) + return BAN::Error::from_errno(EROFS); return set_link_target_impl(target); } @@ -207,6 +219,8 @@ namespace Kernel LockGuard _(m_mutex); if (mode().ifdir()) return BAN::Error::from_errno(EISDIR); + if (auto* fs = filesystem(); fs && (fs->flag() & ST_RDONLY)) + return BAN::Error::from_errno(EROFS); return write_impl(offset, buffer); } @@ -215,6 +229,8 @@ namespace Kernel LockGuard _(m_mutex); if (mode().ifdir()) return BAN::Error::from_errno(EISDIR); + if (auto* fs = filesystem(); fs && (fs->flag() & ST_RDONLY)) + return BAN::Error::from_errno(EROFS); return truncate_impl(size); } @@ -222,18 +238,24 @@ namespace Kernel { ASSERT((mode & Inode::Mode::TYPE_MASK) == 0); LockGuard _(m_mutex); + if (auto* fs = filesystem(); fs && (fs->flag() & ST_RDONLY)) + return BAN::Error::from_errno(EROFS); return chmod_impl(mode); } BAN::ErrorOr Inode::chown(uid_t uid, gid_t gid) { LockGuard _(m_mutex); + if (auto* fs = filesystem(); fs && (fs->flag() & ST_RDONLY)) + return BAN::Error::from_errno(EROFS); return chown_impl(uid, gid); } BAN::ErrorOr Inode::utimens(const timespec times[2]) { LockGuard _(m_mutex); + if (auto* fs = filesystem(); fs && (fs->flag() & ST_RDONLY)) + return BAN::Error::from_errno(EROFS); return utimens_impl(times); }