Part

Part — plugin for operations with partition tables

Functions

Types and Values

Includes

#include <part.h>

Description

A plugin for operations with partition tables. Currently supported table (disk label) types are MBR and GPT. See the functions below to get an overview of which operations are supported. If there's anything missing, please don't hesitate to report it as this plugin (just like all the others) is subject to future development and enhancements.

This particular implementation of the part plugin uses libfdisk for manipulations of both the MBR and GPT disk label types.

Functions

bd_part_init ()

gboolean
bd_part_init (void);

Initializes the plugin. **This function is called automatically by the library's initialization functions.**


bd_part_close ()

void
bd_part_close (void);

Cleans up after the plugin. **This function is called automatically by the library's functions that unload it.**


bd_part_create_table ()

gboolean
bd_part_create_table (const gchar *disk,
                      BDPartTableType type,
                      gboolean ignore_existing,
                      GError **error);

Parameters

disk

path of the disk block device to create partition table on

 

type

type of the partition table to create

 

ignore_existing

whether to ignore/overwrite the existing table or not (reports an error if FALSE and there's some table on disk )

 

error

place to store error (if any).

[out][optional]

Returns

whether the partition table was successfully created or not

Tech category: BD_PART_TECH_MODE_CREATE_TABLE + the tech according to type


bd_part_create_part ()

BDPartSpec *
bd_part_create_part (const gchar *disk,
                     BDPartTypeReq type,
                     guint64 start,
                     guint64 size,
                     BDPartAlign align,
                     GError **error);

Parameters

disk

disk to create partition on

 

type

type of the partition to create (if BD_PART_TYPE_REQ_NEXT, the partition type will be determined automatically based on the existing partitions)

 

start

where the partition should start (i.e. offset from the disk start)

 

size

desired size of the partition (if 0, a max-sized partition is created)

 

align

alignment to use for the partition

 

error

place to store error (if any).

[out][optional]

Returns

specification of the created partition or NULL in case of error

NOTE: The resulting partition may start at a different position than given by start and can have different size than size due to alignment.

Tech category: BD_PART_TECH_MODE_MODIFY_TABLE + the tech according to the partition table type.

[transfer full]


bd_part_delete_part ()

gboolean
bd_part_delete_part (const gchar *disk,
                     const gchar *part,
                     GError **error);

Parameters

disk

disk to remove the partition from

 

part

partition to remove

 

error

place to store error (if any).

[out][optional]

Returns

whether the part partition was successfully deleted from disk

Tech category: BD_PART_TECH_MODE_MODIFY_TABLE + the tech according to the partition table type


bd_part_resize_part ()

gboolean
bd_part_resize_part (const gchar *disk,
                     const gchar *part,
                     guint64 size,
                     BDPartAlign align,
                     GError **error);

Parameters

disk

disk containing the partition

 

part

partition to resize

 

size

new partition size, 0 for maximal size

 

align

alignment to use for the partition end

 

error

place to store error (if any).

[out][optional]

Returns

whether the part partition was successfully resized on disk to size

NOTE: The resulting partition may be slightly bigger than requested due to alignment.

Tech category: BD_PART_TECH_MODE_MODIFY_TABLE + the tech according to the partition table type


bd_part_get_disk_parts ()

BDPartSpec **
bd_part_get_disk_parts (const gchar *disk,
                        GError **error);

Parameters

disk

disk to get information about partitions for

 

error

place to store error (if any).

[out][optional]

Returns

specs of the partitions from disk or NULL in case of error

Tech category: BD_PART_TECH_MODE_QUERY_TABLE + the tech according to the partition table type.

[transfer full][array zero-terminated=1]


bd_part_get_part_spec ()

BDPartSpec *
bd_part_get_part_spec (const gchar *disk,
                       const gchar *part,
                       GError **error);

Parameters

disk

disk to remove the partition from

 

part

partition to get spec for

 

error

place to store error (if any).

[out][optional]

Returns

spec of the part partition from disk or NULL in case of error

Tech category: BD_PART_TECH_MODE_QUERY_PART + the tech according to the partition table type.

[transfer full]


bd_part_spec_copy ()

BDPartSpec *
bd_part_spec_copy (BDPartSpec *data);

bd_part_spec_free ()

void
bd_part_spec_free (BDPartSpec *data);

bd_part_spec_get_type ()

GType
bd_part_spec_get_type ();

bd_part_get_part_table_type_str ()

const gchar *
bd_part_get_part_table_type_str (BDPartTableType type,
                                 GError **error);

Parameters

type

table type to get string representation for

 

error

place to store error (if any).

[out][optional]

Returns

string representation of table_type

Tech category: the tech according to type .

[transfer none]


bd_part_get_type_str ()

const gchar *
bd_part_get_type_str (BDPartType type,
                      GError **error);

Parameters

type

type to get string representation for

 

error

place to store error (if any).

[out][optional]

Returns

string representation of type

Tech category: always available.

[transfer none]


bd_part_get_best_free_region ()

BDPartSpec *
bd_part_get_best_free_region (const gchar *disk,
                              BDPartType type,
                              guint64 size,
                              GError **error);

Parameters

disk

disk to get the best free region for

 

type

type of the partition that is planned to be added

 

size

size of the partition to be added

 

error

place to store error (if any).

[out][optional]

Returns

spec of the best free region on disk for a new partition of type type with the size of size or NULL if there is none such region or if there was an error (error gets populated)

Note: For the type BD_PART_TYPE_NORMAL, the smallest possible space that *is not* in an extended partition is found. For the type BD_PART_TYPE_LOGICAL, the smallest possible space that *is* in an extended partition is found. For BD_PART_TYPE_EXTENDED, the biggest possible space is found as long as there is no other extended partition (there can only be one).

Tech category: BD_PART_TECH_MODE_QUERY_TABLE + the tech according to the partition table type.

[transfer full]


bd_part_get_disk_free_regions ()

BDPartSpec **
bd_part_get_disk_free_regions (const gchar *disk,
                               GError **error);

Parameters

disk

disk to get free regions for

 

error

place to store error (if any).

[out][optional]

Returns

specs of the free regions from disk or NULL in case of error

Tech category: BD_PART_TECH_MODE_QUERY_TABLE + the tech according to the partition table type.

[transfer full][array zero-terminated=1]


bd_part_get_disk_spec ()

BDPartDiskSpec *
bd_part_get_disk_spec (const gchar *disk,
                       GError **error);

Parameters

disk

disk to get information about

 

error

place to store error (if any).

[out][optional]

Returns

information about the given disk or NULL (in case of error)

Tech category: BD_PART_TECH_MODE_QUERY_TABLE + the tech according to the partition table type.

[transfer full]


bd_part_get_part_by_pos ()

BDPartSpec *
bd_part_get_part_by_pos (const gchar *disk,
                         guint64 position,
                         GError **error);

Parameters

disk

disk to remove the partition from

 

position

position (in bytes) determining the partition

 

error

place to store error (if any).

[out][optional]

Returns

spec of the partition from disk spanning over the position or NULL if no such partition exists or in case of error (error is set)

Tech category: BD_PART_TECH_MODE_QUERY_PART + the tech according to the partition table type.

[transfer full]


bd_part_set_part_name ()

gboolean
bd_part_set_part_name (const gchar *disk,
                       const gchar *part,
                       const gchar *name,
                       GError **error);

Parameters

disk

device the partition belongs to

 

part

partition the name should be set for

 

name

name to set

 

error

place to store error (if any).

[out][optional]

Returns

whether the name was successfully set or not

Tech category: BD_PART_TECH_GPT-BD_PART_TECH_MODE_MODIFY_PART


bd_part_set_part_type ()

gboolean
bd_part_set_part_type (const gchar *disk,
                       const gchar *part,
                       const gchar *type_guid,
                       GError **error);

Parameters

disk

device the partition belongs to

 

part

partition the type should be set for

 

type_guid

GUID of the type

 

error

place to store error (if any).

[out][optional]

Returns

whether the type_guid type was successfully set for part or not

Tech category: BD_PART_TECH_GPT-BD_PART_TECH_MODE_MODIFY_PART


bd_part_set_part_id ()

gboolean
bd_part_set_part_id (const gchar *disk,
                     const gchar *part,
                     const gchar *part_id,
                     GError **error);

Parameters

disk

device the partition belongs to

 

part

partition the ID should be set for

 

part_id

partition Id

 

error

place to store error (if any).

[out][optional]

Returns

whether the part_id type was successfully set for part or not

Tech category: BD_PART_TECH_MBR-BD_PART_TECH_MODE_MODIFY_PART


bd_part_set_part_bootable ()

gboolean
bd_part_set_part_bootable (const gchar *disk,
                           const gchar *part,
                           gboolean bootable,
                           GError **error);

Parameters

disk

device the partition belongs to

 

part

partition the bootable flag should be set for

 

bootable

whether to set or unset the bootable flag

 

error

place to store error (if any).

[out][optional]

Returns

whether the bootable flag was successfully set for part or not

Tech category: BD_PART_TECH_MBR-BD_PART_TECH_MODE_MODIFY_PART


bd_part_set_part_attributes ()

gboolean
bd_part_set_part_attributes (const gchar *disk,
                             const gchar *part,
                             guint64 attrs,
                             GError **error);

Parameters

disk

device the partition belongs to

 

part

partition the attributes should be set for

 

attrs

GPT attributes to set on part

 

error

place to store error (if any).

[out][optional]

Returns

whether the attrs GPT attributes were successfully set for part or not

Tech category: BD_PART_TECH_GPT-BD_PART_TECH_MODE_MODIFY_PART


bd_part_set_part_uuid ()

gboolean
bd_part_set_part_uuid (const gchar *disk,
                       const gchar *part,
                       const gchar *uuid,
                       GError **error);

Parameters

disk

device the partition belongs to

 

part

partition the UUID should be set for

 

uuid

partition UUID to set

 

error

place to store error (if any).

[out][optional]

Returns

whether the uuid type was successfully set for part or not

Tech category: BD_PART_TECH_MODE_MODIFY_PART + the tech according to the partition table type


bd_part_error_quark ()

GQuark
bd_part_error_quark (void);

[skip]


bd_part_is_tech_avail ()

gboolean
bd_part_is_tech_avail (BDPartTech tech,
                       guint64 mode,
                       GError **error);

Parameters

tech

the queried tech

 

mode

a bit mask of queried modes of operation (BDPartTechMode) for tech

 

error

place to store error (details about why the tech -mode combination is not available).

[out][optional]

Returns

whether the tech -mode combination is available -- supported by the plugin implementation and having all the runtime dependencies available


bd_part_disk_spec_copy ()

BDPartDiskSpec *
bd_part_disk_spec_copy (BDPartDiskSpec *data);

bd_part_disk_spec_free ()

void
bd_part_disk_spec_free (BDPartDiskSpec *data);

Types and Values

BD_PART_ERROR

#define             BD_PART_ERROR

BD_PART_TYPE_SPEC

#define BD_PART_TYPE_SPEC (bd_part_spec_get_type ())

enum BDPartAlign

Members

BD_PART_ALIGN_NONE

   

BD_PART_ALIGN_MINIMAL

   

BD_PART_ALIGN_OPTIMAL

   

BDPartSpec

typedef struct {
    gchar *path;
    gchar *name;
    gchar *uuid;
    gchar *id;
    gchar *type_guid;
    guint64 type;
    guint64 start;
    guint64 size;
    gboolean bootable;
    guint64 attrs;
    gchar *type_name;
} BDPartSpec;

Members

gchar *path;

path of the partition (block device)

 

gchar *name;

name of the partition (for GPT partitions)

 

gchar *uuid;

UUID of the partition (for GPT partitions)

 

gchar *id;

id of the partition (for MSDOS partitions)

 

gchar *type_guid;

GUID of the partition's type (GPT)

 

guint64 type;

bit combination of partition's types (BDPartType)

 

guint64 start;

start of the partition

 

guint64 size;

size of the partition

 

gboolean bootable;

whether the bootable flag is set or not (for MSDOS partitions)

 

guint64 attrs;

partition GPT attributes

 

gchar *type_name;

human readable representation of type_guid

 

enum BDPartType

Members

BD_PART_TYPE_NORMAL

   

BD_PART_TYPE_LOGICAL

   

BD_PART_TYPE_EXTENDED

   

BD_PART_TYPE_FREESPACE

   

BD_PART_TYPE_METADATA

   

BD_PART_TYPE_PROTECTED

   

enum BDPartTypeReq

Members

BD_PART_TYPE_REQ_NORMAL

   

BD_PART_TYPE_REQ_LOGICAL

   

BD_PART_TYPE_REQ_EXTENDED

   

BD_PART_TYPE_REQ_NEXT

   

enum BDPartError

Members

BD_PART_ERROR_TECH_UNAVAIL

   

BD_PART_ERROR_FAIL

   

BD_PART_ERROR_INVAL

   

BD_PART_ERROR_EXISTS

   

enum BDPartTableType

Members

BD_PART_TABLE_MSDOS

   

BD_PART_TABLE_GPT

   

BD_PART_TABLE_UNDEF

   

BDPartDiskSpec

typedef struct {
    gchar *path;
    BDPartTableType table_type;
    guint64 size;
    guint64 sector_size;
} BDPartDiskSpec;

Members

gchar *path;

path of the disk (block device)

 

BDPartTableType table_type;

type of the disk's partition table

 

guint64 size;

size of the disk

 

guint64 sector_size;

disk's sector size

 

enum BDPartTech

Members

BD_PART_TECH_MBR

   

BD_PART_TECH_GPT

   

enum BDPartTechMode

Members

BD_PART_TECH_MODE_CREATE_TABLE

   

BD_PART_TECH_MODE_MODIFY_TABLE

   

BD_PART_TECH_MODE_QUERY_TABLE

   

BD_PART_TECH_MODE_MODIFY_PART

   

BD_PART_TECH_MODE_QUERY_PART