On Thu, Jun 12, 2025 at 10:47 AM Burak Emir <[email protected]> wrote: > > On Wed, Jun 11, 2025 at 11:58 PM Alice Ryhl <[email protected]> wrote: > > > > On Wed, Jun 11, 2025 at 9:48 PM Burak Emir <[email protected]> wrote: > [...] > > > diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs > > > new file mode 100644 > > > index 000000000000..1fe72ca980ac > > > --- /dev/null > > > +++ b/rust/kernel/bitmap.rs > > > @@ -0,0 +1,582 @@ > > > +// SPDX-License-Identifier: GPL-2.0 > > > + > > > +// Copyright (C) 2025 Google LLC. > > > + > > > +//! Rust API for bitmap. > > > +//! > > > +//! C headers: > > > [`include/linux/bitmap.h`](srctree/include/linux/bitmap.h). > > > + > > > +use crate::alloc::{AllocError, Flags}; > > > +use crate::bindings; > > > +#[cfg(not(CONFIG_RUST_BITMAP_HARDENED))] > > > +use crate::pr_err; > > > +use core::ptr::NonNull; > > > + > > > +/// Represents a C bitmap. Wraps underlying C bitmap API. > > > +/// > > > +/// # Invariants > > > +/// > > > +/// Must reference a `[c_ulong]` long enough to fit `data.len()` bits. > > > +#[cfg_attr(CONFIG_64BIT, repr(align(8)))] > > > +#[cfg_attr(not(CONFIG_64BIT), repr(align(4)))] > > > +pub struct CBitmap { > > > + data: [()], > > > +} > > > > I wonder if we should just call this type Bitmap? > > > > OK. I am renaming the other type to OwnedBitmap then.
Just thinking a bit more about naming ... how about calling it BitmapVec? Rust generally uses the terminology "Vec" to refer to arrays whose size is not known at compile-time, and "Array" when the size is known. Then, if we eventually add another type for declaring fixed-size bitmaps in Rust, that type can be BitmapArray (that's the type you'll want in a global). Alice
