sock_alloc_file(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… sock_alloc_file β€” like, the whole glow-up where a socket gets a file

Ok so bestie, we're in the Kernel API Manual today and this one's a certified banger. It's called sock_alloc_file and honestly? It's giving matchmaker energy. πŸŽ€


✨ NAME ✨

sock_alloc_file β€” bind a &socket to a &file. That's it, that's the whole vibe. Two lonely structs, one function, zero cap. 🫢


🌸 SYNOPSIS 🌸

struct file * sock_alloc_file (struct socket *sock , int flags , const
char *dname );

Look at that signature. Three args, no notes. Iconic. πŸ’…


πŸ¦‹ ARGUMENTS πŸ¦‹

  • sock β€” the socket. Like, the actual socket you want to bind. Main character.
  • flags β€” file status flags. The little personality settings for the file, iykyk.
  • dname β€” protocol name. Just a string, no big deal. πŸ’–

πŸ”₯ DESCRIPTION πŸ”₯

So what does it even do? It returns the file bound with sock, and β€” sneakily β€” it implicitly stores it in sock->file. Not me doing two things at once. 😭

If dname is NULL, it gets set to "". Empty string. Blank. A little ghost of a name. πŸ‘»

On failure, sock is released, and an ERR pointer is returned. So like, the socket doesn't survive a failed attempt, bestie. Be aware. πŸ’€

Also important: this function uses GFP_KERNEL internally. That's the allocation flavour it's running on, no substitutions. ✨


πŸ‘‘ SEE ALSO πŸ‘‘

Kernel file ./net/socket.c β€” go read it, it's fine, it's literally right there. πŸ“–

And the whole friend group shows up too:


That's the whole thing, no crumbs left. πŸ’œ

Sign-off time πŸŽ€ β€” this lil masterpiece lives under ./net in the source tree, dated October 2026, and it's filed under the sock_alloc_file(9) page name. Slay, go bind some sockets. πŸ¦‹

πŸ“¦ where this page comes from