/*
 * Image_exists
 *
 * Returns -1 if don't know, otherwise 0 (no) or 1 (yes).
 */
int toi_bio_image_exists(int quiet)
{
    int result;
    char *msg = NULL;

    toi_message(TOI_IO, TOI_VERBOSE, 0, "toi_bio_image_exists.");

    if (!resume_dev_t) {
        if (!quiet)
            printk(KERN_INFO "Not even trying to read header "
                   "because resume_dev_t is not set.\n");
        return -1;
    }

    if (open_resume_dev_t(0, quiet))
        return -1;

    result = toi_check_for_signature();

    clear_toi_state(TOI_RESUMED_BEFORE);
    if (toi_sig_data->resumed_before)
        set_toi_state(TOI_RESUMED_BEFORE);

    if (quiet || result == -ENOMEM)
        return result;

    if (result == -1)
        msg = "TuxOnIce: Unable to find a signature."
              " Could you have moved a swap file?\n";
    else if (!result)
        msg = "TuxOnIce: No image found.\n";
    else if (result == 1)
        msg = "TuxOnIce: Image found.\n";
    else if (result == 2)
        msg = "TuxOnIce: uswsusp or swsusp image found.\n";
    else if (result == 3)
        msg = "TuxOnIce: Old implementation's signature found.\n";

    printk(KERN_INFO "%s", msg);

    return result;
}
Example #2
0
void toi_early_boot_message(int message_detail, int default_answer,
	char *warning_reason, ...)
{
#if defined(CONFIG_VT) || defined(CONFIG_SERIAL_CONSOLE)
	unsigned long orig_state = get_toi_state(), continue_req = 0;
	unsigned long orig_loglevel = console_loglevel;
	int can_ask = 1;
#else
	int can_ask = 0;
#endif

	va_list args;
	int printed_len;

	if (!toi_wait) {
		set_toi_state(TOI_CONTINUE_REQ);
		can_ask = 0;
	}

	if (warning_reason) {
		va_start(args, warning_reason);
		printed_len = vsnprintf(local_printf_buf,
				sizeof(local_printf_buf),
				warning_reason,
				args);
		va_end(args);
	}

	if (!test_toi_state(TOI_BOOT_TIME)) {
		printk("TuxOnIce: %s\n", local_printf_buf);
		return;
	}

	if (!can_ask) {
		continue_req = !!default_answer;
		goto post_ask;
	}

#if defined(CONFIG_VT) || defined(CONFIG_SERIAL_CONSOLE)
	console_loglevel = 7;

	say("=== TuxOnIce ===\n\n");
	if (warning_reason) {
		say("BIG FAT WARNING!! %s\n\n", local_printf_buf);
		switch (message_detail) {
		case 0:
			say("If you continue booting, note that any image WILL"
				"NOT BE REMOVED.\nTuxOnIce is unable to do so "
				"because the appropriate modules aren't\n"
				"loaded. You should manually remove the image "
				"to avoid any\npossibility of corrupting your "
				"filesystem(s) later.\n");
			break;
		case 1:
			say("If you want to use the current TuxOnIce image, "
				"reboot and try\nagain with the same kernel "
				"that you hibernated from. If you want\n"
				"to forget that image, continue and the image "
				"will be erased.\n");
			break;
		}
		say("Press SPACE to reboot or C to continue booting with "
			"this kernel\n\n");
		if (toi_wait > 0)
			say("Default action if you don't select one in %d "
				"seconds is: %s.\n",
				toi_wait,
				default_answer == TOI_CONTINUE_REQ ?
				"continue booting" : "reboot");
	} else {
		say("BIG FAT WARNING!!\n\n"
			"You have tried to resume from this image before.\n"
			"If it failed once, it may well fail again.\n"
			"Would you like to remove the image and boot "
			"normally?\nThis will be equivalent to entering "
			"noresume on the\nkernel command line.\n\n"
			"Press SPACE to remove the image or C to continue "
			"resuming.\n\n");
		if (toi_wait > 0)
			say("Default action if you don't select one in %d "
				"seconds is: %s.\n", toi_wait,
				!!default_answer ?
				"continue resuming" : "remove the image");
	}
	console_loglevel = orig_loglevel;

	set_toi_state(TOI_SANITY_CHECK_PROMPT);
	clear_toi_state(TOI_CONTINUE_REQ);

	if (toi_wait_for_keypress(toi_wait) == 0) /* We timed out */
		continue_req = !!default_answer;
	else
		continue_req = test_toi_state(TOI_CONTINUE_REQ);

#endif /* CONFIG_VT or CONFIG_SERIAL_CONSOLE */

post_ask:
	if ((warning_reason) && (!continue_req))
		machine_restart(NULL);

	restore_toi_state(orig_state);
	if (continue_req)
		set_toi_state(TOI_CONTINUE_REQ);
}