Commit Graph

467 Commits

Author SHA1 Message Date
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