/* * This routine tries to find a RAM disk image to load, and returns the * number of blocks to read for a non-compressed image, 0 if the image * is a compressed image, and -1 if an image with the right magic * numbers could not be found. * * We currently check for the following magic numbers: * minix * ext2 * romfs * cramfs * squashfs * gzip * bzip2 * lzma * xz * lzo * lz4
*/ staticint __init
identify_ramdisk_image(struct file *file, loff_t pos,
decompress_fn *decompressor)
{ constint size = 512; struct minix_super_block *minixsb; struct romfs_super_block *romfsb; struct cramfs_super *cramfsb; struct squashfs_super_block *squashfsb; int nblocks = -1; unsignedchar *buf; constchar *compress_name; unsignedlong n; int start_block = rd_image_start;
buf = kmalloc(size, GFP_KERNEL); if (!buf) return -ENOMEM;
/* * Read block 0 to test for compressed kernel
*/
pos = start_block * BLOCK_SIZE;
kernel_read(file, buf, size, &pos);
*decompressor = decompress_method(buf, size, &compress_name); if (compress_name) {
printk(KERN_NOTICE "RAMDISK: %s image found at block %d\n",
compress_name, start_block); if (!*decompressor)
printk(KERN_EMERG "RAMDISK: %s decompressor not configured!\n",
compress_name);
nblocks = 0; goto done;
}
/* romfs is at block zero too */ if (romfsb->word0 == ROMSB_WORD0 &&
romfsb->word1 == ROMSB_WORD1) {
printk(KERN_NOTICE "RAMDISK: romfs filesystem found at block %d\n",
start_block);
nblocks = (ntohl(romfsb->size)+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS; goto done;
}
if (cramfsb->magic == CRAMFS_MAGIC) {
printk(KERN_NOTICE "RAMDISK: cramfs filesystem found at block %d\n",
start_block);
nblocks = (cramfsb->size + BLOCK_SIZE - 1) >> BLOCK_SIZE_BITS; goto done;
}
/* 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;
}
/* * Read 512 bytes further to check if cramfs is padded
*/
pos = start_block * BLOCK_SIZE + 0x200;
kernel_read(file, buf, size, &pos);
if (cramfsb->magic == CRAMFS_MAGIC) {
printk(KERN_NOTICE "RAMDISK: cramfs filesystem found at block %d\n",
start_block);
nblocks = (cramfsb->size + BLOCK_SIZE - 1) >> BLOCK_SIZE_BITS; goto done;
}
/* * Read block 1 to test for minix and ext2 superblock
*/
pos = (start_block + 1) * BLOCK_SIZE;
kernel_read(file, buf, size, &pos);
/* Try minix */ if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
minixsb->s_magic == MINIX_SUPER_MAGIC2) {
printk(KERN_NOTICE "RAMDISK: Minix filesystem found at block %d\n",
start_block);
nblocks = minixsb->s_nzones << minixsb->s_log_zone_size; goto done;
}
/* Try ext2 */
n = ext2_image_size(buf); if (n) {
printk(KERN_NOTICE "RAMDISK: ext2 filesystem found at block %d\n",
start_block);
nblocks = n; goto done;
}
printk(KERN_NOTICE "RAMDISK: Couldn't find valid RAM disk image starting at %d.\n",
start_block);
if (nblocks == 0) { if (crd_load(decompressor) == 0) goto successful_load; goto done;
}
/* * NOTE NOTE: nblocks is not actually blocks but * the number of kibibytes of data to load into a ramdisk.
*/
rd_blocks = nr_blocks(out_file); if (nblocks > rd_blocks) {
printk("RAMDISK: image too big! (%dKiB/%ldKiB)\n",
nblocks, rd_blocks); goto done;
}
/* * OK, time to copy in the data
*/ if (strcmp(from, "/initrd.image") == 0)
devblocks = nblocks; else
devblocks = nr_blocks(in_file);
if (devblocks == 0) {
printk(KERN_ERR "RAMDISK: could not determine device size\n"); goto done;
}
buf = kmalloc(BLOCK_SIZE, GFP_KERNEL); if (!buf) {
printk(KERN_ERR "RAMDISK: could not allocate buffer\n"); goto done;
}
printk(KERN_NOTICE "RAMDISK: Loading %dKiB [%ld disk%s] into ram disk... ",
nblocks, ((nblocks-1)/devblocks)+1, nblocks>devblocks ? "s" : ""); for (i = 0; i < nblocks; i++) { if (i && (i % devblocks == 0)) {
pr_cont("done disk #1.\n");
rotate = 0;
fput(in_file); break;
}
kernel_read(in_file, buf, BLOCK_SIZE, &in_pos);
kernel_write(out_file, buf, BLOCK_SIZE, &out_pos); #if !defined(CONFIG_S390) if (!(i % 16)) {
pr_cont("%c\b", rotator[rotate & 0x3]);
rotate++;
} #endif
}
pr_cont("done.\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.