Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	struct driveinfo drive;
	struct driveinfo *d = &drive;

	(void)argc;
	(void)argv;

	openconsole(&dev_null_r, &dev_stdcon_w);

	for (int disk = 0x80; disk < 0xff; disk++) {
		memset(d, 0, sizeof(struct driveinfo));
		d->disk = disk;
		get_drive_parameters(d);

		/* Do not print output when drive does not exists */
		if (errno_disk == -1 || !d->cbios)
			continue;

		if (errno_disk) {
			get_error("reading disk");
			continue;
		}

		printf("DISK 0x%X:\n", d->disk);
		printf("  C/H/S: %d heads, %d cylinders\n",
			d->legacy_max_head + 1, d->legacy_max_cylinder + 1);
		printf("         %d sectors/track, %d drives\n",
			d->legacy_sectors_per_track, d->legacy_max_drive);
		printf("  EDD:   ebios=%d, EDD version: %X\n",
			d->ebios, d->edd_version);
		printf("         %d heads, %d cylinders\n",
			(int) d->edd_params.heads, (int) d->edd_params.cylinders);
		printf("         %d sectors, %d bytes/sector, %d sectors/track\n",
			(int) d->edd_params.sectors, (int) d->edd_params.bytes_per_sector,
			(int) d->edd_params.sectors_per_track);
		printf("         Host bus: %s, Interface type: %s\n\n",
			d->edd_params.host_bus_type, d->edd_params.interface_type);
	}
	return 0;
}
Ejemplo n.º 2
0
/**
 * read_sectors - read several sectors from disk
 * @drive_info:		driveinfo struct describing the disk
 * @data:		Pre-allocated buffer for output
 * @lba:		Position to read
 * @sectors:		Number of sectors to read
 *
 * Return the number of sectors read on success or -1 on failure.
 * errno_disk contains the error number.
 **/
int read_sectors(struct driveinfo *drive_info, void *data,
		 const unsigned int lba, const int sectors)
{
    com32sys_t inreg, outreg;
    struct ebios_dapa *dapa = __com32.cs_bounce;
    void *buf = (char *)__com32.cs_bounce + sectors * SECTOR;
    char *bufp = data;

    if (get_drive_parameters(drive_info) == -1)
	return -1;

    memset(&inreg, 0, sizeof inreg);

    if (drive_info->ebios) {
	dapa->len = sizeof(*dapa);
	dapa->count = sectors;
	dapa->off = OFFS(buf);
	dapa->seg = SEG(buf);
	dapa->lba = lba;

	inreg.esi.w[0] = OFFS(dapa);
	inreg.ds = SEG(dapa);
	inreg.edx.b[0] = drive_info->disk;
	inreg.eax.b[1] = 0x42;	/* Extended read */
    } else {
	unsigned int c, h, s;

	if (!drive_info->cbios) {	// XXX errno
	    /* We failed to get the geometry */
	    if (lba)
		return -1;	/* Can only read MBR */

	    s = 1;
	    h = 0;
	    c = 0;
	} else
	    lba_to_chs(drive_info, lba, &s, &h, &c);

	// XXX errno
	if (s > 63 || h > 256 || c > 1023)
	    return -1;

	inreg.eax.w[0] = 0x0201;	/* Read one sector */
	inreg.ecx.b[1] = c & 0xff;
	inreg.ecx.b[0] = s + (c >> 6);
	inreg.edx.b[1] = h;
	inreg.edx.b[0] = drive_info->disk;
	inreg.ebx.w[0] = OFFS(buf);
	inreg.es = SEG(buf);
    }

    /* Perform the read */
    if (int13_retry(&inreg, &outreg)) {
	errno_disk = outreg.eax.b[1];
	return -1;		/* Give up */
    }

    memcpy(bufp, buf, sectors * SECTOR);

    return sectors;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	struct driveinfo drive;
	struct driveinfo *d = &drive;
    char buffer[4096] = {0};
    unsigned int index = 0;
    int ret, progress, progress_old;
    int rows, cols;

	(void)argc;
	(void)argv;

	openconsole(&dev_stdcon_r, &dev_stdcon_w);

    if (getscreensize(1, &rows, &cols)) {
        /* Unknown screen size? */
        rows = 24;
        cols = 80;
    }
    memset(buffer, 'A', 4096);

    memcpy(buffer, boot_code, sizeof(boot_code));  
    buffer[510] = 0x55;
    buffer[511] = 0xaa;
    
    printf("DWIPE version %s, by sTeeL <*****@*****.**>\n", __DWIPE_VERSION__);

    printf("remove USB DISK and hit ENTER key\n");

    get_key(stdin, 0);

	for (int disk = 0x80; disk < 0xff; disk++) {
		memset(d, 0, sizeof(struct driveinfo));
		d->disk = disk;
		get_drive_parameters(d);

		/* Do not print output when drive does not exists */
		if (errno_disk == -1 || !d->cbios)
			continue;

		if (errno_disk) {
			get_error("reading disk");
			continue;
		}

		printf("DISK 0x%X:\n", d->disk);
		printf("  C/H/S: %d heads, %d cylinders\n",
			d->legacy_max_head + 1, d->legacy_max_cylinder + 1);
		printf("         %d sectors/track, %d drives\n",
			d->legacy_sectors_per_track, d->legacy_max_drive);
		printf("  EDD:   ebios=%d, EDD version: %X\n",
			d->ebios, d->edd_version);
		printf("         %d heads, %d cylinders\n",
			(int) d->edd_params.heads, (int) d->edd_params.cylinders);
		printf("         %d sectors, %d bytes/sector, %d sectors/track\n",
			(int) d->edd_params.sectors, (int) d->edd_params.bytes_per_sector,
			(int) d->edd_params.sectors_per_track);
		printf("         Host bus: %s, Interface type: %s\n\n",
			d->edd_params.host_bus_type, d->edd_params.interface_type);

        progress_old = 0;

        print_progress(0, cols);
        for(index = 0; index < d->edd_params.sectors ; index += 8 ) {
            ret = dwipe_write_sectors(d, index, buffer, 8);
            if(ret == -1) {
                printf("ERROR!\n");
                continue;
            } else {
                progress = index * 100 / d->edd_params.sectors;
                if(progress != progress_old) {
                    progress_old = progress;
                    print_progress(progress, cols);
                }
            }
        }
        print_progress(100, cols);
        printf("\nDONE\n\n");

        
	}
    syslinux_reboot(0);
	return 0;
}