From eb63b9b8f4cecb34c2478282567862bc48ef256d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 7 Dec 2006 00:25:41 +0100 Subject: Imported from util-linux-2.10f tarball. --- fdisk/cfdisk.c | 13 +++++---- fdisk/common.h | 1 + fdisk/fdisk.8 | 11 ++++---- fdisk/fdisk.c | 77 ++++++++++++++++++++++++++++++++++----------------- fdisk/fdisk.h | 5 +++- fdisk/fdiskbsdlabel.c | 55 +++++++++++++++++++----------------- fdisk/fdiskbsdlabel.h | 2 +- fdisk/fdisksgilabel.c | 2 +- fdisk/fdisksunlabel.c | 2 +- fdisk/sfdisk.c | 25 +++++++++++------ 10 files changed, 117 insertions(+), 76 deletions(-) (limited to 'fdisk') 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 #include -#include #include #include #include @@ -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 #include #include -#include #include "nls.h" #include @@ -110,7 +109,6 @@ #include "fdisksgilabel.h" #include "fdiskaixlabel.h" -#include "../version.h" #include "../defines.h" #ifdef HAVE_blkpg_h #include @@ -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 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 #include /* atoi, free */ @@ -48,7 +48,6 @@ #include /* _syscall */ #include /* HDIO_GETGEO */ #include /* BLKGETSIZE */ -#include #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); -- cgit v1.2.3