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