Skip to content

Commit 629b480

Browse files
author
Jiri Svoboda
committed
Assorted installer fixes.
1 parent 4b9213d commit 629b480

File tree

6 files changed

+191
-86
lines changed

6 files changed

+191
-86
lines changed

uspace/app/sysinst/sysinst.c

Lines changed: 105 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
*/
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 */
7778
#define INST_VOL_LABEL "HelenOS"
@@ -94,6 +95,7 @@
9495
static const char *default_devs[] = {
9596
DEFAULT_DEV_0,
9697
DEFAULT_DEV_1,
98+
DEFAULT_DEV_2,
9799
NULL
98100
};
99101

@@ -154,6 +156,7 @@ static void sysinst_debug(sysinst_t *, const char *);
154156

155157
static void sysinst_futil_copy_file(void *, const char *, const char *);
156158
static void sysinst_futil_create_dir(void *, const char *);
159+
static errno_t sysinst_eject_dev(sysinst_t *, service_id_t);
157160

158161
static futil_cb_t sysinst_futil_cb = {
159162
.copy_file = sysinst_futil_copy_file,
@@ -423,22 +426,23 @@ static errno_t sysinst_check_dev(const char *dev)
423426
return EOK;
424427
}
425428

426-
/** Label the destination device.
429+
/** Label and mount the destination device.
427430
*
428431
* @param sysinst System installer
429432
* @param dev Disk device to label
430433
* @param psvc_id Place to store service ID of the created partition
431434
*
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)
437+
static errno_t sysinst_label_dev(sysinst_t *sysinst, const char *dev)
436438
{
437-
fdisk_t *fdisk;
438-
fdisk_dev_t *fdev;
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;
444448
errno_t rc;
@@ -447,45 +451,49 @@ static errno_t sysinst_label_dev(sysinst_t *sysinst, const char *dev,
447451

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");
453457

454458
rc = fdisk_create(&fdisk);
455459
if (rc != EOK) {
456460
sysinst_error(sysinst, "Error initializing fdisk.");
457-
return rc;
461+
goto error;
458462
}
459463

460464
rc = fdisk_dev_open(fdisk, sid, &fdev);
461465
if (rc != EOK) {
462466
sysinst_error(sysinst, "Error opening device.");
463-
return rc;
467+
goto error;
464468
}
465469

466470
sysinst_debug(sysinst, "sysinst_label_dev(): create mount directory");
467471

468472
rc = vfs_link_path(MOUNT_POINT, KIND_DIRECTORY, NULL);
469473
if (rc != EOK) {
470474
sysinst_error(sysinst, "Error creating mount directory.");
471-
return rc;
475+
goto error;
472476
}
473477

478+
dir_created = true;
479+
474480
sysinst_debug(sysinst, "sysinst_label_dev(): create label");
475481

476482
rc = fdisk_label_create(fdev, lt_mbr);
477483
if (rc != EOK) {
478484
sysinst_error(sysinst, "Error creating label.");
479-
return rc;
485+
goto error;
480486
}
481487

488+
label_created = true;
489+
482490
sysinst_debug(sysinst, "sysinst_label_dev(): create partition");
483491

484492
rc = fdisk_part_get_max_avail(fdev, spc_pri, &capa);
485493
if (rc != EOK) {
486494
sysinst_error(sysinst,
487495
"Error getting available capacity.");
488-
return rc;
496+
goto error;
489497
}
490498

491499
fdisk_pspec_init(&pspec);
@@ -498,17 +506,51 @@ static errno_t sysinst_label_dev(sysinst_t *sysinst, const char *dev,
498506
rc = fdisk_part_create(fdev, &pspec, &part);
499507
if (rc != EOK) {
500508
sysinst_error(sysinst, "Error creating partition.");
501-
return rc;
509+
goto error;
502510
}
503511

504512
rc = fdisk_part_get_info(part, &pinfo);
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;
523+
error:
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+
*/
541+
static 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
}
514556

@@ -810,7 +852,7 @@ static errno_t sysinst_copy_boot_blocks(sysinst_t *sysinst, const char *devp)
810852
/** Eject installation volume.
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
*/
816858
static errno_t sysinst_eject_dev(sysinst_t *sysinst, service_id_t part_id)
@@ -824,6 +866,46 @@ static errno_t sysinst_eject_dev(sysinst_t *sysinst, service_id_t part_id)
824866
goto out;
825867
}
826868

869+
rc = vol_part_eject(vol, part_id, vef_none);
870+
if (rc != EOK) {
871+
sysinst_error(sysinst, "Error ejecting volume.");
872+
goto out;
873+
}
874+
875+
rc = EOK;
876+
out:
877+
vol_destroy(vol);
878+
return rc;
879+
}
880+
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+
*/
887+
static 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);
827909
rc = vol_part_eject(vol, part_id, vef_physical);
828910
if (rc != EOK) {
829911
sysinst_error(sysinst, "Error ejecting volume.");
@@ -900,11 +982,10 @@ static errno_t sysinst_restart(sysinst_t *sysinst)
900982
static errno_t sysinst_install(sysinst_t *sysinst, const char *dev)
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;
910991

@@ -923,13 +1004,18 @@ static errno_t sysinst_install(sysinst_t *sysinst, const char *dev)
9231004
if (rc != EOK)
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);
9281014
if (rc != EOK)
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;
9351021

uspace/app/sysinst/sysinst.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include <futil.h>
4040
#include <gfx/color.h>
41+
#include <loc.h>
4142
#include <system.h>
4243
#include <ui/fixed.h>
4344
#include <ui/label.h>
@@ -59,6 +60,8 @@ typedef struct {
5960
gfx_color_t *bg_color;
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];
6467
} sysinst_t;

uspace/app/vol/vol.c

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -53,60 +53,6 @@ typedef enum {
5353
vcmd_cfglist,
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-
11056
static errno_t vol_cmd_eject(const char *volspec, bool physical)
11157
{
11258
vol_t *vol = NULL;
@@ -119,7 +65,7 @@ static errno_t vol_cmd_eject(const char *volspec, bool physical)
11965
goto out;
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);
12571
goto out;

uspace/lib/device/include/vol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern errno_t vol_info(vol_t *, volume_id_t, vol_info_t *);
6060
extern errno_t vol_fstype_format(vol_fstype_t, char **);
6161
extern errno_t vol_pcnt_fs_format(vol_part_cnt_t, vol_fstype_t, char **);
6262
extern errno_t vol_mountp_validate(const char *);
63+
extern errno_t vol_part_by_mp(vol_t *, const char *, service_id_t *);
6364

6465
#endif
6566

0 commit comments

Comments
 (0)