CategoryC

Meaning of “man” numbers (e.g. mkfifo(3)

I always forget what the number after the man pages means.
For example mkfifo(3) (https://linux.die.net/man/3/mkfifo).

This post helps me (and you) to not forget 🙂

MANUAL SECTIONS
    The standard sections of the manual include:

    1      User Commands
    2      System Calls
    3      C Library Functions
    4      Devices and Special Files
    5      File Formats and Conventions
    6      Games et. al.
    7      Miscellanea
    8      System Administration tools and Daemons

    Distributions customize the manual section to their specifics,
    which often include additional sections.

Note: I found out that “man” has a man page of itself. So this is not really necessary anymore. I keep it here for others to find though.

But remember:

$ man man

How to check if path is a mountpoint in C

For an application in C I wanted to know if a provided path is a mountpoint, so that a drive is mounted at that path.

With the help of the mtab file, which include all the mounts, we can iterate over that list and see if provided path is actually a mount point.
See ‘cat /etc/mtab’ to see the content of this file.

#include <mntent.h>
#include <stdio.h>
#include <string.h>

static bool path_is_mountpoint( CHAR* path )
{
  // Return if path is mountpoint (true), or not (false)
  BOOLEAN mounted = false;

  // Open mtab file.
  FILE * mtab = setmntent ("/etc/mtab", "r");
  struct mntent* mountpoint = nullptr;

  // Return directly if we could not open the file.
  if ( mtab == nullptr) return mounted;

  // Iterate over each entry in mtab list, and check if path is present
  while ( ( mountpoint = getmntent(mtab) ) != nullptr) {
    if ( (mountpoint->mnt_fsname != nullptr ) &&
         (strcmp(mountpoint->mnt_fsname, path ) == 0) )
    {
      // We found path in mtab, so path is mountpoint.
      // Stop iterating.
      mounted = true;
      break;
    }
  }

  endmntent (mtab);

  printf("path: %s, Is mountpoint: %d", path, mounted);

  return mounted;
}

© 2025 Roholt

Thema door Anders NorénOmhoog ↑