summaryrefslogtreecommitdiff
path: root/src/readahead-common.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-03-03 23:03:26 +0100
committerLennart Poettering <lennart@poettering.net>2011-03-03 23:03:26 +0100
commit2b590e135f53a1bd3e771bdc555f7bf28c4cd232 (patch)
tree692dcb53426de099bc71ab5ed111d62823e74f2e /src/readahead-common.c
parentc1b664d055276f47f152fe90d1dd765c384271bc (diff)
readahead: disable collector automatically on read-only media
Diffstat (limited to 'src/readahead-common.c')
-rw-r--r--src/readahead-common.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/readahead-common.c b/src/readahead-common.c
index 85e3227f6e..e991dfd05d 100644
--- a/src/readahead-common.c
+++ b/src/readahead-common.c
@@ -114,6 +114,41 @@ finish:
return b;
}
+int fs_on_read_only(const char *p) {
+ struct stat st;
+ struct udev *udev = NULL;
+ struct udev_device *udev_device = NULL;
+ bool b = false;
+ const char *read_only;
+
+ assert(p);
+
+ if (stat(p, &st) < 0)
+ return -errno;
+
+ if (major(st.st_dev) == 0)
+ return false;
+
+ if (!(udev = udev_new()))
+ return -ENOMEM;
+
+ if (!(udev_device = udev_device_new_from_devnum(udev, 'b', st.st_dev)))
+ goto finish;
+
+ if ((read_only = udev_device_get_sysattr_value(udev_device, "ro")))
+ if ((b = streq(read_only, "1")))
+ goto finish;
+
+finish:
+ if (udev_device)
+ udev_device_unref(udev_device);
+
+ if (udev)
+ udev_unref(udev);
+
+ return b;
+}
+
bool enough_ram(void) {
struct sysinfo si;