mtd: Fix erasing of devices >4GiB
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>
This commit is contained in:
parent
e0ae56c008
commit
81737c1d43
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 = {};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
2
fs/fs.c
2
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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue