- Timestamp:
- 2018-06-29T13:22:39Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 72c72d4
- Parents:
- 5f36841
- git-author:
- Jiri Svoboda <jiri@…> (2018-06-28 17:22:13)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-06-29 13:22:39)
- Location:
- uspace
- Files:
-
- 4 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/Makefile
r5f36841 rdb9c889 79 79 app/untar \ 80 80 app/usbinfo \ 81 app/vol \ 81 82 app/vuhid \ 82 83 app/nic \ -
uspace/app/fdisk/fdisk.c
r5f36841 rdb9c889 37 37 #include <cap.h> 38 38 #include <errno.h> 39 #include <fdisk.h> 40 #include <io/label.h> 39 41 #include <nchoice.h> 40 42 #include <stdbool.h> 41 43 #include <stdio.h> 42 44 #include <stdlib.h> 43 #include <fdisk.h>44 45 #include <str.h> 46 #include <vol.h> 45 47 46 48 #define NO_LABEL_CAPTION "(No name)" … … 69 71 } devac_t; 70 72 71 static errno_t fdsk_pcnt_fs_format(vol_part_cnt_t pcnt, vol_fstype_t fstype,72 char **rstr)73 {74 errno_t rc;75 char *s;76 77 switch (pcnt) {78 case vpc_empty:79 s = str_dup("Empty");80 if (s == NULL)81 return ENOMEM;82 break;83 case vpc_fs:84 rc = fdisk_fstype_format(fstype, &s);85 if (rc != EOK)86 return ENOMEM;87 break;88 case vpc_unknown:89 s = str_dup("Unknown");90 if (s == NULL)91 return ENOMEM;92 break;93 }94 95 *rstr = s;96 return EOK;97 }98 99 73 /** Confirm user selection. */ 100 74 static errno_t fdsk_confirm(const char *msg, bool *rconfirm) … … 305 279 306 280 for (i = LT_FIRST; i < LT_LIMIT; i++) { 307 rc = fdisk_ltype_format(i, &sltype);281 rc = label_type_format(i, &sltype); 308 282 if (rc != EOK) 309 283 goto error; … … 413 387 414 388 for (i = 0; i < VOL_FSTYPE_LIMIT; i++) { 415 rc = fdisk_fstype_format(i, &sfstype);389 rc = vol_fstype_format(i, &sfstype); 416 390 if (rc != EOK) 417 391 goto error; … … 598 572 } 599 573 600 rc = fdisk_pkind_format(pinfo.pkind, &spkind);574 rc = label_pkind_format(pinfo.pkind, &spkind); 601 575 if (rc != EOK) { 602 576 printf("\nOut of memory.\n"); … … 605 579 606 580 if (pinfo.pkind != lpk_extended) { 607 rc = fdsk_pcnt_fs_format(pinfo.pcnt, pinfo.fstype, &sfstype);581 rc = vol_pcnt_fs_format(pinfo.pcnt, pinfo.fstype, &sfstype); 608 582 if (rc != EOK) { 609 583 printf("Out of memory.\n"); … … 773 747 break; 774 748 default: 775 rc = fdisk_ltype_format(linfo.ltype, &sltype);749 rc = label_type_format(linfo.ltype, &sltype); 776 750 if (rc != EOK) { 777 751 assert(rc == ENOMEM); … … 804 778 } 805 779 806 rc = fdsk_pcnt_fs_format(pinfo.pcnt, pinfo.fstype, &sfstype);780 rc = vol_pcnt_fs_format(pinfo.pcnt, pinfo.fstype, &sfstype); 807 781 if (rc != EOK) { 808 782 printf("Out of memory.\n"); … … 821 795 822 796 if ((linfo.flags & lf_ext_supp) != 0) { 823 rc = fdisk_pkind_format(pinfo.pkind, &spkind);797 rc = label_pkind_format(pinfo.pkind, &spkind); 824 798 if (rc != EOK) { 825 799 printf("\nOut of memory.\n"); -
uspace/lib/c/Makefile
r5f36841 rdb9c889 112 112 generic/io/log.c \ 113 113 generic/io/logctl.c \ 114 generic/io/label.c \ 114 115 generic/io/kio.c \ 115 116 generic/io/klog.c \ -
uspace/lib/c/generic/vol.c
r5f36841 rdb9c889 304 304 } 305 305 306 /** Format file system type as string. 307 * 308 * @param fstype File system type 309 * @param rstr Place to store pointer to newly allocated string 310 * @return EOK on success, ENOMEM if out of memory 311 */ 312 errno_t vol_fstype_format(vol_fstype_t fstype, char **rstr) 313 { 314 const char *sfstype; 315 char *s; 316 317 sfstype = NULL; 318 switch (fstype) { 319 case fs_exfat: 320 sfstype = "ExFAT"; 321 break; 322 case fs_fat: 323 sfstype = "FAT"; 324 break; 325 case fs_minix: 326 sfstype = "MINIX"; 327 break; 328 case fs_ext4: 329 sfstype = "Ext4"; 330 break; 331 case fs_cdfs: 332 sfstype = "ISO 9660"; 333 break; 334 } 335 336 s = str_dup(sfstype); 337 if (s == NULL) 338 return ENOMEM; 339 340 *rstr = s; 341 return EOK; 342 } 343 344 /** Format partition content / file system type as string. 345 * 346 * @param pcnt Partition content 347 * @param fstype File system type 348 * @param rstr Place to store pointer to newly allocated string 349 * @return EOK on success, ENOMEM if out of memory 350 */ 351 errno_t vol_pcnt_fs_format(vol_part_cnt_t pcnt, vol_fstype_t fstype, 352 char **rstr) 353 { 354 int rc; 355 char *s = NULL; 356 357 switch (pcnt) { 358 case vpc_empty: 359 s = str_dup("Empty"); 360 if (s == NULL) 361 return ENOMEM; 362 break; 363 case vpc_fs: 364 rc = vol_fstype_format(fstype, &s); 365 if (rc != EOK) 366 return ENOMEM; 367 break; 368 case vpc_unknown: 369 s = str_dup("Unknown"); 370 if (s == NULL) 371 return ENOMEM; 372 break; 373 } 374 375 assert(s != NULL); 376 *rstr = s; 377 return EOK; 378 } 379 306 380 /** @} 307 381 */ -
uspace/lib/c/include/types/vol.h
r5f36841 rdb9c889 37 37 38 38 #include <async.h> 39 #include <ipc/vfs.h> 39 40 #include <ipc/vol.h> 40 41 #include <stdbool.h> … … 75 76 /** Volume label */ 76 77 char label[VOL_LABEL_MAXLEN + 1]; 78 /** Current mount point */ 79 char cur_mp[MAX_PATH_LEN + 1]; /* XXX too big */ 80 /** Current mount point is automatic */ 81 bool cur_mp_auto; 77 82 } vol_part_info_t; 78 83 -
uspace/lib/c/include/vol.h
r5f36841 rdb9c889 37 37 38 38 #include <async.h> 39 #include <errno.h> 39 40 #include <loc.h> 40 41 #include <stdint.h> … … 47 48 extern errno_t vol_part_add(vol_t *, service_id_t); 48 49 extern errno_t vol_part_info(vol_t *, service_id_t, vol_part_info_t *); 50 extern errno_t vol_part_eject(vol_t *, service_id_t); 49 51 extern errno_t vol_part_empty(vol_t *, service_id_t); 50 52 extern errno_t vol_part_get_lsupp(vol_t *, vol_fstype_t, vol_label_supp_t *); 51 53 extern errno_t vol_part_mkfs(vol_t *, service_id_t, vol_fstype_t, const char *); 54 55 extern errno_t vol_fstype_format(vol_fstype_t, char **); 56 extern errno_t vol_pcnt_fs_format(vol_part_cnt_t, vol_fstype_t, char **); 52 57 53 58 #endif -
uspace/lib/fdisk/include/fdisk.h
r5f36841 rdb9c889 37 37 #define LIBFDISK_FDISK_H_ 38 38 39 #include <errno.h> 39 40 #include <loc.h> 40 41 #include <types/fdisk.h> … … 72 73 extern void fdisk_pspec_init(fdisk_part_spec_t *); 73 74 74 extern errno_t fdisk_ltype_format(label_type_t, char **);75 extern errno_t fdisk_fstype_format(vol_fstype_t, char **);76 extern errno_t fdisk_pkind_format(label_pkind_t, char **);77 78 75 extern errno_t fdisk_get_vollabel_support(fdisk_dev_t *, vol_fstype_t, 79 76 vol_label_supp_t *); -
uspace/lib/fdisk/src/fdisk.c
r5f36841 rdb9c889 813 813 } 814 814 815 errno_t fdisk_ltype_format(label_type_t ltype, char **rstr)816 {817 const char *sltype;818 char *s;819 820 sltype = NULL;821 switch (ltype) {822 case lt_none:823 sltype = "None";824 break;825 case lt_mbr:826 sltype = "MBR";827 break;828 case lt_gpt:829 sltype = "GPT";830 break;831 }832 833 s = str_dup(sltype);834 if (s == NULL)835 return ENOMEM;836 837 *rstr = s;838 return EOK;839 }840 841 errno_t fdisk_fstype_format(vol_fstype_t fstype, char **rstr)842 {843 const char *sfstype;844 char *s;845 846 sfstype = NULL;847 switch (fstype) {848 case fs_exfat:849 sfstype = "ExFAT";850 break;851 case fs_fat:852 sfstype = "FAT";853 break;854 case fs_minix:855 sfstype = "MINIX";856 break;857 case fs_ext4:858 sfstype = "Ext4";859 break;860 case fs_cdfs:861 sfstype = "ISO 9660";862 break;863 }864 865 s = str_dup(sfstype);866 if (s == NULL)867 return ENOMEM;868 869 *rstr = s;870 return EOK;871 }872 873 errno_t fdisk_pkind_format(label_pkind_t pkind, char **rstr)874 {875 const char *spkind;876 char *s;877 878 spkind = NULL;879 switch (pkind) {880 case lpk_primary:881 spkind = "Primary";882 break;883 case lpk_extended:884 spkind = "Extended";885 break;886 case lpk_logical:887 spkind = "Logical";888 break;889 }890 891 s = str_dup(spkind);892 if (s == NULL)893 return ENOMEM;894 895 *rstr = s;896 return EOK;897 }898 899 815 /** Get free partition index. */ 900 816 static errno_t fdisk_part_get_free_idx(fdisk_dev_t *dev, int *rindex) -
uspace/srv/volsrv/part.c
r5f36841 rdb9c889 155 155 return; 156 156 157 free(part->cur_mp); 157 158 free(part->svc_name); 158 159 free(part); … … 219 220 } 220 221 221 static int vol_part_mount(vol_part_t *part)222 static errno_t vol_part_mount(vol_part_t *part) 222 223 { 223 224 char *mp; 224 int rc; 225 int err; 226 errno_t rc; 225 227 226 228 if (str_size(part->label) < 1) { … … 231 233 232 234 log_msg(LOG_DEFAULT, LVL_NOTE, "Determine MP label='%s'", part->label); 233 rc= asprintf(&mp, "/vol/%s", part->label);234 if ( rc< 0) {235 log_msg(LOG_DEFAULT, LVL_ NOTE, "rc -> %d", rc);235 err = asprintf(&mp, "/vol/%s", part->label); 236 if (err < 0) { 237 log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory"); 236 238 return ENOMEM; 237 239 } … … 255 257 log_msg(LOG_DEFAULT, LVL_NOTE, "Mount to %s -> %d\n", mp, rc); 256 258 257 free(mp); 259 part->cur_mp = mp; 260 part->cur_mp_auto = true; 261 258 262 return rc; 259 263 } … … 381 385 382 386 return ENOENT; 387 } 388 389 errno_t vol_part_eject_part(vol_part_t *part) 390 { 391 int rc; 392 393 log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_part_eject_part()"); 394 395 if (part->cur_mp == NULL) { 396 log_msg(LOG_DEFAULT, LVL_DEBUG, "Attempt to mount unmounted " 397 "partition."); 398 return EINVAL; 399 } 400 401 rc = vfs_unmount_path(part->cur_mp); 402 if (rc != EOK) { 403 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed unmounting partition " 404 "from %s", part->cur_mp); 405 return rc; 406 } 407 408 if (part->cur_mp_auto) { 409 rc = vfs_unlink_path(part->cur_mp); 410 if (rc != EOK) { 411 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed deleting " 412 "mount directory %s.", part->cur_mp); 413 } 414 } 415 416 free(part->cur_mp); 417 part->cur_mp = NULL; 418 part->cur_mp_auto = false; 419 420 return EOK; 383 421 } 384 422 … … 443 481 pinfo->fstype = part->fstype; 444 482 str_cpy(pinfo->label, sizeof(pinfo->label), part->label); 483 str_cpy(pinfo->cur_mp, sizeof(pinfo->cur_mp), part->cur_mp); 484 pinfo->cur_mp_auto = part->cur_mp_auto; 445 485 return EOK; 446 486 } -
uspace/srv/volsrv/part.h
r5f36841 rdb9c889 48 48 extern errno_t vol_part_get_ids(service_id_t *, size_t, size_t *); 49 49 extern errno_t vol_part_find_by_id(service_id_t, vol_part_t **); 50 extern errno_t vol_part_eject_part(vol_part_t *); 50 51 extern errno_t vol_part_empty_part(vol_part_t *); 51 52 extern errno_t vol_part_mkfs_part(vol_part_t *, vol_fstype_t, const char *); -
uspace/srv/volsrv/types/part.h
r5f36841 rdb9c889 39 39 40 40 #include <adt/list.h> 41 #include <stdbool.h> 41 42 #include <types/label.h> 42 43 … … 55 56 /** Volume label */ 56 57 char *label; 58 /** Where volume is currently mounted */ 59 char *cur_mp; 60 /** Mounted at automatic mount point */ 61 bool cur_mp_auto; 57 62 } vol_part_t; 58 63
Note:
See TracChangeset
for help on using the changeset viewer.