#include <stdlib.h>
#include <string.h>
#include <sys/sysinfo.h>
+#include <sys/inotify.h>
#include "log.h"
#include "readahead-common.h"
#include "util.h"
-int file_verify(int fd, const char *fn, struct stat *st) {
+int file_verify(int fd, const char *fn, off_t file_size_max, struct stat *st) {
assert(fd >= 0);
assert(fn);
assert(st);
return 0;
}
- if (st->st_size <= 0 || st->st_size > READAHEAD_FILE_SIZE_MAX) {
+ if (st->st_size <= 0 || st->st_size > file_size_max) {
log_debug("Not preloading file %s with size out of bounds %zi", fn, st->st_size);
return 0;
}
* with at least 128MB
* memory */
}
+
+int open_inotify(void) {
+ int fd;
+
+ if ((fd = inotify_init1(IN_CLOEXEC|IN_NONBLOCK)) < 0) {
+ log_error("Failed to create inotify handle: %m");
+ return -errno;
+ }
+
+ mkdir("/dev/.systemd", 0755);
+ mkdir("/dev/.systemd/readahead", 0755);
+
+ if (inotify_add_watch(fd, "/dev/.systemd/readahead", IN_CREATE) < 0) {
+ log_error("Failed to watch /dev/.systemd/readahead: %m");
+ close_nointr_nofail(fd);
+ return -errno;
+ }
+
+ return fd;
+}