diff options
author | Sergey Bugaev <bugaevc@serenityos.org> | 2020-06-02 19:20:05 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-02 21:49:47 +0200 |
commit | 1b4e88fb59d35d7d720de15ddbdd6975d7175964 (patch) | |
tree | 886a4779c79a02e1dc5ab35aff6aa2f72664caaa /Kernel/FileSystem | |
parent | d4ddb0013cda7a8ef59e01883c643cac53448ef6 (diff) | |
download | serenity-1b4e88fb59d35d7d720de15ddbdd6975d7175964.zip |
Kernel: Allow File::close() to fail
And pass the result through to sys$close() return value.
Fixes https://github.com/SerenityOS/serenity/issues/427
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r-- | Kernel/FileSystem/File.cpp | 3 | ||||
-rw-r--r-- | Kernel/FileSystem/File.h | 2 | ||||
-rw-r--r-- | Kernel/FileSystem/FileDescription.cpp | 6 | ||||
-rw-r--r-- | Kernel/FileSystem/FileDescription.h | 2 |
4 files changed, 8 insertions, 5 deletions
diff --git a/Kernel/FileSystem/File.cpp b/Kernel/FileSystem/File.cpp index c12b80db5b..594652d643 100644 --- a/Kernel/FileSystem/File.cpp +++ b/Kernel/FileSystem/File.cpp @@ -46,8 +46,9 @@ KResultOr<NonnullRefPtr<FileDescription>> File::open(int options) return description; } -void File::close() +KResult File::close() { + return KSuccess; } int File::ioctl(FileDescription&, unsigned, FlatPtr) diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h index 02fc614326..9fbcd94947 100644 --- a/Kernel/FileSystem/File.h +++ b/Kernel/FileSystem/File.h @@ -69,7 +69,7 @@ public: virtual ~File(); virtual KResultOr<NonnullRefPtr<FileDescription>> open(int options); - virtual void close(); + virtual KResult close(); virtual bool can_read(const FileDescription&, size_t) const = 0; virtual bool can_write(const FileDescription&, size_t) const = 0; diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp index 984eadfd50..4b76e4ca4a 100644 --- a/Kernel/FileSystem/FileDescription.cpp +++ b/Kernel/FileSystem/FileDescription.cpp @@ -256,9 +256,11 @@ MasterPTY* FileDescription::master_pty() return static_cast<MasterPTY*>(m_file.ptr()); } -int FileDescription::close() +KResult FileDescription::close() { - return 0; + if (m_file->ref_count() > 1) + return KSuccess; + return m_file->close(); } String FileDescription::absolute_path() const diff --git a/Kernel/FileSystem/FileDescription.h b/Kernel/FileSystem/FileDescription.h index f3b8108083..767f270a95 100644 --- a/Kernel/FileSystem/FileDescription.h +++ b/Kernel/FileSystem/FileDescription.h @@ -65,7 +65,7 @@ public: set_writable(options & O_WRONLY); } - int close(); + KResult close(); off_t seek(off_t, int whence); ssize_t read(u8*, ssize_t); |