]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: use libfdisk label->changed
authorKarel Zak <kzak@redhat.com>
Fri, 18 Jan 2013 15:11:40 +0000 (16:11 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 11 Mar 2013 11:47:30 +0000 (12:47 +0100)
The patch is huge because it's necessary to add a pointer context to
all read_<foo> functions.

Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.c
fdisks/fdisk.h
fdisks/fdiskbsdlabel.c
fdisks/fdiskdoslabel.c
fdisks/fdisksgilabel.c
fdisks/fdisksunlabel.c
fdisks/gpt.c

index b34d0f8da9366d734e181b891e4fe823e8ae0d2e..58b945281b2e397ec15496b6d1eb0ae934c1c223 100644 (file)
@@ -51,8 +51,6 @@
 
 #include "gpt.h"
 
-int MBRbuffer_changed;
-
 #define hex_val(c)     ({ \
                                char _c = (c); \
                                isdigit(_c) ? _c - '0' : \
@@ -178,19 +176,6 @@ get_part_table(int i) {
        return ptes[i].part_table;
 }
 
-void
-set_all_unchanged(void) {
-       int i;
-
-       for (i = 0; i < MAXIMUM_PARTS; i++)
-               ptes[i].changed = 0;
-}
-
-void
-set_changed(int i) {
-       ptes[i].changed = 1;
-}
-
 static int
 is_garbage_table(void) {
        int i;
@@ -330,42 +315,37 @@ void warn_limits(struct fdisk_context *cxt)
        }
 }
 
-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)
+static void maybe_exit(struct fdisk_context *cxt, int rc, int *asked)
 {
        char line[LINE_LENGTH];
 
+       assert(cxt);
+       assert(cxt->label);
+
        putchar('\n');
        if (asked)
                *asked = 0;
 
-       if (is_partition_table_changed() || MBRbuffer_changed) {
+       if (fdisk_label_is_changed(cxt->label)) {
                fprintf(stderr, _("Do you really want to quit? "));
 
                if (!fgets(line, LINE_LENGTH, stdin) || rpmatch(line) == 1)
-                       exit(rc);
+                       goto leave;
                if (asked)
                        *asked = 1;
-       } else
-               exit(rc);
+               return;
+       }
+leave:
+       fdisk_free_context(cxt);
+       exit(rc);
 }
 
 /* read line; return 0 or first char */
-int
-read_line(int *asked)
+int read_line(struct fdisk_context *cxt, int *asked)
 {
        line_ptr = line_buffer;
        if (!fgets(line_buffer, LINE_LENGTH, stdin)) {
-               maybe_exit(1, asked);
+               maybe_exit(cxt, 1, asked);
                return 0;
        }
        if (asked)
@@ -375,25 +355,25 @@ read_line(int *asked)
        return *line_ptr;
 }
 
-char
-read_char(char *mesg)
+char read_char(struct fdisk_context *cxt, char *mesg)
 {
        do {
                fputs(mesg, stdout);
                fflush (stdout);         /* requested by niles@scyld.com */
-       } while (!read_line(NULL));
+
+       } while (!read_line(cxt, NULL));
+
        return *line_ptr;
 }
 
-char
-read_chars(char *mesg)
+char read_chars(struct fdisk_context *cxt, char *mesg)
 {
        int rc, asked = 0;
 
        do {
                fputs(mesg, stdout);
                fflush (stdout);        /* niles@scyld.com */
-               rc = read_line(&asked);
+               rc = read_line(cxt, &asked);
        } while (asked);
 
        if (!rc) {
@@ -412,9 +392,9 @@ struct fdisk_parttype *read_partition_type(struct fdisk_context *cxt)
                size_t sz;
 
                if (cxt->label->parttypes[0].typestr)
-                       read_chars(_("Partition type (type L to list all types): "));
+                       read_chars(cxt, _("Partition type (type L to list all types): "));
                else
-                       read_chars(_("Hex code (type L to list all codes): "));
+                       read_chars(cxt, _("Hex code (type L to list all codes): "));
 
                sz = strlen(line_ptr);
                if (!sz || line_ptr[sz - 1] != '\n' || sz == 1)
@@ -461,7 +441,7 @@ read_int_with_suffix(struct fdisk_context *cxt,
                int use_default = default_ok;
 
                /* ask question and read answer */
-               while (read_chars(ms) != '\n' && !isdigit(*line_ptr)
+               while (read_chars(cxt, ms) != '\n' && !isdigit(*line_ptr)
                       && *line_ptr != '-' && *line_ptr != '+')
                        continue;
 
@@ -645,7 +625,7 @@ str_units(int n)
 }
 
 static void
-toggle_active(int i) {
+toggle_active(struct fdisk_context *cxt, int i) {
        struct pte *pe = &ptes[i];
        struct partition *p = pe->part_table;
 
@@ -655,6 +635,7 @@ toggle_active(int i) {
                        i + 1);
        p->boot_ind = (p->boot_ind ? 0 : ACTIVE_FLAG);
        pe->changed = 1;
+       fdisk_label_set_changed(cxt->label, 1);
 }
 
 static void toggle_dos_compatibility_flag(struct fdisk_context *cxt)
@@ -1312,7 +1293,7 @@ expert_command_prompt(struct fdisk_context *cxt)
 
        while(1) {
                putchar('\n');
-               c = tolower(read_char(_("Expert command (m for help): ")));
+               c = tolower(read_char(cxt, _("Expert command (m for help): ")));
                switch (c) {
                case 'a':
                        if (fdisk_is_disklabel(cxt, SUN))
@@ -1505,11 +1486,11 @@ static void command_prompt(struct fdisk_context *cxt)
 
        while (1) {
                putchar('\n');
-               c = tolower(read_char(_("Command (m for help): ")));
+               c = tolower(read_char(cxt, _("Command (m for help): ")));
                switch (c) {
                case 'a':
                        if (fdisk_is_disklabel(cxt, DOS))
-                               toggle_active(get_partition(cxt, 1, partitions));
+                               toggle_active(cxt, get_partition(cxt, 1, partitions));
                        else if (fdisk_is_disklabel(cxt, SUN))
                                toggle_sunflags(cxt, get_partition(cxt, 1, partitions),
                                                SUN_FLAG_UNMNT);
index 4196d7bda5f0493100680ac0ce85f504515aa4ad..ae9d3a127962a36324d402395b272703be9ee237 100644 (file)
@@ -71,8 +71,8 @@ extern void check(struct fdisk_context *cxt, int n, unsigned int h, unsigned int
 extern void fatal(struct fdisk_context *cxt, enum failure why);
 extern int  get_partition(struct fdisk_context *cxt, int warn, int max);
 extern void list_partition_types(struct fdisk_context *cxt);
-extern int read_line (int *asked);
-extern char read_char(char *mesg);
+extern int read_line(struct fdisk_context *cxt, int *asked);
+extern char read_char(struct fdisk_context *cxt, char *mesg);
 extern struct fdisk_parttype *read_partition_type(struct fdisk_context *cxt);
 extern void reread_partition_table(struct fdisk_context *cxt, int leave);
 extern struct partition *get_part_table(int);
@@ -85,9 +85,7 @@ extern void print_partition_size(struct fdisk_context *cxt, int num, sector_t st
 extern void fill_bounds(sector_t *first, sector_t *last);
 
 extern char *partition_type(struct fdisk_context *cxt, unsigned char type);
-extern char read_chars(char *mesg);
-extern void set_changed(int);
-extern void set_all_unchanged(void);
+extern char read_chars(struct fdisk_context *cxt, char *mesg);
 extern int warn_geometry(struct fdisk_context *cxt);
 extern void warn_limits(struct fdisk_context *cxt);
 extern unsigned int read_int_with_suffix(struct fdisk_context *cxt,
@@ -102,7 +100,6 @@ extern const char * str_units(int);
 extern sector_t get_nr_sects(struct partition *p);
 
 extern int nowarn;
-extern int MBRbuffer_changed;
 
 /* start_sect and nr_sects are stored little endian on all machines */
 /* moreover, they are not aligned correctly */
index 3788b2b021ace523fa3fe1a6491aea84c85a8fc4..19dfd78d570040d961e36a84492866802bb3fd9c 100644 (file)
@@ -72,11 +72,11 @@ struct fdisk_bsd_label {
 
 static int xbsd_delete_part (struct fdisk_context *cxt,
                             struct fdisk_label *lb, int partnum);
-static void xbsd_edit_disklabel (void);
+static void xbsd_edit_disklabel (struct fdisk_context *cxt);
 static void xbsd_write_bootstrap (struct fdisk_context *cxt);
 static void xbsd_change_fstype (struct fdisk_context *cxt, struct fdisk_label *lb);
-static int xbsd_get_part_index (int max);
-static int xbsd_check_new_partition (int *i);
+static int xbsd_get_part_index (struct fdisk_context *cxt, int max);
+static int xbsd_check_new_partition (struct fdisk_context *cxt, int *i);
 static unsigned short xbsd_dkcksum (struct xbsd_disklabel *lp);
 static int xbsd_initlabel  (struct fdisk_context *cxt,
                            struct partition *p, struct xbsd_disklabel *d,
@@ -173,7 +173,7 @@ static int xbsd_add_part (struct fdisk_context *cxt,
        char mesg[256];
        int i, rc;
 
-       rc = xbsd_check_new_partition(&i);
+       rc = xbsd_check_new_partition(cxt, &i);
        if (rc)
                return rc;
 
@@ -186,7 +186,7 @@ static int xbsd_add_part (struct fdisk_context *cxt,
 #endif
 
        snprintf (mesg, sizeof(mesg), _("First %s"), str_units(SINGULAR));
-       begin = read_int (cxt, bsd_cround (begin), bsd_cround (begin), bsd_cround (end),
+       begin = read_int(cxt, bsd_cround (begin), bsd_cround (begin), bsd_cround (end),
                          0, mesg);
 
        if (display_in_cyl_units)
@@ -205,6 +205,7 @@ static int xbsd_add_part (struct fdisk_context *cxt,
        xbsd_dlabel.d_partitions[i].p_fstype = BSD_FS_UNUSED;
 
        lb->nparts_cur = xbsd_dlabel.d_npartitions;
+       fdisk_label_set_changed(lb, 1);
 
        return 0;
 }
@@ -222,7 +223,7 @@ static int xbsd_create_disklabel(struct fdisk_context *cxt,
 #endif
 
        while (1) {
-               c = read_char (_("Do you want to create a disklabel? (y/n) "));
+               c = read_char(cxt, _("Do you want to create a disklabel? (y/n) "));
                if (tolower(c) == 'y') {
                        if (xbsd_initlabel (cxt,
 #if defined (__alpha__) || defined (__powerpc__) || defined (__hppa__) || \
@@ -285,12 +286,13 @@ bsd_command_prompt (struct fdisk_context *cxt)
 
   while (1) {
     putchar ('\n');
-    switch (tolower (read_char (_("BSD disklabel command (m for help): ")))) {
+    switch (tolower (read_char(cxt, _("BSD disklabel command (m for help): ")))) {
       case 'd':
-             xbsd_delete_part(cxt, cxt->label, xbsd_get_part_index(xbsd_dlabel.d_npartitions));
+             xbsd_delete_part(cxt, cxt->label,
+                             xbsd_get_part_index(cxt, xbsd_dlabel.d_npartitions));
              break;
       case 'e':
-       xbsd_edit_disklabel ();
+       xbsd_edit_disklabel (cxt);
        break;
       case 'i':
        xbsd_write_bootstrap (cxt);
@@ -346,6 +348,7 @@ static int xbsd_delete_part(
                        xbsd_dlabel.d_npartitions--;
 
        lb->nparts_cur = xbsd_dlabel.d_npartitions;
+       fdisk_label_set_changed(lb, 1);
        return 0;
 }
 
@@ -447,49 +450,49 @@ xbsd_print_disklabel (struct fdisk_context *cxt, int show_all) {
   }
 }
 
-static int
-edit_int (int def, char *mesg)
+static unsigned long
+edit_int(struct fdisk_context *cxt, unsigned long def, char *mesg)
 {
   do {
     fputs (mesg, stdout);
-    printf (" (%d): ", def);
-    if (!read_line (NULL))
+    printf (" (%lu): ", def);
+    if (!read_line(cxt, NULL))
       return def;
-  }
-  while (!isdigit (*line_ptr));
-  return atoi (line_ptr);
+  } while (!isdigit (*line_ptr));
+
+  return strtoul(line_ptr, NULL, 10);  /* TODO check it! */
 }
 
 static void
-xbsd_edit_disklabel (void)
+xbsd_edit_disklabel(struct fdisk_context *cxt)
 {
   struct xbsd_disklabel *d;
 
   d = &xbsd_dlabel;
 
 #if defined (__alpha__) || defined (__ia64__)
-  d -> d_secsize    = (unsigned long) edit_int ((unsigned long) d -> d_secsize     ,_("bytes/sector"));
-  d -> d_nsectors   = (unsigned long) edit_int ((unsigned long) d -> d_nsectors    ,_("sectors/track"));
-  d -> d_ntracks    = (unsigned long) edit_int ((unsigned long) d -> d_ntracks     ,_("tracks/cylinder"));
-  d -> d_ncylinders = (unsigned long) edit_int ((unsigned long) d -> d_ncylinders  ,_("cylinders"));
+  d -> d_secsize    = edit_int(cxt, d->d_secsize     ,_("bytes/sector"));
+  d -> d_nsectors   = edit_int(cxt, d->d_nsectors    ,_("sectors/track"));
+  d -> d_ntracks    = edit_int(cxt, d->d_ntracks     ,_("tracks/cylinder"));
+  d -> d_ncylinders = edit_int(cxt, d->d_ncylinders  ,_("cylinders"));
 #endif
 
   /* d -> d_secpercyl can be != d -> d_nsectors * d -> d_ntracks */
   while (1)
   {
-    d -> d_secpercyl = (unsigned long) edit_int ((unsigned long) d -> d_nsectors * d -> d_ntracks,
+    d -> d_secpercyl = edit_int(cxt, (unsigned long) d->d_nsectors * d -> d_ntracks,
                                          _("sectors/cylinder"));
     if (d -> d_secpercyl <= d -> d_nsectors * d -> d_ntracks)
       break;
 
     printf (_("Must be <= sectors/track * tracks/cylinder (default).\n"));
   }
-  d -> d_rpm        = (unsigned short) edit_int ((unsigned short) d -> d_rpm       ,_("rpm"));
-  d -> d_interleave = (unsigned short) edit_int ((unsigned short) d -> d_interleave,_("interleave"));
-  d -> d_trackskew  = (unsigned short) edit_int ((unsigned short) d -> d_trackskew ,_("trackskew"));
-  d -> d_cylskew    = (unsigned short) edit_int ((unsigned short) d -> d_cylskew   ,_("cylinderskew"));
-  d -> d_headswitch = (unsigned long) edit_int ((unsigned long) d -> d_headswitch  ,_("headswitch"));
-  d -> d_trkseek    = (unsigned long) edit_int ((unsigned long) d -> d_trkseek     ,_("track-to-track seek"));
+  d -> d_rpm        = (unsigned short) edit_int(cxt, d->d_rpm       ,_("rpm"));
+  d -> d_interleave = (unsigned short) edit_int(cxt, d->d_interleave,_("interleave"));
+  d -> d_trackskew  = (unsigned short) edit_int(cxt, d->d_trackskew ,_("trackskew"));
+  d -> d_cylskew    = (unsigned short) edit_int(cxt, d->d_cylskew   ,_("cylinderskew"));
+  d -> d_headswitch = edit_int(cxt, d->d_headswitch  ,_("headswitch"));
+  d -> d_trkseek    = edit_int(cxt, d->d_trkseek     ,_("track-to-track seek"));
 
   d -> d_secperunit = d -> d_secpercyl * d -> d_ncylinders;
 }
@@ -532,7 +535,7 @@ xbsd_write_bootstrap (struct fdisk_context *cxt)
 
   printf (_("Bootstrap: %sboot -> boot%s (%s): "),
          dkbasename, dkbasename, dkbasename);
-  if (read_line (NULL)) {
+  if (read_line(cxt, NULL)) {
     line_ptr[strlen (line_ptr)-1] = '\0';
     dkbasename = line_ptr;
   }
@@ -589,35 +592,36 @@ xbsd_write_bootstrap (struct fdisk_context *cxt)
 static void
 xbsd_change_fstype (
                struct fdisk_context *cxt,
-               struct fdisk_label *lb __attribute__((__unused__)))
+               struct fdisk_label *lb)
 {
   int i;
   struct fdisk_parttype *t;
 
-  i = xbsd_get_part_index (xbsd_dlabel.d_npartitions);
+  i = xbsd_get_part_index (cxt, xbsd_dlabel.d_npartitions);
   t = read_partition_type(cxt);
 
   if (t) {
     xbsd_dlabel.d_partitions[i].p_fstype = t->type;
     fdisk_free_parttype(t);
+    fdisk_label_set_changed(lb, 1);
   }
 }
 
 static int
-xbsd_get_part_index (int max)
+xbsd_get_part_index(struct fdisk_context *cxt, int max)
 {
   char prompt[256];
   char l;
 
   snprintf (prompt, sizeof(prompt), _("Partition (a-%c): "), 'a' + max - 1);
   do
-     l = tolower (read_char (prompt));
+     l = tolower(read_char(cxt, prompt));
   while (l < 'a' || l > 'a' + max - 1);
   return l - 'a';
 }
 
 static int
-xbsd_check_new_partition (int *i) {
+xbsd_check_new_partition(struct fdisk_context *cxt, int *i) {
 
        /* room for more? various BSD flavours have different maxima */
        if (xbsd_dlabel.d_npartitions == BSD_MAXPARTITIONS) {
@@ -634,7 +638,7 @@ xbsd_check_new_partition (int *i) {
                }
        }
 
-       *i = xbsd_get_part_index (BSD_MAXPARTITIONS);
+       *i = xbsd_get_part_index(cxt, BSD_MAXPARTITIONS);
 
        if (*i >= xbsd_dlabel.d_npartitions)
                xbsd_dlabel.d_npartitions = (*i) + 1;
@@ -746,9 +750,9 @@ xbsd_readlabel (struct fdisk_context *cxt, struct partition *p, struct xbsd_disk
 #endif
 
        if (lseek (cxt->dev_fd, (off_t) sector * SECTOR_SIZE, SEEK_SET) == -1)
-               fatal (cxt, unable_to_seek);
+               return 0;
        if (BSD_BBSIZE != read (cxt->dev_fd, disklabelbuffer, BSD_BBSIZE))
-               fatal (cxt, unable_to_read);
+               return 0;
 
        memmove (d,
                 &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET],
@@ -849,7 +853,7 @@ xbsd_link_part (struct fdisk_context *cxt)
 
   k = get_partition (cxt, 1, partitions);
 
-  if (xbsd_check_new_partition (&i))
+  if (xbsd_check_new_partition(cxt, &i))
     return;
 
   p = get_part_table(k);
@@ -898,7 +902,7 @@ static struct fdisk_parttype *xbsd_get_parttype(
 
 static int xbsd_set_parttype(
                struct fdisk_context *cxt __attribute__((__unused__)),
-               struct fdisk_label *lb __attribute__((__unused__)),
+               struct fdisk_label *lb,
                int partnum,
                struct fdisk_parttype *t)
 {
@@ -912,6 +916,7 @@ static int xbsd_set_parttype(
                return 0;
 
        p->p_fstype = t->type;
+       fdisk_label_set_changed(lb, 1);
        return 0;
 }
 
index fde9a5da9d294e9c31e43e1187599b01301ff5df..3a3b710184dfd3738c7c4933d3196aa8acf9c51c 100644 (file)
@@ -47,6 +47,8 @@ int ext_index;
 
 unsigned int units_per_sector = 1, display_in_cyl_units = 0;
 
+static int MBRbuffer_changed;
+
 void update_units(struct fdisk_context *cxt)
 {
        int cyl_units = cxt->geom.heads * cxt->geom.sectors;
@@ -199,7 +201,7 @@ void dos_init(struct fdisk_context *cxt)
 
 static int dos_delete_partition(
                struct fdisk_context *cxt __attribute__ ((__unused__)),
-               struct fdisk_label *lb __attribute__ ((__unused__)),
+               struct fdisk_label *lb,
                int partnum)
 {
        struct pte *pe = &ptes[partnum];
@@ -254,6 +256,7 @@ static int dos_delete_partition(
                        clear_partition(ptes[partnum].part_table);
        }
 
+       fdisk_label_set_changed(lb, 1);
        return 0;
 }
 
@@ -368,8 +371,7 @@ static int dos_create_disklabel(struct fdisk_context *cxt,
 
        dos_init(cxt);
        fdisk_zeroize_firstsector(cxt);
-       set_all_unchanged();
-       set_changed(0);
+       fdisk_label_set_changed(cxt->label, 1);
 
        /* Generate an MBR ID for this disk */
        mbr_set_id(cxt->firstsector, id);
@@ -388,7 +390,7 @@ void dos_set_mbr_id(struct fdisk_context *cxt)
        snprintf(ps, sizeof ps, _("New disk identifier (current 0x%08x): "),
                 mbr_get_id(cxt->firstsector));
 
-       if (read_chars(ps) == '\n')
+       if (read_chars(cxt, ps) == '\n')
                return;
 
        new_id = strtoul(line_ptr, &ep, 0);
@@ -397,6 +399,7 @@ void dos_set_mbr_id(struct fdisk_context *cxt)
 
        mbr_set_id(cxt->firstsector, new_id);
        MBRbuffer_changed = 1;
+       fdisk_label_set_changed(cxt->label, 1);
        dos_print_mbr_id(cxt);
 }
 
@@ -704,6 +707,7 @@ static int add_partition(struct fdisk_context *cxt, int n, struct fdisk_parttype
                partitions = 5;
        }
 
+       fdisk_label_set_changed(cxt->label, 1);
        return 0;
 }
 
@@ -834,7 +838,7 @@ static int dos_add_partition(
                         extended_offset ? _("   l   logical (numbered from 5)") : _("   e   extended"),
                         dflt);
 
-               c = tolower(read_chars(line));
+               c = tolower(read_chars(cxt, line));
                if (c == '\n') {
                        c = dflt;
                        printf(_("Using default response %c\n"), c);
@@ -930,7 +934,7 @@ static struct fdisk_parttype *dos_get_parttype(
 
 static int dos_set_parttype(
                struct fdisk_context *cxt __attribute__((__unused__)),
-               struct fdisk_label *lb __attribute__((__unused__)),
+               struct fdisk_label *lb,
                int partnum,
                struct fdisk_parttype *t)
 {
@@ -956,6 +960,7 @@ static int dos_set_parttype(
                "information.\n\n"));
 
        p->sys_ind = t->type;
+       fdisk_label_set_changed(lb, 1);
        return 0;
 }
 
index 4b330bdb9fdc043fce0105e67a24c5eb5fe72458..132e7fd02185e1166aa44454050fd22cdf8d216a 100644 (file)
@@ -314,7 +314,7 @@ void
 sgi_set_bootfile(struct fdisk_context *cxt)
 {
        printf(_("\nThe current boot file is: %s\n"), sgilabel->boot_file);
-       if (read_chars(_("Please enter the name of the new boot file: ")) == '\n') {
+       if (read_chars(cxt, _("Please enter the name of the new boot file: ")) == '\n') {
                printf(_("Boot file unchanged\n"));
                return;
        }
@@ -607,7 +607,8 @@ static int sgi_set_partition(struct fdisk_context *cxt, int i,
        sgilabel->partitions[i].id = SSWAP32(sys);
        sgilabel->partitions[i].num_sectors = SSWAP32(length);
        sgilabel->partitions[i].start_sector = SSWAP32(start);
-       set_changed(i);
+
+       fdisk_label_set_changed(cxt->label, 1);
 
        if (sgi_gaps(cxt) < 0)  /* rebuild freelist */
                printf(_("Partition overlap on the disk.\n"));
@@ -936,7 +937,7 @@ static int sgi_set_parttype(struct fdisk_context *cxt,
 
        if (((t->type != ENTIRE_DISK) && (t->type != SGI_VOLHDR))
            && (sgi_get_start_sector(cxt, i) < 1)) {
-               read_chars(
+               read_chars(cxt,
                        _("It is highly recommended that the partition at offset 0\n"
                          "is of type \"SGI volhdr\", the IRIX system will rely on it to\n"
                          "retrieve from its directory standalone tools like sash and fx.\n"
index c8861b01145a5534c27790e2e173e489281d5310..39a0f024c427dbc44a1a561454eaa07f8c5d3768 100644 (file)
@@ -100,7 +100,7 @@ static void set_sun_partition(struct fdisk_context *cxt,
                SSWAP32(start / (cxt->geom.heads * cxt->geom.sectors));
        sunlabel->partitions[i].num_sectors =
                SSWAP32(stop - start);
-       set_changed(i);
+       fdisk_label_set_changed(cxt->label, 1);
        print_partition_size(cxt, i + 1, start, stop, sysid);
 }
 
@@ -190,7 +190,7 @@ static int sun_probe_label(struct fdisk_context *cxt, struct fdisk_label *lb)
                        csum ^= *ush++;
                sunlabel->cksum = csum;
 
-               set_changed(0);
+               fdisk_label_set_changed(lb, 1);
        }
 
        lb->nparts_cur = partitions_in_use(lb);
@@ -301,8 +301,7 @@ static int sun_create_disklabel(struct fdisk_context *cxt, struct fdisk_label *l
                sunlabel->cksum = csum;
        }
 
-       set_all_unchanged();
-       set_changed(0);
+       fdisk_label_set_changed(lb, 1);
        lb->nparts_cur = partitions_in_use(lb);
 
        return 0;
@@ -315,7 +314,7 @@ void toggle_sunflags(struct fdisk_context *cxt, int i, uint16_t mask)
 
        p->flag ^= SSWAP16(mask);
 
-       set_changed(i);
+       fdisk_label_set_changed(cxt->label, 1);
 }
 
 static void fetch_sun(struct fdisk_context *cxt,
@@ -609,6 +608,7 @@ static int sun_delete_partition(struct fdisk_context *cxt,
        tag->tag = SSWAP16(SUN_TAG_UNASSIGNED);
        part->num_sectors = 0;
        lb->nparts_cur = partitions_in_use(lb);
+       fdisk_label_set_changed(lb, 1);
        return 0;
 }
 
@@ -794,7 +794,7 @@ static int sun_set_parttype(
        tag = &sunlabel->part_tags[i];
 
        if (t->type == SUN_TAG_LINUX_SWAP && !part->start_cylinder) {
-           read_chars(
+           read_chars(cxt,
              _("It is highly recommended that the partition at offset 0\n"
              "is UFS, EXT2FS filesystem or SunOS swap. Putting Linux swap\n"
              "there may destroy your partition table and bootblock.\n"
index ba7d257d25631a6e553abbd7c6f7d88ecdcfb0e9..115dcd4eb841463124be049cd432741c276b5f04 100644 (file)
@@ -1439,6 +1439,7 @@ static int gpt_delete_partition(struct fdisk_context *cxt,
                gpt_recompute_crc(gpt->pheader, gpt->ents);
                gpt_recompute_crc(gpt->bheader, gpt->ents);
                lb->nparts_cur--;
+               fdisk_label_set_changed(lb, 1);
        }
 
        return 0;
@@ -1606,6 +1607,7 @@ static int gpt_add_partition(
        else {
                printf(_("Created partition %d\n"), partnum + 1);
                lb->nparts_cur++;
+               fdisk_label_set_changed(lb, 1);
        }
 
        return 0;
@@ -1670,6 +1672,7 @@ static int gpt_create_disklabel(struct fdisk_context *cxt, struct fdisk_label *l
                            uid->node[0], uid->node[1],
                            uid->node[2], uid->node[3],
                            uid->node[4], uid->node[5]);
+       fdisk_label_set_changed(lb, 1);
 done:
        return rc;
 }
@@ -1721,6 +1724,8 @@ static int gpt_set_partition_type(
        gpt_entry_set_type(&gpt->ents[i], &uuid);
        gpt_recompute_crc(gpt->pheader, gpt->ents);
        gpt_recompute_crc(gpt->bheader, gpt->ents);
+
+       fdisk_label_set_changed(lb, 1);
        return 0;
 }