diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2021-10-12 09:33:51 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-10-12 10:28:32 +0200 |
commit | 839d934c79aee95a7d67d2f8dceacbfd0e5ea848 (patch) | |
tree | 07983024016ad25ae42895b03455fc7959d565a4 /common | |
parent | e563d9723963d4468bd6a60f603d827941c7ff77 (diff) | |
download | barebox-839d934c79aee95a7d67d2f8dceacbfd0e5ea848.tar.gz barebox-839d934c79aee95a7d67d2f8dceacbfd0e5ea848.tar.xz |
cdev: Add function to get unallocated space at start of device
On several SoCs barebox is written to the raw device in front of the
first partition. So far we blindly trust that there is enough space
available for the barebox image. Start changing this by adding a
function that retrieves the available space.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Link: https://lore.barebox.org/20211012073352.4071559-8-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/partitions.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/common/partitions.c b/common/partitions.c index d80878e065..b579559672 100644 --- a/common/partitions.c +++ b/common/partitions.c @@ -156,3 +156,30 @@ int partition_parser_register(struct partition_parser *p) return 0; } + +/** + * cdev_unallocated_space - return unallocated space + * cdev: The cdev + * + * This function returns the space that is not allocated by any partition + * at the start of a device. + * + * Return: The unallocated space at the start of the device in bytes + */ +loff_t cdev_unallocated_space(struct cdev *cdev) +{ + struct cdev *partcdev; + loff_t start; + + if (!cdev) + return 0; + + start = cdev->size; + + list_for_each_entry(partcdev, &cdev->partitions, partition_entry) { + if (partcdev->offset < start) + start = partcdev->offset; + } + + return start; +} |