diff --git a/fs/fs.c b/fs/fs.c index 12faaeb..e00bbcd 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -497,6 +497,31 @@ } EXPORT_SYMBOL(protect); +int discard_range(int fd, loff_t count, loff_t offset) +{ + struct fs_driver_d *fsdrv; + FILE *f = fd_to_file(fd); + int ret; + + if (IS_ERR(f)) + return -errno; + if (offset >= f->size) + return 0; + if (count > f->size - offset) + count = f->size - offset; + + fsdrv = f->fsdev->driver; + if (fsdrv->discard_range) + ret = fsdrv->discard_range(&f->fsdev->dev, f, count, offset); + else + ret = -ENOSYS; + + if (ret) + errno = -ret; + + return ret; +} + int protect_file(const char *file, int prot) { int fd, ret; diff --git a/include/fs.h b/include/fs.h index 38debfc..d9684c8 100644 --- a/include/fs.h +++ b/include/fs.h @@ -60,6 +60,8 @@ loff_t offset); int (*protect)(struct device_d *dev, FILE *f, size_t count, loff_t offset, int prot); + int (*discard_range)(struct device_d *dev, FILE *f, loff_t count, + loff_t offset); int (*memmap)(struct device_d *dev, FILE *f, void **map, int flags); @@ -127,6 +129,7 @@ #define ERASE_SIZE_ALL ((loff_t) - 1) int erase(int fd, loff_t count, loff_t offset); int protect(int fd, size_t count, loff_t offset, int prot); +int discard_range(int fd, loff_t count, loff_t offset); int protect_file(const char *file, int prot); void *memmap(int fd, int flags);