Commit Graph

789 Commits

Author SHA1 Message Date
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
Karel Zak a389baf116 libfdisk: (dos) fix N-1 error for partition size
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-14 16:44:54 +02:00
Karel Zak b1c524aeed libfdisk: fix script unit test
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-14 14:46:16 +02:00
Benno Schulenberg 9ed38607d7 textual: grammarize an informative message, and tweak some comments
Also add two clarifying comments for translators.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-10-14 12:03:56 +02:00
Karel Zak 2ce7b95985 libfdisk: fix script next_token()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-10 12:53:12 +02:00
Karel Zak 2d2cb0251d libfdisk: make script header parser more pedantic
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-10 12:24:10 +02:00
Karel Zak 28d79d9b0d libfdisk: (dos) reset logical partition stuff after error
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-09 14:03:45 +02:00
Karel Zak 8f48195846 libfdisk: cleanup script dump
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-09 13:03:52 +02:00
Karel Zak bcdeacd796 libfdisk: (dos) follow explicit sizes
* this patch add to dos driver support for fdisk_partition->size_explicit
  to avoid unexpected last sector alignment for sizes explicitly specified
  in sectors

* add support for small "first LBA", the current default is to use
  1MiB offset for the first partition and for each EBR. This is not
  backwardly compatible and it makes impossible to apply sfdisk
  scripts/dumps from old systems, because original offset can be
  smaller than 2048 sectors (old sfdisk default is 1 sector).

  The solution is on the fly to detect this situation and change
  fdisk_context->first_lba to 1 sector. Nasty.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-09 12:10:36 +02:00
Karel Zak 18b266cea3 libfdisk: (gpt) follow explicit size, fiz size+1 buf
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-09 12:10:09 +02:00
Karel Zak 9b0b9fb1bf libfdisk: follow explicitly specified partition size
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-09 12:09:07 +02:00
Karel Zak 6d37c2ce9a libfdisk: add functions to play nasty games with first/last LBA
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-09 12:06:52 +02:00
Karel Zak 892c89eb76 libfdisk: allow to specify partition size by explicit number of sectors
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-09 12:02:17 +02:00
Karel Zak 0a9ac4d2f5 libfdisk: use skip_blank() in scripts
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-08 13:11:59 +02:00
Karel Zak a536cf7106 libfdisk: (dos) don't inform about logical partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-08 13:00:19 +02:00
Karel Zak 4e8ee117c4 libfdisk: consolidate script parser code
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-08 12:59:50 +02:00
Karel Zak d79634cfa8 libfdisk: fix script parser
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 15:33:18 +02:00
Karel Zak 50f7514e9d libfdisk: (dos) fix booable flag usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 15:32:09 +02:00
Karel Zak 11eee4c477 libfdisk: propagate assign-device operation to parent
Let's make it possible to use fdisk_assign_device() for nested
contexts.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:33 +02:00
Karel Zak a8a4887bcd libfdisk: fix sun and sgi to be usable from sfdisk
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:33 +02:00
Karel Zak eac3aac95b libfdisk: add fdisk_label_get_field_by_name() and const for labels
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 00665c3fe1 libfdisk: (gpt) remove 'Cylinders'
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak c77ba5316f libfdisk: (gpt) parse attr bits
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 95085ec5d6 libfdisk: (dos) use script label-id
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 9a79aa6e7a sfdisk: more update to the man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 347a7f7756 sfdisk: add --append
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak e54b1c6fcb sfdisk: be sensitive to PT limits
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak ea50ba5bf1 libfdisk: remove old label drives' API for parttypes
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 71c895fc62 libfdisk: (sgi) add set_part() API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 7f63194ac6 libfdisk: (bsd) add set_part() API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak b305ad4065 libfdisk: use new set_part API in fdisk_set_partition_type()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak a48c09853c libfdisk: (gpt) check string_to_guid()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak 2aeff7618e linfdisk: cleanup fsync usage
* always use fsync() if the device open read-write
 * use sync() on demand

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:32 +02:00
Karel Zak d151447ba1 sfdisk: make dump format usable on stdin
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 6936c081ab libfdisk: (gpt) use generic API to change UUID and name
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak b0a484a880 libfdisk: (gpt) implement fdisk_set_partition() backend
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 0ecf3ab504 libfdisk: (dos) implement fdisk_set_partition() backend
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 0dad217785 libfdisk: add fdisk_set_partition()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak e11c668449 libfdisk: cleanup internal drivers' API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 78049787a5 libfdisk: add fdisk_copy_parttype()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 2d12903265 libfdisk: make yes/no dialogs more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 3186f4a927 sfdisk: improve UI
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak d5bee4bb59 libfdisk: cleanup script size= code
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak c3bc748352 libfdisk: return partno when add new partition
* improve the way how sfdisk report results
 * the API change simplify applications

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 0051ec9bff libfdisk: fix script partitions size parsing
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak ea987bb509 libfdisk: (dos) more carefully check for primary partitions
* check if there is space for primary partitions, if no and extended
    exists then create logical partitions

  * create extended if @pa->type is extended partition

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 59c8e95b3b libfdisk: add fdisk_partition_is_bootable()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:31 +02:00
Karel Zak 152788aacb fdisk: improve --list output
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:30 +02:00
Karel Zak fdb006e8b5 fdisk: move --list functionality to separated file
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 14:55:30 +02:00
Karel Zak 60ba8c362d libfdisk: fix add_logical() assert
The zero index is absolutely valid for extended partition (it means
extended partition could be the first partition on the device).

Reported-by: Christoph Hoopmann <christophhoopmann@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-10-07 11:33:46 +02:00
Sami Kerola 1bcf491a78 textual: fix couple typos in comments
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:15 +02:00
Benno Schulenberg 8d7a6285ec textual: add a comma for clarity, plus some other tweaks
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-10-01 09:37:05 +02:00
Karel Zak 7b83dcc8a8 libfdisk: add support for sfdisk-like script format
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-09-02 13:51:32 +02:00
Karel Zak 4b43f7c96b libfdisk: (gpt) follow label-id from script
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-09-01 15:01:34 +02:00
Karel Zak 9138d6f972 libfdisk: add functions to apply partitiong scripts
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-09-01 14:44:39 +02:00
Karel Zak ee50336c03 libfdisk: (gpt) don't align last possible LBA
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-09-01 14:42:12 +02:00
Karel Zak 73b7c331b3 libfdisk: rename fdisk_dump_ to fdisk_script_
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-09-01 11:16:21 +02:00
Karel Zak 6e5e9368a0 libfdisk: fix fdisk_delete_all_partitions()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-09-01 11:14:18 +02:00
Karel Zak 3c0e6b1530 libfdisk: add fdisk_apply_table() and fdisk_delete_all_partitions()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-29 11:18:29 +02:00
Karel Zak a835add045 libfdisk: improve debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-29 09:57:51 +02:00
Karel Zak b1c5a4be93 libfdisk: accept dump with quotes
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-29 09:55:31 +02:00
Karel Zak 7bc31adac4 libfdisk: (dos) follow bootable setting when add partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-29 09:19:13 +02:00
Karel Zak 8d95e7e0e4 libfdisk: (gpt) allow to specify uuid and name when create new partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-28 14:42:55 +02:00
Karel Zak 080633e43d libfdisk: (gpt) set_{name,uuid} functions refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-28 14:16:56 +02:00
Karel Zak 62a9ef3e2f libfdisk: add reference to context to dump
* add fdisk_ref_context() function

 * context is necessary to parse label specific partition types

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-28 13:03:23 +02:00
Karel Zak c7119037f0 libfdisk: use reference counting for context
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-28 12:49:16 +02:00
Karel Zak c1ba586395 libfdisk: extend dump parsing function
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-28 12:37:46 +02:00
Karel Zak afef428f40 libfdisk: (dos) fix typo
Reported-by: https://github.com/Mikachu
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-28 10:45:58 +02:00
Karel Zak 613596b387 libfdisk: (dos) fix logical partitions add/delete code
If you delete logical partition and then create a new one than fdisk
(and cfdisk) might write EBR to the first sector on the device. That's
wrong of course; because you will lost MBR (primary partitions).

(Probably introduced by commit bcddbe9688
 where code completely clears EBR stuff.)

Reported-by: Michał Górny <mgorny@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-26 16:54:45 +02:00
Karel Zak 1d691b258e libfdisk: vary basic dump parsing functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-25 15:33:02 +02:00
Karel Zak cb4d680467 libfdisk: basic fdisk_dump_* functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-22 14:43:52 +02:00
Karel Zak 385810d22a libfdisk: remove debug dump function, cleanup API
The fdisk_dump_* prefix will be used for sfdisk-like functionality.
The patch also add FDISK_ prefix to fdisk_get_unit() options.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-22 10:25:35 +02:00
Karel Zak 6b11aad26b libfdisk: fix fdisk_get_optimal_iosize() and update tests
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-20 11:43:02 +02:00
Karel Zak 2ae3d038b9 libfdisk: move fdisk_ask_partnum() to API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-15 12:34:42 +02:00
Karel Zak 1753a234a1 libfdisk: add geometry to API, cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-15 12:16:27 +02:00
Karel Zak 4af064f3fc libfdisk: fdisk_label_is_labeltype()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-15 10:49:51 +02:00
Karel Zak 5175ae8738 libfdisk: more docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-14 21:04:01 +02:00
Karel Zak a745611d69 libfdisk: final parttype API cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-14 13:28:37 +02:00
Karel Zak 5ab3760071 libfdisk: move get_parttypes to label API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-14 12:01:38 +02:00
Karel Zak 773aae5c51 libfdisk: (gpt) allow to specify attr bit by API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-14 11:33:46 +02:00
Karel Zak 11ee1177ff libfdisk: make it possible to get fields for all labes
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-14 00:27:28 +02:00
Karel Zak 72d2965c44 libfdisk: cleanup label geometry API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-14 00:09:48 +02:00
Karel Zak aa36c2cf2c libfdisk: cleanup fdisk_is_label stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-13 23:57:54 +02:00
Karel Zak 8d605c884a libfdisk: clean up API (alignment.c)
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-13 23:27:00 +02:00
Karel Zak 6a6321360d libfdisk: clean up API (context.c)
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-13 22:26:53 +02:00
Karel Zak 03e4220d29 include/debug: cleanup masks
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-13 14:13:32 +02:00
Ondrej Oprala 14ad2353cc libs/debug: accept human readable names for _DEBUG=
For example
	$ LIBMOUNT_DEBUG=tab,cache findmnt

to debug only TAB and CACHE subsystem.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-13 12:33:47 +02:00
Karel Zak bd85d11fba libfdisk: rename fdisk_column to fdisk_field
.. to make the API and fdisk(s) code more readable.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-13 11:12:27 +02:00
Karel Zak d44115f3b5 libfdisk: remove dependence on libsmartcols
It's application business to convert libfdisk_table to string.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-13 10:10:11 +02:00
Karel Zak c9400a1ea7 fdisk: always print warning for mis-aligned partitions
This patch restores the original fdisk behavior and always prints
information about misaligned partitions in 'p'print output.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-08 11:33:28 +02:00
Sergei Antonov 210d4595de libfdisk: (gpt) add Microsoft Storage Spaces GUID
Storage Spaces is Microsoft's logical volume management.
It has been around since Windows 8.

Cc: Karel Zak <kzak@redhat.com>
Signed-off-by: Sergei Antonov <saproj@gmail.com>
2014-07-31 10:50:42 +02:00
Benno Schulenberg 09af3db48e textual: fix some typos and inconsistencies in various messages
Fixing plain typos, miswordings, inconsistent periods, some missing
angular brackets, and a proper pluralization (even when it involves
a constant, because for some languages the precise value matters).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-07-23 08:56:00 +02:00
Karel Zak bc787727d4 libfdisk: make disk sync() optional
... this allows to avoid unnecessary sync() from cfdisk.

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-15 12:32:03 +02:00
Karel Zak 2fa32bea49 Merge branch 'minor-fixes' of git://github.com/kerolasa/lelux-utiliteetit
* 'minor-fixes' of git://github.com/kerolasa/lelux-utiliteetit:
  lscpu: avoid double free
  libsmartcols: avoid variable dereference after release
  libfdisk: do not do the same thing twice in single if statement
  whereis: avoid printing uninitialized string
  setpriv: avoid alloca() use xmalloc() instead
  dmesg: avoid unnecessary variable assignment
  fdisk: avoid code duplication
  mkfs.cramfs: use defined failure name rather than magic value
  fdformat: match variable and print format types
  cfdisk: add braces to ensure operation order
  lscpu: avoid use of bzero() in favor of memset()
  setterm: remove unnecessary variable
  cal: remove unnused structure and definition
  textual: fix some typos
2014-07-14 16:03:48 +02:00
Karel Zak 7c2cfb1896 libfdisk: make first sector buffer usage more robust
$ ~/util-linux/fdisk -b 4096 xxx
	..
	Segmentation fault

The buffer has to be reinitialized always when we apply a new
device properties (e.g. sector size).

Reported-by: Bernhard Voelker <mail@bernhard-voelker.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-14 15:05:22 +02:00
Sami Kerola 99cacc6adf libfdisk: do not do the same thing twice in single if statement
The second argument was very likely meant to be 'be->offset'.
Maintainers review & sign-off will further verify this change being
correct.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-13 18:35:39 +01:00
Sami Kerola 0e65dcde88 textual: fix some typos
Found with misspell-check version 2.0d.

Reference: https://github.com/lyda/misspell-check
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-13 17:21:02 +01:00
Karel Zak 1671b2ed1a libfdisk: fix possible memory leak [clang-analyze]
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-07-01 13:36:37 +02:00
Karel Zak 11712b6667 libfdisk: (dos) count fisrt usable LBA to total number of used sectors
The check() function counts number of used sectors, but it counts only
partitions. This is mistake, the area before the first partition is
also "used" place (boot loaders or we have to align the first partition
to disk I/O limits, etc).

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-24 10:32:25 +02:00
Karel Zak 63fb717d8c libfdisk: (dos) use check() for dos-comaptible mode only
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-24 09:40:56 +02:00
Thorsten Wilmer 9bb8caff87 libfdisk: (dos) calculation of total size based on CHS in check function
Many people report a problem with the message if (cylinders <= 1024 &&
start != total) fprintf(stderr, _("Partition %d: previous sectors %d
disagrees with " "total %d\n"), n, start, total);

This message comes from the fact that the previous code caluclates the
total number of sectors in the wrong way.

The formula should be total = (real_c * heads + h) * sectors + real_s;

As a Cylinder consists of some heads * sectors A Head consists of some
sectors and finally sectors are the smallest unit

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-24 09:40:06 +02:00
Karel Zak 2c94e10b50 libfdisk: fix fdisk_context_assign_device() comment
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-09 12:09:18 +02:00
Ruediger Meier 0b166f2482 libfdisk: fix bsd_translate_fstype() for alpha
Reported-by: Tobias Klausmann <klausman@schwarzvogel.de>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-06-09 10:43:36 +02:00
Karel Zak cbebd20d26 libfdisk: (gpt) fix last LBA code for S_ISREG
Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-05-30 10:51:53 +02:00
Karel Zak 73548d6e60 libfdisk: fix %ju -> %zu
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-05-13 09:52:42 +02:00
Karel Zak c1156d8564 libfdisk: (dos) improve logical partition reorder command
- use qsort to sort by EBR offsets
 - sort by EBR data partition start sectors

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-22 21:11:03 +02:00
Karel Zak 6c64adeeb6 libfdisk: (mbr) fix logical chain termination
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-22 14:54:44 +02:00
Karel Zak 9348ef2511 libfdisk: (gpt) implement 'fix order' commnad
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-18 14:00:39 +02:00
Karel Zak dd7ba60463 libfdisk: add partitions reorder operation to label API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-18 13:26:08 +02:00
Karel Zak a60087aa32 libfdisk: fix logical partition reorder command
Reported-by: Olaf Hering <olaf@aepfle.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-18 11:48:53 +02:00
Karel Zak 8b60872ec0 libfdisk: add generic function to check partitions order
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-16 12:51:08 +02:00
Karel Zak 11fe0448a0 libfdisk: (dos) make EBR parser more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-08 10:14:12 +02:00
Karel Zak 9c7955dabe libfdisk: make qsort_r() optional
The function is no critical for fdisk functionality. The SUN label
verification will check for less issues. All the verification code is
optional ('v' fdisk command).

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-04 16:02:35 +02:00
Karel Zak 0925a9dd6c libsmartcols: clean up flags usage
* rename flags functions to scols_table_enable_*
 * rename *_no_foo() functions to _nofoo()
 * output formats are mutually exclusive, so don't use flags there
 * don't assume symbols in scols_new_table(), use scols_table_set_symbols()

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-03 16:09:57 +02:00
Karel Zak 5fd7160e83 libfdisk: fix freesapce detection for nested partitions
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-03 12:29:21 +02:00
Karel Zak c743bf744a cfdisk: clean up scols usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-03 12:29:21 +02:00
Karel Zak 7bae0563b8 libfdisk: clean up scols usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-03 12:29:21 +02:00
Ondrej Oprala baa3b270ec Use libsmartcols in libfdisk and cfdisk
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2014-04-03 12:29:18 +02:00
Karel Zak 412791a995 libfdisk: remove fdisk_colon()
It was unnecessary overkill to have colorized "foo:" prefix in fdisk
output.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-01 14:39:13 +02:00
Karel Zak e146ae4edb libfdisk: properly implement read-only mode
Don't use fallback to read-only mode in fdisk_context_assign_device(),
it's application responsibility open the device in the right mode.

The commands fdisk and cfdisk check (and report) read-only mode now.

Reported-by: Maciej Małecki <me@mmalecki.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-21 14:04:59 +01:00
Karel Zak d71bd2f0d6 libfdisk: clean up debug output
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-21 13:33:37 +01:00
Karel Zak 881410671f libfdisk: use new debug functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-21 12:35:21 +01:00
Karel Zak 9a7769141a Merge branch 'common_debug' of https://github.com/ooprala/util-linux
* 'common_debug' of https://github.com/ooprala/util-linux:
  clean up redundant macros and defines
  libfdisk: use include/debug.h
  libblkid: use include/debug.h
  libmount: further debug.h integration
  libcommon: don't mention lib versions in debug macros
  libcommon: define more debugging macros
  libmount: use macros from include/debug.h
  libcommon: add common debugging routines
2014-03-21 10:59:58 +01:00
Ondrej Oprala 274228fecc clean up redundant macros and defines
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2014-03-13 11:53:31 +01:00
Ondrej Oprala 2618b9cc1f libfdisk: use include/debug.h
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2014-03-13 11:11:27 +01:00
Karel Zak 01086b80b6 libfdisk: (gpt) use entry attributes as bitmap
* care about endianess
 * don't use by compiler packed struct with bit array for GPT
   attributes, it's more robust use it as bitmap stored in uint64_t.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-13 11:08:01 +01:00
Karel Zak 5a1b4999f7 libfdisk: update GPT partition types
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-12 13:52:01 +01:00
Benno Schulenberg 27aadd8bf6 libfdisk: avoid two compiler warnings about wrong print formats
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-03-12 12:14:34 +01:00
Karel Zak 41050b7e23 libfdisk: (bsd) fix output
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 12:33:30 +01:00
Karel Zak 8d6ec09aba libfdisk: follow requested size rather than use all available space
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 12:16:14 +01:00
Karel Zak ef97e92ba5 libfdisk: (sun) add info about whole-disk partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:15 +01:00
Karel Zak 7e241236fc libfdisk: (sgi) cleanup, add infor about whole-disk partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:15 +01:00
Karel Zak c1c58b492f libfdisk: don't count special whole-disk partitions
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:15 +01:00
Karel Zak 7aa0d52963 cfdisk: add create lebel UI
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:14 +01:00
Karel Zak 5139eca74a libfdisk: add dump functions, make freespace code generic
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:14 +01:00
Karel Zak 1b92d076ba libfdisk: (dos) consolidate partition end-offset code
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:14 +01:00
Karel Zak e77313a67d libfdisk: (dos) fix ext_index usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:14 +01:00
Karel Zak bd5e829198 libfdisk: remove label specific get_freespace
- it seems we can use improved nested<->container relationship
   rather than implement DOS specific function

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:14 +01:00
Karel Zak bcddbe9688 libfdisk: (dos) fix log.partition delete
- deallocate sector buffer and deincrement part_max when delete last
   logical partition
 - zap obsolete EBR on begin of the extended partition when no logical
   partition defined

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:14 +01:00
Karel Zak aa423fd39e libfdisk: again improve freespace code
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:14 +01:00
Karel Zak 036439315f libfdisk: improve freesapce detection
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:14 +01:00
Karel Zak a3e37fa7af libfdisk: don't ask for pri/log if wanted start within extended partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:14 +01:00
Karel Zak e5c93999e6 libfdisk: add table sort function, use it in get_freespace
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 2cec794994 libfdisk: rewrite freespace code
* use separate function to get free space
 * allow to use label-specific get_freespace() function
   (this is necessary for MBR extended partitions mess)

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 81c29a73d9 linfdisk: align free space
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 1240f549d8 libfdisk: (gpt) initialize last_lba, cleanup pa->{start,size} usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak ef7b2f1c88 libfdisk: initialize last_lba
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 732aefdf26 libfdisk: add fdisk_partition_*_follow_default()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 20f878fee3 libfdisk: add ASKTYPE_MENU and context last_lba
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 849968b9ba fdisk: fix 'p'rint error on empty PT
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 28b6a23cae libfdisk: add fdisk_table_get_partition()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 04406c0d0c libfdisk: add fdisk_table_get_nents()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 9f7fdeaf0e libfdisk: tiny clean up in fdisk_table_to_string()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak d0059a2491 libfdisk: clean up cylinder column
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 9f670072f4 libfdisk: remove tt stuff from API
The include/tt.h has to be used only internally by the library (for
example to convert fdisk_table to string).

The fdisk_ask API should not be more used for complex tasks like print
partition table. The application has to use fdisk_get_table() and
fdisk_table_to_string() or something else.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:13 +01:00
Karel Zak 6c89f750d2 libfdisk: use fdisk_table to generate output
* add generic fdisk_iter iterator
 * use fdisk_table to convert partition table to human readable output
 * clean up partition.c API (don't use reference to fdisk_context in
   fdisk_partition struct)
 * extern table.c API to use fdisk_iter iterator
 * remove old fdisk_list_partitions()

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 187de51c8a libfdisk: move partition stuff to partition.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak b48cdebcb4 libfdisk: add table container
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak d6cfa8b327 libfdisk: add reference counting to fdisk_partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 1de9fddbe5 libfdisk: add support to list free space
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 77d6a70ac4 libfdisk: use partition template
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 851515216f libfdisk: remove fdisk_get_partition_type()
Let's use more generic:

	fdisk_get_partition()
        fdisk_partition_get_parttype()

rather than fdisk_get_partition_type().

The patch also improves fdisk_get_partition() semantic to allocate
a new partition struct if the argument is NULL.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 27d4d07292 libfdisk: (sun) remove get_partition_type()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 5d660fa488 libfdisk: (sgi) remove get_partition_type()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 7f01ec7aad libfdisk: (dos) remove get_partition_type()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak a699b27de4 libfdisk: (bsd) remove get_partition_type()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 7f539277e8 libfdisk: (gpt) remove get_partition_type()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 0a2aedf0e2 libfdisk: (sun) use new list() and get_part() API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak d787618b97 libfdisk: (sgi) use new list() and get_part() API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 262002ee6f libfdisk: (dos) use new list() and get_part() API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak d6faa8e00d libfdisk: add new list() columns, cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak d48419f3a9 libfdisk: (bsd) use new get_part() API
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 82ebc7dea7 libfdisk: improve conversion to string
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 8c0a7f9136 libfdisk: add struct fdisk_partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 6941952e8d libfdisk: (gpt) use fdisk_column
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 8152753d58 libfdisk: implement generic functions for FDISK_COL_ stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak 21a44c9b84 libfdisk: extend API definition to list info about partitions
This change adds a struct fdisk_column to provide generic description
for information about partitions. The struct is used for tt tables as
well as lists of possible columns for specified label driver.

We use the same concept in all applications linked with tt.c (lsblk,
findmnt, partx, ...) where is possible to dynamically change columns,
order of the columns etc. Now it will be possible to do the same with
fdisk.

And it's also possible to use FDISK_COL_* Ids to address data, for
example:

   fdisk_partition_get_data(cxt, FDISK_COL_SIZE, 1, &data);

returns a string with human readable size (<num>{MGT}) of the second
partition.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-11 11:35:12 +01:00
Karel Zak dbf7043ea1 build-sys: don't connect _DEPENDENCIES and _LIBADD
The _DEPENDENCIES has to be used for dependencies on another in-tree
files, but _LIBADD is to specify additional libs (including external
libs).

Reported-by: oleid <notifications@github.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-05 10:20:10 +01:00
Karel Zak b37ab36eec libfdisk: (dos) warn on type 0
This is old warning, but somehow lost during rewrite to libfdisk. Sorry.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-27 22:04:10 +01:00
Karel Zak 28a5bccc47 libfdisk: (dos) fix free part counter
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-27 21:42:18 +01:00
Karel Zak 6d0ed4cb38 fdisk: (gpt) more human readable info about free space
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-25 13:18:02 +01:00
Karel Zak d0a870c5b3 fdisk: don't care about partition type
fdisk allows to overwrite existing partition if the partition has
partition type set to zero (very unusual, but possible).

This is incorrect because such partition is pretty valid (and Linux
kernel does not care about the type at all). For example:

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048       22527       10240   83  Linux
/dev/sdb2           22528      227327      102400    0  Empty
                    ^^^^^                            ^^^^^^^^

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (22528-1228799, default 22528):
                                    ^^^^^^^

.. if user follows the default then the result are overlapping
partitions:

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048       22527       10240   83  Linux
/dev/sdb2           22528      227327      102400    0  Empty
/dev/sdb3           22528     1228799      603136   83  Linux
                    ^^^^^

... and if you call "mkfs /dev/sdb3" then you lost data on sdb2. Sad
thing.

Reported-by: Marc MERLIN <marc@merlins.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-25 12:00:55 +01:00
Karel Zak 488cc17a99 fdisk: fix nasty coding style
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-25 10:58:18 +01:00
Karel Zak e41e151427 libfdisk: (sgi) generate partname according to partition position
The SGI drive currently counts only usable partitions, that's wrong as
Linux kernel counts all partition to generate partition number. For
example:

Kernel:
	sdb                                             8:16   0   600M  0 disk
	├─sdb9                                          8:25   0     2M  0 part
	└─sdb11                                         8:27   0 596.2M  0 part

Fdisk:
	Pt# Device    Info Start       End   Sectors Id System
	 9: /dev/sdb1          0      4095      4096  0 SGI volhdr
	11: /dev/sdb2          0   1220939   1220940  6 SGI volume

Reported-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-19 13:02:39 +01:00
Karel Zak 36da6b64c4 libfdisk: (sun) fix end sectors with +1 error
partx (or parted, etc.):

NR     START       END   SECTORS   SIZE NAME UUID
 1         0    410047    410048 200.2M
 2    410048  82329055  81919008  39.1G
 4  82329056 102807615  20478560   9.8G
 5 102807616 110999039   8191424   3.9G
 6 110999040 312580543 201581504  96.1G

and the same with fdisk:

     Device Flag    Start       End    Blocks   Id  System
/dev/loop0p1             0    410048    205024    1  Boot
/dev/loop0p2        410048  82329056  40959504   83  Linux native
/dev/loop0p3             0 312580544 156290272    5  Whole disk
/dev/loop0p4      82329056 102807616  10239280   83  Linux native
/dev/loop0p5     102807616 110999040   4095712   83  Linux native
/dev/loop0p6     110999040 312580544 100790752   8e  Linux LVM

Reported-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-11-01 12:15:25 +01:00
Karel Zak e49874e24c libfdisk: (gpt) add /home GUID
Reported-by: andreas.hanke@gmx-topmail.de
References: http://cgit.freedesktop.org/systemd/systemd/commit/?id=1a14a53cfded6e78c6e8dfb73fdff0039971d642
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-31 08:53:03 +01:00
Karel Zak 433d05ff9a libfdisk: (gpt) allow to work with hybrid GPT
Notes:

 * fdisk don't sync hybrid MBR with GPT
 * hybrid MBR is ignored and not overwritten by PBMR
 * users is informed about expert command 'M' to toggle between MBR
   and GPT mode. It's possible to manually modify hybrid MBR.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-23 16:59:45 +02:00
Karel Zak 45ddb828ed libfdisk: (gpt) improve and cleanup recovery code
* use AlternativeLBA rather than hardcoded offset to backup GPT
 * create gpt_copy_header()

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-23 12:06:47 +02:00
Karel Zak d2d9efa103 libfdisk: (gpt) recover from corrupted primary/backup PT
We already have all code to support this feature, unfortunately
it was not used in gpt_probe_label()...

References: https://bugzilla.redhat.com/show_bug.cgi?id=1022217
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-23 10:46:10 +02:00
Karel Zak 6e876a98ac libfdisk: warn about obsolete signatures on the device
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-23 10:46:10 +02:00
Karel Zak c83f772efd libfdisk: support extended attributes modification
* GPT attributes defined by standard (e.g. legacy boot etc.)
 * attributes (bits 48-63) reserved for GUID specific attributes (used for example
   by MS Windows)

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-23 10:46:10 +02:00
Karel Zak f736ae5117 libfdisk: (dos) be more verbose when change bootable flag
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-23 10:46:10 +02:00
Karel Zak 829f4206fc libfdisk: fix printf stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-23 10:46:10 +02:00
Karel Zak d17c584ac1 libfdisk: support nested MBR
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-23 10:45:14 +02:00
Karel Zak 68e0b7c855 libfdisk: (gpt) %ld -> %ju in verify function
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-21 13:14:04 +02:00
Karel Zak ae48894081 libfdisk: add Intel Rapid Start Technology GUID
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-18 12:05:35 +02:00
Karel Zak 243631e75e libfdisk: (bsd) leave context if new disklabel unwanted
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-16 12:03:48 +02:00
Karel Zak e39966c6a0 fdisk: fix printf stuff
Unfortunately, fdisk_warn/info/.. function was not marked by
printf __attribute__.

We don't want to break gettext stuff now, so all compiler warnings
have been fixed by casts. This is temporary solution, after release it
will be necessary to fix all the strings.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-15 12:46:35 +02:00
Karel Zak f32a9be45a libfdisk: (dos) all disklabel locate function
.. to make 'D'ump expert command usable also for MBR.

Yes, we have -rc2 now and this is a new feature, but it's tiny change
without any interaction to the rest of the code and without gettext stuff.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-15 12:21:28 +02:00
Benno Schulenberg 8321764154 textual: equalize four error messages with already existing ones
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-10-14 14:54:45 +02:00
Karel Zak 1572fb3e00 libfdisk: mark label modified for PMBR mismatch
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-10-11 11:50:10 +02:00