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/>.
28 #include "readahead-common.h"
31 int file_verify(int fd, const char *fn, struct stat *st) {
36 if (fstat(fd, st) < 0) {
37 log_warning("fstat(%s) failed: %m", fn);
41 if (!S_ISREG(st->st_mode)) {
42 log_debug("Not preloading special file %s", fn);
46 if (st->st_size <= 0 || st->st_size > READAHEAD_FILE_SIZE_MAX) {
47 log_debug("Not preloading file %s with size out of bounds %zi", fn, st->st_size);
54 int fs_on_ssd(const char *p) {
56 struct udev *udev = NULL;
57 struct udev_device *udev_device = NULL, *look_at = NULL;
59 const char *devtype, *rotational, *model, *id;
66 if (!(udev = udev_new()))
69 if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev)))
72 if ((devtype = udev_device_get_property_value(udev_device, "DEVTYPE")) &&
73 streq(devtype, "partition"))
74 look_at = udev_device_get_parent(udev_device);
76 look_at = udev_device;
81 /* First, try high-level property */
82 if ((id = udev_device_get_property_value(look_at, "ID_SSD"))) {
87 /* Second, try kernel attribute */
88 if ((rotational = udev_device_get_sysattr_value(look_at, "queue/rotational")))
89 if ((b = streq(rotational, "0")))
92 /* Finally, fallback to heuristics */
93 if (!(look_at = udev_device_get_parent(look_at)))
96 if ((model = udev_device_get_sysattr_value(look_at, "model")))
97 b = !!strstr(model, "SSD");
101 udev_device_unref(udev_device);