Exemplo n.º 1
0
/*
 * signal handler:
 * enables the disk again in case of SIGTERM, SIGINT and SIGQUIT
 */
static void program_interrupt_signal (int sig)
{
    int rc;

    if (program_interrupt_in_progress)
        raise (sig);
    program_interrupt_in_progress = 1;

    if (disk_disabled) {
        printf("Re-accessing the device... \n");
        rc = ioctl(filedes, BIODASDENABLE, &format_params);
        if (rc)
            ERRMSG_EXIT(EXIT_FAILURE,
                        "%s: (signal handler) IOCTL BIODASDENABLE "
                        "failed (%s)\n",prog_name,strerror(errno));
    }

    printf("Rereading the partition table... \n");
    rc = reread_partition_table();
    if (rc) {
        ERRMSG("%s: (signal handler) Re-reading partition table "
               "failed. (%s)\n", prog_name, strerror(errno));
    } else
        printf("Exiting...\n");

    rc = close(filedes);
    if (rc)
        ERRMSG("%s: (signal handler) Unable to close device (%s)\n",
               prog_name, strerror(errno));

    signal (sig, SIG_DFL);
    raise (sig);
}
Exemplo n.º 2
0
static void
xbsd_write_disklabel (void) {
#if defined (__alpha__)
	printf (_("Writing disklabel to %s.\n"), disk_device);
	xbsd_writelabel (NULL, &xbsd_dlabel);
#else
	printf (_("Writing disklabel to %s.\n"),
		partname(disk_device, xbsd_part_index+1, 0));
	xbsd_writelabel (xbsd_part, &xbsd_dlabel);
#endif
	reread_partition_table(0);	/* no exit yet */
}
Exemplo n.º 3
0
static void do_format_dasd(dasdfmt_info_t *info, format_data_t *p,
                           volume_label_t *vlabel)
{
    char               inp_buffer[5];
    dasd_information_t  dasd_info;
    struct dasd_eckd_characteristics *characteristics;
    unsigned int cylinders, heads;

    if (info->verbosity > 0) printf("Retrieving disk geometry...\n");

    if (ioctl(filedes, BIODASDINFO, &dasd_info) != 0)
        ERRMSG_EXIT(EXIT_FAILURE, "%s: (retrieving disk information) "
                    "IOCTL BIODASDINFO failed (%s).\n",
                    prog_name, strerror(errno));

    characteristics =
        (struct dasd_eckd_characteristics *) &dasd_info.characteristics;
    if (characteristics->no_cyl == LV_COMPAT_CYL &&
            characteristics->long_no_cyl)
        cylinders = characteristics->long_no_cyl;
    else
        cylinders = characteristics->no_cyl;
    heads = characteristics->trk_per_cyl;

    p->start_unit = 0;
    p->stop_unit  = (cylinders * heads) - 1;

    if (info->writenolabel) {
        if (cylinders > LV_COMPAT_CYL && !info->withoutprompt) {
            printf("\n--->> ATTENTION! <<---\n");
            printf("You specified to write no labels to a"
                   " volume with more then %u cylinders.\n"
                   "Cylinders above this limit will not be"
                   " accessible as a linux partition!\n"
                   "Type \"yes\" to continue, no will leave"
                   " the disk untouched: ", LV_COMPAT_CYL);
            if (fgets(inp_buffer, sizeof(inp_buffer), stdin) == NULL)
                return;
            if (strcasecmp(inp_buffer, "yes") &&
                    strcasecmp(inp_buffer, "yes\n")) {
                printf("Omitting ioctl call (disk will "
                       "NOT be formatted).\n");
                return;
            }
        }
    } else {
        if (!info->labelspec && !info->keep_volser) {
            char buf[7];

            sprintf(buf, "0X%04x", info->devno);
            check_volser(buf, info->devno);
            vtoc_volume_label_set_volser(vlabel, buf);
        }

        if (p->intensity & DASD_FMT_INT_COMPAT) {
            info->cdl_format = 1;
            vtoc_volume_label_set_label(vlabel, "VOL1");
            vtoc_volume_label_set_key(vlabel, "VOL1");
            vtoc_set_cchhb(&vlabel->vtoc, 0x0000, 0x0001, 0x01);
        } else
            vtoc_volume_label_set_label(vlabel, "LNX1");
    }

    if ((info->verbosity > 0) || (!info->withoutprompt))
        dasdfmt_print_info(info, vlabel, cylinders, heads, p);

    if (!info->testmode) {
        if (!info->withoutprompt) {
            printf("\n--->> ATTENTION! <<---\n");
            printf("All data of that device will be lost.\nType "
                   "\"yes\" to continue, no will leave the disk "
                   "untouched: ");
            if (fgets(inp_buffer, sizeof(inp_buffer), stdin) == NULL)
                return;
            if (strcasecmp(inp_buffer,"yes") &&
                    strcasecmp(inp_buffer,"yes\n")) {
                printf("Omitting ioctl call (disk will "
                       "NOT be formatted).\n");
                return;
            }
        }

        if (!((info->withoutprompt)&&(info->verbosity<1)))
            printf("Formatting the device. This may take a "
                   "while (get yourself a coffee).\n");

        dasdfmt_prepare_and_format(info, cylinders, heads, p);

        printf("Finished formatting the device.\n");

        if (!info->writenolabel)
            dasdfmt_write_labels(info, vlabel, cylinders, heads);

        printf("Rereading the partition table... ");
        if (reread_partition_table()) {
            ERRMSG("%s: error during rereading the partition "
                   "table: %s.\n", prog_name, strerror(errno));
        } else
            printf("ok\n");
    }
}