⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfdisk.c

📁 Util-linux 软件包包含许多工具。其中比较重要的是加载、卸载、格式化、分区和管理硬盘驱动器
💻 C
📖 第 1 页 / 共 5 页
字号:
    else	fp_printf(fp, "%2d %-7.7s", p->num+1,		  IS_LOGICAL(p->num) ? _("Logical") : _("Primary"));    fp_printf(fp, " ");    fp_printf(fp, "%11lld%c", p->first_sector,	      ((p->first_sector/cylinder_size) !=	       ((float)p->first_sector/cylinder_size) ?	       '*' : ' '));    fp_printf(fp, "%11lld%c", p->last_sector,	      (((p->last_sector+1)/cylinder_size) !=	       ((float)(p->last_sector+1)/cylinder_size) ?	       '*' : ' '));    fp_printf(fp, "%6ld%c", p->offset,	      ((((p->first_sector == 0 || IS_LOGICAL(p->num)) &&		 (p->offset != sectors)) ||		(p->first_sector != 0 && IS_PRIMARY(p->num) &&		 p->offset != 0)) ?	       '#' : ' '));    size = p->last_sector - p->first_sector + 1;    fp_printf(fp, "%11lld%c", size,	      ((size/cylinder_size) != ((float)size/cylinder_size) ?	       '*' : ' '));    /* fp_printf(fp, " "); */    if (p->id == UNUSABLE)	sprintf(part_str, "%.15s", _("Unusable"));    else if (p->id == FREE_SPACE)	sprintf(part_str, "%.15s", _("Free Space"));    else if (partition_type_name(p->id))	sprintf(part_str, "%.15s (%02X)", partition_type_name(p->id), p->id);    else	sprintf(part_str, "%.15s (%02X)", _("Unknown"), p->id);    fp_printf(fp, "%-20.20s", part_str);    fp_printf(fp, " ");    if (p->flags == ACTIVE_FLAG)	fp_printf(fp, _("Boot"), p->flags);    else if (p->flags != 0)	fp_printf(fp, _("(%02X)"), p->flags);    else	fp_printf(fp, _("None"), p->flags);    fp_printf(fp, "\n");}static voidprint_p_info(void) {    char fname[LINE_LENGTH];    FILE *fp;    int i, to_file, pext = is_extended(ext_info.id);    if (print_only) {	fp = stdout;	to_file = TRUE;    } else {	mvaddstr(COMMAND_LINE_Y, COMMAND_LINE_X,		 _("Enter filename or press RETURN to display on screen: "));	if ((to_file = get_string(fname, LINE_LENGTH, NULL)) < 0)	    return;	if (to_file) {	    if ((fp = fopen(fname, "w")) == NULL) {		char errstr[LINE_LENGTH];		sprintf(errstr, _("Cannot open file '%s'"), fname);		print_warning(errstr);		return;	    }	} else {	    fp = NULL;	    erase();	    move(0, 0);	}    }    fp_printf(fp, _("Partition Table for %s\n"), disk_device);    fp_printf(fp, "\n");    fp_printf(fp, _("               First       Last\n"));    fp_printf(fp, _(" # Type       Sector      Sector   Offset    Length   Filesystem Type (ID) Flag\n"));    fp_printf(fp, _("-- ------- ----------- ----------- ------ ----------- -------------------- ----\n"));    for (i = 0; i < num_parts; i++) {	if (pext && (p_info[i].first_sector >= ext_info.first_sector)) {	    print_p_info_entry(fp,&ext_info);	    pext = FALSE;	}	print_p_info_entry(fp, &(p_info[i]));    }    if (to_file) {	if (!print_only)	    fclose(fp);    } else {        menuContinue();    }}static voidprint_part_entry(FILE *fp, int num, partition_info *pi) {    long long first = 0, start = 0, end = 0, size = 0;    unsigned char ss, es, sh, eh;    int sc, ec;    int flags = 0, id = 0;    ss = sh = es = eh = 0;    sc = ec = 0;    if (pi != NULL) {	flags = pi->flags;	id = pi->id;	if (IS_LOGICAL(num))	    first = pi->offset;	else	    first = pi->first_sector + pi->offset;	start = pi->first_sector + pi->offset;	end = pi->last_sector;	size = end - start + 1;	set_hsc0(&sh, &ss, &sc, start);	set_hsc0(&eh, &es, &ec, end);    }    fp_printf(fp, "%2d  0x%02X %4d %4d %4d 0x%02X %4d %4d %4d %11lld %11lld\n",	      num+1, flags, sh, ss, sc, id, eh, es, ec, first, size);}static voidprint_part_table(void) {    int i, j, to_file;    char fname[LINE_LENGTH];    FILE *fp;    if (print_only) {	fp = stdout;	to_file = TRUE;    } else {	mvaddstr(COMMAND_LINE_Y, COMMAND_LINE_X,		 _("Enter filename or press RETURN to display on screen: "));	if ((to_file = get_string(fname, LINE_LENGTH, NULL)) < 0)	    return;	if (to_file) {	    if ((fp = fopen(fname, "w")) == NULL) {		char errstr[LINE_LENGTH];		sprintf(errstr, _("Cannot open file '%s'"), fname);		print_warning(errstr);		return;	    }	} else {	    fp = NULL;	    erase();	    move(0, 0);	}    }    fp_printf(fp, _("Partition Table for %s\n"), disk_device);    fp_printf(fp, "\n");    /* Three-line heading. Read "Start Sector" etc vertically. */    fp_printf(fp, _("         ---Starting---      ----Ending----    Start     Number of\n"));    fp_printf(fp, _(" # Flags Head Sect Cyl   ID  Head Sect Cyl     Sector    Sectors\n"));    fp_printf(fp, _("-- ----- ---- ---- ---- ---- ---- ---- ---- ----------- -----------\n"));    for (i = 0; i < 4; i++) {	for (j = 0;	     j < num_parts && (p_info[j].id <= 0 || p_info[j].num != i);	     j++);	if (j < num_parts) {	    print_part_entry(fp, i, &(p_info[j]));	} else if (is_extended(ext_info.id) && ext_info.num == i) {	    print_part_entry(fp, i, &ext_info);	} else {	    print_part_entry(fp, i, NULL);	}    }    for (i = 0; i < num_parts; i++)	if (IS_LOGICAL(p_info[i].num))	    print_part_entry(fp, p_info[i].num, &(p_info[i]));    if (to_file) {	if (!print_only)	    fclose(fp);    } else {        menuContinue();    }}static voidprint_tables(void) {    int done = FALSE;    static struct MenuItem menuFormat[]=    {        { 'r', N_("Raw"), N_("Print the table using raw data format") },        { 's', N_("Sectors"), N_("Print the table ordered by sectors") },        { 't', N_("Table"), N_("Just print the partition table") },        { ESC, N_("Cancel"), N_("Don't print the table") },        { 0, NULL, NULL }    };        while (!done)	switch ( toupper(menuSimple( menuFormat, 2)) ) {	case 'R':	    print_raw_table();	    done = TRUE;	    break;	case 'S':	    print_p_info();	    done = TRUE;	    break;	case 'T':	    print_part_table();	    done = TRUE;	    break;	case ESC:	    done = TRUE;	    break;	}}#define END_OF_HELP "EOHS!"static voiddisplay_help(void) {    char *help_text[] = {	N_("Help Screen for cfdisk"),	"",	N_("This is cfdisk, a curses based disk partitioning program, which"),	N_("allows you to create, delete and modify partitions on your hard"),	N_("disk drive."),	"",	N_("Copyright (C) 1994-1999 Kevin E. Martin & aeb"),	"",	N_("Command      Meaning"),	N_("-------      -------"),	N_("  b          Toggle bootable flag of the current partition"),	N_("  d          Delete the current partition"),	N_("  g          Change cylinders, heads, sectors-per-track parameters"),	N_("             WARNING: This option should only be used by people who"),	N_("             know what they are doing."),	N_("  h          Print this screen"),	N_("  m          Maximize disk usage of the current partition"),	N_("             Note: This may make the partition incompatible with"),	N_("             DOS, OS/2, ..."),	N_("  n          Create new partition from free space"),	N_("  p          Print partition table to the screen or to a file"),	N_("             There are several different formats for the partition"),	N_("             that you can choose from:"),	N_("                r - Raw data (exactly what would be written to disk)"),	N_("                s - Table ordered by sectors"),	N_("                t - Table in raw format"),	N_("  q          Quit program without writing partition table"),	N_("  t          Change the filesystem type"),	N_("  u          Change units of the partition size display"),	N_("             Rotates through MB, sectors and cylinders"),	N_("  W          Write partition table to disk (must enter upper case W)"),        N_("             Since this might destroy data on the disk, you must"),	N_("             either confirm or deny the write by entering `yes' or"),	N_("             `no'"),	N_("Up Arrow     Move cursor to the previous partition"),	N_("Down Arrow   Move cursor to the next partition"),	N_("CTRL-L       Redraws the screen"),	N_("  ?          Print this screen"),	"",	N_("Note: All of the commands can be entered with either upper or lower"),	N_("case letters (except for Writes)."),	END_OF_HELP    };    int cur_line = 0;    FILE *fp = NULL;    erase();    move(0, 0);    while (strcmp(help_text[cur_line], END_OF_HELP)) {	if (help_text[cur_line][0])	    fp_printf(fp, "%s\n", _(help_text[cur_line]));	else	    fp_printf(fp, "\n");	cur_line++;    }    menuContinue();}static intchange_geometry(void) {    int ret_val = FALSE;    int done = FALSE;    char def[LINE_LENGTH];    char response[LINE_LENGTH];    long long tmp_val;    int i;    while (!done) {        static struct MenuItem menuGeometry[]=        {            { 'c', N_("Cylinders"), N_("Change cylinder geometry") },            { 'h', N_("Heads"), N_("Change head geometry") },            { 's', N_("Sectors"), N_("Change sector geometry") },            { 'd', N_("Done"), N_("Done with changing geometry") },            { 0, NULL, NULL }        };	move(COMMAND_LINE_Y, COMMAND_LINE_X);	clrtoeol();	refresh();	clear_warning();	switch (toupper( menuSimple(menuGeometry, 3) )) {	case 'C':	    sprintf(def, "%llu", actual_size/cylinder_size);	    mvaddstr(COMMAND_LINE_Y, COMMAND_LINE_X,		     _("Enter the number of cylinders: "));	    i = get_string(response, LINE_LENGTH, def);	    if (i == GS_DEFAULT) {		user_cylinders = actual_size/cylinder_size;		ret_val = TRUE;	    } else if (i > 0) {		tmp_val = atoll(response);		if (tmp_val > 0) {		    user_cylinders = tmp_val;		    ret_val = TRUE;		} else		    print_warning(_("Illegal cylinders value"));	    }	    break;	case 'H':	    sprintf(def, "%d", heads);	    mvaddstr(COMMAND_LINE_Y, COMMAND_LINE_X,		     _("Enter the number of heads: "));	    if (get_string(response, LINE_LENGTH, def) > 0) {		tmp_val = atoll(response);		if (tmp_val > 0 && tmp_val <= MAX_HEADS) {		    user_heads = tmp_val;		    ret_val = TRUE;		} else		    print_warning(_("Illegal heads value"));	    }	    break;	case 'S':	    sprintf(def, "%d", sectors);	    mvaddstr(COMMAND_LINE_Y, COMMAND_LINE_X,		     _("Enter the number of sectors per track: "));	    if (get_string(response, LINE_LENGTH, def) > 0) {		tmp_val = atoll(response);		if (tmp_val > 0 && tmp_val <= MAX_SECTORS) {		    user_sectors = tmp_val;		    ret_val = TRUE;		} else		    print_warning(_("Illegal sectors value"));	    }	    break;	case ESC:	case 'D':	    done = TRUE;	    break;	default:	    putchar(BELL);	    break;	}	if (ret_val) {	    decide_on_geometry();	    draw_screen();	}    }    if (ret_val) {	long long disk_end;	disk_end = total_size-1;	if (p_info[num_parts-1].last_sector > disk_end) {	    while (p_info[num_parts-1].first_sector > disk_end) {		if (p_info[num_parts-1].id == FREE_SPACE ||		    p_info[num_parts-1].id == UNUSABLE)		    remove_part(num_parts-1);		else		    del_part(num_parts-1);	    }	    p_info[num_parts-1].last_sector = disk_end;	    if (ext_info.last_sector > disk_end)		ext_info.last_sector = disk_end;	} else if (p_info[num_parts-1].last_sector < disk_end) {	    if (p_info[num_parts-1].id == FREE_SPACE ||		p_info[num_parts-1].id == UNUSABLE) {		p_info[num_parts-1].last_sector = disk_end;	    } else {		insert_empty_part(num_parts,				  p_info[num_parts-1].last_sector+1,				  disk_end);	    }	}	/* Make sure the partitions are correct */	check_part_info();    }    return ret_val;}static voidchange_id(int i) {    char id[LINE_LENGTH], def[LINE_LENGTH];    int num_types = 0;    int num_across, num_down;    int len, new_id = ((p_info[i].id == LINUX) ? LINUX_SWAP : LINUX);    int y_start, y_end, row, row_min, row_max, row_offset, j, needmore;    for (j = 1; i386_sys_types[j].name; j++) ;    num_types = j-1;		/* do not count the Empty type */    num_across = COLS/COL_ID_WIDTH;    num_down = (((float)num_types)/num_across + 1);    y_start = COMMAND_LINE_Y - 1 - num_down;    if (y_start < 1) {	y_start = 1;	y_end = COMMAND_LINE_Y - 2;    } else {	if (y_start > DISK_TABLE_START+cur_part+4)	    y_start = DISK_TABLE_START+cur_part+4;	y_end = y_start + num_down - 1;    }    row_min = 1;    row_max = COMMAND_LINE_Y - 2;    row_offset = 0;    do {	for (j = y_start - 1; j <= y_end + 1; j++) {	    move(j, 0);	    clrtoeol();	}	needmore = 0;	for (j = 1; i386_sys_types[j].name; j++) {	    row = y_start + (j-1) % num_down - row_offset;	    if (row >= row_min && row <= row_max) {		move(row, ((j-1)/num_down)*COL_ID_WIDTH + 1);		printw("%02X %-20.20s",		       i386_sys_types[j].type,		       i386_sys_types[j].name);	    }	    if (row > row_max)		needmore = 1;	}	if (needmore)		menuContinue();	row_offset += (row_max - row_min + 1);    } while(needmore);    sprintf(def, "%02X", new_id);    mvaddstr(COMMAND_LINE_Y, COMMAND_LINE_X, _("Enter filesystem type: "));    if ((len = get_string(id, 2, def)) <= 0 && len != GS_DEFAULT)	return;    if (len != GS_DEFAULT) {	if (!isxdigit(id[0]))	    return;	new_id = (isdigit(id[0]) ? id[0] - '0' : tolower(id[0]) - 'a' + 10);	if (len == 2) {	    if (isxdigit(id[1]))		new_id = new_id*16 +		    (isdigit(id[1]) ? id[1] - '0' : tolower(id[1]) - 'a' + 10);	    else		return;	}    }    if (new_id == 0)	print_warning(_("Cannot change FS Type to empty"));    else if (is_extended(new_id))	print_warning(_("Cannot change FS Type to extended"));    else	p_info[i].id = new_id;}static voiddraw_partition(int i) {    int j;    int y = i + DISK_TABLE_S

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -