1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
7 #include "load-fragment.h"
8 #include "load-fstab.h"
9 #include "load-dropin.h"
11 static int automount_init(Name *n) {
13 Automount *a = AUTOMOUNT(n);
17 exec_context_init(&a->exec_context);
19 /* Load a .automount file */
20 if ((r = name_load_fragment(n)) < 0 && errno != -ENOENT)
23 /* Load entry from /etc/fstab */
24 if ((r = name_load_fstab(n)) < 0)
27 /* Load drop-in directory data */
28 if ((r = name_load_dropin(n)) < 0)
34 static void automount_done(Name *n) {
35 Automount *d = AUTOMOUNT(n);
41 static void automount_dump(Name *n, FILE *f, const char *prefix) {
43 static const char* const state_table[_AUTOMOUNT_STATE_MAX] = {
44 [AUTOMOUNT_DEAD] = "dead",
45 [AUTOMOUNT_START_PRE] = "start-pre",
46 [AUTOMOUNT_START_POST] = "start-post",
47 [AUTOMOUNT_WAITING] = "waiting",
48 [AUTOMOUNT_RUNNING] = "running",
49 [AUTOMOUNT_STOP_PRE] = "stop-pre",
50 [AUTOMOUNT_STOP_POST] = "stop-post",
51 [AUTOMOUNT_MAINTAINANCE] = "maintainance"
54 static const char* const command_table[_AUTOMOUNT_EXEC_MAX] = {
55 [AUTOMOUNT_EXEC_START_PRE] = "StartPre",
56 [AUTOMOUNT_EXEC_START_POST] = "StartPost",
57 [AUTOMOUNT_EXEC_STOP_PRE] = "StopPre",
58 [AUTOMOUNT_EXEC_STOP_POST] = "StopPost"
61 AutomountExecCommand c;
62 Automount *s = AUTOMOUNT(n);
67 "%sAutomount State: %s\n"
69 prefix, state_table[s->state],
72 exec_context_dump(&s->exec_context, f, prefix);
74 for (c = 0; c < _AUTOMOUNT_EXEC_MAX; c++) {
77 LIST_FOREACH(command, i, s->exec_command[c])
78 fprintf(f, "%s%s: %s\n", prefix, command_table[c], i->path);
82 static NameActiveState automount_active_state(Name *n) {
84 static const NameActiveState table[_AUTOMOUNT_STATE_MAX] = {
85 [AUTOMOUNT_DEAD] = NAME_INACTIVE,
86 [AUTOMOUNT_START_PRE] = NAME_ACTIVATING,
87 [AUTOMOUNT_START_POST] = NAME_ACTIVATING,
88 [AUTOMOUNT_WAITING] = NAME_ACTIVE,
89 [AUTOMOUNT_RUNNING] = NAME_ACTIVE,
90 [AUTOMOUNT_STOP_PRE] = NAME_DEACTIVATING,
91 [AUTOMOUNT_STOP_POST] = NAME_DEACTIVATING,
92 [AUTOMOUNT_MAINTAINANCE] = NAME_INACTIVE,
95 return table[AUTOMOUNT(n)->state];
98 const NameVTable automount_vtable = {
101 .init = automount_init,
102 .done = automount_done,
104 .dump = automount_dump,
106 .active_state = automount_active_state