MODSTAT(2)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

✨ NAME ✨

okay so bestie, this is modstat(2), a System Calls Manual page β€” and it's literally the system call that gets you the status of a kernel module. yes, the whole vibe is "tell me about this module by its id." πŸ’…

πŸŽ€ LIBRARY πŸŽ€

Standard C Library (libc, -lc) β€” she's right there in libc, link with -lc. 🫢

🌸 SYNOPSIS 🌸

       #include <sys/param.h>
       #include <sys/module.h>

       int
       modstat(int modid, struct module_stat *stat);

πŸ’– DESCRIPTION πŸ’–

okay so modstat() is the system call that writes the info for the kernel module referred to by modid into stat. no cap, that's the whole job.

here's the struct situation, and yes you need to know it:

       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;
  • version β€” this field is set to the size of the structure mentioned above by the code calling modstat(), and not by modstat() itself. so like, you set it, bestie. πŸ‘‘
  • name β€” the name of the module referred to by modid.
  • refs β€” the number of modules referenced by modid.
  • id β€” the id of the module specified in modid.
  • data β€” module specific data.

🌈 RETURN VALUES 🌈

modstat() returns the value 0 if successful; otherwise, the value -1 is returned and the global variable errno is set to indicate the error. that's the whole deal. 😭

πŸ”₯ ERRORS πŸ”₯

the information for the module referred to by modid is filled into the structure pointed to by stat unless one of these pops off:

  • ENOENT β€” the module was not found (probably not loaded). πŸ’€
  • EINVAL β€” the version specified in the version field of stat is 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 the version field. yes, that's the dramatic part. 😭
  • EFAULT β€” there was a problem copying one, some, or all of the fields into stat in the copyout(9) function. πŸ™ˆ

πŸ¦‹ SEE ALSO πŸ¦‹

⭐ HISTORY ⭐

the kld interface first appeared in FreeBSD 3.0. periodt. πŸŽ€


xoxo, your Debian bestie πŸ’– β€” source/version: Debian, page date: July 15, 2008, manual: MODSTAT(2). 🫢

πŸ“¦ where this page comes from