add_to_list(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– add_to_list(9) πŸ’–

okay so welcome to the Kernel API Manual, section 9, bestie β€” this is the add_to_list page and honestly it's giving "tiny function, big responsibility" energy. let's get into it 🫢


✨ NAME ✨

add_to_list β€” add physical eraseblock to a list. that's it, that's the whole vibe πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

int add_to_list (struct ubi_attach_info *ai , int pnum , int vol_id ,
int lnum , int ec , int to_head , struct list_head *list );

like look at all those arguments. she's thorough. she has range πŸ”₯


🌸 ARGUMENTS 🌸

  • ai β€” the attaching information. the main-character struct of this whole operation πŸ‘‘
  • pnum β€” the physical eraseblock number you want to add. this is literally the PEB in question 🎯
  • vol_id β€” the last used volume id for the PEB
  • lnum β€” the last used LEB number for the PEB
  • ec β€” the erase counter of the physical eraseblock. keeping track of wear, iconic behaviour ⭐
  • to_head β€” if it's not zero, the PEB gets added to the head of the list instead of wherever. queue-jumping, but make it intentional πŸ’€
  • list β€” the list to add to. pick your girl, she's going on one of them 🌈

πŸ¦‹ DESCRIPTION πŸ¦‹

so what this function actually does: it allocates a struct ubi_ainf_peb object for the physical eraseblock pnum and adds it to one of the "free", "erase", or "alien" lists. yes, those are the real names, and yes, the "alien" list is exactly as mysterious as it sounds πŸ™ˆ

it also stores lnum and vol_id alongside β€” and both of those can be UBI_UNKNOWN if they're not available, not readable, or not assigned. no info? no problem, she still files it πŸ’…

now for to_head. if it's not zero, the PEB goes to the head of the list, which basically means it gets processed first later. and there's a genuinely good reason for that, bestie: corrupted PEBs (corrupted due to power cuts, the classic 😭) get added to the head of the erase list so we erase them first and get rid of the corruption ASAP. priority queue of problems. we love a proactive queen ⚑

return value: zero on success, a negative error code on failure. periodt. ✨

🫢 SEE ALSO 🫢

Kernel file ./drivers/mtd/ubi/attach.c, plus the whole friend group (fr fr, this is a big friend group):


aaaand that's the page!! mwah πŸ’‹ this one lives in ./drivers/mtd/ubi, it's tagged October 2026, and it is β€” say it with me β€” add_to_list(9). go read the other 20-something pages now, i believe in you πŸ§šβ€β™€οΈπŸ’œ

πŸ“¦ where this page comes from