From: Tony Breeds Date: Fri, 16 Jul 2010 05:11:38 +0000 (+1000) Subject: Merge branch 'devel' X-Git-Tag: yaboot-1.3.17-rc1~26 X-Git-Url: https://git.ozlabs.org/?p=yaboot.git;a=commitdiff_plain;h=8aef1508bddad47681e258e9f2eaa7987cbd8a32;hp=a7e2774dc319f3a64ae9b612a428f488a60d2721 Merge branch 'devel' --- diff --git a/Makefile b/Makefile index d975e4e..336ac52 100644 --- a/Makefile +++ b/Makefile @@ -83,7 +83,8 @@ HOSTCFLAGS = -O2 $(CFLAGS) -Wall -I/usr/include OBJS = second/crt0.o second/yaboot.o second/cache.o second/prom.o second/file.o \ second/partition.o second/fs.o second/cfg.o second/setjmp.o second/cmdline.o \ - second/fs_of.o second/fs_ext2.o second/fs_iso.o second/iso_util.o \ + second/fs_of.o second/fs_ext2.o second/fs_iso.o second/fs_swap.o \ + second/iso_util.o \ lib/nosys.o lib/string.o lib/strtol.o lib/vsprintf.o lib/ctype.o lib/malloc.o lib/strstr.o ifeq ($(USE_MD5_PASSWORDS),y) diff --git a/include/errors.h b/include/errors.h index e994dd5..c0a67ed 100644 --- a/include/errors.h +++ b/include/errors.h @@ -34,6 +34,7 @@ #define FILE_ERR_LENGTH -10 #define FILE_ERR_FSBUSY -11 #define FILE_ERR_BADDEV -12 +#define FILE_ERR_NOMEM -13 /* Device kind */ #define FILE_DEVICE_BLOCK 1 diff --git a/second/fs.c b/second/fs.c index b748bed..e7aeed0 100644 --- a/second/fs.c +++ b/second/fs.c @@ -27,6 +27,7 @@ extern const struct fs_t of_filesystem; extern const struct fs_t of_net_filesystem; extern const struct fs_t ext2_filesystem; +extern const struct fs_t swap_filesystem; //extern const struct fs_t iso_filesystem; /* Configurable filesystems */ @@ -41,6 +42,7 @@ extern const struct fs_t reiserfs_filesystem; /* Filesystem handlers yaboot knows about */ static const struct fs_t *block_filesystems[] = { + &swap_filesystem, /* swap signature checker */ &ext2_filesystem, /* ext2 */ #ifdef CONFIG_FS_XFS &xfs_filesystem, /* XFS */ diff --git a/second/fs_of.c b/second/fs_of.c index bd481e4..2e5feb9 100644 --- a/second/fs_of.c +++ b/second/fs_of.c @@ -92,8 +92,9 @@ of_open(struct boot_file_t* file, strncpy(buffer, fspec->dev, 768); strcat(buffer, ":"); if (part) { - if (part->sys_ind == LINUX_RAID) { - DEBUG_F("skipping because partition is marked LINUX_RAID\n"); + if (part->sys_ind == LINUX_RAID || part->sys_ind == LINUX_NATIVE) { + DEBUG_F("skipping because partition is tagged %08x\n", + part->sys_ind ); DEBUG_LEAVE(FILE_ERR_BAD_FSYS); return FILE_ERR_BAD_FSYS; } diff --git a/second/fs_swap.c b/second/fs_swap.c new file mode 100644 index 0000000..cfa5709 --- /dev/null +++ b/second/fs_swap.c @@ -0,0 +1,127 @@ +/* + * fs_swap.c - A filesystem driver to detect swapspace on a partition. + * + * Copyright 2009 Tony Breeds, IBM Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "ctype.h" +#include "types.h" +#include "stddef.h" +#include "stdlib.h" +#include "file.h" +#include "prom.h" +#include "string.h" +#include "partition.h" +#include "fs.h" +#include "errors.h" +#include "debug.h" +#include "bootinfo.h" + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +#define BLKCOUNT 2 + +static struct { + char *magic; + int len, offset; +} signatures[] = { + { "SWAP-SPACE", 10, 0xff6}, /* 4k Pages */ + { "SWAPSPACE2", 10, 0xff6}, + { "SWAP-SPACE", 10, 0xfff6}, /* 64k Pages */ + { "SWAPSPACE2", 10, 0xfff6}, +}; + +/* swap_open: Open a block device and look for swapspace magic. + * If we find a valid signature the retuning FILE_ERR_NOTFOUND means + * that no other filsystem drivers will check this partition */ +static int +swap_open(struct boot_file_t* file, struct partition_t* part, + struct boot_fspec_t* fspec) +{ + int i; + unsigned char *buffer; + /* Make static to move into the BSS rather then the stack */ + static unsigned char device_name[1024]; + + DEBUG_ENTER; + DEBUG_OPEN; + + if (file->device_kind != FILE_DEVICE_BLOCK || part == NULL) { + DEBUG_LEAVE(FILE_ERR_BADDEV); + return FILE_ERR_BADDEV; + } + + /* We assume that device is "short" and is correctly NULL terminsated */ + strncpy(device_name, fspec->dev, 1020); + if (_machine != _MACH_bplan) + strcat(device_name, ":0"); + + DEBUG_F("Opening device: %s\n", device_name); + file->of_device = prom_open(device_name); + if (file->of_device == NULL) { + DEBUG_LEAVE(FILE_IOERR); + return FILE_IOERR; + } + DEBUG_F("file->of_device = %p\n", file->of_device); + + /* If the signature is right on a block boundry we may need two blocks, + * so lets just allocate room for them now */ + buffer = malloc(sizeof(unsigned char) * part->blocksize * BLKCOUNT); + if (buffer == NULL) { + DEBUG_LEAVE("malloc for disk buffer failed\n"); + return FILE_ERR_NOMEM; + } + + for(i=0; i< ARRAY_SIZE(signatures); i++) { + int blk = part->part_start + (signatures[i].offset / part->blocksize); + int rc = prom_readblocks(file->of_device, blk, BLKCOUNT, buffer); + + /* FIXME: going past partition length */ + DEBUG_F("Looking for %s @ offset 0x%x, rc == %d, blk=0x%x\n", + signatures[i].magic, signatures[i].offset, rc, blk); + + if (memcmp(&buffer[signatures[i].offset % part->blocksize], + signatures[i].magic, signatures[i].len) == 0) { + free(buffer); + DEBUG_F("Found a swap signature\n"); + DEBUG_LEAVE(FILE_ERR_NOTFOUND); + return FILE_ERR_NOTFOUND; + } + } + + free(buffer); + prom_close(file->of_device); + file->of_device = NULL; + + DEBUG_LEAVE(FILE_ERR_BAD_FSYS); + return FILE_ERR_BAD_FSYS; +} + +struct fs_t swap_filesystem = +{ + "swap signature checker", + swap_open, + NULL, + NULL, + NULL, +}; + +/* + * Local variables: + * c-file-style: "k&r" + * c-basic-offset: 5 + * End: + */