1 // SPDX-License-Identifier: GPL-2.0
5 //! C header: [`include/linux/seq_file.h`](srctree/include/linux/seq_file.h)
7 use crate::{bindings, c_str, types::NotThreadSafe, types::Opaque};
9 /// A utility for generating the contents of a seq file.
12 inner: Opaque<bindings::seq_file>,
13 _not_send: NotThreadSafe,
17 /// Creates a new [`SeqFile`] from a raw pointer.
21 /// The caller must ensure that for the duration of 'a the following is satisfied:
22 /// * The pointer points at a valid `struct seq_file`.
23 /// * The `struct seq_file` is not accessed from any other thread.
24 pub unsafe fn from_raw<'a>(ptr: *mut bindings::seq_file) -> &'a SeqFile {
25 // SAFETY: The caller ensures that the reference is valid for 'a. There's no way to trigger
26 // a data race by using the `&SeqFile` since this is the only thread accessing the seq_file.
28 // CAST: The layout of `struct seq_file` and `SeqFile` is compatible.
29 unsafe { &*ptr.cast() }
32 /// Used by the [`seq_print`] macro.
33 pub fn call_printf(&self, args: core::fmt::Arguments<'_>) {
34 // SAFETY: Passing a void pointer to `Arguments` is valid for `%pA`.
38 c_str!("%pA").as_char_ptr(),
39 &args as *const _ as *const core::ffi::c_void,
45 /// Write to a [`SeqFile`] with the ordinary Rust formatting syntax.
47 macro_rules! seq_print {
48 ($m:expr, $($arg:tt)+) => (
49 $m.call_printf(format_args!($($arg)+))