umountall.c (579B)
1 #include <stdio.h> 2 #include <string.h> 3 #include <sys/mount.h> 4 5 #define MAXBUF 4096 6 7 static int quiet = 0; 8 9 int 10 main(int argc, char** argv) 11 { 12 FILE* mounts = NULL; 13 char line[MAXBUF]; 14 char* eol = NULL; 15 16 if (*argv[1] && !strcmp(argv[1], "-q")) 17 quiet = 1; 18 19 if (!(mounts = fopen("/proc/self/mounts", "r"))) 20 { 21 if (!quiet) 22 perror("umountall"); 23 return 1; 24 } 25 26 while (fgets(line, MAXBUF, mounts)) 27 { 28 eol = strchr(line, '\n'); 29 if (eol) 30 *eol = 0; 31 strtok(line, " "); 32 if (umount(strtok(NULL, " ")) && !quiet) 33 perror("umountall"); 34 } 35 36 fclose(mounts); 37 return 0; 38 }