diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c index c7fe3b48f..1ac4dd9b7 100644 --- a/fdisks/fdisk.c +++ b/fdisks/fdisk.c @@ -47,8 +47,6 @@ # include #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++) diff --git a/fdisks/fdisk.h b/fdisks/fdisk.h index c8f94d331..9c40d314b 100644 --- a/fdisks/fdisk.h +++ b/fdisks/fdisk.h @@ -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; - diff --git a/fdisks/fdiskdoslabel.c b/fdisks/fdiskdoslabel.c index f17eb1ef7..934312b6c 100644 --- a/fdisks/fdiskdoslabel.c +++ b/fdisks/fdiskdoslabel.c @@ -1,18 +1,18 @@ /* - * Many, many hands. - * Specific DOS label file - Davidlohr Bueso + * + * Copyright (C) 2013 Karel Zak + * + * This is re-written version for libfdisk, the original was fdiskdoslabel.c + * from util-linux fdisk. */ - -#include -#include - #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; diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index 4ee4e0f1b..f44505a5b 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -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". * diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h index 3832c0123..88b0a466d 100644 --- a/libfdisk/src/fdiskP.h +++ b/libfdisk/src/fdiskP.h @@ -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 */