diff options
| -rw-r--r-- | init/do_mounts_rd.c | 82 |
1 files changed, 35 insertions, 47 deletions
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c index dcaeb1f90b32..9c9d7dbcf9ca 100644 --- a/init/do_mounts_rd.c +++ b/init/do_mounts_rd.c | |||
| @@ -43,13 +43,31 @@ static int __init crd_load(int in_fd, int out_fd, decompress_fn deco); | |||
| 43 | * numbers could not be found. | 43 | * numbers could not be found. |
| 44 | * | 44 | * |
| 45 | * We currently check for the following magic numbers: | 45 | * We currently check for the following magic numbers: |
| 46 | * minix | 46 | * minix |
| 47 | * ext2 | 47 | * ext2 |
| 48 | * romfs | 48 | * romfs |
| 49 | * cramfs | 49 | * cramfs |
| 50 | * gzip | 50 | * gzip |
| 51 | */ | 51 | */ |
| 52 | static int __init | 52 | static const struct compress_format { |
| 53 | unsigned char magic[2]; | ||
| 54 | const char *name; | ||
| 55 | decompress_fn decompressor; | ||
| 56 | } compressed_formats[] = { | ||
| 57 | #ifdef CONFIG_RD_GZIP | ||
| 58 | { {037, 0213}, "gzip", gunzip }, | ||
| 59 | { {037, 0236}, "gzip", gunzip }, | ||
| 60 | #endif | ||
| 61 | #ifdef CONFIG_RD_BZIP2 | ||
| 62 | { {0x42, 0x5a}, "bzip2", bunzip2 }, | ||
| 63 | #endif | ||
| 64 | #ifdef CONFIG_RD_LZMA | ||
| 65 | { {0x5d, 0x00}, "lzma", unlzma }, | ||
| 66 | #endif | ||
| 67 | { {0, 0}, NULL, NULL } | ||
| 68 | }; | ||
| 69 | |||
| 70 | static int __init | ||
| 53 | identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor) | 71 | identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor) |
| 54 | { | 72 | { |
| 55 | const int size = 512; | 73 | const int size = 512; |
| @@ -59,6 +77,7 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor) | |||
| 59 | struct cramfs_super *cramfsb; | 77 | struct cramfs_super *cramfsb; |
| 60 | int nblocks = -1; | 78 | int nblocks = -1; |
| 61 | unsigned char *buf; | 79 | unsigned char *buf; |
| 80 | const struct compress_format *cf; | ||
| 62 | 81 | ||
| 63 | buf = kmalloc(size, GFP_KERNEL); | 82 | buf = kmalloc(size, GFP_KERNEL); |
| 64 | if (!buf) | 83 | if (!buf) |
| @@ -71,52 +90,21 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor) | |||
| 71 | memset(buf, 0xe5, size); | 90 | memset(buf, 0xe5, size); |
| 72 | 91 | ||
| 73 | /* | 92 | /* |
| 74 | * Read block 0 to test for gzipped kernel | 93 | * Read block 0 to test for compressed kernel |
| 75 | */ | 94 | */ |
| 76 | sys_lseek(fd, start_block * BLOCK_SIZE, 0); | 95 | sys_lseek(fd, start_block * BLOCK_SIZE, 0); |
| 77 | sys_read(fd, buf, size); | 96 | sys_read(fd, buf, size); |
| 78 | 97 | ||
| 79 | #ifdef CONFIG_RD_GZIP | 98 | for (cf = compressed_formats; cf->decompressor; cf++) { |
| 80 | /* | 99 | if (buf[0] == cf->magic[0] && buf[1] == cf->magic[1]) { |
| 81 | * If it matches the gzip magic numbers, return 0 | 100 | printk(KERN_NOTICE |
| 82 | */ | 101 | "RAMDISK: %s image found at block %d\n", |
| 83 | if (buf[0] == 037 && ((buf[1] == 0213) || (buf[1] == 0236))) { | 102 | cf->name, start_block); |
| 84 | printk(KERN_NOTICE | 103 | *decompressor = cf->decompressor; |
| 85 | "RAMDISK: Compressed image found at block %d\n", | 104 | nblocks = 0; |
| 86 | start_block); | 105 | goto done; |
| 87 | *decompressor = gunzip; | 106 | } |
| 88 | nblocks = 0; | ||
| 89 | goto done; | ||
| 90 | } | ||
| 91 | #endif | ||
| 92 | |||
| 93 | #ifdef CONFIG_RD_BZIP2 | ||
| 94 | /* | ||
| 95 | * If it matches the bzip2 magic numbers, return -1 | ||
| 96 | */ | ||
| 97 | if (buf[0] == 0x42 && (buf[1] == 0x5a)) { | ||
| 98 | printk(KERN_NOTICE | ||
| 99 | "RAMDISK: Bzipped image found at block %d\n", | ||
| 100 | start_block); | ||
| 101 | *decompressor = bunzip2; | ||
| 102 | nblocks = 0; | ||
| 103 | goto done; | ||
| 104 | } | ||
| 105 | #endif | ||
| 106 | |||
| 107 | #ifdef CONFIG_RD_LZMA | ||
| 108 | /* | ||
| 109 | * If it matches the lzma magic numbers, return -1 | ||
| 110 | */ | ||
| 111 | if (buf[0] == 0x5d && (buf[1] == 0x00)) { | ||
| 112 | printk(KERN_NOTICE | ||
| 113 | "RAMDISK: Lzma image found at block %d\n", | ||
| 114 | start_block); | ||
| 115 | *decompressor = unlzma; | ||
| 116 | nblocks = 0; | ||
| 117 | goto done; | ||
| 118 | } | 107 | } |
| 119 | #endif | ||
| 120 | 108 | ||
| 121 | /* romfs is at block zero too */ | 109 | /* romfs is at block zero too */ |
| 122 | if (romfsb->word0 == ROMSB_WORD0 && | 110 | if (romfsb->word0 == ROMSB_WORD0 && |
| @@ -165,7 +153,7 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor) | |||
| 165 | printk(KERN_NOTICE | 153 | printk(KERN_NOTICE |
| 166 | "RAMDISK: Couldn't find valid RAM disk image starting at %d.\n", | 154 | "RAMDISK: Couldn't find valid RAM disk image starting at %d.\n", |
| 167 | start_block); | 155 | start_block); |
| 168 | 156 | ||
| 169 | done: | 157 | done: |
| 170 | sys_lseek(fd, start_block * BLOCK_SIZE, 0); | 158 | sys_lseek(fd, start_block * BLOCK_SIZE, 0); |
| 171 | kfree(buf); | 159 | kfree(buf); |
| @@ -224,7 +212,7 @@ int __init rd_load_image(char *from) | |||
| 224 | nblocks, rd_blocks); | 212 | nblocks, rd_blocks); |
| 225 | goto done; | 213 | goto done; |
| 226 | } | 214 | } |
| 227 | 215 | ||
| 228 | /* | 216 | /* |
| 229 | * OK, time to copy in the data | 217 | * OK, time to copy in the data |
| 230 | */ | 218 | */ |
