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 #include #include +#include #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