1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
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/>.
25 #include "automount.h"
26 #include "load-fragment.h"
27 #include "load-dropin.h"
29 static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
30 [AUTOMOUNT_DEAD] = UNIT_INACTIVE,
31 [AUTOMOUNT_WAITING] = UNIT_ACTIVE,
32 [AUTOMOUNT_RUNNING] = UNIT_ACTIVE,
33 [AUTOMOUNT_MAINTAINANCE] = UNIT_INACTIVE,
36 static const char* const state_string_table[_AUTOMOUNT_STATE_MAX] = {
37 [AUTOMOUNT_DEAD] = "dead",
38 [AUTOMOUNT_WAITING] = "waiting",
39 [AUTOMOUNT_RUNNING] = "running",
40 [AUTOMOUNT_MAINTAINANCE] = "maintainance"
43 static void automount_init(Unit *u) {
44 Automount *a = AUTOMOUNT(u);
50 static int automount_load(Unit *u) {
52 Automount *a = AUTOMOUNT(u);
55 assert(u->meta.load_state == UNIT_STUB);
57 /* Load a .automount file */
58 if ((r = unit_load_fragment_and_dropin_optional(u)) < 0)
61 if (u->meta.load_state == UNIT_LOADED) {
63 if ((r = unit_load_related_unit(u, ".mount", (Unit**) &a->mount)) < 0)
66 if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(a->mount))) < 0)
73 static void automount_done(Unit *u) {
74 Automount *a = AUTOMOUNT(u);
81 static void automount_dump(Unit *u, FILE *f, const char *prefix) {
82 Automount *s = AUTOMOUNT(u);
87 "%sAutomount State: %s\n",
88 prefix, state_string_table[s->state]);
91 static UnitActiveState automount_active_state(Unit *u) {
93 return state_translation_table[AUTOMOUNT(u)->state];
96 static const char *automount_sub_state_to_string(Unit *u) {
99 return state_string_table[AUTOMOUNT(u)->state];
102 const UnitVTable automount_vtable = {
107 .init = automount_init,
108 .load = automount_load,
109 .done = automount_done,
111 .dump = automount_dump,
113 .active_state = automount_active_state,
114 .sub_state_to_string = automount_sub_state_to_string