summaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-01-11 19:00:04 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-01-11 19:00:04 +0100
commit08c62ae2fa9378732588ef7b9a9120b377d26d1e (patch)
tree6c4b687f9ec73397be1f3be08f7df191ab2d6542 /drivers/mtd
parent917225203ff8047ae91e03ac4fc6fc320f37f1ce (diff)
parentfa9cc22e29faf24a70a4771a71f93e8a17045524 (diff)
downloadbarebox-08c62ae2fa9378732588ef7b9a9120b377d26d1e.tar.gz
barebox-08c62ae2fa9378732588ef7b9a9120b377d26d1e.tar.xz
Merge branch 'for-next/truncate'
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/ubi/barebox.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/drivers/mtd/ubi/barebox.c b/drivers/mtd/ubi/barebox.c
index 329cf4564a..d67e566db6 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)
@@ -228,9 +244,6 @@ int ubi_volume_cdev_add(struct ubi_device *ubi, struct ubi_volume *vol)
cdev->priv = priv;
cdev->size = vol->used_bytes;
- if (vol->vol_type == UBI_STATIC_VOLUME)
- cdev->flags = DEVFS_IS_CHARACTER_DEV;
-
cdev->dev = &vol->dev;
ubi_msg(ubi, "registering %s as /dev/%s", vol->name, cdev->name);
ret = devfs_create(cdev);