chiark / gitweb /
the systemd logger only matters in the abstract namespace
[elogind.git] / mount.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #include <errno.h>
4
5 #include "unit.h"
6 #include "mount.h"
7 #include "load-fragment.h"
8 #include "load-fstab.h"
9 #include "load-dropin.h"
10
11 static int mount_init(Unit *u) {
12         int r;
13         Mount *m = MOUNT(u);
14
15         assert(m);
16
17         /* Load a .mount file */
18         if ((r = unit_load_fragment(u)) < 0)
19                 return r;
20
21         /* Load entry from /etc/fstab */
22         if ((r = unit_load_fstab(u)) < 0)
23                 return r;
24
25         /* Load drop-in directory data */
26         if ((r = unit_load_dropin(u)) < 0)
27                 return r;
28
29         return r;
30 }
31
32 static void mount_done(Unit *u) {
33         Mount *d = MOUNT(u);
34
35         assert(d);
36         free(d->path);
37 }
38
39 static void mount_dump(Unit *u, FILE *f, const char *prefix) {
40
41         static const char* const state_table[_MOUNT_STATE_MAX] = {
42                 [MOUNT_DEAD] = "dead",
43                 [MOUNT_MOUNTING] = "mounting",
44                 [MOUNT_MOUNTED] = "mounted",
45                 [MOUNT_UNMOUNTING] = "unmounting",
46                 [MOUNT_MAINTAINANCE] = "maintainance"
47         };
48
49         Mount *s = MOUNT(u);
50
51         assert(s);
52
53         fprintf(f,
54                 "%sMount State: %s\n"
55                 "%sPath: %s\n",
56                 prefix, state_table[s->state],
57                 prefix, s->path);
58 }
59
60 static UnitActiveState mount_active_state(Unit *u) {
61
62         static const UnitActiveState table[_MOUNT_STATE_MAX] = {
63                 [MOUNT_DEAD] = UNIT_INACTIVE,
64                 [MOUNT_MOUNTING] = UNIT_ACTIVATING,
65                 [MOUNT_MOUNTED] = UNIT_ACTIVE,
66                 [MOUNT_UNMOUNTING] = UNIT_DEACTIVATING,
67                 [MOUNT_MAINTAINANCE] = UNIT_INACTIVE,
68         };
69
70         return table[MOUNT(u)->state];
71 }
72
73 const UnitVTable mount_vtable = {
74         .suffix = ".mount",
75
76         .init = mount_init,
77         .done = mount_done,
78
79         .dump = mount_dump,
80
81         .active_state = mount_active_state,
82 };