OSDN Git Service

android-x86/external-parted.git
14 years agogpt: rewrite GPT header-reading code
Jim Meyering [Wed, 21 Oct 2009 11:33:20 +0000 (13:33 +0200)]
gpt: rewrite GPT header-reading code

* libparted/labels/gpt.c (read_header): Remove now-unused function.
(gpt_read_headers): New function.
(gpt_read): Rewrite to use gpt_read_headers.

14 years agogpt: require that the backup table's AlternateLBA is 1
Jim Meyering [Mon, 19 Oct 2009 18:14:44 +0000 (20:14 +0200)]
gpt: require that the backup table's AlternateLBA is 1

* libparted/labels/gpt.c (_header_is_valid): When checking
the backup header, ensure that its AlternateLBA is 1.

14 years agotests: gpt: test for detection of corrupt backup partition header
Jim Meyering [Mon, 19 Oct 2009 18:12:41 +0000 (20:12 +0200)]
tests: gpt: test for detection of corrupt backup partition header

* tests/t0280-gpt-corrupt.sh: Corrupt the backup partition header's
MyLBA, and require that an attempt to print the table fails.

14 years agotests: hook up new GPT-crc-corrupting script
Jim Meyering [Mon, 19 Oct 2009 16:55:06 +0000 (18:55 +0200)]
tests: hook up new GPT-crc-corrupting script

* tests/Makefile.am (TESTS): Add t0280-gpt-corrupt.sh.
* libparted/labels/gpt.c (gpt_read): Change diagnostic to say that
the PTE CRC mismatch is in the primary table.
* tests/t0280-gpt-corrupt.sh: Tweak diagnostic to match
what the code now prints.

14 years agogpt: also verify MyLBA when checking table validity
Jim Meyering [Mon, 19 Oct 2009 16:47:00 +0000 (18:47 +0200)]
gpt: also verify MyLBA when checking table validity

* libparted/labels/gpt.c (_header_is_valid): Add parameter, my_lba.
(_read_header): Update caller.
(_parse_header): Comment out this use of _header_is_valid
in an assertion.

14 years agogpt: clean up formatting of static initializers
Jim Meyering [Mon, 19 Oct 2009 16:03:46 +0000 (18:03 +0200)]
gpt: clean up formatting of static initializers

* libparted/labels/gpt.c (NULL_IF_DISCOVER_ONLY): Define.
(gpt_disk_ops): Use it to avoid in-decl #if directives.

14 years agogpt.c: filter through indent --no-tabs...
Jim Meyering [Mon, 19 Oct 2009 15:34:19 +0000 (17:34 +0200)]
gpt.c: filter through indent --no-tabs...

and manual fix-up to shorten long lines.
Also, manually format the static initializers in e.g., gpt_disk_ops,
since GNU indent botches that.

14 years agogpt: add a comment
Jim Meyering [Mon, 19 Oct 2009 14:56:21 +0000 (16:56 +0200)]
gpt: add a comment

* libparted/labels/gpt.c (_header_is_valid): Add a comment to explain
the new partition entry size limitation of UINT32_MAX/16.

14 years agobuild: update gnulib submodule to latest
Jim Meyering [Mon, 19 Oct 2009 12:41:00 +0000 (14:41 +0200)]
build: update gnulib submodule to latest

14 years agotests: use scsi_debug to test-for 4k-sector-specific bug
Jim Meyering [Fri, 16 Oct 2009 17:14:38 +0000 (19:14 +0200)]
tests: use scsi_debug to test-for 4k-sector-specific bug

* tests/t9010-big-sector.sh: New root-only test.
Requires 2.6.31, and the scsi_debug module, /sys/block/... support
and an upcoming version of libblkid.
* tests/Makefile.am (TESTS): Add t9010-big-sector.sh.
Thanks to Mike Snitzer for advice and for pointing me to similar
code he wrote to test LVM.

14 years agotests: begin the transition to coreutils' testing framework
Jim Meyering [Mon, 19 Oct 2009 10:03:20 +0000 (12:03 +0200)]
tests: begin the transition to coreutils' testing framework

The existing testing framework makes it hard to diagnose test failures,
so I'm switching to one that works better for me, from coreutils.
* tests/t-lib.sh: New file.  Mostly from coreutils/tests/test-lib.sh.
* tests/Makefile.am (TMPDIR): Update to pass more info to test scripts.
(EXTRA_DIST): Add t-lib.sh.

14 years agolinux: use libblkid to determine ->phys_sector_size
Jim Meyering [Thu, 15 Oct 2009 19:29:36 +0000 (21:29 +0200)]
linux: use libblkid to determine ->phys_sector_size

Before this change, creating a memory-mapped disk on a fedora-based
system running 2.6.31.1-56.fc12.x86_64 using this command:
modprobe scsi_debug dev_size_mb=1025 sector_size=4096
and then running "parted -s /dev/sdd mklabel gpt print"
would mistakenly print "Sector size (logical/physical): 4096B/512B"
The "512B" is what's wrong.  It should be "4096B".
* configure.ac: Test for a new-enough blkid library.
* libparted/Makefile.am (libparted_la_LIBADD): Add $(LIB_BLKID).
* libparted/arch/linux.c (get_minimum_io_size): New function.
(_device_set_sector_size): Use it.

14 years agolibparted: weaken a diagnostic
Jim Meyering [Wed, 14 Oct 2009 18:53:48 +0000 (20:53 +0200)]
libparted: weaken a diagnostic

* libparted/arch/linux.c (_kernel_reread_part_table): Give a more
accurate diagnostic.  Reported by Curtis Gedak.

14 years agogpt: verify CRC32 of partition table entry array, too
Jim Meyering [Wed, 14 Oct 2009 18:50:39 +0000 (20:50 +0200)]
gpt: verify CRC32 of partition table entry array, too

The partition table entry array's CRC was not being verified at all.
This adds an interim check.  The full-blown change required to make
this implementation conform to the EFI spec will be more invasive.
* libparted/labels/gpt.c (gpt_read): Check CRC of PTE array, too.
* tests/t0280-gpt-corrupt.sh: New test for this.
Reported by Karel Zak.

14 years agodoc: mention the "bios_grub" flag
Jim Meyering [Wed, 14 Oct 2009 10:34:56 +0000 (12:34 +0200)]
doc: mention the "bios_grub" flag

I don't like the idea of documenting this "flag setting" option,
but it's been in the code for long enough now, and in actual use,
that I feel obliged.  In the longer term, we'll probably deprecate
it and instead add an interface to set a partition's type independent
of mkpart's "type" argument.
* doc/parted.texi (set): Mention bios_grub.

14 years agotests: gpt: do not munge GPT data manually
Jim Meyering [Wed, 14 Oct 2009 09:36:47 +0000 (11:36 +0200)]
tests: gpt: do not munge GPT data manually

Otherwise, an upcoming change would cause this test to fail.
* tests/t5000-tags.sh: Do not munge GPT data manually, since that
does not update embedded CRCs, and thus renders it invalid.
Set the attribute via "set 1 bios_grub on" instead.
Also, use "name1" as the partition name, rather than the
misleading "primary".
Adjust diagnostics: the changes we make are no longer "manual."

15 years agolibparted: fix big-endian bug in gpt_get_max_supported_partition_count
Jim Meyering [Thu, 8 Oct 2009 20:03:37 +0000 (22:03 +0200)]
libparted: fix big-endian bug in gpt_get_max_supported_partition_count

* libparted/labels/gpt.c (gpt_get_max_supported_partition_count):
Convert ->SizeOfPartitionEntry from little-endian to CPU endianness
here, too.  This is along the same lines as commit d6e9b3bb, but
with the difference that this code is not reachable via the
command-line interface.

15 years agopost-release administrivia
Jim Meyering [Tue, 6 Oct 2009 18:38:19 +0000 (20:38 +0200)]
post-release administrivia

* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.

15 years agoversion 2.0
Jim Meyering [Tue, 6 Oct 2009 18:29:16 +0000 (20:29 +0200)]
version 2.0

* NEWS: Record release date.

15 years agogpt: don't malfunction on big-endian systems
Jim Meyering [Tue, 6 Oct 2009 18:10:00 +0000 (20:10 +0200)]
gpt: don't malfunction on big-endian systems

Numerous GPT tests would fail when run on e.g., big-endian PPC.
* libparted/labels/gpt.c (gpt_read): Now that we use the
SizeOfPartitionEntry member, be sure to convert from GPT's
little-endian on-disk format to to CPU endianness.
This bug was introduced via commit 14cce9b2, 2009-06-10, "gpt:
fix gpt_read to read all of the partition entries correctly".
* libparted/labels/gpt.c (_header_is_valid): Also convert it here.
Add a test to ensure that the partition entry size is no larger
than the slightly arbitrary UINT32_MAX/16.
* NEWS (Bug fixes): Mention it.

15 years agobuild: update gnulib submodule to latest
Jim Meyering [Tue, 6 Oct 2009 14:56:45 +0000 (16:56 +0200)]
build: update gnulib submodule to latest

15 years agomaint: add gnulib's gnu-web-doc-update module
Jim Meyering [Tue, 6 Oct 2009 14:39:13 +0000 (16:39 +0200)]
maint: add gnulib's gnu-web-doc-update module

* bootstrap.conf (gnulib_modules): Add gnu-web-doc-update

15 years agodoc: add pointer to NEWS in README
Jim Meyering [Tue, 6 Oct 2009 14:26:00 +0000 (16:26 +0200)]
doc: add pointer to NEWS in README

* README: Mention NEWS.

15 years agodoc: update README
Jim Meyering [Tue, 6 Oct 2009 14:23:19 +0000 (16:23 +0200)]
doc: update README

* README (WARNING): Mention upcoming removal of FS-manipulation
capabilities and that we'll retain FAT/HFS resize capabilities.
Remove an obsolete URL.  Do not encourage email to individuals.
Update info-viewing instructions, provide the on-line doc URL.

15 years agotests: resize FAT and HFS file systems
Jim Meyering [Sat, 19 Sep 2009 06:22:20 +0000 (08:22 +0200)]
tests: resize FAT and HFS file systems

Since it looks like we're stuck with keeping at least FAT and HFS
file-system resizing support in libparted, we have an obligation to
exercise at least some of that functionality.  For now, I've limited
this test to shrinking well-aligned partitions by a well-behaved
amount.  Curtis Gedak helped come up with a usable test.

* tests/t3000-resize-fs.sh: New file.
Use starting partition offset that is on a cylinder boundary,
and increase the partition size to be larger than 256 MiB.
When resizing, choose the new size to be exactly one cylinder
(8MiB) smaller than the original.

15 years agoped_partition_busy: do not call the libparted exception handler
Hans de Goede [Tue, 6 Oct 2009 09:31:14 +0000 (11:31 +0200)]
ped_partition_busy: do not call the libparted exception handler

Modify libparted/arch/linux.c _partition_get_part_dev() to not call
_device_stat() but instead use stat directly, as _device_stat() calls
the libparted exception handler, and we don't want this here, the only
caller of _partition_get_part_dev() is _partition_is_mounted(), which
in turn only gets called by linux_partition_is_busy(), and we don't
want to "throw" exceptions from ped_partition_busy().

This issue was noticed in combination with pyparted as used by
anaconda, see: http://bugzilla.redhat.com/527035#c10

15 years agodoc: mention the GPT/msftres bug fix
Jim Meyering [Thu, 1 Oct 2009 18:00:32 +0000 (20:00 +0200)]
doc: mention the GPT/msftres bug fix

* NEWS (Bug fixes): Mention it.

15 years agoparted: issue a warning upon any use of a file-system op
Jim Meyering [Thu, 1 Oct 2009 13:01:52 +0000 (15:01 +0200)]
parted: issue a warning upon any use of a file-system op

* parted/parted.c (issue_fs_op_warning): New function.
(do_cp, do_mkfs, do_mkpartfs, do_move, do_resize, do_check): Call it.
* tests/test-lib.sh: Export the envvar setting,
PARTED_SUPPRESS_FILE_SYSTEM_MANIPULATION_WARNING=1 to suppress
those warnings while running the few remaining FS-related tests.

15 years agomaint: avoid false-positive NULL-deref warning from clang
Jim Meyering [Wed, 30 Sep 2009 09:42:32 +0000 (11:42 +0200)]
maint: avoid false-positive NULL-deref warning from clang

* parted/ui.c: Include <assert.h>.
(command_line_get_disk): Add an assertion that command_line_get_device
currently guarantees will always be true.  This placates clang regarding
its sole NULL-deref warning.
(command_line_get_device): Move declarations "down" to first use.

15 years agobuild: use more gnulib modules for better POSIX compliance
Jim Meyering [Thu, 17 Sep 2009 12:15:01 +0000 (14:15 +0200)]
build: use more gnulib modules for better POSIX compliance

* bootstrap.conf (gnulib_modules): Add modules exposed via
make CFLAGS=-DGNULIB_POSIXCHECK 2>&1 \
|perl -lne '/.* use gnulib module (\S+).*/ and print $1' \
|sort |uniq -c|sort -nr
Add these: close fsync lseek mkstemp strdup unlink

15 years agomaint: function returning "int", did not return a value.
Jim Meyering [Tue, 29 Sep 2009 20:02:56 +0000 (22:02 +0200)]
maint: function returning "int", did not return a value.

* parted/ui.c (init_readline): Return a value (always 0 for now).
* parted/parted.c (_init): Handle init_readline's return value.

15 years agomaint: remove more dead stores and fix a bug in do_mkpartfs
Jim Meyering [Tue, 29 Sep 2009 19:49:55 +0000 (21:49 +0200)]
maint: remove more dead stores and fix a bug in do_mkpartfs

* libparted/fs/ext2/ext2_mkfs.c (ext2_mkfs_create_lost_and_found_inode):
Punt: suppress clang's (aka scan-build's) warning.
* parted/parted.c (snap_to_boundaries): Remove a dead store.
(do_mkpartfs): The apparent dead store to part_name exposed a real bug.
In fact, it highlighted that while do_mkpart uses its "part_name"
variable (and calls ped_partition_set_name), do_mkpartfs did not.
(snap_to_boundaries): Remove dead store.
* libparted/unit.c (parse_chs): Likewise, and a leak.
* libparted/fs/hfs/reloc_plus.c (hfsplus_cache_from_catalog): Likewise.
(hfsplus_cache_from_extent): Remove a dead store.
(hfsplus_cache_from_attributes): Likewise.
* libparted/fs/hfs/advfs_plus.c (hfsplus_btree_search): Likewise.
* libparted/fs/ext2/ext2_block_relocator.c (ext2_block_relocate_shrink):
Remove dead store and corresponding decl.
* parted/ui.h: Mark 2nd parameter as non-null.

15 years agomaint: remove dead store code and declarations
Jim Meyering [Tue, 29 Sep 2009 19:29:00 +0000 (21:29 +0200)]
maint: remove dead store code and declarations

* libparted/labels/bsd.c (bsd_partition_set_flag): Remove dead store
and corresponding decl.
* libparted/arch/linux.c (init_ide): Likewise.
(_dm_maptype): Likewise.
(_mount_table_search): Likewise.
* libparted/fs/amiga/asfs.c (_asfs_probe): Likewise.
* libparted/labels/mac.c (mac_alloc_metadata): Likewise.
* libparted/labels/rdb.c (amiga_write): Likewise.
(amiga_write): Again.
* libparted/fs/amiga/apfs.c (_generic_apfs_probe): Likewise.
* libparted/fs/hfs/reloc_plus.c (hfsplus_effect_move_extent): Likewise.
* libparted/fs/hfs/reloc.c (hfs_effect_move_extent): Likewise.
* libparted/labels/dos.c (probe_partition_for_geom): Remove dead
store in "can't happen" case.

15 years agomake PED_ASSERT handling sane: abort on false condition
Jim Meyering [Wed, 30 Sep 2009 09:10:15 +0000 (11:10 +0200)]
make PED_ASSERT handling sane: abort on false condition

Upon a failed PED_ASSERT, Do not ask the interactive user if they want
to continue.  This change will affect any code that expects to be able
to continue after a failed PED_ASSERT condition.  However, such code is
so fundamentally broken that this change is required.  If you require
to be able to continue after a false condition, then the code must
not use a macro named like PED_ASSERT.  This change was motivated by
my desire to use the clang static analysis tool.  Without this change,
there were over 300 mostly-false-positive reports.  With it, just 31,
almost all legitimate.
* libparted/debug.c (ped_assert): Remove first parameter.
It is now tested via the macro.
Now, this function always aborts, which helps clang understand.
Do not ask the interactive user if s/he wants to continue.
* include/parted/debug.h (PED_ASSERT): Test condition here,
not in ped_assert.
* libparted/disk.c (ped_disk_remove_partition): Remove the label
that was used only upon failing PED_ASSERT.  Now that PED_ASSERT
always aborts for a false condition, that would have been dead code.
(ped_disk_new_fresh): Likewise.

15 years agobuild: avoid a shadowing warning
Jim Meyering [Thu, 1 Oct 2009 10:03:07 +0000 (12:03 +0200)]
build: avoid a shadowing warning

* libparted/fs/hfs/advfs_plus.c (hfsplus_get_empty_end): Rename local,
"link" to avoid shadowing the syscall.
* libparted/fs/hfs/advfs.c (hfs_get_empty_end): Likewise.

15 years agofat-FS: do not modify fat file system support
Jim Meyering [Fri, 25 Sep 2009 06:53:30 +0000 (08:53 +0200)]
fat-FS: do not modify fat file system support

Revert "Add fat support for sector_size > 512."
This reverts commit 14395c356664a3b88f3929a6a3ad69bca374f70d.

15 years agoRevert "Fix compile failures."
Jim Meyering [Fri, 25 Sep 2009 06:53:18 +0000 (08:53 +0200)]
Revert "Fix compile failures."

This reverts commit 7603e404ee60f2f892be380a23c390f4638f451f.

15 years agodoc: update NEWS
Jim Meyering [Tue, 29 Sep 2009 15:16:59 +0000 (17:16 +0200)]
doc: update NEWS

* NEWS: Mention >512-byte sector support.

15 years agobuild: use newer bootstrap script
Jim Meyering [Tue, 29 Sep 2009 14:58:41 +0000 (16:58 +0200)]
build: use newer bootstrap script

* bootstrap: Update from coreutils.

15 years agobuild: update gnulib submodule to latest
Jim Meyering [Tue, 29 Sep 2009 14:57:08 +0000 (16:57 +0200)]
build: update gnulib submodule to latest

15 years agomaint: update most copyright year lists to include 2009
Jim Meyering [Tue, 29 Sep 2009 14:55:37 +0000 (16:55 +0200)]
maint: update most copyright year lists to include 2009

I used this command:
make update-copyright \
  UPDATE_COPYRIGHT_FORCE=1 UPDATE_COPYRIGHT_USE_INTERVALS=1

15 years agotests: enable more syntax-checks
Jim Meyering [Tue, 29 Sep 2009 14:52:18 +0000 (16:52 +0200)]
tests: enable more syntax-checks

* cfg.mk: Enable a few more tests.
* include/parted/debug.h: Remove useless parens to avoid
triggering failure of the sc_useless_cpp_parens syntax-check.
* libparted/arch/linux.h: Likewise.
* libparted/libparted.c: Likewise.

15 years agotests: enable a few syntax-checks
Jim Meyering [Tue, 29 Sep 2009 14:46:16 +0000 (16:46 +0200)]
tests: enable a few syntax-checks

* cfg.mk (local-checks-to-skip): Remove a few useless exclusions
and enable a few syntax checks.
* libparted/arch/linux.c (linux_destroy): Avoid triggering the
sc_cast_of_argument_to_free check.
* parted/strlist.c (str_list_destroy_node): Likewise.

15 years agotests: gpt: exercise creating all partition types; check for msftres bug
Jim Meyering [Thu, 24 Sep 2009 17:56:37 +0000 (19:56 +0200)]
tests: gpt: exercise creating all partition types; check for msftres bug

Ensure that a newly-created partition in a GPT partition table has no
'flag' set, by default.  This test also exercises setting the "name"
on a partition and creates one partition of each supported type.
* tests/t0220-gpt-msftres.sh: New file.
* tests/Makefile.am (TESTS): Add that new file.

15 years agogpt: don't use msftres flag for FAT/NTFS partitions
Keshav P R [Fri, 18 Sep 2009 11:07:51 +0000 (16:37 +0530)]
gpt: don't use msftres flag for FAT/NTFS partitions

This patch corrects the bug in parted due to which any FAT(12,16,32)
or NTFS partition(s) is, by default, incorrectly set as "Microsoft
Reserved Partition" type in GPT disks.  With this change, parted
defaults to setting the FAT/NTFS Partitions partition type to
Linux/Windows Basic Data Partition which will make them accessible
in Mac OS X and Windows.

Reported by hramrach@centrum.cz in <http://bugs.debian.org/441033>,
with suggested change by Osamu Aoki <osamu@debian.org>.
Keshav P R <skodabenz@rocketmail.com> wrote the above and prepared
this patch.

15 years agoui: do not initialize readline (which would output!) in --script mode
Jim Meyering [Thu, 24 Sep 2009 16:46:45 +0000 (18:46 +0200)]
ui: do not initialize readline (which would output!) in --script mode

Running parted with its --script (-s) option would, surprisingly,
print a few control characters if TERM were set appropriately,
and if readline and curses support were compiled in.
This fixes it not to do that.
* parted/parted.c (_init): Initialize readline support only after
parsing command line options, so we can skip it in --script mode.
* parted/ui.c (init_readline): New function.
Body extracted from ...
(init_ui): ...here.
* parted/ui.h (init_readline): Declare.
* tests/t0010-script-no-ctrl-chars.sh: New file.  Test for the above.
* tests/Makefile.am (TESTS): Add that new file.

15 years agoloop: don't infloop
Jim Meyering [Fri, 18 Sep 2009 13:30:07 +0000 (15:30 +0200)]
loop: don't infloop

Correct a bug introduced in commit 52815877, 2007-06-15,
"Make loop_probe and loop_clobber work with sector_size > 512, too."
* libparted/labels/loop.c (loop_clobber): Initialize "i" before
the loop, not inside it.
* tests/t0400-loop-clobber-infloop.sh: Test for this.
* tests/Makefile.am (TESTS): Add it.

15 years agotests: correct t1100-busy-label
Jim Meyering [Thu, 17 Sep 2009 13:20:38 +0000 (15:20 +0200)]
tests: correct t1100-busy-label

This test had two problems: FS-manipulation (creates a FAT fs) even
for non-512-byte sectors, and it had a now-unexpected line in the
expected output of its final command.
* tests/t1100-busy-label.sh: Use require_512_byte_sector_size_,
so that we skip this test when in non-512-sector size mode.
Remove the now-bogus line.
Note: this test is not normally run.
In order to run it, you have to run as root and set two envvars, e.g.,
sudo make check DEVICE_TO_ERASE=/dev/sde DEVICE_TO_ERASE_SIZE=16.4MB

15 years agobuild: update gnulib submodule to latest
Jim Meyering [Sun, 13 Sep 2009 18:42:24 +0000 (20:42 +0200)]
build: update gnulib submodule to latest

15 years agobuild: sync bootstrap from coreutils
Jim Meyering [Sun, 13 Sep 2009 18:44:56 +0000 (20:44 +0200)]
build: sync bootstrap from coreutils

* bootstrap: Update from coreutils.

15 years agolinux-commit: do not unnecessarily open partition device nodes
Hans de Goede [Fri, 28 Aug 2009 15:05:55 +0000 (17:05 +0200)]
linux-commit: do not unnecessarily open partition device nodes

After patching parted with my do-not-use-BLKPG patch, I started
to get EBUSY errors on commit_to_os. Note this is not caused
by the do-not-use-BLKPG patch, this was already happening, but
parted was silently ignoring the errors (and the kernel was
not notified of the changes, which is bad).  The error now
actually gets reported.

The problem turns out to be in libparted/arch/linux.c's
_flush_cache function, which walks all the partitions of the
disk and does BLKFLSBUF calls on them.  This causes the following:

commit_to_os -> device_open -> fd = open /dev/sda ->
_flush_cache -> for each /dev/sda# open, ioctl, close
-> ioctl(fd, BLKRRPART) -> EBUSY

What is happening here is that the:
for each /dev/sda# open, ioctl, close

Is causing udev change events for all the /dev/sda#
nodes, which causes udev to call blkid on all these nodes
(on systems which use DeviceKit), so blkid has /dev/sda# nodes
open while BLKRRPART gets called on /dev/sda -> EBUSY.

I've checked with two independend storage subsystem kernel
developers, and /dev/sda and /dev/sda#, guarantee cache coherency
now-a-days.  So there is no need to do this for 2.6, which also
eliminates the need to call _flush_cache() on device open at all.

* libparted/arch/linux.c (_have_kern26): New function.
(_flush_cache): For linux kernels 2.6 and newer, don't flush
partition devices.
(linux_open): Skip _flush_cache on newer kernels here, too.

15 years agolinux-commit: remove the use of the BLKPG ioctl
Hans de Goede [Fri, 28 Aug 2009 08:29:00 +0000 (10:29 +0200)]
linux-commit: remove the use of the BLKPG ioctl

While testing partitionable mdraid I noticed that the kernels
view of the partition table never changes even though I was successfully
making commit_to_os() calls.

This has let to me diving into libparted's commit_to_os() code for Linux
and there are multiple issues hiding in there:

1) Parted reads /sys/block/foo/range to determine how many partitions
   the device type supports and then makes BLKPG ioctl's to update the
   kernels view of the partition table for partitions which fall into
   this range. However for example /sys/block/sda/range contains 16,
   there are 2 issue with libparted using this number:
   1) scsi major's only support 15 partitions, 1 of the range of 16
      is reserved for the whole device, yet libparted will try
      to notify the kernel about 16 partitions if present
   2) If the major's partition minor's run out, the kernel will switch
      to the mdp major for the other partitions, iow range no longer
      limits the number of partitions.

2) libparted assumes the user knows what he is doing, and will ignore
   -ebusy errors for partitions, assuming that the user is smart enough
   to only change unused partitions. Parted does this without checking
   if the partitions which return ebusy actually are unchanged causing
   REAL errors to get unreported (BAD, really really BAD)

3) because of 1) libparted will only sync 1 partition on /dev/md#
   devices (would be 0 if not for the of by 1 bug as all md#p#
   partitions use the mdp major), and it fails to even do that without
   reporting an error.

###

1) we can fix by simply not checking /sys/block/foo/range, but instead
   just syncing max partitions.

2) is more troublesome, we could just make -EBUSY n error,
   but that may annoy / bug some users. OTOH in certain cases libparted
   already falls back to BLKRRPART which will return EBUSY so users
   should already be prepared to handle EBUSY

3) Could be fixed by making libparted recognize mdraid as a device type
   and except mdraid from using BLKPG, like it already is doing with
   DASD, but it might be better to just get rid of using BLKPG all
   together.  See below.

An even bigger problem IMHO is the use of the BLKPG ioctl instead of
BLKRRPART at all. What this does is tell the kernel parted's view
of the partition table and make it use that, instead of telling
the kernel to reread the partition table.  According to the parted
sources this is done for the case where the kernel does not know
the disklabel type. However as soon as the system is rebooted, the
system will be using the kernel's view. So IMHO it would be much
better to always use the kernels view and just always call BLKRRPART
in commit_to_os(), this would solve all of the above issues, *and*
make the way the system views the partition table consistent between
just after running parted and after a reboot.

I've attached a patch which removes the use of the BLKPG ioctl, notice
that this also removes a lot of special case code and workarounds,
which existence to me clearly indicates that using the BLKPG ioctl is
a bad idea.

* libparted/arch/linux.c (linux_disk_commit): Remove the use of the
BLKPG ioctl.
(_blkpg_add_partition, _blkpg_part_command, _blkpg_remove_partition):
(_device_get_partition_range, _disk_sync_part_table, _have_blkpg):
(_have_devfs): Remove functions thus rendered unused.

15 years agotests: make two partition-related tests work for other sector sizes
Jim Meyering [Fri, 28 Aug 2009 16:53:39 +0000 (18:53 +0200)]
tests: make two partition-related tests work for other sector sizes

These two root-only tests would fail with the PARTED_SECTOR_SIZE envvar
set to anything other than 512.  Now they also work for multiples.
* tests/t4100-dvh-partition-limits.sh: Make sector-size agnostic.
* tests/t4100-msdos-partition-limits.sh: Likewise.

15 years agotests: make it easier to diagnose loop_setup_ failure
Jim Meyering [Fri, 28 Aug 2009 09:47:40 +0000 (11:47 +0200)]
tests: make it easier to diagnose loop_setup_ failure

* tests/lvm-utils.sh: Don't redirect stderr to /dev/null.

15 years agotests: avoid spurious failure due to extra space in diagnostic
Jim Meyering [Fri, 28 Aug 2009 09:30:40 +0000 (11:30 +0200)]
tests: avoid spurious failure due to extra space in diagnostic

* libparted/labels/pt-tools.c (ptt_partition_max_start_len):
Remove stray space in diagnostic that was causing the root-only
regression test, t4100-dvh-partition-limits.sh, to fail.

15 years agotests: avoid spurious failure on "nodev" mounted partition
Jim Meyering [Fri, 28 Aug 2009 09:17:34 +0000 (11:17 +0200)]
tests: avoid spurious failure on "nodev" mounted partition

* tests/t8000-loop.sh: Skip this test if loop_setup_ fails.
* tests/t6000-dm.sh: Likewise.

15 years agoparted: avoid unnecessary open/close on commit, and thus udev activity
Hans de Goede [Thu, 27 Aug 2009 18:16:09 +0000 (20:16 +0200)]
parted: avoid unnecessary open/close on commit, and thus udev activity

* libparted/disk.c (ped_disk_commit): Open/close the underlying file
descriptor in this function, so that callees, ped_disk_commit_to_dev
and ped_disk_commit_to_os do not each perform open/close syscalls.
This saves an open/close pair, and thus avoids unneeded udev
activity on Linux.

Before this change, when calling commit() on a ped_disk, the
following would happen:

open /dev/sda
write partition table
close /dev/sda
open /dev/sda
ioctl (BLKRRPART)
close /dev/sda

This is rather inefficient, and causes 2 udev change events to be fired
for /dev/sda (+ the change events from the BLKRRPART), causing all kind
of scanning (blkid & friends) twice.

This patch fixes things to only open the device once.

15 years agodos: adjust variable declarations
Petr Uzel [Wed, 26 Aug 2009 10:29:46 +0000 (12:29 +0200)]
dos: adjust variable declarations

* libparted/labels/dos.c (write_ext_table): Move declaration of S down
to just before its first use.
Fix alignment of lba_offset declaration.

15 years agodos: factor out and define DOS_N_PRI_PARTITIONS
Petr Uzel [Wed, 26 Aug 2009 10:29:26 +0000 (12:29 +0200)]
dos: factor out and define DOS_N_PRI_PARTITIONS

* dos.c (DOS_N_PRI_PARTITIONS): Define.

15 years agodos: use sizeof(variable) instead of sizeof(type)
Petr Uzel [Wed, 26 Aug 2009 10:28:41 +0000 (12:28 +0200)]
dos: use sizeof(variable) instead of sizeof(type)

* libparted/labels/dos.c (write_ext_table): Use sizeof(variable)
instead of sizeof(type)
(write_empty_table, msdos_write): Likewise.

15 years agotests: t0202-gpt-pmbr.sh: various fixes
Petr Uzel [Wed, 26 Aug 2009 13:10:49 +0000 (15:10 +0200)]
tests: t0202-gpt-pmbr.sh: various fixes

* tests/t0202-gpt-pmbr.sh: use $bootcode_size variable instead
of plain 446.  Do not use /dev/urandom since it might not exist.

15 years agotests: t2300-dos-label-extended-bootcode.sh: various fixes
Petr Uzel [Wed, 26 Aug 2009 13:10:31 +0000 (15:10 +0200)]
tests: t2300-dos-label-extended-bootcode.sh: various fixes

* tests/t2300-dos-label-extended-bootcode.sh:
- fix typo where only first 400B of fake bootcode was installed
- use bootcode_size variable and increase its value from 440 to 446
- do not use /dev/urandom since it might not exist

15 years agobuild: ignore more generated files
Jim Meyering [Sat, 22 Aug 2009 13:58:34 +0000 (15:58 +0200)]
build: ignore more generated files

* .gitignore: Ignore a few more build artifacts.

15 years agotests: don't use "echo -n"
Jim Meyering [Sat, 22 Aug 2009 13:52:14 +0000 (15:52 +0200)]
tests: don't use "echo -n"

* tests/t7000-scripting.sh: Use printf, not "echo -n", for portability.

15 years agotest for the bootcode-in-extended-partition fix
Petr Uzel [Thu, 20 Aug 2009 13:27:30 +0000 (15:27 +0200)]
test for the bootcode-in-extended-partition fix

* tests/t2300-dos-label-extended-bootcode.sh: New file.
* tests/Makefile.am (TESTS): Add t2300-dos-label-extended-bootcode.sh.

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
15 years agodo not discard bootcode from extended partition
Petr Uzel [Thu, 20 Aug 2009 13:27:09 +0000 (15:27 +0200)]
do not discard bootcode from extended partition

* libparted/labels/dos.c (write_ext_table): Do not discard
  bootcode from extended partition on msdos label when some of
  the logical partitions are changed

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
15 years agoRemove unneeded test.
Joel Granados Moreno [Tue, 18 Aug 2009 16:23:35 +0000 (18:23 +0200)]
Remove unneeded test.

This test made sure that "md" was ignored when doing partition specific
actions.  We have added code that allows this scan once more, therefore
the test is no longer needed.

* tests/t6001-dm-ignoremd.sh: Remove file.
* tests/Makefile.am: Remove the test file from the list of tests.

15 years agoCompensate for different behavior in t7000 test.
Joel Granados Moreno [Tue, 18 Aug 2009 15:21:09 +0000 (17:21 +0200)]
Compensate for different behavior in t7000 test.

When the t7000 test was first engineered the "n" did not appear in the
output when testing mkpart & mkpartfs.  ATM, for an unknown reason,
the "n" is being echoed in the resulting string causing test failure
when compared with the errI string.  This patch attempts to make both
behaviors (with and without the echoed "n") pass the test.

* tests/t7000-scripting.sh: Make sure we don't have an " n" at the end
of the output string.

15 years agoFix 2 typos.
Gilles Espinasse [Tue, 18 Aug 2009 08:24:07 +0000 (10:24 +0200)]
Fix 2 typos.

* libparted/labels/fdasd.c (fdasd_enqueue_new_partition): Fix typo in
comment.
* parted/parted.c (_init_commands): Fix typo in message.

15 years agobuild: update dist-check rules
Jim Meyering [Tue, 18 Aug 2009 20:05:34 +0000 (22:05 +0200)]
build: update dist-check rules

* dist-check.mk: Merge from coreutils.

15 years agobuild: ignore new -Wjump-misses-init warnings
Jim Meyering [Tue, 18 Aug 2009 19:24:53 +0000 (21:24 +0200)]
build: ignore new -Wjump-misses-init warnings

* configure.ac: Ignore warnings from gcc's new -Wjump-misses-init.

15 years agobuild: update from gnulib
Jim Meyering [Tue, 18 Aug 2009 18:50:03 +0000 (20:50 +0200)]
build: update from gnulib

* gnulib: Update submodule to latest.
* bootstrap.conf (gnulib_modules): Add update-copyright
* cfg.mk (update-copyright-env): Define.

15 years agolabel/dasd: add missing prototype for dasd_get_max_supported_partition_count
Otavio Salvador [Wed, 12 Aug 2009 13:24:42 +0000 (10:24 -0300)]
label/dasd: add missing prototype for dasd_get_max_supported_partition_count

15 years agoUse fsync rather than O_DIRECT
Colin Watson [Fri, 24 Jul 2009 17:25:22 +0000 (18:25 +0100)]
Use fsync rather than O_DIRECT

O_DIRECT doesn't work on all filesystems (e.g. tmpfs), and fsync does
just as good a job to ensure that buffers are flushed.

Based on
http://lists.alioth.debian.org/pipermail/parted-devel/2008-August/002392.html
by Olaf Hering, but with added fsync/close error checking.

15 years agoUpdate the NEWS has.
Joel Granados Moreno [Fri, 31 Jul 2009 11:50:10 +0000 (13:50 +0200)]
Update the NEWS has.

* cfg.mk (old_NEWS_hash): Update the NEWS hash.

15 years agoRescue the news file from the stable-1.8.x branch
Joel Granados Moreno [Thu, 30 Jul 2009 16:07:53 +0000 (18:07 +0200)]
Rescue the news file from the stable-1.8.x branch

* NEWS:  Add all the contents from the NEWS file from the stable-1.8.x
branch.  Did some indentation and addeded some "**" where needed.

15 years agoExplicitly handle the signing key.
Joel Granados Moreno [Fri, 24 Jul 2009 12:37:13 +0000 (14:37 +0200)]
Explicitly handle the signing key.

If we are sure that we have the key, we are able to use it in any
subroutine (like make major).

* build-aux/parted-release (_find_signingkey): New function.
(_do_release): Use the key_id to sign the tag and to execute `make
major`.

15 years agoMinor corrections to the release README.
Joel Granados Moreno [Mon, 27 Jul 2009 09:12:30 +0000 (11:12 +0200)]
Minor corrections to the release README.

* README-release: Change "$v" to "$VERSION", its more explicit.  Include
a reminder to add the definition of parted to the release mail.

15 years agolinux: recognize md devices again, but know they can't be partitioned
Colin Watson [Fri, 24 Jul 2009 11:43:42 +0000 (12:43 +0100)]
linux: recognize md devices again, but know they can't be partitioned

* libparted/arch/linux.c (_skip_entry): Don't skip "md" devices.
(_has_partitions): New function; "loop" labels can't be partitioned.
(_blkpg_add_partition, _blkpg_remove_partition, _dm_add_partition,
_have_blkpg): Don't attempt to apply partition table changes to
unpartitionable devices.

15 years agodos: plug just-introduced leaks on error path
Jim Meyering [Fri, 10 Jul 2009 21:02:36 +0000 (23:02 +0200)]
dos: plug just-introduced leaks on error path

* libparted/labels/dos.c (write_ext_table): Also free new buffer
on error paths.

15 years agodos: don't write sector-size (>512) bytes from a 512-byte buffer
Jim Meyering [Fri, 10 Jul 2009 20:54:54 +0000 (22:54 +0200)]
dos: don't write sector-size (>512) bytes from a 512-byte buffer

* libparted/labels/dos.c (write_ext_table): Fix this error reported
by valgrind, by allocating/using a sector-sized buffer, rather than
using a 512-byte buffer on the stack.
Syscall param write(buf) points to uninitialised byte(s)
   at 0x33E12D13A0: __write_nocancel (in /lib64/libc-2.10.1.so)
   by 0x432B48: linux_write (linux.c:1782)
   by 0x42648C: write_ext_table (dos.c:1063)
   by 0x426471: write_ext_table (dos.c:1059)
   by 0x4268C5: msdos_write (dos.c:1094)
   by 0x40E9C4: ped_disk_commit_to_dev (disk.c:479)
   by 0x40EA08: ped_disk_commit (disk.c:502)
   by 0x408AE0: test_duplicate (disk.c:79)
   by 0x4C249ED: srunner_run_all (in /usr/lib64/libcheck.so.0.0.0)
   by 0x4089AD: main (disk.c:121)
 Address 0x4e48e00 is 512 bytes inside a block of size 1,024 alloc'd
   at 0x4A05260: memalign (vg_replace_malloc.c:460)
   by 0x4A05317: posix_memalign (vg_replace_malloc.c:569)
   by 0x432B06: linux_write (linux.c:1777)
   by 0x42648C: write_ext_table (dos.c:1063)
   by 0x426471: write_ext_table (dos.c:1059)
   by 0x4268C5: msdos_write (dos.c:1094)
   by 0x40E9C4: ped_disk_commit_to_dev (disk.c:479)
   by 0x40EA08: ped_disk_commit (disk.c:502)
   by 0x408AE0: test_duplicate (disk.c:79)
   by 0x4C249ED: srunner_run_all (in /usr/lib64/libcheck.so.0.0.0)
   by 0x4089AD: main (disk.c:121)

15 years agosun: don't read freed memory
Jim Meyering [Fri, 26 Jun 2009 19:24:14 +0000 (21:24 +0200)]
sun: don't read freed memory

* libparted/labels/sun.c (_use_old_info): Rename from
_probe_and_use_old_info.  Don't read sector 0 here.
(sun_write): Read it here instead.
Write not a constant-sized 512-byte buffer, but the sector-sized
buffer just read above.

15 years agogpt: adjust _write_pmbr[*] to work with >512-byte sectors
Jim Meyering [Wed, 17 Jun 2009 11:42:32 +0000 (13:42 +0200)]
gpt: adjust _write_pmbr[*] to work with >512-byte sectors

* libparted/labels/gpt.c (_write_pmbr): Adjust, to work with
larger-than 512-byte sectors.
[*] commit 14a15891 "gpt: preserve first 446 bytes of the PMBR"

15 years agotests: skip t2100-mkswap.sh for >512-byte SS, now that it fails
Jim Meyering [Wed, 17 Jun 2009 11:03:34 +0000 (13:03 +0200)]
tests: skip t2100-mkswap.sh for >512-byte SS, now that it fails

* tests/t2100-mkswap.sh: Use require_512_byte_sector_size_

15 years agobuild: arrange for "make check" to run the tests four times,
Jim Meyering [Wed, 17 Jun 2009 09:21:17 +0000 (11:21 +0200)]
build: arrange for "make check" to run the tests four times,

each using a different simulated partition size.  First with an
explicit size of 1024, then 2048, then 4096, and finally with
the default of 512.
* Makefile.am (check-other-sector_sizes): New rule.
(check): Depend on it.
* README-big-sector: Update accordingly.
Suggestion from Otavio Salvador.

15 years agobuild: enable many warnings
Jim Meyering [Wed, 17 Jun 2009 08:12:57 +0000 (10:12 +0200)]
build: enable many warnings

* configure.ac: New configure-time option: --enable-gcc-warnings.
* bootstrap.conf: Use gnulib modules: warnings manywarnings.
* debug/Makefile.am: Define AM_CFLAGS.
* libparted/Makefile.am: Likewise.
* libparted/tests/Makefile.am: Likewise.
* parted/Makefile.am: Likewise.
* partprobe/Makefile.am: Likewise.
* debug/clearfat/Makefile.am: Likewise.
* libparted/labels/Makefile.am: Likewise.

15 years agobuild: avoid new warnings
Jim Meyering [Wed, 17 Jun 2009 08:21:31 +0000 (10:21 +0200)]
build: avoid new warnings

* debug/clearfat/clearfat.c (usage): Declare static.
* partprobe/partprobe.c (usage): Likewise.
* libparted/cs/natmath.c (abs_mod, extended_euclid): Declare static.
* libparted/timer.c (PED_TIMER_START_DELAY): Remove unused definition.
* libparted/unit.c (ped_unit_format_custom_byte): Remove an unnecessary
cast-to-double.

15 years agosun: remove obsolete FIXME comments
Jim Meyering [Tue, 16 Jun 2009 14:02:15 +0000 (16:02 +0200)]
sun: remove obsolete FIXME comments

* libparted/labels/sun.c:

15 years agoui: avoid infloop in testing
Jim Meyering [Tue, 16 Jun 2009 13:25:52 +0000 (15:25 +0200)]
ui: avoid infloop in testing

These commands would provoke an infinite loop:
ss=4096 N=100; dd if=/dev/zero of=testfile bs=${ss}c count=$N
./parted ---pretend-input-tty testfile -- mklabel gpt mkpart \
  primary ext3 1s -1s < /dev/null
* parted/ui.c (command_line_prompt_words): Treat EOF like ^C.

15 years agotests: skip FS-related part when sector size is larger than 512
Jim Meyering [Tue, 16 Jun 2009 13:23:14 +0000 (15:23 +0200)]
tests: skip FS-related part when sector size is larger than 512

* tests/t7000-scripting.sh: Adapt to work with large sector sizes.

15 years agotests: handle SS>512, clean up, add consistency check
Jim Meyering [Tue, 16 Jun 2009 10:26:29 +0000 (12:26 +0200)]
tests: handle SS>512, clean up, add consistency check

* tests/t5000-tags.sh: Don't fail for sector size of 4096 and greater.

15 years agotests: t4000-sun-raid-type: accommodate arbitrary sector sizes
Jim Meyering [Tue, 16 Jun 2009 09:50:42 +0000 (11:50 +0200)]
tests: t4000-sun-raid-type: accommodate arbitrary sector sizes

* tests/t4000-sun-raid-type.sh: Make the expected output depend
on the sector size.

15 years agotests: reenable sun label tests
Jim Meyering [Tue, 16 Jun 2009 09:33:17 +0000 (11:33 +0200)]
tests: reenable sun label tests

* libparted/tests/common.c (_implemented_disk_label): Remove "sun".

15 years agodisk.c: add assertions
Jim Meyering [Mon, 15 Jun 2009 21:20:39 +0000 (23:20 +0200)]
disk.c: add assertions

15 years agosun: don't segfault for sector sizes larger than 512
Jim Meyering [Fri, 12 Jun 2009 19:40:02 +0000 (21:40 +0200)]
sun: don't segfault for sector sizes larger than 512

* libparted/labels/sun.c Include "pt-tools.h" and "verify.h".
(sun_verify_checksum): Make parameter "const".
(sun_probe): Don't always return 0, now that this code works.
(sun_probe): Rewrite to work with sector sizes larger than 512.
(_probe_and_use_old_info): Likewise.
(sun_clobber): Likewise.
(sun_read): Likewise.
(_check_geometry_sanity) Don't accept all-zeros c,h,s.
Add assertions and uses of verify.
(sun_alloc): Remove bogus cast.
Don't modify through const pointer.

15 years agomsdos: clean-up (no semantic change)
Jim Meyering [Fri, 12 Jun 2009 10:32:53 +0000 (12:32 +0200)]
msdos: clean-up (no semantic change)

* libparted/labels/dos.c (msdos_write): Remove useless initialization.
(msdos_clobber): Remove unnecessary cast.

15 years agomsdos: do not scale counts by sector_size/512
Jim Meyering [Fri, 12 Jun 2009 09:34:50 +0000 (11:34 +0200)]
msdos: do not scale counts by sector_size/512

* libparted/labels/dos.c (chs_to_sector, linear_start):
(linear_end, fill_raw_part, fill_ext_raw_part_geom):
(sector_to_chs): Scaling (e.g., a starting sector number) by
sector_size/512 loses information when sector_size > 512.  Don't do it.

15 years agoparted-ui: when failing, include more information in an unusual case
Jim Meyering [Fri, 12 Jun 2009 08:20:49 +0000 (10:20 +0200)]
parted-ui: when failing, include more information in an unusual case

* libparted/cs/geom.c (ped_geometry_set): Include starting sector
number and length in diagnostic.  To trigger this, run the following:
dev=f; rm -f $dev; dd if=/dev/null of=$dev bs=1 seek=100k
PARTED_SECTOR_SIZE=2048 ./parted -s $dev mklabel msdos
PARTED_SECTOR_SIZE=2048 ./parted -s $dev mkpart primary 1s 40s
PARTED_SECTOR_SIZE=2048 ./parted -s $dev p
Error: Can't have the end before the start! (start sector=128 \
  length=-78)

15 years agotests: t2200-dos-label-recog.sh: adapt to work with larger sector size
Jim Meyering [Fri, 12 Jun 2009 08:09:47 +0000 (10:09 +0200)]
tests: t2200-dos-label-recog.sh: adapt to work with larger sector size

Using a 100K image is inadequate for larger sector sizes, since it
triggers a bug whereby the device length (in sectors) smaller than
the cylinder_size: from dos.c:
  if (!ped_geometry_init (&start_geom, dev, cylinder_size,
      dev->length - cylinder_size))
That would pass a negative value for the 3rd argument.
* tests/t2200-dos-label-recog.sh: Use an image of size 10MB, not 100K.

15 years agotests: add infrastructure: when skipping a test, say why
Jim Meyering [Fri, 12 Jun 2009 07:58:57 +0000 (09:58 +0200)]
tests: add infrastructure: when skipping a test, say why

* tests/Makefile.am (TESTS_ENVIRONMENT): Arrange for the first line
of 'skip_test_'s argument to be printed on stderr.
* tests/test-lib.sh (skip_test_): New function.