]> git.ipfire.org Git - people/ms/systemd.git/blame - automount.c
execute: make flags_fds() parameters const
[people/ms/systemd.git] / automount.c
CommitLineData
5cb5a6ff
LP
1/*-*- Mode: C; c-basic-offset: 8 -*-*/
2
a7334b09
LP
3/***
4 This file is part of systemd.
5
6 Copyright 2010 Lennart Poettering
7
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.
12
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.
17
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/>.
20***/
21
5cb5a6ff
LP
22#include <errno.h>
23
87f0e418 24#include "unit.h"
5cb5a6ff
LP
25#include "automount.h"
26#include "load-fragment.h"
5cb5a6ff
LP
27#include "load-dropin.h"
28
e537352b
LP
29static 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,
34};
5cb5a6ff 35
e537352b
LP
36static 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"
41};
5cb5a6ff 42
e537352b
LP
43static void automount_init(Unit *u) {
44 Automount *a = AUTOMOUNT(u);
5cb5a6ff 45
e537352b
LP
46 a->state = 0;
47 a->mount = NULL;
48}
5cb5a6ff 49
e537352b
LP
50static int automount_load(Unit *u) {
51 int r;
52 Automount *a = AUTOMOUNT(u);
23a177ef 53
e537352b
LP
54 assert(u);
55 assert(u->meta.load_state == UNIT_STUB);
5cb5a6ff 56
e537352b
LP
57 /* Load a .automount file */
58 if ((r = unit_load_fragment_and_dropin_optional(u)) < 0)
59 return r;
23a177ef 60
e537352b 61 if (u->meta.load_state == UNIT_LOADED) {
23a177ef 62
e537352b 63 if ((r = unit_load_related_unit(u, ".mount", (Unit**) &a->mount)) < 0)
23a177ef
LP
64 return r;
65
e537352b 66 if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(a->mount))) < 0)
23a177ef
LP
67 return r;
68 }
69
5cb5a6ff
LP
70 return 0;
71}
72
87f0e418 73static void automount_done(Unit *u) {
e537352b
LP
74 Automount *a = AUTOMOUNT(u);
75
76 assert(a);
034c6ed7 77
e537352b 78 a->mount = NULL;
034c6ed7
LP
79}
80
87f0e418 81static void automount_dump(Unit *u, FILE *f, const char *prefix) {
87f0e418 82 Automount *s = AUTOMOUNT(u);
5cb5a6ff
LP
83
84 assert(s);
85
86 fprintf(f,
e537352b
LP
87 "%sAutomount State: %s\n",
88 prefix, state_string_table[s->state]);
5cb5a6ff
LP
89}
90
87f0e418
LP
91static UnitActiveState automount_active_state(Unit *u) {
92
e537352b 93 return state_translation_table[AUTOMOUNT(u)->state];
5cb5a6ff
LP
94}
95
87f0e418 96const UnitVTable automount_vtable = {
5cb5a6ff
LP
97 .suffix = ".mount",
98
e537352b
LP
99 .no_alias = true,
100
034c6ed7 101 .init = automount_init,
e537352b 102 .load = automount_load,
034c6ed7 103 .done = automount_done,
5cb5a6ff 104
034c6ed7 105 .dump = automount_dump,
5cb5a6ff 106
034c6ed7 107 .active_state = automount_active_state
5cb5a6ff 108};