On Thu, Jan 25, 2024 at 08:05:25AM +1100, Dave Chinner wrote: > On Wed, Jan 24, 2024 at 03:26:03PM -0300, Wedson Almeida Filho wrote: > > So what is the recommended way? Which file systems are using it (so I > > can do something similar)? > > e.g. btrfs_read_dev_one_super(). Essentially, if your superblock is > at block zero in the block device: > > struct address_space *mapping = bdev->bd_inode->i_mapping; > > ...... > > page = read_cache_page_gfp(mapping, 0, GFP_NOFS); > if (IS_ERR(page)) > return ERR_CAST(page); > > super = page_address(page); > > And now you have a pointer to your in memory buffer containing the > on-disk superblock. If the sueprblock is not at block zero, then > replace the '0' passed to read_cache_page_gfp() with whatever page > cache index the superblock can be found at.... Just to modify this slightly ... folio = read_mapping_folio(mapping, pos / PAGE_SIZE); if (IS_ERR(folio)) return ERR_CAST(folio); super = folio_address(folio) + offset_in_folio(folio, pos); ... and then in your shutdown path, you'll need to call folio_put(). Maybe that's easiest done in Rust by "leaking" the folio into the in-memory super block so it doesn't get dropped at the end of the function? I don't think you need the GFP_NOFS. We don't have a superblock yet, so we can't call back into the filesystem.