Re: [PATCH] rust: fs: file: add FMODE constants and stream_open for LocalFile

From: Miguel Ojeda

Date: Sat Apr 04 2026 - 16:15:24 EST


On Fri, Apr 3, 2026 at 10:20 PM Christian Benton
<t1bur0n.kernel.org@xxxxxxxxxxxxx> wrote:
>
> The C function stream_open() has no Rust equivalent, requiring Rust
> drivers to manipulate f_mode directly through unsafe bindings. This adds
> the necessary FMODE constants to the bindings and implements stream_open()
> natively on LocalFile, giving Rust character device drivers a safe way to
> mark a file as a stream.
>
> Add the FMODE_STREAM, FMODE_LSEEK, FMODE_PREAD, FMODE_PWRITE and
> FMODE_ATOMIC_POS constants to the bindings. These constants were not
> previously accessible to Rust code because bindgen cannot handle the
> __force cast used in their C macro definitions. They are exposed here
> using the RUST_CONST_HELPER pattern already established in
> bindings_helper.h.
>
> stream_open() should be called from the open() handler of a character
> device that produces data as a stream rather than supporting random
> access. It clears the seek-related file mode flags and sets FMODE_STREAM,
> telling the VFS layer not to validate seek positions on read_iter and
> write_iter calls. This mirrors the behavior of stream_open() in
> fs/open.c, which does not use the inode parameter and only manipulates
> f_mode on the file struct.
>
> The method is placed on LocalFile rather than File because stream_open()
> must be called during open(), before the file descriptor is installed
> into the process fd table. LocalFile is !Send, which statically
> guarantees that no other thread can concurrently access f_mode at the
> point this method is called, making the unsafe f_mode manipulation sound.
>
> Signed-off-by: Christian Benton <t1bur0n.kernel.org@xxxxxxxxxxxxx>

Please use `scripts/get_maintainer.pl` to get a list of people to Cc,
i.e. VFS maintainers and reviewers should be included at least, plus
usually the RUST entry. Cc'ing them here for you. :)

I think one thing they may ask is whether you have an expected user of
this new API to land.

Thanks!

Cheers,
Miguel