* [PATCH 1/5] fdisk: make grain global variable part of fdisk_context()
@ 2012-07-26 14:04 Petr Uzel
2012-07-26 14:04 ` [PATCH 2/5] fdisk: fix typo Petr Uzel
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Petr Uzel @ 2012-07-26 14:04 UTC (permalink / raw)
To: util-linux; +Cc: dave
There is no reason for this to be global variable - it belongs
to the context.
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
fdisks/fdisk.c | 17 ++++++++---------
fdisks/fdisk.h | 3 ++-
fdisks/fdiskdoslabel.c | 2 +-
fdisks/utils.c | 2 ++
4 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
index f00db4a..0aa8a0b 100644
--- a/fdisks/fdisk.c
+++ b/fdisks/fdisk.c
@@ -132,7 +132,6 @@ int nowarn = 0, /* no warnings for fdisk -l/-s */
unsigned int user_cylinders, user_heads, user_sectors;
sector_t sector_offset = 1;
unsigned int units_per_sector = 1, display_in_cyl_units = 0;
-unsigned long grain = DEFAULT_SECTOR_SIZE;
enum fdisk_labeltype disklabel; /* Current disklabel */
static void __attribute__ ((__noreturn__)) usage(FILE *out)
@@ -300,8 +299,8 @@ lba_is_aligned(struct fdisk_context *cxt, sector_t lba)
unsigned int granularity = max(cxt->phy_sector_size, cxt->min_io_size);
unsigned long long offset;
- if (grain > granularity)
- granularity = grain;
+ if (cxt->grain > granularity)
+ granularity = cxt->grain;
offset = (lba * cxt->sector_size) & (granularity - 1);
return !((granularity + cxt->alignment_offset - offset) & (granularity - 1));
@@ -323,7 +322,7 @@ sector_t align_lba(struct fdisk_context *cxt, sector_t lba, int direction)
if (lba_is_aligned(cxt, lba))
res = lba;
else {
- sector_t sects_in_phy = grain / cxt->sector_size;
+ sector_t sects_in_phy = cxt->grain / cxt->sector_size;
if (lba < sector_offset)
res = sector_offset;
@@ -446,7 +445,7 @@ void warn_alignment(struct fdisk_context *cxt)
void
update_sector_offset(struct fdisk_context *cxt)
{
- grain = cxt->io_size;
+ cxt->grain = cxt->io_size;
if (dos_compatible_flag)
sector_offset = cxt->geom.sectors; /* usually 63 sectors */
@@ -481,12 +480,12 @@ update_sector_offset(struct fdisk_context *cxt)
sector_offset = cxt->phy_sector_size / cxt->sector_size;
/* use 1MiB grain always when possible */
- if (grain < 2048 * 512)
- grain = 2048 * 512;
+ if (cxt->grain < 2048 * 512)
+ cxt->grain = 2048 * 512;
/* don't use huge grain on small devices */
- if (cxt->total_sectors <= (grain * 4 / cxt->sector_size))
- grain = cxt->phy_sector_size;
+ if (cxt->total_sectors <= (cxt->grain * 4 / cxt->sector_size))
+ cxt->grain = cxt->phy_sector_size;
}
}
diff --git a/fdisks/fdisk.h b/fdisks/fdisk.h
index 29b57fe..04c25e2 100644
--- a/fdisks/fdisk.h
+++ b/fdisks/fdisk.h
@@ -121,6 +121,8 @@ struct fdisk_context {
unsigned long sector_size; /* logical size */
unsigned long alignment_offset;
+ unsigned long grain; /* alignment unit */
+
/* geometry */
sector_t total_sectors; /* in logical sectors */
struct fdisk_geometry geom;
@@ -237,7 +239,6 @@ enum fdisk_labeltype {
extern enum fdisk_labeltype disklabel;
extern int MBRbuffer_changed;
-extern unsigned long grain;
/* start_sect and nr_sects are stored little endian on all machines */
/* moreover, they are not aligned correctly */
diff --git a/fdisks/fdiskdoslabel.c b/fdisks/fdiskdoslabel.c
index 06c868e..10006f6 100644
--- a/fdisks/fdiskdoslabel.c
+++ b/fdisks/fdiskdoslabel.c
@@ -22,7 +22,7 @@
s |= (sector >> 2) & 0xc0; \
}
-#define alignment_required (grain != cxt->sector_size)
+#define alignment_required (cxt->grain != cxt->sector_size)
struct pte ptes[MAXIMUM_PARTS];
sector_t extended_offset;
diff --git a/fdisks/utils.c b/fdisks/utils.c
index 19aed87..9b69de3 100644
--- a/fdisks/utils.c
+++ b/fdisks/utils.c
@@ -488,6 +488,8 @@ struct fdisk_context *fdisk_new_context_from_filename(const char *fname, int rea
__discover_topology(cxt);
__discover_system_geometry(cxt);
+ cxt->grain = DEFAULT_SECTOR_SIZE;
+
/* detect labels and apply labes specific stuff (e.g geomery)
* to the context */
__probe_labels(cxt);
--
1.7.7
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/5] fdisk: fix typo
2012-07-26 14:04 [PATCH 1/5] fdisk: make grain global variable part of fdisk_context() Petr Uzel
@ 2012-07-26 14:04 ` Petr Uzel
2012-07-26 15:19 ` Karel Zak
2012-07-26 14:04 ` [PATCH 3/5] fdisk: always print total number of sectors Petr Uzel
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Petr Uzel @ 2012-07-26 14:04 UTC (permalink / raw)
To: util-linux; +Cc: dave
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
fdisks/fdisk.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
index 0aa8a0b..3eddfa1 100644
--- a/fdisks/fdisk.c
+++ b/fdisks/fdisk.c
@@ -1561,7 +1561,7 @@ expert_command_prompt(struct fdisk_context *cxt)
if (dos_compatible_flag)
fprintf(stderr, _("Warning: setting "
"sector offset for DOS "
- "compatiblity\n"));
+ "compatibility\n"));
update_sector_offset(cxt);
update_units(cxt);
break;
--
1.7.7
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/5] fdisk: always print total number of sectors
2012-07-26 14:04 [PATCH 1/5] fdisk: make grain global variable part of fdisk_context() Petr Uzel
2012-07-26 14:04 ` [PATCH 2/5] fdisk: fix typo Petr Uzel
@ 2012-07-26 14:04 ` Petr Uzel
2012-07-26 15:20 ` Karel Zak
2012-07-26 14:04 ` [PATCH 4/5] fdisk: don't print CHS geometry unless DOS compatible mode is set Petr Uzel
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Petr Uzel @ 2012-07-26 14:04 UTC (permalink / raw)
To: util-linux; +Cc: dave
Print it no regardless on units_per_sector.
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
fdisks/fdisk.c | 7 +++----
1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
index 3eddfa1..fb897d8 100644
--- a/fdisks/fdisk.c
+++ b/fdisks/fdisk.c
@@ -997,17 +997,16 @@ list_disk_geometry(struct fdisk_context *cxt) {
long megabytes = bytes/1000000;
if (megabytes < 10000)
- printf(_("\nDisk %s: %ld MB, %lld bytes\n"),
+ printf(_("\nDisk %s: %ld MB, %lld bytes"),
cxt->dev_path, megabytes, bytes);
else {
long hectomega = (megabytes + 50) / 100;
- printf(_("\nDisk %s: %ld.%ld GB, %llu bytes\n"),
+ printf(_("\nDisk %s: %ld.%ld GB, %llu bytes"),
cxt->dev_path, hectomega / 10, hectomega % 10, bytes);
}
+ printf(_(", %llu sectors\n"), cxt->total_sectors);
printf(_("%d heads, %llu sectors/track, %llu cylinders"),
cxt->geom.heads, cxt->geom.sectors, cxt->geom.cylinders);
- if (units_per_sector == 1)
- printf(_(", total %llu sectors"), cxt->total_sectors);
printf("\n");
printf(_("Units = %s of %d * %ld = %ld bytes\n"),
str_units(PLURAL),
--
1.7.7
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/5] fdisk: don't print CHS geometry unless DOS compatible mode is set
2012-07-26 14:04 [PATCH 1/5] fdisk: make grain global variable part of fdisk_context() Petr Uzel
2012-07-26 14:04 ` [PATCH 2/5] fdisk: fix typo Petr Uzel
2012-07-26 14:04 ` [PATCH 3/5] fdisk: always print total number of sectors Petr Uzel
@ 2012-07-26 14:04 ` Petr Uzel
2012-07-26 15:21 ` Karel Zak
2012-07-26 14:04 ` [PATCH 5/5] tests: update fdisk test (default output format changed) Petr Uzel
2012-07-26 15:07 ` [PATCH 1/5] fdisk: make grain global variable part of fdisk_context() Karel Zak
4 siblings, 1 reply; 10+ messages in thread
From: Petr Uzel @ 2012-07-26 14:04 UTC (permalink / raw)
To: util-linux; +Cc: dave
References: http://marc.info/?l=util-linux-ng&m=134329693623430&w=2
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
fdisks/fdisk.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
index fb897d8..fa20218 100644
--- a/fdisks/fdisk.c
+++ b/fdisks/fdisk.c
@@ -1005,9 +1005,9 @@ list_disk_geometry(struct fdisk_context *cxt) {
cxt->dev_path, hectomega / 10, hectomega % 10, bytes);
}
printf(_(", %llu sectors\n"), cxt->total_sectors);
- printf(_("%d heads, %llu sectors/track, %llu cylinders"),
- cxt->geom.heads, cxt->geom.sectors, cxt->geom.cylinders);
- printf("\n");
+ if (dos_compatible_flag)
+ printf(_("%d heads, %llu sectors/track, %llu cylinders\n"),
+ cxt->geom.heads, cxt->geom.sectors, cxt->geom.cylinders);
printf(_("Units = %s of %d * %ld = %ld bytes\n"),
str_units(PLURAL),
units_per_sector, cxt->sector_size, units_per_sector * cxt->sector_size);
--
1.7.7
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/5] tests: update fdisk test (default output format changed)
2012-07-26 14:04 [PATCH 1/5] fdisk: make grain global variable part of fdisk_context() Petr Uzel
` (2 preceding siblings ...)
2012-07-26 14:04 ` [PATCH 4/5] fdisk: don't print CHS geometry unless DOS compatible mode is set Petr Uzel
@ 2012-07-26 14:04 ` Petr Uzel
2012-07-26 15:21 ` Karel Zak
2012-07-26 15:07 ` [PATCH 1/5] fdisk: make grain global variable part of fdisk_context() Karel Zak
4 siblings, 1 reply; 10+ messages in thread
From: Petr Uzel @ 2012-07-26 14:04 UTC (permalink / raw)
To: util-linux; +Cc: dave
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
tests/expected/fdisk/align-512-4K | 3 +--
tests/expected/fdisk/align-512-4K-63 | 3 +--
tests/expected/fdisk/align-512-4K-md | 6 ++----
tests/expected/fdisk/align-512-512 | 3 +--
tests/expected/fdisk/align-512-512-topology | 3 +--
tests/expected/fdisk/oddinput | 2 +-
6 files changed, 7 insertions(+), 13 deletions(-)
diff --git a/tests/expected/fdisk/align-512-4K b/tests/expected/fdisk/align-512-4K
index a510c73..293f4ae 100644
--- a/tests/expected/fdisk/align-512-4K
+++ b/tests/expected/fdisk/align-512-4K
@@ -54,8 +54,7 @@ Last sector, +sectors or +size{K,M,G} (90112-102399, default 102399): Using defa
Partition 7 of type Linux and of size 6 MiB is set
Command (m for help):
-Disk /dev/...: 52 MB, 52428800 bytes
-32 heads, 32 sectors/track, 100 cylinders, total 102400 sectors
+Disk /dev/...: 52 MB, 52428800 bytes, 102400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 32768 bytes
diff --git a/tests/expected/fdisk/align-512-4K-63 b/tests/expected/fdisk/align-512-4K-63
index e8192ce..5369ec5 100644
--- a/tests/expected/fdisk/align-512-4K-63
+++ b/tests/expected/fdisk/align-512-4K-63
@@ -54,8 +54,7 @@ Last sector, +sectors or +size{K,M,G} (88063-102399, default 102399): Using defa
Partition 7 of type Linux and of size 7 MiB is set
Command (m for help):
-Disk /dev/...: 52 MB, 52428800 bytes
-32 heads, 32 sectors/track, 100 cylinders, total 102400 sectors
+Disk /dev/...: 52 MB, 52428800 bytes, 102400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 32768 bytes
diff --git a/tests/expected/fdisk/align-512-4K-md b/tests/expected/fdisk/align-512-4K-md
index b0081c6..7b7e4bf 100644
--- a/tests/expected/fdisk/align-512-4K-md
+++ b/tests/expected/fdisk/align-512-4K-md
@@ -25,8 +25,7 @@ Last sector, +sectors or +size{K,M,G} (43008-102399, default 102399): Using defa
Partition 2 of type Linux and of size 29 MiB is set
Command (m for help):
-Disk /dev/...: 52 MB, 52428800 bytes
-32 heads, 32 sectors/track, 100 cylinders, total 102400 sectors
+Disk /dev/...: 52 MB, 52428800 bytes, 102400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 32768 bytes
@@ -69,8 +68,7 @@ Select (default p): Partition number (1-4, default 2): First sector (22528-10009
Last sector, +sectors or +size{K,M,G} (22528-100095, default 100095): Partition 2 of type Linux and of size 10 MiB is set
Command (m for help):
-Disk /dev/md8: 51 MB, 51249152 bytes
-2 heads, 4 sectors/track, 12512 cylinders, total 100096 sectors
+Disk /dev/md8: 51 MB, 51249152 bytes, 100096 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 65536 bytes / 131072 bytes
diff --git a/tests/expected/fdisk/align-512-512 b/tests/expected/fdisk/align-512-512
index 190ad0a..37cfa71 100644
--- a/tests/expected/fdisk/align-512-512
+++ b/tests/expected/fdisk/align-512-512
@@ -50,8 +50,7 @@ Last sector, +sectors or +size{K,M,G} (90112-102399, default 102399): Using defa
Partition 7 of type Linux and of size 6 MiB is set
Command (m for help):
-Disk /dev/loop0: 52 MB, 52428800 bytes
-255 heads, 63 sectors/track, 6 cylinders, total 102400 sectors
+Disk /dev/loop0: 52 MB, 52428800 bytes, 102400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
diff --git a/tests/expected/fdisk/align-512-512-topology b/tests/expected/fdisk/align-512-512-topology
index 2180081..d16233f 100644
--- a/tests/expected/fdisk/align-512-512-topology
+++ b/tests/expected/fdisk/align-512-512-topology
@@ -50,8 +50,7 @@ Last sector, +sectors or +size{K,M,G} (90112-102399, default 102399): Using defa
Partition 7 of type Linux and of size 6 MiB is set
Command (m for help):
-Disk /dev/...: 52 MB, 52428800 bytes
-32 heads, 32 sectors/track, 100 cylinders, total 102400 sectors
+Disk /dev/...: 52 MB, 52428800 bytes, 102400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 32768 bytes
diff --git a/tests/expected/fdisk/oddinput b/tests/expected/fdisk/oddinput
index 65feb03..14f2528 100644
--- a/tests/expected/fdisk/oddinput
+++ b/tests/expected/fdisk/oddinput
@@ -2,7 +2,7 @@ Initialize empty image
f1c9645dbc14efddc7d8a322685f26eb oddinput.img
Empty image listing
-Disk testimage: 10 MB, 10485760 bytes
+Disk testimage: 10 MB, 10485760 bytes, 20480 sectors
255 heads, 63 sectors/track, 1 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
--
1.7.7
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/5] fdisk: make grain global variable part of fdisk_context()
2012-07-26 14:04 [PATCH 1/5] fdisk: make grain global variable part of fdisk_context() Petr Uzel
` (3 preceding siblings ...)
2012-07-26 14:04 ` [PATCH 5/5] tests: update fdisk test (default output format changed) Petr Uzel
@ 2012-07-26 15:07 ` Karel Zak
4 siblings, 0 replies; 10+ messages in thread
From: Karel Zak @ 2012-07-26 15:07 UTC (permalink / raw)
To: Petr Uzel; +Cc: util-linux, dave
On Thu, Jul 26, 2012 at 04:04:24PM +0200, Petr Uzel wrote:
> There is no reason for this to be global variable - it belongs
> to the context.
Yes. Applied, thanks.
> diff --git a/fdisks/utils.c b/fdisks/utils.c
> index 19aed87..9b69de3 100644
> --- a/fdisks/utils.c
> +++ b/fdisks/utils.c
> @@ -488,6 +488,8 @@ struct fdisk_context *fdisk_new_context_from_filename(const char *fname, int rea
> __discover_topology(cxt);
> __discover_system_geometry(cxt);
>
> + cxt->grain = DEFAULT_SECTOR_SIZE;
> +
This is unnecessary now, we call update_sector_offset() here. IMHO this
function should be modified to contains non-DOS stuff only and
renamed to update_alignment_info().
But it would be nice to add label specific update_alignment() to
fdisk_label struct. For DOS compatible mode we can set sector_offset
and grain there.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/5] fdisk: fix typo
2012-07-26 14:04 ` [PATCH 2/5] fdisk: fix typo Petr Uzel
@ 2012-07-26 15:19 ` Karel Zak
0 siblings, 0 replies; 10+ messages in thread
From: Karel Zak @ 2012-07-26 15:19 UTC (permalink / raw)
To: Petr Uzel; +Cc: util-linux, dave
On Thu, Jul 26, 2012 at 04:04:25PM +0200, Petr Uzel wrote:
> fdisks/fdisk.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/5] fdisk: always print total number of sectors
2012-07-26 14:04 ` [PATCH 3/5] fdisk: always print total number of sectors Petr Uzel
@ 2012-07-26 15:20 ` Karel Zak
0 siblings, 0 replies; 10+ messages in thread
From: Karel Zak @ 2012-07-26 15:20 UTC (permalink / raw)
To: Petr Uzel; +Cc: util-linux, dave
On Thu, Jul 26, 2012 at 04:04:26PM +0200, Petr Uzel wrote:
> fdisks/fdisk.c | 7 +++----
> 1 files changed, 3 insertions(+), 4 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 4/5] fdisk: don't print CHS geometry unless DOS compatible mode is set
2012-07-26 14:04 ` [PATCH 4/5] fdisk: don't print CHS geometry unless DOS compatible mode is set Petr Uzel
@ 2012-07-26 15:21 ` Karel Zak
0 siblings, 0 replies; 10+ messages in thread
From: Karel Zak @ 2012-07-26 15:21 UTC (permalink / raw)
To: Petr Uzel; +Cc: util-linux, dave
On Thu, Jul 26, 2012 at 04:04:27PM +0200, Petr Uzel wrote:
> fdisks/fdisk.c | 6 +++---
> 1 files changed, 3 insertions(+), 3 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 5/5] tests: update fdisk test (default output format changed)
2012-07-26 14:04 ` [PATCH 5/5] tests: update fdisk test (default output format changed) Petr Uzel
@ 2012-07-26 15:21 ` Karel Zak
0 siblings, 0 replies; 10+ messages in thread
From: Karel Zak @ 2012-07-26 15:21 UTC (permalink / raw)
To: Petr Uzel; +Cc: util-linux, dave
On Thu, Jul 26, 2012 at 04:04:28PM +0200, Petr Uzel wrote:
> tests/expected/fdisk/align-512-4K | 3 +--
> tests/expected/fdisk/align-512-4K-63 | 3 +--
> tests/expected/fdisk/align-512-4K-md | 6 ++----
> tests/expected/fdisk/align-512-512 | 3 +--
> tests/expected/fdisk/align-512-512-topology | 3 +--
> tests/expected/fdisk/oddinput | 2 +-
> 6 files changed, 7 insertions(+), 13 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2012-07-26 15:21 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-26 14:04 [PATCH 1/5] fdisk: make grain global variable part of fdisk_context() Petr Uzel
2012-07-26 14:04 ` [PATCH 2/5] fdisk: fix typo Petr Uzel
2012-07-26 15:19 ` Karel Zak
2012-07-26 14:04 ` [PATCH 3/5] fdisk: always print total number of sectors Petr Uzel
2012-07-26 15:20 ` Karel Zak
2012-07-26 14:04 ` [PATCH 4/5] fdisk: don't print CHS geometry unless DOS compatible mode is set Petr Uzel
2012-07-26 15:21 ` Karel Zak
2012-07-26 14:04 ` [PATCH 5/5] tests: update fdisk test (default output format changed) Petr Uzel
2012-07-26 15:21 ` Karel Zak
2012-07-26 15:07 ` [PATCH 1/5] fdisk: make grain global variable part of fdisk_context() Karel Zak
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).