summaryrefslogtreecommitdiffstats
path: root/fs/jffs2/fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/jffs2/fs.c')
-rw-r--r--fs/jffs2/fs.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index f094291aa4..6f2cbff6c9 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
/*
* JFFS2 -- Journalling Flash File System, Version 2.
*
@@ -5,9 +6,6 @@
* Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
*
* Created by David Woodhouse <dwmw2@infradead.org>
- *
- * For licensing information, see the file 'LICENCE' in this directory.
- *
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <common.h>
@@ -42,7 +40,7 @@ static inline void i_gid_write(struct inode *inode, gid_t gid)
const struct file_operations jffs2_file_operations;
const struct inode_operations jffs2_file_inode_operations;
-static int jffs2_open(struct device_d *dev, FILE *file, const char *filename)
+static int jffs2_open(struct device *dev, FILE *file, const char *filename)
{
struct inode *inode = file->f_inode;
struct jffs2_file *jf;
@@ -58,7 +56,7 @@ static int jffs2_open(struct device_d *dev, FILE *file, const char *filename)
return 0;
}
-static int jffs2_close(struct device_d *dev, FILE *f)
+static int jffs2_close(struct device *dev, FILE *f)
{
struct jffs2_file *jf = f->priv;
@@ -74,6 +72,9 @@ static int jffs2_get_block(struct jffs2_file *jf, unsigned int pos)
struct jffs2_inode_info *f = JFFS2_INODE_INFO(jf->inode);
int ret;
+ /* pos always has to be 4096 bytes aligned here */
+ WARN_ON(pos % JFFS2_BLOCK_SIZE != 0);
+
if (pos != jf->offset) {
ret = jffs2_read_inode_range(c, f, jf->buf, pos,
JFFS2_BLOCK_SIZE);
@@ -85,7 +86,7 @@ static int jffs2_get_block(struct jffs2_file *jf, unsigned int pos)
return 0;
}
-static int jffs2_read(struct device_d *_dev, FILE *f, void *buf,
+static int jffs2_read(struct device *_dev, FILE *f, void *buf,
size_t insize)
{
struct jffs2_file *jf = f->priv;
@@ -98,12 +99,13 @@ static int jffs2_read(struct device_d *_dev, FILE *f, void *buf,
/* Read till end of current block */
ofs = f->pos % JFFS2_BLOCK_SIZE;
if (ofs) {
- ret = jffs2_get_block(jf, pos);
+ ret = jffs2_get_block(jf, f->pos - ofs); /* Align down block */
if (ret)
return ret;
now = min(size, JFFS2_BLOCK_SIZE - ofs);
+ /* Complete block has been read, re-apply ofset now */
memcpy(buf, jf->buf + ofs, now);
size -= now;
pos += now;
@@ -397,9 +399,11 @@ void jffs2_flash_cleanup(struct jffs2_sb_info *c) {
}
}
-static int jffs2_probe(struct device_d *dev)
+static int jffs2_probe_cnt;
+
+static int jffs2_probe(struct device *dev)
{
- struct fs_device_d *fsdev;
+ struct fs_device *fsdev;
struct super_block *sb;
struct jffs2_sb_info *ctx;
int ret;
@@ -419,28 +423,24 @@ static int jffs2_probe(struct device_d *dev)
sb->s_fs_info = ctx;
- ret = jffs2_compressors_init();
- if (ret) {
- pr_err("error: Failed to initialise compressors\n");
- goto err_out;
- }
-
- ret = jffs2_create_slab_caches();
- if (ret) {
- pr_err("error: Failed to initialise slab caches\n");
- goto err_compressors;
- }
+ if (!jffs2_probe_cnt) {
+ ret = jffs2_compressors_init();
+ if (ret) {
+ pr_err("error: Failed to initialise compressors\n");
+ goto err_out;
+ }
+ }
if (jffs2_fill_super(fsdev, 0)) {
dev_err(dev, "no valid jffs2 found\n");
ret = -EINVAL;
- goto err_slab;
+ goto err_compressors;
}
+ jffs2_probe_cnt++;
+
return 0;
-err_slab:
- jffs2_destroy_slab_caches();
err_compressors:
jffs2_compressors_exit();
err_out:
@@ -448,22 +448,25 @@ err_out:
return ret;
}
-static void jffs2_remove(struct device_d *dev)
+static void jffs2_remove(struct device *dev)
{
- struct fs_device_d *fsdev;
+ struct fs_device *fsdev;
struct super_block *sb;
fsdev = dev_to_fs_device(dev);
sb = &fsdev->sb;
- jffs2_destroy_slab_caches();
- jffs2_compressors_exit();
+ jffs2_probe_cnt--;
+
+ if (!jffs2_probe_cnt) {
+ jffs2_compressors_exit();
+ }
jffs2_put_super(sb);
}
-static struct fs_driver_d jffs2_driver = {
+static struct fs_driver jffs2_driver = {
.open = jffs2_open,
.close = jffs2_close,
.read = jffs2_read,