[PATCH 2/6] devfs: Add optional truncate callback for device files

Teresa Remmet t.remmet at phytec.de
Fri Nov 25 00:06:03 PST 2016


Not all device files have trivial fix device sizes like static
ubi volumes. Here the device file size equals the image size it contains.

Signed-off-by: Teresa Remmet <t.remmet at phytec.de>
---
 fs/devfs.c       | 5 +++++
 include/driver.h | 1 +
 2 files changed, 6 insertions(+)

diff --git a/fs/devfs.c b/fs/devfs.c
index 6fabcf8..2a7b1b3 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -168,6 +168,11 @@ static int devfs_ioctl(struct device_d *_dev, FILE *f, int request, void *buf)
 
 static int devfs_truncate(struct device_d *dev, FILE *f, ulong size)
 {
+	struct cdev *cdev = f->priv;
+
+	if (cdev->ops->truncate)
+		return cdev->ops->truncate(cdev, size);
+
 	if (f->fsdev->dev.num_resources < 1)
 		return -ENOSPC;
 	if (size > resource_size(&f->fsdev->dev.resource[0]))
diff --git a/include/driver.h b/include/driver.h
index 80aa8d8..6abaaad 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -434,6 +434,7 @@ struct file_operations {
 	int (*erase)(struct cdev*, loff_t count, loff_t offset);
 	int (*protect)(struct cdev*, size_t count, loff_t offset, int prot);
 	int (*memmap)(struct cdev*, void **map, int flags);
+	int (*truncate)(struct cdev*, size_t size);
 };
 
 #define MAX_PARTUUID_STR	sizeof("00112233-4455-6677-8899-AABBCCDDEEFF")
-- 
1.9.1




More information about the barebox mailing list