Commit Graph

27 Commits

Author SHA1 Message Date
Davidlohr Bueso 8254c3a594 fdisk: api: propagate add partitions to users
Similarly to commit 1f5eb51b79 we
do not propagate problems when adding partitions to user visible
api.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-11-30 13:48:27 +01:00
Davidlohr Bueso ff5775bd4f fdisk: api: move disklabel type to cxt
Get rid of it as a global variable as it belongs in the context.
To compare a disklabel on the device, the fdisk_dev_is_disklabel()
function is introduced. Also, to avoid naming issues, the fdisk_labeltype
members where renamed to FDISK_DISKLABEL_<type>.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-11-30 13:48:19 +01:00
Karel Zak 21770662c3 fdisk: don't fails silently if EBR is outside of disk
Reported-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-11-30 11:54:10 +01:00
Davidlohr Bueso 1f5eb51b79 fdisk: api: propagate partition deletion to users
The generic fdisk_delete_partition() function returns 0 when a partition
is correctly deleted, otherwise it's corresponding error (negative values).
This, however, does not include problems that can occur in actual label
specific contexts, so we need to propagate the corresponding return code,
back to the user visible api.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-10-18 12:15:33 +02:00
Davidlohr Bueso 766d5156c4 fdisk: add GPT support
This patch allows fdisk to handle GUID partition tables, based on the latest UEFI specifications
version 2.3.1, from June 27th, 2012. The following operations are supported:

  - Probing (detects both protective and hybrid MBRs)
  - Writing to disk
  - Listing used partitions
  - Adding partitions
  - Deleting partitions
  - Data integrity verifications (for both headers and partitions).

A few considerations:
  - Currently we do not fix invalid primary headers -- we just abort!
  - Header checksums are updated upon every change (ie: add/delete partitions), this allows us
    to mathematically verify the changes on-the-fly, and not only when writing to disk, like
    most other related tools do.
  - We are extremly picky when writing to disk, any error aborts the opeartion.
  - When creating a new partition, the following GUIDs are available:
     http://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs

For test cases, the gpt.img from libblkid tests, scsi_debug and my own hard drive (/dev/sda) were used.
For the image, all operations were tested successfully, and for /dev/sda all except write, which
was not tested - hey, I'm not suicidal!

[kzak@redhat.com: - add get/set partition type functions
                  - use unified on strings based table for partition types
                  - add partition type to table list function]

Tested-and-reviewed-by: Petr Uzel <petr.uzel@suse.cz>
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-27 13:38:14 +02:00
Karel Zak ed470672bb fdisk: use fdisk_parttype in add_partition
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-27 13:38:13 +02:00
Karel Zak 02460b8aae fdisk: add fdisk_set_partition_type()
- remove all label specific partition type stuff from fdisk.c to
   label files
 - add new fdisk_set_partition_type() to API

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-27 13:38:13 +02:00
Karel Zak 010186f2a2 fdisk: add fdisk_get_partition_type()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-27 13:38:13 +02:00
Karel Zak 559d921eda fdisk: add new functions for work with fdisk_parttype
- add flags to fdisk_parttype to store more information about the types
 - function for conversion from code to fdisk_parttype
 - function for conversion from string to fdisk_parttype
 - function for conversion from user input to fdisk_parttype
 - support for unknown complex types (e.g. unknown UUIDs)

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-27 13:38:13 +02:00
Karel Zak 7b575fcc3b fdisk: improve list partition types
- add fdisk_parttype->typestr for types like GPT UUID or Mac
 - list typestr if specified

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-27 13:38:13 +02:00
Karel Zak 749af4b609 fdisk: move partition types to label specific part
- move MBR partition types to dos_part_types.h
 - make dos_part_types.h independent on datetypes to keep it useful in
   all fdisks
 - add struct fdisk_parrtype
 - move label specific partition types to context->label

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-27 13:38:13 +02:00
Davidlohr Bueso c0bf8e97dd fdisk: fix menu
Commit 79c8a145dd changed the numerical values of
fdisk_labeltype and broke the menu functionality, mixing main and expert menus.
Revert this change along with the label comment regarding it matching labeltype.

This is no longer valid since the original patch that lead to this modification
assumed that __probe_labels() would use these indices when creating a default
DOS/SUN disklabel, see http://www.spinics.net/lists/util-linux-ng/msg06509.html

Reported-by: Petr Uzel <petr.uzel@suse.cz>
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-07-26 17:25:41 +02:00
Petr Uzel b29ce87ba4 fdisk: make grain global variable part of fdisk_context()
There is no reason for this to be global variable - it belongs
to the context.

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-26 16:59:35 +02:00
Karel Zak 685fe42e12 fdisk: remove unused variables
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-24 10:52:09 +02:00
Davidlohr Bueso 639f1d56b9 fdisk: API: add fdisk_label_change
[kzak@redhat.com: - rename function
                  - remove fdisk_create_default_disklabel()]

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-07-24 10:31:32 +02:00
Davidlohr Bueso 2ca61a61e1 fdisk: API: add verify to label operations
[kzak@redhat.com: - rename some functions]

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-24 09:54:52 +02:00
Davidlohr Bueso 0f639e54df fdisk: API: add new partition to label operations
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-07-24 09:34:22 +02:00
Davidlohr Bueso fae7b1bcb5 fdisk: API: add write to label operations
[kzak@redhat.com: - rename functions
                  - use errno]

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-07-24 09:13:59 +02:00
Davidlohr Bueso 61c4cb8530 fdisk: API: add delete partition to label operations
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-23 18:15:57 +02:00
Davidlohr Bueso 79c8a145dd fdisk: API: add to label operations to context
The context structure is the fdisk API's main data type as it keeps all data
together. Add the label structure to it, so that the pt-specific operations can
be called from the context.

[kzak@redhat.com: - merge with latest changes
                  - don't allocate the label, use const pointer]

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-07-23 17:31:06 +02:00
Karel Zak 67987b4734 fdisk: rename cxt->mbr buffer to cxt->firstsector
MBR is regular name for DOS partition table, let use less confusing
name for the buffer.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-23 14:24:25 +02:00
Karel Zak 6718834075 fdisk: move label specific stuff to fdiskdoslabel.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-23 14:07:35 +02:00
Karel Zak 9a5e29e94b fdisk: move DOS geometry code from generic part to label specific
get_partition_table_geometry() should be called from DOS code

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-23 13:57:58 +02:00
Karel Zak a71601af27 fdisk: get_boot() has to die (step I.)
- move generic stuff around "create disklabel" operation to API

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-23 10:56:06 +02:00
Karel Zak 759d093fae fdisk: move user geometry setting from fdisk.c to API
- to avoid duplicate code
 - to remove fdisk_geom_set_cyls() from API

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-23 10:11:08 +02:00
Davidlohr Bueso b8855c868f fdisk: API: add label probing functionality
This patch sets the initial layout for label specific operations. A
new fdisk_label structure is created that will hold all these ops,
like new, delete, write and probe, among others. For now only probing
is implemented. Once this design is established, a copy of the probed
label will be copied to the main context structure, where calling the
specific functions will save 'disklabel' checks. Debugging support is
added as well.

This patch passes regression tests and manually passes bsd, sun, dos
and sgi labels probes.

Reviewed-by: Petr Uzel <petr.uzel@suse.cz>
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2012-07-16 17:59:52 +02:00
Karel Zak 50ea679509 build-sys: rename fdisk -> fdisks/, convert to module
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-26 20:50:53 +02:00