fdisk: remove nowarn global variable

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2013-06-25 16:40:01 +02:00
parent f8ad389986
commit c10937dcaf
5 changed files with 37 additions and 15 deletions

View 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++)

View 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;

View 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;

View 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".
*

View 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 */