summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/File.h
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-04-30 10:33:33 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-30 11:42:35 +0200
commit7a1d09ef1a79f43ae39bc11f3c529cf420699c76 (patch)
treec6d90513a21817cd86739c982e43cc4264fd235d /Kernel/FileSystem/File.h
parentcae33305b05fee14fb6c8035b7b240a14d555c2e (diff)
downloadserenity-7a1d09ef1a79f43ae39bc11f3c529cf420699c76.zip
Kernel: Closing a file descriptor should not always close the file
When there is more than one file descriptor for a file closing one of them should not close the underlying file. Previously this relied on the file's ref_count() but at least for sockets this didn't work reliably.
Diffstat (limited to 'Kernel/FileSystem/File.h')
-rw-r--r--Kernel/FileSystem/File.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h
index 4f8173aefa..fade38d7a7 100644
--- a/Kernel/FileSystem/File.h
+++ b/Kernel/FileSystem/File.h
@@ -82,8 +82,8 @@ public:
virtual bool can_read(const FileDescription&, size_t) const = 0;
virtual bool can_write(const FileDescription&, size_t) const = 0;
- virtual KResult attach(FileDescription&) { return KSuccess; }
- virtual void detach(FileDescription&) { }
+ virtual KResult attach(FileDescription&);
+ virtual void detach(FileDescription&);
virtual void did_seek(FileDescription&, off_t) { }
virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) = 0;
virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) = 0;
@@ -112,6 +112,8 @@ public:
virtual FileBlockCondition& block_condition() { return m_block_condition; }
+ size_t attach_count() const { return m_attach_count; }
+
protected:
File();
@@ -138,6 +140,7 @@ private:
}
FileBlockCondition m_block_condition;
+ size_t m_attach_count { 0 };
};
}