+static int add_fsck(FILE *f, const char *what, const char *where, const char *type, int passno) {
+ assert(f);
+
+ if (passno == 0)
+ return 0;
+
+ if (!is_device_path(what)) {
+ log_warning("Checking was requested for \"%s\", but it is not a device.", what);
+ return 0;
+ }
+
+ if (type && !streq(type, "auto")) {
+ int r;
+ const char *checker;
+
+ checker = strappenda("/sbin/fsck.", type);
+ r = access(checker, X_OK);
+ if (r < 0) {
+ log_warning("Checking was requested for %s, but %s cannot be used: %m", what, checker);
+
+ /* treat missing check as essentially OK */
+ return errno == ENOENT ? 0 : -errno;
+ }
+ }
+
+ if (streq(where, "/")) {
+ char *lnk;
+
+ lnk = strappenda(arg_dest, "/" SPECIAL_LOCAL_FS_TARGET ".wants/systemd-fsck-root.service");
+ mkdir_parents_label(lnk, 0755);
+ if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-fsck-root.service", lnk) < 0) {
+ log_error("Failed to create symlink %s: %m", lnk);
+ return -errno;
+ }
+ } else {
+ _cleanup_free_ char *fsck = NULL;
+
+ fsck = unit_name_from_path_instance("systemd-fsck", what, ".service");
+ if (!fsck)
+ return log_oom();
+
+ fprintf(f,
+ "RequiresOverridable=%s\n"
+ "After=%s\n",
+ fsck,
+ fsck);
+ }
+
+ return 0;
+}
+