MODSTAT(2)
π MODSTAT(2) β the modstat system call, bestie edition π
okay so you wanna know what's going on inside a kernel module? not just that it exists, but like... its whole deal? that's modstat, and she is literally the group chat gossip of the kernel world β¨. this one lives in the System Calls Manual, and she is that girl.
β¨ NAME β¨
modstat β get status of kernel module
no cap, that's the whole vibe: you ask, she tells you. π
π LIBRARY π
Standard C Library (libc, -lc)
πΈ SYNOPSIS πΈ
#include <sys/param.h>
#include <sys/module.h>
int
modstat(int modid, struct module_stat *stat);
π DESCRIPTION π
so basically, the modstat() system call writes the info for the kernel module referred to by modid into stat. that's it. that's the whole thing. she takes the module id, she fills in the struct, she moves on with her day π«Ά.
and here's the struct you're filling, looking all iconic:
struct module_stat {
int version; /* set to sizeof(module_stat) */
char name[MAXMODNAME];
int refs;
int id;
modspecific_t data;
};
typedef union modspecific {
int intval;
u_int uintval;
long longval;
u_long ulongval;
} modspecific_t;
and now let's go field by field because every single one matters, fr fr:
versionβ this field is set to the size of the structure mentioned above by the code callingmodstat(), and notmodstat()itself. like, you set it, bestie. she does not do it for you. the audacity? no, the responsibility πnameβ The name of the module referred to bymodid.refsβ The number of modules referenced bymodid.idβ The id of the module specified inmodid.dataβ Module specific data.
π₯ RETURN VALUES π₯
The modstat() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.
0 = slay. -1 = not slay, go read errno π
π ERRORS π
The information for the module referred to by modid is filled into the structure pointed to by stat unless one of these little drama bombs happens:
[ENOENT]β The module was not found (probably not loaded). she's not ghosting you, she genuinely could not find her π[EINVAL]β The version specified in theversionfield ofstatis not the proper version. You would need to rebuild world, the kernel, or your application, if this error occurs, given that you did properly fill in theversionfield. yeah. that's a whole rebuild. sorry bestie π[EFAULT]β There was a problem copying one, some, or all of the fields intostatin thecopyout(9)function.
not me casually having three separate ways to fail. but like, respectfully, the error messages are giving β¨clarityβ¨ so we move.
π¦ SEE ALSO π¦
kldfind(2)kldfirstmod(2)kldload(2)kldnext(2)kldstat(2)kldsym(2)kldunload(2)modfind(2)modfnext(2)modnext(2)kld(4)kldstat(8)
the whole friend group honestly, go say hi π
π HISTORY π
The kld interface first appeared in FreeBSD 3.0.
old money. vintage. iconic. she's been here since before you were born and she still eats every time π
and that's the tea, bestie β this page is from Debian, dated July 15, 2008, and it's MODSTAT(2), so go forth and check your modules, you absolute main character ππβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1999 Chris Costello
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms