LCOV - code coverage report
Current view: top level - lib/plugin_apis - part.c (source / functions) Coverage Total Hit
Test: libblockdev Coverage Report Lines: 53.8 % 286 154
Test Date: 2026-01-23 09:12:16 Functions: 51.1 % 47 24
Legend: Lines: hit not hit

            Line data    Source code
       1           24 : GQuark  bd_part_error_quark (void) {
       2           24 :         return g_quark_from_static_string ("g-bd-part-error-quark");
       3              : }
       4              : 
       5              : /**
       6              :  * BDPartSpec:
       7              :  * @path: path of the partition (block device)
       8              :  * @name: name of the partition (for GPT partitions)
       9              :  * @uuid: UUID of the partition (for GPT partitions)
      10              :  * @id: id of the partition (for MSDOS partitions)
      11              :  * @type_guid: GUID of the partition's type (GPT)
      12              :  * @type: bit combination of partition's types (#BDPartType)
      13              :  * @start: start of the partition
      14              :  * @size: size of the partition
      15              :  * @bootable: whether the bootable flag is set or not (for MSDOS partitions)
      16              :  * @attrs: partition GPT attributes
      17              :  * @type_name: human readable representation of @type_guid
      18              :  */
      19            0 : BDPartSpec* bd_part_spec_copy (BDPartSpec *data) {
      20            0 :         if (data == NULL)
      21            0 :         return NULL;
      22              : 
      23            0 :     BDPartSpec *ret = g_new0 (BDPartSpec, 1);
      24              : 
      25            0 :     ret->path = g_strdup (data->path);
      26            0 :     ret->name = g_strdup (data->name);
      27            0 :     ret->uuid = g_strdup (data->uuid);
      28            0 :     ret->id = g_strdup (data->id);
      29            0 :     ret->type_guid = g_strdup (data->type_guid);
      30            0 :     ret->type_name = g_strdup (data->type_name);
      31            0 :     ret->type = data->type;
      32            0 :     ret->start = data->start;
      33            0 :     ret->size = data->size;
      34            0 :     ret->bootable = data->bootable;
      35            0 :     ret->attrs = data->attrs;
      36              : 
      37            0 :     return ret;
      38              : }
      39              : 
      40          358 : void  bd_part_spec_free (BDPartSpec *data) {
      41          358 :         if (data == NULL)
      42            0 :         return;
      43              : 
      44          358 :     g_free (data->path);
      45          358 :     g_free (data->name);
      46          358 :     g_free (data->uuid);
      47          358 :     g_free (data->id);
      48          358 :     g_free (data->type_guid);
      49          358 :     g_free (data->type_name);
      50          358 :     g_free (data);
      51              : }
      52              : 
      53          828 : GType  bd_part_spec_get_type () {
      54              :         static GType type = 0;
      55              : 
      56          828 :     if (G_UNLIKELY(type == 0)) {
      57            1 :         type = g_boxed_type_register_static("BDPartSpec",
      58              :                                             (GBoxedCopyFunc) bd_part_spec_copy,
      59              :                                             (GBoxedFreeFunc) bd_part_spec_free);
      60              :     }
      61              : 
      62          828 :     return type;
      63              : }
      64              : 
      65              : /**
      66              :  * BDPartDiskSpec:
      67              :  * @path: path of the disk (block device)
      68              :  * @table_type: type of the disk's partition table
      69              :  * @size: size of the disk
      70              :  * @sector_size: disk's sector size
      71              :  */
      72            0 : BDPartDiskSpec* bd_part_disk_spec_copy (BDPartDiskSpec *data) {
      73            0 :         if (data == NULL)
      74            0 :         return NULL;
      75              : 
      76            0 :     BDPartDiskSpec *ret = g_new0 (BDPartDiskSpec, 1);
      77              : 
      78            0 :     ret->path = g_strdup (data->path);
      79            0 :     ret->table_type = data->table_type;
      80            0 :     ret->size = data->size;
      81            0 :     ret->sector_size = data->sector_size;
      82              : 
      83            0 :     return ret;
      84              : }
      85              : 
      86            6 : void  bd_part_disk_spec_free (BDPartDiskSpec *data) {
      87            6 :         if (data == NULL)
      88            0 :         return;
      89              : 
      90            6 :     g_free (data->path);
      91            6 :     g_free (data);
      92              : }
      93              : 
      94           27 : GType  bd_part_disk_spec_get_type () {
      95              :         static GType type = 0;
      96              : 
      97           27 :     if (G_UNLIKELY(type == 0)) {
      98            1 :         type = g_boxed_type_register_static("BDPartDiskSpec",
      99              :                                             (GBoxedCopyFunc) bd_part_disk_spec_copy,
     100              :                                             (GBoxedFreeFunc) bd_part_disk_spec_free);
     101              :     }
     102              : 
     103           27 :     return type;
     104              : }
     105              : 
     106            0 : static gboolean  bd_part_is_tech_avail_stub (BDPartTech tech G_GNUC_UNUSED, guint64 mode G_GNUC_UNUSED, GError **error) {
     107            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_is_tech_avail' called, but not implemented!");
     108            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     109              :                 "The function 'bd_part_is_tech_avail' called, but not implemented!");
     110            0 :     return FALSE;
     111              : }
     112              : 
     113              : static gboolean  (*_bd_part_is_tech_avail) (BDPartTech tech, guint64 mode, GError **error) = bd_part_is_tech_avail_stub;
     114              : 
     115              : /**
     116              :  * bd_part_is_tech_avail:
     117              :  * @tech: the queried tech
     118              :  * @mode: a bit mask of queried modes of operation (#BDPartTechMode) for @tech
     119              :  * @error: (out) (optional): place to store error (details about why the @tech-@mode combination is not available)
     120              :  *
     121              :  * Returns: whether the @tech-@mode combination is available -- supported by the
     122              :  *          plugin implementation and having all the runtime dependencies available
     123              :  */
     124            0 : gboolean  bd_part_is_tech_avail (BDPartTech tech, guint64 mode, GError **error) {
     125            0 :     return _bd_part_is_tech_avail (tech, mode, error);
     126              : }
     127              : 
     128              : 
     129            0 : static gboolean  bd_part_create_table_stub (const gchar *disk G_GNUC_UNUSED, BDPartTableType type G_GNUC_UNUSED, gboolean ignore_existing G_GNUC_UNUSED, GError **error) {
     130            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_create_table' called, but not implemented!");
     131            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     132              :                 "The function 'bd_part_create_table' called, but not implemented!");
     133            0 :     return FALSE;
     134              : }
     135              : 
     136              : static gboolean  (*_bd_part_create_table) (const gchar *disk, BDPartTableType type, gboolean ignore_existing, GError **error) = bd_part_create_table_stub;
     137              : 
     138              : /**
     139              :  * bd_part_create_table:
     140              :  * @disk: path of the disk block device to create partition table on
     141              :  * @type: type of the partition table to create
     142              :  * @ignore_existing: whether to ignore/overwrite the existing table or not
     143              :  *                   (reports an error if %FALSE and there's some table on @disk)
     144              :  * @error: (out) (optional): place to store error (if any)
     145              :  *
     146              :  * Returns: whether the partition table was successfully created or not
     147              :  *
     148              :  * Tech category: %BD_PART_TECH_MODE_CREATE_TABLE + the tech according to @type
     149              :  */
     150           50 : gboolean  bd_part_create_table (const gchar *disk, BDPartTableType type, gboolean ignore_existing, GError **error) {
     151           50 :     return _bd_part_create_table (disk, type, ignore_existing, error);
     152              : }
     153              : 
     154              : 
     155            0 : static BDPartSpec* bd_part_get_part_spec_stub (const gchar *disk G_GNUC_UNUSED, const gchar *part G_GNUC_UNUSED, GError **error) {
     156            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_get_part_spec' called, but not implemented!");
     157            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     158              :                 "The function 'bd_part_get_part_spec' called, but not implemented!");
     159            0 :     return NULL;
     160              : }
     161              : 
     162              : static BDPartSpec* (*_bd_part_get_part_spec) (const gchar *disk, const gchar *part, GError **error) = bd_part_get_part_spec_stub;
     163              : 
     164              : /**
     165              :  * bd_part_get_part_spec:
     166              :  * @disk: disk to remove the partition from
     167              :  * @part: partition to get spec for
     168              :  * @error: (out) (optional): place to store error (if any)
     169              :  *
     170              :  * Returns: (transfer full): spec of the @part partition from @disk or %NULL in case of error
     171              :  *
     172              :  * Tech category: %BD_PART_TECH_MODE_QUERY_PART + the tech according to the partition table type
     173              :  */
     174          114 : BDPartSpec* bd_part_get_part_spec (const gchar *disk, const gchar *part, GError **error) {
     175          114 :     return _bd_part_get_part_spec (disk, part, error);
     176              : }
     177              : 
     178              : 
     179            0 : static BDPartSpec* bd_part_get_part_by_pos_stub (const gchar *disk G_GNUC_UNUSED, guint64 position G_GNUC_UNUSED, GError **error) {
     180            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_get_part_by_pos' called, but not implemented!");
     181            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     182              :                 "The function 'bd_part_get_part_by_pos' called, but not implemented!");
     183            0 :     return NULL;
     184              : }
     185              : 
     186              : static BDPartSpec* (*_bd_part_get_part_by_pos) (const gchar *disk, guint64 position, GError **error) = bd_part_get_part_by_pos_stub;
     187              : 
     188              : /**
     189              :  * bd_part_get_part_by_pos:
     190              :  * @disk: disk to remove the partition from
     191              :  * @position: position (in bytes) determining the partition
     192              :  * @error: (out) (optional): place to store error (if any)
     193              :  *
     194              :  * Returns: (transfer full): spec of the partition from @disk spanning over the @position or %NULL if no such
     195              :  *          partition exists or in case of error (@error is set)
     196              :  *
     197              :  * Tech category: %BD_PART_TECH_MODE_QUERY_PART + the tech according to the partition table type
     198              :  */
     199           12 : BDPartSpec* bd_part_get_part_by_pos (const gchar *disk, guint64 position, GError **error) {
     200           12 :     return _bd_part_get_part_by_pos (disk, position, error);
     201              : }
     202              : 
     203              : 
     204            0 : static BDPartDiskSpec* bd_part_get_disk_spec_stub (const gchar *disk G_GNUC_UNUSED, GError **error) {
     205            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_get_disk_spec' called, but not implemented!");
     206            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     207              :                 "The function 'bd_part_get_disk_spec' called, but not implemented!");
     208            0 :     return NULL;
     209              : }
     210              : 
     211              : static BDPartDiskSpec* (*_bd_part_get_disk_spec) (const gchar *disk, GError **error) = bd_part_get_disk_spec_stub;
     212              : 
     213              : /**
     214              :  * bd_part_get_disk_spec:
     215              :  * @disk: disk to get information about
     216              :  * @error: (out) (optional): place to store error (if any)
     217              :  *
     218              :  * Returns: (transfer full): information about the given @disk or %NULL (in case of error)
     219              :  *
     220              :  * Tech category: %BD_PART_TECH_MODE_QUERY_TABLE + the tech according to the partition table type
     221              :  */
     222            8 : BDPartDiskSpec* bd_part_get_disk_spec (const gchar *disk, GError **error) {
     223            8 :     return _bd_part_get_disk_spec (disk, error);
     224              : }
     225              : 
     226              : 
     227            0 : static BDPartSpec** bd_part_get_disk_parts_stub (const gchar *disk G_GNUC_UNUSED, GError **error) {
     228            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_get_disk_parts' called, but not implemented!");
     229            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     230              :                 "The function 'bd_part_get_disk_parts' called, but not implemented!");
     231            0 :     return NULL;
     232              : }
     233              : 
     234              : static BDPartSpec** (*_bd_part_get_disk_parts) (const gchar *disk, GError **error) = bd_part_get_disk_parts_stub;
     235              : 
     236              : /**
     237              :  * bd_part_get_disk_parts:
     238              :  * @disk: disk to get information about partitions for
     239              :  * @error: (out) (optional): place to store error (if any)
     240              :  *
     241              :  * Returns: (transfer full) (array zero-terminated=1): specs of the partitions from @disk or %NULL in case of error
     242              :  *
     243              :  * Tech category: %BD_PART_TECH_MODE_QUERY_TABLE + the tech according to the partition table type
     244              :  */
     245            9 : BDPartSpec** bd_part_get_disk_parts (const gchar *disk, GError **error) {
     246            9 :     return _bd_part_get_disk_parts (disk, error);
     247              : }
     248              : 
     249              : 
     250            0 : static BDPartSpec** bd_part_get_disk_free_regions_stub (const gchar *disk G_GNUC_UNUSED, GError **error) {
     251            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_get_disk_free_regions' called, but not implemented!");
     252            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     253              :                 "The function 'bd_part_get_disk_free_regions' called, but not implemented!");
     254            0 :     return NULL;
     255              : }
     256              : 
     257              : static BDPartSpec** (*_bd_part_get_disk_free_regions) (const gchar *disk, GError **error) = bd_part_get_disk_free_regions_stub;
     258              : 
     259              : /**
     260              :  * bd_part_get_disk_free_regions:
     261              :  * @disk: disk to get free regions for
     262              :  * @error: (out) (optional): place to store error (if any)
     263              :  *
     264              :  * Returns: (transfer full) (array zero-terminated=1): specs of the free regions from @disk or %NULL in case of error
     265              :  *
     266              :  * Tech category: %BD_PART_TECH_MODE_QUERY_TABLE + the tech according to the partition table type
     267              :  */
     268           11 : BDPartSpec** bd_part_get_disk_free_regions (const gchar *disk, GError **error) {
     269           11 :     return _bd_part_get_disk_free_regions (disk, error);
     270              : }
     271              : 
     272              : 
     273            0 : static BDPartSpec* bd_part_get_best_free_region_stub (const gchar *disk G_GNUC_UNUSED, BDPartType type G_GNUC_UNUSED, guint64 size G_GNUC_UNUSED, GError **error) {
     274            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_get_best_free_region' called, but not implemented!");
     275            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     276              :                 "The function 'bd_part_get_best_free_region' called, but not implemented!");
     277            0 :     return NULL;
     278              : }
     279              : 
     280              : static BDPartSpec* (*_bd_part_get_best_free_region) (const gchar *disk, BDPartType type, guint64 size, GError **error) = bd_part_get_best_free_region_stub;
     281              : 
     282              : /**
     283              :  * bd_part_get_best_free_region:
     284              :  * @disk: disk to get the best free region for
     285              :  * @type: type of the partition that is planned to be added
     286              :  * @size: size of the partition to be added
     287              :  * @error: (out) (optional): place to store error (if any)
     288              :  *
     289              :  * Returns: (transfer full): spec of the best free region on @disk for a new partition of type @type
     290              :  *                           with the size of @size or %NULL if there is none such region or if
     291              :  *                           there was an error (@error gets populated)
     292              :  *
     293              :  * Note: For the @type %BD_PART_TYPE_NORMAL, the smallest possible space that *is not* in an extended partition
     294              :  *       is found. For the @type %BD_PART_TYPE_LOGICAL, the smallest possible space that *is* in an extended
     295              :  *       partition is found. For %BD_PART_TYPE_EXTENDED, the biggest possible space is found as long as there
     296              :  *       is no other extended partition (there can only be one).
     297              :  *
     298              :  * Tech category: %BD_PART_TECH_MODE_QUERY_TABLE + the tech according to the partition table type
     299              :  */
     300            7 : BDPartSpec* bd_part_get_best_free_region (const gchar *disk, BDPartType type, guint64 size, GError **error) {
     301            7 :     return _bd_part_get_best_free_region (disk, type, size, error);
     302              : }
     303              : 
     304              : 
     305            0 : static BDPartSpec* bd_part_create_part_stub (const gchar *disk G_GNUC_UNUSED, BDPartTypeReq type G_GNUC_UNUSED, guint64 start G_GNUC_UNUSED, guint64 size G_GNUC_UNUSED, BDPartAlign align G_GNUC_UNUSED, GError **error) {
     306            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_create_part' called, but not implemented!");
     307            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     308              :                 "The function 'bd_part_create_part' called, but not implemented!");
     309            0 :     return NULL;
     310              : }
     311              : 
     312              : static BDPartSpec* (*_bd_part_create_part) (const gchar *disk, BDPartTypeReq type, guint64 start, guint64 size, BDPartAlign align, GError **error) = bd_part_create_part_stub;
     313              : 
     314              : /**
     315              :  * bd_part_create_part:
     316              :  * @disk: disk to create partition on
     317              :  * @type: type of the partition to create (if %BD_PART_TYPE_REQ_NEXT, the
     318              :  *        partition type will be determined automatically based on the existing
     319              :  *        partitions)
     320              :  * @start: where the partition should start (i.e. offset from the disk start)
     321              :  * @size: desired size of the partition (if 0, a max-sized partition is created)
     322              :  * @align: alignment to use for the partition
     323              :  * @error: (out) (optional): place to store error (if any)
     324              :  *
     325              :  * Returns: (transfer full): specification of the created partition or %NULL in case of error
     326              :  *
     327              :  * NOTE: The resulting partition may start at a different position than given by
     328              :  *       @start and can have different size than @size due to alignment.
     329              :  *
     330              :  * Tech category: %BD_PART_TECH_MODE_MODIFY_TABLE + the tech according to the partition table type
     331              :  */
     332           82 : BDPartSpec* bd_part_create_part (const gchar *disk, BDPartTypeReq type, guint64 start, guint64 size, BDPartAlign align, GError **error) {
     333           82 :     return _bd_part_create_part (disk, type, start, size, align, error);
     334              : }
     335              : 
     336              : 
     337            0 : static gboolean  bd_part_delete_part_stub (const gchar *disk G_GNUC_UNUSED, const gchar *part G_GNUC_UNUSED, GError **error) {
     338            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_delete_part' called, but not implemented!");
     339            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     340              :                 "The function 'bd_part_delete_part' called, but not implemented!");
     341            0 :     return FALSE;
     342              : }
     343              : 
     344              : static gboolean  (*_bd_part_delete_part) (const gchar *disk, const gchar *part, GError **error) = bd_part_delete_part_stub;
     345              : 
     346              : /**
     347              :  * bd_part_delete_part:
     348              :  * @disk: disk to remove the partition from
     349              :  * @part: partition to remove
     350              :  * @error: (out) (optional): place to store error (if any)
     351              :  *
     352              :  * Returns: whether the @part partition was successfully deleted from @disk
     353              :  *
     354              :  * Tech category: %BD_PART_TECH_MODE_MODIFY_TABLE + the tech according to the partition table type
     355              :  */
     356            5 : gboolean  bd_part_delete_part (const gchar *disk, const gchar *part, GError **error) {
     357            5 :     return _bd_part_delete_part (disk, part, error);
     358              : }
     359              : 
     360              : 
     361            0 : static gboolean  bd_part_resize_part_stub (const gchar *disk G_GNUC_UNUSED, const gchar *part G_GNUC_UNUSED, guint64 size G_GNUC_UNUSED, BDPartAlign align G_GNUC_UNUSED, GError **error) {
     362            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_resize_part' called, but not implemented!");
     363            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     364              :                 "The function 'bd_part_resize_part' called, but not implemented!");
     365            0 :     return FALSE;
     366              : }
     367              : 
     368              : static gboolean  (*_bd_part_resize_part) (const gchar *disk, const gchar *part, guint64 size, BDPartAlign align, GError **error) = bd_part_resize_part_stub;
     369              : 
     370              : /**
     371              :  * bd_part_resize_part:
     372              :  * @disk: disk containing the partition
     373              :  * @part: partition to resize
     374              :  * @size: new partition size, 0 for maximal size
     375              :  * @align: alignment to use for the partition end
     376              :  * @error: (out) (optional): place to store error (if any)
     377              :  *
     378              :  * Returns: whether the @part partition was successfully resized on @disk to @size
     379              :  *
     380              :  * NOTE: The resulting partition may be slightly bigger than requested due to alignment.
     381              :  *
     382              :  * Tech category: %BD_PART_TECH_MODE_MODIFY_TABLE + the tech according to the partition table type
     383              :  */
     384           26 : gboolean  bd_part_resize_part (const gchar *disk, const gchar *part, guint64 size, BDPartAlign align, GError **error) {
     385           26 :     return _bd_part_resize_part (disk, part, size, align, error);
     386              : }
     387              : 
     388              : 
     389            0 : static gboolean  bd_part_set_part_name_stub (const gchar *disk G_GNUC_UNUSED, const gchar *part G_GNUC_UNUSED, const gchar *name G_GNUC_UNUSED, GError **error) {
     390            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_set_part_name' called, but not implemented!");
     391            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     392              :                 "The function 'bd_part_set_part_name' called, but not implemented!");
     393            0 :     return FALSE;
     394              : }
     395              : 
     396              : static gboolean  (*_bd_part_set_part_name) (const gchar *disk, const gchar *part, const gchar *name, GError **error) = bd_part_set_part_name_stub;
     397              : 
     398              : /**
     399              :  * bd_part_set_part_name:
     400              :  * @disk: device the partition belongs to
     401              :  * @part: partition the name should be set for
     402              :  * @name: name to set
     403              :  * @error: (out) (optional): place to store error (if any)
     404              :  *
     405              :  * Returns: whether the name was successfully set or not
     406              :  *
     407              :  * Tech category: %BD_PART_TECH_GPT-%BD_PART_TECH_MODE_MODIFY_PART
     408              :  */
     409            4 : gboolean  bd_part_set_part_name (const gchar *disk, const gchar *part, const gchar *name, GError **error) {
     410            4 :     return _bd_part_set_part_name (disk, part, name, error);
     411              : }
     412              : 
     413              : 
     414            0 : static gboolean  bd_part_set_part_type_stub (const gchar *disk G_GNUC_UNUSED, const gchar *part G_GNUC_UNUSED, const gchar *type_guid G_GNUC_UNUSED, GError **error) {
     415            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_set_part_type' called, but not implemented!");
     416            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     417              :                 "The function 'bd_part_set_part_type' called, but not implemented!");
     418            0 :     return FALSE;
     419              : }
     420              : 
     421              : static gboolean  (*_bd_part_set_part_type) (const gchar *disk, const gchar *part, const gchar *type_guid, GError **error) = bd_part_set_part_type_stub;
     422              : 
     423              : /**
     424              :  * bd_part_set_part_type:
     425              :  * @disk: device the partition belongs to
     426              :  * @part: partition the type should be set for
     427              :  * @type_guid: GUID of the type
     428              :  * @error: (out) (optional): place to store error (if any)
     429              :  *
     430              :  * Returns: whether the @type_guid type was successfully set for @part or not
     431              :  *
     432              :  * Tech category: %BD_PART_TECH_GPT-%BD_PART_TECH_MODE_MODIFY_PART
     433              :  */
     434            4 : gboolean  bd_part_set_part_type (const gchar *disk, const gchar *part, const gchar *type_guid, GError **error) {
     435            4 :     return _bd_part_set_part_type (disk, part, type_guid, error);
     436              : }
     437              : 
     438              : 
     439            0 : static gboolean  bd_part_set_part_id_stub (const gchar *disk G_GNUC_UNUSED, const gchar *part G_GNUC_UNUSED, const gchar *part_id G_GNUC_UNUSED, GError **error) {
     440            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_set_part_id' called, but not implemented!");
     441            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     442              :                 "The function 'bd_part_set_part_id' called, but not implemented!");
     443            0 :     return FALSE;
     444              : }
     445              : 
     446              : static gboolean  (*_bd_part_set_part_id) (const gchar *disk, const gchar *part, const gchar *part_id, GError **error) = bd_part_set_part_id_stub;
     447              : 
     448              : /**
     449              :  * bd_part_set_part_id:
     450              :  * @disk: device the partition belongs to
     451              :  * @part: partition the ID should be set for
     452              :  * @part_id: partition Id
     453              :  * @error: (out) (optional): place to store error (if any)
     454              :  *
     455              :  * Returns: whether the @part_id type was successfully set for @part or not
     456              :  *
     457              :  * Tech category: %BD_PART_TECH_MBR-%BD_PART_TECH_MODE_MODIFY_PART
     458              :  */
     459            2 : gboolean  bd_part_set_part_id (const gchar *disk, const gchar *part, const gchar *part_id, GError **error) {
     460            2 :     return _bd_part_set_part_id (disk, part, part_id, error);
     461              : }
     462              : 
     463              : 
     464            0 : static gboolean  bd_part_set_part_uuid_stub (const gchar *disk G_GNUC_UNUSED, const gchar *part G_GNUC_UNUSED, const gchar *uuid G_GNUC_UNUSED, GError **error) {
     465            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_set_part_uuid' called, but not implemented!");
     466            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     467              :                 "The function 'bd_part_set_part_uuid' called, but not implemented!");
     468            0 :     return FALSE;
     469              : }
     470              : 
     471              : static gboolean  (*_bd_part_set_part_uuid) (const gchar *disk, const gchar *part, const gchar *uuid, GError **error) = bd_part_set_part_uuid_stub;
     472              : 
     473              : /**
     474              :  * bd_part_set_part_uuid:
     475              :  * @disk: device the partition belongs to
     476              :  * @part: partition the UUID should be set for
     477              :  * @uuid: partition UUID to set
     478              :  * @error: (out) (optional): place to store error (if any)
     479              :  *
     480              :  * Returns: whether the @uuid type was successfully set for @part or not
     481              :  *
     482              :  * Tech category: %BD_PART_TECH_MODE_MODIFY_PART + the tech according to the partition table type
     483              :  */
     484            1 : gboolean  bd_part_set_part_uuid (const gchar *disk, const gchar *part, const gchar *uuid, GError **error) {
     485            1 :     return _bd_part_set_part_uuid (disk, part, uuid, error);
     486              : }
     487              : 
     488              : 
     489            0 : static gboolean  bd_part_set_part_bootable_stub (const gchar *disk G_GNUC_UNUSED, const gchar *part G_GNUC_UNUSED, gboolean bootable G_GNUC_UNUSED, GError **error) {
     490            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_set_part_bootable' called, but not implemented!");
     491            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     492              :                 "The function 'bd_part_set_part_bootable' called, but not implemented!");
     493            0 :     return FALSE;
     494              : }
     495              : 
     496              : static gboolean  (*_bd_part_set_part_bootable) (const gchar *disk, const gchar *part, gboolean bootable, GError **error) = bd_part_set_part_bootable_stub;
     497              : 
     498              : /**
     499              :  * bd_part_set_part_bootable:
     500              :  * @disk: device the partition belongs to
     501              :  * @part: partition the bootable flag should be set for
     502              :  * @bootable: whether to set or unset the bootable flag
     503              :  * @error: (out) (optional): place to store error (if any)
     504              :  *
     505              :  * Returns: whether the @bootable flag was successfully set for @part or not
     506              :  *
     507              :  * Tech category: %BD_PART_TECH_MBR-%BD_PART_TECH_MODE_MODIFY_PART
     508              :  */
     509            2 : gboolean  bd_part_set_part_bootable (const gchar *disk, const gchar *part, gboolean bootable, GError **error) {
     510            2 :     return _bd_part_set_part_bootable (disk, part, bootable, error);
     511              : }
     512              : 
     513              : 
     514            0 : static gboolean  bd_part_set_part_attributes_stub (const gchar *disk G_GNUC_UNUSED, const gchar *part G_GNUC_UNUSED, guint64 attrs G_GNUC_UNUSED, GError **error) {
     515            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_set_part_attributes' called, but not implemented!");
     516            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     517              :                 "The function 'bd_part_set_part_attributes' called, but not implemented!");
     518            0 :     return FALSE;
     519              : }
     520              : 
     521              : static gboolean  (*_bd_part_set_part_attributes) (const gchar *disk, const gchar *part, guint64 attrs, GError **error) = bd_part_set_part_attributes_stub;
     522              : 
     523              : /**
     524              :  * bd_part_set_part_attributes:
     525              :  * @disk: device the partition belongs to
     526              :  * @part: partition the attributes should be set for
     527              :  * @attrs: GPT attributes to set on @part
     528              :  * @error: (out) (optional): place to store error (if any)
     529              :  *
     530              :  * Returns: whether the @attrs GPT attributes were successfully set for @part or not
     531              :  *
     532              :  * Tech category: %BD_PART_TECH_GPT-%BD_PART_TECH_MODE_MODIFY_PART
     533              :  */
     534            1 : gboolean  bd_part_set_part_attributes (const gchar *disk, const gchar *part, guint64 attrs, GError **error) {
     535            1 :     return _bd_part_set_part_attributes (disk, part, attrs, error);
     536              : }
     537              : 
     538              : 
     539            0 : static const gchar* bd_part_get_part_table_type_str_stub (BDPartTableType type G_GNUC_UNUSED, GError **error) {
     540            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_get_part_table_type_str' called, but not implemented!");
     541            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     542              :                 "The function 'bd_part_get_part_table_type_str' called, but not implemented!");
     543            0 :     return NULL;
     544              : }
     545              : 
     546              : static const gchar* (*_bd_part_get_part_table_type_str) (BDPartTableType type, GError **error) = bd_part_get_part_table_type_str_stub;
     547              : 
     548              : /**
     549              :  * bd_part_get_part_table_type_str:
     550              :  * @type: table type to get string representation for
     551              :  * @error: (out) (optional): place to store error (if any)
     552              :  *
     553              :  * Returns: (transfer none): string representation of @table_type
     554              :  *
     555              :  * Tech category: the tech according to @type
     556              :  */
     557            0 : const gchar* bd_part_get_part_table_type_str (BDPartTableType type, GError **error) {
     558            0 :     return _bd_part_get_part_table_type_str (type, error);
     559              : }
     560              : 
     561              : 
     562            0 : static const gchar* bd_part_get_type_str_stub (BDPartType type G_GNUC_UNUSED, GError **error) {
     563            0 :     bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_part_get_type_str' called, but not implemented!");
     564            0 :     g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
     565              :                 "The function 'bd_part_get_type_str' called, but not implemented!");
     566            0 :     return NULL;
     567              : }
     568              : 
     569              : static const gchar* (*_bd_part_get_type_str) (BDPartType type, GError **error) = bd_part_get_type_str_stub;
     570              : 
     571              : /**
     572              :  * bd_part_get_type_str:
     573              :  * @type: type to get string representation for
     574              :  * @error: (out) (optional): place to store error (if any)
     575              :  *
     576              :  * Returns: (transfer none): string representation of @type
     577              :  *
     578              :  * Tech category: always available
     579              :  */
     580            6 : const gchar* bd_part_get_type_str (BDPartType type, GError **error) {
     581            6 :     return _bd_part_get_type_str (type, error);
     582              : }
     583              : 
     584              : 
     585           35 : static gpointer load_part_from_plugin(const gchar *so_name) {
     586           35 :     void *handle = NULL;
     587           35 :     char *error = NULL;
     588           35 :     gboolean (*init_fn) (void) = NULL;
     589              : 
     590           35 :     handle = dlopen(so_name, RTLD_LAZY);
     591           35 :     if (!handle) {
     592            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load module part: %s", dlerror());
     593            0 :         return NULL;
     594              :     }
     595              : 
     596           35 :     dlerror();
     597           35 :     * (void**) (&init_fn) = dlsym(handle, "bd_part_init");
     598           35 :     if ((error = dlerror()) != NULL)
     599            0 :         bd_utils_log_format (BD_UTILS_LOG_DEBUG, "failed to load the init() function for part: %s", error);
     600              :     /* coverity[dead_error_condition] */
     601           35 :     if (init_fn && !init_fn()) {
     602            0 :         dlclose(handle);
     603            0 :         return NULL;
     604              :     }
     605           35 :     init_fn = NULL;
     606              : 
     607           35 :     dlerror();
     608           35 :     * (void**) (&_bd_part_is_tech_avail) = dlsym(handle, "bd_part_is_tech_avail");
     609           35 :     if ((error = dlerror()) != NULL)
     610            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_is_tech_avail: %s", error);
     611              : 
     612           35 :     dlerror();
     613           35 :     * (void**) (&_bd_part_create_table) = dlsym(handle, "bd_part_create_table");
     614           35 :     if ((error = dlerror()) != NULL)
     615            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_create_table: %s", error);
     616              : 
     617           35 :     dlerror();
     618           35 :     * (void**) (&_bd_part_get_part_spec) = dlsym(handle, "bd_part_get_part_spec");
     619           35 :     if ((error = dlerror()) != NULL)
     620            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_get_part_spec: %s", error);
     621              : 
     622           35 :     dlerror();
     623           35 :     * (void**) (&_bd_part_get_part_by_pos) = dlsym(handle, "bd_part_get_part_by_pos");
     624           35 :     if ((error = dlerror()) != NULL)
     625            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_get_part_by_pos: %s", error);
     626              : 
     627           35 :     dlerror();
     628           35 :     * (void**) (&_bd_part_get_disk_spec) = dlsym(handle, "bd_part_get_disk_spec");
     629           35 :     if ((error = dlerror()) != NULL)
     630            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_get_disk_spec: %s", error);
     631              : 
     632           35 :     dlerror();
     633           35 :     * (void**) (&_bd_part_get_disk_parts) = dlsym(handle, "bd_part_get_disk_parts");
     634           35 :     if ((error = dlerror()) != NULL)
     635            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_get_disk_parts: %s", error);
     636              : 
     637           35 :     dlerror();
     638           35 :     * (void**) (&_bd_part_get_disk_free_regions) = dlsym(handle, "bd_part_get_disk_free_regions");
     639           35 :     if ((error = dlerror()) != NULL)
     640            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_get_disk_free_regions: %s", error);
     641              : 
     642           35 :     dlerror();
     643           35 :     * (void**) (&_bd_part_get_best_free_region) = dlsym(handle, "bd_part_get_best_free_region");
     644           35 :     if ((error = dlerror()) != NULL)
     645            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_get_best_free_region: %s", error);
     646              : 
     647           35 :     dlerror();
     648           35 :     * (void**) (&_bd_part_create_part) = dlsym(handle, "bd_part_create_part");
     649           35 :     if ((error = dlerror()) != NULL)
     650            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_create_part: %s", error);
     651              : 
     652           35 :     dlerror();
     653           35 :     * (void**) (&_bd_part_delete_part) = dlsym(handle, "bd_part_delete_part");
     654           35 :     if ((error = dlerror()) != NULL)
     655            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_delete_part: %s", error);
     656              : 
     657           35 :     dlerror();
     658           35 :     * (void**) (&_bd_part_resize_part) = dlsym(handle, "bd_part_resize_part");
     659           35 :     if ((error = dlerror()) != NULL)
     660            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_resize_part: %s", error);
     661              : 
     662           35 :     dlerror();
     663           35 :     * (void**) (&_bd_part_set_part_name) = dlsym(handle, "bd_part_set_part_name");
     664           35 :     if ((error = dlerror()) != NULL)
     665            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_set_part_name: %s", error);
     666              : 
     667           35 :     dlerror();
     668           35 :     * (void**) (&_bd_part_set_part_type) = dlsym(handle, "bd_part_set_part_type");
     669           35 :     if ((error = dlerror()) != NULL)
     670            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_set_part_type: %s", error);
     671              : 
     672           35 :     dlerror();
     673           35 :     * (void**) (&_bd_part_set_part_id) = dlsym(handle, "bd_part_set_part_id");
     674           35 :     if ((error = dlerror()) != NULL)
     675            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_set_part_id: %s", error);
     676              : 
     677           35 :     dlerror();
     678           35 :     * (void**) (&_bd_part_set_part_uuid) = dlsym(handle, "bd_part_set_part_uuid");
     679           35 :     if ((error = dlerror()) != NULL)
     680            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_set_part_uuid: %s", error);
     681              : 
     682           35 :     dlerror();
     683           35 :     * (void**) (&_bd_part_set_part_bootable) = dlsym(handle, "bd_part_set_part_bootable");
     684           35 :     if ((error = dlerror()) != NULL)
     685            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_set_part_bootable: %s", error);
     686              : 
     687           35 :     dlerror();
     688           35 :     * (void**) (&_bd_part_set_part_attributes) = dlsym(handle, "bd_part_set_part_attributes");
     689           35 :     if ((error = dlerror()) != NULL)
     690            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_set_part_attributes: %s", error);
     691              : 
     692           35 :     dlerror();
     693           35 :     * (void**) (&_bd_part_get_part_table_type_str) = dlsym(handle, "bd_part_get_part_table_type_str");
     694           35 :     if ((error = dlerror()) != NULL)
     695            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_get_part_table_type_str: %s", error);
     696              : 
     697           35 :     dlerror();
     698           35 :     * (void**) (&_bd_part_get_type_str) = dlsym(handle, "bd_part_get_type_str");
     699           35 :     if ((error = dlerror()) != NULL)
     700            0 :         bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_part_get_type_str: %s", error);
     701              : 
     702           35 :     return handle;
     703              : }
     704              : 
     705           35 : static gboolean unload_part (gpointer handle) {
     706           35 :     char *error = NULL;
     707           35 :     gboolean (*close_fn) (void) = NULL;
     708              : 
     709           35 :     _bd_part_is_tech_avail = bd_part_is_tech_avail_stub;
     710           35 :     _bd_part_create_table = bd_part_create_table_stub;
     711           35 :     _bd_part_get_part_spec = bd_part_get_part_spec_stub;
     712           35 :     _bd_part_get_part_by_pos = bd_part_get_part_by_pos_stub;
     713           35 :     _bd_part_get_disk_spec = bd_part_get_disk_spec_stub;
     714           35 :     _bd_part_get_disk_parts = bd_part_get_disk_parts_stub;
     715           35 :     _bd_part_get_disk_free_regions = bd_part_get_disk_free_regions_stub;
     716           35 :     _bd_part_get_best_free_region = bd_part_get_best_free_region_stub;
     717           35 :     _bd_part_create_part = bd_part_create_part_stub;
     718           35 :     _bd_part_delete_part = bd_part_delete_part_stub;
     719           35 :     _bd_part_resize_part = bd_part_resize_part_stub;
     720           35 :     _bd_part_set_part_name = bd_part_set_part_name_stub;
     721           35 :     _bd_part_set_part_type = bd_part_set_part_type_stub;
     722           35 :     _bd_part_set_part_id = bd_part_set_part_id_stub;
     723           35 :     _bd_part_set_part_uuid = bd_part_set_part_uuid_stub;
     724           35 :     _bd_part_set_part_bootable = bd_part_set_part_bootable_stub;
     725           35 :     _bd_part_set_part_attributes = bd_part_set_part_attributes_stub;
     726           35 :     _bd_part_get_part_table_type_str = bd_part_get_part_table_type_str_stub;
     727           35 :     _bd_part_get_type_str = bd_part_get_type_str_stub;
     728              : 
     729           35 :     dlerror();
     730           35 :     * (void**) (&close_fn) = dlsym(handle, "bd_part_close");
     731           35 :     if (((error = dlerror()) != NULL) || !close_fn)
     732            0 :         bd_utils_log_format (BD_UTILS_LOG_DEBUG, "failed to load the close_plugin() function for part: %s", error);
     733              :     /* coverity[dead_error_condition] */
     734           35 :     if (close_fn) {
     735           35 :         close_fn();
     736              :     }
     737              : 
     738           35 :     return dlclose(handle) == 0;
     739              : }
     740              : 
        

Generated by: LCOV version 2.0-1