befs_find_brun_direct(9)
β¨ 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 formblocknoβ the blocknumber you're trying to find, the whole reason we're hererunβ 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 π
- Kernel file
./fs/befs/datastream.c befs_read_datastream(9)befs_fblock2brun(9)befs_count_blocks(9)befs_find_brun_indirect(9)befs_find_brun_dblindirect(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms