Kernel/LibC: Implement fsync

This commit is contained in:
2024-12-02 03:42:49 +02:00
parent cccb4e6d5e
commit 747c3b2a4b
21 changed files with 140 additions and 35 deletions

View File

@@ -24,6 +24,8 @@ namespace Kernel
protected:
Device(mode_t, uid_t, gid_t);
virtual BAN::ErrorOr<void> fsync_impl() final override { return BAN::Error::from_errno(EINVAL); }
};
class BlockDevice : public Device
@@ -31,6 +33,7 @@ namespace Kernel
public:
virtual BAN::ErrorOr<void> read_blocks(uint64_t first_block, size_t block_count, BAN::ByteSpan) = 0;
virtual BAN::ErrorOr<void> write_blocks(uint64_t first_block, size_t block_count, BAN::ConstByteSpan) = 0;
virtual BAN::ErrorOr<void> sync_blocks(uint64_t block, size_t block_count) = 0;
virtual blksize_t blksize() const = 0;

View File

@@ -67,6 +67,7 @@ namespace Kernel
BAN::ErrorOr<void> read_block(uint32_t, BlockBufferWrapper&);
BAN::ErrorOr<void> write_block(uint32_t, const BlockBufferWrapper&);
BAN::ErrorOr<void> sync_superblock();
BAN::ErrorOr<void> sync_block(uint32_t block);
BlockBufferWrapper get_block_buffer();

View File

@@ -42,6 +42,7 @@ namespace Kernel
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
virtual BAN::ErrorOr<void> truncate_impl(size_t) override;
virtual BAN::ErrorOr<void> chmod_impl(mode_t) override;
virtual BAN::ErrorOr<void> fsync_impl() override;
virtual bool can_read_impl() const override { return true; }
virtual bool can_write_impl() const override { return true; }

View File

@@ -42,6 +42,7 @@ namespace Kernel
//virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
//virtual BAN::ErrorOr<void> truncate_impl(size_t) override;
//virtual BAN::ErrorOr<void> chmod_impl(mode_t) override;
virtual BAN::ErrorOr<void> fsync_impl() override { return {}; }
virtual bool can_read_impl() const override { return true; }
virtual bool can_write_impl() const override { return true; }

View File

@@ -111,6 +111,7 @@ namespace Kernel
BAN::ErrorOr<void> truncate(size_t);
BAN::ErrorOr<void> chmod(mode_t);
BAN::ErrorOr<void> chown(uid_t, gid_t);
BAN::ErrorOr<void> fsync();
// Select/Non blocking API
bool can_read() const;
@@ -145,6 +146,7 @@ namespace Kernel
virtual BAN::ErrorOr<void> truncate_impl(size_t) { return BAN::Error::from_errno(ENOTSUP); }
virtual BAN::ErrorOr<void> chmod_impl(mode_t) { return BAN::Error::from_errno(ENOTSUP); }
virtual BAN::ErrorOr<void> chown_impl(uid_t, gid_t) { return BAN::Error::from_errno(ENOTSUP); }
virtual BAN::ErrorOr<void> fsync_impl() = 0;
// Select/Non blocking API
virtual bool can_read_impl() const = 0;

View File

@@ -33,6 +33,7 @@ namespace Kernel
protected:
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
virtual BAN::ErrorOr<void> fsync_impl() final override { return {}; }
virtual bool can_read_impl() const override { return m_buffer_size > 0; }
virtual bool can_write_impl() const override { return true; }

View File

@@ -51,6 +51,7 @@ namespace Kernel
BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan buffer) override { return recvfrom_impl(buffer, nullptr, nullptr); }
BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan buffer) override { return sendto_impl(buffer, nullptr, 0); }
BAN::ErrorOr<void> fsync_impl() final override { return {}; }
private:
const Info m_info;

View File

@@ -45,6 +45,8 @@ namespace Kernel
protected:
TmpInode(TmpFileSystem&, ino_t, const TmpInodeInfo&);
virtual BAN::ErrorOr<void> fsync_impl() override { return {}; }
void sync();
void free_all_blocks();
virtual BAN::ErrorOr<void> prepare_unlink() { return {}; };

View File

@@ -143,6 +143,8 @@ namespace Kernel
BAN::ErrorOr<long> sys_truncate(int fd, off_t length);
BAN::ErrorOr<long> sys_fsync(int fd);
BAN::ErrorOr<long> sys_fstatat(int fd, const char* path, struct stat* buf, int flag);
BAN::ErrorOr<long> sys_realpath(const char* path, char* buffer);

View File

@@ -20,10 +20,14 @@ namespace Kernel
BAN::ErrorOr<void> write_to_cache(uint64_t sector, BAN::ConstByteSpan, bool dirty);
BAN::ErrorOr<void> sync();
BAN::ErrorOr<void> sync(uint64_t sector, size_t sector_count);
size_t release_clean_pages(size_t);
size_t release_pages(size_t);
void release_all_pages();
private:
BAN::ErrorOr<void> sync_cache_index(size_t index);
private:
struct PageCache
{

View File

@@ -15,13 +15,14 @@ namespace Kernel
const BAN::GUID& partition_guid() const { return m_guid; }
const BAN::RefPtr<BlockDevice> device() const { return m_device; }
virtual blksize_t blksize() const { return m_device->blksize(); }
virtual blksize_t blksize() const override { return m_device->blksize(); }
BAN::ErrorOr<void> read_sectors(uint64_t first_block, size_t block_count, BAN::ByteSpan buffer) { return read_blocks(first_block, block_count, buffer); }
BAN::ErrorOr<void> write_sectors(uint64_t first_block, size_t block_count, BAN::ConstByteSpan buffer) { return write_blocks(first_block, block_count, buffer); }
virtual BAN::ErrorOr<void> read_blocks(uint64_t first_block, size_t block_count, BAN::ByteSpan) override;
virtual BAN::ErrorOr<void> write_blocks(uint64_t first_block, size_t block_count, BAN::ConstByteSpan) override;
virtual BAN::ErrorOr<void> sync_blocks(uint64_t block, size_t block_count) override;
virtual BAN::StringView name() const override { return m_name; }

View File

@@ -21,11 +21,12 @@ namespace Kernel
virtual BAN::ErrorOr<void> read_blocks(uint64_t lba, size_t sector_count, BAN::ByteSpan buffer) override { return read_sectors(lba, sector_count, buffer); }
virtual BAN::ErrorOr<void> write_blocks(uint64_t lba, size_t sector_count, BAN::ConstByteSpan buffer) override { return write_sectors(lba, sector_count, buffer); }
virtual BAN::ErrorOr<void> sync_blocks(uint64_t block, size_t block_count) override;
BAN::ErrorOr<void> read_sectors(uint64_t lba, size_t sector_count, BAN::ByteSpan);
BAN::ErrorOr<void> write_sectors(uint64_t lba, size_t sector_count, BAN::ConstByteSpan);
virtual blksize_t blksize() const { return sector_size(); }
virtual blksize_t blksize() const override { return sector_size(); }
virtual uint32_t sector_size() const = 0;
virtual uint64_t total_size() const = 0;