]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (sun) move driver from fdisk to library
authorKarel Zak <kzak@redhat.com>
Thu, 2 May 2013 13:40:36 +0000 (15:40 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:46:54 +0000 (16:46 +0200)
 ... and also add fdisk_info_new_partition()

Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/Makemodule.am
fdisks/fdisk.c
fdisks/fdisk.h
fdisks/fdiskdoslabel.c
fdisks/fdisksgilabel.c
fdisks/fdisksunlabel.h [deleted file]
libfdisk/src/Makemodule.am
libfdisk/src/ask.c
libfdisk/src/fdiskP.h
libfdisk/src/libfdisk.h
libfdisk/src/sun.c [moved from fdisks/fdisksunlabel.c with 98% similarity]

index ebda3361d11e4909467e03a730647d150e69ce23..7532d6d23f9d7ade93d45f5cdc492c2fa4e42f27 100644 (file)
@@ -17,8 +17,6 @@ fdisk_SOURCES = \
        fdisks/fdiskmaclabel.h \
        fdisks/fdisksgilabel.c \
        fdisks/fdisksgilabel.h \
-       fdisks/fdisksunlabel.c \
-       fdisks/fdisksunlabel.h \
        fdisks/partname.c \
        fdisks/common.h
 
index 0149d59f0a42a8327c67160edca3435475a913b3..1964e4af89787f7d214507d8f8015e16933975ee 100644 (file)
@@ -35,7 +35,7 @@
 #include "strutils.h"
 #include "closestream.h"
 
-#include "fdisksunlabel.h"
+#include "pt-sun.h"            /* to toggle flags */
 #include "fdisksgilabel.h"
 #include "fdiskmaclabel.h"
 #include "fdiskdoslabel.h"
@@ -683,18 +683,6 @@ static void verify(struct fdisk_context *cxt)
        fdisk_verify_disklabel(cxt);
 }
 
-void print_partition_size(struct fdisk_context *cxt,
-                         int num, sector_t start, sector_t stop, int sysid)
-{
-       char *str = size_to_human_string(SIZE_SUFFIX_3LETTER | SIZE_SUFFIX_SPACE,
-                                    (uint64_t)(stop - start + 1) * cxt->sector_size);
-       struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sysid);
-
-       printf(_("Partition %d of type %s and of size %s is set\n"),
-                       num, t ? t->name : _("Unknown"), str);
-       free(str);
-}
-
 static void new_partition(struct fdisk_context *cxt)
 {
        assert(cxt);
index 99ef3255ea9dcc35c75742016d902e2c64337053..45d86c94a1fdc0d0d0036b5233dd87fb1bdf7651 100644 (file)
@@ -84,7 +84,6 @@ extern unsigned int read_int(struct fdisk_context *cxt,
                             unsigned int low, unsigned int dflt,
                             unsigned int high, unsigned int base, char *mesg);
 extern void print_menu(struct fdisk_context *cxt, enum menutype menu);
-extern void print_partition_size(struct fdisk_context *cxt, int num, sector_t start, sector_t stop, int sysid);
 
 extern char *partition_type(struct fdisk_context *cxt, unsigned char type);
 extern char read_chars(struct fdisk_context *cxt, char *mesg);
@@ -94,9 +93,6 @@ extern unsigned int read_int_with_suffix(struct fdisk_context *cxt,
                                         unsigned int low, unsigned int dflt, unsigned int high,
                                  unsigned int base, char *mesg, int *is_suffix_used);
 
-#define PLURAL 0
-#define SINGULAR 1
-
 extern sector_t get_nr_sects(struct partition *p);
 
 extern int nowarn;
index 5fd1da8230be213d7ef8941b444fb75eaa75b628..44dc40e12b7577f53624d041929d641d4ea6f06f 100644 (file)
@@ -522,9 +522,10 @@ static void set_partition(struct fdisk_context *cxt,
        set_start_sect(p, start - offset);
        set_nr_sects(p, stop - start + 1);
 
-       if (!doext)
-               print_partition_size(cxt, i + 1, start, stop, sysid);
-
+       if (!doext) {
+               struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sysid);
+               fdisk_info_new_partition(cxt, i + 1, start, stop, t);
+       }
        if (is_dos_compatible(cxt) && (start/(cxt->geom.sectors*cxt->geom.heads) > 1023))
                start = cxt->geom.heads*cxt->geom.sectors*1024 - 1;
        set_hsc(p->head, p->sector, p->cyl, start);
index 796b4580fc0afad889698df1dd68dae2e3397c72..15a25c503f5be9861ffc459e4767f491315b71aa 100644 (file)
@@ -629,8 +629,10 @@ static int sgi_set_partition(struct fdisk_context *cxt, size_t i,
 
        if (sgi_gaps(cxt) < 0)  /* rebuild freelist */
                printf(_("Partition overlap on the disk.\n"));
-       if (length)
-               print_partition_size(cxt, i + 1, start, start + length, sys);
+       if (length) {
+               struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sys);
+               fdisk_info_new_partition(cxt, i + 1, start, start + length, t);
+       }
 
        return 0;
 }
diff --git a/fdisks/fdisksunlabel.h b/fdisks/fdisksunlabel.h
deleted file mode 100644 (file)
index f973725..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef FDISK_SUN_LABEL_H
-#define FDISK_SUN_LABEL_H
-
-#include "pt-sun.h"
-
-/* public SUN specific functions (TODO: move to libfdisk.h) */
-extern void fdisk_sun_set_alt_cyl(struct fdisk_context *cxt);
-extern void fdisk_sun_set_ncyl(struct fdisk_context *cxt, int cyl);
-extern void fdisk_sun_set_xcyl(struct fdisk_context *cxt);
-extern void fdisk_sun_set_ilfact(struct fdisk_context *cxt);
-extern void fdisk_sun_set_rspeed(struct fdisk_context *cxt);
-extern void fdisk_sun_set_pcylcount(struct fdisk_context *cxt);
-
-#endif /* FDISK_SUN_LABEL_H */
index 3858e7b0964bdbc51980d548cc5ce1d4f2677a16..3ea1fa44925e79bfeb537fe868aa0931d95915fd 100644 (file)
@@ -17,6 +17,8 @@ libfdisk_la_SOURCES = \
        libfdisk/src/utils.c \
        libfdisk/src/context.c \
        libfdisk/src/parttype.c \
+       \
+       libfdisk/src/sun.c \
        libfdisk/src/gpt.c
 
 
index a95d54233ea013c87e806c37b8befea09cf105c2..0127d645a07085dc2157de0cb2e85b871a326148 100644 (file)
@@ -532,6 +532,21 @@ int fdisk_warnx(struct fdisk_context *cxt, const char *fmt, ...)
        return rc;
 }
 
+int fdisk_info_new_partition(
+                       struct fdisk_context *cxt,
+                       int num, sector_t start, sector_t stop,
+                       struct fdisk_parttype *t)
+{
+       int rc;
+       char *str = size_to_human_string(SIZE_SUFFIX_3LETTER | SIZE_SUFFIX_SPACE,
+                                    (uint64_t)(stop - start + 1) * cxt->sector_size);
+
+       rc = fdisk_info(cxt, _("Partition %d of type %s and of size %s is set\n"),
+                       num, t ? t->name : _("Unknown"), str);
+       free(str);
+       return rc;
+}
+
 #ifdef TEST_PROGRAM
 struct fdisk_label *fdisk_new_dos_label(struct fdisk_context *cxt) { return NULL; }
 struct fdisk_label *fdisk_new_bsd_label(struct fdisk_context *cxt) { return NULL; }
index 4dd4db6c9932e352eb70594f5098842c7667ca63..e05bb86287d0e0d77522a272cb317103eadba984 100644 (file)
@@ -327,13 +327,24 @@ extern int fdisk_probe_labels(struct fdisk_context *cxt);
 extern void fdisk_deinit_label(struct fdisk_label *lb);
 
 
-/* gpt.c -- temporary bypass library API... */
-extern void gpt_list_table(struct fdisk_context *cxt, int xtra);
-
 /* ask.c */
 extern int fdisk_ask_partnum(struct fdisk_context *cxt, size_t *partnum, int wantnew);
 
 extern struct tt *fdisk_ask_get_table(struct fdisk_ask *ask);
 extern int fdisk_print_table(struct fdisk_context *cxt, struct tt *tb);
 
+extern int fdisk_info_new_partition(
+                       struct fdisk_context *cxt,
+                       int num, sector_t start, sector_t stop,
+                       struct fdisk_parttype *t);
+
+/* sun.h */
+extern void fdisk_sun_set_alt_cyl(struct fdisk_context *cxt);
+extern void fdisk_sun_set_ncyl(struct fdisk_context *cxt, int cyl);
+extern void fdisk_sun_set_xcyl(struct fdisk_context *cxt);
+extern void fdisk_sun_set_ilfact(struct fdisk_context *cxt);
+extern void fdisk_sun_set_rspeed(struct fdisk_context *cxt);
+extern void fdisk_sun_set_pcylcount(struct fdisk_context *cxt);
+
+
 #endif /* _LIBFDISK_PRIVATE_H */
index b7c2735d136b7acbc65080ea4fb77390cdc2d330..b414ff7bcb680e959e306586b6f3195a7ad3357e 100644 (file)
@@ -88,7 +88,11 @@ extern int fdisk_context_switch_label(struct fdisk_context *cxt,
                                const char *name);
 
 extern int fdisk_context_set_unit(struct fdisk_context *cxt, const char *str);
+
+#define PLURAL 0
+#define SINGULAR 1
 extern const char *fdisk_context_get_unit(struct fdisk_context *cxt, int n);
+
 extern unsigned int fdisk_context_get_units_per_sector(struct fdisk_context *cxt);
 
 extern int fdisk_context_enable_details(struct fdisk_context *cxt, int enable);
similarity index 98%
rename from fdisks/fdisksunlabel.c
rename to libfdisk/src/sun.c
index 864a8b5a6593735e3e304079e4e749e34eef633f..e7a1c879ea6e5cd0de21819aeca530eb3c89f78c 100644 (file)
@@ -1,15 +1,11 @@
 /*
- * fdisksunlabel.c
+ * Copyright (C) 2013 Karel Zak <kzak@redhat.com>
  *
- * I think this is mostly, or entirely, due to
- *     Jakub Jelinek (jj@sunsite.mff.cuni.cz), July 1996
- *
- * Merged with fdisk for other architectures, aeb, June 1998.
- *
- * Sat Mar 20 EST 1999 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
- *      Internationalization
+ * Based on original code from fdisk:
+ *   Jakub Jelinek (jj@sunsite.mff.cuni.cz), July 1996
+ *   Merged with fdisk for other architectures, aeb, June 1998.
+ *   Arnaldo Carvalho de Melo <acme@conectiva.com.br> Mar 1999, Internationalization
  */
-
 #include <stdio.h>             /* stderr */
 #include <stdlib.h>            /* qsort */
 #include <string.h>            /* strstr */
 #include "blkdev.h"
 #include "bitops.h"
 
-#include "common.h"
-#include "fdisk.h"
-#include "fdiskdoslabel.h"
-#include "fdisksunlabel.h"
+#include "fdiskP.h"
+#include "pt-sun.h"
+#include "all-io.h"
 
 /*
  * in-memory fdisk SUN stuff
@@ -77,6 +72,7 @@ static void set_sun_partition(struct fdisk_context *cxt, size_t i,
                uint32_t start,uint32_t stop, uint16_t sysid)
 {
        struct sun_disklabel *sunlabel = self_disklabel(cxt);
+       struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sysid);
 
        sunlabel->vtoc.infos[i].id = cpu_to_be16(sysid);
        sunlabel->vtoc.infos[i].flags = cpu_to_be16(0);
@@ -84,7 +80,8 @@ static void set_sun_partition(struct fdisk_context *cxt, size_t i,
                cpu_to_be32(start / (cxt->geom.heads * cxt->geom.sectors));
        sunlabel->partitions[i].num_sectors = cpu_to_be32(stop - start);
        fdisk_label_set_changed(cxt->label, 1);
-       print_partition_size(cxt, i + 1, start, stop, sysid);
+
+       fdisk_info_new_partition(cxt, i + 1, start, stop, t);
 }
 
 static size_t count_used_partitions(struct fdisk_context *cxt)
@@ -842,6 +839,7 @@ static int sun_write_disklabel(struct fdisk_context *cxt)
        struct sun_disklabel *sunlabel;
        unsigned short *ush;
        unsigned short csum = 0;
+       const size_t sz = sizeof(struct sun_disklabel);
 
        assert(cxt);
        assert(cxt->label);
@@ -855,7 +853,7 @@ static int sun_write_disklabel(struct fdisk_context *cxt)
        sunlabel->csum = csum;
        if (lseek(cxt->dev_fd, 0, SEEK_SET) < 0)
                return -errno;
-       if (write(cxt->dev_fd, sunlabel, SECTOR_SIZE) != SECTOR_SIZE)
+       if (write_all(cxt->dev_fd, sunlabel, sz) != 0)
                return -errno;
 
        return 0;