From: Wedson Almeida Filho <walmeida@xxxxxxxxxxxxx>
Using these bindings it becomes possible to access files from drivers
written in Rust. This patch only adds support for accessing the flags,
and for managing the refcount of the file.
Signed-off-by: Wedson Almeida Filho <walmeida@xxxxxxxxxxxxx>
Co-Developed-by: Daniel Xu <dxu@xxxxxxxxx>
Signed-off-by: Daniel Xu <dxu@xxxxxxxxx>
Co-Developed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
---
In this patch, I am defining an error type called `BadFdError`. I'd like
your thoughts on doing it this way vs just using the normal `Error`
type.
Pros:
* The type system makes it clear that the function can only fail with
EBADF, and that no other errors are possible.
* Since the compiler knows that `ARef<Self>` cannot be null and that
`BadFdError` has only one possible value, the return type of
`File::from_fd` is represented as a pointer with null being an error.
Cons:
* Defining additional error types involves boilerplate.
* The return type becomes a tagged union, making it larger than a
pointer.
* The question mark operator will only utilize the `From` trait once,
which prevents you from using the question mark operator on
`BadFdError` in methods that return some third error type that the
kernel `Error` is convertible into.
rust/bindings/bindings_helper.h | 2 +
rust/helpers.c | 7 ++
rust/kernel/file.rs | 176 ++++++++++++++++++++++++++++++++
rust/kernel/lib.rs | 1 +
4 files changed, 186 insertions(+)
create mode 100644 rust/kernel/file.rs
[...]
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
[...]
diff --git a/rust/helpers.c b/rust/helpers.c
[...]