sort_nodes(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ sort_nodes(9) β€” the UBIFS glow-up πŸ’…

okay so real talk, bestie: this is a Kernel API Manual page for sort_nodes, and it is genuinely the main character of garbage collection in UBIFS. It's the function that literally sorts your nodes so GC doesn't have to be messy. no cap. πŸŽ€


🌸 NAME 🌸

sort_nodes β€” sort nodes for GC. that's it, that's the vibe. ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

int sort_nodes (struct ubifs_info *c , struct ubifs_scan_leb *sleb ,
struct list_head *nondata , int *min );

πŸ’– ARGUMENTS πŸ’–

  • c β€” the UBIFS file-system description object. your whole file-system situation, basically. 🫢
  • sleb β€” describes the nodes to sort, and on exit it's holding the result. so it comes in describing, goes out serving. πŸ’…
  • nondata β€” on exit this contains the non-data nodes. that's the whole job. ✨
  • min β€” the minimum node size gets returned right here. cute little out-param. πŸŽ€

πŸ”₯ DESCRIPTION πŸ”₯

okay so this function sorts the list of inodes to garbage collect. that's the mission. 🫑

First of all, it kills obsolete nodes (πŸ’€ bye bestie) and separates data and non-data nodes off into the sleb->nodes and nondata lists correspondingly.

Then the data nodes get sorted in block number order β€” and this is important for bulk-read, iykyk. the rules are:

  • data nodes with lower inode number go before data nodes with higher inode number βœ…
  • data nodes with lower block number go before data nodes with higher block number βœ…

Non-data nodes get sorted like this:

  • first go inode nodes β€” they're sorted in descending length order πŸ“
  • then go directory entry nodes β€” they're sorted in hash order, which should supposedly optimize 'readdir'. and specifically:
    • direntry nodes with lower parent inode number go before direntry nodes with higher parent inode number πŸ‘‘
    • direntry nodes with lower name hash values go before direntry nodes with higher name hash values πŸ‘‘

This function returns zero in case of success and a negative error code in case of failure. no in-between, no drama (well, the negative error code is the drama 😭).


🌈 SEE ALSO 🌈

Kernel file ./fs/ubifs/gc.c and its whole friend group, fr fr:


πŸ’‘ friendly reminder: this page lives under ./fs/ubifs, and it's the October 2026 vintage. slay.

and that's the whole page, bestie β€” go forth and sort responsibly. πŸ§šπŸ’œ

πŸ“¦ where this page comes from