Changeset 629b480 in mainline


Ignore:
Timestamp:
2025-04-25T20:48:07Z (4 weeks ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
0526285, 21cd0c8, 32cb7cd, 4ae6a23, a4f8c3f, abd1eff, cbaf408, f7f60e70
Parents:
4b9213d
Message:

Assorted installer fixes.

Location:
uspace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sysinst/sysinst.c

    r4b9213d r629b480  
    7373#define DEFAULT_DEV_0 "devices/\\hw\\sys\\00:01.1\\c0d0"
    7474#define DEFAULT_DEV_1 "devices/\\hw\\sys\\ide1\\c0d0"
     75#define DEFAULT_DEV_2 "devices/\\hw\\sys\\00:01.0\\ide1\\c0d0"
    7576//#define DEFAULT_DEV "devices/\\hw\\pci0\\00:01.2\\uhci_rh\\usb01_a1\\mass-storage0\\l0"
    7677/** Volume label for the new file system */
     
    9596        DEFAULT_DEV_0,
    9697        DEFAULT_DEV_1,
     98        DEFAULT_DEV_2,
    9799        NULL
    98100};
     
    155157static void sysinst_futil_copy_file(void *, const char *, const char *);
    156158static void sysinst_futil_create_dir(void *, const char *);
     159static errno_t sysinst_eject_dev(sysinst_t *, service_id_t);
    157160
    158161static futil_cb_t sysinst_futil_cb = {
     
    424427}
    425428
    426 /** Label the destination device.
     429/** Label and mount the destination device.
    427430 *
    428431 * @param sysinst System installer
     
    432435 * @return EOK on success or an error code
    433436 */
    434 static errno_t sysinst_label_dev(sysinst_t *sysinst, const char *dev,
    435     service_id_t *psvc_id)
    436 {
    437         fdisk_t *fdisk;
    438         fdisk_dev_t *fdev;
     437static errno_t sysinst_label_dev(sysinst_t *sysinst, const char *dev)
     438{
     439        fdisk_t *fdisk = NULL;
     440        fdisk_dev_t *fdev = NULL;
    439441        fdisk_part_t *part;
    440442        fdisk_part_spec_t pspec;
    441443        fdisk_part_info_t pinfo;
     444        bool dir_created = false;
     445        bool label_created = false;
    442446        capa_spec_t capa;
    443447        service_id_t sid;
     
    448452        rc = loc_service_get_id(dev, &sid, 0);
    449453        if (rc != EOK)
    450                 return rc;
     454                goto error;
    451455
    452456        sysinst_debug(sysinst, "sysinst_label_dev(): open device");
     
    455459        if (rc != EOK) {
    456460                sysinst_error(sysinst, "Error initializing fdisk.");
    457                 return rc;
     461                goto error;
    458462        }
    459463
     
    461465        if (rc != EOK) {
    462466                sysinst_error(sysinst, "Error opening device.");
    463                 return rc;
     467                goto error;
    464468        }
    465469
     
    469473        if (rc != EOK) {
    470474                sysinst_error(sysinst, "Error creating mount directory.");
    471                 return rc;
    472         }
     475                goto error;
     476        }
     477
     478        dir_created = true;
    473479
    474480        sysinst_debug(sysinst, "sysinst_label_dev(): create label");
     
    477483        if (rc != EOK) {
    478484                sysinst_error(sysinst, "Error creating label.");
    479                 return rc;
    480         }
     485                goto error;
     486        }
     487
     488        label_created = true;
    481489
    482490        sysinst_debug(sysinst, "sysinst_label_dev(): create partition");
     
    486494                sysinst_error(sysinst,
    487495                    "Error getting available capacity.");
    488                 return rc;
     496                goto error;
    489497        }
    490498
     
    499507        if (rc != EOK) {
    500508                sysinst_error(sysinst, "Error creating partition.");
    501                 return rc;
     509                goto error;
    502510        }
    503511
     
    505513        if (rc != EOK) {
    506514                sysinst_error(sysinst, "Error getting partition information.");
    507                 return rc;
     515                goto error;
    508516        }
    509517
    510518        sysinst_debug(sysinst, "sysinst_label_dev(): OK");
    511         *psvc_id = pinfo.svc_id;
     519        fdisk_dev_close(fdev);
     520        fdisk_destroy(fdisk);
     521        sysinst->psvc_id = pinfo.svc_id;
     522        return EOK;
     523error:
     524        if (label_created)
     525                fdisk_label_destroy(fdev);
     526        if (dir_created)
     527                (void)vfs_unlink_path(MOUNT_POINT);
     528        if (fdev != NULL)
     529                fdisk_dev_close(fdev);
     530        if (fdisk != NULL)
     531                fdisk_destroy(fdisk);
     532        return rc;
     533}
     534
     535/** Finish/unmount destination device.
     536 *
     537 * @param sysinst System installer
     538 *
     539 * @return EOK on success or an error code
     540 */
     541static errno_t sysinst_finish_dev(sysinst_t *sysinst)
     542{
     543        errno_t rc;
     544
     545        sysinst_debug(sysinst, "sysinst_finish_dev(): eject target volume");
     546        rc = sysinst_eject_dev(sysinst, sysinst->psvc_id);
     547        if (rc != EOK)
     548                return rc;
     549
     550        sysinst_debug(sysinst, "sysinst_finish_dev(): "
     551            "deleting mount directory");
     552        (void)vfs_unlink_path(MOUNT_POINT);
     553
    512554        return EOK;
    513555}
     
    811853 *
    812854 * @param sysinst System installer
    813  * @param psvc_id Partition service ID
     855 * @param part_id Partition service ID
    814856 * @return EOK on success or an error code
    815857 */
     
    825867        }
    826868
    827         rc = vol_part_eject(vol, part_id, vef_physical);
     869        rc = vol_part_eject(vol, part_id, vef_none);
    828870        if (rc != EOK) {
    829871                sysinst_error(sysinst, "Error ejecting volume.");
     
    837879}
    838880
     881/** Physically eject volume by mount point.
     882 *
     883 * @param sysinst System installer
     884 * @param path Mount point
     885 * @return EOK on success or an error code
     886 */
     887static errno_t sysinst_eject_phys_by_mp(sysinst_t *sysinst, const char *path)
     888{
     889        vol_t *vol = NULL;
     890        sysarg_t part_id;
     891        errno_t rc;
     892
     893        rc = vol_create(&vol);
     894        if (rc != EOK) {
     895                sysinst_error(sysinst, "Error contacting volume service.");
     896                goto out;
     897        }
     898
     899        log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_by_mp: mp='%s'\n",
     900            path);
     901        rc = vol_part_by_mp(vol, path, &part_id);
     902        if (rc != EOK) {
     903                sysinst_error(sysinst,
     904                    "Error finding installation media mount point.");
     905                goto out;
     906        }
     907
     908        log_msg(LOG_DEFAULT, LVL_NOTE, "eject svc_id %lu", (unsigned long)part_id);
     909        rc = vol_part_eject(vol, part_id, vef_physical);
     910        if (rc != EOK) {
     911                sysinst_error(sysinst, "Error ejecting volume.");
     912                goto out;
     913        }
     914
     915        rc = EOK;
     916out:
     917        vol_destroy(vol);
     918        return rc;
     919}
     920
    839921/** Restart the system.
    840922 *
     
    901983{
    902984        errno_t rc;
    903         service_id_t psvc_id;
    904985
    905986        sysinst_action(sysinst, "Creating device label and file system.");
    906987
    907         rc = sysinst_label_dev(sysinst, dev, &psvc_id);
     988        rc = sysinst_label_dev(sysinst, dev);
    908989        if (rc != EOK)
    909990                return rc;
     
    9241005                return rc;
    9251006
     1007        sysinst_action(sysinst, "Finishing system volume.");
     1008        rc = sysinst_finish_dev(sysinst);
     1009        if (rc != EOK)
     1010                return rc;
     1011
    9261012        sysinst_action(sysinst, "Installing boot blocks.");
    9271013        rc = sysinst_copy_boot_blocks(sysinst, dev);
     
    9291015                return rc;
    9301016
    931         sysinst_action(sysinst, "Ejecting device.");
    932         rc = sysinst_eject_dev(sysinst, psvc_id);
     1017        sysinst_action(sysinst, "Ejecting installation media.");
     1018        rc = sysinst_eject_phys_by_mp(sysinst, CD_MOUNT_POINT);
    9331019        if (rc != EOK)
    9341020                return rc;
  • uspace/app/sysinst/sysinst.h

    r4b9213d r629b480  
    3939#include <futil.h>
    4040#include <gfx/color.h>
     41#include <loc.h>
    4142#include <system.h>
    4243#include <ui/fixed.h>
     
    6061        sysinst_progress_t *progress;
    6162        system_t *system;
     63        /** Service ID of destination partition. */
     64        sysarg_t psvc_id;
    6265        futil_t *futil;
    6366        char errmsg[128];
  • uspace/app/vol/vol.c

    r4b9213d r629b480  
    5454} vol_cmd_t;
    5555
    56 /** Find volume by current mount point. */
    57 static errno_t vol_cmd_part_by_mp(vol_t *vol, const char *mp,
    58     service_id_t *rid)
    59 {
    60         vol_part_info_t vinfo;
    61         service_id_t *part_ids = NULL;
    62         char *canon_mp_buf = NULL;
    63         char *canon_mp;
    64         size_t nparts;
    65         size_t i;
    66         errno_t rc;
    67 
    68         canon_mp_buf = str_dup(mp);
    69         if (canon_mp_buf == NULL) {
    70                 printf("Out of memory.\n");
    71                 rc = ENOMEM;
    72                 goto out;
    73         }
    74 
    75         canon_mp = vfs_absolutize(canon_mp_buf, NULL);
    76         if (canon_mp == NULL) {
    77                 printf("Invalid volume path '%s'.\n", mp);
    78                 rc = EINVAL;
    79                 goto out;
    80         }
    81 
    82         rc = vol_get_parts(vol, &part_ids, &nparts);
    83         if (rc != EOK) {
    84                 printf("Error getting list of volumes.\n");
    85                 goto out;
    86         }
    87 
    88         for (i = 0; i < nparts; i++) {
    89                 rc = vol_part_info(vol, part_ids[i], &vinfo);
    90                 if (rc != EOK) {
    91                         printf("Error getting volume information.\n");
    92                         rc = EIO;
    93                         goto out;
    94                 }
    95 
    96                 if (str_cmp(vinfo.cur_mp, canon_mp) == 0) {
    97                         *rid = part_ids[i];
    98                         rc = EOK;
    99                         goto out;
    100                 }
    101         }
    102 
    103         rc = ENOENT;
    104 out:
    105         free(part_ids);
    106         free(canon_mp_buf);
    107         return rc;
    108 }
    109 
    11056static errno_t vol_cmd_eject(const char *volspec, bool physical)
    11157{
     
    12066        }
    12167
    122         rc = vol_cmd_part_by_mp(vol, volspec, &part_id);
     68        rc = vol_part_by_mp(vol, volspec, &part_id);
    12369        if (rc != EOK) {
    12470                printf("Error looking up volume '%s'.\n", volspec);
  • uspace/lib/device/include/vol.h

    r4b9213d r629b480  
    6161extern errno_t vol_pcnt_fs_format(vol_part_cnt_t, vol_fstype_t, char **);
    6262extern errno_t vol_mountp_validate(const char *);
     63extern errno_t vol_part_by_mp(vol_t *, const char *, service_id_t *);
    6364
    6465#endif
  • uspace/lib/device/src/vol.c

    r4b9213d r629b480  
    608608}
    609609
     610/** Find volume by current mount point.
     611 *
     612 * @param vol Volume service
     613 * @param mp Mount point
     614 * @param rid Place to store partition service ID
     615 * @return EOK on success or an error code
     616 */
     617errno_t vol_part_by_mp(vol_t *vol, const char *mp, service_id_t *rid)
     618{
     619        vol_part_info_t vinfo;
     620        service_id_t *part_ids = NULL;
     621        char *canon_mp_buf = NULL;
     622        char *canon_mp;
     623        size_t nparts;
     624        size_t i;
     625        errno_t rc;
     626
     627        canon_mp_buf = str_dup(mp);
     628        if (canon_mp_buf == NULL) {
     629                rc = ENOMEM;
     630                goto out;
     631        }
     632
     633        canon_mp = vfs_absolutize(canon_mp_buf, NULL);
     634        if (canon_mp == NULL) {
     635                rc = EINVAL;
     636                goto out;
     637        }
     638
     639        rc = vol_get_parts(vol, &part_ids, &nparts);
     640        if (rc != EOK)
     641                goto out;
     642
     643        for (i = 0; i < nparts; i++) {
     644                rc = vol_part_info(vol, part_ids[i], &vinfo);
     645                if (rc != EOK) {
     646                        rc = EIO;
     647                        goto out;
     648                }
     649
     650                if (str_cmp(vinfo.cur_mp, canon_mp) == 0) {
     651                        *rid = part_ids[i];
     652                        rc = EOK;
     653                        goto out;
     654                }
     655        }
     656
     657        rc = ENOENT;
     658out:
     659        free(part_ids);
     660        free(canon_mp_buf);
     661        return rc;
     662}
     663
    610664/** @}
    611665 */
  • uspace/lib/futil/src/futil.c

    r4b9213d r629b480  
    9999                return EIO;
    100100
    101         rc = vfs_lookup_open(destp, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE, &df);
    102         if (rc != EOK)
    103                 return EIO;
     101        rc = vfs_lookup_open(destp, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE,
     102            &df);
     103        if (rc != EOK) {
     104                vfs_put(sf);
     105                return EIO;
     106        }
    104107
    105108        do {
     
    152155        de = readdir(dir);
    153156        while (de != NULL) {
    154                 if (asprintf(&srcp, "%s/%s", srcdir, de->d_name) < 0)
    155                         return ENOMEM;
    156                 if (asprintf(&destp, "%s/%s", destdir, de->d_name) < 0)
    157                         return ENOMEM;
     157                if (asprintf(&srcp, "%s/%s", srcdir, de->d_name) < 0) {
     158                        rc = ENOMEM;
     159                        goto error;
     160                }
     161
     162                if (asprintf(&destp, "%s/%s", destdir, de->d_name) < 0) {
     163                        rc = ENOMEM;
     164                        goto error;
     165                }
    158166
    159167                rc = vfs_stat_path(srcp, &s);
    160168                if (rc != EOK)
    161                         return EIO;
     169                        goto error;
    162170
    163171                if (s.is_file) {
    164172                        rc = futil_copy_file(futil, srcp, destp);
    165                         if (rc != EOK)
    166                                 return EIO;
     173                        if (rc != EOK) {
     174                                rc = EIO;
     175                                goto error;
     176                        }
    167177                } else if (s.is_directory) {
    168178                        if (futil->cb != NULL && futil->cb->create_dir != NULL)
     
    170180                        rc = vfs_link_path(destp, KIND_DIRECTORY, NULL);
    171181                        if (rc != EOK)
    172                                 return EIO;
     182                                goto error;
    173183                        rc = futil_rcopy_contents(futil, srcp, destp);
    174184                        if (rc != EOK)
    175                                 return EIO;
     185                                goto error;
    176186                } else {
    177                         return EIO;
     187                        rc = EIO;
     188                        goto error;
    178189                }
    179190
     
    181192        }
    182193
    183         return EOK;
     194        closedir(dir);
     195        return EOK;
     196error:
     197        closedir(dir);
     198        return rc;
    184199}
    185200
Note: See TracChangeset for help on using the changeset viewer.