rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wedson Almeida Filho <wedsonaf@google.com>
To: rust-for-linux@vger.kernel.org
Subject: File operations
Date: Wed, 9 Dec 2020 21:47:47 +0000	[thread overview]
Message-ID: <CAMKQLNLp+XfVcQf_+8OHJO=faTkwfdiFYR2s72LoAryHxFBJFA@mail.gmail.com> (raw)

Hello,

I'm looking to implement a FileOperations trait for a driver and am
finding it cumbersome. For example, to implement read, one needs to
declare the following (copied from example):

impl file_operations::FileOperations for CycleFile {
    const READ: file_operations::ReadFn<Self> = Some(
        |_this: &Self,
         _file: &file_operations::File,
         _buf: &mut user_ptr::UserSlicePtrWriter,
         _offset: u64|
         -> KernelResult<()> {
         ...
       },
    );
}

I couldn't find a way to simplify this to just implementing the
desired functions, but I can get it down to implementing just the
desired functions plus one annotation for the impl block, for example
(note the [#build_fileops] annotation at the top):

[#build_fileops]
impl file_operations::FileOperations for CycleFile {
    fn read(
        &self,
        _file: &file_operations::File,
        _buf: &mut user_ptr::UserSlicePtrWriter,
        _offset: u64,
    ) -> KernelResult() {
        ...
    }
}

How do you all feel about this? I think it is an improvement but would
like to hear what you think before spending more time on this.

Thanks,
-Wedson

             reply	other threads:[~2020-12-09 21:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-09 21:47 Wedson Almeida Filho [this message]
2020-12-09 23:18 ` File operations Miguel Ojeda
2020-12-13  0:01   ` Wedson Almeida Filho
2020-12-13  0:50     ` Miguel Ojeda
2020-12-13  2:12       ` Wedson Almeida Filho
2020-12-13  3:33         ` Miguel Ojeda
2020-12-14  2:02           ` Wedson Almeida Filho
2020-12-18  3:58             ` Miguel Ojeda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMKQLNLp+XfVcQf_+8OHJO=faTkwfdiFYR2s72LoAryHxFBJFA@mail.gmail.com' \
    --to=wedsonaf@google.com \
    --cc=rust-for-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).