befs_find_brun_direct(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ befs_find_brun_direct ✨

okay bestie, so this is a page from the Kernel API Manual β€” yes we're in kernel-land now, put your big-girl hat on πŸ’… It's called befs_find_brun_direct, and it's literally the function that finds a direct block run in the datastream. befs hive rise up 🐝


🌸 SYNOPSIS 🌸

int befs_find_brun_direct (struct super_block *sb , const
       befs_data_stream *data , befs_blocknr_t blockno , befs_block_run *run );

πŸŽ€ ARGUMENTS πŸŽ€

  • sb β€” the superblock, the big one, the main character πŸ‘‘
  • data β€” the datastream, aka the file's vibe in block form
  • blockno β€” the blocknumber you're trying to find, the whole reason we're here
  • run β€” the found run gets passed back to you through this pointer, so it's an out-param bestie, it comes back changed 🫢

πŸ¦‹ DESCRIPTION πŸ¦‹

So what does it actually do? It finds the block run that starts at file block number blockno in the file represented by the datastream data β€” but only if that blockno is chillin' in the direct region of the datastream. Direct region only, no cap. If it's not in there, this function is not the one.

The return value is BEFS_OK if the blockrun is found, BEFS_ERR otherwise. Binary. Iconic. πŸ’€

Algorithm: linear search, fr fr. It checks each element of array[] to see if it contains the blockno-th filesystem block. And why do we have to do this the long way? Because block runs map variable amounts of data β€” you can't just index in and expect the math to work, that's not how any of this goes. So instead it simply keeps a count of the number of blocks searched so far (sum), incrementing this by the length of each block run as we come across it. Then it adds sum to *count before returning β€” and like, that's on purpose, it's so you can search multiple arrays that are logicaly one array (yes that's the original spelling, we stan 🌈), as in the indirect region code. iykyk.

When/if blockno is found, if blockno is inside of a block run as stored on disk, we offset the start and length members of the block run, so that blockno is the start and len is still valid (the run ends in the same place). The run stays exactly where it was, it just gets a little glow-up on the front end ✨

not me obsessed with the fact that len is still valid afterwards β€” king behaviour honestly

πŸ’œ SEE ALSO πŸ’œ


and that's the whole thing bestie 🧚 stay hydrated, go read datastream.c, and remember: this page came from the ./fs/befs source, dated October 2026 β€” so go forth and find those direct block runs πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from