+ if (st.f_flag & ST_RDONLY)
+ return true;
+
+ /* On NFS, statvfs() might not reflect whether we can actually
+ * write to the remote share. Let's try again with
+ * access(W_OK) which is more reliable, at least sometimes. */
+ if (access(path, W_OK) < 0 && errno == EROFS)
+ return true;
+
+ return false;
+}
+
+int path_is_os_tree(const char *path) {
+ char *p;
+ int r;
+
+ /* We use /usr/lib/os-release as flag file if something is an OS */
+ p = strjoina(path, "/usr/lib/os-release");
+ r = access(p, F_OK);
+
+ if (r >= 0)
+ return 1;
+
+ /* Also check for the old location in /etc, just in case. */
+ p = strjoina(path, "/etc/os-release");
+ r = access(p, F_OK);
+
+ return r >= 0;
+}
+
+int find_binary(const char *name, bool local, char **filename) {
+ assert(name);
+
+ if (is_path(name)) {
+ if (local && access(name, X_OK) < 0)
+ return -errno;
+
+ if (filename) {
+ char *p;
+
+ p = path_make_absolute_cwd(name);
+ if (!p)
+ return -ENOMEM;
+
+ *filename = p;
+ }
+
+ return 0;
+ } else {
+ const char *path;
+ const char *word, *state;
+ size_t l;
+
+ /**
+ * Plain getenv, not secure_getenv, because we want
+ * to actually allow the user to pick the binary.
+ */
+ path = getenv("PATH");
+ if (!path)
+ path = DEFAULT_PATH;
+
+ FOREACH_WORD_SEPARATOR(word, l, path, ":", state) {
+ _cleanup_free_ char *p = NULL;
+
+ if (asprintf(&p, "%.*s/%s", (int) l, word, name) < 0)
+ return -ENOMEM;
+
+ if (access(p, X_OK) < 0)
+ continue;
+
+ if (filename) {
+ *filename = path_kill_slashes(p);
+ p = NULL;
+ }
+
+ return 0;
+ }
+
+ return -ENOENT;
+ }
+}
+
+bool paths_check_timestamp(const char* const* paths, usec_t *timestamp, bool update) {
+ bool changed = false;
+ const char* const* i;
+
+ assert(timestamp);
+
+ if (paths == NULL)
+ return false;
+
+ STRV_FOREACH(i, paths) {
+ struct stat stats;
+ usec_t u;
+
+ if (stat(*i, &stats) < 0)
+ continue;
+
+ u = timespec_load(&stats.st_mtim);
+
+ /* first check */
+ if (*timestamp >= u)
+ continue;
+
+ log_debug("timestamp of '%s' changed", *i);
+
+ /* update timestamp */
+ if (update) {
+ *timestamp = u;
+ changed = true;
+ } else
+ return true;
+ }
+
+ return changed;
+}
+
+int fsck_exists(const char *fstype) {
+ _cleanup_free_ char *p = NULL, *d = NULL;
+ const char *checker;
+ int r;
+
+ checker = strjoina("fsck.", fstype);
+
+ r = find_binary(checker, true, &p);
+ if (r < 0)
+ return r;
+
+ /* An fsck that is linked to /bin/true is a non-existent
+ * fsck */
+
+ r = readlink_malloc(p, &d);
+ if (r >= 0 &&
+ (path_equal(d, "/bin/true") ||
+ path_equal(d, "/usr/bin/true") ||
+ path_equal(d, "/dev/null")))
+ return -ENOENT;
+
+ return 0;