GETFSENT(3)
π GETFSENT β the libc manual page, but make it make sense
okay so bestie, you're in section 3 of the Library Functions Manual (that's the libc one, <fstab.h> territory) and honestly? this whole page is about reading entries out of your file system descriptor file. iconic behaviour, lowkey. let's get into it π
β¨ NAME β¨
getfsent, getfsspec, getfsfile, setfsent, endfsent β get file system descriptor file entry
like, that's the whole vibe. it grabs you an entry. π
π LIBRARY π
Standard C Library (libc, -lc) β so you already have it, no cap, just link it and go π
π«Ά SYNOPSIS π«Ά
#include <fstab.h>
struct fstab *
getfsent(void);
struct fstab *
getfsspec(const char *spec);
struct fstab *
getfsfile(const char *file);
int
setfsent(void);
void
endfsent(void);
void
setfstab(const char *file);
const char *
getfstab(void);
not me listing all seven of them, every single one, because we do NOT skip functions on this page β¨
π DESCRIPTION π
so getfsent(), getfsspec(), and getfsfile() each hand you back a pointer to an object β and that object has the following structure, containing the broken-out fields of a line in the file system description file, <fstab.h>:
struct fstab {
char *fs_spec; /* block special device name */
char *fs_file; /* file system path prefix */
char *fs_vfstype; /* File system type, ufs, nfs */
char *fs_mntops; /* Mount options ala -o */
char *fs_type; /* FSTAB_* from fs_mntops */
int fs_freq; /* dump frequency, in days */
int fs_passno; /* pass number on parallel fsck */
};
the fields mean exactly what fstab(5) says they mean β go read that one, it's the whole lore π¦
setfsent()opens the file (closing any previously opened file) or rewinds it if it's already open. very "reuse the same handle, bestie" of it.endfsent()closes the file. that's it. that's the function. πsetfstab()sets the file to be used by subsequent operations. β οΈ important caveat: the value set bysetfstab()does not persist across calls toendfsent(). so don't get attached.getfstab()returns the name of the file that will be used. just the name. a little peek. π
getfsspec() and getfsfile() search the entire file (opening it if necessary) for a matching special file name or file system file name. whole-file scavenger hunt energy π₯
and for programs wishing to read the entire database, getfsent() reads the next entry (opening the file if necessary). one at a time, like a sensible main character πΈ
also!! all entries in the file with a type field equivalent to FSTAB_XX are ignored. yes, ignored. we don't see them. they're not invited to the group chat π
π RETURN VALUES π
getfsent(),getfsspec(), andgetfsfile()return aNULLpointer on EOF or error.NULLmeans "nothing for you, queen". πsetfsent()returns0on failure,1on success.endfsent()returns nothing. void. a true minimalist. π
π ENVIRONMENT π
PATH_FSTABβ if the environment variablePATH_FSTABis set, all operations are performed against the specified file. but β οΈPATH_FSTABwill not be honored if the process environment or memory address space is considered βtaintedβ. (Seeissetugid(2)for more information.) so if you're tainted? it's giving "we're not doing that". π
π FILES π
/etc/fstab
π SEE ALSO π
fstab(5) β literally the plot, go read it π«Ά
β HISTORY β
the lore!! π
getfsent()appeared in4.0BSDendfsent(),getfsfile(),getfsspec(), andsetfsent()appeared in4.3BSDsetfstab()andgetfstab()appeared inFreeBSD 5.1
generational icons, all of them β¨
π BUGS π
okay so THIS is the one you cannot sleep on:
these functions use static data storage. if the data is needed for future use, it should be copied before any subsequent calls overwrite it.
fr fr. it's the same buffer every time. if you stash that pointer and go make another call, your data is GONE and you're gonna be debugging at 2am like π. copy it. please. for me. π
and that's the page!! brought to you by Debian, dated April 7, 2003 β yes, that April 7, 2003, and it's still out here explaining fstab to us all these years later. slay, honestly. π§ββοΈπΈ
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 1983, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms