Skip to contentSkip to conversation

Backport of squashfs-2.6.29+ (squashfs-4.0) to kernel 2.6.27

PATCH Michael Tokarev 1 participant 1 message Jun 19, 2009

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

Below are two diffs for squashfs-4 (as found in 2.6.29 and 2.6.30 kernels) to kernel 2.6.27.

In order to build, grab fs/squashfs directory from 2.6.29 or 2.6.30 (or maybe later version), copy it to fs/squashfs in 2.6.27 tree, and apply 2 provided patches.

First (squashfs-2.6.29-to-.27-backport.diff) changes squashfs itself to be compatible with kernel 2.6.27 API (namely, adding magic number definition and implementing d_obtain_alias() which is missing in 2.6.27.

And second changes 2.6.27 build infrastructure to actually include squashfs filesystem -- init/do_mounts_rd.c, fs/Kconfig and fs/Makefile.

JFYI, in case it will be useful to someone.

What I use it for is -- since 2.6.29+ does not work with version 3 of the filesystem layout, and 2.6.28- only recognizes v.3, and since I'm tired updating kernels on all supported machines, I want to stop for some time, relying on 2.6.27.y stable series. But we also use squashfs and some machines requires more modern kernel features. So I thought about updating squashfs to v4 on all. So here it goes.

Thanks.

/mjt

fs/squashfs/export.c +19 -3
@@ -76,14 +76,30 @@ static struct dentry *squashfs_export_ig
 	unsigned int ino_num)
 {
 	long long ino;
-	struct dentry *dentry = ERR_PTR(-ENOENT);
+	struct dentry *dentry;
+	struct inode *i;
 
 	TRACE("Entered squashfs_export_iget\n");
 
 	ino = squashfs_inode_lookup(sb, ino_num);
-	if (ino >= 0)
-		dentry = d_obtain_alias(squashfs_iget(sb, ino, ino_num));
+	if (ino < 0) {
+		dentry = ERR_PTR(-ENOENT);
+		goto failure;
+	}
+
+	i = squashfs_iget(sb, ino, ino_num);
+	if (i == NULL) {
+		dentry = ERR_PTR(-EACCES);
+		goto failure;
+	}
+
+	dentry = d_alloc_anon(i);
+	if (dentry == NULL) {
+		iput(i);
+		dentry = ERR_PTR(-ENOMEM);
+	}
 
+failure:
 	return dentry;
 }
 
fs/squashfs/squashfs_fs.h +2 -0
@@ -23,6 +23,8 @@
  * squashfs_fs.h
  */
 
+#define SQUASHFS_MAGIC		0x73717368
+
 #define SQUASHFS_CACHED_FRAGMENTS	CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE
 #define SQUASHFS_MAJOR			4
 #define SQUASHFS_MINOR			0
fs/Kconfig +2 -0
@@ -1350,2 +1350,4 @@ config CRAMFS
 
+source "fs/squashfs/Kconfig"
+
 config VXFS_FS
fs/Makefile +1 -0
@@ -76,2 +76,3 @@ obj-$(CONFIG_EXT2_FS)		+= ext2/
 obj-$(CONFIG_CRAMFS)		+= cramfs/
+obj-$(CONFIG_SQUASHFS)		+= squashfs/
 obj-y				+= ramfs/
init/do_mounts_rd.c +14 -0
@@ -11,2 +11,3 @@
 #include "do_mounts.h"
+#include "../fs/squashfs/squashfs_fs.h"
 
@@ -43,2 +44,3 @@ static int __init crd_load(int in_fd, in
  *	cramfs
+ *	squashfs
  * 	gzip
@@ -53,2 +55,3 @@ identify_ramdisk_image(int fd, int start
 	struct cramfs_super *cramfsb;
+	struct squashfs_super_block *squashfsb;
 	int nblocks = -1;
@@ -64,2 +67,3 @@ identify_ramdisk_image(int fd, int start
 	cramfsb = (struct cramfs_super *) buf;
+	squashfsb = (struct squashfs_super_block *) buf;
 	memset(buf, 0xe5, size);
@@ -101,2 +105,12 @@ identify_ramdisk_image(int fd, int start
 
+	/* squashfs is at block zero too */
+	if (le32_to_cpu(squashfsb->s_magic) == SQUASHFS_MAGIC) {
+		printk(KERN_NOTICE
+		       "RAMDISK: squashfs filesystem found at block %d\n",
+		       start_block);
+		nblocks = (le64_to_cpu(squashfsb->bytes_used) + BLOCK_SIZE - 1)
+			 >> BLOCK_SIZE_BITS;
+		goto done;
+	}
+
 	/*