Commit Graph

789 Commits

Author SHA1 Message Date
Karel Zak 6d00cfb233 include/debug: don't print pointer address for SUID programs
* introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing

* use __UL_DEBUG_FL_NOADDR when SUID

* move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK
  to provide access to the current mask from ul_debugobj(). It's better
  than modify all ul_debugobj() calls and use the global mask as
  argument.

* remove never used UL_DEBUG_DEFINE_FLAG

Reported-by: halfdog <me@halfdog.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-12 11:01:26 +01:00
Karel Zak 9c76f85f9a libfdisk: allow to start freespace for zero
This is necessary for disk labels like SUN where whole disk is possible
to address by partitions.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-11 15:18:00 +01:00
Karel Zak f7606d2d9f libfdisk: (sun) fix n-1 bug and whole-disk
* set whole_disk variable if SUN_TAG_WHOLEDISK specified
* fix N-1 bug in add new partition according to template (script)

Addresses: https://github.com/karelzak/util-linux/issues/555
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-11 14:23:57 +01:00
Karel Zak 6ebc37854d libfdisk: (script) support R (RAID) and V (LVM) shortcuts
Addresses: https://github.com/karelzak/util-linux/issues/560
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-09 12:12:50 +01:00
Karel Zak af846e1ff9 libfdisk: (gpt) add VMware specific UUIDs
Addresses: https://github.com/karelzak/util-linux/issues/559
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-08 12:43:22 +01:00
Karel Zak 280b975475 libfdisk: (dos) fix max heads
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-02 16:50:31 +01:00
Karel Zak 2dd2880f12 libfdisk: extend API to provide label specific geometry ranges
Now fdisk provides DOS specific geometry ranges in expert menu.

Addresses: https://github.com/karelzak/util-linux/issues/556
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-02 16:43:22 +01:00
Karel Zak 760942e284 libfdisk: (gpt) use fdisk_warn() for failed name setting
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-20 12:31:10 +01:00
Vaclav Dolezal c116524184 libfdisk: return bytes processed from gpt_entry_set_name(), process rc
Made gpt_entry_set_name() return number of utf8 bytes processed on
success, so info message about change can be accurate.

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-12-19 10:48:13 +01:00
Vaclav Dolezal f069f6fe69 libfdisk: allocate enough bytes for ucs2 to utf8 encoding
Allocate 3*number_of_ucs2_characters bytes for utf8 output.

Also as we are using calloc there's no need to write terminating null
byte.

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-12-18 16:18:44 +01:00
Vaclav Dolezal 5be3df4afd libfdisk: gpt: properly encode string on rename
GPT partition name entry should be recorded as little endian UCS2, so I have
written proper conversion (assuming UTF8 input).

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-12-18 16:17:49 +01:00
Sami Kerola fcf841f8d3 misc: fix typos
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-28 14:39:13 +01:00
Mikhail Vorobyov 9e6ccaab5b libfdisk: (sun) enhance searching of free space
Potential partition start should be aligned to cylinders. So fdisk
wouldn't consider partition's last cylinder remains as eligible space
for new partition start.
2017-11-16 14:11:19 +01:00
Mikhail Vorobyov 45ce148778 libfdisk: (sun) move aligning of the first sector before availability check
So it will check a sector which would be actualy used as the first sector
of the partition.
2017-11-16 14:11:10 +01:00
Karel Zak 9a8a3b88dc libfdisk: (gpt) move backup header after device resize
Addresses: https://github.com/karelzak/util-linux/issues/532
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-14 13:51:48 +01:00
Roddy Shuler cfe4691c6f libfdisk: Fix uninitialized structure
Without this, 'sfdisk -d' with certain filenames would lead to
reading an 's' from the 'type' field in fdisk_reset_labelitem
and cause a crash due to prematurely freeing the 'data.str' field.

Signed-off-by: Roddy Shuler <roddy@endlessm.com>
2017-11-02 21:22:51 -07:00
Mikhail Vorobyov 27895be260 libfdisk: (sun) fix creation of whole disk partition
sun_add_partition() allowed the 1st sector to be 0 for the 3rd partition
only if that sector was free or if other partitions covered the whole
disk. Now it's always allowed for the 1st sector to be set to 0 for
the 3rd partition.

[kzak@redhat.com: - print info about "wholedisk" before "First sector" dialog for 3rd partition
                  - default to 0 for 3rd partition start sector]

Signed-off-by: Mikhail Vorobyov <m.vorobyov@cs.msu.ru>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-02 10:43:27 +01:00
Karel Zak e163adb83b build-sys: fix non-blkid compilation
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-19 13:48:52 +02:00
Karel Zak 9f20d80079 misc: cleanup UUID_STR_LEN definitions
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-15 13:25:32 +02:00
Philip Prindeville b443c1779e misc: replace magic number 37 with UUID_STR_LEN
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
2017-09-05 11:49:21 +02:00
Vaclav Dolezal 504c594777 libfdisk: fix fdisk_reset_partition() leaking *_chs strings.
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2017-08-24 11:23:44 +02:00
Vaclav Dolezal 5cebb2ab33 libfdisk: fix two potential memory errors.
Fixes one leak and one unchecked allocation error.

[kzak@redhat.com: - don't call fdisk_ask_menu_get_result()
                    after failed fdisk_do_ask()]

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-24 11:21:59 +02:00
Karel Zak b428eb14a8 libfdisk: improve alignment debug mesagges
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-22 15:12:36 +02:00
Karel Zak 27c284b848 libfdisk: add --grain to mkpart sample
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-22 14:59:42 +02:00
Karel Zak adf09b5c38 libfdisk: add fdisk_save_user_grain()
Let's provide API for applications that don't want to use the default
1MiB grain. The new function allow to use "as minimal as possible" if
grain is set by fdisk_save_user_grain() to 512.

If the phy sector size (or minimal I/O size) is greater than specified
grain size than smallest possible setting is used.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-22 14:55:51 +02:00
Karel Zak 980cc4a182 libfdisk: (dos) use size-=1 when alignment not used later
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-22 14:54:27 +02:00
Karel Zak 1573e95514 libfdisk: improve "add partition" debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-22 14:53:18 +02:00
Karel Zak 694a407de9 libfdisk: (gpt) fix size-1 error
If partition does not require alignment, then don't call LBA align
function and don't use size-=1 (fdisk_align_lba_in_range() returns
unmodified size and we call size=-1 more than once for the same size).

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-22 14:48:14 +02:00
Karel Zak dd3b72b3e9 libfdisk: add --nopartno to mkpart sample
* disable dialogs for the mkpart sample
* add --nopartno use-case to force libfdisk to use default partno(s)
* add test for this feature

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-08-01 13:51:27 +02:00
Karel Zak 537b4db151 libfdisk: allow to resize in unsorted partition table
The current code assumes that partition offsets (starts) are sorted.
This is usual situation, but unsorted partition table is also valid...

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-19 15:09:36 +02:00
Karel Zak 264ef9875a libfdisk: improve table print debugs
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-19 15:09:12 +02:00
Karel Zak ea36907965 libfdisk: support default partno in mkpart-fullspec sample
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-19 12:19:38 +02:00
Karel Zak 992f7cbae4 libfdisk: add fdisk_disable_dialogs()
The default (for historical reasons) is to use dialog driven partitioning.
It's possible to avoid dialogs by fdisk_partition template for
fdisk_add_partition().

Unfortunately in some case (mostly DOS driver) it's not enough, because
we need to distinguish between logical and primary partitions. If we know
that dialogs are unwanted then we can default to primary partition, etc.

This function simplify semantic of the library for non-interactive
programs.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-19 11:30:57 +02:00
Karel Zak e5e704630f libfdisk: (dos) return EINVAL when delete unused partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-19 10:34:03 +02:00
Ruediger Meier 18751601a8 libfdisk: fix warning -Wunused-function
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-07-18 11:08:28 +02:00
Ruediger Meier 21be08ac8c build-sys: don't use non-existing UUID_LIBS
We've added UUID_LIBS in f77a4d1087 but I don't see what it
was good for.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-07-18 11:06:53 +02:00
Ruediger Meier ac6a6b0d3c libfdisk: use fdisk_sector_t consistently and fix printf format strings
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-07-18 11:06:53 +02:00
Karel Zak 5ecd618511 libfdisk: use BLKPG_* ioctls on linux only
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-17 09:47:42 +02:00
Karel Zak 8ffa3b651d libfdisk: make fdisk compliant to UEFI/GPT specification on PMBR
The PMBR partition record should be StartingCHS=0x002000 (0/0/2)
and EndingCHS=0xFFFFFF (1023/255/63)

Addresses: https://github.com/karelzak/util-linux/issues/485
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 12:48:18 +02:00
Karel Zak c0eabc5382 libfdisk: remove whitespaces
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:36:22 +02:00
Karel Zak 1dd63a3b05 libfdisk: use BLKPG ioctls to inform kernel about changes
This patch introduces fdisk_reread_changes(). The function is
less invasive alternative to fdisk_reread_partition_table().

The new function uses BLKPG ioctls for modified partitions. The
another partitions are not affected. This solution allows to
successfully use fdisks on disk where some partitions are still use
(mounted). For example if you want to resize the last partition on the
device.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:34:55 +02:00
Karel Zak 0d034857f2 libfdisk: add comment
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:34:55 +02:00
Karel Zak b9da153254 libfdisk: add fdisk_device_is_used()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:34:55 +02:00
Karel Zak 2db3cc4cf3 libfdisk: remove unnecessary fstat() call
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:33:30 +02:00
Karel Zak 6a1889b03b libfdisk: move fdisk_reread_partition_table() to another file
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-14 11:33:30 +02:00
Karel Zak 288acb4eee tests: don't use errno in output
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-12 12:34:22 +02:00
Karel Zak 167d7e9537 libfdisk: (dos) accept start for log.partitions on template
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-11 14:24:32 +02:00
Karel Zak f2b6a0c0f5 libfdisk: don't hardcode label type in samples
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-11 13:27:01 +02:00
Karel Zak 5fb427c8d2 libfdisk: add sample-fdisk-mkpart-fullspec
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-11 13:00:46 +02:00
Karel Zak 2cb4754276 libfdisk: (dos) cleanup template based partitioning
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-11 12:25:02 +02:00
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