diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2024-02-15 08:47:53 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2024-02-16 12:04:42 +0100 |
commit | c641d9ed9d35196932625358e63bdd073371c132 (patch) | |
tree | dd086f8a54ddfd6386156be4b3c7a409a5fcdbf5 | |
parent | 729370043ab67efc82b2574a8dc88b82a99f986c (diff) | |
download | barebox-c641d9ed9d35.tar.gz barebox-c641d9ed9d35.tar.xz |
partition: allow to reparse a partition table
The partition table of a block device may change when it is written to.
Allow to reparse the partition table when this happens.
This is easy when none of the partitions is opened, in that case just
remove the old partitions and call parse_partition_table() again.
When a partition is opened (including mounted) we can't remove it. In
that case continue with the old partition table and print a warning.
Reviewed-by: Marco Felsch <m.felsch@pengutronix.de>
Link: https://lore.barebox.org/20240215074757.960200-4-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | common/partitions.c | 20 | ||||
-rw-r--r-- | include/disks.h | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/common/partitions.c b/common/partitions.c index 78b68276c3..cfcd0e080b 100644 --- a/common/partitions.c +++ b/common/partitions.c @@ -154,6 +154,26 @@ on_error: return rc; } +int reparse_partition_table(struct block_device *blk) +{ + struct cdev *cdev = &blk->cdev; + struct cdev *c, *tmp; + + list_for_each_entry(c, &cdev->partitions, partition_entry) { + if (c->open) { + pr_warn("%s is busy, will continue to use old partition table\n", c->name); + return -EBUSY; + } + } + + list_for_each_entry_safe(c, tmp, &cdev->partitions, partition_entry) { + if (c->flags & DEVFS_PARTITION_FROM_TABLE) + cdevfs_del_partition(c); + } + + return parse_partition_table(blk); +} + int partition_parser_register(struct partition_parser *p) { list_add_tail(&p->list, &partition_parser_list); diff --git a/include/disks.h b/include/disks.h index 1ca7063c54..ccb50d3ce9 100644 --- a/include/disks.h +++ b/include/disks.h @@ -24,5 +24,6 @@ struct partition_entry { } __attribute__ ((packed)); extern int parse_partition_table(struct block_device*); +int reparse_partition_table(struct block_device *blk); #endif /* DISKS_H */ |