Re: [PATCH 8/8] rust: samples: Add debugfs sample

Greg Kroah-Hartman
2025-04-30T12:06:22Z

On Tue, Apr 29, 2025 at 11:16:02PM +0000, Matthew Maurer wrote:
> + fn build<'a>(&'a self, builder: Builder<'a>) -> Result<()> {
> + builder.display_file(c_str!("simple"), &self.simple)?;
> + builder.display_file(c_str!("composite"), &self.composite)?;
> + debugfs_fmt_file!(
> + builder,
> + c_str!("custom"),
> + &self.custom,
> + "Foo! {:#010x} Bar!\n"
> + )?;
> + for record in self.many.iter() {
> + let dir = builder.dir(record.name)?;
> + dir.display_file(c_str!("size"), &record.size)?;
> + dir.display_file(c_str!("stride"), &record.stride)?;
> + }
> + builder.fmt_file(c_str!("atomic"), &self.atomic, &|atomic, f| {
> + write!(f, "{}\n", atomic.load(Ordering::Relaxed))
> + })?;
> + builder.fmt_file(c_str!("locked"), &self.locked, &|locked, f| {
> + write!(f, "{}\n", *locked.lock())
> + })?;
> + Ok(())

Good luck removing all of those ? checks, this should work just fine
without any of that.

I'm not set on the "builder" pattern here, it's not a normal one for C
to be following, why do you feel debugfs should be using it?

thanks,

greg k-h