public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Simon Arlott <simon@fire.lp0.eu>
Cc: Matthew Wilcox <matthew@wil.cx>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-scsi <linux-scsi@vger.kernel.org>
Subject: Re: [PATCH 1/2] lib: add generic helper to print sizes rounded to the	correct SI range
Date: Sun, 31 Aug 2008 10:41:52 -0500	[thread overview]
Message-ID: <1220197312.4021.19.camel@localhost.localdomain> (raw)
In-Reply-To: <48BAB6C4.20007@simon.arlott.org.uk>

On Sun, 2008-08-31 at 16:20 +0100, Simon Arlott wrote:
> On 31/08/08 16:13, James Bottomley wrote:
> > This patch adds the ability to print sizes in either units of 10^3 (SI)
> > or 2^10 (Binary) units.  It rounds up to three significant figures and
> > can be used for either memory or storage capacities.
> 
> > +	const char *units_2[] = {"B", "Kib", "MiB", "GiB", "TiB", "PiB",
> 
> I think this should have been "KiB".

Yes, shift slip.

> I'd prefer an option to display these without the "i"...

If anyone ever finds a use for that, possibly ... but with the i is the
NIST way now, so we follow the standards.

> Oh and you need to store the original capacity before it's re-scaled to 
> 512 bytes. Outputting sdkp->capacity at that stage it'll be a count of 
> 512-byte sectors.

Yes, just trying to avoid a multiplication.  I should have just used ffz
instead.

James

---

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index e5e7d78..ef1c06c 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -47,6 +47,7 @@
 #include <linux/blkpg.h>
 #include <linux/delay.h>
 #include <linux/mutex.h>
+#include <linux/string_helpers.h>
 #include <asm/uaccess.h>
 
 #include <scsi/scsi.h>
@@ -1429,27 +1430,21 @@ got_data:
 		 */
 		sector_size = 512;
 	}
+	blk_queue_hardsect_size(sdp->request_queue, sector_size);
+		
 	{
-		/*
-		 * The msdos fs needs to know the hardware sector size
-		 * So I have created this table. See ll_rw_blk.c
-		 * Jacques Gelinas (Jacques@solucorp.qc.ca)
-		 */
-		int hard_sector = sector_size;
-		sector_t sz = (sdkp->capacity/2) * (hard_sector/256);
-		struct request_queue *queue = sdp->request_queue;
-		sector_t mb = sz;
+		char cap_str_2[10], cap_str_10[10];
+		u64 sz = sdkp->capacity << ffz(~sector_size);
 
-		blk_queue_hardsect_size(queue, hard_sector);
-		/* avoid 64-bit division on 32-bit platforms */
-		sector_div(sz, 625);
-		mb -= sz - 974;
-		sector_div(mb, 1950);
+		string_get_size(sz, STRING_UNITS_2, cap_str_2,
+				sizeof(cap_str_2));
+		string_get_size(sz, STRING_UNITS_10, cap_str_10,
+				sizeof(cap_str_10));
 
 		sd_printk(KERN_NOTICE, sdkp,
-			  "%llu %d-byte hardware sectors (%llu MB)\n",
+			  "%llu %d-byte hardware sectors: (%s/%s)\n",
 			  (unsigned long long)sdkp->capacity,
-			  hard_sector, (unsigned long long)mb);
+			  sector_size, cap_str_10, cap_str_2);
 	}
 
 	/* Rescale capacity to 512-byte units */




  reply	other threads:[~2008-08-31 15:42 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-30 14:08 [PATCH] scsi/sd: Fix size output in MB Simon Arlott
2008-08-30 17:24 ` James Bottomley
2008-08-30 17:45   ` Matthew Wilcox
2008-08-30 20:59     ` Pierre Ossman
2008-08-30 21:45       ` James Bottomley
2008-08-30 22:13         ` Pierre Ossman
2008-08-30 22:24           ` Simon Arlott
2008-08-30 22:36           ` Matthew Wilcox
2008-08-30 21:02     ` Simon Arlott
2008-08-30 21:03       ` [PATCH] scsi/sd: Fix capacity output to show MB/GB/TB/ Simon Arlott
2008-08-31  1:59         ` James Bottomley
2008-08-31  2:54           ` Matthew Wilcox
2008-08-31 14:25             ` Ingo Oeser
2008-08-31 15:04               ` Simon Arlott
2008-08-31 15:08             ` James Bottomley
2008-08-31 15:13               ` [PATCH 1/2] lib: add generic helper to print sizes rounded to the correct SI range James Bottomley
2008-08-31 15:20                 ` Simon Arlott
2008-08-31 15:41                   ` James Bottomley [this message]
2008-08-31 15:51                 ` Matthew Wilcox
2008-08-31 18:54                 ` [PATCH] mmc_block: use generic helper to print capacities Pierre Ossman
2008-09-05 20:09                   ` James Bottomley
2008-09-05 20:52                     ` Pierre Ossman
2008-09-05 21:03                       ` James Bottomley
2008-09-06  8:57                         ` Pierre Ossman
2008-09-03  3:39                 ` [PATCH 1/2] lib: add generic helper to print sizes rounded to the correct SI range Andrew Morton
2008-09-03 14:32                   ` James Bottomley
2008-09-03 15:58                     ` Andrew Morton
2008-08-31 15:15               ` [PATCH 2/2] sd: use generic helper to print capacities in both binary and SI James Bottomley
2008-08-31 15:08           ` [PATCH] scsi/sd: Fix capacity output to show MB/GB/TB/ Simon Arlott
2008-08-30 21:57       ` [PATCH] scsi/sd: Fix size output in MB Matthew Wilcox
2008-08-30 22:22         ` Simon Arlott
2008-08-31 12:27         ` James Smart

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=1220197312.4021.19.camel@localhost.localdomain \
    --to=james.bottomley@hansenpartnership.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=simon@fire.lp0.eu \
    /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