Commit Graph

511 Commits

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