diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2024-02-15 08:47:54 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2024-02-16 12:13:47 +0100 |
commit | 713a23cb2aeae374efcfc391e66b2959bba23f0d (patch) | |
tree | 2b65755fc2bd22404481bec6e5d8eb95907418fb | |
parent | c641d9ed9d35196932625358e63bdd073371c132 (diff) | |
download | barebox-713a23cb2aea.tar.gz barebox-713a23cb2aea.tar.xz |
block: reparse partition table when necessary
Call reparse_partition_table() when the partition table may have
changed. We detect this by recording if the block device has been
written to in the area where the partition table is.
Reviewed-by: Marco Felsch <m.felsch@pengutronix.de>
Link: https://lore.barebox.org/20240215074757.960200-5-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | common/block.c | 25 | ||||
-rw-r--r-- | include/block.h | 2 |
2 files changed, 26 insertions, 1 deletions
diff --git a/common/block.c b/common/block.c index 3a4a9fb731..98ed67e966 100644 --- a/common/block.c +++ b/common/block.c @@ -284,6 +284,17 @@ static ssize_t block_op_write(struct cdev *cdev, const void *buf, size_t count, blkcnt_t blocks; int ret; + /* + * When the offset that is written to is within the first two + * LBAs then the partition table has changed, reparse the partition + * table at close time in this case. A GPT covers more space than + * only the first two LBAs, but a CRC of the remaining pieces is + * written to LBA1, so LBA1 must change as well when the partioning + * is changed. + */ + if (offset < 2 * SECTOR_SIZE) + blk->need_reparse = true; + if (offset & mask) { size_t now = BLOCKSIZE(blk) - (offset & mask); void *iobuf = block_get(blk, block); @@ -341,7 +352,19 @@ static int block_op_flush(struct cdev *cdev) return writebuffer_flush(blk); } -static int block_op_close(struct cdev *cdev) __alias(block_op_flush); +static int block_op_close(struct cdev *cdev) +{ + struct block_device *blk = cdev->priv; + + block_op_flush(cdev); + + if (blk->need_reparse) { + reparse_partition_table(blk); + blk->need_reparse = false; + } + + return 0; +} static int block_op_discard_range(struct cdev *cdev, loff_t count, loff_t offset) { diff --git a/include/block.h b/include/block.h index 44037bd74c..aaaa97400f 100644 --- a/include/block.h +++ b/include/block.h @@ -33,6 +33,8 @@ struct block_device { struct list_head idle_blocks; struct cdev cdev; + + bool need_reparse; }; extern struct list_head block_device_list; |