void _add_drive_node( _dnode *exist_node, drive_inf *new_drv, vol_inf *vol, int disk_number ) { wchar_t drvname[MAX_PATH]; wchar_t fs[MAX_PATH] = { 0 }; wchar_t label[MAX_PATH] = { 0 }; wchar_t path[MAX_PATH]; list_entry *node; BOOL root_exists = FALSE; _dnode *root; _dnode *mnt; mnt = exist_node; if ( mnt == NULL ) { mnt = malloc( sizeof(_dnode) ); memset( mnt, 0, sizeof(_dnode) ); } mnt->exists = TRUE; memcpy( &mnt->mnt.info, vol, sizeof(vol_inf) ); _snwprintf( path, sizeof_w(path), L"%s\\", vol->status.mnt_point ); GetVolumeInformation( path, label, sizeof_w(label), 0, 0, 0, fs, sizeof_w(fs) ); wcscpy( mnt->mnt.label, label ); wcscpy( mnt->mnt.fs, fs ); if (! exist_node ) { dc_get_hw_name( disk_number, vol->status.flags & F_CDROM, drvname, sizeof_w(drvname) ); if (! ( vol->status.flags & F_CDROM ) ) { for ( node = __drives.flink; node != &__drives; node = node->flink ) { root = contain_record(node, _dnode, list); if ( root->root.dsk_num == disk_number ) { root_exists = TRUE; break; } } } mnt->is_root = FALSE; memcpy( &mnt->root.info, new_drv, sizeof(drive_inf) ); if (! root_exists ) { root = malloc(sizeof(_dnode)); root->is_root = TRUE; memcpy(&root->mnt.info, vol, sizeof(vol_inf)); memcpy(&root->root.info, new_drv, sizeof(drive_inf)); wcscpy(root->root.dsk_name, drvname); root->root.dsk_num = disk_number; _init_list_head(&root->root.vols); _insert_tail_list(&__drives, &root->list); } _insert_tail_list(&root->root.vols, &mnt->list); } if ( vol->status.flags & F_SYNC && _create_act_thread(mnt, -1, -1) == NULL ) { _create_act_thread(mnt, ACT_ENCRYPT, ACT_PAUSED); } }
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; }