Due to license conflict between libparted and efibootguard,
libparted cannot be used. Instead, needed code is reimplemented
from scratch.
Signed-off-by: Andreas Reichel <
andreas.r...@siemens.com>
---
Makefile.am | 4 +-
swupdate-adapter/Makefile | 54 -----
tools/bg_utils.h | 2 +-
tools/ebgpart.c | 447 ++++++++++++++++++++++++++++++++++++++++++
tools/ebgpart.h | 132 +++++++++++++
tools/tests/Makefile | 10 +-
tools/tests/test_partitions.c | 27 +--
7 files changed, 591 insertions(+), 85 deletions(-)
delete mode 100644 swupdate-adapter/Makefile
create mode 100644 tools/ebgpart.c
create mode 100644 tools/ebgpart.h
diff --git a/Makefile.am b/Makefile.am
index 73da593..7745bb1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -42,6 +42,7 @@ lib_LIBRARIES = libebgenv.a libbg_utils.a
libebgenv_a_SOURCES = \
tools/bg_utils.c \
+ tools/ebgpart.c \
swupdate-adapter/ebgenv.c
libebgenv_a_CPPFLAGS = \
@@ -52,6 +53,7 @@ libebgenv_a_CFLAGS = \
$(AM_CFLAGS)
libbg_utils_a_SOURCES = \
+ tools/ebgpart.c \
tools/bg_utils.c
libbg_utils_a_CFLAGS = \
@@ -67,6 +69,7 @@ pkginclude_HEADERS = \
bin_PROGRAMS = bg_setenv
bg_setenv_SOURCES = \
+ tools/ebgpart.c \
tools/bg_setenv.c
bg_setenv_CFLAGS = \
@@ -74,7 +77,6 @@ bg_setenv_CFLAGS = \
bg_setenv_LDADD = \
-lbg_utils \
- -lparted \
-lz
bg_setenv_DEPENDENCIES = \
diff --git a/swupdate-adapter/Makefile b/swupdate-adapter/Makefile
deleted file mode 100644
index bd826e3..0000000
--- a/swupdate-adapter/Makefile
+++ /dev/null
@@ -1,54 +0,0 @@
-#
-# EFI Boot Guard FAT Environment Tool
-#
-# Copyright (c) Siemens AG, 2017
-#
-# Authors:
-# Andreas Reichel <
andreas.r...@siemens.com>
-#
-# This work is licensed under the terms of the GNU GPL, version 2. See
-# the COPYING file in the top-level directory.
-#
-
-ARCH := $(shell uname -m)
-
-CC = $(CROSS_COMPILE)gcc
-LD = $(CROSS_COMPILE)ld
-AR = $(CROSS_COMPILE)ar
-OBJCOPY = $(CROSS_COMPILE)objcopy
-
-INCLUDE = /usr/include
-
-CFLAGS = \
- -I$(shell pwd) \
- -I$(shell pwd)/../include \
- -I$(shell pwd)/../tools \
- -I$(INCLUDE) \
- -std=gnu99 \
-
-DEFINES = \
- -DHAVE_ENDIAN_H \
- -D_GNU_SOURCE
-
-ifneq ($(DEBUG),)
-DEFINES += -DDEBUG
-endif
-
-CFLAGS += \
- -fshort-wchar
-
-LIBS = -lparted \
- -lbg_utils
-
-OBJS = ../tools/bg_utils.o
-
-libebgenv.a: $(OBJS) ebgenv.o
- $(AR) rcs $@ $^
-
-%.o: %.c
- $(CC) $(CFLAGS) $(DEFINES) -c $< -o $@
-
-clean:
- @rm -rf *.o *.a
-
-.PHONY: clean
diff --git a/tools/bg_utils.h b/tools/bg_utils.h
index eb52877..70727e9 100644
--- a/tools/bg_utils.h
+++ b/tools/bg_utils.h
@@ -27,7 +27,7 @@
#include <sys/file.h>
#include <sys/mount.h>
-#include <parted/parted.h>
+#include "ebgpart.h"
#include <zlib.h>
#include "envdata.h"
diff --git a/tools/ebgpart.c b/tools/ebgpart.c
new file mode 100644
index 0000000..5ed67bd
--- /dev/null
+++ b/tools/ebgpart.c
@@ -0,0 +1,447 @@
+/*
+ * EFI Boot Guard
+ *
+ * Copyright (c) Siemens AG, 2017
+ *
+ * Authors:
+ * Andreas Reichel <
andreas.r...@siemens.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ *
+ * This code replaces libparted and provides reimplemented routines to
+ * be able to scan for FAT partitions in DOS/GPT partition tables.
+ */
+
+#include "ebgpart.h"
+
+PedDevice *firstDevice = NULL;
+PedDisk g_ped_dummy_disk;
+char buffer[37];
+
+bool verbosity = false;
+
+void ebgpart_beverbose(bool v)
+{
+ verbosity = v;
+}
+
+void addBlockDev(PedDevice *dev)
+{
+ if (!firstDevice) {
+ firstDevice = dev;
+ return;
+ }
+ PedDevice *d = firstDevice;
+ while (d->next) {
+ d = d->next;
+ }
+ d->next = dev;
+}
+
+char *GUIDtoStr(uint8_t *g)
+{
+ snprintf(buffer, 37, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%"
+ "02X%02X%02X%02X%02X",
+ g[3], g[2], g[1], g[0], g[5], g[4], g[7], g[6], g[8], g[9],
+ g[10], g[11], g[12], g[13], g[14], g[15]);
+ return buffer;
+}
+
+char *typeToName(char t)
+{
+ switch (t) {
+ case MBR_TYPE_FAT12:
+ return "fat12";
+ break;
+ case MBR_TYPE_FAT16A:
+ case MBR_TYPE_FAT16:
+ case MBR_TYPE_FAT16_LBA:
+ return "fat16";
+ break;
+ case MBR_TYPE_FAT32:
+ case MBR_TYPE_FAT32_LBA:
+ return "fat32";
+ break;
+ case MBR_TYPE_EXTENDED_LBA:
+ case MBR_TYPE_EXTENDED:
+ return "extended";
+ break;
+ default:
+ return "not supported";
+ break;
+ }
+}
+
+bool checkGPTFATEntry(int fd, struct EFIpartitionentry *e,
+ PedFileSystemType *pfst, uint32_t i)
+{
+ if (strcmp(GPT_PARTITION_GUID_FAT_NTFS, GUIDtoStr(e->type_GUID)) != 0 &&
+ strcmp(GPT_PARTITION_GUID_ESP, GUIDtoStr(e->type_GUID)) != 0) {
+ asprintf(&pfst->name, "not supported");
+ return true;
+ }
+ VERBOSE(stdout, "GPT Partition #%u is FAT/NTFS.\n", i);
+ /* Save current file offset */
+ errno = 0;
+ off64_t curr = lseek64(fd, 0, SEEK_CUR);
+ if (errno) {
+ VERBOSE(stderr, "Error getting current seek position: %s\n",
+ strerror(errno));
+ return false;
+ }
+ /* Look if it is a FAT12 or FAT16 */
+ errno = 0;
+ lseek64(fd, e->start_LBA * LB_SIZE + 0x36, SEEK_SET);
+ if (errno) {
+ VERBOSE(stderr, "Error seeking FAT12/16 Id String: %s\n",
+ strerror(errno));
+ return false;
+ }
+ char FATname[9];
+ if (read(fd, FATname, 8) != 8) {
+ VERBOSE(stderr, "Error reading FAT12/16 Id String: %s\n",
+ strerror(errno));
+ return false;
+ };
+ FATname[9] = 0;
+ if (strcmp(FATname, "FAT12 ") != 0 &&
+ strcmp(FATname, "FAT16 ") != 0) {
+ /* No FAT12/16 so read ID field for FAT32 */
+ errno = 0;
+ lseek64(fd, e->start_LBA * LB_SIZE + 0x52, SEEK_SET);
+ if (errno) {
+ VERBOSE(stderr, "Error seeking FAT32 Id String: %s\n",
+ strerror(errno));
+ return false;
+ }
+ errno = 0;
+ if (read(fd, FATname, 8) != 8) {
+ VERBOSE(stderr, "Error reading FAT32 Id String: %s\n",
+ strerror(errno));
+ return false;
+ }
+ }
+ if (strcmp(FATname, "FAT12 ") == 0) {
+ asprintf(&pfst->name, "fat12");
+ } else if (strcmp(FATname, "FAT16 ") == 0) {
+ asprintf(&pfst->name, "fat16");
+ } else {
+ asprintf(&pfst->name, "fat32");
+ }
+ VERBOSE(stdout, "GPT Partition #%u is %s.\n", i, pfst->name);
+ errno = 0;
+ lseek64(fd, curr, SEEK_SET);
+ if (errno) {
+ VERBOSE(stderr, "Error restoring seek position (%s)",
+ strerror(errno));
+ return false;
+ }
+ return true;
+}
+
+void readGPTEntries(int fd, uint64_t tableLBA, uint32_t num, PedDevice *dev)
+{
+ off64_t offset;
+ struct EFIpartitionentry e;
+ PedPartition *partition = NULL, *tmpp;
+ PedFileSystemType *pfst = NULL;
+
+ offset = LB_SIZE * tableLBA;
+ if (lseek64(fd, offset, SEEK_SET) != offset) {
+ VERBOSE(stderr, "Error seeking EFI partition table\n");
+ return;
+ }
+
+ for (uint32_t i = 0; i < num; i++) {
+ errno = 0;
+ if (read(fd, &e, sizeof(e)) != sizeof(e)) {
+ VERBOSE(stderr, "Error reading partition entry\n");
+ VERBOSE(stderr, "(%s)\n", strerror(errno));
+ return;
+ }
+ if ((*((uint64_t *)&e.type_GUID[0]) == 0) &&
+ (*((uint64_t *)&e.type_GUID[8]) == 0)) {
+ return;
+ }
+ VERBOSE(stdout, "%u: %s\n", i, GUIDtoStr(e.type_GUID));
+ pfst = calloc(sizeof(PedFileSystemType), 1);
+ if (!pfst) {
+ VERBOSE(stderr, "Out of memory\n");
+ return;
+ }
+ tmpp = partition;
+ if (!partition) {
+ partition = calloc(sizeof(PedPartition), 1);
+ if (!partition) {
+ VERBOSE(stderr, "Out of memory\n");
+ free(pfst);
+ return;
+ }
+ dev->part_list = partition;
+ } else {
+ partition->next = calloc(sizeof(PedPartition), 1);
+ if (!partition->next) {
+ VERBOSE(stderr, "Out of memory\n");
+ free(pfst);
+ return;
+ }
+ partition = partition->next;
+ }
+ partition->num = i + 1;
+ partition->fs_type = pfst;
+ if (!checkGPTFATEntry(fd, &e, pfst, i)) {
+ if (pfst->name) free(pfst->name);
+ free(pfst);
+ free(partition);
+ partition = tmpp;
+ if (!partition) {
+ dev->part_list = NULL;
+ }
+ }
+ }
+}
+
+void scanLogicalVolumes(int fd, off64_t extended_start_LBA,
+ struct Masterbootrecord *ebr, int i,
+ PedPartition *partition, int lognum)
+{
+ struct Masterbootrecord next_ebr;
+ PedFileSystemType *pfst;
+
+ off64_t offset = extended_start_LBA + ebr->parttable[i].start_LBA;
+ if (extended_start_LBA == 0) {
+ extended_start_LBA = offset;
+ }
+ VERBOSE(stdout, "Seeking to LBA %u\n", offset);
+ errno = 0;
+ off64_t res = lseek64(fd, offset * LB_SIZE, SEEK_SET);
+ if (errno) {
+ VERBOSE(stderr, "(%s)\n", strerror(errno));
+ return;
+ }
+ VERBOSE(stdout, "Seek returned %llu\n", res);
+ errno = 0;
+ read(fd, &next_ebr, sizeof(next_ebr));
+ if (errno) {
+ VERBOSE(stderr, "Error reading next EBR (%s)\n",
+ strerror(errno));
+ return;
+ }
+ if (next_ebr.mbrsignature != 0xaa55) {
+ VERBOSE(stderr, "Wrong signature of extended boot record.\n");
+ return;
+ }
+
+ for (uint8_t j = 0; j < 4; j++) {
+ uint8_t t = next_ebr.parttable[j].partition_type;
+ if (t == 0) {
+ return;
+ }
+ if (t == MBR_TYPE_EXTENDED || t == MBR_TYPE_EXTENDED_LBA) {
+ VERBOSE(stdout, "Next EBR found.\n");
+ scanLogicalVolumes(fd, extended_start_LBA, &next_ebr, j,
+ partition, lognum + 1);
+ continue;
+ }
+ partition->next = calloc(sizeof(PedPartition), 1);
+ if (!partition->next) {
+ VERBOSE(stderr, "Out of memory\n");
+ return;
+ }
+ pfst = calloc(sizeof(PedFileSystemType), 1);
+ if (!pfst) {
+ VERBOSE(stderr, "Out of memory\n");
+ free(partition->next);
+ return;
+ }
+ if (asprintf(&pfst->name, typeToName(t)) == -1) {
+ VERBOSE(stderr, "Out of memory\n");
+ free(partition->next);
+ free(pfst);
+ return;
+ };
+ partition = partition->next;
+ partition->num = lognum;
+ partition->fs_type = pfst;
+ }
+}
+
+bool checkPartitionTable(PedDevice *dev)
+{
+ int fd;
+ struct Masterbootrecord mbr;
+
+ if ((fd = open(dev->path, O_RDONLY)) == 0) {
+ VERBOSE(stderr, "Error opening block device.\n");
+ return false;
+ }
+ if (read(fd, &mbr, sizeof(mbr)) != sizeof(mbr)) {
+ VERBOSE(stderr, "Error reading mbr.\n");
+ close(fd);
+ return false;
+ };
+ if (mbr.mbrsignature != 0xaa55) {
+ VERBOSE(stderr, "Error, MBR has wrong signature.\n");
+ close(fd);
+ return false;
+ }
+ int partitions = 0;
+ PedFileSystemType *pfst;
+ PedPartition *partition = NULL;
+ for (int i = 0; i < 4; i++) {
+ if (mbr.parttable[i].partition_type == 0) {
+ continue;
+ }
+ partitions++;
+ VERBOSE(stdout, "Partition %u: Type %X\n", i,
+ mbr.parttable[i].partition_type);
+ uint8_t t = mbr.parttable[i].partition_type;
+ if (t == MBR_TYPE_GPT) {
+ VERBOSE(stdout, "GPT header at %X\n",
+ mbr.parttable[i].start_LBA);
+ off64_t offset = LB_SIZE * mbr.parttable[i].start_LBA;
+ errno = 0;
+ if (lseek64(fd, offset, SEEK_SET) != offset) {
+ VERBOSE(stderr, "Error seeking EFI Header\n.");
+ VERBOSE(stderr, "(%s)", strerror(errno));
+ return false;
+ }
+ struct EFIHeader efihdr;
+ errno = 0;
+ if (read(fd, &efihdr, sizeof(efihdr)) !=
+ sizeof(efihdr)) {
+ VERBOSE(stderr, "Error reading EFI Header\n.");
+ VERBOSE(stderr, "(%s)", strerror(errno));
+ return false;
+ }
+ VERBOSE(stdout, "EFI Header: %X %X %X %X %X %X %X %X\n",
+ efihdr.signature[0], efihdr.signature[1],
+ efihdr.signature[2], efihdr.signature[3],
+ efihdr.signature[4], efihdr.signature[5],
+ efihdr.signature[6], efihdr.signature[7]);
+ VERBOSE(stdout, "Number of partition entries: %u\n",
+ efihdr.partitions);
+ VERBOSE(stdout, "Partition Table @ LBA %llu\n",
+ efihdr.partitiontable_LBA);
+ readGPTEntries(fd, efihdr.partitiontable_LBA,
+ efihdr.partitions, dev);
+ break;
+ } else {
+ pfst = calloc(sizeof(PedFileSystemType), 1);
+ if (!partition) {
+ partition = calloc(sizeof(PedPartition), 1);
+ dev->part_list = partition;
+ } else {
+ partition->next =
+ calloc(sizeof(PedPartition), 1);
+ partition = partition->next;
+ }
+ partition->num = i + 1;
+ partition->fs_type = pfst;
+
+ if (t == MBR_TYPE_EXTENDED ||
+ t == MBR_TYPE_EXTENDED_LBA) {
+ asprintf(&pfst->name, "extended");
+ scanLogicalVolumes(fd, 0, &mbr, i, partition,
+ 5);
+ } else {
+ asprintf(&pfst->name, typeToName(t));
+ }
+ }
+ }
+ (void)close(fd);
+ if (partitions == 0) {
+ return false;
+ }
+ return true;
+}
+
+void ped_device_probe_all()
+{
+ int blkdev;
+ struct dirent *devfile;
+ char fullname[256];
+
+ DIR *devdir = opendir("/dev");
+ if (!devdir) {
+ VERBOSE(stderr, "Could not open /dev\n");
+ return;
+ }
+
+ /* get all files from devdir */
+ while ((devfile = readdir(devdir)) != NULL) {
+ struct stat s;
+ char lastletter = devfile->d_name[strlen(devfile->d_name) - 1];
+ if (lastletter <= '9') {
+ /* do not handle linux partition block devices, i.e.
+ * /dev/sda5, but only /dev/sda */
+ continue;
+ }
+ snprintf(fullname, 255, "%s/%s", DEVDIRNAME, devfile->d_name);
+ if (lstat(fullname, &s) != 0) {
+ continue;
+ };
+ if (S_ISBLK(s.st_mode)) {
+ /* This is a block device, so add it to the list*/
+ PedDevice *dev = calloc(sizeof(PedDevice), 1);
+ asprintf(&dev->model, "N/A");
+ asprintf(&dev->path, "%s", fullname);
+ if (checkPartitionTable(dev)) {
+ addBlockDev(dev);
+ } else {
+ free(dev->model);
+ free(dev->path);
+ free(dev);
+ }
+ }
+ }
+ (void)closedir(devdir);
+}
+
+PedDevice *ped_device_get_next(PedDevice *dev)
+{
+ if (!dev) {
+ return firstDevice;
+ }
+ if (dev->next != NULL) {
+ return dev->next;
+ }
+ /* free all memory */
+ PedDevice *d = firstDevice;
+ PedDevice *tmpd;
+
+ while (d) {
+ tmpd = d;
+ d = d->next;
+ if (tmpd->model) free(tmpd->model);
+ if (tmpd->path) free(tmpd->path);
+ PedPartition *p = tmpd->part_list;
+ PedPartition *tmpp;
+ while (p) {
+ tmpp = p;
+ p = p->next;
+ if (tmpp->fs_type) {
+ if (tmpp->fs_type->name)
+ free(tmpp->fs_type->name);
+ free(tmpp->fs_type);
+ }
+ free(tmpp);
+ }
+ free(tmpd);
+ }
+ return NULL;
+}
+
+PedDisk *ped_disk_new(PedDevice *dev)
+{
+ g_ped_dummy_disk.part_list = dev->part_list;
+ return &g_ped_dummy_disk;
+}
+
+PedPartition *ped_disk_next_partition(PedDisk *pd, PedPartition *part)
+{
+ (void)pd;
+ return part->next;
+}
diff --git a/tools/ebgpart.h b/tools/ebgpart.h
new file mode 100644
index 0000000..44effb5
--- /dev/null
+++ b/tools/ebgpart.h
@@ -0,0 +1,132 @@
+/*
+ * EFI Boot Guard
+ *
+ * Copyright (c) Siemens AG, 2017
+ *
+ * Authors:
+ * Andreas Reichel <
andreas.r...@siemens.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ *
+ * This code replaces libparted and provides reimplemented routines to
+ * be able to scan for FAT partitions in DOS/GPT partition tables.
+ */
+
+#ifndef __EBGPART_H__
+#define __EBGPART_H__
+
+#ifndef _LARGEFILE64_SOURCE
+#define _LARGEFILE64_SOURCE
+#endif
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#ifndef VERBOSE
+#define VERBOSE(o, ...) \
+ if (verbosity) fprintf(o, __VA_ARGS__)
+#endif
+
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define DEVDIRNAME "/dev"
+
+#define LB_SIZE 512
+
+#define MBR_TYPE_GPT 0xEE
+#define MBR_TYPE_FAT12 0x01
+#define MBR_TYPE_FAT16A 0x04
+#define MBR_TYPE_FAT16 0x06
+#define MBR_TYPE_EXTENDED 0x05
+#define MBR_TYPE_FAT32 0x0B
+#define MBR_TYPE_FAT32_LBA 0x0C
+#define MBR_TYPE_FAT16_LBA 0x0E
+#define MBR_TYPE_EXTENDED_LBA 0x0F
+
+#define GPT_PARTITION_GUID_FAT_NTFS "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7"
+#define GPT_PARTITION_GUID_ESP "C12A7328-F81F-11D2-BA4B-00A0C93EC93B"
+
+#pragma pack(push)
+#pragma pack(1)
+struct MBRentry {
+ uint8_t boot_flag;
+ uint8_t first_sector_chs[3];
+ uint8_t partition_type;
+ uint8_t last_sector_chs[3];
+ uint32_t start_LBA;
+ uint32_t num_Sectors;
+};
+struct Masterbootrecord {
+ char bootloader[0x1B8];
+ char devsignature[4];
+ char mbr_padding[2];
+ struct MBRentry parttable[4];
+ uint16_t mbrsignature;
+};
+struct EFIHeader {
+ char signature[8];
+ uint32_t revision;
+ uint32_t header_size;
+ uint32_t header_crc32;
+ uint32_t reserved;
+ uint64_t this_LBA;
+ uint64_t backup_LBA;
+ uint64_t firstentry_LBA;
+ uint64_t lastentry_LBA;
+ uint8_t GUID[16];
+ uint64_t partitiontable_LBA;
+ uint32_t partitions;
+ uint32_t partitionentrysize;
+ uint32_t partitiontable_CRC32;
+ uint32_t reserved2[420];
+};
+struct EFIpartitionentry {
+ uint8_t type_GUID[16];
+ uint8_t partition_GUID[16];
+ uint64_t start_LBA;
+ uint64_t end_LBA;
+ uint64_t attribute;
+ uint16_t name[36];
+};
+#pragma pack(pop)
+
+/* Implementing a minimalistic API replacing used libparted functions */
+typedef struct _PedFileSystemType {
+ char *name;
+} PedFileSystemType;
+
+typedef struct _PedPartition {
+ PedFileSystemType *fs_type;
+ uint16_t num;
+ struct _PedPartition *next;
+} PedPartition;
+
+typedef struct _PedDevice {
+ char *model;
+ char *path;
+ PedPartition *part_list;
+ struct _PedDevice *next;
+} PedDevice;
+
+typedef struct _PedDisk {
+ PedPartition *part_list;
+} PedDisk;
+
+void ped_device_probe_all();
+PedDevice *ped_device_get_next(PedDevice *dev);
+PedDisk *ped_disk_new(PedDevice *dev);
+PedPartition *ped_disk_next_partition(PedDisk *pd, PedPartition *part);
+
+#endif // __EBGPART_H__
diff --git a/tools/tests/Makefile b/tools/tests/Makefile
index 68c1495..ff66742 100644
--- a/tools/tests/Makefile
+++ b/tools/tests/Makefile
@@ -38,10 +38,9 @@ endif
CFLAGS += \
-fshort-wchar
-LIBS = -L.. \
+LIBS = -L../.. \
-L../../swupdate-adapter \
-lcmocka \
- -lparted \
-lebgenv \
-lz
@@ -52,11 +51,11 @@ LIBS = -L.. \
# dependency recipes.
# All targets' '.target' extensions get removed within the target recipes.
#
-OBJS_test_partitions = test_partitions.O bg_utils.O
-OBJS_test_environment = test_environment.O bg_utils.O
+OBJS_test_partitions = test_partitions.O bg_utils.O ebgpart.O
+OBJS_test_environment = test_environment.O bg_utils.O ebgpart.O
OBJS_test_api = test_api.O bg_utils.O ebgenv.O
-MOCKOBJS_test_partitions = bg_utils
+MOCKOBJS_test_partitions = bg_utils ebgpart
MOCKOBJS_test_environment = bg_utils
MOCKOBJS_test_api = bg_utils
@@ -66,6 +65,7 @@ MOCKOBJS_test_api = bg_utils
MOCKOBJS_SYMBOLS_bg_utils-test_partitions = probe_config_file
MOCKOBJS_SYMBOLS_bg_utils-test_environment = oldenvs configparts fopen fclose fread fwrite feof mount_partition
MOCKOBJS_SYMBOLS_bg_utils-test_api = bgenv_init bgenv_write bgenv_close bgenv_get_latest bgenv_get_by_index bgenv_get_oldest
+MOCKOBJS_SYMBOLS_ebgpart-test_partitions = ped_device_probe_all ped_device_get_next ped_disk_next_partition
TEST_TARGETS = test_partitions.target test_environment.target test_api.target
diff --git a/tools/tests/test_partitions.c b/tools/tests/test_partitions.c
index 93c0aef..05b6b41 100644
--- a/tools/tests/test_partitions.c
+++ b/tools/tests/test_partitions.c
@@ -16,13 +16,9 @@
#include <stdbool.h>
#include <setjmp.h>
#include <cmocka.h>
-#include <parted/device.h>
-#include <parted/disk.h>
#include "bg_utils.h"
static PedDevice ped_devices[32] = {0};
-static PedDisk ped_disks[32] = {0};
-static PedDiskType ped_disktypes[32] = {0};
static int num_simulated_devices = 2;
static int curr_ped_device = 0;
static PedPartition ped_parts[32] = {0};
@@ -30,7 +26,6 @@ static int num_simulated_partitions_per_disk = 2;
static PedFileSystemType ped_fstypes[32] = {0};
static const char *const fsname = "fat16";
-static const char *const disktypename = "gpt";
static char *fakemodel = "Mocked Disk Drive";
static char *fakedevice = "/dev/nobrain";
@@ -44,9 +39,7 @@ void ped_device_probe_all()
for (int i = 0; i < 32; i++) {
ped_devices[i].model = fakemodel;
ped_devices[i].path = fakedevice;
- ped_disktypes[i].name = disktypename;
- ped_disks[i].type = &ped_disktypes[i];
- ped_disks[i].part_list = &ped_parts[0];
+ ped_devices[i].part_list = &ped_parts[0];
}
for (int i = 0; i < 32; i++) {
@@ -62,7 +55,7 @@ void ped_device_probe_all()
}
}
-PedDevice *ped_device_get_next(const PedDevice *dev)
+PedDevice *ped_device_get_next(PedDevice *dev)
{
if (dev == NULL) {
return &ped_devices[0];
@@ -75,21 +68,7 @@ PedDevice *ped_device_get_next(const PedDevice *dev)
return NULL;
}
-PedDisk *ped_disk_new(PedDevice *dev)
-{
- if (dev == NULL) {
- return NULL;
- }
- for (int i = 0; i < 32; i++) {
- if (dev == &ped_devices[i]) {
- return &ped_disks[i];
- }
- }
- return NULL;
-}
-
-PedPartition *ped_disk_next_partition(const PedDisk *disk,
- const PedPartition *part)
+PedPartition *ped_disk_next_partition(PedDisk *disk, PedPartition *part)
{
if (disk == NULL) {
return NULL;
--
2.11.0