Changeset 5df2570 in mainline
- Timestamp:
- 2026-04-14T21:44:17Z (5 weeks ago)
- Branches:
- master, topic/fix-logger-deadlock
- Children:
- 3272be1, e2b47b3c
- Parents:
- 417cc85
- Location:
- uspace
- Files:
-
- 15 edited
-
app/sysinst/meson.build (modified) (2 diffs)
-
app/sysinst/sysinst.c (modified) (22 diffs)
-
app/sysinst/sysinst.h (modified) (3 diffs)
-
lib/fmgt/include/types/fmgt.h (modified) (2 diffs)
-
lib/fmgt/private/fmgt.h (modified) (1 diff)
-
lib/fmgt/src/copy.c (modified) (2 diffs)
-
lib/fmgt/src/delete.c (modified) (2 diffs)
-
lib/fmgt/src/fmgt.c (modified) (1 diff)
-
lib/fmgt/src/move.c (modified) (2 diffs)
-
lib/fmgt/src/newdir.c (modified) (1 diff)
-
lib/fmgt/src/newfile.c (modified) (1 diff)
-
lib/fmgt/src/rename.c (modified) (1 diff)
-
lib/fmgt/src/verify.c (modified) (1 diff)
-
lib/futil/include/futil.h (modified) (2 diffs)
-
lib/futil/src/futil.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sysinst/meson.build
r417cc85 r5df2570 1 1 # 2 # Copyright (c) 202 5Jiri Svoboda2 # Copyright (c) 2026 Jiri Svoboda 3 3 # All rights reserved. 4 4 # … … 27 27 # 28 28 29 deps = [ 'block', 'fdisk', 'f util', 'sif', 'system', 'ui' ]29 deps = [ 'block', 'fdisk', 'fmgt', 'sif', 'system', 'ui' ] 30 30 src = files( 31 31 'rdimg.c', -
uspace/app/sysinst/sysinst.c
r417cc85 r5df2570 41 41 #include <errno.h> 42 42 #include <fdisk.h> 43 #include <f util.h>43 #include <fmgt.h> 44 44 #include <gfx/render.h> 45 45 #include <io/log.h> … … 91 91 #define CD_MOUNT_POINT "/vol/" CD_VOL_LABEL 92 92 93 #define BOOT_FILES_SRC CD_MOUNT_POINT 93 #define BOOT_FILES_SRC CD_MOUNT_POINT "/boot" 94 94 #define BOOT_BLOCK_IDX 0 /* MBR */ 95 95 96 96 #define CFG_FILES_SRC "/cfg" 97 #define CFG_FILES_DEST MOUNT_POINT "/cfg"97 #define CFG_FILES_DEST MOUNT_POINT 98 98 99 99 static const char *default_devs[] = { … … 163 163 static errno_t sysinst_restart(sysinst_t *); 164 164 static void sysinst_progress_destroy(sysinst_progress_t *); 165 static void sysinst_progress(sysinst_t *, const char *); 165 166 static void sysinst_action(sysinst_t *, const char *); 166 167 static void sysinst_error(sysinst_t *, const char *); 167 168 static void sysinst_debug(sysinst_t *, const char *); 168 169 169 static void sysinst_futil_copy_file(void *, const char *, const char *); 170 static void sysinst_futil_create_dir(void *, const char *); 170 static fmgt_exists_action_t sysinst_fmgt_exists_query(void *, fmgt_exists_t *); 171 static void sysinst_fmgt_action(void *, fmgt_action_t, const char *, 172 const char *); 173 static void sysinst_fmgt_progress(void *, fmgt_progress_t *); 171 174 static errno_t sysinst_eject_dev(sysinst_t *, service_id_t); 172 175 static errno_t sysinst_eject_phys_by_mp(sysinst_t *, const char *); 173 176 static errno_t sysinst_upgrade_confirm_create(sysinst_t *); 174 177 175 static futil_cb_t sysinst_futil_cb = { 176 .copy_file = sysinst_futil_copy_file, 177 .create_dir = sysinst_futil_create_dir 178 static fmgt_cb_t sysinst_fmgt_cb = { 179 .exists_query = sysinst_fmgt_exists_query, 180 .action = sysinst_fmgt_action, 181 .progress = sysinst_fmgt_progress 178 182 }; 179 183 … … 410 414 } 411 415 412 /** Called when futil is starting to copy a file. 416 /** Called when fmgt hits an existing file while copying. 417 * 418 * @param arg Argument (sysinst_t *) 419 * @param exists Information about existing file 420 * @return Existing file recovery action 421 */ 422 fmgt_exists_action_t sysinst_fmgt_exists_query(void *arg, fmgt_exists_t *exists) 423 { 424 sysinst_t *sysinst = (sysinst_t *)arg; 425 (void)sysinst; 426 (void)exists->fname; 427 // XXX Do not overwrite configuration files. 428 return fmgt_exr_overwrite; 429 } 430 431 /** Called when fmgt is starting to perform action on a file. 432 * 433 * @param arg Argument (sysinst_t *) 434 * @param action Action being performed 435 * @param src Source or only path 436 * @param dest Destination path or @c NULL 437 */ 438 static void sysinst_fmgt_action(void *arg, fmgt_action_t action, 439 const char *src, const char *dest) 440 { 441 sysinst_t *sysinst = (sysinst_t *)arg; 442 char buf[128]; 443 444 (void)src; 445 446 switch (action) { 447 case fmgt_ac_create: 448 snprintf(buf, sizeof(buf), "Creating %s.", src); 449 sysinst_action(sysinst, buf); 450 break; 451 case fmgt_ac_copy: 452 snprintf(buf, sizeof(buf), "Copying %s.", dest); 453 sysinst_action(sysinst, buf); 454 break; 455 default: 456 break; 457 } 458 } 459 460 /** Called by fmgt to update on progress. 413 461 * 414 462 * @param arg Argument (sysinst_t *) … … 416 464 * @param dest Destination path 417 465 */ 418 static void sysinst_futil_copy_file(void *arg, const char *src, 419 const char *dest) 466 static void sysinst_fmgt_progress(void *arg, fmgt_progress_t *progress) 420 467 { 421 468 sysinst_t *sysinst = (sysinst_t *)arg; 422 469 char buf[128]; 423 470 424 (void)src; 425 snprintf(buf, sizeof(buf), "Copying %s.", dest); 426 sysinst_action(sysinst, buf); 427 } 428 429 /** Called when futil is about to create a directory. 430 * 431 * @param arg Argument (sysinst_t *) 432 * @param dest Destination path 433 */ 434 static void sysinst_futil_create_dir(void *arg, const char *dest) 435 { 436 sysinst_t *sysinst = (sysinst_t *)arg; 437 char buf[128]; 438 439 snprintf(buf, sizeof(buf), "Creating %s.", dest); 440 sysinst_action(sysinst, buf); 471 snprintf(buf, sizeof(buf), "Copied %s files, %s; " 472 "current file: %s done.", progress->total_procf, 473 progress->total_procb, progress->curf_percent); 474 sysinst_progress(sysinst, buf); 441 475 } 442 476 … … 769 803 char *path = NULL; 770 804 const char **cp; 805 fmgt_flist_t *flist = NULL; 771 806 int rv; 772 807 … … 794 829 795 830 /* Copy initial configuration files */ 796 rc = futil_rcopy_contents(sysinst->futil, CFG_FILES_SRC, 797 CFG_FILES_DEST); 831 832 log_msg(LOG_DEFAULT, LVL_NOTE, 833 "sysinst_copy_boot_files(): copy initial configuration files"); 834 835 rc = fmgt_flist_create(&flist); 836 if (rc != EOK) 837 goto error; 838 839 rc = fmgt_flist_append(flist, CFG_FILES_SRC); 840 if (rc != EOK) 841 goto error; 842 843 rc = fmgt_copy(sysinst->fmgt, flist, CFG_FILES_DEST); 798 844 if (rc != EOK) { 799 845 sysinst_error(sysinst, "Error copying initial configuration " 800 846 "files."); 801 return rc; 802 } 803 847 goto error; 848 } 849 850 fmgt_flist_destroy(flist); 851 log_msg(LOG_DEFAULT, LVL_NOTE, 852 "sysinst_copy_boot_files(): copy initial configuration files OK"); 804 853 return EOK; 805 854 error: 855 if (flist != NULL) 856 fmgt_flist_destroy(flist); 806 857 if (path != NULL) 807 858 free(path); … … 815 866 static errno_t sysinst_copy_boot_files(sysinst_t *sysinst) 816 867 { 868 fmgt_flist_t *flist = NULL; 817 869 errno_t rc; 818 870 819 871 log_msg(LOG_DEFAULT, LVL_NOTE, 820 872 "sysinst_copy_boot_files(): copy bootloader files"); 821 rc = futil_rcopy_contents(sysinst->futil, BOOT_FILES_SRC, MOUNT_POINT); 873 rc = fmgt_flist_create(&flist); 874 if (rc != EOK) 875 goto error; 876 877 rc = fmgt_flist_append(flist, BOOT_FILES_SRC); 878 if (rc != EOK) 879 goto error; 880 881 rc = fmgt_copy(sysinst->fmgt, flist, MOUNT_POINT); 822 882 if (rc != EOK) { 823 883 sysinst_error(sysinst, "Error copying bootloader " 824 884 "files."); 825 return rc; 826 } 827 885 goto error; 886 } 887 888 fmgt_flist_destroy(flist); 828 889 sysinst_debug(sysinst, "sysinst_copy_boot_files(): OK"); 829 890 return EOK; 891 error: 892 if (flist != NULL) 893 fmgt_flist_destroy(flist); 894 return rc; 830 895 } 831 896 … … 941 1006 } 942 1007 1008 /** Return file contents as a heap-allocated block of bytes. 1009 * 1010 * @param srcp File path 1011 * @param rdata Place to store pointer to data 1012 * @param rsize Place to store size of data 1013 * 1014 * @return EOK on success, ENOENT if failed to open file, EIO on other 1015 * I/O error, ENOMEM if out of memory 1016 */ 1017 static errno_t sysinst_get_file(const char *srcp, void **rdata, size_t *rsize) 1018 { 1019 int sf; 1020 size_t nr; 1021 errno_t rc; 1022 size_t fsize; 1023 char *data; 1024 vfs_stat_t st; 1025 1026 rc = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ, &sf); 1027 if (rc != EOK) 1028 return ENOENT; 1029 1030 if (vfs_stat(sf, &st) != EOK) { 1031 vfs_put(sf); 1032 return EIO; 1033 } 1034 1035 fsize = st.size; 1036 1037 data = calloc(fsize, 1); 1038 if (data == NULL) { 1039 vfs_put(sf); 1040 return ENOMEM; 1041 } 1042 1043 rc = vfs_read(sf, (aoff64_t []) { 0 }, data, fsize, &nr); 1044 if (rc != EOK || nr != fsize) { 1045 vfs_put(sf); 1046 free(data); 1047 return EIO; 1048 } 1049 1050 (void) vfs_put(sf); 1051 *rdata = data; 1052 *rsize = fsize; 1053 1054 return EOK; 1055 } 1056 943 1057 /** Copy boot blocks. 944 1058 * … … 966 1080 "sysinst_copy_boot_blocks: Read boot block image."); 967 1081 968 rc = futil_get_file(sysinst->futil, 969 BOOT_FILES_SRC "/boot/grub/i386-pc/boot.img", 1082 rc = sysinst_get_file(BOOT_FILES_SRC "/grub/i386-pc/boot.img", 970 1083 &boot_img, &boot_img_size); 971 if (rc != EOK || boot_img_size != 512) 1084 if (rc != EOK || boot_img_size != 512) { 1085 sysinst_error(sysinst, "Error reading boot block image."); 972 1086 return EIO; 1087 } 973 1088 974 1089 log_msg(LOG_DEFAULT, LVL_NOTE, 975 1090 "sysinst_copy_boot_blocks: Read GRUB core image."); 976 1091 977 rc = futil_get_file(sysinst->futil, 978 BOOT_FILES_SRC "/boot/grub/i386-pc/core.img", 1092 rc = sysinst_get_file(BOOT_FILES_SRC "/grub/i386-pc/core.img", 979 1093 &core_img, &core_img_size); 980 if (rc != EOK) 1094 if (rc != EOK) { 1095 sysinst_error(sysinst, "Error reading GRUB core image."); 981 1096 return EIO; 1097 } 982 1098 983 1099 log_msg(LOG_DEFAULT, LVL_NOTE, … … 992 1108 993 1109 rc = block_init(sid); 994 if (rc != EOK) 1110 if (rc != EOK) { 1111 sysinst_error(sysinst, "Error opening block device."); 995 1112 return rc; 1113 } 996 1114 997 1115 log_msg(LOG_DEFAULT, LVL_NOTE, … … 999 1117 1000 1118 rc = block_get_bsize(sid, &bsize); 1001 if (rc != EOK) 1119 if (rc != EOK) { 1120 sysinst_error(sysinst, "Error getting block size."); 1002 1121 return rc; 1122 } 1003 1123 1004 1124 if (bsize != 512) { … … 1011 1131 1012 1132 rc = block_read_direct(sid, BOOT_BLOCK_IDX, 1, bbuf); 1013 if (rc != EOK) 1133 if (rc != EOK) { 1134 sysinst_error(sysinst, "Error reading boot block."); 1014 1135 return EIO; 1136 } 1015 1137 1016 1138 core_start = 16; … … 1043 1165 1044 1166 rc = block_write_direct(sid, BOOT_BLOCK_IDX, 1, bbuf); 1045 if (rc != EOK) 1167 if (rc != EOK) { 1168 sysinst_error(sysinst, "Error writing boot block."); 1046 1169 return EIO; 1170 } 1047 1171 1048 1172 log_msg(LOG_DEFAULT, LVL_NOTE, … … 1051 1175 /* XXX Must pad last block with zeros */ 1052 1176 rc = block_write_direct(sid, core_start, core_blocks, core_img); 1053 if (rc != EOK) 1177 if (rc != EOK) { 1178 sysinst_error(sysinst, "Error writing GRUB core blocks."); 1054 1179 return EIO; 1180 } 1055 1181 1056 1182 log_msg(LOG_DEFAULT, LVL_NOTE, … … 1324 1450 params.rect.p0.y = 0; 1325 1451 params.rect.p1.x = 64; 1326 params.rect.p1.y = 5;1452 params.rect.p1.y = 7; 1327 1453 } else { 1328 1454 params.rect.p0.x = 0; 1329 1455 params.rect.p0.y = 0; 1330 1456 params.rect.p1.x = 500; 1331 params.rect.p1.y = 60;1457 params.rect.p1.y = 90; 1332 1458 } 1333 1459 … … 1355 1481 } 1356 1482 1483 /* Installing/upgrading system line */ 1357 1484 rc = ui_label_create(ui_res, "Installing system. Please wait...", 1358 1485 &progress->label); … … 1387 1514 } 1388 1515 1516 /* Action line */ 1389 1517 rc = ui_label_create(ui_res, "", 1390 1518 &progress->action); … … 1398 1526 rect.p0.y = 3; 1399 1527 rect.p1.x = arect.p1.x; 1528 rect.p1.y = 4; 1529 } else { 1530 rect.p0.x = arect.p0.x; 1531 rect.p0.y = 40; 1532 rect.p1.x = arect.p1.x; 1533 rect.p1.y = 60; 1534 } 1535 ui_label_set_rect(progress->action, &rect); 1536 ui_label_set_halign(progress->action, gfx_halign_center); 1537 ui_label_set_valign(progress->action, gfx_valign_top); 1538 1539 rc = ui_fixed_add(fixed, ui_label_ctl(progress->action)); 1540 if (rc != EOK) { 1541 sysinst_error(sysinst, "Error adding control to layout."); 1542 ui_label_destroy(progress->label); 1543 progress->label = NULL; 1544 goto error; 1545 } 1546 1547 /* Progress line */ 1548 rc = ui_label_create(ui_res, "", 1549 &progress->progress); 1550 if (rc != EOK) { 1551 sysinst_error(sysinst, "Error creating label."); 1552 goto error; 1553 } 1554 1555 if (ui_is_textmode(sysinst->ui)) { 1556 rect.p0.x = arect.p0.x; 1557 rect.p0.y = 5; 1558 rect.p1.x = arect.p1.x; 1400 1559 rect.p1.y = arect.p1.y; 1401 1560 } else { 1402 1561 rect.p0.x = arect.p0.x; 1403 rect.p0.y = 30;1562 rect.p0.y = 70; 1404 1563 rect.p1.x = arect.p1.x; 1405 1564 rect.p1.y = arect.p1.y; 1406 1565 } 1407 ui_label_set_rect(progress-> action, &rect);1408 ui_label_set_halign(progress-> action, gfx_halign_center);1409 ui_label_set_valign(progress-> action, gfx_valign_center);1410 1411 rc = ui_fixed_add(fixed, ui_label_ctl(progress-> action));1566 ui_label_set_rect(progress->progress, &rect); 1567 ui_label_set_halign(progress->progress, gfx_halign_center); 1568 ui_label_set_valign(progress->progress, gfx_valign_top); 1569 1570 rc = ui_fixed_add(fixed, ui_label_ctl(progress->progress)); 1412 1571 if (rc != EOK) { 1413 1572 sysinst_error(sysinst, "Error adding control to layout."); … … 1455 1614 } 1456 1615 1616 /** Set current progress message. 1617 * 1618 * @param sysinst System installer 1619 * @param progress Progress text 1620 */ 1621 static void sysinst_progress(sysinst_t *sysinst, const char *progress) 1622 { 1623 log_msg(LOG_DEFAULT, LVL_NOTE, "%s", progress); 1624 1625 if (sysinst->progress == NULL) 1626 return; 1627 1628 ui_label_set_text(sysinst->progress->progress, progress); 1629 ui_label_paint(sysinst->progress->progress); 1630 } 1631 1457 1632 /** Set current action message. 1458 1633 * … … 1616 1791 fibril_mutex_initialize(&sysinst->responded_lock); 1617 1792 1618 rc = f util_create(&sysinst_futil_cb, (void *)sysinst, &sysinst->futil);1793 rc = fmgt_create(&sysinst->fmgt); 1619 1794 if (rc != EOK) { 1620 1795 printf("Out of memory.\n"); 1621 1796 goto error; 1622 1797 } 1798 1799 fmgt_set_cb(sysinst->fmgt, &sysinst_fmgt_cb, (void *)sysinst); 1800 fmgt_set_init_update(sysinst->fmgt, true); 1623 1801 1624 1802 rc = ui_create(display_spec, &ui); … … 1681 1859 return EOK; 1682 1860 error: 1683 if (sysinst->f util!= NULL)1684 f util_destroy(sysinst->futil);1861 if (sysinst->fmgt != NULL) 1862 fmgt_destroy(sysinst->fmgt); 1685 1863 if (sysinst->system != NULL) 1686 1864 system_close(sysinst->system); -
uspace/app/sysinst/sysinst.h
r417cc85 r5df2570 38 38 39 39 #include <fibril_synch.h> 40 #include <f util.h>40 #include <fmgt.h> 41 41 #include <gfx/color.h> 42 42 #include <loc.h> … … 54 54 ui_label_t *label; 55 55 ui_label_t *action; 56 ui_label_t *progress; 56 57 } sysinst_progress_t; 57 58 … … 75 76 /** operation being performed */ 76 77 sysinst_oper_t oper; 77 f util_t *futil;78 fmgt_t *fmgt; 78 79 /** @c true after user responds to interactive query. */ 79 80 bool responded; -
uspace/lib/fmgt/include/types/fmgt.h
r417cc85 r5df2570 114 114 } fmgt_exists_action_t; 115 115 116 /** Action being performed. */ 117 typedef enum { 118 /** copying file */ 119 fmgt_ac_copy, 120 /** creating file or directory */ 121 fmgt_ac_create, 122 /** deleting file or directory */ 123 fmgt_ac_delete, 124 /** moving file */ 125 fmgt_ac_move, 126 /** renaming file */ 127 fmgt_ac_rename, 128 /** verifying file */ 129 fmgt_ac_verify, 130 } fmgt_action_t; 131 116 132 /** File management callbacks */ 117 133 typedef struct { … … 119 135 fmgt_error_action_t (*io_error_query)(void *, fmgt_io_error_t *); 120 136 fmgt_exists_action_t (*exists_query)(void *, fmgt_exists_t *); 137 void (*action)(void *, fmgt_action_t, const char *, const char *); 121 138 void (*progress)(void *, fmgt_progress_t *); 122 139 } fmgt_cb_t; -
uspace/lib/fmgt/private/fmgt.h
r417cc85 r5df2570 54 54 extern void fmgt_initial_progress_update(fmgt_t *); 55 55 extern void fmgt_final_progress_update(fmgt_t *); 56 extern void fmgt_report_action(fmgt_t *, fmgt_action_t, const char *, 57 const char *); 56 58 57 59 #endif -
uspace/lib/fmgt/src/copy.c
r417cc85 r5df2570 64 64 65 65 (void)dest; 66 fmgt_report_action(fmgt, fmgt_ac_create, dest, NULL); 66 67 return fmgt_create_dir(fmgt, dest, false); 67 68 } … … 86 87 char *buffer; 87 88 errno_t rc; 89 90 fmgt_report_action(fmgt, fmgt_ac_copy, src, dest); 88 91 89 92 buffer = calloc(BUFFER_SIZE, 1); -
uspace/lib/fmgt/src/delete.c
r417cc85 r5df2570 64 64 errno_t rc; 65 65 66 fmgt_report_action(fmgt, fmgt_ac_delete, src, NULL); 67 66 68 /* Remove original file. */ 67 69 rc = fmgt_remove(fmgt, src); … … 85 87 fmgt_t *fmgt = (fmgt_t *)walk->params->arg; 86 88 (void)dest; 89 fmgt_report_action(fmgt, fmgt_ac_delete, src, NULL); 87 90 return fmgt_remove(fmgt, src); 88 91 } -
uspace/lib/fmgt/src/fmgt.c
r417cc85 r5df2570 218 218 } 219 219 220 /** Report action being performed to the caller. 221 * 222 * @param fmgt File management object 223 * @param action Action we started performing 224 * @param src Source (or only) path 225 * @param dest Destination path or @c NULL 226 */ 227 void fmgt_report_action(fmgt_t *fmgt, fmgt_action_t action, const char *src, 228 const char *dest) 229 { 230 if (fmgt->cb != NULL && fmgt->cb->action != NULL) { 231 fmgt->cb->action(fmgt->cb_arg, action, src, dest); 232 } 233 } 234 220 235 /** Provide initial progress update (if required). 221 236 * -
uspace/lib/fmgt/src/move.c
r417cc85 r5df2570 89 89 errno_t rc; 90 90 91 fmgt_report_action(fmgt, fmgt_ac_move, src, dest); 92 91 93 buffer = calloc(BUFFER_SIZE, 1); 92 94 if (buffer == NULL) … … 166 168 167 169 (void)dest; 170 fmgt_report_action(fmgt, fmgt_ac_delete, src, NULL); 168 171 return fmgt_remove(fmgt, src); 169 172 } -
uspace/lib/fmgt/src/newdir.c
r417cc85 r5df2570 84 84 errno_t rc; 85 85 86 fmgt_report_action(fmgt, fmgt_ac_create, dname, NULL); 87 86 88 /* Clear statistics. */ 87 89 fmgt_progress_init(fmgt); -
uspace/lib/fmgt/src/newfile.c
r417cc85 r5df2570 98 98 errno_t rc; 99 99 100 fmgt_report_action(fmgt, fmgt_ac_create, fname, NULL); 101 100 102 buffer = calloc(BUFFER_SIZE, 1); 101 103 if (buffer == NULL) -
uspace/lib/fmgt/src/rename.c
r417cc85 r5df2570 50 50 errno_t rc; 51 51 52 fmgt_report_action(fmgt, fmgt_ac_rename, old_path, new_name); 53 52 54 /* Clear statistics. */ 53 55 fmgt_progress_init(fmgt); -
uspace/lib/fmgt/src/verify.c
r417cc85 r5df2570 68 68 69 69 (void)unused; 70 fmgt_report_action(fmgt, fmgt_ac_verify, fname, NULL); 70 71 71 72 buffer = calloc(BUFFER_SIZE, 1); -
uspace/lib/futil/include/futil.h
r417cc85 r5df2570 1 1 /* 2 * Copyright (c) 202 5Jiri Svoboda2 * Copyright (c) 2026 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 46 46 extern errno_t futil_copy_file(futil_t *, const char *, const char *); 47 47 extern errno_t futil_rcopy_contents(futil_t *, const char *, const char *); 48 extern errno_t futil_get_file(futil_t *, const char *, void **, size_t *);49 48 50 49 #endif -
uspace/lib/futil/src/futil.c
r417cc85 r5df2570 199 199 } 200 200 201 /** Return file contents as a heap-allocated block of bytes.202 *203 * @param futil File utility instance204 * @param srcp File path205 * @param rdata Place to store pointer to data206 * @param rsize Place to store size of data207 *208 * @return EOK on success, ENOENT if failed to open file, EIO on other209 * I/O error, ENOMEM if out of memory210 */211 errno_t futil_get_file(futil_t *futil, const char *srcp, void **rdata,212 size_t *rsize)213 {214 int sf;215 size_t nr;216 errno_t rc;217 size_t fsize;218 char *data;219 vfs_stat_t st;220 221 rc = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ, &sf);222 if (rc != EOK)223 return ENOENT;224 225 if (vfs_stat(sf, &st) != EOK) {226 vfs_put(sf);227 return EIO;228 }229 230 fsize = st.size;231 232 data = calloc(fsize, 1);233 if (data == NULL) {234 vfs_put(sf);235 return ENOMEM;236 }237 238 rc = vfs_read(sf, (aoff64_t []) { 0 }, data, fsize, &nr);239 if (rc != EOK || nr != fsize) {240 vfs_put(sf);241 free(data);242 return EIO;243 }244 245 (void) vfs_put(sf);246 *rdata = data;247 *rsize = fsize;248 249 return EOK;250 }251 252 201 /** @} 253 202 */
Note:
See TracChangeset
for help on using the changeset viewer.
