Add support for LZO compression in GRUB:
- import of minilzo library, - LZO decompression for btrfs, - lzop files decompression. * grub-core/io/lzopio.c: New file. * grub-core/lib/adler32.c: Likewise. * grub-core/lib/minilzo/lzoconf.h: Likewise. * grub-core/lib/minilzo/lzodefs.h: Likewise. * grub-core/lib/minilzo/minilzo.c: Likewise. * grub-core/lib/minilzo/minilzo.h: Likewise. * Makefile.util.def (libgrubmods.a): Add grub-core/io/lzopio.c, grub-core/lib/adler32.c, grub-core/io/lzopio.c, grub-core/lib/minilzo/minilzo.c to common. * Makefile.util.def (libgrubmods.a): Add flags required by minilzo to cflags in cppflags. * grub-core/Makefile.core.def (btrfs): Likewise. * grub-core/Makefile.core.def (lzopio): New module. (adler32): Likewise. * grub-core/fs/btrfs.c: Include minilzo.h. (GRUB_BTRFS_COMPRESSION_LZO): New define. (GRUB_BTRFS_LZO_BLOCK_SIZE): Likewise. (GRUB_BTRFS_LZO_BLOCK_MAX_CSIZE): Likewise. (grub_btrfs_lzo_decompress): New function. (grub_btrfs_extent_read): Add support for LZO compression type. * include/grub/types.h (GRUB_UCHAR_MAX): New define. (GRUB_USHRT_MAX): Likewise. (GRUB_UINT_MAX): Likewise. * grub-core/lib/posix_wrap/limits.h (USHRT_MAX): Likewise. (UINT_MAX): Likewise. (CHAR_BIT): Likewise. * grub-core/lib/posix_wrap/sys/types.h (ULONG_MAX): Moved to grub-core/lib/posix_wrap/limits.h (UCHAR_MAX): Likewise. * include/grub/file.h (grub_file_filter_id): New compression filter GRUB_FILE_FILTER_LZOPIO. * include/grub/file.h (grub_file_filter_id): Set GRUB_FILE_FILTER_LZOPIO as GRUB_FILE_FILTER_COMPRESSION_LAST. * include/grub/types.h (grub_get_unaligned16): New function. (grub_get_unaligned32): Likewise. (grub_get_unaligned64): Likewise. * util/import_gcry.py (cryptolist): Add adler32.
This commit is contained in:
commit
050e8e9080
15 changed files with 8010 additions and 101 deletions
45
ChangeLog
45
ChangeLog
|
@ -1,3 +1,48 @@
|
||||||
|
2011-10-06 Szymon Janc <szymon@janc.net.pl>
|
||||||
|
|
||||||
|
Add support for LZO compression in GRUB:
|
||||||
|
- import of minilzo library,
|
||||||
|
- LZO decompression for btrfs,
|
||||||
|
- lzop files decompression.
|
||||||
|
|
||||||
|
* grub-core/io/lzopio.c: New file.
|
||||||
|
* grub-core/lib/adler32.c: Likewise.
|
||||||
|
* grub-core/lib/minilzo/lzoconf.h: Likewise.
|
||||||
|
* grub-core/lib/minilzo/lzodefs.h: Likewise.
|
||||||
|
* grub-core/lib/minilzo/minilzo.c: Likewise.
|
||||||
|
* grub-core/lib/minilzo/minilzo.h: Likewise.
|
||||||
|
* Makefile.util.def (libgrubmods.a): Add grub-core/io/lzopio.c,
|
||||||
|
grub-core/lib/adler32.c, grub-core/io/lzopio.c,
|
||||||
|
grub-core/lib/minilzo/minilzo.c to common.
|
||||||
|
* Makefile.util.def (libgrubmods.a): Add flags required by minilzo to
|
||||||
|
cflags in cppflags.
|
||||||
|
* grub-core/Makefile.core.def (btrfs): Likewise.
|
||||||
|
* grub-core/Makefile.core.def (lzopio): New module.
|
||||||
|
(adler32): Likewise.
|
||||||
|
* grub-core/fs/btrfs.c: Include minilzo.h.
|
||||||
|
(GRUB_BTRFS_COMPRESSION_LZO): New define.
|
||||||
|
(GRUB_BTRFS_LZO_BLOCK_SIZE): Likewise.
|
||||||
|
(GRUB_BTRFS_LZO_BLOCK_MAX_CSIZE): Likewise.
|
||||||
|
(grub_btrfs_lzo_decompress): New function.
|
||||||
|
(grub_btrfs_extent_read): Add support for LZO compression type.
|
||||||
|
* include/grub/types.h (GRUB_UCHAR_MAX): New define.
|
||||||
|
(GRUB_USHRT_MAX): Likewise.
|
||||||
|
(GRUB_UINT_MAX): Likewise.
|
||||||
|
* grub-core/lib/posix_wrap/limits.h (USHRT_MAX): Likewise.
|
||||||
|
(UINT_MAX): Likewise.
|
||||||
|
(CHAR_BIT): Likewise.
|
||||||
|
* grub-core/lib/posix_wrap/sys/types.h (ULONG_MAX): Moved to
|
||||||
|
grub-core/lib/posix_wrap/limits.h
|
||||||
|
(UCHAR_MAX): Likewise.
|
||||||
|
* include/grub/file.h (grub_file_filter_id): New compression filter
|
||||||
|
GRUB_FILE_FILTER_LZOPIO.
|
||||||
|
* include/grub/file.h (grub_file_filter_id): Set
|
||||||
|
GRUB_FILE_FILTER_LZOPIO as GRUB_FILE_FILTER_COMPRESSION_LAST.
|
||||||
|
* include/grub/types.h (grub_get_unaligned16): New function.
|
||||||
|
(grub_get_unaligned32): Likewise.
|
||||||
|
(grub_get_unaligned64): Likewise.
|
||||||
|
* util/import_gcry.py (cryptolist): Add adler32.
|
||||||
|
|
||||||
2011-10-01 Ales Nesrsta <starous@volny.cz>
|
2011-10-01 Ales Nesrsta <starous@volny.cz>
|
||||||
|
|
||||||
* grub-core/bus/usb/uhci.c: Changes made by Rock Cui - thanks!
|
* grub-core/bus/usb/uhci.c: Changes made by Rock Cui - thanks!
|
||||||
|
|
|
@ -33,6 +33,8 @@ library = {
|
||||||
|
|
||||||
library = {
|
library = {
|
||||||
name = libgrubmods.a;
|
name = libgrubmods.a;
|
||||||
|
cflags = '$(CFLAGS_POSIX) -Wno-undef';
|
||||||
|
cppflags = '-I$(srcdir)/lib/posix_wrap -I$(top_srcdir)/grub-core/lib/minilzo -DMINILZO_HAVE_CONFIG_H';
|
||||||
|
|
||||||
common_nodist = grub_script.tab.c;
|
common_nodist = grub_script.tab.c;
|
||||||
common_nodist = grub_script.yy.c;
|
common_nodist = grub_script.yy.c;
|
||||||
|
@ -89,6 +91,7 @@ library = {
|
||||||
common = grub-core/lib/LzFind.c;
|
common = grub-core/lib/LzFind.c;
|
||||||
common = grub-core/lib/LzmaEnc.c;
|
common = grub-core/lib/LzmaEnc.c;
|
||||||
common = grub-core/lib/crc.c;
|
common = grub-core/lib/crc.c;
|
||||||
|
common = grub-core/lib/adler32.c;
|
||||||
common = grub-core/normal/datetime.c;
|
common = grub-core/normal/datetime.c;
|
||||||
common = grub-core/normal/misc.c;
|
common = grub-core/normal/misc.c;
|
||||||
common = grub-core/partmap/acorn.c;
|
common = grub-core/partmap/acorn.c;
|
||||||
|
@ -106,7 +109,9 @@ library = {
|
||||||
common = grub-core/script/script.c;
|
common = grub-core/script/script.c;
|
||||||
common = grub-core/script/argv.c;
|
common = grub-core/script/argv.c;
|
||||||
common = grub-core/io/gzio.c;
|
common = grub-core/io/gzio.c;
|
||||||
|
common = grub-core/io/lzopio.c;
|
||||||
common = grub-core/kern/ia64/dl_helper.c;
|
common = grub-core/kern/ia64/dl_helper.c;
|
||||||
|
common = grub-core/lib/minilzo/minilzo.c;
|
||||||
};
|
};
|
||||||
|
|
||||||
program = {
|
program = {
|
||||||
|
|
|
@ -985,6 +985,8 @@ module = {
|
||||||
name = btrfs;
|
name = btrfs;
|
||||||
common = fs/btrfs.c;
|
common = fs/btrfs.c;
|
||||||
common = lib/crc.c;
|
common = lib/crc.c;
|
||||||
|
cflags = '$(CFLAGS_POSIX) -Wno-undef';
|
||||||
|
cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/minilzo -DMINILZO_HAVE_CONFIG_H';
|
||||||
};
|
};
|
||||||
|
|
||||||
module = {
|
module = {
|
||||||
|
@ -1652,6 +1654,14 @@ module = {
|
||||||
cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed';
|
cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/xzembed';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module = {
|
||||||
|
name = lzopio;
|
||||||
|
common = io/lzopio.c;
|
||||||
|
common = lib/minilzo/minilzo.c;
|
||||||
|
cflags = '$(CFLAGS_POSIX) -Wno-undef';
|
||||||
|
cppflags = '-I$(srcdir)/lib/posix_wrap -I$(srcdir)/lib/minilzo -DMINILZO_HAVE_CONFIG_H';
|
||||||
|
};
|
||||||
|
|
||||||
module = {
|
module = {
|
||||||
name = testload;
|
name = testload;
|
||||||
common = commands/testload.c;
|
common = commands/testload.c;
|
||||||
|
@ -1679,3 +1689,8 @@ module = {
|
||||||
common = commands/cacheinfo.c;
|
common = commands/cacheinfo.c;
|
||||||
condition = COND_ENABLE_CACHE_STATS;
|
condition = COND_ENABLE_CACHE_STATS;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module = {
|
||||||
|
name = adler32;
|
||||||
|
common = lib/adler32.c;
|
||||||
|
};
|
||||||
|
|
|
@ -26,11 +26,23 @@
|
||||||
#include <grub/types.h>
|
#include <grub/types.h>
|
||||||
#include <grub/lib/crc.h>
|
#include <grub/lib/crc.h>
|
||||||
#include <grub/deflate.h>
|
#include <grub/deflate.h>
|
||||||
|
#include <minilzo.h>
|
||||||
|
|
||||||
GRUB_MOD_LICENSE ("GPLv3+");
|
GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
|
|
||||||
#define GRUB_BTRFS_SIGNATURE "_BHRfS_M"
|
#define GRUB_BTRFS_SIGNATURE "_BHRfS_M"
|
||||||
|
|
||||||
|
/* From http://www.oberhumer.com/opensource/lzo/lzofaq.php
|
||||||
|
* LZO will expand incompressible data by a little amount. I still haven't
|
||||||
|
* computed the exact values, but I suggest using these formulas for
|
||||||
|
* a worst-case expansion calculation:
|
||||||
|
*
|
||||||
|
* output_block_size = input_block_size + (input_block_size / 16) + 64 + 3
|
||||||
|
* */
|
||||||
|
#define GRUB_BTRFS_LZO_BLOCK_SIZE 4096
|
||||||
|
#define GRUB_BTRFS_LZO_BLOCK_MAX_CSIZE (GRUB_BTRFS_LZO_BLOCK_SIZE + \
|
||||||
|
(GRUB_BTRFS_LZO_BLOCK_SIZE / 16) + 64 + 3)
|
||||||
|
|
||||||
typedef grub_uint8_t grub_btrfs_checksum_t[0x20];
|
typedef grub_uint8_t grub_btrfs_checksum_t[0x20];
|
||||||
typedef grub_uint16_t grub_btrfs_uuid_t[8];
|
typedef grub_uint16_t grub_btrfs_uuid_t[8];
|
||||||
|
|
||||||
|
@ -160,7 +172,8 @@ struct grub_btrfs_leaf_descriptor
|
||||||
{
|
{
|
||||||
unsigned depth;
|
unsigned depth;
|
||||||
unsigned allocated;
|
unsigned allocated;
|
||||||
struct {
|
struct
|
||||||
|
{
|
||||||
grub_disk_addr_t addr;
|
grub_disk_addr_t addr;
|
||||||
unsigned iter;
|
unsigned iter;
|
||||||
unsigned maxiter;
|
unsigned maxiter;
|
||||||
|
@ -179,7 +192,7 @@ struct grub_btrfs_time
|
||||||
{
|
{
|
||||||
grub_int64_t sec;
|
grub_int64_t sec;
|
||||||
grub_uint32_t nanosec;
|
grub_uint32_t nanosec;
|
||||||
} __attribute__ ((aligned(4)));
|
} __attribute__ ((aligned (4)));
|
||||||
|
|
||||||
struct grub_btrfs_inode
|
struct grub_btrfs_inode
|
||||||
{
|
{
|
||||||
|
@ -215,12 +228,13 @@ struct grub_btrfs_extent_data
|
||||||
|
|
||||||
#define GRUB_BTRFS_COMPRESSION_NONE 0
|
#define GRUB_BTRFS_COMPRESSION_NONE 0
|
||||||
#define GRUB_BTRFS_COMPRESSION_ZLIB 1
|
#define GRUB_BTRFS_COMPRESSION_ZLIB 1
|
||||||
|
#define GRUB_BTRFS_COMPRESSION_LZO 2
|
||||||
|
|
||||||
#define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100
|
#define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100
|
||||||
|
|
||||||
static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2,
|
static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2,
|
||||||
256 * 1048576 * 2,
|
256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2
|
||||||
1048576ULL * 1048576ULL * 2 };
|
};
|
||||||
|
|
||||||
static grub_err_t
|
static grub_err_t
|
||||||
grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
||||||
|
@ -307,7 +321,7 @@ save_ref (struct grub_btrfs_leaf_descriptor *desc,
|
||||||
static int
|
static int
|
||||||
next (struct grub_btrfs_data *data,
|
next (struct grub_btrfs_data *data,
|
||||||
struct grub_btrfs_leaf_descriptor *desc,
|
struct grub_btrfs_leaf_descriptor *desc,
|
||||||
grub_disk_addr_t *outaddr, grub_size_t *outsize,
|
grub_disk_addr_t * outaddr, grub_size_t * outsize,
|
||||||
struct grub_btrfs_key *key_out)
|
struct grub_btrfs_key *key_out)
|
||||||
{
|
{
|
||||||
grub_err_t err;
|
grub_err_t err;
|
||||||
|
@ -330,13 +344,13 @@ next (struct grub_btrfs_data *data,
|
||||||
err = grub_btrfs_read_logical (data, desc->data[desc->depth - 1].iter
|
err = grub_btrfs_read_logical (data, desc->data[desc->depth - 1].iter
|
||||||
* sizeof (node)
|
* sizeof (node)
|
||||||
+ sizeof (struct btrfs_header)
|
+ sizeof (struct btrfs_header)
|
||||||
+ desc->data[desc->depth - 1].addr, &node,
|
+ desc->data[desc->depth - 1].addr,
|
||||||
sizeof (node));
|
&node, sizeof (node));
|
||||||
if (err)
|
if (err)
|
||||||
return -err;
|
return -err;
|
||||||
|
|
||||||
err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (node.addr), &head,
|
err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (node.addr),
|
||||||
sizeof (head));
|
&head, sizeof (head));
|
||||||
if (err)
|
if (err)
|
||||||
return -err;
|
return -err;
|
||||||
|
|
||||||
|
@ -410,7 +424,8 @@ lower_bound (struct grub_btrfs_data *data,
|
||||||
grub_dprintf ("btrfs",
|
grub_dprintf ("btrfs",
|
||||||
"internal node (depth %d) %" PRIxGRUB_UINT64_T
|
"internal node (depth %d) %" PRIxGRUB_UINT64_T
|
||||||
" %x %" PRIxGRUB_UINT64_T "\n", depth,
|
" %x %" PRIxGRUB_UINT64_T "\n", depth,
|
||||||
node.key.object_id, node.key.type, node.key.offset);
|
node.key.object_id, node.key.type,
|
||||||
|
node.key.offset);
|
||||||
|
|
||||||
if (key_cmp (&node.key, key_in) == 0)
|
if (key_cmp (&node.key, key_in) == 0)
|
||||||
{
|
{
|
||||||
|
@ -433,7 +448,7 @@ lower_bound (struct grub_btrfs_data *data,
|
||||||
err = GRUB_ERR_NONE;
|
err = GRUB_ERR_NONE;
|
||||||
if (desc)
|
if (desc)
|
||||||
err = save_ref (desc, addr - sizeof (head), i - 1,
|
err = save_ref (desc, addr - sizeof (head), i - 1,
|
||||||
grub_le_to_cpu32 (head.nitems), 0);
|
grub_le_to_cpu32 (head.nitems), 0);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
addr = grub_le_to_cpu64 (node_last.addr);
|
addr = grub_le_to_cpu64 (node_last.addr);
|
||||||
|
@ -465,7 +480,7 @@ lower_bound (struct grub_btrfs_data *data,
|
||||||
|
|
||||||
if (key_cmp (&leaf.key, key_in) == 0)
|
if (key_cmp (&leaf.key, key_in) == 0)
|
||||||
{
|
{
|
||||||
grub_memcpy (key_out, &leaf.key, sizeof(*key_out));
|
grub_memcpy (key_out, &leaf.key, sizeof (*key_out));
|
||||||
*outsize = grub_le_to_cpu32 (leaf.size);
|
*outsize = grub_le_to_cpu32 (leaf.size);
|
||||||
*outaddr = addr + grub_le_to_cpu32 (leaf.offset);
|
*outaddr = addr + grub_le_to_cpu32 (leaf.offset);
|
||||||
if (desc)
|
if (desc)
|
||||||
|
@ -483,7 +498,7 @@ lower_bound (struct grub_btrfs_data *data,
|
||||||
|
|
||||||
if (have_last)
|
if (have_last)
|
||||||
{
|
{
|
||||||
grub_memcpy (key_out, &leaf_last.key, sizeof(*key_out));
|
grub_memcpy (key_out, &leaf_last.key, sizeof (*key_out));
|
||||||
*outsize = grub_le_to_cpu32 (leaf_last.size);
|
*outsize = grub_le_to_cpu32 (leaf_last.size);
|
||||||
*outaddr = addr + grub_le_to_cpu32 (leaf_last.offset);
|
*outaddr = addr + grub_le_to_cpu32 (leaf_last.offset);
|
||||||
if (desc)
|
if (desc)
|
||||||
|
@ -503,8 +518,7 @@ lower_bound (struct grub_btrfs_data *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
static grub_device_t
|
static grub_device_t
|
||||||
find_device (struct grub_btrfs_data *data, grub_uint64_t id,
|
find_device (struct grub_btrfs_data *data, grub_uint64_t id, int do_rescan)
|
||||||
int do_rescan)
|
|
||||||
{
|
{
|
||||||
grub_device_t dev_found = NULL;
|
grub_device_t dev_found = NULL;
|
||||||
auto int hook (const char *name);
|
auto int hook (const char *name);
|
||||||
|
@ -579,8 +593,7 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id,
|
||||||
}
|
}
|
||||||
|
|
||||||
static grub_err_t
|
static grub_err_t
|
||||||
grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
|
||||||
grub_disk_addr_t addr,
|
|
||||||
void *buf, grub_size_t size)
|
void *buf, grub_size_t size)
|
||||||
{
|
{
|
||||||
while (size > 0)
|
while (size > 0)
|
||||||
|
@ -601,15 +614,15 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
||||||
addr);
|
addr);
|
||||||
for (ptr = data->sblock.bootstrap_mapping;
|
for (ptr = data->sblock.bootstrap_mapping;
|
||||||
ptr < data->sblock.bootstrap_mapping
|
ptr < data->sblock.bootstrap_mapping
|
||||||
+ sizeof (data->sblock.bootstrap_mapping)
|
+ sizeof (data->sblock.bootstrap_mapping)
|
||||||
- sizeof (struct grub_btrfs_key);
|
- sizeof (struct grub_btrfs_key);)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
key = (struct grub_btrfs_key *) ptr;
|
key = (struct grub_btrfs_key *) ptr;
|
||||||
if (key->type != GRUB_BTRFS_ITEM_TYPE_CHUNK)
|
if (key->type != GRUB_BTRFS_ITEM_TYPE_CHUNK)
|
||||||
break;
|
break;
|
||||||
chunk = (struct grub_btrfs_chunk_item *) (key + 1);
|
chunk = (struct grub_btrfs_chunk_item *) (key + 1);
|
||||||
grub_dprintf ("btrfs", "%" PRIxGRUB_UINT64_T " %" PRIxGRUB_UINT64_T " \n",
|
grub_dprintf ("btrfs",
|
||||||
|
"%" PRIxGRUB_UINT64_T " %" PRIxGRUB_UINT64_T " \n",
|
||||||
grub_le_to_cpu64 (key->offset),
|
grub_le_to_cpu64 (key->offset),
|
||||||
grub_le_to_cpu64 (chunk->size));
|
grub_le_to_cpu64 (chunk->size));
|
||||||
if (grub_le_to_cpu64 (key->offset) <= addr
|
if (grub_le_to_cpu64 (key->offset) <= addr
|
||||||
|
@ -707,8 +720,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
||||||
|
|
||||||
high = grub_divmod64 (middle, grub_le_to_cpu16 (chunk->nstripes),
|
high = grub_divmod64 (middle, grub_le_to_cpu16 (chunk->nstripes),
|
||||||
&stripen);
|
&stripen);
|
||||||
stripe_offset = low + grub_le_to_cpu64 (chunk->stripe_length)
|
stripe_offset =
|
||||||
* high;
|
low + grub_le_to_cpu64 (chunk->stripe_length) * high;
|
||||||
csize = grub_le_to_cpu64 (chunk->stripe_length) - low;
|
csize = grub_le_to_cpu64 (chunk->stripe_length) - low;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -759,7 +772,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
||||||
paddr = stripe->offset + stripe_offset;
|
paddr = stripe->offset + stripe_offset;
|
||||||
|
|
||||||
grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
|
grub_dprintf ("btrfs", "chunk 0x%" PRIxGRUB_UINT64_T
|
||||||
"+0x%" PRIxGRUB_UINT64_T " (%d stripes (%d substripes) of %"
|
"+0x%" PRIxGRUB_UINT64_T
|
||||||
|
" (%d stripes (%d substripes) of %"
|
||||||
PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT64_T
|
PRIxGRUB_UINT64_T ") stripe %" PRIxGRUB_UINT64_T
|
||||||
" maps to 0x%" PRIxGRUB_UINT64_T "\n",
|
" maps to 0x%" PRIxGRUB_UINT64_T "\n",
|
||||||
grub_le_to_cpu64 (key->offset),
|
grub_le_to_cpu64 (key->offset),
|
||||||
|
@ -769,7 +783,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
|
||||||
grub_le_to_cpu64 (chunk->stripe_length),
|
grub_le_to_cpu64 (chunk->stripe_length),
|
||||||
stripen, stripe->offset);
|
stripen, stripe->offset);
|
||||||
grub_dprintf ("btrfs", "reading paddr 0x%" PRIxGRUB_UINT64_T
|
grub_dprintf ("btrfs", "reading paddr 0x%" PRIxGRUB_UINT64_T
|
||||||
" for laddr 0x%" PRIxGRUB_UINT64_T"\n", paddr,
|
" for laddr 0x%" PRIxGRUB_UINT64_T "\n", paddr,
|
||||||
addr);
|
addr);
|
||||||
|
|
||||||
dev = find_device (data, stripe->device_id, j);
|
dev = find_device (data, stripe->device_id, j);
|
||||||
|
@ -815,7 +829,7 @@ grub_btrfs_mount (grub_device_t dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
data = grub_zalloc (sizeof (*data));
|
data = grub_zalloc (sizeof (*data));
|
||||||
if (! data)
|
if (!data)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = read_sblock (dev->disk, &data->sblock);
|
err = read_sblock (dev->disk, &data->sblock);
|
||||||
|
@ -866,8 +880,7 @@ grub_btrfs_read_inode (struct grub_btrfs_data *data,
|
||||||
key_in.type = GRUB_BTRFS_ITEM_TYPE_INODE_ITEM;
|
key_in.type = GRUB_BTRFS_ITEM_TYPE_INODE_ITEM;
|
||||||
key_in.offset = 0;
|
key_in.offset = 0;
|
||||||
|
|
||||||
err = lower_bound (data, &key_in, &key_out, tree,
|
err = lower_bound (data, &key_in, &key_out, tree, &elemaddr, &elemsize, NULL);
|
||||||
&elemaddr, &elemsize, NULL);
|
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
if (num != key_out.object_id
|
if (num != key_out.object_id
|
||||||
|
@ -877,6 +890,76 @@ grub_btrfs_read_inode (struct grub_btrfs_data *data,
|
||||||
return grub_btrfs_read_logical (data, elemaddr, inode, sizeof (*inode));
|
return grub_btrfs_read_logical (data, elemaddr, inode, sizeof (*inode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static grub_ssize_t
|
||||||
|
grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off,
|
||||||
|
char *obuf, grub_size_t osize)
|
||||||
|
{
|
||||||
|
grub_uint32_t total_size, cblock_size, ret = 0;
|
||||||
|
unsigned char buf[GRUB_BTRFS_LZO_BLOCK_SIZE];
|
||||||
|
|
||||||
|
total_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf));
|
||||||
|
ibuf += sizeof (total_size);
|
||||||
|
|
||||||
|
if (isize < total_size)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Jump forward to first block with requested data. */
|
||||||
|
while (off >= GRUB_BTRFS_LZO_BLOCK_SIZE)
|
||||||
|
{
|
||||||
|
cblock_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf));
|
||||||
|
ibuf += sizeof (cblock_size);
|
||||||
|
|
||||||
|
if (cblock_size > GRUB_BTRFS_LZO_BLOCK_MAX_CSIZE)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
off -= GRUB_BTRFS_LZO_BLOCK_SIZE;
|
||||||
|
ibuf += cblock_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (osize > 0)
|
||||||
|
{
|
||||||
|
lzo_uint usize = GRUB_BTRFS_LZO_BLOCK_SIZE;
|
||||||
|
|
||||||
|
cblock_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf));
|
||||||
|
ibuf += sizeof (cblock_size);
|
||||||
|
|
||||||
|
if (cblock_size > GRUB_BTRFS_LZO_BLOCK_MAX_CSIZE)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Block partially filled with requested data. */
|
||||||
|
if (off > 0 || osize < GRUB_BTRFS_LZO_BLOCK_SIZE)
|
||||||
|
{
|
||||||
|
grub_size_t to_copy = grub_min(osize, GRUB_BTRFS_LZO_BLOCK_SIZE - off);
|
||||||
|
|
||||||
|
if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, buf, &usize,
|
||||||
|
NULL) != LZO_E_OK)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
to_copy = grub_min(to_copy, usize);
|
||||||
|
grub_memcpy(obuf, buf + off, to_copy);
|
||||||
|
|
||||||
|
osize -= to_copy;
|
||||||
|
ret += to_copy;
|
||||||
|
obuf += to_copy;
|
||||||
|
ibuf += cblock_size;
|
||||||
|
off = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Decompress whole block directly to output buffer. */
|
||||||
|
if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, (lzo_bytep)obuf,
|
||||||
|
&usize, NULL) != LZO_E_OK)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
osize -= usize;
|
||||||
|
ret += usize;
|
||||||
|
obuf += usize;
|
||||||
|
ibuf += cblock_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static grub_ssize_t
|
static grub_ssize_t
|
||||||
grub_btrfs_extent_read (struct grub_btrfs_data *data,
|
grub_btrfs_extent_read (struct grub_btrfs_data *data,
|
||||||
grub_uint64_t ino, grub_uint64_t tree,
|
grub_uint64_t ino, grub_uint64_t tree,
|
||||||
|
@ -917,19 +1000,17 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
|
||||||
if (!data->extent)
|
if (!data->extent)
|
||||||
return grub_errno;
|
return grub_errno;
|
||||||
|
|
||||||
err = grub_btrfs_read_logical (data, elemaddr,
|
err = grub_btrfs_read_logical (data, elemaddr, data->extent,
|
||||||
data->extent, elemsize);
|
elemsize);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
data->extend = data->extstart
|
data->extend = data->extstart + grub_le_to_cpu64 (data->extent->size);
|
||||||
+ grub_le_to_cpu64 (data->extent->size);
|
|
||||||
if (data->extent->type == GRUB_BTRFS_EXTENT_REGULAR
|
if (data->extent->type == GRUB_BTRFS_EXTENT_REGULAR
|
||||||
&& (char *) &data->extent + elemsize
|
&& (char *) &data->extent + elemsize
|
||||||
>= (char *) &data->extent->filled
|
>= (char *) &data->extent->filled + sizeof (data->extent->filled))
|
||||||
+ sizeof (data->extent->filled))
|
data->extend =
|
||||||
data->extend = data->extstart
|
data->extstart + grub_le_to_cpu64 (data->extent->filled);
|
||||||
+ grub_le_to_cpu64 (data->extent->filled);
|
|
||||||
|
|
||||||
grub_dprintf ("btrfs", "extent 0x%" PRIxGRUB_UINT64_T "+0x%"
|
grub_dprintf ("btrfs", "extent 0x%" PRIxGRUB_UINT64_T "+0x%"
|
||||||
PRIxGRUB_UINT64_T " (0x%"
|
PRIxGRUB_UINT64_T " (0x%"
|
||||||
|
@ -956,7 +1037,8 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->extent->compression != GRUB_BTRFS_COMPRESSION_NONE
|
if (data->extent->compression != GRUB_BTRFS_COMPRESSION_NONE
|
||||||
&& data->extent->compression != GRUB_BTRFS_COMPRESSION_ZLIB)
|
&& data->extent->compression != GRUB_BTRFS_COMPRESSION_ZLIB
|
||||||
|
&& data->extent->compression != GRUB_BTRFS_COMPRESSION_LZO)
|
||||||
{
|
{
|
||||||
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||||
"compression type 0x%x not supported",
|
"compression type 0x%x not supported",
|
||||||
|
@ -966,8 +1048,7 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
|
||||||
|
|
||||||
if (data->extent->encoding)
|
if (data->extent->encoding)
|
||||||
{
|
{
|
||||||
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "encoding not supported");
|
||||||
"encoding not supported");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -983,6 +1064,15 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
|
||||||
!= (grub_ssize_t) csize)
|
!= (grub_ssize_t) csize)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_LZO)
|
||||||
|
{
|
||||||
|
if (grub_btrfs_lzo_decompress(data->extent->inl, data->extsize -
|
||||||
|
((grub_uint8_t *) data->extent->inl
|
||||||
|
- (grub_uint8_t *) data->extent),
|
||||||
|
extoff, buf, csize)
|
||||||
|
!= (grub_ssize_t) csize)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
grub_memcpy (buf, data->extent->inl + extoff, csize);
|
grub_memcpy (buf, data->extent->inl + extoff, csize);
|
||||||
break;
|
break;
|
||||||
|
@ -992,10 +1082,13 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
|
||||||
grub_memset (buf, 0, csize);
|
grub_memset (buf, 0, csize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (data->extent->compression == GRUB_BTRFS_COMPRESSION_ZLIB)
|
|
||||||
|
if (data->extent->compression != GRUB_BTRFS_COMPRESSION_NONE)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
grub_uint64_t zsize;
|
grub_uint64_t zsize;
|
||||||
|
grub_ssize_t ret;
|
||||||
|
|
||||||
zsize = grub_le_to_cpu64 (data->extent->compressed_size);
|
zsize = grub_le_to_cpu64 (data->extent->compressed_size);
|
||||||
tmp = grub_malloc (zsize);
|
tmp = grub_malloc (zsize);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
|
@ -1008,21 +1101,29 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
|
||||||
grub_free (tmp);
|
grub_free (tmp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (grub_zlib_decompress (tmp, zsize, extoff
|
|
||||||
+ grub_le_to_cpu64 (data->extent->offset),
|
if (data->extent->compression == GRUB_BTRFS_COMPRESSION_ZLIB)
|
||||||
buf, csize) != (grub_ssize_t) csize)
|
ret = grub_zlib_decompress (tmp, zsize, extoff
|
||||||
{
|
+ grub_le_to_cpu64 (data->extent->offset),
|
||||||
grub_free (tmp);
|
buf, csize);
|
||||||
return -1;
|
else if (data->extent->compression == GRUB_BTRFS_COMPRESSION_LZO)
|
||||||
}
|
ret = grub_btrfs_lzo_decompress (tmp, zsize, extoff
|
||||||
|
+ grub_le_to_cpu64 (data->extent->offset),
|
||||||
|
buf, csize);
|
||||||
|
else
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
grub_free (tmp);
|
grub_free (tmp);
|
||||||
|
|
||||||
|
if (ret != (grub_ssize_t) csize)
|
||||||
|
return -1;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
err = grub_btrfs_read_logical (data,
|
err = grub_btrfs_read_logical (data,
|
||||||
grub_le_to_cpu64 (data->extent->laddr)
|
grub_le_to_cpu64 (data->extent->laddr)
|
||||||
+ grub_le_to_cpu64 (data->extent->offset)
|
+ grub_le_to_cpu64 (data->extent->offset)
|
||||||
+ extoff,
|
+ extoff, buf, csize);
|
||||||
buf, csize);
|
|
||||||
if (err)
|
if (err)
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
|
@ -1097,8 +1198,8 @@ find_path (struct grub_btrfs_data *data,
|
||||||
key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
|
key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
|
||||||
key->offset = grub_cpu_to_le64 (~grub_getcrc32c (1, ctoken, ctokenlen));
|
key->offset = grub_cpu_to_le64 (~grub_getcrc32c (1, ctoken, ctokenlen));
|
||||||
|
|
||||||
err = lower_bound (data, key, &key_out, *tree,
|
err = lower_bound (data, key, &key_out, *tree, &elemaddr, &elemsize,
|
||||||
&elemaddr, &elemsize, NULL);
|
NULL);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
grub_free (direl);
|
grub_free (direl);
|
||||||
|
@ -1140,7 +1241,7 @@ find_path (struct grub_btrfs_data *data,
|
||||||
|
|
||||||
for (cdirel = direl;
|
for (cdirel = direl;
|
||||||
(grub_uint8_t *) cdirel - (grub_uint8_t *) direl
|
(grub_uint8_t *) cdirel - (grub_uint8_t *) direl
|
||||||
< (grub_ssize_t) elemsize;
|
< (grub_ssize_t) elemsize;
|
||||||
cdirel = (void *) ((grub_uint8_t *) (direl + 1)
|
cdirel = (void *) ((grub_uint8_t *) (direl + 1)
|
||||||
+ grub_le_to_cpu16 (cdirel->n)
|
+ grub_le_to_cpu16 (cdirel->n)
|
||||||
+ grub_le_to_cpu16 (cdirel->m)))
|
+ grub_le_to_cpu16 (cdirel->m)))
|
||||||
|
@ -1247,8 +1348,7 @@ find_path (struct grub_btrfs_data *data,
|
||||||
grub_free (origpath);
|
grub_free (origpath);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
err = grub_btrfs_read_logical (data, elemaddr,
|
err = grub_btrfs_read_logical (data, elemaddr, &ri, sizeof (ri));
|
||||||
&ri, sizeof (ri));
|
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
grub_free (direl);
|
grub_free (direl);
|
||||||
|
@ -1290,8 +1390,8 @@ find_path (struct grub_btrfs_data *data,
|
||||||
|
|
||||||
static grub_err_t
|
static grub_err_t
|
||||||
grub_btrfs_dir (grub_device_t device, const char *path,
|
grub_btrfs_dir (grub_device_t device, const char *path,
|
||||||
int (*hook) (const char *filename,
|
int (*hook) (const char *filename,
|
||||||
const struct grub_dirhook_info *info))
|
const struct grub_dirhook_info *info))
|
||||||
{
|
{
|
||||||
struct grub_btrfs_data *data = grub_btrfs_mount (device);
|
struct grub_btrfs_data *data = grub_btrfs_mount (device);
|
||||||
struct grub_btrfs_key key_in, key_out;
|
struct grub_btrfs_key key_in, key_out;
|
||||||
|
@ -1314,8 +1414,7 @@ grub_btrfs_dir (grub_device_t device, const char *path,
|
||||||
if (type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY)
|
if (type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY)
|
||||||
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
|
return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
|
||||||
|
|
||||||
err = lower_bound (data, &key_in, &key_out, tree,
|
err = lower_bound (data, &key_in, &key_out, tree, &elemaddr, &elemsize, &desc);
|
||||||
&elemaddr, &elemsize, &desc);
|
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
if (key_out.type != GRUB_BTRFS_ITEM_TYPE_DIR_ITEM
|
if (key_out.type != GRUB_BTRFS_ITEM_TYPE_DIR_ITEM
|
||||||
|
@ -1355,7 +1454,7 @@ grub_btrfs_dir (grub_device_t device, const char *path,
|
||||||
|
|
||||||
for (cdirel = direl;
|
for (cdirel = direl;
|
||||||
(grub_uint8_t *) cdirel - (grub_uint8_t *) direl
|
(grub_uint8_t *) cdirel - (grub_uint8_t *) direl
|
||||||
< (grub_ssize_t) elemsize;
|
< (grub_ssize_t) elemsize;
|
||||||
cdirel = (void *) ((grub_uint8_t *) (direl + 1)
|
cdirel = (void *) ((grub_uint8_t *) (direl + 1)
|
||||||
+ grub_le_to_cpu16 (cdirel->n)
|
+ grub_le_to_cpu16 (cdirel->n)
|
||||||
+ grub_le_to_cpu16 (cdirel->m)))
|
+ grub_le_to_cpu16 (cdirel->m)))
|
||||||
|
@ -1384,7 +1483,7 @@ grub_btrfs_dir (grub_device_t device, const char *path,
|
||||||
}
|
}
|
||||||
while (r > 0);
|
while (r > 0);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
grub_free (direl);
|
grub_free (direl);
|
||||||
|
|
||||||
free_iterator (&desc);
|
free_iterator (&desc);
|
||||||
|
@ -1456,7 +1555,7 @@ grub_btrfs_uuid (grub_device_t device, char **uuid)
|
||||||
*uuid = NULL;
|
*uuid = NULL;
|
||||||
|
|
||||||
data = grub_btrfs_mount (device);
|
data = grub_btrfs_mount (device);
|
||||||
if (! data)
|
if (!data)
|
||||||
return grub_errno;
|
return grub_errno;
|
||||||
|
|
||||||
*uuid = grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
|
*uuid = grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
|
||||||
|
@ -1482,7 +1581,7 @@ grub_btrfs_label (grub_device_t device, char **label)
|
||||||
*label = NULL;
|
*label = NULL;
|
||||||
|
|
||||||
data = grub_btrfs_mount (device);
|
data = grub_btrfs_mount (device);
|
||||||
if (! data)
|
if (!data)
|
||||||
return grub_errno;
|
return grub_errno;
|
||||||
|
|
||||||
*label = grub_strndup (data->sblock.label, sizeof (data->sblock.label));
|
*label = grub_strndup (data->sblock.label, sizeof (data->sblock.label));
|
||||||
|
@ -1492,26 +1591,25 @@ grub_btrfs_label (grub_device_t device, char **label)
|
||||||
return grub_errno;
|
return grub_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct grub_fs grub_btrfs_fs =
|
static struct grub_fs grub_btrfs_fs = {
|
||||||
{
|
.name = "btrfs",
|
||||||
.name = "btrfs",
|
.dir = grub_btrfs_dir,
|
||||||
.dir = grub_btrfs_dir,
|
.open = grub_btrfs_open,
|
||||||
.open = grub_btrfs_open,
|
.read = grub_btrfs_read,
|
||||||
.read = grub_btrfs_read,
|
.close = grub_btrfs_close,
|
||||||
.close = grub_btrfs_close,
|
.uuid = grub_btrfs_uuid,
|
||||||
.uuid = grub_btrfs_uuid,
|
.label = grub_btrfs_label,
|
||||||
.label = grub_btrfs_label,
|
|
||||||
#ifdef GRUB_UTIL
|
#ifdef GRUB_UTIL
|
||||||
.reserved_first_sector = 1,
|
.reserved_first_sector = 1,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
GRUB_MOD_INIT(btrfs)
|
GRUB_MOD_INIT (btrfs)
|
||||||
{
|
{
|
||||||
grub_fs_register (&grub_btrfs_fs);
|
grub_fs_register (&grub_btrfs_fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
GRUB_MOD_FINI(btrfs)
|
GRUB_MOD_FINI (btrfs)
|
||||||
{
|
{
|
||||||
grub_fs_unregister (&grub_btrfs_fs);
|
grub_fs_unregister (&grub_btrfs_fs);
|
||||||
}
|
}
|
||||||
|
|
564
grub-core/io/lzopio.c
Normal file
564
grub-core/io/lzopio.c
Normal file
|
@ -0,0 +1,564 @@
|
||||||
|
/* lzopio.c - decompression support for lzop */
|
||||||
|
/*
|
||||||
|
* GRUB -- GRand Unified Bootloader
|
||||||
|
* Copyright (C) 2011 Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* GRUB 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <grub/err.h>
|
||||||
|
#include <grub/mm.h>
|
||||||
|
#include <grub/file.h>
|
||||||
|
#include <grub/fs.h>
|
||||||
|
#include <grub/dl.h>
|
||||||
|
#include <grub/crypto.h>
|
||||||
|
#include <minilzo.h>
|
||||||
|
|
||||||
|
GRUB_MOD_LICENSE ("GPLv3+");
|
||||||
|
|
||||||
|
#define LZOP_MAGIC "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a"
|
||||||
|
#define LZOP_MAGIC_SIZE 9
|
||||||
|
#define LZOP_CHECK_SIZE 4
|
||||||
|
#define LZOP_NEW_LIB 0x0940
|
||||||
|
|
||||||
|
/* Header flags - copied from conf.h of LZOP source code. */
|
||||||
|
#define F_ADLER32_D 0x00000001L
|
||||||
|
#define F_ADLER32_C 0x00000002L
|
||||||
|
#define F_STDIN 0x00000004L
|
||||||
|
#define F_STDOUT 0x00000008L
|
||||||
|
#define F_NAME_DEFAULT 0x00000010L
|
||||||
|
#define F_DOSISH 0x00000020L
|
||||||
|
#define F_H_EXTRA_FIELD 0x00000040L
|
||||||
|
#define F_H_GMTDIFF 0x00000080L
|
||||||
|
#define F_CRC32_D 0x00000100L
|
||||||
|
#define F_CRC32_C 0x00000200L
|
||||||
|
#define F_MULTIPART 0x00000400L
|
||||||
|
#define F_H_FILTER 0x00000800L
|
||||||
|
#define F_H_CRC32 0x00001000L
|
||||||
|
#define F_H_PATH 0x00002000L
|
||||||
|
#define F_MASK 0x00003FFFL
|
||||||
|
|
||||||
|
struct block_header
|
||||||
|
{
|
||||||
|
grub_uint32_t usize;
|
||||||
|
grub_uint32_t csize;
|
||||||
|
grub_uint32_t ucheck;
|
||||||
|
grub_uint32_t ccheck;
|
||||||
|
unsigned char *cdata;
|
||||||
|
unsigned char *udata;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct grub_lzopio
|
||||||
|
{
|
||||||
|
grub_file_t file;
|
||||||
|
int has_ccheck;
|
||||||
|
int has_ucheck;
|
||||||
|
const gcry_md_spec_t *ucheck_fun;
|
||||||
|
const gcry_md_spec_t *ccheck_fun;
|
||||||
|
grub_off_t saved_off; /* Rounded down to block boundary. */
|
||||||
|
grub_off_t start_block_off;
|
||||||
|
struct block_header block;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct grub_lzopio *grub_lzopio_t;
|
||||||
|
static struct grub_fs grub_lzopio_fs;
|
||||||
|
|
||||||
|
/* Some helper functions. On errors memory allocated by those function is free
|
||||||
|
* either on close() so no risk of leaks. This makes functions simpler. */
|
||||||
|
|
||||||
|
/* Read block header from file, after successful exit file points to
|
||||||
|
* beginning of block data. */
|
||||||
|
static int
|
||||||
|
read_block_header (struct grub_lzopio *lzopio)
|
||||||
|
{
|
||||||
|
lzopio->saved_off += lzopio->block.usize;
|
||||||
|
|
||||||
|
/* Free cached block data if any. */
|
||||||
|
grub_free (lzopio->block.udata);
|
||||||
|
grub_free (lzopio->block.cdata);
|
||||||
|
lzopio->block.udata = NULL;
|
||||||
|
lzopio->block.cdata = NULL;
|
||||||
|
|
||||||
|
if (grub_file_read (lzopio->file, &lzopio->block.usize,
|
||||||
|
sizeof (lzopio->block.usize)) !=
|
||||||
|
sizeof (lzopio->block.usize))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
lzopio->block.usize = grub_be_to_cpu32 (lzopio->block.usize);
|
||||||
|
|
||||||
|
/* Last block has uncompressed data size == 0 and no other fields. */
|
||||||
|
if (lzopio->block.usize == 0)
|
||||||
|
{
|
||||||
|
if (grub_file_tell (lzopio->file) == grub_file_size (lzopio->file))
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read compressed data block size. */
|
||||||
|
if (grub_file_read (lzopio->file, &lzopio->block.csize,
|
||||||
|
sizeof (lzopio->block.csize)) !=
|
||||||
|
sizeof (lzopio->block.csize))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
lzopio->block.csize = grub_be_to_cpu32 (lzopio->block.csize);
|
||||||
|
|
||||||
|
/* Corrupted. */
|
||||||
|
if (lzopio->block.csize > lzopio->block.usize)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Read checksum of uncompressed data. */
|
||||||
|
if (lzopio->has_ucheck)
|
||||||
|
{
|
||||||
|
if (grub_file_read (lzopio->file, &lzopio->block.ucheck,
|
||||||
|
sizeof (lzopio->block.ucheck)) !=
|
||||||
|
sizeof (lzopio->block.ucheck))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
lzopio->block.ucheck = grub_be_to_cpu32 (lzopio->block.ucheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read checksum of compressed data. */
|
||||||
|
if (lzopio->has_ccheck)
|
||||||
|
{
|
||||||
|
/* Incompressible data block. */
|
||||||
|
if (lzopio->block.csize == lzopio->block.usize)
|
||||||
|
{
|
||||||
|
lzopio->block.ccheck = lzopio->block.ucheck;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (grub_file_read (lzopio->file, &lzopio->block.ccheck,
|
||||||
|
sizeof (lzopio->block.ccheck)) !=
|
||||||
|
sizeof (lzopio->block.ccheck))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
lzopio->block.ccheck = grub_be_to_cpu32 (lzopio->block.ccheck);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read block data into memory. File must be set to beginning of block data.
|
||||||
|
* Can't be called on last block. */
|
||||||
|
static int
|
||||||
|
read_block_data (struct grub_lzopio *lzopio)
|
||||||
|
{
|
||||||
|
lzopio->block.cdata = grub_malloc (lzopio->block.csize);
|
||||||
|
if (!lzopio->block.cdata)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (grub_file_read (lzopio->file, lzopio->block.cdata, lzopio->block.csize)
|
||||||
|
!= (grub_ssize_t) lzopio->block.csize)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (lzopio->ccheck_fun)
|
||||||
|
{
|
||||||
|
grub_uint64_t context[(lzopio->ccheck_fun->contextsize + 7) / 8];
|
||||||
|
|
||||||
|
lzopio->ccheck_fun->init (context);
|
||||||
|
lzopio->ccheck_fun->write (context, lzopio->block.cdata,
|
||||||
|
lzopio->block.csize);
|
||||||
|
lzopio->ccheck_fun->final (context);
|
||||||
|
|
||||||
|
if (grub_memcmp
|
||||||
|
(lzopio->ccheck_fun->read (context), &lzopio->block.ccheck,
|
||||||
|
sizeof (lzopio->block.ccheck)) != 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read block data, uncompressed and also store it in memory. */
|
||||||
|
/* XXX Investigate possibility of in-place decompression to reduce memory
|
||||||
|
* footprint. Or try to uncompress directly to buf if possible. */
|
||||||
|
static int
|
||||||
|
uncompress_block (struct grub_lzopio *lzopio)
|
||||||
|
{
|
||||||
|
lzo_uint usize = lzopio->block.usize;
|
||||||
|
|
||||||
|
if (read_block_data (lzopio) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Incompressible data. */
|
||||||
|
if (lzopio->block.csize == lzopio->block.usize)
|
||||||
|
{
|
||||||
|
lzopio->block.udata = lzopio->block.cdata;
|
||||||
|
lzopio->block.cdata = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lzopio->block.udata = grub_malloc (lzopio->block.usize);
|
||||||
|
if (!lzopio->block.udata)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (lzo1x_decompress_safe (lzopio->block.cdata, lzopio->block.csize,
|
||||||
|
lzopio->block.udata, &usize, NULL)
|
||||||
|
!= LZO_E_OK)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (lzopio->ucheck_fun)
|
||||||
|
{
|
||||||
|
grub_uint64_t context[(lzopio->ccheck_fun->contextsize + 7) / 8];
|
||||||
|
|
||||||
|
lzopio->ucheck_fun->init (context);
|
||||||
|
lzopio->ucheck_fun->write (context, lzopio->block.udata,
|
||||||
|
lzopio->block.usize);
|
||||||
|
lzopio->ucheck_fun->final (context);
|
||||||
|
|
||||||
|
if (grub_memcmp
|
||||||
|
(lzopio->ucheck_fun->read (context), &lzopio->block.ucheck,
|
||||||
|
sizeof (lzopio->block.ucheck)) != 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compressed data can be free now. */
|
||||||
|
grub_free (lzopio->block.cdata);
|
||||||
|
lzopio->block.cdata = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Jump to next block and read its header. */
|
||||||
|
static int
|
||||||
|
jump_block (struct grub_lzopio *lzopio)
|
||||||
|
{
|
||||||
|
/* only jump if block was not decompressed (and read from disk) */
|
||||||
|
if (!lzopio->block.udata)
|
||||||
|
{
|
||||||
|
grub_off_t off = grub_file_tell (lzopio->file) + lzopio->block.csize;
|
||||||
|
|
||||||
|
if (grub_file_seek (lzopio->file, off) == ((grub_off_t) - 1))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return read_block_header (lzopio);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
calculate_uncompressed_size (grub_file_t file)
|
||||||
|
{
|
||||||
|
grub_lzopio_t lzopio = file->data;
|
||||||
|
grub_off_t usize_total = 0;
|
||||||
|
|
||||||
|
if (read_block_header (lzopio) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* FIXME: Don't do this for not easily seekable files. */
|
||||||
|
while (lzopio->block.usize != 0)
|
||||||
|
{
|
||||||
|
usize_total += lzopio->block.usize;
|
||||||
|
|
||||||
|
if (jump_block (lzopio) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
file->size = usize_total;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct lzop_header
|
||||||
|
{
|
||||||
|
grub_uint8_t magic[LZOP_MAGIC_SIZE];
|
||||||
|
grub_uint16_t lzop_version;
|
||||||
|
grub_uint16_t lib_version;
|
||||||
|
grub_uint16_t lib_version_ext;
|
||||||
|
grub_uint8_t method;
|
||||||
|
grub_uint8_t level;
|
||||||
|
grub_uint32_t flags;
|
||||||
|
/* grub_uint32_t filter; */ /* No filters support. Rarely used anyway. */
|
||||||
|
grub_uint32_t mode;
|
||||||
|
grub_uint32_t mtime_lo;
|
||||||
|
grub_uint32_t mtime_hi;
|
||||||
|
grub_uint8_t name_len;
|
||||||
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
static int
|
||||||
|
test_header (grub_file_t file)
|
||||||
|
{
|
||||||
|
grub_lzopio_t lzopio = file->data;
|
||||||
|
struct lzop_header header;
|
||||||
|
grub_uint32_t flags, checksum;
|
||||||
|
const gcry_md_spec_t *hcheck;
|
||||||
|
grub_uint8_t *context = NULL;
|
||||||
|
grub_uint8_t *name = NULL;
|
||||||
|
|
||||||
|
if (grub_file_read (lzopio->file, &header, sizeof (header)) != sizeof (header))
|
||||||
|
{
|
||||||
|
grub_error (GRUB_ERR_BAD_FILE_TYPE, "no lzop magic found");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_memcmp (header.magic, LZOP_MAGIC, LZOP_MAGIC_SIZE) != 0)
|
||||||
|
{
|
||||||
|
grub_error (GRUB_ERR_BAD_FILE_TYPE, "no lzop magic found");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_be_to_cpu16(header.lib_version) < LZOP_NEW_LIB)
|
||||||
|
{
|
||||||
|
grub_error (GRUB_ERR_BAD_COMPRESSED_DATA,
|
||||||
|
"unsupported (too old) LZOP version");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Too new version, should upgrade minilzo? */
|
||||||
|
if (grub_be_to_cpu16 (header.lib_version_ext) > MINILZO_VERSION)
|
||||||
|
{
|
||||||
|
grub_error (GRUB_ERR_BAD_COMPRESSED_DATA,
|
||||||
|
"unsupported (too new) LZO version");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
flags = grub_be_to_cpu32 (header.flags);
|
||||||
|
|
||||||
|
if (flags & F_CRC32_D)
|
||||||
|
{
|
||||||
|
lzopio->has_ucheck = 1;
|
||||||
|
lzopio->ucheck_fun = grub_crypto_lookup_md_by_name ("crc32");
|
||||||
|
}
|
||||||
|
else if (flags & F_ADLER32_D)
|
||||||
|
{
|
||||||
|
lzopio->has_ucheck = 1;
|
||||||
|
lzopio->ucheck_fun = grub_crypto_lookup_md_by_name ("adler32");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & F_CRC32_C)
|
||||||
|
{
|
||||||
|
lzopio->has_ccheck = 1;
|
||||||
|
lzopio->ccheck_fun = grub_crypto_lookup_md_by_name ("crc32");
|
||||||
|
}
|
||||||
|
else if (flags & F_ADLER32_C)
|
||||||
|
{
|
||||||
|
lzopio->has_ccheck = 1;
|
||||||
|
lzopio->ccheck_fun = grub_crypto_lookup_md_by_name ("adler32");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & F_H_CRC32)
|
||||||
|
hcheck = grub_crypto_lookup_md_by_name ("crc32");
|
||||||
|
else
|
||||||
|
hcheck = grub_crypto_lookup_md_by_name ("adler32");
|
||||||
|
|
||||||
|
if (hcheck) {
|
||||||
|
context = grub_malloc(hcheck->contextsize);
|
||||||
|
if (! context)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
hcheck->init(context);
|
||||||
|
|
||||||
|
/* MAGIC is not included in check calculation. */
|
||||||
|
hcheck->write(context, &header.lzop_version, sizeof(header)- LZOP_MAGIC_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (header.name_len != 0)
|
||||||
|
{
|
||||||
|
name = grub_malloc (header.name_len);
|
||||||
|
if (! name)
|
||||||
|
{
|
||||||
|
grub_free (context);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grub_file_read (lzopio->file, name, header.name_len) !=
|
||||||
|
header.name_len)
|
||||||
|
{
|
||||||
|
grub_free(name);
|
||||||
|
goto CORRUPTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hcheck)
|
||||||
|
hcheck->write(context, name, header.name_len);
|
||||||
|
|
||||||
|
grub_free(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hcheck)
|
||||||
|
hcheck->final(context);
|
||||||
|
|
||||||
|
if (grub_file_read (lzopio->file, &checksum, sizeof (checksum)) !=
|
||||||
|
sizeof (checksum))
|
||||||
|
goto CORRUPTED;
|
||||||
|
|
||||||
|
if (hcheck)
|
||||||
|
{
|
||||||
|
checksum = grub_cpu_to_be32(checksum);
|
||||||
|
if (memcmp(&checksum, hcheck->read(context), sizeof(checksum)) != 0)
|
||||||
|
goto CORRUPTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
lzopio->start_block_off = grub_file_tell (lzopio->file);
|
||||||
|
|
||||||
|
if (calculate_uncompressed_size (file) < 0)
|
||||||
|
goto CORRUPTED;
|
||||||
|
|
||||||
|
/* Get back to start block. */
|
||||||
|
grub_file_seek (lzopio->file, lzopio->start_block_off);
|
||||||
|
|
||||||
|
/* Read first block - grub_lzopio_read() expects valid block. */
|
||||||
|
if (read_block_header (lzopio) < 0)
|
||||||
|
goto CORRUPTED;
|
||||||
|
|
||||||
|
lzopio->saved_off = 0;
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
CORRUPTED:
|
||||||
|
grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "lzop file corrupted");
|
||||||
|
|
||||||
|
grub_free(name);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static grub_file_t
|
||||||
|
grub_lzopio_open (grub_file_t io)
|
||||||
|
{
|
||||||
|
grub_file_t file;
|
||||||
|
grub_lzopio_t lzopio;
|
||||||
|
|
||||||
|
file = (grub_file_t) grub_zalloc (sizeof (*file));
|
||||||
|
if (!file)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
lzopio = grub_zalloc (sizeof (*lzopio));
|
||||||
|
if (!lzopio)
|
||||||
|
{
|
||||||
|
grub_free (file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lzopio->file = io;
|
||||||
|
|
||||||
|
file->device = io->device;
|
||||||
|
file->offset = 0;
|
||||||
|
file->data = lzopio;
|
||||||
|
file->read_hook = 0;
|
||||||
|
file->fs = &grub_lzopio_fs;
|
||||||
|
file->size = GRUB_FILE_SIZE_UNKNOWN;
|
||||||
|
file->not_easily_seekable = 1;
|
||||||
|
|
||||||
|
if (grub_file_tell (lzopio->file) != 0)
|
||||||
|
grub_file_seek (lzopio->file, 0);
|
||||||
|
|
||||||
|
if (!test_header (file))
|
||||||
|
{
|
||||||
|
grub_errno = GRUB_ERR_NONE;
|
||||||
|
grub_file_seek (io, 0);
|
||||||
|
grub_free (lzopio);
|
||||||
|
grub_free (file);
|
||||||
|
|
||||||
|
return io;
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
static grub_ssize_t
|
||||||
|
grub_lzopio_read (grub_file_t file, char *buf, grub_size_t len)
|
||||||
|
{
|
||||||
|
grub_lzopio_t lzopio = file->data;
|
||||||
|
grub_ssize_t ret = 0;
|
||||||
|
grub_off_t off;
|
||||||
|
|
||||||
|
/* Backward seek before last read block. */
|
||||||
|
if (lzopio->saved_off > grub_file_tell (file))
|
||||||
|
{
|
||||||
|
grub_file_seek (lzopio->file, lzopio->start_block_off);
|
||||||
|
|
||||||
|
if (read_block_header (lzopio) < 0)
|
||||||
|
goto CORRUPTED;
|
||||||
|
|
||||||
|
lzopio->saved_off = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Forward to first block with requested data. */
|
||||||
|
while (lzopio->saved_off + lzopio->block.usize <= grub_file_tell (file))
|
||||||
|
{
|
||||||
|
/* EOF, could be possible files with unknown size. */
|
||||||
|
if (lzopio->block.usize == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (jump_block (lzopio) < 0)
|
||||||
|
goto CORRUPTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
off = grub_file_tell (file) - lzopio->saved_off;
|
||||||
|
|
||||||
|
while (len != 0 && lzopio->block.usize != 0)
|
||||||
|
{
|
||||||
|
long to_copy;
|
||||||
|
|
||||||
|
/* Block not decompressed yet. */
|
||||||
|
if (!lzopio->block.udata && uncompress_block (lzopio) < 0)
|
||||||
|
goto CORRUPTED;
|
||||||
|
|
||||||
|
/* Copy requested data into buffer. */
|
||||||
|
to_copy = grub_min (lzopio->block.usize - off, len);
|
||||||
|
grub_memcpy (buf, lzopio->block.udata + off, to_copy);
|
||||||
|
|
||||||
|
len -= to_copy;
|
||||||
|
buf += to_copy;
|
||||||
|
ret += to_copy;
|
||||||
|
off = 0;
|
||||||
|
|
||||||
|
/* Read next block if needed. */
|
||||||
|
if (len > 0 && read_block_header (lzopio) < 0)
|
||||||
|
goto CORRUPTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
CORRUPTED:
|
||||||
|
grub_error (GRUB_ERR_BAD_COMPRESSED_DATA, "lzop file corrupted");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Release everything, including the underlying file object. */
|
||||||
|
static grub_err_t
|
||||||
|
grub_lzopio_close (grub_file_t file)
|
||||||
|
{
|
||||||
|
grub_lzopio_t lzopio = file->data;
|
||||||
|
|
||||||
|
grub_file_close (lzopio->file);
|
||||||
|
grub_free (lzopio->block.cdata);
|
||||||
|
grub_free (lzopio->block.udata);
|
||||||
|
grub_free (lzopio);
|
||||||
|
|
||||||
|
/* Device must not be closed twice. */
|
||||||
|
file->device = 0;
|
||||||
|
return grub_errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct grub_fs grub_lzopio_fs = {
|
||||||
|
.name = "lzopio",
|
||||||
|
.dir = 0,
|
||||||
|
.open = 0,
|
||||||
|
.read = grub_lzopio_read,
|
||||||
|
.close = grub_lzopio_close,
|
||||||
|
.label = 0,
|
||||||
|
.next = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
GRUB_MOD_INIT (lzopio)
|
||||||
|
{
|
||||||
|
grub_file_filter_register (GRUB_FILE_FILTER_LZOPIO, grub_lzopio_open);
|
||||||
|
}
|
||||||
|
|
||||||
|
GRUB_MOD_FINI (lzopio)
|
||||||
|
{
|
||||||
|
grub_file_filter_unregister (GRUB_FILE_FILTER_LZOPIO);
|
||||||
|
}
|
151
grub-core/lib/adler32.c
Normal file
151
grub-core/lib/adler32.c
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
/* adler32.c - adler32 check. */
|
||||||
|
/*
|
||||||
|
* GRUB -- GRand Unified Bootloader
|
||||||
|
* Copyright (C) 2011 Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* GRUB 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <grub/types.h>
|
||||||
|
#include <grub/dl.h>
|
||||||
|
#include <grub/crypto.h>
|
||||||
|
|
||||||
|
/* Based on adler32() from adler32.c of zlib-1.2.5 library. */
|
||||||
|
|
||||||
|
#define BASE 65521UL
|
||||||
|
#define NMAX 5552
|
||||||
|
|
||||||
|
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
|
||||||
|
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
|
||||||
|
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
|
||||||
|
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
|
||||||
|
#define DO16(buf) DO8(buf,0); DO8(buf,8);
|
||||||
|
|
||||||
|
static grub_uint32_t
|
||||||
|
update_adler32 (grub_uint32_t adler, const grub_uint8_t *buf, grub_size_t len)
|
||||||
|
{
|
||||||
|
unsigned long sum2;
|
||||||
|
unsigned int n;
|
||||||
|
|
||||||
|
sum2 = (adler >> 16) & 0xffff;
|
||||||
|
adler &= 0xffff;
|
||||||
|
|
||||||
|
if (len == 1)
|
||||||
|
{
|
||||||
|
adler += buf[0];
|
||||||
|
if (adler >= BASE)
|
||||||
|
adler -= BASE;
|
||||||
|
sum2 += adler;
|
||||||
|
if (sum2 >= BASE)
|
||||||
|
sum2 -= BASE;
|
||||||
|
return adler | (sum2 << 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len < 16)
|
||||||
|
{
|
||||||
|
while (len--)
|
||||||
|
{
|
||||||
|
adler += *buf++;
|
||||||
|
sum2 += adler;
|
||||||
|
}
|
||||||
|
if (adler >= BASE)
|
||||||
|
adler -= BASE;
|
||||||
|
sum2 %= BASE;
|
||||||
|
return adler | (sum2 << 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (len >= NMAX)
|
||||||
|
{
|
||||||
|
len -= NMAX;
|
||||||
|
n = NMAX / 16;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
DO16 (buf);
|
||||||
|
buf += 16;
|
||||||
|
}
|
||||||
|
while (--n);
|
||||||
|
adler %= BASE;
|
||||||
|
sum2 %= BASE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len)
|
||||||
|
{
|
||||||
|
while (len >= 16)
|
||||||
|
{
|
||||||
|
len -= 16;
|
||||||
|
DO16 (buf);
|
||||||
|
buf += 16;
|
||||||
|
}
|
||||||
|
while (len--)
|
||||||
|
{
|
||||||
|
adler += *buf++;
|
||||||
|
sum2 += adler;
|
||||||
|
}
|
||||||
|
adler %= BASE;
|
||||||
|
sum2 %= BASE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return adler | (sum2 << 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
grub_uint32_t adler;
|
||||||
|
}
|
||||||
|
adler32_context;
|
||||||
|
|
||||||
|
static void
|
||||||
|
adler32_init (void *context)
|
||||||
|
{
|
||||||
|
adler32_context *ctx = (adler32_context *) context;
|
||||||
|
ctx->adler = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
adler32_write (void *context, const void *inbuf, grub_size_t inlen)
|
||||||
|
{
|
||||||
|
adler32_context *ctx = (adler32_context *) context;
|
||||||
|
if (!inbuf)
|
||||||
|
return;
|
||||||
|
ctx->adler = update_adler32 (ctx->adler, inbuf, inlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
static grub_uint8_t *
|
||||||
|
adler32_read (void *context)
|
||||||
|
{
|
||||||
|
adler32_context *ctx = (adler32_context *) context;
|
||||||
|
return (grub_uint8_t *) &ctx->adler;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
adler32_final (void *context __attribute__ ((unused)))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
gcry_md_spec_t _gcry_digest_spec_adler32 = {
|
||||||
|
"ADLER32",0 , 0, 0 , 4,
|
||||||
|
adler32_init, adler32_write, adler32_final, adler32_read,
|
||||||
|
sizeof (adler32_context),
|
||||||
|
.blocksize = 64
|
||||||
|
};
|
||||||
|
|
||||||
|
GRUB_MOD_INIT(adler32)
|
||||||
|
{
|
||||||
|
grub_md_register (&_gcry_digest_spec_adler32);
|
||||||
|
}
|
||||||
|
|
||||||
|
GRUB_MOD_FINI(adler32)
|
||||||
|
{
|
||||||
|
grub_md_unregister (&_gcry_digest_spec_adler32);
|
||||||
|
}
|
446
grub-core/lib/minilzo/lzoconf.h
Normal file
446
grub-core/lib/minilzo/lzoconf.h
Normal file
|
@ -0,0 +1,446 @@
|
||||||
|
/* lzoconf.h -- configuration of the LZO data compression library
|
||||||
|
|
||||||
|
This file is part of the LZO real-time data compression library.
|
||||||
|
|
||||||
|
Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
The LZO library 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.
|
||||||
|
|
||||||
|
The LZO library 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 the LZO library; see the file COPYING.
|
||||||
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
Markus F.X.J. Oberhumer
|
||||||
|
<markus@oberhumer.com>
|
||||||
|
http://www.oberhumer.com/opensource/lzo/
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __LZOCONF_H_INCLUDED
|
||||||
|
#define __LZOCONF_H_INCLUDED 1
|
||||||
|
|
||||||
|
#define LZO_VERSION 0x2050
|
||||||
|
#define LZO_VERSION_STRING "2.05"
|
||||||
|
#define LZO_VERSION_DATE "Apr 23 2011"
|
||||||
|
|
||||||
|
/* internal Autoconf configuration file - only used when building LZO */
|
||||||
|
#if defined(LZO_HAVE_CONFIG_H)
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
// LZO requires a conforming <limits.h>
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if !defined(CHAR_BIT) || (CHAR_BIT != 8)
|
||||||
|
# error "invalid CHAR_BIT"
|
||||||
|
#endif
|
||||||
|
#if !defined(UCHAR_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX)
|
||||||
|
# error "check your compiler installation"
|
||||||
|
#endif
|
||||||
|
#if (USHRT_MAX < 1) || (UINT_MAX < 1) || (ULONG_MAX < 1)
|
||||||
|
# error "your limits.h macros are broken"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* get OS and architecture defines */
|
||||||
|
#ifndef __LZODEFS_H_INCLUDED
|
||||||
|
#include "lzodefs.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
// some core defines
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if !defined(LZO_UINT32_C)
|
||||||
|
# if (UINT_MAX < LZO_0xffffffffL)
|
||||||
|
# define LZO_UINT32_C(c) c ## UL
|
||||||
|
# else
|
||||||
|
# define LZO_UINT32_C(c) ((c) + 0U)
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* memory checkers */
|
||||||
|
#if !defined(__LZO_CHECKER)
|
||||||
|
# if defined(__BOUNDS_CHECKING_ON)
|
||||||
|
# define __LZO_CHECKER 1
|
||||||
|
# elif defined(__CHECKER__)
|
||||||
|
# define __LZO_CHECKER 1
|
||||||
|
# elif defined(__INSURE__)
|
||||||
|
# define __LZO_CHECKER 1
|
||||||
|
# elif defined(__PURIFY__)
|
||||||
|
# define __LZO_CHECKER 1
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
// integral and pointer types
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/* lzo_uint should match size_t */
|
||||||
|
#if !defined(LZO_UINT_MAX)
|
||||||
|
# if defined(LZO_ABI_LLP64) /* WIN64 */
|
||||||
|
# if defined(LZO_OS_WIN64)
|
||||||
|
typedef unsigned __int64 lzo_uint;
|
||||||
|
typedef __int64 lzo_int;
|
||||||
|
# else
|
||||||
|
typedef unsigned long long lzo_uint;
|
||||||
|
typedef long long lzo_int;
|
||||||
|
# endif
|
||||||
|
# define LZO_UINT_MAX 0xffffffffffffffffull
|
||||||
|
# define LZO_INT_MAX 9223372036854775807LL
|
||||||
|
# define LZO_INT_MIN (-1LL - LZO_INT_MAX)
|
||||||
|
# elif defined(LZO_ABI_IP32L64) /* MIPS R5900 */
|
||||||
|
typedef unsigned int lzo_uint;
|
||||||
|
typedef int lzo_int;
|
||||||
|
# define LZO_UINT_MAX UINT_MAX
|
||||||
|
# define LZO_INT_MAX INT_MAX
|
||||||
|
# define LZO_INT_MIN INT_MIN
|
||||||
|
# elif (ULONG_MAX >= LZO_0xffffffffL)
|
||||||
|
typedef unsigned long lzo_uint;
|
||||||
|
typedef long lzo_int;
|
||||||
|
# define LZO_UINT_MAX ULONG_MAX
|
||||||
|
# define LZO_INT_MAX LONG_MAX
|
||||||
|
# define LZO_INT_MIN LONG_MIN
|
||||||
|
# else
|
||||||
|
# error "lzo_uint"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Integral types with 32 bits or more. */
|
||||||
|
#if !defined(LZO_UINT32_MAX)
|
||||||
|
# if (UINT_MAX >= LZO_0xffffffffL)
|
||||||
|
typedef unsigned int lzo_uint32;
|
||||||
|
typedef int lzo_int32;
|
||||||
|
# define LZO_UINT32_MAX UINT_MAX
|
||||||
|
# define LZO_INT32_MAX INT_MAX
|
||||||
|
# define LZO_INT32_MIN INT_MIN
|
||||||
|
# elif (ULONG_MAX >= LZO_0xffffffffL)
|
||||||
|
typedef unsigned long lzo_uint32;
|
||||||
|
typedef long lzo_int32;
|
||||||
|
# define LZO_UINT32_MAX ULONG_MAX
|
||||||
|
# define LZO_INT32_MAX LONG_MAX
|
||||||
|
# define LZO_INT32_MIN LONG_MIN
|
||||||
|
# else
|
||||||
|
# error "lzo_uint32"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Integral types with exactly 64 bits. */
|
||||||
|
#if !defined(LZO_UINT64_MAX)
|
||||||
|
# if (LZO_UINT_MAX >= LZO_0xffffffffL)
|
||||||
|
# if ((((LZO_UINT_MAX) >> 31) >> 31) == 3)
|
||||||
|
# define lzo_uint64 lzo_uint
|
||||||
|
# define lzo_int64 lzo_int
|
||||||
|
# define LZO_UINT64_MAX LZO_UINT_MAX
|
||||||
|
# define LZO_INT64_MAX LZO_INT_MAX
|
||||||
|
# define LZO_INT64_MIN LZO_INT_MIN
|
||||||
|
# endif
|
||||||
|
# elif (ULONG_MAX >= LZO_0xffffffffL)
|
||||||
|
# if ((((ULONG_MAX) >> 31) >> 31) == 3)
|
||||||
|
typedef unsigned long lzo_uint64;
|
||||||
|
typedef long lzo_int64;
|
||||||
|
# define LZO_UINT64_MAX ULONG_MAX
|
||||||
|
# define LZO_INT64_MAX LONG_MAX
|
||||||
|
# define LZO_INT64_MIN LONG_MIN
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* The larger type of lzo_uint and lzo_uint32. */
|
||||||
|
#if (LZO_UINT_MAX >= LZO_UINT32_MAX)
|
||||||
|
# define lzo_xint lzo_uint
|
||||||
|
#else
|
||||||
|
# define lzo_xint lzo_uint32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Memory model that allows to access memory at offsets of lzo_uint. */
|
||||||
|
#if !defined(__LZO_MMODEL)
|
||||||
|
# if (LZO_UINT_MAX <= UINT_MAX)
|
||||||
|
# define __LZO_MMODEL /*empty*/
|
||||||
|
# elif defined(LZO_HAVE_MM_HUGE_PTR)
|
||||||
|
# define __LZO_MMODEL_HUGE 1
|
||||||
|
# define __LZO_MMODEL __huge
|
||||||
|
# else
|
||||||
|
# define __LZO_MMODEL /*empty*/
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* no typedef here because of const-pointer issues */
|
||||||
|
#define lzo_bytep unsigned char __LZO_MMODEL *
|
||||||
|
#define lzo_charp char __LZO_MMODEL *
|
||||||
|
#define lzo_voidp void __LZO_MMODEL *
|
||||||
|
#define lzo_shortp short __LZO_MMODEL *
|
||||||
|
#define lzo_ushortp unsigned short __LZO_MMODEL *
|
||||||
|
#define lzo_uint32p lzo_uint32 __LZO_MMODEL *
|
||||||
|
#define lzo_int32p lzo_int32 __LZO_MMODEL *
|
||||||
|
#if defined(LZO_UINT64_MAX)
|
||||||
|
#define lzo_uint64p lzo_uint64 __LZO_MMODEL *
|
||||||
|
#define lzo_int64p lzo_int64 __LZO_MMODEL *
|
||||||
|
#endif
|
||||||
|
#define lzo_uintp lzo_uint __LZO_MMODEL *
|
||||||
|
#define lzo_intp lzo_int __LZO_MMODEL *
|
||||||
|
#define lzo_xintp lzo_xint __LZO_MMODEL *
|
||||||
|
#define lzo_voidpp lzo_voidp __LZO_MMODEL *
|
||||||
|
#define lzo_bytepp lzo_bytep __LZO_MMODEL *
|
||||||
|
/* deprecated - use 'lzo_bytep' instead of 'lzo_byte *' */
|
||||||
|
#define lzo_byte unsigned char __LZO_MMODEL
|
||||||
|
|
||||||
|
typedef int lzo_bool;
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
// function types
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/* name mangling */
|
||||||
|
#if !defined(__LZO_EXTERN_C)
|
||||||
|
# ifdef __cplusplus
|
||||||
|
# define __LZO_EXTERN_C extern "C"
|
||||||
|
# else
|
||||||
|
# define __LZO_EXTERN_C extern
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* calling convention */
|
||||||
|
#if !defined(__LZO_CDECL)
|
||||||
|
# define __LZO_CDECL __lzo_cdecl
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* DLL export information */
|
||||||
|
#if !defined(__LZO_EXPORT1)
|
||||||
|
# define __LZO_EXPORT1 /*empty*/
|
||||||
|
#endif
|
||||||
|
#if !defined(__LZO_EXPORT2)
|
||||||
|
# define __LZO_EXPORT2 /*empty*/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* __cdecl calling convention for public C and assembly functions */
|
||||||
|
#if !defined(LZO_PUBLIC)
|
||||||
|
# define LZO_PUBLIC(_rettype) __LZO_EXPORT1 _rettype __LZO_EXPORT2 __LZO_CDECL
|
||||||
|
#endif
|
||||||
|
#if !defined(LZO_EXTERN)
|
||||||
|
# define LZO_EXTERN(_rettype) __LZO_EXTERN_C LZO_PUBLIC(_rettype)
|
||||||
|
#endif
|
||||||
|
#if !defined(LZO_PRIVATE)
|
||||||
|
# define LZO_PRIVATE(_rettype) static _rettype __LZO_CDECL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* function types */
|
||||||
|
typedef int
|
||||||
|
(__LZO_CDECL *lzo_compress_t) ( const lzo_bytep src, lzo_uint src_len,
|
||||||
|
lzo_bytep dst, lzo_uintp dst_len,
|
||||||
|
lzo_voidp wrkmem );
|
||||||
|
|
||||||
|
typedef int
|
||||||
|
(__LZO_CDECL *lzo_decompress_t) ( const lzo_bytep src, lzo_uint src_len,
|
||||||
|
lzo_bytep dst, lzo_uintp dst_len,
|
||||||
|
lzo_voidp wrkmem );
|
||||||
|
|
||||||
|
typedef int
|
||||||
|
(__LZO_CDECL *lzo_optimize_t) ( lzo_bytep src, lzo_uint src_len,
|
||||||
|
lzo_bytep dst, lzo_uintp dst_len,
|
||||||
|
lzo_voidp wrkmem );
|
||||||
|
|
||||||
|
typedef int
|
||||||
|
(__LZO_CDECL *lzo_compress_dict_t)(const lzo_bytep src, lzo_uint src_len,
|
||||||
|
lzo_bytep dst, lzo_uintp dst_len,
|
||||||
|
lzo_voidp wrkmem,
|
||||||
|
const lzo_bytep dict, lzo_uint dict_len );
|
||||||
|
|
||||||
|
typedef int
|
||||||
|
(__LZO_CDECL *lzo_decompress_dict_t)(const lzo_bytep src, lzo_uint src_len,
|
||||||
|
lzo_bytep dst, lzo_uintp dst_len,
|
||||||
|
lzo_voidp wrkmem,
|
||||||
|
const lzo_bytep dict, lzo_uint dict_len );
|
||||||
|
|
||||||
|
|
||||||
|
/* Callback interface. Currently only the progress indicator ("nprogress")
|
||||||
|
* is used, but this may change in a future release. */
|
||||||
|
|
||||||
|
struct lzo_callback_t;
|
||||||
|
typedef struct lzo_callback_t lzo_callback_t;
|
||||||
|
#define lzo_callback_p lzo_callback_t __LZO_MMODEL *
|
||||||
|
|
||||||
|
/* malloc & free function types */
|
||||||
|
typedef lzo_voidp (__LZO_CDECL *lzo_alloc_func_t)
|
||||||
|
(lzo_callback_p self, lzo_uint items, lzo_uint size);
|
||||||
|
typedef void (__LZO_CDECL *lzo_free_func_t)
|
||||||
|
(lzo_callback_p self, lzo_voidp ptr);
|
||||||
|
|
||||||
|
/* a progress indicator callback function */
|
||||||
|
typedef void (__LZO_CDECL *lzo_progress_func_t)
|
||||||
|
(lzo_callback_p, lzo_uint, lzo_uint, int);
|
||||||
|
|
||||||
|
struct lzo_callback_t
|
||||||
|
{
|
||||||
|
/* custom allocators (set to 0 to disable) */
|
||||||
|
lzo_alloc_func_t nalloc; /* [not used right now] */
|
||||||
|
lzo_free_func_t nfree; /* [not used right now] */
|
||||||
|
|
||||||
|
/* a progress indicator callback function (set to 0 to disable) */
|
||||||
|
lzo_progress_func_t nprogress;
|
||||||
|
|
||||||
|
/* NOTE: the first parameter "self" of the nalloc/nfree/nprogress
|
||||||
|
* callbacks points back to this struct, so you are free to store
|
||||||
|
* some extra info in the following variables. */
|
||||||
|
lzo_voidp user1;
|
||||||
|
lzo_xint user2;
|
||||||
|
lzo_xint user3;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
// error codes and prototypes
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/* Error codes for the compression/decompression functions. Negative
|
||||||
|
* values are errors, positive values will be used for special but
|
||||||
|
* normal events.
|
||||||
|
*/
|
||||||
|
#define LZO_E_OK 0
|
||||||
|
#define LZO_E_ERROR (-1)
|
||||||
|
#define LZO_E_OUT_OF_MEMORY (-2) /* [lzo_alloc_func_t failure] */
|
||||||
|
#define LZO_E_NOT_COMPRESSIBLE (-3) /* [not used right now] */
|
||||||
|
#define LZO_E_INPUT_OVERRUN (-4)
|
||||||
|
#define LZO_E_OUTPUT_OVERRUN (-5)
|
||||||
|
#define LZO_E_LOOKBEHIND_OVERRUN (-6)
|
||||||
|
#define LZO_E_EOF_NOT_FOUND (-7)
|
||||||
|
#define LZO_E_INPUT_NOT_CONSUMED (-8)
|
||||||
|
#define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */
|
||||||
|
#define LZO_E_INVALID_ARGUMENT (-10)
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef lzo_sizeof_dict_t
|
||||||
|
# define lzo_sizeof_dict_t ((unsigned)sizeof(lzo_bytep))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* lzo_init() should be the first function you call.
|
||||||
|
* Check the return code !
|
||||||
|
*
|
||||||
|
* lzo_init() is a macro to allow checking that the library and the
|
||||||
|
* compiler's view of various types are consistent.
|
||||||
|
*/
|
||||||
|
#define lzo_init() __lzo_init_v2(LZO_VERSION,(int)sizeof(short),(int)sizeof(int),\
|
||||||
|
(int)sizeof(long),(int)sizeof(lzo_uint32),(int)sizeof(lzo_uint),\
|
||||||
|
(int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\
|
||||||
|
(int)sizeof(lzo_callback_t))
|
||||||
|
LZO_EXTERN(int) __lzo_init_v2(unsigned,int,int,int,int,int,int,int,int,int);
|
||||||
|
|
||||||
|
/* version functions (useful for shared libraries) */
|
||||||
|
LZO_EXTERN(unsigned) lzo_version(void);
|
||||||
|
LZO_EXTERN(const char *) lzo_version_string(void);
|
||||||
|
LZO_EXTERN(const char *) lzo_version_date(void);
|
||||||
|
LZO_EXTERN(const lzo_charp) _lzo_version_string(void);
|
||||||
|
LZO_EXTERN(const lzo_charp) _lzo_version_date(void);
|
||||||
|
|
||||||
|
/* string functions */
|
||||||
|
LZO_EXTERN(int)
|
||||||
|
lzo_memcmp(const lzo_voidp a, const lzo_voidp b, lzo_uint len);
|
||||||
|
LZO_EXTERN(lzo_voidp)
|
||||||
|
lzo_memcpy(lzo_voidp dst, const lzo_voidp src, lzo_uint len);
|
||||||
|
LZO_EXTERN(lzo_voidp)
|
||||||
|
lzo_memmove(lzo_voidp dst, const lzo_voidp src, lzo_uint len);
|
||||||
|
LZO_EXTERN(lzo_voidp)
|
||||||
|
lzo_memset(lzo_voidp buf, int c, lzo_uint len);
|
||||||
|
|
||||||
|
/* checksum functions */
|
||||||
|
LZO_EXTERN(lzo_uint32)
|
||||||
|
lzo_adler32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len);
|
||||||
|
LZO_EXTERN(lzo_uint32)
|
||||||
|
lzo_crc32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len);
|
||||||
|
LZO_EXTERN(const lzo_uint32p)
|
||||||
|
lzo_get_crc32_table(void);
|
||||||
|
|
||||||
|
/* misc. */
|
||||||
|
LZO_EXTERN(int) _lzo_config_check(void);
|
||||||
|
typedef union { lzo_bytep p; lzo_uint u; } __lzo_pu_u;
|
||||||
|
typedef union { lzo_bytep p; lzo_uint32 u32; } __lzo_pu32_u;
|
||||||
|
typedef union { void *vp; lzo_bytep bp; lzo_uint u; lzo_uint32 u32; unsigned long l; } lzo_align_t;
|
||||||
|
|
||||||
|
/* align a char pointer on a boundary that is a multiple of 'size' */
|
||||||
|
LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size);
|
||||||
|
#define LZO_PTR_ALIGN_UP(p,size) \
|
||||||
|
((p) + (lzo_uint) __lzo_align_gap((const lzo_voidp)(p),(lzo_uint)(size)))
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
// deprecated macros - only for backward compatibility with LZO v1.xx
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#if defined(LZO_CFG_COMPAT)
|
||||||
|
|
||||||
|
#define __LZOCONF_H 1
|
||||||
|
|
||||||
|
#if defined(LZO_ARCH_I086)
|
||||||
|
# define __LZO_i386 1
|
||||||
|
#elif defined(LZO_ARCH_I386)
|
||||||
|
# define __LZO_i386 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(LZO_OS_DOS16)
|
||||||
|
# define __LZO_DOS 1
|
||||||
|
# define __LZO_DOS16 1
|
||||||
|
#elif defined(LZO_OS_DOS32)
|
||||||
|
# define __LZO_DOS 1
|
||||||
|
#elif defined(LZO_OS_WIN16)
|
||||||
|
# define __LZO_WIN 1
|
||||||
|
# define __LZO_WIN16 1
|
||||||
|
#elif defined(LZO_OS_WIN32)
|
||||||
|
# define __LZO_WIN 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define __LZO_CMODEL /*empty*/
|
||||||
|
#define __LZO_DMODEL /*empty*/
|
||||||
|
#define __LZO_ENTRY __LZO_CDECL
|
||||||
|
#define LZO_EXTERN_CDECL LZO_EXTERN
|
||||||
|
#define LZO_ALIGN LZO_PTR_ALIGN_UP
|
||||||
|
|
||||||
|
#define lzo_compress_asm_t lzo_compress_t
|
||||||
|
#define lzo_decompress_asm_t lzo_decompress_t
|
||||||
|
|
||||||
|
#endif /* LZO_CFG_COMPAT */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* already included */
|
||||||
|
|
||||||
|
|
||||||
|
/* vim:set ts=4 et: */
|
1852
grub-core/lib/minilzo/lzodefs.h
Normal file
1852
grub-core/lib/minilzo/lzodefs.h
Normal file
File diff suppressed because it is too large
Load diff
4562
grub-core/lib/minilzo/minilzo.c
Normal file
4562
grub-core/lib/minilzo/minilzo.c
Normal file
File diff suppressed because it is too large
Load diff
109
grub-core/lib/minilzo/minilzo.h
Normal file
109
grub-core/lib/minilzo/minilzo.h
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
/* minilzo.h -- mini subset of the LZO real-time data compression library
|
||||||
|
|
||||||
|
This file is part of the LZO real-time data compression library.
|
||||||
|
|
||||||
|
Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
All Rights Reserved.
|
||||||
|
|
||||||
|
The LZO library 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.
|
||||||
|
|
||||||
|
The LZO library 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 the LZO library; see the file COPYING.
|
||||||
|
If not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
Markus F.X.J. Oberhumer
|
||||||
|
<markus@oberhumer.com>
|
||||||
|
http://www.oberhumer.com/opensource/lzo/
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE:
|
||||||
|
* the full LZO package can be found at
|
||||||
|
* http://www.oberhumer.com/opensource/lzo/
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __MINILZO_H
|
||||||
|
#define __MINILZO_H 1
|
||||||
|
|
||||||
|
#define MINILZO_VERSION 0x2050
|
||||||
|
|
||||||
|
#ifdef __LZOCONF_H
|
||||||
|
# error "you cannot use both LZO and miniLZO"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef LZO_HAVE_CONFIG_H
|
||||||
|
#include "lzoconf.h"
|
||||||
|
|
||||||
|
#if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION)
|
||||||
|
# error "version mismatch in header files"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
//
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
/* Memory required for the wrkmem parameter.
|
||||||
|
* When the required size is 0, you can also pass a NULL pointer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS
|
||||||
|
#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t))
|
||||||
|
#define LZO1X_MEM_DECOMPRESS (0)
|
||||||
|
|
||||||
|
|
||||||
|
/* compression */
|
||||||
|
LZO_EXTERN(int)
|
||||||
|
lzo1x_1_compress ( const lzo_bytep src, lzo_uint src_len,
|
||||||
|
lzo_bytep dst, lzo_uintp dst_len,
|
||||||
|
lzo_voidp wrkmem );
|
||||||
|
|
||||||
|
/* decompression */
|
||||||
|
LZO_EXTERN(int)
|
||||||
|
lzo1x_decompress ( const lzo_bytep src, lzo_uint src_len,
|
||||||
|
lzo_bytep dst, lzo_uintp dst_len,
|
||||||
|
lzo_voidp wrkmem /* NOT USED */ );
|
||||||
|
|
||||||
|
/* safe decompression with overrun testing */
|
||||||
|
LZO_EXTERN(int)
|
||||||
|
lzo1x_decompress_safe ( const lzo_bytep src, lzo_uint src_len,
|
||||||
|
lzo_bytep dst, lzo_uintp dst_len,
|
||||||
|
lzo_voidp wrkmem /* NOT USED */ );
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* already included */
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* GRUB -- GRand Unified Bootloader
|
||||||
|
* Copyright (C) 2010 Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* GRUB 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GRUB_POSIX_LIMITS_H
|
||||||
|
#define GRUB_POSIX_LIMITS_H
|
||||||
|
|
||||||
|
#include <grub/types.h>
|
||||||
|
|
||||||
|
#define UCHAR_MAX GRUB_UCHAR_MAX
|
||||||
|
#define USHRT_MAX GRUB_USHRT_MAX
|
||||||
|
#define UINT_MAX GRUB_UINT_MAX
|
||||||
|
#define ULONG_MAX GRUB_ULONG_MAX
|
||||||
|
|
||||||
|
#define CHAR_BIT 8
|
||||||
|
|
||||||
|
#endif
|
|
@ -24,9 +24,6 @@
|
||||||
typedef grub_size_t size_t;
|
typedef grub_size_t size_t;
|
||||||
typedef enum { false = 0, true = 1 } bool;
|
typedef enum { false = 0, true = 1 } bool;
|
||||||
|
|
||||||
#define ULONG_MAX GRUB_ULONG_MAX
|
|
||||||
#define UCHAR_MAX 0xff
|
|
||||||
|
|
||||||
typedef grub_uint8_t uint8_t;
|
typedef grub_uint8_t uint8_t;
|
||||||
typedef grub_uint16_t uint16_t;
|
typedef grub_uint16_t uint16_t;
|
||||||
typedef grub_uint32_t uint32_t;
|
typedef grub_uint32_t uint32_t;
|
||||||
|
|
|
@ -56,9 +56,10 @@ typedef enum grub_file_filter_id
|
||||||
{
|
{
|
||||||
GRUB_FILE_FILTER_GZIO,
|
GRUB_FILE_FILTER_GZIO,
|
||||||
GRUB_FILE_FILTER_XZIO,
|
GRUB_FILE_FILTER_XZIO,
|
||||||
|
GRUB_FILE_FILTER_LZOPIO,
|
||||||
GRUB_FILE_FILTER_MAX,
|
GRUB_FILE_FILTER_MAX,
|
||||||
GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO,
|
GRUB_FILE_FILTER_COMPRESSION_FIRST = GRUB_FILE_FILTER_GZIO,
|
||||||
GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_XZIO,
|
GRUB_FILE_FILTER_COMPRESSION_LAST = GRUB_FILE_FILTER_LZOPIO,
|
||||||
} grub_file_filter_id_t;
|
} grub_file_filter_id_t;
|
||||||
|
|
||||||
typedef grub_file_t (*grub_file_filter_t) (grub_file_t in);
|
typedef grub_file_t (*grub_file_filter_t) (grub_file_t in);
|
||||||
|
|
|
@ -116,6 +116,10 @@ typedef grub_int32_t grub_ssize_t;
|
||||||
# define PRIuGRUB_SIZE "u"
|
# define PRIuGRUB_SIZE "u"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define GRUB_UCHAR_MAX 0xFF
|
||||||
|
#define GRUB_USHRT_MAX 65535
|
||||||
|
#define GRUB_UINT_MAX 4294967295U
|
||||||
|
|
||||||
#if GRUB_CPU_SIZEOF_LONG == 8
|
#if GRUB_CPU_SIZEOF_LONG == 8
|
||||||
# define GRUB_ULONG_MAX 18446744073709551615UL
|
# define GRUB_ULONG_MAX 18446744073709551615UL
|
||||||
# define GRUB_LONG_MAX 9223372036854775807L
|
# define GRUB_LONG_MAX 9223372036854775807L
|
||||||
|
@ -218,4 +222,31 @@ static inline grub_uint64_t grub_swap_bytes64(grub_uint64_t x)
|
||||||
# define grub_cpu_to_le32_compile_time(x) ((grub_uint32_t) (x))
|
# define grub_cpu_to_le32_compile_time(x) ((grub_uint32_t) (x))
|
||||||
#endif /* ! WORDS_BIGENDIAN */
|
#endif /* ! WORDS_BIGENDIAN */
|
||||||
|
|
||||||
|
static inline grub_uint16_t grub_get_unaligned16(void *ptr)
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
grub_uint16_t d;
|
||||||
|
} __attribute__((packed)) *dd = ptr;
|
||||||
|
return dd->d;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline grub_uint32_t grub_get_unaligned32(void *ptr)
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
grub_uint32_t d;
|
||||||
|
} __attribute__((packed)) *dd = ptr;
|
||||||
|
return dd->d;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline grub_uint64_t grub_get_unaligned64(void *ptr)
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
grub_uint64_t d;
|
||||||
|
} __attribute__((packed)) *dd = ptr;
|
||||||
|
return dd->d;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* ! GRUB_TYPES_HEADER */
|
#endif /* ! GRUB_TYPES_HEADER */
|
||||||
|
|
|
@ -81,6 +81,8 @@ cryptolist.write ("AES-128: gcry_rijndael\n");
|
||||||
cryptolist.write ("AES-192: gcry_rijndael\n");
|
cryptolist.write ("AES-192: gcry_rijndael\n");
|
||||||
cryptolist.write ("AES-256: gcry_rijndael\n");
|
cryptolist.write ("AES-256: gcry_rijndael\n");
|
||||||
|
|
||||||
|
cryptolist.write ("ADLER32: adler32\n");
|
||||||
|
|
||||||
for cipher_file in cipher_files:
|
for cipher_file in cipher_files:
|
||||||
infile = os.path.join (cipher_dir_in, cipher_file)
|
infile = os.path.join (cipher_dir_in, cipher_file)
|
||||||
outfile = os.path.join (cipher_dir_out, cipher_file)
|
outfile = os.path.join (cipher_dir_out, cipher_file)
|
||||||
|
|
Loading…
Reference in a new issue