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, fdsize (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
);
76 void cache_short_info ()
78 printf ("System cache. (linux only)");
81 void cache_long_info ()
83 printf ("System cache. (linux only)\n");
84 printf ("Version: 1.0\n");
85 printf ("Load files to system cache.\n");
86 printf ("options: [--cache-load | --cache-free]\n");
90 DArray
* plugin_init (struct env_t
*env
)
97 plug
= CNEW (mod_t
, 1);
98 memset (plug
, 0, sizeof (mod_t
));
99 plug
->Version
= strdup ("1.0");
100 plug
->Name
= strdup ("Cache");
101 plug
->opt2
= cache_opt
;
102 plug
->short_info
= cache_short_info
;
103 plug
->long_info
= cache_long_info
;
105 ENV
->listOptions
->add ("--cache-load");
106 ENV
->listOptions
->add ("--cache-free");
108 Ret
->add (LPCHAR (plug
));