[1356f85a] | 1 | /*
|
---|
[4285f384] | 2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
[1356f85a] | 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 Volume service
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <async.h>
|
---|
| 37 | #include <errno.h>
|
---|
[c1694b6b] | 38 | #include <str_error.h>
|
---|
[1356f85a] | 39 | #include <io/log.h>
|
---|
| 40 | #include <ipc/services.h>
|
---|
[22fb7ab] | 41 | #include <ipc/vol.h>
|
---|
[1356f85a] | 42 | #include <loc.h>
|
---|
[0ecfc62] | 43 | #include <macros.h>
|
---|
[1356f85a] | 44 | #include <stdio.h>
|
---|
| 45 | #include <stdlib.h>
|
---|
| 46 | #include <task.h>
|
---|
[edebb4a1] | 47 | #include <types/vol.h>
|
---|
[1356f85a] | 48 |
|
---|
[9c2c7d2] | 49 | #include "mkfs.h"
|
---|
[372df8f] | 50 | #include "part.h"
|
---|
[64ffd83] | 51 | #include "volume.h"
|
---|
[1356f85a] | 52 |
|
---|
| 53 | #define NAME "volsrv"
|
---|
| 54 |
|
---|
[ca127f37] | 55 | const char *vol_icfg_file = "/cfg/initvol.sif";
|
---|
| 56 | const char *vol_cfg_file = "/w/cfg/volsrv.sif";
|
---|
[1dcba91] | 57 |
|
---|
[984a9ba] | 58 | static void vol_client_conn(ipc_call_t *, void *);
|
---|
[1356f85a] | 59 |
|
---|
[b7fd2a0] | 60 | static errno_t vol_init(void)
|
---|
[1356f85a] | 61 | {
|
---|
[b7fd2a0] | 62 | errno_t rc;
|
---|
[64ffd83] | 63 | vol_volumes_t *volumes = NULL;
|
---|
[e89a06a] | 64 | vol_parts_t *parts = NULL;
|
---|
[4c6fd56] | 65 | loc_srv_t *srv = NULL;
|
---|
[e89a06a] | 66 |
|
---|
[1356f85a] | 67 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_init()");
|
---|
| 68 |
|
---|
[ca127f37] | 69 | rc = vol_volumes_create(vol_icfg_file, &volumes);
|
---|
[64ffd83] | 70 | if (rc != EOK)
|
---|
| 71 | goto error;
|
---|
| 72 |
|
---|
| 73 | rc = vol_parts_create(volumes, &parts);
|
---|
[22fb7ab] | 74 | if (rc != EOK)
|
---|
[e89a06a] | 75 | goto error;
|
---|
[22fb7ab] | 76 |
|
---|
[e89a06a] | 77 | rc = vol_part_discovery_start(parts);
|
---|
[1356f85a] | 78 | if (rc != EOK)
|
---|
[e89a06a] | 79 | goto error;
|
---|
[1356f85a] | 80 |
|
---|
[e89a06a] | 81 | async_set_fallback_port_handler(vol_client_conn, parts);
|
---|
[1356f85a] | 82 |
|
---|
[4c6fd56] | 83 | rc = loc_server_register(NAME, &srv);
|
---|
[1356f85a] | 84 | if (rc != EOK) {
|
---|
[c1694b6b] | 85 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server: %s.", str_error(rc));
|
---|
[e89a06a] | 86 | rc = EEXIST;
|
---|
[1356f85a] | 87 | }
|
---|
| 88 |
|
---|
| 89 | service_id_t sid;
|
---|
[ca48672] | 90 | rc = loc_service_register(srv, SERVICE_NAME_VOLSRV, fallback_port_id,
|
---|
| 91 | &sid);
|
---|
[1356f85a] | 92 | if (rc != EOK) {
|
---|
[c1694b6b] | 93 | log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service: %s.", str_error(rc));
|
---|
[e89a06a] | 94 | rc = EEXIST;
|
---|
| 95 | goto error;
|
---|
[1356f85a] | 96 | }
|
---|
| 97 |
|
---|
| 98 | return EOK;
|
---|
[e89a06a] | 99 | error:
|
---|
[4c6fd56] | 100 | if (srv != NULL)
|
---|
| 101 | loc_server_unregister(srv);
|
---|
[64ffd83] | 102 | vol_volumes_destroy(volumes);
|
---|
[e89a06a] | 103 | vol_parts_destroy(parts);
|
---|
| 104 | return rc;
|
---|
[1356f85a] | 105 | }
|
---|
| 106 |
|
---|
[e89a06a] | 107 | static void vol_get_parts_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[22fb7ab] | 108 | {
|
---|
[984a9ba] | 109 | ipc_call_t call;
|
---|
[22fb7ab] | 110 | size_t size;
|
---|
| 111 | size_t act_size;
|
---|
[b7fd2a0] | 112 | errno_t rc;
|
---|
[22fb7ab] | 113 |
|
---|
[984a9ba] | 114 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 115 | async_answer_0(&call, EREFUSED);
|
---|
| 116 | async_answer_0(icall, EREFUSED);
|
---|
[22fb7ab] | 117 | return;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | service_id_t *id_buf = (service_id_t *) malloc(size);
|
---|
| 121 | if (id_buf == NULL) {
|
---|
[984a9ba] | 122 | async_answer_0(&call, ENOMEM);
|
---|
| 123 | async_answer_0(icall, ENOMEM);
|
---|
[22fb7ab] | 124 | return;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[e89a06a] | 127 | rc = vol_part_get_ids(parts, id_buf, size, &act_size);
|
---|
[22fb7ab] | 128 | if (rc != EOK) {
|
---|
[984a9ba] | 129 | async_answer_0(&call, rc);
|
---|
| 130 | async_answer_0(icall, rc);
|
---|
[22fb7ab] | 131 | return;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[984a9ba] | 134 | errno_t retval = async_data_read_finalize(&call, id_buf, size);
|
---|
[22fb7ab] | 135 | free(id_buf);
|
---|
| 136 |
|
---|
[984a9ba] | 137 | async_answer_1(icall, retval, act_size);
|
---|
[22fb7ab] | 138 | }
|
---|
| 139 |
|
---|
[e89a06a] | 140 | static void vol_part_add_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[edebb4a1] | 141 | {
|
---|
| 142 | service_id_t sid;
|
---|
[b7fd2a0] | 143 | errno_t rc;
|
---|
[edebb4a1] | 144 |
|
---|
[fafb8e5] | 145 | sid = ipc_get_arg1(icall);
|
---|
[edebb4a1] | 146 |
|
---|
[64ffd83] | 147 | rc = vol_part_add_part(parts, sid);
|
---|
[edebb4a1] | 148 | if (rc != EOK) {
|
---|
[984a9ba] | 149 | async_answer_0(icall, rc);
|
---|
[edebb4a1] | 150 | return;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[984a9ba] | 153 | async_answer_0(icall, EOK);
|
---|
[edebb4a1] | 154 | }
|
---|
| 155 |
|
---|
[e89a06a] | 156 | static void vol_part_info_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[22fb7ab] | 157 | {
|
---|
| 158 | service_id_t sid;
|
---|
[372df8f] | 159 | vol_part_t *part;
|
---|
| 160 | vol_part_info_t pinfo;
|
---|
[b7fd2a0] | 161 | errno_t rc;
|
---|
[22fb7ab] | 162 |
|
---|
[fafb8e5] | 163 | sid = ipc_get_arg1(icall);
|
---|
[55f8c6e7] | 164 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_info_srv(%zu)",
|
---|
[edebb4a1] | 165 | sid);
|
---|
[e89a06a] | 166 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
---|
[22fb7ab] | 167 | if (rc != EOK) {
|
---|
[984a9ba] | 168 | async_answer_0(icall, ENOENT);
|
---|
[22fb7ab] | 169 | return;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[372df8f] | 172 | rc = vol_part_get_info(part, &pinfo);
|
---|
[b7a4d06] | 173 | if (rc != EOK) {
|
---|
[984a9ba] | 174 | async_answer_0(icall, EIO);
|
---|
[1a9174e] | 175 | goto error;
|
---|
[b7a4d06] | 176 | }
|
---|
| 177 |
|
---|
[984a9ba] | 178 | ipc_call_t call;
|
---|
[0ecfc62] | 179 | size_t size;
|
---|
[984a9ba] | 180 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 181 | async_answer_0(&call, EREFUSED);
|
---|
| 182 | async_answer_0(icall, EREFUSED);
|
---|
[1a9174e] | 183 | goto error;
|
---|
[0ecfc62] | 184 | }
|
---|
| 185 |
|
---|
| 186 | if (size != sizeof(vol_part_info_t)) {
|
---|
[984a9ba] | 187 | async_answer_0(&call, EINVAL);
|
---|
| 188 | async_answer_0(icall, EINVAL);
|
---|
[1a9174e] | 189 | goto error;
|
---|
[0ecfc62] | 190 | }
|
---|
| 191 |
|
---|
[984a9ba] | 192 | rc = async_data_read_finalize(&call, &pinfo,
|
---|
[0ecfc62] | 193 | min(size, sizeof(pinfo)));
|
---|
| 194 | if (rc != EOK) {
|
---|
[984a9ba] | 195 | async_answer_0(&call, rc);
|
---|
| 196 | async_answer_0(icall, rc);
|
---|
[1a9174e] | 197 | goto error;
|
---|
[0ecfc62] | 198 | }
|
---|
| 199 |
|
---|
[984a9ba] | 200 | async_answer_0(icall, EOK);
|
---|
[1a9174e] | 201 | error:
|
---|
| 202 | vol_part_del_ref(part);
|
---|
[22fb7ab] | 203 | }
|
---|
| 204 |
|
---|
[e89a06a] | 205 | static void vol_part_eject_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[72c72d4] | 206 | {
|
---|
| 207 | service_id_t sid;
|
---|
[4285f384] | 208 | vol_eject_flags_t flags;
|
---|
[72c72d4] | 209 | vol_part_t *part;
|
---|
| 210 | errno_t rc;
|
---|
| 211 |
|
---|
[fafb8e5] | 212 | sid = ipc_get_arg1(icall);
|
---|
[4285f384] | 213 | flags = ipc_get_arg2(icall);
|
---|
| 214 |
|
---|
| 215 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_eject_srv(%zu, %x)",
|
---|
| 216 | sid, flags);
|
---|
[72c72d4] | 217 |
|
---|
[e89a06a] | 218 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
---|
[72c72d4] | 219 | if (rc != EOK) {
|
---|
[984a9ba] | 220 | async_answer_0(icall, ENOENT);
|
---|
[f0f8787] | 221 | return;
|
---|
[72c72d4] | 222 | }
|
---|
| 223 |
|
---|
[4285f384] | 224 | rc = vol_part_eject_part(part, flags);
|
---|
[72c72d4] | 225 | if (rc != EOK) {
|
---|
[984a9ba] | 226 | async_answer_0(icall, EIO);
|
---|
[1a9174e] | 227 | goto error;
|
---|
[72c72d4] | 228 | }
|
---|
| 229 |
|
---|
[984a9ba] | 230 | async_answer_0(icall, EOK);
|
---|
[1a9174e] | 231 | error:
|
---|
| 232 | vol_part_del_ref(part);
|
---|
[72c72d4] | 233 | }
|
---|
| 234 |
|
---|
[f0f8787] | 235 | static void vol_part_insert_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
| 236 | {
|
---|
| 237 | service_id_t sid;
|
---|
| 238 | vol_part_t *part;
|
---|
| 239 | errno_t rc;
|
---|
| 240 |
|
---|
[fafb8e5] | 241 | sid = ipc_get_arg1(icall);
|
---|
[f0f8787] | 242 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_insert_srv(%zu)", sid);
|
---|
| 243 |
|
---|
| 244 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
---|
| 245 | if (rc != EOK) {
|
---|
| 246 | async_answer_0(icall, ENOENT);
|
---|
| 247 | return;
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | rc = vol_part_insert_part(part);
|
---|
| 251 | if (rc != EOK) {
|
---|
| 252 | async_answer_0(icall, EIO);
|
---|
| 253 | goto error;
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | async_answer_0(icall, EOK);
|
---|
| 257 | error:
|
---|
| 258 | vol_part_del_ref(part);
|
---|
| 259 | }
|
---|
| 260 |
|
---|
[b82985e] | 261 | static void vol_part_insert_by_path_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
| 262 | {
|
---|
| 263 | vol_part_t *part;
|
---|
| 264 | char *path = NULL;
|
---|
| 265 | errno_t rc;
|
---|
| 266 |
|
---|
[9e45a41] | 267 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_insert_by_path_srv()");
|
---|
[b82985e] | 268 |
|
---|
| 269 | rc = async_data_write_accept((void **)&path, true, 0, VOL_MOUNTP_MAXLEN,
|
---|
| 270 | 0, NULL);
|
---|
| 271 | if (rc != EOK) {
|
---|
| 272 | async_answer_0(icall, rc);
|
---|
| 273 | goto error;
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | rc = vol_part_find_by_path_ref(parts, path, &part);
|
---|
| 277 | if (rc != EOK) {
|
---|
| 278 | async_answer_0(icall, ENOENT);
|
---|
| 279 | goto error;
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | rc = vol_part_insert_part(part);
|
---|
| 283 | if (rc != EOK) {
|
---|
| 284 | async_answer_0(icall, rc);
|
---|
| 285 | vol_part_del_ref(part);
|
---|
| 286 | goto error;
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | free(path);
|
---|
| 290 | vol_part_del_ref(part);
|
---|
| 291 | async_answer_0(icall, EOK);
|
---|
| 292 |
|
---|
| 293 | return;
|
---|
| 294 | error:
|
---|
| 295 | if (path != NULL)
|
---|
| 296 | free(path);
|
---|
| 297 | }
|
---|
| 298 |
|
---|
[e89a06a] | 299 | static void vol_part_empty_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[22fb7ab] | 300 | {
|
---|
| 301 | service_id_t sid;
|
---|
[372df8f] | 302 | vol_part_t *part;
|
---|
[b7fd2a0] | 303 | errno_t rc;
|
---|
[22fb7ab] | 304 |
|
---|
[fafb8e5] | 305 | sid = ipc_get_arg1(icall);
|
---|
[55f8c6e7] | 306 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_empty_srv(%zu)", sid);
|
---|
[22fb7ab] | 307 |
|
---|
[e89a06a] | 308 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
---|
[22fb7ab] | 309 | if (rc != EOK) {
|
---|
[984a9ba] | 310 | async_answer_0(icall, ENOENT);
|
---|
[22fb7ab] | 311 | return;
|
---|
| 312 | }
|
---|
| 313 |
|
---|
[372df8f] | 314 | rc = vol_part_empty_part(part);
|
---|
[603c1d1f] | 315 | if (rc != EOK) {
|
---|
[984a9ba] | 316 | async_answer_0(icall, EIO);
|
---|
[1a9174e] | 317 | goto error;
|
---|
[603c1d1f] | 318 | }
|
---|
[22fb7ab] | 319 |
|
---|
[984a9ba] | 320 | async_answer_0(icall, EOK);
|
---|
[1a9174e] | 321 | error:
|
---|
| 322 | vol_part_del_ref(part);
|
---|
[22fb7ab] | 323 | }
|
---|
[1356f85a] | 324 |
|
---|
[e89a06a] | 325 | static void vol_part_get_lsupp_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[9c2c7d2] | 326 | {
|
---|
| 327 | vol_fstype_t fstype;
|
---|
| 328 | vol_label_supp_t vlsupp;
|
---|
[b7fd2a0] | 329 | errno_t rc;
|
---|
[9c2c7d2] | 330 |
|
---|
[fafb8e5] | 331 | fstype = ipc_get_arg1(icall);
|
---|
[9c2c7d2] | 332 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_get_lsupp_srv(%u)",
|
---|
| 333 | fstype);
|
---|
| 334 |
|
---|
| 335 | volsrv_part_get_lsupp(fstype, &vlsupp);
|
---|
| 336 |
|
---|
[984a9ba] | 337 | ipc_call_t call;
|
---|
[9c2c7d2] | 338 | size_t size;
|
---|
[984a9ba] | 339 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 340 | async_answer_0(&call, EREFUSED);
|
---|
| 341 | async_answer_0(icall, EREFUSED);
|
---|
[9c2c7d2] | 342 | return;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | if (size != sizeof(vol_label_supp_t)) {
|
---|
[984a9ba] | 346 | async_answer_0(&call, EINVAL);
|
---|
| 347 | async_answer_0(icall, EINVAL);
|
---|
[9c2c7d2] | 348 | return;
|
---|
| 349 | }
|
---|
| 350 |
|
---|
[984a9ba] | 351 | rc = async_data_read_finalize(&call, &vlsupp,
|
---|
[9c2c7d2] | 352 | min(size, sizeof(vlsupp)));
|
---|
| 353 | if (rc != EOK) {
|
---|
[984a9ba] | 354 | async_answer_0(&call, rc);
|
---|
| 355 | async_answer_0(icall, rc);
|
---|
[9c2c7d2] | 356 | return;
|
---|
| 357 | }
|
---|
| 358 |
|
---|
[984a9ba] | 359 | async_answer_0(icall, EOK);
|
---|
[9c2c7d2] | 360 | }
|
---|
| 361 |
|
---|
[e89a06a] | 362 | static void vol_part_mkfs_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
[44fe800] | 363 | {
|
---|
| 364 | service_id_t sid;
|
---|
| 365 | vol_part_t *part;
|
---|
| 366 | vol_fstype_t fstype;
|
---|
[2d78d88] | 367 | char *label = NULL;
|
---|
| 368 | char *mountp = NULL;
|
---|
[b7fd2a0] | 369 | errno_t rc;
|
---|
[44fe800] | 370 |
|
---|
[9e45a41] | 371 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_mkfs_srv()");
|
---|
[5f36841] | 372 |
|
---|
[fafb8e5] | 373 | sid = ipc_get_arg1(icall);
|
---|
| 374 | fstype = ipc_get_arg2(icall);
|
---|
[44fe800] | 375 |
|
---|
[9c2c7d2] | 376 | rc = async_data_write_accept((void **)&label, true, 0, VOL_LABEL_MAXLEN,
|
---|
| 377 | 0, NULL);
|
---|
| 378 | if (rc != EOK) {
|
---|
[984a9ba] | 379 | async_answer_0(icall, rc);
|
---|
[2d78d88] | 380 | goto error;
|
---|
[9c2c7d2] | 381 | }
|
---|
| 382 |
|
---|
[5f36841] | 383 | if (label != NULL) {
|
---|
[9e45a41] | 384 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_mkfs_srv: label='%s'",
|
---|
[5f36841] | 385 | label);
|
---|
| 386 | }
|
---|
[9c2c7d2] | 387 |
|
---|
[64ffd83] | 388 | rc = async_data_write_accept((void **)&mountp, true, 0, VOL_MOUNTP_MAXLEN,
|
---|
| 389 | 0, NULL);
|
---|
| 390 | if (rc != EOK) {
|
---|
| 391 | async_answer_0(icall, rc);
|
---|
[2d78d88] | 392 | goto error;
|
---|
[64ffd83] | 393 | }
|
---|
| 394 |
|
---|
| 395 | if (mountp != NULL) {
|
---|
[9e45a41] | 396 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_mkfs_srv: mountp='%s'",
|
---|
[64ffd83] | 397 | mountp);
|
---|
| 398 | }
|
---|
| 399 |
|
---|
[e89a06a] | 400 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
---|
[44fe800] | 401 | if (rc != EOK) {
|
---|
[984a9ba] | 402 | async_answer_0(icall, ENOENT);
|
---|
[2d78d88] | 403 | goto error;
|
---|
[44fe800] | 404 | }
|
---|
| 405 |
|
---|
[64ffd83] | 406 | rc = vol_part_mkfs_part(part, fstype, label, mountp);
|
---|
[44fe800] | 407 | if (rc != EOK) {
|
---|
[2d78d88] | 408 | async_answer_0(icall, rc);
|
---|
| 409 | vol_part_del_ref(part);
|
---|
| 410 | goto error;
|
---|
| 411 | }
|
---|
| 412 |
|
---|
| 413 | free(label);
|
---|
| 414 | free(mountp);
|
---|
| 415 | async_answer_0(icall, EOK);
|
---|
| 416 |
|
---|
| 417 | return;
|
---|
| 418 | error:
|
---|
| 419 | if (label != NULL)
|
---|
[9c2c7d2] | 420 | free(label);
|
---|
[2d78d88] | 421 | if (mountp != NULL)
|
---|
| 422 | free(mountp);
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 | static void vol_part_set_mountp_srv(vol_parts_t *parts,
|
---|
| 426 | ipc_call_t *icall)
|
---|
| 427 | {
|
---|
| 428 | service_id_t sid;
|
---|
| 429 | vol_part_t *part;
|
---|
| 430 | char *mountp;
|
---|
| 431 | errno_t rc;
|
---|
| 432 |
|
---|
[9e45a41] | 433 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_set_mountp_srv()");
|
---|
[2d78d88] | 434 |
|
---|
[fafb8e5] | 435 | sid = ipc_get_arg1(icall);
|
---|
[2d78d88] | 436 |
|
---|
| 437 | rc = async_data_write_accept((void **)&mountp, true, 0,
|
---|
| 438 | VOL_MOUNTP_MAXLEN, 0, NULL);
|
---|
| 439 | if (rc != EOK) {
|
---|
| 440 | async_answer_0(icall, rc);
|
---|
| 441 | return;
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | if (mountp != NULL) {
|
---|
[9e45a41] | 445 | log_msg(LOG_DEFAULT, LVL_DEBUG,
|
---|
[2d78d88] | 446 | "vol_part_set_mountp_srv: mountp='%s'", mountp);
|
---|
| 447 | }
|
---|
| 448 |
|
---|
| 449 | rc = vol_part_find_by_id_ref(parts, sid, &part);
|
---|
| 450 | if (rc != EOK) {
|
---|
| 451 | free(mountp);
|
---|
| 452 | async_answer_0(icall, ENOENT);
|
---|
| 453 | return;
|
---|
| 454 | }
|
---|
| 455 |
|
---|
| 456 | rc = vol_part_set_mountp_part(part, mountp);
|
---|
| 457 | if (rc != EOK) {
|
---|
| 458 | free(mountp);
|
---|
[984a9ba] | 459 | async_answer_0(icall, rc);
|
---|
[1a9174e] | 460 | vol_part_del_ref(part);
|
---|
[44fe800] | 461 | return;
|
---|
| 462 | }
|
---|
| 463 |
|
---|
[2d78d88] | 464 | free(mountp);
|
---|
[984a9ba] | 465 | async_answer_0(icall, EOK);
|
---|
[44fe800] | 466 | }
|
---|
| 467 |
|
---|
[63c1dd5] | 468 | static void vol_get_volumes_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
| 469 | {
|
---|
| 470 | ipc_call_t call;
|
---|
| 471 | size_t size;
|
---|
| 472 | size_t act_size;
|
---|
| 473 | errno_t rc;
|
---|
| 474 |
|
---|
[9e45a41] | 475 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_get_volumes_srv()");
|
---|
[63c1dd5] | 476 |
|
---|
| 477 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 478 | async_answer_0(&call, EREFUSED);
|
---|
| 479 | async_answer_0(icall, EREFUSED);
|
---|
| 480 | return;
|
---|
| 481 | }
|
---|
| 482 |
|
---|
| 483 | volume_id_t *id_buf = (volume_id_t *) malloc(size);
|
---|
| 484 | if (id_buf == NULL) {
|
---|
| 485 | async_answer_0(&call, ENOMEM);
|
---|
| 486 | async_answer_0(icall, ENOMEM);
|
---|
| 487 | return;
|
---|
| 488 | }
|
---|
| 489 |
|
---|
| 490 | rc = vol_get_ids(parts->volumes, id_buf, size, &act_size);
|
---|
| 491 | if (rc != EOK) {
|
---|
| 492 | async_answer_0(&call, rc);
|
---|
| 493 | async_answer_0(icall, rc);
|
---|
| 494 | return;
|
---|
| 495 | }
|
---|
| 496 |
|
---|
| 497 | errno_t retval = async_data_read_finalize(&call, id_buf, size);
|
---|
| 498 | free(id_buf);
|
---|
| 499 |
|
---|
| 500 | async_answer_1(icall, retval, act_size);
|
---|
| 501 | }
|
---|
| 502 |
|
---|
| 503 | static void vol_info_srv(vol_parts_t *parts, ipc_call_t *icall)
|
---|
| 504 | {
|
---|
| 505 | volume_id_t vid;
|
---|
| 506 | vol_volume_t *volume;
|
---|
| 507 | vol_info_t vinfo;
|
---|
| 508 | errno_t rc;
|
---|
| 509 |
|
---|
[fafb8e5] | 510 | vid.id = ipc_get_arg1(icall);
|
---|
[63c1dd5] | 511 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_info_srv(%zu)", vid.id);
|
---|
| 512 |
|
---|
| 513 | rc = vol_volume_find_by_id_ref(parts->volumes, vid, &volume);
|
---|
| 514 | if (rc != EOK) {
|
---|
| 515 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_info_srv: volume %zu not found",
|
---|
| 516 | vid.id);
|
---|
| 517 | async_answer_0(icall, ENOENT);
|
---|
| 518 | return;
|
---|
| 519 | }
|
---|
| 520 |
|
---|
| 521 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_info_srv: vol_volume_get_info");
|
---|
| 522 | rc = vol_volume_get_info(volume, &vinfo);
|
---|
| 523 | if (rc != EOK) {
|
---|
| 524 | async_answer_0(icall, EIO);
|
---|
| 525 | goto error;
|
---|
| 526 | }
|
---|
| 527 |
|
---|
| 528 | ipc_call_t call;
|
---|
| 529 | size_t size;
|
---|
| 530 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 531 | async_answer_0(&call, EREFUSED);
|
---|
| 532 | async_answer_0(icall, EREFUSED);
|
---|
| 533 | goto error;
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | if (size != sizeof(vol_info_t)) {
|
---|
| 537 | async_answer_0(&call, EINVAL);
|
---|
| 538 | async_answer_0(icall, EINVAL);
|
---|
| 539 | goto error;
|
---|
| 540 | }
|
---|
| 541 |
|
---|
| 542 | rc = async_data_read_finalize(&call, &vinfo,
|
---|
| 543 | min(size, sizeof(vinfo)));
|
---|
| 544 | if (rc != EOK) {
|
---|
| 545 | async_answer_0(&call, rc);
|
---|
| 546 | async_answer_0(icall, rc);
|
---|
| 547 | goto error;
|
---|
| 548 | }
|
---|
| 549 |
|
---|
| 550 | async_answer_0(icall, EOK);
|
---|
| 551 | error:
|
---|
| 552 | vol_volume_del_ref(volume);
|
---|
| 553 | }
|
---|
| 554 |
|
---|
[984a9ba] | 555 | static void vol_client_conn(ipc_call_t *icall, void *arg)
|
---|
[1356f85a] | 556 | {
|
---|
[e89a06a] | 557 | vol_parts_t *parts = (vol_parts_t *) arg;
|
---|
| 558 |
|
---|
[1356f85a] | 559 | log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_client_conn()");
|
---|
| 560 |
|
---|
| 561 | /* Accept the connection */
|
---|
[beb83c1] | 562 | async_accept_0(icall);
|
---|
[1356f85a] | 563 |
|
---|
| 564 | while (true) {
|
---|
| 565 | ipc_call_t call;
|
---|
[984a9ba] | 566 | async_get_call(&call);
|
---|
[fafb8e5] | 567 | sysarg_t method = ipc_get_imethod(&call);
|
---|
[1356f85a] | 568 |
|
---|
| 569 | if (!method) {
|
---|
| 570 | /* The other side has hung up */
|
---|
[984a9ba] | 571 | async_answer_0(&call, EOK);
|
---|
[1356f85a] | 572 | return;
|
---|
| 573 | }
|
---|
| 574 |
|
---|
| 575 | switch (method) {
|
---|
[372df8f] | 576 | case VOL_GET_PARTS:
|
---|
[e89a06a] | 577 | vol_get_parts_srv(parts, &call);
|
---|
[22fb7ab] | 578 | break;
|
---|
[edebb4a1] | 579 | case VOL_PART_ADD:
|
---|
[e89a06a] | 580 | vol_part_add_srv(parts, &call);
|
---|
[edebb4a1] | 581 | break;
|
---|
[372df8f] | 582 | case VOL_PART_INFO:
|
---|
[e89a06a] | 583 | vol_part_info_srv(parts, &call);
|
---|
[22fb7ab] | 584 | break;
|
---|
[72c72d4] | 585 | case VOL_PART_EJECT:
|
---|
[e89a06a] | 586 | vol_part_eject_srv(parts, &call);
|
---|
[72c72d4] | 587 | break;
|
---|
[372df8f] | 588 | case VOL_PART_EMPTY:
|
---|
[e89a06a] | 589 | vol_part_empty_srv(parts, &call);
|
---|
[22fb7ab] | 590 | break;
|
---|
[f0f8787] | 591 | case VOL_PART_INSERT:
|
---|
| 592 | vol_part_insert_srv(parts, &call);
|
---|
| 593 | break;
|
---|
[b82985e] | 594 | case VOL_PART_INSERT_BY_PATH:
|
---|
| 595 | vol_part_insert_by_path_srv(parts, &call);
|
---|
| 596 | break;
|
---|
[9c2c7d2] | 597 | case VOL_PART_LSUPP:
|
---|
[e89a06a] | 598 | vol_part_get_lsupp_srv(parts, &call);
|
---|
[9c2c7d2] | 599 | break;
|
---|
[44fe800] | 600 | case VOL_PART_MKFS:
|
---|
[e89a06a] | 601 | vol_part_mkfs_srv(parts, &call);
|
---|
[44fe800] | 602 | break;
|
---|
[2d78d88] | 603 | case VOL_PART_SET_MOUNTP:
|
---|
| 604 | vol_part_set_mountp_srv(parts, &call);
|
---|
| 605 | break;
|
---|
[63c1dd5] | 606 | case VOL_GET_VOLUMES:
|
---|
| 607 | vol_get_volumes_srv(parts, &call);
|
---|
| 608 | break;
|
---|
| 609 | case VOL_INFO:
|
---|
| 610 | vol_info_srv(parts, &call);
|
---|
| 611 | break;
|
---|
[1356f85a] | 612 | default:
|
---|
[984a9ba] | 613 | async_answer_0(&call, EINVAL);
|
---|
[1356f85a] | 614 | }
|
---|
| 615 | }
|
---|
| 616 | }
|
---|
| 617 |
|
---|
| 618 | int main(int argc, char *argv[])
|
---|
| 619 | {
|
---|
[b7fd2a0] | 620 | errno_t rc;
|
---|
[1356f85a] | 621 |
|
---|
| 622 | printf("%s: Volume service\n", NAME);
|
---|
| 623 |
|
---|
| 624 | if (log_init(NAME) != EOK) {
|
---|
| 625 | printf(NAME ": Failed to initialize logging.\n");
|
---|
| 626 | return 1;
|
---|
| 627 | }
|
---|
| 628 |
|
---|
| 629 | rc = vol_init();
|
---|
| 630 | if (rc != EOK)
|
---|
| 631 | return 1;
|
---|
| 632 |
|
---|
| 633 | printf(NAME ": Accepting connections.\n");
|
---|
| 634 | task_retval(0);
|
---|
| 635 | async_manager();
|
---|
| 636 |
|
---|
| 637 | return 0;
|
---|
| 638 | }
|
---|
| 639 |
|
---|
| 640 | /** @}
|
---|
| 641 | */
|
---|