int _update_layout(
		_dnode *node,
		int     new_layout,  /* -1 - init */
		int    *old_layout

	)
{
	BOOL boot_dev = _is_boot_device( &node->mnt.info );
	ldr_config conf;

	int kbd_layout = KB_QWERTY;
	int rlt = ST_OK;

	if ( new_layout != -1 )
	{
		if ( boot_dev )
		{
			if ( (rlt = dc_get_mbr_config( -1, NULL, &conf )) != ST_OK )
			{
				return rlt;
			}
			conf.kbd_layout = new_layout;

			if ( (rlt = dc_set_mbr_config( -1, NULL, &conf )) != ST_OK )
			{
				return rlt;
			}
		}
		return rlt;
	} 
	else 
	{
		BOOL result = dc_get_mbr_config( -1, NULL, &conf ) == ST_OK;

		if ( old_layout )
		{
			*old_layout = result ? conf.kbd_layout : KB_QWERTY;
		}
		return result;
	}
}
Esempio n. 2
0
int boot_menu(int argc, wchar_t *argv[])
{
	ldr_config conf;
	int        resl;
	int        is_small;

	is_small = is_param(L"-small");
	do
	{
		if ( (argc == 3) && (wcscmp(argv[2], L"-enum") == 0) )
		{
			wchar_t  s_size[MAX_PATH];
			wchar_t  h_name[MAX_PATH];
			wchar_t *str;
			u64      size;
			int      i, bd_1, bd_2;

			wprintf(
				L"--------------------------------------------------------------\n"
				L"HDD |           name           |  size   | bootable | bootloader\n" 
				L"----+--------------------------+---------+----------+-----------\n");

			if (dc_get_boot_disk(&bd_1, &bd_2) != ST_OK) {
				bd_1 = bd_2 = -1;
			}

			for (i = 0; i < 100; i++)
			{
				if (size = dc_dsk_get_size(i, 0)) 
				{
					dc_format_byte_size(s_size, sizeof_w(s_size), size);

					if (dc_get_hw_name(i, 0, h_name, sizeof_w(h_name)) != ST_OK) {
						h_name[0] = 0;
					}
					
					if (dc_get_mbr_config(i, NULL, &conf) == ST_OK) {
						str = L"installed"; 
					} else {
						str = L"none";
					}

					wprintf(
						L"hd%d | %-24s | %-8s| %-8s | %s\n", 
						i, h_name, s_size, (i == bd_1) || (i == bd_2) ? L"yes":L"no", str
						);
				} 
			}
			resl = ST_OK; break;
		}

		if ( (argc >= 4) && (wcscmp(argv[2], L"-setmbr") == 0) )
		{
			int d_num;
			
			if (dsk_num(argv[3], &d_num) == 0) {
				resl = ST_OK; break;
			}			

			if ( (resl = dc_set_boot_interactive(d_num, is_small)) == ST_OK) {
				wprintf(L"Bootloader successfully installed to %s\n", argv[3]);
			}
			break; 
		}

		if ( (argc == 4) && (wcscmp(argv[2], L"-delmbr") == 0) )
		{
			int d_num;
			
			if (dsk_num(argv[3], &d_num) == 0) {
				resl = ST_OK; break;
			}

			if ( (resl = dc_unset_mbr(d_num)) == ST_OK ) {
				wprintf(L"Bootloader successfully removed from %s\n", argv[3]);
			}
			break;
		}

		if ( (argc == 4) && (wcscmp(argv[2], L"-updmbr") == 0) )
		{
			int d_num;
			
			if (dsk_num(argv[3], &d_num) == 0) {
				resl = ST_OK; break;
			}

			if ( (resl = dc_update_boot(d_num)) == ST_OK ) {
				wprintf(L"Bootloader on %s successfully updated\n", argv[3]);
			}
			break;
		}	

		if ( (argc >= 4) && (wcscmp(argv[2], L"-setpar") == 0) )
		{
			if ( (resl = dc_set_boot(argv[3], 0, is_small)) == ST_FORMAT_NEEDED )
			{
				wprintf(
				   L"Removable media not correctly formatted\n"
				   L"Format media? (Y/N)\n"
				   );

				if (tolower(_getch()) == 'y') {
					resl = dc_set_boot(argv[3], 1, is_small);
				} else {
					resl = ST_OK; break;
				}
			}

			if (resl != ST_OK) {
				break;
			}

			if ( (resl = dc_mbr_config_by_partition(argv[3], 0, &conf)) != ST_OK ) {
				break;
			}

			conf.options  |= OP_EXTERNAL;
			conf.boot_type = BT_AP_PASSWORD;

			boot_conf_menu(
				&conf, L"Please set bootloader options:");

			if ( (resl = dc_mbr_config_by_partition(argv[3], 1, &conf)) == ST_OK ) {
				wprintf(L"Bootloader successfully installed\n");
			}
			break;
		}

		if ( (argc >= 4) && (wcscmp(argv[2], L"-makeiso") == 0) )
		{
			if ( (resl = dc_make_iso(argv[3], is_small)) != ST_OK ) {
				break;
			}

			if ( (resl = dc_get_mbr_config(0, argv[3], &conf)) != ST_OK ) {
				break;
			}

			conf.options  |= OP_EXTERNAL;
			conf.boot_type = BT_MBR_FIRST;

			boot_conf_menu(
				&conf, L"Please set bootloader options:");

			if ( (resl = dc_set_mbr_config(0, argv[3], &conf)) == ST_OK ) {
				wprintf(L"Bootloader .iso image successfully created\n", argv[3]);
			}
			break;
		}

		if ( (argc >= 4) && (wcscmp(argv[2], L"-makepxe") == 0) )
		{
			if ( (resl = dc_make_pxe(argv[3], is_small)) != ST_OK ) {
				break;
			}

			if ( (resl = dc_get_mbr_config(0, argv[3], &conf)) != ST_OK ) {
				break;
			}

			conf.options  |= OP_EXTERNAL;
			conf.boot_type = BT_MBR_FIRST;

			boot_conf_menu(
				&conf, L"Please set bootloader options:");

			if ( (resl = dc_set_mbr_config(0, argv[3], &conf)) == ST_OK ) {
				wprintf(L"Bootloader PXE image successfully created\n", argv[3]);
			}
			break;
		}

		if ( (argc == 4) && (wcscmp(argv[2], L"-config") == 0) )
		{
			int      d_num;
			wchar_t *file;
			int      ispar;
			
			if ( ((argv[3][1] == L':')  && (argv[3][2] == 0)) ||
				 ((argv[3][0] == L'\\') && (argv[3][5] == L':')) )
			{
				ispar = 1;
			} else 
			{
				if (dsk_num(argv[3], &d_num) == 0) {
					file = argv[3]; d_num = 0;
				} else {
					file = NULL;
				}

				ispar = 0;
			}

			if (ispar != 0) {
				resl = dc_mbr_config_by_partition(argv[3], 0, &conf);
			} else {
				resl = dc_get_mbr_config(d_num, file, &conf);
			}

			if (resl != ST_OK) {
				break;
			}

			boot_conf_menu(
				&conf, L"Please change bootloader options:");

			if (ispar != 0) {
				resl = dc_mbr_config_by_partition(argv[3], 1, &conf);
			} else {
				resl = dc_set_mbr_config(d_num, file, &conf);
			}

			if (resl == ST_OK) {
				wprintf(L"Bootloader configuration successfully changed\n");
			}
			break;
		}
	} while (0);

	return resl;
}