[PATCH 17/23] fs: switch to resource

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Fri Jul 29 23:17:05 EDT 2011


Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 fs/devfs.c |    4 +++-
 fs/fs.c    |    8 ++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/fs/devfs.c b/fs/devfs.c
index 07ca16c..66f7ca4 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -161,7 +161,9 @@ 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)
 {
-	if (size > f->dev->size)
+	if (f->dev->num_resources < 1)
+		return -ENOSPC;
+	if (size > f->dev->resource[0].size)
 		return -ENOSPC;
 	return 0;
 }
diff --git a/fs/fs.c b/fs/fs.c
index bcc6ff4..7d65ec8 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1043,11 +1043,11 @@ ssize_t mem_read(struct cdev *cdev, void *buf, size_t count, ulong offset, ulong
 	ulong size;
 	struct device_d *dev;
 
-	if (!cdev->dev)
+	if (!cdev->dev || cdev->dev->num_resources < 1)
 		return -1;
 	dev = cdev->dev;
 
-	size = min((ulong)count, dev->size - offset);
+	size = min((ulong)count, dev->resource[0].size - offset);
 	memcpy_sz(buf, dev_get_mem_region(dev, 0) + offset, size, flags & O_RWSIZE_MASK);
 	return size;
 }
@@ -1058,11 +1058,11 @@ ssize_t mem_write(struct cdev *cdev, const void *buf, size_t count, ulong offset
 	ulong size;
 	struct device_d *dev;
 
-	if (!cdev->dev)
+	if (!cdev->dev || cdev->dev->num_resources < 1)
 		return -1;
 	dev = cdev->dev;
 
-	size = min((ulong)count, dev->size - offset);
+	size = min((ulong)count, dev->resource[0].size - offset);
 	memcpy_sz(dev_get_mem_region(dev, 0) + offset, buf, size, flags & O_RWSIZE_MASK);
 	return size;
 }
-- 
1.7.5.4




More information about the barebox mailing list