Mageia Bugzilla – Attachment 595 Details for
Bug 1215
Partitioning issues with 4k drives ("advanced format")
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
[patch]
WIP patch for non-512-byte logical sector sizes
0001-WIP-non-512-sectors-e.g.-4k.patch (text/plain), 34.10 KB, created by
Anssi Hannula
on 2011-06-20 21:11:07 CEST
(
hide
)
Description:
WIP patch for non-512-byte logical sector sizes
Filename:
MIME Type:
Creator:
Anssi Hannula
Created:
2011-06-20 21:11:07 CEST
Size:
34.10 KB
patch
obsolete
>From c5a3bb69c3fdf37dac69680b2e6017889f30307d Mon Sep 17 00:00:00 2001 >From: Anssi Hannula <anssi.hannula@iki.fi> >Date: Mon, 20 Jun 2011 20:58:08 +0300 >Subject: [PATCH] WIP non 512 sectors, e.g. 4k > >--- > perl-install/c/stuff.xs.pl | 9 ++-- > perl-install/common.pm | 7 +-- > perl-install/diskdrake/hd_gtk.pm | 7 ++- > perl-install/diskdrake/interactive.pm | 87 +++++++++++++++++++------------- > perl-install/diskdrake/resize_ext2.pm | 4 +- > perl-install/diskdrake/resize_ntfs.pm | 4 +- > perl-install/fs.pm | 2 +- > perl-install/fs/any.pm | 18 ++++-- > perl-install/fs/partitioning_wizard.pm | 20 ++++--- > perl-install/install/any.pm | 2 +- > perl-install/partition_table.pm | 17 ++++--- > perl-install/partition_table/dos.pm | 3 +- > perl-install/partition_table/raw.pm | 36 ++++++++++++-- > perl-install/resize_fat/any.pm | 15 ++--- > perl-install/resize_fat/boot_sector.pm | 6 +- > perl-install/resize_fat/main.pm | 14 +++--- > 16 files changed, 153 insertions(+), 98 deletions(-) > >diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl >index 1dbc968..ad12ef1 100644 >--- a/perl-install/c/stuff.xs.pl >+++ b/perl-install/c/stuff.xs.pl >@@ -26,6 +26,7 @@ print ' > #include <linux/keyboard.h> > #include <linux/kd.h> > #include <linux/hdreg.h> >+#include <linux/fs.h> > #include <linux/vt.h> > #include <linux/fd.h> > #include <linux/cdrom.h> >@@ -214,14 +215,14 @@ floppy_info(name) > RETVAL > > NV >-total_sectors(fd) >+total_size(fd) > int fd > CODE: > { > unsigned long long ll; > unsigned long l; >- RETVAL = ioctl(fd, BLKGETSIZE64, &ll) == 0 ? ll / 512 : >- ioctl(fd, BLKGETSIZE, &l) == 0 ? l : 0; >+ RETVAL = ioctl(fd, BLKGETSIZE64, &ll) == 0 ? ll : >+ ioctl(fd, BLKGETSIZE, &l) == 0 ? (long long)l * 512: 0; > } > OUTPUT: > RETVAL >@@ -705,7 +706,7 @@ disk_add_partition(char * device_path, double start, double length, const char * > > @macros = ( > [ qw(int S_IFCHR S_IFBLK S_IFIFO S_IFMT KDSKBENT K_NOSUCHMAP NR_KEYS MAX_NR_KEYMAPS BLKRRPART TIOCSCTTY >- HDIO_GETGEO LOOP_GET_STATUS >+ HDIO_GETGEO BLKSSZGET LOOP_GET_STATUS > MS_MGC_VAL O_WRONLY O_RDWR O_CREAT O_NONBLOCK F_SETFL F_GETFL WNOHANG > VT_ACTIVATE VT_WAITACTIVE VT_GETSTATE > CDROMEJECT CDROMCLOSETRAY CDROM_LOCKDOOR >diff --git a/perl-install/common.pm b/perl-install/common.pm >index fb42180..24646c8 100644 >--- a/perl-install/common.pm >+++ b/perl-install/common.pm >@@ -21,7 +21,7 @@ $::prefix ||= ""; # no warning > #-##################################################################################### > #- Globals > #-##################################################################################### >-our $SECTORSIZE = 512; >+our $DEFAULT_SECTORSIZE = 512; > > #-##################################################################################### > #- Functions >@@ -112,11 +112,10 @@ sub nonblock { > fcntl($F, c::F_SETFL(), fcntl($F, c::F_GETFL(), 0) | c::O_NONBLOCK()) or die "cannot fcntl F_SETFL: $!"; > } > >-#- return a size in sector >-#- ie MB(1) is 2048 sectors, which is 1MB >+#- return the size in bytes > sub MB { > my ($nb_MB) = @_; >- $nb_MB * 2048; >+ $nb_MB * 1024 * 1024; > } > > sub removeXiBSuffix { >diff --git a/perl-install/diskdrake/hd_gtk.pm b/perl-install/diskdrake/hd_gtk.pm >index 977c32a..6b8f775 100644 >--- a/perl-install/diskdrake/hd_gtk.pm >+++ b/perl-install/diskdrake/hd_gtk.pm >@@ -257,7 +257,8 @@ sub current_kind_changed { > $kind->{type} eq 'loopback' ? @$v : fs::get::hds_fstab_and_holes($v); > my $totalsectors = > $kind->{type} =~ /raid|loopback/ ? sum(map { $_->{size} } @parts) : $v->{totalsectors}; >- create_buttons4partitions($kind, $totalsectors, @parts); >+ my $sector_size = ($v->{sector_size} || $DEFAULT_SECTOR_SIZE); >+ create_buttons4partitions($kind, $totalsectors, $sector_size, @parts); > } > > sub current_entry_changed { >@@ -296,7 +297,7 @@ sub create_automatic_notebooks { > # parts: helpers > ################################################################################ > sub create_buttons4partitions { >- my ($kind, $totalsectors, @parts) = @_; >+ my ($kind, $totalsectors, $sector_size, @parts) = @_; > > $width = first($w->{window}->window->get_size) - first(get_action_box_size()) - 25 if $w->{window}->window; > >@@ -320,7 +321,7 @@ sub create_buttons4partitions { > $entry = $p if $p; > } > my $info = $entry->{mntpoint} || $entry->{device_LABEL}; >- $info .= "\n" . ($entry->{size} ? formatXiB($entry->{size}, 512) : N("Unknown")) if $info; >+ $info .= "\n" . ($entry->{size} ? formatXiB($entry->{size}, $sector_size) : N("Unknown")) if $info; > my $w = Gtk2::ToggleButton->new_with_label($info) or internal_error('new_with_label'); > $w->signal_connect(clicked => sub { > $current_button != $w or return; >diff --git a/perl-install/diskdrake/interactive.pm b/perl-install/diskdrake/interactive.pm >index 600079c..76f9cb1 100644 >--- a/perl-install/diskdrake/interactive.pm >+++ b/perl-install/diskdrake/interactive.pm >@@ -3,6 +3,7 @@ package diskdrake::interactive; # $Id: interactive.pm 269771 2010-06-03 11:50:24 > use diagnostics; > use strict; > use utf8; >+use POSIX qw(ceil); > > use common; > use fs::type; >@@ -131,6 +132,7 @@ struct geom { > > struct hd { > int totalsectors # size in sectors >+ int sector_size # bytes per sector > string device # 'hda', 'sdc' ... > string device_alias # 'cdrom', 'floppy' ... > string media_type # one of { 'hd', 'cdrom', 'fd', 'tape' } >@@ -479,7 +481,7 @@ sub Create { > #- one. > my ($primaryOrExtended, $migrate_files); > my $type_name = fs::type::part2type_name($part); >- my $mb_size = to_Mb($part->{size}); >+ my $mb_size = to_Mb($part->{size}, $hd); > my $has_startsector = ($::expert || arch() !~ /i.86/) && !isLVM($hd); > my $use_dmcrypt; > my $requested_type; >@@ -489,9 +491,9 @@ sub Create { > { label => N("Create a new partition"), title => 1 }, > if_($has_startsector, > { label => N("Start sector: "), val => \$part->{start}, min => $def_start, max => ($max - min_partition_size($hd)), >- type => 'range', SpinButton => $::expert, changed => sub { $mb_size = min($mb_size, to_Mb($max - $part->{start})) } }, >+ type => 'range', SpinButton => $::expert, changed => sub { $mb_size = min($mb_size, to_Mb($max - $part->{start}, $hd)) } }, > ), >- { label => N("Size in MB: "), val => \$mb_size, min => to_Mb(min_partition_size($hd)), max => to_Mb($def_size), >+ { label => N("Size in MB: "), val => \$mb_size, min => to_Mb(min_partition_size($hd), $hd), max => to_Mb($def_size, $hd), > type => 'range', SpinButton => $::expert, changed => sub { $part->{start} = min($part->{start}, $max - $mb_size * 2048) } }, > { label => N("Filesystem type: "), val => \$type_name, list => [ fs::type::type_names($::expert, $hd) ], > sort => 0, if_($::expert, gtk => { wrap_width => 2 }, do_not_ellipsize => 1) }, >@@ -508,7 +510,7 @@ sub Create { > { label => N("Encryption key "), val => \$part->{dmcrypt_key}, disabled => sub { !$use_dmcrypt }, hidden => 1, weakness_check => 1 }, > { label => N("Encryption key (again)"), val => \$part->{dmcrypt_key2}, disabled => sub { !$use_dmcrypt }, hidden => 1 }, > ], complete => sub { >- $part->{size} = from_Mb($mb_size, min_partition_size($hd), $max - $part->{start}); #- need this to be able to get back the approximation of using MB >+ $part->{size} = from_Mb($mb_size, $hd, min_partition_size($hd), $max - $part->{start}); #- need this to be able to get back the approximation of using MB > $do_suggest_mount_point = 0 if !$part->{mntpoint}; > put_in_hash($part, fs::type::type_name2subpart($type_name)); > $part->{mntpoint} = '' if isNonMountable($part); >@@ -766,6 +768,14 @@ sub Resize { > > my ($min, $max) = (min_partition_size($hd), max_partition_resize($hd, $low_part)); > >+ my $sectors2bytes = sub { >+ my ($sectors) = @_; >+ $sectors * ($hd->{sector_size} || $DEFAULT_SECTORSIZE); >+ } >+ >+ my $min_b = $sectors2bytes->($min); >+ my $max_b = $sectors2bytes->($max); >+ > if (maybeFormatted($part)) { > # here we may have a non-formatted or a formatted partition > # -> doing as if it was formatted >@@ -777,13 +787,13 @@ sub Resize { > > require resize_fat::main; > $nice_resize{fat} = resize_fat::main->new($part->{device}, devices::make($part->{device})); >- $min = max($min, $nice_resize{fat}->min_size); >- $max = min($max, $nice_resize{fat}->max_size); >+ $min_b = max($min_b, $nice_resize{fat}->min_size); >+ $max_b = min($max_b, $nice_resize{fat}->max_size); > } elsif (member($part->{fs_type}, qw(ext2 ext3 ext4))) { > write_partitions($in, $hd) or return; > require diskdrake::resize_ext2; > if ($nice_resize{ext2} = diskdrake::resize_ext2->new($part->{device}, devices::make($part->{device}))) { >- $min = max($min, $nice_resize{ext2}->min_size); >+ $min_b = max($min_b, $nice_resize{ext2}->min_size); > } else { > delete $nice_resize{ext2}; > } >@@ -792,26 +802,31 @@ sub Resize { > require diskdrake::resize_ntfs; > diskdrake::resize_ntfs::check_prog($in) or return; > $nice_resize{ntfs} = diskdrake::resize_ntfs->new($part->{device}, devices::make($part->{device})); >- $min = $nice_resize{ntfs}->min_size or delete $nice_resize{ntfs}; >+ $min_b = $nice_resize{ntfs}->min_size or delete $nice_resize{ntfs}; > } elsif ($part->{fs_type} eq 'reiserfs') { > write_partitions($in, $hd) or return; > if ($part->{isMounted}) { > $nice_resize{reiserfs} = 1; >- $min = $part->{size}; #- ensure the user can only increase >+ $min_b = $sectors2bytes->($part->{size}); #- ensure the user can only increase > } elsif (defined(my $free = fs::df($part))) { > $nice_resize{reiserfs} = 1; >- $min = max($min, $part->{size} - $free); >+ $min_b = max($min_b, $sectors2bytes->($part->{size}) - $free * 1024); > } > } elsif ($part->{fs_type} eq 'xfs' && isLVM($hd) && $::isStandalone && $part->{isMounted}) { >- $min = $part->{size}; #- ensure the user can only increase >+ $min_b = $sectors2bytes->($part->{size}); #- ensure the user can only increase > $nice_resize{xfs} = 1; > } elsif ($part->{fs_type} eq 'btrfs') { > write_partitions($in, $hd) or return; > if (defined(my $free = fs::df($part))) { > $nice_resize{btrfs} = 1; >- $min = max($min, $part->{size} - $free); >+ $min_b = max($min_b, $sectors2bytes->($part->{size}) - $free * 1024); > } > } >+ >+ # ceil() as we want to round partial sectors up >+ $min = ceil($min_b / ($hd->{sector_size} || $DEFAULT_SECTORSIZE)); >+ $max = int($max_b / ($hd->{sector_size} || $DEFAULT_SECTORSIZE)); >+ > #- make sure that even after normalizing the size to cylinder boundaries, the minimun will be saved, > #- this save at least a cylinder (less than 8Mb). > $min += partition_table::raw::cylinder_size($hd); >@@ -826,8 +841,8 @@ sub Resize { > } > } > >- my $mb_size = to_Mb($part->{size}); >- my ($gmin, $gmax) = (to_Mb($min), to_Mb($max)); >+ my $mb_size = to_Mb($part->{size}, $hd); >+ my ($gmin, $gmax) = (to_Mb($min, $hd), to_Mb($max, $hd)); > $in->ask_from(N("Resize"), '', [ > { label => N("Choose the new size"), title => 1 }, > { label => N("New size in MB: "), val => \$mb_size, min => $gmin, max => $gmax, type => 'range', SpinButton => $::expert }, >@@ -836,7 +851,7 @@ sub Resize { > ]) or return; > > >- my $size = from_Mb($mb_size, $min, $max); >+ my $size = from_Mb($mb_size, $hd, $min, $max); > $part->{size} == $size and return; > > my $oldsize = $part->{size}; >@@ -870,20 +885,22 @@ sub Resize { > > my $wait = $in->wait_message(N("Please wait"), N("Resizing")); > >+ my $new_fs_size = $part->{size} * ($hd->{sector_size} || $DEFAULT_SECTORSIZE); >+ > if ($nice_resize{fat}) { > local *log::l = sub { $wait->set(join(' ', @_)) }; >- $nice_resize{fat}->resize($part->{size}); >+ $nice_resize{fat}->resize($new_fs_size); > } elsif ($nice_resize{ext2}) { >- $nice_resize{ext2}->resize($part->{size}); >+ $nice_resize{ext2}->resize($new_fs_size); > } elsif ($nice_resize{ntfs}) { >- log::l("ntfs resize to $part->{size} sectors"); >- $nice_resize{ntfs}->resize($part->{size}); >+ log::l("ntfs resize to $part->{size} sectors, $new_fs_size bytes"); >+ $nice_resize{ntfs}->resize($new_fs_size); > $wait = undef; > $in->ask_warn(N("Warning"), N("To ensure data integrity after resizing the partition(s), > filesystem checks will be run on your next boot into Microsoft Windows®")); > } elsif ($nice_resize{reiserfs}) { >- log::l("reiser resize to $part->{size} sectors"); >- run_program::run_or_die('resize_reiserfs', '-f', '-q', '-s' . int($part->{size}/2) . 'K', devices::make($part->{device})); >+ log::l("reiser resize to $part->{size} sectors, $new_fs_size bytes"); >+ run_program::run_or_die('resize_reiserfs', '-f', '-q', '-s' . int($new_fs_size/1024) . 'K', devices::make($part->{device})); > } elsif ($nice_resize{xfs}) { > #- happens only with mounted LVM, see above > run_program::run_or_die("xfs_growfs", $part->{mntpoint}); >@@ -895,7 +912,7 @@ filesystem checks will be run on your next boot into Microsoft Windows®")); > mkdir_p($dir); > fs::mount::mount(devices::make($part->{device}), $dir, $part->{fs_type}); > } >- if (!run_program::run("btrfsctl", "-r", $part->{size}*512, $dir)) { >+ if (!run_program::run("btrfsctl", "-r", $new_fs_size, $dir)) { > $nice_resize{btrfs} = undef; > if (!$part->{isMounted}) { > fs::mount::umount($dir); >@@ -1060,10 +1077,10 @@ sub Loopback { > delete $part->{mntpoint}; # we do not want the suggested mntpoint > > my $type_name = fs::type::part2type_name($part); >- my $mb_size = to_Mb($part->{size}); >+ my $mb_size = to_Mb($part->{size}, $hd); > $in->ask_from(N("Loopback"), '', [ > { label => N("Loopback file name: "), val => \$part->{loopback_file} }, >- { label => N("Size in MB: "), val => \$mb_size, min => to_Mb($min), max => to_Mb($max), type => 'range', SpinButton => $::expert }, >+ { label => N("Size in MB: "), val => \$mb_size, min => to_Mb($min, $hd), max => to_Mb($max, $hd), type => 'range', SpinButton => $::expert }, > { label => N("Filesystem type: "), val => \$type_name, list => [ fs::type::type_names($::expert, $hd) ], not_edit => !$::expert, sort => 0 }, > ], > complete => sub { >@@ -1073,9 +1090,9 @@ sub Loopback { > $size == -1 and $in->ask_warn(N("Warning"), N("File is already used by another loopback, choose another one")), return 1, 0; > $in->ask_yesorno(N("Warning"), N("File already exists. Use it?")) or return 1, 0; > delete $part->{notFormatted}; >- $part->{size} = divide($size, 512); >+ $part->{size} = int($size, $hd->{sector_size} || $DEFAULT_SECTORSIZE); > } else { >- $part->{size} = from_Mb($mb_size, $min, $max); >+ $part->{size} = from_Mb($mb_size, $hd, $min, $max); > } > 0; > }) or return; >@@ -1343,15 +1360,15 @@ sub warn_if_renumbered { > #- a partition ($mb) given from the interface (on Resize or Create). > #- modified to take into account a true bounding with min and max. > sub from_Mb { >- my ($mb, $min, $max) = @_; >- $mb <= to_Mb($min) and return $min; >- $mb >= to_Mb($max) and return $max; >- $mb * 2048; >+ my ($mb, $hd, $min, $max) = @_; >+ $mb <= to_Mb($min, $hd) and return $min; >+ $mb >= to_Mb($max, $hd) and return $max; >+ to_int($mb * 1024 * 1024 / ($hd->{sector_size} || $DEFAULT_SECTORSIZE)); > } > > sub to_Mb { >- my ($size_sector) = @_; >- to_int($size_sector / 2048); >+ my ($size_sector, $hd) = @_; >+ to_int($size_sector * ($hd->{sector_size} || $DEFAULT_SECTORSIZE) / 1024 / 1024); > } > > sub format_part_info { >@@ -1379,7 +1396,7 @@ sub format_part_info { > $info .= N("Type: ") . (fs::type::part2type_name($part) || $part->{fs_type}) . ($::expert ? sprintf " (0x%x)", $part->{pt_type} : '') . "\n"; > } > $info .= N("Start: sector %s\n", $part->{start}) if $::expert && !isSpecial($part) && !isLVM($hd); >- $info .= N("Size: %s", formatXiB($part->{size}, 512)); >+ $info .= N("Size: %s", formatXiB($part->{size}, $hd->{sector_size} || $DEFAULT_SECTORSIZE)); > $info .= sprintf " (%s%%)", int 100 * $part->{size} / $hd->{totalsectors} if $hd->{totalsectors}; > $info .= N(", %s sectors", $part->{size}) if $::expert; > $info .= "\n"; >@@ -1423,7 +1440,7 @@ sub format_part_info { > > sub format_part_info_short { > my ($hd, $part) = @_; >- isEmpty($part) ? N("Free space on %s (%s)", $hd->{device}, formatXiB($part->{size}, 512)) >+ isEmpty($part) ? N("Free space on %s (%s)", $hd->{device}, formatXiB($part->{size}, $hd->{sector_size} || $DEFAULT_SECTORSIZE)) > : partition_table::description($part); > } > >@@ -1433,7 +1450,7 @@ sub format_hd_info { > my $info = ''; > $info .= N("Device: ") . "$hd->{device}\n"; > $info .= N("Read-only") . "\n" if $hd->{readonly}; >- $info .= N("Size: %s\n", formatXiB($hd->{totalsectors}, 512)) if $hd->{totalsectors}; >+ $info .= N("Size: %s\n", formatXiB($hd->{totalsectors}, $hd->{sector_size} || $DEFAULT_SECTORSIZE)) if $hd->{totalsectors}; > $info .= N("Geometry: %s cylinders, %s heads, %s sectors\n", $hd->{geom}{cylinders}, $hd->{geom}{heads}, $hd->{geom}{sectors}) if $::expert && $hd->{geom}; > $info .= N("Name: ") . $hd->{info} . "\n" if $hd->{info}; > $info .= N("Medium type: ") . $hd->{media_type} . "\n" if $hd->{media_type} && $::expert; >diff --git a/perl-install/diskdrake/resize_ext2.pm b/perl-install/diskdrake/resize_ext2.pm >index ca222b3..2405571 100644 >--- a/perl-install/diskdrake/resize_ext2.pm >+++ b/perl-install/diskdrake/resize_ext2.pm >@@ -23,13 +23,13 @@ sub new { > > sub min_size { > my ($o) = @_; >- ($o->{block_count} - $o->{free_block}) * ($o->{block_size} / 512); >+ ($o->{block_count} - $o->{free_block}) * $o->{block_size}; > } > > sub resize { > my ($o, $size) = @_; > >- my $s = int($size / ($o->{block_size} / 512)); >+ my $s = int($size / $o->{block_size}); > log::l("resize2fs $o->{dev} to size $s in block of $o->{block_size} bytes"); > run_program::raw({ timeout => 60 * 60 }, "resize2fs", "-pf", $o->{dev}, $s) or die "resize2fs failed"; > } >diff --git a/perl-install/diskdrake/resize_ntfs.pm b/perl-install/diskdrake/resize_ntfs.pm >index 1b24a97..4c9f880 100644 >--- a/perl-install/diskdrake/resize_ntfs.pm >+++ b/perl-install/diskdrake/resize_ntfs.pm >@@ -22,12 +22,12 @@ sub min_size { > my ($o) = @_; > my $r; > run_program::run('ntfsresize', '>', \$r, '-f', '-i', $o->{dev}) or die "ntfsresize failed:\n$r\n"; >- $r =~ /minimal size: (\d+) KiB/ && $1 * 2; >+ $r =~ /minimal size: (\d+) KiB/ && $1 * 1024; > } > > sub resize { > my ($o, $size) = @_; >- my @l = ('-ff', '-s' . int($size / 2) . 'ki', $o->{dev}); >+ my @l = ('-ff', '-s' . int($size / 1024) . 'ki', $o->{dev}); > my $r; > run_program::run('ntfsresize', '>', \$r, '-n', @l) or die "ntfsresize failed: $r\n"; > run_program::raw({ timeout => 'never' }, 'ntfsresize', '>', \$r, @l) or die "ntfsresize failed: $r\n"; >diff --git a/perl-install/fs.pm b/perl-install/fs.pm >index d4f742d..8575a14 100644 >--- a/perl-install/fs.pm >+++ b/perl-install/fs.pm >@@ -373,7 +373,7 @@ sub df { > unlink($dir); > } > >- $part->{free} = 2 * $free if defined $free; >+ $part->{free} = $free if defined $free; > $part->{free}; > } > >diff --git a/perl-install/fs/any.pm b/perl-install/fs/any.pm >index 65ca024..9c6641d 100644 >--- a/perl-install/fs/any.pm >+++ b/perl-install/fs/any.pm >@@ -5,6 +5,7 @@ use strict; > > use common; > use fsedit; >+use fs::get; > use fs::mount_point; > > sub get_hds { >@@ -102,7 +103,7 @@ sub prepare_minimal_root { > } > > sub getAvailableSpace { >- my ($fstab, $o_skip_mounted) = @_; >+ my ($fstab, $all_hds, $o_skip_mounted) = @_; > > #- make sure of this place to be available for installation, this could help a lot. > #- currently doing a very small install use 36Mb of postinstall-rpm, but installing >@@ -111,7 +112,7 @@ sub getAvailableSpace { > my $minAvailableSize = 65 * sqr(1024); > > my $n = !$::testing && !$o_skip_mounted && getAvailableSpace_mounted($::prefix) || >- getAvailableSpace_raw($fstab) * 512 / 1.07; >+ getAvailableSpace_raw($fstab, $all_hds) / 1.07; > $n - max(0.1 * $n, $minAvailableSize); > } > >@@ -123,15 +124,20 @@ sub getAvailableSpace_mounted { > $free * 1024 || 1; > } > sub getAvailableSpace_raw { >- my ($fstab) = @_; >+ my ($fstab, $all_hds) = @_; > >- do { $_->{mntpoint} eq '/usr' and return $_->{size} } foreach @$fstab; >- do { $_->{mntpoint} eq '/' and return $_->{size} } foreach @$fstab; >+ my $get_sectorsize = sub { >+ my ($part) = @_; >+ fs::get:part2hd($part, $all_hds)->{sector_size} || $DEFAULT_SECTORSIZE; >+ } >+ >+ do { $_->{mntpoint} eq '/usr' and return $_->{size} * $get_sectorsize->($_) } foreach @$fstab; >+ do { $_->{mntpoint} eq '/' and return $_->{size} * $get_sectorsize->($_) } foreach @$fstab; > > if ($::testing) { > my $nb = 450; > log::l("taking ${nb}MB for testing"); >- return MB($nb); >+ return int(MB($nb) / $DEFAULT_SECTORSIZE); > } > die "missing root partition"; > } >diff --git a/perl-install/fs/partitioning_wizard.pm b/perl-install/fs/partitioning_wizard.pm >index 97e7472..5343231 100644 >--- a/perl-install/fs/partitioning_wizard.pm >+++ b/perl-install/fs/partitioning_wizard.pm >@@ -19,14 +19,15 @@ use POSIX qw(ceil); > #- a partition ($mb) given from the interface (on Resize or Create). > #- modified to take into account a true bounding with min and max. > sub from_Mb { >- my ($mb, $min, $max) = @_; >- $mb <= to_Mb($min) and return $min; >- $mb >= to_Mb($max) and return $max; >- MB($mb); >+ my ($mb, $hd, $min, $max) = @_; >+ $mb <= to_Mb($min, $hd) and return $min; >+ $mb >= to_Mb($max, $hd) and return $max; >+ to_int(MB($mb) / ($hd->{sector_size} || $DEFAULT_SECTORSIZE)); > } >+ > sub to_Mb { >- my ($size_sector) = @_; >- to_int($size_sector / 2048); >+ my ($size_sector, $hd) = @_; >+ to_int($size_sector * ($hd->{sector_size} || $DEFAULT_SECTORSIZE) / 1024 / 1024); > } > > sub partition_with_diskdrake { >@@ -288,6 +289,7 @@ sub create_display_box { > my @parts = fs::get::hds_fstab_and_holes($kind->{val}); > > my $totalsectors = $kind->{val}{totalsectors}; >+ my $sector_size = $kind->{val}{sector_size} || $DEFAULT_SECTORSIZE; > > my $width = 540; > my $minwidth = 40; >@@ -351,8 +353,8 @@ sub create_display_box { > $add_part_size_info->("PART_new", $mdv_size_label); > > my $update_size_labels = sub { >- $win_size_label->set_label(" Windows (" . formatXiB($entry->{req_size}, 512) . ")"); >- $mdv_size_label->set_label(" Mageia (" . formatXiB($entry->{size} - $entry->{req_size}, 512) . ")"); >+ $win_size_label->set_label(" Windows (" . formatXiB($entry->{req_size}, $sector_size) . ")"); >+ $mdv_size_label->set_label(" Mageia (" . formatXiB($entry->{size} - $entry->{req_size}, $sector_size) . ")"); > 0; > }; > my $update_req_size = sub { >@@ -513,7 +515,7 @@ sub main { > foreach (@kinds) { > my $info = $_->{val}{info} || $_->{val}{device}; > $info =~ s|^(?:.*/)?(.{24}).*|$1|; >- $info .= " (" . formatXiB($_->{val}{totalsectors}, 512) . ")" if $_->{val}{totalsectors}; >+ $info .= " (" . formatXiB($_->{val}{totalsectors}, $_->{val}{sector_size} || $DEFAULT_SECTORSIZE) . ")" if $_->{val}{totalsectors}; > $combobox->append_text($info); > } > $combobox->set_active(0); >diff --git a/perl-install/install/any.pm b/perl-install/install/any.pm >index e5050b8..a18bc35 100644 >--- a/perl-install/install/any.pm >+++ b/perl-install/install/any.pm >@@ -84,7 +84,7 @@ cant_spawn: > > sub getAvailableSpace { > my ($o) = @_; >- fs::any::getAvailableSpace($o->{fstab}); >+ fs::any::getAvailableSpace($o->{fstab}, $o->{all_hds}); > } > > sub preConfigureTimezone { >diff --git a/perl-install/partition_table.pm b/perl-install/partition_table.pm >index ee801fc..63edc58 100644 >--- a/perl-install/partition_table.pm >+++ b/perl-install/partition_table.pm >@@ -4,6 +4,7 @@ use diagnostics; > use strict; > > use common; >+use fs::get; > use fs::type; > use partition_table::raw; > use detect_devices; >@@ -28,7 +29,8 @@ sub description { > $win && " [$win:]", > join(', ', > grep { $_ } >- formatXiB($hd->{totalsectors} || $hd->{size}, 512), >+ formatXiB($hd->{totalsectors} || $hd->{size}, >+ $hd->{sector_size} || fs::get:part2hd($hd, $all_hds)->{sector_size} || $DEFAULT_SECTORSIZE), > $hd->{info}, $hd->{mntpoint}, $hd->{fs_type}); > } > >@@ -49,28 +51,29 @@ sub verifyInside { > } > > sub verifyParts_ { >- foreach my $i (@_) { >- foreach (@_) { >+ my ($sectorsize, @parts) = @_; >+ foreach my $i (@parts) { >+ foreach (@parts) { > next if !$i || !$_ || $i == $_ || isWholedisk($i) || isExtended($i); #- avoid testing twice for simplicity :-) > if (isWholedisk($_)) { > verifyInside($i, $_) or > cdie sprintf("partition sector #$i->{start} (%s) is not inside whole disk (%s)!", >- formatXiB($i->{size}, 512), formatXiB($_->{size}, 512)); >+ formatXiB($i->{size}, $sectorsize), formatXiB($_->{size}, $sectorsize)); > } elsif (isExtended($_)) { > verifyNotOverlap($i, $_) or > log::l(sprintf("warning partition sector #$i->{start} (%s) is overlapping with extended partition!", >- formatXiB($i->{size}, 512))); #- only warning for this one is acceptable >+ formatXiB($i->{size}, $sectorsize))); #- only warning for this one is acceptable > } else { > verifyNotOverlap($i, $_) or > cdie sprintf("partitions sector #$i->{start} (%s) and sector #$_->{start} (%s) are overlapping!", >- formatXiB($i->{size}, 512), formatXiB($_->{size}, 512)); >+ formatXiB($i->{size}, $sectorsize), formatXiB($_->{size}, $sectorsize)); > } > } > } > } > sub verifyParts { > my ($hd) = @_; >- verifyParts_(get_normal_parts($hd)); >+ verifyParts_($hd->{sector_size} || $DEFAULT_SECTORSIZE, get_normal_parts($hd)); > } > sub verifyPrimary { > my ($pt) = @_; >diff --git a/perl-install/partition_table/dos.pm b/perl-install/partition_table/dos.pm >index 2cd6fe3..7baac43 100644 >--- a/perl-install/partition_table/dos.pm >+++ b/perl-install/partition_table/dos.pm >@@ -17,7 +17,7 @@ my $format = "C8 V2"; > my $magic = "\x55\xAA"; > my $nb_primary = 4; > >-my $offset = $common::SECTORSIZE - length($magic) - $nb_primary * common::psizeof($format); >+my $offset = $common::DEFAULT_SECTORSIZE - length($magic) - $nb_primary * common::psizeof($format); > > sub use_pt_type { 1 } > sub hasExtended { 1 } >@@ -33,6 +33,7 @@ sub last_usable_sector { > $hd->{geom}{sectors} * $hd->{geom}{heads} * $hd->{geom}{cylinders}; > } > >+# max unsigned 32bit integer, 2 TB with 512 byte sectors > my $two_TB = 2 * 1024 * 1024 * 2048; > sub max_partition_start { $two_TB - 1 } > sub max_partition_size { $two_TB - 1 } >diff --git a/perl-install/partition_table/raw.pm b/perl-install/partition_table/raw.pm >index 7659a39..6d6f932 100644 >--- a/perl-install/partition_table/raw.pm >+++ b/perl-install/partition_table/raw.pm >@@ -120,13 +120,40 @@ sub keep_non_duplicates { > map { @$_ } grep { $l{$_->[0]} == 1 } @_; > } > >+sub get_sector_size { >+ my ($F, $name) = @_; >+ >+ my $g = ''; >+ my $sector_size = 0; >+ if (ioctl($F, c::BLKSSZGET(), $g)) { >+ $sector_size = unpack "i", $g; >+ } else { >+ log::l("$name: ioctl BLKSSZGET failed"); >+ } >+ >+ if ($sector_size <= 0 || $sector_size % $DEFAULT_SECTORSIZE) { >+ log::l("$name: using default sector size $DEFAULT_SECTORSIZE instead of $sector_size"); >+ $sector_size = $DEFAULT_SECTORSIZE; >+ } >+ $sector_size; >+} >+ >+sub get_total_sectors { >+ my ($F, $sector_size) = @_; >+ my $total = c::total_size(fileno $F); >+ >+ $total = divide($total, $sector_size) >+} >+ > sub get_geometries { > my (@hds) = @_; > > @hds = grep { > if ($_->{bus} =~ /dmraid/) { > sysopen(my $F, $_->{file}, 0); >- my $total = c::total_sectors(fileno $F); >+ my $sector_size = get_sector_size($F, $_->{file}); >+ my $total = get_total_sectors($F, $sector_size); >+ log::l($_->{file}.": totalsectors=$total, sector_size=$sector_size"); > my %geom; > $geom{heads} = 255; > $geom{sectors} = 63; >@@ -134,7 +161,7 @@ sub get_geometries { > compute_nb_cylinders(\%geom, $total); > $geom{totalcylinders} = $geom{cylinders}; > log::l("Fake geometry on ".$_->{file}.": heads=$geom{heads} sectors=$geom{sectors} cylinders=$geom{cylinders} start=$geom{start}"); >- add2hash_($_, { totalsectors => $total, geom => \%geom }); >+ add2hash_($_, { totalsectors => $total, sector_size => $sector_size, geom => \%geom }); > 1; > } elsif (my $h = get_geometry($_->{file})) { > add2hash_($_, $h); >@@ -181,7 +208,8 @@ sub get_geometry { > my ($dev) = @_; > sysopen(my $F, $dev, 0) or return; > >- my $total = c::total_sectors(fileno $F); >+ my $sector_size = get_sector_size($F, $dev); >+ my $total = get_total_sectors($F, $sector_size); > > my $g = ""; > my %geom; >@@ -198,7 +226,7 @@ sub get_geometry { > } > } > >- { totalsectors => $total, if_($geom{heads}, geom => \%geom) }; >+ { totalsectors => $total, sector_size => $sector_size, if_($geom{heads}, geom => \%geom) }; > } > > sub openit { >diff --git a/perl-install/resize_fat/any.pm b/perl-install/resize_fat/any.pm >index 59f4add..f02258b 100644 >--- a/perl-install/resize_fat/any.pm >+++ b/perl-install/resize_fat/any.pm >@@ -51,7 +51,7 @@ sub last_unmoveable($) { > 2; > } > >-#- calculates the minimum size of a partition, in physical sectors >+#- calculates the minimum size of a partition, in bytes > sub min_size($) { > my ($fs) = @_; > my $count = $fs->{clusters}{count}; >@@ -62,13 +62,12 @@ sub min_size($) { > my $min_cluster_count = max(2 + $count->{used} + $count->{bad} + $count->{dirs}, min_cluster_count($fs)); > $min_cluster_count = max($min_cluster_count, last_unmoveable($fs)); > >- my $size = $min_cluster_count * divide($fs->{cluster_size}, $SECTORSIZE) + >- divide($fs->{cluster_offset}, $SECTORSIZE) + >- 64*1024*1024 / $SECTORSIZE; #- help with such more sectors (ie 64Mb). >+ my $size = $min_cluster_count * $fs->{cluster_size} + $fs->{cluster_offset} + >+ 64*1024*1024; #- help with such more sectors (ie 64Mb). > > #- help zindozs again with 512Mb+ at least else partition is ignored. > if ($resize_fat::isFAT32) { >- $size = max($size, 524*1024*1024 / $SECTORSIZE); >+ $size = max($size, 524*1024*1024); > } > $size; > >@@ -79,8 +78,7 @@ sub max_size($) { > > my $max_cluster_count = min($fs->{nb_fat_entries} - 2, max_cluster_count($fs)); > >- $max_cluster_count * divide($fs->{cluster_size}, $SECTORSIZE) + >- divide($fs->{cluster_offset}, $SECTORSIZE); >+ $max_cluster_count * $fs->{cluster_size} + $fs->{cluster_offset}; > } > #- calculates used size in order to avoid modifying anything. > sub used_size($) { >@@ -96,8 +94,7 @@ sub used_size($) { > } > $used_cluster_count = max($last_used, min_cluster_count($fs)); > >- $used_cluster_count * divide($fs->{cluster_size}, $SECTORSIZE) + >- divide($fs->{cluster_offset}, $SECTORSIZE); >+ $used_cluster_count * $fs->{cluster_size} + $fs->{cluster_offset}; > } > > #- fills in fat_flag_map in c_rewritten. >diff --git a/perl-install/resize_fat/boot_sector.pm b/perl-install/resize_fat/boot_sector.pm >index 8496166..7b17f55 100644 >--- a/perl-install/resize_fat/boot_sector.pm >+++ b/perl-install/resize_fat/boot_sector.pm >@@ -50,7 +50,7 @@ my @fields = ( > sub read($) { > my ($fs) = @_; > >- my $boot = eval { resize_fat::io::read($fs, 0, $SECTORSIZE) }; $@ and die "reading boot sector failed on device $fs->{fs_name}"; >+ my $boot = eval { resize_fat::io::read($fs, 0, $DEFAULT_SECTORSIZE) }; $@ and die "reading boot sector failed on device $fs->{fs_name}"; > @$fs{@fields} = unpack $format, $boot; > > $fs->{nb_sectors} = $fs->{small_nb_sectors} || $fs->{big_nb_sectors}; >@@ -100,11 +100,11 @@ sub write($) { > my ($fs) = @_; > my $boot = pack($format, @$fs{@fields}); > >- eval { resize_fat::io::write($fs, 0, $SECTORSIZE, $boot) }; $@ and die "writing the boot sector failed on device $fs->{fs_name}"; >+ eval { resize_fat::io::write($fs, 0, $DEFAULT_SECTORSIZE, $boot) }; $@ and die "writing the boot sector failed on device $fs->{fs_name}"; > > if ($resize_fat::isFAT32) { > #- write backup >- eval { resize_fat::io::write($fs, $fs->{fat32_backup_sector} * $SECTORSIZE, $SECTORSIZE, $boot) }; >+ eval { resize_fat::io::write($fs, $fs->{fat32_backup_sector} * $DEFAULT_SECTORSIZE, $DEFAULT_SECTORSIZE, $boot) }; > $@ and die "writing the backup boot sector (#$fs->{fat32_backup_sector}) failed on device $fs->{fs_name}"; > } > } >diff --git a/perl-install/resize_fat/main.pm b/perl-install/resize_fat/main.pm >index 34bf2f9..733de69 100644 >--- a/perl-install/resize_fat/main.pm >+++ b/perl-install/resize_fat/main.pm >@@ -117,16 +117,16 @@ sub resize { > > $size += $min if $size =~ /^\+/; > >- $size >= $min or die "Minimum filesystem size is $min sectors"; >- $size <= $max or die "Maximum filesystem size is $max sectors"; >+ $size >= $min or die "Minimum filesystem size is $min bytes"; >+ $size <= $max or die "Maximum filesystem size is $max bytes"; > >- log::l("resize_fat: Partition size will be " . (($size * $SECTORSIZE) >> 20) . "Mb (well exactly ${size} sectors)"); >+ log::l("resize_fat: Partition size will be " . ($size >> 20) . "Mb (well exactly ${size} bytes)"); > >- my $new_data_size = $size * $SECTORSIZE - $fs->{cluster_offset}; >+ my $new_data_size = $size - $fs->{cluster_offset}; > my $new_nb_clusters = divide($new_data_size, $fs->{cluster_size}); > my $used_size = used_size($fs); > >- log::l("resize_fat: Break point for moving files is " . (($used_size * $SECTORSIZE) >> 20) . " Mb ($used_size sectors)"); >+ log::l("resize_fat: Break point for moving files is " . ($used_size >> 20) . " Mb ($used_size bytes)"); > if ($size < $used_size) { > log::l("resize_fat: Allocating new clusters"); > resize_fat::fat::allocate_remap($fs, $new_nb_clusters); >@@ -144,14 +144,14 @@ sub resize { > log::l("resize_fat: Nothing need to be moved"); > } > >- $fs->{nb_sectors} = $size; >+ $fs->{nb_sectors} = divide($size, $fs->{sector_size}) > $fs->{nb_clusters} = $new_nb_clusters; > $fs->{clusters}{count}{free} = > $fs->{nb_clusters} - $fs->{clusters}{count}{used} - $fs->{clusters}{count}{bad} - 2; > > $fs->{system_id} = 'was here!'; > $fs->{small_nb_sectors} = 0; >- $fs->{big_nb_sectors} = $size; >+ $fs->{big_nb_sectors} = divide($size, $fs->{sector_size}); > > log::l("resize_fat: Writing new boot sector..."); > >-- >1.7.4.4 >
From c5a3bb69c3fdf37dac69680b2e6017889f30307d Mon Sep 17 00:00:00 2001 From: Anssi Hannula <anssi.hannula@iki.fi> Date: Mon, 20 Jun 2011 20:58:08 +0300 Subject: [PATCH] WIP non 512 sectors, e.g. 4k --- perl-install/c/stuff.xs.pl | 9 ++-- perl-install/common.pm | 7 +-- perl-install/diskdrake/hd_gtk.pm | 7 ++- perl-install/diskdrake/interactive.pm | 87 +++++++++++++++++++------------- perl-install/diskdrake/resize_ext2.pm | 4 +- perl-install/diskdrake/resize_ntfs.pm | 4 +- perl-install/fs.pm | 2 +- perl-install/fs/any.pm | 18 ++++-- perl-install/fs/partitioning_wizard.pm | 20 ++++--- perl-install/install/any.pm | 2 +- perl-install/partition_table.pm | 17 ++++--- perl-install/partition_table/dos.pm | 3 +- perl-install/partition_table/raw.pm | 36 ++++++++++++-- perl-install/resize_fat/any.pm | 15 ++--- perl-install/resize_fat/boot_sector.pm | 6 +- perl-install/resize_fat/main.pm | 14 +++--- 16 files changed, 153 insertions(+), 98 deletions(-) diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl index 1dbc968..ad12ef1 100644 --- a/perl-install/c/stuff.xs.pl +++ b/perl-install/c/stuff.xs.pl @@ -26,6 +26,7 @@ print ' #include <linux/keyboard.h> #include <linux/kd.h> #include <linux/hdreg.h> +#include <linux/fs.h> #include <linux/vt.h> #include <linux/fd.h> #include <linux/cdrom.h> @@ -214,14 +215,14 @@ floppy_info(name) RETVAL NV -total_sectors(fd) +total_size(fd) int fd CODE: { unsigned long long ll; unsigned long l; - RETVAL = ioctl(fd, BLKGETSIZE64, &ll) == 0 ? ll / 512 : - ioctl(fd, BLKGETSIZE, &l) == 0 ? l : 0; + RETVAL = ioctl(fd, BLKGETSIZE64, &ll) == 0 ? ll : + ioctl(fd, BLKGETSIZE, &l) == 0 ? (long long)l * 512: 0; } OUTPUT: RETVAL @@ -705,7 +706,7 @@ disk_add_partition(char * device_path, double start, double length, const char * @macros = ( [ qw(int S_IFCHR S_IFBLK S_IFIFO S_IFMT KDSKBENT K_NOSUCHMAP NR_KEYS MAX_NR_KEYMAPS BLKRRPART TIOCSCTTY - HDIO_GETGEO LOOP_GET_STATUS + HDIO_GETGEO BLKSSZGET LOOP_GET_STATUS MS_MGC_VAL O_WRONLY O_RDWR O_CREAT O_NONBLOCK F_SETFL F_GETFL WNOHANG VT_ACTIVATE VT_WAITACTIVE VT_GETSTATE CDROMEJECT CDROMCLOSETRAY CDROM_LOCKDOOR diff --git a/perl-install/common.pm b/perl-install/common.pm index fb42180..24646c8 100644 --- a/perl-install/common.pm +++ b/perl-install/common.pm @@ -21,7 +21,7 @@ $::prefix ||= ""; # no warning #-##################################################################################### #- Globals #-##################################################################################### -our $SECTORSIZE = 512; +our $DEFAULT_SECTORSIZE = 512; #-##################################################################################### #- Functions @@ -112,11 +112,10 @@ sub nonblock { fcntl($F, c::F_SETFL(), fcntl($F, c::F_GETFL(), 0) | c::O_NONBLOCK()) or die "cannot fcntl F_SETFL: $!"; } -#- return a size in sector -#- ie MB(1) is 2048 sectors, which is 1MB +#- return the size in bytes sub MB { my ($nb_MB) = @_; - $nb_MB * 2048; + $nb_MB * 1024 * 1024; } sub removeXiBSuffix { diff --git a/perl-install/diskdrake/hd_gtk.pm b/perl-install/diskdrake/hd_gtk.pm index 977c32a..6b8f775 100644 --- a/perl-install/diskdrake/hd_gtk.pm +++ b/perl-install/diskdrake/hd_gtk.pm @@ -257,7 +257,8 @@ sub current_kind_changed { $kind->{type} eq 'loopback' ? @$v : fs::get::hds_fstab_and_holes($v); my $totalsectors = $kind->{type} =~ /raid|loopback/ ? sum(map { $_->{size} } @parts) : $v->{totalsectors}; - create_buttons4partitions($kind, $totalsectors, @parts); + my $sector_size = ($v->{sector_size} || $DEFAULT_SECTOR_SIZE); + create_buttons4partitions($kind, $totalsectors, $sector_size, @parts); } sub current_entry_changed { @@ -296,7 +297,7 @@ sub create_automatic_notebooks { # parts: helpers ################################################################################ sub create_buttons4partitions { - my ($kind, $totalsectors, @parts) = @_; + my ($kind, $totalsectors, $sector_size, @parts) = @_; $width = first($w->{window}->window->get_size) - first(get_action_box_size()) - 25 if $w->{window}->window; @@ -320,7 +321,7 @@ sub create_buttons4partitions { $entry = $p if $p; } my $info = $entry->{mntpoint} || $entry->{device_LABEL}; - $info .= "\n" . ($entry->{size} ? formatXiB($entry->{size}, 512) : N("Unknown")) if $info; + $info .= "\n" . ($entry->{size} ? formatXiB($entry->{size}, $sector_size) : N("Unknown")) if $info; my $w = Gtk2::ToggleButton->new_with_label($info) or internal_error('new_with_label'); $w->signal_connect(clicked => sub { $current_button != $w or return; diff --git a/perl-install/diskdrake/interactive.pm b/perl-install/diskdrake/interactive.pm index 600079c..76f9cb1 100644 --- a/perl-install/diskdrake/interactive.pm +++ b/perl-install/diskdrake/interactive.pm @@ -3,6 +3,7 @@ package diskdrake::interactive; # $Id: interactive.pm 269771 2010-06-03 11:50:24 use diagnostics; use strict; use utf8; +use POSIX qw(ceil); use common; use fs::type; @@ -131,6 +132,7 @@ struct geom { struct hd { int totalsectors # size in sectors + int sector_size # bytes per sector string device # 'hda', 'sdc' ... string device_alias # 'cdrom', 'floppy' ... string media_type # one of { 'hd', 'cdrom', 'fd', 'tape' } @@ -479,7 +481,7 @@ sub Create { #- one. my ($primaryOrExtended, $migrate_files); my $type_name = fs::type::part2type_name($part); - my $mb_size = to_Mb($part->{size}); + my $mb_size = to_Mb($part->{size}, $hd); my $has_startsector = ($::expert || arch() !~ /i.86/) && !isLVM($hd); my $use_dmcrypt; my $requested_type; @@ -489,9 +491,9 @@ sub Create { { label => N("Create a new partition"), title => 1 }, if_($has_startsector, { label => N("Start sector: "), val => \$part->{start}, min => $def_start, max => ($max - min_partition_size($hd)), - type => 'range', SpinButton => $::expert, changed => sub { $mb_size = min($mb_size, to_Mb($max - $part->{start})) } }, + type => 'range', SpinButton => $::expert, changed => sub { $mb_size = min($mb_size, to_Mb($max - $part->{start}, $hd)) } }, ), - { label => N("Size in MB: "), val => \$mb_size, min => to_Mb(min_partition_size($hd)), max => to_Mb($def_size), + { label => N("Size in MB: "), val => \$mb_size, min => to_Mb(min_partition_size($hd), $hd), max => to_Mb($def_size, $hd), type => 'range', SpinButton => $::expert, changed => sub { $part->{start} = min($part->{start}, $max - $mb_size * 2048) } }, { label => N("Filesystem type: "), val => \$type_name, list => [ fs::type::type_names($::expert, $hd) ], sort => 0, if_($::expert, gtk => { wrap_width => 2 }, do_not_ellipsize => 1) }, @@ -508,7 +510,7 @@ sub Create { { label => N("Encryption key "), val => \$part->{dmcrypt_key}, disabled => sub { !$use_dmcrypt }, hidden => 1, weakness_check => 1 }, { label => N("Encryption key (again)"), val => \$part->{dmcrypt_key2}, disabled => sub { !$use_dmcrypt }, hidden => 1 }, ], complete => sub { - $part->{size} = from_Mb($mb_size, min_partition_size($hd), $max - $part->{start}); #- need this to be able to get back the approximation of using MB + $part->{size} = from_Mb($mb_size, $hd, min_partition_size($hd), $max - $part->{start}); #- need this to be able to get back the approximation of using MB $do_suggest_mount_point = 0 if !$part->{mntpoint}; put_in_hash($part, fs::type::type_name2subpart($type_name)); $part->{mntpoint} = '' if isNonMountable($part); @@ -766,6 +768,14 @@ sub Resize { my ($min, $max) = (min_partition_size($hd), max_partition_resize($hd, $low_part)); + my $sectors2bytes = sub { + my ($sectors) = @_; + $sectors * ($hd->{sector_size} || $DEFAULT_SECTORSIZE); + } + + my $min_b = $sectors2bytes->($min); + my $max_b = $sectors2bytes->($max); + if (maybeFormatted($part)) { # here we may have a non-formatted or a formatted partition # -> doing as if it was formatted @@ -777,13 +787,13 @@ sub Resize { require resize_fat::main; $nice_resize{fat} = resize_fat::main->new($part->{device}, devices::make($part->{device})); - $min = max($min, $nice_resize{fat}->min_size); - $max = min($max, $nice_resize{fat}->max_size); + $min_b = max($min_b, $nice_resize{fat}->min_size); + $max_b = min($max_b, $nice_resize{fat}->max_size); } elsif (member($part->{fs_type}, qw(ext2 ext3 ext4))) { write_partitions($in, $hd) or return; require diskdrake::resize_ext2; if ($nice_resize{ext2} = diskdrake::resize_ext2->new($part->{device}, devices::make($part->{device}))) { - $min = max($min, $nice_resize{ext2}->min_size); + $min_b = max($min_b, $nice_resize{ext2}->min_size); } else { delete $nice_resize{ext2}; } @@ -792,26 +802,31 @@ sub Resize { require diskdrake::resize_ntfs; diskdrake::resize_ntfs::check_prog($in) or return; $nice_resize{ntfs} = diskdrake::resize_ntfs->new($part->{device}, devices::make($part->{device})); - $min = $nice_resize{ntfs}->min_size or delete $nice_resize{ntfs}; + $min_b = $nice_resize{ntfs}->min_size or delete $nice_resize{ntfs}; } elsif ($part->{fs_type} eq 'reiserfs') { write_partitions($in, $hd) or return; if ($part->{isMounted}) { $nice_resize{reiserfs} = 1; - $min = $part->{size}; #- ensure the user can only increase + $min_b = $sectors2bytes->($part->{size}); #- ensure the user can only increase } elsif (defined(my $free = fs::df($part))) { $nice_resize{reiserfs} = 1; - $min = max($min, $part->{size} - $free); + $min_b = max($min_b, $sectors2bytes->($part->{size}) - $free * 1024); } } elsif ($part->{fs_type} eq 'xfs' && isLVM($hd) && $::isStandalone && $part->{isMounted}) { - $min = $part->{size}; #- ensure the user can only increase + $min_b = $sectors2bytes->($part->{size}); #- ensure the user can only increase $nice_resize{xfs} = 1; } elsif ($part->{fs_type} eq 'btrfs') { write_partitions($in, $hd) or return; if (defined(my $free = fs::df($part))) { $nice_resize{btrfs} = 1; - $min = max($min, $part->{size} - $free); + $min_b = max($min_b, $sectors2bytes->($part->{size}) - $free * 1024); } } + + # ceil() as we want to round partial sectors up + $min = ceil($min_b / ($hd->{sector_size} || $DEFAULT_SECTORSIZE)); + $max = int($max_b / ($hd->{sector_size} || $DEFAULT_SECTORSIZE)); + #- make sure that even after normalizing the size to cylinder boundaries, the minimun will be saved, #- this save at least a cylinder (less than 8Mb). $min += partition_table::raw::cylinder_size($hd); @@ -826,8 +841,8 @@ sub Resize { } } - my $mb_size = to_Mb($part->{size}); - my ($gmin, $gmax) = (to_Mb($min), to_Mb($max)); + my $mb_size = to_Mb($part->{size}, $hd); + my ($gmin, $gmax) = (to_Mb($min, $hd), to_Mb($max, $hd)); $in->ask_from(N("Resize"), '', [ { label => N("Choose the new size"), title => 1 }, { label => N("New size in MB: "), val => \$mb_size, min => $gmin, max => $gmax, type => 'range', SpinButton => $::expert }, @@ -836,7 +851,7 @@ sub Resize { ]) or return; - my $size = from_Mb($mb_size, $min, $max); + my $size = from_Mb($mb_size, $hd, $min, $max); $part->{size} == $size and return; my $oldsize = $part->{size}; @@ -870,20 +885,22 @@ sub Resize { my $wait = $in->wait_message(N("Please wait"), N("Resizing")); + my $new_fs_size = $part->{size} * ($hd->{sector_size} || $DEFAULT_SECTORSIZE); + if ($nice_resize{fat}) { local *log::l = sub { $wait->set(join(' ', @_)) }; - $nice_resize{fat}->resize($part->{size}); + $nice_resize{fat}->resize($new_fs_size); } elsif ($nice_resize{ext2}) { - $nice_resize{ext2}->resize($part->{size}); + $nice_resize{ext2}->resize($new_fs_size); } elsif ($nice_resize{ntfs}) { - log::l("ntfs resize to $part->{size} sectors"); - $nice_resize{ntfs}->resize($part->{size}); + log::l("ntfs resize to $part->{size} sectors, $new_fs_size bytes"); + $nice_resize{ntfs}->resize($new_fs_size); $wait = undef; $in->ask_warn(N("Warning"), N("To ensure data integrity after resizing the partition(s), filesystem checks will be run on your next boot into Microsoft Windows®")); } elsif ($nice_resize{reiserfs}) { - log::l("reiser resize to $part->{size} sectors"); - run_program::run_or_die('resize_reiserfs', '-f', '-q', '-s' . int($part->{size}/2) . 'K', devices::make($part->{device})); + log::l("reiser resize to $part->{size} sectors, $new_fs_size bytes"); + run_program::run_or_die('resize_reiserfs', '-f', '-q', '-s' . int($new_fs_size/1024) . 'K', devices::make($part->{device})); } elsif ($nice_resize{xfs}) { #- happens only with mounted LVM, see above run_program::run_or_die("xfs_growfs", $part->{mntpoint}); @@ -895,7 +912,7 @@ filesystem checks will be run on your next boot into Microsoft Windows®")); mkdir_p($dir); fs::mount::mount(devices::make($part->{device}), $dir, $part->{fs_type}); } - if (!run_program::run("btrfsctl", "-r", $part->{size}*512, $dir)) { + if (!run_program::run("btrfsctl", "-r", $new_fs_size, $dir)) { $nice_resize{btrfs} = undef; if (!$part->{isMounted}) { fs::mount::umount($dir); @@ -1060,10 +1077,10 @@ sub Loopback { delete $part->{mntpoint}; # we do not want the suggested mntpoint my $type_name = fs::type::part2type_name($part); - my $mb_size = to_Mb($part->{size}); + my $mb_size = to_Mb($part->{size}, $hd); $in->ask_from(N("Loopback"), '', [ { label => N("Loopback file name: "), val => \$part->{loopback_file} }, - { label => N("Size in MB: "), val => \$mb_size, min => to_Mb($min), max => to_Mb($max), type => 'range', SpinButton => $::expert }, + { label => N("Size in MB: "), val => \$mb_size, min => to_Mb($min, $hd), max => to_Mb($max, $hd), type => 'range', SpinButton => $::expert }, { label => N("Filesystem type: "), val => \$type_name, list => [ fs::type::type_names($::expert, $hd) ], not_edit => !$::expert, sort => 0 }, ], complete => sub { @@ -1073,9 +1090,9 @@ sub Loopback { $size == -1 and $in->ask_warn(N("Warning"), N("File is already used by another loopback, choose another one")), return 1, 0; $in->ask_yesorno(N("Warning"), N("File already exists. Use it?")) or return 1, 0; delete $part->{notFormatted}; - $part->{size} = divide($size, 512); + $part->{size} = int($size, $hd->{sector_size} || $DEFAULT_SECTORSIZE); } else { - $part->{size} = from_Mb($mb_size, $min, $max); + $part->{size} = from_Mb($mb_size, $hd, $min, $max); } 0; }) or return; @@ -1343,15 +1360,15 @@ sub warn_if_renumbered { #- a partition ($mb) given from the interface (on Resize or Create). #- modified to take into account a true bounding with min and max. sub from_Mb { - my ($mb, $min, $max) = @_; - $mb <= to_Mb($min) and return $min; - $mb >= to_Mb($max) and return $max; - $mb * 2048; + my ($mb, $hd, $min, $max) = @_; + $mb <= to_Mb($min, $hd) and return $min; + $mb >= to_Mb($max, $hd) and return $max; + to_int($mb * 1024 * 1024 / ($hd->{sector_size} || $DEFAULT_SECTORSIZE)); } sub to_Mb { - my ($size_sector) = @_; - to_int($size_sector / 2048); + my ($size_sector, $hd) = @_; + to_int($size_sector * ($hd->{sector_size} || $DEFAULT_SECTORSIZE) / 1024 / 1024); } sub format_part_info { @@ -1379,7 +1396,7 @@ sub format_part_info { $info .= N("Type: ") . (fs::type::part2type_name($part) || $part->{fs_type}) . ($::expert ? sprintf " (0x%x)", $part->{pt_type} : '') . "\n"; } $info .= N("Start: sector %s\n", $part->{start}) if $::expert && !isSpecial($part) && !isLVM($hd); - $info .= N("Size: %s", formatXiB($part->{size}, 512)); + $info .= N("Size: %s", formatXiB($part->{size}, $hd->{sector_size} || $DEFAULT_SECTORSIZE)); $info .= sprintf " (%s%%)", int 100 * $part->{size} / $hd->{totalsectors} if $hd->{totalsectors}; $info .= N(", %s sectors", $part->{size}) if $::expert; $info .= "\n"; @@ -1423,7 +1440,7 @@ sub format_part_info { sub format_part_info_short { my ($hd, $part) = @_; - isEmpty($part) ? N("Free space on %s (%s)", $hd->{device}, formatXiB($part->{size}, 512)) + isEmpty($part) ? N("Free space on %s (%s)", $hd->{device}, formatXiB($part->{size}, $hd->{sector_size} || $DEFAULT_SECTORSIZE)) : partition_table::description($part); } @@ -1433,7 +1450,7 @@ sub format_hd_info { my $info = ''; $info .= N("Device: ") . "$hd->{device}\n"; $info .= N("Read-only") . "\n" if $hd->{readonly}; - $info .= N("Size: %s\n", formatXiB($hd->{totalsectors}, 512)) if $hd->{totalsectors}; + $info .= N("Size: %s\n", formatXiB($hd->{totalsectors}, $hd->{sector_size} || $DEFAULT_SECTORSIZE)) if $hd->{totalsectors}; $info .= N("Geometry: %s cylinders, %s heads, %s sectors\n", $hd->{geom}{cylinders}, $hd->{geom}{heads}, $hd->{geom}{sectors}) if $::expert && $hd->{geom}; $info .= N("Name: ") . $hd->{info} . "\n" if $hd->{info}; $info .= N("Medium type: ") . $hd->{media_type} . "\n" if $hd->{media_type} && $::expert; diff --git a/perl-install/diskdrake/resize_ext2.pm b/perl-install/diskdrake/resize_ext2.pm index ca222b3..2405571 100644 --- a/perl-install/diskdrake/resize_ext2.pm +++ b/perl-install/diskdrake/resize_ext2.pm @@ -23,13 +23,13 @@ sub new { sub min_size { my ($o) = @_; - ($o->{block_count} - $o->{free_block}) * ($o->{block_size} / 512); + ($o->{block_count} - $o->{free_block}) * $o->{block_size}; } sub resize { my ($o, $size) = @_; - my $s = int($size / ($o->{block_size} / 512)); + my $s = int($size / $o->{block_size}); log::l("resize2fs $o->{dev} to size $s in block of $o->{block_size} bytes"); run_program::raw({ timeout => 60 * 60 }, "resize2fs", "-pf", $o->{dev}, $s) or die "resize2fs failed"; } diff --git a/perl-install/diskdrake/resize_ntfs.pm b/perl-install/diskdrake/resize_ntfs.pm index 1b24a97..4c9f880 100644 --- a/perl-install/diskdrake/resize_ntfs.pm +++ b/perl-install/diskdrake/resize_ntfs.pm @@ -22,12 +22,12 @@ sub min_size { my ($o) = @_; my $r; run_program::run('ntfsresize', '>', \$r, '-f', '-i', $o->{dev}) or die "ntfsresize failed:\n$r\n"; - $r =~ /minimal size: (\d+) KiB/ && $1 * 2; + $r =~ /minimal size: (\d+) KiB/ && $1 * 1024; } sub resize { my ($o, $size) = @_; - my @l = ('-ff', '-s' . int($size / 2) . 'ki', $o->{dev}); + my @l = ('-ff', '-s' . int($size / 1024) . 'ki', $o->{dev}); my $r; run_program::run('ntfsresize', '>', \$r, '-n', @l) or die "ntfsresize failed: $r\n"; run_program::raw({ timeout => 'never' }, 'ntfsresize', '>', \$r, @l) or die "ntfsresize failed: $r\n"; diff --git a/perl-install/fs.pm b/perl-install/fs.pm index d4f742d..8575a14 100644 --- a/perl-install/fs.pm +++ b/perl-install/fs.pm @@ -373,7 +373,7 @@ sub df { unlink($dir); } - $part->{free} = 2 * $free if defined $free; + $part->{free} = $free if defined $free; $part->{free}; } diff --git a/perl-install/fs/any.pm b/perl-install/fs/any.pm index 65ca024..9c6641d 100644 --- a/perl-install/fs/any.pm +++ b/perl-install/fs/any.pm @@ -5,6 +5,7 @@ use strict; use common; use fsedit; +use fs::get; use fs::mount_point; sub get_hds { @@ -102,7 +103,7 @@ sub prepare_minimal_root { } sub getAvailableSpace { - my ($fstab, $o_skip_mounted) = @_; + my ($fstab, $all_hds, $o_skip_mounted) = @_; #- make sure of this place to be available for installation, this could help a lot. #- currently doing a very small install use 36Mb of postinstall-rpm, but installing @@ -111,7 +112,7 @@ sub getAvailableSpace { my $minAvailableSize = 65 * sqr(1024); my $n = !$::testing && !$o_skip_mounted && getAvailableSpace_mounted($::prefix) || - getAvailableSpace_raw($fstab) * 512 / 1.07; + getAvailableSpace_raw($fstab, $all_hds) / 1.07; $n - max(0.1 * $n, $minAvailableSize); } @@ -123,15 +124,20 @@ sub getAvailableSpace_mounted { $free * 1024 || 1; } sub getAvailableSpace_raw { - my ($fstab) = @_; + my ($fstab, $all_hds) = @_; - do { $_->{mntpoint} eq '/usr' and return $_->{size} } foreach @$fstab; - do { $_->{mntpoint} eq '/' and return $_->{size} } foreach @$fstab; + my $get_sectorsize = sub { + my ($part) = @_; + fs::get:part2hd($part, $all_hds)->{sector_size} || $DEFAULT_SECTORSIZE; + } + + do { $_->{mntpoint} eq '/usr' and return $_->{size} * $get_sectorsize->($_) } foreach @$fstab; + do { $_->{mntpoint} eq '/' and return $_->{size} * $get_sectorsize->($_) } foreach @$fstab; if ($::testing) { my $nb = 450; log::l("taking ${nb}MB for testing"); - return MB($nb); + return int(MB($nb) / $DEFAULT_SECTORSIZE); } die "missing root partition"; } diff --git a/perl-install/fs/partitioning_wizard.pm b/perl-install/fs/partitioning_wizard.pm index 97e7472..5343231 100644 --- a/perl-install/fs/partitioning_wizard.pm +++ b/perl-install/fs/partitioning_wizard.pm @@ -19,14 +19,15 @@ use POSIX qw(ceil); #- a partition ($mb) given from the interface (on Resize or Create). #- modified to take into account a true bounding with min and max. sub from_Mb { - my ($mb, $min, $max) = @_; - $mb <= to_Mb($min) and return $min; - $mb >= to_Mb($max) and return $max; - MB($mb); + my ($mb, $hd, $min, $max) = @_; + $mb <= to_Mb($min, $hd) and return $min; + $mb >= to_Mb($max, $hd) and return $max; + to_int(MB($mb) / ($hd->{sector_size} || $DEFAULT_SECTORSIZE)); } + sub to_Mb { - my ($size_sector) = @_; - to_int($size_sector / 2048); + my ($size_sector, $hd) = @_; + to_int($size_sector * ($hd->{sector_size} || $DEFAULT_SECTORSIZE) / 1024 / 1024); } sub partition_with_diskdrake { @@ -288,6 +289,7 @@ sub create_display_box { my @parts = fs::get::hds_fstab_and_holes($kind->{val}); my $totalsectors = $kind->{val}{totalsectors}; + my $sector_size = $kind->{val}{sector_size} || $DEFAULT_SECTORSIZE; my $width = 540; my $minwidth = 40; @@ -351,8 +353,8 @@ sub create_display_box { $add_part_size_info->("PART_new", $mdv_size_label); my $update_size_labels = sub { - $win_size_label->set_label(" Windows (" . formatXiB($entry->{req_size}, 512) . ")"); - $mdv_size_label->set_label(" Mageia (" . formatXiB($entry->{size} - $entry->{req_size}, 512) . ")"); + $win_size_label->set_label(" Windows (" . formatXiB($entry->{req_size}, $sector_size) . ")"); + $mdv_size_label->set_label(" Mageia (" . formatXiB($entry->{size} - $entry->{req_size}, $sector_size) . ")"); 0; }; my $update_req_size = sub { @@ -513,7 +515,7 @@ sub main { foreach (@kinds) { my $info = $_->{val}{info} || $_->{val}{device}; $info =~ s|^(?:.*/)?(.{24}).*|$1|; - $info .= " (" . formatXiB($_->{val}{totalsectors}, 512) . ")" if $_->{val}{totalsectors}; + $info .= " (" . formatXiB($_->{val}{totalsectors}, $_->{val}{sector_size} || $DEFAULT_SECTORSIZE) . ")" if $_->{val}{totalsectors}; $combobox->append_text($info); } $combobox->set_active(0); diff --git a/perl-install/install/any.pm b/perl-install/install/any.pm index e5050b8..a18bc35 100644 --- a/perl-install/install/any.pm +++ b/perl-install/install/any.pm @@ -84,7 +84,7 @@ cant_spawn: sub getAvailableSpace { my ($o) = @_; - fs::any::getAvailableSpace($o->{fstab}); + fs::any::getAvailableSpace($o->{fstab}, $o->{all_hds}); } sub preConfigureTimezone { diff --git a/perl-install/partition_table.pm b/perl-install/partition_table.pm index ee801fc..63edc58 100644 --- a/perl-install/partition_table.pm +++ b/perl-install/partition_table.pm @@ -4,6 +4,7 @@ use diagnostics; use strict; use common; +use fs::get; use fs::type; use partition_table::raw; use detect_devices; @@ -28,7 +29,8 @@ sub description { $win && " [$win:]", join(', ', grep { $_ } - formatXiB($hd->{totalsectors} || $hd->{size}, 512), + formatXiB($hd->{totalsectors} || $hd->{size}, + $hd->{sector_size} || fs::get:part2hd($hd, $all_hds)->{sector_size} || $DEFAULT_SECTORSIZE), $hd->{info}, $hd->{mntpoint}, $hd->{fs_type}); } @@ -49,28 +51,29 @@ sub verifyInside { } sub verifyParts_ { - foreach my $i (@_) { - foreach (@_) { + my ($sectorsize, @parts) = @_; + foreach my $i (@parts) { + foreach (@parts) { next if !$i || !$_ || $i == $_ || isWholedisk($i) || isExtended($i); #- avoid testing twice for simplicity :-) if (isWholedisk($_)) { verifyInside($i, $_) or cdie sprintf("partition sector #$i->{start} (%s) is not inside whole disk (%s)!", - formatXiB($i->{size}, 512), formatXiB($_->{size}, 512)); + formatXiB($i->{size}, $sectorsize), formatXiB($_->{size}, $sectorsize)); } elsif (isExtended($_)) { verifyNotOverlap($i, $_) or log::l(sprintf("warning partition sector #$i->{start} (%s) is overlapping with extended partition!", - formatXiB($i->{size}, 512))); #- only warning for this one is acceptable + formatXiB($i->{size}, $sectorsize))); #- only warning for this one is acceptable } else { verifyNotOverlap($i, $_) or cdie sprintf("partitions sector #$i->{start} (%s) and sector #$_->{start} (%s) are overlapping!", - formatXiB($i->{size}, 512), formatXiB($_->{size}, 512)); + formatXiB($i->{size}, $sectorsize), formatXiB($_->{size}, $sectorsize)); } } } } sub verifyParts { my ($hd) = @_; - verifyParts_(get_normal_parts($hd)); + verifyParts_($hd->{sector_size} || $DEFAULT_SECTORSIZE, get_normal_parts($hd)); } sub verifyPrimary { my ($pt) = @_; diff --git a/perl-install/partition_table/dos.pm b/perl-install/partition_table/dos.pm index 2cd6fe3..7baac43 100644 --- a/perl-install/partition_table/dos.pm +++ b/perl-install/partition_table/dos.pm @@ -17,7 +17,7 @@ my $format = "C8 V2"; my $magic = "\x55\xAA"; my $nb_primary = 4; -my $offset = $common::SECTORSIZE - length($magic) - $nb_primary * common::psizeof($format); +my $offset = $common::DEFAULT_SECTORSIZE - length($magic) - $nb_primary * common::psizeof($format); sub use_pt_type { 1 } sub hasExtended { 1 } @@ -33,6 +33,7 @@ sub last_usable_sector { $hd->{geom}{sectors} * $hd->{geom}{heads} * $hd->{geom}{cylinders}; } +# max unsigned 32bit integer, 2 TB with 512 byte sectors my $two_TB = 2 * 1024 * 1024 * 2048; sub max_partition_start { $two_TB - 1 } sub max_partition_size { $two_TB - 1 } diff --git a/perl-install/partition_table/raw.pm b/perl-install/partition_table/raw.pm index 7659a39..6d6f932 100644 --- a/perl-install/partition_table/raw.pm +++ b/perl-install/partition_table/raw.pm @@ -120,13 +120,40 @@ sub keep_non_duplicates { map { @$_ } grep { $l{$_->[0]} == 1 } @_; } +sub get_sector_size { + my ($F, $name) = @_; + + my $g = ''; + my $sector_size = 0; + if (ioctl($F, c::BLKSSZGET(), $g)) { + $sector_size = unpack "i", $g; + } else { + log::l("$name: ioctl BLKSSZGET failed"); + } + + if ($sector_size <= 0 || $sector_size % $DEFAULT_SECTORSIZE) { + log::l("$name: using default sector size $DEFAULT_SECTORSIZE instead of $sector_size"); + $sector_size = $DEFAULT_SECTORSIZE; + } + $sector_size; +} + +sub get_total_sectors { + my ($F, $sector_size) = @_; + my $total = c::total_size(fileno $F); + + $total = divide($total, $sector_size) +} + sub get_geometries { my (@hds) = @_; @hds = grep { if ($_->{bus} =~ /dmraid/) { sysopen(my $F, $_->{file}, 0); - my $total = c::total_sectors(fileno $F); + my $sector_size = get_sector_size($F, $_->{file}); + my $total = get_total_sectors($F, $sector_size); + log::l($_->{file}.": totalsectors=$total, sector_size=$sector_size"); my %geom; $geom{heads} = 255; $geom{sectors} = 63; @@ -134,7 +161,7 @@ sub get_geometries { compute_nb_cylinders(\%geom, $total); $geom{totalcylinders} = $geom{cylinders}; log::l("Fake geometry on ".$_->{file}.": heads=$geom{heads} sectors=$geom{sectors} cylinders=$geom{cylinders} start=$geom{start}"); - add2hash_($_, { totalsectors => $total, geom => \%geom }); + add2hash_($_, { totalsectors => $total, sector_size => $sector_size, geom => \%geom }); 1; } elsif (my $h = get_geometry($_->{file})) { add2hash_($_, $h); @@ -181,7 +208,8 @@ sub get_geometry { my ($dev) = @_; sysopen(my $F, $dev, 0) or return; - my $total = c::total_sectors(fileno $F); + my $sector_size = get_sector_size($F, $dev); + my $total = get_total_sectors($F, $sector_size); my $g = ""; my %geom; @@ -198,7 +226,7 @@ sub get_geometry { } } - { totalsectors => $total, if_($geom{heads}, geom => \%geom) }; + { totalsectors => $total, sector_size => $sector_size, if_($geom{heads}, geom => \%geom) }; } sub openit { diff --git a/perl-install/resize_fat/any.pm b/perl-install/resize_fat/any.pm index 59f4add..f02258b 100644 --- a/perl-install/resize_fat/any.pm +++ b/perl-install/resize_fat/any.pm @@ -51,7 +51,7 @@ sub last_unmoveable($) { 2; } -#- calculates the minimum size of a partition, in physical sectors +#- calculates the minimum size of a partition, in bytes sub min_size($) { my ($fs) = @_; my $count = $fs->{clusters}{count}; @@ -62,13 +62,12 @@ sub min_size($) { my $min_cluster_count = max(2 + $count->{used} + $count->{bad} + $count->{dirs}, min_cluster_count($fs)); $min_cluster_count = max($min_cluster_count, last_unmoveable($fs)); - my $size = $min_cluster_count * divide($fs->{cluster_size}, $SECTORSIZE) + - divide($fs->{cluster_offset}, $SECTORSIZE) + - 64*1024*1024 / $SECTORSIZE; #- help with such more sectors (ie 64Mb). + my $size = $min_cluster_count * $fs->{cluster_size} + $fs->{cluster_offset} + + 64*1024*1024; #- help with such more sectors (ie 64Mb). #- help zindozs again with 512Mb+ at least else partition is ignored. if ($resize_fat::isFAT32) { - $size = max($size, 524*1024*1024 / $SECTORSIZE); + $size = max($size, 524*1024*1024); } $size; @@ -79,8 +78,7 @@ sub max_size($) { my $max_cluster_count = min($fs->{nb_fat_entries} - 2, max_cluster_count($fs)); - $max_cluster_count * divide($fs->{cluster_size}, $SECTORSIZE) + - divide($fs->{cluster_offset}, $SECTORSIZE); + $max_cluster_count * $fs->{cluster_size} + $fs->{cluster_offset}; } #- calculates used size in order to avoid modifying anything. sub used_size($) { @@ -96,8 +94,7 @@ sub used_size($) { } $used_cluster_count = max($last_used, min_cluster_count($fs)); - $used_cluster_count * divide($fs->{cluster_size}, $SECTORSIZE) + - divide($fs->{cluster_offset}, $SECTORSIZE); + $used_cluster_count * $fs->{cluster_size} + $fs->{cluster_offset}; } #- fills in fat_flag_map in c_rewritten. diff --git a/perl-install/resize_fat/boot_sector.pm b/perl-install/resize_fat/boot_sector.pm index 8496166..7b17f55 100644 --- a/perl-install/resize_fat/boot_sector.pm +++ b/perl-install/resize_fat/boot_sector.pm @@ -50,7 +50,7 @@ my @fields = ( sub read($) { my ($fs) = @_; - my $boot = eval { resize_fat::io::read($fs, 0, $SECTORSIZE) }; $@ and die "reading boot sector failed on device $fs->{fs_name}"; + my $boot = eval { resize_fat::io::read($fs, 0, $DEFAULT_SECTORSIZE) }; $@ and die "reading boot sector failed on device $fs->{fs_name}"; @$fs{@fields} = unpack $format, $boot; $fs->{nb_sectors} = $fs->{small_nb_sectors} || $fs->{big_nb_sectors}; @@ -100,11 +100,11 @@ sub write($) { my ($fs) = @_; my $boot = pack($format, @$fs{@fields}); - eval { resize_fat::io::write($fs, 0, $SECTORSIZE, $boot) }; $@ and die "writing the boot sector failed on device $fs->{fs_name}"; + eval { resize_fat::io::write($fs, 0, $DEFAULT_SECTORSIZE, $boot) }; $@ and die "writing the boot sector failed on device $fs->{fs_name}"; if ($resize_fat::isFAT32) { #- write backup - eval { resize_fat::io::write($fs, $fs->{fat32_backup_sector} * $SECTORSIZE, $SECTORSIZE, $boot) }; + eval { resize_fat::io::write($fs, $fs->{fat32_backup_sector} * $DEFAULT_SECTORSIZE, $DEFAULT_SECTORSIZE, $boot) }; $@ and die "writing the backup boot sector (#$fs->{fat32_backup_sector}) failed on device $fs->{fs_name}"; } } diff --git a/perl-install/resize_fat/main.pm b/perl-install/resize_fat/main.pm index 34bf2f9..733de69 100644 --- a/perl-install/resize_fat/main.pm +++ b/perl-install/resize_fat/main.pm @@ -117,16 +117,16 @@ sub resize { $size += $min if $size =~ /^\+/; - $size >= $min or die "Minimum filesystem size is $min sectors"; - $size <= $max or die "Maximum filesystem size is $max sectors"; + $size >= $min or die "Minimum filesystem size is $min bytes"; + $size <= $max or die "Maximum filesystem size is $max bytes"; - log::l("resize_fat: Partition size will be " . (($size * $SECTORSIZE) >> 20) . "Mb (well exactly ${size} sectors)"); + log::l("resize_fat: Partition size will be " . ($size >> 20) . "Mb (well exactly ${size} bytes)"); - my $new_data_size = $size * $SECTORSIZE - $fs->{cluster_offset}; + my $new_data_size = $size - $fs->{cluster_offset}; my $new_nb_clusters = divide($new_data_size, $fs->{cluster_size}); my $used_size = used_size($fs); - log::l("resize_fat: Break point for moving files is " . (($used_size * $SECTORSIZE) >> 20) . " Mb ($used_size sectors)"); + log::l("resize_fat: Break point for moving files is " . ($used_size >> 20) . " Mb ($used_size bytes)"); if ($size < $used_size) { log::l("resize_fat: Allocating new clusters"); resize_fat::fat::allocate_remap($fs, $new_nb_clusters); @@ -144,14 +144,14 @@ sub resize { log::l("resize_fat: Nothing need to be moved"); } - $fs->{nb_sectors} = $size; + $fs->{nb_sectors} = divide($size, $fs->{sector_size}) $fs->{nb_clusters} = $new_nb_clusters; $fs->{clusters}{count}{free} = $fs->{nb_clusters} - $fs->{clusters}{count}{used} - $fs->{clusters}{count}{bad} - 2; $fs->{system_id} = 'was here!'; $fs->{small_nb_sectors} = 0; - $fs->{big_nb_sectors} = $size; + $fs->{big_nb_sectors} = divide($size, $fs->{sector_size}); log::l("resize_fat: Writing new boot sector..."); -- 1.7.4.4
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1215
:
594
| 595