-static int mount_add_fstab_links(Mount *m) {
- const char *target, *after, *tu_wants = NULL;
- MountParameters *p;
- Unit *tu;
- int r;
- bool noauto, nofail, automount;
-
- assert(m);
-
- if (UNIT(m)->manager->running_as != MANAGER_SYSTEM)
- return 0;
-
- if (!(p = get_mount_parameters_configured(m)))
- return 0;
-
- if (p != &m->parameters_etc_fstab)
- return 0;
-
- noauto = !!mount_test_option(p->options, "noauto");
- nofail = !!mount_test_option(p->options, "nofail");
- automount =
- mount_test_option(p->options, "comment=systemd.automount") ||
- mount_test_option(p->options, "x-systemd.automount");
-
- if (mount_is_network(p)) {
- target = SPECIAL_REMOTE_FS_TARGET;
- after = tu_wants = SPECIAL_REMOTE_FS_PRE_TARGET;
- } else {
- target = SPECIAL_LOCAL_FS_TARGET;
- after = SPECIAL_LOCAL_FS_PRE_TARGET;
- }
-
- r = manager_load_unit(UNIT(m)->manager, target, NULL, NULL, &tu);
- if (r < 0)
- return r;
-
- if (tu_wants) {
- r = unit_add_dependency_by_name(tu, UNIT_WANTS, tu_wants, NULL, true);
- if (r < 0)
- return r;
- }
-
- if (after) {
- r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, after, NULL, true);
- if (r < 0)
- return r;
- }
-
- if (automount) {
- Unit *am;
-
- if ((r = unit_load_related_unit(UNIT(m), ".automount", &am)) < 0)
- return r;
-
- /* If auto is configured as well also pull in the
- * mount right-away, but don't rely on it. */
- if (!noauto) /* automount + auto */
- if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(m), true)) < 0)
- return r;
-
- /* Install automount unit */
- if (!nofail) /* automount + fail */
- return unit_add_two_dependencies(tu, UNIT_AFTER, UNIT_REQUIRES, am, true);
- else /* automount + nofail */
- return unit_add_two_dependencies(tu, UNIT_AFTER, UNIT_WANTS, am, true);
-
- } else if (!noauto) {
-
- /* Automatically add mount points that aren't natively
- * configured to local-fs.target */
-
- if (!nofail) /* auto + fail */
- return unit_add_two_dependencies(tu, UNIT_AFTER, UNIT_REQUIRES, UNIT(m), true);
- else /* auto + nofail */
- return unit_add_dependency(tu, UNIT_WANTS, UNIT(m), true);
- }
-
- return 0;
-}
-