Skip to content

Instantly share code, notes, and snippets.

@devendranaga
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devendranaga/210dcbecbb3e2f0d256a to your computer and use it in GitHub Desktop.
Save devendranaga/210dcbecbb3e2f0d256a to your computer and use it in GitHub Desktop.
find the file systems that are available in linux (vfs and mountable)
#include <stdio.h>
#include <stdlib.h>
FILE *fp;
char buffer[1000];
struct fstypes {
int vfs;
char *filesystem;
} fs_types[30];
int maxfs = 0;
int k = 0;
int main(void)
{
fp = fopen("/proc/filesystems", "r");
if (!fp)
return -1;
while (fgets(buffer, sizeof(buffer), fp)) {
int i = 0, j = 0;
char var[90], val[90];
memset(var, 0, sizeof(var));
memset(val, 0, sizeof(val));
while (buffer[i] != '\0') {
if (buffer[i] == ' ' || buffer[i] == '\t')
break;
var[i] = buffer[i];
i++;
}
var[i] = '\0';
while (buffer[i] == ' ' || buffer[i] == '\t')
i++;
do {
val[j] = buffer[i];
j++; i++;
} while (buffer[i] != '\n' &&
buffer[i] != '\0');
val[j] = '\0';
if (k < sizeof(fs_types) / sizeof(fs_types[0])) {
fs_types[k].vfs = !!strlen(var);
fs_types[k].filesystem = strdup(val);
k++;
maxfs++;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment