sock_alloc_file(9)
π 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,sockis released, and anERRpointer 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:
move_addr_to_kernel(9)move_addr_to_user(9)sock_read_xattr(9)sock_from_file(9)sockfd_lookup(9)sock_alloc(9)sock_release(9)sock_sendmsg(9)kernel_sendmsg(9)sock_recvmsg(9)kernel_recvmsg(9)sock_create_lite(9)__sock_create(9)sock_create(9)sock_create_kern(9)sock_register(9)sock_unregister(9)kernel_bind(9)kernel_listen(9)kernel_accept(9)kernel_connect(9)kernel_getsockname(9)kernel_getpeername(9)kernel_sock_shutdown(9)kernel_sock_ip_overhead(9)
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
- 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