fdisk.c
来自「fdisk 实现源码,可以查询Linux下系统的分区信息」· C语言 代码 · 共 2,469 行 · 第 1/5 页
C
2,469 行
if (first) first = 0; else str_list_append (list, ", "); str_list_append (list, _(ped_partition_flag_get_name (part_flag))); } str_list_append (list, "\n"); flag_msg = str_list_convert (list); str_list_destroy (list);/* units */ first = 1; list = str_list_create (_(unit_msg_start), NULL); for (unit = PED_UNIT_FIRST; unit <= PED_UNIT_LAST; unit++) { if (first) first = 0; else str_list_append (list, ", "); str_list_append (list, ped_unit_get_name (unit)); } str_list_append (list, "\n"); unit_msg = str_list_convert (list); str_list_destroy (list);/* disk type */ list = str_list_create (_(label_type_msg_start), NULL); first = 1; for (disk_type = ped_disk_type_get_next (NULL); disk_type; disk_type = ped_disk_type_get_next (disk_type)) { if (disk_type->ops->write == NULL) continue; if (first) first = 0; else str_list_append (list, ", "); str_list_append (list, disk_type->name); } str_list_append (list, "\n"); label_type_msg = str_list_convert (list); str_list_destroy (list);/* mkfs - file system types */ list = str_list_create (_(fs_type_msg_start), NULL); first = 1; for (fs_type = ped_file_system_type_get_next (NULL); fs_type; fs_type = ped_file_system_type_get_next (fs_type)) { if (fs_type->ops->create == NULL) continue; if (first) first = 0; else str_list_append (list, ", "); str_list_append (list, fs_type->name); } str_list_append (list, "\n"); mkfs_fs_type_msg = str_list_convert (list); str_list_destroy (list);/* mkpart - file system types */ list = str_list_create (_(fs_type_msg_start), NULL); first = 1; for (fs_type = ped_file_system_type_get_next (NULL); fs_type; fs_type = ped_file_system_type_get_next (fs_type)) { if (first) first = 0; else str_list_append (list, ", "); str_list_append (list, fs_type->name); } str_list_append (list, "\n"); mkpart_fs_type_msg = str_list_convert (list); str_list_destroy (list);/* resize - file system types */ list = str_list_create (_(resize_msg_start), NULL); first = 1; for (fs_type = ped_file_system_type_get_next (NULL); fs_type; fs_type = ped_file_system_type_get_next (fs_type)) { if (fs_type->ops->resize == NULL) continue; if (first) first = 0; else str_list_append (list, ", "); str_list_append (list, fs_type->name); } str_list_append (list, "\n"); resize_fs_type_msg = str_list_convert (list); str_list_destroy (list);}static void_done_messages (){ free (flag_msg); free (mkfs_fs_type_msg); free (mkpart_fs_type_msg); free (resize_fs_type_msg); free (label_type_msg);}static void_init_bsd_menu_commands () { fdisk_command_register (fdisk_bsd_menu_commands, fdisk_command_create ( str_list_create_unique ("d", _("d"), NULL), do_rm, str_list_create (_(" d delete a BSD partition"),NULL), NULL, 1)); fdisk_command_register (fdisk_bsd_menu_commands, fdisk_command_create ( str_list_create_unique ("l", _("l"), NULL), do_list_systypes, str_list_create (_(" l list known filesystem types"),NULL), NULL, 1)); fdisk_command_register (fdisk_bsd_menu_commands, fdisk_command_create ( str_list_create_unique ("m", _("m"), NULL), do_help, str_list_create (_(" m print this menu"),NULL), NULL, 1)); fdisk_command_register (fdisk_bsd_menu_commands, fdisk_command_create ( str_list_create_unique ("n", _("n"), NULL), do_mkpart, str_list_create (_(" n add a new BSD partition"),NULL), NULL, 1)); fdisk_command_register (fdisk_bsd_menu_commands, fdisk_command_create ( str_list_create_unique ("p", _("p"), NULL), do_print, str_list_create (_(" p print the BSD partition table"),NULL), NULL, 1));#if 0 fdisk_command_register (fdisk_bsd_menu_commands, fdisk_command_create ( str_list_create_unique ("q", _("q"), NULL), do_quit, str_list_create (_(" q quit without saving changes"),NULL), NULL, 1));#endif fdisk_command_register (fdisk_bsd_menu_commands, fdisk_command_create ( str_list_create_unique ("r", _("r"), NULL), NULL, str_list_create (_(" r return to the main menu"),NULL), NULL, 1));#if 0 /* TODO: This should be available only on msdos and sun disklabels */ fdisk_command_register (fdisk_bsd_menu_commands, fdisk_command_create ( str_list_create_unique ("t", _("t"), NULL), do_change_system_type, str_list_create (_(" t change a partition's filesystem id"),NULL), NULL, 1));#endif fdisk_command_register (fdisk_bsd_menu_commands, fdisk_command_create ( str_list_create_unique ("u", _("u"), NULL), do_unit, str_list_create (_(" u change display/entry units"),NULL), NULL, 1)); fdisk_command_register (fdisk_bsd_menu_commands, fdisk_command_create ( str_list_create_unique ("w", _("w"), NULL), do_commit, str_list_create (_(" w write disklabel to disk"),NULL), NULL, 1)); }static void_init_ex_menu_commands () { if (!fdisk_compatibility_mode) { fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("v", _("v"), NULL), do_move, str_list_create (_(" v move a partition"),NULL), str_list_create (_(number_msg), _(start_end_msg), NULL), 1)); fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("c", _("c"), NULL), do_rescue, str_list_create (_(" c rescue a lost partition"),NULL), str_list_create (_(start_end_msg), NULL), 1)); fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("z", _("z"), NULL), do_resize, str_list_create (_(" z resize a partition and its file system"),NULL), NULL, 1)); fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("h", _("h"), NULL), do_check, str_list_create (_(" h check the consistency of a partition"),NULL), NULL, 1)); fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("o", _("o"), NULL), do_copy, str_list_create (_(" o copy the partition over another partition"),NULL), NULL, 1)); fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("k", _("k"), NULL), do_mkfs, str_list_create (_(" k creates a filesystem on a partition"),NULL), NULL, 1)); } if (fdisk_compatibility_mode) fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("b", _("b"), NULL), do_move_partition_beginning, str_list_create (_(" b move beginning of data in a partition"),NULL), NULL, 1)); if (fdisk_compatibility_mode) fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("c", _("c"), NULL), do_change_cylinders, str_list_create (_(" c change number of cylinders"),NULL), NULL, 1)); if (fdisk_compatibility_mode) fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("e", _("e"), NULL), do_eprint, str_list_create (_(" e list extended partitions"),NULL), NULL, 1)); fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("f", _("f"), NULL), do_fix_partition_order, str_list_create (_(" f fix partition order"),NULL), NULL, 1)); fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("g", _("g"), NULL), do_dvh_mklabel, str_list_create (_(" g create an IRIX (SGI) partition table"),NULL), NULL, 1)); if (fdisk_compatibility_mode) { fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("h", _("h"), NULL), do_change_heads, str_list_create (_(" h change number of heads"),NULL), NULL, 1)); fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("m", _("m"), NULL), do_help, str_list_create (_(" m print this menu"),NULL), NULL, 1)); } if (fdisk_compatibility_mode) fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("p", _("p"), NULL), do_xprint, str_list_create (_(" p print the partition table"),NULL), NULL, 1)); else fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("p", _("p"), NULL), do_print, str_list_create (_(" p print the partition table"),NULL), NULL, 1)); fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("q", _("q"), NULL), do_quit, str_list_create (_(" q quit without saving changes"),NULL), NULL, 1)); fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("r", _("r"), NULL), NULL, str_list_create (_(" r return to the main menu"),NULL), NULL, 1)); if (fdisk_compatibility_mode) fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("s", _("s"), NULL), do_change_sectors, str_list_create (_(" s change number of sectors/track"),NULL), NULL, 1)); if (fdisk_compatibility_mode) fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("v", _("v"), NULL), do_verify, str_list_create (_(" v verify the partition table"),NULL), NULL, 1)); fdisk_command_register (fdisk_ex_menu_commands, fdisk_command_create ( str_list_create_unique ("w", _("w"), NULL), do_commit, str_list_create (_(" w write table to disk and exit"),NULL), NULL, 1)); }static void_init_main_menu_commands () { fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("a", _("a"), NULL), do_toggle_boot_flag, str_list_create (_(" a toggle bootable flag"),NULL), NULL, 1)); fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("b", _("b"), NULL), do_edit_bsd_disklabel, str_list_create (_(" b edit bsd disklabel"),NULL), NULL, 1)); fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("d", _("d"), NULL), do_rm, str_list_create (_(" d delete a partition"),NULL), NULL, 1)); fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("l", _("l"), NULL), do_list_systypes, str_list_create (_(" l list known partition types"),NULL), NULL, 1)); fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("m", _("m"), NULL), do_help, str_list_create (_(" m print this menu"),NULL), NULL, 1)); fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("n", _("n"), NULL), do_mkpart, str_list_create (_(" n add a new partition"),NULL), NULL, 1)); fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("o", _("o"), NULL), do_msdos_mklabel, str_list_create (_(" o create a new empty DOS partition table"),NULL), NULL, 1)); fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("p", _("p"), NULL), do_print, str_list_create (_(" p print the partition table"),NULL), NULL, 1)); fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("q", _("q"), NULL), do_quit, str_list_create (_(" q quit without saving changes"),NULL), NULL, 1)); fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("s", _("s"), NULL), do_sun_mklabel, str_list_create (_(" s create a new empty Sun disklabel"),NULL), NULL, 1)); /* TODO: This should be available only on msdos and sun disklabels */ fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("t", _("t"), NULL), do_change_system_type, str_list_create (_(" t change a partition's system id"),NULL), NULL, 1)); fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("u", _("u"), NULL), do_unit, str_list_create (_(" u change display/entry units"),NULL), NULL, 1)); if (fdisk_compatibility_mode) fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("v", _("v"), NULL), do_verify, str_list_create (_(" v verify the partition table"),NULL), NULL, 1)); fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("w", _("w"), NULL), do_commit, str_list_create (_(" w write table to disk and exit"),NULL), NULL, 1)); fdisk_command_register (fdisk_main_menu_commands, fdisk_command_create ( str_list_create_unique ("x", _("x"), NULL), do_ex_menu, str_list_create (_(" x extra functionality (experts only)"),NULL), NULL, 1));}static void_done_commands (){ FdiskCommand** walk; for (walk = fdisk_main_menu_commands; *walk; walk++) { fdisk_command_destroy (*walk); *walk = NULL; } for (walk = fdisk_ex_menu_commands; *walk; walk++) { fdisk_command_destroy (*walk); *walk = NULL; } for (walk = fdisk_bsd_menu_commands; *w
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?