-
Notifications
You must be signed in to change notification settings - Fork 1
/
syncfs.c
61 lines (54 loc) · 883 Bytes
/
syncfs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <err.h>
#include <errno.h>
#include <string.h> //strdup
#include <stdio.h> //printf
#include <fcntl.h> //O_*
#define _GNU_SOURCE 1
#include <sys/syscall.h>
int syncfs(int fd)
{
return syscall(SYS_syncfs, fd);
}
int main(int argc, char** argv)
{
char* path;
int narg = 1;
int fd;
if(argc > 1 && strcmp(argv[1], "--help")==0)
{
printf(
"Usage: syncfs [<PATH>]\n"
"Request sync to the disk for the filesystem which <PATH> is on.\n"
"<PATH> is the current directory by default.\n");
return 0;
}
if(argc < 2)
{
path = strdup(".");
goto have_path;
}
else
{
while(narg < argc)
{
path = argv[narg];
have_path:
fd = open(path, O_RDONLY);
if(fd == -1)
{
err(errno, "%s: open", path);
}
else
{
int ok = syncfs(fd);
if(ok != 0)
{
warn("%s", path);
}
close(fd);
}
narg++;
}
}
return 0;
}