| 1 | #include <assert.h>
|
|---|
| 2 | #include <errno.h>
|
|---|
| 3 | #include <fibril_synch.h>
|
|---|
| 4 | #include <stdlib.h>
|
|---|
| 5 | #include <vfs/vfs.h>
|
|---|
| 6 |
|
|---|
| 7 | #include "log.h"
|
|---|
| 8 | #include "unit.h"
|
|---|
| 9 | #include "unit_mnt.h"
|
|---|
| 10 |
|
|---|
| 11 | static void unit_mnt_init(unit_t *unit)
|
|---|
| 12 | {
|
|---|
| 13 | assert(unit->data.mnt.type == NULL);
|
|---|
| 14 | assert(unit->data.mnt.mountpoint == NULL);
|
|---|
| 15 | assert(unit->data.mnt.device == NULL);
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | static int unit_mnt_start(unit_t *unit)
|
|---|
| 19 | {
|
|---|
| 20 | fibril_mutex_lock(&unit->state_mtx);
|
|---|
| 21 |
|
|---|
| 22 | // TODO think about unit's lifecycle (is STOPPED only acceptable?)
|
|---|
| 23 | assert(unit->state == STATE_STOPPED);
|
|---|
| 24 | unit->state = STATE_STARTING;
|
|---|
| 25 |
|
|---|
| 26 | fibril_condvar_broadcast(&unit->state_cv);
|
|---|
| 27 | fibril_mutex_unlock(&unit->state_mtx);
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | unit_mnt_t *data = &unit->data.mnt;
|
|---|
| 31 |
|
|---|
| 32 | // TODO use other mount parameters
|
|---|
| 33 | int rc = mount(data->type, data->mountpoint, data->device, "",
|
|---|
| 34 | IPC_FLAG_BLOCKING, 0);
|
|---|
| 35 |
|
|---|
| 36 | if (rc == EOK) {
|
|---|
| 37 | sysman_log(LVL_NOTE, "Mount (%p) mounted", unit);
|
|---|
| 38 | unit_set_state(unit, STATE_STARTED);
|
|---|
| 39 | } else {
|
|---|
| 40 | sysman_log(LVL_ERROR, "Mount (%p) failed (%i)", unit, rc);
|
|---|
| 41 | unit_set_state(unit, STATE_FAILED);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | return rc;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | static void unit_mnt_destroy(unit_t *unit)
|
|---|
| 48 | {
|
|---|
| 49 | free(unit->data.mnt.type);
|
|---|
| 50 | free(unit->data.mnt.mountpoint);
|
|---|
| 51 | free(unit->data.mnt.device);
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 | DEFINE_UNIT_OPS(unit_mnt)
|
|---|
| 56 |
|
|---|