util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Davidlohr Bueso <dave@gnu.org>
To: Karel Zak <kzak@redhat.com>, Petr Uzel <petr.uzel@suse.cz>
Cc: util-linux <util-linux@vger.kernel.org>
Subject: [PATCH 5/5] fdisk: add fdisk_dev_sectsz_is_default helper
Date: Sun, 03 Jun 2012 20:15:34 +0200	[thread overview]
Message-ID: <1338747334.2864.14.camel@offbook> (raw)

From: Davidlohr Bueso <dave@gnu.org>

Instead of printing this warning from the API, add a helper and call it from fdisk logic.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 fdisk/fdisk.c |    4 ++++
 fdisk/fdisk.h |    1 +
 fdisk/utils.c |   14 +++++++++++---
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index baa5bad..df0d29b 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -2152,6 +2152,10 @@ int main(int argc, char **argv)
 
 	print_welcome();
 
+	if (!fdisk_dev_sectsz_is_default(cxt))
+		printf(_("Note: sector size is %ld (not %d)\n"),
+		       cxt->sector_size, DEFAULT_SECTOR_SIZE);
+
 	gpt_warning(cxt->dev_path);
 	get_boot(cxt, 0);
 
diff --git a/fdisk/fdisk.h b/fdisk/fdisk.h
index a74f25e..6aacc05 100644
--- a/fdisk/fdisk.h
+++ b/fdisk/fdisk.h
@@ -119,6 +119,7 @@ struct fdisk_context {
 
 extern struct fdisk_context *fdisk_new_context_from_filename(const char *fname, int readonly);
 extern int fdisk_dev_has_topology(struct fdisk_context *cxt);
+extern int fdisk_dev_sectsz_is_default(struct fdisk_context *cxt);
 extern void fdisk_free_context(struct fdisk_context *cxt);
 
 /* prototypes for fdisk.c */
diff --git a/fdisk/utils.c b/fdisk/utils.c
index 6fabd82..d57abe9 100644
--- a/fdisk/utils.c
+++ b/fdisk/utils.c
@@ -80,14 +80,22 @@ static int __discover_topology(struct fdisk_context *cxt)
 	cxt->sector_size = __get_sector_size(cxt->dev_fd);
 	if (!cxt->phy_sector_size) /* could not discover physical size */
 		cxt->phy_sector_size = cxt->sector_size;
-	if (cxt->sector_size != DEFAULT_SECTOR_SIZE)
-		printf(_("Note: sector size is %ld (not %d)\n"),
-		       cxt->sector_size, DEFAULT_SECTOR_SIZE);
 
 	return 0;
 }
 
 /**
+ * fdisk_dev_sectsz_is_default:
+ * @cxt: fdisk context
+ *
+ * Returns 1 if the device's sector size is the default value, otherwise 0.
+ */
+int fdisk_dev_sectsz_is_default(struct fdisk_context *cxt)
+{
+	return cxt->sector_size == DEFAULT_SECTOR_SIZE;
+}
+
+/**
  * fdisk_dev_has_topology:
  * @cxt: fdisk context
  *
-- 
1.7.4.1





                 reply	other threads:[~2012-06-03 18:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1338747334.2864.14.camel@offbook \
    --to=dave@gnu.org \
    --cc=kzak@redhat.com \
    --cc=petr.uzel@suse.cz \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).