From 3e5f782a7cc553f072916d730fcdfce2e74c95f0 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 29 Feb 2024 23:46:26 +0100 Subject: [PATCH] remove obsolete code - `close` in trait ObjectInterface is never used => remove it --- src/fd/mod.rs | 7 ------- src/fs/mod.rs | 6 ++++-- src/syscalls/mod.rs | 8 +------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/fd/mod.rs b/src/fd/mod.rs index b1951edc27..a9df6a0345 100644 --- a/src/fd/mod.rs +++ b/src/fd/mod.rs @@ -281,9 +281,6 @@ pub(crate) trait ObjectInterface: Sync + Send + core::fmt::Debug + DynClone { fn ioctl(&self, _cmd: IoCtl, _value: bool) -> Result<(), IoError> { Err(IoError::ENOSYS) } - - // close a file descriptor - fn close(&self) {} } pub(crate) fn open( @@ -306,10 +303,6 @@ pub(crate) fn open( } } -pub(crate) fn close(fd: FileDescriptor) { - let _ = remove_object(fd).map(|v| v.close()); -} - pub(crate) fn read(fd: FileDescriptor, buf: &mut [u8]) -> Result { let obj = get_object(fd)?; diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 16b03ecf23..5a25967dd0 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -12,7 +12,9 @@ use alloc::vec::Vec; use hermit_sync::OnceCell; use mem::MemDirectory; -use crate::fd::{insert_object, AccessPermission, IoError, ObjectInterface, OpenOption}; +use crate::fd::{ + insert_object, remove_object, AccessPermission, IoError, ObjectInterface, OpenOption, +}; use crate::io::Write; use crate::time::{timespec, SystemTime}; @@ -488,6 +490,6 @@ impl crate::io::Write for File { impl Drop for File { fn drop(&mut self) { - fd::close(self.fd); + let _ = remove_object(self.fd); } } diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index b9931f5d01..f893150014 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -247,13 +247,7 @@ pub extern "C" fn sys_open(name: *const u8, flags: i32, mode: u32) -> FileDescri extern "C" fn __sys_close(fd: FileDescriptor) -> i32 { let obj = remove_object(fd); - obj.map_or_else( - |e| -num::ToPrimitive::to_i32(&e).unwrap(), - |v| { - v.close(); - 0 - }, - ) + obj.map_or_else(|e| -num::ToPrimitive::to_i32(&e).unwrap(), |_| 0) } #[no_mangle]