📄 cfdisk.c
字号:
info = str_list_append(info,""); /* Position in sectors */ snprintf(buf,SMALLBUF,"%30s: %llds-%llds", _("Position"), (*part)->geom.start, (*part)->geom.end); info = str_list_append(info,buf); /* Start and end */ snprintf(buf,SMALLBUF,"%30s: %s", _("Start (cyl,heads,sector)"), ped_unit_format_custom ((*part)->disk->dev, (*part)->geom.start, PED_UNIT_CHS)); info = str_list_append(info,buf); snprintf(buf,SMALLBUF,"%30s: %s", _("End (cyl,heads,sector)"), ped_unit_format_custom ((*part)->disk->dev, (*part)->geom.end, PED_UNIT_CHS)); info = str_list_append(info,buf); info = str_list_append(info,""); /* Flags */ if (!((*part)->type & PED_PARTITION_FREESPACE)) { snprintf(buf,SMALLBUF,"%30s: %s", _("Flags"), partition_print_flags(*part)); info = str_list_append(info,buf); info = str_list_append(info,""); } do_strlist(_("Partition info"),info,3); str_list_destroy(info); return 1;}/* We remember last disk listed here */static struct { Context *c; PedPartition *selected; int selnum; int start;} last_plist = { NULL, NULL, 0, 0 };/* Define column positions. The first three will be fixed. */#define col_name 3#define col_flags 12#define col_type 23#define col_fs 35/* TODO: Use printw, instead of buffer where possible ? *//* Partition list drawing function */static voidplist_draw (Context *c, PedPartition *selected, int selnum, int *start) { if (!c) { c = last_plist.c; selected = last_plist.selected; selnum = last_plist.selnum; start = &last_plist.start; } else { last_plist.c = c; last_plist.selected = selected; last_plist.selnum = selnum; last_plist.start = *start; } if (!c || !c->disk) { return; } PedPartition *part; const char* temp; char buf[SMALLBUF],fsbuf[FSBUF]; int col_label = ((double)(53-col_fs)/(80-col_fs))*(COLS-col_fs)+col_fs; int col_size = ((double)(66-col_fs)/(80-col_fs))*(COLS-col_fs)+col_fs; int n,i,x,y = INFOSIZE; int can_primary = can_create_primary(c->disk); int can_extended = can_create_extended(c->disk); /* TODO: Should we make can_name global? */ int can_name = ped_disk_type_check_feature(c->disk->type,PED_DISK_TYPE_PARTITION_NAME); n = LINES-3-MENUSIZE; if (selnum - *start < 0) *start = selnum; else if (selnum - *start >= n - INFOSIZE - 4) *start = selnum - n + INFOSIZE + 5; move(y++,0); clrtoeol(); /* Display header */ move(y,0); clrtoeol(); mvaddstr(y,col_name,_("Number")); mvaddstr(y,col_flags,_("Flags")); mvaddstr(y,col_type,_("Part Type")); mvaddstr(y,col_fs,_("Filesystem")); mvaddstr(y,col_label,_("Label")); /* We want size to be right aligned */ temp = _("Size"); x = COLS-strlen(temp)-2; x = MAX(x,col_size); mvaddstr(y++,x,temp); buf[0] = ' '; for (i = 1; i < COLS-1 && i < SMALLBUF; i++) { buf[i] = '-'; } if (i < SMALLBUF) buf[i++] = ' '; if (i < SMALLBUF) buf[i] = '\0'; mvaddstr(y++,0,buf); n = LINES-3-MENUSIZE; for (part = ped_disk_next_partition (c->disk, NULL), i=0; part && y < n; part = ped_disk_next_partition (c->disk, part)) { if (part->type & PED_PARTITION_METADATA) continue; /* We skip METADATA partitions */ i++; if (i < *start) continue; /* If the user has scrolled down, skip hidden */ int free = part->type & PED_PARTITION_FREESPACE; if (part == selected) { if (arrow_cursor) mvaddstr(y,0,"-->"); else { attron(A_STANDOUT); mvaddstr(y,0," "); } } else mvaddstr(y,0," "); if (!free) snprintf(buf, SMALLBUF, "%*d%*s", 4,part->num, col_flags-col_name-4, ""); else snprintf(buf, SMALLBUF, "%*s", col_flags, ""); mvaddstr(y,col_name,buf); /* ped_partition_get_flag(part, PED_PARTITION_BOOT) throws an exception when ran on a free space. */ snprintf(buf, SMALLBUF, "%-*s", col_type-col_flags, (!free && ped_partition_is_flag_available(part, PED_PARTITION_BOOT) && ped_partition_get_flag(part, PED_PARTITION_BOOT) ? N_("Bootable") : "")); mvaddstr(y,col_flags,buf); if (part->type & PED_PARTITION_EXTENDED) temp = _("Extended"); else if (part->type & PED_PARTITION_LOGICAL) temp = _("Logical"); else if (free) { if (can_primary) temp = (can_extended ? _("Pri/Ext") : _("Primary")); else temp = _("None"); } else temp = _("Primary"); snprintf(buf, SMALLBUF, "%-*s", col_fs-col_type, temp); mvaddstr(y,col_type,buf); temp = NULL; if (free) temp = _("Free space"); else if (part->type & PED_PARTITION_EXTENDED) temp = ""; else if(part->fs_type) temp = part->fs_type->name; if (temp) { snprintf(buf, SMALLBUF, "%-*s", col_label-col_fs, temp); } else { temp = get_disk_specific_system_name(part,1); if (temp) { snprintf(fsbuf, FSBUF, "[%s]", temp); temp = fsbuf; } else { temp = ""; } } snprintf(buf, SMALLBUF, "%-*s", col_label-col_fs, temp); mvaddstr(y,col_fs,buf); temp = NULL; if (can_name && !free && !(part->type & PED_PARTITION_EXTENDED)) temp = ped_partition_get_name(part); if (!temp) temp = ""; snprintf(buf, SMALLBUF, "%-*s", col_size-col_label, temp); mvaddstr(y,col_label,buf); /* Display the size of the disk right-aligned. */ snprintf(buf, SMALLBUF, "%*s ", COLS-col_size-1, ped_unit_format (part->disk->dev, part->geom.length)); mvaddstr(y++,col_size,buf); if (part == selected && !arrow_cursor) attroff(A_STANDOUT); } /* Please note that we clean one more line */ while (y < n+1) { move(y++,0); clrtoeol(); } refresh();}static MenuItem main_menu[] = { { 'b', N_("Flags"), N_("Change the flags of the current partition") }, { 'n', N_("New"), N_("Create new partition from free space") }, { 'e', N_("Edit"), N_("Edit this BSD disklabel") }, { 's', N_("Rescue"), N_("Look for deleted and corrupted partitions in the free space") }, { 'f', N_("Make FS"), N_("Creates a filesystem on the partition") }, { 'c', N_("Check"), N_("Check partition for consistency") }, { 'm', N_("Rename"), N_("Change partition name") }, { 'y', N_("Copy"), N_("Write another partition over this one (requires commit)") }, { 'r', N_("Resize"), N_("Resizes the current partition (requires commit)") }, { 'x', N_("Maximize"), N_("Enlarges the partition to the maximum possible size") }, { 'z', N_("Minimize"), N_("Shrinks the partition to the minimum possible size") }, { 'o', N_("Move"), N_("Moves the current partition (requires commit)") }, { 'd', N_("Delete"), N_("Delete the current partition") }, { 't', N_("Type"), N_("Set the filesystem type (doesn't convert the filesystem)") }, { 'u', N_("Units"), N_("Change units of the partition size display") }, { 'w', N_("Commit"), N_("Write the changes to the disk") }, { 'q', N_("Quit"), N_("End editing this partition table") }, { 'i', N_("Info"), N_("Display additional partition information") }, { 'h', N_("Help"), N_("Display help") }, { 0, NULL, NULL }};const char keys_ext[] = { 'm','d','u','w','q','i','h','r','x','z', ESC, '\0' };const char keys_free[] = { 'n','s','u','w','q','h','i', ESC, '\0' };const char keys_part[] = { 'b','f','c','m','y','r','o','d','t','u','w','q','i','h', ESC, '\0' };/*bfcayrodtuwqph*/const char keys_bsd[] = { 'b', 'e', 'd', 't', 'u', 'w', 'q', 'i', 'h', ESC, '\0' };static MenuItem partselect_menu[] = { { 's', N_("Select"), N_("Select this as the source partition") }, { ESC, N_("Cancel"), N_("Abort partition copy") }, { 0, NULL, NULL }};const char keys_partselect[] = { 's', ESC, '\0' };const char keys_cantselect[] = { ESC, '\0' };/* We need to separate this to use the partition list for other purposes like partition copy *//* FIXME Make use of redraw or get rid of it completely */static intmain_plist(Context *c, PedPartition **part, int key) { switch (key) { case ESC: case 'q': if (uiquery.need_commit) { key = 0; getbool(N_("Partition table has changed, are you sure you want to quit?"), &key); } else if (key == ESC) { key = 0; getbool(N_("Are you sure you want to quit?"), &key); } break; case 'n': do_new(c, part); //redraw = 1; key = 0; break; case 'e': do_edit(c, part); //redraw = 1; key = 0; break; case 'w': do_commit(c); //redraw = 1; key = 0; break; case 'f': do_mkfs(c,part); //redraw = 1; key = 0; break; case 'c': do_check(c,part); //redraw = 1; key = 0; break; case 'u': do_units(); //redraw = 1; key = 0; break; case 's': do_rescue(c,part); //redraw = 1; key = 0; break; case 'y': do_copy(c,part); //redraw = 1; key = 0; break; case 'r': do_resize(c,part); //redraw = 1; key = 0; break; case 'd': do_delete(c,part); //redraw = 1; key = 0; break; case 'o': do_move(c,part); //redraw = 1; key = 0; break; case 'x': do_maximize(c,part); //redraw = 1; key = 0; break; case 'z': do_minimize(c,part); //redraw = 1; key = 0; break; case 'b': do_flag(c,part); //redraw = 1; key = 0; break; case 't': do_type(c,part); //redraw = 0; //?? key = 0; break; case 'h': do_help(); //redraw = 0; key = 0; break; case 'm': do_name(c,part); //redraw = 0; key = 0; break; case 'i': do_pinfo(c,part); //redraw = 0; key = 0; break; default: /* NOTE: I think this can't be reached */ warning_waitkey("Unimplemented"); key = 0; } return key;}/* TODO: This doesn't need a page up/down, but leave it as a TODO *//* Okay, this is our partition list. If there is no pointer to partition given, ASSume main menu have and havent aren't perfect, but work for our purposes */static intdo_plist (Context *c, PedPartition **part, PedPartitionType have, PedPartitionType havent) { int key = 0, i, redraw = 1, selnum = 0, start = 0; const char* keys; PedPartition *selected = NULL; PedPartition *temp,*memp; MenuOptions menu_opts = MENU_BUTTON | MENU_ARROWS; MenuItem *part_menu; int menupos = 0; if (!part) part_menu = main_menu; else { part_menu = partselect_menu; menu_opts |= MENU_TITLE; } do { selected = ped_disk_next_partition(c->disk,selected); } while (selected && selected->type & PED_PARTITION_METADATA); while (!key) { if(redraw) { show_info(c); plist_draw(c,selected, selnum, &start); redraw = 0; } if (part) { if ((!have || selected->type & have) && !(havent && selected->type & havent)) keys = keys_partselect; else keys = keys_cantselect; } else if (selected->type & PED_PARTITION_EXTENDED) keys = keys_ext; else if (selected->type & PED_PARTITION_FREESPACE) keys = keys_free; else if (is_part_type_bsd(selected)) keys = keys_bsd; else keys = keys_part; key = do_menu(part_menu, 8, menu_opts, keys, &menupos); menu_opts &= ~MENU_LEAVE_WARNING; if (key == KEY_UP) { temp = disk_get_prev_nmd_partition(c->disk,selected); if (temp) { selected = temp; selnum--; redraw = 1; } else { menu_opts |= MENU_LEAVE_WARNING; print_warning(N_("No more partitions"),0); } key = 0; } else if (key == KEY_DOWN) { temp = ped_disk_next_partition(c->disk,selected); while (temp && temp->type & PED_PARTITION_METADATA) temp = ped_disk_next_partition(c->disk,temp); if (temp) { selnum++; selected = temp; redraw = 1; } else { menu_opts |= MENU_LEAVE_WARNING; print_warning(N_("No more partitions"),0); } key = 0; } else { if (part) { if (key == ESC) { return 0; } else if (key == 's') { *part = selected; return 1; } key = 0; } else { key = main_plist(c, &selected, key); /* Count which partition is now selected */ PedPartition *temp; selnum = 0; for(temp = ped_disk_next_partition(c->disk,NULL); temp && temp != selected; temp = ped_disk_next_partition(c->disk,temp)) selnum++; redraw = 1; } } refresh(); } return 1; }/* This prints the information at the top */static voidshow_info(Context *c) { if (!c) { c = last_plist.c; if (!c) { return; } } int y; char buf[SMALLBUF]; for (y = 0; y < INFOSIZE+1; y++) { move(y,0); clrtoeol(); } y
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -