/* Function to detect the CDROM drives, returns the number of drives and fills in the CDROM info */ int detect_cdrom(install_info *info) { struct cdrom_elem *cd; int num_cdroms = 0, num_mounted = 0, i; char file[PATH_MAX], *cds[SETUP_MAX_DRIVES]; /* Clear all of the mount points */ for( cd = info->cdroms_list; cd; cd = cd->next ) { set_cdrom_mounted(cd, NULL); } /* Override the CD detection ? */ for ( cd = info->cdroms_list; cd; cd = cd->next ) { char *env = getenv("SETUP_CDROM"); if ( ! env ) { char cdenv[256], *ptr, *pid; strcpy(cdenv, "SETUP_CDROM_"); ptr = cdenv + strlen(cdenv); for ( pid = cd->id; *pid; pid ++ ) { *ptr ++ = toupper(*pid); } *ptr = '\0'; env = getenv(cdenv); if ( !env ) continue; } snprintf(file, sizeof(file), "%s/%s", env, cd->file); if ( ! access(file, F_OK) ) { set_cdrom_mounted(cd, env); num_cdroms ++; } } if ( num_cdroms ) return num_cdroms; num_cdroms = detect_and_mount_cdrom(cds); for ( i = 0; i < num_cdroms; ++i ) { for ( cd = info->cdroms_list; cd; cd = cd->next ) { snprintf(file, sizeof(file), "%s/%s", cds[i], cd->file); if ( !access(file, F_OK) ) { set_cdrom_mounted(cd, cds[i]); ++ num_mounted; break; } } } free_mounted_cdrom(num_cdroms, cds); return(num_mounted); }
int main(int argc, char **argv) { char *cds[SETUP_MAX_DRIVES]; int nb_drives, i; argv0 = argv[0]; log_init(LOG_DEBUG); nb_drives = detect_and_mount_cdrom(cds); printf("%d drives detected.\n", nb_drives); for(i = 0; i < nb_drives; ++i ) { printf("Detected CDROM on %s\n", cds[i]); } free_mounted_cdrom(nb_drives, cds); unmount_filesystems(); return 0; }
void DoMediaCheck(const char *Dir) { carbon_debug("DoMediaCheck()\n"); char path[PATH_MAX], root[PATH_MAX]; install_info *install; //if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)) ) { // If path was specified if(Dir) { /* We ignore the CDROM prefix in that case */ snprintf(path, sizeof(path), "%s/setup.data/setup.xml", Dir); if ( access( path, R_OK) ) { /* Doesn't look like a setup archive */ carbon_SetLabelText(Res, CHECK_STATUS_LABEL_ID, _("Unable to identify an installation media.")); return; } strncpy(root, Dir, sizeof(root)); } // Else, assume they selected CDROM drive else { /* Go through all CDROM devices and look for setup.xml files */ char *cds[SETUP_MAX_DRIVES]; int nb_drives = detect_and_mount_cdrom(cds), i; for(i = 0; i < nb_drives; ++i ) { snprintf(path, sizeof(path), "%s/%s/setup.data/setup.xml", cds[i], info->prefix); if ( !access( path, R_OK) ) { snprintf(root, sizeof(root), "%s/%s", cds[i], info->prefix); break; /* FIXME: What if there are many setup CDs ? */ } } free_mounted_cdrom(nb_drives, cds); } /* Verify that the package is the same (product name and version) */ if(!check_xml_setup(path, info->name)) { carbon_SetLabelText(Res, CHECK_STATUS_LABEL_ID, _("Installation media doesn't match the product.")); return; } carbon_SetLabelText(Res, CHECK_STATUS_LABEL_ID, _("Restoring files...")); /* Fetch the files to be refreshed, i.e install with a restricted set of files */ install = create_install(path, info->root, NULL, info->prefix); if ( install ) { const char *f; if ( chdir(root) < 0 ) { fprintf(stderr, _("Unable to change to directory %s\n"), root); } else { /* Update the setup path */ strncpy(install->setup_path, root, sizeof(install->setup_path)); } /* Check if we need to create a default component entry */ if ( GetProductNumComponents(install) == 0 ) { current_component = add_component_entry(install, "Default", install->version, 1, NULL, NULL); } /* Restore any environment */ loki_put_envvars_component(loki_find_component(product, current_component->name)); /* Enable the relevant options */ select_corrupt_options(install); copy_tree(install, install->config->root->childs, install->install_path, NULL); /* Menu items are currently not being restored - maybe they should be tagged in setupdb ? */ /* Install the optional README and EULA files Warning: those are always installed in the root of the installation directory! */ f = GetProductREADME(install); if ( f && ! GetProductIsMeta(install) ) { copy_path(install, f, install->install_path, NULL, 1, NULL, NULL); } f = GetProductEULA(install); if ( f && ! GetProductIsMeta(install) ) { copy_path(install, f, install->install_path, NULL, 1, NULL, NULL); } } /* Print end message and disable the "Rescue" button */ carbon_SetLabelText(Res, CHECK_STATUS_LABEL_ID, _("Files successfully restored !")); carbon_DisableControl(Res, CHECK_RESCUE_BUTTON_ID); carbon_Prompt(Res, PromptType_OK, _("Files successfully restored !"), NULL, 0); /* Unmount filesystems that may have been mounted */ unmount_filesystems(); }
void on_media_ok_clicked (GtkButton *button, gpointer user_data) { GtkWidget *diag = glade_xml_get_widget(check_glade, "diagnostic_label"), *radio; char path[PATH_MAX], root[PATH_MAX]; install_info *install; radio = glade_xml_get_widget(rescue_glade, "dir_radio"); if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)) ) { /* Directory */ const gchar *str = gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(rescue_glade, "dir_entry"))); /* We ignore the CDROM prefix in that case */ snprintf(path, sizeof(path), "%s/setup.data/setup.xml", str); if ( access( path, R_OK) ) { /* Doesn't look like a setup archive */ gtk_label_set_text(GTK_LABEL(diag), _("Unable to identify an installation media.")); gtk_widget_hide(glade_xml_get_widget(rescue_glade, "media_select")); return; } strncpy(root, str, sizeof(root)); } else { /* Go through all CDROM devices and look for setup.xml files */ char *cds[SETUP_MAX_DRIVES]; int nb_drives = detect_and_mount_cdrom(cds), i; for(i = 0; i < nb_drives; ++i ) { snprintf(path, sizeof(path), "%s/%s/setup.data/setup.xml", cds[i], info->prefix); if ( !access( path, R_OK) ) { snprintf(root, sizeof(root), "%s/%s", cds[i], info->prefix); break; /* FIXME: What if there are many setup CDs ? */ } } free_mounted_cdrom(nb_drives, cds); } /* Verify that the package is the same (product name and version) */ if ( ! check_xml_setup(path, info->name) ) { gtk_label_set_text(GTK_LABEL(diag), _("Installation media doesn't match the product.")); gtk_widget_hide(glade_xml_get_widget(rescue_glade, "media_select")); return; } gtk_label_set_text(GTK_LABEL(diag), _("Restoring files...")); gtk_widget_realize(diag); /* Fetch the files to be refreshed, i.e install with a restricted set of files */ install = create_install(path, info->root, NULL, info->prefix); if ( install ) { const char *f; if ( chdir(root) < 0 ) { fprintf(stderr, _("Unable to change to directory %s\n"), root); } else { /* Update the setup path */ strncpy(install->setup_path, root, sizeof(install->setup_path)); } /* Check if we need to create a default component entry */ if ( GetProductNumComponents(install) == 0 ) { current_component = add_component_entry(install, "Default", install->version, 1, NULL, NULL); } /* Restore any environment */ loki_put_envvars_component(loki_find_component(product, current_component->name)); /* Enable the relevant options */ select_corrupt_options(install); copy_tree(install, install->config->root->childs, install->install_path, NULL); /* Menu items are currently not being restored - maybe they should be tagged in setupdb ? */ /* Install the optional README and EULA files Warning: those are always installed in the root of the installation directory! */ f = GetProductREADME(install, NULL); if ( f && ! GetProductIsMeta(install) ) { copy_path(install, f, install->install_path, NULL, 1, NULL, NULL); } f = GetProductEULA(install, NULL); if ( f && ! GetProductIsMeta(install) ) { copy_path(install, f, install->install_path, NULL, 1, NULL, NULL); } } /* Print end message and disable the "Rescue" button */ gtk_label_set_text(GTK_LABEL(diag), _("Files successfully restored !")); gtk_widget_set_sensitive(glade_xml_get_widget(check_glade, "rescue_button"), FALSE); gtk_widget_hide(glade_xml_get_widget(rescue_glade, "media_select")); message_dialog(_("Files successfully restored !"), _("Success")); /* Unmount filesystems that may have been mounted */ unmount_filesystems(); }