diff options
author | Teresa Remmet <t.remmet@phytec.de> | 2016-11-25 09:06:04 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-01-11 08:06:48 +0100 |
commit | 55513dcec567c760fad4daadb3805983a3626d27 (patch) | |
tree | a6c70d895416e42695580fcb8ea0a5023777c226 | |
parent | a6785bae3b30232c126b2432d2391f89963d100d (diff) | |
download | barebox-55513dcec567c760fad4daadb3805983a3626d27.tar.gz barebox-55513dcec567c760fad4daadb3805983a3626d27.tar.xz |
ubi: Add truncate callback
The size of static ubi volumes changes depending on the content.
Add truncate callback to handle resizes.
Signed-off-by: Teresa Remmet <t.remmet@phytec.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/mtd/ubi/barebox.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/drivers/mtd/ubi/barebox.c b/drivers/mtd/ubi/barebox.c index 329cf4564a..2ad731ad9a 100644 --- a/drivers/mtd/ubi/barebox.c +++ b/drivers/mtd/ubi/barebox.c @@ -162,6 +162,21 @@ static loff_t ubi_volume_cdev_lseek(struct cdev *cdev, loff_t ofs) return ofs; } +static int ubi_volume_cdev_truncate(struct cdev *cdev, size_t size) +{ + struct ubi_volume_cdev_priv *priv = cdev->priv; + struct ubi_device *ubi = priv->ubi; + struct ubi_volume *vol = priv->vol; + uint64_t rsvd_bytes; + + rsvd_bytes = (long long)vol->reserved_pebs * + ubi->leb_size - vol->data_pad; + if (size > rsvd_bytes) + return -ENOSPC; + + return 0; +} + static int ubi_volume_cdev_ioctl(struct cdev *cdev, int cmd, void *buf) { struct ubi_volume_cdev_priv *priv = cdev->priv; @@ -210,6 +225,7 @@ static struct file_operations ubi_volume_fops = { .write = ubi_volume_cdev_write, .lseek = ubi_volume_cdev_lseek, .ioctl = ubi_volume_cdev_ioctl, + .truncate = ubi_volume_cdev_truncate, }; int ubi_volume_cdev_add(struct ubi_device *ubi, struct ubi_volume *vol) |