sysfs(2)

πŸŽ€ sysfs(2) β€” the manual page, bestie edition

okay so before anything else: this is section 2 of the manual, aka System Calls Manual territory β€” we're talking actual kernel syscalls here, not your cute little shell commands. buckle up πŸ’–


✨ NAME ✨

sysfs β€” get filesystem type information

like. that's the whole job. it tells you stuff about filesystems. iconic of it honestly.


🌸 SYNOPSIS 🌸

[[deprecated]] int sysfs(int option, const char *fsname);
[[deprecated]] int sysfs(int option, unsigned int fs_index, char *buf);
[[deprecated]] int sysfs(int option);

bestie do you see the [[deprecated]] up there? three times?? THREE TIMES. the compiler is literally screaming at you and it is so right to do so 😭


πŸ’… DESCRIPTION πŸ’…

quick heads up before you spiral: if what you actually want is info about the sysfs filesystem that lives mounted at /sys, that is a completely different page. go read sysfs(5). do not pass go. do not collect $200. 🫢

so. the (obsolete!!) sysfs() system call hands you information about the filesystem types that are, like, currently present in the kernel. the exact shape of the call and the tea it returns depends entirely on which option you're running:

  1. translates the filesystem identifier string fsname into a filesystem type index. like a lil name-to-number glow-up ✨
  2. translates the filesystem type index fs_index into a null-terminated filesystem identifier string. that string gets written into the buffer that buf points at. and please double-check that buf actually has enough room to hold the string, because it will not be checking for you hun πŸ’€
  3. returns the total number of filesystem types currently present in the kernel. just the count. the vibe check, numerically.

also super important: the numbering of the filesystem type indexes begins with zero. zero-indexed, as the ancestors intended, no cap. πŸ”₯


πŸ‘‘ RETURN VALUE πŸ‘‘

on success, sysfs() gives you:

  • the filesystem index for option 1
  • zero for option 2
  • the number of currently configured filesystems for option 3

on error? it's -1, and errno gets set to tell you what went wrong. classic. πŸ™ˆ


πŸ¦‹ ERRORS πŸ¦‹

  • EFAULT β€” either fsname or buf is outside your accessible address space. you reached into a place you were not invited, bestie 😭
  • EINVAL β€” fsname is not a valid filesystem type identifier; or fs_index is out-of-bounds; or option is invalid. basically: bad input, bad index, or a number that doesn't exist. any of the three, we don't judge (we do, a little).

⭐ STANDARDS ⭐

None.

that's it. that's the whole section. none. not a single standard claims this thing. she's ungoverned πŸ’€


🌈 HISTORY 🌈

SVr4.

and here's the part where I hold your hand: this System-V derived system call is obsolete. don't use it. I'm being so serious right now, this is not a drill, this is the manpage itself saying it. 🚨

on systems that have /proc, you can get all this same information through /proc β€” so use that interface instead, okay? please? for me? πŸ₯Ί


πŸ’€ BUGS πŸ’€

  • there is no libc or glibc support. none. not a crumb. 😭
  • there is no way to guess how large buf should be. so good luck sizing that buffer, you're on your own, godspeed 🫑

🧚 SEE ALSO 🧚


okay so that's the whole thing!! go use /proc like a good citizen, stay hydrated, and remember: [[deprecated]] is not a personality trait πŸ’–βœ¨

signing off β€” this came from Linux man-pages 6.20, dated 2026-02-08, and yeah she's old and deprecated but she's still iconic πŸŽ€

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms