summaryrefslogtreecommitdiff
path: root/mount.c
blob: 7a1ec087e7a5f6e20bf2384c6577660736d54d22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*-*- Mode: C; c-basic-offset: 8 -*-*/

#include <errno.h>

#include "unit.h"
#include "mount.h"
#include "load-fragment.h"
#include "load-fstab.h"
#include "load-dropin.h"

static int mount_init(Unit *u) {
        int r;
        Mount *m = MOUNT(u);

        assert(m);

        /* Load a .mount file */
        if ((r = unit_load_fragment(u)) < 0)
                return r;

        /* Load entry from /etc/fstab */
        if ((r = unit_load_fstab(u)) < 0)
                return r;

        /* Load drop-in directory data */
        if ((r = unit_load_dropin(u)) < 0)
                return r;

        return r;
}

static void mount_done(Unit *u) {
        Mount *d = MOUNT(u);

        assert(d);
        free(d->path);
}

static void mount_dump(Unit *u, FILE *f, const char *prefix) {

        static const char* const state_table[_MOUNT_STATE_MAX] = {
                [MOUNT_DEAD] = "dead",
                [MOUNT_MOUNTING] = "mounting",
                [MOUNT_MOUNTED] = "mounted",
                [MOUNT_UNMOUNTING] = "unmounting",
                [MOUNT_MAINTAINANCE] = "maintainance"
        };

        Mount *s = MOUNT(u);

        assert(s);

        fprintf(f,
                "%sMount State: %s\n"
                "%sPath: %s\n",
                prefix, state_table[s->state],
                prefix, s->path);
}

static UnitActiveState mount_active_state(Unit *u) {

        static const UnitActiveState table[_MOUNT_STATE_MAX] = {
                [MOUNT_DEAD] = UNIT_INACTIVE,
                [MOUNT_MOUNTING] = UNIT_ACTIVATING,
                [MOUNT_MOUNTED] = UNIT_ACTIVE,
                [MOUNT_UNMOUNTING] = UNIT_DEACTIVATING,
                [MOUNT_MAINTAINANCE] = UNIT_INACTIVE,
        };

        return table[MOUNT(u)->state];
}

const UnitVTable mount_vtable = {
        .suffix = ".mount",

        .init = mount_init,
        .done = mount_done,

        .dump = mount_dump,

        .active_state = mount_active_state,
};