Skip to contentSkip to conversation

squashfs: pull out common logic of backend init functions

PATCH New Ferenc Wagner 1 participant 1 message Mar 23, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 squashfs: pull out common logic of backend init functions

---
 fs/squashfs/backend.h |    2 +-
 fs/squashfs/bdev.c    |  155 +++++++++----------------------------------------
 fs/squashfs/block.c   |   33 ++++++++++-
 fs/squashfs/mtd.c     |   38 +-----------
 4 files changed, 62 insertions(+), 166 deletions(-)
fs/squashfs/backend.h +1 -1
index 308fe6d..5beba00 100644
@@ -4,7 +4,7 @@
 #include "squashfs_fs_sb.h"
 
 struct squashfs_backend {
-	int	(*init)(struct super_block *, u64, int, int, u64 *, int *);
+	int	(*init)(struct super_block *, u64, int);
 	void	(*free)(struct squashfs_sb_info *);
 	int	(*read)(struct super_block *, void *, int);
 	int	(*probe)(struct file_system_type *, int, const char *,
fs/squashfs/bdev.c +27 -128

183 lines not on this page · raw message

fs/squashfs/block.c +31 -2
index 1c85063..eb33770 100644
@@ -53,8 +53,37 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,
 	int compressed;
 	struct squashfs_sb_info *msblk = sb->s_fs_info;
 
-	length = msblk->backend->init(sb, index, length, srclength,
-					next_index, &compressed);
+	if (length) { /* Data block */
+		compressed = SQUASHFS_COMPRESSED_BLOCK(length);
+		length = SQUASHFS_COMPRESSED_SIZE_BLOCK(length);
+		TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n",
+			index, compressed ? "" : "un", length, srclength);
+	} else { /* Metadata block */
+		int read;
+		u16 metalen;
+
+		length = msblk->backend->init(sb, index, 2);
+		if (length < 0)
+			return length;
+		read = msblk->backend->read(sb, &metalen, 2);
+		if (read != 2)
+			goto read_failure;
+		msblk->backend->free(msblk);
+		length = le16_to_cpu(metalen);
+		compressed = SQUASHFS_COMPRESSED(length);
+		length = SQUASHFS_COMPRESSED_SIZE(length);
+		index += 2;
+		TRACE("Block @ 0x%llx, %scompressed size %d\n", index,
+				compressed ? "" : "un", length);
+	}
+	if (length < 0 || length > srclength ||
+	    (index + length) > msblk->bytes_used)
+		goto read_failure;
+
+	if (next_index)
+		*next_index = index + length;
+
+	length = msblk->backend->init(sb, index, length);
 	if (length < 0)
 		return length;
 
fs/squashfs/mtd.c +3 -35
index c9ba361..99f2d35 100644
@@ -38,50 +38,18 @@ static int checked_mtd_read(struct super_block *sb, u64 index, int length,
 	return 0;
 }
 
-static int mtd_init(struct super_block *sb, u64 index, int length,
-		    int srclength, u64 *next_index, int *compressed)
+static int mtd_init(struct super_block *sb, u64 index, int length)
 {
 	struct squashfs_sb_info *msblk = sb->s_fs_info;
 	struct squashfs_mtd *mtd = msblk->backend_data;
 
-	TRACE("Entering mtd_init: index=0x%llx, length=0x%x, srclength=%d\n",
-		index, length, srclength);
-
-	if (length) { /* datablock */
-		*compressed = SQUASHFS_COMPRESSED_BLOCK(length);
-		length = SQUASHFS_COMPRESSED_SIZE_BLOCK(length);
-		if (next_index)
-			*next_index = index + length;
-		TRACE("Block @ 0x%llx, %scompressed size %d, src size %d\n",
-			index, *compressed ? "" : "un", length, srclength);
-	} else { /* metadata block */
-		u16 metalen;
-		if ((index + 2) > msblk->bytes_used)
-			goto read_failure;
-		if (checked_mtd_read(sb, index, 2, &metalen))
-			goto read_failure;
-		length = le16_to_cpu(metalen);
-		*compressed = SQUASHFS_COMPRESSED(length);
-		length = SQUASHFS_COMPRESSED_SIZE(length);
-		if (next_index)
-			*next_index = index + length + 2;
-		TRACE("Block @ 0x%llx, %scompressed size %d\n", index,
-				*compressed ? "" : "un", length);
-		index += 2;
-	}
-	if (length < 0 || length > srclength ||
-			(index + length) > msblk->bytes_used)
-		goto read_failure;
+	TRACE("Entering mtd_init: index=0x%llx, length=0x%x\n",
+		index, length);
 
 	mtd->index = index;
 	mtd->length = length;
 	mtd->bytes_read = 0;
 	return length;
-
-read_failure:
-	ERROR("mtd_init failed to read block 0x%llx\n",
-					(unsigned long long) index);
-	return -EIO;
 }
 
 static void mtd_free(struct squashfs_sb_info *msblk)
Signature · 4 lines
1.5.6.5


--=-=-=--