1 |
dpavlin |
142 |
/* This program removes specified (or current) directory/file from Linux filesystem cache */ |
2 |
|
|
#define _GNU_SOURCE |
3 |
|
|
#define _XOPEN_SOURCE 600 |
4 |
|
|
|
5 |
|
|
#include <unistd.h> |
6 |
|
|
#include <stdlib.h> |
7 |
|
|
#include <string.h> |
8 |
|
|
#include <stdio.h> |
9 |
|
|
#include <fts.h> |
10 |
|
|
#include <fcntl.h> |
11 |
|
|
|
12 |
|
|
int main(int ac, char ** av) { |
13 |
|
|
FTS * tree; |
14 |
|
|
FTSENT * node; |
15 |
|
|
|
16 |
|
|
char **paths = malloc(ac*sizeof(char*)); |
17 |
|
|
memcpy(paths,av+1,(ac-1)*sizeof(char*)); |
18 |
|
|
paths[ac]=NULL; |
19 |
|
|
if (ac<2) paths[0]=getcwd(NULL,0); |
20 |
|
|
|
21 |
|
|
tree=fts_open(paths,FTS_LOGICAL|FTS_NOCHDIR,NULL); |
22 |
|
|
while((node=fts_read(tree))) { |
23 |
|
|
int fd; |
24 |
|
|
if (node->fts_info != FTS_F) continue; |
25 |
|
|
fd=open(node->fts_path,O_DIRECT); |
26 |
|
|
posix_fadvise(fd,0,0,POSIX_FADV_DONTNEED); |
27 |
|
|
close(fd); |
28 |
|
|
} |
29 |
|
|
fts_close(tree); |
30 |
|
|
if (ac<2) free(paths[0]); |
31 |
|
|
free(paths); |
32 |
|
|
return(0); |
33 |
|
|
} |
34 |
|
|
|