[44fe800] | 1 | /*
|
---|
| 2 | * Copyright (c) 2015 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup volsrv
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file Filesystem creation
|
---|
| 34 | * @brief
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #include <errno.h>
|
---|
| 38 | #include <io/log.h>
|
---|
| 39 | #include <loc.h>
|
---|
| 40 | #include <stdarg.h>
|
---|
| 41 | #include <stdlib.h>
|
---|
| 42 | #include <str_error.h>
|
---|
| 43 | #include <task.h>
|
---|
| 44 | #include <types/vol.h>
|
---|
| 45 |
|
---|
| 46 | #include "mkfs.h"
|
---|
| 47 |
|
---|
| 48 | static int cmd_runl(const char *path, ...)
|
---|
| 49 | {
|
---|
| 50 | va_list ap;
|
---|
| 51 | const char *arg;
|
---|
| 52 | int cnt = 0;
|
---|
| 53 |
|
---|
| 54 | va_start(ap, path);
|
---|
| 55 | do {
|
---|
| 56 | arg = va_arg(ap, const char *);
|
---|
| 57 | cnt++;
|
---|
| 58 | } while (arg != NULL);
|
---|
| 59 | va_end(ap);
|
---|
| 60 |
|
---|
| 61 | va_start(ap, path);
|
---|
| 62 | task_id_t id;
|
---|
| 63 | task_wait_t wait;
|
---|
| 64 | int rc = task_spawn(&id, &wait, path, cnt, ap);
|
---|
| 65 | va_end(ap);
|
---|
| 66 |
|
---|
| 67 | if (rc != EOK) {
|
---|
| 68 | log_msg(LOG_DEFAULT, LVL_ERROR, "Error spawning %s (%s)",
|
---|
| 69 | path, str_error(rc));
|
---|
| 70 | return rc;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | if (!id) {
|
---|
| 74 | log_msg(LOG_DEFAULT, LVL_ERROR, "Error spawning %s "
|
---|
| 75 | "(invalid task ID)", path);
|
---|
| 76 | return EINVAL;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | task_exit_t texit;
|
---|
| 80 | int retval;
|
---|
| 81 | rc = task_wait(&wait, &texit, &retval);
|
---|
| 82 | if (rc != EOK) {
|
---|
| 83 | log_msg(LOG_DEFAULT, LVL_ERROR, "Error waiting for %s (%s)",
|
---|
| 84 | path, str_error(rc));
|
---|
| 85 | return rc;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | if (texit != TASK_EXIT_NORMAL) {
|
---|
| 89 | log_msg(LOG_DEFAULT, LVL_ERROR, "Command %s unexpectedly "
|
---|
| 90 | "terminated", path);
|
---|
| 91 | return EINVAL;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | if (retval != 0) {
|
---|
| 95 | log_msg(LOG_DEFAULT, LVL_ERROR, "Command %s returned non-zero "
|
---|
| 96 | "exit code %d)", path, retval);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | return retval;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | int volsrv_part_mkfs(service_id_t sid, vol_fstype_t fstype)
|
---|
| 104 | {
|
---|
| 105 | const char *cmd;
|
---|
| 106 | char *svc_name;
|
---|
| 107 | int rc;
|
---|
| 108 |
|
---|
| 109 | cmd = NULL;
|
---|
| 110 | switch (fstype) {
|
---|
| 111 | case fs_exfat:
|
---|
| 112 | cmd = "/app/mkexfat";
|
---|
| 113 | break;
|
---|
| 114 | case fs_fat:
|
---|
| 115 | cmd = "/app/mkfat";
|
---|
| 116 | break;
|
---|
| 117 | case fs_minix:
|
---|
| 118 | cmd = "/app/mkmfs";
|
---|
| 119 | break;
|
---|
| 120 | case fs_ext4:
|
---|
| 121 | cmd = NULL;
|
---|
| 122 | break;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | if (cmd == NULL)
|
---|
| 126 | return ENOTSUP;
|
---|
| 127 |
|
---|
| 128 | rc = loc_service_get_name(sid, &svc_name);
|
---|
| 129 | if (rc != EOK)
|
---|
| 130 | return rc;
|
---|
| 131 |
|
---|
| 132 | rc = cmd_runl(cmd, cmd, svc_name, NULL);
|
---|
| 133 | free(svc_name);
|
---|
| 134 | return rc;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | /** @}
|
---|
| 138 | */
|
---|