Return-Path: <klibc-bounces@zytor.com>
Received: from terminus.zytor.com (mailman@localhost [127.0.0.1])
	by terminus.zytor.com (8.13.4/8.13.4) with ESMTP id k15AWHcj007144;
	Sun, 5 Feb 2006 02:32:26 -0800
Received: from palpatine.hardeman.nu (1-1-12-13a.han.sth.bostream.se
	[82.182.30.168])
	by terminus.zytor.com (8.13.4/8.13.4) with ESMTP id k15ARSKU006978
	(version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO)
	for <klibc@zytor.com>; Sun, 5 Feb 2006 02:27:31 -0800
Received: from ip54532fb6.speed.planet.nl ([84.83.47.182] helo=austin)
	by palpatine.hardeman.nu with esmtpsa
	(TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.50) id 1F5h73-0002o9-8K
	for klibc@zytor.com; Sun, 05 Feb 2006 11:27:23 +0100
Received: by austin (Postfix, from userid 1000)
	id EB6DE19AF41; Sun,  5 Feb 2006 11:26:47 +0100 (CET)
Date: Sun, 5 Feb 2006 11:26:47 +0100
From: David =?iso-8859-1?Q?H=E4rdeman?= <david@2gen.com>
To: klibc@zytor.com
Message-ID: <20060205102647.GB10190@hardeman.nu>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="MW5yreqqjyrRcusr"
Content-Disposition: inline
User-Agent: Mutt/1.5.11+cvs20060126
Content-Transfer-Encoding: 7bit
X-SA-Score: -2.2
X-Virus-Scanned: ClamAV version 0.88, clamav-milter version 0.87 on localhost
X-Virus-Scanned: ClamAV version 0.88, clamav-milter version 0.87 on localhost
X-Virus-Status: Clean
X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 
	autolearn=unavailable version=3.0.4
X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on terminus.zytor.com
Subject: [klibc] Add swap support to fstype, second version
X-BeenThere: klibc@zytor.com
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: About Linux klibc and early userspace issues <klibc.zytor.com>
List-Unsubscribe: <http://www.zytor.com/mailman/listinfo/klibc>,
	<mailto:klibc-request@zytor.com?subject=unsubscribe>
List-Archive: <http://www.zytor.com/pipermail/klibc>
List-Post: <mailto:klibc@zytor.com>
List-Help: <mailto:klibc-request@zytor.com?subject=help>
List-Subscribe: <http://www.zytor.com/mailman/listinfo/klibc>,
	<mailto:klibc-request@zytor.com?subject=subscribe>
Sender: klibc-bounces@zytor.com
Errors-To: klibc-bounces@zytor.com
X-UID: 1337
X-Keywords: NonJunk                                                                                           


--MW5yreqqjyrRcusr
Content-Type: text/plain; charset=iso-8859-1; format=flowed
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

This patch adds support for swap detection to fstype (to be applied on=20
top of the previous luks patch).

The patch is now against klibc's git tree instead of klibc-1.2.

Signed-off-by: David H=E4rdeman <david@2gen.com>

--=20

 fstype.c  |   42 ++++++++++++++++++++++++++++++------------
 swap_fs.h |   18 ++++++++++++++++++
 2 files changed, 48 insertions(+), 12 deletions(-)


--MW5yreqqjyrRcusr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline; filename=klibc-add-swap-to-fstype-v2

Index: klibc/usr/kinit/fstype/fstype.c
===================================================================
--- klibc.orig/usr/kinit/fstype/fstype.c	2006-02-05 11:09:31.000000000 +0100
+++ klibc/usr/kinit/fstype/fstype.c	2006-02-05 11:11:15.000000000 +0100
@@ -7,7 +7,7 @@
  *  FSSIZE - filesystem size (if known)
  *
  * We currently detect (in order):
- *  gzip, cramfs, romfs, xfs, luks, minix, ext3, ext2, reiserfs, jfs
+ *  gzip, cramfs, romfs, xfs, luks, minix, ext3, ext2, reiserfs, jfs, swap
  *
  * MINIX, ext3 and Reiserfs bits are currently untested.
  */
@@ -20,6 +20,7 @@
 #include <endian.h>
 #include <netinet/in.h>
 #include <sys/vfs.h>
+#include <asm/page.h>
 
 #define cpu_to_be32(x) __cpu_to_be32(x)	/* Needed by romfs_fs.h */
 
@@ -49,6 +50,9 @@
 
 #define BLOCK_SIZE 1024
 
+/* Swap needs the definition of block size */
+#include "swap_fs.h"
+
 static int gzip_image(const unsigned char *buf, unsigned long long *bytes)
 {
 	if (buf[0] == 037 && (buf[1] == 0213 || buf[1] == 0236)) {
@@ -182,6 +186,19 @@
 	return 0;
 }
 
+static int swap_image(const unsigned char *buf, unsigned long long *blocks)
+{
+	const struct swap_super_block *ssb =
+		(const struct swap_super_block *)buf;
+
+	if (!memcmp(ssb->magic, SWAP_MAGIC_1, SWAP_MAGIC_L) ||
+	    !memcmp(ssb->magic, SWAP_MAGIC_2, SWAP_MAGIC_L)) {
+		*blocks = 0;
+		return 1;
+	}
+	return 0;
+}
+
 struct imagetype {
 	off_t		block;
 	const char	name[12];
@@ -189,17 +206,18 @@
 };
 
 static struct imagetype images[] = {
-	{ 0,	"gzip",		gzip_image	},
-	{ 0,	"cramfs",	cramfs_image	},
-	{ 0,	"romfs",	romfs_image	},
-	{ 0,	"xfs",		xfs_image	},
-	{ 0,	"luks",		luks_image	},
-	{ 1,	"minix",	minix_image	},
-	{ 1,	"ext3",		ext3_image	},
-	{ 1,	"ext2",		ext2_image	},
-	{ 8,	"reiserfs",	reiserfs_image	},
-	{ 64,	"reiserfs",	reiserfs_image	},
-	{ 32,	"jfs",		jfs_image	}
+	{ 0,		"gzip",		gzip_image	},
+	{ 0,		"cramfs",	cramfs_image	},
+	{ 0,		"romfs",	romfs_image	},
+	{ 0,		"xfs",		xfs_image	},
+	{ 0,		"luks",		luks_image	},
+	{ 1,		"minix",	minix_image	},
+	{ 1,		"ext3",		ext3_image	},
+	{ 1,		"ext2",		ext2_image	},
+	{ 8,		"reiserfs",	reiserfs_image	},
+	{ 64,		"reiserfs",	reiserfs_image	},
+	{ 32,		"jfs",		jfs_image	},
+	{ SWAP_OFFSET,	"swap",		swap_image	}
 };
 
 int identify_fs(int fd, const char **fstype,
Index: klibc/usr/kinit/fstype/swap_fs.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ klibc/usr/kinit/fstype/swap_fs.h	2006-02-05 11:10:01.000000000 +0100
@@ -0,0 +1,18 @@
+#ifndef __LINUX_SWAP_FS_H
+#define __LINUX_SWAP_FS_H
+
+/* The basic structures of the swap super block */
+#define SWAP_RESERVED_L		BLOCK_SIZE - 10
+#define SWAP_MAGIC_L		10
+#define SWAP_MAGIC_1		"SWAP-SPACE"
+#define SWAP_MAGIC_2		"SWAPSPACE2"
+/* The super block is the last block in the first page */
+#define SWAP_OFFSET		((PAGE_SIZE - BLOCK_SIZE) / BLOCK_SIZE)
+
+/* On-disk "super block" */
+struct swap_super_block {
+	char reserved[SWAP_RESERVED_L];
+	char magic[SWAP_MAGIC_L];
+};
+
+#endif

--MW5yreqqjyrRcusr
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
klibc mailing list
klibc@zytor.com
http://www.zytor.com/mailman/listinfo/klibc

--MW5yreqqjyrRcusr--
