9
0
Fork 0

fs: implement flush function

Once we have caching in file functions we need a way to sync
the the underlying devices.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2011-03-25 11:04:53 +01:00
parent 3efa8f7bed
commit f1bb89fd9e
4 changed files with 34 additions and 0 deletions

View File

@ -169,6 +169,16 @@ static int devfs_close(struct device_d *_dev, FILE *f)
return 0; return 0;
} }
static int devfs_flush(struct device_d *_dev, FILE *f)
{
struct cdev *cdev = f->inode;
if (cdev->ops->flush)
return cdev->ops->flush(cdev);
return 0;
}
static int partition_ioctl(struct cdev *cdev, int request, void *buf) static int partition_ioctl(struct cdev *cdev, int request, void *buf)
{ {
size_t offset; size_t offset;
@ -287,6 +297,7 @@ static struct fs_driver_d devfs_driver = {
.lseek = devfs_lseek, .lseek = devfs_lseek,
.open = devfs_open, .open = devfs_open,
.close = devfs_close, .close = devfs_close,
.flush = devfs_flush,
.ioctl = devfs_ioctl, .ioctl = devfs_ioctl,
.opendir = devfs_opendir, .opendir = devfs_opendir,
.readdir = devfs_readdir, .readdir = devfs_readdir,

20
fs/fs.c
View File

@ -536,6 +536,26 @@ ssize_t write(int fd, const void *buf, size_t count)
} }
EXPORT_SYMBOL(write); EXPORT_SYMBOL(write);
int flush(int fd)
{
struct device_d *dev;
struct fs_driver_d *fsdrv;
FILE *f = &files[fd];
if (check_fd(fd))
return errno;
dev = f->dev;
fsdrv = (struct fs_driver_d *)dev->driver->type_data;
if (fsdrv->flush)
errno = fsdrv->flush(dev, f);
else
errno = 0;
return errno;
}
off_t lseek(int fildes, off_t offset, int whence) off_t lseek(int fildes, off_t offset, int whence)
{ {
struct device_d *dev; struct device_d *dev;

View File

@ -292,6 +292,7 @@ struct file_operations {
off_t (*lseek)(struct cdev*, off_t); off_t (*lseek)(struct cdev*, off_t);
int (*open)(struct cdev*); int (*open)(struct cdev*);
int (*close)(struct cdev*); int (*close)(struct cdev*);
int (*flush)(struct cdev*);
int (*erase)(struct cdev*, size_t count, unsigned long offset); int (*erase)(struct cdev*, size_t count, unsigned long offset);
int (*protect)(struct cdev*, size_t count, unsigned long offset, int prot); int (*protect)(struct cdev*, size_t count, unsigned long offset, int prot);
int (*memmap)(struct cdev*, void **map, int flags); int (*memmap)(struct cdev*, void **map, int flags);

View File

@ -53,6 +53,7 @@ struct fs_driver_d {
int (*close)(struct device_d *dev, FILE *f); int (*close)(struct device_d *dev, FILE *f);
int (*read)(struct device_d *dev, FILE *f, void *buf, size_t size); int (*read)(struct device_d *dev, FILE *f, void *buf, size_t size);
int (*write)(struct device_d *dev, FILE *f, const void *buf, size_t size); int (*write)(struct device_d *dev, FILE *f, const void *buf, size_t size);
int (*flush)(struct device_d *dev, FILE *f);
off_t (*lseek)(struct device_d *dev, FILE *f, off_t pos); off_t (*lseek)(struct device_d *dev, FILE *f, off_t pos);
struct dir* (*opendir)(struct device_d *dev, const char *pathname); struct dir* (*opendir)(struct device_d *dev, const char *pathname);
@ -98,6 +99,7 @@ int open(const char *pathname, int flags, ...);
int creat(const char *pathname, mode_t mode); int creat(const char *pathname, mode_t mode);
int unlink(const char *pathname); int unlink(const char *pathname);
int close(int fd); int close(int fd);
int flush(int fd);
int stat(const char *filename, struct stat *s); int stat(const char *filename, struct stat *s);
int read(int fd, void *buf, size_t count); int read(int fd, void *buf, size_t count);
int ioctl(int fd, int request, void *buf); int ioctl(int fd, int request, void *buf);