int main(int argc, char *argv[]){ disk_info_t *disk_info, *disk_list; partition_info_t *partition_info; char buf[PATH_MAX]; usb_dbg("%d: Using myself to get information:\n", VERSION); if(argc == 3){ get_mount_path("sdb1", buf, PATH_MAX); printf("buf=%s.\n", buf); } else if(argc == 2){ if(is_disk_name(argv[1])){ // Disk usb_dbg("%d: Get disk(%s)'s information:\n", VERSION, argv[1]); create_disk(argv[1], &disk_info); print_disk(disk_info); free_disk_data(&disk_info); } else{ usb_dbg("%d: Get partition(%s)'s information:\n", VERSION, argv[1]); create_partition(argv[1], &partition_info); print_partition(partition_info); free_partition_data(&partition_info); } } else{ usb_dbg("%d: Get all Disk information:\n", VERSION); disk_list = read_disk_data(); print_disks(disk_list); free_disk_data(&disk_list); } return 0; }
int main(int argc, char *argv[]) { di_opts_t opts = { B_FALSE, B_FALSE }; char c; dm_descriptor_t *media; int error, ii; int filter[] = { DM_DT_FIXED, -1 }; while ((c = getopt(argc, argv, "Hp")) != EOF) { switch (c) { case 'H': opts.di_scripted = B_TRUE; break; case 'p': opts.di_parseable = B_TRUE; break; default: return (1); } } error = 0; if ((media = dm_get_descriptors(DM_MEDIA, filter, &error)) == NULL) { fprintf(stderr, "Error from dm_get_descriptors: %d\n", error); return (1); } if (!opts.di_scripted) { printf("TYPE DISK VID PID" " SIZE REMV\n"); } for (ii = 0; media != NULL && media[ii] != NULL; ii++) print_disks(media[ii], &opts); dm_free_descriptors(media); return (0); }
void debugger(void) { extern u_int history[3]; extern int irq0_pending; static int in_debugger = 0; char buf[80], buf2[80], reg[4]; u_int i, j, k; if (in_debugger) return; in_debugger ++; no_exceptions = 1; #if 0 char *textbuf; textbuf = (char*)malloc(TEXT_SIZE); if (!textbuf) { leaveemu(ERR_MEM); } memcpy(textbuf, SCR_STATE.virt_address, TEXT_SIZE); #endif push_debug_flags(); DEBUG_OFF(); for(;;) { printf("\ndbg> "); if (fgets(buf, 80, stdin) == NULL) leaveemu(0); buf[strlen(buf)-1] = 0; /* kill \n */ if (*buf==0) { continue; } else if (!strcmp(buf, "help")) { usage(); } else if (!strcmp(buf, "r")) { show_regs(0, 0); } else if (!strcmp(buf, "logue")) { printf("prologue: 0x%08x\n", UAREA.u_entprologue); printf("epilogue: 0x%08x\n", UAREA.u_entepilogue); } else if (!strcmp(buf, "exc")) { printf("current exception: #0x%x, 0x%x\n", vm86s.trapno, vm86s.err); printf("pending guest exception: "); if (vmstate.exc) printf("#0x%x, 0x%x\n", vmstate.exc_vect, vmstate.exc_erc); else printf("none\n"); } else if (!strcmp(buf, "cr")) { show_cregs(); } else if (!strcmp(buf, "g")) { REG(eflags) &= ~TF_MASK; break; } else if (!strcmp(buf, "q") || !strcmp(buf, "quit")) { leaveemu(0); } else if (!strcmp(buf, "disks")) { print_disks(); } else if (!strcmp(buf, "ptmap")) { /* everything is in k to avoid overflows */ u_int granularity = 4*1024; u_int width = 64; printf("granularity: 0x%08x\n", granularity*1024); for (i=0; i < (4*1024*1024)/(width*granularity); i++) { u_int start = i*width*granularity; printf("0x%08x ", start*1024); for (j=0; j<width; j++) { int gp = 0, hp = 0; for (k=0; k < granularity/NBPG; k++) { u_int pte, err=0; pte = sys_read_pte(k*NBPG + (j*granularity + i*width*granularity)*1024, 0, vmstate.eid, &err); if (err == -E_NOT_FOUND) { err = pte = 0; } if (err == 0) { if (pte&1) { if (pte & PG_GUEST) gp = 1; else hp = 1; } } } if (!gp && !hp) printf("-"); else if (gp && hp) printf("+"); else if (gp && !hp) printf("g"); else printf("h"); } printf("\n"); } #if 0 } else if (!strcmp(buf, "memmap")) { memcheck_dump(); #endif } else if (sscanf(buf, "port %x", &i) == 1) { print_port(i); } else if (sscanf(buf, "int %x", &i) == 1) { pop_debug_flags(); push_debug_flags(); no_exceptions = 0; do_int(i); no_exceptions = 1; DEBUG_OFF(); } else if (sscanf(buf, "gdt %x", &i) == 1) { struct descr *sd; if (set_get_any(&vmstate.g_gdt_base, (u_int*)&sd)) { printf("no gdt is defined\n"); continue; } print_dt_entry(i, sd); } else if (sscanf(buf, "idt %x", &i) == 1) { print_dt_entry(i, (struct descr *)vmstate.g_idt_base); } else if (sscanf(buf, "ro %x", &i) == 1) { protect_range(PGROUNDDOWN(i), NBPG); } else if (sscanf(buf, "rw %x", &i) == 1) { unprotect_range(PGROUNDDOWN(i), NBPG); } else if (!strcmp(buf, "history")) { printf("most recent trap eip: %x %x %x\n", history[2], history[1], history[0]); } else if (!strcmp(buf, "irq")) { struct gate_descr *sg = (struct gate_descr *)vmstate.g_idt_base + hardware_irq_number(0); for (i=0; i<16; i++) { printf("irq %2d %s, handled by idt[%2d], function @ 0x%08x\n", i, irq_disabled(i) ? "disabled" : " enabled", hardware_irq_number(i), GATE_OFFSET(sg+i)); } } else if (sscanf(buf, "dump %x:%x %x", &i, &j, &k) == 2) { dump_memory((i<<4)+j, k); } else if (sscanf(buf, "dump %x:%x", &i, &j) == 2) { dump_memory((i<<4)+j, 0x80); } else if (sscanf(buf, "dump %x %x", &i, &j) == 2) { dump_memory(i, j); } else if (sscanf(buf, "dump %x", &i) == 1) { dump_memory(i, 0x80); } else if (!strcmp(buf, "dump")) { dump_memory(dump_offset, 0x80); } else if (sscanf(buf, "search %x %79s", &i, buf2) == 2) { search_memory(i, buf2); } else if (!strcmp(buf, "debug on")) { pop_debug_flags(); DEBUG_ON(); push_debug_flags(); } else if (!strcmp(buf, "debug off")) { pop_debug_flags(); DEBUG_OFF(); push_debug_flags(); } else if (sscanf(buf, "pte %x", &i) == 1) { Bit32u host_pte = 0; if (! (vmstate.cr[0] & PG_MASK)) { printf("guest paging not enabled\n"); printf("guest_phys_to_host_phys(0x%08x) = 0x%08x\n", i, guest_phys_to_host_phys(i)); } else { Bit32u gpte = guest_pte(i); printf("guest cr3 0x%08x\n", vmstate.cr[3]); printf("guest 0x%08x -> 0x%08x\n", i, gpte); printf("guest_phys_to_host_phys(0x%08x) = 0x%08x\n", gpte & ~PGMASK, guest_phys_to_host_phys(gpte & ~PGMASK)); } get_host_pte(i, &host_pte); printf("host 0x%08x -> 0x%08x\n", i, host_pte); } else if (sscanf(buf, "gp2hp %x", &i) == 1) { printf("&vmstate.gp2hp[0] = %p, 0x%x mappings\n", vmstate.gp2hp, vmstate.ppages); if (i<vmstate.ppages) printf("gp2hp[%x] = 0x%08x\n", i, vmstate.gp2hp[i]); } else if (!strcmp(buf, "cr3")) { u_int cr3; Set *set = &vmstate.cr3; printf("cr3 register: 0x%08x\n", vmstate.cr[3]); printf("cr3 set : "); for(set_iter_init(set); set_iter_get(set, &cr3); set_iter_next(set)) { printf("0x%08x ", cr3); } printf("\n"); } else if (!strcmp(buf, "dt")) { print_dt_mappings(); printf("h gdt base:lim 0x%08x:0x%04x\n", vmstate.h_gdt_base, vmstate.h_gdt_limit); printf("h idt base:lim 0x%08x:0x%04x\n", vmstate.h_idt_base, vmstate.h_idt_limit); } else if (!strcmp(buf, "memory")) { printf("0x%08x real physical pages (%3d megs)\n", PHYSICAL_PAGES, PHYSICAL_MEGS_RAM); printf("0x%08x fake physical pages (%3d megs)\n", vmstate.ppages, config.phys_mem_size/1024); #if 0 printf("Eavesdropping on Linux:\n"); printf("RAM %dk\n", *((Bit32u*)0x901e0)); printf("pointing device? 0x%x\n", *((Bit16u*)0x901ff)); printf("APM? 0x%x\n", *((Bit16u*)0x90040)); #endif ASSERT(vmstate.ppages == config.phys_mem_size*1024/NBPG); } else if (sscanf(buf, "%2s=%x", reg, &i) == 2 || sscanf(buf, "%3s=%x", reg, &i) == 2) { int r = reg_s2i(reg); if (r == -1) { printf("unknown register\n"); } else if (r==14) { REG(eip) = i; } else if (r<=REGNO_EDI) { set_reg(r, i, 4); /* normal regs */ } else { set_reg(r, i, 2); /* segment regs */ } } else { printf("huh?\n"); } } pop_debug_flags(); #if 0 if (debug_flags == 0) memcpy(SCR_STATE.virt_address, textbuf, TEXT_SIZE); free(textbuf); #endif REG(eflags) |= RF; in_debugger --; no_exceptions = 0; irq0_pending = 0; }