from_kgid(9)
π from_kgid β the Kernel API Manual, bestie edition π
okay so picture this: you're deep in the kernel, you've got a kgid (that's the kernel's own internal gid, the β¨realβ¨ one) and you need to hand it to userspace in somebody's user namespace. That's literally this function. It's the glow-up translator between kernelspace and your targ namespace, and honestly? iconic.
πΈ SYNOPSIS πΈ
gid_t from_kgid (struct user_namespace *targ , kgid_t kgid );
no cap, that's the whole signature. two args, one gid_t coming back at you π«Ά
π¦ ARGUMENTS π¦
- targ β the
struct user_namespace *you want a gid in. like, where do you want this gid to live? that one. β¨ - kgid β the kernel internal gid you're starting with (
kgid_t). the raw material, the before picture π
π DESCRIPTION π
So what happens is: it maps kgid into the user namespace that targ points at, and then returns the resulting gid to you. That's it. That's the function. π
There is always a mapping into the initial user_namespace β so like, the original namespace never ghosts you, that mapping is guaranteed to be there, fr fr.
β οΈ but bestie, listen: ifkgidhas no mapping intarg, you don't get a nice value back β you get(gid_t)-1. that's your "nope, not found" signal, so check for it. lowkey important. π«Ά
π SEE ALSO π
the kernel file in question is ./kernel/user_namespace.c, and if you're gonna be messing with ids and namespaces, you'll want the whole bestie squad:
make_kuid(9)from_kuid(9)from_kuid_munged(9)make_kgid(9)from_kgid_munged(9)make_kprojid(9)from_kprojid(9)from_kprojid_munged(9)verify_root_map(9)
alright that's the page π
this lil slice of kernel API lives in ./kernel, it's the October 2026 vibes, and the whole thing is filed under from_kgid(9) β go map those gids, queen πβ¨
π¦ 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