1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
26 #include <sys/sysinfo.h>
29 #include "readahead-common.h"
32 int file_verify(int fd, const char *fn, off_t file_size_max, struct stat *st) {
37 if (fstat(fd, st) < 0) {
38 log_warning("fstat(%s) failed: %m", fn);
42 if (!S_ISREG(st->st_mode)) {
43 log_debug("Not preloading special file %s", fn);
47 if (st->st_size <= 0 || st->st_size > file_size_max) {
48 log_debug("Not preloading file %s with size out of bounds %zi", fn, st->st_size);
55 int fs_on_ssd(const char *p) {
57 struct udev *udev = NULL;
58 struct udev_device *udev_device = NULL, *look_at = NULL;
60 const char *devtype, *rotational, *model, *id;
67 if (!(udev = udev_new()))
70 if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev)))
73 if ((devtype = udev_device_get_property_value(udev_device, "DEVTYPE")) &&
74 streq(devtype, "partition"))
75 look_at = udev_device_get_parent(udev_device);
77 look_at = udev_device;
82 /* First, try high-level property */
83 if ((id = udev_device_get_property_value(look_at, "ID_SSD"))) {
88 /* Second, try kernel attribute */
89 if ((rotational = udev_device_get_sysattr_value(look_at, "queue/rotational")))
90 if ((b = streq(rotational, "0")))
93 /* Finally, fallback to heuristics */
94 if (!(look_at = udev_device_get_parent(look_at)))
97 if ((model = udev_device_get_sysattr_value(look_at, "model")))
98 b = !!strstr(model, "SSD");
102 udev_device_unref(udev_device);
110 bool enough_ram(void) {
113 assert_se(sysinfo(&si) >= 0);
115 return si.totalram > 127 * 1024*1024; /* Enable readahead only
116 * with at least 128MB