mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Teresa Remmet <t.remmet@phytec.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/6] ubi: Add truncate callback
Date: Fri, 25 Nov 2016 09:06:04 +0100	[thread overview]
Message-ID: <1480061167-21590-4-git-send-email-t.remmet@phytec.de> (raw)
In-Reply-To: <1480061167-21590-1-git-send-email-t.remmet@phytec.de>

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>
---
 drivers/mtd/ubi/barebox.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/mtd/ubi/barebox.c b/drivers/mtd/ubi/barebox.c
index 329cf45..2ad731a 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)
-- 
1.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-11-25  8:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-25  8:06 [PATCH 0/6] ubi: remove character device flag from static volumes Teresa Remmet
2016-11-25  8:06 ` [PATCH 1/6] libfile: copy_file: Only open regular files with O_TRUNC Teresa Remmet
2016-11-25  8:06 ` [PATCH 2/6] devfs: Add optional truncate callback for device files Teresa Remmet
2016-11-25  8:06 ` Teresa Remmet [this message]
2016-11-25  8:06 ` [PATCH 4/6] fs: Remove O_TRUNC check for devices when open files Teresa Remmet
2016-11-25  8:06 ` [PATCH 5/6] commands: ubi: ubiupdatevol: Open device with O_TRUNC Teresa Remmet
2016-11-25  8:06 ` [PATCH 6/6] ubi: barebox: Remove character device flag from static volumes Teresa Remmet
2016-12-07 20:13 ` [PATCH 0/6] ubi: remove " Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1480061167-21590-4-git-send-email-t.remmet@phytec.de \
    --to=t.remmet@phytec.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox