chiark / gitweb /
first attempt in implementinging execution logic
[elogind.git] / mount.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #include <errno.h>
4
5 #include "name.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_load(Name *n) {
12         int r;
13         Mount *m = MOUNT(n);
14
15         assert(m);
16
17         /* Load a .mount file */
18         if ((r = name_load_fragment(n)) < 0 && errno != -ENOENT)
19                 return r;
20
21         /* Load entry from /etc/fstab */
22         if ((r = name_load_fstab(n)) < 0)
23                 return r;
24
25         /* Load drop-in directory data */
26         if ((r = name_load_dropin(n)) < 0)
27                 return r;
28
29         return r;
30 }
31
32 static void mount_dump(Name *n, FILE *f, const char *prefix) {
33
34         static const char* const state_table[_MOUNT_STATE_MAX] = {
35                 [MOUNT_DEAD] = "dead",
36                 [MOUNT_MOUNTING] = "mounting",
37                 [MOUNT_MOUNTED] = "mounted",
38                 [MOUNT_UNMOUNTING] = "unmounting",
39                 [MOUNT_MAINTAINANCE] = "maintainance"
40         };
41
42         Mount *s = MOUNT(n);
43
44         assert(s);
45
46         fprintf(f,
47                 "%sMount State: %s\n"
48                 "%sPath: %s\n",
49                 prefix, state_table[s->state],
50                 prefix, s->path);
51 }
52
53 static NameActiveState mount_active_state(Name *n) {
54
55         static const NameActiveState table[_MOUNT_STATE_MAX] = {
56                 [MOUNT_DEAD] = NAME_INACTIVE,
57                 [MOUNT_MOUNTING] = NAME_ACTIVATING,
58                 [MOUNT_MOUNTED] = NAME_ACTIVE,
59                 [MOUNT_UNMOUNTING] = NAME_DEACTIVATING,
60                 [MOUNT_MAINTAINANCE] = NAME_INACTIVE,
61         };
62
63         return table[MOUNT(n)->state];
64 }
65
66 static void mount_free_hook(Name *n) {
67         Mount *d = MOUNT(n);
68
69         assert(d);
70         free(d->path);
71 }
72
73 const NameVTable mount_vtable = {
74         .suffix = ".mount",
75
76         .load = mount_load,
77         .dump = mount_dump,
78
79         .start = NULL,
80         .stop = NULL,
81         .reload = NULL,
82
83         .active_state = mount_active_state,
84
85         .free_hook = mount_free_hook
86 };