mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 6/7] mtd: Fix erasing of devices >4GiB
Date: Tue,  9 Feb 2016 10:55:47 +0100	[thread overview]
Message-ID: <1455011748-5538-7-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1455011748-5538-1-git-send-email-s.hauer@pengutronix.de>

When a device >4GiB is erased, not only the offset can be bigger
than 4GiB, but also the size. This happens with the simplest command
to erase a device: erase /dev/nand0. Make the size argument a 64bit
type to make this work.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/core.c         | 6 +++---
 drivers/mtd/mtdraw.c       | 2 +-
 drivers/mtd/nand/nand-bb.c | 2 +-
 fs/devfs-core.c            | 2 +-
 fs/devfs.c                 | 2 +-
 fs/fs.c                    | 2 +-
 include/driver.h           | 4 ++--
 include/fs.h               | 4 ++--
 8 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 0bc9fed..9234525 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -114,13 +114,13 @@ static struct mtd_erase_region_info *mtd_find_erase_region(struct mtd_info *mtd,
 	return NULL;
 }
 
-static int mtd_erase_align(struct mtd_info *mtd, size_t *count, loff_t *offset)
+static int mtd_erase_align(struct mtd_info *mtd, loff_t *count, loff_t *offset)
 {
 	struct mtd_erase_region_info *e;
 	loff_t ofs;
 
 	if (mtd->numeraseregions == 0) {
-		ofs = *offset & ~(mtd->erasesize - 1);
+		ofs = *offset & ~(loff_t)(mtd->erasesize - 1);
 		*count += (*offset - ofs);
 		*count = ALIGN(*count, mtd->erasesize);
 		*offset = ofs;
@@ -144,7 +144,7 @@ static int mtd_erase_align(struct mtd_info *mtd, size_t *count, loff_t *offset)
 	return 0;
 }
 
-static int mtd_op_erase(struct cdev *cdev, size_t count, loff_t offset)
+static int mtd_op_erase(struct cdev *cdev, loff_t count, loff_t offset)
 {
 	struct mtd_info *mtd = cdev->priv;
 	struct erase_info erase;
diff --git a/drivers/mtd/mtdraw.c b/drivers/mtd/mtdraw.c
index 837dcd1..4d6ac72 100644
--- a/drivers/mtd/mtdraw.c
+++ b/drivers/mtd/mtdraw.c
@@ -239,7 +239,7 @@ static ssize_t mtdraw_write(struct cdev *cdev, const void *buf, size_t count,
 	}
 }
 
-static int mtdraw_erase(struct cdev *cdev, size_t count, loff_t offset)
+static int mtdraw_erase(struct cdev *cdev, loff_t count, loff_t offset)
 {
 	struct mtd_info *mtd = to_mtd(cdev);
 	struct erase_info erase;
diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
index 5a2fd10..e6d4277 100644
--- a/drivers/mtd/nand/nand-bb.c
+++ b/drivers/mtd/nand/nand-bb.c
@@ -157,7 +157,7 @@ static ssize_t nand_bb_write(struct cdev *cdev, const void *buf, size_t count,
 	return bytes;
 }
 
-static int nand_bb_erase(struct cdev *cdev, size_t count, loff_t offset)
+static int nand_bb_erase(struct cdev *cdev, loff_t count, loff_t offset)
 {
 	struct nand_bb *bb = cdev->priv;
 	struct erase_info erase = {};
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 88a7e3a..deacaaa 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -259,7 +259,7 @@ int cdev_ioctl(struct cdev *cdev, int request, void *buf)
 	return cdev->ops->ioctl(cdev, request, buf);
 }
 
-int cdev_erase(struct cdev *cdev, size_t count, loff_t offset)
+int cdev_erase(struct cdev *cdev, loff_t count, loff_t offset)
 {
 	if (!cdev->ops->erase)
 		return -ENOSYS;
diff --git a/fs/devfs.c b/fs/devfs.c
index 0b8d4fd..6fabcf8 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -66,7 +66,7 @@ static loff_t devfs_lseek(struct device_d *_dev, FILE *f, loff_t pos)
 	return ret - cdev->offset;
 }
 
-static int devfs_erase(struct device_d *_dev, FILE *f, size_t count, loff_t offset)
+static int devfs_erase(struct device_d *_dev, FILE *f, loff_t count, loff_t offset)
 {
 	struct cdev *cdev = f->priv;
 
diff --git a/fs/fs.c b/fs/fs.c
index ace72f7..c4b3583 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -924,7 +924,7 @@ out:
 }
 EXPORT_SYMBOL(lseek);
 
-int erase(int fd, size_t count, loff_t offset)
+int erase(int fd, loff_t count, loff_t offset)
 {
 	struct fs_driver_d *fsdrv;
 	FILE *f;
diff --git a/include/driver.h b/include/driver.h
index 31c6734..ce8c966 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -425,7 +425,7 @@ struct file_operations {
 	int (*open)(struct cdev*, unsigned long flags);
 	int (*close)(struct cdev*);
 	int (*flush)(struct cdev*);
-	int (*erase)(struct cdev*, size_t count, loff_t offset);
+	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);
 };
@@ -470,7 +470,7 @@ int cdev_flush(struct cdev *cdev);
 ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags);
 ssize_t cdev_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags);
 int cdev_ioctl(struct cdev *cdev, int cmd, void *buf);
-int cdev_erase(struct cdev *cdev, size_t count, loff_t offset);
+int cdev_erase(struct cdev *cdev, loff_t count, loff_t offset);
 
 #define DEVFS_PARTITION_FIXED		(1U << 0)
 #define DEVFS_PARTITION_READONLY	(1U << 1)
diff --git a/include/fs.h b/include/fs.h
index 23156ea..9f4164e 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -70,7 +70,7 @@ struct fs_driver_d {
 	int (*stat)(struct device_d *dev, const char *file, struct stat *stat);
 
 	int (*ioctl)(struct device_d *dev, FILE *f, int request, void *buf);
-	int (*erase)(struct device_d *dev, FILE *f, size_t count,
+	int (*erase)(struct device_d *dev, FILE *f, loff_t count,
 			loff_t offset);
 	int (*protect)(struct device_d *dev, FILE *f, size_t count,
 			loff_t offset, int prot);
@@ -145,7 +145,7 @@ int mount (const char *device, const char *fsname, const char *path,
 int umount(const char *pathname);
 
 /* not-so-standard functions */
-int erase(int fd, size_t count, loff_t offset);
+int erase(int fd, loff_t count, loff_t offset);
 int protect(int fd, size_t count, loff_t offset, int prot);
 int protect_file(const char *file, int prot);
 void *memmap(int fd, int flags);
-- 
2.7.0.rc3


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

  parent reply	other threads:[~2016-02-09  9:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-09  9:55 [PATCH] mtd: >4GiB fixes Sascha Hauer
2016-02-09  9:55 ` [PATCH 1/7] mtd: nand-bb: Fix 8k page size nands Sascha Hauer
2016-02-09  9:55 ` [PATCH 2/7] mtd: Fix mtdraw for Nand > 4GiB Sascha Hauer
2016-02-09  9:55 ` [PATCH 3/7] mtd: Make erase_info structs 64bit where necessary Sascha Hauer
2016-02-09  9:55 ` [PATCH 4/7] mtd: Fix mtd_op_read for devices >4GiB Sascha Hauer
2016-02-09  9:55 ` [PATCH 5/7] mtd: Fix mtd_op_erase " Sascha Hauer
2016-02-09  9:55 ` Sascha Hauer [this message]
2016-02-09  9:55 ` [PATCH 7/7] mtd: mtdoob device: change name to have the chip name first 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=1455011748-5538-7-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.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