diff options
-rw-r--r-- | common/partitions.c | 27 | ||||
-rw-r--r-- | include/driver.h | 1 |
2 files changed, 28 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; +} diff --git a/include/driver.h b/include/driver.h index c7f5903fce..4f6d40e17c 100644 --- a/include/driver.h +++ b/include/driver.h @@ -494,6 +494,7 @@ ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulo ssize_t cdev_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags); int cdev_ioctl(struct cdev *cdev, int cmd, void *buf); int cdev_erase(struct cdev *cdev, loff_t count, loff_t offset); +loff_t cdev_unallocated_space(struct cdev *cdev); #define DEVFS_PARTITION_FIXED (1U << 0) #define DEVFS_PARTITION_READONLY (1U << 1) |