Example #1
0
/**
 * Construct a disc around an IsoImage track (convenience function)
 */
cdrom_disc_t cdrom_disc_new_from_iso_image( cdrom_disc_type_t type, IsoImage *iso, cdrom_lba_t lba,
                                            const char *bootstrap, ERROR *err )
{
    sector_mode_t mode = (type == CDROM_DISC_NONXA ? SECTOR_MODE1 : SECTOR_MODE2_FORM1 );
    sector_source_t source = iso_sector_source_new( iso, mode, lba, bootstrap, err );
    if( source != NULL ) {
        cdrom_disc_t disc = cdrom_disc_new_from_track(type, source, lba, err);
        if( disc == NULL ) {
            sector_source_unref( source );
        } else {
            return disc;
        }
    }
    return NULL;
}
Example #2
0
/**
 * Create a new CDROM disc containing a single 1ST_READ.BIN.
 * @param type The disc type - must be CDROM_DISC_GDROM or CDROM_DISC_XA
 * @param bin The binary data (takes ownership)
 * @param bin_size
 */
cdrom_disc_t cdrom_disc_new_wrapped_binary( cdrom_disc_type_t type, const gchar *filename, unsigned char *bin, size_t bin_size,
                                            ERROR *err )
{
    IsoImage *iso = NULL;
    unsigned char *data = bin;
    cdrom_lba_t start_lba = 45000; /* GDROM_START */
    char bootstrap[32768];

    /* 1. Load in the bootstrap: Note failures here are considered configuration errors */
    gchar *bootstrap_file = lxdream_get_global_config_path_value(CONFIG_BOOTSTRAP);
    if( bootstrap_file == NULL || bootstrap_file[0] == '\0' ) {
        g_free(data);
        SET_ERROR( err, LX_ERR_CONFIG, "Unable to create CD image: bootstrap file is not configured" );
        return NULL;
    }

    FILE *f = fopen( bootstrap_file, "ro" );
    if( f == NULL ) {
        g_free(data);
        SET_ERROR( err, LX_ERR_CONFIG, "Unable to create CD image: bootstrap file '%s' could not be opened", bootstrap_file );
        return FALSE;
    }
    size_t len = fread( bootstrap, 1, 32768, f );
    fclose(f);
    if( len != 32768 ) {
        g_free(data);
        SET_ERROR( err, LX_ERR_CONFIG, "Unable to create CD image: bootstrap file '%s' is invalid", bootstrap_file );
        return FALSE;
    }

    /* 2. Scramble the binary if necessary (and set type settings) */
    if( type != CDROM_DISC_GDROM ) {
        /* scramble the binary if we're going the MIL-CD route */
        unsigned char *scramblebin = g_malloc(bin_size);
        bootprogram_scramble( scramblebin, bin, bin_size );
        data = scramblebin;
        start_lba = 0x2DB6; /* CDROM_START (does it matter?) */
        g_free(bin);
    }

    /* 3. Frob the bootstrap data */
    dc_bootstrap_head_t boot_header = (dc_bootstrap_head_t)bootstrap;
    memcpy( boot_header->boot_file, "1ST_READ.BIN    ", 16 );
    char tmp[129];
    int name_len = snprintf( tmp, 129, "lxdream wrapped image: %s", filename );
    if( name_len < 128 )
        memset( tmp+name_len, ' ', 128-name_len );
    memcpy( boot_header->product_name, tmp, 128 );
//    bootstrap_update_crc(bootstrap);


    /* 4. Build the ISO image */
    int status = iso_image_new("autocd", &iso);
    if( status != 1 ) {
        g_free(data);
        SET_ERROR( err, LX_ERR_NOMEM, "Unable to create CD image: out of memory" );
        return NULL;
    }

    IsoStream *stream;
    if( iso_mem_stream_new(data, bin_size, &stream) != 1 ) {
        g_free(data);
        iso_image_unref(iso);
        SET_ERROR( err, LX_ERR_NOMEM, "Unable to create CD image: out of memory" );
        return NULL;
    }
    iso_tree_add_new_file(iso_image_get_root(iso), "1ST_READ.BIN", stream, NULL);
    sector_source_t track = iso_sector_source_new( iso, SECTOR_MODE2_FORM1, start_lba,
            bootstrap, err );
    if( track == NULL ) {
        iso_image_unref(iso);
        return NULL;
    }

    cdrom_disc_t disc = cdrom_disc_new_from_track( type, track, start_lba, err );
    iso_image_unref(iso);
    if( disc != NULL ) {
        disc->name = g_strdup(filename);
    } 
    return disc;
}