Skip to contentSkip to conversation

rust: kernel: ioctl returns ENOTTY if not implemented

RFC In review Gioh Kim 3 participants 3 messages Aug 19, 2021 – Aug 23, 2021 Rust

lore
Share & tools
lore

Gioh Kim

author
#0 lore raw

RFC 1/1 rust: kernel: ioctl returns ENOTTY if not implemented

From: Gioh Kim <[email protected]>

According to fs/ioctl.c, ioctl system call first test the cmd value with do_vfs_ioctl. If the cmd is not supported command, it calls vfs_ioctl. Then vfs_ioctl returns ENOTTY if ioctl is not implemented.

---
 rust/kernel/file_operations.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
rust/kernel/file_operations.rs +2 -2
index cad665c0016f..c6f03938de97 100644
@@ -662,7 +662,7 @@ pub trait FileOperations: Send + Sync + Sized {
         _file: &File,
         _cmd: &mut IoctlCommand,
     ) -> Result<i32> {
-        Err(Error::EINVAL)
+        Err(Error::ENOTTY)
     }
 
     /// Performs 32-bit IO control operations on that are specific to the file on 64-bit kernels.
@@ -673,7 +673,7 @@ pub trait FileOperations: Send + Sync + Sized {
         _file: &File,
         _cmd: &mut IoctlCommand,
     ) -> Result<i32> {
-        Err(Error::EINVAL)
+        Err(Error::ENOTTY)
     }
 
     /// Syncs pending changes to this file.
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Gioh Kim

From: Gioh Kim <[email protected]>

According to fs/ioctl.c, ioctl system call first test the cmd value with do_vfs_ioctl. If the cmd is not supported command, it calls vfs_ioctl. Then vfs_ioctl returns ENOTTY if ioctl is not implemented.

FWIW:

Quoted 29 lines
---
 rust/kernel/file_operations.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
rust/kernel/file_operations.rs +2 -2
index cad665c0016f..c6f03938de97 100644
@@ -662,7 +662,7 @@ pub trait FileOperations: Send + Sync + Sized {
         _file: &File,
         _cmd: &mut IoctlCommand,
     ) -> Result<i32> {
-        Err(Error::EINVAL)
+        Err(Error::ENOTTY)
     }
 
     /// Performs 32-bit IO control operations on that are specific to the file on 64-bit kernels.
@@ -673,7 +673,7 @@ pub trait FileOperations: Send + Sync + Sized {
         _file: &File,
         _cmd: &mut IoctlCommand,
     ) -> Result<i32> {
-        Err(Error::EINVAL)
+        Err(Error::ENOTTY)
     }
 
     /// Syncs pending changes to this file.
Signature · 1 line
2.25.1
#2 lore raw
In reply to Gioh Kim

Hi Gioh,

Quoted 9 lines · Gioh Kim

From: Gioh Kim <[email protected]>

According to fs/ioctl.c, ioctl system call first test the cmd value with do_vfs_ioctl. If the cmd is not supported command, it calls vfs_ioctl. Then vfs_ioctl returns ENOTTY if ioctl is not implemented.

Thanks! Applying it.

(By the way, always try to match the From -- I understand you are sending this as a personal contribution vs. your other commits in the kernel).

Cheers,
Miguel