]>
Commit | Line | Data |
---|---|---|
5cb5a6ff LP |
1 | /*-*- Mode: C; c-basic-offset: 8 -*-*/ |
2 | ||
3 | #include <errno.h> | |
4 | ||
87f0e418 | 5 | #include "unit.h" |
5cb5a6ff LP |
6 | #include "mount.h" |
7 | #include "load-fragment.h" | |
8 | #include "load-fstab.h" | |
9 | #include "load-dropin.h" | |
10 | ||
87f0e418 | 11 | static int mount_init(Unit *u) { |
5cb5a6ff | 12 | int r; |
87f0e418 | 13 | Mount *m = MOUNT(u); |
5cb5a6ff LP |
14 | |
15 | assert(m); | |
16 | ||
17 | /* Load a .mount file */ | |
87f0e418 | 18 | if ((r = unit_load_fragment(u)) < 0 && errno != -ENOENT) |
5cb5a6ff LP |
19 | return r; |
20 | ||
21 | /* Load entry from /etc/fstab */ | |
87f0e418 | 22 | if ((r = unit_load_fstab(u)) < 0) |
5cb5a6ff LP |
23 | return r; |
24 | ||
25 | /* Load drop-in directory data */ | |
87f0e418 | 26 | if ((r = unit_load_dropin(u)) < 0) |
5cb5a6ff LP |
27 | return r; |
28 | ||
29 | return r; | |
30 | } | |
31 | ||
87f0e418 LP |
32 | static void mount_done(Unit *u) { |
33 | Mount *d = MOUNT(u); | |
034c6ed7 LP |
34 | |
35 | assert(d); | |
36 | free(d->path); | |
37 | } | |
38 | ||
87f0e418 | 39 | static void mount_dump(Unit *u, FILE *f, const char *prefix) { |
5cb5a6ff LP |
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 | ||
87f0e418 | 49 | Mount *s = MOUNT(u); |
5cb5a6ff LP |
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 | ||
87f0e418 | 60 | static UnitActiveState mount_active_state(Unit *u) { |
5cb5a6ff | 61 | |
87f0e418 LP |
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, | |
5cb5a6ff LP |
68 | }; |
69 | ||
87f0e418 | 70 | return table[MOUNT(u)->state]; |
5cb5a6ff LP |
71 | } |
72 | ||
87f0e418 | 73 | const UnitVTable mount_vtable = { |
5cb5a6ff LP |
74 | .suffix = ".mount", |
75 | ||
034c6ed7 LP |
76 | .init = mount_init, |
77 | .done = mount_done, | |
5cb5a6ff | 78 | |
034c6ed7 | 79 | .dump = mount_dump, |
5cb5a6ff LP |
80 | |
81 | .active_state = mount_active_state, | |
5cb5a6ff | 82 | }; |