]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: remove nowarn global variable
authorKarel Zak <kzak@redhat.com>
Tue, 25 Jun 2013 14:40:01 +0000 (16:40 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:47:04 +0000 (16:47 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.c
fdisks/fdisk.h
fdisks/fdiskdoslabel.c
libfdisk/src/context.c
libfdisk/src/fdiskP.h

index c7fe3b48f23805a5d7270754e2fc61374908038c..1ac4dd9b7b0b8f9d283895747039c8d2be883ce2 100644 (file)
@@ -47,8 +47,6 @@
 # include <linux/blkpg.h>
 #endif
 
-int    nowarn = 0;                     /* no warnings for fdisk -l/-s */
-
 static void __attribute__ ((__noreturn__)) usage(FILE *out)
 {
        fputs(USAGE_HEADER, out);
@@ -716,7 +714,7 @@ int main(int argc, char **argv)
                         " be used with one specified device\n"));
 
        if (optl) {
-               nowarn = 1;
+               fdisk_context_enable_listonly(cxt, 1);
                if (argc > optind) {
                        int k;
                        for (k = optind; k < argc; k++)
index c8f94d3317ff974f21057dc914cc2f37eff6c205..9c40d314bfef7e777c80be2c77616fb85a5d06d6 100644 (file)
@@ -40,5 +40,3 @@ extern int warn_geometry(struct fdisk_context *cxt);
 extern void toggle_dos_compatibility_flag(struct fdisk_context *cxt);
 extern void warn_limits(struct fdisk_context *cxt);
 
-extern int nowarn;
-
index f17eb1ef780f2771add9dee0bdb770affba6626d..934312b6ceb0268ec0e24f9b0824b29e61fffd8b 100644 (file)
@@ -1,18 +1,18 @@
 /*
- * Many, many hands.
- * Specific DOS label file  - Davidlohr Bueso <dave@gnu.org>
+ *
+ * Copyright (C) 2013 Karel Zak <kzak@redhat.com>
+ *
+ * This is re-written version for libfdisk, the original was fdiskdoslabel.c
+ * from util-linux fdisk.
  */
-
-#include <unistd.h>
-#include <ctype.h>
-
 #include "c.h"
 #include "nls.h"
 #include "randutils.h"
 #include "common.h"
 #include "pt-mbr.h"
 
-#include "fdisk.h"
+#include "fdiskP.h"
+
 #include "fdiskdoslabel.h"
 
 #define MAXIMUM_PARTS  60
@@ -147,7 +147,7 @@ static int is_cleared_partition(struct dos_partition *p)
 
 static void warn_alignment(struct fdisk_context *cxt)
 {
-       if (nowarn)
+       if (fdisk_context_listonly(cxt))
                return;
 
        if (cxt->sector_size != cxt->phy_sector_size)
@@ -269,7 +269,7 @@ static void dos_init(struct fdisk_context *cxt)
        warn_geometry(cxt);
        warn_alignment(cxt);
 
-       if (cxt->total_sectors > UINT_MAX && !nowarn) {
+       if (cxt->total_sectors > UINT_MAX && !fdisk_context_listonly(cxt)) {
                unsigned long long bytes = cxt->total_sectors * cxt->sector_size;
                int giga = bytes / 1000000000;
                int hectogiga = (giga + 50) / 100;
index 4ee4e0f1b454921340068e0baa190b949bcd209d..f44505a5b37b87ba68c1a585c697a3eef11188d6 100644 (file)
@@ -255,6 +255,29 @@ int fdisk_context_display_details(struct fdisk_context *cxt)
        return cxt->display_details == 1;
 }
 
+/**
+ * fdisk_context_enable_listonly:
+ * cxt: context
+ * enable: true/flase
+ *
+ * Just list partition only, don't care about another details, mistakes, ...
+ *
+ * Returns: 0 on success, < 0 on error.
+ */
+int fdisk_context_enable_listonly(struct fdisk_context *cxt, int enable)
+{
+       assert(cxt);
+       cxt->listonly = enable ? 1 : 0;
+       return 0;
+}
+
+int fdisk_context_listonly(struct fdisk_context *cxt)
+{
+       assert(cxt);
+       return cxt->listonly == 1;
+}
+
+
 /*
  * @str: "cylinder" or "sector".
  *
index 3832c012379ff91b38002c830bc3c0d73e73b61f..88b0a466d2b80a3921793be41fb6ab93bf09c498 100644 (file)
@@ -269,7 +269,8 @@ struct fdisk_context {
        unsigned long alignment_offset;
 
        unsigned int display_in_cyl_units : 1,  /* for obscure labels */
-                    display_details : 1;       /* expert display mode */
+                    display_details : 1,       /* expert display mode */
+                    listonly : 1;              /* list partition, nothing else */
 
        /* alignment */
        unsigned long grain;            /* alignment unit */
@@ -302,6 +303,8 @@ extern int __fdisk_context_switch_label(struct fdisk_context *cxt,
 
 extern int fdisk_context_use_cylinders(struct fdisk_context *cxt);
 extern int fdisk_context_display_details(struct fdisk_context *cxt);
+extern int fdisk_context_enable_listonly(struct fdisk_context *cxt, int enable);
+extern int fdisk_context_listonly(struct fdisk_context *cxt);
 
 
 /* alignment.c */