diff options
author | Karel Zak <kzak@redhat.com> | 2006-12-07 00:25:41 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2006-12-07 00:25:41 +0100 |
commit | eb63b9b8f4cecb34c2478282567862bc48ef256d (patch) | |
tree | 99243f8eecb44c2bb6a559982b99c680fcb649e7 /fdisk | |
parent | 7eda085c41faa3445b4b168ce78ab18dab87d98a (diff) | |
download | util-linux-eb63b9b8f4cecb34c2478282567862bc48ef256d.tar.gz |
Imported from util-linux-2.10f tarball.
Diffstat (limited to 'fdisk')
-rw-r--r-- | fdisk/cfdisk.c | 13 | ||||
-rw-r--r-- | fdisk/common.h | 1 | ||||
-rw-r--r-- | fdisk/fdisk.8 | 11 | ||||
-rw-r--r-- | fdisk/fdisk.c | 77 | ||||
-rw-r--r-- | fdisk/fdisk.h | 5 | ||||
-rw-r--r-- | fdisk/fdiskbsdlabel.c | 55 | ||||
-rw-r--r-- | fdisk/fdiskbsdlabel.h | 2 | ||||
-rw-r--r-- | fdisk/fdisksgilabel.c | 2 | ||||
-rw-r--r-- | fdisk/fdisksunlabel.c | 2 | ||||
-rw-r--r-- | fdisk/sfdisk.c | 25 |
10 files changed, 117 insertions, 76 deletions
diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c index 4fe759b6..4d0eb7ea 100644 --- a/fdisk/cfdisk.c +++ b/fdisk/cfdisk.c @@ -69,7 +69,6 @@ #endif #include <signal.h> #include <math.h> -#include <locale.h> #include <string.h> #include <sys/stat.h> #include <sys/ioctl.h> @@ -89,7 +88,6 @@ typedef long ext2_loff_t; extern ext2_loff_t ext2_llseek(unsigned int fd, ext2_loff_t offset, unsigned int origin); -#include "../version.h" #define VERSION UTIL_LINUX_VERSION #define DEFAULT_DEVICE "/dev/hda" @@ -1316,7 +1314,7 @@ void new_part(int i) int num_sects = last - first + 1; int len, ext, j; char *errmsg; - + double sectors_per_MB = K*K / 512.0; if (p_info[i].num == PRI_OR_LOG) { static struct MenuItem menuPartType[]= @@ -1341,7 +1339,7 @@ void new_part(int i) else print_warning(_("!!! Internal error !!!")); - sprintf(def, "%.2f", ceiling(num_sects/(K*0.02))/100); + sprintf(def, "%.2f", num_sects/sectors_per_MB); mvaddstr(COMMAND_LINE_Y, COMMAND_LINE_X, _("Size (in MB): ")); if ((len = get_string(response, LINE_LENGTH, def)) <= 0 && len != GS_DEFAULT) @@ -2367,8 +2365,13 @@ void draw_partition(int i) } if (p_info[i].id > 0) { + char *dbn = my_basename(disk_device); + int l = strlen(dbn); + int digit_last = isdigit(dbn[l-1]); + mvprintw(y, NAME_START, - "%s%d", my_basename(disk_device), p_info[i].num+1); + "%s%s%d", dbn, (digit_last ? "p" : ""), + p_info[i].num+1); if (p_info[i].flags) { if (p_info[i].flags == ACTIVE_FLAG) mvaddstr(y, FLAGS_START, _("Boot")); diff --git a/fdisk/common.h b/fdisk/common.h index d9fa4e8e..a79d9acc 100644 --- a/fdisk/common.h +++ b/fdisk/common.h @@ -6,3 +6,4 @@ struct systypes { }; extern struct systypes i386_sys_types[]; + diff --git a/fdisk/fdisk.8 b/fdisk/fdisk.8 index e26baf1c..2a8c85e8 100644 --- a/fdisk/fdisk.8 +++ b/fdisk/fdisk.8 @@ -7,7 +7,7 @@ fdisk \- Partition table manipulator for Linux .SH SYNOPSIS .BI "fdisk [\-u] " device .sp -.BI "fdisk \-l [\-u] " "device ..." +.BI "fdisk \-l [\-u] [" "device ..." ] .sp .BI "fdisk \-s " "partition ..." .sp @@ -175,11 +175,10 @@ Print version number of program and exit. .TP .B \-l -List the partition tables for -.BR /dev/hd[a-d] , -.BR /dev/sd[a-h] , -.BR /dev/ed[a-d] , -and then exit. +List the partition tables for the specified devices and then exit. +If no devices are given, those mentioned in +.I /proc/partitions +(if that exists) are used. .TP .B \-u When listing partition tables, give sizes in sectors instead diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 8270d344..56caa9a1 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -94,7 +94,6 @@ #include <setjmp.h> #include <errno.h> #include <getopt.h> -#include <locale.h> #include "nls.h" #include <sys/stat.h> @@ -110,7 +109,6 @@ #include "fdisksgilabel.h" #include "fdiskaixlabel.h" -#include "../version.h" #include "../defines.h" #ifdef HAVE_blkpg_h #include <linux/blkpg.h> @@ -264,13 +262,6 @@ void fatal(enum failure why) " or: fdisk /dev/rd/c0d0 or: fdisk /dev/ida/c0d0 (for RAID devices)\n" " ...\n"); break; - case no_device: - message = _("A disk block device is needed.\n"); - break; - case no_partition: - message =_("Given name does not refer to a partition,\n" - "or maybe not even to a block device.\n"); - break; case unable_to_open: sprintf(error, _("Unable to open %s\n"), disk_device); break; @@ -805,7 +796,7 @@ read_hex(struct systypes *sys) } /* - * Print the message MESG, then read an integer between LOW and HIGH. + * Print the message MESG, then read an integer between LOW and HIGH (inclusive). * If the user hits Enter, DFLT is returned. * Answers like +10 are interpreted as offsets from BASE. * @@ -1243,10 +1234,10 @@ void x_list_table(int extend) q = part_table; printf(_("\nDisk %s: %d heads, %d sectors, %d cylinders\n\n"), disk_device, heads, sectors, cylinders); - printf(_("Nr AF Hd Sec Cyl Hd Sec Cyl Start Size ID\n")); + printf(_("Nr AF Hd Sec Cyl Hd Sec Cyl Start Size ID\n")); for (i = 0 ; i < partitions; i++) if ((p = q[i]) != NULL) { - printf("%2d %02x%4d%4d%5d%4d%4d%5d%8d%8d %02x\n", + printf("%2d %02x%4d%4d%5d%4d%4d%5d%9d%9d %02x\n", i + 1, p->boot_ind, p->head, sector(p->sector), cylinder(p->sector, p->cyl), p->end_head, @@ -1370,7 +1361,7 @@ void verify(void) void add_partition(int n, int sys) { - char mesg[48]; + char mesg[256]; /* 48 does not suffice in Japanese */ int i, read = 0; struct partition *p = part_table[n], *q = part_table[ext_index]; uint start, stop = 0, limit, temp, @@ -1563,7 +1554,7 @@ void new_partition(void) void write_table(void) { - int i, error = 0; + int i; changed[3] = changed[0] || changed[1] || changed[2] || changed[3]; if (!sun_label && !sgi_label) { @@ -1588,6 +1579,13 @@ void write_table(void) } printf(_("The partition table has been altered!\n\n")); + reread_partition_table(1); +} + +void +reread_partition_table(int leave) { + int error = 0; + int i; printf(_("Calling ioctl() to re-read partition table.\n")); sync(); @@ -1604,12 +1602,6 @@ void write_table(void) error = errno; } - close(fd); - - printf(_("Syncing disks.\n")); - sync(); - sleep(4); /* for sync() */ - if (i < 0) printf(_("Re-read table failed with error %d: %s.\nReboot your " "system to ensure the partition table is updated.\n"), @@ -1621,7 +1613,14 @@ void write_table(void) "partitions, please see the fdisk manual page for additional\n" "information.\n")); - exit(0); + if (leave) { + close(fd); + + printf(_("Syncing disks.\n")); + sync(); + sleep(4); /* for sync() */ + exit(!!i); + } } #define MAX_PER_LINE 16 @@ -1693,7 +1692,7 @@ void xselect(void) move_begin(get_partition(0, partitions)); break; case 'c': - cylinders = read_int(1, cylinders, 65535, + cylinders = read_int(1, cylinders, 131071, 0, _("Number of cylinders")); if (sun_label) sun_set_ncyl(cylinders); @@ -1826,6 +1825,32 @@ void try(char *device, int user_specified) } } +/* for fdisk -l: try all things in /proc/partitions + that look like a partition name (do not end in a digit) */ +void +tryprocpt() { + FILE *procpt; + char line[100], ptname[100], devname[120], *s; + int ma, mi, sz; + + procpt = fopen(PROC_PARTITIONS, "r"); + if (procpt == NULL) { + fprintf(stderr, _("cannot open %s\n"), PROC_PARTITIONS); + return; + } + + while (fgets(line, sizeof(line), procpt)) { + if (sscanf (line, " %d %d %d %[^\n]\n", + &ma, &mi, &sz, ptname) != 4) + continue; + for(s = ptname; *s; s++); + if (isdigit(s[-1])) + continue; + sprintf(devname, "/dev/%s", ptname); + try(devname, 1); + } +} + int dir_exists(char *dirname) { struct stat statbuf; @@ -1837,8 +1862,7 @@ void dummy(int *kk) {} int -main(int argc, char **argv) -{ +main(int argc, char **argv) { int j, c; int optl = 0, opts = 0; int user_set_sector_size = 0; @@ -1892,7 +1916,6 @@ main(int argc, char **argv) #endif if (optl) { - listing = 1; nowarn = 1; type_open = O_RDONLY; if (argc > optind) { @@ -1900,11 +1923,13 @@ main(int argc, char **argv) /* avoid gcc warning: variable `k' might be clobbered by `longjmp' */ dummy(&k); + listing = 1; for(k=optind; k<argc; k++) try(argv[k], 1); } else { /* we no longer have default device names */ - fatal(usage2); + /* but, we can use /proc/partitions instead */ + tryprocpt(); } exit(0); } diff --git a/fdisk/fdisk.h b/fdisk/fdisk.h index ace1b0cd..551b02f6 100644 --- a/fdisk/fdisk.h +++ b/fdisk/fdisk.h @@ -49,7 +49,7 @@ struct partition { enum failure {usage, usage2, ioctl_error, unable_to_open, unable_to_read, unable_to_seek, - unable_to_write, out_of_memory, no_partition, no_device}; + unable_to_write, out_of_memory}; enum action {fdisk, require, try_only, create_empty}; @@ -68,6 +68,7 @@ extern void list_types(struct systypes *sys); extern int read_line (void); extern char read_char(char *mesg); extern int read_hex(struct systypes *sys); +extern void reread_partition_table(int leave); uint read_int(uint low, uint dflt, uint high, uint base, char *mesg); #define PLURAL 0 @@ -83,3 +84,5 @@ extern int btrydev (char * dev); /* prototypes for fdisksgilabel.c */ extern int valid_part_table_flag(unsigned char *b); + +#define PROC_PARTITIONS "/proc/partitions" diff --git a/fdisk/fdiskbsdlabel.c b/fdisk/fdiskbsdlabel.c index 64a79273..980bc38c 100644 --- a/fdisk/fdiskbsdlabel.c +++ b/fdisk/fdiskbsdlabel.c @@ -75,7 +75,7 @@ static int xbsd_initlabel (struct partition *p, struct xbsd_disklabel *d, int p static int xbsd_readlabel (struct partition *p, struct xbsd_disklabel *d); static int xbsd_writelabel (struct partition *p, struct xbsd_disklabel *d); static void sync_disks (void); -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) static int xbsd_translate_fstype (int linux_type); static void xbsd_link_part (void); #endif @@ -85,7 +85,7 @@ void alpha_bootblock_checksum (char *boot); static struct xbsd_disklabel xbsd_dlabel; static char buffer[BSD_BBSIZE]; -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) static struct partition *xbsd_part; static int xbsd_part_index; #endif @@ -111,13 +111,13 @@ bmenu (void) puts (_(" n add a new BSD partition")); puts (_(" p print BSD partition table")); puts (_(" q quit without saving changes")); -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) puts (_(" r return to main menu")); #endif puts (_(" s show complete disklabel")); puts (_(" t change a partition's filesystem id")); puts (_(" w write disklabel to disk")); -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) puts (_(" x link BSD partition to non-BSD partition")); #endif } @@ -134,7 +134,7 @@ is_netbsd_partition_type(int type) { void bselect (void) { -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) int t, ss; for (t=0; t<4; t++) @@ -203,7 +203,7 @@ bselect (void) { case 'w': xbsd_write_disklabel (); break; -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) case 'r': return; case 'x': @@ -235,33 +235,35 @@ static void xbsd_new_part (void) { uint begin, end; - char mesg[48]; + char mesg[256]; int i; if (!xbsd_check_new_partition (&i)) return; -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) begin = get_start_sect(xbsd_part); end = begin + get_nr_sects(xbsd_part) - 1; #elif defined (__alpha__) || defined (__powerpc__) begin = 0; - end = xbsd_dlabel.d_secperunit; + end = xbsd_dlabel.d_secperunit - 1; #endif sprintf (mesg, _("First %s"), str_units(SINGULAR)); begin = read_int (cround (begin), cround (begin), cround (end), 0, mesg); - sprintf (mesg, _("Last %s or +size or +sizeM or +sizeK"), str_units(SINGULAR)); + if (display_in_cyl_units) + begin = (begin - 1) * units_per_sector; + + sprintf (mesg, _("Last %s or +size or +sizeM or +sizeK"), + str_units(SINGULAR)); end = read_int (cround (begin), cround (end), cround (end), cround (begin), mesg); if (display_in_cyl_units) - { - begin = (begin - 1) * units_per_sector; end = end * units_per_sector - 1; - } + xbsd_dlabel.d_partitions[i].p_size = end - begin + 1; xbsd_dlabel.d_partitions[i].p_offset = begin; xbsd_dlabel.d_partitions[i].p_fstype = BSD_FS_UNUSED; @@ -277,7 +279,7 @@ xbsd_print_disklabel (int show_all) if (show_all) { -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) fprintf(f, "# %s%d:\n", disk_device, xbsd_part_index+1); #elif defined (__alpha__) fprintf(f, "# %s:\n", disk_device); @@ -374,13 +376,14 @@ xbsd_print_disklabel (int show_all) static void xbsd_write_disklabel (void) { -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) printf (_("Writing disklabel to %s%d.\n"), disk_device, xbsd_part_index+1); xbsd_writelabel (xbsd_part, &xbsd_dlabel); #elif defined (__alpha__) printf (_("Writing disklabel to %s.\n"), disk_device); xbsd_writelabel (NULL, &xbsd_dlabel); #endif + reread_partition_table(0); /* no exit yet */ } static int @@ -388,7 +391,7 @@ xbsd_create_disklabel (void) { char c; -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) fprintf (stderr, _("%s%d contains no disklabel.\n"), disk_device, xbsd_part_index+1); #elif defined (__alpha__) @@ -398,7 +401,7 @@ xbsd_create_disklabel (void) while (1) if ((c = tolower (read_char (_("Do you want to create a disklabel? (y/n) ")))) == 'y') { -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) if (xbsd_initlabel (xbsd_part, &xbsd_dlabel, xbsd_part_index) == 1) #elif defined (__alpha__) || defined (__powerpc__) if (xbsd_initlabel (NULL, &xbsd_dlabel, 0) == 1) @@ -529,7 +532,7 @@ xbsd_write_bootstrap (void) bcopy (&dl, d, sizeof (struct xbsd_disklabel)); -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) sector = get_start_sect(xbsd_part); #elif defined (__powerpc__) sector = 0; @@ -543,7 +546,7 @@ xbsd_write_bootstrap (void) if (BSD_BBSIZE != write (fd, buffer, BSD_BBSIZE)) fatal (unable_to_write); -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) printf (_("Bootstrap installed on %s%d.\n"), disk_device, xbsd_part_index+1); #elif defined (__alpha__) printf (_("Bootstrap installed on %s.\n"), disk_device); @@ -564,7 +567,7 @@ xbsd_change_fstype (void) static int xbsd_get_part_index (int max) { - char prompt[40]; + char prompt[256]; char l; sprintf (prompt, _("Partition (a-%c): "), 'a' + max - 1); @@ -647,7 +650,7 @@ xbsd_initlabel (struct partition *p, struct xbsd_disklabel *d, int pindex) d -> d_subtype = BSD_DSTYPE_INDOSPART & pindex; #endif -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) d -> d_flags = BSD_D_DOSPART; #else d -> d_flags = 0; @@ -670,7 +673,7 @@ xbsd_initlabel (struct partition *p, struct xbsd_disklabel *d, int pindex) d -> d_bbsize = BSD_BBSIZE; d -> d_sbsize = BSD_SBSIZE; -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) d -> d_npartitions = 4; pp = &d -> d_partitions[2]; /* Partition C should be the NetBSD partition */ pp -> p_offset = get_start_sect(p); @@ -696,7 +699,7 @@ xbsd_readlabel (struct partition *p, struct xbsd_disklabel *d) { int t, sector; -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) sector = (p ? get_start_sect(p) : 0); #elif defined (__alpha__) sector = 0; @@ -730,7 +733,7 @@ xbsd_writelabel (struct partition *p, struct xbsd_disklabel *d) { int sector; -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) sector = get_start_sect(p) + BSD_LABELSECTOR; #elif defined (__alpha__) || defined (__powerpc__) sector = BSD_LABELSECTOR; @@ -771,7 +774,7 @@ sync_disks (void) sleep (4); } -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) static int xbsd_translate_fstype (int linux_type) { @@ -810,7 +813,7 @@ xbsd_link_part (void) #if defined (__alpha__) -#if 0 +#if !defined(__GLIBC__) typedef unsigned long long u_int64_t; #endif diff --git a/fdisk/fdiskbsdlabel.h b/fdisk/fdiskbsdlabel.h index b9f2c9c3..1a06a08d 100644 --- a/fdisk/fdiskbsdlabel.h +++ b/fdisk/fdiskbsdlabel.h @@ -43,7 +43,7 @@ #define BSD_LINUX_BOOTDIR "/usr/ucb/mdec" -#if defined (i386) || defined (sparc) +#if defined (i386) || defined (__sparc__) || defined (__arm__) #define BSD_LABELSECTOR 1 #define BSD_LABELOFFSET 0 #elif defined (__alpha__) || defined (__powerpc__) diff --git a/fdisk/fdisksgilabel.c b/fdisk/fdisksgilabel.c index 25ed31a3..b2870e65 100644 --- a/fdisk/fdisksgilabel.c +++ b/fdisk/fdisksgilabel.c @@ -671,7 +671,7 @@ sgi_delete_partition( int i ) void sgi_add_partition( int n, int sys ) { - char mesg[48]; + char mesg[256]; int first=0, last=0; if( n == 10 ) { diff --git a/fdisk/fdisksunlabel.c b/fdisk/fdisksunlabel.c index d484e793..48916ad4 100644 --- a/fdisk/fdisksunlabel.c +++ b/fdisk/fdisksunlabel.c @@ -472,7 +472,7 @@ void add_sun_partition(int n, int sys) uint starts[8], lens[8]; int whole_disk = 0; - char mesg[48]; + char mesg[256]; int i, first, last; if (sunlabel->partitions[n].num_sectors && sunlabel->infos[n].id) { diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c index d25543dd..7bf7fd83 100644 --- a/fdisk/sfdisk.c +++ b/fdisk/sfdisk.c @@ -32,7 +32,7 @@ #define PROGNAME "sfdisk" #define VERSION "3.07" -#define DATE "980518" +#define DATE "990908" #include <stdio.h> #include <stdlib.h> /* atoi, free */ @@ -48,7 +48,6 @@ #include <linux/unistd.h> /* _syscall */ #include <linux/hdreg.h> /* HDIO_GETGEO */ #include <linux/fs.h> /* BLKGETSIZE */ -#include <locale.h> #include "nls.h" #include "common.h" @@ -829,7 +828,7 @@ void out_partition_header(char *dev, int format, struct geometry G) { if (dump) { printf(_("# partition table of %s\n"), dev); - printf(_("unit: sectors\n\n")); + printf("unit: sectors\n\n"); return; } @@ -929,12 +928,12 @@ out_partition(char *dev, int format, struct part_desc *p, size = p->size; if (dump) { - printf(_(" start=%9lu"), start); - printf(_(", size=%8lu"), size); + printf(" start=%9lu", start); + printf(", size=%8lu", size); if (p->ptype == DOS_TYPE) { - printf(_(", Id=%2x"), p->p.sys_type); + printf(", Id=%2x", p->p.sys_type); if (p->p.bootable == 0x80) - printf(_(", bootable")); + printf(", bootable"); } printf("\n"); return; @@ -1012,16 +1011,24 @@ out_partition(char *dev, int format, struct part_desc *p, void out_partitions(char *dev, struct disk_desc *z) { + struct part_desc *p; int pno, format = 0; if (z->partno == 0) printf(_("No partitions found\n")); else { - if (get_fdisk_geometry(&(z->partitions[0]))) - printf(_("Warning: The first partition looks like it was made\n" + for (pno=0; pno < z->partno; pno++) { + p = &(z->partitions[pno]); + if (p->size != 0 && p->p.sys_type != 0) { + if (get_fdisk_geometry(p)) + printf( + _("Warning: The first partition looks like it was made\n" " for C/H/S=*/%ld/%ld (instead of %ld/%ld/%ld).\n" "For this listing I'll assume that geometry.\n"), F.heads, F.sectors, B.cylinders, B.heads, B.sectors); + break; + } + } out_partition_header(dev, format, F); for(pno=0; pno < z->partno; pno++) { out_partition(dev, format, &(z->partitions[pno]), z, F); |