mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:28:12 +00:00
Kernel/FileSystem: Make Inode::{write,read}_bytes methods non-virtual
We make these methods non-virtual because we want to ensure we properly enforce locking of the m_inode_lock mutex. Also, for write operations, we want to call prepare_to_write_data before the actual write. The previous design required us to ensure the callers do that at various places which lead to hard-to-find bugs. By moving everything to a place where we call prepare_to_write_data only once, we eliminate a possibilty of forgeting to call it on some code path in the kernel.
This commit is contained in:
parent
4f4717e351
commit
c88cc8557f
20 changed files with 87 additions and 72 deletions
|
@ -56,13 +56,14 @@ public:
|
|||
|
||||
ErrorOr<NonnullOwnPtr<KBuffer>> read_entire(OpenFileDescription* = nullptr) const;
|
||||
|
||||
ErrorOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const& data, OpenFileDescription*);
|
||||
ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const;
|
||||
|
||||
virtual ErrorOr<void> attach(OpenFileDescription&) { return {}; }
|
||||
virtual void detach(OpenFileDescription&) { }
|
||||
virtual void did_seek(OpenFileDescription&, off_t) { }
|
||||
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const = 0;
|
||||
virtual ErrorOr<void> traverse_as_directory(Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const = 0;
|
||||
virtual ErrorOr<NonnullLockRefPtr<Inode>> lookup(StringView name) = 0;
|
||||
virtual ErrorOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const& data, OpenFileDescription*) = 0;
|
||||
virtual ErrorOr<NonnullLockRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) = 0;
|
||||
virtual ErrorOr<void> add_child(Inode&, StringView name, mode_t) = 0;
|
||||
virtual ErrorOr<void> remove_child(StringView name) = 0;
|
||||
|
@ -119,6 +120,9 @@ protected:
|
|||
|
||||
mutable Mutex m_inode_lock { "Inode"sv };
|
||||
|
||||
virtual ErrorOr<size_t> write_bytes_locked(off_t, size_t, UserOrKernelBuffer const& data, OpenFileDescription*) = 0;
|
||||
virtual ErrorOr<size_t> read_bytes_locked(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const = 0;
|
||||
|
||||
private:
|
||||
ErrorOr<bool> try_apply_flock(Process const&, OpenFileDescription const&, flock const&);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue