summaryrefslogtreecommitdiff
path: root/mount.c
blob: 21d347785a0855bd45d4f3a38cc0d9ab5291ca8a (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 "name.h"
#include "mount.h"
#include "load-fragment.h"
#include "load-fstab.h"
#include "load-dropin.h"

static int mount_init(Name *n) {
        int r;
        Mount *m = MOUNT(n);

        assert(m);

        /* Load a .mount file */
        if ((r = name_load_fragment(n)) < 0 && errno != -ENOENT)
                return r;

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

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

        return r;
}

static void mount_done(Name *n) {
        Mount *d = MOUNT(n);

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

static void mount_dump(Name *n, 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(n);

        assert(s);

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

static NameActiveState mount_active_state(Name *n) {

        static const NameActiveState table[_MOUNT_STATE_MAX] = {
                [MOUNT_DEAD] = NAME_INACTIVE,
                [MOUNT_MOUNTING] = NAME_ACTIVATING,
                [MOUNT_MOUNTED] = NAME_ACTIVE,
                [MOUNT_UNMOUNTING] = NAME_DEACTIVATING,
                [MOUNT_MAINTAINANCE] = NAME_INACTIVE,
        };

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

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

        .init = mount_init,
        .done = mount_done,

        .dump = mount_dump,

        .active_state = mount_active_state,
};