PMbwmon bandwidth monitor: can specify which interfaces to watch, also supporting...
[hband-tools.git] / compiled-tools / syncfs.c
blobfc92fec06185a665380f1c27f9b2777432837a16
2 #include <err.h>
3 #include <errno.h>
4 #include <string.h> //strdup
5 #include <stdio.h> //printf
6 #include <fcntl.h> //O_*
7 #define _GNU_SOURCE 1
8 #include <sys/syscall.h>
11 int syncfs(int fd)
13 return syscall(SYS_syncfs, fd);
16 int main(int argc, char** argv)
18 char* path;
19 int narg = 1;
20 int fd;
22 if(argc > 1 && strcmp(argv[1], "--help")==0)
24 printf(
25 "Usage: syncfs [<PATH>]\n"
26 "Request sync to the disk for the filesystem which <PATH> is on.\n"
27 "<PATH> is the current directory by default.\n");
28 return 0;
31 if(argc < 2)
33 path = strdup(".");
34 goto have_path;
36 else
38 while(narg < argc)
40 path = argv[narg];
42 have_path:
43 fd = open(path, O_RDONLY);
44 if(fd == -1)
46 err(errno, "%s: open", path);
48 else
50 int ok = syncfs(fd);
51 if(ok != 0)
53 warn("%s", path);
55 close(fd);
57 narg++;
60 return 0;