diff options
author | LaMont Jones <lamont@debian.org> | 2011-01-31 20:15:49 -0700 |
---|---|---|
committer | LaMont Jones <lamont@debian.org> | 2011-01-31 20:15:49 -0700 |
commit | 11292d25510e67c83c6580401eccd42d6d6da931 (patch) | |
tree | ca5850da93c90f8798d7ff115e0124edffb8bb97 /fdisk | |
parent | 4f9e177060fb5ad6e574598aefdf2d5f50a8b54f (diff) | |
parent | 9f55bf3794ca98852dd1f352f993dea60d83a2e1 (diff) | |
download | util-linux-old-11292d25510e67c83c6580401eccd42d6d6da931.tar.gz |
Merge remote branch 'origin/master'
Conflicts:
mount/mount.8
mount/mount.c
Diffstat (limited to 'fdisk')
-rw-r--r-- | fdisk/cfdisk.c | 48 | ||||
-rw-r--r-- | fdisk/fdisk.c | 165 | ||||
-rw-r--r-- | fdisk/fdisk.h | 6 | ||||
-rw-r--r-- | fdisk/fdiskbsdlabel.c | 4 | ||||
-rw-r--r-- | fdisk/fdisksgilabel.c | 3 | ||||
-rw-r--r-- | fdisk/i386_sys_types.c | 3 |
6 files changed, 126 insertions, 103 deletions
diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c index 1e078a9f..7faa44a3 100644 --- a/fdisk/cfdisk.c +++ b/fdisk/cfdisk.c @@ -98,6 +98,7 @@ #endif #include "nls.h" +#include "rpmatch.h" #include "blkdev.h" #include "strutils.h" #include "common.h" @@ -150,7 +151,6 @@ #define COL_ID_WIDTH 25 -#define CR '\015' #define ESC '\033' #define DEL '\177' #define BELL '\007' @@ -427,8 +427,9 @@ fdexit(int ret) { */ static int get_string(char *str, int len, char *def) { - size_t cells = 0, i = 0; - int x, y, key; + size_t cells = 0; + ssize_t i = 0; + int x, y; int use_def = FALSE; wint_t c; @@ -445,13 +446,21 @@ get_string(char *str, int len, char *def) { refresh(); + while (1) { #if !defined(HAVE_SLCURSES_H) && !defined(HAVE_SLANG_SLCURSES_H) && \ defined(HAVE_LIBNCURSESW) && defined(HAVE_WIDECHAR) - while ((key = get_wch(&c)) != ERR && - c != '\r' && c != '\n' && c != KEY_ENTER) { + if (get_wch(&c) == ERR) { #else - while ((c = getch()) != '\n' && c != CR) { + if ((c = getch()) == ERR) { #endif + if (!isatty(STDIN_FILENO)) + exit(2); + else + break; + } + if (c == '\r' || c == '\n' || c == KEY_ENTER) + break; + switch (c) { case ESC: move(y, x); @@ -554,11 +563,11 @@ fatal(char *s, int ret) { char *str = xmalloc(strlen(s) + strlen(err1) + strlen(err2) + 10); sprintf(str, "%s: %s", err1, s); - if (strlen(str) > COLS) + if (strlen(str) > (size_t) COLS) str[COLS] = 0; mvaddstr(WARNING_START, (COLS-strlen(str))/2, str); sprintf(str, "%s", err2); - if (strlen(str) > COLS) + if (strlen(str) > (size_t) COLS) str[COLS] = 0; mvaddstr(WARNING_START+1, (COLS-strlen(str))/2, str); putchar(BELL); /* CTRL-G */ @@ -1059,7 +1068,7 @@ menuUpdate( int y, int x, struct MenuItem *menuItems, int itemLength, if(lenName > itemLength || lenName >= sizeof(buff)) print_warning(_("Menu item too long. Menu may look odd.")); #endif - if (lenName >= sizeof(buff)) { /* truncate ridiculously long string */ + if ((size_t) lenName >= sizeof(buff)) { /* truncate ridiculously long string */ xstrncpy(buff, mi, sizeof(buff)); } else if (lenName >= itemLength) { snprintf(buff, sizeof(buff), @@ -1131,6 +1140,10 @@ menuSelect( int y, int x, struct MenuItem *menuItems, int itemLength, refresh(); key = getch(); + if (key == ERR) + if (!isatty(STDIN_FILENO)) + exit(2); + /* Clear out all prompts and such */ clear_warning(); for (i = y; i < ylast; i++) { @@ -1176,7 +1189,7 @@ menuSelect( int y, int x, struct MenuItem *menuItems, int itemLength, } /* Enter equals the keyboard shortcut of current menu item */ - if (key == CR) + if (key == '\r') key = menuItems[current].key; /* Give alternatives for arrow keys in case the window manager @@ -1437,17 +1450,12 @@ get_kernel_geometry(void) { static int said_yes(char answer) { -#ifdef HAVE_RPMATCH char reply[2]; - int yn; reply[0] = answer; reply[1] = 0; - yn = rpmatch(reply); /* 1: yes, 0: no, -1: ? */ - if (yn >= 0) - return yn; -#endif - return (answer == 'y' || answer == 'Y'); + + return (rpmatch(reply) == 1) ? 1 : 0; } static void @@ -1558,7 +1566,11 @@ fill_p_info(void) { unsigned long long llsectors; struct partition *p; partition_table buffer; - partition_info tmp_ext = { 0, 0, 0, 0, FREE_SPACE, PRIMARY }; + partition_info tmp_ext; + + memset(&tmp_ext, 0, sizeof tmp_ext); + tmp_ext.id = FREE_SPACE; + tmp_ext.num = PRIMARY; if ((fd = open(disk_device, O_RDWR)) < 0) { if ((fd = open(disk_device, O_RDONLY)) < 0) diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 5a694373..b6b81e49 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -22,7 +22,9 @@ #include <time.h> #include <limits.h> +#include "xalloc.h" #include "nls.h" +#include "rpmatch.h" #include "blkdev.h" #include "common.h" #include "mbsalign.h" @@ -243,10 +245,26 @@ int possibly_osf_label = 0; jmp_buf listingbuf; +static void __attribute__ ((__noreturn__)) usage(FILE *out) +{ + fprintf(out, _("Usage:\n" + " %1$s [options] <disk> change partition table\n" + " %1$s [options] -l <disk> list partition table(s)\n" + " %1$s -s <partition> give partition size(s) in blocks\n" + "\nOptions:\n" + " -b <size> sector size (512, 1024, 2048 or 4096)\n" + " -c[=<mode>] compatible mode: 'dos' or 'nondos' (default)\n" + " -h print this help text\n" + " -u[=<unit>] display units: 'cylinders' or 'sectors' (default)\n" + " -v print program version\n" + " -C <number> specify the number of cylinders\n" + " -H <number> specify the number of heads\n" + " -S <number> specify the number of sectors per track\n" + "\n"), program_invocation_short_name); + exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); +} + void fatal(enum failure why) { - char error[LINE_LENGTH], - *message = error; - int rc = EXIT_FAILURE; if (listing) { close(fd); @@ -254,55 +272,24 @@ void fatal(enum failure why) { } switch (why) { - case help: - rc = EXIT_SUCCESS; - case usage: message = _( -"Usage:\n" -" fdisk [options] <disk> change partition table\n" -" fdisk [options] -l <disk> list partition table(s)\n" -" fdisk -s <partition> give partition size(s) in blocks\n" -"\nOptions:\n" -" -b <size> sector size (512, 1024, 2048 or 4096)\n" -" -c[=<mode>] compatible mode: 'dos' or 'nondos' (default)\n" -" -h print this help text\n" -" -u[=<unit>] display units: 'cylinders' or 'sectors' (default)\n" -" -v print program version\n" -" -C <number> specify the number of cylinders\n" -" -H <number> specify the number of heads\n" -" -S <number> specify the number of sectors per track\n" -"\n"); - break; case unable_to_open: - snprintf(error, sizeof(error), - _("Unable to open %s\n"), disk_device); - break; + err(EXIT_FAILURE, _("unable to open %s"), disk_device); + case unable_to_read: - snprintf(error, sizeof(error), - _("Unable to read %s\n"), disk_device); - break; + err(EXIT_FAILURE, _("unable to read %s"), disk_device); + case unable_to_seek: - snprintf(error, sizeof(error), - _("Unable to seek on %s\n"),disk_device); - break; + err(EXIT_FAILURE, _("unable to seek on %s"), disk_device); + case unable_to_write: - snprintf(error, sizeof(error), - _("Unable to write %s\n"), disk_device); - break; + err(EXIT_FAILURE, _("unable to write %s"), disk_device); + case ioctl_error: - snprintf(error, sizeof(error), - _("BLKGETSIZE ioctl failed on %s\n"), - disk_device); - break; - case out_of_memory: - message = _("Unable to allocate any more memory\n"); - break; + err(EXIT_FAILURE, _("BLKGETSIZE ioctl failed on %s"), disk_device); + default: - message = _("Fatal error\n"); + err(EXIT_FAILURE, _("fatal error")); } - - fputc('\n', stderr); - fputs(message, stderr); - exit(rc); } static void @@ -332,9 +319,7 @@ read_pte(int fd, int pno, unsigned long long offset) { struct pte *pe = &ptes[pno]; pe->offset = offset; - pe->sectorbuffer = malloc(sector_size); - if (!pe->sectorbuffer) - fatal(out_of_memory); + pe->sectorbuffer = xmalloc(sector_size); read_sector(fd, offset, pe->sectorbuffer); pe->changed = 0; pe->part_table = pe->ext_pointer = NULL; @@ -1172,9 +1157,7 @@ static void init_mbr_buffer(void) if (MBRbuffer) return; - MBRbuffer = calloc(1, MAX_SECTOR_SIZE); - if (!MBRbuffer) - fatal(out_of_memory); + MBRbuffer = xcalloc(1, MAX_SECTOR_SIZE); } void zeroize_mbr_buffer(void) @@ -1316,23 +1299,46 @@ got_dos_table: return 0; } +static int is_partition_table_changed(void) +{ + int i; + + for (i = 0; i < partitions; i++) + if (ptes[i].changed) + return 1; + return 0; +} + +static void maybe_exit(int rc, int *asked) +{ + char line[LINE_LENGTH]; + + putchar('\n'); + if (asked) + *asked = 0; + + if (is_partition_table_changed() || MBRbuffer_changed) { + fprintf(stderr, _("Do you really want to quit? ")); + + if (!fgets(line, LINE_LENGTH, stdin) || rpmatch(line) == 1) + exit(rc); + if (asked) + *asked = 1; + } else + exit(rc); +} + /* read line; return 0 or first char */ int -read_line(void) +read_line(int *asked) { - static int got_eof = 0; - line_ptr = line_buffer; if (!fgets(line_buffer, LINE_LENGTH, stdin)) { - if (feof(stdin)) - got_eof++; /* user typed ^D ? */ - if (got_eof >= 3) { - fflush(stdout); - fprintf(stderr, _("\ngot EOF thrice - exiting..\n")); - exit(1); - } + maybe_exit(1, asked); return 0; } + if (asked) + *asked = 0; while (*line_ptr && !isgraph(*line_ptr)) line_ptr++; return *line_ptr; @@ -1344,16 +1350,22 @@ read_char(char *mesg) do { fputs(mesg, stdout); fflush (stdout); /* requested by niles@scyld.com */ - } while (!read_line()); + } while (!read_line(NULL)); return *line_ptr; } char read_chars(char *mesg) { - fputs(mesg, stdout); - fflush (stdout); /* niles@scyld.com */ - if (!read_line()) { + int rc, asked = 0; + + do { + fputs(mesg, stdout); + fflush (stdout); /* niles@scyld.com */ + rc = read_line(&asked); + } while (asked); + + if (!rc) { *line_ptr = '\n'; line_ptr[1] = 0; } @@ -1392,8 +1404,7 @@ read_int_sx(unsigned int low, unsigned int dflt, unsigned int high, if (!ms || strlen(mesg)+100 > mslen) { mslen = strlen(mesg)+200; - if (!(ms = realloc(ms,mslen))) - fatal(out_of_memory); + ms = xrealloc(ms,mslen); } if (dflt < low || dflt > high) @@ -2444,8 +2455,7 @@ add_partition(int n, int sys) { ext_index = n; pen->ext_pointer = p; pe4->offset = extended_offset = start; - if (!(pe4->sectorbuffer = calloc(1, sector_size))) - fatal(out_of_memory); + pe4->sectorbuffer = xcalloc(1, sector_size); pe4->part_table = pt_offset(pe4->sectorbuffer, 0); pe4->ext_pointer = pe4->part_table + 1; pe4->changed = 1; @@ -2458,8 +2468,7 @@ add_logical(void) { if (partitions > 5 || ptes[4].part_table->sys_ind) { struct pte *pe = &ptes[partitions]; - if (!(pe->sectorbuffer = calloc(1, sector_size))) - fatal(out_of_memory); + pe->sectorbuffer = xcalloc(1, sector_size); pe->part_table = pt_offset(pe->sectorbuffer, 0); pe->ext_pointer = pe->part_table + 1; pe->offset = 0; @@ -2949,7 +2958,7 @@ main(int argc, char **argv) { sector_size = atoi(optarg); if (sector_size != 512 && sector_size != 1024 && sector_size != 2048 && sector_size != 4096) - fatal(usage); + usage(stderr); sector_offset = 2; user_set_sector_size = 1; break; @@ -2962,10 +2971,10 @@ main(int argc, char **argv) { if (optarg && !strcmp(optarg, "=dos")) dos_compatible_flag = ~0; else if (optarg && strcmp(optarg, "=nondos")) - fatal(usage); + usage(stderr); break; case 'h': - fatal(help); + usage(stdout); break; case 'H': user_heads = atoi(optarg); @@ -2988,14 +2997,14 @@ main(int argc, char **argv) { if (optarg && strcmp(optarg, "=cylinders") == 0) display_in_cyl_units = !display_in_cyl_units; else if (optarg && strcmp(optarg, "=sectors")) - fatal(usage); + usage(stderr); break; case 'V': case 'v': printf("fdisk (%s)\n", PACKAGE_STRING); exit(0); default: - fatal(usage); + usage(stderr); } } @@ -3037,7 +3046,7 @@ main(int argc, char **argv) { opts = argc - optind; if (opts <= 0) - fatal(usage); + usage(stderr); for (j = optind; j < argc; j++) { disk_device = argv[j]; @@ -3057,7 +3066,7 @@ main(int argc, char **argv) { if (argc-optind == 1) disk_device = argv[optind]; else - fatal(usage); + usage(stderr); gpt_warning(disk_device); get_boot(fdisk); diff --git a/fdisk/fdisk.h b/fdisk/fdisk.h index 56230d68..302a7a7a 100644 --- a/fdisk/fdisk.h +++ b/fdisk/fdisk.h @@ -45,9 +45,9 @@ struct partition { unsigned char size4[4]; /* nr of sectors in partition */ } PACKED; -enum failure {help, usage, ioctl_error, +enum failure {ioctl_error, unable_to_open, unable_to_read, unable_to_seek, - unable_to_write, out_of_memory}; + unable_to_write}; enum action {fdisk, require, try_only, create_empty_dos, create_empty_sun}; @@ -67,7 +67,7 @@ extern void get_geometry(int fd, struct geom *); extern int get_boot(enum action what); extern int get_partition(int warn, int max); extern void list_types(struct systypes *sys); -extern int read_line (void); +extern int read_line (int *asked); extern char read_char(char *mesg); extern int read_hex(struct systypes *sys); extern void reread_partition_table(int leave); diff --git a/fdisk/fdiskbsdlabel.c b/fdisk/fdiskbsdlabel.c index 9c092524..0c3810d4 100644 --- a/fdisk/fdiskbsdlabel.c +++ b/fdisk/fdiskbsdlabel.c @@ -448,7 +448,7 @@ edit_int (int def, char *mesg) do { fputs (mesg, stdout); printf (" (%d): ", def); - if (!read_line ()) + if (!read_line (NULL)) return def; } while (!isdigit (*line_ptr)); @@ -527,7 +527,7 @@ xbsd_write_bootstrap (void) printf (_("Bootstrap: %sboot -> boot%s (%s): "), dkbasename, dkbasename, dkbasename); - if (read_line ()) { + if (read_line (NULL)) { line_ptr[strlen (line_ptr)-1] = '\0'; dkbasename = line_ptr; } diff --git a/fdisk/fdisksgilabel.c b/fdisk/fdisksgilabel.c index 3547195c..4019eace 100644 --- a/fdisk/fdisksgilabel.c +++ b/fdisk/fdisksgilabel.c @@ -22,6 +22,7 @@ #include <endian.h> #include "nls.h" +#include "xalloc.h" #include "blkdev.h" @@ -825,7 +826,7 @@ sgi_set_ncyl(void) sgiinfo * fill_sgiinfo(void) { - sgiinfo*info=calloc(1, sizeof(sgiinfo)); + sgiinfo *info=xcalloc(1, sizeof(sgiinfo)); info->magic=SSWAP32(SGI_INFO_MAGIC); info->b1=SSWAP32(-1); info->b2=SSWAP16(-1); diff --git a/fdisk/i386_sys_types.c b/fdisk/i386_sys_types.c index e37ec51a..916daf68 100644 --- a/fdisk/i386_sys_types.c +++ b/fdisk/i386_sys_types.c @@ -10,7 +10,7 @@ struct systypes i386_sys_types[] = { {0x04, N_("FAT16 <32M")}, {0x05, N_("Extended")}, /* DOS 3.3+ extended partition */ {0x06, N_("FAT16")}, /* DOS 16-bit >=32M */ - {0x07, N_("HPFS/NTFS")}, /* OS/2 IFS, eg, HPFS or NTFS or QNX */ + {0x07, N_("HPFS/NTFS/exFAT")}, /* OS/2 IFS, eg, HPFS or NTFS or QNX or exFAT */ {0x08, N_("AIX")}, /* AIX boot (AIX -- PS/2 port) or SplitDrive */ {0x09, N_("AIX bootable")}, /* AIX data or Coherent */ {0x0a, N_("OS/2 Boot Manager")},/* OS/2 Boot Manager */ @@ -29,6 +29,7 @@ struct systypes i386_sys_types[] = { {0x1c, N_("Hidden W95 FAT32 (LBA)")}, {0x1e, N_("Hidden W95 FAT16 (LBA)")}, {0x24, N_("NEC DOS")}, + {0x27, N_("Hidden NTFS WinRE")}, {0x39, N_("Plan 9")}, {0x3c, N_("PartitionMagic recovery")}, {0x40, N_("Venix 80286")}, |