2 * (c) Oleg Puchinin 2006
3 * graycardinalster@gmail.com
11 #include <gclib/gclib.h>
17 #ifdef POSIX_FADV_WILLNEED
18 #define cache_opt __cache_opt
20 #define POSIX_FADV_WILLNEED 0
21 #define POSIX_FADV_DONTNEED 0
22 #define cache_opt __nofadvise
25 extern "C" DArray
* plugin_init (struct env_t
*env
);
27 void cache_file (char * file
, int adv
)
31 fd
= open (file
, O_RDONLY
);
35 // Dposix_fadvise (fd, 0, fsize (fd), adv);
40 char __no_fadvise (DArray
* d_opts
, int * pos
)
42 char * S
= d_opts
->get (*pos
);
43 if (EQ (S
, "--cache-load") || EQ (S
, "--cache-free")) {
44 fprintf (stderr
, "Sorry, your system do not support %s option.\n", S
);
50 char __cache_opt (DArray
* d_opts
, int * pos
)
52 DArray
* files
= ENV
->d_files
;
56 if (! d_opts
|| ! pos
)
59 S
= d_opts
->get (*pos
);
60 if (EQ (S
, "--cache-load")) {
61 for (i
= 0; i
< files
->get_size (); i
++)
62 cache_file (files
->get (i
), POSIX_FADV_WILLNEED
);
67 if (EQ (S
, "--cache-free")) {
68 for (i
= 0; i
< files
->get_size (); i
++)
69 cache_file (files
->get (i
), POSIX_FADV_DONTNEED
);
78 printf ("System cache.\n");
79 printf ("Version: 1.0\n");
80 printf ("Load files to system cache.\n");
81 printf ("options: [--cache-load | --cache-free]\n");
84 DArray
* plugin_init (struct env_t
*env
)
87 struct mod_feature
* pm
;
91 pm
= CNEW (mod_feature
, 1);
92 memset (pm
, 0, sizeof (mod_feature
));
93 pm
->mod
.Type
= TYPE_FEATURE
;
94 pm
->mod
.Version
= strdup ("1.0");
95 pm
->mod
.Name
= strdup ("Cache");
97 pm
->mod
.info
= cache_info
;
99 Ret
->add (LPCHAR (pm
));