Barra laterale

programmazione:linux:elencare_punti_di_montaggio

Elencare i mount points di Linux

Autore: Fabio Di Matteo
Ultima revisione: 14/03/2016 - 13:48

Il seguente ciclo while itera i mount point del sistema riempiendo per ognuno la struttura struct mntent.

#include <stdio.h>
#include <stdlib.h>
#include <mntent.h>
 
int main(void)
{
  struct mntent *ent;
  FILE *aFile;
 
  aFile = setmntent("/proc/mounts", "r");
  if (aFile == NULL) {
    perror("setmntent");
    exit(1);
  }
  while (NULL != (ent = getmntent(aFile))) {
    printf("Device: %s Mount: %s\n", ent->mnt_fsname, ent->mnt_dir);
  }
  endmntent(aFile);
}

Ecco la struttura di mntent :

struct mntent {
    char *mnt_fsname;   /* name of mounted file system */
    char *mnt_dir;      /* file system path prefix */
    char *mnt_type;     /* mount type (see mntent.h) */
    char *mnt_opts;     /* mount options (see mntent.h) */
    int   mnt_freq;     /* dump frequency in days */
    int   mnt_passno;   /* pass number on parallel fsck */
};

programmazione/linux/elencare_punti_di_montaggio.txt · Ultima modifica: 18/04/2018 - 15:48 (modifica esterna)