Changeset 64ffd83 in mainline
- Timestamp:
- 2018-07-24T09:43:38Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bec18a9
- Parents:
- 05208d9
- git-author:
- Jiri Svoboda <jiri@…> (2018-07-23 18:41:45)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-07-24 09:43:38)
- Files:
-
- 5 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
.gitignore
r05208d9 r64ffd83 427 427 uspace/srv/test/chardev-test/chardev-test 428 428 uspace/srv/vfs/vfs 429 uspace/srv/volsrv/test-volsrv 429 430 uspace/srv/volsrv/volsrv -
boot/Makefile.common
r05208d9 r64ffd83 243 243 $(USPACE_PATH)/drv/bus/usb/xhci/test-xhci \ 244 244 $(USPACE_PATH)/app/bdsh/test-bdsh \ 245 $(USPACE_PATH)/srv/net/tcp/test-tcp 245 $(USPACE_PATH)/srv/net/tcp/test-tcp \ 246 $(USPACE_PATH)/srv/volsrv/test-volsrv \ 246 247 247 248 RD_DATA_ESSENTIAL = \ -
uspace/app/fdisk/fdisk.c
r05208d9 r64ffd83 1 1 /* 2 * Copyright (c) 201 5Jiri Svoboda2 * Copyright (c) 2018 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 432 432 char *smcap = NULL; 433 433 char *label = NULL; 434 char *mountp = NULL; 434 435 435 436 if (pkind == lpk_logical) … … 506 507 } 507 508 509 /* Ask for mount point */ 510 tinput = tinput_new(); 511 if (tinput == NULL) { 512 rc = ENOMEM; 513 goto error; 514 } 515 516 rc = tinput_set_prompt(tinput, "?> "); 517 if (rc != EOK) 518 goto error; 519 520 while (true) { 521 printf("Enter mount point for new partition (Auto, None or /path).\n"); 522 rc = tinput_read_i(tinput, "Auto", &mountp); 523 if (rc != EOK) 524 goto error; 525 526 rc = vol_mountp_validate(mountp); 527 if (rc == EOK) 528 break; 529 530 free(mountp); 531 mountp = NULL; 532 } 533 534 tinput_destroy(tinput); 535 tinput = NULL; 536 508 537 fdisk_pspec_init(&pspec); 509 538 pspec.capacity = cap; … … 511 540 pspec.fstype = fstype; 512 541 pspec.label = label; 542 pspec.mountp = mountp; 513 543 514 544 rc = fdisk_part_create(dev, &pspec, NULL); … … 519 549 520 550 free(label); 551 free(mountp); 521 552 return EOK; 522 553 error: 523 554 free(smcap); 524 555 free(label); 556 free(mountp); 525 557 if (tinput != NULL) 526 558 tinput_destroy(tinput); -
uspace/app/sysinst/sysinst.c
r05208d9 r64ffd83 132 132 pspec.pkind = lpk_primary; 133 133 pspec.fstype = fs_minix; 134 pspec.mountp = ""; 134 135 135 136 rc = fdisk_part_create(fdev, &pspec, &part); -
uspace/lib/c/generic/vol.c
r05208d9 r64ffd83 40 40 #include <stdlib.h> 41 41 #include <str.h> 42 #include <vfs/vfs.h> 42 43 #include <vol.h> 43 44 … … 220 221 exch = async_exchange_begin(vol->sess); 221 222 aid_t req = async_send_1(exch, VOL_PART_INFO, sid, &answer); 223 222 224 errno_t rc = async_data_read_start(exch, vinfo, sizeof(vol_part_info_t)); 223 225 async_exchange_end(exch); 224 225 226 if (rc != EOK) { 226 227 async_forget(req); … … 294 295 } 295 296 296 /** Create file system. */ 297 /** Create file system. 298 * 299 * @param vol Volume service 300 * @param sid Partition service ID 301 * @param fstype File system type 302 * @param label Volume label 303 * @param mountp Mount point 304 * 305 * @return EOK on success or an error code 306 */ 297 307 errno_t vol_part_mkfs(vol_t *vol, service_id_t sid, vol_fstype_t fstype, 298 const char *label )308 const char *label, const char *mountp) 299 309 { 300 310 async_exch_t *exch; … … 304 314 exch = async_exchange_begin(vol->sess); 305 315 aid_t req = async_send_2(exch, VOL_PART_MKFS, sid, fstype, &answer); 316 306 317 retval = async_data_write_start(exch, label, str_size(label)); 307 async_exchange_end(exch);308 309 318 if (retval != EOK) { 319 async_exchange_end(exch); 310 320 async_forget(req); 311 321 return retval; 312 322 } 313 323 324 retval = async_data_write_start(exch, mountp, str_size(mountp)); 325 if (retval != EOK) { 326 async_exchange_end(exch); 327 async_forget(req); 328 return retval; 329 } 330 331 async_exchange_end(exch); 314 332 async_wait_for(req, &retval); 315 333 … … 394 412 } 395 413 414 /** Validate mount point. 415 * 416 * Verify that mount point is valid. A valid mount point is 417 * one of: 418 * - 'Auto' 419 * - 'None' 420 * - /path (string beginning with '/') to an existing directory 421 * 422 * @return EOK if mount point is in valid, EINVAL if the format is invalid, 423 * ENOENT if the directory does not exist 424 */ 425 errno_t vol_mountp_validate(const char *mountp) 426 { 427 errno_t rc; 428 vfs_stat_t stat; 429 430 if (str_cmp(mountp, "Auto") == 0 || str_cmp(mountp, "auto") == 0) 431 return EOK; 432 433 if (str_casecmp(mountp, "None") == 0 || str_cmp(mountp, "none") == 0) 434 return EOK; 435 436 if (mountp[0] == '/') { 437 rc = vfs_stat_path(mountp, &stat); 438 if (rc != EOK || !stat.is_directory) 439 return ENOENT; 440 441 return EOK; 442 } 443 444 return EINVAL; 445 } 446 396 447 /** @} 397 448 */ -
uspace/lib/c/include/ipc/vol.h
r05208d9 r64ffd83 37 37 38 38 #define VOL_LABEL_MAXLEN 63 39 #define VOL_MOUNTP_MAXLEN 4096 39 40 40 41 typedef enum { -
uspace/lib/c/include/vol.h
r05208d9 r64ffd83 51 51 extern errno_t vol_part_empty(vol_t *, service_id_t); 52 52 extern errno_t vol_part_get_lsupp(vol_t *, vol_fstype_t, vol_label_supp_t *); 53 extern errno_t vol_part_mkfs(vol_t *, service_id_t, vol_fstype_t, const char *); 53 extern errno_t vol_part_mkfs(vol_t *, service_id_t, vol_fstype_t, const char *, 54 const char *); 54 55 55 56 extern errno_t vol_fstype_format(vol_fstype_t, char **); 56 57 extern errno_t vol_pcnt_fs_format(vol_part_cnt_t, vol_fstype_t, char **); 58 extern errno_t vol_mountp_validate(const char *); 57 59 58 60 #endif -
uspace/lib/fdisk/include/types/fdisk.h
r05208d9 r64ffd83 156 156 vol_fstype_t fstype; 157 157 /** Volume label */ 158 char *label; 158 const char *label; 159 /** Mount point */ 160 const char *mountp; 159 161 } fdisk_part_spec_t; 160 162 -
uspace/lib/fdisk/src/fdisk.c
r05208d9 r64ffd83 729 729 } 730 730 731 /** Create partition. 732 * 733 * Create new partition based on a specification. 734 * 735 * @param dev Fdisk device 736 * @param pspec Partition specification 737 * @param rpart Place to store pointer to new partition 738 * 739 * @return EOK on success or error code 740 */ 731 741 errno_t fdisk_part_create(fdisk_dev_t *dev, fdisk_part_spec_t *pspec, 732 742 fdisk_part_t **rpart) … … 737 747 vol_part_info_t vpinfo; 738 748 const char *label; 749 const char *mountp; 739 750 errno_t rc; 740 751 741 752 label = pspec->label != NULL ? pspec->label : ""; 753 mountp = pspec->mountp != NULL ? pspec->mountp : ""; 742 754 743 755 rc = fdisk_part_spec_prepare(dev, pspec, &vpspec); … … 761 773 if (part->svc_id != 0) { 762 774 rc = vol_part_mkfs(dev->fdisk->vol, part->svc_id, pspec->fstype, 763 label );775 label, mountp); 764 776 if (rc != EOK && rc != ENOTSUP) { 765 777 rc = EIO; -
uspace/srv/volsrv/Makefile
r05208d9 r64ffd83 37 37 mkfs.c \ 38 38 part.c \ 39 volsrv.c 39 volsrv.c \ 40 volume.c 41 42 TEST_SOURCES = \ 43 volume.c \ 44 test/main.c \ 45 test/volume.c 40 46 41 47 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/volsrv/part.c
r05208d9 r64ffd83 45 45 #include <str_error.h> 46 46 #include <vfs/vfs.h> 47 #include <vol.h> 47 48 48 49 #include "empty.h" … … 50 51 #include "part.h" 51 52 #include "types/part.h" 53 #include "volume.h" 52 54 53 55 static errno_t vol_part_add_locked(vol_parts_t *, service_id_t); … … 191 193 return; 192 194 195 if (part->volume != NULL) 196 vol_volume_del_ref(part->volume); 197 193 198 free(part->cur_mp); 194 199 free(part->svc_name); … … 202 207 struct fsname_type *fst; 203 208 char *label; 209 vol_volume_t *volume; 204 210 errno_t rc; 205 211 … … 250 256 } 251 257 258 /* Look up new or existing volume. */ 259 rc = vol_volume_lookup_ref(part->parts->volumes, part->label, &volume); 260 if (rc != EOK) 261 goto error; 262 263 part->volume = volume; 252 264 return EOK; 253 265 … … 275 287 } 276 288 289 /** Determine the default mount point for a partition. 290 * 291 * @param part Partition 292 * @return Pointer to the constant string "Auto" or "None" 293 */ 294 static const char *vol_part_def_mountp(vol_part_t *part) 295 { 296 return vol_part_allow_mount_by_def(part) ? "Auto" : "None"; 297 } 298 299 /** Mount partition. 300 * 301 * @param part Partition 302 */ 277 303 static errno_t vol_part_mount(vol_part_t *part) 278 304 { 305 const char *cfg_mp; 279 306 char *mp; 280 307 int err; 281 errno_t rc; 282 283 if (str_size(part->label) < 1) { 284 /* Don't mount nameless volumes */ 285 log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting nameless partition."); 308 bool mp_auto; 309 errno_t rc; 310 311 /* Get configured mount point */ 312 if (str_size(part->volume->mountp) > 0) { 313 cfg_mp = part->volume->mountp; 314 log_msg(LOG_DEFAULT, LVL_NOTE, "Configured mount point '%s", 315 cfg_mp); 316 } else { 317 cfg_mp = vol_part_def_mountp(part); 318 log_msg(LOG_DEFAULT, LVL_NOTE, "Default mount point '%s", 319 cfg_mp); 320 } 321 322 if (str_cmp(cfg_mp, "Auto") == 0 || str_cmp(cfg_mp, "auto") == 0) { 323 324 if (str_size(part->label) < 1) { 325 /* Don't mount nameless volumes */ 326 log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting nameless volume."); 327 return EOK; 328 } 329 330 log_msg(LOG_DEFAULT, LVL_NOTE, "Determine MP label='%s'", part->label); 331 err = asprintf(&mp, "/vol/%s", part->label); 332 if (err < 0) { 333 log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory"); 334 return ENOMEM; 335 } 336 337 log_msg(LOG_DEFAULT, LVL_NOTE, "Create mount point '%s'", mp); 338 rc = vfs_link_path(mp, KIND_DIRECTORY, NULL); 339 if (rc != EOK) { 340 log_msg(LOG_DEFAULT, LVL_ERROR, "Error creating mount point '%s'", 341 mp); 342 free(mp); 343 return EIO; 344 } 345 346 mp_auto = true; 347 } else if (str_cmp(cfg_mp, "None") == 0 || str_cmp(cfg_mp, "none") == 0) { 348 log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting volume."); 286 349 return EOK; 287 } 288 289 if (!vol_part_allow_mount_by_def(part)) { 290 /* Don't mount partition by default */ 291 log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting per default policy."); 292 return EOK; 293 } 294 295 log_msg(LOG_DEFAULT, LVL_NOTE, "Determine MP label='%s'", part->label); 296 err = asprintf(&mp, "/vol/%s", part->label); 297 if (err < 0) { 298 log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory"); 299 return ENOMEM; 300 } 301 302 log_msg(LOG_DEFAULT, LVL_NOTE, "Create mount point '%s'", mp); 303 rc = vfs_link_path(mp, KIND_DIRECTORY, NULL); 304 if (rc != EOK) { 305 log_msg(LOG_DEFAULT, LVL_ERROR, "Error creating mount point '%s'", 306 mp); 307 free(mp); 308 return EIO; 350 } else { 351 mp = str_dup(cfg_mp); 352 mp_auto = false; 309 353 } 310 354 … … 319 363 320 364 part->cur_mp = mp; 321 part->cur_mp_auto = true;365 part->cur_mp_auto = mp_auto; 322 366 323 367 return rc; … … 385 429 } 386 430 387 errno_t vol_part_add (vol_parts_t *parts, service_id_t sid)431 errno_t vol_part_add_part(vol_parts_t *parts, service_id_t sid) 388 432 { 389 433 errno_t rc; … … 403 447 } 404 448 405 errno_t vol_parts_create(vol_ parts_t **rparts)449 errno_t vol_parts_create(vol_volumes_t *volumes, vol_parts_t **rparts) 406 450 { 407 451 vol_parts_t *parts; … … 413 457 fibril_mutex_initialize(&parts->lock); 414 458 list_initialize(&parts->parts); 459 parts->volumes = volumes; 415 460 416 461 *rparts = parts; … … 557 602 } 558 603 604 /** Set mount point. 605 * 606 * Verify and set a mount point. If the value of the mount point is 607 * the same as the default value, we will actually unset the mount point 608 * value (therefore effectively changing it to use the default). 609 * 610 * @return EOK on success, error code otherwise 611 */ 612 static errno_t vol_part_mountp_set(vol_part_t *part, const char *mountp) 613 { 614 errno_t rc; 615 const char *def_mp; 616 const char *mp; 617 618 rc = vol_mountp_validate(mountp); 619 if (rc != EOK) 620 return rc; 621 622 def_mp = vol_part_def_mountp(part); 623 624 /* If the value is the same as default, set to empty string. */ 625 if (str_cmp(def_mp, mountp) == 0) 626 mp = ""; 627 else 628 mp = mountp; 629 630 rc = vol_volume_set_mountp(part->volume, mp); 631 if (rc != EOK) 632 return rc; 633 634 return EOK; 635 } 636 559 637 errno_t vol_part_mkfs_part(vol_part_t *part, vol_fstype_t fstype, 560 const char *label )638 const char *label, const char *mountp) 561 639 { 562 640 errno_t rc; … … 585 663 } 586 664 665 rc = vol_part_mountp_set(part, mountp); 666 if (rc != EOK) { 667 fibril_mutex_unlock(&part->parts->lock); 668 return rc; 669 } 670 587 671 rc = vol_part_mount(part); 588 672 if (rc != EOK) { -
uspace/srv/volsrv/part.h
r05208d9 r64ffd83 42 42 #include <types/vol.h> 43 43 #include "types/part.h" 44 #include "types/volume.h" 44 45 45 extern errno_t vol_parts_create(vol_ parts_t **);46 extern errno_t vol_parts_create(vol_volumes_t *, vol_parts_t **); 46 47 extern void vol_parts_destroy(vol_parts_t *); 47 48 extern errno_t vol_part_discovery_start(vol_parts_t *); 48 extern errno_t vol_part_add (vol_parts_t *, service_id_t);49 extern errno_t vol_part_add_part(vol_parts_t *, service_id_t); 49 50 extern errno_t vol_part_get_ids(vol_parts_t *, service_id_t *, size_t, 50 51 size_t *); … … 54 55 extern errno_t vol_part_eject_part(vol_part_t *); 55 56 extern errno_t vol_part_empty_part(vol_part_t *); 56 extern errno_t vol_part_mkfs_part(vol_part_t *, vol_fstype_t, const char *); 57 extern errno_t vol_part_mkfs_part(vol_part_t *, vol_fstype_t, const char *, 58 const char *); 57 59 extern errno_t vol_part_get_info(vol_part_t *, vol_part_info_t *); 58 60 -
uspace/srv/volsrv/types/part.h
r05208d9 r64ffd83 66 66 /** Mounted at automatic mount point */ 67 67 bool cur_mp_auto; 68 /** Volume */ 69 struct vol_volume *volume; 68 70 } vol_part_t; 69 71 … … 74 76 /** Partitions (list of vol_part_t) */ 75 77 list_t parts; 78 /** Underlying volumes */ 79 struct vol_volumes *volumes; 76 80 } vol_parts_t; 77 81 -
uspace/srv/volsrv/volsrv.c
r05208d9 r64ffd83 49 49 #include "mkfs.h" 50 50 #include "part.h" 51 #include "volume.h" 51 52 52 53 #define NAME "volsrv" … … 57 58 { 58 59 errno_t rc; 60 vol_volumes_t *volumes = NULL; 59 61 vol_parts_t *parts = NULL; 60 62 61 63 log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_init()"); 62 64 63 rc = vol_parts_create(&parts); 65 rc = vol_volumes_create(&volumes); 66 if (rc != EOK) 67 goto error; 68 69 rc = vol_parts_create(volumes, &parts); 64 70 if (rc != EOK) 65 71 goto error; … … 87 93 return EOK; 88 94 error: 95 vol_volumes_destroy(volumes); 89 96 vol_parts_destroy(parts); 90 97 return rc; … … 131 138 sid = IPC_GET_ARG1(*icall); 132 139 133 rc = vol_part_add (parts, sid);140 rc = vol_part_add_part(parts, sid); 134 141 if (rc != EOK) { 135 142 async_answer_0(icall, rc); … … 285 292 vol_fstype_t fstype; 286 293 char *label; 294 char *mountp; 287 295 errno_t rc; 288 296 … … 304 312 } 305 313 314 rc = async_data_write_accept((void **)&mountp, true, 0, VOL_MOUNTP_MAXLEN, 315 0, NULL); 316 if (rc != EOK) { 317 free(label); 318 async_answer_0(icall, rc); 319 return; 320 } 321 322 if (mountp != NULL) { 323 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_mkfs_srv: mountp='%s'", 324 mountp); 325 } 326 306 327 rc = vol_part_find_by_id_ref(parts, sid, &part); 307 328 if (rc != EOK) { … … 311 332 } 312 333 313 rc = vol_part_mkfs_part(part, fstype, label );334 rc = vol_part_mkfs_part(part, fstype, label, mountp); 314 335 if (rc != EOK) { 315 336 free(label);
Note:
See TracChangeset
for help on using the changeset viewer.