Commit Graph

789 Commits

Author SHA1 Message Date
Karel Zak 2469ba3677 libfdisk: add fdisk_reassign_device()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-10 12:32:26 +02:00
Karel Zak c134c8b101 libfdisk: support logical partition resize
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-19 16:03:41 +02:00
Karel Zak 5ec4400dec libfdisk: allow to resize container
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-19 15:32:02 +02:00
Karel Zak 22f4c4641a libfdisk: add more debug messages to get-last-possible resize space
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-19 15:27:05 +02:00
Karel Zak 53625d1ae9 libfdisk: (dos) be more verbose on partno -ERANGE error
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-19 14:32:59 +02:00
Karel Zak ee9ba4fa5e libfdisk: (dos) fix primary/logical logic when follow template
This stupid bug has been introduced by e1cfb304 (v2.30) and it
disables to create extended partition by cfdisk :-(

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-19 11:41:02 +02:00
Sami Kerola 1b5042636f misc: fix reassigned values before old ones has been used [cppcheck]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 12:19:20 +02:00
Ruediger Meier 92e486f80e libfdisk: fix guid usage of packed struct gpt_entry
clang issued warnings like this:

../libfdisk/src/gpt.c:371:18: warning: taking address of packed member 'type' of class or structure 'gpt_entry' may result in an unaligned pointer value [-Waddress-of-packed-member]
        guid_to_string(&e->type, str);
                        ^~~~~~~

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-13 23:38:48 +02:00
Ruediger Meier 7f387c5c21 libfdisk: cleanup sun label checksum usuage
We are using now the formerly unused function sun_pt_checksum(). This
cleanup was motivated by clang compiler warning, see below. Also nice
that we are now always using uint16_t instead of short.

Warning was:

../libfdisk/src/sun.c:177:35: warning: taking address of packed member 'csum' of class or structure 'sun_disklabel' may result in an unaligned pointer value
      [-Waddress-of-packed-member]
                while(ush < (unsigned short *)(&sunlabel->csum))

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-13 18:06:36 +02:00
Karel Zak 7dec8dfeca Merge branch 'master' of https://github.com/yurchor/util-linux
* 'master' of https://github.com/yurchor/util-linux:
  Fix minor typos
2017-06-02 11:13:39 +02:00
Ruediger Meier c0d7b11a3f build-sys: fix library order when linking
We got some errors on Alpine Linux where $LTLIBINTL is non-empty:

./.libs/libcommon.a(libcommon_la-blkdev.o): In function `open_blkdev_or_file':
lib/blkdev.c:282: undefined reference to `libintl_gettext
collect2: error: ld returned 1 exit status

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-01 03:16:48 +02:00
Sami Kerola 2e2cfdae79 libfdisk: fix variable shadowing
libfdisk/src/context.c: In function 'fdisk_assign_device':
libfdisk/src/context.c:549:7: warning: declaration of 'rc' shadows a previous local [-Wshadow]
libfdisk/src/context.c:542:10: note: shadowed declaration is here

[kzak@redhat.com: - add rc to debug message]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-29 12:18:08 +02:00
Yuri Chornoivan 0508f347c8 Fix minor typos 2017-05-24 00:22:20 +03:00
Karel Zak f854eca369 libfdisk: update docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-23 14:22:04 +02:00
Karel Zak 8d3e3e6b4d libfdisk: (docs) add missing 'since' tags
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-23 14:02:14 +02:00
Karel Zak 199f8cd3b5 libfdisk: don't use errno after close()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:43:48 +02:00
Karel Zak 274e6f6f8f libfdisk: use memcpy() for non-terminated string [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:29:50 +02:00
Karel Zak 3fdbf0ee09 libfdisk: initialize partno variable [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:28:07 +02:00
Karel Zak 0a48e2370d libmount: check fstat() return code [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:28:07 +02:00
Karel Zak 059ad53815 libfdisk: don't print uninitialized variable [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:28:07 +02:00
Karel Zak 29f2e825d8 libfdisk: add fdisk_partition_has_wipe()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-09 14:30:02 +02:00
Karel Zak 7095232d21 libfdisk: fix NLS support
The current libfdisk code uses gettext() to translate strings. It
means it follows the default text domain (as set by textdomain(3)
usually in the main program). This is useless for public shared
library.

We have call private bindtextdomain() and use dgettext() with private
domain name to be independent on the main program. For this purpose
include/nls.h supports UL_TEXTDOMAIN_EXPLICIT to use dgettext().

Note that libfdisk will continue to use util-linux.po, rather than
keep the texts in the separate file.

The nls.h has to be included only from fdiskP.h to be sure that
nls.h works as expected for the library.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-25 17:05:09 +02:00
Karel Zak 02a376f2ee libfdisk: (gpt) rename to gpt_entry_is_used()
The current function name is inconsistent with the rest of the code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-19 14:00:07 +02:00
Pavel Butsykin e6b4209d95 libfdisk: allow to change an existing extended partition
Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
2017-04-19 10:25:39 +02:00
Ruediger Meier c8df4b17d4 misc: fix some printf format strings
Fix compiler warnings seen on Linux/i586 and OSX/travis.

  #type            #format   #cast
   unsigned long    %lu       -
   uint64_t         PRIu64    -
   fdisk_sector_t   %ju       (uintmax_t)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-04-10 15:40:58 +02:00
Karel Zak 52f35f1ecc libfdisk: (gpt) fix ents zeroize
The gpt->ents is "unsigned char" buffer now. We need to use bytes, no
number of entries...

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-06 13:39:44 +02:00
Karel Zak bbb574a293 libfdisk: (gpt) update nparts_max
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-06 13:04:09 +02:00
Karel Zak a8294f401f libfdisk: (gpt) care about SSIZE_MAX for read(2)
read(2) behavior is undefined if you want to read more  than SSIZE_MAX
bytes. Let's be paranoid and check for this...

Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-06 12:13:46 +02:00
Karel Zak 9e320545bb libfdisk: (gpt) make entries array size calculation more robust
* use the same function everywhere
* keep calculation based on size_t

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-05 18:40:56 +02:00
Karel Zak b683c08108 libfdisk: (gpt) use size_t and gpt_get_nentries()
If possible use size_t for number of entries (partitions). It
makes code more readable and without unnecessary casts.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-05 14:55:32 +02:00
Karel Zak b28df75eec libfdisk: (gpt) don't access entries array directly
We blindly assume that our sizeof(struct gpt_entry) is the same
on-disk stored header->sizeof_partition_entry.

It seems more correct would be to use sizeof specified by header to
access the entries array items. This patch introduces gpt_get_entry()
to avoid direct access to gpt->ents[].

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-05 14:19:13 +02:00
Karel Zak 3006dd7352 Merge branch '2017wk11' of git://github.com/kerolasa/lelux-utiliteetit
* '2017wk11' of git://github.com/kerolasa/lelux-utiliteetit:
  blkid: add control struct
  blkid: simplify version option handling
  tests: add static keyword where needed [smatch scan]
  tests: do not use plain 0 as NULL [smatch scan]
  libsmartcols: fix test variable shadowing
2017-03-24 11:59:57 +01:00
Sami Kerola 71f08e9706
tests: do not use plain 0 as NULL [smatch scan]
Likewise commit 8791804065.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-17 21:22:26 +00:00
Karel Zak bb6762035a libfdisk: fix compiler warning [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-16 10:01:54 +01:00
Karel Zak b2b5292541 libfdisk: fix potentially NULL pointer usage
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-13 15:20:56 +01:00
Karel Zak 168950e3ce libfdisk: (dos) add ID related debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-27 13:44:08 +01:00
Karel Zak ea4ea332a8 libfdisk: add version to debug output
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-27 13:16:18 +01:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Karel Zak 1c1d30c750 libfdisk: add sample-fdisk-mkpart binary
For example:
	# sample-fdisk-mkpart --device /dev/sdc 1M 2M 3M - 5M

	# fdisk -l /dev/sdc
	...
	Device     Boot Start    End Sectors Size Id Type
	/dev/sdc1        2048   4095    2048   1M 83 Linux
	/dev/sdc2        4096   8191    4096   2M 83 Linux
	/dev/sdc3        8192  14335    6144   3M 83 Linux
	/dev/sdc4       14336 204799  190464  93M  5 Extended
	/dev/sdc5       16384  26623   10240   5M 83 Linux

Addresses: https://github.com/karelzak/util-linux/issues/204
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-17 16:15:03 +01:00
Karel Zak 8d03f4af49 libfdisk: (dos) make it possible to create primary/logical by template
Let's check partition partno if specified to create logical or primary
partition.

Addresses: https://github.com/karelzak/util-linux/issues/204
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-17 16:11:37 +01:00
Karel Zak 21f1206aac libfdisk: (gpt) make sure it's GPT in public API
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-17 14:47:00 +01:00
Karel Zak e1cfb30466 libfdisk: verify partno from template
* verify partno from template when create a new partition
* remove unnecessary l->ext_offset check

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-17 13:17:48 +01:00
Karel Zak a1001292ae libfdisk: (dos) debug what we read from first sector
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-14 14:46:19 +01:00
Karel Zak 0cec78a3c4 libfdisk: classify collision type
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-14 14:23:45 +01:00
Karel Zak 37204dc60c libfdisk: check for collisions when create new label
We need to be sure that when create a new disklabel than the old label
will be removed.

Addresses: https://github.com/karelzak/util-linux/issues/410
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-14 13:07:54 +01:00
Karel Zak bd3457b8d9 libfdisk: fix fdisk_set_wipe_area() calls
The function expects size in sectors rather than in bytes.

Addresses: https://github.com/karelzak/util-linux/issues/410
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-10 16:45:18 +01:00
Karel Zak 91cce31a8e sfdisk: --quiet fixes
Addresses: https://github.com/karelzak/util-linux/issues/412
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-10 12:54:23 +01:00
Karel Zak f71b96bfa1 libfdisk: (gpt) add check for entries array size
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-25 12:00:27 +01:00
Karel Zak 5eaeb5858f libfdisk: (gpt) make calculations more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-16 14:57:02 +01:00
Karel Zak b2140d2f24 libfdisk: apply label alignment properties
This fix changes from the previous patches.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-16 11:20:32 +01:00
Karel Zak 502dd53c86 libfdisk: change the way how apply user device properties
The current code calls fdisk_apply_user_device_properties() after
label probing, because we want to overwrite label geometry by user
settings (e.g. -C -H -S fdisk options).

Unfortunately, this way does not work if we need to use a different
sector size, because label probing depends on sector size... So, the
right way is to apply user setting to the fdisk context before we
start to read from device, and overwrite geometry again after label is
already read. Fortunately, this shit is necessary only rarely and for
SUN and SGI disk labels.

Addresses: https://github.com/karelzak/util-linux/issues/396
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-13 12:56:10 +01:00
Karel Zak e86c73164f libfdisk: recount size when apply user device properties
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-13 12:16:06 +01:00
Karel Zak 7526c305b4 libfdisk: don't use blkdev ioctls for regular files
$ fdisk <diskimage>

open("sdc.img", O_RDONLY|O_CLOEXEC)     = 3
ioctl(3, BLKSSZGET, 0x7ffcf51357c4)     = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(3, BLKGETSIZE64, 0x7ffcf51357b0)  = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(3, BLKGETSIZE, 0x7ffcf51356c8)    = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(3, FDGETPRM, 0x7ffcf51356d0)      = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(3, HDIO_GETGEO, 0x7ffcf5135790)   = -1 ENOTTY (Inappropriate ioctl for device)

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-13 11:23:23 +01:00
Karel Zak e213a8e5a3 libfdisk: (sun) use self_label()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-05 12:36:08 +01:00
Sébastien Helleu d673b74e9d docs: replace FTP by HTTPS in kernel.org URLs
The links to ftp://ftp.kernel.org/ are replaced by
https://www.kernel.org/.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 11:22:26 +01:00
Ruediger Meier 223939d95b misc: spelling, always use "cannot" instead of "can not"
Just to be consistent ...

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-11-30 14:56:50 +01:00
Karel Zak 35ca511827 sfdisk: support empty label use-case
By default sfdisk creates partition table when a first partition is
specified, otherwise the device is not modified. This force users to
create at least one partition.

This commit allows to create empty label without partitions if "label:
<name>" header line is specified by script.

The commit also modifies "New situation:" output to list label name
and label identifier.

Addresses: https://github.com/karelzak/util-linux/issues/374
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-11-30 13:01:33 +01:00
Karel Zak 8c2e8e86d2 libfdisk: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-11-02 12:56:06 +01:00
Ruediger Meier eaaf0e7e37 misc: once again some printf format strings
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-10-27 11:03:27 +02:00
Karel Zak a50c849007 libfdisk: cleanup labelitem initialization
* use macro for label initialization
* make sure we do not call fdisk_ref_labelitem() and
  fdisk_unref_labelitem() for non-allocated items

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-27 10:53:55 +02:00
Ruediger Meier 14b7f754c9 libfdisk: fix uninitialized fdisk_labelitem
fdisk -l could crash randomly. Only seen on some i586 systems with
certain exotic compiler options.

The problem was that this item is later used in
function fdisk_reset_labelitem() like this:

    if (li->type == 's')
        free(li->data.str);

This may crash if item is randomly initialized.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-10-27 10:43:45 +02:00
Karel Zak 469acdb449 libfdisk: (script) make bootable flag parsing more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-26 14:01:29 +02:00
Karel Zak 16b5238eb3 libfdisk: add trivial script test
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-26 13:59:07 +02:00
Karel Zak bae57b5a3c misc: fix unsigned int usage for ctype.h functions
Reported-by: "Yuriy M. Kaminskiy" <yumkam@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-26 10:13:47 +02:00
Karel Zak 8430b9b884 libfdisk: make script token parser more robust
* make sure token is terminated
* skip closing quotes
* allow extra space after quotes and before terminater
* skip extra space after terminater

Addresses: https://github.com/karelzak/util-linux/issues/367
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-25 13:42:48 +02:00
Karel Zak f37f50594f libfdisk: fix script Type= and Id= parsing
The parser is not consistent and *case insensitive* Type= and Id= tokens
are not expected on all places.

Addresses: https://github.com/karelzak/util-linux/issues/367
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-25 12:32:23 +02:00
Karel Zak 17d0902c89 libfdisk: (gpt) make attributes parser more robust
* allow GUID: prefix only for numbers
* require space or comma separator

Addresses: https://github.com/karelzak/util-linux/issues/367
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-25 12:10:31 +02:00
Gustavo Zacarias 7f0d4d56a2 lib/crc32: prefix public functions
Make the publicly-visible crc32 library functions prefixed by ul_, such
as crc32() -> ul_crc32().
This is because it clashes with the crc32() function from zlib.
For newer versions of glib (2.50+) zlib and libblkid are required
dependencies and otherwise results in build failure when building
statically.

Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
2016-10-19 12:11:59 +02:00
Karel Zak 81b176c4da docs: some random fixes
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-09-27 12:52:47 +02:00
Karel Zak be163aa0da libfdisk: (docs) add missing version notes
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-09-27 11:58:32 +02:00
Igor Gnatenko 0e0943c15b debug: use const void * for ul_debugobj()
We don't modify data it's pointing out and we should not modify it.

Also remove casting to void * as gcc will do it automatically (before
we had to cast it explicitly to avoid warning on discarding 'const'
qualifier).

Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2016-09-21 08:22:35 +02:00
Tobias Stoeckmann 1037269fec libfdisk: Distinguish between first LBA sector and partition
An insufficient check leads to an invalid free space output, as seen here:

$ dd if=/dev/zero of=cfdisk.iso bs=1M count=1
$ losetup -f cfdisk.iso
$ echo w | fdisk /dev/loop0
$ echo '1,1' | sfdisk /dev/loop0 --append
$ echo '3,' | sfdisk /dev/loop0 --append
$ sfdisk --list-free /dev/loop0
Start End Sectors Size
    1   2       2   1K
$ _

In this case, libfdisk fails to notice that it tries to calculate space
between two partitions, not between start of disk and first partition.
Currently, the code tries to achieve that by checking the address of the
last "partition", which is the first_lba block.  Now if the first
partition is merely 1 block in size, the "last" address is still equal
to the first_lba block, which renders the check in libfdisk for the next
partition invalid.

I chose to use "nparts == 0" for this check, because the partitions are
properly sorted before iterating over them.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-08-29 13:22:24 +02:00
Tobias Stoeckmann 8480181838 libfdisk: Fix assert error in free space handling
An off-by-one issue exists in fdisk_get_freespaces. It can trigger an
assert, as seen here:

$ dd if=/dev/zero of=cfdisk.iso bs=1M count=1
$ losetup -f cfdisk.iso
$ echo w | fdisk /dev/loop0
$ echo '1,2' | sfdisk /dev/loop0 --append
$ echo '3,' | sfdisk /dev/loop0 --append
$ sfdisk --list-free /dev/loop0
Aborted
$ _

Problem here is an invalid "grain" processing. A grain is considered
expected free space between partitions which can be required for proper
alignment. Normally, it's 1 MB but in this case our iso is merely 1 MB
so the grain is reduced to 1 byte.

The if-condition in question checks for "last + grain <= pa->start" and
therefore even triggers if there is no space between them (due to equal
check). Eventually, the start block address is higher than the end block
address which triggers the assert().

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-08-29 13:22:24 +02:00
Sami Kerola 74ce680a3e
misc: simplify if clauses [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Karel Zak f88eeb25f2 libfdisk: cleanup fdisk_gpt_set_npartitions()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-21 14:21:30 +02:00
Karel Zak 0a7cdf8060 libfdisk: (gpt) be more careful with 64bit constants
It's probably more robust (and readable) to be explicit when we count
with constant and 64bit numbers.

Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1344482
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-21 14:06:14 +02:00
Sebastian Rasmussen d1b7bfe506 fdisk: Fix typo RequiredPartiton -> RequiredPartition
This typo fix is backwards compatible in that fdisk will accept both
the GPT attribute RequiredPartition and RequiredPartiton with the typo.
Update documentation and tests to all use the new attribute name.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:51:07 +02:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Sebastian Rasmussen d35df4db5b docs: Fix various typos
Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Karel Zak 747600537c libfdisk: use table-length in dump for non-standard PT
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-18 14:29:50 +02:00
Karel Zak a67054f9be libfdisk: make table-length usage more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-18 14:15:02 +02:00
Sassan Panahinejad d96153f8c8 sfdisk: Add support for altering GPT size
Adds a header option to alter the GPT table length
2016-05-18 13:56:25 +02:00
Sassan Panahinejad a18e726c66 libfdisk: Add support for altering GPT size
This is useful in two situations:

1. More than 128 partitions are required. Or

2. The partition table must be restricted in size, such as when a system
expects to find a bootloader at a location that would otherwise overlap the
partition table.

The gdisk partitioner supports this feature.

libfdisk is already capable of reading and writing partition tables of any
size, but previously could only create ones of 128 entries and could not
resize.

This change should be fairly safe, as it has no effect unless explicitly
activated.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-18 13:48:04 +02:00
Sassan Panahinejad 083c35b9f6 libfdisk: fix range checking for fdisk_set_last_lba 2016-05-18 13:46:35 +02:00
Karel Zak 40c9c3a6b7 libfdisk: add API for work with labelitems
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-12 14:37:29 +02:00
Karel Zak e4c5250dfb libfdisk: move fdisk_field_...() functions to field.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-12 12:21:59 +02:00
Karel Zak a3a125b922 libfdisk: use fdisk_add_partition() for unused partno
For example:

   sfdisk -N <parno>

may address unused partition. In this case we need to redirect from
fdisk_set_partition() to fdisk_add_partition() and follow default
setting (used all free space).

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-10 10:52:31 +02:00
Karel Zak 131e38a28e libfdisk: add fdisk_wipe_partition()
Now libfdisk provides functionality wipe disk device only ([s]fdisk
option --wipe).

This patch allows to probe for filesystems/RAIDs on newly created
partitions.  It means we can remove signatures before the partition
node (device) is created. This reduces udev events and it's
unnecessary to call wipefs for all partitions.  For example

  sfdisk --wipe=always --wipe-partitions=always /dev/sda <<<
  ...
  EOF

is a elegant way how to create new disk layout without any obsolete
filesystems/RAIDs.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-04 12:32:52 +02:00
Karel Zak b362a4cb98 libfdisk: don't offer zero length freespace
Reported-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-25 11:59:06 +02:00
Karel Zak deb1c90327 libmount: remove duplicate code
For petty long time we have strdup_to_struct_member() macro to avoid
duplicate code when strdup() strings in setter functions. Let's use it
for libmount.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-22 13:59:06 +02:00
Karel Zak 00e40d688a libfdisk: fix ref.counting in fdisk_apply_script() [clang analyze]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-30 11:18:07 +02:00
Benno Schulenberg 614ddddfc1 libfdisk: (gpt) reword two error messages with a sense of direction
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-16 10:39:37 +01:00
Benno Schulenberg e906ab3c6a libfdisk: (bsd) fix spelling in warning message
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-16 10:39:36 +01:00
Ruediger Meier 18336d16d9 build-sys: use AC_PROG_MKDIR_P and remove a few gnuisms
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-13 21:48:09 +01:00
Ruediger Meier e1a15f8f68 misc: fix printf i386 compiler warnings
Still a few printf warnings found on i386 Linux:

libfdisk/src/alignment.c: In function 'fdisk_align_lba':
libfdisk/src/alignment.c:115:3: warning: format '%ju' expects argument of type 'uintmax_t', but argument 6 has type 'long unsigned int' [-Wformat]
sys-utils/lsns.c: In function ‘add_namespace’:
sys-utils/lsns.c:346:2: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘ino_t’ [-Wformat]
sys-utils/lsns.c: In function ‘add_process_to_namespace’:
sys-utils/lsns.c:362:2: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 6 has type ‘ino_t’ [-Wformat]
sys-utils/lsns.c: In function ‘add_scols_line’:
sys-utils/lsns.c:440:4: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘ino_t’ [-Wformat]

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-12 11:28:03 +01:00
Karel Zak 5bb1d22e8a build-sys: fix if..endif for *_la_LDFLAGS
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-10 13:54:15 +01:00
Ruediger Meier d9851e63fb libfdisk: remove ifdef HDIO_GETGEO
We don't use HDIO_GETGEO since e5b5a349.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:29:05 +01:00
Ruediger Meier 7a11addee8 fdisk: sun, undef HAVE_QSORT_R for non-Linux
Linux/glibc's qsort_r(3) has differently ordered arguments than BSD
implementations. For now we undef that quick and dirty.

The real fix would be to make configure check for qsort_r more
carefully (AC_CHECK_FUNCS with AC_LANG_WERROR). Moreover one could
add a wrapper to swap arguments, see
https://github.com/noporpoise/sort_r/blob/master/sort_r.h

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:28:48 +01:00
Ruediger Meier fdbd7bb940 misc: again fixing many printf format strings
This is again a huge patch regarding printf format strings to
fix compiler warnings seen on clang/OSX.

I'm trying to follow these rules strictly:

 #type      #format   #cast
 uintmax_t   %ju      -
 intmax_t    %jd      -
 uint64_t    PRIu64   -
 int64_t     PRId64   -
 size_t      %zu      -
 ssize_t     %zd      -
 ino_t       %ju      (uintmax_t)
 off_t       %jd      (intmax_t)

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:16:04 +01:00
Yuriy M. Kaminskiy 06fa581748 misc: safer (and uniform) handling of return value
When `rc` is `INT_MAX`, `rc + 1` result in signed integer overflow.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-07 15:11:06 +01:00
Andreas Henriksson a2ad58ac51 libfdisk: Fix order of C/H/S numbers output
While the header says C/H/S the actual numbers where printed as
C/S/H.

Addresses: http://bugs.debian.org/815847
Reported-by: "groups, freeman" <freeman_groups@reason.dyndns.org>
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
2016-03-07 15:08:50 +01:00
Ruediger Meier 262c94c2c7 fdisk: fix warning, incompatible pointer types passing 'uint64_t *'
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-29 13:04:48 +01:00
Ruediger Meier 2013b33f40 build-sys: disable unused parameter warnings for some test progs
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 03:20:22 +01:00
Ruediger Meier b9710f1f08 misc: fix compiler warnungs (unsigned/signed)
These ones should be fixed:
libblkid/src/probe.c:393:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/probe.c:907:25: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libblkid/src/probe.c:1221:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:540:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1043:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1056:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1057:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1061:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/partitions/partitions.c:1199:27: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libblkid/src/partitions/partitions.c:1410:26: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libblkid/src/partitions/partitions.c:1431:25: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libblkid/src/superblocks/linux_raid.c:151:8: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
libblkid/src/superblocks/linux_raid.c:155:2: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
libblkid/src/superblocks/superblocks.c:375:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libblkid/src/superblocks/xfs.c:141:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libsmartcols/src/table.c:333:24: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libsmartcols/src/table.c:344:25: warning: signed and unsigned type in conditional expression [-Wsign-compare]
libsmartcols/src/table_print.c:753:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/ask.c:364:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/utils.c:33:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/context.c:435:56: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/context.c:730:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/script.c:557:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/dos.c:1791:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
libfdisk/src/gpt.c:813:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
misc-utils/logger.c:408:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
disk-utils/partx.c:140:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
disk-utils/partx.c:551:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
disk-utils/partx.c:640:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 03:18:27 +01:00
Ruediger Meier 71177ab8f9 misc: fix warnings "unused parameter" [-Wunused-parameter]
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 03:18:24 +01:00
Ruediger Meier 63a7065b2c libfdisk: fix warnings, "redundant redeclaration" [-Wredundant-decls]
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 03:18:21 +01:00
Ruediger Meier 5fde1d9f06 tests: fix compiler warnings [-Wmissing-prototypes]
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 03:18:09 +01:00
Ruediger Meier 74272f00e1 libfdisk: fix compiler warnings [-Wmissing-prototypes]
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 01:27:34 +01:00
Ruediger Meier f3aca7ab21 libfdisk: fix missing symbol
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 01:25:41 +01:00
Ruediger Meier b0b54cc582 build-sys: always add AM_CFLAGS
We were missing our nice compliler warnings for many programs
and libs. See next commits how many trivial and non-trival
warnings have to be fixed.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 01:17:29 +01:00
Ruediger Meier b201f1d86c build-sys: always use global LDADD
This was a major showstopper when building on a system where
LTLIBINTL libs are needed (e.g. OSX). Maybe there are a few test
programs which wouldn't need LDADD ... never mind.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-23 01:16:58 +01:00
Karel Zak 45c9a3d27f Merge branch 'port-osx' of https://github.com/rudimeier/util-linux
* 'port-osx' of https://github.com/rudimeier/util-linux:
  include: fix sys/sysinfo.h
  libblkid: don't include endian.h
  lib: fix ismounted includes for FreeBSD
  lib: remove unused variable
  lsns: use xcalloc()
  include: remove unused mntent.h
  include: check for sys/sysmacros.h
  lib: define LOGIN_NAME_MAX fallback
  include: provide MAP_ANONYMOUS on OSX
  lib: rename strmode() and setmode()
  tests: fix ts_option helpers
  build-sys: fix [g]libtoolize version for OSX
  build-sys: check linker support for version scripts
  build-sys: portable usage of find command
  travis: minor cleanup
2016-02-19 11:30:53 +01:00
Karel Zak eae665f24b libfdisk: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-18 14:23:37 +01:00
Karel Zak 6cbb7371b3 libfdisk: add API to control signatures wiping
Now libfdisk warns if another filesystem/RAID/PT signature is detected
on the device. It seems better and user-friendly to make it possible to
wipe the signatures when we write a new disk label to the device.

This patch adds to the library API

	fdisk_enable_wipe()
	fdisk_has_wipe()
	fdisk_get_collision()

to control this new feature. The device modification is done by
libblkid (the same we use in some mkfs-like utils).

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-18 12:58:12 +01:00
Ruediger Meier 3719bf8de9 build-sys: check linker support for version scripts
The macro AX_CHECK_VSCRIPT was taken from gnu autoconf archive.
http://www.gnu.org/software/autoconf-archive/

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 12:53:48 +01:00
Karel Zak f4a1d26609 libfdisk: add missing break
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-09 10:04:36 +01:00
Karel Zak 300e24a8ea sfdisk: add ESP shortcut also for Legacy MBR
References: https://github.com/karelzak/util-linux/issues/267
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-08 16:37:03 +01:00
Ruediger Meier 3fd1f7711e docs: fix typos found by codespell
Using "codespell" from https://github.com/lucasdemarchi/codespell

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-03 15:10:08 +01:00
Karel Zak d09c06baf4 sfdisk: add 'U' shortcut for ESP
echo -e ',512M,U\n,,L' | sfdisk --label gpt /dev/foo

to make ESP system partition.

References: https://github.com/karelzak/util-linux/issues/267
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-02-01 14:08:04 +01:00
Andrew Wilcox f136260aeb libfdisk: Add GPT type GUID for Itanium Linux root
References: http://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/
Signed-off-by: Andrew Wilcox <awilfox@adelielinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-12 10:35:11 +01:00
Ian Wienand 240ddd3a5f libfdisk: Detect out-of-space when adding new primary partition
I got a bit confused with the interaction below:

  Command (m for help): p
  Disk /dev/sda: 41 GiB, 43965677568 bytes, 85870464 sectors
    ...
  Device     Boot   Start      End  Sectors  Size Id Type
  /dev/sda1  *       2048  1026047  1024000  500M 83 Linux
  /dev/sda2       1026048 85868543 84842496 40.5G 8e Linux LVM

  Command (m for help): n
  To create more partitions, first replace a primary with an extended partition.

I knew I should have had two primary partitions available, but I did
not notice that the disk was seen as full (I was trying to grow it)

This change detects available primary partitions, and if so indicates
we are out of space, rather than out of partitions.

Signed-off-by: Ian Wienand <iwienand@redhat.com>
2015-10-09 13:07:41 +02:00
Karel Zak 7020de0be8 lib/crc32: don't require to modify GPT header
This patch introduces smart crc32 function that is able to exclude
specified. The advantage is that we does not have to modify GPT header
(set the current in-header crc field to zero) when we count crc32.

This allows to keep GPT header in read-only buffers and simplify code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-24 09:26:42 +02:00
Karel Zak 83677b99cb libfdisk: fix partition move/resize code
- verify that the new partition fits to the area if the size of the
  has not been modified
- fix remaining space calculation (yes, brown-paper-bag bug..)
- offer also space before first partition as free space

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-17 13:22:11 +02:00
Karel Zak f2be8b3dfc libfdisk: add more debug message to resize code
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-17 12:04:23 +02:00
Karel Zak c949fa98d8 libfdisk: (gpt) control ranges in set_partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-17 11:44:08 +02:00
Karel Zak dd49c7d6d6 libfdisk: (gpt) reorder only when necessary
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-02 14:51:00 +02:00
Karel Zak 5cea5be05f libfdisk: (bsd) add note about non-written parental MBR
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-31 13:24:33 +02:00
Yuri Chornoivan 75a8e726e9 Fix trivial typos 2015-08-25 20:02:53 +03:00
Karel Zak e820595b81 libfdisk: (gpt) fix label pointer usage [smatch scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 12:59:16 +02:00
Karel Zak 06fb6eabeb libfdisk: remove impossible condition [smatch scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 12:55:30 +02:00
Karel Zak 1c736ff38b libfdisk: make context->label usage more robust [smatch scan] 2015-08-05 12:54:49 +02:00
Karel Zak 2c6567799d build-sys: add --disable-assert
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 13:40:44 +02:00
Karel Zak 1c3c92cd8d libfdisk: cleanup assert() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 13:03:14 +02:00
Karel Zak df15fb3d05 libfdisk: allow to change partition type for extended partitions
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1248115
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-30 12:55:56 +02:00
Karel Zak 129fe4f31b libfdisk: result of operation is garbage or undefined [clang analyze]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-29 14:04:17 +02:00
Karel Zak 30ca5e70ce libfdisk: undefined or garbage value returned to caller [clang analyze]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-29 14:01:40 +02:00
Karel Zak 8c14a7434c libfdisk: add comment to the header file
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-24 11:18:11 +02:00
Karel Zak 4bd02cdfdf libfdisk: fix fdisk_label_parse_parttype() for unknown types
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-15 15:42:22 +02:00
Karel Zak 5aa8d13b13 libfdisk: (gpt) add missing GUIDs
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-15 15:02:13 +02:00
Scott Moser b8d07d9bec libfdisk: add GPT GUIDs for PReP
Power Firmware (OFW) scans chosen devices for PReP partition IDs.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
2015-07-15 14:38:03 +02:00
Karel Zak 5adcb6c77f libfdisk: (gpt) fix "MidnightBSD UFS" UUID
Reported-by: Андрей Гаврилин <gaal.dev@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-15 14:29:53 +02:00
Karel Zak 4b7248c029 libfdisk: add GPT GUIDs for ARMs
Addresses: https://github.com/karelzak/util-linux/issues/203
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-22 11:56:43 +02:00
Karel Zak acb7651f88 libfdisk: ignore misaligned optimal I/O size
For example:

 # modprobe scsi_debug dev_size_mb=1000 opt_blks=65535 physblk_exp=3

creates a disk with:

 Sector size (logical/physical): 512 bytes / 4096 bytes
 I/O size (minimum/optimal): 4096 bytes / 33553920 bytes

where 33553920 % 4096 != 0, it means that use Optimal I/O size to
align partition results that partition is not aligned to physical
sector boundary.

Reported-by: Tom Yan <tom.ty89@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-18 11:55:29 +02:00
Karel Zak 3c7fde5f92 libfdisk: add JSON dump output
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-15 13:18:09 +02:00
Karel Zak 0baeca2aef libfdisk: rename script functions to improve readability
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-15 10:38:47 +02:00
Karel Zak 5989556ad3 libfdisk: add new API to read label specific data
* removes list() label operation from internal API

  The list() has been based on fdisk_info() it was useless for
  anything else than print on stdout...

* add a new get_item() label operation and fdisk_get_disklabel_item() public API

  The new API provides abstract and pretty simple way how to get label
  specific disk label information, for example

     fdisk_get_disklabel_item(cxt, GPT_LABELITEM_ENTRIESLBA, &iterm);

  return LBA of the array with GPT entries.

  Note that this patch does not implement public functions to get
  data from the @item object.

* removes get_id() label operation -- it's subset of the new get_item()

* the new internal API is also used to implement backwardly compatible
  fdisk_list_disklabel() and fdisk_get_disklabel_id()

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-11 14:19:47 +02:00
Karel Zak 535748a617 libfdisk: (dos) fix cylinders calculation
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-10 16:55:29 +02:00
Karel Zak 8c73e5096d fdisk: differentiate between +<sector> and +<size>{M,G,...}
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-10 13:06:15 +02:00
Karel Zak 7c43fd23ce libfdisk: improve +0 partition size
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-08 17:26:31 +02:00
Karel Zak 09a4ca5e45 libfdisk: (dos) fix tiny partitions calculation
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-08 16:45:15 +02:00
Karel Zak 765004f3eb libfdisk: (gpt) make it possible to create really small partitions
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-08 16:02:17 +02:00
Karel Zak 68a8648ce5 libfdisk: support alignment to non power of 2
Let's create a disk with 33553920 bytes optimal I/O size:

	# modprobe scsi_debug dev_size_mb=1000 opt_blks=65535

and try to create partition:

	 echo -e 'n\n\n\n\n+512M\np\nq\n'  | fdisk /dev/sdc

old version:

	 Device     Boot Start     End Sectors  Size Id Type
	 /dev/sdc1       65535 1114110 1048576  512M 83 Linux

The next partition will be expected on sector 1114110 + 1, but it's
not aligned to optimal I/O:

        ((1114110 + 1) * 512) % 33553920 = 8192

fixed version:

 Device     Boot Start     End Sectors  Size Id Type
 /dev/sdc1       65535 1114094 1048560  512M 83 Linux

        ((1114094 + 1) * 512) % 33553920 = 0

Note that the same problem with alignment calculation has been fixed
in Linux kernel by commit b8839b8c55f3fdd60dc36abcda7e0266aff7985c
(Oct 2014).

The patch also improves fdisk_align_lba_in_range() to not align sizes
smaller than grain (default 1MiB) to make it possible to create really
small partitions.

Reported-by: Tom Yan <tom.ty89@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-08 15:57:23 +02:00
Karel Zak d5dbd57b22 docs: fix gtk-docs related warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-28 12:28:23 +02:00
Stanislav Brabec 97c68d4204 libfdisk: Use predictable /dev/mapper partition names for /dev/dm-N
It is impossible to predict /dev/dm-N partition names. Use predictable
and better readable /dev/mapper names instead.

[kzak@redhat.com: - remove if-before-free]

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-28 10:25:58 +02:00
Stanislav Brabec 8b5940be96 Use correct partition names for /dev/mapper
The default configuration of multipath-tools appends "-partN" to
partition nodes. Follow this conventions and do the same.

It fixes for example fdisk -l /dev/mapper/name_of_the_device.

Note that the current implementation only partially fixes the problem. It
does not reflect any udev configuration changes, as udev does not provide
any function to return names of future (or current) partitions of a
particular device. It also does not fix fdisk -l /dev/dm-0.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2015-05-26 11:42:38 +02:00
Karel Zak c1be496a93 libfdisk: keep FDISK_FIELD_CYLINDERS independent on context mode
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-11 13:01:26 +02:00
Karel Zak 31ea7fa6d4 libfdisk: add fdisk_label_get_fields_ids_all()
The current fdisk_label_get_fields_ids() is too smart as it
differentiate between details mode etc. It's useful for default
output, but in some cases it's better to provide all output fields.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-11 12:42:24 +02:00
Ruediger Meier 159652d937 libfdisk: (gpt) fix attributes endianess
The new libfdisk/gpt test (4a4a0927) discovered that we read and write
partition attributes wrongly on BE systems.

Our temporarily used char[8] bits are always LE and do not need to be
converted.

CC: Michael Marineau <michael.marineau@coreos.com>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2015-05-11 10:51:15 +02:00
Michael Marineau 4a4a0927c6 libfdisk: (gpt) add API for raw partition attributes
The existing APIs can only toggle individual bits or get and set bits in
a complex text representation, making it impractical to use libfdisk for
manipulating the GPT partition attribute field in more complex ways such
as updating a value that is multiple bits wide. For example priority
based partition selection originally designed for ChromeOS includes two
integer values that are 4-bits wide.

http://www.chromium.org/chromium-os/chromiumos-design-docs/disk-format#TOC-Trusting-the-GPT

[kzak@redhat.com: - add new symbols to .sym file and docs
                  - remove unused variables from test program]

Signed-off-by: Michael Marineau <michael.marineau@coreos.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-05 12:39:36 +02:00
Michael Marineau c6bf5c094d libfdisk: (gpt) fix check for beginning of protective partition
Search for the protective partition before attempting to validate that
it covers the GPT header. Some hybrid MBRs list partitions out of order.
For example, CoreOS images ship with a hybrid MBR that lists the boot
partition first and the protective partition second in order to maintain
compatibility with old versions of Xen's PV-GRUB.

Signed-off-by: Michael Marineau <michael.marineau@coreos.com>
2015-05-05 12:28:52 +02:00
Karel Zak 9d9a1b8760 libfdisk: (gpt) add extra check for First/Last LBA
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-23 12:32:36 +02:00
Karel Zak 7678505292 libfdisk: (gpt) fix end sector calculation on resize
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-23 11:34:05 +02:00
Karel Zak a7c27ff297 libfdisk: fix scriptk parser to support alone signs
for example echo "- - - *" | sfdisk /dev/sda1 -N1

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-22 17:14:28 +02:00
Karel Zak 339ca8416c libfdisk: allow to move start to first usable LBA
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-22 17:13:48 +02:00
Karel Zak 8cf10fd08d libfdisk: add warning to resize function
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-22 12:21:19 +02:00
Karel Zak 98e15beb61 libfdisk: support resize operation in fdisk_set_partition()
Note that the resize is not exported by API yet, the only way to use
it is sfdisk-like scripts.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-22 12:21:19 +02:00
Karel Zak b17c1f1447 libfdisk: add fdisk_table_get_partition_by_partno()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-22 12:21:19 +02:00
Karel Zak 6f16392937 libfdisk: fix script parser to support resize operations
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-22 12:21:19 +02:00
Karel Zak ee105ed6f3 libfdisk: don't resize in label drivers
The resize operation has to be implemented on upper layer.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-22 12:21:19 +02:00
Karel Zak 43a2b09426 libfdisk: (gpt) fix LE usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-22 11:52:24 +02:00
Karel Zak 3457d90e30 libfdisk: support bootbits protection from (p)MBR
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-13 13:40:25 +02:00
Karel Zak 4d156d92eb libfdisk: (dos) retain existing boot flag when resizing a partition
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1210912
Signed-off-by: Karel Zak <kzak@redhat.com>
Co-Author:  awilliam@redhat.com
2015-04-13 10:29:00 +02:00
Karel Zak 7298680365 libfdisk: don't return empty strings from fdisk_partition_to_string()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-27 13:47:13 +01:00
Karel Zak 5cdbe36fbc libfdisk: add fgets() callback for scripts
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-25 16:05:14 +01:00
Karel Zak 310399cafe libfdisk: fix symbols versioning script
Really stupid copy & past mistake. The libfdisk symbols should not be
prefixed by MOUNT_ suffix.

This change makes binaries linked with libfdisk 2.26 incompatible with
new libfdisk. Fortunately, 2.26 has been the first release and very
probably the library has been used for util-linux fdisks only.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-25 11:32:00 +01:00
Karel Zak 9c6f3de60f libfdisk: (gpt) check header size before verify CRC
Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=780834
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-23 12:03:30 +01:00
Karel Zak b7c67e6414 libfdisk: add {first,last}-lba header to sfdisk scritps
The current sfdisk does not allow to create partition that
starts before the default libfdisk First LBA (~1MiB). It
means that

 # sfdisk --dump /dev/sda > foo
 # sfdisk /dev/sdb < foo

does not work on systems where 1st partition does not start at offset
2048.

This patch add new headers to scripts to inform libfdisk about different
First/Last LBA ranges. For example:

 label: gpt
 first-lba: 34

allows to override the library default.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-02 13:58:23 +01:00
Karel Zak 0be901e535 libfdisk: fix fdisk_partition_get_parent() docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-19 12:37:23 +01:00
Karel Zak 4863ddaddf libfdisk: add some docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-10 13:17:29 +01:00
Karel Zak fbec8d9fad libfdisk: ignore whole-disk partition when check order
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-10 13:00:52 +01:00
Karel Zak 943271e214 libfdisk: add fdisk_partition_is_wholedisk()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-10 13:00:30 +01:00
Karel Zak 9992324409 libfdisk: fix compiler warning
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-06 10:34:06 +01:00
Karel Zak c603d076f8 libfdisk: make code more readable
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-06 10:24:18 +01:00
Karel Zak d527d2dd64 libfdisk: grain is in bytes, fix previous patches
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-03 13:44:16 +01:00
Benno Schulenberg 33b981f757 libfdisk: (dos) make a helpful message fit within 80 characters
Also add a hint for translators.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-02-03 13:25:27 +01:00
Karel Zak 68fe4b2822 libfdisk: don't align very small partitions
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-03 13:20:45 +01:00
Karel Zak 1bb387bdbd libfdisk: fix issues with very small partitions
- cfdisk: minimal partitions size is 1 sector
 - dos: when align last sector then don't set partition size to zero
   for very small partitions.
 - don't ignore tiny partitions before free space when define
   free-space start offset
 - improve some debug messages

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-03 12:44:00 +01:00
Karel Zak 3d919d9583 libfdisk: (dos) write new empty label too
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-03 12:03:12 +01:00
Karel Zak eed0e7b9bc libfdisk: (dos) fix logical partitions errors handling
The current code in add_partition() de-increment number of partitions
on error when logical partition requested and add_logical() does the
same. The result is mess in partitions array.

The another fixed issue is that add_logical() is called if all primary
partitions are already used although 'pa->start' (the template) is
explicitly defined outside the extended partition. The right behavior
is to end with error message.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-02 12:20:44 +01:00
Benno Schulenberg dc45b86e14 libfdisk: actually translate the human-readable name of the partition type
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-02-02 10:57:07 +01:00
Karel Zak 625d00fefb libfdisk: (dos) delete also logical with extended
deleting an extended partition with cfdisk leaves its contained
partitions in existence

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-02 10:38:05 +01:00
Karel Zak edc4cf94a8 libfdisk: make fdisk_partition_to_string() more robust [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-29 10:49:51 +01:00
Karel Zak 4044d24468 libfdisk: (gpt) check return from GUID parser [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-28 15:10:15 +01:00
Karel Zak 9c321dfbf0 libfdisk: fix possible mem leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-28 15:05:14 +01:00
Karel Zak bf031d89ea libfdisk: support unknown partition types in sfdisk scripts
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1183234
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-28 09:57:03 +01:00
Karel Zak 9bbcf43f88 libfdisk: don't use off_t in public API
It's better to use exact and explicitly defined types (e.g. uint64_t)
rather than something like off_t to make code more portable.

[reported with gcc (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3)]

The patch also fixes one debug message.

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-26 12:26:00 +01:00
Benno Schulenberg 54fefa078e textual: fix spellos and inconsistencies in several program messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-26 11:17:55 +01:00
Karel Zak ce9f568c25 libfdisk: accept Start offset in {B,M,G..}iB in sfdisk scripts
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-20 14:20:47 +01:00
Karel Zak a473657eac libfdisk: (docs) fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-20 10:34:19 +01:00
Karel Zak 4a79a8f177 libfdisk: make label names case insensitive
and support 'MBR' as alias to 'DOS'.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-19 12:25:37 +01:00
Karel Zak 354f8cc8cf libfdiskL add API to print SIZE field in bytes
The patch also add --bytes to fdisk and fdisk.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-19 11:24:48 +01:00
Karel Zak 791da22d0e libfdisk: add version.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-13 13:46:31 +01:00
Karel Zak dee59a1ee6 libfdisk: fix some typos
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-13 13:46:09 +01:00
Karel Zak 2b6c532e17 docs: update API docs years
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-13 12:03:17 +01:00
Karel Zak 0c07055c39 libfdisk: cleanup gtk-docs warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-13 11:45:19 +01:00
Karel Zak 4bb82a4554 libfdisk: (gpt) cleanup header size usage
Kay reported that Windows 8.1 installed does not recognize GPT created
by libfdisk, but parted works as expected.

It seems (according to the header hexdump) that the problem is
HeaderSize GPT field where libfdisk uses 512 (header + reserved area),
but parted uses 92. The both is pretty valid according to the current
EFI standard, but 92 is probably more backwardly compatible.

I also found places in code where libfdisk gpt driver is inconsistent
and uses sometimes all sector and simetimes sizeof(gpt_header) only.
The right solution is to read all sector (into zeroized memory) and
later write again all sector to the device.

Reported-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-09 13:05:49 +01:00
Sami Kerola 7ee26cbf02 maint: fix shadow declaration
This change fixes all shadow declarations.  The worth while to mention
fix is with libfdisk sun geometry.  It comes from bitops.h cpu_to_be16
macro that further expands from include/bits/byteswap.h that has the
shadowing.

libfdisk/src/sun.c:961:173: warning: declaration of '__v' shadows a previous local [-Wshadow]
libfdisk/src/sun.c:961:69: warning: shadowed declaration is here [-Wshadow]
libfdisk/src/sun.c:961:178: warning: declaration of '__x' shadows a previous local [-Wshadow]
libfdisk/src/sun.c:961:74: warning: shadowed declaration is here [-Wshadow]

That could have caused earlier some unexpected results.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-07 10:08:21 +01:00
Karel Zak 764b697c56 libfdisk: fix bug in cmp_numbers() and partitions sorting
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-04 13:06:03 +01:00
Karel Zak bbfc24298f libfdisk: remove 'end' from struct fdisk_partition
This struct member duplicate "start+size".

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-04 12:24:31 +01:00
Karel Zak 0073a4cff2 libfdisk: rename sector_t to fdisk_sector_t
.. just to avoid too generic names for public API.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-04 11:41:51 +01:00
Karel Zak 19ff8ff7c4 libfdisk: fix cfdisk freespace analyze
The problem is how fdisk_partition_cmp_start() compare numbers, the
function returns result from "a->start - b->start", unfortunately the
numbers are uint64, but function returns "int".

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-04 10:27:39 +01:00
Karel Zak 705854f307 libfdisk: add API docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-26 19:13:57 +01:00
Karel Zak a1ef792fda libfdisk: rename and move function
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-26 17:33:07 +01:00
Karel Zak ed79557e1d build-sys: add fdisk.pc
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-26 13:20:16 +01:00
Karel Zak c820e3ffcf build-sys: add fdiskP.h to sources
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-26 12:51:32 +01:00
Karel Zak 0bb4c979c6 build-sys: create a regular shared libfdisk.so
- symbols versioning
- SONAME from configure.ac
- library version to header file
- modify build-sys to compile and install shared lib

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-26 12:45:24 +01:00
Karel Zak a78dba34a4 libfdisk: add comments to header file
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-26 11:55:45 +01:00
Karel Zak 77e46d1c06 libfdisk: add docs for SGI functions 2014-11-26 11:45:00 +01:00
Karel Zak fd979f5be7 libfdisk: add docs for SUN functions 2014-11-26 11:34:57 +01:00
Karel Zak 4e76cecd6f libfdisk: cleanup fdisk_partition_to_string() comment 2014-11-26 11:26:31 +01:00
Karel Zak 0e679d79e2 libfdisk: fix typo 2014-11-26 11:23:27 +01:00
Karel Zak 7ab7af7578 libfdisk: add docs for iterator 2014-11-26 11:21:16 +01:00
Karel Zak 5d54d9f55b libfdisk: add docs for init functions 2014-11-26 11:13:11 +01:00
Karel Zak 0077e7cd95 libfdisk: add docs for GPT functions 2014-11-26 11:11:19 +01:00
Karel Zak b7d101a20d libfdisk: add docs for DOS functions 2014-11-26 11:00:43 +01:00
Karel Zak a4e6a45e54 libfdisk: add docs for BSD functions 2014-11-26 10:28:37 +01:00
Karel Zak 1c01e44f15 libfdisk: cleanup ask API, add comments
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-25 14:36:50 +01:00
Karel Zak 0477369af4 libfdisk: remove flags from fdisk_ask API
We don't use it for anything usable, lets kill this over-engineering.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-21 15:31:55 +01:00
Karel Zak a3d834888e libfdisk: add ref.counting to ask API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-21 11:03:08 +01:00
Karel Zak 3c5ee57cd3 agetty: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-21 09:42:23 +01:00
Karel Zak 9146a00823 ibfdisk: (gpt) allow to maximize partition
enlarge second partition:

	# echo ',+' | ./sfdisk -N2 /dev/sdb
	...
	Disk /dev/sdb: 100 MiB, 104857600 bytes, 204800 sectors

	Old situation:
	Device     Start   End Sectors Size Type
	/dev/sdb1   2048 22527   20480  10M Linux filesystem
	/dev/sdb2  22528 43007   20480  10M Linux filesystem

	New situation:
	Device     Start    End Sectors Size Type
	/dev/sdb1   2048  22527   20480  10M Linux filesystem
	/dev/sdb2  22528 204766  182239  89M Linux filesystem

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-20 13:28:41 +01:00
Karel Zak 333c376138 libfdisk: (dos) allow to maximize partition
The struct fdisk_partition has special flag "end_follow_default" to
make the partition large as much as possible. This patch makes this
flag usable for fdisk_set_partition() function.

Command line example (enlarge the first partition):

	# echo ',+' | ./sfdisk -N1 /dev/sdb
	...
	Disk /dev/sdb: 100 MiB, 104857600 bytes, 204800 sectors
	...
	Old situation:
	Device     Boot Start   End Sectors Size Id Type
	/dev/sdb1        2048 22527   20480  10M 83 Linux
			      ^^^^^
	New situation:
	Device     Boot Start    End Sectors Size Id Type
	/dev/sdb1        2048 204799  202752  99M 83 Linux
			      ^^^^^^

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-20 13:11:38 +01:00
Gabriele Giacone 96f7a117b3 libfdisk: fix partition names on GNU Hurd. 2014-11-18 02:13:22 +01:00
Boris Egorov 44374b10d1 libfdisk: fix get_partition_unused_primary()
Was:
Mentioned function returns -1 if adding of primary partition is
impossible. Caller treats this value as size_t (res variable) and then
compares it for negative values, totally ignoring errors.

Becomes:
Now function takes address to variable and fills it with partition
number. Caller treats return value as int and use it appropriately.

[kzak@redhat.com: - don't mix return code and partno at all]

Signed-off-by: Boris Egorov <egorov@linux.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-14 10:02:00 +01:00
Karel Zak d0bdf18434 libfdisk: (dos) be sure that sorted EBR list is terminated
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-13 14:37:05 +01:00
Karel Zak 2248aaf98f libfdisk: fix table_add_freespace(), add debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-13 14:17:47 +01:00
Karel Zak 6237329972 libfdisk: fix script parser, add debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-12 10:34:13 +01:00
Karel Zak 4a4616b22e libfdisk: (gpt) don't offer first sector before the first partion
The GPT first usable LBA is usually aligned to grain (1MiB), but for small
(<=4MiB) devices we strictly follow sector sizes.

In this case there is a small space in front of the aligned begin of
the first partition. This useless space should not be offered for the
next partitions.

	Sector size (logical/physical): 512 bytes / 4096 bytes
	I/O size (minimum/optimal): 4096 bytes / 32768 bytes
	Disklabel type: gpt
	Disk identifier: 041E2D54-AD0C-4C7E-A50D-363D23058D47

	Device    Start          End Size Type
	/dev/sdb1    40         2087   1M Linux filesystem

	Command (m for help): n
	Partition number (2-128, default 2):
	First sector (34-8158, default 2088):
                      ^^

first usable LBA is 34, but first aligned (recommended) LBA is 40, we
use it for the first partition. All this is correct, but the space
before the first partition should be ignored. Fixed version:

        Command (m for help): n
	Partition number (2-128, default 2):
	First sector (2088-8158, default 2088):
                      ^^^^

Note this problem does not exist for "normal" (large) devices where
first usable LBA is aligned to grain.

Reported-by: Boaz Harrosh <boaz@plexistor.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-10 14:01:09 +01:00
Karel Zak 8ccfcf70da libfdisk: (gpt) make mode more readable
* use check_ prefix for checking functions
* use plural in function names where we work with more partitions than one
* always use "ents" when when we work with gpt entries array

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-10 12:22:55 +01:00
Samuel Thibault a56b70f8ff libfdisk: fdisk_read_firstsector should seek to offset 0
The current offset of cxt->dev_fd may not be still 0, notably when
blkdev_get_size has to resort to using blkdev_find_size

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org
2014-11-10 11:57:50 +01:00
Karel Zak 4dcea32061 libfdisk: clean up debug, add help debug mask
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-03 13:13:32 +01:00
Karel Zak 819d9a2975 include/debug: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-24 11:19:23 +02:00
Karel Zak 7190b9b2ce libfdisk: add more comments
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-16 13:15:06 +02:00
Karel Zak dfc6db2a35 libfdisk: cleanup parttype API
* add reference counting
 * add functions to set allocated types

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-15 14:10:25 +02:00
Karel Zak 0123bd1a87 libfdisk: cleanup partno API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-15 13:06:23 +02:00
Karel Zak ecf40cda76 libfdisk: make it possible to use zero for size and start
The zero may be valid size and start of the partition. This patch
introduces:

	fdisk_partition_has_start()
	fdisk_partition_has_size()
	fdisk_partition_unset_size()
	fdisk_partition_unset_start()

to make it possible to work with zero. The feature is internally
implemented by magic constant ((type) -1) for undefined sizes and
offsets.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-15 12:17:40 +02:00
Karel Zak 150d98ee3f libfdisk: (dos) set partition start/size only when requested 2014-10-14 19:46:17 +02:00
Karel Zak 13633a81df libfdisk: cleanup context devname usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-14 17:59:41 +02:00
Karel Zak 0c344037f0 libfdisk: (gpt) fix N-1 error for partition size
The same bug like on dos.c, the limits for the "last sector" dialog
are already with "-1".

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-14 17:26:27 +02:00