📄 cfdisk.c
字号:
static intdo_check (Context *c, PedPartition **part) { if (!perform_check(c->disk,*part)) { warning_waitkey(N_("The consistency check failed.")); return 0; } notice_waitkey(N_("The consistency of the partition seems to be OK.")); return 1;}static intdo_rescue(Context *c, PedPartition **part) { static MenuItem rescue_menu[] = { { 'g', N_("Continue"), N_("Proceed with the rescue") }, { 'c', N_("Custom"), N_("Select custom area to look for partitions (for experts only)") }, { ESC, N_("Cancel"), N_("Return to the main menu") }, { 0, NULL, NULL } }; const char keys[] = { 'g', 'c', ESC, '\0' }; int key; PedPartition *temp; menu_title(_("This will try to rescue broken or deleted partitions")); key = do_menu(rescue_menu, 8, MENU_BUTTON | MENU_TITLE, keys, NULL); if (key == ESC) return 0;#if 0 /* Remember either the previous partition so we can select the free space */ temp = disk_get_prev_nmd_partition(disk, *part); if (temp && temp->type & PED_PARTITION_FREESPACE) temp = disk_get_prev_nmd_partition(disk, temp); #endif if(!perform_rescue (c->disk, (*part)->geom.start, (*part)->geom.end, UI_WARN_COMMIT | (key == 'c' ? UI_CUSTOM_VALUES : 0))) { warning_waitkey(N_("There was an error during rescue")); return 0; }#if 0 do { temp = ped_disk_next_partition(disk,temp); } while (temp && temp->type & PED_PARTITION_METADATA); *part = temp;#endif *part = NULL; do { *part = ped_disk_next_partition(c->disk,*part); } while (*part && (*part)->type & PED_PARTITION_METADATA); notice_waitkey(N_("Finished looking for partitions")); return 1;}static intdo_copy(Context *c, PedPartition **part) { if (!perform_cp(c->disk,*part, UI_WARN_COMMIT)) { if (uiquery.need_commit) _disk_reread(c, part); warning_waitkey(N_("Partition not copied successfully")); return 0; } notice_waitkey(N_("Partition copied successfully")); return 1;}static intdo_delete(Context *c, PedPartition **part) { int go = 1; PedPartition *temp; /* Don't delete the first partition on a mac partition table */ if (!strcmp(c->disk->type->name,"mac") && (*part)->num == 1) { warning_waitkey(N_("You should not delete this partition.")); return 0; } /* Remember either the previous partition so we can select the free space */ temp = disk_get_prev_nmd_partition(c->disk, *part); if (temp && temp->type & PED_PARTITION_FREESPACE) temp = disk_get_prev_nmd_partition(c->disk, temp); getbool(_("Do you want to delete this partition?"),&go); if (!go) return 0; if (!perform_rm(c->disk,*part)) { warning_waitkey(N_("Can't delete partition")); return 0; } do { temp = ped_disk_next_partition(c->disk,temp); } while (temp && temp->type & PED_PARTITION_METADATA); *part = temp; return 1;}static intdo_maximize(Context *c, PedPartition **part) { if (!perform_maximize(c->disk,*part)) { warning_waitkey(N_("Couldn't maximize this partition")); return 0; } return 1;}static intdo_minimize(Context *c, PedPartition **part) { PedPartition *temp; temp = disk_get_prev_nmd_partition(c->disk, *part); if (temp && temp->type & PED_PARTITION_FREESPACE) temp = disk_get_prev_nmd_partition(c->disk, temp); if (!(*part)->type & PED_PARTITION_EXTENDED) return 0; if (!ped_disk_minimize_extended_partition(c->disk)) { warning_waitkey(N_("Couldn't minimize the extended partition")); return 0; } if (!ped_disk_extended_partition(c->disk)) { *part = temp; do { temp = ped_disk_next_partition(c->disk,temp); } while (temp && temp->type & PED_PARTITION_METADATA); if (temp) *part = temp; } return 1;}static intdo_commit (Context *c) { if (!perform_commit(c->disk,UI_WARN_COMMIT)) { warning_waitkey(N_("Commit failed.")); return 0; } notice_waitkey(N_("Partition table successfully written.")); return 1;}static intdo_units () { static MenuItem units[] = { { 's' , N_("Sectors"), N_("Show the sizes in sectors") }, { 'b' , N_("Bytes"), N_("Show the sizes in bytes") }, { 'k' , N_("Kilobytes"), N_("Use 1,000 bytes as unit size") }, { 'm' , N_("Megabytes"), N_("Use 1,000,000 bytes as unit size") }, { 'g' , N_("Gigabytes"), N_("Use 1,000,000,000 bytes as unit size") }, { 't' , N_("Terabytes"), N_("Use 1,000,000,000,000 bytes as unit size") }, { 'c', N_("Percents"), N_("Show the sizes in percents") }, { 'a', N_("Compact"), N_("Show the size in most appropriate units") }, { 'K' , N_("Kibibytes"), N_("Use 1,024 bytes as unit size") }, { 'M' , N_("Mebibytes"), N_("Use 1,048,576 bytes as unit size") }, { 'G' , N_("Gibibytes"), N_("Use 1,073,741,824 bytes as unit size") }, { 'T', N_("Tebibytes"), N_("Use 1,099,511,627,776 bytes as unit size") }, { 'y', N_("Cylinders"), N_("Show the sizes in cylinders") }, { 'C', N_("CHS"), N_("Show the sizes in CHS units") }, { 0, NULL, NULL } }; int key; /* FIXME: If we add another way of chnaging the unit type, change this :) */ static int units_menu = 3; //menu_title(_("Choose the display unit type")); /* Heh, no place for a title, heh */ key = do_menu(units, 9, MENU_BUTTON, "sbkmgtcaKMGTyh", &units_menu); switch (key) { case 's': ped_unit_set_default(PED_UNIT_SECTOR); return 1; case 'b': ped_unit_set_default(PED_UNIT_BYTE); return 1; case 'k': ped_unit_set_default(PED_UNIT_KILOBYTE); return 1; case 'm': ped_unit_set_default(PED_UNIT_MEGABYTE); return 1; case 'g': ped_unit_set_default(PED_UNIT_GIGABYTE); return 1; case 't': ped_unit_set_default(PED_UNIT_TERABYTE); return 1; case 'c': ped_unit_set_default(PED_UNIT_PERCENT); return 1; case 'a': ped_unit_set_default(PED_UNIT_COMPACT); return 1; case 'K': ped_unit_set_default(PED_UNIT_KIBIBYTE); return 1; case 'M': ped_unit_set_default(PED_UNIT_MEBIBYTE); return 1; case 'G': ped_unit_set_default(PED_UNIT_GIBIBYTE); return 1; case 'T': ped_unit_set_default(PED_UNIT_TEBIBYTE); return 1; case 'y': ped_unit_set_default(PED_UNIT_CYLINDER); return 1; case 'C': ped_unit_set_default(PED_UNIT_CHS); return 1; }}/* I'm not quite sure we should let the user do this... *//* Actually, I'm still not quite sure if it does what it says to do :) */static intdo_type (Context *c, PedPartition **part) { static MenuItem type_menu[] = { { 'a', N_("Auto"), N_("Try to automatically set the correct type") }, { 'c', N_("Custom"), N_("Select a custom filesystem type (for experts only)") }, { ESC, N_("Cancel"), N_("Do not change the filesystem type") }, { 0, NULL, NULL } }; static char keys [] = { 'a', 'c', ESC, '\0' }; const PedFileSystemType *type = NULL; int key; menu_title(_("Set the filesystem type of the partition")); key = do_menu(type_menu, 8, MENU_BUTTON | MENU_TITLE, keys, 0); if (key == ESC) return 0; else if (key == 'a') type = ped_file_system_probe(&(*part)->geom); else if (!perform_set_system(c->disk,*part,type)) { warning_waitkey(N_("Couldn't change the filesystem type")); return 0; } return 1;}static intdo_name (Context *c, PedPartition **part) { if (!ped_disk_type_check_feature(c->disk->type,PED_DISK_TYPE_PARTITION_NAME)) { warning_waitkey(N_("The partition label doesn't support partition names")); return 0; } if (!perform_name(c->disk,*part, NULL)) { warning_waitkey(N_("Name wasn't changed successfully.")); return 0; } notice_waitkey(N_("Name was changed successfully.")); return 1;}/* Here we begin with flag editing */static voidprintaflag (int *y, const PedPartition *part, PedPartitionFlag flag, PedPartitionFlag selected) { /* TODO: I decided we should not have the names here. */#if 0 const struct { const PedPartitionFlag flag; const char* text; } labels[] = { { PED_PARTITION_BOOT, _("Bootable") }, { PED_PARTITION_ROOT, _("Root") }, { PED_PARTITION_SWAP, _("Swap") }, { PED_PARTITION_HIDDEN, _("Hidden") }, { PED_PARTITION_RAID, _("RAID") }, { PED_PARTITION_LVM, _("LVM") }, { PED_PARTITION_LBA, _("LBA") }, { PED_PARTITION_HPSERVICE, _("HP Service") }, { PED_PARTITION_PALO, _("Palo") }, /* What the hell is this? */ { PED_PARTITION_PREP, _("Prep") }, /* Hm, ok, I retract the last question */ { PED_PARTITION_MSFT_RESERVED, _("MSFT Reserved") }, /* Please, play with this on any partition you happen to find */ { 0, NULL } };#endif int i; if (!ped_partition_is_flag_available(part,flag)) return; move(*y,0); clrtoeol(); if (selected == flag) { if (arrow_cursor) mvaddstr(*y,3,"-->"); else attron(A_STANDOUT); } /* Find suitable text */#if 0 for (i = 0; labels[i].flag; i++) { if (flag == labels[i].flag) { text = labels[i].text; break; } } if (!text) text = ped_partition_flag_get_name(flag);#endif mvaddch((*y),7,'['); mvaddch((*y),8,ped_partition_get_flag (part, flag) ? 'X' : ' '); mvaddstr((*y),9,"] "); mvaddstr((*y)++,11,P_(ped_partition_flag_get_name(flag))); if (selected == flag && !arrow_cursor) attroff(A_STANDOUT); }static voidflag_draw (const PedPartition *part, PedPartitionFlag selected) { PedPartitionFlag walk; int n,x,y = INFOSIZE; n = LINES-MENUSIZE-3; move(y++,0); clrtoeol(); move(y,0); clrtoeol(); mvaddstr(y++,5,_("Partition flags (press Esc two times to end)")); mvaddch(y,0,' '); for (x = 1; x < COLS-1; x++) { mvaddch(y,x,'-'); } mvaddch(y++,x,' '); move(y++,0); clrtoeol(); printaflag(&y,part,PED_PARTITION_BOOT,selected); printaflag(&y,part,PED_PARTITION_HIDDEN,selected); move(y++,0); clrtoeol(); move(y,0); clrtoeol(); mvaddstr(y++,5,_("Other partition flags (for experts only):")); for (walk = ped_partition_flag_next(0); walk && y < n; walk = ped_partition_flag_next(walk)) { if (walk != PED_PARTITION_BOOT && walk != PED_PARTITION_HIDDEN) { printaflag(&y,part,walk,selected); } } while (y < n) { move(y++,0); clrtoeol(); } refresh();}static intdo_flag (Context *c, PedPartition **part) { PedPartitionFlag walk; /* We will put the flags in this array */ PedPartitionFlag flags[MAXFLAGS+1]; int key, done = 0, redraw = 1, i = 0; /* Put the boot and hidden flags at the beginning */ if (ped_partition_is_flag_available(*part,PED_PARTITION_BOOT)) flags[i++] = PED_PARTITION_BOOT; if (ped_partition_is_flag_available(*part,PED_PARTITION_HIDDEN)) flags[i++] = PED_PARTITION_HIDDEN; /* Put the other flags */ for (walk = ped_partition_flag_next(0); walk && i < MAXFLAGS; walk = ped_partition_flag_next(walk)) { if (walk == PED_PARTITION_BOOT || walk == PED_PARTITION_HIDDEN) continue; if (ped_partition_is_flag_available(*part,walk)) flags[i++] = walk; } flags[i] = 0; /* If there are no flags available, sorry */ if (i == 0) { warning_waitkey(_("No flags can be changed for this partition")); return 0; } /* We select the first one */ i = 0; while (!done) { if (redraw) { flag_draw(*part,flags[i]); clear_menu(); redraw = 0; } refresh(); key = getch();#if USE_KEYPAD == 0 if (key == ESC) { key = getch(); if (key == '[' || key == 'O') { key = getch(); if (key == 'B') { /* That's down arrow */ key = KEY_DOWN; } else if (key == 'A') { /* That's up arrow */ key = KEY_UP; } else print_warning(_("Invalid key"),0); } else if (key != ESC) print_warning(_("Invalid key"),0); }#endif if (key == ESC) return 1; else if (key == KEY_DOWN) { if (!flags[i+1]) print_warning(_("No more flags"),0); else { i++; redraw = 1; } } else if (key == KEY_UP) { if (i == 0) print_warning(_("No more flags"),0); else { i--; redraw = 1; } } else if (key == CR || key == ' ') { perform_set(c->disk,*part,flags[i],UI_FLAG_TOGGLE); redraw = 1; } else print_warning(_("Invalid key"),0); } return 1;}static intdo_help () { StrList *message = _message_display_strlist(help,NULL,TAB_TO_INDENT); do_strlist(_("cfdisk help"),message,1); str_list_destroy(message); return 1;}static intdo_pinfo (Context *c, PedPartition **part) { StrList *info = NULL; char buf[SMALLBUF], buf2[SMALLBUF]; const char *temp; int n; unsigned int system_type; int system_type_size; /* TODO: I did like it is done in Linux cfdisk. This won't be always correct */ n = strlen(c->dev->path); if (!(0 && c->is_devicefile) && !((*part)->type & PED_PARTITION_FREESPACE)) { get_partition_device(buf2, SMALLBUF, *part, 0); snprintf(buf,SMALLBUF, "%30s: %s", _("Possible partition device"), buf2); info = str_list_append(info,buf); } if ((*part)->type & PED_PARTITION_FREESPACE) { if ((*part)->type & PED_PARTITION_LOGICAL) temp = _("Free space inside an extended partition"); else temp = _("Free space"); } else if ((*part)->type & PED_PARTITION_LOGICAL) temp = _("Logical"); else if ((*part)->type & PED_PARTITION_EXTENDED) temp = _("Extended"); else temp = _("Primary"); snprintf(buf,SMALLBUF,"%30s: %s", _("Partition type"), temp); info = str_list_append(info,buf); if (ped_disk_type_check_feature(c->disk->type,PED_DISK_TYPE_PARTITION_NAME)) { snprintf(buf,SMALLBUF,"%30s: %s", _("Partition name"), ped_partition_get_name(*part)); info = str_list_append(info,buf); } info = str_list_append(info,""); /* Partition size */ snprintf(buf,SMALLBUF,"%30s: %s", _("Partition size in bytes"), ped_unit_format_custom ((*part)->disk->dev, (*part)->geom.length, PED_UNIT_BYTE)); info = str_list_append(info,buf); snprintf(buf,SMALLBUF,"%30s: %s", _("Partition size in sectors"), ped_unit_format_custom ((*part)->disk->dev, (*part)->geom.length, PED_UNIT_SECTOR)); info = str_list_append(info,buf); snprintf(buf,SMALLBUF,"%30s: %s", _("Portion of the hard disk"), ped_unit_format_custom ((*part)->disk->dev, (*part)->geom.length, PED_UNIT_PERCENT)); info = str_list_append(info,buf); info = str_list_append(info,""); /* Filesystem info */ if (!((*part)->type & PED_PARTITION_FREESPACE)) { if ((*part)->fs_type) { snprintf(buf,SMALLBUF,"%30s: %s", _("Filesystem type"), (*part)->fs_type->name); info = str_list_append(info,buf); } system_type = get_disk_specific_system_type(*part,&system_type_size); if (system_type_size) { system_type_size *= 2; snprintf(buf,SMALLBUF,"%30s: 0x%0*x", _("System type"), system_type_size, system_type); info = str_list_append(info,buf); } temp = get_disk_specific_system_name(*part,0); if (temp) { snprintf(buf,SMALLBUF,"%30s: %s", _("System type name"), temp); info = str_list_append(info,buf); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -