diff options
Diffstat (limited to 'master/debian')
46 files changed, 18025 insertions, 0 deletions
diff --git a/master/debian/4k_sectors.patch b/master/debian/4k_sectors.patch new file mode 100644 index 0000000..7281b3f --- /dev/null +++ b/master/debian/4k_sectors.patch @@ -0,0 +1,1029 @@ +Description: Support non-512B sectors and agglomerate reads +Author: Vladimir Serbinenko <phcoder@gmail.com> +Origin: backport, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3325 +Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3476 +Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3709 +Forwarded: not-needed +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3325 +Last-Update: 2012-04-02 + +Index: b/Makefile.util.def +=================================================================== +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -34,6 +34,7 @@ + common_nodist = grub_script.tab.h; + + common = grub-core/commands/blocklist.c; ++ common = grub-core/commands/testload.c; + common = grub-core/commands/extcmd.c; + common = grub-core/commands/ls.c; + common = grub-core/disk/dmraid_nvidia.c; +Index: b/grub-core/disk/efi/efidisk.c +=================================================================== +--- a/grub-core/disk/efi/efidisk.c ++++ b/grub-core/disk/efi/efidisk.c +@@ -33,12 +33,10 @@ + grub_efi_device_path_t *device_path; + grub_efi_device_path_t *last_device_path; + grub_efi_block_io_t *block_io; +- grub_efi_disk_io_t *disk_io; + struct grub_efidisk_data *next; + }; + +-/* GUIDs. */ +-static grub_efi_guid_t disk_io_guid = GRUB_EFI_DISK_IO_GUID; ++/* GUID. */ + static grub_efi_guid_t block_io_guid = GRUB_EFI_BLOCK_IO_GUID; + + static struct grub_efidisk_data *fd_devices; +@@ -143,7 +141,7 @@ + struct grub_efidisk_data *devices = 0; + + /* Find handles which support the disk io interface. */ +- handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &disk_io_guid, ++ handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &block_io_guid, + 0, &num_handles); + if (! handles) + return 0; +@@ -155,7 +153,6 @@ + grub_efi_device_path_t *ldp; + struct grub_efidisk_data *d; + grub_efi_block_io_t *bio; +- grub_efi_disk_io_t *dio; + + dp = grub_efi_get_device_path (*handle); + if (! dp) +@@ -168,9 +165,7 @@ + + bio = grub_efi_open_protocol (*handle, &block_io_guid, + GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); +- dio = grub_efi_open_protocol (*handle, &disk_io_guid, +- GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); +- if (! bio || ! dio) ++ if (! bio) + /* This should not happen... Why? */ + continue; + +@@ -186,7 +181,6 @@ + d->device_path = dp; + d->last_device_path = ldp; + d->block_io = bio; +- d->disk_io = dio; + d->next = devices; + devices = d; + } +@@ -536,8 +530,13 @@ + and total sectors should be replaced with total blocks. */ + grub_dprintf ("efidisk", "m = %p, last block = %llx, block size = %x\n", + m, (unsigned long long) m->last_block, m->block_size); +- disk->total_sectors = (m->last_block +- * (m->block_size >> GRUB_DISK_SECTOR_BITS)); ++ disk->total_sectors = m->last_block; ++ if (m->block_size & (m->block_size - 1) || !m->block_size) ++ return grub_error (GRUB_ERR_IO, "invalid sector size %d", ++ m->block_size); ++ for (disk->log_sector_size = 0; ++ (1U << disk->log_sector_size) < m->block_size; ++ disk->log_sector_size++); + disk->data = d; + + grub_dprintf ("efidisk", "opening %s succeeded\n", name); +@@ -558,22 +557,20 @@ + { + /* For now, use the disk io interface rather than the block io's. */ + struct grub_efidisk_data *d; +- grub_efi_disk_io_t *dio; + grub_efi_block_io_t *bio; + grub_efi_status_t status; + + d = disk->data; +- dio = d->disk_io; + bio = d->block_io; + + grub_dprintf ("efidisk", + "reading 0x%lx sectors at the sector 0x%llx from %s\n", + (unsigned long) size, (unsigned long long) sector, disk->name); + +- status = efi_call_5 (dio->read, dio, bio->media->media_id, +- (grub_efi_uint64_t) sector << GRUB_DISK_SECTOR_BITS, +- (grub_efi_uintn_t) size << GRUB_DISK_SECTOR_BITS, +- buf); ++ status = efi_call_5 (bio->read_blocks, bio, bio->media->media_id, ++ (grub_efi_uint64_t) sector, ++ (grub_efi_uintn_t) size << disk->log_sector_size, ++ buf); + if (status != GRUB_EFI_SUCCESS) + return grub_error (GRUB_ERR_READ_ERROR, "efidisk read error"); + +@@ -586,21 +583,19 @@ + { + /* For now, use the disk io interface rather than the block io's. */ + struct grub_efidisk_data *d; +- grub_efi_disk_io_t *dio; + grub_efi_block_io_t *bio; + grub_efi_status_t status; + + d = disk->data; +- dio = d->disk_io; + bio = d->block_io; + + grub_dprintf ("efidisk", + "writing 0x%lx sectors at the sector 0x%llx to %s\n", + (unsigned long) size, (unsigned long long) sector, disk->name); + +- status = efi_call_5 (dio->write, dio, bio->media->media_id, +- (grub_efi_uint64_t) sector << GRUB_DISK_SECTOR_BITS, +- (grub_efi_uintn_t) size << GRUB_DISK_SECTOR_BITS, ++ status = efi_call_5 (bio->write_blocks, bio, bio->media->media_id, ++ (grub_efi_uint64_t) sector, ++ (grub_efi_uintn_t) size << disk->log_sector_size, + (void *) buf); + if (status != GRUB_EFI_SUCCESS) + return grub_error (GRUB_ERR_WRITE_ERROR, "efidisk write error"); +Index: b/grub-core/disk/i386/pc/biosdisk.c +=================================================================== +--- a/grub-core/disk/i386/pc/biosdisk.c ++++ b/grub-core/disk/i386/pc/biosdisk.c +@@ -340,7 +340,8 @@ + if ((cd_drive) && (drive == cd_drive)) + { + data->flags = GRUB_BIOSDISK_FLAG_LBA | GRUB_BIOSDISK_FLAG_CDROM; +- data->sectors = 32; ++ data->sectors = 8; ++ disk->log_sector_size = 11; + /* TODO: get the correct size. */ + total_sectors = GRUB_DISK_SIZE_UNKNOWN; + } +@@ -349,6 +350,8 @@ + /* HDD */ + int version; + ++ disk->log_sector_size = 9; ++ + version = grub_biosdisk_check_int13_extensions (drive); + if (version) + { +@@ -369,6 +372,15 @@ + correctly but returns zero. So if it is zero, compute + it by C/H/S returned by the LBA BIOS call. */ + total_sectors = drp->cylinders * drp->heads * drp->sectors; ++ if (drp->bytes_per_sector ++ && !(drp->bytes_per_sector & (drp->bytes_per_sector - 1)) ++ && drp->bytes_per_sector >= 512 ++ && drp->bytes_per_sector <= 16384) ++ { ++ for (disk->log_sector_size = 0; ++ (1 << disk->log_sector_size) < drp->bytes_per_sector; ++ disk->log_sector_size++); ++ } + } + } + } +@@ -431,7 +443,7 @@ + + dap = (struct grub_biosdisk_dap *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + + (data->sectors +- << GRUB_DISK_SECTOR_BITS)); ++ << disk->log_sector_size)); + dap->length = sizeof (*dap); + dap->reserved = 0; + dap->blocks = size; +@@ -445,9 +457,6 @@ + if (cmd) + return grub_error (GRUB_ERR_WRITE_ERROR, "can\'t write to cdrom"); + +- dap->blocks = ALIGN_UP (dap->blocks, 4) >> 2; +- dap->block >>= 2; +- + for (i = 0; i < GRUB_BIOSDISK_CDROM_RETRY_COUNT; i++) + if (! grub_biosdisk_rw_int13_extensions (0x42, data->drive, dap)) + break; +@@ -503,19 +512,21 @@ + + /* Return the number of sectors which can be read safely at a time. */ + static grub_size_t +-get_safe_sectors (grub_disk_addr_t sector, grub_uint32_t sectors) ++get_safe_sectors (grub_disk_t disk, grub_disk_addr_t sector) + { + grub_size_t size; +- grub_uint32_t offset; ++ grub_uint64_t offset; ++ struct grub_biosdisk_data *data = disk->data; ++ grub_uint32_t sectors = data->sectors; + + /* OFFSET = SECTOR % SECTORS */ +- grub_divmod64 (sector, sectors, &offset); ++ grub_divmod64_full (sector, sectors, &offset); + + size = sectors - offset; + + /* Limit the max to 0x7f because of Phoenix EDD. */ +- if (size > 0x7f) +- size = 0x7f; ++ if (size > ((0x7fU << GRUB_DISK_SECTOR_BITS) >> disk->log_sector_size)) ++ size = ((0x7fU << GRUB_DISK_SECTOR_BITS) >> disk->log_sector_size); + + return size; + } +@@ -524,21 +535,11 @@ + grub_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector, + grub_size_t size, char *buf) + { +- struct grub_biosdisk_data *data = disk->data; +- + while (size) + { + grub_size_t len; +- grub_size_t cdoff = 0; + +- len = get_safe_sectors (sector, data->sectors); +- +- if (data->flags & GRUB_BIOSDISK_FLAG_CDROM) +- { +- cdoff = (sector & 3) << GRUB_DISK_SECTOR_BITS; +- len = ALIGN_UP (sector + len, 4) - (sector & ~3); +- sector &= ~3; +- } ++ len = get_safe_sectors (disk, sector); + + if (len > size) + len = size; +@@ -547,9 +548,10 @@ + GRUB_MEMORY_MACHINE_SCRATCH_SEG)) + return grub_errno; + +- grub_memcpy (buf, (void *) (GRUB_MEMORY_MACHINE_SCRATCH_ADDR + cdoff), +- len << GRUB_DISK_SECTOR_BITS); +- buf += len << GRUB_DISK_SECTOR_BITS; ++ grub_memcpy (buf, (void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, ++ len << disk->log_sector_size); ++ ++ buf += len << disk->log_sector_size; + sector += len; + size -= len; + } +@@ -570,18 +572,18 @@ + { + grub_size_t len; + +- len = get_safe_sectors (sector, data->sectors); ++ len = get_safe_sectors (disk, sector); + if (len > size) + len = size; + + grub_memcpy ((void *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR, buf, +- len << GRUB_DISK_SECTOR_BITS); ++ len << disk->log_sector_size); + + if (grub_biosdisk_rw (GRUB_BIOSDISK_WRITE, disk, sector, len, + GRUB_MEMORY_MACHINE_SCRATCH_SEG)) + return grub_errno; + +- buf += len << GRUB_DISK_SECTOR_BITS; ++ buf += len << disk->log_sector_size; + sector += len; + size -= len; + } +Index: b/grub-core/disk/scsi.c +=================================================================== +--- a/grub-core/disk/scsi.c ++++ b/grub-core/disk/scsi.c +@@ -465,15 +465,20 @@ + return err; + } + +- /* SCSI blocks can be something else than 512, although GRUB +- wants 512 byte blocks. */ +- disk->total_sectors = ((grub_uint64_t)scsi->size +- * (grub_uint64_t)scsi->blocksize) +- >> GRUB_DISK_SECTOR_BITS; ++ disk->total_sectors = scsi->size; ++ if (scsi->blocksize & (scsi->blocksize - 1) || !scsi->blocksize) ++ { ++ grub_free (scsi); ++ return grub_error (GRUB_ERR_IO, "invalid sector size %d", ++ scsi->blocksize); ++ } ++ for (disk->log_sector_size = 0; ++ (1 << disk->log_sector_size) < scsi->blocksize; ++ disk->log_sector_size++); + + grub_dprintf ("scsi", "blocks=%u, blocksize=%u\n", + scsi->size, scsi->blocksize); +- grub_dprintf ("scsi", "Disk total 512 sectors = %llu\n", ++ grub_dprintf ("scsi", "Disk total sectors = %llu\n", + (unsigned long long) disk->total_sectors); + + return GRUB_ERR_NONE; +@@ -503,25 +508,6 @@ + + scsi = disk->data; + +- /* SCSI sectors are variable in size. GRUB uses 512 byte +- sectors. */ +- if (scsi->blocksize != GRUB_DISK_SECTOR_SIZE) +- { +- unsigned spb = scsi->blocksize >> GRUB_DISK_SECTOR_BITS; +- if (spb == 0 || (scsi->blocksize & (GRUB_DISK_SECTOR_SIZE - 1)) != 0) +- return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, +- "unsupported SCSI block size"); +- +- grub_uint32_t sector_mod = 0; +- sector = grub_divmod64 (sector, spb, §or_mod); +- +- if (! (sector_mod == 0 && size % spb == 0)) +- return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, +- "unaligned SCSI read not supported"); +- +- size /= spb; +- } +- + /* Depending on the type, select a read function. */ + switch (scsi->devtype) + { +Index: b/grub-core/kern/disk.c +=================================================================== +--- a/grub-core/kern/disk.c ++++ b/grub-core/kern/disk.c +@@ -247,6 +247,7 @@ + disk = (grub_disk_t) grub_zalloc (sizeof (*disk)); + if (! disk) + return 0; ++ disk->log_sector_size = GRUB_DISK_SECTOR_BITS; + + p = find_part_sep (name); + if (p) +@@ -266,7 +267,6 @@ + if (! disk->name) + goto fail; + +- + for (dev = grub_disk_dev_list; dev; dev = dev->next) + { + if ((dev->open) (raw, disk) == GRUB_ERR_NONE) +@@ -282,6 +282,14 @@ + grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such disk"); + goto fail; + } ++ if (disk->log_sector_size > GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS ++ || disk->log_sector_size < GRUB_DISK_SECTOR_BITS) ++ { ++ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, ++ "sector sizes of %d bytes aren't supported yet", ++ (1 << disk->log_sector_size)); ++ goto fail; ++ } + + disk->dev = dev; + +@@ -373,21 +381,113 @@ + *sector += start; + } + +- if (disk->total_sectors <= *sector +- || ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1) +- >> GRUB_DISK_SECTOR_BITS) > disk->total_sectors - *sector) ++ if (disk->total_sectors != GRUB_DISK_SIZE_UNKNOWN ++ && ((disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)) <= *sector ++ || ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1) ++ >> GRUB_DISK_SECTOR_BITS) > (disk->total_sectors ++ << (disk->log_sector_size ++ - GRUB_DISK_SECTOR_BITS)) - *sector)) + return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of disk"); + + return GRUB_ERR_NONE; + } + ++static inline grub_disk_addr_t ++transform_sector (grub_disk_t disk, grub_disk_addr_t sector) ++{ ++ return sector >> (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); ++} ++ ++/* Small read (less than cache size and not pass across cache unit boundaries). ++ sector is already adjusted and is divisible by cache unit size. ++ */ ++static grub_err_t ++grub_disk_read_small (grub_disk_t disk, grub_disk_addr_t sector, ++ grub_off_t offset, grub_size_t size, void *buf) ++{ ++ char *data; ++ char *tmp_buf; ++ ++ /* Fetch the cache. */ ++ data = grub_disk_cache_fetch (disk->dev->id, disk->id, sector); ++ if (data) ++ { ++ /* Just copy it! */ ++ grub_memcpy (buf, data + offset, size); ++ grub_disk_cache_unlock (disk->dev->id, disk->id, sector); ++ return GRUB_ERR_NONE; ++ } ++ ++ /* Allocate a temporary buffer. */ ++ tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS); ++ if (! tmp_buf) ++ return grub_errno; ++ ++ /* Otherwise read data from the disk actually. */ ++ if (disk->total_sectors == GRUB_DISK_SIZE_UNKNOWN ++ || sector + GRUB_DISK_CACHE_SIZE ++ < (disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS))) ++ { ++ grub_err_t err; ++ err = (disk->dev->read) (disk, transform_sector (disk, sector), ++ 1 << (GRUB_DISK_CACHE_BITS ++ + GRUB_DISK_SECTOR_BITS ++ - disk->log_sector_size), tmp_buf); ++ if (!err) ++ { ++ /* Copy it and store it in the disk cache. */ ++ grub_memcpy (buf, tmp_buf + offset, size); ++ grub_disk_cache_store (disk->dev->id, disk->id, ++ sector, tmp_buf); ++ grub_free (tmp_buf); ++ return GRUB_ERR_NONE; ++ } ++ } ++ ++ grub_free (tmp_buf); ++ grub_errno = GRUB_ERR_NONE; ++ ++ { ++ /* Uggh... Failed. Instead, just read necessary data. */ ++ unsigned num; ++ grub_disk_addr_t aligned_sector; ++ ++ sector += (offset >> GRUB_DISK_SECTOR_BITS); ++ offset &= ((1 << GRUB_DISK_SECTOR_BITS) - 1); ++ aligned_sector = (sector & ~((1 << (disk->log_sector_size ++ - GRUB_DISK_SECTOR_BITS)) ++ - 1)); ++ offset += ((sector - aligned_sector) << GRUB_DISK_SECTOR_BITS); ++ num = ((size + offset + (1 << (disk->log_sector_size)) ++ - 1) >> (disk->log_sector_size)); ++ ++ tmp_buf = grub_malloc (num << disk->log_sector_size); ++ if (!tmp_buf) ++ return grub_errno; ++ ++ if ((disk->dev->read) (disk, transform_sector (disk, aligned_sector), ++ num, tmp_buf)) ++ { ++ grub_error_push (); ++ grub_dprintf ("disk", "%s read failed\n", disk->name); ++ grub_error_pop (); ++ grub_free (tmp_buf); ++ return grub_errno; ++ } ++ grub_memcpy (buf, tmp_buf + offset, size); ++ grub_free (tmp_buf); ++ return GRUB_ERR_NONE; ++ } ++} ++ + /* Read data from the disk. */ + grub_err_t + grub_disk_read (grub_disk_t disk, grub_disk_addr_t sector, + grub_off_t offset, grub_size_t size, void *buf) + { +- char *tmp_buf; +- unsigned real_offset; ++ grub_off_t real_offset; ++ grub_disk_addr_t real_sector; ++ grub_size_t real_size; + + /* First of all, check if the region is within the disk. */ + if (grub_disk_adjust_range (disk, §or, &offset, size) != GRUB_ERR_NONE) +@@ -399,126 +499,126 @@ + return grub_errno; + } + ++ real_sector = sector; + real_offset = offset; ++ real_size = size; + +- /* Allocate a temporary buffer. */ +- tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS); +- if (! tmp_buf) +- return grub_errno; +- +- /* Until SIZE is zero... */ +- while (size) ++ /* First read until first cache boundary. */ ++ if (offset || (sector & (GRUB_DISK_CACHE_SIZE - 1))) + { +- char *data; + grub_disk_addr_t start_sector; +- grub_size_t len; + grub_size_t pos; ++ grub_err_t err; ++ grub_size_t len; + +- /* For reading bulk data. */ + start_sector = sector & ~(GRUB_DISK_CACHE_SIZE - 1); + pos = (sector - start_sector) << GRUB_DISK_SECTOR_BITS; + len = ((GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS) +- - pos - real_offset); ++ - pos - offset); + if (len > size) + len = size; ++ err = grub_disk_read_small (disk, start_sector, ++ offset + pos, len, buf); ++ if (err) ++ return err; ++ buf = (char *) buf + len; ++ size -= len; ++ offset += len; ++ sector += (offset >> GRUB_DISK_SECTOR_BITS); ++ offset &= ((1 << GRUB_DISK_SECTOR_BITS) - 1); ++ } + +- /* Fetch the cache. */ +- data = grub_disk_cache_fetch (disk->dev->id, disk->id, start_sector); +- if (data) ++ /* Until SIZE is zero... */ ++ while (size >= (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS)) ++ { ++ char *data = NULL; ++ grub_disk_addr_t agglomerate; ++ grub_err_t err; ++ ++ /* agglomerate read until we find a first cached entry. */ ++ for (agglomerate = 0; agglomerate ++ < (size >> (GRUB_DISK_SECTOR_BITS + GRUB_DISK_CACHE_BITS)); ++ agglomerate++) + { +- /* Just copy it! */ +- grub_memcpy (buf, data + pos + real_offset, len); +- grub_disk_cache_unlock (disk->dev->id, disk->id, start_sector); ++ data = grub_disk_cache_fetch (disk->dev->id, disk->id, ++ sector + (agglomerate ++ << GRUB_DISK_CACHE_BITS)); ++ if (data) ++ break; + } +- else ++ ++ if (data) + { +- /* Otherwise read data from the disk actually. */ +- if (start_sector + GRUB_DISK_CACHE_SIZE > disk->total_sectors +- || (disk->dev->read) (disk, start_sector, +- GRUB_DISK_CACHE_SIZE, tmp_buf) +- != GRUB_ERR_NONE) +- { +- /* Uggh... Failed. Instead, just read necessary data. */ +- unsigned num; +- char *p; +- +- grub_errno = GRUB_ERR_NONE; +- +- num = ((size + real_offset + GRUB_DISK_SECTOR_SIZE - 1) +- >> GRUB_DISK_SECTOR_BITS); +- +- p = grub_realloc (tmp_buf, num << GRUB_DISK_SECTOR_BITS); +- if (!p) +- goto finish; +- +- tmp_buf = p; +- +- if ((disk->dev->read) (disk, sector, num, tmp_buf)) +- { +- grub_error_push (); +- grub_dprintf ("disk", "%s read failed\n", disk->name); +- grub_error_pop (); +- goto finish; +- } +- +- grub_memcpy (buf, tmp_buf + real_offset, size); +- +- /* Call the read hook, if any. */ +- if (disk->read_hook) +- while (size) +- { +- grub_size_t to_read = (size > GRUB_DISK_SECTOR_SIZE) ? GRUB_DISK_SECTOR_SIZE : size; +- (disk->read_hook) (sector, real_offset, +- to_read); +- if (grub_errno != GRUB_ERR_NONE) +- goto finish; +- +- sector++; +- size -= to_read - real_offset; +- real_offset = 0; +- } ++ grub_memcpy ((char *) buf ++ + (agglomerate << (GRUB_DISK_CACHE_BITS ++ + GRUB_DISK_SECTOR_BITS)), ++ data, GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS); ++ grub_disk_cache_unlock (disk->dev->id, disk->id, ++ sector + (agglomerate ++ << GRUB_DISK_CACHE_BITS)); ++ } + +- /* This must be the end. */ +- goto finish; +- } ++ if (agglomerate) ++ { ++ grub_disk_addr_t i; + +- /* Copy it and store it in the disk cache. */ +- grub_memcpy (buf, tmp_buf + pos + real_offset, len); +- grub_disk_cache_store (disk->dev->id, disk->id, +- start_sector, tmp_buf); ++ err = (disk->dev->read) (disk, transform_sector (disk, sector), ++ agglomerate << (GRUB_DISK_CACHE_BITS ++ + GRUB_DISK_SECTOR_BITS ++ - disk->log_sector_size), ++ buf); ++ if (err) ++ return err; ++ ++ for (i = 0; i < agglomerate; i ++) ++ grub_disk_cache_store (disk->dev->id, disk->id, ++ sector + (i << GRUB_DISK_CACHE_BITS), ++ (char *) buf ++ + (i << (GRUB_DISK_CACHE_BITS ++ + GRUB_DISK_SECTOR_BITS))); ++ ++ sector += agglomerate << GRUB_DISK_CACHE_BITS; ++ size -= agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS); ++ buf = (char *) buf ++ + (agglomerate << (GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS)); + } + +- /* Call the read hook, if any. */ +- if (disk->read_hook) ++ if (data) + { +- grub_disk_addr_t s = sector; +- grub_size_t l = len; +- +- while (l) +- { +- (disk->read_hook) (s, real_offset, +- ((l > GRUB_DISK_SECTOR_SIZE) +- ? GRUB_DISK_SECTOR_SIZE +- : l)); +- +- if (l < GRUB_DISK_SECTOR_SIZE - real_offset) +- break; +- +- s++; +- l -= GRUB_DISK_SECTOR_SIZE - real_offset; +- real_offset = 0; +- } ++ sector += GRUB_DISK_CACHE_SIZE; ++ buf = (char *) buf + (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS); ++ size -= (GRUB_DISK_CACHE_SIZE << GRUB_DISK_SECTOR_BITS); + } ++ } + +- sector = start_sector + GRUB_DISK_CACHE_SIZE; +- buf = (char *) buf + len; +- size -= len; +- real_offset = 0; ++ /* And now read the last part. */ ++ if (size) ++ { ++ grub_err_t err; ++ err = grub_disk_read_small (disk, sector, 0, size, buf); ++ if (err) ++ return err; + } + +- finish: ++ /* Call the read hook, if any. */ ++ if (disk->read_hook) ++ { ++ grub_disk_addr_t s = real_sector; ++ grub_size_t l = real_size; ++ grub_off_t o = real_offset; + +- grub_free (tmp_buf); ++ while (l) ++ { ++ grub_size_t cl; ++ cl = GRUB_DISK_SECTOR_SIZE - o; ++ if (cl > l) ++ cl = l; ++ (disk->read_hook) (s, o, cl); ++ s++; ++ l -= cl; ++ o = 0; ++ } ++ } + + return grub_errno; + } +@@ -528,25 +628,31 @@ + grub_off_t offset, grub_size_t size, const void *buf) + { + unsigned real_offset; ++ grub_disk_addr_t aligned_sector; + + grub_dprintf ("disk", "Writing `%s'...\n", disk->name); + + if (grub_disk_adjust_range (disk, §or, &offset, size) != GRUB_ERR_NONE) + return -1; + +- real_offset = offset; ++ aligned_sector = (sector & ~((1 << (disk->log_sector_size ++ - GRUB_DISK_SECTOR_BITS)) - 1)); ++ real_offset = offset + ((sector - aligned_sector) << GRUB_DISK_SECTOR_BITS); ++ sector = aligned_sector; + + while (size) + { +- if (real_offset != 0 || (size < GRUB_DISK_SECTOR_SIZE && size != 0)) ++ if (real_offset != 0 || (size < (1U << disk->log_sector_size) ++ && size != 0)) + { +- char tmp_buf[GRUB_DISK_SECTOR_SIZE]; ++ char tmp_buf[1 << disk->log_sector_size]; + grub_size_t len; + grub_partition_t part; + + part = disk->partition; + disk->partition = 0; +- if (grub_disk_read (disk, sector, 0, GRUB_DISK_SECTOR_SIZE, tmp_buf) ++ if (grub_disk_read (disk, sector, ++ 0, (1 << disk->log_sector_size), tmp_buf) + != GRUB_ERR_NONE) + { + disk->partition = part; +@@ -554,7 +660,7 @@ + } + disk->partition = part; + +- len = GRUB_DISK_SECTOR_SIZE - real_offset; ++ len = (1 << disk->log_sector_size) - real_offset; + if (len > size) + len = size; + +@@ -565,7 +671,7 @@ + if ((disk->dev->write) (disk, sector, 1, tmp_buf) != GRUB_ERR_NONE) + goto finish; + +- sector++; ++ sector += (1 << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); + buf = (char *) buf + len; + size -= len; + real_offset = 0; +@@ -575,8 +681,8 @@ + grub_size_t len; + grub_size_t n; + +- len = size & ~(GRUB_DISK_SECTOR_SIZE - 1); +- n = size >> GRUB_DISK_SECTOR_BITS; ++ len = size & ~((1 << disk->log_sector_size) - 1); ++ n = size >> disk->log_sector_size; + + if ((disk->dev->write) (disk, sector, n, buf) != GRUB_ERR_NONE) + goto finish; +@@ -599,6 +705,8 @@ + { + if (disk->partition) + return grub_partition_get_len (disk->partition); ++ else if (disk->total_sectors != GRUB_DISK_SIZE_UNKNOWN) ++ return disk->total_sectors << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); + else +- return disk->total_sectors; ++ return GRUB_DISK_SIZE_UNKNOWN; + } +Index: b/grub-core/kern/emu/hostdisk.c +=================================================================== +--- a/grub-core/kern/emu/hostdisk.c ++++ b/grub-core/kern/emu/hostdisk.c +@@ -43,6 +43,7 @@ + + #ifdef __linux__ + # include <sys/ioctl.h> /* ioctl */ ++# include <sys/mount.h> + # if !defined(__GLIBC__) || \ + ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 1))) + /* Maybe libc doesn't have large file support. */ +@@ -267,6 +268,7 @@ + # else + unsigned long long nr; + # endif ++ int sector_size; + int fd; + + fd = open (map[drive].device, O_RDONLY); +@@ -299,16 +301,32 @@ + goto fail; + } + ++# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) ++ if (ioctl (fd, DIOCGSECTORSIZE, §or_size)) ++# else ++ if (ioctl (fd, BLKSSZGET, §or_size)) ++# endif ++ { ++ close (fd); ++ goto fail; ++ } ++ + close (fd); + ++ if (sector_size & (sector_size - 1) || !sector_size) ++ goto fail; ++ for (disk->log_sector_size = 0; ++ (1 << disk->log_sector_size) < sector_size; ++ disk->log_sector_size++); ++ + # if defined (__APPLE__) + disk->total_sectors = nr; + # elif defined(__NetBSD__) + disk->total_sectors = label.d_secperunit; + # else +- disk->total_sectors = nr / 512; ++ disk->total_sectors = nr >> disk->log_sector_size; + +- if (nr % 512) ++ if (nr & ((1 << disk->log_sector_size) - 1)) + grub_util_error ("unaligned device size"); + # endif + +@@ -325,7 +343,7 @@ + if (stat (map[drive].device, &st) < 0) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "cannot stat `%s'", map[drive].device); + +- disk->total_sectors = st.st_size >> GRUB_DISK_SECTOR_BITS; ++ disk->total_sectors = st.st_size >> disk->log_sector_size; + + grub_util_info ("the size of %s is %lu", name, disk->total_sectors); + +@@ -798,7 +816,7 @@ + _syscall5 (int, _llseek, uint, filedes, ulong, hi, ulong, lo, + loff_t *, res, uint, wh); + +- offset = (loff_t) sector << GRUB_DISK_SECTOR_BITS; ++ offset = (loff_t) sector << disk->log_sector_size; + if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET)) + { + grub_error (GRUB_ERR_BAD_DEVICE, "cannot seek `%s'", map[disk->id].device); +@@ -808,7 +826,7 @@ + } + #else + { +- off_t offset = (off_t) sector << GRUB_DISK_SECTOR_BITS; ++ off_t offset = (off_t) sector << disk->log_sector_size; + + if (lseek (fd, offset, SEEK_SET) != offset) + { +@@ -908,19 +926,20 @@ + sectors that are read together with the MBR in one read. It + should only remap the MBR, so we split the read in two + parts. -jochen */ +- if (nread (fd, buf, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE) ++ if (nread (fd, buf, (1 << disk->log_sector_size)) ++ != (1 << disk->log_sector_size)) + { + grub_error (GRUB_ERR_READ_ERROR, "cannot read `%s'", map[disk->id].device); + return grub_errno; + } + +- buf += GRUB_DISK_SECTOR_SIZE; ++ buf += (1 << disk->log_sector_size); + size--; + } + #endif /* __linux__ */ + +- if (nread (fd, buf, size << GRUB_DISK_SECTOR_BITS) +- != (ssize_t) (size << GRUB_DISK_SECTOR_BITS)) ++ if (nread (fd, buf, size << disk->log_sector_size) ++ != (ssize_t) (size << disk->log_sector_size)) + grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id].device); + + return grub_errno; +@@ -953,8 +972,8 @@ + if (fd < 0) + return grub_errno; + +- if (nwrite (fd, buf, size << GRUB_DISK_SECTOR_BITS) +- != (ssize_t) (size << GRUB_DISK_SECTOR_BITS)) ++ if (nwrite (fd, buf, size << disk->log_sector_size) ++ != (ssize_t) (size << disk->log_sector_size)) + grub_error (GRUB_ERR_WRITE_ERROR, "cannot write to `%s'", map[disk->id].device); + + return grub_errno; +Index: b/grub-core/partmap/msdos.c +=================================================================== +--- a/grub-core/partmap/msdos.c ++++ b/grub-core/partmap/msdos.c +@@ -152,8 +152,11 @@ + { + e = mbr.entries + p.index; + +- p.start = p.offset + grub_le_to_cpu32 (e->start) - delta; +- p.len = grub_le_to_cpu32 (e->length); ++ p.start = p.offset ++ + (grub_le_to_cpu32 (e->start) ++ << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)) - delta; ++ p.len = grub_le_to_cpu32 (e->length) ++ << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); + p.msdostype = e->type; + + grub_dprintf ("partition", +@@ -188,7 +191,9 @@ + + if (grub_msdos_partition_is_extended (e->type)) + { +- p.offset = ext_offset + grub_le_to_cpu32 (e->start); ++ p.offset = ext_offset ++ + (grub_le_to_cpu32 (e->start) ++ << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); + if (! ext_offset) + ext_offset = p.offset; + +@@ -267,8 +272,11 @@ + e = mbr.entries + i; + + if (!grub_msdos_partition_is_empty (e->type) +- && end > offset + grub_le_to_cpu32 (e->start)) +- end = offset + grub_le_to_cpu32 (e->start); ++ && end > offset ++ + (grub_le_to_cpu32 (e->start) ++ << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS))) ++ end = offset + (grub_le_to_cpu32 (e->start) ++ << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); + + /* If this is a GPT partition, this MBR is just a dummy. */ + if (e->type == GRUB_PC_PARTITION_TYPE_GPT_DISK && i == 0) +@@ -282,7 +290,9 @@ + + if (grub_msdos_partition_is_extended (e->type)) + { +- offset = ext_offset + grub_le_to_cpu32 (e->start); ++ offset = ext_offset ++ + (grub_le_to_cpu32 (e->start) ++ << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); + if (! ext_offset) + ext_offset = offset; + +Index: b/include/grub/disk.h +=================================================================== +--- a/include/grub/disk.h ++++ b/include/grub/disk.h +@@ -100,6 +100,9 @@ + /* The total number of sectors. */ + grub_uint64_t total_sectors; + ++ /* Logarithm of sector size. */ ++ unsigned int log_sector_size; ++ + /* The id used by the disk cache manager. */ + unsigned long id; + +@@ -132,9 +135,10 @@ + /* The maximum number of disk caches. */ + #define GRUB_DISK_CACHE_NUM 1021 + +-/* The size of a disk cache in sector units. */ +-#define GRUB_DISK_CACHE_SIZE 8 +-#define GRUB_DISK_CACHE_BITS 3 ++/* The size of a disk cache in 512B units. Must be at least as big as the ++ largest supported sector size, currently 16K. */ ++#define GRUB_DISK_CACHE_BITS 6 ++#define GRUB_DISK_CACHE_SIZE (1 << GRUB_DISK_CACHE_BITS) + + /* Return value of grub_disk_get_size() in case disk size is unknown. */ + #define GRUB_DISK_SIZE_UNKNOWN 0xffffffffffffffffULL +Index: b/util/grub-fstest.c +=================================================================== +--- a/util/grub-fstest.c ++++ b/util/grub-fstest.c +@@ -60,6 +60,7 @@ + #define CMD_HEX 4 + #define CMD_CRC 6 + #define CMD_BLOCKLIST 7 ++#define CMD_TESTLOAD 8 + + #define BUF_SIZE 32256 + +@@ -333,6 +334,9 @@ + case CMD_BLOCKLIST: + execute_command ("blocklist", n, args); + grub_printf ("\n"); ++ case CMD_TESTLOAD: ++ execute_command ("testload", n, args); ++ grub_printf ("\n"); + } + + for (i = 0; i < num_disks; i++) +@@ -488,6 +492,11 @@ + cmd = CMD_BLOCKLIST; + nparm = 1; + } ++ else if (!grub_strcmp (arg, "testload")) ++ { ++ cmd = CMD_TESTLOAD; ++ nparm = 1; ++ } + else + { + fprintf (stderr, _("Invalid command %s.\n"), arg); diff --git a/master/debian/bash-completion_identifiers.patch b/master/debian/bash-completion_identifiers.patch new file mode 100644 index 0000000..814c101 --- /dev/null +++ b/master/debian/bash-completion_identifiers.patch @@ -0,0 +1,45 @@ +Description: Fix incorrect identifiers in bash-completion +Author: Andreas Born <futur.andy@googlemail.com> +Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3426 +Last-Update: 2012-03-05 + +Index: b/util/bash-completion.d/grub-completion.bash.in +=================================================================== +--- a/util/bash-completion.d/grub-completion.bash.in ++++ b/util/bash-completion.d/grub-completion.bash.in +@@ -402,7 +402,7 @@ + # + # grub-mkpasswd-pbkdf2 + # +-_grub_mkpasswd-pbkdf2 () { ++_grub_mkpasswd_pbkdf2 () { + local cur + + COMPREPLY=() +@@ -417,7 +417,7 @@ + } + __grub_mkpasswd_pbkdf2_program=$( echo grub-mkpasswd-pbkdf2 | sed "@program_transform_name@" ) + have ${__grub_mkpasswd_pbkdf2_program} && \ +- complete -F _grub_mkpasswd-pbkdf2 -o filenames ${__grub_mkpasswd_pbkdf2_program} ++ complete -F _grub_mkpasswd_pbkdf2 -o filenames ${__grub_mkpasswd_pbkdf2_program} + unset __grub_mkpasswd_pbkdf2_program + + +@@ -462,7 +462,7 @@ + # + # grub-script-check + # +-_grub_script-check () { ++_grub_script_check () { + local cur + + COMPREPLY=() +@@ -477,7 +477,7 @@ + } + __grub_script_check_program=$( echo grub-script-check | sed "@program_transform_name@" ) + have ${__grub_script_check_program} && \ +- complete -F _grub_script-check -o filenames ${__grub_script_check_program} ++ complete -F _grub_script_check -o filenames ${__grub_script_check_program} + + + # Local variables: diff --git a/master/debian/branch_devmapper.patch b/master/debian/branch_devmapper.patch new file mode 100644 index 0000000..1911a0b --- /dev/null +++ b/master/debian/branch_devmapper.patch @@ -0,0 +1,286 @@ +Description: Support for partitioned loop devices; improved devmapper support +Author: Vladimir Serbinenko <phcoder@gmail.com> +Origin: upstream, http://bzr.sv.gnu.org/r/grub/branches/devmapper/ +Forwarded: not-needed +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3302 +Last-Update: 2011-05-19 + +Index: b/grub-core/kern/emu/getroot.c +=================================================================== +--- a/grub-core/kern/emu/getroot.c ++++ b/grub-core/kern/emu/getroot.c +@@ -34,6 +34,10 @@ + #include <stdint.h> + #include <grub/util/misc.h> + ++#ifdef HAVE_DEVICE_MAPPER ++# include <libdevmapper.h> ++#endif ++ + #ifdef __GNU__ + #include <hurd.h> + #include <hurd/lookup.h> +@@ -634,32 +638,65 @@ + } + + static int +-grub_util_is_dmraid (const char *os_dev) ++grub_util_is_lvm (const char *os_dev) + { +- if (! strncmp (os_dev, "/dev/mapper/nvidia_", 19)) +- return 1; +- else if (! strncmp (os_dev, "/dev/mapper/isw_", 16)) +- return 1; +- else if (! strncmp (os_dev, "/dev/mapper/hpt37x_", 19)) +- return 1; +- else if (! strncmp (os_dev, "/dev/mapper/hpt45x_", 19)) +- return 1; +- else if (! strncmp (os_dev, "/dev/mapper/via_", 16)) +- return 1; +- else if (! strncmp (os_dev, "/dev/mapper/lsi_", 16)) +- return 1; +- else if (! strncmp (os_dev, "/dev/mapper/pdc_", 16)) +- return 1; +- else if (! strncmp (os_dev, "/dev/mapper/jmicron_", 20)) +- return 1; +- else if (! strncmp (os_dev, "/dev/mapper/asr_", 16)) +- return 1; +- else if (! strncmp (os_dev, "/dev/mapper/sil_", 16)) +- return 1; +- else if (! strncmp (os_dev, "/dev/mapper/ddf1_", 17)) +- return 1; ++ if ((strncmp ("/dev/mapper/", os_dev, 12) != 0)) ++ return 0; ++ ++#ifdef HAVE_DEVICE_MAPPER ++ { ++ struct dm_tree *tree; ++ uint32_t maj, min; ++ struct dm_tree_node *node = NULL; ++ const char *node_uuid; ++ struct stat st; + +- return 0; ++ if (stat (os_dev, &st) < 0) ++ return 0; ++ ++ tree = dm_tree_create (); ++ if (! tree) ++ { ++ grub_printf ("Failed to create tree\n"); ++ grub_dprintf ("hostdisk", "dm_tree_create failed\n"); ++ return 0; ++ } ++ ++ maj = major (st.st_rdev); ++ min = minor (st.st_rdev); ++ ++ if (! dm_tree_add_dev (tree, maj, min)) ++ { ++ grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n"); ++ dm_tree_free (tree); ++ return 0; ++ } ++ ++ node = dm_tree_find_node (tree, maj, min); ++ if (! node) ++ { ++ grub_dprintf ("hostdisk", "dm_tree_find_node failed\n"); ++ dm_tree_free (tree); ++ return 0; ++ } ++ node_uuid = dm_tree_node_get_uuid (node); ++ if (! node_uuid) ++ { ++ grub_dprintf ("hostdisk", "%s has no DM uuid\n", os_dev); ++ dm_tree_free (tree); ++ return 0; ++ } ++ if (strncmp (node_uuid, "LVM-", 4) != 0) ++ { ++ dm_tree_free (tree); ++ return 0; ++ } ++ dm_tree_free (tree); ++ return 1; ++ } ++#else ++ return 1; ++#endif /* HAVE_DEVICE_MAPPER */ + } + + int +@@ -671,13 +708,11 @@ + return GRUB_DEV_ABSTRACTION_NONE; + + /* Check for LVM. */ +- if (!strncmp (os_dev, "/dev/mapper/", 12) +- && ! grub_util_is_dmraid (os_dev) +- && strncmp (os_dev, "/dev/mapper/mpath", 17) != 0) ++ if (grub_util_is_lvm (os_dev)) + return GRUB_DEV_ABSTRACTION_LVM; + + /* Check for RAID. */ +- if (!strncmp (os_dev, "/dev/md", 7)) ++ if (!strncmp (os_dev, "/dev/md", 7) && ! grub_util_device_is_mapped (os_dev)) + return GRUB_DEV_ABSTRACTION_RAID; + #endif + +Index: b/grub-core/kern/emu/hostdisk.c +=================================================================== +--- a/grub-core/kern/emu/hostdisk.c ++++ b/grub-core/kern/emu/hostdisk.c +@@ -24,6 +24,7 @@ + #include <grub/err.h> + #include <grub/emu/misc.h> + #include <grub/emu/hostdisk.h> ++#include <grub/emu/getroot.h> + #include <grub/misc.h> + #include <grub/i18n.h> + #include <grub/list.h> +@@ -331,18 +332,23 @@ + return GRUB_ERR_NONE; + } + +-#ifdef HAVE_DEVICE_MAPPER +-static int +-device_is_mapped (const char *dev) ++int ++grub_util_device_is_mapped (const char *dev) + { ++#ifdef HAVE_DEVICE_MAPPER + struct stat st; + ++ if (!grub_device_mapper_supported ()) ++ return 0; ++ + if (stat (dev, &st) < 0) + return 0; + + return dm_is_dm_major (major (st.st_rdev)); +-} ++#else ++ return 0; + #endif /* HAVE_DEVICE_MAPPER */ ++} + + #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) + /* FIXME: geom actually gives us the whole container hierarchy. +@@ -418,7 +424,7 @@ + # endif /* !defined(HAVE_DIOCGDINFO) */ + + # ifdef HAVE_DEVICE_MAPPER +- if (grub_device_mapper_supported () && device_is_mapped (dev)) { ++ if (grub_util_device_is_mapped (dev)) { + struct dm_task *task = NULL; + grub_uint64_t start, length; + char *target_type, *params, *space; +@@ -1161,6 +1167,54 @@ + return ret; + } + ++#ifdef HAVE_DEVICE_MAPPER ++static int ++grub_util_get_dm_node_linear_info (const char *dev, ++ int *maj, int *min) ++{ ++ struct dm_task *dmt; ++ void *next = NULL; ++ uint64_t length, start; ++ char *target, *params; ++ char *ptr; ++ int major, minor; ++ ++ dmt = dm_task_create(DM_DEVICE_TABLE); ++ if (!dmt) ++ return 0; ++ ++ if (!dm_task_set_name(dmt, dev)) ++ return 0; ++ dm_task_no_open_count(dmt); ++ if (!dm_task_run(dmt)) ++ return 0; ++ next = dm_get_next_target(dmt, next, &start, &length, ++ &target, ¶ms); ++ if (grub_strcmp (target, "linear") != 0) ++ return 0; ++ major = grub_strtoul (params, &ptr, 10); ++ if (grub_errno) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ return 0; ++ } ++ if (*ptr != ':') ++ return 0; ++ ptr++; ++ minor = grub_strtoul (ptr, 0, 10); ++ if (grub_errno) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ return 0; ++ } ++ if (maj) ++ *maj = major; ++ if (min) ++ *min = minor; ++ return 1; ++} ++#endif ++ + static char * + convert_system_partition_to_system_disk (const char *os_dev, struct stat *st) + { +@@ -1337,9 +1391,39 @@ + node = NULL; + goto devmapper_out; + } +- else if (strncmp (node_uuid, "DMRAID-", 7) != 0) ++ if (strncmp (node_uuid, "LVM-", 4) == 0) + { ++ grub_dprintf ("hostdisk", "%s is an LVM\n", path); ++ node = NULL; ++ goto devmapper_out; ++ } ++ if (strncmp (node_uuid, "mpath-", 6) == 0) ++ { ++ /* Multipath partitions have partN-mpath-* UUIDs, and are ++ linear mappings so are handled by ++ grub_util_get_dm_node_linear_info. Multipath disks are not ++ linear mappings and must be handled specially. */ ++ grub_dprintf ("hostdisk", "%s is a multipath disk\n", path); ++ mapper_name = dm_tree_node_get_name (node); ++ goto devmapper_out; ++ } ++ if (strncmp (node_uuid, "DMRAID-", 7) != 0) ++ { ++ int major, minor; ++ const char *node_name; + grub_dprintf ("hostdisk", "%s is not DM-RAID\n", path); ++ ++ if ((node_name = dm_tree_node_get_name (node)) ++ && grub_util_get_dm_node_linear_info (node_name, ++ &major, &minor)) ++ { ++ if (tree) ++ dm_tree_free (tree); ++ free (path); ++ char *ret = grub_find_device (NULL, (major << 8) | minor); ++ return ret; ++ } ++ + node = NULL; + goto devmapper_out; + } +Index: b/include/grub/emu/misc.h +=================================================================== +--- a/include/grub/emu/misc.h ++++ b/include/grub/emu/misc.h +@@ -54,6 +54,8 @@ + + char *grub_make_system_path_relative_to_its_root (const char *path) + __attribute__ ((warn_unused_result)); ++int ++grub_util_device_is_mapped (const char *dev); + + void * EXPORT_FUNC(xmalloc) (grub_size_t size) __attribute__ ((warn_unused_result)); + void * EXPORT_FUNC(xrealloc) (void *ptr, grub_size_t size) __attribute__ ((warn_unused_result)); diff --git a/master/debian/branch_embed-sectors.patch b/master/debian/branch_embed-sectors.patch new file mode 100644 index 0000000..9b16423 --- /dev/null +++ b/master/debian/branch_embed-sectors.patch @@ -0,0 +1,247 @@ +Description: Detect other software using embedding area + When embedding the core image in a post-MBR gap, check for and avoid + sectors matching any of the signatures in embed_signatures. +Author: Colin Watson <cjwatson@ubuntu.com> +Origin: upstream, http://bzr.sv.gnu.org/r/grub/branches/embed-sectors/ +Forwarded: http://lists.gnu.org/archive/html/grub-devel/2010-08/msg00137.html +Last-Update: 2011-04-21 + +Index: b/ChangeLog.embed-sectors +=================================================================== +--- /dev/null ++++ b/ChangeLog.embed-sectors +@@ -0,0 +1,12 @@ ++2011-03-14 Colin Watson <cjwatson@ubuntu.com> ++ ++ * include/grub/partition.h (grub_partition_map): Change prototype of ++ embed to take a maximum value for nsectors. ++ * grub-core/partmap/msdos.c (embed_signatures): New array. ++ (pc_partition_map_embed): Check for and avoid sectors matching any ++ of the signatures in embed_signatures, up to max_nsectors. ++ * grub-core/partmap/gpt.c (gpt_partition_map_embed): Restrict ++ returned sector map to max_nsectors. ++ * util/grub-setup.c (setup): Allow for the embedding area being ++ split into multiple blocklists. Tell dest_partmap->embed the ++ maximum number of sectors we care about. +Index: b/grub-core/partmap/gpt.c +=================================================================== +--- a/grub-core/partmap/gpt.c ++++ b/grub-core/partmap/gpt.c +@@ -127,6 +127,7 @@ + #ifdef GRUB_UTIL + static grub_err_t + gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, ++ unsigned int max_nsectors, + grub_embed_type_t embed_type, + grub_disk_addr_t **sectors) + { +@@ -176,6 +177,8 @@ + " embedding won't be possible!"); + + *nsectors = len; ++ if (*nsectors > max_nsectors) ++ *nsectors = max_nsectors; + *sectors = grub_malloc (*nsectors * sizeof (**sectors)); + if (!*sectors) + return grub_errno; +Index: b/grub-core/partmap/msdos.c +=================================================================== +--- a/grub-core/partmap/msdos.c ++++ b/grub-core/partmap/msdos.c +@@ -29,6 +29,66 @@ + static struct grub_partition_map grub_msdos_partition_map; + + ++#ifdef GRUB_UTIL ++#include <grub/emu/misc.h> ++ ++struct embed_signature ++{ ++ const char *name; ++ const char *signature; ++ int signature_len; ++ enum { TYPE_SOFTWARE, TYPE_RAID } type; ++}; ++ ++const char message_warn[][200] = { ++ [TYPE_RAID] = "Sector %llu is already in use by %s; avoiding it. " ++ "Please ask the manufacturer not to store data in MBR gap", ++ [TYPE_SOFTWARE] = "Sector %llu is already in use by %s; avoiding it. " ++ "This software may cause boot or other problems in " ++ "future. Please ask its authors not to store data " ++ "in the boot track" ++}; ++ ++ ++/* Signatures of other software that may be using sectors in the embedding ++ area. */ ++struct embed_signature embed_signatures[] = ++ { ++ { ++ .name = "ZISD", ++ .signature = "ZISD", ++ .signature_len = 4, ++ .type = TYPE_SOFTWARE ++ }, ++ { ++ .name = "FlexNet", ++ .signature = "\xd4\x41\xa0\xf5\x03\x00\x03\x00", ++ .signature_len = 8, ++ .type = TYPE_SOFTWARE ++ }, ++ { ++ .name = "FlexNet", ++ .signature = "\xd8\x41\xa0\xf5\x02\x00\x02\x00", ++ .signature_len = 8, ++ .type = TYPE_SOFTWARE ++ }, ++ { ++ /* from Ryan Perkins */ ++ .name = "HP Backup and Recovery Manager (?)", ++ .signature = "\x70\x8a\x5d\x46\x35\xc5\x1b\x93" ++ "\xae\x3d\x86\xfd\xb1\x55\x3e\xe0", ++ .signature_len = 16, ++ .type = TYPE_SOFTWARE ++ }, ++ { ++ .name = "HighPoint RAID controller", ++ .signature = "ycgl", ++ .signature_len = 4, ++ .type = TYPE_RAID ++ } ++ }; ++#endif ++ + grub_err_t + grub_partition_msdos_iterate (grub_disk_t disk, + int (*hook) (grub_disk_t disk, +@@ -148,6 +208,7 @@ + #ifdef GRUB_UTIL + static grub_err_t + pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, ++ unsigned int max_nsectors, + grub_embed_type_t embed_type, + grub_disk_addr_t **sectors) + { +@@ -236,13 +297,65 @@ + + if (end >= *nsectors + 2) + { +- unsigned i; ++ unsigned i, j; ++ char *embed_signature_check; ++ unsigned int orig_nsectors, avail_nsectors; ++ ++ orig_nsectors = *nsectors; + *nsectors = end - 2; ++ avail_nsectors = *nsectors; ++ if (*nsectors > max_nsectors) ++ *nsectors = max_nsectors; + *sectors = grub_malloc (*nsectors * sizeof (**sectors)); + if (!*sectors) + return grub_errno; + for (i = 0; i < *nsectors; i++) + (*sectors)[i] = 1 + i; ++ ++ /* Check for software that is already using parts of the embedding ++ * area. ++ */ ++ embed_signature_check = grub_malloc (GRUB_DISK_SECTOR_SIZE); ++ for (i = 0; i < *nsectors; i++) ++ { ++ if (grub_disk_read (disk, (*sectors)[i], 0, GRUB_DISK_SECTOR_SIZE, ++ embed_signature_check)) ++ continue; ++ ++ for (j = 0; j < ARRAY_SIZE (embed_signatures); j++) ++ if (! grub_memcmp (embed_signatures[j].signature, ++ embed_signature_check, ++ embed_signatures[j].signature_len)) ++ break; ++ if (j == ARRAY_SIZE (embed_signatures)) ++ continue; ++ grub_util_warn (message_warn[embed_signatures[j].type], ++ (*sectors)[i], embed_signatures[j].name); ++ avail_nsectors--; ++ if (avail_nsectors < *nsectors) ++ *nsectors = avail_nsectors; ++ ++ /* Avoid this sector. */ ++ for (j = i; j < *nsectors; j++) ++ (*sectors)[j]++; ++ ++ /* Have we run out of space? */ ++ if (avail_nsectors < orig_nsectors) ++ break; ++ ++ /* Make sure to check the next sector. */ ++ i--; ++ } ++ grub_free (embed_signature_check); ++ ++ if (*nsectors < orig_nsectors) ++ return grub_error (GRUB_ERR_OUT_OF_RANGE, ++ "Other software is using the embedding area, and " ++ "there is not enough room for core.img. Such " ++ "software is often trying to store data in a way " ++ "that avoids detection. We recommend you " ++ "investigate."); ++ + return GRUB_ERR_NONE; + } + +Index: b/include/grub/partition.h +=================================================================== +--- a/include/grub/partition.h ++++ b/include/grub/partition.h +@@ -49,6 +49,7 @@ + #ifdef GRUB_UTIL + /* Determine sectors available for embedding. */ + grub_err_t (*embed) (struct grub_disk *disk, unsigned int *nsectors, ++ unsigned int max_nsectors, + grub_embed_type_t embed_type, + grub_disk_addr_t **sectors); + #endif +Index: b/util/grub-setup.c +=================================================================== +--- a/util/grub-setup.c ++++ b/util/grub-setup.c +@@ -428,10 +428,8 @@ + } + + nsec = core_sectors; +- err = dest_partmap->embed (dest_dev->disk, &nsec, ++ err = dest_partmap->embed (dest_dev->disk, &nsec, 2 * core_sectors, + GRUB_EMBED_PCBIOS, §ors); +- if (nsec > 2 * core_sectors) +- nsec = 2 * core_sectors; + + if (err) + { +@@ -460,6 +458,13 @@ + save_blocklists (sectors[i] + grub_partition_get_start (container), + 0, GRUB_DISK_SECTOR_SIZE); + ++ /* Make sure that the last blocklist is a terminator. */ ++ if (block == first_block) ++ block--; ++ block->start = 0; ++ block->len = 0; ++ block->segment = 0; ++ + write_rootdev (core_img, root_dev, boot_img, first_sector); + + core_img = realloc (core_img, nsec * GRUB_DISK_SECTOR_SIZE); +@@ -476,12 +481,6 @@ + nsec * GRUB_DISK_SECTOR_SIZE + - core_size); + +- /* Make sure that the second blocklist is a terminator. */ +- block = first_block - 1; +- block->start = 0; +- block->len = 0; +- block->segment = 0; +- + /* Write the core image onto the disk. */ + for (i = 0; i < nsec; i++) + grub_disk_write (dest_dev->disk, sectors[i], 0, diff --git a/master/debian/branch_fuse.patch b/master/debian/branch_fuse.patch new file mode 100644 index 0000000..1f5a22d --- /dev/null +++ b/master/debian/branch_fuse.patch @@ -0,0 +1,605 @@ +Description: Add grub-mount utility +Author: Vladimir Serbinenko <phcoder@gmail.com> +Origin: upstream, http://bzr.sv.gnu.org/r/grub/branches/fuse/ +Forwarded: http://lists.gnu.org/archive/html/grub-devel/2011-01/msg00056.html +Last-Update: 2011-07-10 + +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -216,6 +216,21 @@ + }; + + program = { ++ name = grub-mount; ++ mansection = 1; ++ common_nodist = grub_fstest_init.c; ++ common = util/grub-mount.c; ++ common = grub-core/kern/emu/hostfs.c; ++ common = grub-core/disk/host.c; ++ ++ ldadd = libgrubmods.a; ++ ldadd = libgrubkern.a; ++ ldadd = grub-core/gnulib/libgnu.a; ++ ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) -lfuse'; ++ condition = COND_GRUB_MOUNT; ++}; ++ ++program = { + name = grub-mkfont; + mansection = 1; + common = util/grub-mkfont.c; +--- a/configure.ac ++++ b/configure.ac +@@ -856,6 +856,37 @@ + AC_SUBST([freetype_cflags]) + AC_SUBST([freetype_libs]) + ++AC_ARG_ENABLE([grub-mount], ++ [AS_HELP_STRING([--enable-grub-mount], ++ [build and install the `grub-mount' utility (default=guessed)])]) ++if test x"$enable_grub_mount" = xno ; then ++ grub_mount_excuse="explicitly disabled" ++fi ++ ++if test x"$grub_mount_excuse" = x ; then ++ AC_CHECK_LIB([fuse], [fuse_main_real], [], ++ [grub_mount_excuse="need FUSE library"]) ++fi ++ ++if test x"$grub_mount_excuse" = x ; then ++ # Check for fuse headers. ++ SAVED_CPPFLAGS="$CPPFLAGS" ++ CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=26" ++ AC_CHECK_HEADERS([fuse/fuse.h], [], ++ [grub_mount_excuse=["need FUSE headers"]]) ++ CPPFLAGS="$SAVED_CPPFLAGS" ++fi ++ ++if test x"$enable_grub_mount" = xyes && test x"$grub_mount_excuse" != x ; then ++ AC_MSG_ERROR([grub-mount was explicitly requested but can't be compiled]) ++fi ++if test x"$grub_mount_excuse" = x ; then ++enable_grub_mount=yes ++else ++enable_grub_mount=no ++fi ++AC_SUBST([enable_grub_mount]) ++ + AC_ARG_ENABLE([device-mapper], + [AS_HELP_STRING([--enable-device-mapper], + [enable Linux device-mapper support (default=guessed)])]) +@@ -967,6 +998,7 @@ + AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes]) + AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes]) + AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes]) ++AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes]) + AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x]) + AM_CONDITIONAL([COND_GRUB_PE2ELF], [test x$TARGET_OBJ2ELF != x]) + AM_CONDITIONAL([COND_APPLE_CC], [test x$TARGET_APPLE_CC = x1]) +@@ -1043,5 +1075,10 @@ + else + echo grub-mkfont: No "($grub_mkfont_excuse)" + fi ++if [ x"$grub_mount_excuse" = x ]; then ++echo grub-mount: Yes ++else ++echo grub-mount: No "($grub_mount_excuse)" ++fi + echo "*******************************************************" + ] +--- /dev/null ++++ b/docs/man/grub-mount.h2m +@@ -0,0 +1,2 @@ ++[NAME] ++grub-mount \- export GRUB filesystem with FUSE +--- /dev/null ++++ b/util/grub-mount.c +@@ -0,0 +1,508 @@ ++/* grub-mount.c - FUSE driver for filesystems that GRUB understands */ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2008,2009,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/>. ++ */ ++#define FUSE_USE_VERSION 26 ++#include <config.h> ++#include <grub/types.h> ++#include <grub/emu/misc.h> ++#include <grub/util/misc.h> ++#include <grub/misc.h> ++#include <grub/device.h> ++#include <grub/disk.h> ++#include <grub/file.h> ++#include <grub/fs.h> ++#include <grub/env.h> ++#include <grub/term.h> ++#include <grub/mm.h> ++#include <grub/lib/hexdump.h> ++#include <grub/crypto.h> ++#include <grub/command.h> ++#include <grub/i18n.h> ++#include <fuse/fuse.h> ++ ++#include <stdio.h> ++#include <unistd.h> ++#include <string.h> ++#include <stdlib.h> ++ ++#include "progname.h" ++#include "argp.h" ++ ++static char *root = NULL; ++grub_device_t dev = NULL; ++grub_fs_t fs = NULL; ++static char **images = NULL; ++static char *debug_str = NULL; ++static char **fuse_args = NULL; ++static int fuse_argc = 0; ++static int num_disks = 0; ++ ++static grub_err_t ++execute_command (char *name, int n, char **args) ++{ ++ grub_command_t cmd; ++ ++ cmd = grub_command_find (name); ++ if (! cmd) ++ grub_util_error (_("can\'t find command %s"), name); ++ ++ return (cmd->func) (cmd, n, args); ++} ++ ++/* Translate GRUB error numbers into OS error numbers. Print any unexpected ++ errors. */ ++static int ++translate_error (void) ++{ ++ int ret; ++ ++ switch (grub_errno) ++ { ++ case GRUB_ERR_NONE: ++ ret = 0; ++ break; ++ ++ case GRUB_ERR_OUT_OF_MEMORY: ++ grub_print_error (); ++ ret = -ENOMEM; ++ break; ++ ++ case GRUB_ERR_BAD_FILE_TYPE: ++ /* This could also be EISDIR. Take a guess. */ ++ ret = -ENOTDIR; ++ break; ++ ++ case GRUB_ERR_FILE_NOT_FOUND: ++ ret = -ENOENT; ++ break; ++ ++ case GRUB_ERR_FILE_READ_ERROR: ++ case GRUB_ERR_READ_ERROR: ++ case GRUB_ERR_IO: ++ grub_print_error (); ++ ret = -EIO; ++ break; ++ ++ case GRUB_ERR_SYMLINK_LOOP: ++ ret = -ELOOP; ++ break; ++ ++ default: ++ grub_print_error (); ++ ret = -EINVAL; ++ break; ++ } ++ ++ /* Any previous errors were handled. */ ++ grub_errno = GRUB_ERR_NONE; ++ ++ return ret; ++} ++ ++static int ++fuse_getattr (const char *path, struct stat *st) ++{ ++ char *filename, *pathname, *path2; ++ const char *pathname_t; ++ struct grub_dirhook_info file_info; ++ int file_exists = 0; ++ ++ /* A hook for iterating directories. */ ++ auto int find_file (const char *cur_filename, ++ const struct grub_dirhook_info *info); ++ int find_file (const char *cur_filename, ++ const struct grub_dirhook_info *info) ++ { ++ if ((info->case_insensitive ? grub_strcasecmp (cur_filename, filename) ++ : grub_strcmp (cur_filename, filename)) == 0) ++ { ++ file_info = *info; ++ file_exists = 1; ++ return 1; ++ } ++ return 0; ++ } ++ ++ if (path[0] == '/' && path[1] == 0) ++ { ++ st->st_dev = 0; ++ st->st_ino = 0; ++ st->st_mode = 0555 | S_IFDIR; ++ st->st_uid = 0; ++ st->st_gid = 0; ++ st->st_rdev = 0; ++ st->st_size = 0; ++ st->st_blksize = 512; ++ st->st_blocks = (st->st_blksize + 511) >> 9; ++ st->st_atime = st->st_mtime = st->st_ctime = 0; ++ return 0; ++ } ++ ++ file_exists = 0; ++ ++ pathname_t = grub_strchr (path, ')'); ++ if (! pathname_t) ++ pathname_t = path; ++ else ++ pathname_t++; ++ pathname = xstrdup (pathname_t); ++ ++ /* Remove trailing '/'. */ ++ while (*pathname && pathname[grub_strlen (pathname) - 1] == '/') ++ pathname[grub_strlen (pathname) - 1] = 0; ++ ++ /* Split into path and filename. */ ++ filename = grub_strrchr (pathname, '/'); ++ if (! filename) ++ { ++ path2 = grub_strdup ("/"); ++ filename = pathname; ++ } ++ else ++ { ++ filename++; ++ path2 = grub_strdup (pathname); ++ path2[filename - pathname] = 0; ++ } ++ ++ /* It's the whole device. */ ++ (fs->dir) (dev, path2, find_file); ++ ++ grub_free (path2); ++ if (!file_exists) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ return -ENOENT; ++ } ++ st->st_dev = 0; ++ st->st_ino = 0; ++ st->st_mode = file_info.dir ? (0555 | S_IFDIR) : (0444 | S_IFREG); ++ st->st_uid = 0; ++ st->st_gid = 0; ++ st->st_rdev = 0; ++ if (!file_info.dir) ++ { ++ grub_file_t file; ++ file = grub_file_open (path); ++ if (! file) ++ return translate_error (); ++ st->st_size = file->size; ++ grub_file_close (file); ++ } ++ else ++ st->st_size = 0; ++ st->st_blksize = 512; ++ st->st_blocks = (st->st_size + 511) >> 9; ++ st->st_atime = st->st_mtime = st->st_ctime = file_info.mtimeset ++ ? file_info.mtime : 0; ++ grub_errno = GRUB_ERR_NONE; ++ return 0; ++} ++ ++static int ++fuse_opendir (const char *path, struct fuse_file_info *fi) ++{ ++ return 0; ++} ++ ++/* FIXME */ ++static grub_file_t files[65536]; ++static int first_fd = 1; ++ ++static int ++fuse_open (const char *path, struct fuse_file_info *fi __attribute__ ((unused))) ++{ ++ grub_file_t file; ++ file = grub_file_open (path); ++ if (! file) ++ return translate_error (); ++ files[first_fd++] = file; ++ fi->fh = first_fd; ++ files[first_fd++] = file; ++ grub_errno = GRUB_ERR_NONE; ++ return 0; ++} ++ ++static int ++fuse_read (const char *path, char *buf, size_t sz, off_t off, ++ struct fuse_file_info *fi) ++{ ++ grub_file_t file = files[fi->fh]; ++ grub_ssize_t size; ++ ++ if (off > file->size) ++ return -EINVAL; ++ ++ file->offset = off; ++ ++ size = grub_file_read (file, buf, sz); ++ if (size < 0) ++ return translate_error (); ++ else ++ { ++ grub_errno = GRUB_ERR_NONE; ++ return size; ++ } ++} ++ ++static int ++fuse_release (const char *path, struct fuse_file_info *fi) ++{ ++ grub_file_close (files[fi->fh]); ++ files[fi->fh] = NULL; ++ grub_errno = GRUB_ERR_NONE; ++ return 0; ++} ++ ++static int ++fuse_readdir (const char *path, void *buf, ++ fuse_fill_dir_t fill, off_t off, struct fuse_file_info *fi) ++{ ++ char *pathname; ++ ++ auto int call_fill (const char *filename, ++ const struct grub_dirhook_info *info); ++ int call_fill (const char *filename, const struct grub_dirhook_info *info) ++ { ++ fill (buf, filename, NULL, 0); ++ return 0; ++ } ++ ++ pathname = xstrdup (path); ++ ++ /* Remove trailing '/'. */ ++ while (pathname [0] && pathname[1] ++ && pathname[grub_strlen (pathname) - 1] == '/') ++ pathname[grub_strlen (pathname) - 1] = 0; ++ ++ (fs->dir) (dev, pathname, call_fill); ++ free (pathname); ++ grub_errno = GRUB_ERR_NONE; ++ return 0; ++} ++ ++struct fuse_operations grub_opers = { ++ .getattr = fuse_getattr, ++ .open = fuse_open, ++ .release = fuse_release, ++ .opendir = fuse_opendir, ++ .readdir = fuse_readdir, ++ .read = fuse_read ++}; ++ ++static grub_err_t ++fuse_init (void) ++{ ++ int i; ++ ++ for (i = 0; i < num_disks; i++) ++ { ++ char *argv[2]; ++ char *host_file; ++ char *loop_name; ++ loop_name = grub_xasprintf ("loop%d", i); ++ if (!loop_name) ++ grub_util_error (grub_errmsg); ++ ++ host_file = grub_xasprintf ("(host)%s", images[i]); ++ if (!host_file) ++ grub_util_error (grub_errmsg); ++ ++ argv[0] = loop_name; ++ argv[1] = host_file; ++ ++ if (execute_command ("loopback", 2, argv)) ++ grub_util_error (_("loopback command fails")); ++ ++ grub_free (loop_name); ++ grub_free (host_file); ++ } ++ ++ grub_lvm_fini (); ++ grub_mdraid09_fini (); ++ grub_mdraid1x_fini (); ++ grub_raid_fini (); ++ grub_raid_init (); ++ grub_mdraid09_init (); ++ grub_mdraid1x_init (); ++ grub_lvm_init (); ++ ++ dev = grub_device_open (0); ++ if (! dev) ++ return grub_errno; ++ ++ fs = grub_fs_probe (dev); ++ if (! fs) ++ { ++ grub_device_close (dev); ++ return grub_errno; ++ } ++ ++ fuse_main (fuse_argc, fuse_args, &grub_opers, NULL); ++ ++ for (i = 0; i < num_disks; i++) ++ { ++ char *argv[2]; ++ char *loop_name; ++ ++ loop_name = grub_xasprintf ("loop%d", i); ++ if (!loop_name) ++ grub_util_error (grub_errmsg); ++ ++ argv[0] = "-d"; ++ argv[1] = loop_name; ++ ++ execute_command ("loopback", 2, argv); ++ ++ grub_free (loop_name); ++ } ++ ++ return GRUB_ERR_NONE; ++} ++ ++static struct argp_option options[] = { ++ {"root", 'r', N_("DEVICE_NAME"), 0, N_("Set root device."), 2}, ++ {"debug", 'd', "S", 0, N_("Set debug environment variable."), 2}, ++ {"verbose", 'v', NULL, OPTION_ARG_OPTIONAL, N_("Print verbose messages."), 2}, ++ {0, 0, 0, 0, 0, 0} ++}; ++ ++/* Print the version information. */ ++static void ++print_version (FILE *stream, struct argp_state *state) ++{ ++ fprintf (stream, "%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION); ++} ++void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; ++ ++error_t ++argp_parser (int key, char *arg, struct argp_state *state) ++{ ++ char *p; ++ ++ switch (key) ++ { ++ case 'r': ++ root = arg; ++ return 0; ++ ++ case 'd': ++ debug_str = arg; ++ return 0; ++ ++ case 'v': ++ verbosity++; ++ return 0; ++ ++ case ARGP_KEY_ARG: ++ if (arg[0] != '-') ++ break; ++ ++ default: ++ if (!arg) ++ return 0; ++ ++ fuse_args = xrealloc (fuse_args, (fuse_argc + 1) * sizeof (fuse_args[0])); ++ fuse_args[fuse_argc] = xstrdup (arg); ++ fuse_argc++; ++ return 0; ++ } ++ ++ if (arg[0] != '/') ++ { ++ fprintf (stderr, "%s", _("Must use absolute path.\n")); ++ argp_usage (state); ++ } ++ images = xrealloc (images, (num_disks + 1) * sizeof (images[0])); ++ images[num_disks] = xstrdup (arg); ++ num_disks++; ++ ++ return 0; ++} ++ ++struct argp argp = { ++ options, argp_parser, N_("IMAGE1 [IMAGE2 ...] MOUNTPOINT"), ++ N_("Debug tool for filesystem driver."), ++ NULL, NULL, NULL ++}; ++ ++int ++main (int argc, char *argv[]) ++{ ++ char *default_root, *alloc_root; ++ ++ set_program_name (argv[0]); ++ ++ grub_util_init_nls (); ++ ++ fuse_args = xrealloc (fuse_args, (fuse_argc + 2) * sizeof (fuse_args[0])); ++ fuse_args[fuse_argc] = xstrdup (argv[0]); ++ fuse_argc++; ++ /* Run single-threaded. */ ++ fuse_args[fuse_argc] = xstrdup ("-s"); ++ fuse_argc++; ++ ++ argp_parse (&argp, argc, argv, 0, 0, 0); ++ ++ if (num_disks < 2) ++ grub_util_error ("need an image and mountpoint"); ++ fuse_args = xrealloc (fuse_args, (fuse_argc + 2) * sizeof (fuse_args[0])); ++ fuse_args[fuse_argc] = images[num_disks - 1]; ++ fuse_argc++; ++ num_disks--; ++ fuse_args[fuse_argc] = NULL; ++ ++ /* Initialize all modules. */ ++ grub_init_all (); ++ ++ if (debug_str) ++ grub_env_set ("debug", debug_str); ++ ++ default_root = (num_disks == 1) ? "loop0" : "md0"; ++ alloc_root = 0; ++ if (root) ++ { ++ if ((*root >= '0') && (*root <= '9')) ++ { ++ alloc_root = xmalloc (strlen (default_root) + strlen (root) + 2); ++ ++ sprintf (alloc_root, "%s,%s", default_root, root); ++ root = alloc_root; ++ } ++ } ++ else ++ root = default_root; ++ ++ grub_env_set ("root", root); ++ ++ if (alloc_root) ++ free (alloc_root); ++ ++ /* Do it. */ ++ fuse_init (); ++ if (grub_errno) ++ { ++ grub_print_error (); ++ return 1; ++ } ++ ++ /* Free resources. */ ++ grub_fini_all (); ++ ++ return 0; ++} diff --git a/master/debian/branch_longlinuxcmd.patch b/master/debian/branch_longlinuxcmd.patch new file mode 100644 index 0000000..f7a048f --- /dev/null +++ b/master/debian/branch_longlinuxcmd.patch @@ -0,0 +1,179 @@ +Description: Support long Linux command lines +Author: Vladimir Serbinenko <phcoder@gmail.com> +Origin: upstream, http://bzr.sv.gnu.org/r/grub/branches/longlinuxcmd/ +Forwarded: not-needed +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3303 +Last-Update: 2011-05-19 + +Index: b/grub-core/loader/i386/linux.c +=================================================================== +--- a/grub-core/loader/i386/linux.c ++++ b/grub-core/loader/i386/linux.c +@@ -57,7 +57,6 @@ + #endif + + #define GRUB_LINUX_CL_OFFSET 0x1000 +-#define GRUB_LINUX_CL_END_OFFSET 0x2000 + + static grub_dl_t my_mod; + +@@ -74,6 +73,7 @@ + static grub_uint32_t initrd_pages; + static struct grub_relocator *relocator = NULL; + static void *efi_mmap_buf; ++static grub_size_t maximal_cmdline_size; + #ifdef GRUB_MACHINE_EFI + static grub_efi_uintn_t efi_mmap_size; + #else +@@ -189,7 +189,7 @@ + grub_err_t err; + + /* Make sure that each size is aligned to a page boundary. */ +- real_size = GRUB_LINUX_CL_END_OFFSET; ++ real_size = GRUB_LINUX_CL_OFFSET + maximal_cmdline_size; + prot_size = page_align (prot_size); + mmap_size = find_mmap_size (); + +@@ -662,6 +662,14 @@ + goto fail; + } + ++ if (grub_le_to_cpu16 (lh.version) >= 0x0206) ++ maximal_cmdline_size = grub_le_to_cpu32 (lh.cmdline_size) + 1; ++ else ++ maximal_cmdline_size = 256; ++ ++ if (maximal_cmdline_size < 128) ++ maximal_cmdline_size = 128; ++ + setup_sects = lh.setup_sects; + + /* If SETUP_SECTS is not set, set it to the default (4). */ +@@ -675,7 +683,7 @@ + goto fail; + + params = (struct linux_kernel_params *) real_mode_mem; +- grub_memset (params, 0, GRUB_LINUX_CL_END_OFFSET); ++ grub_memset (params, 0, GRUB_LINUX_CL_OFFSET + maximal_cmdline_size); + grub_memcpy (¶ms->setup_sects, &lh.setup_sects, sizeof (lh) - 0x1F1); + + params->ps_mouse = params->padding10 = 0; +@@ -870,7 +878,7 @@ + grub_create_loader_cmdline (argc, argv, + (char *)real_mode_mem + GRUB_LINUX_CL_OFFSET + + sizeof (LINUX_IMAGE) - 1, +- GRUB_LINUX_CL_END_OFFSET - GRUB_LINUX_CL_OFFSET ++ maximal_cmdline_size + - (sizeof (LINUX_IMAGE) - 1)); + + len = prot_size; +Index: b/grub-core/loader/i386/pc/linux.c +=================================================================== +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -39,7 +39,6 @@ + GRUB_MOD_LICENSE ("GPLv3+"); + + #define GRUB_LINUX_CL_OFFSET 0x9000 +-#define GRUB_LINUX_CL_END_OFFSET 0x90FF + + static grub_dl_t my_mod; + +@@ -49,6 +48,7 @@ + static grub_addr_t grub_linux_real_target; + static char *grub_linux_real_chunk; + static grub_size_t grub_linux16_prot_size; ++static grub_size_t maximal_cmdline_size; + + static grub_err_t + grub_linux16_boot (void) +@@ -128,15 +128,20 @@ + setup_sects = lh.setup_sects; + linux_mem_size = 0; + ++ maximal_cmdline_size = 256; ++ + if (lh.header == grub_cpu_to_le32 (GRUB_LINUX_MAGIC_SIGNATURE) + && grub_le_to_cpu16 (lh.version) >= 0x0200) + { + grub_linux_is_bzimage = (lh.loadflags & GRUB_LINUX_FLAG_BIG_KERNEL); + lh.type_of_loader = GRUB_LINUX_BOOT_LOADER_TYPE; + ++ if (grub_le_to_cpu16 (lh.version) >= 0x0206) ++ maximal_cmdline_size = grub_le_to_cpu32 (lh.cmdline_size) + 1; ++ + /* Put the real mode part at as a high location as possible. */ + grub_linux_real_target = grub_mmap_get_lower () +- - GRUB_LINUX_SETUP_MOVE_SIZE; ++ - (GRUB_LINUX_CL_OFFSET + maximal_cmdline_size); + /* But it must not exceed the traditional area. */ + if (grub_linux_real_target > GRUB_LINUX_OLD_REAL_MODE_ADDR) + grub_linux_real_target = GRUB_LINUX_OLD_REAL_MODE_ADDR; +@@ -153,7 +158,8 @@ + { + lh.cl_magic = grub_cpu_to_le16 (GRUB_LINUX_CL_MAGIC); + lh.cl_offset = grub_cpu_to_le16 (GRUB_LINUX_CL_OFFSET); +- lh.setup_move_size = grub_cpu_to_le16 (GRUB_LINUX_SETUP_MOVE_SIZE); ++ lh.setup_move_size = grub_cpu_to_le16 (GRUB_LINUX_CL_OFFSET ++ + maximal_cmdline_size); + } + } + else +@@ -185,12 +191,13 @@ + goto fail; + } + +- if (grub_linux_real_target + GRUB_LINUX_SETUP_MOVE_SIZE ++ if (grub_linux_real_target + GRUB_LINUX_CL_OFFSET + maximal_cmdline_size + > grub_mmap_get_lower ()) + { + grub_error (GRUB_ERR_OUT_OF_RANGE, + "too small lower memory (0x%x > 0x%x)", +- grub_linux_real_target + GRUB_LINUX_SETUP_MOVE_SIZE, ++ grub_linux_real_target + GRUB_LINUX_CL_OFFSET ++ + maximal_cmdline_size, + (int) grub_mmap_get_lower ()); + goto fail; + } +@@ -263,7 +270,8 @@ + grub_relocator_chunk_t ch; + err = grub_relocator_alloc_chunk_addr (relocator, &ch, + grub_linux_real_target, +- GRUB_LINUX_SETUP_MOVE_SIZE); ++ GRUB_LINUX_CL_OFFSET ++ + maximal_cmdline_size); + if (err) + return err; + grub_linux_real_chunk = get_virtual_current_address (ch); +@@ -294,7 +302,7 @@ + grub_create_loader_cmdline (argc, argv, + (char *)grub_linux_real_chunk + + GRUB_LINUX_CL_OFFSET + sizeof (LINUX_IMAGE) - 1, +- GRUB_LINUX_CL_END_OFFSET - GRUB_LINUX_CL_OFFSET ++ maximal_cmdline_size + - (sizeof (LINUX_IMAGE) - 1)); + + if (grub_linux_is_bzimage) +Index: b/include/grub/i386/linux.h +=================================================================== +--- a/include/grub/i386/linux.h ++++ b/include/grub/i386/linux.h +@@ -41,7 +41,6 @@ + #define GRUB_LINUX_VID_MODE_ASK 0xFFFD + #define GRUB_LINUX_VID_MODE_VESA_START 0x0300 + +-#define GRUB_LINUX_SETUP_MOVE_SIZE 0x9100 + #define GRUB_LINUX_CL_MAGIC 0xA33F + + #ifdef __x86_64__ +@@ -130,6 +129,10 @@ + grub_uint16_t pad1; /* Unused */ + grub_uint32_t cmd_line_ptr; /* Points to the kernel command line */ + grub_uint32_t initrd_addr_max; /* Highest address for initrd */ ++ grub_uint32_t kernel_alignment; ++ grub_uint8_t relocatable; ++ grub_uint8_t pad[3]; ++ grub_uint32_t cmdline_size; + } __attribute__ ((packed)); + + /* Boot parameters for Linux based on 2.6.12. This is used by the setup diff --git a/master/debian/branch_parse-color.patch b/master/debian/branch_parse-color.patch new file mode 100644 index 0000000..3d68937 --- /dev/null +++ b/master/debian/branch_parse-color.patch @@ -0,0 +1,1310 @@ +Description: Add a background_color command + Move gfxmenu color handling to video, so that gfxterm can use it too; add a + background_color command. +Author: Colin Watson <cjwatson@ubuntu.com> +Origin: upstream, http://bzr.sv.gnu.org/r/grub/branches/parse-color/ +Forwarded: http://lists.gnu.org/archive/html/grub-devel/2010-12/msg00045.html +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3308 +Last-Update: 2011-05-19 + +Index: b/ChangeLog.parse-color +=================================================================== +--- /dev/null ++++ b/ChangeLog.parse-color +@@ -0,0 +1,44 @@ ++2010-12-23 Colin Watson <cjwatson@ubuntu.com> ++ ++ Move gfxmenu color handling to video, so that gfxterm can use it ++ too. ++ ++ * grub-core/gfxmenu/named_colors.c: Move to ... ++ * grub-core/video/colors.c: ... here. Rename ++ grub_gui_get_named_color to grub_video_get_named_color. ++ * grub-core/gfxmenu/gui_string_util.c (my_isxdigit): Move to ... ++ * grub-core/video/colors.c (my_isxdigit): ... here. ++ * grub-core/gfxmenu/gui_string_util.c (parse_hex_color_component): ++ Move to ... ++ * grub-core/video/colors.c (parse_hex_color_component): ... here. ++ * grub-core/gfxmenu/gui_string_util.c (grub_gui_parse_color): Move ++ to ... ++ * grub-core/video/colors.c (grub_video_parse_color): ... here. ++ ++ * include/grub/gui.h (grub_gui_color_t): Move to ... ++ * include/grub/video.h (grub_video_rgba_color_t): ... here. ++ * include/grub/gui.h (grub_gui_color_rgb): Move to ... ++ * include/grub/video.h (grub_video_rgba_color_rgb): ... here. ++ * include/grub/gui.h (grub_gui_map_color): Move to ... ++ * include/grub/video.h (grub_video_map_rgba_color): ... here. ++ * include/grub/gui_string_util.h (grub_gui_get_named_color): Move ++ to ... ++ * include/grub/video.h (grub_video_get_named_color): ... here. ++ * include/grub/gui_string_util.h (grub_gui_parse_color): Move to ... ++ * include/grub/video.h (grub_video_parse_color): ... here. ++ ++ * grub-core/Makefile.core.def (kernel) [videoinkernel]: Add ++ video/colors.c. ++ (gfxmenu): Remove gfxmenu/named_colors.c. ++ (video) [videomodules]: Add video/colors.c. ++ ++ Add a background_color command. ++ ++ * grub-core/term/gfxterm.c (grub_gfxterm_background_color_cmd): New ++ function. ++ (GRUB_MOD_INIT): Register background_color command. ++ (GRUB_MOD_FINI): Unregister background_color command. ++ (redraw_screen_rect): Allow blend/replace of text layer to be ++ controlled independently from whether there is a background bitmap. ++ (grub_gfxterm_background_image_cmd): Change blend_text_bg when ++ changing bitmap. +Index: b/grub-core/Makefile.core.def +=================================================================== +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -178,6 +178,7 @@ + videoinkernel = io/bufio.c; + videoinkernel = video/bitmap.c; + videoinkernel = video/bitmap_scale.c; ++ videoinkernel = video/colors.c; + videoinkernel = video/fb/fbblit.c; + videoinkernel = video/fb/fbfill.c; + videoinkernel = video/fb/fbutil.c; +@@ -1056,7 +1057,6 @@ + common = gfxmenu/gui_progress_bar.c; + common = gfxmenu/gui_util.c; + common = gfxmenu/gui_string_util.c; +- common = gfxmenu/named_colors.c; + }; + + module = { +@@ -1463,6 +1463,7 @@ + module = { + name = video; + common = video/video.c; ++ common = video/colors.c; + enable = videomodules; + }; + +Index: b/grub-core/gfxmenu/gui_label.c +=================================================================== +--- a/grub-core/gfxmenu/gui_label.c ++++ b/grub-core/gfxmenu/gui_label.c +@@ -48,7 +48,7 @@ + char *text; + char *template; + grub_font_t font; +- grub_gui_color_t color; ++ grub_video_rgba_color_t color; + int value; + enum align_mode align; + }; +@@ -107,7 +107,7 @@ + grub_gui_set_viewport (&self->bounds, &vpsave); + grub_font_draw_string (self->text, + self->font, +- grub_gui_map_color (self->color), ++ grub_video_map_rgba_color (self->color), + left_x, + grub_font_get_ascent (self->font)); + grub_gui_restore_viewport (&vpsave); +@@ -186,7 +186,7 @@ + } + else if (grub_strcmp (name, "color") == 0) + { +- grub_gui_parse_color (value, &self->color); ++ grub_video_parse_color (value, &self->color); + } + else if (grub_strcmp (name, "align") == 0) + { +Index: b/grub-core/gfxmenu/gui_list.c +=================================================================== +--- a/grub-core/gfxmenu/gui_list.c ++++ b/grub-core/gfxmenu/gui_list.c +@@ -41,9 +41,9 @@ + int item_spacing; + grub_font_t item_font; + grub_font_t selected_item_font; +- grub_gui_color_t item_color; ++ grub_video_rgba_color_t item_color; + int selected_item_color_set; +- grub_gui_color_t selected_item_color; ++ grub_video_rgba_color_t selected_item_color; + + int draw_scrollbar; + int need_to_recreate_scrollbar; +@@ -269,13 +269,13 @@ + (is_selected && self->selected_item_font + ? self->selected_item_font + : self->item_font); +- grub_gui_color_t text_color = ++ grub_video_rgba_color_t text_color = + ((is_selected && self->selected_item_color_set) + ? self->selected_item_color + : self->item_color); + grub_font_draw_string (item_title, + font, +- grub_gui_map_color (text_color), ++ grub_video_map_rgba_color (text_color), + sel_leftpad + self->icon_width + icon_text_space, + (item_top + (item_height - (ascent + descent)) + / 2 + ascent)); +@@ -431,7 +431,7 @@ + } + else if (grub_strcmp (name, "item_color") == 0) + { +- grub_gui_parse_color (value, &self->item_color); ++ grub_video_parse_color (value, &self->item_color); + } + else if (grub_strcmp (name, "selected_item_color") == 0) + { +@@ -441,7 +441,7 @@ + } + else + { +- if (grub_gui_parse_color (value, &self->selected_item_color) ++ if (grub_video_parse_color (value, &self->selected_item_color) + == GRUB_ERR_NONE) + self->selected_item_color_set = 1; + } +@@ -564,7 +564,7 @@ + { + list_impl_t self; + grub_font_t default_font; +- grub_gui_color_t default_fg_color; ++ grub_video_rgba_color_t default_fg_color; + + self = grub_zalloc (sizeof (*self)); + if (! self) +@@ -576,7 +576,7 @@ + self->visible = 1; + + default_font = grub_font_get ("Unknown Regular 16"); +- default_fg_color = grub_gui_color_rgb (0, 0, 0); ++ default_fg_color = grub_video_rgba_color_rgb (0, 0, 0); + + self->icon_width = 32; + self->icon_height = 32; +Index: b/grub-core/gfxmenu/gui_progress_bar.c +=================================================================== +--- a/grub-core/gfxmenu/gui_progress_bar.c ++++ b/grub-core/gfxmenu/gui_progress_bar.c +@@ -40,10 +40,10 @@ + int show_text; + char *template; + grub_font_t font; +- grub_gui_color_t text_color; +- grub_gui_color_t border_color; +- grub_gui_color_t bg_color; +- grub_gui_color_t fg_color; ++ grub_video_rgba_color_t text_color; ++ grub_video_rgba_color_t border_color; ++ grub_video_rgba_color_t bg_color; ++ grub_video_rgba_color_t fg_color; + + char *theme_dir; + int need_to_recreate_pixmaps; +@@ -109,7 +109,7 @@ + f.height = self->bounds.height - 2; + + /* Border. */ +- grub_video_fill_rect (grub_gui_map_color (self->border_color), ++ grub_video_fill_rect (grub_video_map_rgba_color (self->border_color), + f.x - 1, f.y - 1, + f.width + 2, f.height + 2); + +@@ -117,12 +117,12 @@ + int barwidth = (f.width + * (self->value - self->start) + / (self->end - self->start)); +- grub_video_fill_rect (grub_gui_map_color (self->bg_color), ++ grub_video_fill_rect (grub_video_map_rgba_color (self->bg_color), + f.x + barwidth, f.y, + f.width - barwidth, f.height); + + /* Bar foreground. */ +- grub_video_fill_rect (grub_gui_map_color (self->fg_color), ++ grub_video_fill_rect (grub_video_map_rgba_color (self->fg_color), + f.x, f.y, + barwidth, f.height); + } +@@ -161,7 +161,8 @@ + if (self->template) + { + grub_font_t font = self->font; +- grub_video_color_t text_color = grub_gui_map_color (self->text_color); ++ grub_video_color_t text_color = ++ grub_video_map_rgba_color (self->text_color); + int width = self->bounds.width; + int height = self->bounds.height; + char *text; +@@ -298,19 +299,19 @@ + } + else if (grub_strcmp (name, "text_color") == 0) + { +- grub_gui_parse_color (value, &self->text_color); ++ grub_video_parse_color (value, &self->text_color); + } + else if (grub_strcmp (name, "border_color") == 0) + { +- grub_gui_parse_color (value, &self->border_color); ++ grub_video_parse_color (value, &self->border_color); + } + else if (grub_strcmp (name, "bg_color") == 0) + { +- grub_gui_parse_color (value, &self->bg_color); ++ grub_video_parse_color (value, &self->bg_color); + } + else if (grub_strcmp (name, "fg_color") == 0) + { +- grub_gui_parse_color (value, &self->fg_color); ++ grub_video_parse_color (value, &self->fg_color); + } + else if (grub_strcmp (name, "bar_style") == 0) + { +@@ -379,9 +380,9 @@ + self->progress.component.ops = &progress_bar_ops; + self->visible = 1; + self->font = grub_font_get ("Unknown Regular 16"); +- grub_gui_color_t black = { .red = 0, .green = 0, .blue = 0, .alpha = 255 }; +- grub_gui_color_t gray = { .red = 128, .green = 128, .blue = 128, .alpha = 255 }; +- grub_gui_color_t lightgray = { .red = 200, .green = 200, .blue = 200, .alpha = 255 }; ++ grub_video_rgba_color_t black = { .red = 0, .green = 0, .blue = 0, .alpha = 255 }; ++ grub_video_rgba_color_t gray = { .red = 128, .green = 128, .blue = 128, .alpha = 255 }; ++ grub_video_rgba_color_t lightgray = { .red = 200, .green = 200, .blue = 200, .alpha = 255 }; + self->text_color = black; + self->border_color = black; + self->bg_color = gray; +Index: b/grub-core/gfxmenu/gui_string_util.c +=================================================================== +--- a/grub-core/gfxmenu/gui_string_util.c ++++ b/grub-core/gfxmenu/gui_string_util.c +@@ -204,124 +204,3 @@ + + return grub_new_substring (file_path, 0, last_slash + 1); + } +- +-static __inline int +-my_isxdigit (char c) +-{ +- return ((c >= '0' && c <= '9') +- || (c >= 'a' && c <= 'f') +- || (c >= 'A' && c <= 'F')); +-} +- +-static int +-parse_hex_color_component (const char *s, unsigned start, unsigned end) +-{ +- unsigned len; +- char buf[3]; +- +- len = end - start; +- /* Check the limits so we don't overrun the buffer. */ +- if (len < 1 || len > 2) +- return 0; +- +- if (len == 1) +- { +- buf[0] = s[start]; /* Get the first and only hex digit. */ +- buf[1] = buf[0]; /* Duplicate the hex digit. */ +- } +- else if (len == 2) +- { +- buf[0] = s[start]; +- buf[1] = s[start + 1]; +- } +- +- buf[2] = '\0'; +- +- return grub_strtoul (buf, 0, 16); +-} +- +-/* Parse a color string of the form "r, g, b", "#RGB", "#RGBA", +- "#RRGGBB", or "#RRGGBBAA". */ +-grub_err_t +-grub_gui_parse_color (const char *s, grub_gui_color_t *color) +-{ +- grub_gui_color_t c; +- +- /* Skip whitespace. */ +- while (*s && grub_isspace (*s)) +- s++; +- +- if (*s == '#') +- { +- /* HTML-style. Number if hex digits: +- [6] #RRGGBB [3] #RGB +- [8] #RRGGBBAA [4] #RGBA */ +- +- s++; /* Skip the '#'. */ +- /* Count the hexits to determine the format. */ +- int hexits = 0; +- const char *end = s; +- while (my_isxdigit (*end)) +- { +- end++; +- hexits++; +- } +- +- /* Parse the color components based on the format. */ +- if (hexits == 3 || hexits == 4) +- { +- c.red = parse_hex_color_component (s, 0, 1); +- c.green = parse_hex_color_component (s, 1, 2); +- c.blue = parse_hex_color_component (s, 2, 3); +- if (hexits == 4) +- c.alpha = parse_hex_color_component (s, 3, 4); +- else +- c.alpha = 255; +- } +- else if (hexits == 6 || hexits == 8) +- { +- c.red = parse_hex_color_component (s, 0, 2); +- c.green = parse_hex_color_component (s, 2, 4); +- c.blue = parse_hex_color_component (s, 4, 6); +- if (hexits == 8) +- c.alpha = parse_hex_color_component (s, 6, 8); +- else +- c.alpha = 255; +- } +- else +- return grub_error (GRUB_ERR_BAD_ARGUMENT, +- "invalid HTML-type color string `%s'", s); +- } +- else if (grub_isdigit (*s)) +- { +- /* Comma separated decimal values. */ +- c.red = grub_strtoul (s, 0, 0); +- if ((s = grub_strchr (s, ',')) == 0) +- return grub_error (GRUB_ERR_BAD_ARGUMENT, +- "missing 1st comma separator in color `%s'", s); +- s++; +- c.green = grub_strtoul (s, 0, 0); +- if ((s = grub_strchr (s, ',')) == 0) +- return grub_error (GRUB_ERR_BAD_ARGUMENT, +- "missing 2nd comma separator in color `%s'", s); +- s++; +- c.blue = grub_strtoul (s, 0, 0); +- if ((s = grub_strchr (s, ',')) == 0) +- c.alpha = 255; +- else +- { +- s++; +- c.alpha = grub_strtoul (s, 0, 0); +- } +- } +- else +- { +- if (! grub_gui_get_named_color (s, &c)) +- return grub_error (GRUB_ERR_BAD_ARGUMENT, +- "invalid named color `%s'", s); +- } +- +- if (grub_errno == GRUB_ERR_NONE) +- *color = c; +- return grub_errno; +-} +Index: b/grub-core/gfxmenu/named_colors.c +=================================================================== +--- a/grub-core/gfxmenu/named_colors.c ++++ /dev/null +@@ -1,209 +0,0 @@ +-/* named_colors.c - Named color values. */ +-/* +- * GRUB -- GRand Unified Bootloader +- * Copyright (C) 2008 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/gui.h> +-#include <grub/gui_string_util.h> +-#include <grub/misc.h> +- +-struct named_color +-{ +- const char *name; +- grub_gui_color_t color; +-}; +- +-/* +- Named color list generated from the list of SVG color keywords from +- <http://www.w3.org/TR/css3-color/#svg-color>, +- processed through the following Perl command: +- perl -ne 'chomp;split;print "{ \"$_[0]\", RGB_COLOR($_[2]) },\n"' +- */ +- +-#define RGB_COLOR(r,g,b) {.red = r, .green = g, .blue = b, .alpha = 255} +- +-static struct named_color named_colors[] = +-{ +- { "aliceblue", RGB_COLOR(240,248,255) }, +- { "antiquewhite", RGB_COLOR(250,235,215) }, +- { "aqua", RGB_COLOR(0,255,255) }, +- { "aquamarine", RGB_COLOR(127,255,212) }, +- { "azure", RGB_COLOR(240,255,255) }, +- { "beige", RGB_COLOR(245,245,220) }, +- { "bisque", RGB_COLOR(255,228,196) }, +- { "black", RGB_COLOR(0,0,0) }, +- { "blanchedalmond", RGB_COLOR(255,235,205) }, +- { "blue", RGB_COLOR(0,0,255) }, +- { "blueviolet", RGB_COLOR(138,43,226) }, +- { "brown", RGB_COLOR(165,42,42) }, +- { "burlywood", RGB_COLOR(222,184,135) }, +- { "cadetblue", RGB_COLOR(95,158,160) }, +- { "chartreuse", RGB_COLOR(127,255,0) }, +- { "chocolate", RGB_COLOR(210,105,30) }, +- { "coral", RGB_COLOR(255,127,80) }, +- { "cornflowerblue", RGB_COLOR(100,149,237) }, +- { "cornsilk", RGB_COLOR(255,248,220) }, +- { "crimson", RGB_COLOR(220,20,60) }, +- { "cyan", RGB_COLOR(0,255,255) }, +- { "darkblue", RGB_COLOR(0,0,139) }, +- { "darkcyan", RGB_COLOR(0,139,139) }, +- { "darkgoldenrod", RGB_COLOR(184,134,11) }, +- { "darkgray", RGB_COLOR(169,169,169) }, +- { "darkgreen", RGB_COLOR(0,100,0) }, +- { "darkgrey", RGB_COLOR(169,169,169) }, +- { "darkkhaki", RGB_COLOR(189,183,107) }, +- { "darkmagenta", RGB_COLOR(139,0,139) }, +- { "darkolivegreen", RGB_COLOR(85,107,47) }, +- { "darkorange", RGB_COLOR(255,140,0) }, +- { "darkorchid", RGB_COLOR(153,50,204) }, +- { "darkred", RGB_COLOR(139,0,0) }, +- { "darksalmon", RGB_COLOR(233,150,122) }, +- { "darkseagreen", RGB_COLOR(143,188,143) }, +- { "darkslateblue", RGB_COLOR(72,61,139) }, +- { "darkslategray", RGB_COLOR(47,79,79) }, +- { "darkslategrey", RGB_COLOR(47,79,79) }, +- { "darkturquoise", RGB_COLOR(0,206,209) }, +- { "darkviolet", RGB_COLOR(148,0,211) }, +- { "deeppink", RGB_COLOR(255,20,147) }, +- { "deepskyblue", RGB_COLOR(0,191,255) }, +- { "dimgray", RGB_COLOR(105,105,105) }, +- { "dimgrey", RGB_COLOR(105,105,105) }, +- { "dodgerblue", RGB_COLOR(30,144,255) }, +- { "firebrick", RGB_COLOR(178,34,34) }, +- { "floralwhite", RGB_COLOR(255,250,240) }, +- { "forestgreen", RGB_COLOR(34,139,34) }, +- { "fuchsia", RGB_COLOR(255,0,255) }, +- { "gainsboro", RGB_COLOR(220,220,220) }, +- { "ghostwhite", RGB_COLOR(248,248,255) }, +- { "gold", RGB_COLOR(255,215,0) }, +- { "goldenrod", RGB_COLOR(218,165,32) }, +- { "gray", RGB_COLOR(128,128,128) }, +- { "green", RGB_COLOR(0,128,0) }, +- { "greenyellow", RGB_COLOR(173,255,47) }, +- { "grey", RGB_COLOR(128,128,128) }, +- { "honeydew", RGB_COLOR(240,255,240) }, +- { "hotpink", RGB_COLOR(255,105,180) }, +- { "indianred", RGB_COLOR(205,92,92) }, +- { "indigo", RGB_COLOR(75,0,130) }, +- { "ivory", RGB_COLOR(255,255,240) }, +- { "khaki", RGB_COLOR(240,230,140) }, +- { "lavender", RGB_COLOR(230,230,250) }, +- { "lavenderblush", RGB_COLOR(255,240,245) }, +- { "lawngreen", RGB_COLOR(124,252,0) }, +- { "lemonchiffon", RGB_COLOR(255,250,205) }, +- { "lightblue", RGB_COLOR(173,216,230) }, +- { "lightcoral", RGB_COLOR(240,128,128) }, +- { "lightcyan", RGB_COLOR(224,255,255) }, +- { "lightgoldenrodyellow", RGB_COLOR(250,250,210) }, +- { "lightgray", RGB_COLOR(211,211,211) }, +- { "lightgreen", RGB_COLOR(144,238,144) }, +- { "lightgrey", RGB_COLOR(211,211,211) }, +- { "lightpink", RGB_COLOR(255,182,193) }, +- { "lightsalmon", RGB_COLOR(255,160,122) }, +- { "lightseagreen", RGB_COLOR(32,178,170) }, +- { "lightskyblue", RGB_COLOR(135,206,250) }, +- { "lightslategray", RGB_COLOR(119,136,153) }, +- { "lightslategrey", RGB_COLOR(119,136,153) }, +- { "lightsteelblue", RGB_COLOR(176,196,222) }, +- { "lightyellow", RGB_COLOR(255,255,224) }, +- { "lime", RGB_COLOR(0,255,0) }, +- { "limegreen", RGB_COLOR(50,205,50) }, +- { "linen", RGB_COLOR(250,240,230) }, +- { "magenta", RGB_COLOR(255,0,255) }, +- { "maroon", RGB_COLOR(128,0,0) }, +- { "mediumaquamarine", RGB_COLOR(102,205,170) }, +- { "mediumblue", RGB_COLOR(0,0,205) }, +- { "mediumorchid", RGB_COLOR(186,85,211) }, +- { "mediumpurple", RGB_COLOR(147,112,219) }, +- { "mediumseagreen", RGB_COLOR(60,179,113) }, +- { "mediumslateblue", RGB_COLOR(123,104,238) }, +- { "mediumspringgreen", RGB_COLOR(0,250,154) }, +- { "mediumturquoise", RGB_COLOR(72,209,204) }, +- { "mediumvioletred", RGB_COLOR(199,21,133) }, +- { "midnightblue", RGB_COLOR(25,25,112) }, +- { "mintcream", RGB_COLOR(245,255,250) }, +- { "mistyrose", RGB_COLOR(255,228,225) }, +- { "moccasin", RGB_COLOR(255,228,181) }, +- { "navajowhite", RGB_COLOR(255,222,173) }, +- { "navy", RGB_COLOR(0,0,128) }, +- { "oldlace", RGB_COLOR(253,245,230) }, +- { "olive", RGB_COLOR(128,128,0) }, +- { "olivedrab", RGB_COLOR(107,142,35) }, +- { "orange", RGB_COLOR(255,165,0) }, +- { "orangered", RGB_COLOR(255,69,0) }, +- { "orchid", RGB_COLOR(218,112,214) }, +- { "palegoldenrod", RGB_COLOR(238,232,170) }, +- { "palegreen", RGB_COLOR(152,251,152) }, +- { "paleturquoise", RGB_COLOR(175,238,238) }, +- { "palevioletred", RGB_COLOR(219,112,147) }, +- { "papayawhip", RGB_COLOR(255,239,213) }, +- { "peachpuff", RGB_COLOR(255,218,185) }, +- { "peru", RGB_COLOR(205,133,63) }, +- { "pink", RGB_COLOR(255,192,203) }, +- { "plum", RGB_COLOR(221,160,221) }, +- { "powderblue", RGB_COLOR(176,224,230) }, +- { "purple", RGB_COLOR(128,0,128) }, +- { "red", RGB_COLOR(255,0,0) }, +- { "rosybrown", RGB_COLOR(188,143,143) }, +- { "royalblue", RGB_COLOR(65,105,225) }, +- { "saddlebrown", RGB_COLOR(139,69,19) }, +- { "salmon", RGB_COLOR(250,128,114) }, +- { "sandybrown", RGB_COLOR(244,164,96) }, +- { "seagreen", RGB_COLOR(46,139,87) }, +- { "seashell", RGB_COLOR(255,245,238) }, +- { "sienna", RGB_COLOR(160,82,45) }, +- { "silver", RGB_COLOR(192,192,192) }, +- { "skyblue", RGB_COLOR(135,206,235) }, +- { "slateblue", RGB_COLOR(106,90,205) }, +- { "slategray", RGB_COLOR(112,128,144) }, +- { "slategrey", RGB_COLOR(112,128,144) }, +- { "snow", RGB_COLOR(255,250,250) }, +- { "springgreen", RGB_COLOR(0,255,127) }, +- { "steelblue", RGB_COLOR(70,130,180) }, +- { "tan", RGB_COLOR(210,180,140) }, +- { "teal", RGB_COLOR(0,128,128) }, +- { "thistle", RGB_COLOR(216,191,216) }, +- { "tomato", RGB_COLOR(255,99,71) }, +- { "turquoise", RGB_COLOR(64,224,208) }, +- { "violet", RGB_COLOR(238,130,238) }, +- { "wheat", RGB_COLOR(245,222,179) }, +- { "white", RGB_COLOR(255,255,255) }, +- { "whitesmoke", RGB_COLOR(245,245,245) }, +- { "yellow", RGB_COLOR(255,255,0) }, +- { "yellowgreen", RGB_COLOR(154,205,50) }, +- { 0, { 0, 0, 0, 0 } } /* Terminator. */ +-}; +- +-/* Get the color named NAME. If the color was found, returns 1 and +- stores the color into *COLOR. If the color was not found, returns 0 and +- does not modify *COLOR. */ +-int +-grub_gui_get_named_color (const char *name, +- grub_gui_color_t *color) +-{ +- int i; +- for (i = 0; named_colors[i].name; i++) +- { +- if (grub_strcmp (named_colors[i].name, name) == 0) +- { +- *color = named_colors[i].color; +- return 1; +- } +- } +- return 0; +-} +Index: b/grub-core/gfxmenu/theme_loader.c +=================================================================== +--- a/grub-core/gfxmenu/theme_loader.c ++++ b/grub-core/gfxmenu/theme_loader.c +@@ -135,11 +135,11 @@ + return grub_errno; + } + else if (! grub_strcmp ("title-color", name)) +- grub_gui_parse_color (value, &view->title_color); ++ grub_video_parse_color (value, &view->title_color); + else if (! grub_strcmp ("message-color", name)) +- grub_gui_parse_color (value, &view->message_color); ++ grub_video_parse_color (value, &view->message_color); + else if (! grub_strcmp ("message-bg-color", name)) +- grub_gui_parse_color (value, &view->message_bg_color); ++ grub_video_parse_color (value, &view->message_bg_color); + else if (! grub_strcmp ("desktop-image", name)) + { + struct grub_video_bitmap *raw_bitmap; +@@ -170,7 +170,7 @@ + view->desktop_image = scaled_bitmap; + } + else if (! grub_strcmp ("desktop-color", name)) +- grub_gui_parse_color (value, &view->desktop_color); ++ grub_video_parse_color (value, &view->desktop_color); + else if (! grub_strcmp ("terminal-box", name)) + { + grub_err_t err; +Index: b/grub-core/gfxmenu/view.c +=================================================================== +--- a/grub-core/gfxmenu/view.c ++++ b/grub-core/gfxmenu/view.c +@@ -50,8 +50,8 @@ + { + grub_gfxmenu_view_t view; + grub_font_t default_font; +- grub_gui_color_t default_fg_color; +- grub_gui_color_t default_bg_color; ++ grub_video_rgba_color_t default_fg_color; ++ grub_video_rgba_color_t default_bg_color; + + view = grub_malloc (sizeof (*view)); + if (! view) +@@ -63,8 +63,8 @@ + view->screen.height = height; + + default_font = grub_font_get ("Unknown Regular 16"); +- default_fg_color = grub_gui_color_rgb (0, 0, 0); +- default_bg_color = grub_gui_color_rgb (255, 255, 255); ++ default_fg_color = grub_video_rgba_color_rgb (0, 0, 0); ++ default_bg_color = grub_video_rgba_color_rgb (255, 255, 255); + + view->canvas = 0; + +@@ -131,7 +131,7 @@ + } + else + { +- grub_video_fill_rect (grub_gui_map_color (view->desktop_color), ++ grub_video_fill_rect (grub_video_map_rgba_color (view->desktop_color), + bounds->x, bounds->y, + bounds->width, bounds->height); + } +@@ -150,7 +150,7 @@ + int y = 40 + grub_font_get_ascent (view->title_font); + grub_font_draw_string (view->title_text, + view->title_font, +- grub_gui_map_color (view->title_color), ++ grub_video_map_rgba_color (view->title_color), + x, y); + } + +@@ -244,13 +244,13 @@ + return; + + grub_font_t font = view->message_font; +- grub_video_color_t color = grub_gui_map_color (view->message_color); ++ grub_video_color_t color = grub_video_map_rgba_color (view->message_color); + + /* Border. */ + grub_video_fill_rect (color, + f.x-1, f.y-1, f.width+2, f.height+2); + /* Fill. */ +- grub_video_fill_rect (grub_gui_map_color (view->message_bg_color), ++ grub_video_fill_rect (grub_video_map_rgba_color (view->message_bg_color), + f.x, f.y, f.width, f.height); + + /* Center the text. */ +Index: b/grub-core/term/gfxterm.c +=================================================================== +--- a/grub-core/term/gfxterm.c ++++ b/grub-core/term/gfxterm.c +@@ -130,6 +130,7 @@ + static unsigned int bitmap_width; + static unsigned int bitmap_height; + static struct grub_video_bitmap *bitmap; ++static int blend_text_bg; + + static struct grub_dirty_region dirty_region; + +@@ -476,26 +477,27 @@ + /* Render background layer. */ + grub_video_fill_rect (color, x, ty, width, h); + } +- +- /* Render text layer as blended. */ +- grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_BLEND, x, y, +- x - virtual_screen.offset_x, +- y - virtual_screen.offset_y, +- width, height); + } + else + { + /* Render background layer. */ + color = virtual_screen.bg_color_display; + grub_video_fill_rect (color, x, y, width, height); +- +- /* Render text layer as replaced (to get texts background color). */ +- grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_REPLACE, x, y, +- x - virtual_screen.offset_x, +- y - virtual_screen.offset_y, +- width, height); + } + ++ if (blend_text_bg) ++ /* Render text layer as blended. */ ++ grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_BLEND, x, y, ++ x - virtual_screen.offset_x, ++ y - virtual_screen.offset_y, ++ width, height); ++ else ++ /* Render text layer as replaced (to get texts background color). */ ++ grub_video_blit_render_target (text_layer, GRUB_VIDEO_BLIT_REPLACE, x, y, ++ x - virtual_screen.offset_x, ++ y - virtual_screen.offset_y, ++ width, height); ++ + /* Restore saved viewport. */ + grub_video_set_viewport (saved_view.x, saved_view.y, + saved_view.width, saved_view.height); +@@ -1127,6 +1129,7 @@ + { + grub_video_bitmap_destroy (bitmap); + bitmap = 0; ++ blend_text_bg = 0; + + /* Mark whole screen as dirty. */ + dirty_region_add (0, 0, window.width, window.height); +@@ -1166,6 +1169,8 @@ + /* If bitmap was loaded correctly, display it. */ + if (bitmap) + { ++ blend_text_bg = 1; ++ + /* Determine bitmap dimensions. */ + bitmap_width = grub_video_bitmap_get_width (bitmap); + bitmap_height = grub_video_bitmap_get_height (bitmap); +@@ -1180,6 +1185,48 @@ + return grub_errno; + } + ++static grub_err_t ++grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)), ++ int argc, char **args) ++{ ++ grub_video_rgba_color_t color; ++ struct grub_video_render_target *old_target; ++ ++ if (argc != 1) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing operand"); ++ ++ /* Check that we have video adapter active. */ ++ if (grub_video_get_info (NULL) != GRUB_ERR_NONE) ++ return grub_errno; ++ ++ if (grub_video_parse_color (args[0], &color) != GRUB_ERR_NONE) ++ return grub_errno; ++ ++ /* Destroy existing background bitmap if loaded. */ ++ if (bitmap) ++ { ++ grub_video_bitmap_destroy (bitmap); ++ bitmap = 0; ++ ++ /* Mark whole screen as dirty. */ ++ dirty_region_add (0, 0, window.width, window.height); ++ } ++ ++ /* Set the background and border colors. The background color needs to be ++ compatible with the text layer. */ ++ grub_video_get_active_render_target (&old_target); ++ grub_video_set_active_render_target (text_layer); ++ virtual_screen.bg_color = grub_video_map_rgba_color (color); ++ grub_video_set_active_render_target (old_target); ++ virtual_screen.bg_color_display = grub_video_map_rgba_color (color); ++ blend_text_bg = 1; ++ ++ /* Mark whole screen as dirty. */ ++ dirty_region_add (0, 0, window.width, window.height); ++ ++ return GRUB_ERR_NONE; ++} ++ + static struct grub_term_output grub_video_term = + { + .name = "gfxterm", +@@ -1201,6 +1248,7 @@ + }; + + static grub_extcmd_t background_image_cmd_handle; ++static grub_command_t background_color_cmd_handle; + + GRUB_MOD_INIT(gfxterm) + { +@@ -1211,10 +1259,16 @@ + N_("[-m (stretch|normal)] FILE"), + N_("Load background image for active terminal."), + background_image_cmd_options); ++ background_color_cmd_handle = ++ grub_register_command ("background_color", ++ grub_gfxterm_background_color_cmd, ++ N_("COLOR"), ++ N_("Set background color for active terminal.")); + } + + GRUB_MOD_FINI(gfxterm) + { ++ grub_unregister_command (background_color_cmd_handle); + grub_unregister_extcmd (background_image_cmd_handle); + grub_term_unregister_output (&grub_video_term); + } +Index: b/include/grub/gfxmenu_view.h +=================================================================== +--- a/include/grub/gfxmenu_view.h ++++ b/include/grub/gfxmenu_view.h +@@ -87,11 +87,11 @@ + grub_font_t title_font; + grub_font_t message_font; + char *terminal_font_name; +- grub_gui_color_t title_color; +- grub_gui_color_t message_color; +- grub_gui_color_t message_bg_color; ++ grub_video_rgba_color_t title_color; ++ grub_video_rgba_color_t message_color; ++ grub_video_rgba_color_t message_bg_color; + struct grub_video_bitmap *desktop_image; +- grub_gui_color_t desktop_color; ++ grub_video_rgba_color_t desktop_color; + grub_gfxmenu_box_t terminal_box; + char *title_text; + char *progress_message_text; +Index: b/include/grub/gui.h +=================================================================== +--- a/include/grub/gui.h ++++ b/include/grub/gui.h +@@ -31,16 +31,6 @@ + status changes. */ + #define GRUB_GFXMENU_TIMEOUT_COMPONENT_ID "__timeout__" + +-/* A representation of a color. Unlike grub_video_color_t, this +- representation is independent of any video mode specifics. */ +-typedef struct grub_gui_color +-{ +- grub_uint8_t red; +- grub_uint8_t green; +- grub_uint8_t blue; +- grub_uint8_t alpha; +-} grub_gui_color_t; +- + typedef struct grub_gui_component *grub_gui_component_t; + typedef struct grub_gui_container *grub_gui_container_t; + typedef struct grub_gui_list *grub_gui_list_t; +@@ -242,23 +232,6 @@ + r->height); + } + +-static __inline grub_gui_color_t +-grub_gui_color_rgb (int r, int g, int b) +-{ +- grub_gui_color_t c; +- c.red = r; +- c.green = g; +- c.blue = b; +- c.alpha = 255; +- return c; +-} +- +-static __inline grub_video_color_t +-grub_gui_map_color (grub_gui_color_t c) +-{ +- return grub_video_map_rgba (c.red, c.green, c.blue, c.alpha); +-} +- + static inline int + grub_video_have_common_points (const grub_video_rect_t *a, + const grub_video_rect_t *b) +Index: b/include/grub/gui_string_util.h +=================================================================== +--- a/include/grub/gui_string_util.h ++++ b/include/grub/gui_string_util.h +@@ -30,8 +30,4 @@ + + char *grub_get_dirname (const char *file_path); + +-int grub_gui_get_named_color (const char *name, grub_gui_color_t *color); +- +-grub_err_t grub_gui_parse_color (const char *s, grub_gui_color_t *color); +- + #endif /* GRUB_GUI_STRING_UTIL_HEADER */ +Index: b/include/grub/video.h +=================================================================== +--- a/include/grub/video.h ++++ b/include/grub/video.h +@@ -27,6 +27,15 @@ + specific coding format. */ + typedef grub_uint32_t grub_video_color_t; + ++/* Video color in hardware independent format. */ ++typedef struct grub_video_rgba_color ++{ ++ grub_uint8_t red; ++ grub_uint8_t green; ++ grub_uint8_t blue; ++ grub_uint8_t alpha; ++} grub_video_rgba_color_t; ++ + /* This structure is driver specific and should not be accessed directly by + outside code. */ + struct grub_video_render_target; +@@ -428,4 +437,27 @@ + + grub_video_driver_id_t EXPORT_FUNC (grub_video_get_driver_id) (void); + ++static __inline grub_video_rgba_color_t ++grub_video_rgba_color_rgb (int r, int g, int b) ++{ ++ grub_video_rgba_color_t c; ++ c.red = r; ++ c.green = g; ++ c.blue = b; ++ c.alpha = 255; ++ return c; ++} ++ ++static __inline grub_video_color_t ++grub_video_map_rgba_color (grub_video_rgba_color_t c) ++{ ++ return grub_video_map_rgba (c.red, c.green, c.blue, c.alpha); ++} ++ ++int EXPORT_FUNC (grub_video_get_named_color) (const char *name, ++ grub_video_rgba_color_t *color); ++ ++grub_err_t EXPORT_FUNC (grub_video_parse_color) (const char *s, ++ grub_video_rgba_color_t *color); ++ + #endif /* ! GRUB_VIDEO_HEADER */ +Index: b/grub-core/video/colors.c +=================================================================== +--- /dev/null ++++ b/grub-core/video/colors.c +@@ -0,0 +1,330 @@ ++/* named_colors.c - Named color values. */ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2008 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/gui.h> ++#include <grub/gui_string_util.h> ++#include <grub/misc.h> ++ ++struct named_color ++{ ++ const char *name; ++ grub_video_rgba_color_t color; ++}; ++ ++/* ++ Named color list generated from the list of SVG color keywords from ++ <http://www.w3.org/TR/css3-color/#svg-color>, ++ processed through the following Perl command: ++ perl -ne 'chomp;split;print "{ \"$_[0]\", RGB_COLOR($_[2]) },\n"' ++ */ ++ ++#define RGB_COLOR(r,g,b) {.red = r, .green = g, .blue = b, .alpha = 255} ++ ++static struct named_color named_colors[] = ++{ ++ { "aliceblue", RGB_COLOR(240,248,255) }, ++ { "antiquewhite", RGB_COLOR(250,235,215) }, ++ { "aqua", RGB_COLOR(0,255,255) }, ++ { "aquamarine", RGB_COLOR(127,255,212) }, ++ { "azure", RGB_COLOR(240,255,255) }, ++ { "beige", RGB_COLOR(245,245,220) }, ++ { "bisque", RGB_COLOR(255,228,196) }, ++ { "black", RGB_COLOR(0,0,0) }, ++ { "blanchedalmond", RGB_COLOR(255,235,205) }, ++ { "blue", RGB_COLOR(0,0,255) }, ++ { "blueviolet", RGB_COLOR(138,43,226) }, ++ { "brown", RGB_COLOR(165,42,42) }, ++ { "burlywood", RGB_COLOR(222,184,135) }, ++ { "cadetblue", RGB_COLOR(95,158,160) }, ++ { "chartreuse", RGB_COLOR(127,255,0) }, ++ { "chocolate", RGB_COLOR(210,105,30) }, ++ { "coral", RGB_COLOR(255,127,80) }, ++ { "cornflowerblue", RGB_COLOR(100,149,237) }, ++ { "cornsilk", RGB_COLOR(255,248,220) }, ++ { "crimson", RGB_COLOR(220,20,60) }, ++ { "cyan", RGB_COLOR(0,255,255) }, ++ { "darkblue", RGB_COLOR(0,0,139) }, ++ { "darkcyan", RGB_COLOR(0,139,139) }, ++ { "darkgoldenrod", RGB_COLOR(184,134,11) }, ++ { "darkgray", RGB_COLOR(169,169,169) }, ++ { "darkgreen", RGB_COLOR(0,100,0) }, ++ { "darkgrey", RGB_COLOR(169,169,169) }, ++ { "darkkhaki", RGB_COLOR(189,183,107) }, ++ { "darkmagenta", RGB_COLOR(139,0,139) }, ++ { "darkolivegreen", RGB_COLOR(85,107,47) }, ++ { "darkorange", RGB_COLOR(255,140,0) }, ++ { "darkorchid", RGB_COLOR(153,50,204) }, ++ { "darkred", RGB_COLOR(139,0,0) }, ++ { "darksalmon", RGB_COLOR(233,150,122) }, ++ { "darkseagreen", RGB_COLOR(143,188,143) }, ++ { "darkslateblue", RGB_COLOR(72,61,139) }, ++ { "darkslategray", RGB_COLOR(47,79,79) }, ++ { "darkslategrey", RGB_COLOR(47,79,79) }, ++ { "darkturquoise", RGB_COLOR(0,206,209) }, ++ { "darkviolet", RGB_COLOR(148,0,211) }, ++ { "deeppink", RGB_COLOR(255,20,147) }, ++ { "deepskyblue", RGB_COLOR(0,191,255) }, ++ { "dimgray", RGB_COLOR(105,105,105) }, ++ { "dimgrey", RGB_COLOR(105,105,105) }, ++ { "dodgerblue", RGB_COLOR(30,144,255) }, ++ { "firebrick", RGB_COLOR(178,34,34) }, ++ { "floralwhite", RGB_COLOR(255,250,240) }, ++ { "forestgreen", RGB_COLOR(34,139,34) }, ++ { "fuchsia", RGB_COLOR(255,0,255) }, ++ { "gainsboro", RGB_COLOR(220,220,220) }, ++ { "ghostwhite", RGB_COLOR(248,248,255) }, ++ { "gold", RGB_COLOR(255,215,0) }, ++ { "goldenrod", RGB_COLOR(218,165,32) }, ++ { "gray", RGB_COLOR(128,128,128) }, ++ { "green", RGB_COLOR(0,128,0) }, ++ { "greenyellow", RGB_COLOR(173,255,47) }, ++ { "grey", RGB_COLOR(128,128,128) }, ++ { "honeydew", RGB_COLOR(240,255,240) }, ++ { "hotpink", RGB_COLOR(255,105,180) }, ++ { "indianred", RGB_COLOR(205,92,92) }, ++ { "indigo", RGB_COLOR(75,0,130) }, ++ { "ivory", RGB_COLOR(255,255,240) }, ++ { "khaki", RGB_COLOR(240,230,140) }, ++ { "lavender", RGB_COLOR(230,230,250) }, ++ { "lavenderblush", RGB_COLOR(255,240,245) }, ++ { "lawngreen", RGB_COLOR(124,252,0) }, ++ { "lemonchiffon", RGB_COLOR(255,250,205) }, ++ { "lightblue", RGB_COLOR(173,216,230) }, ++ { "lightcoral", RGB_COLOR(240,128,128) }, ++ { "lightcyan", RGB_COLOR(224,255,255) }, ++ { "lightgoldenrodyellow", RGB_COLOR(250,250,210) }, ++ { "lightgray", RGB_COLOR(211,211,211) }, ++ { "lightgreen", RGB_COLOR(144,238,144) }, ++ { "lightgrey", RGB_COLOR(211,211,211) }, ++ { "lightpink", RGB_COLOR(255,182,193) }, ++ { "lightsalmon", RGB_COLOR(255,160,122) }, ++ { "lightseagreen", RGB_COLOR(32,178,170) }, ++ { "lightskyblue", RGB_COLOR(135,206,250) }, ++ { "lightslategray", RGB_COLOR(119,136,153) }, ++ { "lightslategrey", RGB_COLOR(119,136,153) }, ++ { "lightsteelblue", RGB_COLOR(176,196,222) }, ++ { "lightyellow", RGB_COLOR(255,255,224) }, ++ { "lime", RGB_COLOR(0,255,0) }, ++ { "limegreen", RGB_COLOR(50,205,50) }, ++ { "linen", RGB_COLOR(250,240,230) }, ++ { "magenta", RGB_COLOR(255,0,255) }, ++ { "maroon", RGB_COLOR(128,0,0) }, ++ { "mediumaquamarine", RGB_COLOR(102,205,170) }, ++ { "mediumblue", RGB_COLOR(0,0,205) }, ++ { "mediumorchid", RGB_COLOR(186,85,211) }, ++ { "mediumpurple", RGB_COLOR(147,112,219) }, ++ { "mediumseagreen", RGB_COLOR(60,179,113) }, ++ { "mediumslateblue", RGB_COLOR(123,104,238) }, ++ { "mediumspringgreen", RGB_COLOR(0,250,154) }, ++ { "mediumturquoise", RGB_COLOR(72,209,204) }, ++ { "mediumvioletred", RGB_COLOR(199,21,133) }, ++ { "midnightblue", RGB_COLOR(25,25,112) }, ++ { "mintcream", RGB_COLOR(245,255,250) }, ++ { "mistyrose", RGB_COLOR(255,228,225) }, ++ { "moccasin", RGB_COLOR(255,228,181) }, ++ { "navajowhite", RGB_COLOR(255,222,173) }, ++ { "navy", RGB_COLOR(0,0,128) }, ++ { "oldlace", RGB_COLOR(253,245,230) }, ++ { "olive", RGB_COLOR(128,128,0) }, ++ { "olivedrab", RGB_COLOR(107,142,35) }, ++ { "orange", RGB_COLOR(255,165,0) }, ++ { "orangered", RGB_COLOR(255,69,0) }, ++ { "orchid", RGB_COLOR(218,112,214) }, ++ { "palegoldenrod", RGB_COLOR(238,232,170) }, ++ { "palegreen", RGB_COLOR(152,251,152) }, ++ { "paleturquoise", RGB_COLOR(175,238,238) }, ++ { "palevioletred", RGB_COLOR(219,112,147) }, ++ { "papayawhip", RGB_COLOR(255,239,213) }, ++ { "peachpuff", RGB_COLOR(255,218,185) }, ++ { "peru", RGB_COLOR(205,133,63) }, ++ { "pink", RGB_COLOR(255,192,203) }, ++ { "plum", RGB_COLOR(221,160,221) }, ++ { "powderblue", RGB_COLOR(176,224,230) }, ++ { "purple", RGB_COLOR(128,0,128) }, ++ { "red", RGB_COLOR(255,0,0) }, ++ { "rosybrown", RGB_COLOR(188,143,143) }, ++ { "royalblue", RGB_COLOR(65,105,225) }, ++ { "saddlebrown", RGB_COLOR(139,69,19) }, ++ { "salmon", RGB_COLOR(250,128,114) }, ++ { "sandybrown", RGB_COLOR(244,164,96) }, ++ { "seagreen", RGB_COLOR(46,139,87) }, ++ { "seashell", RGB_COLOR(255,245,238) }, ++ { "sienna", RGB_COLOR(160,82,45) }, ++ { "silver", RGB_COLOR(192,192,192) }, ++ { "skyblue", RGB_COLOR(135,206,235) }, ++ { "slateblue", RGB_COLOR(106,90,205) }, ++ { "slategray", RGB_COLOR(112,128,144) }, ++ { "slategrey", RGB_COLOR(112,128,144) }, ++ { "snow", RGB_COLOR(255,250,250) }, ++ { "springgreen", RGB_COLOR(0,255,127) }, ++ { "steelblue", RGB_COLOR(70,130,180) }, ++ { "tan", RGB_COLOR(210,180,140) }, ++ { "teal", RGB_COLOR(0,128,128) }, ++ { "thistle", RGB_COLOR(216,191,216) }, ++ { "tomato", RGB_COLOR(255,99,71) }, ++ { "turquoise", RGB_COLOR(64,224,208) }, ++ { "violet", RGB_COLOR(238,130,238) }, ++ { "wheat", RGB_COLOR(245,222,179) }, ++ { "white", RGB_COLOR(255,255,255) }, ++ { "whitesmoke", RGB_COLOR(245,245,245) }, ++ { "yellow", RGB_COLOR(255,255,0) }, ++ { "yellowgreen", RGB_COLOR(154,205,50) }, ++ { 0, { 0, 0, 0, 0 } } /* Terminator. */ ++}; ++ ++/* Get the color named NAME. If the color was found, returns 1 and ++ stores the color into *COLOR. If the color was not found, returns 0 and ++ does not modify *COLOR. */ ++int ++grub_video_get_named_color (const char *name, ++ grub_video_rgba_color_t *color) ++{ ++ int i; ++ for (i = 0; named_colors[i].name; i++) ++ { ++ if (grub_strcmp (named_colors[i].name, name) == 0) ++ { ++ *color = named_colors[i].color; ++ return 1; ++ } ++ } ++ return 0; ++} ++ ++static __inline int ++my_isxdigit (char c) ++{ ++ return ((c >= '0' && c <= '9') ++ || (c >= 'a' && c <= 'f') ++ || (c >= 'A' && c <= 'F')); ++} ++ ++static int ++parse_hex_color_component (const char *s, unsigned start, unsigned end) ++{ ++ unsigned len; ++ char buf[3]; ++ ++ len = end - start; ++ /* Check the limits so we don't overrun the buffer. */ ++ if (len < 1 || len > 2) ++ return 0; ++ ++ if (len == 1) ++ { ++ buf[0] = s[start]; /* Get the first and only hex digit. */ ++ buf[1] = buf[0]; /* Duplicate the hex digit. */ ++ } ++ else if (len == 2) ++ { ++ buf[0] = s[start]; ++ buf[1] = s[start + 1]; ++ } ++ ++ buf[2] = '\0'; ++ ++ return grub_strtoul (buf, 0, 16); ++} ++ ++/* Parse a color string of the form "r, g, b", "#RGB", "#RGBA", ++ "#RRGGBB", or "#RRGGBBAA". */ ++grub_err_t ++grub_video_parse_color (const char *s, grub_video_rgba_color_t *color) ++{ ++ grub_video_rgba_color_t c; ++ ++ /* Skip whitespace. */ ++ while (*s && grub_isspace (*s)) ++ s++; ++ ++ if (*s == '#') ++ { ++ /* HTML-style. Number if hex digits: ++ [6] #RRGGBB [3] #RGB ++ [8] #RRGGBBAA [4] #RGBA */ ++ ++ s++; /* Skip the '#'. */ ++ /* Count the hexits to determine the format. */ ++ int hexits = 0; ++ const char *end = s; ++ while (my_isxdigit (*end)) ++ { ++ end++; ++ hexits++; ++ } ++ ++ /* Parse the color components based on the format. */ ++ if (hexits == 3 || hexits == 4) ++ { ++ c.red = parse_hex_color_component (s, 0, 1); ++ c.green = parse_hex_color_component (s, 1, 2); ++ c.blue = parse_hex_color_component (s, 2, 3); ++ if (hexits == 4) ++ c.alpha = parse_hex_color_component (s, 3, 4); ++ else ++ c.alpha = 255; ++ } ++ else if (hexits == 6 || hexits == 8) ++ { ++ c.red = parse_hex_color_component (s, 0, 2); ++ c.green = parse_hex_color_component (s, 2, 4); ++ c.blue = parse_hex_color_component (s, 4, 6); ++ if (hexits == 8) ++ c.alpha = parse_hex_color_component (s, 6, 8); ++ else ++ c.alpha = 255; ++ } ++ else ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, ++ "invalid HTML-type color string `%s'", s); ++ } ++ else if (grub_isdigit (*s)) ++ { ++ /* Comma separated decimal values. */ ++ c.red = grub_strtoul (s, 0, 0); ++ if ((s = grub_strchr (s, ',')) == 0) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, ++ "missing 1st comma separator in color `%s'", s); ++ s++; ++ c.green = grub_strtoul (s, 0, 0); ++ if ((s = grub_strchr (s, ',')) == 0) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, ++ "missing 2nd comma separator in color `%s'", s); ++ s++; ++ c.blue = grub_strtoul (s, 0, 0); ++ if ((s = grub_strchr (s, ',')) == 0) ++ c.alpha = 255; ++ else ++ { ++ s++; ++ c.alpha = grub_strtoul (s, 0, 0); ++ } ++ } ++ else ++ { ++ if (! grub_video_get_named_color (s, &c)) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, ++ "invalid named color `%s'", s); ++ } ++ ++ if (grub_errno == GRUB_ERR_NONE) ++ *color = c; ++ return grub_errno; ++} diff --git a/master/debian/branch_squash.patch b/master/debian/branch_squash.patch new file mode 100644 index 0000000..594d03c --- /dev/null +++ b/master/debian/branch_squash.patch @@ -0,0 +1,694 @@ +Description: Add squashfs 4 support +Author: Vladimir Serbinenko <phcoder@gmail.com> +Origin: upstream, http://bzr.sv.gnu.org/r/grub/branches/squash/ +Forwarded: not-needed +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3278 +Last-Update: 2011-05-19 + +Index: b/Makefile.util.def +=================================================================== +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -65,6 +65,7 @@ + common = grub-core/fs/ntfscomp.c; + common = grub-core/fs/reiserfs.c; + common = grub-core/fs/sfs.c; ++ common = grub-core/fs/squash4.c; + common = grub-core/fs/tar.c; + common = grub-core/fs/udf.c; + common = grub-core/fs/ufs2.c; +Index: b/grub-core/Makefile.core.def +=================================================================== +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -985,6 +985,11 @@ + }; + + module = { ++ name = squash4; ++ common = fs/squash4.c; ++}; ++ ++module = { + name = tar; + common = fs/tar.c; + }; +Index: b/grub-core/fs/squash4.c +=================================================================== +--- /dev/null ++++ b/grub-core/fs/squash4.c +@@ -0,0 +1,548 @@ ++/* squash4.c - SquashFS */ ++/* ++ * 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/>. ++ */ ++ ++#include <grub/err.h> ++#include <grub/file.h> ++#include <grub/mm.h> ++#include <grub/misc.h> ++#include <grub/disk.h> ++#include <grub/dl.h> ++#include <grub/types.h> ++#include <grub/fshelp.h> ++#include <grub/deflate.h> ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++/* ++ object format Pointed by ++ superblock RAW Fixed offset (0) ++ data RAW ? Fixed offset (60) ++ inode table Chunk superblock ++ dir table Chunk superblock ++ fragment table Chunk unk1 ++ unk1 RAW, Chunk superblock ++ unk2 RAW superblock ++ UID/GID Chunk exttblptr ++ exttblptr RAW superblock ++ ++ UID/GID table is the array ot uint32_t ++ unk1 contains pointer to unk3 followed by some chunk. ++ unk2 containts one uint64_t ++*/ ++ ++struct grub_squash_super ++{ ++ grub_uint32_t magic; ++#define SQUASH_MAGIC 0x73717368 ++ grub_uint32_t dummy1; ++ grub_uint32_t creation_time; ++ grub_uint32_t dummy2; ++ grub_uint64_t dummy3; ++ grub_uint8_t flags; ++#define SQUASH_FLAG_UNCOMPRESSED_INODES 1 ++#define SQUASH_FLAG_UNCOMPRESSED_DATA 2 ++#define SQUASH_FLAG_UNCOMPRESSED_FRAGMENTS 8 ++ grub_uint8_t dummy4[7]; ++ grub_uint16_t root_ino_offset; ++ grub_uint32_t root_ino_chunk; ++ grub_uint16_t dummy5; ++ grub_uint64_t total_size; ++ grub_uint64_t exttbloffset; ++ grub_uint64_t dummy6; ++ grub_uint64_t inodeoffset; ++ grub_uint64_t diroffset; ++ grub_uint64_t unk1offset; ++ grub_uint64_t unk2offset; ++} __attribute__ ((packed)); ++ ++ ++/* Chunk-based */ ++struct grub_squash_inode ++{ ++ /* Same values as direlem types. */ ++ grub_uint16_t type; ++ grub_uint16_t dummy[3]; ++ grub_uint32_t mtime; ++ union ++ { ++ struct { ++ grub_uint32_t dummy; ++ grub_uint32_t chunk; ++ grub_uint32_t fragment; ++ grub_uint32_t offset; ++ grub_uint32_t size; ++ } __attribute__ ((packed)) file; ++ struct { ++ grub_uint32_t dummy1; ++ grub_uint32_t chunk; ++ grub_uint32_t dummy2; ++ grub_uint16_t size; ++ grub_uint32_t offset; ++ grub_uint16_t dummy3; ++ } __attribute__ ((packed)) dir; ++ struct { ++ grub_uint64_t dummy; ++ grub_uint32_t namelen; ++ char name[0]; ++ } __attribute__ ((packed)) symlink; ++ } __attribute__ ((packed)); ++} __attribute__ ((packed)); ++ ++/* Chunk-based. */ ++struct grub_squash_dirent_header ++{ ++ /* Actually the value is the number of elements - 1. */ ++ grub_uint32_t nelems; ++ grub_uint64_t ino_chunk; ++} __attribute__ ((packed)); ++ ++struct grub_squash_dirent ++{ ++ grub_uint16_t ino_offset; ++ grub_uint16_t dummy; ++ grub_uint16_t type; ++#define SQUASH_TYPE_DIR 1 ++#define SQUASH_TYPE_REGULAR 2 ++#define SQUASH_TYPE_SYMLINK 3 ++ /* Actually the value is the length of name - 1. */ ++ grub_uint16_t namelen; ++ char name[0]; ++} __attribute__ ((packed)); ++ ++struct grub_squash_frag_desc ++{ ++ grub_uint64_t offset; ++ grub_uint64_t dummy; ++} __attribute__ ((packed)); ++ ++#define SQUASH_CHUNK_SIZE 0x2000 ++#define SQUASH_CHUNK_FLAGS 0x8000 ++#define SQUASH_CHUNK_UNCOMPRESSED 0x8000 ++ ++struct grub_squash_data ++{ ++ grub_disk_t disk; ++ struct grub_squash_super sb; ++ struct grub_squash_inode ino; ++ grub_uint64_t fragments; ++}; ++ ++struct grub_fshelp_node ++{ ++ struct grub_squash_data *data; ++ struct grub_squash_inode ino; ++ grub_uint32_t ino_chunk; ++ grub_uint16_t ino_offset; ++}; ++ ++static grub_err_t ++read_chunk (grub_disk_t disk, void *buf, grub_size_t len, ++ grub_uint64_t chunk, grub_off_t offset) ++{ ++ grub_uint64_t chunk_start; ++ chunk_start = grub_le_to_cpu64 (chunk); ++ while (len > 0) ++ { ++ grub_uint64_t csize; ++ grub_uint16_t d; ++ grub_err_t err; ++ while (1) ++ { ++ err = grub_disk_read (disk, chunk_start >> GRUB_DISK_SECTOR_BITS, ++ chunk_start & (GRUB_DISK_SECTOR_SIZE - 1), ++ sizeof (d), &d); ++ if (err) ++ return err; ++ if (offset < SQUASH_CHUNK_SIZE) ++ break; ++ offset -= SQUASH_CHUNK_SIZE; ++ chunk_start += 2 + (grub_le_to_cpu16 (d) & ~SQUASH_CHUNK_FLAGS); ++ } ++ ++ csize = SQUASH_CHUNK_SIZE - offset; ++ if (csize > len) ++ csize = len; ++ ++ if (grub_le_to_cpu16 (d) & SQUASH_CHUNK_UNCOMPRESSED) ++ { ++ grub_disk_addr_t a = chunk_start + 2 + offset; ++ err = grub_disk_read (disk, (a >> GRUB_DISK_SECTOR_BITS), ++ a & (GRUB_DISK_SECTOR_SIZE - 1), ++ csize, buf); ++ if (err) ++ return err; ++ } ++ else ++ { ++ char *tmp; ++ grub_size_t bsize = grub_le_to_cpu16 (d) & ~SQUASH_CHUNK_FLAGS; ++ grub_disk_addr_t a = chunk_start + 2; ++ tmp = grub_malloc (bsize); ++ if (!tmp) ++ return grub_errno; ++ /* FIXME: buffer uncompressed data. */ ++ err = grub_disk_read (disk, (a >> GRUB_DISK_SECTOR_BITS), ++ a & (GRUB_DISK_SECTOR_SIZE - 1), ++ bsize, tmp); ++ if (err) ++ { ++ grub_free (tmp); ++ return err; ++ } ++ ++ if (grub_zlib_decompress (tmp, bsize, offset, ++ buf, csize) < 0) ++ { ++ grub_free (tmp); ++ return grub_errno; ++ } ++ grub_free (tmp); ++ } ++ len -= csize; ++ offset += csize; ++ buf = (char *) buf + csize; ++ } ++ return GRUB_ERR_NONE; ++} ++ ++static struct grub_squash_data * ++squash_mount (grub_disk_t disk) ++{ ++ struct grub_squash_super sb; ++ grub_err_t err; ++ struct grub_squash_data *data; ++ grub_uint64_t frag; ++ ++ err = grub_disk_read (disk, 0, 0, sizeof (sb), &sb); ++ if (grub_errno == GRUB_ERR_OUT_OF_RANGE) ++ grub_error (GRUB_ERR_BAD_FS, "not a squash4"); ++ if (err) ++ return NULL; ++ if (grub_le_to_cpu32 (sb.magic) != SQUASH_MAGIC) ++ { ++ grub_error (GRUB_ERR_BAD_FS, "not squash4"); ++ return NULL; ++ } ++ ++ err = grub_disk_read (disk, grub_le_to_cpu32 (sb.unk1offset) ++ >> GRUB_DISK_SECTOR_BITS, ++ grub_le_to_cpu32 (sb.unk1offset) ++ & (GRUB_DISK_SECTOR_SIZE - 1), sizeof (frag), &frag); ++ if (grub_errno == GRUB_ERR_OUT_OF_RANGE) ++ grub_error (GRUB_ERR_BAD_FS, "not a squash4"); ++ if (err) ++ return NULL; ++ ++ data = grub_malloc (sizeof (*data)); ++ if (!data) ++ return NULL; ++ data->sb = sb; ++ data->disk = disk; ++ data->fragments = frag; ++ ++ return data; ++} ++ ++static char * ++grub_squash_read_symlink (grub_fshelp_node_t node) ++{ ++ char *ret; ++ grub_err_t err; ++ ret = grub_malloc (grub_le_to_cpu32 (node->ino.symlink.namelen) + 1); ++ ++ err = read_chunk (node->data->disk, ret, ++ grub_le_to_cpu32 (node->ino.symlink.namelen), ++ grub_le_to_cpu64 (node->data->sb.inodeoffset) ++ + node->ino_chunk, ++ node->ino_offset + (node->ino.symlink.name ++ - (char *) &node->ino)); ++ if (err) ++ { ++ grub_free (ret); ++ return NULL; ++ } ++ ret[grub_le_to_cpu32 (node->ino.symlink.namelen)] = 0; ++ return ret; ++} ++ ++static int ++grub_squash_iterate_dir (grub_fshelp_node_t dir, ++ int NESTED_FUNC_ATTR ++ (*hook) (const char *filename, ++ enum grub_fshelp_filetype filetype, ++ grub_fshelp_node_t node)) ++{ ++ grub_uint32_t off = grub_le_to_cpu16 (dir->ino.dir.offset); ++ grub_uint32_t endoff; ++ unsigned i; ++ ++ /* FIXME: why - 3 ? */ ++ endoff = grub_le_to_cpu32 (dir->ino.dir.size) + off - 3; ++ ++ while (off < endoff) ++ { ++ struct grub_squash_dirent_header dh; ++ grub_err_t err; ++ ++ err = read_chunk (dir->data->disk, &dh, sizeof (dh), ++ grub_le_to_cpu64 (dir->data->sb.diroffset) ++ + grub_le_to_cpu32 (dir->ino.dir.chunk), off); ++ if (err) ++ return 0; ++ off += sizeof (dh); ++ for (i = 0; i < (unsigned) grub_le_to_cpu16 (dh.nelems) + 1; i++) ++ { ++ char *buf; ++ int r; ++ struct grub_fshelp_node *node; ++ enum grub_fshelp_filetype filetype = GRUB_FSHELP_REG; ++ struct grub_squash_dirent di; ++ struct grub_squash_inode ino; ++ ++ err = read_chunk (dir->data->disk, &di, sizeof (di), ++ grub_le_to_cpu64 (dir->data->sb.diroffset) ++ + grub_le_to_cpu32 (dir->ino.dir.chunk), off); ++ if (err) ++ return 0; ++ off += sizeof (di); ++ ++ err = read_chunk (dir->data->disk, &ino, sizeof (ino), ++ grub_le_to_cpu64 (dir->data->sb.inodeoffset) ++ + grub_le_to_cpu32 (dh.ino_chunk), ++ grub_cpu_to_le16 (di.ino_offset)); ++ if (err) ++ return 0; ++ ++ buf = grub_malloc (grub_le_to_cpu16 (di.namelen) + 2); ++ if (!buf) ++ return 0; ++ err = read_chunk (dir->data->disk, buf, ++ grub_le_to_cpu16 (di.namelen) + 1, ++ grub_le_to_cpu64 (dir->data->sb.diroffset) ++ + grub_le_to_cpu32 (dir->ino.dir.chunk), off); ++ if (err) ++ return 0; ++ ++ off += grub_le_to_cpu16 (di.namelen) + 1; ++ buf[grub_le_to_cpu16 (di.namelen) + 1] = 0; ++ if (grub_le_to_cpu16 (di.type) == SQUASH_TYPE_DIR) ++ filetype = GRUB_FSHELP_DIR; ++ if (grub_le_to_cpu16 (di.type) == SQUASH_TYPE_SYMLINK) ++ filetype = GRUB_FSHELP_SYMLINK; ++ ++ node = grub_malloc (sizeof (*node)); ++ if (! node) ++ return 0; ++ *node = *dir; ++ node->ino = ino; ++ node->ino_chunk = grub_le_to_cpu32 (dh.ino_chunk); ++ node->ino_offset = grub_le_to_cpu16 (di.ino_offset); ++ ++ r = hook (buf, filetype, node); ++ ++ grub_free (buf); ++ if (r) ++ return r; ++ } ++ } ++ return 0; ++} ++ ++static grub_err_t ++make_root_node (struct grub_squash_data *data, struct grub_fshelp_node *root) ++{ ++ grub_memset (root, 0, sizeof (*root)); ++ root->data = data; ++ ++ return read_chunk (data->disk, &root->ino, sizeof (root->ino), ++ grub_le_to_cpu64 (data->sb.inodeoffset) ++ + grub_le_to_cpu16 (data->sb.root_ino_chunk), ++ grub_cpu_to_le16 (data->sb.root_ino_offset)); ++} ++ ++static grub_err_t ++grub_squash_dir (grub_device_t device, const char *path, ++ int (*hook) (const char *filename, ++ const struct grub_dirhook_info *info)) ++{ ++ auto int NESTED_FUNC_ATTR iterate (const char *filename, ++ enum grub_fshelp_filetype filetype, ++ grub_fshelp_node_t node); ++ ++ int NESTED_FUNC_ATTR iterate (const char *filename, ++ enum grub_fshelp_filetype filetype, ++ grub_fshelp_node_t node) ++ { ++ struct grub_dirhook_info info; ++ grub_memset (&info, 0, sizeof (info)); ++ info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR); ++ info.mtimeset = 1; ++ info.mtime = grub_le_to_cpu32 (node->ino.mtime); ++ return hook (filename, &info); ++ } ++ ++ struct grub_squash_data *data = 0; ++ struct grub_fshelp_node *fdiro = 0; ++ struct grub_fshelp_node root; ++ grub_err_t err; ++ ++ data = squash_mount (device->disk); ++ if (! data) ++ return grub_errno; ++ ++ err = make_root_node (data, &root); ++ if (err) ++ return err; ++ ++ grub_fshelp_find_file (path, &root, &fdiro, grub_squash_iterate_dir, ++ grub_squash_read_symlink, GRUB_FSHELP_DIR); ++ if (!grub_errno) ++ grub_squash_iterate_dir (fdiro, iterate); ++ ++ grub_free (data); ++ ++ return grub_errno; ++} ++ ++static grub_err_t ++grub_squash_open (struct grub_file *file, const char *name) ++{ ++ struct grub_squash_data *data = 0; ++ struct grub_fshelp_node *fdiro = 0; ++ struct grub_fshelp_node root; ++ grub_err_t err; ++ ++ data = squash_mount (file->device->disk); ++ if (! data) ++ return grub_errno; ++ ++ err = make_root_node (data, &root); ++ if (err) ++ return err; ++ ++ grub_fshelp_find_file (name, &root, &fdiro, grub_squash_iterate_dir, ++ grub_squash_read_symlink, GRUB_FSHELP_REG); ++ if (grub_errno) ++ { ++ grub_free (data); ++ return grub_errno; ++ } ++ ++ file->data = data; ++ data->ino = fdiro->ino; ++ file->size = grub_le_to_cpu32 (fdiro->ino.file.size); ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_ssize_t ++grub_squash_read_data (struct grub_squash_data *data, ++ grub_disk_t disk, const struct grub_squash_inode *ino, ++ grub_off_t off, char *buf, grub_size_t len) ++{ ++ grub_err_t err; ++ grub_uint64_t a, b; ++ int compressed = 0; ++ ++ if (grub_le_to_cpu16 (ino->file.fragment) == 0xffff) ++ { ++ if (grub_le_to_cpu32 (ino->file.chunk)) ++ a = grub_le_to_cpu32 (ino->file.chunk); ++ else ++ a = sizeof (struct grub_squash_super); ++ compressed = !(data->sb.flags & SQUASH_FLAG_UNCOMPRESSED_DATA); ++ } ++ else ++ { ++ struct grub_squash_frag_desc frag; ++ err = read_chunk (disk, &frag, sizeof (frag), ++ data->fragments, sizeof (frag) ++ * grub_le_to_cpu16 (ino->file.fragment)); ++ if (err) ++ return -1; ++ a = grub_le_to_cpu64 (frag.offset) + grub_le_to_cpu32 (ino->file.chunk); ++ compressed = !(data->sb.flags & SQUASH_FLAG_UNCOMPRESSED_FRAGMENTS); ++ } ++ ++ b = grub_le_to_cpu32 (data->ino.file.offset) + off; ++ ++ /* FIXME: cache uncompressed chunks. */ ++ if (compressed) ++ err = grub_zlib_disk_read (disk, a, b, buf, len); ++ else ++ err = grub_disk_read (disk, (a + b) >> GRUB_DISK_SECTOR_BITS, ++ (a + b) & (GRUB_DISK_SECTOR_SIZE - 1), len, buf); ++ if (err) ++ return -1; ++ return len; ++} ++ ++static grub_ssize_t ++grub_squash_read (grub_file_t file, char *buf, grub_size_t len) ++{ ++ struct grub_squash_data *data = file->data; ++ ++ return grub_squash_read_data (data, file->device->disk, &data->ino, ++ file->offset, buf, len); ++} ++ ++static grub_err_t ++grub_squash_close (grub_file_t file) ++{ ++ grub_free (file->data); ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++grub_squash_mtime (grub_device_t dev, grub_int32_t *tm) ++{ ++ struct grub_squash_data *data = 0; ++ ++ data = squash_mount (dev->disk); ++ if (! data) ++ return grub_errno; ++ *tm = grub_le_to_cpu32 (data->sb.creation_time); ++ grub_free (data); ++ return GRUB_ERR_NONE; ++} ++ ++static struct grub_fs grub_squash_fs = ++ { ++ .name = "squash4", ++ .dir = grub_squash_dir, ++ .open = grub_squash_open, ++ .read = grub_squash_read, ++ .close = grub_squash_close, ++ .mtime = grub_squash_mtime, ++#ifdef GRUB_UTIL ++ .reserved_first_sector = 0, ++#endif ++ .next = 0 ++ }; ++ ++GRUB_MOD_INIT(squash4) ++{ ++ grub_fs_register (&grub_squash_fs); ++} ++ ++GRUB_MOD_FINI(squash4) ++{ ++ grub_fs_unregister (&grub_squash_fs); ++} ++ +Index: b/grub-core/io/gzio.c +=================================================================== +--- a/grub-core/io/gzio.c ++++ b/grub-core/io/gzio.c +@@ -41,6 +41,7 @@ + #include <grub/fs.h> + #include <grub/file.h> + #include <grub/dl.h> ++#include <grub/disk.h> + #include <grub/deflate.h> + + GRUB_MOD_LICENSE ("GPLv3+"); +@@ -64,6 +65,9 @@ + /* If input is in memory following fields are used instead of file. */ + grub_size_t mem_input_size, mem_input_off; + grub_uint8_t *mem_input; ++ grub_disk_addr_t disk_input_off; ++ grub_disk_addr_t disk_input_start; ++ grub_disk_t disk_input; + /* The offset at which the data starts in the underlying file. */ + grub_off_t data_offset; + /* The type of current block. */ +@@ -384,8 +388,21 @@ + return 0; + } + +- if (grub_file_tell (gzio->file) == (grub_off_t) gzio->data_offset +- || gzio->inbuf_d == INBUFSIZ) ++ if (gzio->disk_input && (gzio->disk_input_off == gzio->data_offset ++ || gzio->inbuf_d == INBUFSIZ)) ++ { ++ grub_disk_addr_t d = gzio->disk_input_start + gzio->disk_input_off; ++ gzio->inbuf_d = 0; ++ grub_disk_read (gzio->disk_input, ++ d >> GRUB_DISK_SECTOR_BITS, ++ d & (GRUB_DISK_SECTOR_SIZE - 1), ++ INBUFSIZ, gzio->inbuf); ++ gzio->disk_input_off += INBUFSIZ; ++ } ++ ++ if (gzio->file && (grub_file_tell (gzio->file) ++ == (grub_off_t) gzio->data_offset ++ || gzio->inbuf_d == INBUFSIZ)) + { + gzio->inbuf_d = 0; + grub_file_read (gzio->file, gzio->inbuf, INBUFSIZ); +@@ -403,8 +420,10 @@ + grub_error (GRUB_ERR_OUT_OF_RANGE, + "attempt to seek outside of the file"); + else +- gzio->mem_input_off = gzio->data_offset; ++ gzio->mem_input_off = off; + } ++ else if (gzio->disk_input) ++ gzio->disk_input_off = off; + else + grub_file_seek (gzio->file, off); + } +@@ -1298,6 +1317,34 @@ + return ret; + } + ++grub_err_t ++grub_zlib_disk_read (grub_disk_t disk, grub_disk_addr_t zlibstart, ++ grub_off_t off, char *outbuf, grub_size_t outsize) ++{ ++ grub_gzio_t gzio = 0; ++ grub_ssize_t ret; ++ ++ gzio = grub_zalloc (sizeof (*gzio)); ++ if (! gzio) ++ return -1; ++ ++ gzio->disk_input_off = 0; ++ gzio->disk_input_start = zlibstart; ++ gzio->disk_input = disk; ++ ++ if (!test_zlib_header (gzio)) ++ { ++ grub_free (gzio); ++ return -1; ++ } ++ ++ ret = grub_gzio_read_real (gzio, off, outbuf, outsize); ++ grub_free (gzio); ++ ++ /* FIXME: Check Adler. */ ++ return ret < 0 ? grub_errno : GRUB_ERR_NONE; ++} ++ + + + static struct grub_fs grub_gzio_fs = +Index: b/include/grub/deflate.h +=================================================================== +--- a/include/grub/deflate.h ++++ b/include/grub/deflate.h +@@ -23,4 +23,8 @@ + grub_zlib_decompress (char *inbuf, grub_size_t insize, grub_off_t off, + char *outbuf, grub_size_t outsize); + ++grub_err_t ++grub_zlib_disk_read (grub_disk_t disk, grub_disk_addr_t zlibstart, ++ grub_off_t off, char *outbuf, grub_size_t outsize); ++ + #endif diff --git a/master/debian/btrfs_stat.patch b/master/debian/btrfs_stat.patch new file mode 100644 index 0000000..7e162e6 --- /dev/null +++ b/master/debian/btrfs_stat.patch @@ -0,0 +1,36 @@ +Description: Cope with btrfs / inside an encrypted block device + If / is inside an encrypted block device, then grub-probe can't tell what + its filesystem type is. Work around this. +Author: alexeagar@gmail.com +Bug-Ubuntu: https://bugs.launchpad.net/bugs/757631 +Forwarded: no +Last-Update: 2011-06-15 + +Index: b/util/grub.d/10_linux.in +=================================================================== +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -56,7 +56,8 @@ + LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} + fi + +-if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then ++if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ] \ ++ || [ "x`stat -f --printf=%T /`" = xbtrfs ]; then + rootsubvol="`make_system_path_relative_to_its_root /`" + rootsubvol="${rootsubvol#/}" + if [ "x${rootsubvol}" != x ]; then +Index: b/util/grub.d/20_linux_xen.in +=================================================================== +--- a/util/grub.d/20_linux_xen.in ++++ b/util/grub.d/20_linux_xen.in +@@ -56,7 +56,8 @@ + LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} + fi + +-if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then ++if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ] \ ++ || [ "x`stat -f --printf=%T /`" = xbtrfs ]; then + rootsubvol="`make_system_path_relative_to_its_root /`" + rootsubvol="${rootsubvol#/}" + if [ "x${rootsubvol}" != x ]; then diff --git a/master/debian/core_in_fs.patch b/master/debian/core_in_fs.patch new file mode 100644 index 0000000..7b597ea --- /dev/null +++ b/master/debian/core_in_fs.patch @@ -0,0 +1,31 @@ +Index: b/util/grub-setup.c +=================================================================== +--- a/util/grub-setup.c ++++ b/util/grub-setup.c +@@ -76,6 +76,7 @@ + + #define DEFAULT_BOOT_FILE "boot.img" + #define DEFAULT_CORE_FILE "core.img" ++#define CORE_IMG_IN_FS "setup_left_core_image_in_filesystem" + + #ifdef GRUB_MACHINE_SPARC64 + #define grub_target_to_host16(x) grub_be_to_cpu16(x) +@@ -489,6 +490,8 @@ + + grub_free (sectors); + ++ unlink (DEFAULT_DIRECTORY "/" CORE_IMG_IN_FS); ++ + goto finish; + } + #endif +@@ -514,6 +517,9 @@ + /* The core image must be put on a filesystem unfortunately. */ + grub_util_info ("will leave the core image on the filesystem"); + ++ fp = fopen (DEFAULT_DIRECTORY "/" CORE_IMG_IN_FS, "w"); ++ fclose (fp); ++ + /* Make sure that GRUB reads the identical image as the OS. */ + tmp_img = xmalloc (core_size); + core_path_dev_full = grub_util_get_path (dir, core_file); diff --git a/master/debian/dirlen.patch b/master/debian/dirlen.patch new file mode 100644 index 0000000..1268456 --- /dev/null +++ b/master/debian/dirlen.patch @@ -0,0 +1,19 @@ +Description: Ignore entries with direct.inode = 0. +Author: Samuel Thibault <samuel.thibault@ens-lyon.org> +Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3749 +Forwarded: not-needed +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3749 +Last-Update: 2012-06-08 + +--- a/grub-core/fs/ext2.c 2012-01-14 10:30:43 +0000 ++++ b/grub-core/fs/ext2.c 2012-01-14 10:55:20 +0000 +@@ -685,7 +685,7 @@ grub_ext2_iterate_dir (grub_fshelp_node_ + if (dirent.direntlen == 0) + return 0; + +- if (dirent.namelen != 0) ++ if (dirent.inode != 0 && dirent.namelen != 0) + { + char filename[dirent.namelen + 1]; + struct grub_fshelp_node *fdiro; + diff --git a/master/debian/disable_floppies.patch b/master/debian/disable_floppies.patch new file mode 100644 index 0000000..6bb2862 --- /dev/null +++ b/master/debian/disable_floppies.patch @@ -0,0 +1,28 @@ + +Author: Robert Millan + +An ugly kludge. Should this be merged upstream? + +Index: b/grub-core/kern/emu/hostdisk.c +=================================================================== +--- a/grub-core/kern/emu/hostdisk.c ++++ b/grub-core/kern/emu/hostdisk.c +@@ -1077,6 +1077,18 @@ + continue; + } + ++ if (! strncmp (p, "/dev/fd", sizeof ("/dev/fd") - 1)) ++ { ++ char *q = p + sizeof ("/dev/fd") - 1; ++ if (*q >= '0' && *q <= '9') ++ { ++ free (map[drive].drive); ++ map[drive].drive = NULL; ++ grub_util_info ("`%s' looks like a floppy drive, skipping", p); ++ continue; ++ } ++ } ++ + #ifdef __linux__ + /* On Linux, the devfs uses symbolic links horribly, and that + confuses the interface very much, so use realpath to expand diff --git a/master/debian/dpkg_version_comparison.patch b/master/debian/dpkg_version_comparison.patch new file mode 100644 index 0000000..6b23c61 --- /dev/null +++ b/master/debian/dpkg_version_comparison.patch @@ -0,0 +1,30 @@ +Description: Improve handling of Debian kernel version numbers +Author: Robert Millan <rmh@aybabtu.com> +Forwarded: not-needed +Last-Update: 2011-04-21 + +Index: b/util/grub-mkconfig_lib.in +=================================================================== +--- a/util/grub-mkconfig_lib.in ++++ b/util/grub-mkconfig_lib.in +@@ -172,8 +172,9 @@ + + version_test_gt () + { +- local a="`echo "$1" | sed -e "s/[^-]*-//"`" +- local b="`echo "$2" | sed -e "s/[^-]*-//"`" ++ local sedexp="s/[^-]*-//;s/[._-]\(pre\|rc\|test\|git\|old\|trunk\)/~\1/g" ++ local a="`echo "$1" | sed -e "$sedexp"`" ++ local b="`echo "$2" | sed -e "$sedexp"`" + local cmp=gt + if [ "x$b" = "x" ] ; then + return 0 +@@ -183,7 +184,7 @@ + *.old:*) a="`echo -n "$a" | sed -e 's/\.old$//'`" ; cmp=gt ;; + *:*.old) b="`echo -n "$b" | sed -e 's/\.old$//'`" ; cmp=ge ;; + esac +- version_test_numeric "$a" "$cmp" "$b" ++ dpkg --compare-versions "$a" $cmp "$b" + return "$?" + } + diff --git a/master/debian/efi_disk_cache.patch b/master/debian/efi_disk_cache.patch new file mode 100644 index 0000000..478e144 --- /dev/null +++ b/master/debian/efi_disk_cache.patch @@ -0,0 +1,26 @@ +Description: Bump the values of GRUB_DISK_CACHE_SIZE and GRUB_DISK_CACHE_BITS + on EFI systems (and only on EFI sytems) to dramatically reduce the load times + for vmlinux and initrd. Forwarding this isn't required as upstream trunk + has completely rewritten how this all works. +Author: Adam Conrad <adconrad@debian.org> +Origin: other, http://blog.fpmurphy.com/2010/03/grub2-efi-support.html +Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/944347 +Forwarded: not-needed +Last-Update: 2012-03-05 + +Index: b/include/grub/disk.h +=================================================================== +--- a/include/grub/disk.h ++++ b/include/grub/disk.h +@@ -137,7 +137,11 @@ + + /* The size of a disk cache in 512B units. Must be at least as big as the + largest supported sector size, currently 16K. */ ++#ifdef GRUB_MACHINE_EFI ++#define GRUB_DISK_CACHE_BITS 10 ++#else + #define GRUB_DISK_CACHE_BITS 6 ++#endif + #define GRUB_DISK_CACHE_SIZE (1 << GRUB_DISK_CACHE_BITS) + + /* Return value of grub_disk_get_size() in case disk size is unknown. */ diff --git a/master/debian/efiemu_fix.patch b/master/debian/efiemu_fix.patch new file mode 100644 index 0000000..5dba671 --- /dev/null +++ b/master/debian/efiemu_fix.patch @@ -0,0 +1,134 @@ +Description: Fix efiemu + Without this, lzo.patch causes efiemu not to be built. +Author: Vladimir Serbinenko <phcoder@gmail.com> +Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3740 +Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/4066 +Forwarded: not-needed +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3740 +Last-Update: 2012-03-19 + +Index: b/configure.ac +=================================================================== +--- a/configure.ac ++++ b/configure.ac +@@ -479,6 +479,42 @@ + esac + AC_MSG_RESULT([$TARGET_OBJ2ELF]) + ++ ++AC_ARG_ENABLE([efiemu], ++ [AS_HELP_STRING([--enable-efiemu], ++ [build and install the efiemu runtimes (default=guessed)])]) ++if test x"$enable_efiemu" = xno ; then ++ efiemu_excuse="explicitly disabled" ++fi ++if test x"$target_cpu" != xi386 ; then ++ efiemu_excuse="only available on i386" ++fi ++if test x"$platform" = xefi ; then ++ efiemu_excuse="not available on efi" ++fi ++if test x"$efiemu_excuse" = x ; then ++ AC_CACHE_CHECK([whether options required for efiemu work], grub_cv_cc_efiemu, [ ++ SAVED_CFLAGS="$CFLAGS" ++ CFLAGS="$CFLAGS -m64 -mcmodel=large -mno-red-zone -nostdlib" ++ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], ++ [grub_cv_cc_efiemu=yes], ++ [grub_cv_cc_efiemu=no]) ++ CFLAGS="$SAVED_CFLAGS" ++ ]) ++ if test x$grub_cv_cc_efiemu = xno; then ++ efiemu_excuse="cannot compile with -m64 -mcmodel=large -mno-red-zone -nostdlib" ++ fi ++fi ++if test x"$enable_efiemu" = xyes && test x"$efiemu_excuse" != x ; then ++ AC_MSG_ERROR([efiemu runtime was explicitly requested but can't be compiled]) ++fi ++if test x"$efiemu_excuse" = x ; then ++enable_efiemu=yes ++else ++enable_efiemu=no ++fi ++AC_SUBST([enable_efiemu]) ++ + if test "x$target_m32" = x1; then + # Force 32-bit mode. + TARGET_CFLAGS="$TARGET_CFLAGS -m32" +@@ -638,39 +674,6 @@ + grub_I386_ASM_ADDR32 + fi + +-AC_ARG_ENABLE([efiemu], +- [AS_HELP_STRING([--enable-efiemu], +- [build and install the efiemu runtimes (default=guessed)])]) +-if test x"$enable_efiemu" = xno ; then +- efiemu_excuse="explicitly disabled" +-fi +-if test x"$target_cpu" != xi386 ; then +- efiemu_excuse="only available on i386" +-fi +-if test x"$platform" = xefi ; then +- efiemu_excuse="not available on efi" +-fi +-if test x"$efiemu_excuse" = x ; then +- AC_CACHE_CHECK([whether options required for efiemu work], grub_cv_cc_efiemu, [ +- CFLAGS="$CFLAGS -m64 -mcmodel=large -mno-red-zone -nostdlib" +- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], +- [grub_cv_cc_efiemu=yes], +- [grub_cv_cc_efiemu=no]) +- ]) +- if test x$grub_cv_cc_efiemu = xno; then +- efiemu_excuse="cannot compile with -m64 -mcmodel=large -mno-red-zone -nostdlib" +- fi +-fi +-if test x"$enable_efiemu" = xyes && test x"$efiemu_excuse" != x ; then +- AC_MSG_ERROR([efiemu runtime was explicitly requested but can't be compiled]) +-fi +-if test x"$efiemu_excuse" = x ; then +-enable_efiemu=yes +-else +-enable_efiemu=no +-fi +-AC_SUBST([enable_efiemu]) +- + if test "$platform" != emu; then + AC_CACHE_CHECK([whether -nostdinc -isystem works], [grub_cv_cc_isystem], [ + SAVED_CPPFLAGS="$CPPFLAGS" +Index: b/grub-core/efiemu/runtime/efiemu.c +=================================================================== +--- a/grub-core/efiemu/runtime/efiemu.c ++++ b/grub-core/efiemu/runtime/efiemu.c +@@ -21,6 +21,12 @@ + As it emulates only runtime serviceit isn't able + to chainload EFI bootloader on non-EFI system (TODO) */ + ++#ifdef __i386__ ++#include <grub/i386/types.h> ++#else ++#include <grub/x86_64/types.h> ++#endif ++ + #include <grub/symbol.h> + #include <grub/types.h> + #include <grub/efi/api.h> +@@ -369,16 +375,16 @@ + switch (cur_relloc->size) + { + case 8: +- *((grub_uint64_t *) UINT_TO_PTR (cur_relloc->addr)) += corr; ++ *((grub_uint64_t *) (grub_addr_t) cur_relloc->addr) += corr; + break; + case 4: +- *((grub_uint32_t *) UINT_TO_PTR (cur_relloc->addr)) += corr; ++ *((grub_uint32_t *) (grub_addr_t) cur_relloc->addr) += corr; + break; + case 2: +- *((grub_uint16_t *) UINT_TO_PTR (cur_relloc->addr)) += corr; ++ *((grub_uint16_t *) (grub_addr_t) cur_relloc->addr) += corr; + break; + case 1: +- *((grub_uint8_t *) UINT_TO_PTR (cur_relloc->addr)) += corr; ++ *((grub_uint8_t *) (grub_addr_t) cur_relloc->addr) += corr; + break; + } + } diff --git a/master/debian/fat_uuid.patch b/master/debian/fat_uuid.patch new file mode 100644 index 0000000..b7c0a46 --- /dev/null +++ b/master/debian/fat_uuid.patch @@ -0,0 +1,25 @@ +Description: Make FAT UUID uppercase to match Linux +Author: Vladimir Serbinenko <phcoder@gmail.com> +Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3482 +Bug-Ubuntu: https://bugs.launchpad.net/bugs/948716 +Forwarded: not-needed +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3482 +Last-Update: 2012-03-19 + +Index: b/grub-core/fs/fat.c +=================================================================== +--- a/grub-core/fs/fat.c ++++ b/grub-core/fs/fat.c +@@ -836,9 +836,12 @@ + data = grub_fat_mount (disk); + if (data) + { ++ char *ptr; + *uuid = grub_xasprintf ("%04x-%04x", + (grub_uint16_t) (data->uuid >> 16), + (grub_uint16_t) data->uuid); ++ for (ptr = *uuid; ptr && *ptr; ptr++) ++ *ptr = grub_toupper (*ptr); + } + else + *uuid = NULL; diff --git a/master/debian/gcc_4_6_space.patch b/master/debian/gcc_4_6_space.patch new file mode 100644 index 0000000..7aaa536 --- /dev/null +++ b/master/debian/gcc_4_6_space.patch @@ -0,0 +1,33 @@ +Description: Build with -fno-asynchronous-unwind-tables to save space +Author: Vladimir Serbinenko <phcoder@gmail.com> +Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3589 +Last-Update: 2012-03-06 + +Index: b/configure.ac +=================================================================== +--- a/configure.ac ++++ b/configure.ac +@@ -415,6 +415,23 @@ + fi + fi + ++# By default, GCC 4.6 generates .eh_frame sections containing unwind ++# information in some cases where it previously did not. GRUB doesn't need ++# these and they just use up vital space. Restore the old compiler ++# behaviour. ++AC_CACHE_CHECK([whether -fno-asynchronous-unwind-tables works], [grub_cv_cc_fno_asynchronous_unwind_tables], [ ++ SAVE_CFLAGS="$CFLAGS" ++ CFLAGS="$CFLAGS -fno-dwarf2-cfi-asm" ++ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], ++ [grub_cv_cc_fno_asynchronous_unwind_tables=yes], ++ [grub_cv_cc_fno_asynchronous_unwind_tables=no]) ++ CFLAGS="$SAVE_CFLAGS" ++]) ++ ++if test "x$grub_cv_cc_fno_asynchronous_unwind_tables" = xyes; then ++ TARGET_CFLAGS="$TARGET_CFLAGS -fno-asynchronous-unwind-tables" ++fi ++ + grub_apple_target_cc + if test x$grub_cv_apple_target_cc = xyes ; then + TARGET_CPPFLAGS="$TARGET_CPPFLAGS -DAPPLE_CC=1" diff --git a/master/debian/gfxpayload_keep_default.patch b/master/debian/gfxpayload_keep_default.patch new file mode 100644 index 0000000..43cfb6f --- /dev/null +++ b/master/debian/gfxpayload_keep_default.patch @@ -0,0 +1,38 @@ +Description: Disable gfxpayload=keep by default + Setting gfxpayload=keep has been known to cause efifb to be inappropriately + enabled. In any case, with the current Linux kernel the result of this + option is that early kernelspace will be unable to print anything to the + console, so (for example) if boot fails and you end up dumped to an + initramfs prompt, you won't be able to see anything on the screen. As such + it shouldn't be enabled by default in Debian, no matter what kernel options + are enabled. + . + gfxpayload=keep is a good idea but rather ahead of its time ... +Author: Colin Watson <cjwatson@debian.org> +Bug-Debian: http://bugs.debian.org/567245 +Forwarded: no +Last-Update: 2010-03-09 + +Index: b/util/grub.d/10_linux.in +=================================================================== +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -77,17 +77,7 @@ + + # Use ELILO's generic "efifb" when it's known to be available. + # FIXME: We need an interface to select vesafb in case efifb can't be used. +- if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then +- cat << EOF +- load_video +-EOF +- if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \ +- && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then +- cat << EOF +- set gfxpayload=keep +-EOF +- fi +- else ++ if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ]; then + if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then + cat << EOF + load_video diff --git a/master/debian/gfxterm_background.patch b/master/debian/gfxterm_background.patch new file mode 100644 index 0000000..6fa0ff8 --- /dev/null +++ b/master/debian/gfxterm_background.patch @@ -0,0 +1,69 @@ +Description: Fix gfxterm background_color regression +Author: Colin Watson <cjwatson@ubuntu.com> +Forwarded: http://lists.gnu.org/archive/html/grub-devel/2011-06/msg00085.html +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3368 +Last-Update: 2011-06-28 + +Index: b/grub-core/term/gfxterm.c +=================================================================== +--- a/grub-core/term/gfxterm.c ++++ b/grub-core/term/gfxterm.c +@@ -131,6 +131,7 @@ + static unsigned int bitmap_height; + static struct grub_video_bitmap *bitmap; + static int blend_text_bg; ++static grub_video_rgba_color_t default_bg_color = { 0, 0, 0, 0 }; + + static struct grub_dirty_region dirty_region; + +@@ -266,7 +267,8 @@ + + grub_video_set_active_render_target (render_target); + +- virtual_screen.bg_color_display = grub_video_map_rgba(0, 0, 0, 0); ++ virtual_screen.bg_color_display = ++ grub_video_map_rgba_color (default_bg_color); + + /* Clear out text buffer. */ + for (i = 0; i < virtual_screen.columns * virtual_screen.rows; i++) +@@ -338,8 +340,8 @@ + double_redraw = mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED + && !(mode_info.mode_type & GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP); + +- /* Make sure screen is black. */ +- color = grub_video_map_rgb (0, 0, 0); ++ /* Make sure screen is set to the default background color. */ ++ color = grub_video_map_rgba_color (default_bg_color); + grub_video_fill_rect (color, 0, 0, mode_info.width, mode_info.height); + if (double_redraw) + { +@@ -1189,7 +1191,6 @@ + grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) + { +- grub_video_rgba_color_t color; + struct grub_video_render_target *old_target; + + if (argc != 1) +@@ -1199,7 +1200,7 @@ + if (grub_video_get_info (NULL) != GRUB_ERR_NONE) + return grub_errno; + +- if (grub_video_parse_color (args[0], &color) != GRUB_ERR_NONE) ++ if (grub_video_parse_color (args[0], &default_bg_color) != GRUB_ERR_NONE) + return grub_errno; + + /* Destroy existing background bitmap if loaded. */ +@@ -1216,9 +1217,10 @@ + compatible with the text layer. */ + grub_video_get_active_render_target (&old_target); + grub_video_set_active_render_target (text_layer); +- virtual_screen.bg_color = grub_video_map_rgba_color (color); ++ virtual_screen.bg_color = grub_video_map_rgba_color (default_bg_color); + grub_video_set_active_render_target (old_target); +- virtual_screen.bg_color_display = grub_video_map_rgba_color (color); ++ virtual_screen.bg_color_display = ++ grub_video_map_rgba_color (default_bg_color); + blend_text_bg = 1; + + /* Mark whole screen as dirty. */ diff --git a/master/debian/grub.cfg_400.patch b/master/debian/grub.cfg_400.patch new file mode 100644 index 0000000..1ac8d44 --- /dev/null +++ b/master/debian/grub.cfg_400.patch @@ -0,0 +1,15 @@ +Index: b/util/grub-mkconfig.in +=================================================================== +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -293,6 +293,10 @@ + esac + done + ++if [ "x${grub_cfg}" != "x" ] && ! grep "^password " ${grub_cfg}.new >/dev/null; then ++ chmod 444 ${grub_cfg}.new || true ++fi ++ + if test "x${grub_cfg}" != "x" ; then + if ! ${grub_script_check} ${grub_cfg}.new; then + echo "Syntax errors are detected in generated GRUB config file." >&2 diff --git a/master/debian/grub_legacy_0_based_partitions.patch b/master/debian/grub_legacy_0_based_partitions.patch new file mode 100644 index 0000000..f245434 --- /dev/null +++ b/master/debian/grub_legacy_0_based_partitions.patch @@ -0,0 +1,43 @@ +Index: b/grub-core/kern/emu/hostdisk.c +=================================================================== +--- a/grub-core/kern/emu/hostdisk.c ++++ b/grub-core/kern/emu/hostdisk.c +@@ -1131,7 +1131,7 @@ + char *bsd_part_str = NULL; + + if (dos_part >= 0) +- dos_part_str = xasprintf (",%d", dos_part + 1); ++ dos_part_str = xasprintf (",%d", dos_part + (getenv ("GRUB_LEGACY_0_BASED_PARTITIONS") ? 0 : 1)); + + if (bsd_part >= 0) + bsd_part_str = xasprintf (",%d", bsd_part + 1); +@@ -1619,6 +1619,29 @@ + + if (start == part_start) + { ++ if (getenv ("GRUB_LEGACY_0_BASED_PARTITIONS")) ++ { ++ int dos_part, bsd_part; ++ char *fullname, *comma; ++ ++ if (partition->parent) ++ { ++ dos_part = partition->parent->number; ++ bsd_part = partition->number; ++ } ++ else ++ { ++ dos_part = partition->number; ++ bsd_part = -1; ++ } ++ ++ fullname = make_device_name (drive, dos_part, bsd_part); ++ comma = strchr (fullname, ','); ++ partname = comma ? xstrdup (comma + 1) : NULL; ++ free (fullname); ++ return 1; ++ } ++ + partname = grub_partition_get_name (partition); + return 1; + } diff --git a/master/debian/handle_new_autotools.patch b/master/debian/handle_new_autotools.patch new file mode 100644 index 0000000..91f72b4 --- /dev/null +++ b/master/debian/handle_new_autotools.patch @@ -0,0 +1,535 @@ +Description: Handle new autotools, and add some missing quotes in the process + Backported by Colin Watson; I modified this to keep update-grub_lib in + place until such time as we upgrade to a newer upstream snapshot. +Author: Vladimir Serbinenko <phcoder@gmail.com> +Origin: backport, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3766 +Last-Update: 2012-01-31 + +Index: b/Makefile.am +=================================================================== +--- a/Makefile.am ++++ b/Makefile.am +@@ -101,8 +101,8 @@ + # Install config.h into platformdir + platform_HEADERS = config.h + +-pkglib_DATA += grub-mkconfig_lib +-pkglib_DATA += update-grub_lib ++pkgdata_DATA += grub-mkconfig_lib ++pkgdata_DATA += update-grub_lib + + + if COND_i386_coreboot +Index: b/conf/Makefile.common +=================================================================== +--- a/conf/Makefile.common ++++ b/conf/Makefile.common +@@ -137,7 +137,7 @@ + + man_MANS = + noinst_DATA = +-pkglib_DATA = ++pkgdata_DATA = + bin_SCRIPTS = + sbin_SCRIPTS = + bin_PROGRAMS = +@@ -147,7 +147,6 @@ + grubconf_DATA = + check_PROGRAMS = + noinst_SCRIPTS = +-pkglib_SCRIPTS = + noinst_PROGRAMS = + grubconf_SCRIPTS = + noinst_LIBRARIES = +Index: b/tests/util/grub-shell-tester.in +=================================================================== +--- a/tests/util/grub-shell-tester.in ++++ b/tests/util/grub-shell-tester.in +@@ -19,18 +19,17 @@ + # Initialize some variables. + transform="@program_transform_name@" + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-bindir=@bindir@ +-libdir=@libdir@ +-builddir=@builddir@ ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++builddir="@builddir@" + PACKAGE_NAME=@PACKAGE_NAME@ + PACKAGE_TARNAME=@PACKAGE_TARNAME@ + PACKAGE_VERSION=@PACKAGE_VERSION@ + target_cpu=@target_cpu@ + + # Force build directory components +-PATH=${builddir}:$PATH ++PATH="${builddir}:$PATH" + export PATH + + # Usage: usage +@@ -85,23 +84,23 @@ + if [ "x${source}" = x ] ; then + tmpfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 + while read REPLY; do +- echo $REPLY >> ${tmpfile} ++ echo $REPLY >> "${tmpfile}" + done +- source=${tmpfile} ++ source="${tmpfile}" + fi + + outfile1=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 +-@builddir@/grub-shell --qemu-opts="${qemuopts}" --modules=${modules} ${source} >${outfile1} ++"@builddir@/grub-shell" --qemu-opts="${qemuopts}" --modules=${modules} "${source}" >"${outfile1}" + + outfile2=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 +-bash ${source} >${outfile2} ++bash "${source}" >"${outfile2}" + +-if ! diff -q ${outfile1} ${outfile2} >/dev/null ++if ! diff -q "${outfile1}" "${outfile2}" >/dev/null + then + echo "${source}: GRUB and BASH outputs did not match (see diff -u ${outfile1} ${outfile2})" + status=1 + else +- rm -f ${outfile1} ${outfile2} ++ rm -f "${outfile1}" "${outfile2}" + fi + + exit $status +Index: b/tests/util/grub-shell.in +=================================================================== +--- a/tests/util/grub-shell.in ++++ b/tests/util/grub-shell.in +@@ -19,11 +19,10 @@ + # Initialize some variables. + transform="@program_transform_name@" + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-bindir=@bindir@ +-libdir=@libdir@ +-builddir=@builddir@ ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++builddir="@builddir@" + PACKAGE_NAME=@PACKAGE_NAME@ + PACKAGE_TARNAME=@PACKAGE_TARNAME@ + PACKAGE_VERSION=@PACKAGE_VERSION@ +@@ -31,7 +30,7 @@ + platform=@platform@ + + # Force build directory components +-PATH=${builddir}:$PATH ++PATH="${builddir}:$PATH" + export PATH + + # Usage: usage +@@ -140,9 +139,9 @@ + + isofile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 + if [ x$boot != xnet ]; then +- sh @builddir@/grub-mkrescue --grub-mkimage=${builddir}/grub-mkimage --output=${isofile} --override-directory=${builddir}/grub-core \ ++ sh "@builddir@/grub-mkrescue" "--grub-mkimage=${builddir}/grub-mkimage" "--output=${isofile}" "--override-directory=${builddir}/grub-core" \ + --rom-directory="${rom_directory}" \ +- /boot/grub/grub.cfg=${cfgfile} /boot/grub/testcase.cfg=${source} \ ++ "/boot/grub/grub.cfg=${cfgfile}" "/boot/grub/testcase.cfg=${source}" \ + ${files} >/dev/null 2>&1 + fi + if [ x$boot = xhd ]; then +@@ -173,12 +172,12 @@ + + if [ x$boot = xnet ]; then + netdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 +- sh @builddir@/grub-mknetdir --grub-mkimage=${builddir}/grub-mkimage --override-directory=${builddir}/grub-core --net-directory=$netdir +- cp ${cfgfile} $netdir/boot/grub/grub.cfg +- cp ${source} $netdir/boot/grub/testcase.cfg +- ${qemu} ${qemuopts} -nographic -serial file:/dev/stdout -monitor file:/dev/null -boot n -net user,tftp=$netdir,bootfile=/boot/grub/$target_cpu-$platform/core.0 -net nic | cat | tr -d "\r" ++ sh "@builddir@/grub-mknetdir" "--grub-mkimage=${builddir}/grub-mkimage" "--override-directory=${builddir}/grub-core" "--net-directory=$netdir" ++ cp "${cfgfile}" "$netdir/boot/grub/grub.cfg" ++ cp "${source}" "$netdir/boot/grub/testcase.cfg" ++ "${qemu}" ${qemuopts} -nographic -serial file:/dev/stdout -monitor file:/dev/null -boot n -net "user,tftp=$netdir,bootfile=/boot/grub/$target_cpu-$platform/core.0" -net nic | cat | tr -d "\r" + else +- ${qemu} ${qemuopts} -nographic -serial file:/dev/stdout -monitor file:/dev/null -${device} ${isofile} ${bootdev} | cat | tr -d "\r" ++ "${qemu}" ${qemuopts} -nographic -serial file:/dev/stdout -monitor file:/dev/null -${device} ${isofile} ${bootdev} | cat | tr -d "\r" + fi + rm -f "${isofile}" "${imgfile}" + rm -rf "${rom_directory}" +Index: b/util/grub-install.in +=================================================================== +--- a/util/grub-install.in ++++ b/util/grub-install.in +@@ -21,6 +21,7 @@ + + prefix="@prefix@" + exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" + sbindir="@sbindir@" + bindir="@bindir@" + libdir="@libdir@" +@@ -32,6 +33,7 @@ + platform=@platform@ + host_os=@host_os@ + pkglibdir="${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}`" ++datadir="@datadir@" + localedir="@datadir@/locale" + + self="`basename $0`" +Index: b/util/grub-mkconfig.in +=================================================================== +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -18,26 +18,27 @@ + # along with GRUB. If not, see <http://www.gnu.org/licenses/>. + + transform="@program_transform_name@" +- +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-sbindir=@sbindir@ +-bindir=@bindir@ +-libdir=@libdir@ +-sysconfdir=@sysconfdir@ ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++ ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++sbindir="@sbindir@" ++bindir="@bindir@" ++sysconfdir="@sysconfdir@" + PACKAGE_NAME=@PACKAGE_NAME@ + PACKAGE_VERSION=@PACKAGE_VERSION@ + host_os=@host_os@ +-datarootdir=@datarootdir@ +-datadir=@datadir@ +-pkgdatadir=${datadir}/`echo @PACKAGE_TARNAME@ | sed "${transform}"` ++datadir="@datadir@" ++pkgdatadir="${datadir}/`echo @PACKAGE_TARNAME@ | sed "${transform}"`" + grub_cfg="" +-grub_mkconfig_dir=${sysconfdir}/grub.d ++grub_mkconfig_dir="${sysconfdir}"/grub.d + + self=`basename $0` + +-grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed "${transform}"` +-grub_probe=${sbindir}/`echo grub-probe | sed "${transform}"` ++grub_mkdevicemap="${sbindir}/`echo grub-mkdevicemap | sed "${transform}"`" ++grub_probe="${sbindir}/`echo grub-probe | sed "${transform}"`" + grub_script_check="${bindir}/`echo grub-script-check | sed "${transform}"`" + + GRUB_PREFIX=`echo '/@bootdirname@/@grubdirname@' | sed "s,//*,/,g"` +@@ -95,7 +96,7 @@ + esac + done + +-. ${libdir}/grub/grub-mkconfig_lib ++. "${datadir}/grub/grub-mkconfig_lib" + + if [ "x$EUID" = "x" ] ; then + EUID=`id -u` +Index: b/util/grub-mknetdir.in +=================================================================== +--- a/util/grub-mknetdir.in ++++ b/util/grub-mknetdir.in +@@ -19,25 +19,23 @@ + # Initialize some variables. + transform="@program_transform_name@" + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-sbindir=@sbindir@ +-bindir=@bindir@ +-libdir=@libdir@ ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++bindir="@bindir@" ++libdir="@libdir@" + PACKAGE_NAME=@PACKAGE_NAME@ + PACKAGE_TARNAME=@PACKAGE_TARNAME@ + PACKAGE_VERSION=@PACKAGE_VERSION@ + target_cpu=@target_cpu@ + platform=@platform@ + host_os=@host_os@ +-pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${transform}` +-localedir=@datadir@/locale + native_platform=@platform@ + pkglib_DATA="moddep.lst command.lst fs.lst partmap.lst parttool.lst handler.lst video.lst crypto.lst terminal.lst" + + self=`basename $0` + +-grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` ++grub_mkimage="${bindir}/`echo grub-mkimage | sed ${transform}`" + rootdir=/srv/tftp + grub_prefix=`echo /boot/grub | sed ${transform}` + modules= +@@ -48,7 +46,7 @@ + debug=no + debug_image= + subdir=`echo /boot/grub | sed ${transform}` +-pc_dir=${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-pc ++pc_dir="${libdir}/$(echo ${PACKAGE_TARNAME} | sed ${transform})/i386-pc" + + # Usage: usage + # Print the usage. +@@ -170,12 +168,12 @@ + config_opt= + mkdir -p "$grubdir" || exit 1 + +- for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img ${grubdir}/efiemu??.o; do +- if test -f $file && [ "`basename $file`" != menu.lst ]; then +- rm -f $file || exit 1 ++ for file in "${grubdir}"/*.mod "${grubdir}"/*.lst "${grubdir}"/*.img "${grubdir}"/efiemu??.o; do ++ if test -f "$file" && [ "`basename $file`" != menu.lst ]; then ++ rm -f "$file" || exit 1 + fi + done +- for file in ${input_dir}/*.mod; do ++ for file in "${input_dir}"/*.mod; do + if test -f "$file"; then + cp -f "$file" "$grubdir/" + fi +@@ -213,7 +211,7 @@ + source ${subdir}/grub.cfg + EOF + +- $grub_mkimage ${config_opt} -d "${input_dir}" -O ${mkimage_target} --output=${grubdir}/core.$ext --prefix=$prefix $modules $netmodules || exit 1 ++ "$grub_mkimage" ${config_opt} -d "${input_dir}" -O ${mkimage_target} "--output=${grubdir}/core.$ext" "--prefix=$prefix" $modules $netmodules || exit 1 + echo "Netboot directory for ${platform} created. Configure your DHCP server to point to ${subdir}/${platform}/core.$ext" + } + +Index: b/util/grub-mkrescue.in +=================================================================== +--- a/util/grub-mkrescue.in ++++ b/util/grub-mkrescue.in +@@ -18,12 +18,14 @@ + # along with GRUB. If not, see <http://www.gnu.org/licenses/>. + + # Initialize some variables. ++ + transform="@program_transform_name@" + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-bindir=@bindir@ +-libdir=@libdir@ ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++bindir="@bindir@" ++libdir="@libdir@" + PACKAGE_NAME=@PACKAGE_NAME@ + PACKAGE_TARNAME=@PACKAGE_TARNAME@ + PACKAGE_VERSION=@PACKAGE_VERSION@ +Index: b/util/grub.d/00_header.in +=================================================================== +--- a/util/grub.d/00_header.in ++++ b/util/grub.d/00_header.in +@@ -19,13 +19,13 @@ + + transform="@program_transform_name@" + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-libdir=@libdir@ ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" + locale_dir=`echo ${GRUB_PREFIX}/locale | sed ${transform}` + grub_lang=`echo $LANG | cut -d . -f 1` + +-. ${libdir}/grub/grub-mkconfig_lib ++. "@datadir@/grub/grub-mkconfig_lib" + + # Do this as early as possible, since other commands might depend on it. + # (e.g. the `loadfont' command might need lvm or raid modules) +@@ -112,7 +112,7 @@ + done + + if [ "x$serial" = x1 ]; then +- if ! test -e ${GRUB_PREFIX}/serial.mod ; then ++ if ! test -e "${GRUB_PREFIX}/serial.mod" ; then + echo "Serial terminal not available on this platform." >&2 ; exit 1 + fi + +Index: b/util/grub.d/10_hurd.in +=================================================================== +--- a/util/grub.d/10_hurd.in ++++ b/util/grub.d/10_hurd.in +@@ -17,10 +17,10 @@ + # You should have received a copy of the GNU General Public License + # along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-libdir=@libdir@ +-. ${libdir}/grub/grub-mkconfig_lib ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++. "@datadir@/grub/grub-mkconfig_lib" + + CLASS="--class gnu --class os" + +Index: b/util/grub.d/10_kfreebsd.in +=================================================================== +--- a/util/grub.d/10_kfreebsd.in ++++ b/util/grub.d/10_kfreebsd.in +@@ -17,14 +17,13 @@ + # You should have received a copy of the GNU General Public License + # along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-bindir=@bindir@ +-libdir=@libdir@ +-. ${libdir}/grub/grub-mkconfig_lib ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++. "@datadir@/grub/grub-mkconfig_lib" + + export TEXTDOMAIN=@PACKAGE@ +-export TEXTDOMAINDIR=@localedir@ ++export TEXTDOMAINDIR="@localedir@" + + CLASS="--class os" + +Index: b/util/grub.d/10_linux.in +=================================================================== +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -17,14 +17,14 @@ + # You should have received a copy of the GNU General Public License + # along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-bindir=@bindir@ +-libdir=@libdir@ +-. ${libdir}/grub/grub-mkconfig_lib ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++ ++. "@datadir@/grub/grub-mkconfig_lib" + + export TEXTDOMAIN=@PACKAGE@ +-export TEXTDOMAINDIR=@localedir@ ++export TEXTDOMAINDIR="@localedir@" + + CLASS="--class gnu-linux --class gnu --class os" + +Index: b/util/grub.d/10_netbsd.in +=================================================================== +--- a/util/grub.d/10_netbsd.in ++++ b/util/grub.d/10_netbsd.in +@@ -17,14 +17,13 @@ + # You should have received a copy of the GNU General Public License + # along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-bindir=@bindir@ +-libdir=@libdir@ +-. ${libdir}/grub/grub-mkconfig_lib ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++. "@datadir@/grub/grub-mkconfig_lib" + + export TEXTDOMAIN=@PACKAGE@ +-export TEXTDOMAINDIR=@localedir@ ++export TEXTDOMAINDIR="@localedir@" + + if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then + OS="NetBSD" +Index: b/util/grub.d/10_windows.in +=================================================================== +--- a/util/grub.d/10_windows.in ++++ b/util/grub.d/10_windows.in +@@ -17,10 +17,11 @@ + # You should have received a copy of the GNU General Public License + # along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-libdir=@libdir@ +-. ${libdir}/grub/grub-mkconfig_lib ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++ ++. "@datadir@/grub/grub-mkconfig_lib" + + case "`uname 2>/dev/null`" in + CYGWIN*) ;; +Index: b/util/grub.d/20_linux_xen.in +=================================================================== +--- a/util/grub.d/20_linux_xen.in ++++ b/util/grub.d/20_linux_xen.in +@@ -17,14 +17,14 @@ + # You should have received a copy of the GNU General Public License + # along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-bindir=@bindir@ +-libdir=@libdir@ +-. ${libdir}/grub/grub-mkconfig_lib ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" ++ ++. "@datadir@/grub/grub-mkconfig_lib" + + export TEXTDOMAIN=@PACKAGE@ +-export TEXTDOMAINDIR=@localedir@ ++export TEXTDOMAINDIR="@localedir@" + + CLASS="--class gnu-linux --class gnu --class os --class xen" + +Index: b/util/grub.d/30_os-prober.in +=================================================================== +--- a/util/grub.d/30_os-prober.in ++++ b/util/grub.d/30_os-prober.in +@@ -17,11 +17,11 @@ + # You should have received a copy of the GNU General Public License + # along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-libdir=@libdir@ ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" + +-. ${libdir}/grub/grub-mkconfig_lib ++. "@datadir@/grub/grub-mkconfig_lib" + + if [ "x${GRUB_DISABLE_OS_PROBER}" = "xtrue" ]; then + exit 0 +Index: b/util/update-grub_lib.in +=================================================================== +--- a/util/update-grub_lib.in ++++ b/util/update-grub_lib.in +@@ -14,10 +14,10 @@ + # You should have received a copy of the GNU General Public License + # along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +-prefix=@prefix@ +-exec_prefix=@exec_prefix@ +-libdir=@libdir@ ++prefix="@prefix@" ++exec_prefix="@exec_prefix@" ++datarootdir="@datarootdir@" + +-. ${libdir}/grub/grub-mkconfig_lib ++. "@datadir@/grub/grub-mkconfig_lib" + + grub_warn "update-grub_lib is deprecated, use grub-mkconfig_lib instead" diff --git a/master/debian/hurd.patch b/master/debian/hurd.patch new file mode 100644 index 0000000..cb04f13 --- /dev/null +++ b/master/debian/hurd.patch @@ -0,0 +1,37 @@ +Description: Fix hurd build by disabling zfs code. +Author: Samuel Thibault <samuel.thibault@ens-lyon.org> +Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/4237 +Forwarded: not-needed +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/4237 +Last-Update: 2012-06-08 + +--- a/grub-core/kern/emu/getroot.c 2012-04-21 14:49:56 +0000 ++++ b/grub-core/kern/emu/getroot.c 2012-04-22 19:02:55 +0000 +@@ -241,6 +241,8 @@ + + #endif /* __linux__ */ + ++#if !defined (__GNU__) ++ + static char * + find_device_from_pool (const char *poolname) + { +@@ -322,6 +323,8 @@ + return device; + } + ++#endif ++ + #ifdef __MINGW32__ + + char * +@@ -331,6 +331,8 @@ + return 0; + } + ++#elif defined (__GNU__) ++ + #elif ! defined(__CYGWIN__) + + char * + diff --git a/master/debian/install_stage2_confusion.patch b/master/debian/install_stage2_confusion.patch new file mode 100644 index 0000000..ff840ef --- /dev/null +++ b/master/debian/install_stage2_confusion.patch @@ -0,0 +1,24 @@ +Description: If GRUB Legacy is still around, tell packaging to ignore it +Author: Colin Watson <cjwatson@debian.org> +Bug-Debian: http://bugs.debian.org/586143 +Forwarded: not-needed +Last-Update: 2010-06-18 + +Index: b/util/grub-install.in +=================================================================== +--- a/util/grub-install.in ++++ b/util/grub-install.in +@@ -660,6 +660,13 @@ + fi + fi + ++# If vestiges of GRUB Legacy still exist, tell the Debian packaging that ++# they can ignore them. ++if test -z "$rootdir" && \ ++ test -e /boot/grub/stage2 && test -e /boot/grub/menu.lst; then ++ touch /boot/grub/grub2-installed ++fi ++ + echo "Installation finished. No error reported." + + # Bye. diff --git a/master/debian/kfreebsd-9_ada_devices.patch b/master/debian/kfreebsd-9_ada_devices.patch new file mode 100644 index 0000000..e1c22e4 --- /dev/null +++ b/master/debian/kfreebsd-9_ada_devices.patch @@ -0,0 +1,71 @@ +2011-06-16 Robert Millan <rmh@gnu.org> + + Detect `ataraid' devices on GNU/kFreeBSD. Fix for ATA devices using + `ata' driver on kernel of FreeBSD 9. + + * util/deviceiter.c [__FreeBSD_kernel__] (get_ada_disk_name) + (get_ataraid_disk_name): New functions. + [__FreeBSD_kernel__] (grub_util_iterate_devices): Scan for ataraid + (/dev/ar[0-9]+) and ada (/dev/ada[0-9]+) devices using + get_ataraid_disk_name() and get_ada_disk_name(). + +=== modified file 'util/deviceiter.c' +--- a/util/deviceiter.c ++++ b/util/deviceiter.c +@@ -286,6 +286,20 @@ + #endif + } + ++#ifdef __FreeBSD_kernel__ ++static void ++get_ada_disk_name (char *name, int unit) ++{ ++ sprintf (name, "/dev/ada%d", unit); ++} ++ ++static void ++get_ataraid_disk_name (char *name, int unit) ++{ ++ sprintf (name, "/dev/ar%d", unit); ++} ++#endif ++ + #ifdef __linux__ + static void + get_virtio_disk_name (char *name, int unit) +@@ -620,6 +634,35 @@ + } + } + ++#ifdef __FreeBSD_kernel__ ++ /* IDE disks using ATA Direct Access driver. */ ++ if (get_kfreebsd_version () >= 800000) ++ for (i = 0; i < 96; i++) ++ { ++ char name[16]; ++ ++ get_ada_disk_name (name, i); ++ if (check_device_readable_unique (name)) ++ { ++ if (hook (name, 0)) ++ goto out; ++ } ++ } ++ ++ /* ATARAID disks. */ ++ for (i = 0; i < 8; i++) ++ { ++ char name[20]; ++ ++ get_ataraid_disk_name (name, i); ++ if (check_device_readable_unique (name)) ++ { ++ if (hook (name, 0)) ++ goto out; ++ } ++ } ++#endif ++ + #ifdef __linux__ + /* Virtio disks. */ + for (i = 0; i < 26; i++) diff --git a/master/debian/kfreebsd_lvm.patch b/master/debian/kfreebsd_lvm.patch new file mode 100644 index 0000000..8583cc9 --- /dev/null +++ b/master/debian/kfreebsd_lvm.patch @@ -0,0 +1,187 @@ +2011-10-09 Robert Millan <rmh@gnu.org> + + LVM support for FreeBSD and GNU/kFreeBSD. + + * util/lvm.c (grub_util_lvm_isvolume): Enable on FreeBSD and + GNU/kFreeBSD. + (LVM_DEV_MAPPER_STRING): Move from here ... + * include/grub/util/lvm.h (LVM_DEV_MAPPER_STRING): ... to here. + * util/getroot.c: Include `<grub/util/lvm.h>'. + (grub_util_get_dev_abstraction): Enable + grub_util_biosdisk_is_present() on FreeBSD and GNU/kFreeBSD. + Check for LVM abstraction on FreeBSD and GNU/kFreeBSD. + (grub_util_get_grub_dev): Replace "/dev/mapper/" with + `LVM_DEV_MAPPER_STRING'. Enable LVM and mdRAID only on platforms that + support it. + * util/grub-setup.c (main): Check for LVM also on FreeBSD and + GNU/kFreeBSD. + * util/grub.d/10_kfreebsd.in: Load `geom_linux_lvm' kernel module + when LVM abstraction is required for ${GRUB_DEVICE}. + +--- a/grub-core/kern/emu/getroot.c ++++ b/grub-core/kern/emu/getroot.c +@@ -33,6 +33,7 @@ + #include <stdlib.h> + #include <stdint.h> + #include <grub/util/misc.h> ++#include <grub/util/lvm.h> + + #ifdef HAVE_DEVICE_MAPPER + # include <libdevmapper.h> +@@ -709,11 +710,13 @@ + int + grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused))) + { +-#ifdef __linux__ ++#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + /* User explicitly claims that this drive is visible by BIOS. */ + if (grub_util_biosdisk_is_present (os_dev)) + return GRUB_DEV_ABSTRACTION_NONE; ++#endif + ++#if defined(__linux__) + /* Check for LVM. */ + if (grub_util_is_lvm (os_dev)) + return GRUB_DEV_ABSTRACTION_LVM; +@@ -723,6 +726,12 @@ + return GRUB_DEV_ABSTRACTION_RAID; + #endif + ++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) ++ /* Check for LVM. */ ++ if (!strncmp (os_dev, LVM_DEV_MAPPER_STRING, sizeof(LVM_DEV_MAPPER_STRING)-1)) ++ return GRUB_DEV_ABSTRACTION_LVM; ++#endif ++ + /* No abstraction found. */ + return GRUB_DEV_ABSTRACTION_NONE; + } +@@ -815,11 +824,12 @@ + + switch (grub_util_get_dev_abstraction (os_dev)) + { ++#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + case GRUB_DEV_ABSTRACTION_LVM: + + { + unsigned short i, len; +- grub_size_t offset = sizeof ("/dev/mapper/") - 1; ++ grub_size_t offset = sizeof (LVM_DEV_MAPPER_STRING) - 1; + + len = strlen (os_dev) - offset + 1; + grub_dev = xmalloc (len); +@@ -833,7 +843,9 @@ + } + + break; ++#endif + ++#ifdef __linux__ + case GRUB_DEV_ABSTRACTION_RAID: + + if (os_dev[7] == '_' && os_dev[8] == 'd') +@@ -909,7 +921,6 @@ + else + grub_util_error ("unknown kind of RAID device `%s'", os_dev); + +-#ifdef __linux__ + { + char *mdadm_name = get_mdadm_uuid (os_dev); + struct stat st; +@@ -934,9 +945,8 @@ + free (mdadm_name); + } + } +-#endif /* __linux__ */ +- + break; ++#endif /* __linux__ */ + + default: /* GRUB_DEV_ABSTRACTION_NONE */ + grub_dev = grub_util_biosdisk_get_grub_dev (os_dev); +--- a/include/grub/util/lvm.h ++++ b/include/grub/util/lvm.h +@@ -20,7 +20,14 @@ + #ifndef GRUB_LVM_UTIL_HEADER + #define GRUB_LVM_UTIL_HEADER 1 + ++#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) ++ + #ifdef __linux__ ++#define LVM_DEV_MAPPER_STRING "/dev/mapper/" ++#else ++#define LVM_DEV_MAPPER_STRING "/dev/linux_lvm/" ++#endif ++ + int grub_util_lvm_isvolume (char *name); + #endif + +--- a/util/grub-setup.c ++++ b/util/grub-setup.c +@@ -959,10 +959,12 @@ + arguments.dir ? : DEFAULT_DIRECTORY); + } + +-#ifdef __linux__ ++#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + if (grub_util_lvm_isvolume (root_dev)) + must_embed = 1; ++#endif + ++#ifdef __linux__ + if (root_dev[0] == 'm' && root_dev[1] == 'd' + && ((root_dev[2] >= '0' && root_dev[2] <= '9') || root_dev[2] == '/')) + { +--- a/util/grub.d/10_kfreebsd.in ++++ b/util/grub.d/10_kfreebsd.in +@@ -98,6 +98,23 @@ + + load_kfreebsd_module acpi true + ++ for abstraction in dummy $(grub-probe -t abstraction --device ${GRUB_DEVICE}) ; do ++ case $abstraction in ++ lvm) load_kfreebsd_module geom_linux_lvm false ;; ++ esac ++ done ++ ++ case "$(grub-probe -t abstraction --device ${GRUB_DEVICE})" in ++ lvm) ++ test -e "${module_dir}/geom_linux_lvm.ko" ++ ++ printf '%s\n' "${prepare_module_dir_cache}" ++ cat << EOF ++ kfreebsd_module_elf ${module_dir_rel}/geom_linux_lvm.ko ++EOF ++ ;; ++ esac ++ + case "${kfreebsd_fs}" in + zfs) + load_kfreebsd_module opensolaris false +--- a/util/lvm.c ++++ b/util/lvm.c +@@ -17,8 +17,7 @@ + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. + */ + +-/* We only support LVM on Linux. */ +-#ifdef __linux__ ++#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + #include <grub/emu/misc.h> + #include <grub/util/misc.h> + #include <grub/util/lvm.h> +@@ -26,8 +25,6 @@ + #include <string.h> + #include <sys/stat.h> + +-#define LVM_DEV_MAPPER_STRING "/dev/mapper/" +- + int + grub_util_lvm_isvolume (char *name) + { +@@ -49,4 +46,4 @@ + return 1; + } + +-#endif /* ! __linux__ */ ++#endif diff --git a/master/debian/kfreebsd_mfi_devices.patch b/master/debian/kfreebsd_mfi_devices.patch new file mode 100644 index 0000000..6b0992e --- /dev/null +++ b/master/debian/kfreebsd_mfi_devices.patch @@ -0,0 +1,35 @@ +--- a/util/deviceiter.c ++++ b/util/deviceiter.c +@@ -298,6 +298,12 @@ + { + sprintf (name, "/dev/ar%d", unit); + } ++ ++static void ++get_mfi_disk_name (char *name, int unit) ++{ ++ sprintf (name, "/dev/mfid%d", unit); ++} + #endif + + #ifdef __linux__ +@@ -658,6 +664,19 @@ + if (check_device_readable_unique (name)) + { + if (hook (name, 0)) ++ goto out; ++ } ++ } ++ ++ /* LSI MegaRAID SAS. */ ++ for (i = 0; i < 32; i++) ++ { ++ char name[20]; ++ ++ get_mfi_disk_name (name, i); ++ if (check_device_readable_unique (name)) ++ { ++ if (hook (name, 0)) + goto out; + } + } diff --git a/master/debian/lazy_stat.patch b/master/debian/lazy_stat.patch new file mode 100644 index 0000000..b2cdfd2 --- /dev/null +++ b/master/debian/lazy_stat.patch @@ -0,0 +1,73 @@ +Description: Don't stat devices unless we have to +Author: Vladimir Serbinenko <phcoder@gmail.com> +Author: Colin Watson <cjwatson@ubuntu.com> +Bug-Debian: http://bugs.debian.org/627587 +Forwarded: yes +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3318 +Last-Update: 2011-05-31 + +Index: b/grub-core/kern/emu/getroot.c +=================================================================== +--- a/grub-core/kern/emu/getroot.c ++++ b/grub-core/kern/emu/getroot.c +@@ -358,7 +358,7 @@ + + if (S_ISLNK (st.st_mode)) { + #ifdef __linux__ +- if (strcmp (dir, "mapper") == 0) { ++ if (strcmp (dir, "mapper") == 0 || strcmp (dir, "/dev/mapper") == 0) { + /* Follow symbolic links under /dev/mapper/; the canonical name + may be something like /dev/dm-0, but the names under + /dev/mapper/ are more human-readable and so we prefer them if +@@ -609,20 +609,27 @@ + + if (os_dev) + { +- if (stat (os_dev, &st) >= 0) +- dev = st.st_rdev; +- else +- grub_util_error ("cannot stat `%s'", os_dev); +- free (os_dev); ++ char *tmp = os_dev; ++ os_dev = canonicalize_file_name (os_dev); ++ free (tmp); + } +- else ++ ++ if (os_dev) + { +- if (stat (dir, &st) >= 0) +- dev = st.st_dev; +- else +- grub_util_error ("cannot stat `%s'", dir); ++ if (strncmp (os_dev, "/dev/dm-", sizeof ("/dev/dm-") - 1) != 0) ++ return os_dev; ++ if (stat (os_dev, &st) < 0) ++ grub_util_error ("cannot stat `%s'", os_dev); ++ free (os_dev); ++ dev = st.st_rdev; ++ return grub_find_device ("/dev/mapper", dev); + } + ++ if (stat (dir, &st) < 0) ++ grub_util_error ("cannot stat `%s'", dir); ++ ++ dev = st.st_dev; ++ + #ifdef __CYGWIN__ + /* Cygwin specific function. */ + os_dev = grub_find_device (dir, dev); +Index: b/grub-core/kern/emu/hostdisk.c +=================================================================== +--- a/grub-core/kern/emu/hostdisk.c ++++ b/grub-core/kern/emu/hostdisk.c +@@ -1420,7 +1420,8 @@ + if (tree) + dm_tree_free (tree); + free (path); +- char *ret = grub_find_device (NULL, (major << 8) | minor); ++ char *ret = grub_find_device ("/dev/mapper", ++ (major << 8) | minor); + return ret; + } + diff --git a/master/debian/lzo.patch b/master/debian/lzo.patch new file mode 100644 index 0000000..08be339 --- /dev/null +++ b/master/debian/lzo.patch @@ -0,0 +1,8643 @@ +Description: Add support for LZO compression in btrfs +Author: Szymon Janc <szymon@janc.net.pl> +Author: Vladimir Serbinenko <phcoder@gmail.com> +Origin: backport, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3436 +Origin: backport, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3446 +Origin: backport, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3459 +Origin: backport, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3551 +Origin: backport, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3804 +Bug-Ubuntu: https://bugs.launchpad.net/bugs/727535 +Forwarded: not-needed +Last-Update: 2012-03-12 + +Index: b/Makefile.util.def +=================================================================== +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -24,8 +24,8 @@ + + library = { + name = libgrubmods.a; +- cflags = '$(CFLAGS_GCRY)'; +- cppflags = '$(CPPFLAGS_GCRY)'; ++ cflags = '$(CFLAGS_GCRY) $(CFLAGS_POSIX) -Wno-undef'; ++ cppflags = '$(CPPFLAGS_GCRY) -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.yy.c; +@@ -85,6 +85,7 @@ + common = grub-core/lib/LzmaEnc.c; + common = grub-core/lib/pbkdf2.c; + common = grub-core/lib/crc.c; ++ common = grub-core/lib/adler32.c; + common = grub-core/normal/datetime.c; + common = grub-core/normal/misc.c; + common = grub-core/partmap/acorn.c; +@@ -101,6 +102,8 @@ + common = grub-core/script/script.c; + common = grub-core/script/argv.c; + common = grub-core/io/gzio.c; ++ common = grub-core/io/lzopio.c; ++ common = grub-core/lib/minilzo/minilzo.c; + }; + + program = { +Index: b/configure.ac +=================================================================== +--- a/configure.ac ++++ b/configure.ac +@@ -483,6 +483,7 @@ + # Force 32-bit mode. + TARGET_CFLAGS="$TARGET_CFLAGS -m32" + TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32" ++ TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32" + TARGET_LDFLAGS="$TARGET_LDFLAGS -m32" + TARGET_MODULE_FORMAT="elf32" + fi +@@ -491,6 +492,7 @@ + # Force 64-bit mode. + TARGET_CFLAGS="$TARGET_CFLAGS -m64" + TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m64" ++ TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m64" + TARGET_LDFLAGS="$TARGET_LDFLAGS -m64" + TARGET_MODULE_FORMAT="elf64" + fi +@@ -607,7 +609,7 @@ + fi + + # Check for libgcc symbols +-AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x) ++AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __trampoline_setup __ucmpdi2 _restgpr_14_x __ctzdi2 __ctzsi2) + + if test "x$TARGET_APPLE_CC" = x1 ; then + CFLAGS="$TARGET_CFLAGS -nostdlib" +Index: b/grub-core/Makefile.core.def +=================================================================== +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -908,6 +908,8 @@ + name = btrfs; + common = fs/btrfs.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 = { +@@ -1509,6 +1511,14 @@ + }; + + 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 = { + name = testload; + common = commands/testload.c; + }; +@@ -1524,3 +1534,8 @@ + common = commands/keylayouts.c; + enable = videomodules; + }; ++ ++module = { ++ name = adler32; ++ common = lib/adler32.c; ++}; +Index: b/grub-core/fs/btrfs.c +=================================================================== +--- a/grub-core/fs/btrfs.c ++++ b/grub-core/fs/btrfs.c +@@ -26,11 +26,23 @@ + #include <grub/types.h> + #include <grub/lib/crc.h> + #include <grub/deflate.h> ++#include <minilzo.h> + + GRUB_MOD_LICENSE ("GPLv3+"); + + #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_uint16_t grub_btrfs_uuid_t[8]; + +@@ -41,7 +53,7 @@ + } __attribute__ ((packed)); + + struct grub_btrfs_superblock +-{ ++{ + grub_btrfs_checksum_t checksum; + grub_btrfs_uuid_t uuid; + grub_uint8_t dummy[0x10]; +@@ -160,7 +172,8 @@ + { + unsigned depth; + unsigned allocated; +- struct { ++ struct ++ { + grub_disk_addr_t addr; + unsigned iter; + unsigned maxiter; +@@ -179,7 +192,7 @@ + { + grub_int64_t sec; + grub_uint32_t nanosec; +-} __attribute__ ((aligned(4))); ++} __attribute__ ((aligned (4))); + + struct grub_btrfs_inode + { +@@ -215,12 +228,13 @@ + + #define GRUB_BTRFS_COMPRESSION_NONE 0 + #define GRUB_BTRFS_COMPRESSION_ZLIB 1 ++#define GRUB_BTRFS_COMPRESSION_LZO 2 + + #define GRUB_BTRFS_OBJECT_ID_CHUNK 0x100 + + static grub_disk_addr_t superblock_sectors[] = { 64 * 2, 64 * 1024 * 2, +- 256 * 1048576 * 2, +- 1048576ULL * 1048576ULL * 2 }; ++ 256 * 1048576 * 2, 1048576ULL * 1048576ULL * 2 ++}; + + static grub_err_t + grub_btrfs_read_logical (struct grub_btrfs_data *data, +@@ -283,7 +297,7 @@ + } + + static grub_err_t +-save_ref (struct grub_btrfs_leaf_descriptor *desc, ++save_ref (struct grub_btrfs_leaf_descriptor *desc, + grub_disk_addr_t addr, unsigned i, unsigned m, int l) + { + desc->depth++; +@@ -307,7 +321,7 @@ + static int + next (struct grub_btrfs_data *data, + 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) + { + grub_err_t err; +@@ -330,17 +344,17 @@ + err = grub_btrfs_read_logical (data, desc->data[desc->depth - 1].iter + * sizeof (node) + + sizeof (struct btrfs_header) +- + desc->data[desc->depth - 1].addr, &node, +- sizeof (node)); ++ + desc->data[desc->depth - 1].addr, ++ &node, sizeof (node)); + if (err) + return -err; + +- err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (node.addr), &head, +- sizeof (head)); ++ err = grub_btrfs_read_logical (data, grub_le_to_cpu64 (node.addr), ++ &head, sizeof (head)); + if (err) + return -err; + +- save_ref (desc, grub_le_to_cpu64 (node.addr), 0, ++ save_ref (desc, grub_le_to_cpu64 (node.addr), 0, + grub_le_to_cpu32 (head.nitems), !head.level); + } + err = grub_btrfs_read_logical (data, desc->data[desc->depth - 1].iter +@@ -354,12 +368,12 @@ + *outaddr = desc->data[desc->depth - 1].addr + sizeof (struct btrfs_header) + + grub_le_to_cpu32 (leaf.offset); + *key_out = leaf.key; +- return 1; ++ return 1; + } + + static grub_err_t + lower_bound (struct grub_btrfs_data *data, +- const struct grub_btrfs_key *key_in, ++ const struct grub_btrfs_key *key_in, + struct grub_btrfs_key *key_out, + grub_disk_addr_t root, + grub_disk_addr_t *outaddr, grub_size_t *outsize, +@@ -410,8 +424,9 @@ + grub_dprintf ("btrfs", + "internal node (depth %d) %" PRIxGRUB_UINT64_T + " %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) + { + err = GRUB_ERR_NONE; +@@ -433,7 +448,7 @@ + err = GRUB_ERR_NONE; + if (desc) + 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) + return err; + addr = grub_le_to_cpu64 (node_last.addr); +@@ -457,7 +472,7 @@ + &leaf, sizeof (leaf)); + if (err) + return err; +- ++ + grub_dprintf ("btrfs", + "leaf (depth %d) %" PRIxGRUB_UINT64_T + " %x %" PRIxGRUB_UINT64_T "\n", depth, +@@ -465,31 +480,31 @@ + + 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); + *outaddr = addr + grub_le_to_cpu32 (leaf.offset); + if (desc) + return save_ref (desc, addr - sizeof (head), i, + grub_le_to_cpu32 (head.nitems), 1); +- return GRUB_ERR_NONE; ++ return GRUB_ERR_NONE; + } +- ++ + if (key_cmp (&leaf.key, key_in) > 0) + break; +- ++ + have_last = 1; + leaf_last = leaf; + } + + 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); + *outaddr = addr + grub_le_to_cpu32 (leaf_last.offset); + if (desc) + return save_ref (desc, addr - sizeof (head), i - 1, + grub_le_to_cpu32 (head.nitems), 1); +- return GRUB_ERR_NONE; ++ return GRUB_ERR_NONE; + } + *outsize = 0; + *outaddr = 0; +@@ -503,8 +518,7 @@ + } + + static grub_device_t +-find_device (struct grub_btrfs_data *data, grub_uint64_t id, +- int do_rescan) ++find_device (struct grub_btrfs_data *data, grub_uint64_t id, int do_rescan) + { + grub_device_t dev_found = NULL; + auto int hook (const char *name); +@@ -540,7 +554,7 @@ + grub_device_close (dev); + return 0; + } +- ++ + dev_found = dev; + return 1; + } +@@ -579,17 +593,16 @@ + } + + static grub_err_t +-grub_btrfs_read_logical (struct grub_btrfs_data *data, +- grub_disk_addr_t addr, ++grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, + void *buf, grub_size_t size) + { + while (size > 0) + { + grub_uint8_t *ptr; + struct grub_btrfs_key *key; +- struct grub_btrfs_chunk_item *chunk; ++ struct grub_btrfs_chunk_item *chunk; + grub_uint64_t csize; +- grub_err_t err; ++ grub_err_t err = 0; + struct grub_btrfs_key key_out; + int challoc = 0; + grub_device_t dev; +@@ -597,15 +610,15 @@ + addr); + for (ptr = data->sblock.bootstrap_mapping; + ptr < data->sblock.bootstrap_mapping +- + sizeof (data->sblock.bootstrap_mapping) +- - sizeof (struct grub_btrfs_key); +- ) ++ + sizeof (data->sblock.bootstrap_mapping) ++ - sizeof (struct grub_btrfs_key);) + { + key = (struct grub_btrfs_key *) ptr; + if (key->type != GRUB_BTRFS_ITEM_TYPE_CHUNK) + break; + 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 (chunk->size)); + if (grub_le_to_cpu64 (key->offset) <= addr +@@ -702,11 +715,11 @@ + middle = grub_divmod64 (off, + grub_le_to_cpu64 (chunk->stripe_length), + &low); +- ++ + high = grub_divmod64 (middle, grub_le_to_cpu16 (chunk->nstripes), + &stripen); +- stripe_offset = low + grub_le_to_cpu64 (chunk->stripe_length) +- * high; ++ stripe_offset = ++ low + grub_le_to_cpu64 (chunk->stripe_length) * high; + csize = grub_le_to_cpu64 (chunk->stripe_length) - low; + break; + } +@@ -717,7 +730,7 @@ + middle = grub_divmod64 (off, + grub_le_to_cpu64 (chunk->stripe_length), + &low); +- ++ + high = grub_divmod64 (middle, + grub_le_to_cpu16 (chunk->nsubstripes), + &stripen); +@@ -757,7 +770,8 @@ + paddr = stripe->offset + stripe_offset; + + 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_UINT32_T + " maps to 0x%" PRIxGRUB_UINT64_T "\n", + grub_le_to_cpu64 (key->offset), +@@ -767,7 +781,7 @@ + grub_le_to_cpu64 (chunk->stripe_length), + stripen, stripe->offset); + 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); + + dev = find_device (data, stripe->device_id, j); +@@ -813,7 +827,7 @@ + } + + data = grub_zalloc (sizeof (*data)); +- if (! data) ++ if (!data) + return NULL; + + err = read_sblock (dev->disk, &data->sblock); +@@ -864,8 +878,7 @@ + key_in.type = GRUB_BTRFS_ITEM_TYPE_INODE_ITEM; + key_in.offset = 0; + +- err = lower_bound (data, &key_in, &key_out, tree, +- &elemaddr, &elemsize, NULL); ++ err = lower_bound (data, &key_in, &key_out, tree, &elemaddr, &elemsize, NULL); + if (err) + return err; + if (num != key_out.object_id +@@ -876,6 +889,76 @@ + } + + 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 + grub_btrfs_extent_read (struct grub_btrfs_data *data, + grub_uint64_t ino, grub_uint64_t tree, + grub_off_t pos0, char *buf, grub_size_t len) +@@ -915,19 +998,17 @@ + if (!data->extent) + return grub_errno; + +- err = grub_btrfs_read_logical (data, elemaddr, +- data->extent, elemsize); ++ err = grub_btrfs_read_logical (data, elemaddr, data->extent, ++ elemsize); + if (err) + return err; + +- data->extend = data->extstart +- + grub_le_to_cpu64 (data->extent->size); ++ data->extend = data->extstart + grub_le_to_cpu64 (data->extent->size); + if (data->extent->type == GRUB_BTRFS_EXTENT_REGULAR + && (char *) &data->extent + elemsize +- >= (char *) &data->extent->filled +- + sizeof (data->extent->filled)) +- data->extend = data->extstart +- + grub_le_to_cpu64 (data->extent->filled); ++ >= (char *) &data->extent->filled + sizeof (data->extent->filled)) ++ data->extend = ++ data->extstart + grub_le_to_cpu64 (data->extent->filled); + + grub_dprintf ("btrfs", "extent 0x%" PRIxGRUB_UINT64_T "+0x%" + PRIxGRUB_UINT64_T " (0x%" +@@ -954,7 +1035,8 @@ + } + + 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, + "compression type 0x%x not supported", +@@ -964,8 +1046,7 @@ + + if (data->extent->encoding) + { +- grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, +- "encoding not supported"); ++ grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "encoding not supported"); + return -1; + } + +@@ -981,6 +1062,15 @@ + != (grub_ssize_t) csize) + 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 + grub_memcpy (buf, data->extent->inl + extoff, csize); + break; +@@ -990,10 +1080,13 @@ + grub_memset (buf, 0, csize); + break; + } +- if (data->extent->compression == GRUB_BTRFS_COMPRESSION_ZLIB) ++ ++ if (data->extent->compression != GRUB_BTRFS_COMPRESSION_NONE) + { + char *tmp; + grub_uint64_t zsize; ++ grub_ssize_t ret; ++ + zsize = grub_le_to_cpu64 (data->extent->compressed_size); + tmp = grub_malloc (zsize); + if (!tmp) +@@ -1006,27 +1099,35 @@ + grub_free (tmp); + return -1; + } +- if (grub_zlib_decompress (tmp, zsize, extoff +- + grub_le_to_cpu64 (data->extent->offset), +- buf, csize) != (grub_ssize_t) csize) +- { +- grub_free (tmp); +- return -1; +- } ++ ++ if (data->extent->compression == GRUB_BTRFS_COMPRESSION_ZLIB) ++ ret = grub_zlib_decompress (tmp, zsize, extoff ++ + grub_le_to_cpu64 (data->extent->offset), ++ buf, csize); ++ 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); ++ ++ if (ret != (grub_ssize_t) csize) ++ return -1; ++ + break; + } + err = grub_btrfs_read_logical (data, + grub_le_to_cpu64 (data->extent->laddr) + + grub_le_to_cpu64 (data->extent->offset) +- + extoff, +- buf, csize); ++ + extoff, buf, csize); + if (err) + return -1; + break; + default: + grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, +- "unsupported extent type 0x%x", data->extent->type); ++ "unsupported extent type 0x%x", data->extent->type); + return -1; + } + buf += csize; +@@ -1089,9 +1190,9 @@ + + key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM; + key->offset = grub_cpu_to_le64 (~grub_getcrc32c (1, ctoken, ctokenlen)); +- +- err = lower_bound (data, key, &key_out, *tree, +- &elemaddr, &elemsize, NULL); ++ ++ err = lower_bound (data, key, &key_out, *tree, &elemaddr, &elemsize, ++ NULL); + if (err) + { + grub_free (direl); +@@ -1128,7 +1229,7 @@ + + for (cdirel = direl; + (grub_uint8_t *) cdirel - (grub_uint8_t *) direl +- < (grub_ssize_t) elemsize; ++ < (grub_ssize_t) elemsize; + cdirel = (void *) ((grub_uint8_t *) (direl + 1) + + grub_le_to_cpu16 (cdirel->n) + + grub_le_to_cpu16 (cdirel->m))) +@@ -1159,7 +1260,7 @@ + return grub_error (GRUB_ERR_SYMLINK_LOOP, + "too deep nesting of symlinks"); + } +- ++ + err = grub_btrfs_read_inode (data, &inode, + cdirel->key.object_id, *tree); + if (err) +@@ -1187,7 +1288,7 @@ + grub_free (tmp); + return grub_errno; + } +- grub_memcpy (tmp + grub_le_to_cpu64 (inode.size), path, ++ grub_memcpy (tmp + grub_le_to_cpu64 (inode.size), path, + grub_strlen (path) + 1); + grub_free (path_alloc); + path = path_alloc = tmp; +@@ -1225,8 +1326,7 @@ + grub_free (path_alloc); + return grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + } +- err = grub_btrfs_read_logical (data, elemaddr, +- &ri, sizeof (ri)); ++ err = grub_btrfs_read_logical (data, elemaddr, &ri, sizeof (ri)); + if (err) + { + grub_free (direl); +@@ -1253,7 +1353,7 @@ + default: + grub_free (path_alloc); + grub_free (direl); +- return grub_error (GRUB_ERR_BAD_FS, "unrecognised object type 0x%x", ++ return grub_error (GRUB_ERR_BAD_FS, "unrecognised object type 0x%x", + cdirel->key.type); + } + } +@@ -1264,8 +1364,8 @@ + + static grub_err_t + grub_btrfs_dir (grub_device_t device, const char *path, +- int (*hook) (const char *filename, +- const struct grub_dirhook_info *info)) ++ int (*hook) (const char *filename, ++ const struct grub_dirhook_info *info)) + { + struct grub_btrfs_data *data = grub_btrfs_mount (device); + struct grub_btrfs_key key_in, key_out; +@@ -1286,10 +1386,9 @@ + if (err) + return err; + 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, +- &elemaddr, &elemsize, &desc); ++ err = lower_bound (data, &key_in, &key_out, tree, &elemaddr, &elemsize, &desc); + if (err) + return err; + if (key_out.type != GRUB_BTRFS_ITEM_TYPE_DIR_ITEM +@@ -1329,7 +1428,7 @@ + + for (cdirel = direl; + (grub_uint8_t *) cdirel - (grub_uint8_t *) direl +- < (grub_ssize_t) elemsize; ++ < (grub_ssize_t) elemsize; + cdirel = (void *) ((grub_uint8_t *) (direl + 1) + + grub_le_to_cpu16 (cdirel->n) + + grub_le_to_cpu16 (cdirel->m))) +@@ -1358,7 +1457,7 @@ + } + while (r > 0); + +- out: ++out: + grub_free (direl); + + free_iterator (&desc); +@@ -1430,7 +1529,7 @@ + *uuid = NULL; + + data = grub_btrfs_mount (device); +- if (! data) ++ if (!data) + return grub_errno; + + *uuid = grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", +@@ -1456,7 +1555,7 @@ + *label = NULL; + + data = grub_btrfs_mount (device); +- if (! data) ++ if (!data) + return grub_errno; + + *label = grub_strndup (data->sblock.label, sizeof (data->sblock.label)); +@@ -1466,26 +1565,25 @@ + return grub_errno; + } + +-static struct grub_fs grub_btrfs_fs = +- { +- .name = "btrfs", +- .dir = grub_btrfs_dir, +- .open = grub_btrfs_open, +- .read = grub_btrfs_read, +- .close = grub_btrfs_close, +- .uuid = grub_btrfs_uuid, +- .label = grub_btrfs_label, ++static struct grub_fs grub_btrfs_fs = { ++ .name = "btrfs", ++ .dir = grub_btrfs_dir, ++ .open = grub_btrfs_open, ++ .read = grub_btrfs_read, ++ .close = grub_btrfs_close, ++ .uuid = grub_btrfs_uuid, ++ .label = grub_btrfs_label, + #ifdef GRUB_UTIL +- .reserved_first_sector = 1, ++ .reserved_first_sector = 1, + #endif +- }; ++}; + +-GRUB_MOD_INIT(btrfs) ++GRUB_MOD_INIT (btrfs) + { + grub_fs_register (&grub_btrfs_fs); + } + +-GRUB_MOD_FINI(btrfs) ++GRUB_MOD_FINI (btrfs) + { + grub_fs_unregister (&grub_btrfs_fs); + } +Index: b/grub-core/io/lzopio.c +=================================================================== +--- /dev/null ++++ b/grub-core/io/lzopio.c +@@ -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->ucheck_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 (grub_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); ++} +Index: b/grub-core/lib/adler32.c +=================================================================== +--- /dev/null ++++ b/grub-core/lib/adler32.c +@@ -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); ++} +Index: b/grub-core/lib/minilzo/lzoconf.h +=================================================================== +--- /dev/null ++++ b/grub-core/lib/minilzo/lzoconf.h +@@ -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: */ +Index: b/grub-core/lib/minilzo/lzodefs.h +=================================================================== +--- /dev/null ++++ b/grub-core/lib/minilzo/lzodefs.h +@@ -0,0 +1,1852 @@ ++/* lzodefs.h -- architecture, OS and compiler specific defines ++ ++ 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 __LZODEFS_H_INCLUDED ++#define __LZODEFS_H_INCLUDED 1 ++ ++#if defined(__CYGWIN32__) && !defined(__CYGWIN__) ++# define __CYGWIN__ __CYGWIN32__ ++#endif ++#if defined(__IBMCPP__) && !defined(__IBMC__) ++# define __IBMC__ __IBMCPP__ ++#endif ++#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) ++# define __INTEL_COMPILER __ICL ++#endif ++#if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) ++# define _ALL_SOURCE 1 ++#endif ++#if defined(__mips__) && defined(__R5900__) ++# if !defined(__LONG_MAX__) ++# define __LONG_MAX__ 9223372036854775807L ++# endif ++#endif ++#if defined(__INTEL_COMPILER) && defined(__linux__) ++# pragma warning(disable: 193) ++#endif ++#if defined(__KEIL__) && defined(__C166__) ++# pragma warning disable = 322 ++#elif 0 && defined(__C251__) ++# pragma warning disable = 322 ++#endif ++#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) ++# if (_MSC_VER >= 1300) ++# pragma warning(disable: 4668) ++# endif ++#endif ++#if 0 && defined(__WATCOMC__) ++# if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) ++# pragma warning 203 9 ++# endif ++#endif ++#if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) ++# pragma option -h ++#endif ++#if 0 ++#define LZO_0xffffL 0xfffful ++#define LZO_0xffffffffL 0xfffffffful ++#else ++#define LZO_0xffffL 65535ul ++#define LZO_0xffffffffL 4294967295ul ++#endif ++#if (LZO_0xffffL == LZO_0xffffffffL) ++# error "your preprocessor is broken 1" ++#endif ++#if (16ul * 16384ul != 262144ul) ++# error "your preprocessor is broken 2" ++#endif ++#if 0 ++#if (32767 >= 4294967295ul) ++# error "your preprocessor is broken 3" ++#endif ++#if (65535u >= 4294967295ul) ++# error "your preprocessor is broken 4" ++#endif ++#endif ++#if (UINT_MAX == LZO_0xffffL) ++#if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) ++# if !defined(MSDOS) ++# define MSDOS 1 ++# endif ++# if !defined(_MSDOS) ++# define _MSDOS 1 ++# endif ++#elif 0 && defined(__VERSION) && defined(MB_LEN_MAX) ++# if (__VERSION == 520) && (MB_LEN_MAX == 1) ++# if !defined(__AZTEC_C__) ++# define __AZTEC_C__ __VERSION ++# endif ++# if !defined(__DOS__) ++# define __DOS__ 1 ++# endif ++# endif ++#endif ++#endif ++#if defined(_MSC_VER) && defined(M_I86HM) && (UINT_MAX == LZO_0xffffL) ++# define ptrdiff_t long ++# define _PTRDIFF_T_DEFINED 1 ++#endif ++#if (UINT_MAX == LZO_0xffffL) ++# undef __LZO_RENAME_A ++# undef __LZO_RENAME_B ++# if defined(__AZTEC_C__) && defined(__DOS__) ++# define __LZO_RENAME_A 1 ++# elif defined(_MSC_VER) && defined(MSDOS) ++# if (_MSC_VER < 600) ++# define __LZO_RENAME_A 1 ++# elif (_MSC_VER < 700) ++# define __LZO_RENAME_B 1 ++# endif ++# elif defined(__TSC__) && defined(__OS2__) ++# define __LZO_RENAME_A 1 ++# elif defined(__MSDOS__) && defined(__TURBOC__) && (__TURBOC__ < 0x0410) ++# define __LZO_RENAME_A 1 ++# elif defined(__PACIFIC__) && defined(DOS) ++# if !defined(__far) ++# define __far far ++# endif ++# if !defined(__near) ++# define __near near ++# endif ++# endif ++# if defined(__LZO_RENAME_A) ++# if !defined(__cdecl) ++# define __cdecl cdecl ++# endif ++# if !defined(__far) ++# define __far far ++# endif ++# if !defined(__huge) ++# define __huge huge ++# endif ++# if !defined(__near) ++# define __near near ++# endif ++# if !defined(__pascal) ++# define __pascal pascal ++# endif ++# if !defined(__huge) ++# define __huge huge ++# endif ++# elif defined(__LZO_RENAME_B) ++# if !defined(__cdecl) ++# define __cdecl _cdecl ++# endif ++# if !defined(__far) ++# define __far _far ++# endif ++# if !defined(__huge) ++# define __huge _huge ++# endif ++# if !defined(__near) ++# define __near _near ++# endif ++# if !defined(__pascal) ++# define __pascal _pascal ++# endif ++# elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__) ++# if !defined(__cdecl) ++# define __cdecl cdecl ++# endif ++# if !defined(__pascal) ++# define __pascal pascal ++# endif ++# endif ++# undef __LZO_RENAME_A ++# undef __LZO_RENAME_B ++#endif ++#if (UINT_MAX == LZO_0xffffL) ++#if defined(__AZTEC_C__) && defined(__DOS__) ++# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 ++#elif defined(_MSC_VER) && defined(MSDOS) ++# if (_MSC_VER < 600) ++# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 ++# endif ++# if (_MSC_VER < 700) ++# define LZO_BROKEN_INTEGRAL_PROMOTION 1 ++# define LZO_BROKEN_SIZEOF 1 ++# endif ++#elif defined(__PACIFIC__) && defined(DOS) ++# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 ++#elif defined(__TURBOC__) && defined(__MSDOS__) ++# if (__TURBOC__ < 0x0150) ++# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 ++# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 ++# define LZO_BROKEN_INTEGRAL_PROMOTION 1 ++# endif ++# if (__TURBOC__ < 0x0200) ++# define LZO_BROKEN_SIZEOF 1 ++# endif ++# if (__TURBOC__ < 0x0400) && defined(__cplusplus) ++# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 ++# endif ++#elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__) ++# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 ++# define LZO_BROKEN_SIZEOF 1 ++#endif ++#endif ++#if defined(__WATCOMC__) && (__WATCOMC__ < 900) ++# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 ++#endif ++#if defined(_CRAY) && defined(_CRAY1) ++# define LZO_BROKEN_SIGNED_RIGHT_SHIFT 1 ++#endif ++#define LZO_PP_STRINGIZE(x) #x ++#define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) ++#define LZO_PP_CONCAT2(a,b) a ## b ++#define LZO_PP_CONCAT3(a,b,c) a ## b ## c ++#define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d ++#define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e ++#define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) ++#define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) ++#define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) ++#define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) ++#if 1 ++#define LZO_CPP_STRINGIZE(x) #x ++#define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) ++#define LZO_CPP_CONCAT2(a,b) a ## b ++#define LZO_CPP_CONCAT3(a,b,c) a ## b ## c ++#define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d ++#define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e ++#define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) ++#define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) ++#define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) ++#define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) ++#endif ++#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) ++#if 1 && defined(__cplusplus) ++# if !defined(__STDC_CONSTANT_MACROS) ++# define __STDC_CONSTANT_MACROS 1 ++# endif ++# if !defined(__STDC_LIMIT_MACROS) ++# define __STDC_LIMIT_MACROS 1 ++# endif ++#endif ++#if defined(__cplusplus) ++# define LZO_EXTERN_C extern "C" ++#else ++# define LZO_EXTERN_C extern ++#endif ++#if !defined(__LZO_OS_OVERRIDE) ++#if (LZO_OS_FREESTANDING) ++# define LZO_INFO_OS "freestanding" ++#elif (LZO_OS_EMBEDDED) ++# define LZO_INFO_OS "embedded" ++#elif 1 && defined(__IAR_SYSTEMS_ICC__) ++# define LZO_OS_EMBEDDED 1 ++# define LZO_INFO_OS "embedded" ++#elif defined(__CYGWIN__) && defined(__GNUC__) ++# define LZO_OS_CYGWIN 1 ++# define LZO_INFO_OS "cygwin" ++#elif defined(__EMX__) && defined(__GNUC__) ++# define LZO_OS_EMX 1 ++# define LZO_INFO_OS "emx" ++#elif defined(__BEOS__) ++# define LZO_OS_BEOS 1 ++# define LZO_INFO_OS "beos" ++#elif defined(__Lynx__) ++# define LZO_OS_LYNXOS 1 ++# define LZO_INFO_OS "lynxos" ++#elif defined(__OS400__) ++# define LZO_OS_OS400 1 ++# define LZO_INFO_OS "os400" ++#elif defined(__QNX__) ++# define LZO_OS_QNX 1 ++# define LZO_INFO_OS "qnx" ++#elif defined(__BORLANDC__) && defined(__DPMI32__) && (__BORLANDC__ >= 0x0460) ++# define LZO_OS_DOS32 1 ++# define LZO_INFO_OS "dos32" ++#elif defined(__BORLANDC__) && defined(__DPMI16__) ++# define LZO_OS_DOS16 1 ++# define LZO_INFO_OS "dos16" ++#elif defined(__ZTC__) && defined(DOS386) ++# define LZO_OS_DOS32 1 ++# define LZO_INFO_OS "dos32" ++#elif defined(__OS2__) || defined(__OS2V2__) ++# if (UINT_MAX == LZO_0xffffL) ++# define LZO_OS_OS216 1 ++# define LZO_INFO_OS "os216" ++# elif (UINT_MAX == LZO_0xffffffffL) ++# define LZO_OS_OS2 1 ++# define LZO_INFO_OS "os2" ++# else ++# error "check your limits.h header" ++# endif ++#elif defined(__WIN64__) || defined(_WIN64) || defined(WIN64) ++# define LZO_OS_WIN64 1 ++# define LZO_INFO_OS "win64" ++#elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS_386__) ++# define LZO_OS_WIN32 1 ++# define LZO_INFO_OS "win32" ++#elif defined(__MWERKS__) && defined(__INTEL__) ++# define LZO_OS_WIN32 1 ++# define LZO_INFO_OS "win32" ++#elif defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows) ++# if (UINT_MAX == LZO_0xffffL) ++# define LZO_OS_WIN16 1 ++# define LZO_INFO_OS "win16" ++# elif (UINT_MAX == LZO_0xffffffffL) ++# define LZO_OS_WIN32 1 ++# define LZO_INFO_OS "win32" ++# else ++# error "check your limits.h header" ++# endif ++#elif defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) || (defined(__PACIFIC__) && defined(DOS)) ++# if (UINT_MAX == LZO_0xffffL) ++# define LZO_OS_DOS16 1 ++# define LZO_INFO_OS "dos16" ++# elif (UINT_MAX == LZO_0xffffffffL) ++# define LZO_OS_DOS32 1 ++# define LZO_INFO_OS "dos32" ++# else ++# error "check your limits.h header" ++# endif ++#elif defined(__WATCOMC__) ++# if defined(__NT__) && (UINT_MAX == LZO_0xffffL) ++# define LZO_OS_DOS16 1 ++# define LZO_INFO_OS "dos16" ++# elif defined(__NT__) && (__WATCOMC__ < 1100) ++# define LZO_OS_WIN32 1 ++# define LZO_INFO_OS "win32" ++# elif defined(__linux__) || defined(__LINUX__) ++# define LZO_OS_POSIX 1 ++# define LZO_INFO_OS "posix" ++# else ++# error "please specify a target using the -bt compiler option" ++# endif ++#elif defined(__palmos__) ++# define LZO_OS_PALMOS 1 ++# define LZO_INFO_OS "palmos" ++#elif defined(__TOS__) || defined(__atarist__) ++# define LZO_OS_TOS 1 ++# define LZO_INFO_OS "tos" ++#elif defined(macintosh) && !defined(__ppc__) ++# define LZO_OS_MACCLASSIC 1 ++# define LZO_INFO_OS "macclassic" ++#elif defined(__VMS) ++# define LZO_OS_VMS 1 ++# define LZO_INFO_OS "vms" ++#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) ++# define LZO_OS_CONSOLE 1 ++# define LZO_OS_CONSOLE_PS2 1 ++# define LZO_INFO_OS "console" ++# define LZO_INFO_OS_CONSOLE "ps2" ++#elif (defined(__mips__) && defined(__psp__)) ++# define LZO_OS_CONSOLE 1 ++# define LZO_OS_CONSOLE_PSP 1 ++# define LZO_INFO_OS "console" ++# define LZO_INFO_OS_CONSOLE "psp" ++#else ++# define LZO_OS_POSIX 1 ++# define LZO_INFO_OS "posix" ++#endif ++#if (LZO_OS_POSIX) ++# if defined(_AIX) || defined(__AIX__) || defined(__aix__) ++# define LZO_OS_POSIX_AIX 1 ++# define LZO_INFO_OS_POSIX "aix" ++# elif defined(__FreeBSD__) ++# define LZO_OS_POSIX_FREEBSD 1 ++# define LZO_INFO_OS_POSIX "freebsd" ++# elif defined(__hpux__) || defined(__hpux) ++# define LZO_OS_POSIX_HPUX 1 ++# define LZO_INFO_OS_POSIX "hpux" ++# elif defined(__INTERIX) ++# define LZO_OS_POSIX_INTERIX 1 ++# define LZO_INFO_OS_POSIX "interix" ++# elif defined(__IRIX__) || defined(__irix__) ++# define LZO_OS_POSIX_IRIX 1 ++# define LZO_INFO_OS_POSIX "irix" ++# elif defined(__linux__) || defined(__linux) || defined(__LINUX__) ++# define LZO_OS_POSIX_LINUX 1 ++# define LZO_INFO_OS_POSIX "linux" ++# elif defined(__APPLE__) || defined(__MACOS__) ++# define LZO_OS_POSIX_MACOSX 1 ++# define LZO_INFO_OS_POSIX "macosx" ++# elif defined(__minix__) || defined(__minix) ++# define LZO_OS_POSIX_MINIX 1 ++# define LZO_INFO_OS_POSIX "minix" ++# elif defined(__NetBSD__) ++# define LZO_OS_POSIX_NETBSD 1 ++# define LZO_INFO_OS_POSIX "netbsd" ++# elif defined(__OpenBSD__) ++# define LZO_OS_POSIX_OPENBSD 1 ++# define LZO_INFO_OS_POSIX "openbsd" ++# elif defined(__osf__) ++# define LZO_OS_POSIX_OSF 1 ++# define LZO_INFO_OS_POSIX "osf" ++# elif defined(__solaris__) || defined(__sun) ++# if defined(__SVR4) || defined(__svr4__) ++# define LZO_OS_POSIX_SOLARIS 1 ++# define LZO_INFO_OS_POSIX "solaris" ++# else ++# define LZO_OS_POSIX_SUNOS 1 ++# define LZO_INFO_OS_POSIX "sunos" ++# endif ++# elif defined(__ultrix__) || defined(__ultrix) ++# define LZO_OS_POSIX_ULTRIX 1 ++# define LZO_INFO_OS_POSIX "ultrix" ++# elif defined(_UNICOS) ++# define LZO_OS_POSIX_UNICOS 1 ++# define LZO_INFO_OS_POSIX "unicos" ++# else ++# define LZO_OS_POSIX_UNKNOWN 1 ++# define LZO_INFO_OS_POSIX "unknown" ++# endif ++#endif ++#endif ++#if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) ++# if (UINT_MAX != LZO_0xffffL) ++# error "this should not happen" ++# endif ++# if (ULONG_MAX != LZO_0xffffffffL) ++# error "this should not happen" ++# endif ++#endif ++#if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) ++# if (UINT_MAX != LZO_0xffffffffL) ++# error "this should not happen" ++# endif ++# if (ULONG_MAX != LZO_0xffffffffL) ++# error "this should not happen" ++# endif ++#endif ++#if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) ++# define LZO_CC_CILLY 1 ++# define LZO_INFO_CC "Cilly" ++# if defined(__CILLY__) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CILLY__) ++# else ++# define LZO_INFO_CCVER "unknown" ++# endif ++#elif 0 && defined(SDCC) && defined(__VERSION__) && !defined(__GNUC__) ++# define LZO_CC_SDCC 1 ++# define LZO_INFO_CC "sdcc" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) ++#elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) ++# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) ++# define LZO_INFO_CC "Pathscale C" ++# define LZO_INFO_CCVER __PATHSCALE__ ++#elif defined(__INTEL_COMPILER) ++# define LZO_CC_INTELC 1 ++# define LZO_INFO_CC "Intel C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) ++# if defined(_WIN32) || defined(_WIN64) ++# define LZO_CC_SYNTAX_MSC 1 ++# else ++# define LZO_CC_SYNTAX_GNUC 1 ++# endif ++#elif defined(__POCC__) && defined(_WIN32) ++# define LZO_CC_PELLESC 1 ++# define LZO_INFO_CC "Pelles C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) ++#elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++# if defined(__GNUC_PATCHLEVEL__) ++# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) ++# else ++# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) ++# endif ++# if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) ++# define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__) ++# else ++# define LZO_CC_CLANG_CLANG 0x010000L ++# endif ++# define LZO_CC_CLANG LZO_CC_CLANG_GNUC ++# define LZO_INFO_CC "clang" ++# define LZO_INFO_CCVER __VERSION__ ++#elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++# if defined(__GNUC_PATCHLEVEL__) ++# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) ++# else ++# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) ++# endif ++# define LZO_CC_LLVM LZO_CC_LLVM_GNUC ++# define LZO_INFO_CC "llvm-gcc" ++# define LZO_INFO_CCVER __VERSION__ ++#elif defined(__GNUC__) && defined(__VERSION__) ++# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) ++# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) ++# elif defined(__GNUC_MINOR__) ++# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) ++# else ++# define LZO_CC_GNUC (__GNUC__ * 0x10000L) ++# endif ++# define LZO_INFO_CC "gcc" ++# define LZO_INFO_CCVER __VERSION__ ++#elif defined(__ACK__) && defined(_ACK) ++# define LZO_CC_ACK 1 ++# define LZO_INFO_CC "Amsterdam Compiler Kit C" ++# define LZO_INFO_CCVER "unknown" ++#elif defined(__AZTEC_C__) ++# define LZO_CC_AZTECC 1 ++# define LZO_INFO_CC "Aztec C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__AZTEC_C__) ++#elif defined(__CODEGEARC__) ++# define LZO_CC_CODEGEARC 1 ++# define LZO_INFO_CC "CodeGear C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CODEGEARC__) ++#elif defined(__BORLANDC__) ++# define LZO_CC_BORLANDC 1 ++# define LZO_INFO_CC "Borland C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__BORLANDC__) ++#elif defined(_CRAYC) && defined(_RELEASE) ++# define LZO_CC_CRAYC 1 ++# define LZO_INFO_CC "Cray C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_RELEASE) ++#elif defined(__DMC__) && defined(__SC__) ++# define LZO_CC_DMC 1 ++# define LZO_INFO_CC "Digital Mars C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DMC__) ++#elif defined(__DECC) ++# define LZO_CC_DECC 1 ++# define LZO_INFO_CC "DEC C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) ++#elif defined(__HIGHC__) ++# define LZO_CC_HIGHC 1 ++# define LZO_INFO_CC "MetaWare High C" ++# define LZO_INFO_CCVER "unknown" ++#elif defined(__IAR_SYSTEMS_ICC__) ++# define LZO_CC_IARC 1 ++# define LZO_INFO_CC "IAR C" ++# if defined(__VER__) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__VER__) ++# else ++# define LZO_INFO_CCVER "unknown" ++# endif ++#elif defined(__IBMC__) ++# define LZO_CC_IBMC 1 ++# define LZO_INFO_CC "IBM C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) ++#elif defined(__KEIL__) && defined(__C166__) ++# define LZO_CC_KEILC 1 ++# define LZO_INFO_CC "Keil C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__C166__) ++#elif defined(__LCC__) && defined(_WIN32) && defined(__LCCOPTIMLEVEL) ++# define LZO_CC_LCCWIN32 1 ++# define LZO_INFO_CC "lcc-win32" ++# define LZO_INFO_CCVER "unknown" ++#elif defined(__LCC__) ++# define LZO_CC_LCC 1 ++# define LZO_INFO_CC "lcc" ++# if defined(__LCC_VERSION__) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__LCC_VERSION__) ++# else ++# define LZO_INFO_CCVER "unknown" ++# endif ++#elif defined(_MSC_VER) ++# define LZO_CC_MSC 1 ++# define LZO_INFO_CC "Microsoft C" ++# if defined(_MSC_FULL_VER) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) ++# else ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) ++# endif ++#elif defined(__MWERKS__) ++# define LZO_CC_MWERKS 1 ++# define LZO_INFO_CC "Metrowerks C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) ++#elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) ++# define LZO_CC_NDPC 1 ++# define LZO_INFO_CC "Microway NDP C" ++# define LZO_INFO_CCVER "unknown" ++#elif defined(__PACIFIC__) ++# define LZO_CC_PACIFICC 1 ++# define LZO_INFO_CC "Pacific C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) ++#elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) ++# define LZO_CC_PGI 1 ++# define LZO_INFO_CC "Portland Group PGI C" ++# define LZO_INFO_CCVER "unknown" ++#elif defined(__PUREC__) && defined(__TOS__) ++# define LZO_CC_PUREC 1 ++# define LZO_INFO_CC "Pure C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PUREC__) ++#elif defined(__SC__) && defined(__ZTC__) ++# define LZO_CC_SYMANTECC 1 ++# define LZO_INFO_CC "Symantec C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) ++#elif defined(__SUNPRO_C) ++# define LZO_INFO_CC "SunPro C" ++# if ((__SUNPRO_C)+0 > 0) ++# define LZO_CC_SUNPROC __SUNPRO_C ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) ++# else ++# define LZO_CC_SUNPROC 1 ++# define LZO_INFO_CCVER "unknown" ++# endif ++#elif defined(__SUNPRO_CC) ++# define LZO_INFO_CC "SunPro C" ++# if ((__SUNPRO_CC)+0 > 0) ++# define LZO_CC_SUNPROC __SUNPRO_CC ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) ++# else ++# define LZO_CC_SUNPROC 1 ++# define LZO_INFO_CCVER "unknown" ++# endif ++#elif defined(__TINYC__) ++# define LZO_CC_TINYC 1 ++# define LZO_INFO_CC "Tiny C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TINYC__) ++#elif defined(__TSC__) ++# define LZO_CC_TOPSPEEDC 1 ++# define LZO_INFO_CC "TopSpeed C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TSC__) ++#elif defined(__WATCOMC__) ++# define LZO_CC_WATCOMC 1 ++# define LZO_INFO_CC "Watcom C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__WATCOMC__) ++#elif defined(__TURBOC__) ++# define LZO_CC_TURBOC 1 ++# define LZO_INFO_CC "Turbo C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TURBOC__) ++#elif defined(__ZTC__) ++# define LZO_CC_ZORTECHC 1 ++# define LZO_INFO_CC "Zortech C" ++# if (__ZTC__ == 0x310) ++# define LZO_INFO_CCVER "0x310" ++# else ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) ++# endif ++#else ++# define LZO_CC_UNKNOWN 1 ++# define LZO_INFO_CC "unknown" ++# define LZO_INFO_CCVER "unknown" ++#endif ++#if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) ++# error "LZO_CC_MSC: _MSC_FULL_VER is not defined" ++#endif ++#if !defined(__LZO_ARCH_OVERRIDE) && !(LZO_ARCH_GENERIC) && defined(_CRAY) ++# if (UINT_MAX > LZO_0xffffffffL) && defined(_CRAY) ++# if defined(_CRAYMPP) || defined(_CRAYT3D) || defined(_CRAYT3E) ++# define LZO_ARCH_CRAY_MPP 1 ++# elif defined(_CRAY1) ++# define LZO_ARCH_CRAY_PVP 1 ++# endif ++# endif ++#endif ++#if !defined(__LZO_ARCH_OVERRIDE) ++#if (LZO_ARCH_GENERIC) ++# define LZO_INFO_ARCH "generic" ++#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) ++# define LZO_ARCH_I086 1 ++# define LZO_ARCH_IA16 1 ++# define LZO_INFO_ARCH "i086" ++#elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) ++# define LZO_ARCH_ALPHA 1 ++# define LZO_INFO_ARCH "alpha" ++#elif (LZO_ARCH_CRAY_MPP) && (defined(_CRAYT3D) || defined(_CRAYT3E)) ++# define LZO_ARCH_ALPHA 1 ++# define LZO_INFO_ARCH "alpha" ++#elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64) ++# define LZO_ARCH_AMD64 1 ++# define LZO_INFO_ARCH "amd64" ++#elif defined(__thumb__) || (defined(_M_ARM) && defined(_M_THUMB)) ++# define LZO_ARCH_ARM 1 ++# define LZO_ARCH_ARM_THUMB 1 ++# define LZO_INFO_ARCH "arm_thumb" ++#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) ++# define LZO_ARCH_ARM 1 ++# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) ++# define LZO_ARCH_ARM_THUMB 1 ++# define LZO_INFO_ARCH "arm_thumb" ++# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) ++# define LZO_INFO_ARCH "arm" ++# else ++# define LZO_INFO_ARCH "arm" ++# endif ++#elif defined(__arm__) || defined(_M_ARM) ++# define LZO_ARCH_ARM 1 ++# define LZO_INFO_ARCH "arm" ++#elif (UINT_MAX <= LZO_0xffffL) && defined(__AVR__) ++# define LZO_ARCH_AVR 1 ++# define LZO_INFO_ARCH "avr" ++#elif defined(__avr32__) || defined(__AVR32__) ++# define LZO_ARCH_AVR32 1 ++# define LZO_INFO_ARCH "avr32" ++#elif defined(__bfin__) ++# define LZO_ARCH_BLACKFIN 1 ++# define LZO_INFO_ARCH "blackfin" ++#elif (UINT_MAX == LZO_0xffffL) && defined(__C166__) ++# define LZO_ARCH_C166 1 ++# define LZO_INFO_ARCH "c166" ++#elif defined(__cris__) ++# define LZO_ARCH_CRIS 1 ++# define LZO_INFO_ARCH "cris" ++#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCEZ80__) ++# define LZO_ARCH_EZ80 1 ++# define LZO_INFO_ARCH "ez80" ++#elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) ++# define LZO_ARCH_H8300 1 ++# define LZO_INFO_ARCH "h8300" ++#elif defined(__hppa__) || defined(__hppa) ++# define LZO_ARCH_HPPA 1 ++# define LZO_INFO_ARCH "hppa" ++#elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386) ++# define LZO_ARCH_I386 1 ++# define LZO_ARCH_IA32 1 ++# define LZO_INFO_ARCH "i386" ++#elif (LZO_CC_ZORTECHC && defined(__I86__)) ++# define LZO_ARCH_I386 1 ++# define LZO_ARCH_IA32 1 ++# define LZO_INFO_ARCH "i386" ++#elif (LZO_OS_DOS32 && LZO_CC_HIGHC) && defined(_I386) ++# define LZO_ARCH_I386 1 ++# define LZO_ARCH_IA32 1 ++# define LZO_INFO_ARCH "i386" ++#elif defined(__ia64__) || defined(__ia64) || defined(_M_IA64) ++# define LZO_ARCH_IA64 1 ++# define LZO_INFO_ARCH "ia64" ++#elif (UINT_MAX == LZO_0xffffL) && defined(__m32c__) ++# define LZO_ARCH_M16C 1 ++# define LZO_INFO_ARCH "m16c" ++#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCM16C__) ++# define LZO_ARCH_M16C 1 ++# define LZO_INFO_ARCH "m16c" ++#elif defined(__m32r__) ++# define LZO_ARCH_M32R 1 ++# define LZO_INFO_ARCH "m32r" ++#elif (LZO_OS_TOS) || defined(__m68k__) || defined(__m68000__) || defined(__mc68000__) || defined(__mc68020__) || defined(_M_M68K) ++# define LZO_ARCH_M68K 1 ++# define LZO_INFO_ARCH "m68k" ++#elif (UINT_MAX == LZO_0xffffL) && defined(__C251__) ++# define LZO_ARCH_MCS251 1 ++# define LZO_INFO_ARCH "mcs251" ++#elif (UINT_MAX == LZO_0xffffL) && defined(__C51__) ++# define LZO_ARCH_MCS51 1 ++# define LZO_INFO_ARCH "mcs51" ++#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC8051__) ++# define LZO_ARCH_MCS51 1 ++# define LZO_INFO_ARCH "mcs51" ++#elif defined(__mips__) || defined(__mips) || defined(_MIPS_ARCH) || defined(_M_MRX000) ++# define LZO_ARCH_MIPS 1 ++# define LZO_INFO_ARCH "mips" ++#elif (UINT_MAX == LZO_0xffffL) && defined(__MSP430__) ++# define LZO_ARCH_MSP430 1 ++# define LZO_INFO_ARCH "msp430" ++#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC430__) ++# define LZO_ARCH_MSP430 1 ++# define LZO_INFO_ARCH "msp430" ++#elif defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) || defined(__PPC__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PWR) ++# define LZO_ARCH_POWERPC 1 ++# define LZO_INFO_ARCH "powerpc" ++#elif defined(__s390__) || defined(__s390) || defined(__s390x__) || defined(__s390x) ++# define LZO_ARCH_S390 1 ++# define LZO_INFO_ARCH "s390" ++#elif defined(__sh__) || defined(_M_SH) ++# define LZO_ARCH_SH 1 ++# define LZO_INFO_ARCH "sh" ++#elif defined(__sparc__) || defined(__sparc) || defined(__sparcv8) ++# define LZO_ARCH_SPARC 1 ++# define LZO_INFO_ARCH "sparc" ++#elif defined(__SPU__) ++# define LZO_ARCH_SPU 1 ++# define LZO_INFO_ARCH "spu" ++#elif (UINT_MAX == LZO_0xffffL) && defined(__z80) ++# define LZO_ARCH_Z80 1 ++# define LZO_INFO_ARCH "z80" ++#elif (LZO_ARCH_CRAY_PVP) ++# if defined(_CRAYSV1) ++# define LZO_ARCH_CRAY_SV1 1 ++# define LZO_INFO_ARCH "cray_sv1" ++# elif (_ADDR64) ++# define LZO_ARCH_CRAY_T90 1 ++# define LZO_INFO_ARCH "cray_t90" ++# elif (_ADDR32) ++# define LZO_ARCH_CRAY_YMP 1 ++# define LZO_INFO_ARCH "cray_ymp" ++# else ++# define LZO_ARCH_CRAY_XMP 1 ++# define LZO_INFO_ARCH "cray_xmp" ++# endif ++#else ++# define LZO_ARCH_UNKNOWN 1 ++# define LZO_INFO_ARCH "unknown" ++#endif ++#endif ++#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2) ++# error "FIXME - missing define for CPU architecture" ++#endif ++#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) ++# error "FIXME - missing WIN32 define for CPU architecture" ++#endif ++#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) ++# error "FIXME - missing WIN64 define for CPU architecture" ++#endif ++#if (LZO_OS_OS216 || LZO_OS_WIN16) ++# define LZO_ARCH_I086PM 1 ++# define LZO_ARCH_IA16PM 1 ++#elif 1 && (LZO_OS_DOS16 && defined(BLX286)) ++# define LZO_ARCH_I086PM 1 ++# define LZO_ARCH_IA16PM 1 ++#elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) ++# define LZO_ARCH_I086PM 1 ++# define LZO_ARCH_IA16PM 1 ++#elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) ++# define LZO_ARCH_I086PM 1 ++# define LZO_ARCH_IA16PM 1 ++#endif ++#if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM) ++# error "this should not happen" ++#endif ++#if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086) ++# error "this should not happen" ++#endif ++#if (LZO_ARCH_I086) ++# if (UINT_MAX != LZO_0xffffL) ++# error "this should not happen" ++# endif ++# if (ULONG_MAX != LZO_0xffffffffL) ++# error "this should not happen" ++# endif ++#endif ++#if (LZO_ARCH_I386) ++# if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) ++# error "this should not happen" ++# endif ++# if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) ++# error "this should not happen" ++# endif ++# if (ULONG_MAX != LZO_0xffffffffL) ++# error "this should not happen" ++# endif ++#endif ++#if !defined(__LZO_MM_OVERRIDE) ++#if (LZO_ARCH_I086) ++#if (UINT_MAX != LZO_0xffffL) ++# error "this should not happen" ++#endif ++#if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) ++# define LZO_MM_TINY 1 ++#elif defined(__HUGE__) || defined(_HUGE_) || defined(M_I86HM) || defined(_M_I86HM) ++# define LZO_MM_HUGE 1 ++#elif defined(__SMALL__) || defined(M_I86SM) || defined(_M_I86SM) || defined(SMALL_MODEL) ++# define LZO_MM_SMALL 1 ++#elif defined(__MEDIUM__) || defined(M_I86MM) || defined(_M_I86MM) ++# define LZO_MM_MEDIUM 1 ++#elif defined(__COMPACT__) || defined(M_I86CM) || defined(_M_I86CM) ++# define LZO_MM_COMPACT 1 ++#elif defined(__LARGE__) || defined(M_I86LM) || defined(_M_I86LM) || defined(LARGE_MODEL) ++# define LZO_MM_LARGE 1 ++#elif (LZO_CC_AZTECC) ++# if defined(_LARGE_CODE) && defined(_LARGE_DATA) ++# define LZO_MM_LARGE 1 ++# elif defined(_LARGE_CODE) ++# define LZO_MM_MEDIUM 1 ++# elif defined(_LARGE_DATA) ++# define LZO_MM_COMPACT 1 ++# else ++# define LZO_MM_SMALL 1 ++# endif ++#elif (LZO_CC_ZORTECHC && defined(__VCM__)) ++# define LZO_MM_LARGE 1 ++#else ++# error "unknown memory model" ++#endif ++#if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) ++#define LZO_HAVE_MM_HUGE_PTR 1 ++#define LZO_HAVE_MM_HUGE_ARRAY 1 ++#if (LZO_MM_TINY) ++# undef LZO_HAVE_MM_HUGE_ARRAY ++#endif ++#if (LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_ZORTECHC) ++# undef LZO_HAVE_MM_HUGE_PTR ++# undef LZO_HAVE_MM_HUGE_ARRAY ++#elif (LZO_CC_DMC || LZO_CC_SYMANTECC) ++# undef LZO_HAVE_MM_HUGE_ARRAY ++#elif (LZO_CC_MSC && defined(_QC)) ++# undef LZO_HAVE_MM_HUGE_ARRAY ++# if (_MSC_VER < 600) ++# undef LZO_HAVE_MM_HUGE_PTR ++# endif ++#elif (LZO_CC_TURBOC && (__TURBOC__ < 0x0295)) ++# undef LZO_HAVE_MM_HUGE_ARRAY ++#endif ++#if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR) ++# if (LZO_OS_DOS16) ++# error "this should not happen" ++# elif (LZO_CC_ZORTECHC) ++# else ++# error "this should not happen" ++# endif ++#endif ++#ifdef __cplusplus ++extern "C" { ++#endif ++#if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200)) ++ extern void __near __cdecl _AHSHIFT(void); ++# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) ++#elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) ++ extern void __near __cdecl _AHSHIFT(void); ++# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) ++#elif (LZO_CC_MSC || LZO_CC_TOPSPEEDC) ++ extern void __near __cdecl _AHSHIFT(void); ++# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) ++#elif (LZO_CC_TURBOC && (__TURBOC__ >= 0x0295)) ++ extern void __near __cdecl _AHSHIFT(void); ++# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) ++#elif ((LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_TURBOC) && LZO_OS_DOS16) ++# define LZO_MM_AHSHIFT 12 ++#elif (LZO_CC_WATCOMC) ++ extern unsigned char _HShift; ++# define LZO_MM_AHSHIFT ((unsigned) _HShift) ++#else ++# error "FIXME - implement LZO_MM_AHSHIFT" ++#endif ++#ifdef __cplusplus ++} ++#endif ++#endif ++#elif (LZO_ARCH_C166) ++#if !defined(__MODEL__) ++# error "FIXME - C166 __MODEL__" ++#elif ((__MODEL__) == 0) ++# define LZO_MM_SMALL 1 ++#elif ((__MODEL__) == 1) ++# define LZO_MM_SMALL 1 ++#elif ((__MODEL__) == 2) ++# define LZO_MM_LARGE 1 ++#elif ((__MODEL__) == 3) ++# define LZO_MM_TINY 1 ++#elif ((__MODEL__) == 4) ++# define LZO_MM_XTINY 1 ++#elif ((__MODEL__) == 5) ++# define LZO_MM_XSMALL 1 ++#else ++# error "FIXME - C166 __MODEL__" ++#endif ++#elif (LZO_ARCH_MCS251) ++#if !defined(__MODEL__) ++# error "FIXME - MCS251 __MODEL__" ++#elif ((__MODEL__) == 0) ++# define LZO_MM_SMALL 1 ++#elif ((__MODEL__) == 2) ++# define LZO_MM_LARGE 1 ++#elif ((__MODEL__) == 3) ++# define LZO_MM_TINY 1 ++#elif ((__MODEL__) == 4) ++# define LZO_MM_XTINY 1 ++#elif ((__MODEL__) == 5) ++# define LZO_MM_XSMALL 1 ++#else ++# error "FIXME - MCS251 __MODEL__" ++#endif ++#elif (LZO_ARCH_MCS51) ++#if !defined(__MODEL__) ++# error "FIXME - MCS51 __MODEL__" ++#elif ((__MODEL__) == 1) ++# define LZO_MM_SMALL 1 ++#elif ((__MODEL__) == 2) ++# define LZO_MM_LARGE 1 ++#elif ((__MODEL__) == 3) ++# define LZO_MM_TINY 1 ++#elif ((__MODEL__) == 4) ++# define LZO_MM_XTINY 1 ++#elif ((__MODEL__) == 5) ++# define LZO_MM_XSMALL 1 ++#else ++# error "FIXME - MCS51 __MODEL__" ++#endif ++#elif (LZO_ARCH_CRAY_PVP) ++# define LZO_MM_PVP 1 ++#else ++# define LZO_MM_FLAT 1 ++#endif ++#if (LZO_MM_COMPACT) ++# define LZO_INFO_MM "compact" ++#elif (LZO_MM_FLAT) ++# define LZO_INFO_MM "flat" ++#elif (LZO_MM_HUGE) ++# define LZO_INFO_MM "huge" ++#elif (LZO_MM_LARGE) ++# define LZO_INFO_MM "large" ++#elif (LZO_MM_MEDIUM) ++# define LZO_INFO_MM "medium" ++#elif (LZO_MM_PVP) ++# define LZO_INFO_MM "pvp" ++#elif (LZO_MM_SMALL) ++# define LZO_INFO_MM "small" ++#elif (LZO_MM_TINY) ++# define LZO_INFO_MM "tiny" ++#else ++# error "unknown memory model" ++#endif ++#endif ++#if defined(SIZEOF_SHORT) ++# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) ++#endif ++#if defined(SIZEOF_INT) ++# define LZO_SIZEOF_INT (SIZEOF_INT) ++#endif ++#if defined(SIZEOF_LONG) ++# define LZO_SIZEOF_LONG (SIZEOF_LONG) ++#endif ++#if defined(SIZEOF_LONG_LONG) ++# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) ++#endif ++#if defined(SIZEOF___INT16) ++# define LZO_SIZEOF___INT16 (SIZEOF___INT16) ++#endif ++#if defined(SIZEOF___INT32) ++# define LZO_SIZEOF___INT32 (SIZEOF___INT32) ++#endif ++#if defined(SIZEOF___INT64) ++# define LZO_SIZEOF___INT64 (SIZEOF___INT64) ++#endif ++#if defined(SIZEOF_VOID_P) ++# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) ++#endif ++#if defined(SIZEOF_SIZE_T) ++# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) ++#endif ++#if defined(SIZEOF_PTRDIFF_T) ++# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) ++#endif ++#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) ++#if !defined(LZO_SIZEOF_SHORT) ++# if (LZO_ARCH_CRAY_PVP) ++# define LZO_SIZEOF_SHORT 8 ++# elif (USHRT_MAX == LZO_0xffffL) ++# define LZO_SIZEOF_SHORT 2 ++# elif (__LZO_LSR(USHRT_MAX,7) == 1) ++# define LZO_SIZEOF_SHORT 1 ++# elif (__LZO_LSR(USHRT_MAX,15) == 1) ++# define LZO_SIZEOF_SHORT 2 ++# elif (__LZO_LSR(USHRT_MAX,31) == 1) ++# define LZO_SIZEOF_SHORT 4 ++# elif (__LZO_LSR(USHRT_MAX,63) == 1) ++# define LZO_SIZEOF_SHORT 8 ++# elif (__LZO_LSR(USHRT_MAX,127) == 1) ++# define LZO_SIZEOF_SHORT 16 ++# else ++# error "LZO_SIZEOF_SHORT" ++# endif ++#endif ++#if !defined(LZO_SIZEOF_INT) ++# if (LZO_ARCH_CRAY_PVP) ++# define LZO_SIZEOF_INT 8 ++# elif (UINT_MAX == LZO_0xffffL) ++# define LZO_SIZEOF_INT 2 ++# elif (UINT_MAX == LZO_0xffffffffL) ++# define LZO_SIZEOF_INT 4 ++# elif (__LZO_LSR(UINT_MAX,7) == 1) ++# define LZO_SIZEOF_INT 1 ++# elif (__LZO_LSR(UINT_MAX,15) == 1) ++# define LZO_SIZEOF_INT 2 ++# elif (__LZO_LSR(UINT_MAX,31) == 1) ++# define LZO_SIZEOF_INT 4 ++# elif (__LZO_LSR(UINT_MAX,63) == 1) ++# define LZO_SIZEOF_INT 8 ++# elif (__LZO_LSR(UINT_MAX,127) == 1) ++# define LZO_SIZEOF_INT 16 ++# else ++# error "LZO_SIZEOF_INT" ++# endif ++#endif ++#if !defined(LZO_SIZEOF_LONG) ++# if (ULONG_MAX == LZO_0xffffffffL) ++# define LZO_SIZEOF_LONG 4 ++# elif (__LZO_LSR(ULONG_MAX,7) == 1) ++# define LZO_SIZEOF_LONG 1 ++# elif (__LZO_LSR(ULONG_MAX,15) == 1) ++# define LZO_SIZEOF_LONG 2 ++# elif (__LZO_LSR(ULONG_MAX,31) == 1) ++# define LZO_SIZEOF_LONG 4 ++# elif (__LZO_LSR(ULONG_MAX,63) == 1) ++# define LZO_SIZEOF_LONG 8 ++# elif (__LZO_LSR(ULONG_MAX,127) == 1) ++# define LZO_SIZEOF_LONG 16 ++# else ++# error "LZO_SIZEOF_LONG" ++# endif ++#endif ++#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) ++#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) ++# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) ++# if (LZO_CC_GNUC >= 0x030300ul) ++# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) ++# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG ++# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) ++# define LZO_SIZEOF_LONG_LONG 4 ++# endif ++# endif ++# endif ++#endif ++#endif ++#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) ++#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) ++#if (LZO_ARCH_I086 && LZO_CC_DMC) ++#elif (LZO_CC_CILLY) && defined(__GNUC__) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_OS_WIN64 || defined(_WIN64)) ++# define LZO_SIZEOF___INT64 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) ++# define LZO_SIZEOF___INT64 8 ++#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) ++# define LZO_SIZEOF___INT64 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) ++# define LZO_SIZEOF___INT64 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) ++# define LZO_SIZEOF___INT64 8 ++#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) ++# define LZO_SIZEOF___INT64 8 ++#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) ++#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ++# define LZO_SIZEOF_LONG_LONG 8 ++#endif ++#endif ++#endif ++#if defined(__cplusplus) && (LZO_CC_GNUC) ++# if (LZO_CC_GNUC < 0x020800ul) ++# undef LZO_SIZEOF_LONG_LONG ++# endif ++#endif ++#if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) ++# undef LZO_SIZEOF_LONG_LONG ++#endif ++#if !defined(LZO_SIZEOF_VOID_P) ++#if (LZO_ARCH_I086) ++# define __LZO_WORDSIZE 2 ++# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) ++# define LZO_SIZEOF_VOID_P 2 ++# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) ++# define LZO_SIZEOF_VOID_P 4 ++# else ++# error "LZO_MM" ++# endif ++#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) ++# define __LZO_WORDSIZE 1 ++# define LZO_SIZEOF_VOID_P 2 ++#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) ++# define LZO_SIZEOF_VOID_P 2 ++#elif (LZO_ARCH_H8300) ++# if defined(__NORMAL_MODE__) ++# define __LZO_WORDSIZE 4 ++# define LZO_SIZEOF_VOID_P 2 ++# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) ++# define __LZO_WORDSIZE 4 ++# define LZO_SIZEOF_VOID_P 4 ++# else ++# define __LZO_WORDSIZE 2 ++# define LZO_SIZEOF_VOID_P 2 ++# endif ++# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT ++# endif ++#elif (LZO_ARCH_M16C) ++# define __LZO_WORDSIZE 2 ++# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) ++# define LZO_SIZEOF_VOID_P 4 ++# else ++# define LZO_SIZEOF_VOID_P 2 ++# endif ++#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) ++# define __LZO_WORDSIZE 8 ++# define LZO_SIZEOF_VOID_P 4 ++#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) ++# define __LZO_WORDSIZE 8 ++# define LZO_SIZEOF_VOID_P 8 ++#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) ++# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG ++#elif (LZO_OS_OS400 || defined(__OS400__)) ++# define __LZO_WORDSIZE LZO_SIZEOF_LONG ++# define LZO_SIZEOF_VOID_P 16 ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG ++#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) ++# define LZO_SIZEOF_VOID_P 8 ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG ++#elif (LZO_ARCH_SPU) ++# if 0 ++# define __LZO_WORDSIZE 16 ++# endif ++# define LZO_SIZEOF_VOID_P 4 ++#else ++# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG ++#endif ++#endif ++#if !defined(LZO_WORDSIZE) ++# if defined(__LZO_WORDSIZE) ++# define LZO_WORDSIZE __LZO_WORDSIZE ++# else ++# define LZO_WORDSIZE LZO_SIZEOF_VOID_P ++# endif ++#endif ++#if !defined(LZO_SIZEOF_SIZE_T) ++#if (LZO_ARCH_I086 || LZO_ARCH_M16C) ++# define LZO_SIZEOF_SIZE_T 2 ++#else ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P ++#endif ++#endif ++#if !defined(LZO_SIZEOF_PTRDIFF_T) ++#if (LZO_ARCH_I086) ++# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P ++# elif (LZO_MM_COMPACT || LZO_MM_LARGE) ++# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) ++# define LZO_SIZEOF_PTRDIFF_T 4 ++# else ++# define LZO_SIZEOF_PTRDIFF_T 2 ++# endif ++# else ++# error "LZO_MM" ++# endif ++#else ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T ++#endif ++#endif ++#if (LZO_ABI_NEUTRAL_ENDIAN) ++# undef LZO_ABI_BIG_ENDIAN ++# undef LZO_ABI_LITTLE_ENDIAN ++#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) ++#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) ++# define LZO_ABI_BIG_ENDIAN 1 ++#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) ++# define LZO_ABI_LITTLE_ENDIAN 1 ++#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) ++# define LZO_ABI_LITTLE_ENDIAN 1 ++#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390) ++# define LZO_ABI_BIG_ENDIAN 1 ++#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) ++# if (__LITTLE_ENDIAN__ == 1) ++# define LZO_ABI_LITTLE_ENDIAN 1 ++# else ++# define LZO_ABI_BIG_ENDIAN 1 ++# endif ++#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) ++# define LZO_ABI_BIG_ENDIAN 1 ++#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) ++# define LZO_ABI_LITTLE_ENDIAN 1 ++#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) ++# define LZO_ABI_BIG_ENDIAN 1 ++#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) ++# define LZO_ABI_LITTLE_ENDIAN 1 ++#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) ++# define LZO_ABI_BIG_ENDIAN 1 ++#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) ++# define LZO_ABI_LITTLE_ENDIAN 1 ++#endif ++#endif ++#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) ++# error "this should not happen" ++#endif ++#if (LZO_ABI_BIG_ENDIAN) ++# define LZO_INFO_ABI_ENDIAN "be" ++#elif (LZO_ABI_LITTLE_ENDIAN) ++# define LZO_INFO_ABI_ENDIAN "le" ++#elif (LZO_ABI_NEUTRAL_ENDIAN) ++# define LZO_INFO_ABI_ENDIAN "neutral" ++#endif ++#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) ++# define LZO_ABI_I8LP16 1 ++# define LZO_INFO_ABI_PM "i8lp16" ++#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) ++# define LZO_ABI_ILP16 1 ++# define LZO_INFO_ABI_PM "ilp16" ++#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) ++# define LZO_ABI_ILP32 1 ++# define LZO_INFO_ABI_PM "ilp32" ++#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) ++# define LZO_ABI_LLP64 1 ++# define LZO_INFO_ABI_PM "llp64" ++#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) ++# define LZO_ABI_LP64 1 ++# define LZO_INFO_ABI_PM "lp64" ++#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) ++# define LZO_ABI_ILP64 1 ++# define LZO_INFO_ABI_PM "ilp64" ++#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) ++# define LZO_ABI_IP32L64 1 ++# define LZO_INFO_ABI_PM "ip32l64" ++#endif ++#if !defined(__LZO_LIBC_OVERRIDE) ++#if (LZO_LIBC_NAKED) ++# define LZO_INFO_LIBC "naked" ++#elif (LZO_LIBC_FREESTANDING) ++# define LZO_INFO_LIBC "freestanding" ++#elif (LZO_LIBC_MOSTLY_FREESTANDING) ++# define LZO_INFO_LIBC "mfreestanding" ++#elif (LZO_LIBC_ISOC90) ++# define LZO_INFO_LIBC "isoc90" ++#elif (LZO_LIBC_ISOC99) ++# define LZO_INFO_LIBC "isoc99" ++#elif defined(__dietlibc__) ++# define LZO_LIBC_DIETLIBC 1 ++# define LZO_INFO_LIBC "dietlibc" ++#elif defined(_NEWLIB_VERSION) ++# define LZO_LIBC_NEWLIB 1 ++# define LZO_INFO_LIBC "newlib" ++#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) ++# if defined(__UCLIBC_SUBLEVEL__) ++# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) ++# else ++# define LZO_LIBC_UCLIBC 0x00090bL ++# endif ++# define LZO_INFO_LIBC "uclibc" ++#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) ++# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) ++# define LZO_INFO_LIBC "glibc" ++#elif (LZO_CC_MWERKS) && defined(__MSL__) ++# define LZO_LIBC_MSL __MSL__ ++# define LZO_INFO_LIBC "msl" ++#elif 1 && defined(__IAR_SYSTEMS_ICC__) ++# define LZO_LIBC_ISOC90 1 ++# define LZO_INFO_LIBC "isoc90" ++#else ++# define LZO_LIBC_DEFAULT 1 ++# define LZO_INFO_LIBC "default" ++#endif ++#endif ++#if !defined(__lzo_gnuc_extension__) ++#if (LZO_CC_GNUC >= 0x020800ul) ++# define __lzo_gnuc_extension__ __extension__ ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_gnuc_extension__ __extension__ ++#else ++# define __lzo_gnuc_extension__ /*empty*/ ++#endif ++#endif ++#if !defined(__lzo_ua_volatile) ++# define __lzo_ua_volatile volatile ++#endif ++#if !defined(__lzo_alignof) ++#if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) ++# define __lzo_alignof(e) __alignof__(e) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) ++# define __lzo_alignof(e) __alignof__(e) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_alignof(e) __alignof(e) ++#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_alignof(e) __alignof__(e) ++#endif ++#endif ++#if defined(__lzo_alignof) ++# define __lzo_HAVE_alignof 1 ++#endif ++#if !defined(__lzo_constructor) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_constructor __attribute__((__constructor__,__used__)) ++#elif (LZO_CC_GNUC >= 0x020700ul) ++# define __lzo_constructor __attribute__((__constructor__)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_constructor __attribute__((__constructor__)) ++#endif ++#endif ++#if defined(__lzo_constructor) ++# define __lzo_HAVE_constructor 1 ++#endif ++#if !defined(__lzo_destructor) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_destructor __attribute__((__destructor__,__used__)) ++#elif (LZO_CC_GNUC >= 0x020700ul) ++# define __lzo_destructor __attribute__((__destructor__)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_destructor __attribute__((__destructor__)) ++#endif ++#endif ++#if defined(__lzo_destructor) ++# define __lzo_HAVE_destructor 1 ++#endif ++#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) ++# error "this should not happen" ++#endif ++#if !defined(__lzo_inline) ++#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) ++#elif defined(__cplusplus) ++# define __lzo_inline inline ++#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) ++# define __lzo_inline __inline ++#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) ++# define __lzo_inline __inline__ ++#elif (LZO_CC_DMC) ++# define __lzo_inline __inline ++#elif (LZO_CC_INTELC) ++# define __lzo_inline __inline ++#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) ++# define __lzo_inline __inline ++#elif (LZO_CC_MSC && (_MSC_VER >= 900)) ++# define __lzo_inline __inline ++#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_inline __inline__ ++#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ++# define __lzo_inline inline ++#endif ++#endif ++#if defined(__lzo_inline) ++# define __lzo_HAVE_inline 1 ++#else ++# define __lzo_inline /*empty*/ ++#endif ++#if !defined(__lzo_forceinline) ++#if (LZO_CC_GNUC >= 0x030200ul) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) ++# define __lzo_forceinline __forceinline ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) ++# define __lzo_forceinline __forceinline ++#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#endif ++#endif ++#if defined(__lzo_forceinline) ++# define __lzo_HAVE_forceinline 1 ++#else ++# define __lzo_forceinline /*empty*/ ++#endif ++#if !defined(__lzo_noinline) ++#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) ++# define __lzo_noinline __attribute__((__noinline__,__used__)) ++#elif (LZO_CC_GNUC >= 0x030200ul) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) ++# define __lzo_noinline __declspec(noinline) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_noinline __declspec(noinline) ++#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) ++# if defined(__cplusplus) ++# else ++# define __lzo_noinline __declspec(noinline) ++# endif ++#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_noinline __attribute__((__noinline__)) ++#endif ++#endif ++#if defined(__lzo_noinline) ++# define __lzo_HAVE_noinline 1 ++#else ++# define __lzo_noinline /*empty*/ ++#endif ++#if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) ++# error "this should not happen" ++#endif ++#if !defined(__lzo_noreturn) ++#if (LZO_CC_GNUC >= 0x020700ul) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) ++# define __lzo_noreturn __declspec(noreturn) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) ++# define __lzo_noreturn __declspec(noreturn) ++#endif ++#endif ++#if defined(__lzo_noreturn) ++# define __lzo_HAVE_noreturn 1 ++#else ++# define __lzo_noreturn /*empty*/ ++#endif ++#if !defined(__lzo_nothrow) ++#if (LZO_CC_GNUC >= 0x030300ul) ++# define __lzo_nothrow __attribute__((__nothrow__)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) ++# define __lzo_nothrow __declspec(nothrow) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC) ++# define __lzo_nothrow __attribute__((__nothrow__)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_nothrow __attribute__((__nothrow__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) ++# define __lzo_nothrow __declspec(nothrow) ++#endif ++#endif ++#if defined(__lzo_nothrow) ++# define __lzo_HAVE_nothrow 1 ++#else ++# define __lzo_nothrow /*empty*/ ++#endif ++#if !defined(__lzo_restrict) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_CLANG || LZO_CC_LLVM) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) ++# define __lzo_restrict __restrict ++#endif ++#endif ++#if defined(__lzo_restrict) ++# define __lzo_HAVE_restrict 1 ++#else ++# define __lzo_restrict /*empty*/ ++#endif ++#if !defined(__lzo_likely) && !defined(__lzo_unlikely) ++#if (LZO_CC_GNUC >= 0x030200ul) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#endif ++#endif ++#if defined(__lzo_likely) ++# define __lzo_HAVE_likely 1 ++#else ++# define __lzo_likely(e) (e) ++#endif ++#if defined(__lzo_unlikely) ++# define __lzo_HAVE_unlikely 1 ++#else ++# define __lzo_unlikely(e) (e) ++#endif ++#if !defined(LZO_UNUSED) ++# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) ++# define LZO_UNUSED(var) ((void) &var) ++# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) ++# define LZO_UNUSED(var) if (&var) ; else ++# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNUSED(var) ((void) var) ++# elif (LZO_CC_MSC && (_MSC_VER < 900)) ++# define LZO_UNUSED(var) if (&var) ; else ++# elif (LZO_CC_KEILC) ++# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} ++# elif (LZO_CC_PACIFICC) ++# define LZO_UNUSED(var) ((void) sizeof(var)) ++# elif (LZO_CC_WATCOMC) && defined(__cplusplus) ++# define LZO_UNUSED(var) ((void) var) ++# else ++# define LZO_UNUSED(var) ((void) &var) ++# endif ++#endif ++#if !defined(LZO_UNUSED_FUNC) ++# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) ++# define LZO_UNUSED_FUNC(func) ((void) func) ++# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) ++# define LZO_UNUSED_FUNC(func) if (func) ; else ++# elif (LZO_CC_CLANG || LZO_CC_LLVM) ++# define LZO_UNUSED_FUNC(func) ((void) &func) ++# elif (LZO_CC_MSC && (_MSC_VER < 900)) ++# define LZO_UNUSED_FUNC(func) if (func) ; else ++# elif (LZO_CC_MSC) ++# define LZO_UNUSED_FUNC(func) ((void) &func) ++# elif (LZO_CC_KEILC || LZO_CC_PELLESC) ++# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} ++# else ++# define LZO_UNUSED_FUNC(func) ((void) func) ++# endif ++#endif ++#if !defined(LZO_UNUSED_LABEL) ++# if (LZO_CC_WATCOMC) && defined(__cplusplus) ++# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l ++# elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) ++# define LZO_UNUSED_LABEL(l) if (0) goto l ++# else ++# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l ++# endif ++#endif ++#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) ++# if 0 ++# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var ++# elif 0 && (LZO_CC_GNUC) ++# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var ++# else ++# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init ++# endif ++#endif ++#if !defined(LZO_UNCONST_CAST) ++# if 0 && defined(__cplusplus) ++# define LZO_UNCONST_CAST(t,e) (const_cast<t> (e)) ++# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e)))))) ++# else ++# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e))))) ++# endif ++#endif ++#if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) ++# if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; ++# elif (LZO_CC_DMC || LZO_CC_SYMANTECC) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; ++# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; ++# else ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; ++# endif ++#endif ++#if !defined(LZO_COMPILE_TIME_ASSERT) ++# if (LZO_CC_AZTECC) ++# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} ++# elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) ++# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; ++# elif (LZO_CC_MSC && (_MSC_VER < 900)) ++# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; ++# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) ++# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; ++# else ++# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} ++# endif ++#endif ++#if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) ++# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) ++# elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) ++# define __lzo_cdecl __cdecl ++# define __lzo_cdecl_atexit /*empty*/ ++# define __lzo_cdecl_main __cdecl ++# if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) ++# define __lzo_cdecl_qsort __pascal ++# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) ++# define __lzo_cdecl_qsort _stdcall ++# else ++# define __lzo_cdecl_qsort __cdecl ++# endif ++# elif (LZO_CC_WATCOMC) ++# define __lzo_cdecl __cdecl ++# else ++# define __lzo_cdecl __cdecl ++# define __lzo_cdecl_atexit __cdecl ++# define __lzo_cdecl_main __cdecl ++# define __lzo_cdecl_qsort __cdecl ++# endif ++# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC) ++# elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) ++# define __lzo_cdecl_sighandler __pascal ++# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) ++# define __lzo_cdecl_sighandler _stdcall ++# elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE) ++# define __lzo_cdecl_sighandler __clrcall ++# elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700)) ++# if defined(_DLL) ++# define __lzo_cdecl_sighandler _far _cdecl _loadds ++# elif defined(_MT) ++# define __lzo_cdecl_sighandler _far _cdecl ++# else ++# define __lzo_cdecl_sighandler _cdecl ++# endif ++# else ++# define __lzo_cdecl_sighandler __cdecl ++# endif ++#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) ++# define __lzo_cdecl __cdecl ++#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) ++# define __lzo_cdecl cdecl ++#endif ++#if !defined(__lzo_cdecl) ++# define __lzo_cdecl /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_atexit) ++# define __lzo_cdecl_atexit /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_main) ++# define __lzo_cdecl_main /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_qsort) ++# define __lzo_cdecl_qsort /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_sighandler) ++# define __lzo_cdecl_sighandler /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_va) ++# define __lzo_cdecl_va __lzo_cdecl ++#endif ++#if !(LZO_CFG_NO_WINDOWS_H) ++#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) ++# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) ++# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) ++# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) ++# else ++# define LZO_HAVE_WINDOWS_H 1 ++# endif ++#endif ++#endif ++#if (LZO_ARCH_ALPHA) ++# define LZO_OPT_AVOID_UINT_INDEX 1 ++# define LZO_OPT_AVOID_SHORT 1 ++# define LZO_OPT_AVOID_USHORT 1 ++#elif (LZO_ARCH_AMD64) ++# define LZO_OPT_AVOID_INT_INDEX 1 ++# define LZO_OPT_AVOID_UINT_INDEX 1 ++# define LZO_OPT_UNALIGNED16 1 ++# define LZO_OPT_UNALIGNED32 1 ++# define LZO_OPT_UNALIGNED64 1 ++#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) ++#elif (LZO_ARCH_ARM) ++# define LZO_OPT_AVOID_SHORT 1 ++# define LZO_OPT_AVOID_USHORT 1 ++#elif (LZO_ARCH_CRIS) ++# define LZO_OPT_UNALIGNED16 1 ++# define LZO_OPT_UNALIGNED32 1 ++#elif (LZO_ARCH_I386) ++# define LZO_OPT_UNALIGNED16 1 ++# define LZO_OPT_UNALIGNED32 1 ++#elif (LZO_ARCH_IA64) ++# define LZO_OPT_AVOID_INT_INDEX 1 ++# define LZO_OPT_AVOID_UINT_INDEX 1 ++# define LZO_OPT_PREFER_POSTINC 1 ++#elif (LZO_ARCH_M68K) ++# define LZO_OPT_PREFER_POSTINC 1 ++# define LZO_OPT_PREFER_PREDEC 1 ++# if defined(__mc68020__) && !defined(__mcoldfire__) ++# define LZO_OPT_UNALIGNED16 1 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++#elif (LZO_ARCH_MIPS) ++# define LZO_OPT_AVOID_UINT_INDEX 1 ++#elif (LZO_ARCH_POWERPC) ++# define LZO_OPT_PREFER_PREINC 1 ++# define LZO_OPT_PREFER_PREDEC 1 ++# if (LZO_ABI_BIG_ENDIAN) ++# define LZO_OPT_UNALIGNED16 1 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++#elif (LZO_ARCH_S390) ++# define LZO_OPT_UNALIGNED16 1 ++# define LZO_OPT_UNALIGNED32 1 ++# if (LZO_SIZEOF_SIZE_T == 8) ++# define LZO_OPT_UNALIGNED64 1 ++# endif ++#elif (LZO_ARCH_SH) ++# define LZO_OPT_PREFER_POSTINC 1 ++# define LZO_OPT_PREFER_PREDEC 1 ++#endif ++#ifndef LZO_CFG_NO_INLINE_ASM ++#if (LZO_CC_LLVM) ++# define LZO_CFG_NO_INLINE_ASM 1 ++#endif ++#endif ++#ifndef LZO_CFG_NO_UNALIGNED ++#if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) ++# define LZO_CFG_NO_UNALIGNED 1 ++#endif ++#endif ++#if (LZO_CFG_NO_UNALIGNED) ++# undef LZO_OPT_UNALIGNED16 ++# undef LZO_OPT_UNALIGNED32 ++# undef LZO_OPT_UNALIGNED64 ++#endif ++#if (LZO_CFG_NO_INLINE_ASM) ++#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) ++# define LZO_ASM_SYNTAX_MSC 1 ++#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) ++#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) ++#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) ++# define LZO_ASM_SYNTAX_GNUC 1 ++#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) ++# define LZO_ASM_SYNTAX_GNUC 1 ++#endif ++#if (LZO_ASM_SYNTAX_GNUC) ++#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) ++# define __LZO_ASM_CLOBBER "ax" ++#elif (LZO_CC_INTELC) ++# define __LZO_ASM_CLOBBER "memory" ++#else ++# define __LZO_ASM_CLOBBER "cc", "memory" ++#endif ++#endif ++#if defined(__LZO_INFOSTR_MM) ++#elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) ++# define __LZO_INFOSTR_MM "" ++#elif defined(LZO_INFO_MM) ++# define __LZO_INFOSTR_MM "." LZO_INFO_MM ++#else ++# define __LZO_INFOSTR_MM "" ++#endif ++#if defined(__LZO_INFOSTR_PM) ++#elif defined(LZO_INFO_ABI_PM) ++# define __LZO_INFOSTR_PM "." LZO_INFO_ABI_PM ++#else ++# define __LZO_INFOSTR_PM "" ++#endif ++#if defined(__LZO_INFOSTR_ENDIAN) ++#elif defined(LZO_INFO_ABI_ENDIAN) ++# define __LZO_INFOSTR_ENDIAN "." LZO_INFO_ABI_ENDIAN ++#else ++# define __LZO_INFOSTR_ENDIAN "" ++#endif ++#if defined(__LZO_INFOSTR_OSNAME) ++#elif defined(LZO_INFO_OS_CONSOLE) ++# define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_CONSOLE ++#elif defined(LZO_INFO_OS_POSIX) ++# define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_POSIX ++#else ++# define __LZO_INFOSTR_OSNAME LZO_INFO_OS ++#endif ++#if defined(__LZO_INFOSTR_LIBC) ++#elif defined(LZO_INFO_LIBC) ++# define __LZO_INFOSTR_LIBC "." LZO_INFO_LIBC ++#else ++# define __LZO_INFOSTR_LIBC "" ++#endif ++#if defined(__LZO_INFOSTR_CCVER) ++#elif defined(LZO_INFO_CCVER) ++# define __LZO_INFOSTR_CCVER " " LZO_INFO_CCVER ++#else ++# define __LZO_INFOSTR_CCVER "" ++#endif ++#define LZO_INFO_STRING \ ++ LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ ++ " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER ++ ++#endif /* already included */ ++ ++/* vim:set ts=4 et: */ +Index: b/grub-core/lib/minilzo/minilzo.c +=================================================================== +--- /dev/null ++++ b/grub-core/lib/minilzo/minilzo.c +@@ -0,0 +1,4562 @@ ++/* minilzo.c -- 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/ ++ */ ++ ++#define __LZO_IN_MINILZO 1 ++ ++#if defined(LZO_CFG_FREESTANDING) ++# undef MINILZO_HAVE_CONFIG_H ++# define LZO_LIBC_FREESTANDING 1 ++# define LZO_OS_FREESTANDING 1 ++#endif ++ ++#ifdef MINILZO_HAVE_CONFIG_H ++# include <config.h> ++#endif ++#include <limits.h> ++#include <stddef.h> ++#if defined(MINILZO_CFG_USE_INTERNAL_LZODEFS) ++ ++#ifndef __LZODEFS_H_INCLUDED ++#define __LZODEFS_H_INCLUDED 1 ++ ++#if defined(__CYGWIN32__) && !defined(__CYGWIN__) ++# define __CYGWIN__ __CYGWIN32__ ++#endif ++#if defined(__IBMCPP__) && !defined(__IBMC__) ++# define __IBMC__ __IBMCPP__ ++#endif ++#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) ++# define __INTEL_COMPILER __ICL ++#endif ++#if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) ++# define _ALL_SOURCE 1 ++#endif ++#if defined(__mips__) && defined(__R5900__) ++# if !defined(__LONG_MAX__) ++# define __LONG_MAX__ 9223372036854775807L ++# endif ++#endif ++#if defined(__INTEL_COMPILER) && defined(__linux__) ++# pragma warning(disable: 193) ++#endif ++#if defined(__KEIL__) && defined(__C166__) ++# pragma warning disable = 322 ++#elif 0 && defined(__C251__) ++# pragma warning disable = 322 ++#endif ++#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) ++# if (_MSC_VER >= 1300) ++# pragma warning(disable: 4668) ++# endif ++#endif ++#if 0 && defined(__WATCOMC__) ++# if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) ++# pragma warning 203 9 ++# endif ++#endif ++#if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) ++# pragma option -h ++#endif ++#if 0 ++#define LZO_0xffffL 0xfffful ++#define LZO_0xffffffffL 0xfffffffful ++#else ++#define LZO_0xffffL 65535ul ++#define LZO_0xffffffffL 4294967295ul ++#endif ++#if (LZO_0xffffL == LZO_0xffffffffL) ++# error "your preprocessor is broken 1" ++#endif ++#if (16ul * 16384ul != 262144ul) ++# error "your preprocessor is broken 2" ++#endif ++#if 0 ++#if (32767 >= 4294967295ul) ++# error "your preprocessor is broken 3" ++#endif ++#if (65535u >= 4294967295ul) ++# error "your preprocessor is broken 4" ++#endif ++#endif ++#if (UINT_MAX == LZO_0xffffL) ++#if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) ++# if !defined(MSDOS) ++# define MSDOS 1 ++# endif ++# if !defined(_MSDOS) ++# define _MSDOS 1 ++# endif ++#elif 0 && defined(__VERSION) && defined(MB_LEN_MAX) ++# if (__VERSION == 520) && (MB_LEN_MAX == 1) ++# if !defined(__AZTEC_C__) ++# define __AZTEC_C__ __VERSION ++# endif ++# if !defined(__DOS__) ++# define __DOS__ 1 ++# endif ++# endif ++#endif ++#endif ++#if defined(_MSC_VER) && defined(M_I86HM) && (UINT_MAX == LZO_0xffffL) ++# define ptrdiff_t long ++# define _PTRDIFF_T_DEFINED 1 ++#endif ++#if (UINT_MAX == LZO_0xffffL) ++# undef __LZO_RENAME_A ++# undef __LZO_RENAME_B ++# if defined(__AZTEC_C__) && defined(__DOS__) ++# define __LZO_RENAME_A 1 ++# elif defined(_MSC_VER) && defined(MSDOS) ++# if (_MSC_VER < 600) ++# define __LZO_RENAME_A 1 ++# elif (_MSC_VER < 700) ++# define __LZO_RENAME_B 1 ++# endif ++# elif defined(__TSC__) && defined(__OS2__) ++# define __LZO_RENAME_A 1 ++# elif defined(__MSDOS__) && defined(__TURBOC__) && (__TURBOC__ < 0x0410) ++# define __LZO_RENAME_A 1 ++# elif defined(__PACIFIC__) && defined(DOS) ++# if !defined(__far) ++# define __far far ++# endif ++# if !defined(__near) ++# define __near near ++# endif ++# endif ++# if defined(__LZO_RENAME_A) ++# if !defined(__cdecl) ++# define __cdecl cdecl ++# endif ++# if !defined(__far) ++# define __far far ++# endif ++# if !defined(__huge) ++# define __huge huge ++# endif ++# if !defined(__near) ++# define __near near ++# endif ++# if !defined(__pascal) ++# define __pascal pascal ++# endif ++# if !defined(__huge) ++# define __huge huge ++# endif ++# elif defined(__LZO_RENAME_B) ++# if !defined(__cdecl) ++# define __cdecl _cdecl ++# endif ++# if !defined(__far) ++# define __far _far ++# endif ++# if !defined(__huge) ++# define __huge _huge ++# endif ++# if !defined(__near) ++# define __near _near ++# endif ++# if !defined(__pascal) ++# define __pascal _pascal ++# endif ++# elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__) ++# if !defined(__cdecl) ++# define __cdecl cdecl ++# endif ++# if !defined(__pascal) ++# define __pascal pascal ++# endif ++# endif ++# undef __LZO_RENAME_A ++# undef __LZO_RENAME_B ++#endif ++#if (UINT_MAX == LZO_0xffffL) ++#if defined(__AZTEC_C__) && defined(__DOS__) ++# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 ++#elif defined(_MSC_VER) && defined(MSDOS) ++# if (_MSC_VER < 600) ++# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 ++# endif ++# if (_MSC_VER < 700) ++# define LZO_BROKEN_INTEGRAL_PROMOTION 1 ++# define LZO_BROKEN_SIZEOF 1 ++# endif ++#elif defined(__PACIFIC__) && defined(DOS) ++# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 ++#elif defined(__TURBOC__) && defined(__MSDOS__) ++# if (__TURBOC__ < 0x0150) ++# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 ++# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 ++# define LZO_BROKEN_INTEGRAL_PROMOTION 1 ++# endif ++# if (__TURBOC__ < 0x0200) ++# define LZO_BROKEN_SIZEOF 1 ++# endif ++# if (__TURBOC__ < 0x0400) && defined(__cplusplus) ++# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 ++# endif ++#elif (defined(__PUREC__) || defined(__TURBOC__)) && defined(__TOS__) ++# define LZO_BROKEN_CDECL_ALT_SYNTAX 1 ++# define LZO_BROKEN_SIZEOF 1 ++#endif ++#endif ++#if defined(__WATCOMC__) && (__WATCOMC__ < 900) ++# define LZO_BROKEN_INTEGRAL_CONSTANTS 1 ++#endif ++#if defined(_CRAY) && defined(_CRAY1) ++# define LZO_BROKEN_SIGNED_RIGHT_SHIFT 1 ++#endif ++#define LZO_PP_STRINGIZE(x) #x ++#define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) ++#define LZO_PP_CONCAT2(a,b) a ## b ++#define LZO_PP_CONCAT3(a,b,c) a ## b ## c ++#define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d ++#define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e ++#define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) ++#define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) ++#define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) ++#define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) ++#if 1 ++#define LZO_CPP_STRINGIZE(x) #x ++#define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) ++#define LZO_CPP_CONCAT2(a,b) a ## b ++#define LZO_CPP_CONCAT3(a,b,c) a ## b ## c ++#define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d ++#define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e ++#define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) ++#define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) ++#define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) ++#define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) ++#endif ++#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) ++#if 1 && defined(__cplusplus) ++# if !defined(__STDC_CONSTANT_MACROS) ++# define __STDC_CONSTANT_MACROS 1 ++# endif ++# if !defined(__STDC_LIMIT_MACROS) ++# define __STDC_LIMIT_MACROS 1 ++# endif ++#endif ++#if defined(__cplusplus) ++# define LZO_EXTERN_C extern "C" ++#else ++# define LZO_EXTERN_C extern ++#endif ++#if !defined(__LZO_OS_OVERRIDE) ++#if (LZO_OS_FREESTANDING) ++# define LZO_INFO_OS "freestanding" ++#elif (LZO_OS_EMBEDDED) ++# define LZO_INFO_OS "embedded" ++#elif 1 && defined(__IAR_SYSTEMS_ICC__) ++# define LZO_OS_EMBEDDED 1 ++# define LZO_INFO_OS "embedded" ++#elif defined(__CYGWIN__) && defined(__GNUC__) ++# define LZO_OS_CYGWIN 1 ++# define LZO_INFO_OS "cygwin" ++#elif defined(__EMX__) && defined(__GNUC__) ++# define LZO_OS_EMX 1 ++# define LZO_INFO_OS "emx" ++#elif defined(__BEOS__) ++# define LZO_OS_BEOS 1 ++# define LZO_INFO_OS "beos" ++#elif defined(__Lynx__) ++# define LZO_OS_LYNXOS 1 ++# define LZO_INFO_OS "lynxos" ++#elif defined(__OS400__) ++# define LZO_OS_OS400 1 ++# define LZO_INFO_OS "os400" ++#elif defined(__QNX__) ++# define LZO_OS_QNX 1 ++# define LZO_INFO_OS "qnx" ++#elif defined(__BORLANDC__) && defined(__DPMI32__) && (__BORLANDC__ >= 0x0460) ++# define LZO_OS_DOS32 1 ++# define LZO_INFO_OS "dos32" ++#elif defined(__BORLANDC__) && defined(__DPMI16__) ++# define LZO_OS_DOS16 1 ++# define LZO_INFO_OS "dos16" ++#elif defined(__ZTC__) && defined(DOS386) ++# define LZO_OS_DOS32 1 ++# define LZO_INFO_OS "dos32" ++#elif defined(__OS2__) || defined(__OS2V2__) ++# if (UINT_MAX == LZO_0xffffL) ++# define LZO_OS_OS216 1 ++# define LZO_INFO_OS "os216" ++# elif (UINT_MAX == LZO_0xffffffffL) ++# define LZO_OS_OS2 1 ++# define LZO_INFO_OS "os2" ++# else ++# error "check your limits.h header" ++# endif ++#elif defined(__WIN64__) || defined(_WIN64) || defined(WIN64) ++# define LZO_OS_WIN64 1 ++# define LZO_INFO_OS "win64" ++#elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WINDOWS_386__) ++# define LZO_OS_WIN32 1 ++# define LZO_INFO_OS "win32" ++#elif defined(__MWERKS__) && defined(__INTEL__) ++# define LZO_OS_WIN32 1 ++# define LZO_INFO_OS "win32" ++#elif defined(__WINDOWS__) || defined(_WINDOWS) || defined(_Windows) ++# if (UINT_MAX == LZO_0xffffL) ++# define LZO_OS_WIN16 1 ++# define LZO_INFO_OS "win16" ++# elif (UINT_MAX == LZO_0xffffffffL) ++# define LZO_OS_WIN32 1 ++# define LZO_INFO_OS "win32" ++# else ++# error "check your limits.h header" ++# endif ++#elif defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) || (defined(__PACIFIC__) && defined(DOS)) ++# if (UINT_MAX == LZO_0xffffL) ++# define LZO_OS_DOS16 1 ++# define LZO_INFO_OS "dos16" ++# elif (UINT_MAX == LZO_0xffffffffL) ++# define LZO_OS_DOS32 1 ++# define LZO_INFO_OS "dos32" ++# else ++# error "check your limits.h header" ++# endif ++#elif defined(__WATCOMC__) ++# if defined(__NT__) && (UINT_MAX == LZO_0xffffL) ++# define LZO_OS_DOS16 1 ++# define LZO_INFO_OS "dos16" ++# elif defined(__NT__) && (__WATCOMC__ < 1100) ++# define LZO_OS_WIN32 1 ++# define LZO_INFO_OS "win32" ++# elif defined(__linux__) || defined(__LINUX__) ++# define LZO_OS_POSIX 1 ++# define LZO_INFO_OS "posix" ++# else ++# error "please specify a target using the -bt compiler option" ++# endif ++#elif defined(__palmos__) ++# define LZO_OS_PALMOS 1 ++# define LZO_INFO_OS "palmos" ++#elif defined(__TOS__) || defined(__atarist__) ++# define LZO_OS_TOS 1 ++# define LZO_INFO_OS "tos" ++#elif defined(macintosh) && !defined(__ppc__) ++# define LZO_OS_MACCLASSIC 1 ++# define LZO_INFO_OS "macclassic" ++#elif defined(__VMS) ++# define LZO_OS_VMS 1 ++# define LZO_INFO_OS "vms" ++#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) ++# define LZO_OS_CONSOLE 1 ++# define LZO_OS_CONSOLE_PS2 1 ++# define LZO_INFO_OS "console" ++# define LZO_INFO_OS_CONSOLE "ps2" ++#elif (defined(__mips__) && defined(__psp__)) ++# define LZO_OS_CONSOLE 1 ++# define LZO_OS_CONSOLE_PSP 1 ++# define LZO_INFO_OS "console" ++# define LZO_INFO_OS_CONSOLE "psp" ++#else ++# define LZO_OS_POSIX 1 ++# define LZO_INFO_OS "posix" ++#endif ++#if (LZO_OS_POSIX) ++# if defined(_AIX) || defined(__AIX__) || defined(__aix__) ++# define LZO_OS_POSIX_AIX 1 ++# define LZO_INFO_OS_POSIX "aix" ++# elif defined(__FreeBSD__) ++# define LZO_OS_POSIX_FREEBSD 1 ++# define LZO_INFO_OS_POSIX "freebsd" ++# elif defined(__hpux__) || defined(__hpux) ++# define LZO_OS_POSIX_HPUX 1 ++# define LZO_INFO_OS_POSIX "hpux" ++# elif defined(__INTERIX) ++# define LZO_OS_POSIX_INTERIX 1 ++# define LZO_INFO_OS_POSIX "interix" ++# elif defined(__IRIX__) || defined(__irix__) ++# define LZO_OS_POSIX_IRIX 1 ++# define LZO_INFO_OS_POSIX "irix" ++# elif defined(__linux__) || defined(__linux) || defined(__LINUX__) ++# define LZO_OS_POSIX_LINUX 1 ++# define LZO_INFO_OS_POSIX "linux" ++# elif defined(__APPLE__) || defined(__MACOS__) ++# define LZO_OS_POSIX_MACOSX 1 ++# define LZO_INFO_OS_POSIX "macosx" ++# elif defined(__minix__) || defined(__minix) ++# define LZO_OS_POSIX_MINIX 1 ++# define LZO_INFO_OS_POSIX "minix" ++# elif defined(__NetBSD__) ++# define LZO_OS_POSIX_NETBSD 1 ++# define LZO_INFO_OS_POSIX "netbsd" ++# elif defined(__OpenBSD__) ++# define LZO_OS_POSIX_OPENBSD 1 ++# define LZO_INFO_OS_POSIX "openbsd" ++# elif defined(__osf__) ++# define LZO_OS_POSIX_OSF 1 ++# define LZO_INFO_OS_POSIX "osf" ++# elif defined(__solaris__) || defined(__sun) ++# if defined(__SVR4) || defined(__svr4__) ++# define LZO_OS_POSIX_SOLARIS 1 ++# define LZO_INFO_OS_POSIX "solaris" ++# else ++# define LZO_OS_POSIX_SUNOS 1 ++# define LZO_INFO_OS_POSIX "sunos" ++# endif ++# elif defined(__ultrix__) || defined(__ultrix) ++# define LZO_OS_POSIX_ULTRIX 1 ++# define LZO_INFO_OS_POSIX "ultrix" ++# elif defined(_UNICOS) ++# define LZO_OS_POSIX_UNICOS 1 ++# define LZO_INFO_OS_POSIX "unicos" ++# else ++# define LZO_OS_POSIX_UNKNOWN 1 ++# define LZO_INFO_OS_POSIX "unknown" ++# endif ++#endif ++#endif ++#if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) ++# if (UINT_MAX != LZO_0xffffL) ++# error "this should not happen" ++# endif ++# if (ULONG_MAX != LZO_0xffffffffL) ++# error "this should not happen" ++# endif ++#endif ++#if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) ++# if (UINT_MAX != LZO_0xffffffffL) ++# error "this should not happen" ++# endif ++# if (ULONG_MAX != LZO_0xffffffffL) ++# error "this should not happen" ++# endif ++#endif ++#if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) ++# define LZO_CC_CILLY 1 ++# define LZO_INFO_CC "Cilly" ++# if defined(__CILLY__) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CILLY__) ++# else ++# define LZO_INFO_CCVER "unknown" ++# endif ++#elif 0 && defined(SDCC) && defined(__VERSION__) && !defined(__GNUC__) ++# define LZO_CC_SDCC 1 ++# define LZO_INFO_CC "sdcc" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) ++#elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) ++# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) ++# define LZO_INFO_CC "Pathscale C" ++# define LZO_INFO_CCVER __PATHSCALE__ ++#elif defined(__INTEL_COMPILER) ++# define LZO_CC_INTELC 1 ++# define LZO_INFO_CC "Intel C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) ++# if defined(_WIN32) || defined(_WIN64) ++# define LZO_CC_SYNTAX_MSC 1 ++# else ++# define LZO_CC_SYNTAX_GNUC 1 ++# endif ++#elif defined(__POCC__) && defined(_WIN32) ++# define LZO_CC_PELLESC 1 ++# define LZO_INFO_CC "Pelles C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) ++#elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++# if defined(__GNUC_PATCHLEVEL__) ++# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) ++# else ++# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) ++# endif ++# if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) ++# define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__) ++# else ++# define LZO_CC_CLANG_CLANG 0x010000L ++# endif ++# define LZO_CC_CLANG LZO_CC_CLANG_GNUC ++# define LZO_INFO_CC "clang" ++# define LZO_INFO_CCVER __VERSION__ ++#elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) ++# if defined(__GNUC_PATCHLEVEL__) ++# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) ++# else ++# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) ++# endif ++# define LZO_CC_LLVM LZO_CC_LLVM_GNUC ++# define LZO_INFO_CC "llvm-gcc" ++# define LZO_INFO_CCVER __VERSION__ ++#elif defined(__GNUC__) && defined(__VERSION__) ++# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) ++# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) ++# elif defined(__GNUC_MINOR__) ++# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) ++# else ++# define LZO_CC_GNUC (__GNUC__ * 0x10000L) ++# endif ++# define LZO_INFO_CC "gcc" ++# define LZO_INFO_CCVER __VERSION__ ++#elif defined(__ACK__) && defined(_ACK) ++# define LZO_CC_ACK 1 ++# define LZO_INFO_CC "Amsterdam Compiler Kit C" ++# define LZO_INFO_CCVER "unknown" ++#elif defined(__AZTEC_C__) ++# define LZO_CC_AZTECC 1 ++# define LZO_INFO_CC "Aztec C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__AZTEC_C__) ++#elif defined(__CODEGEARC__) ++# define LZO_CC_CODEGEARC 1 ++# define LZO_INFO_CC "CodeGear C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__CODEGEARC__) ++#elif defined(__BORLANDC__) ++# define LZO_CC_BORLANDC 1 ++# define LZO_INFO_CC "Borland C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__BORLANDC__) ++#elif defined(_CRAYC) && defined(_RELEASE) ++# define LZO_CC_CRAYC 1 ++# define LZO_INFO_CC "Cray C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_RELEASE) ++#elif defined(__DMC__) && defined(__SC__) ++# define LZO_CC_DMC 1 ++# define LZO_INFO_CC "Digital Mars C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DMC__) ++#elif defined(__DECC) ++# define LZO_CC_DECC 1 ++# define LZO_INFO_CC "DEC C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) ++#elif defined(__HIGHC__) ++# define LZO_CC_HIGHC 1 ++# define LZO_INFO_CC "MetaWare High C" ++# define LZO_INFO_CCVER "unknown" ++#elif defined(__IAR_SYSTEMS_ICC__) ++# define LZO_CC_IARC 1 ++# define LZO_INFO_CC "IAR C" ++# if defined(__VER__) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__VER__) ++# else ++# define LZO_INFO_CCVER "unknown" ++# endif ++#elif defined(__IBMC__) ++# define LZO_CC_IBMC 1 ++# define LZO_INFO_CC "IBM C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) ++#elif defined(__KEIL__) && defined(__C166__) ++# define LZO_CC_KEILC 1 ++# define LZO_INFO_CC "Keil C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__C166__) ++#elif defined(__LCC__) && defined(_WIN32) && defined(__LCCOPTIMLEVEL) ++# define LZO_CC_LCCWIN32 1 ++# define LZO_INFO_CC "lcc-win32" ++# define LZO_INFO_CCVER "unknown" ++#elif defined(__LCC__) ++# define LZO_CC_LCC 1 ++# define LZO_INFO_CC "lcc" ++# if defined(__LCC_VERSION__) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__LCC_VERSION__) ++# else ++# define LZO_INFO_CCVER "unknown" ++# endif ++#elif defined(_MSC_VER) ++# define LZO_CC_MSC 1 ++# define LZO_INFO_CC "Microsoft C" ++# if defined(_MSC_FULL_VER) ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) ++# else ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) ++# endif ++#elif defined(__MWERKS__) ++# define LZO_CC_MWERKS 1 ++# define LZO_INFO_CC "Metrowerks C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) ++#elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) ++# define LZO_CC_NDPC 1 ++# define LZO_INFO_CC "Microway NDP C" ++# define LZO_INFO_CCVER "unknown" ++#elif defined(__PACIFIC__) ++# define LZO_CC_PACIFICC 1 ++# define LZO_INFO_CC "Pacific C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) ++#elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) ++# define LZO_CC_PGI 1 ++# define LZO_INFO_CC "Portland Group PGI C" ++# define LZO_INFO_CCVER "unknown" ++#elif defined(__PUREC__) && defined(__TOS__) ++# define LZO_CC_PUREC 1 ++# define LZO_INFO_CC "Pure C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PUREC__) ++#elif defined(__SC__) && defined(__ZTC__) ++# define LZO_CC_SYMANTECC 1 ++# define LZO_INFO_CC "Symantec C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) ++#elif defined(__SUNPRO_C) ++# define LZO_INFO_CC "SunPro C" ++# if ((__SUNPRO_C)+0 > 0) ++# define LZO_CC_SUNPROC __SUNPRO_C ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) ++# else ++# define LZO_CC_SUNPROC 1 ++# define LZO_INFO_CCVER "unknown" ++# endif ++#elif defined(__SUNPRO_CC) ++# define LZO_INFO_CC "SunPro C" ++# if ((__SUNPRO_CC)+0 > 0) ++# define LZO_CC_SUNPROC __SUNPRO_CC ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) ++# else ++# define LZO_CC_SUNPROC 1 ++# define LZO_INFO_CCVER "unknown" ++# endif ++#elif defined(__TINYC__) ++# define LZO_CC_TINYC 1 ++# define LZO_INFO_CC "Tiny C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TINYC__) ++#elif defined(__TSC__) ++# define LZO_CC_TOPSPEEDC 1 ++# define LZO_INFO_CC "TopSpeed C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TSC__) ++#elif defined(__WATCOMC__) ++# define LZO_CC_WATCOMC 1 ++# define LZO_INFO_CC "Watcom C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__WATCOMC__) ++#elif defined(__TURBOC__) ++# define LZO_CC_TURBOC 1 ++# define LZO_INFO_CC "Turbo C" ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__TURBOC__) ++#elif defined(__ZTC__) ++# define LZO_CC_ZORTECHC 1 ++# define LZO_INFO_CC "Zortech C" ++# if (__ZTC__ == 0x310) ++# define LZO_INFO_CCVER "0x310" ++# else ++# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) ++# endif ++#else ++# define LZO_CC_UNKNOWN 1 ++# define LZO_INFO_CC "unknown" ++# define LZO_INFO_CCVER "unknown" ++#endif ++#if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) ++# error "LZO_CC_MSC: _MSC_FULL_VER is not defined" ++#endif ++#if !defined(__LZO_ARCH_OVERRIDE) && !(LZO_ARCH_GENERIC) && defined(_CRAY) ++# if (UINT_MAX > LZO_0xffffffffL) && defined(_CRAY) ++# if defined(_CRAYMPP) || defined(_CRAYT3D) || defined(_CRAYT3E) ++# define LZO_ARCH_CRAY_MPP 1 ++# elif defined(_CRAY1) ++# define LZO_ARCH_CRAY_PVP 1 ++# endif ++# endif ++#endif ++#if !defined(__LZO_ARCH_OVERRIDE) ++#if (LZO_ARCH_GENERIC) ++# define LZO_INFO_ARCH "generic" ++#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) ++# define LZO_ARCH_I086 1 ++# define LZO_ARCH_IA16 1 ++# define LZO_INFO_ARCH "i086" ++#elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) ++# define LZO_ARCH_ALPHA 1 ++# define LZO_INFO_ARCH "alpha" ++#elif (LZO_ARCH_CRAY_MPP) && (defined(_CRAYT3D) || defined(_CRAYT3E)) ++# define LZO_ARCH_ALPHA 1 ++# define LZO_INFO_ARCH "alpha" ++#elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64) ++# define LZO_ARCH_AMD64 1 ++# define LZO_INFO_ARCH "amd64" ++#elif defined(__thumb__) || (defined(_M_ARM) && defined(_M_THUMB)) ++# define LZO_ARCH_ARM 1 ++# define LZO_ARCH_ARM_THUMB 1 ++# define LZO_INFO_ARCH "arm_thumb" ++#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) ++# define LZO_ARCH_ARM 1 ++# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) ++# define LZO_ARCH_ARM_THUMB 1 ++# define LZO_INFO_ARCH "arm_thumb" ++# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) ++# define LZO_INFO_ARCH "arm" ++# else ++# define LZO_INFO_ARCH "arm" ++# endif ++#elif defined(__arm__) || defined(_M_ARM) ++# define LZO_ARCH_ARM 1 ++# define LZO_INFO_ARCH "arm" ++#elif (UINT_MAX <= LZO_0xffffL) && defined(__AVR__) ++# define LZO_ARCH_AVR 1 ++# define LZO_INFO_ARCH "avr" ++#elif defined(__avr32__) || defined(__AVR32__) ++# define LZO_ARCH_AVR32 1 ++# define LZO_INFO_ARCH "avr32" ++#elif defined(__bfin__) ++# define LZO_ARCH_BLACKFIN 1 ++# define LZO_INFO_ARCH "blackfin" ++#elif (UINT_MAX == LZO_0xffffL) && defined(__C166__) ++# define LZO_ARCH_C166 1 ++# define LZO_INFO_ARCH "c166" ++#elif defined(__cris__) ++# define LZO_ARCH_CRIS 1 ++# define LZO_INFO_ARCH "cris" ++#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCEZ80__) ++# define LZO_ARCH_EZ80 1 ++# define LZO_INFO_ARCH "ez80" ++#elif defined(__H8300__) || defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) ++# define LZO_ARCH_H8300 1 ++# define LZO_INFO_ARCH "h8300" ++#elif defined(__hppa__) || defined(__hppa) ++# define LZO_ARCH_HPPA 1 ++# define LZO_INFO_ARCH "hppa" ++#elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386) ++# define LZO_ARCH_I386 1 ++# define LZO_ARCH_IA32 1 ++# define LZO_INFO_ARCH "i386" ++#elif (LZO_CC_ZORTECHC && defined(__I86__)) ++# define LZO_ARCH_I386 1 ++# define LZO_ARCH_IA32 1 ++# define LZO_INFO_ARCH "i386" ++#elif (LZO_OS_DOS32 && LZO_CC_HIGHC) && defined(_I386) ++# define LZO_ARCH_I386 1 ++# define LZO_ARCH_IA32 1 ++# define LZO_INFO_ARCH "i386" ++#elif defined(__ia64__) || defined(__ia64) || defined(_M_IA64) ++# define LZO_ARCH_IA64 1 ++# define LZO_INFO_ARCH "ia64" ++#elif (UINT_MAX == LZO_0xffffL) && defined(__m32c__) ++# define LZO_ARCH_M16C 1 ++# define LZO_INFO_ARCH "m16c" ++#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCM16C__) ++# define LZO_ARCH_M16C 1 ++# define LZO_INFO_ARCH "m16c" ++#elif defined(__m32r__) ++# define LZO_ARCH_M32R 1 ++# define LZO_INFO_ARCH "m32r" ++#elif (LZO_OS_TOS) || defined(__m68k__) || defined(__m68000__) || defined(__mc68000__) || defined(__mc68020__) || defined(_M_M68K) ++# define LZO_ARCH_M68K 1 ++# define LZO_INFO_ARCH "m68k" ++#elif (UINT_MAX == LZO_0xffffL) && defined(__C251__) ++# define LZO_ARCH_MCS251 1 ++# define LZO_INFO_ARCH "mcs251" ++#elif (UINT_MAX == LZO_0xffffL) && defined(__C51__) ++# define LZO_ARCH_MCS51 1 ++# define LZO_INFO_ARCH "mcs51" ++#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC8051__) ++# define LZO_ARCH_MCS51 1 ++# define LZO_INFO_ARCH "mcs51" ++#elif defined(__mips__) || defined(__mips) || defined(_MIPS_ARCH) || defined(_M_MRX000) ++# define LZO_ARCH_MIPS 1 ++# define LZO_INFO_ARCH "mips" ++#elif (UINT_MAX == LZO_0xffffL) && defined(__MSP430__) ++# define LZO_ARCH_MSP430 1 ++# define LZO_INFO_ARCH "msp430" ++#elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICC430__) ++# define LZO_ARCH_MSP430 1 ++# define LZO_INFO_ARCH "msp430" ++#elif defined(__powerpc__) || defined(__powerpc) || defined(__ppc__) || defined(__PPC__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PWR) ++# define LZO_ARCH_POWERPC 1 ++# define LZO_INFO_ARCH "powerpc" ++#elif defined(__s390__) || defined(__s390) || defined(__s390x__) || defined(__s390x) ++# define LZO_ARCH_S390 1 ++# define LZO_INFO_ARCH "s390" ++#elif defined(__sh__) || defined(_M_SH) ++# define LZO_ARCH_SH 1 ++# define LZO_INFO_ARCH "sh" ++#elif defined(__sparc__) || defined(__sparc) || defined(__sparcv8) ++# define LZO_ARCH_SPARC 1 ++# define LZO_INFO_ARCH "sparc" ++#elif defined(__SPU__) ++# define LZO_ARCH_SPU 1 ++# define LZO_INFO_ARCH "spu" ++#elif (UINT_MAX == LZO_0xffffL) && defined(__z80) ++# define LZO_ARCH_Z80 1 ++# define LZO_INFO_ARCH "z80" ++#elif (LZO_ARCH_CRAY_PVP) ++# if defined(_CRAYSV1) ++# define LZO_ARCH_CRAY_SV1 1 ++# define LZO_INFO_ARCH "cray_sv1" ++# elif (_ADDR64) ++# define LZO_ARCH_CRAY_T90 1 ++# define LZO_INFO_ARCH "cray_t90" ++# elif (_ADDR32) ++# define LZO_ARCH_CRAY_YMP 1 ++# define LZO_INFO_ARCH "cray_ymp" ++# else ++# define LZO_ARCH_CRAY_XMP 1 ++# define LZO_INFO_ARCH "cray_xmp" ++# endif ++#else ++# define LZO_ARCH_UNKNOWN 1 ++# define LZO_INFO_ARCH "unknown" ++#endif ++#endif ++#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2) ++# error "FIXME - missing define for CPU architecture" ++#endif ++#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) ++# error "FIXME - missing WIN32 define for CPU architecture" ++#endif ++#if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) ++# error "FIXME - missing WIN64 define for CPU architecture" ++#endif ++#if (LZO_OS_OS216 || LZO_OS_WIN16) ++# define LZO_ARCH_I086PM 1 ++# define LZO_ARCH_IA16PM 1 ++#elif 1 && (LZO_OS_DOS16 && defined(BLX286)) ++# define LZO_ARCH_I086PM 1 ++# define LZO_ARCH_IA16PM 1 ++#elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) ++# define LZO_ARCH_I086PM 1 ++# define LZO_ARCH_IA16PM 1 ++#elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) ++# define LZO_ARCH_I086PM 1 ++# define LZO_ARCH_IA16PM 1 ++#endif ++#if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM) ++# error "this should not happen" ++#endif ++#if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086) ++# error "this should not happen" ++#endif ++#if (LZO_ARCH_I086) ++# if (UINT_MAX != LZO_0xffffL) ++# error "this should not happen" ++# endif ++# if (ULONG_MAX != LZO_0xffffffffL) ++# error "this should not happen" ++# endif ++#endif ++#if (LZO_ARCH_I386) ++# if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) ++# error "this should not happen" ++# endif ++# if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) ++# error "this should not happen" ++# endif ++# if (ULONG_MAX != LZO_0xffffffffL) ++# error "this should not happen" ++# endif ++#endif ++#if !defined(__LZO_MM_OVERRIDE) ++#if (LZO_ARCH_I086) ++#if (UINT_MAX != LZO_0xffffL) ++# error "this should not happen" ++#endif ++#if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) ++# define LZO_MM_TINY 1 ++#elif defined(__HUGE__) || defined(_HUGE_) || defined(M_I86HM) || defined(_M_I86HM) ++# define LZO_MM_HUGE 1 ++#elif defined(__SMALL__) || defined(M_I86SM) || defined(_M_I86SM) || defined(SMALL_MODEL) ++# define LZO_MM_SMALL 1 ++#elif defined(__MEDIUM__) || defined(M_I86MM) || defined(_M_I86MM) ++# define LZO_MM_MEDIUM 1 ++#elif defined(__COMPACT__) || defined(M_I86CM) || defined(_M_I86CM) ++# define LZO_MM_COMPACT 1 ++#elif defined(__LARGE__) || defined(M_I86LM) || defined(_M_I86LM) || defined(LARGE_MODEL) ++# define LZO_MM_LARGE 1 ++#elif (LZO_CC_AZTECC) ++# if defined(_LARGE_CODE) && defined(_LARGE_DATA) ++# define LZO_MM_LARGE 1 ++# elif defined(_LARGE_CODE) ++# define LZO_MM_MEDIUM 1 ++# elif defined(_LARGE_DATA) ++# define LZO_MM_COMPACT 1 ++# else ++# define LZO_MM_SMALL 1 ++# endif ++#elif (LZO_CC_ZORTECHC && defined(__VCM__)) ++# define LZO_MM_LARGE 1 ++#else ++# error "unknown memory model" ++#endif ++#if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) ++#define LZO_HAVE_MM_HUGE_PTR 1 ++#define LZO_HAVE_MM_HUGE_ARRAY 1 ++#if (LZO_MM_TINY) ++# undef LZO_HAVE_MM_HUGE_ARRAY ++#endif ++#if (LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_ZORTECHC) ++# undef LZO_HAVE_MM_HUGE_PTR ++# undef LZO_HAVE_MM_HUGE_ARRAY ++#elif (LZO_CC_DMC || LZO_CC_SYMANTECC) ++# undef LZO_HAVE_MM_HUGE_ARRAY ++#elif (LZO_CC_MSC && defined(_QC)) ++# undef LZO_HAVE_MM_HUGE_ARRAY ++# if (_MSC_VER < 600) ++# undef LZO_HAVE_MM_HUGE_PTR ++# endif ++#elif (LZO_CC_TURBOC && (__TURBOC__ < 0x0295)) ++# undef LZO_HAVE_MM_HUGE_ARRAY ++#endif ++#if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR) ++# if (LZO_OS_DOS16) ++# error "this should not happen" ++# elif (LZO_CC_ZORTECHC) ++# else ++# error "this should not happen" ++# endif ++#endif ++#ifdef __cplusplus ++extern "C" { ++#endif ++#if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200)) ++ extern void __near __cdecl _AHSHIFT(void); ++# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) ++#elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) ++ extern void __near __cdecl _AHSHIFT(void); ++# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) ++#elif (LZO_CC_MSC || LZO_CC_TOPSPEEDC) ++ extern void __near __cdecl _AHSHIFT(void); ++# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) ++#elif (LZO_CC_TURBOC && (__TURBOC__ >= 0x0295)) ++ extern void __near __cdecl _AHSHIFT(void); ++# define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) ++#elif ((LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_TURBOC) && LZO_OS_DOS16) ++# define LZO_MM_AHSHIFT 12 ++#elif (LZO_CC_WATCOMC) ++ extern unsigned char _HShift; ++# define LZO_MM_AHSHIFT ((unsigned) _HShift) ++#else ++# error "FIXME - implement LZO_MM_AHSHIFT" ++#endif ++#ifdef __cplusplus ++} ++#endif ++#endif ++#elif (LZO_ARCH_C166) ++#if !defined(__MODEL__) ++# error "FIXME - C166 __MODEL__" ++#elif ((__MODEL__) == 0) ++# define LZO_MM_SMALL 1 ++#elif ((__MODEL__) == 1) ++# define LZO_MM_SMALL 1 ++#elif ((__MODEL__) == 2) ++# define LZO_MM_LARGE 1 ++#elif ((__MODEL__) == 3) ++# define LZO_MM_TINY 1 ++#elif ((__MODEL__) == 4) ++# define LZO_MM_XTINY 1 ++#elif ((__MODEL__) == 5) ++# define LZO_MM_XSMALL 1 ++#else ++# error "FIXME - C166 __MODEL__" ++#endif ++#elif (LZO_ARCH_MCS251) ++#if !defined(__MODEL__) ++# error "FIXME - MCS251 __MODEL__" ++#elif ((__MODEL__) == 0) ++# define LZO_MM_SMALL 1 ++#elif ((__MODEL__) == 2) ++# define LZO_MM_LARGE 1 ++#elif ((__MODEL__) == 3) ++# define LZO_MM_TINY 1 ++#elif ((__MODEL__) == 4) ++# define LZO_MM_XTINY 1 ++#elif ((__MODEL__) == 5) ++# define LZO_MM_XSMALL 1 ++#else ++# error "FIXME - MCS251 __MODEL__" ++#endif ++#elif (LZO_ARCH_MCS51) ++#if !defined(__MODEL__) ++# error "FIXME - MCS51 __MODEL__" ++#elif ((__MODEL__) == 1) ++# define LZO_MM_SMALL 1 ++#elif ((__MODEL__) == 2) ++# define LZO_MM_LARGE 1 ++#elif ((__MODEL__) == 3) ++# define LZO_MM_TINY 1 ++#elif ((__MODEL__) == 4) ++# define LZO_MM_XTINY 1 ++#elif ((__MODEL__) == 5) ++# define LZO_MM_XSMALL 1 ++#else ++# error "FIXME - MCS51 __MODEL__" ++#endif ++#elif (LZO_ARCH_CRAY_PVP) ++# define LZO_MM_PVP 1 ++#else ++# define LZO_MM_FLAT 1 ++#endif ++#if (LZO_MM_COMPACT) ++# define LZO_INFO_MM "compact" ++#elif (LZO_MM_FLAT) ++# define LZO_INFO_MM "flat" ++#elif (LZO_MM_HUGE) ++# define LZO_INFO_MM "huge" ++#elif (LZO_MM_LARGE) ++# define LZO_INFO_MM "large" ++#elif (LZO_MM_MEDIUM) ++# define LZO_INFO_MM "medium" ++#elif (LZO_MM_PVP) ++# define LZO_INFO_MM "pvp" ++#elif (LZO_MM_SMALL) ++# define LZO_INFO_MM "small" ++#elif (LZO_MM_TINY) ++# define LZO_INFO_MM "tiny" ++#else ++# error "unknown memory model" ++#endif ++#endif ++#if defined(SIZEOF_SHORT) ++# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) ++#endif ++#if defined(SIZEOF_INT) ++# define LZO_SIZEOF_INT (SIZEOF_INT) ++#endif ++#if defined(SIZEOF_LONG) ++# define LZO_SIZEOF_LONG (SIZEOF_LONG) ++#endif ++#if defined(SIZEOF_LONG_LONG) ++# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) ++#endif ++#if defined(SIZEOF___INT16) ++# define LZO_SIZEOF___INT16 (SIZEOF___INT16) ++#endif ++#if defined(SIZEOF___INT32) ++# define LZO_SIZEOF___INT32 (SIZEOF___INT32) ++#endif ++#if defined(SIZEOF___INT64) ++# define LZO_SIZEOF___INT64 (SIZEOF___INT64) ++#endif ++#if defined(SIZEOF_VOID_P) ++# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) ++#endif ++#if defined(SIZEOF_SIZE_T) ++# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) ++#endif ++#if defined(SIZEOF_PTRDIFF_T) ++# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) ++#endif ++#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) ++#if !defined(LZO_SIZEOF_SHORT) ++# if (LZO_ARCH_CRAY_PVP) ++# define LZO_SIZEOF_SHORT 8 ++# elif (USHRT_MAX == LZO_0xffffL) ++# define LZO_SIZEOF_SHORT 2 ++# elif (__LZO_LSR(USHRT_MAX,7) == 1) ++# define LZO_SIZEOF_SHORT 1 ++# elif (__LZO_LSR(USHRT_MAX,15) == 1) ++# define LZO_SIZEOF_SHORT 2 ++# elif (__LZO_LSR(USHRT_MAX,31) == 1) ++# define LZO_SIZEOF_SHORT 4 ++# elif (__LZO_LSR(USHRT_MAX,63) == 1) ++# define LZO_SIZEOF_SHORT 8 ++# elif (__LZO_LSR(USHRT_MAX,127) == 1) ++# define LZO_SIZEOF_SHORT 16 ++# else ++# error "LZO_SIZEOF_SHORT" ++# endif ++#endif ++#if !defined(LZO_SIZEOF_INT) ++# if (LZO_ARCH_CRAY_PVP) ++# define LZO_SIZEOF_INT 8 ++# elif (UINT_MAX == LZO_0xffffL) ++# define LZO_SIZEOF_INT 2 ++# elif (UINT_MAX == LZO_0xffffffffL) ++# define LZO_SIZEOF_INT 4 ++# elif (__LZO_LSR(UINT_MAX,7) == 1) ++# define LZO_SIZEOF_INT 1 ++# elif (__LZO_LSR(UINT_MAX,15) == 1) ++# define LZO_SIZEOF_INT 2 ++# elif (__LZO_LSR(UINT_MAX,31) == 1) ++# define LZO_SIZEOF_INT 4 ++# elif (__LZO_LSR(UINT_MAX,63) == 1) ++# define LZO_SIZEOF_INT 8 ++# elif (__LZO_LSR(UINT_MAX,127) == 1) ++# define LZO_SIZEOF_INT 16 ++# else ++# error "LZO_SIZEOF_INT" ++# endif ++#endif ++#if !defined(LZO_SIZEOF_LONG) ++# if (ULONG_MAX == LZO_0xffffffffL) ++# define LZO_SIZEOF_LONG 4 ++# elif (__LZO_LSR(ULONG_MAX,7) == 1) ++# define LZO_SIZEOF_LONG 1 ++# elif (__LZO_LSR(ULONG_MAX,15) == 1) ++# define LZO_SIZEOF_LONG 2 ++# elif (__LZO_LSR(ULONG_MAX,31) == 1) ++# define LZO_SIZEOF_LONG 4 ++# elif (__LZO_LSR(ULONG_MAX,63) == 1) ++# define LZO_SIZEOF_LONG 8 ++# elif (__LZO_LSR(ULONG_MAX,127) == 1) ++# define LZO_SIZEOF_LONG 16 ++# else ++# error "LZO_SIZEOF_LONG" ++# endif ++#endif ++#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) ++#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) ++# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) ++# if (LZO_CC_GNUC >= 0x030300ul) ++# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) ++# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG ++# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) ++# define LZO_SIZEOF_LONG_LONG 4 ++# endif ++# endif ++# endif ++#endif ++#endif ++#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) ++#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) ++#if (LZO_ARCH_I086 && LZO_CC_DMC) ++#elif (LZO_CC_CILLY) && defined(__GNUC__) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_OS_WIN64 || defined(_WIN64)) ++# define LZO_SIZEOF___INT64 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) ++# define LZO_SIZEOF___INT64 8 ++#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) ++# define LZO_SIZEOF___INT64 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) ++# define LZO_SIZEOF___INT64 8 ++#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) ++# define LZO_SIZEOF___INT64 8 ++#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) ++# define LZO_SIZEOF___INT64 8 ++#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) ++# define LZO_SIZEOF_LONG_LONG 8 ++#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) ++#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ++# define LZO_SIZEOF_LONG_LONG 8 ++#endif ++#endif ++#endif ++#if defined(__cplusplus) && (LZO_CC_GNUC) ++# if (LZO_CC_GNUC < 0x020800ul) ++# undef LZO_SIZEOF_LONG_LONG ++# endif ++#endif ++#if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) ++# undef LZO_SIZEOF_LONG_LONG ++#endif ++#if !defined(LZO_SIZEOF_VOID_P) ++#if (LZO_ARCH_I086) ++# define __LZO_WORDSIZE 2 ++# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) ++# define LZO_SIZEOF_VOID_P 2 ++# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) ++# define LZO_SIZEOF_VOID_P 4 ++# else ++# error "LZO_MM" ++# endif ++#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) ++# define __LZO_WORDSIZE 1 ++# define LZO_SIZEOF_VOID_P 2 ++#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) ++# define LZO_SIZEOF_VOID_P 2 ++#elif (LZO_ARCH_H8300) ++# if defined(__NORMAL_MODE__) ++# define __LZO_WORDSIZE 4 ++# define LZO_SIZEOF_VOID_P 2 ++# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) ++# define __LZO_WORDSIZE 4 ++# define LZO_SIZEOF_VOID_P 4 ++# else ++# define __LZO_WORDSIZE 2 ++# define LZO_SIZEOF_VOID_P 2 ++# endif ++# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT ++# endif ++#elif (LZO_ARCH_M16C) ++# define __LZO_WORDSIZE 2 ++# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) ++# define LZO_SIZEOF_VOID_P 4 ++# else ++# define LZO_SIZEOF_VOID_P 2 ++# endif ++#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) ++# define __LZO_WORDSIZE 8 ++# define LZO_SIZEOF_VOID_P 4 ++#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) ++# define __LZO_WORDSIZE 8 ++# define LZO_SIZEOF_VOID_P 8 ++#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) ++# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG ++#elif (LZO_OS_OS400 || defined(__OS400__)) ++# define __LZO_WORDSIZE LZO_SIZEOF_LONG ++# define LZO_SIZEOF_VOID_P 16 ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG ++#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) ++# define LZO_SIZEOF_VOID_P 8 ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG ++#elif (LZO_ARCH_SPU) ++# if 0 ++# define __LZO_WORDSIZE 16 ++# endif ++# define LZO_SIZEOF_VOID_P 4 ++#else ++# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG ++#endif ++#endif ++#if !defined(LZO_WORDSIZE) ++# if defined(__LZO_WORDSIZE) ++# define LZO_WORDSIZE __LZO_WORDSIZE ++# else ++# define LZO_WORDSIZE LZO_SIZEOF_VOID_P ++# endif ++#endif ++#if !defined(LZO_SIZEOF_SIZE_T) ++#if (LZO_ARCH_I086 || LZO_ARCH_M16C) ++# define LZO_SIZEOF_SIZE_T 2 ++#else ++# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P ++#endif ++#endif ++#if !defined(LZO_SIZEOF_PTRDIFF_T) ++#if (LZO_ARCH_I086) ++# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P ++# elif (LZO_MM_COMPACT || LZO_MM_LARGE) ++# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) ++# define LZO_SIZEOF_PTRDIFF_T 4 ++# else ++# define LZO_SIZEOF_PTRDIFF_T 2 ++# endif ++# else ++# error "LZO_MM" ++# endif ++#else ++# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T ++#endif ++#endif ++#if (LZO_ABI_NEUTRAL_ENDIAN) ++# undef LZO_ABI_BIG_ENDIAN ++# undef LZO_ABI_LITTLE_ENDIAN ++#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) ++#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) ++# define LZO_ABI_BIG_ENDIAN 1 ++#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) ++# define LZO_ABI_LITTLE_ENDIAN 1 ++#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) ++# define LZO_ABI_LITTLE_ENDIAN 1 ++#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390) ++# define LZO_ABI_BIG_ENDIAN 1 ++#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) ++# if (__LITTLE_ENDIAN__ == 1) ++# define LZO_ABI_LITTLE_ENDIAN 1 ++# else ++# define LZO_ABI_BIG_ENDIAN 1 ++# endif ++#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) ++# define LZO_ABI_BIG_ENDIAN 1 ++#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) ++# define LZO_ABI_LITTLE_ENDIAN 1 ++#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) ++# define LZO_ABI_BIG_ENDIAN 1 ++#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) ++# define LZO_ABI_LITTLE_ENDIAN 1 ++#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) ++# define LZO_ABI_BIG_ENDIAN 1 ++#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) ++# define LZO_ABI_LITTLE_ENDIAN 1 ++#endif ++#endif ++#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) ++# error "this should not happen" ++#endif ++#if (LZO_ABI_BIG_ENDIAN) ++# define LZO_INFO_ABI_ENDIAN "be" ++#elif (LZO_ABI_LITTLE_ENDIAN) ++# define LZO_INFO_ABI_ENDIAN "le" ++#elif (LZO_ABI_NEUTRAL_ENDIAN) ++# define LZO_INFO_ABI_ENDIAN "neutral" ++#endif ++#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) ++# define LZO_ABI_I8LP16 1 ++# define LZO_INFO_ABI_PM "i8lp16" ++#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) ++# define LZO_ABI_ILP16 1 ++# define LZO_INFO_ABI_PM "ilp16" ++#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) ++# define LZO_ABI_ILP32 1 ++# define LZO_INFO_ABI_PM "ilp32" ++#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) ++# define LZO_ABI_LLP64 1 ++# define LZO_INFO_ABI_PM "llp64" ++#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) ++# define LZO_ABI_LP64 1 ++# define LZO_INFO_ABI_PM "lp64" ++#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) ++# define LZO_ABI_ILP64 1 ++# define LZO_INFO_ABI_PM "ilp64" ++#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) ++# define LZO_ABI_IP32L64 1 ++# define LZO_INFO_ABI_PM "ip32l64" ++#endif ++#if !defined(__LZO_LIBC_OVERRIDE) ++#if (LZO_LIBC_NAKED) ++# define LZO_INFO_LIBC "naked" ++#elif (LZO_LIBC_FREESTANDING) ++# define LZO_INFO_LIBC "freestanding" ++#elif (LZO_LIBC_MOSTLY_FREESTANDING) ++# define LZO_INFO_LIBC "mfreestanding" ++#elif (LZO_LIBC_ISOC90) ++# define LZO_INFO_LIBC "isoc90" ++#elif (LZO_LIBC_ISOC99) ++# define LZO_INFO_LIBC "isoc99" ++#elif defined(__dietlibc__) ++# define LZO_LIBC_DIETLIBC 1 ++# define LZO_INFO_LIBC "dietlibc" ++#elif defined(_NEWLIB_VERSION) ++# define LZO_LIBC_NEWLIB 1 ++# define LZO_INFO_LIBC "newlib" ++#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) ++# if defined(__UCLIBC_SUBLEVEL__) ++# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) ++# else ++# define LZO_LIBC_UCLIBC 0x00090bL ++# endif ++# define LZO_INFO_LIBC "uclibc" ++#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) ++# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) ++# define LZO_INFO_LIBC "glibc" ++#elif (LZO_CC_MWERKS) && defined(__MSL__) ++# define LZO_LIBC_MSL __MSL__ ++# define LZO_INFO_LIBC "msl" ++#elif 1 && defined(__IAR_SYSTEMS_ICC__) ++# define LZO_LIBC_ISOC90 1 ++# define LZO_INFO_LIBC "isoc90" ++#else ++# define LZO_LIBC_DEFAULT 1 ++# define LZO_INFO_LIBC "default" ++#endif ++#endif ++#if !defined(__lzo_gnuc_extension__) ++#if (LZO_CC_GNUC >= 0x020800ul) ++# define __lzo_gnuc_extension__ __extension__ ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_gnuc_extension__ __extension__ ++#else ++# define __lzo_gnuc_extension__ /*empty*/ ++#endif ++#endif ++#if !defined(__lzo_ua_volatile) ++# define __lzo_ua_volatile volatile ++#endif ++#if !defined(__lzo_alignof) ++#if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) ++# define __lzo_alignof(e) __alignof__(e) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) ++# define __lzo_alignof(e) __alignof__(e) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_alignof(e) __alignof(e) ++#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_alignof(e) __alignof__(e) ++#endif ++#endif ++#if defined(__lzo_alignof) ++# define __lzo_HAVE_alignof 1 ++#endif ++#if !defined(__lzo_constructor) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_constructor __attribute__((__constructor__,__used__)) ++#elif (LZO_CC_GNUC >= 0x020700ul) ++# define __lzo_constructor __attribute__((__constructor__)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_constructor __attribute__((__constructor__)) ++#endif ++#endif ++#if defined(__lzo_constructor) ++# define __lzo_HAVE_constructor 1 ++#endif ++#if !defined(__lzo_destructor) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_destructor __attribute__((__destructor__,__used__)) ++#elif (LZO_CC_GNUC >= 0x020700ul) ++# define __lzo_destructor __attribute__((__destructor__)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_destructor __attribute__((__destructor__)) ++#endif ++#endif ++#if defined(__lzo_destructor) ++# define __lzo_HAVE_destructor 1 ++#endif ++#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) ++# error "this should not happen" ++#endif ++#if !defined(__lzo_inline) ++#if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) ++#elif defined(__cplusplus) ++# define __lzo_inline inline ++#elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) ++# define __lzo_inline __inline ++#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) ++# define __lzo_inline __inline__ ++#elif (LZO_CC_DMC) ++# define __lzo_inline __inline ++#elif (LZO_CC_INTELC) ++# define __lzo_inline __inline ++#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) ++# define __lzo_inline __inline ++#elif (LZO_CC_MSC && (_MSC_VER >= 900)) ++# define __lzo_inline __inline ++#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_inline __inline__ ++#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) ++# define __lzo_inline inline ++#endif ++#endif ++#if defined(__lzo_inline) ++# define __lzo_HAVE_inline 1 ++#else ++# define __lzo_inline /*empty*/ ++#endif ++#if !defined(__lzo_forceinline) ++#if (LZO_CC_GNUC >= 0x030200ul) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) ++# define __lzo_forceinline __forceinline ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) ++# define __lzo_forceinline __forceinline ++#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) ++#endif ++#endif ++#if defined(__lzo_forceinline) ++# define __lzo_HAVE_forceinline 1 ++#else ++# define __lzo_forceinline /*empty*/ ++#endif ++#if !defined(__lzo_noinline) ++#if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) ++# define __lzo_noinline __attribute__((__noinline__,__used__)) ++#elif (LZO_CC_GNUC >= 0x030200ul) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) ++# define __lzo_noinline __declspec(noinline) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_noinline __attribute__((__noinline__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# define __lzo_noinline __declspec(noinline) ++#elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x3200) && (LZO_OS_WIN32 || LZO_OS_WIN64)) ++# if defined(__cplusplus) ++# else ++# define __lzo_noinline __declspec(noinline) ++# endif ++#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) ++# define __lzo_noinline __attribute__((__noinline__)) ++#endif ++#endif ++#if defined(__lzo_noinline) ++# define __lzo_HAVE_noinline 1 ++#else ++# define __lzo_noinline /*empty*/ ++#endif ++#if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) ++# error "this should not happen" ++#endif ++#if !defined(__lzo_noreturn) ++#if (LZO_CC_GNUC >= 0x020700ul) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) ++# define __lzo_noreturn __declspec(noreturn) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_noreturn __attribute__((__noreturn__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) ++# define __lzo_noreturn __declspec(noreturn) ++#endif ++#endif ++#if defined(__lzo_noreturn) ++# define __lzo_HAVE_noreturn 1 ++#else ++# define __lzo_noreturn /*empty*/ ++#endif ++#if !defined(__lzo_nothrow) ++#if (LZO_CC_GNUC >= 0x030300ul) ++# define __lzo_nothrow __attribute__((__nothrow__)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) ++# define __lzo_nothrow __declspec(nothrow) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC) ++# define __lzo_nothrow __attribute__((__nothrow__)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_nothrow __attribute__((__nothrow__)) ++#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) ++# define __lzo_nothrow __declspec(nothrow) ++#endif ++#endif ++#if defined(__lzo_nothrow) ++# define __lzo_HAVE_nothrow 1 ++#else ++# define __lzo_nothrow /*empty*/ ++#endif ++#if !defined(__lzo_restrict) ++#if (LZO_CC_GNUC >= 0x030400ul) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_CLANG || LZO_CC_LLVM) ++# define __lzo_restrict __restrict__ ++#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) ++# define __lzo_restrict __restrict ++#endif ++#endif ++#if defined(__lzo_restrict) ++# define __lzo_HAVE_restrict 1 ++#else ++# define __lzo_restrict /*empty*/ ++#endif ++#if !defined(__lzo_likely) && !defined(__lzo_unlikely) ++#if (LZO_CC_GNUC >= 0x030200ul) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define __lzo_likely(e) (__builtin_expect(!!(e),1)) ++# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) ++#endif ++#endif ++#if defined(__lzo_likely) ++# define __lzo_HAVE_likely 1 ++#else ++# define __lzo_likely(e) (e) ++#endif ++#if defined(__lzo_unlikely) ++# define __lzo_HAVE_unlikely 1 ++#else ++# define __lzo_unlikely(e) (e) ++#endif ++#if !defined(LZO_UNUSED) ++# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) ++# define LZO_UNUSED(var) ((void) &var) ++# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) ++# define LZO_UNUSED(var) if (&var) ; else ++# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNUSED(var) ((void) var) ++# elif (LZO_CC_MSC && (_MSC_VER < 900)) ++# define LZO_UNUSED(var) if (&var) ; else ++# elif (LZO_CC_KEILC) ++# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} ++# elif (LZO_CC_PACIFICC) ++# define LZO_UNUSED(var) ((void) sizeof(var)) ++# elif (LZO_CC_WATCOMC) && defined(__cplusplus) ++# define LZO_UNUSED(var) ((void) var) ++# else ++# define LZO_UNUSED(var) ((void) &var) ++# endif ++#endif ++#if !defined(LZO_UNUSED_FUNC) ++# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) ++# define LZO_UNUSED_FUNC(func) ((void) func) ++# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) ++# define LZO_UNUSED_FUNC(func) if (func) ; else ++# elif (LZO_CC_CLANG || LZO_CC_LLVM) ++# define LZO_UNUSED_FUNC(func) ((void) &func) ++# elif (LZO_CC_MSC && (_MSC_VER < 900)) ++# define LZO_UNUSED_FUNC(func) if (func) ; else ++# elif (LZO_CC_MSC) ++# define LZO_UNUSED_FUNC(func) ((void) &func) ++# elif (LZO_CC_KEILC || LZO_CC_PELLESC) ++# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} ++# else ++# define LZO_UNUSED_FUNC(func) ((void) func) ++# endif ++#endif ++#if !defined(LZO_UNUSED_LABEL) ++# if (LZO_CC_WATCOMC) && defined(__cplusplus) ++# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l ++# elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) ++# define LZO_UNUSED_LABEL(l) if (0) goto l ++# else ++# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l ++# endif ++#endif ++#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) ++# if 0 ++# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var ++# elif 0 && (LZO_CC_GNUC) ++# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var ++# else ++# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init ++# endif ++#endif ++#if !defined(LZO_UNCONST_CAST) ++# if 0 && defined(__cplusplus) ++# define LZO_UNCONST_CAST(t,e) (const_cast<t> (e)) ++# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) ++# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e)))))) ++# else ++# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e))))) ++# endif ++#endif ++#if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) ++# if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; ++# elif (LZO_CC_DMC || LZO_CC_SYMANTECC) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; ++# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; ++# else ++# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; ++# endif ++#endif ++#if !defined(LZO_COMPILE_TIME_ASSERT) ++# if (LZO_CC_AZTECC) ++# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} ++# elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) ++# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; ++# elif (LZO_CC_MSC && (_MSC_VER < 900)) ++# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; ++# elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) ++# define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; ++# else ++# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} ++# endif ++#endif ++#if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) ++# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) ++# elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) ++# define __lzo_cdecl __cdecl ++# define __lzo_cdecl_atexit /*empty*/ ++# define __lzo_cdecl_main __cdecl ++# if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) ++# define __lzo_cdecl_qsort __pascal ++# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) ++# define __lzo_cdecl_qsort _stdcall ++# else ++# define __lzo_cdecl_qsort __cdecl ++# endif ++# elif (LZO_CC_WATCOMC) ++# define __lzo_cdecl __cdecl ++# else ++# define __lzo_cdecl __cdecl ++# define __lzo_cdecl_atexit __cdecl ++# define __lzo_cdecl_main __cdecl ++# define __lzo_cdecl_qsort __cdecl ++# endif ++# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC) ++# elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) ++# define __lzo_cdecl_sighandler __pascal ++# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) ++# define __lzo_cdecl_sighandler _stdcall ++# elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE) ++# define __lzo_cdecl_sighandler __clrcall ++# elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700)) ++# if defined(_DLL) ++# define __lzo_cdecl_sighandler _far _cdecl _loadds ++# elif defined(_MT) ++# define __lzo_cdecl_sighandler _far _cdecl ++# else ++# define __lzo_cdecl_sighandler _cdecl ++# endif ++# else ++# define __lzo_cdecl_sighandler __cdecl ++# endif ++#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) ++# define __lzo_cdecl __cdecl ++#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) ++# define __lzo_cdecl cdecl ++#endif ++#if !defined(__lzo_cdecl) ++# define __lzo_cdecl /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_atexit) ++# define __lzo_cdecl_atexit /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_main) ++# define __lzo_cdecl_main /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_qsort) ++# define __lzo_cdecl_qsort /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_sighandler) ++# define __lzo_cdecl_sighandler /*empty*/ ++#endif ++#if !defined(__lzo_cdecl_va) ++# define __lzo_cdecl_va __lzo_cdecl ++#endif ++#if !(LZO_CFG_NO_WINDOWS_H) ++#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) ++# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) ++# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) ++# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) ++# else ++# define LZO_HAVE_WINDOWS_H 1 ++# endif ++#endif ++#endif ++#if (LZO_ARCH_ALPHA) ++# define LZO_OPT_AVOID_UINT_INDEX 1 ++# define LZO_OPT_AVOID_SHORT 1 ++# define LZO_OPT_AVOID_USHORT 1 ++#elif (LZO_ARCH_AMD64) ++# define LZO_OPT_AVOID_INT_INDEX 1 ++# define LZO_OPT_AVOID_UINT_INDEX 1 ++# define LZO_OPT_UNALIGNED16 1 ++# define LZO_OPT_UNALIGNED32 1 ++# define LZO_OPT_UNALIGNED64 1 ++#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) ++#elif (LZO_ARCH_ARM) ++# define LZO_OPT_AVOID_SHORT 1 ++# define LZO_OPT_AVOID_USHORT 1 ++#elif (LZO_ARCH_CRIS) ++# define LZO_OPT_UNALIGNED16 1 ++# define LZO_OPT_UNALIGNED32 1 ++#elif (LZO_ARCH_I386) ++# define LZO_OPT_UNALIGNED16 1 ++# define LZO_OPT_UNALIGNED32 1 ++#elif (LZO_ARCH_IA64) ++# define LZO_OPT_AVOID_INT_INDEX 1 ++# define LZO_OPT_AVOID_UINT_INDEX 1 ++# define LZO_OPT_PREFER_POSTINC 1 ++#elif (LZO_ARCH_M68K) ++# define LZO_OPT_PREFER_POSTINC 1 ++# define LZO_OPT_PREFER_PREDEC 1 ++# if defined(__mc68020__) && !defined(__mcoldfire__) ++# define LZO_OPT_UNALIGNED16 1 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++#elif (LZO_ARCH_MIPS) ++# define LZO_OPT_AVOID_UINT_INDEX 1 ++#elif (LZO_ARCH_POWERPC) ++# define LZO_OPT_PREFER_PREINC 1 ++# define LZO_OPT_PREFER_PREDEC 1 ++# if (LZO_ABI_BIG_ENDIAN) ++# define LZO_OPT_UNALIGNED16 1 ++# define LZO_OPT_UNALIGNED32 1 ++# endif ++#elif (LZO_ARCH_S390) ++# define LZO_OPT_UNALIGNED16 1 ++# define LZO_OPT_UNALIGNED32 1 ++# if (LZO_SIZEOF_SIZE_T == 8) ++# define LZO_OPT_UNALIGNED64 1 ++# endif ++#elif (LZO_ARCH_SH) ++# define LZO_OPT_PREFER_POSTINC 1 ++# define LZO_OPT_PREFER_PREDEC 1 ++#endif ++#ifndef LZO_CFG_NO_INLINE_ASM ++#if (LZO_CC_LLVM) ++# define LZO_CFG_NO_INLINE_ASM 1 ++#endif ++#endif ++#ifndef LZO_CFG_NO_UNALIGNED ++#if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) ++# define LZO_CFG_NO_UNALIGNED 1 ++#endif ++#endif ++#if (LZO_CFG_NO_UNALIGNED) ++# undef LZO_OPT_UNALIGNED16 ++# undef LZO_OPT_UNALIGNED32 ++# undef LZO_OPT_UNALIGNED64 ++#endif ++#if (LZO_CFG_NO_INLINE_ASM) ++#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) ++# define LZO_ASM_SYNTAX_MSC 1 ++#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) ++#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) ++#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) ++# define LZO_ASM_SYNTAX_GNUC 1 ++#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) ++# define LZO_ASM_SYNTAX_GNUC 1 ++#endif ++#if (LZO_ASM_SYNTAX_GNUC) ++#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) ++# define __LZO_ASM_CLOBBER "ax" ++#elif (LZO_CC_INTELC) ++# define __LZO_ASM_CLOBBER "memory" ++#else ++# define __LZO_ASM_CLOBBER "cc", "memory" ++#endif ++#endif ++#if defined(__LZO_INFOSTR_MM) ++#elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) ++# define __LZO_INFOSTR_MM "" ++#elif defined(LZO_INFO_MM) ++# define __LZO_INFOSTR_MM "." LZO_INFO_MM ++#else ++# define __LZO_INFOSTR_MM "" ++#endif ++#if defined(__LZO_INFOSTR_PM) ++#elif defined(LZO_INFO_ABI_PM) ++# define __LZO_INFOSTR_PM "." LZO_INFO_ABI_PM ++#else ++# define __LZO_INFOSTR_PM "" ++#endif ++#if defined(__LZO_INFOSTR_ENDIAN) ++#elif defined(LZO_INFO_ABI_ENDIAN) ++# define __LZO_INFOSTR_ENDIAN "." LZO_INFO_ABI_ENDIAN ++#else ++# define __LZO_INFOSTR_ENDIAN "" ++#endif ++#if defined(__LZO_INFOSTR_OSNAME) ++#elif defined(LZO_INFO_OS_CONSOLE) ++# define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_CONSOLE ++#elif defined(LZO_INFO_OS_POSIX) ++# define __LZO_INFOSTR_OSNAME LZO_INFO_OS "." LZO_INFO_OS_POSIX ++#else ++# define __LZO_INFOSTR_OSNAME LZO_INFO_OS ++#endif ++#if defined(__LZO_INFOSTR_LIBC) ++#elif defined(LZO_INFO_LIBC) ++# define __LZO_INFOSTR_LIBC "." LZO_INFO_LIBC ++#else ++# define __LZO_INFOSTR_LIBC "" ++#endif ++#if defined(__LZO_INFOSTR_CCVER) ++#elif defined(LZO_INFO_CCVER) ++# define __LZO_INFOSTR_CCVER " " LZO_INFO_CCVER ++#else ++# define __LZO_INFOSTR_CCVER "" ++#endif ++#define LZO_INFO_STRING \ ++ LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ ++ " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER ++ ++#endif ++ ++#endif ++ ++#undef LZO_HAVE_CONFIG_H ++#include "minilzo.h" ++ ++#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2050) ++# error "version mismatch in miniLZO source files" ++#endif ++ ++#ifdef MINILZO_HAVE_CONFIG_H ++# define LZO_HAVE_CONFIG_H 1 ++#endif ++ ++#ifndef __LZO_CONF_H ++#define __LZO_CONF_H 1 ++ ++#if !defined(__LZO_IN_MINILZO) ++#if (LZO_CFG_FREESTANDING) ++# define LZO_LIBC_FREESTANDING 1 ++# define LZO_OS_FREESTANDING 1 ++# define ACC_LIBC_FREESTANDING 1 ++# define ACC_OS_FREESTANDING 1 ++#endif ++#if (LZO_CFG_NO_UNALIGNED) ++# define ACC_CFG_NO_UNALIGNED 1 ++#endif ++#if (LZO_ARCH_GENERIC) ++# define ACC_ARCH_GENERIC 1 ++#endif ++#if (LZO_ABI_NEUTRAL_ENDIAN) ++# define ACC_ABI_NEUTRAL_ENDIAN 1 ++#endif ++#if (LZO_HAVE_CONFIG_H) ++# define ACC_CONFIG_NO_HEADER 1 ++#endif ++#if defined(LZO_CFG_EXTRA_CONFIG_HEADER) ++# include LZO_CFG_EXTRA_CONFIG_HEADER ++#endif ++#if defined(__LZOCONF_H) || defined(__LZOCONF_H_INCLUDED) ++# error "include this file first" ++#endif ++#include "lzo/lzoconf.h" ++#endif ++ ++#if (LZO_VERSION < 0x02000) || !defined(__LZOCONF_H_INCLUDED) ++# error "version mismatch" ++#endif ++ ++#if (LZO_CC_BORLANDC && LZO_ARCH_I086) ++# pragma option -h ++#endif ++ ++#if (LZO_CC_MSC && (_MSC_VER >= 1000)) ++# pragma warning(disable: 4127 4701) ++#endif ++#if (LZO_CC_MSC && (_MSC_VER >= 1300)) ++# pragma warning(disable: 4820) ++# pragma warning(disable: 4514 4710 4711) ++#endif ++ ++#if (LZO_CC_SUNPROC) ++#if !defined(__cplusplus) ++# pragma error_messages(off,E_END_OF_LOOP_CODE_NOT_REACHED) ++# pragma error_messages(off,E_LOOP_NOT_ENTERED_AT_TOP) ++# pragma error_messages(off,E_STATEMENT_NOT_REACHED) ++#endif ++#endif ++ ++#if (__LZO_MMODEL_HUGE) && !(LZO_HAVE_MM_HUGE_PTR) ++# error "this should not happen - check defines for __huge" ++#endif ++ ++#if defined(__LZO_IN_MINILZO) || defined(LZO_CFG_FREESTANDING) ++#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) ++# define ACC_WANT_ACC_INCD_H 1 ++# define ACC_WANT_ACC_INCE_H 1 ++# define ACC_WANT_ACC_INCI_H 1 ++#elif 1 ++# include <string.h> ++#else ++# define ACC_WANT_ACC_INCD_H 1 ++#endif ++ ++#if (LZO_ARCH_I086) ++# define ACC_MM_AHSHIFT LZO_MM_AHSHIFT ++# define ACC_PTR_FP_OFF(x) (((const unsigned __far*)&(x))[0]) ++# define ACC_PTR_FP_SEG(x) (((const unsigned __far*)&(x))[1]) ++# define ACC_PTR_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o))) ++#endif ++ ++#if !defined(lzo_uintptr_t) ++# if defined(__LZO_MMODEL_HUGE) ++# define lzo_uintptr_t unsigned long ++# elif 1 && defined(LZO_OS_OS400) && (LZO_SIZEOF_VOID_P == 16) ++# define __LZO_UINTPTR_T_IS_POINTER 1 ++ typedef char* lzo_uintptr_t; ++# define lzo_uintptr_t lzo_uintptr_t ++# elif (LZO_SIZEOF_SIZE_T == LZO_SIZEOF_VOID_P) ++# define lzo_uintptr_t size_t ++# elif (LZO_SIZEOF_LONG == LZO_SIZEOF_VOID_P) ++# define lzo_uintptr_t unsigned long ++# elif (LZO_SIZEOF_INT == LZO_SIZEOF_VOID_P) ++# define lzo_uintptr_t unsigned int ++# elif (LZO_SIZEOF_LONG_LONG == LZO_SIZEOF_VOID_P) ++# define lzo_uintptr_t unsigned long long ++# else ++# define lzo_uintptr_t size_t ++# endif ++#endif ++LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) ++ ++#if 1 && !defined(LZO_CFG_FREESTANDING) ++#if 1 && !defined(HAVE_STRING_H) ++#define HAVE_STRING_H 1 ++#endif ++#if 1 && !defined(HAVE_MEMCMP) ++#define HAVE_MEMCMP 1 ++#endif ++#if 1 && !defined(HAVE_MEMCPY) ++#define HAVE_MEMCPY 1 ++#endif ++#if 1 && !defined(HAVE_MEMMOVE) ++#define HAVE_MEMMOVE 1 ++#endif ++#if 1 && !defined(HAVE_MEMSET) ++#define HAVE_MEMSET 1 ++#endif ++#endif ++ ++#if 1 && defined(HAVE_STRING_H) ++#include <string.h> ++#endif ++ ++#if (LZO_CFG_FREESTANDING) ++# undef HAVE_MEMCMP ++# undef HAVE_MEMCPY ++# undef HAVE_MEMMOVE ++# undef HAVE_MEMSET ++#endif ++ ++#if !(HAVE_MEMCMP) ++# undef memcmp ++# define memcmp(a,b,c) lzo_memcmp(a,b,c) ++#elif !(__LZO_MMODEL_HUGE) ++# undef lzo_memcmp ++# define lzo_memcmp(a,b,c) memcmp(a,b,c) ++#endif ++#if !(HAVE_MEMCPY) ++# undef memcpy ++# define memcpy(a,b,c) lzo_memcpy(a,b,c) ++#elif !(__LZO_MMODEL_HUGE) ++# undef lzo_memcpy ++# define lzo_memcpy(a,b,c) memcpy(a,b,c) ++#endif ++#if !(HAVE_MEMMOVE) ++# undef memmove ++# define memmove(a,b,c) lzo_memmove(a,b,c) ++#elif !(__LZO_MMODEL_HUGE) ++# undef lzo_memmove ++# define lzo_memmove(a,b,c) memmove(a,b,c) ++#endif ++#if !(HAVE_MEMSET) ++# undef memset ++# define memset(a,b,c) lzo_memset(a,b,c) ++#elif !(__LZO_MMODEL_HUGE) ++# undef lzo_memset ++# define lzo_memset(a,b,c) memset(a,b,c) ++#endif ++ ++#undef NDEBUG ++#if (LZO_CFG_FREESTANDING) ++# undef LZO_DEBUG ++# define NDEBUG 1 ++# undef assert ++# define assert(e) ((void)0) ++#else ++# if !defined(LZO_DEBUG) ++# define NDEBUG 1 ++# endif ++# include <assert.h> ++#endif ++ ++#if 0 && defined(__BOUNDS_CHECKING_ON) ++# include <unchecked.h> ++#else ++# define BOUNDS_CHECKING_OFF_DURING(stmt) stmt ++# define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr) ++#endif ++ ++#if !defined(__lzo_inline) ++# define __lzo_inline /*empty*/ ++#endif ++#if !defined(__lzo_forceinline) ++# define __lzo_forceinline /*empty*/ ++#endif ++#if !defined(__lzo_noinline) ++# define __lzo_noinline /*empty*/ ++#endif ++ ++#if (LZO_CFG_PGO) ++# undef __acc_likely ++# undef __acc_unlikely ++# undef __lzo_likely ++# undef __lzo_unlikely ++# define __acc_likely(e) (e) ++# define __acc_unlikely(e) (e) ++# define __lzo_likely(e) (e) ++# define __lzo_unlikely(e) (e) ++#endif ++ ++#if 1 ++# define LZO_BYTE(x) ((unsigned char) (x)) ++#else ++# define LZO_BYTE(x) ((unsigned char) ((x) & 0xff)) ++#endif ++ ++#define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b)) ++#define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b)) ++#define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c)) ++#define LZO_MIN3(a,b,c) ((a) <= (b) ? LZO_MIN(a,c) : LZO_MIN(b,c)) ++ ++#define lzo_sizeof(type) ((lzo_uint) (sizeof(type))) ++ ++#define LZO_HIGH(array) ((lzo_uint) (sizeof(array)/sizeof(*(array)))) ++ ++#define LZO_SIZE(bits) (1u << (bits)) ++#define LZO_MASK(bits) (LZO_SIZE(bits) - 1) ++ ++#define LZO_LSIZE(bits) (1ul << (bits)) ++#define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1) ++ ++#define LZO_USIZE(bits) ((lzo_uint) 1 << (bits)) ++#define LZO_UMASK(bits) (LZO_USIZE(bits) - 1) ++ ++#if !defined(DMUL) ++#if 0 ++ ++# define DMUL(a,b) ((lzo_xint) ((lzo_uint32)(a) * (lzo_uint32)(b))) ++#else ++# define DMUL(a,b) ((lzo_xint) ((a) * (b))) ++#endif ++#endif ++ ++#if 1 && (LZO_ARCH_AMD64 || LZO_ARCH_I386 || LZO_ARCH_POWERPC) ++# if (LZO_SIZEOF_SHORT == 2) ++# define LZO_UNALIGNED_OK_2 1 ++# endif ++# if (LZO_SIZEOF_INT == 4) ++# define LZO_UNALIGNED_OK_4 1 ++# endif ++#endif ++#if 1 && (LZO_ARCH_AMD64) ++# if defined(LZO_UINT64_MAX) ++# define LZO_UNALIGNED_OK_8 1 ++# endif ++#endif ++#if (LZO_CFG_NO_UNALIGNED) ++# undef LZO_UNALIGNED_OK_2 ++# undef LZO_UNALIGNED_OK_4 ++# undef LZO_UNALIGNED_OK_8 ++#endif ++ ++#undef UA_GET16 ++#undef UA_SET16 ++#undef UA_COPY16 ++#undef UA_GET32 ++#undef UA_SET32 ++#undef UA_COPY32 ++#undef UA_GET64 ++#undef UA_SET64 ++#undef UA_COPY64 ++#if defined(LZO_UNALIGNED_OK_2) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(unsigned short) == 2) ++# if 1 && defined(ACC_UA_COPY16) ++# define UA_GET16 ACC_UA_GET16 ++# define UA_SET16 ACC_UA_SET16 ++# define UA_COPY16 ACC_UA_COPY16 ++# else ++# define UA_GET16(p) (* (__lzo_ua_volatile const lzo_ushortp) (__lzo_ua_volatile const lzo_voidp) (p)) ++# define UA_SET16(p,v) ((* (__lzo_ua_volatile lzo_ushortp) (__lzo_ua_volatile lzo_voidp) (p)) = (unsigned short) (v)) ++# define UA_COPY16(d,s) UA_SET16(d, UA_GET16(s)) ++# endif ++#endif ++#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32) == 4) ++# if 1 && defined(ACC_UA_COPY32) ++# define UA_GET32 ACC_UA_GET32 ++# define UA_SET32 ACC_UA_SET32 ++# define UA_COPY32 ACC_UA_COPY32 ++# else ++# define UA_GET32(p) (* (__lzo_ua_volatile const lzo_uint32p) (__lzo_ua_volatile const lzo_voidp) (p)) ++# define UA_SET32(p,v) ((* (__lzo_ua_volatile lzo_uint32p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint32) (v)) ++# define UA_COPY32(d,s) UA_SET32(d, UA_GET32(s)) ++# endif ++#endif ++#if defined(LZO_UNALIGNED_OK_8) ++ LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64) == 8) ++# if 1 && defined(ACC_UA_COPY64) ++# define UA_GET64 ACC_UA_GET64 ++# define UA_SET64 ACC_UA_SET64 ++# define UA_COPY64 ACC_UA_COPY64 ++# else ++# define UA_GET64(p) (* (__lzo_ua_volatile const lzo_uint64p) (__lzo_ua_volatile const lzo_voidp) (p)) ++# define UA_SET64(p,v) ((* (__lzo_ua_volatile lzo_uint64p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint64) (v)) ++# define UA_COPY64(d,s) UA_SET64(d, UA_GET64(s)) ++# endif ++#endif ++ ++#define MEMCPY8_DS(dest,src,len) \ ++ lzo_memcpy(dest,src,len); dest += len; src += len ++ ++#define BZERO8_PTR(s,l,n) \ ++ lzo_memset((lzo_voidp)(s),0,(lzo_uint)(l)*(n)) ++ ++#define MEMCPY_DS(dest,src,len) \ ++ do *dest++ = *src++; while (--len > 0) ++ ++LZO_EXTERN(const lzo_bytep) lzo_copyright(void); ++ ++#ifndef __LZO_PTR_H ++#define __LZO_PTR_H 1 ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++#if !defined(lzo_uintptr_t) ++# if (__LZO_MMODEL_HUGE) ++# define lzo_uintptr_t unsigned long ++# else ++# define lzo_uintptr_t acc_uintptr_t ++# ifdef __ACC_INTPTR_T_IS_POINTER ++# define __LZO_UINTPTR_T_IS_POINTER 1 ++# endif ++# endif ++#endif ++ ++#if (LZO_ARCH_I086) ++#define PTR(a) ((lzo_bytep) (a)) ++#define PTR_ALIGNED_4(a) ((ACC_PTR_FP_OFF(a) & 3) == 0) ++#define PTR_ALIGNED2_4(a,b) (((ACC_PTR_FP_OFF(a) | ACC_PTR_FP_OFF(b)) & 3) == 0) ++#elif (LZO_MM_PVP) ++#define PTR(a) ((lzo_bytep) (a)) ++#define PTR_ALIGNED_8(a) ((((lzo_uintptr_t)(a)) >> 61) == 0) ++#define PTR_ALIGNED2_8(a,b) ((((lzo_uintptr_t)(a)|(lzo_uintptr_t)(b)) >> 61) == 0) ++#else ++#define PTR(a) ((lzo_uintptr_t) (a)) ++#define PTR_LINEAR(a) PTR(a) ++#define PTR_ALIGNED_4(a) ((PTR_LINEAR(a) & 3) == 0) ++#define PTR_ALIGNED_8(a) ((PTR_LINEAR(a) & 7) == 0) ++#define PTR_ALIGNED2_4(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 3) == 0) ++#define PTR_ALIGNED2_8(a,b) (((PTR_LINEAR(a) | PTR_LINEAR(b)) & 7) == 0) ++#endif ++ ++#define PTR_LT(a,b) (PTR(a) < PTR(b)) ++#define PTR_GE(a,b) (PTR(a) >= PTR(b)) ++#define PTR_DIFF(a,b) (PTR(a) - PTR(b)) ++#define pd(a,b) ((lzo_uint) ((a)-(b))) ++ ++LZO_EXTERN(lzo_uintptr_t) ++__lzo_ptr_linear(const lzo_voidp ptr); ++ ++typedef union ++{ ++ char a_char; ++ unsigned char a_uchar; ++ short a_short; ++ unsigned short a_ushort; ++ int a_int; ++ unsigned int a_uint; ++ long a_long; ++ unsigned long a_ulong; ++ lzo_int a_lzo_int; ++ lzo_uint a_lzo_uint; ++ lzo_int32 a_lzo_int32; ++ lzo_uint32 a_lzo_uint32; ++#if defined(LZO_UINT64_MAX) ++ lzo_int64 a_lzo_int64; ++ lzo_uint64 a_lzo_uint64; ++#endif ++ ptrdiff_t a_ptrdiff_t; ++ lzo_uintptr_t a_lzo_uintptr_t; ++ lzo_voidp a_lzo_voidp; ++ void * a_void_p; ++ lzo_bytep a_lzo_bytep; ++ lzo_bytepp a_lzo_bytepp; ++ lzo_uintp a_lzo_uintp; ++ lzo_uint * a_lzo_uint_p; ++ lzo_uint32p a_lzo_uint32p; ++ lzo_uint32 * a_lzo_uint32_p; ++ unsigned char * a_uchar_p; ++ char * a_char_p; ++} ++lzo_full_align_t; ++ ++#ifdef __cplusplus ++} ++#endif ++ ++#endif ++ ++#ifndef LZO_DETERMINISTIC ++#define LZO_DETERMINISTIC 1 ++#endif ++ ++#ifndef LZO_DICT_USE_PTR ++#define LZO_DICT_USE_PTR 1 ++#if 0 && (LZO_ARCH_I086) ++# undef LZO_DICT_USE_PTR ++# define LZO_DICT_USE_PTR 0 ++#endif ++#endif ++ ++#if (LZO_DICT_USE_PTR) ++# define lzo_dict_t const lzo_bytep ++# define lzo_dict_p lzo_dict_t __LZO_MMODEL * ++#else ++# define lzo_dict_t lzo_uint ++# define lzo_dict_p lzo_dict_t __LZO_MMODEL * ++#endif ++ ++#endif ++ ++#if !defined(MINILZO_CFG_SKIP_LZO_PTR) ++ ++LZO_PUBLIC(lzo_uintptr_t) ++__lzo_ptr_linear(const lzo_voidp ptr) ++{ ++ lzo_uintptr_t p; ++ ++#if (LZO_ARCH_I086) ++ p = (((lzo_uintptr_t)(ACC_PTR_FP_SEG(ptr))) << (16 - ACC_MM_AHSHIFT)) + (ACC_PTR_FP_OFF(ptr)); ++#elif (LZO_MM_PVP) ++ p = (lzo_uintptr_t) (ptr); ++ p = (p << 3) | (p >> 61); ++#else ++ p = (lzo_uintptr_t) PTR_LINEAR(ptr); ++#endif ++ ++ return p; ++} ++ ++LZO_PUBLIC(unsigned) ++__lzo_align_gap(const lzo_voidp ptr, lzo_uint size) ++{ ++#if defined(__LZO_UINTPTR_T_IS_POINTER) ++ size_t n = (size_t) ptr; ++ n = (((n + size - 1) / size) * size) - n; ++#else ++ lzo_uintptr_t p, n; ++ p = __lzo_ptr_linear(ptr); ++ n = (((p + size - 1) / size) * size) - p; ++#endif ++ ++ assert(size > 0); ++ assert((long)n >= 0); ++ assert(n <= size); ++ return (unsigned)n; ++} ++ ++#endif ++#if !defined(MINILZO_CFG_SKIP_LZO_UTIL) ++ ++/* If you use the LZO library in a product, I would appreciate that you ++ * keep this copyright string in the executable of your product. ++ */ ++ ++static const char __lzo_copyright[] = ++#if !defined(__LZO_IN_MINLZO) ++ LZO_VERSION_STRING; ++#else ++ "\r\n\n" ++ "LZO data compression library.\n" ++ "$Copyright: LZO Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\n" ++ "<markus@oberhumer.com>\n" ++ "http://www.oberhumer.com $\n\n" ++ "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n" ++ "$Info: " LZO_INFO_STRING " $\n"; ++#endif ++ ++LZO_PUBLIC(const lzo_bytep) ++lzo_copyright(void) ++{ ++#if (LZO_OS_DOS16 && LZO_CC_TURBOC) ++ return (lzo_voidp) __lzo_copyright; ++#else ++ return (const lzo_bytep) __lzo_copyright; ++#endif ++} ++ ++LZO_PUBLIC(unsigned) ++lzo_version(void) ++{ ++ return LZO_VERSION; ++} ++ ++LZO_PUBLIC(const char *) ++lzo_version_string(void) ++{ ++ return LZO_VERSION_STRING; ++} ++ ++LZO_PUBLIC(const char *) ++lzo_version_date(void) ++{ ++ return LZO_VERSION_DATE; ++} ++ ++LZO_PUBLIC(const lzo_charp) ++_lzo_version_string(void) ++{ ++ return LZO_VERSION_STRING; ++} ++ ++LZO_PUBLIC(const lzo_charp) ++_lzo_version_date(void) ++{ ++ return LZO_VERSION_DATE; ++} ++ ++#define LZO_BASE 65521u ++#define LZO_NMAX 5552 ++ ++#define LZO_DO1(buf,i) s1 += buf[i]; s2 += s1 ++#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1); ++#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2); ++#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4); ++#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8); ++ ++LZO_PUBLIC(lzo_uint32) ++lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len) ++{ ++ lzo_uint32 s1 = adler & 0xffff; ++ lzo_uint32 s2 = (adler >> 16) & 0xffff; ++ unsigned k; ++ ++ if (buf == NULL) ++ return 1; ++ ++ while (len > 0) ++ { ++ k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX; ++ len -= k; ++ if (k >= 16) do ++ { ++ LZO_DO16(buf,0); ++ buf += 16; ++ k -= 16; ++ } while (k >= 16); ++ if (k != 0) do ++ { ++ s1 += *buf++; ++ s2 += s1; ++ } while (--k > 0); ++ s1 %= LZO_BASE; ++ s2 %= LZO_BASE; ++ } ++ return (s2 << 16) | s1; ++} ++ ++#undef LZO_DO1 ++#undef LZO_DO2 ++#undef LZO_DO4 ++#undef LZO_DO8 ++#undef LZO_DO16 ++ ++#endif ++#if !defined(MINILZO_CFG_SKIP_LZO_STRING) ++#undef lzo_memcmp ++#undef lzo_memcpy ++#undef lzo_memmove ++#undef lzo_memset ++#if !defined(__LZO_MMODEL_HUGE) ++# undef LZO_HAVE_MM_HUGE_PTR ++#endif ++#define lzo_hsize_t lzo_uint ++#define lzo_hvoid_p lzo_voidp ++#define lzo_hbyte_p lzo_bytep ++#define LZOLIB_PUBLIC(r,f) LZO_PUBLIC(r) f ++#define lzo_hmemcmp lzo_memcmp ++#define lzo_hmemcpy lzo_memcpy ++#define lzo_hmemmove lzo_memmove ++#define lzo_hmemset lzo_memset ++#define __LZOLIB_HMEMCPY_CH_INCLUDED 1 ++#if !defined(LZOLIB_PUBLIC) ++# define LZOLIB_PUBLIC(r,f) r __LZOLIB_FUNCNAME(f) ++#endif ++LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo_hsize_t len) ++{ ++#if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCMP) ++ const lzo_hbyte_p p1 = (const lzo_hbyte_p) s1; ++ const lzo_hbyte_p p2 = (const lzo_hbyte_p) s2; ++ if __lzo_likely(len > 0) do ++ { ++ int d = *p1 - *p2; ++ if (d != 0) ++ return d; ++ p1++; p2++; ++ } while __lzo_likely(--len > 0); ++ return 0; ++#else ++ return memcmp(s1, s2, len); ++#endif ++} ++LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) ++{ ++#if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCPY) ++ lzo_hbyte_p p1 = (lzo_hbyte_p) dest; ++ const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; ++ if (!(len > 0) || p1 == p2) ++ return dest; ++ do ++ *p1++ = *p2++; ++ while __lzo_likely(--len > 0); ++ return dest; ++#else ++ return memcpy(dest, src, len); ++#endif ++} ++LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) ++{ ++#if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMMOVE) ++ lzo_hbyte_p p1 = (lzo_hbyte_p) dest; ++ const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; ++ if (!(len > 0) || p1 == p2) ++ return dest; ++ if (p1 < p2) ++ { ++ do ++ *p1++ = *p2++; ++ while __lzo_likely(--len > 0); ++ } ++ else ++ { ++ p1 += len; ++ p2 += len; ++ do ++ *--p1 = *--p2; ++ while __lzo_likely(--len > 0); ++ } ++ return dest; ++#else ++ return memmove(dest, src, len); ++#endif ++} ++LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int c, lzo_hsize_t len) ++{ ++#if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMSET) ++ lzo_hbyte_p p = (lzo_hbyte_p) s; ++ if __lzo_likely(len > 0) do ++ *p++ = (unsigned char) c; ++ while __lzo_likely(--len > 0); ++ return s; ++#else ++ return memset(s, c, len); ++#endif ++} ++#undef LZOLIB_PUBLIC ++#endif ++#if !defined(MINILZO_CFG_SKIP_LZO_INIT) ++ ++#if !defined(__LZO_IN_MINILZO) ++ ++#define ACC_WANT_ACC_CHK_CH 1 ++#undef ACCCHK_ASSERT ++ ++ ACCCHK_ASSERT_IS_SIGNED_T(lzo_int) ++ ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint) ++ ++ ACCCHK_ASSERT_IS_SIGNED_T(lzo_int32) ++ ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint32) ++ ACCCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0) ++ ACCCHK_ASSERT(sizeof(lzo_uint32) >= 4) ++#if defined(LZO_UINT64_MAX) ++ ACCCHK_ASSERT(sizeof(lzo_uint64) == 8) ++ ACCCHK_ASSERT_IS_SIGNED_T(lzo_int64) ++ ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint64) ++#endif ++ ++#if !defined(__LZO_UINTPTR_T_IS_POINTER) ++ ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t) ++#endif ++ ACCCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) ++ ++ ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_xint) ++ ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint32)) ++ ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint)) ++ ACCCHK_ASSERT(sizeof(lzo_xint) == sizeof(lzo_uint32) || sizeof(lzo_xint) == sizeof(lzo_uint)) ++ ++#endif ++#undef ACCCHK_ASSERT ++ ++#if 0 ++#define WANT_lzo_bitops_clz32 1 ++#define WANT_lzo_bitops_clz64 1 ++#endif ++#define WANT_lzo_bitops_ctz32 1 ++#define WANT_lzo_bitops_ctz64 1 ++ ++#if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) ++#include <intrin.h> ++#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0 ++#pragma intrinsic(_BitScanReverse) ++static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v) ++{ ++ unsigned long r; ++ (void) _BitScanReverse(&r, v); ++ return (unsigned) r; ++} ++#define lzo_bitops_clz32 lzo_bitops_clz32 ++#endif ++#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0 ++#pragma intrinsic(_BitScanReverse64) ++static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v) ++{ ++ unsigned long r; ++ (void) _BitScanReverse64(&r, v); ++ return (unsigned) r; ++} ++#define lzo_bitops_clz64 lzo_bitops_clz64 ++#endif ++#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) ++#pragma intrinsic(_BitScanForward) ++static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v) ++{ ++ unsigned long r; ++ (void) _BitScanForward(&r, v); ++ return (unsigned) r; ++} ++#define lzo_bitops_ctz32 lzo_bitops_ctz32 ++#endif ++#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) ++#pragma intrinsic(_BitScanForward64) ++static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v) ++{ ++ unsigned long r; ++ (void) _BitScanForward64(&r, v); ++ return (unsigned) r; ++} ++#define lzo_bitops_ctz64 lzo_bitops_ctz64 ++#endif ++ ++#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM) ++#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) ++#define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v)) ++#endif ++#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) ++#define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v)) ++#endif ++#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) ++#define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v)) ++#endif ++#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) ++#define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v)) ++#endif ++#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32) ++#define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v)) ++#endif ++#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX) ++#define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v)) ++#endif ++#endif ++ ++#if 0 ++#define u2p(ptr,off) ((lzo_voidp) (((lzo_bytep)(lzo_voidp)(ptr)) + (off))) ++#else ++static __lzo_noinline lzo_voidp u2p(lzo_voidp ptr, lzo_uint off) ++{ ++ return (lzo_voidp) ((lzo_bytep) ptr + off); ++} ++#endif ++ ++LZO_PUBLIC(int) ++_lzo_config_check(void) ++{ ++ lzo_bool r = 1; ++ union { ++ lzo_xint a[2]; unsigned char b[2*LZO_MAX(8,sizeof(lzo_xint))]; ++#if defined(LZO_UNALIGNED_OK_8) ++ lzo_uint64 c[2]; ++#endif ++ unsigned short x[2]; lzo_uint32 y[2]; lzo_uint z[2]; ++ } u; ++ lzo_voidp p; ++ ++ u.a[0] = u.a[1] = 0; ++ p = u2p(&u, 0); ++ r &= ((* (lzo_bytep) p) == 0); ++#if !defined(LZO_CFG_NO_CONFIG_CHECK) ++#if defined(LZO_ABI_BIG_ENDIAN) ++ u.a[0] = u.a[1] = 0; u.b[sizeof(lzo_uint) - 1] = 128; ++ p = u2p(&u, 0); ++ r &= ((* (lzo_uintp) p) == 128); ++#endif ++#if defined(LZO_ABI_LITTLE_ENDIAN) ++ u.a[0] = u.a[1] = 0; u.b[0] = 128; ++ p = u2p(&u, 0); ++ r &= ((* (lzo_uintp) p) == 128); ++#endif ++#if defined(LZO_UNALIGNED_OK_2) ++ u.a[0] = u.a[1] = 0; ++ u.b[0] = 1; u.b[sizeof(unsigned short) + 1] = 2; ++ p = u2p(&u, 1); ++ r &= ((* (lzo_ushortp) p) == 0); ++#endif ++#if defined(LZO_UNALIGNED_OK_4) ++ u.a[0] = u.a[1] = 0; ++ u.b[0] = 3; u.b[sizeof(lzo_uint32) + 1] = 4; ++ p = u2p(&u, 1); ++ r &= ((* (lzo_uint32p) p) == 0); ++#endif ++#if defined(LZO_UNALIGNED_OK_8) ++ u.c[0] = u.c[1] = 0; ++ u.b[0] = 5; u.b[sizeof(lzo_uint64) + 1] = 6; ++ p = u2p(&u, 1); ++ r &= ((* (lzo_uint64p) p) == 0); ++#endif ++#if defined(lzo_bitops_clz32) ++ { unsigned i; lzo_uint32 v = 1; ++ for (i = 0; i < 31; i++, v <<= 1) ++ r &= lzo_bitops_clz32(v) == 31 - i; ++ } ++#endif ++#if defined(lzo_bitops_clz64) ++ { unsigned i; lzo_uint64 v = 1; ++ for (i = 0; i < 63; i++, v <<= 1) ++ r &= lzo_bitops_clz64(v) == 63 - i; ++ } ++#endif ++#if defined(lzo_bitops_ctz32) ++ { unsigned i; lzo_uint32 v = 1; ++ for (i = 0; i < 31; i++, v <<= 1) ++ r &= lzo_bitops_ctz32(v) == i; ++ } ++#endif ++#if defined(lzo_bitops_ctz64) ++ { unsigned i; lzo_uint64 v = 1; ++ for (i = 0; i < 63; i++, v <<= 1) ++ r &= lzo_bitops_ctz64(v) == i; ++ } ++#endif ++#endif ++ ++ return r == 1 ? LZO_E_OK : LZO_E_ERROR; ++} ++ ++LZO_PUBLIC(int) ++__lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5, ++ int s6, int s7, int s8, int s9) ++{ ++ int r; ++ ++#if defined(__LZO_IN_MINILZO) ++#elif (LZO_CC_MSC && ((_MSC_VER) < 700)) ++#else ++#define ACC_WANT_ACC_CHK_CH 1 ++#undef ACCCHK_ASSERT ++#define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) ++#endif ++#undef ACCCHK_ASSERT ++ ++ if (v == 0) ++ return LZO_E_ERROR; ++ ++ r = (s1 == -1 || s1 == (int) sizeof(short)) && ++ (s2 == -1 || s2 == (int) sizeof(int)) && ++ (s3 == -1 || s3 == (int) sizeof(long)) && ++ (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) && ++ (s5 == -1 || s5 == (int) sizeof(lzo_uint)) && ++ (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) && ++ (s7 == -1 || s7 == (int) sizeof(char *)) && ++ (s8 == -1 || s8 == (int) sizeof(lzo_voidp)) && ++ (s9 == -1 || s9 == (int) sizeof(lzo_callback_t)); ++ if (!r) ++ return LZO_E_ERROR; ++ ++ r = _lzo_config_check(); ++ if (r != LZO_E_OK) ++ return r; ++ ++ return r; ++} ++ ++#if !defined(__LZO_IN_MINILZO) ++ ++#if (LZO_OS_WIN16 && LZO_CC_WATCOMC) && defined(__SW_BD) ++ ++#if 0 ++BOOL FAR PASCAL LibMain ( HANDLE hInstance, WORD wDataSegment, ++ WORD wHeapSize, LPSTR lpszCmdLine ) ++#else ++int __far __pascal LibMain ( int a, short b, short c, long d ) ++#endif ++{ ++ LZO_UNUSED(a); LZO_UNUSED(b); LZO_UNUSED(c); LZO_UNUSED(d); ++ return 1; ++} ++ ++#endif ++ ++#endif ++ ++#endif ++ ++#define LZO1X 1 ++#define LZO_EOF_CODE 1 ++#define M2_MAX_OFFSET 0x0800 ++ ++#if !defined(MINILZO_CFG_SKIP_LZO1X_1_COMPRESS) ++ ++#if 1 && defined(UA_GET32) ++#undef LZO_DICT_USE_PTR ++#define LZO_DICT_USE_PTR 0 ++#undef lzo_dict_t ++#define lzo_dict_t unsigned short ++#endif ++ ++#define LZO_NEED_DICT_H 1 ++#ifndef D_BITS ++#define D_BITS 14 ++#endif ++#define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5) ++#define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f) ++#if 1 ++#define DINDEX(dv,p) DM(((DMUL(0x1824429d,dv)) >> (32-D_BITS))) ++#else ++#define DINDEX(dv,p) DM((dv) + ((dv) >> (32-D_BITS))) ++#endif ++ ++#ifndef __LZO_CONFIG1X_H ++#define __LZO_CONFIG1X_H 1 ++ ++#if !defined(LZO1X) && !defined(LZO1Y) && !defined(LZO1Z) ++# define LZO1X 1 ++#endif ++ ++#if !defined(__LZO_IN_MINILZO) ++#include "lzo/lzo1x.h" ++#endif ++ ++#ifndef LZO_EOF_CODE ++#define LZO_EOF_CODE 1 ++#endif ++#undef LZO_DETERMINISTIC ++ ++#define M1_MAX_OFFSET 0x0400 ++#ifndef M2_MAX_OFFSET ++#define M2_MAX_OFFSET 0x0800 ++#endif ++#define M3_MAX_OFFSET 0x4000 ++#define M4_MAX_OFFSET 0xbfff ++ ++#define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET) ++ ++#define M1_MIN_LEN 2 ++#define M1_MAX_LEN 2 ++#define M2_MIN_LEN 3 ++#ifndef M2_MAX_LEN ++#define M2_MAX_LEN 8 ++#endif ++#define M3_MIN_LEN 3 ++#define M3_MAX_LEN 33 ++#define M4_MIN_LEN 3 ++#define M4_MAX_LEN 9 ++ ++#define M1_MARKER 0 ++#define M2_MARKER 64 ++#define M3_MARKER 32 ++#define M4_MARKER 16 ++ ++#ifndef MIN_LOOKAHEAD ++#define MIN_LOOKAHEAD (M2_MAX_LEN + 1) ++#endif ++ ++#if defined(LZO_NEED_DICT_H) ++ ++#ifndef LZO_HASH ++#define LZO_HASH LZO_HASH_LZO_INCREMENTAL_B ++#endif ++#define DL_MIN_LEN M2_MIN_LEN ++ ++#ifndef __LZO_DICT_H ++#define __LZO_DICT_H 1 ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++#if !defined(D_BITS) && defined(DBITS) ++# define D_BITS DBITS ++#endif ++#if !defined(D_BITS) ++# error "D_BITS is not defined" ++#endif ++#if (D_BITS < 16) ++# define D_SIZE LZO_SIZE(D_BITS) ++# define D_MASK LZO_MASK(D_BITS) ++#else ++# define D_SIZE LZO_USIZE(D_BITS) ++# define D_MASK LZO_UMASK(D_BITS) ++#endif ++#define D_HIGH ((D_MASK >> 1) + 1) ++ ++#if !defined(DD_BITS) ++# define DD_BITS 0 ++#endif ++#define DD_SIZE LZO_SIZE(DD_BITS) ++#define DD_MASK LZO_MASK(DD_BITS) ++ ++#if !defined(DL_BITS) ++# define DL_BITS (D_BITS - DD_BITS) ++#endif ++#if (DL_BITS < 16) ++# define DL_SIZE LZO_SIZE(DL_BITS) ++# define DL_MASK LZO_MASK(DL_BITS) ++#else ++# define DL_SIZE LZO_USIZE(DL_BITS) ++# define DL_MASK LZO_UMASK(DL_BITS) ++#endif ++ ++#if (D_BITS != DL_BITS + DD_BITS) ++# error "D_BITS does not match" ++#endif ++#if (D_BITS < 6 || D_BITS > 18) ++# error "invalid D_BITS" ++#endif ++#if (DL_BITS < 6 || DL_BITS > 20) ++# error "invalid DL_BITS" ++#endif ++#if (DD_BITS < 0 || DD_BITS > 6) ++# error "invalid DD_BITS" ++#endif ++ ++#if !defined(DL_MIN_LEN) ++# define DL_MIN_LEN 3 ++#endif ++#if !defined(DL_SHIFT) ++# define DL_SHIFT ((DL_BITS + (DL_MIN_LEN - 1)) / DL_MIN_LEN) ++#endif ++ ++#define LZO_HASH_GZIP 1 ++#define LZO_HASH_GZIP_INCREMENTAL 2 ++#define LZO_HASH_LZO_INCREMENTAL_A 3 ++#define LZO_HASH_LZO_INCREMENTAL_B 4 ++ ++#if !defined(LZO_HASH) ++# error "choose a hashing strategy" ++#endif ++ ++#undef DM ++#undef DX ++ ++#if (DL_MIN_LEN == 3) ++# define _DV2_A(p,shift1,shift2) \ ++ (((( (lzo_xint)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2]) ++# define _DV2_B(p,shift1,shift2) \ ++ (((( (lzo_xint)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0]) ++# define _DV3_B(p,shift1,shift2,shift3) \ ++ ((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0]) ++#elif (DL_MIN_LEN == 2) ++# define _DV2_A(p,shift1,shift2) \ ++ (( (lzo_xint)(p[0]) << shift1) ^ p[1]) ++# define _DV2_B(p,shift1,shift2) \ ++ (( (lzo_xint)(p[1]) << shift1) ^ p[2]) ++#else ++# error "invalid DL_MIN_LEN" ++#endif ++#define _DV_A(p,shift) _DV2_A(p,shift,shift) ++#define _DV_B(p,shift) _DV2_B(p,shift,shift) ++#define DA2(p,s1,s2) \ ++ (((((lzo_xint)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0]) ++#define DS2(p,s1,s2) \ ++ (((((lzo_xint)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0]) ++#define DX2(p,s1,s2) \ ++ (((((lzo_xint)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0]) ++#define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0]) ++#define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0]) ++#define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0]) ++#define DMS(v,s) ((lzo_uint) (((v) & (D_MASK >> (s))) << (s))) ++#define DM(v) DMS(v,0) ++ ++#if (LZO_HASH == LZO_HASH_GZIP) ++# define _DINDEX(dv,p) (_DV_A((p),DL_SHIFT)) ++ ++#elif (LZO_HASH == LZO_HASH_GZIP_INCREMENTAL) ++# define __LZO_HASH_INCREMENTAL 1 ++# define DVAL_FIRST(dv,p) dv = _DV_A((p),DL_SHIFT) ++# define DVAL_NEXT(dv,p) dv = (((dv) << DL_SHIFT) ^ p[2]) ++# define _DINDEX(dv,p) (dv) ++# define DVAL_LOOKAHEAD DL_MIN_LEN ++ ++#elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_A) ++# define __LZO_HASH_INCREMENTAL 1 ++# define DVAL_FIRST(dv,p) dv = _DV_A((p),5) ++# define DVAL_NEXT(dv,p) \ ++ dv ^= (lzo_xint)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2]) ++# define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5) ++# define DVAL_LOOKAHEAD DL_MIN_LEN ++ ++#elif (LZO_HASH == LZO_HASH_LZO_INCREMENTAL_B) ++# define __LZO_HASH_INCREMENTAL 1 ++# define DVAL_FIRST(dv,p) dv = _DV_B((p),5) ++# define DVAL_NEXT(dv,p) \ ++ dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_xint)(p[2]) << (2*5))) ++# define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5) ++# define DVAL_LOOKAHEAD DL_MIN_LEN ++ ++#else ++# error "choose a hashing strategy" ++#endif ++ ++#ifndef DINDEX ++#define DINDEX(dv,p) ((lzo_uint)((_DINDEX(dv,p)) & DL_MASK) << DD_BITS) ++#endif ++#if !defined(DINDEX1) && defined(D_INDEX1) ++#define DINDEX1 D_INDEX1 ++#endif ++#if !defined(DINDEX2) && defined(D_INDEX2) ++#define DINDEX2 D_INDEX2 ++#endif ++ ++#if !defined(__LZO_HASH_INCREMENTAL) ++# define DVAL_FIRST(dv,p) ((void) 0) ++# define DVAL_NEXT(dv,p) ((void) 0) ++# define DVAL_LOOKAHEAD 0 ++#endif ++ ++#if !defined(DVAL_ASSERT) ++#if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG) ++#if (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_LLVM) ++static void __attribute__((__unused__)) ++#else ++static void ++#endif ++DVAL_ASSERT(lzo_xint dv, const lzo_bytep p) ++{ ++ lzo_xint df; ++ DVAL_FIRST(df,(p)); ++ assert(DINDEX(dv,p) == DINDEX(df,p)); ++} ++#else ++# define DVAL_ASSERT(dv,p) ((void) 0) ++#endif ++#endif ++ ++#if (LZO_DICT_USE_PTR) ++# define DENTRY(p,in) (p) ++# define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex] ++#else ++# define DENTRY(p,in) ((lzo_dict_t) pd(p, in)) ++# define GINDEX(m_pos,m_off,dict,dindex,in) m_off = dict[dindex] ++#endif ++ ++#if (DD_BITS == 0) ++ ++# define UPDATE_D(dict,drun,dv,p,in) dict[ DINDEX(dv,p) ] = DENTRY(p,in) ++# define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in) ++# define UPDATE_P(ptr,drun,p,in) (ptr)[0] = DENTRY(p,in) ++ ++#else ++ ++# define UPDATE_D(dict,drun,dv,p,in) \ ++ dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK ++# define UPDATE_I(dict,drun,index,p,in) \ ++ dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK ++# define UPDATE_P(ptr,drun,p,in) \ ++ (ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK ++ ++#endif ++ ++#if (LZO_DICT_USE_PTR) ++ ++#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \ ++ (m_pos == NULL || (m_off = pd(ip, m_pos)) > max_offset) ++ ++#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \ ++ (BOUNDS_CHECKING_OFF_IN_EXPR(( \ ++ m_pos = ip - (lzo_uint) PTR_DIFF(ip,m_pos), \ ++ PTR_LT(m_pos,in) || \ ++ (m_off = (lzo_uint) PTR_DIFF(ip,m_pos)) == 0 || \ ++ m_off > max_offset ))) ++ ++#else ++ ++#define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \ ++ (m_off == 0 || \ ++ ((m_off = pd(ip, in) - m_off) > max_offset) || \ ++ (m_pos = (ip) - (m_off), 0) ) ++ ++#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \ ++ (pd(ip, in) <= m_off || \ ++ ((m_off = pd(ip, in) - m_off) > max_offset) || \ ++ (m_pos = (ip) - (m_off), 0) ) ++ ++#endif ++ ++#if (LZO_DETERMINISTIC) ++# define LZO_CHECK_MPOS LZO_CHECK_MPOS_DET ++#else ++# define LZO_CHECK_MPOS LZO_CHECK_MPOS_NON_DET ++#endif ++ ++#ifdef __cplusplus ++} ++#endif ++ ++#endif ++ ++#endif ++ ++#endif ++ ++#define LZO_DETERMINISTIC !(LZO_DICT_USE_PTR) ++ ++#ifndef DO_COMPRESS ++#define DO_COMPRESS lzo1x_1_compress ++#endif ++ ++#if 1 && defined(DO_COMPRESS) && !defined(do_compress) ++# define do_compress LZO_CPP_ECONCAT2(DO_COMPRESS,_core) ++#endif ++ ++#if defined(UA_GET64) ++# define WANT_lzo_bitops_ctz64 1 ++#elif defined(UA_GET32) ++# define WANT_lzo_bitops_ctz32 1 ++#endif ++ ++#if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) ++#include <intrin.h> ++#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0 ++#pragma intrinsic(_BitScanReverse) ++static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v) ++{ ++ unsigned long r; ++ (void) _BitScanReverse(&r, v); ++ return (unsigned) r; ++} ++#define lzo_bitops_clz32 lzo_bitops_clz32 ++#endif ++#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0 ++#pragma intrinsic(_BitScanReverse64) ++static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v) ++{ ++ unsigned long r; ++ (void) _BitScanReverse64(&r, v); ++ return (unsigned) r; ++} ++#define lzo_bitops_clz64 lzo_bitops_clz64 ++#endif ++#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) ++#pragma intrinsic(_BitScanForward) ++static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v) ++{ ++ unsigned long r; ++ (void) _BitScanForward(&r, v); ++ return (unsigned) r; ++} ++#define lzo_bitops_ctz32 lzo_bitops_ctz32 ++#endif ++#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) ++#pragma intrinsic(_BitScanForward64) ++static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v) ++{ ++ unsigned long r; ++ (void) _BitScanForward64(&r, v); ++ return (unsigned) r; ++} ++#define lzo_bitops_ctz64 lzo_bitops_ctz64 ++#endif ++ ++#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || LZO_CC_LLVM) ++#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) ++#define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v)) ++#endif ++#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) ++#define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v)) ++#endif ++#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) ++#define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v)) ++#endif ++#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) ++#define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v)) ++#endif ++#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32) ++#define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v)) ++#endif ++#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX) ++#define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v)) ++#endif ++#endif ++ ++static __lzo_noinline lzo_uint ++do_compress ( const lzo_bytep in , lzo_uint in_len, ++ lzo_bytep out, lzo_uintp out_len, ++ lzo_uint ti, lzo_voidp wrkmem) ++{ ++ register const lzo_bytep ip; ++ lzo_bytep op; ++ const lzo_bytep const in_end = in + in_len; ++ const lzo_bytep const ip_end = in + in_len - 20; ++ const lzo_bytep ii; ++ lzo_dict_p const dict = (lzo_dict_p) wrkmem; ++ ++ op = out; ++ ip = in; ++ ii = ip - ti; ++ ++ ip += ti < 4 ? 4 - ti : 0; ++ for (;;) ++ { ++ const lzo_bytep m_pos; ++#if !(LZO_DETERMINISTIC) ++ LZO_DEFINE_UNINITIALIZED_VAR(lzo_uint, m_off, 0); ++ lzo_uint m_len; ++ lzo_uint dindex; ++next: ++ if __lzo_unlikely(ip >= ip_end) ++ break; ++ DINDEX1(dindex,ip); ++ GINDEX(m_pos,m_off,dict,dindex,in); ++ if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET)) ++ goto literal; ++#if 1 ++ if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) ++ goto try_match; ++ DINDEX2(dindex,ip); ++#endif ++ GINDEX(m_pos,m_off,dict,dindex,in); ++ if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET)) ++ goto literal; ++ if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) ++ goto try_match; ++ goto literal; ++ ++try_match: ++#if defined(UA_GET32) ++ if (UA_GET32(m_pos) != UA_GET32(ip)) ++#else ++ if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3]) ++#endif ++ { ++literal: ++ UPDATE_I(dict,0,dindex,ip,in); ++ ip += 1 + ((ip - ii) >> 5); ++ continue; ++ } ++ UPDATE_I(dict,0,dindex,ip,in); ++#else ++ lzo_uint m_off; ++ lzo_uint m_len; ++ { ++ lzo_uint32 dv; ++ lzo_uint dindex; ++literal: ++ ip += 1 + ((ip - ii) >> 5); ++next: ++ if __lzo_unlikely(ip >= ip_end) ++ break; ++ dv = UA_GET32(ip); ++ dindex = DINDEX(dv,ip); ++ GINDEX(m_off,m_pos,in+dict,dindex,in); ++ UPDATE_I(dict,0,dindex,ip,in); ++ if __lzo_unlikely(dv != UA_GET32(m_pos)) ++ goto literal; ++ } ++#endif ++ ++ { ++ register lzo_uint t = pd(ip,ii); ++ if (t != 0) ++ { ++ if (t <= 3) ++ { ++ op[-2] |= LZO_BYTE(t); ++#if defined(UA_COPY32) ++ UA_COPY32(op, ii); ++ op += t; ++#else ++ { do *op++ = *ii++; while (--t > 0); } ++#endif ++ } ++#if defined(UA_COPY32) || defined(UA_COPY64) ++ else if (t <= 16) ++ { ++ *op++ = LZO_BYTE(t - 3); ++#if defined(UA_COPY64) ++ UA_COPY64(op, ii); ++ UA_COPY64(op+8, ii+8); ++#else ++ UA_COPY32(op, ii); ++ UA_COPY32(op+4, ii+4); ++ UA_COPY32(op+8, ii+8); ++ UA_COPY32(op+12, ii+12); ++#endif ++ op += t; ++ } ++#endif ++ else ++ { ++ if (t <= 18) ++ *op++ = LZO_BYTE(t - 3); ++ else ++ { ++ register lzo_uint tt = t - 18; ++ *op++ = 0; ++ while __lzo_unlikely(tt > 255) ++ { ++ tt -= 255; ++#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) ++ * (volatile unsigned char *) op++ = 0; ++#else ++ *op++ = 0; ++#endif ++ } ++ assert(tt > 0); ++ *op++ = LZO_BYTE(tt); ++ } ++#if defined(UA_COPY32) || defined(UA_COPY64) ++ do { ++#if defined(UA_COPY64) ++ UA_COPY64(op, ii); ++ UA_COPY64(op+8, ii+8); ++#else ++ UA_COPY32(op, ii); ++ UA_COPY32(op+4, ii+4); ++ UA_COPY32(op+8, ii+8); ++ UA_COPY32(op+12, ii+12); ++#endif ++ op += 16; ii += 16; t -= 16; ++ } while (t >= 16); if (t > 0) ++#endif ++ { do *op++ = *ii++; while (--t > 0); } ++ } ++ } ++ } ++ m_len = 4; ++ { ++#if defined(UA_GET64) ++ lzo_uint64 v; ++ v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len); ++ if __lzo_unlikely(v == 0) { ++ do { ++ m_len += 8; ++ v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len); ++ if __lzo_unlikely(ip + m_len >= ip_end) ++ goto m_len_done; ++ } while (v == 0); ++ } ++#if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz64) ++ m_len += lzo_bitops_ctz64(v) / CHAR_BIT; ++#elif (LZO_ABI_LITTLE_ENDIAN) ++ if ((v & UCHAR_MAX) == 0) do { ++ v >>= CHAR_BIT; ++ m_len += 1; ++ } while ((v & UCHAR_MAX) == 0); ++#else ++ if (ip[m_len] == m_pos[m_len]) do { ++ m_len += 1; ++ } while (ip[m_len] == m_pos[m_len]); ++#endif ++#elif defined(UA_GET32) ++ lzo_uint32 v; ++ v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len); ++ if __lzo_unlikely(v == 0) { ++ do { ++ m_len += 4; ++ v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len); ++ if __lzo_unlikely(ip + m_len >= ip_end) ++ goto m_len_done; ++ } while (v == 0); ++ } ++#if (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz32) ++ m_len += lzo_bitops_ctz32(v) / CHAR_BIT; ++#elif (LZO_ABI_LITTLE_ENDIAN) ++ if ((v & UCHAR_MAX) == 0) do { ++ v >>= CHAR_BIT; ++ m_len += 1; ++ } while ((v & UCHAR_MAX) == 0); ++#else ++ if (ip[m_len] == m_pos[m_len]) do { ++ m_len += 1; ++ } while (ip[m_len] == m_pos[m_len]); ++#endif ++#else ++ if __lzo_unlikely(ip[m_len] == m_pos[m_len]) { ++ do { ++ m_len += 1; ++ if __lzo_unlikely(ip + m_len >= ip_end) ++ goto m_len_done; ++ } while (ip[m_len] == m_pos[m_len]); ++ } ++#endif ++ } ++m_len_done: ++ m_off = pd(ip,m_pos); ++ ip += m_len; ++ ii = ip; ++ if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET) ++ { ++ m_off -= 1; ++#if defined(LZO1X) ++ *op++ = LZO_BYTE(((m_len - 1) << 5) | ((m_off & 7) << 2)); ++ *op++ = LZO_BYTE(m_off >> 3); ++#elif defined(LZO1Y) ++ *op++ = LZO_BYTE(((m_len + 1) << 4) | ((m_off & 3) << 2)); ++ *op++ = LZO_BYTE(m_off >> 2); ++#endif ++ } ++ else if (m_off <= M3_MAX_OFFSET) ++ { ++ m_off -= 1; ++ if (m_len <= M3_MAX_LEN) ++ *op++ = LZO_BYTE(M3_MARKER | (m_len - 2)); ++ else ++ { ++ m_len -= M3_MAX_LEN; ++ *op++ = M3_MARKER | 0; ++ while __lzo_unlikely(m_len > 255) ++ { ++ m_len -= 255; ++#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) ++ * (volatile unsigned char *) op++ = 0; ++#else ++ *op++ = 0; ++#endif ++ } ++ *op++ = LZO_BYTE(m_len); ++ } ++ *op++ = LZO_BYTE(m_off << 2); ++ *op++ = LZO_BYTE(m_off >> 6); ++ } ++ else ++ { ++ m_off -= 0x4000; ++ if (m_len <= M4_MAX_LEN) ++ *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8) | (m_len - 2)); ++ else ++ { ++ m_len -= M4_MAX_LEN; ++ *op++ = LZO_BYTE(M4_MARKER | ((m_off >> 11) & 8)); ++ while __lzo_unlikely(m_len > 255) ++ { ++ m_len -= 255; ++#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) ++ * (volatile unsigned char *) op++ = 0; ++#else ++ *op++ = 0; ++#endif ++ } ++ *op++ = LZO_BYTE(m_len); ++ } ++ *op++ = LZO_BYTE(m_off << 2); ++ *op++ = LZO_BYTE(m_off >> 6); ++ } ++ goto next; ++ } ++ ++ *out_len = pd(op, out); ++ return pd(in_end,ii); ++} ++ ++LZO_PUBLIC(int) ++DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, ++ lzo_bytep out, lzo_uintp out_len, ++ lzo_voidp wrkmem ) ++{ ++ const lzo_bytep ip = in; ++ lzo_bytep op = out; ++ lzo_uint l = in_len; ++ lzo_uint t = 0; ++ ++ while (l > 20) ++ { ++ lzo_uint ll = l; ++ lzo_uintptr_t ll_end; ++#if 0 || (LZO_DETERMINISTIC) ++ ll = LZO_MIN(ll, 49152); ++#endif ++ ll_end = (lzo_uintptr_t)ip + ll; ++ if ((ll_end + ((t + ll) >> 5)) <= ll_end || (const lzo_bytep)(ll_end + ((t + ll) >> 5)) <= ip + ll) ++ break; ++#if (LZO_DETERMINISTIC) ++ lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t)); ++#endif ++ t = do_compress(ip,ll,op,out_len,t,wrkmem); ++ ip += ll; ++ op += *out_len; ++ l -= ll; ++ } ++ t += l; ++ ++ if (t > 0) ++ { ++ const lzo_bytep ii = in + in_len - t; ++ ++ if (op == out && t <= 238) ++ *op++ = LZO_BYTE(17 + t); ++ else if (t <= 3) ++ op[-2] |= LZO_BYTE(t); ++ else if (t <= 18) ++ *op++ = LZO_BYTE(t - 3); ++ else ++ { ++ lzo_uint tt = t - 18; ++ ++ *op++ = 0; ++ while (tt > 255) ++ { ++ tt -= 255; ++#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) ++ ++ * (volatile unsigned char *) op++ = 0; ++#else ++ *op++ = 0; ++#endif ++ } ++ assert(tt > 0); ++ *op++ = LZO_BYTE(tt); ++ } ++ do *op++ = *ii++; while (--t > 0); ++ } ++ ++ *op++ = M4_MARKER | 1; ++ *op++ = 0; ++ *op++ = 0; ++ ++ *out_len = pd(op, out); ++ return LZO_E_OK; ++} ++ ++#endif ++ ++#undef do_compress ++#undef DO_COMPRESS ++#undef LZO_HASH ++ ++#undef LZO_TEST_OVERRUN ++#undef DO_DECOMPRESS ++#define DO_DECOMPRESS lzo1x_decompress ++ ++#if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS) ++ ++#if defined(LZO_TEST_OVERRUN) ++# if !defined(LZO_TEST_OVERRUN_INPUT) ++# define LZO_TEST_OVERRUN_INPUT 2 ++# endif ++# if !defined(LZO_TEST_OVERRUN_OUTPUT) ++# define LZO_TEST_OVERRUN_OUTPUT 2 ++# endif ++# if !defined(LZO_TEST_OVERRUN_LOOKBEHIND) ++# define LZO_TEST_OVERRUN_LOOKBEHIND 1 ++# endif ++#endif ++ ++#undef TEST_IP ++#undef TEST_OP ++#undef TEST_LB ++#undef TEST_LBO ++#undef NEED_IP ++#undef NEED_OP ++#undef HAVE_TEST_IP ++#undef HAVE_TEST_OP ++#undef HAVE_NEED_IP ++#undef HAVE_NEED_OP ++#undef HAVE_ANY_IP ++#undef HAVE_ANY_OP ++ ++#if defined(LZO_TEST_OVERRUN_INPUT) ++# if (LZO_TEST_OVERRUN_INPUT >= 1) ++# define TEST_IP (ip < ip_end) ++# endif ++# if (LZO_TEST_OVERRUN_INPUT >= 2) ++# define NEED_IP(x) \ ++ if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun ++# endif ++#endif ++ ++#if defined(LZO_TEST_OVERRUN_OUTPUT) ++# if (LZO_TEST_OVERRUN_OUTPUT >= 1) ++# define TEST_OP (op <= op_end) ++# endif ++# if (LZO_TEST_OVERRUN_OUTPUT >= 2) ++# undef TEST_OP ++# define NEED_OP(x) \ ++ if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun ++# endif ++#endif ++ ++#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) ++# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun ++# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun ++#else ++# define TEST_LB(m_pos) ((void) 0) ++# define TEST_LBO(m_pos,o) ((void) 0) ++#endif ++ ++#if !defined(LZO_EOF_CODE) && !defined(TEST_IP) ++# define TEST_IP (ip < ip_end) ++#endif ++ ++#if defined(TEST_IP) ++# define HAVE_TEST_IP 1 ++#else ++# define TEST_IP 1 ++#endif ++#if defined(TEST_OP) ++# define HAVE_TEST_OP 1 ++#else ++# define TEST_OP 1 ++#endif ++ ++#if defined(NEED_IP) ++# define HAVE_NEED_IP 1 ++#else ++# define NEED_IP(x) ((void) 0) ++#endif ++#if defined(NEED_OP) ++# define HAVE_NEED_OP 1 ++#else ++# define NEED_OP(x) ((void) 0) ++#endif ++ ++#if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) ++# define HAVE_ANY_IP 1 ++#endif ++#if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP) ++# define HAVE_ANY_OP 1 ++#endif ++ ++#if defined(DO_DECOMPRESS) ++LZO_PUBLIC(int) ++DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, ++ lzo_bytep out, lzo_uintp out_len, ++ lzo_voidp wrkmem ) ++#endif ++{ ++ register lzo_bytep op; ++ register const lzo_bytep ip; ++ register lzo_uint t; ++#if defined(COPY_DICT) ++ lzo_uint m_off; ++ const lzo_bytep dict_end; ++#else ++ register const lzo_bytep m_pos; ++#endif ++ ++ const lzo_bytep const ip_end = in + in_len; ++#if defined(HAVE_ANY_OP) ++ lzo_bytep const op_end = out + *out_len; ++#endif ++#if defined(LZO1Z) ++ lzo_uint last_m_off = 0; ++#endif ++ ++ LZO_UNUSED(wrkmem); ++ ++#if defined(COPY_DICT) ++ if (dict) ++ { ++ if (dict_len > M4_MAX_OFFSET) ++ { ++ dict += dict_len - M4_MAX_OFFSET; ++ dict_len = M4_MAX_OFFSET; ++ } ++ dict_end = dict + dict_len; ++ } ++ else ++ { ++ dict_len = 0; ++ dict_end = NULL; ++ } ++#endif ++ ++ *out_len = 0; ++ ++ op = out; ++ ip = in; ++ ++ if (*ip > 17) ++ { ++ t = *ip++ - 17; ++ if (t < 4) ++ goto match_next; ++ assert(t > 0); NEED_OP(t); NEED_IP(t+1); ++ do *op++ = *ip++; while (--t > 0); ++ goto first_literal_run; ++ } ++ ++ while (TEST_IP && TEST_OP) ++ { ++ t = *ip++; ++ if (t >= 16) ++ goto match; ++ if (t == 0) ++ { ++ NEED_IP(1); ++ while (*ip == 0) ++ { ++ t += 255; ++ ip++; ++ NEED_IP(1); ++ } ++ t += 15 + *ip++; ++ } ++ assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); ++#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) ++ t += 3; ++ if (t >= 8) do ++ { ++ UA_COPY64(op,ip); ++ op += 8; ip += 8; t -= 8; ++ } while (t >= 8); ++ if (t >= 4) ++ { ++ UA_COPY32(op,ip); ++ op += 4; ip += 4; t -= 4; ++ } ++ if (t > 0) ++ { ++ *op++ = *ip++; ++ if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } ++ } ++#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) ++#if !defined(LZO_UNALIGNED_OK_4) ++ if (PTR_ALIGNED2_4(op,ip)) ++ { ++#endif ++ UA_COPY32(op,ip); ++ op += 4; ip += 4; ++ if (--t > 0) ++ { ++ if (t >= 4) ++ { ++ do { ++ UA_COPY32(op,ip); ++ op += 4; ip += 4; t -= 4; ++ } while (t >= 4); ++ if (t > 0) do *op++ = *ip++; while (--t > 0); ++ } ++ else ++ do *op++ = *ip++; while (--t > 0); ++ } ++#if !defined(LZO_UNALIGNED_OK_4) ++ } ++ else ++#endif ++#endif ++#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) ++ { ++ *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; ++ do *op++ = *ip++; while (--t > 0); ++ } ++#endif ++ ++first_literal_run: ++ ++ t = *ip++; ++ if (t >= 16) ++ goto match; ++#if defined(COPY_DICT) ++#if defined(LZO1Z) ++ m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); ++ last_m_off = m_off; ++#else ++ m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2); ++#endif ++ NEED_OP(3); ++ t = 3; COPY_DICT(t,m_off) ++#else ++#if defined(LZO1Z) ++ t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); ++ m_pos = op - t; ++ last_m_off = t; ++#else ++ m_pos = op - (1 + M2_MAX_OFFSET); ++ m_pos -= t >> 2; ++ m_pos -= *ip++ << 2; ++#endif ++ TEST_LB(m_pos); NEED_OP(3); ++ *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos; ++#endif ++ goto match_done; ++ ++ do { ++match: ++ if (t >= 64) ++ { ++#if defined(COPY_DICT) ++#if defined(LZO1X) ++ m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3); ++ t = (t >> 5) - 1; ++#elif defined(LZO1Y) ++ m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2); ++ t = (t >> 4) - 3; ++#elif defined(LZO1Z) ++ m_off = t & 0x1f; ++ if (m_off >= 0x1c) ++ m_off = last_m_off; ++ else ++ { ++ m_off = 1 + (m_off << 6) + (*ip++ >> 2); ++ last_m_off = m_off; ++ } ++ t = (t >> 5) - 1; ++#endif ++#else ++#if defined(LZO1X) ++ m_pos = op - 1; ++ m_pos -= (t >> 2) & 7; ++ m_pos -= *ip++ << 3; ++ t = (t >> 5) - 1; ++#elif defined(LZO1Y) ++ m_pos = op - 1; ++ m_pos -= (t >> 2) & 3; ++ m_pos -= *ip++ << 2; ++ t = (t >> 4) - 3; ++#elif defined(LZO1Z) ++ { ++ lzo_uint off = t & 0x1f; ++ m_pos = op; ++ if (off >= 0x1c) ++ { ++ assert(last_m_off > 0); ++ m_pos -= last_m_off; ++ } ++ else ++ { ++ off = 1 + (off << 6) + (*ip++ >> 2); ++ m_pos -= off; ++ last_m_off = off; ++ } ++ } ++ t = (t >> 5) - 1; ++#endif ++ TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); ++ goto copy_match; ++#endif ++ } ++ else if (t >= 32) ++ { ++ t &= 31; ++ if (t == 0) ++ { ++ NEED_IP(1); ++ while (*ip == 0) ++ { ++ t += 255; ++ ip++; ++ NEED_IP(1); ++ } ++ t += 31 + *ip++; ++ } ++#if defined(COPY_DICT) ++#if defined(LZO1Z) ++ m_off = 1 + (ip[0] << 6) + (ip[1] >> 2); ++ last_m_off = m_off; ++#else ++ m_off = 1 + (ip[0] >> 2) + (ip[1] << 6); ++#endif ++#else ++#if defined(LZO1Z) ++ { ++ lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2); ++ m_pos = op - off; ++ last_m_off = off; ++ } ++#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) ++ m_pos = op - 1; ++ m_pos -= UA_GET16(ip) >> 2; ++#else ++ m_pos = op - 1; ++ m_pos -= (ip[0] >> 2) + (ip[1] << 6); ++#endif ++#endif ++ ip += 2; ++ } ++ else if (t >= 16) ++ { ++#if defined(COPY_DICT) ++ m_off = (t & 8) << 11; ++#else ++ m_pos = op; ++ m_pos -= (t & 8) << 11; ++#endif ++ t &= 7; ++ if (t == 0) ++ { ++ NEED_IP(1); ++ while (*ip == 0) ++ { ++ t += 255; ++ ip++; ++ NEED_IP(1); ++ } ++ t += 7 + *ip++; ++ } ++#if defined(COPY_DICT) ++#if defined(LZO1Z) ++ m_off += (ip[0] << 6) + (ip[1] >> 2); ++#else ++ m_off += (ip[0] >> 2) + (ip[1] << 6); ++#endif ++ ip += 2; ++ if (m_off == 0) ++ goto eof_found; ++ m_off += 0x4000; ++#if defined(LZO1Z) ++ last_m_off = m_off; ++#endif ++#else ++#if defined(LZO1Z) ++ m_pos -= (ip[0] << 6) + (ip[1] >> 2); ++#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) ++ m_pos -= UA_GET16(ip) >> 2; ++#else ++ m_pos -= (ip[0] >> 2) + (ip[1] << 6); ++#endif ++ ip += 2; ++ if (m_pos == op) ++ goto eof_found; ++ m_pos -= 0x4000; ++#if defined(LZO1Z) ++ last_m_off = pd((const lzo_bytep)op, m_pos); ++#endif ++#endif ++ } ++ else ++ { ++#if defined(COPY_DICT) ++#if defined(LZO1Z) ++ m_off = 1 + (t << 6) + (*ip++ >> 2); ++ last_m_off = m_off; ++#else ++ m_off = 1 + (t >> 2) + (*ip++ << 2); ++#endif ++ NEED_OP(2); ++ t = 2; COPY_DICT(t,m_off) ++#else ++#if defined(LZO1Z) ++ t = 1 + (t << 6) + (*ip++ >> 2); ++ m_pos = op - t; ++ last_m_off = t; ++#else ++ m_pos = op - 1; ++ m_pos -= t >> 2; ++ m_pos -= *ip++ << 2; ++#endif ++ TEST_LB(m_pos); NEED_OP(2); ++ *op++ = *m_pos++; *op++ = *m_pos; ++#endif ++ goto match_done; ++ } ++ ++#if defined(COPY_DICT) ++ ++ NEED_OP(t+3-1); ++ t += 3-1; COPY_DICT(t,m_off) ++ ++#else ++ ++ TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); ++#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) ++ if (op - m_pos >= 8) ++ { ++ t += (3 - 1); ++ if (t >= 8) do ++ { ++ UA_COPY64(op,m_pos); ++ op += 8; m_pos += 8; t -= 8; ++ } while (t >= 8); ++ if (t >= 4) ++ { ++ UA_COPY32(op,m_pos); ++ op += 4; m_pos += 4; t -= 4; ++ } ++ if (t > 0) ++ { ++ *op++ = m_pos[0]; ++ if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } } ++ } ++ } ++ else ++#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) ++#if !defined(LZO_UNALIGNED_OK_4) ++ if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) ++ { ++ assert((op - m_pos) >= 4); ++#else ++ if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) ++ { ++#endif ++ UA_COPY32(op,m_pos); ++ op += 4; m_pos += 4; t -= 4 - (3 - 1); ++ do { ++ UA_COPY32(op,m_pos); ++ op += 4; m_pos += 4; t -= 4; ++ } while (t >= 4); ++ if (t > 0) do *op++ = *m_pos++; while (--t > 0); ++ } ++ else ++#endif ++ { ++copy_match: ++ *op++ = *m_pos++; *op++ = *m_pos++; ++ do *op++ = *m_pos++; while (--t > 0); ++ } ++ ++#endif ++ ++match_done: ++#if defined(LZO1Z) ++ t = ip[-1] & 3; ++#else ++ t = ip[-2] & 3; ++#endif ++ if (t == 0) ++ break; ++ ++match_next: ++ assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); ++#if 0 ++ do *op++ = *ip++; while (--t > 0); ++#else ++ *op++ = *ip++; ++ if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } ++#endif ++ t = *ip++; ++ } while (TEST_IP && TEST_OP); ++ } ++ ++#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) ++ *out_len = pd(op, out); ++ return LZO_E_EOF_NOT_FOUND; ++#endif ++ ++eof_found: ++ assert(t == 1); ++ *out_len = pd(op, out); ++ return (ip == ip_end ? LZO_E_OK : ++ (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); ++ ++#if defined(HAVE_NEED_IP) ++input_overrun: ++ *out_len = pd(op, out); ++ return LZO_E_INPUT_OVERRUN; ++#endif ++ ++#if defined(HAVE_NEED_OP) ++output_overrun: ++ *out_len = pd(op, out); ++ return LZO_E_OUTPUT_OVERRUN; ++#endif ++ ++#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) ++lookbehind_overrun: ++ *out_len = pd(op, out); ++ return LZO_E_LOOKBEHIND_OVERRUN; ++#endif ++} ++ ++#endif ++ ++#define LZO_TEST_OVERRUN 1 ++#undef DO_DECOMPRESS ++#define DO_DECOMPRESS lzo1x_decompress_safe ++ ++#if !defined(MINILZO_CFG_SKIP_LZO1X_DECOMPRESS_SAFE) ++ ++#if defined(LZO_TEST_OVERRUN) ++# if !defined(LZO_TEST_OVERRUN_INPUT) ++# define LZO_TEST_OVERRUN_INPUT 2 ++# endif ++# if !defined(LZO_TEST_OVERRUN_OUTPUT) ++# define LZO_TEST_OVERRUN_OUTPUT 2 ++# endif ++# if !defined(LZO_TEST_OVERRUN_LOOKBEHIND) ++# define LZO_TEST_OVERRUN_LOOKBEHIND 1 ++# endif ++#endif ++ ++#undef TEST_IP ++#undef TEST_OP ++#undef TEST_LB ++#undef TEST_LBO ++#undef NEED_IP ++#undef NEED_OP ++#undef HAVE_TEST_IP ++#undef HAVE_TEST_OP ++#undef HAVE_NEED_IP ++#undef HAVE_NEED_OP ++#undef HAVE_ANY_IP ++#undef HAVE_ANY_OP ++ ++#if defined(LZO_TEST_OVERRUN_INPUT) ++# if (LZO_TEST_OVERRUN_INPUT >= 1) ++# define TEST_IP (ip < ip_end) ++# endif ++# if (LZO_TEST_OVERRUN_INPUT >= 2) ++# define NEED_IP(x) \ ++ if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun ++# endif ++#endif ++ ++#if defined(LZO_TEST_OVERRUN_OUTPUT) ++# if (LZO_TEST_OVERRUN_OUTPUT >= 1) ++# define TEST_OP (op <= op_end) ++# endif ++# if (LZO_TEST_OVERRUN_OUTPUT >= 2) ++# undef TEST_OP ++# define NEED_OP(x) \ ++ if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun ++# endif ++#endif ++ ++#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) ++# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun ++# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun ++#else ++# define TEST_LB(m_pos) ((void) 0) ++# define TEST_LBO(m_pos,o) ((void) 0) ++#endif ++ ++#if !defined(LZO_EOF_CODE) && !defined(TEST_IP) ++# define TEST_IP (ip < ip_end) ++#endif ++ ++#if defined(TEST_IP) ++# define HAVE_TEST_IP 1 ++#else ++# define TEST_IP 1 ++#endif ++#if defined(TEST_OP) ++# define HAVE_TEST_OP 1 ++#else ++# define TEST_OP 1 ++#endif ++ ++#if defined(NEED_IP) ++# define HAVE_NEED_IP 1 ++#else ++# define NEED_IP(x) ((void) 0) ++#endif ++#if defined(NEED_OP) ++# define HAVE_NEED_OP 1 ++#else ++# define NEED_OP(x) ((void) 0) ++#endif ++ ++#if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) ++# define HAVE_ANY_IP 1 ++#endif ++#if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP) ++# define HAVE_ANY_OP 1 ++#endif ++ ++#if defined(DO_DECOMPRESS) ++LZO_PUBLIC(int) ++DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, ++ lzo_bytep out, lzo_uintp out_len, ++ lzo_voidp wrkmem ) ++#endif ++{ ++ register lzo_bytep op; ++ register const lzo_bytep ip; ++ register lzo_uint t; ++#if defined(COPY_DICT) ++ lzo_uint m_off; ++ const lzo_bytep dict_end; ++#else ++ register const lzo_bytep m_pos; ++#endif ++ ++ const lzo_bytep const ip_end = in + in_len; ++#if defined(HAVE_ANY_OP) ++ lzo_bytep const op_end = out + *out_len; ++#endif ++#if defined(LZO1Z) ++ lzo_uint last_m_off = 0; ++#endif ++ ++ LZO_UNUSED(wrkmem); ++ ++#if defined(COPY_DICT) ++ if (dict) ++ { ++ if (dict_len > M4_MAX_OFFSET) ++ { ++ dict += dict_len - M4_MAX_OFFSET; ++ dict_len = M4_MAX_OFFSET; ++ } ++ dict_end = dict + dict_len; ++ } ++ else ++ { ++ dict_len = 0; ++ dict_end = NULL; ++ } ++#endif ++ ++ *out_len = 0; ++ ++ op = out; ++ ip = in; ++ ++ if (*ip > 17) ++ { ++ t = *ip++ - 17; ++ if (t < 4) ++ goto match_next; ++ assert(t > 0); NEED_OP(t); NEED_IP(t+1); ++ do *op++ = *ip++; while (--t > 0); ++ goto first_literal_run; ++ } ++ ++ while (TEST_IP && TEST_OP) ++ { ++ t = *ip++; ++ if (t >= 16) ++ goto match; ++ if (t == 0) ++ { ++ NEED_IP(1); ++ while (*ip == 0) ++ { ++ t += 255; ++ ip++; ++ NEED_IP(1); ++ } ++ t += 15 + *ip++; ++ } ++ assert(t > 0); NEED_OP(t+3); NEED_IP(t+4); ++#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) ++ t += 3; ++ if (t >= 8) do ++ { ++ UA_COPY64(op,ip); ++ op += 8; ip += 8; t -= 8; ++ } while (t >= 8); ++ if (t >= 4) ++ { ++ UA_COPY32(op,ip); ++ op += 4; ip += 4; t -= 4; ++ } ++ if (t > 0) ++ { ++ *op++ = *ip++; ++ if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } ++ } ++#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) ++#if !defined(LZO_UNALIGNED_OK_4) ++ if (PTR_ALIGNED2_4(op,ip)) ++ { ++#endif ++ UA_COPY32(op,ip); ++ op += 4; ip += 4; ++ if (--t > 0) ++ { ++ if (t >= 4) ++ { ++ do { ++ UA_COPY32(op,ip); ++ op += 4; ip += 4; t -= 4; ++ } while (t >= 4); ++ if (t > 0) do *op++ = *ip++; while (--t > 0); ++ } ++ else ++ do *op++ = *ip++; while (--t > 0); ++ } ++#if !defined(LZO_UNALIGNED_OK_4) ++ } ++ else ++#endif ++#endif ++#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) ++ { ++ *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; ++ do *op++ = *ip++; while (--t > 0); ++ } ++#endif ++ ++first_literal_run: ++ ++ t = *ip++; ++ if (t >= 16) ++ goto match; ++#if defined(COPY_DICT) ++#if defined(LZO1Z) ++ m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); ++ last_m_off = m_off; ++#else ++ m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2); ++#endif ++ NEED_OP(3); ++ t = 3; COPY_DICT(t,m_off) ++#else ++#if defined(LZO1Z) ++ t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); ++ m_pos = op - t; ++ last_m_off = t; ++#else ++ m_pos = op - (1 + M2_MAX_OFFSET); ++ m_pos -= t >> 2; ++ m_pos -= *ip++ << 2; ++#endif ++ TEST_LB(m_pos); NEED_OP(3); ++ *op++ = *m_pos++; *op++ = *m_pos++; *op++ = *m_pos; ++#endif ++ goto match_done; ++ ++ do { ++match: ++ if (t >= 64) ++ { ++#if defined(COPY_DICT) ++#if defined(LZO1X) ++ m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3); ++ t = (t >> 5) - 1; ++#elif defined(LZO1Y) ++ m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2); ++ t = (t >> 4) - 3; ++#elif defined(LZO1Z) ++ m_off = t & 0x1f; ++ if (m_off >= 0x1c) ++ m_off = last_m_off; ++ else ++ { ++ m_off = 1 + (m_off << 6) + (*ip++ >> 2); ++ last_m_off = m_off; ++ } ++ t = (t >> 5) - 1; ++#endif ++#else ++#if defined(LZO1X) ++ m_pos = op - 1; ++ m_pos -= (t >> 2) & 7; ++ m_pos -= *ip++ << 3; ++ t = (t >> 5) - 1; ++#elif defined(LZO1Y) ++ m_pos = op - 1; ++ m_pos -= (t >> 2) & 3; ++ m_pos -= *ip++ << 2; ++ t = (t >> 4) - 3; ++#elif defined(LZO1Z) ++ { ++ lzo_uint off = t & 0x1f; ++ m_pos = op; ++ if (off >= 0x1c) ++ { ++ assert(last_m_off > 0); ++ m_pos -= last_m_off; ++ } ++ else ++ { ++ off = 1 + (off << 6) + (*ip++ >> 2); ++ m_pos -= off; ++ last_m_off = off; ++ } ++ } ++ t = (t >> 5) - 1; ++#endif ++ TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); ++ goto copy_match; ++#endif ++ } ++ else if (t >= 32) ++ { ++ t &= 31; ++ if (t == 0) ++ { ++ NEED_IP(1); ++ while (*ip == 0) ++ { ++ t += 255; ++ ip++; ++ NEED_IP(1); ++ } ++ t += 31 + *ip++; ++ } ++#if defined(COPY_DICT) ++#if defined(LZO1Z) ++ m_off = 1 + (ip[0] << 6) + (ip[1] >> 2); ++ last_m_off = m_off; ++#else ++ m_off = 1 + (ip[0] >> 2) + (ip[1] << 6); ++#endif ++#else ++#if defined(LZO1Z) ++ { ++ lzo_uint off = 1 + (ip[0] << 6) + (ip[1] >> 2); ++ m_pos = op - off; ++ last_m_off = off; ++ } ++#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) ++ m_pos = op - 1; ++ m_pos -= UA_GET16(ip) >> 2; ++#else ++ m_pos = op - 1; ++ m_pos -= (ip[0] >> 2) + (ip[1] << 6); ++#endif ++#endif ++ ip += 2; ++ } ++ else if (t >= 16) ++ { ++#if defined(COPY_DICT) ++ m_off = (t & 8) << 11; ++#else ++ m_pos = op; ++ m_pos -= (t & 8) << 11; ++#endif ++ t &= 7; ++ if (t == 0) ++ { ++ NEED_IP(1); ++ while (*ip == 0) ++ { ++ t += 255; ++ ip++; ++ NEED_IP(1); ++ } ++ t += 7 + *ip++; ++ } ++#if defined(COPY_DICT) ++#if defined(LZO1Z) ++ m_off += (ip[0] << 6) + (ip[1] >> 2); ++#else ++ m_off += (ip[0] >> 2) + (ip[1] << 6); ++#endif ++ ip += 2; ++ if (m_off == 0) ++ goto eof_found; ++ m_off += 0x4000; ++#if defined(LZO1Z) ++ last_m_off = m_off; ++#endif ++#else ++#if defined(LZO1Z) ++ m_pos -= (ip[0] << 6) + (ip[1] >> 2); ++#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) ++ m_pos -= UA_GET16(ip) >> 2; ++#else ++ m_pos -= (ip[0] >> 2) + (ip[1] << 6); ++#endif ++ ip += 2; ++ if (m_pos == op) ++ goto eof_found; ++ m_pos -= 0x4000; ++#if defined(LZO1Z) ++ last_m_off = pd((const lzo_bytep)op, m_pos); ++#endif ++#endif ++ } ++ else ++ { ++#if defined(COPY_DICT) ++#if defined(LZO1Z) ++ m_off = 1 + (t << 6) + (*ip++ >> 2); ++ last_m_off = m_off; ++#else ++ m_off = 1 + (t >> 2) + (*ip++ << 2); ++#endif ++ NEED_OP(2); ++ t = 2; COPY_DICT(t,m_off) ++#else ++#if defined(LZO1Z) ++ t = 1 + (t << 6) + (*ip++ >> 2); ++ m_pos = op - t; ++ last_m_off = t; ++#else ++ m_pos = op - 1; ++ m_pos -= t >> 2; ++ m_pos -= *ip++ << 2; ++#endif ++ TEST_LB(m_pos); NEED_OP(2); ++ *op++ = *m_pos++; *op++ = *m_pos; ++#endif ++ goto match_done; ++ } ++ ++#if defined(COPY_DICT) ++ ++ NEED_OP(t+3-1); ++ t += 3-1; COPY_DICT(t,m_off) ++ ++#else ++ ++ TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); ++#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) ++ if (op - m_pos >= 8) ++ { ++ t += (3 - 1); ++ if (t >= 8) do ++ { ++ UA_COPY64(op,m_pos); ++ op += 8; m_pos += 8; t -= 8; ++ } while (t >= 8); ++ if (t >= 4) ++ { ++ UA_COPY32(op,m_pos); ++ op += 4; m_pos += 4; t -= 4; ++ } ++ if (t > 0) ++ { ++ *op++ = m_pos[0]; ++ if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } } ++ } ++ } ++ else ++#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) ++#if !defined(LZO_UNALIGNED_OK_4) ++ if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) ++ { ++ assert((op - m_pos) >= 4); ++#else ++ if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) ++ { ++#endif ++ UA_COPY32(op,m_pos); ++ op += 4; m_pos += 4; t -= 4 - (3 - 1); ++ do { ++ UA_COPY32(op,m_pos); ++ op += 4; m_pos += 4; t -= 4; ++ } while (t >= 4); ++ if (t > 0) do *op++ = *m_pos++; while (--t > 0); ++ } ++ else ++#endif ++ { ++copy_match: ++ *op++ = *m_pos++; *op++ = *m_pos++; ++ do *op++ = *m_pos++; while (--t > 0); ++ } ++ ++#endif ++ ++match_done: ++#if defined(LZO1Z) ++ t = ip[-1] & 3; ++#else ++ t = ip[-2] & 3; ++#endif ++ if (t == 0) ++ break; ++ ++match_next: ++ assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+1); ++#if 0 ++ do *op++ = *ip++; while (--t > 0); ++#else ++ *op++ = *ip++; ++ if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } ++#endif ++ t = *ip++; ++ } while (TEST_IP && TEST_OP); ++ } ++ ++#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) ++ *out_len = pd(op, out); ++ return LZO_E_EOF_NOT_FOUND; ++#endif ++ ++eof_found: ++ assert(t == 1); ++ *out_len = pd(op, out); ++ return (ip == ip_end ? LZO_E_OK : ++ (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); ++ ++#if defined(HAVE_NEED_IP) ++input_overrun: ++ *out_len = pd(op, out); ++ return LZO_E_INPUT_OVERRUN; ++#endif ++ ++#if defined(HAVE_NEED_OP) ++output_overrun: ++ *out_len = pd(op, out); ++ return LZO_E_OUTPUT_OVERRUN; ++#endif ++ ++#if defined(LZO_TEST_OVERRUN_LOOKBEHIND) ++lookbehind_overrun: ++ *out_len = pd(op, out); ++ return LZO_E_LOOKBEHIND_OVERRUN; ++#endif ++} ++ ++#endif ++ ++/***** End of minilzo.c *****/ ++ +Index: b/grub-core/lib/minilzo/minilzo.h +=================================================================== +--- /dev/null ++++ b/grub-core/lib/minilzo/minilzo.h +@@ -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 */ ++ +Index: b/grub-core/lib/posix_wrap/limits.h +=================================================================== +--- /dev/null ++++ b/grub-core/lib/posix_wrap/limits.h +@@ -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 +Index: b/grub-core/lib/posix_wrap/sys/types.h +=================================================================== +--- a/grub-core/lib/posix_wrap/sys/types.h ++++ b/grub-core/lib/posix_wrap/sys/types.h +@@ -24,9 +24,6 @@ + typedef grub_size_t size_t; + 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_uint16_t uint16_t; + typedef grub_uint32_t uint32_t; +Index: b/include/grub/file.h +=================================================================== +--- a/include/grub/file.h ++++ b/include/grub/file.h +@@ -56,9 +56,10 @@ + { + GRUB_FILE_FILTER_GZIO, + GRUB_FILE_FILTER_XZIO, ++ GRUB_FILE_FILTER_LZOPIO, + GRUB_FILE_FILTER_MAX, + 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; + + typedef grub_file_t (*grub_file_filter_t) (grub_file_t in); +Index: b/include/grub/libgcc.h +=================================================================== +--- a/include/grub/libgcc.h ++++ b/include/grub/libgcc.h +@@ -39,6 +39,12 @@ + # ifdef HAVE___BSWAPDI2 + void EXPORT_FUNC (__bswapdi2) (void); + # endif ++# ifdef HAVE___CTZDI2 ++void EXPORT_FUNC (__ctzdi2) (void); ++# endif ++# ifdef HAVE___CTZSI2 ++void EXPORT_FUNC (__ctzsi2) (void); ++# endif + #endif + + #ifdef HAVE___TRAMPOLINE_SETUP +Index: b/include/grub/types.h +=================================================================== +--- a/include/grub/types.h ++++ b/include/grub/types.h +@@ -113,6 +113,10 @@ + # define PRIuGRUB_SIZE "u" + #endif + ++#define GRUB_UCHAR_MAX 0xFF ++#define GRUB_USHRT_MAX 65535 ++#define GRUB_UINT_MAX 4294967295U ++ + #if GRUB_CPU_SIZEOF_LONG == 8 + # define GRUB_ULONG_MAX 18446744073709551615UL + # define GRUB_LONG_MAX 9223372036854775807L +@@ -215,4 +219,31 @@ + # define grub_cpu_to_le32_compile_time(x) ((grub_uint32_t) (x)) + #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 */ +Index: b/util/import_gcry.py +=================================================================== +--- a/util/import_gcry.py ++++ b/util/import_gcry.py +@@ -73,6 +73,8 @@ + cryptolist.write ("AES-192: gcry_rijndael\n"); + cryptolist.write ("AES-256: gcry_rijndael\n"); + ++cryptolist.write ("ADLER32: adler32\n"); ++ + for cipher_file in cipher_files: + infile = os.path.join (cipher_dir_in, cipher_file) + outfile = os.path.join (cipher_dir_out, cipher_file) diff --git a/master/debian/mkconfig_gnumach.patch b/master/debian/mkconfig_gnumach.patch new file mode 100644 index 0000000..2c28ef5 --- /dev/null +++ b/master/debian/mkconfig_gnumach.patch @@ -0,0 +1,53 @@ +Description: Add support for GRUB_CMDLINE_GNUMACH +Author: Samuel Thibault <samuel.thibault@ens-lyon.org> +Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3942 +Last-Update: 2012-03-05 + +Index: b/docs/grub.texi +=================================================================== +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -1167,6 +1167,9 @@ + As @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT}, but for + NetBSD. + ++@item GRUB_CMDLINE_GNUMACH ++As @samp{GRUB_CMDLINE_LINUX}, but for GNU Mach. ++ + @item GRUB_CMDLINE_XEN + @itemx GRUB_CMDLINE_XEN_DEFAULT + The values of these options are appended to the values of +Index: b/util/grub-mkconfig.in +=================================================================== +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -244,6 +244,7 @@ + GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT \ + GRUB_CMDLINE_NETBSD \ + GRUB_CMDLINE_NETBSD_DEFAULT \ ++ GRUB_CMDLINE_GNUMACH \ + GRUB_TERMINAL_INPUT \ + GRUB_TERMINAL_OUTPUT \ + GRUB_SERIAL_COMMAND \ +Index: b/util/grub.d/10_hurd.in +=================================================================== +--- a/util/grub.d/10_hurd.in ++++ b/util/grub.d/10_hurd.in +@@ -84,7 +84,7 @@ + message="$(gettext_printf "Loading GNU Mach ...")" + cat << EOF + echo '$message' +- multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} ++ multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} ${GRUB_CMDLINE_GNUMACH} + EOF + save_default_entry | sed -e "s/^/\t/" + prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" +@@ -108,7 +108,7 @@ + message="$(gettext_printf "Loading GNU Mach ...")" + cat << EOF + echo '$message' +- multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} -s ++ multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/} -s ${GRUB_CMDLINE_GNUMACH} + EOF + prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/" + message="$(gettext_printf "Loading the Hurd ...")" diff --git a/master/debian/mkconfig_loopback.patch b/master/debian/mkconfig_loopback.patch new file mode 100644 index 0000000..1c04063 --- /dev/null +++ b/master/debian/mkconfig_loopback.patch @@ -0,0 +1,84 @@ +Description: Handle filesystems loop-mounted on file images + Improve prepare_grub_to_access_device to emit appropriate commands for such + filesystems, and ignore them in Linux grub.d scripts. + . + This is needed for Ubuntu's Wubi installation method. + . + This patch isn't inherently Debian/Ubuntu-specific. losetup and + /proc/mounts are Linux-specific, though, so we might need to refine this + before sending it upstream. The changes to the Linux grub.d scripts might + be better handled by integrating 10_lupin properly instead. + +Index: b/util/grub-mkconfig_lib.in +=================================================================== +--- a/util/grub-mkconfig_lib.in ++++ b/util/grub-mkconfig_lib.in +@@ -105,6 +105,21 @@ + { + device="$1" + ++ loop_file= ++ case ${device} in ++ /dev/loop/*|/dev/loop[0-9]) ++ grub_loop_device="${device#/dev/}" ++ loop_file=`losetup "${device}" | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` ++ case $loop_file in ++ /dev/*) ;; ++ *) ++ loop_device="${device}" ++ device=`"${grub_probe}" --target=device "${loop_file}"` ++ ;; ++ esac ++ ;; ++ esac ++ + if dmsetup status $device 2>/dev/null | grep -q 'crypt[[:space:]]$'; then + grub_warn \ + "$device is a crypto device, which GRUB cannot read directly. Some" \ +@@ -141,6 +156,14 @@ + if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then + echo "search --no-floppy --fs-uuid --set=root ${fs_uuid}" + fi ++ ++ if [ "x${loop_file}" != x ]; then ++ loop_mountpoint="$(awk '"'${loop_file}'" ~ "^"$2 && $2 != "/" { print $2 }' /proc/mounts | tail -n1)" ++ if [ "x${loop_mountpoint}" != x ]; then ++ echo "loopback ${grub_loop_device} ${loop_file#$loop_mountpoint}" ++ echo "set root=(${grub_loop_device})" ++ fi ++ fi + } + + grub_file_is_not_garbage () +Index: b/util/grub.d/10_linux.in +=================================================================== +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -40,6 +40,11 @@ + case ${GRUB_DEVICE} in + /dev/loop/*|/dev/loop[0-9]) + GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` ++ # We can't cope with devices loop-mounted from files here. ++ case ${GRUB_DEVICE} in ++ /dev/*) ;; ++ *) exit 0 ;; ++ esac + ;; + esac + +Index: b/util/grub.d/20_linux_xen.in +=================================================================== +--- a/util/grub.d/20_linux_xen.in ++++ b/util/grub.d/20_linux_xen.in +@@ -40,6 +40,11 @@ + case ${GRUB_DEVICE} in + /dev/loop/*|/dev/loop[0-9]) + GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` ++ # We can't cope with devices loop-mounted from files here. ++ case ${GRUB_DEVICE} in ++ /dev/*) ;; ++ *) exit 0 ;; ++ esac + ;; + esac + diff --git a/master/debian/mkconfig_skip_dmcrypt.patch b/master/debian/mkconfig_skip_dmcrypt.patch new file mode 100644 index 0000000..4e74652 --- /dev/null +++ b/master/debian/mkconfig_skip_dmcrypt.patch @@ -0,0 +1,30 @@ +Description: Warn and return without error if /boot is a dm-crypt device + With any luck the administrator knows what they're doing; in any event, we + probably can't improve matters by having update-grub exit non-zero. +Author: Marc Haber <mh+debian-bugs@zugschlus.de> +Author: Colin Watson <cjwatson@debian.org> +Origin: other, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=542165#25 +Bug-Debian: http://bugs.debian.org/542165 +Forwarded: no +Last-Update: 2010-06-05 + +Index: b/util/grub-mkconfig_lib.in +=================================================================== +--- a/util/grub-mkconfig_lib.in ++++ b/util/grub-mkconfig_lib.in +@@ -105,6 +105,15 @@ + { + device="$1" + ++ if dmsetup status $device 2>/dev/null | grep -q 'crypt[[:space:]]$'; then ++ grub_warn \ ++ "$device is a crypto device, which GRUB cannot read directly. Some" \ ++ "necessary modules may be missing from /boot/grub/grub.cfg. You may" \ ++ "need to list them in GRUB_PRELOAD_MODULES in /etc/default/grub. See" \ ++ "http://bugs.debian.org/542165 for details." ++ return 0 ++ fi ++ + # Abstraction modules aren't auto-loaded. + abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`" + for module in ${abstraction} ; do diff --git a/master/debian/mkconfig_skip_readme.patch b/master/debian/mkconfig_skip_readme.patch new file mode 100644 index 0000000..e354c2c --- /dev/null +++ b/master/debian/mkconfig_skip_readme.patch @@ -0,0 +1,20 @@ +Description: Skip */README* as well as README* +Author: Colin Watson <cjwatson@ubuntu.com> +Bug-Ubuntu: https://bugs.launchpad.net/bugs/537123 +Forwarded: yes +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3422 +Last-Update: 2011-09-05 + +Index: b/util/grub-mkconfig_lib.in +=================================================================== +--- a/util/grub-mkconfig_lib.in ++++ b/util/grub-mkconfig_lib.in +@@ -171,7 +171,7 @@ + if test -f "$1" ; then + case "$1" in + *.dpkg-*) return 1 ;; # debian dpkg +- README*) return 1 ;; # documentation ++ README*|*/README*) return 1 ;; # documentation + esac + else + return 1 diff --git a/master/debian/mkrescue_diet.patch b/master/debian/mkrescue_diet.patch new file mode 100644 index 0000000..57246b2 --- /dev/null +++ b/master/debian/mkrescue_diet.patch @@ -0,0 +1,54 @@ +Description: Allow reducing size of xorriso-created rescue images + This lets us create smaller images that will fit on floppy disks. It has + been approved by the upstream maintainer but has not yet been applied. +Author: Thomas Schmitt <scdbackup@gmx.net> +Origin: other, http://lists.gnu.org/archive/html/grub-devel/2010-05/msg00100.html +Forwarded: yes +Last-Update: 2010-06-02 + +Index: b/util/grub-mkrescue.in +=================================================================== +--- a/util/grub-mkrescue.in ++++ b/util/grub-mkrescue.in +@@ -44,6 +44,7 @@ + grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}` + + xorriso=xorriso ++diet=no + + # Usage: usage + # Print the usage. +@@ -59,6 +60,7 @@ + --rom-directory=DIR save rom images in DIR [optional] + --xorriso=FILE use FILE as xorriso [optional] + --grub-mkimage=FILE use FILE as grub-mkimage ++ --diet apply size reducing measures [optional] + + $self generates a bootable rescue image with specified source files, source + directories, or mkisofs options listed by: xorriso -as mkisofs -help +@@ -133,6 +135,9 @@ + --xorriso=*) + xorriso=`echo "${option}/" | sed 's/--xorriso=//'` ;; + ++ --diet) ++ diet=yes ;; ++ + *) + source="${source} ${option} $@"; break ;; + esac +@@ -307,7 +312,14 @@ + fi + + # build iso image +-"${xorriso}" -as mkisofs -graft-points ${grub_mkisofs_arguments} --protective-msdos-label -o ${output_image} -r ${iso9660_dir} --sort-weight 0 / --sort-weight 1 /boot ${source} ++if [ "${diet}" = yes ]; then ++ if [ -e "${output_image}" ]; then ++ rm "${output_image}" || exit 1 ++ fi ++ "${xorriso}" -report_about HINT -as mkisofs -graft-points -no-pad ${grub_mkisofs_arguments} --protective-msdos-label -r ${iso9660_dir} --sort-weight 0 / --sort-weight 1 /boot ${source} | cat >"${output_image}" ++else ++ "${xorriso}" -report_about HINT -as mkisofs -graft-points ${grub_mkisofs_arguments} --protective-msdos-label -o ${output_image} -r ${iso9660_dir} --sort-weight 0 / --sort-weight 1 /boot ${source} ++fi + rm -rf ${iso9660_dir} + + rm -f ${embed_img} diff --git a/master/debian/mkrescue_efi_modules.patch b/master/debian/mkrescue_efi_modules.patch new file mode 100644 index 0000000..47029f4 --- /dev/null +++ b/master/debian/mkrescue_efi_modules.patch @@ -0,0 +1,22 @@ +Description: Build part_msdos and vfat into EFI boot images +Author: Mario Limonciello <Mario_Limonciello@dell.com> +Bug-Ubuntu: https://bugs.launchpad.net/bugs/677758 +Forwarded: http://lists.gnu.org/archive/html/grub-devel/2011-01/msg00028.html +Last-Update: 2011-04-11 + +Index: b/util/grub-mkrescue.in +=================================================================== +--- a/util/grub-mkrescue.in ++++ b/util/grub-mkrescue.in +@@ -288,9 +288,9 @@ + mkdir -p "${efi_dir}/efi/boot" + + # build bootx64.efi +- make_image "${efi64_dir}" x86_64-efi "${efi_dir}"/efi/boot/bootx64.efi "" ++ make_image "${efi64_dir}" x86_64-efi "${efi_dir}"/efi/boot/bootx64.efi "part_msdos fat" + # build bootia32.efi +- make_image "${efi32_dir}" i386-efi "${efi_dir}"/efi/boot/bootia32.efi "" ++ make_image "${efi32_dir}" i386-efi "${efi_dir}"/efi/boot/bootia32.efi "part_msdos fat" + if [ -e "${efi_dir}"/efi/boot/bootia32.efi ]; then + # For old macs. Suggested by Peter Jones. + cp "${efi_dir}"/efi/boot/bootia32.efi "${efi_dir}"/efi/boot/boot.efi diff --git a/master/debian/no_libzfs.patch b/master/debian/no_libzfs.patch new file mode 100644 index 0000000..5b9b7eb --- /dev/null +++ b/master/debian/no_libzfs.patch @@ -0,0 +1,227 @@ +--- a/grub-core/kern/emu/getroot.c ++++ b/grub-core/kern/emu/getroot.c +@@ -32,6 +32,9 @@ + #include <stdio.h> + #include <stdlib.h> + #include <stdint.h> ++#ifdef HAVE_LIMITS_H ++#include <limits.h> ++#endif + #include <grub/util/misc.h> + #include <grub/util/lvm.h> + +@@ -238,7 +241,67 @@ + + #endif /* __linux__ */ + +-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) ++static char * ++find_device_from_pool (const char *poolname) ++{ ++ char *device; ++ char *cmd; ++ FILE *fp; ++ int ret; ++ char *line; ++ size_t len; ++ int st; ++ ++ char name[PATH_MAX], state[256], readlen[256], writelen[256], cksum[256], notes[256]; ++ unsigned int dummy; ++ ++ cmd = xasprintf ("zpool status %s", poolname); ++ fp = popen (cmd, "r"); ++ free (cmd); ++ ++ st = 0; ++ while (st < 3) ++ { ++ line = NULL; ++ ret = getline (&line, &len, fp); ++ if (ret == -1) ++ { ++ pclose (fp); ++ return NULL; ++ } ++ ++ if (sscanf (line, " %s %s %s %s %s %s", name, state, readlen, writelen, cksum, notes) >= 5) ++ switch (st) ++ { ++ case 0: ++ if (!strcmp (name, "NAME") ++ && !strcmp (state, "STATE") ++ && !strcmp (readlen, "READ") ++ && !strcmp (writelen, "WRITE") ++ && !strcmp (cksum, "CKSUM")) ++ st++; ++ break; ++ case 1: ++ if (!strcmp (name, poolname)) ++ st++; ++ break; ++ case 2: ++ if (strcmp (name, "mirror") && !sscanf (name, "mirror-%u", &dummy) ++ && !sscanf (name, "raidz%u", &dummy) ++ && !strcmp (state, "ONLINE")) ++ st++; ++ break; ++ } ++ ++ free (line); ++ } ++ pclose (fp); ++ ++ device = xasprintf ("/dev/%s", name); ++ ++ return device; ++} ++ + static char * + find_root_device_from_libzfs (const char *dir) + { +@@ -250,49 +313,7 @@ + if (! poolname) + return NULL; + +- { +- zpool_handle_t *zpool; +- libzfs_handle_t *libzfs; +- nvlist_t *config, *vdev_tree; +- nvlist_t **children, **path; +- unsigned int nvlist_count; +- unsigned int i; +- +- libzfs = grub_get_libzfs_handle (); +- if (! libzfs) +- return NULL; +- +- zpool = zpool_open (libzfs, poolname); +- config = zpool_get_config (zpool, NULL); +- +- if (nvlist_lookup_nvlist (config, "vdev_tree", &vdev_tree) != 0) +- error (1, errno, "nvlist_lookup_nvlist (\"vdev_tree\")"); +- +- if (nvlist_lookup_nvlist_array (vdev_tree, "children", &children, &nvlist_count) != 0) +- error (1, errno, "nvlist_lookup_nvlist_array (\"children\")"); +- assert (nvlist_count > 0); +- +- while (nvlist_lookup_nvlist_array (children[0], "children", +- &children, &nvlist_count) == 0) +- assert (nvlist_count > 0); +- +- for (i = 0; i < nvlist_count; i++) +- { +- if (nvlist_lookup_string (children[i], "path", &device) != 0) +- error (1, errno, "nvlist_lookup_string (\"path\")"); +- +- struct stat st; +- if (stat (device, &st) == 0) +- { +- device = xstrdup (device); +- break; +- } +- +- device = NULL; +- } +- +- zpool_close (zpool); +- } ++ device = find_device_from_pool (poolname); + + free (poolname); + if (poolfs) +@@ -300,7 +321,6 @@ + + return device; + } +-#endif + + #ifdef __MINGW32__ + +@@ -603,10 +623,8 @@ + os_dev = grub_find_root_device_from_mountinfo (dir, NULL); + #endif /* __linux__ */ + +-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + if (!os_dev) + os_dev = find_root_device_from_libzfs (dir); +-#endif + + if (os_dev) + { +@@ -708,7 +726,7 @@ + } + + int +-grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused))) ++grub_util_get_dev_abstraction (const char *os_dev) + { + #if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + /* User explicitly claims that this drive is visible by BIOS. */ +--- a/grub-core/kern/emu/misc.c ++++ b/grub-core/kern/emu/misc.c +@@ -287,7 +287,6 @@ + } + #endif /* HAVE_LIBZFS */ + +-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + /* ZFS has similar problems to those of btrfs (see above). */ + void + grub_find_zpool_from_dir (const char *dir, char **poolname, char **poolfs) +@@ -348,7 +347,6 @@ + else + *poolfs = xstrdup (""); + } +-#endif + + /* This function never prints trailing slashes (so that its output + can be appended a slash unconditionally). */ +@@ -361,22 +359,18 @@ + dev_t num; + size_t len; + +-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + char *poolfs = NULL; +-#endif + + /* canonicalize. */ + p = canonicalize_file_name (path); + if (p == NULL) + grub_util_error ("failed to get canonical path of %s", path); + +-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + /* For ZFS sub-pool filesystems, could be extended to others (btrfs?). */ + { + char *dummy; + grub_find_zpool_from_dir (p, &dummy, &poolfs); + } +-#endif + + len = strlen (p) + 1; + buf = xstrdup (p); +@@ -428,10 +422,8 @@ + } + #endif + free (buf2); +-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + if (poolfs) + return xasprintf ("/%s/@", poolfs); +-#endif + return xstrdup (""); + } + else +@@ -488,14 +480,12 @@ + len--; + } + +-#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR) + if (poolfs) + { + ret = xasprintf ("/%s/@%s", poolfs, buf3); + free (buf3); + } + else +-#endif + ret = buf3; + + return ret; diff --git a/master/debian/olpc_prefix_hack.patch b/master/debian/olpc_prefix_hack.patch new file mode 100644 index 0000000..79c2a5b --- /dev/null +++ b/master/debian/olpc_prefix_hack.patch @@ -0,0 +1,50 @@ + +This sucks, but it's better than what OFW was giving us. + +Index: b/grub-core/kern/ieee1275/init.c +=================================================================== +--- a/grub-core/kern/ieee1275/init.c ++++ b/grub-core/kern/ieee1275/init.c +@@ -53,6 +53,7 @@ + grub_ieee1275_exit (); + } + ++#ifndef __i386__ + /* Translate an OF filesystem path (separated by backslashes), into a GRUB + path (separated by forward slashes). */ + static void +@@ -67,13 +68,16 @@ + backslash = grub_strchr (filepath, '\\'); + } + } ++#endif + + void + grub_machine_set_prefix (void) + { ++#ifndef __i386__ + char bootpath[64]; /* XXX check length */ + char *filename; + char *prefix; ++#endif + + if (grub_prefix[0]) + { +@@ -82,6 +86,9 @@ + return; + } + ++#ifdef __i386__ ++ grub_env_set ("prefix", "(sd,1)/"); ++#else + if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", &bootpath, + sizeof (bootpath), 0)) + { +@@ -120,6 +127,7 @@ + + grub_free (filename); + grub_free (prefix); ++#endif + } + + /* Claim some available memory in the first /memory node. */ diff --git a/master/debian/partition_performance.patch b/master/debian/partition_performance.patch new file mode 100644 index 0000000..79fb453 --- /dev/null +++ b/master/debian/partition_performance.patch @@ -0,0 +1,36 @@ +Description: Give up scanning partitions after ten consecutive open failures + Scanning all the way up to 10000 is excessive and can cause serious + performance problems in some configurations. +Author: Colin Watson <cjwatson@ubuntu.com> +Bug-Ubuntu: https://bugs.launchpad.net/bugs/787461 +Forwarded: yes +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3320 +Last-Update: 2011-05-27 + +Index: b/grub-core/kern/emu/hostdisk.c +=================================================================== +--- a/grub-core/kern/emu/hostdisk.c ++++ b/grub-core/kern/emu/hostdisk.c +@@ -564,6 +564,7 @@ + int i; + char real_dev[PATH_MAX]; + struct linux_partition_cache *cache; ++ int missing = 0; + + strcpy(real_dev, dev); + +@@ -602,7 +603,13 @@ + + fd = open (real_dev, O_RDONLY); + if (fd == -1) +- continue; ++ { ++ if (missing++ < 10) ++ continue; ++ else ++ return 0; ++ } ++ missing = 0; + close (fd); + + start = find_partition_start (real_dev); diff --git a/master/debian/probe_canonicalise.patch b/master/debian/probe_canonicalise.patch new file mode 100644 index 0000000..ba40995 --- /dev/null +++ b/master/debian/probe_canonicalise.patch @@ -0,0 +1,26 @@ +Description: Canonicalise path argument to grub-probe + This fixes use of "/path/.." as in grub-install for EFI, as well as + handling symlinks correctly. +Author: Mario Limonciello <mario_limonciello@dell.com> +Author: Colin Watson <cjwatson@ubuntu.com> +Bug-Debian: http://bugs.debian.org/637768 +Forwarded: yes +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3401 +Last-Update: 2011-08-15 + +Index: b/util/grub-probe.c +=================================================================== +--- a/util/grub-probe.c ++++ b/util/grub-probe.c +@@ -108,7 +108,10 @@ + #endif + } + else +- device_name = grub_guess_root_device (path); ++ { ++ grub_path = canonicalize_file_name (path); ++ device_name = grub_guess_root_device (grub_path); ++ } + + if (! device_name) + grub_util_error ("cannot find a device for %s (is /dev mounted?)", path); diff --git a/master/debian/qemu_img_exists.patch b/master/debian/qemu_img_exists.patch new file mode 100644 index 0000000..b560067 --- /dev/null +++ b/master/debian/qemu_img_exists.patch @@ -0,0 +1,18 @@ +Description: Skip partmap test if qemu-img doesn't exist (e.g. on the Hurd) +Author: Colin Watson <cjwatson@debian.org> +Forwarded: no +Last-Update: 2010-11-22 + +Index: b/tests/partmap_test.in +=================================================================== +--- a/tests/partmap_test.in ++++ b/tests/partmap_test.in +@@ -51,6 +51,8 @@ + echo + } + ++which qemu-img >/dev/null 2>&1 || exit 77 ++ + imgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 + outfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1 + diff --git a/master/debian/series b/master/debian/series new file mode 100644 index 0000000..95505f9 --- /dev/null +++ b/master/debian/series @@ -0,0 +1,45 @@ +olpc_prefix_hack.patch +core_in_fs.patch +dpkg_version_comparison.patch +grub_legacy_0_based_partitions.patch +disable_floppies.patch +grub.cfg_400.patch +gfxpayload_keep_default.patch +mkrescue_diet.patch +mkconfig_skip_dmcrypt.patch +install_stage2_confusion.patch +qemu_img_exists.patch +branch_devmapper.patch +branch_squash.patch +branch_longlinuxcmd.patch +branch_parse-color.patch +branch_embed-sectors.patch +branch_fuse.patch +mkrescue_efi_modules.patch +mkconfig_loopback.patch +lazy_stat.patch +btrfs_stat.patch +partition_performance.patch +kfreebsd-9_ada_devices.patch +gfxterm_background.patch +zfs_packed_la_array.patch +xen_replace.patch +kfreebsd_mfi_devices.patch +probe_canonicalise.patch +mkconfig_skip_readme.patch +kfreebsd_lvm.patch +zfs_update.patch +no_libzfs.patch +xfs_invalid_bmap.patch +handle_new_autotools.patch +bash-completion_identifiers.patch +mkconfig_gnumach.patch +gcc_4_6_space.patch +lzo.patch +fat_uuid.patch +efiemu_fix.patch +4k_sectors.patch +efi_disk_cache.patch +dirlen.patch +hurd.patch +userland-part.patch diff --git a/master/debian/userland-part.patch b/master/debian/userland-part.patch new file mode 100644 index 0000000..16d2156 --- /dev/null +++ b/master/debian/userland-part.patch @@ -0,0 +1,149 @@ +Description: Handle hurd userspace partitions. +Author: Samuel Thibault <samuel.thibault@ens-lyon.org> +Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/4290 +Forwarded: not-needed +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/4290 +Last-Update: 2012-06-08 + +--- a/grub-core/kern/emu/getroot.c 2012-05-03 20:59:16 +0000 ++++ b/grub-core/kern/emu/getroot.c 2012-05-03 21:41:46 +0000 +@@ -337,6 +337,75 @@ + + #elif defined (__GNU__) + ++static char * ++find_hurd_root_device (const char *path) ++{ ++ file_t file; ++ error_t err; ++ char *argz = NULL, *name = NULL, *ret; ++ size_t argz_len = 0; ++ int i; ++ ++ file = file_name_lookup (path, 0, 0); ++ if (file == MACH_PORT_NULL) ++ grub_util_error ("cannot open `%s': %s", path, strerror (errno)); ++ ++ /* This returns catenated 0-terminated strings. */ ++ err = file_get_fs_options (file, &argz, &argz_len); ++ if (err) ++ grub_util_error ("cannot get filesystem options " ++ "for path `%s': %s", path, strerror(err)); ++ if (argz_len == 0) ++ /* TRANSLATORS: a "translator" is similar to a filesystem, but handled by a ++ * userland daemon. */ ++ grub_util_error ("translator is empty for path `%s'", path); ++ ++ /* Make sure the string is terminated. */ ++ argz[argz_len-1] = 0; ++ ++ /* Skip first word (translator path) and options. */ ++ for (i = strlen (argz) + 1; i < argz_len; i += strlen (argz + i) + 1) ++ { ++ if (argz[i] != '-') ++ { ++ /* Non-option. Only accept one, assumed to be the FS path. */ ++ /* XXX: this should be replaced by an RPC to the translator. */ ++ if (name) ++ /* TRANSLATORS: we expect to get something like ++ /hurd/foobar --option1 --option2=baz /dev/something ++ */ ++ grub_util_error ("translator `%s' for path `%s' has several " ++ "non-option words, at least `%s' and `%s'", ++ argz, path, name, argz + i); ++ name = argz + i; ++ } ++ } ++ ++ if (!name) ++ /* TRANSLATORS: we expect to get something like ++ /hurd/foobar --option1 --option2=baz /dev/something ++ */ ++ grub_util_error ("translator `%s' for path `%s' is given only options, " ++ "cannot find device part", argz, path); ++ ++ if (strncmp (name, "device:", sizeof ("device:") - 1) == 0) ++ { ++ char *dev_name = name + sizeof ("device:") - 1; ++ size_t size = sizeof ("/dev/") - 1 + strlen (dev_name) + 1; ++ char *next; ++ ret = malloc (size); ++ next = stpncpy (ret, "/dev/", size); ++ stpncpy (next, dev_name, size - (next - ret)); ++ } ++ else if (!strncmp (name, "file:", sizeof ("file:") - 1)) ++ ret = strdup (name + sizeof ("file:") - 1); ++ else ++ ret = strdup (name); ++ ++ munmap (argz, argz_len); ++ return ret; ++} ++ + #elif ! defined(__CYGWIN__) + + char * +@@ -565,61 +634,8 @@ + { + char *os_dev = NULL; + #ifdef __GNU__ +- file_t file; +- mach_port_t *ports; +- int *ints; +- loff_t *offsets; +- char *data; +- error_t err; +- mach_msg_type_number_t num_ports = 0, num_ints = 0, num_offsets = 0, data_len = 0; +- size_t name_len; +- +- file = file_name_lookup (dir, 0, 0); +- if (file == MACH_PORT_NULL) +- return 0; +- +- err = file_get_storage_info (file, +- &ports, &num_ports, +- &ints, &num_ints, +- &offsets, &num_offsets, +- &data, &data_len); +- +- if (num_ints < 1) +- grub_util_error ("Storage info for `%s' does not include type", dir); +- if (ints[0] != STORAGE_DEVICE) +- grub_util_error ("Filesystem of `%s' is not stored on local disk", dir); +- +- if (num_ints < 5) +- grub_util_error ("Storage info for `%s' does not include name", dir); +- name_len = ints[4]; +- if (name_len < data_len) +- grub_util_error ("Bogus name length for storage info for `%s'", dir); +- if (data[name_len - 1] != '\0') +- grub_util_error ("Storage name for `%s' not NUL-terminated", dir); +- +- os_dev = xmalloc (strlen ("/dev/") + data_len); +- memcpy (os_dev, "/dev/", strlen ("/dev/")); +- memcpy (os_dev + strlen ("/dev/"), data, data_len); +- +- if (ports && num_ports > 0) +- { +- mach_msg_type_number_t i; +- for (i = 0; i < num_ports; i++) +- { +- mach_port_t port = ports[i]; +- if (port != MACH_PORT_NULL) +- mach_port_deallocate (mach_task_self(), port); +- } +- munmap ((caddr_t) ports, num_ports * sizeof (*ports)); +- } +- +- if (ints && num_ints > 0) +- munmap ((caddr_t) ints, num_ints * sizeof (*ints)); +- if (offsets && num_offsets > 0) +- munmap ((caddr_t) offsets, num_offsets * sizeof (*offsets)); +- if (data && data_len > 0) +- munmap (data, data_len); +- mach_port_deallocate (mach_task_self (), file); ++ /* GNU/Hurd specific function. */ ++ os_dev = find_hurd_root_device (dir); + #else /* !__GNU__ */ + struct stat st; + dev_t dev; diff --git a/master/debian/xen_replace.patch b/master/debian/xen_replace.patch new file mode 100644 index 0000000..84df6b3 --- /dev/null +++ b/master/debian/xen_replace.patch @@ -0,0 +1,64 @@ +Description: New GRUB_CMDLINE_LINUX_XEN_REPLACE* options + Honour GRUB_CMDLINE_LINUX_XEN_REPLACE and + GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT, which replace GRUB_CMDLINE_LINUX + and GRUB_CMDLINE_LINUX_DEFAULT (complementing the existing options which + append). +Author: Colin Watson <cjwatson@ubuntu.com> +Bug-Debian: http://bugs.debian.org/617538 +Forwarded: yes +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3294 +Last-Update: 2011-08-08 + +Index: b/docs/grub.texi +=================================================================== +--- a/docs/grub.texi ++++ b/docs/grub.texi +@@ -1169,8 +1169,14 @@ + + @item GRUB_CMDLINE_XEN + @itemx GRUB_CMDLINE_XEN_DEFAULT +-As @samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT}, but for +-Linux and Xen. ++The values of these options are appended to the values of ++@samp{GRUB_CMDLINE_LINUX} and @samp{GRUB_CMDLINE_LINUX_DEFAULT} for Linux ++and Xen menu entries. ++ ++@item GRUB_CMDLINE_LINUX_XEN_REPLACE ++@item GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT ++The values of these options replace the values of @samp{GRUB_CMDLINE_LINUX} ++and @samp{GRUB_CMDLINE_LINUX_DEFAULT} for Linux and Xen menu entries. + + @item GRUB_DISABLE_LINUX_UUID + Normally, @command{grub-mkconfig} will generate menu entries that use +Index: b/util/grub.d/20_linux_xen.in +=================================================================== +--- a/util/grub.d/20_linux_xen.in ++++ b/util/grub.d/20_linux_xen.in +@@ -56,6 +56,14 @@ + LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} + fi + ++# Allow overriding GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT. ++if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE}" ]; then ++ GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX_XEN_REPLACE}" ++fi ++if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}" ]; then ++ GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}" ++fi ++ + if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ] \ + || [ "x`stat -f --printf=%T /`" = xbtrfs ]; then + rootsubvol="`make_system_path_relative_to_its_root /`" +Index: b/util/grub-mkconfig.in +=================================================================== +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -239,6 +239,8 @@ + GRUB_CMDLINE_LINUX_DEFAULT \ + GRUB_CMDLINE_XEN \ + GRUB_CMDLINE_XEN_DEFAULT \ ++ GRUB_CMDLINE_LINUX_XEN_REPLACE \ ++ GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT \ + GRUB_CMDLINE_NETBSD \ + GRUB_CMDLINE_NETBSD_DEFAULT \ + GRUB_TERMINAL_INPUT \ diff --git a/master/debian/xfs_invalid_bmap.patch b/master/debian/xfs_invalid_bmap.patch new file mode 100644 index 0000000..71d04de --- /dev/null +++ b/master/debian/xfs_invalid_bmap.patch @@ -0,0 +1,188 @@ +Description: Rewrite XFS btree parsing; fixes invalid BMAP +Author: Vladimir Serbinenko <phcoder@gmail.com> +Bug: http://savannah.gnu.org/bugs/?34213 +Bug-Debian: http://bugs.debian.org/657776 +Applied-Upstream: http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/3443 +Last-Update: 2012-01-29 + +Index: b/grub-core/fs/xfs.c +=================================================================== +--- a/grub-core/fs/xfs.c ++++ b/grub-core/fs/xfs.c +@@ -111,7 +111,9 @@ + grub_uint64_t nblocks; + grub_uint32_t extsize; + grub_uint32_t nextents; +- grub_uint8_t unused3[20]; ++ grub_uint16_t unused3; ++ grub_uint8_t fork_offset; ++ grub_uint8_t unused4[17]; + union + { + char raw[156]; +@@ -145,7 +147,7 @@ + grub_disk_t disk; + int pos; + int bsize; +- int agsize; ++ grub_uint32_t agsize; + struct grub_fshelp_node diropen; + }; + +@@ -159,33 +161,67 @@ + #define FILETYPE_INO_DIRECTORY 0040000 + #define FILETYPE_INO_SYMLINK 0120000 + +-#define GRUB_XFS_INO_AGBITS(data) \ +- ((data)->sblock.log2_agblk + (data)->sblock.log2_inop) +-#define GRUB_XFS_INO_INOINAG(data, ino) \ +- (grub_be_to_cpu64 (ino) & ((1LL << GRUB_XFS_INO_AGBITS (data)) - 1)) +-#define GRUB_XFS_INO_AG(data,ino) \ +- (grub_be_to_cpu64 (ino) >> GRUB_XFS_INO_AGBITS (data)) +- +-#define GRUB_XFS_FSB_TO_BLOCK(data, fsb) \ +- (((fsb) >> (data)->sblock.log2_agblk) * (data)->agsize \ +- + ((fsb) & ((1LL << (data)->sblock.log2_agblk) - 1))) +- +-#define GRUB_XFS_EXTENT_OFFSET(exts,ex) \ +- ((grub_be_to_cpu32 (exts[ex][0]) & ~(1 << 31)) << 23 \ +- | grub_be_to_cpu32 (exts[ex][1]) >> 9) +- +-#define GRUB_XFS_EXTENT_BLOCK(exts,ex) \ +- ((grub_uint64_t) (grub_be_to_cpu32 (exts[ex][1]) \ +- & (0x1ff)) << 43 \ +- | (grub_uint64_t) grub_be_to_cpu32 (exts[ex][2]) << 11 \ +- | grub_be_to_cpu32 (exts[ex][3]) >> 21) +- +-#define GRUB_XFS_EXTENT_SIZE(exts,ex) \ +- (grub_be_to_cpu32 (exts[ex][3]) & ((1 << 20) - 1)) +- +-#define GRUB_XFS_ROUND_TO_DIRENT(pos) ((((pos) + 8 - 1) / 8) * 8) +-#define GRUB_XFS_NEXT_DIRENT(pos,len) \ +- (pos) + GRUB_XFS_ROUND_TO_DIRENT (8 + 1 + len + 2) ++static inline int ++GRUB_XFS_INO_AGBITS(struct grub_xfs_data *data) ++{ ++ return ((data)->sblock.log2_agblk + (data)->sblock.log2_inop); ++} ++ ++static inline grub_uint64_t ++GRUB_XFS_INO_INOINAG (struct grub_xfs_data *data, ++ grub_uint64_t ino) ++{ ++ return (grub_be_to_cpu64 (ino) & ((1LL << GRUB_XFS_INO_AGBITS (data)) - 1)); ++} ++ ++static inline grub_uint64_t ++GRUB_XFS_INO_AG (struct grub_xfs_data *data, ++ grub_uint64_t ino) ++{ ++ return (grub_be_to_cpu64 (ino) >> GRUB_XFS_INO_AGBITS (data)); ++} ++ ++static inline grub_disk_addr_t ++GRUB_XFS_FSB_TO_BLOCK (struct grub_xfs_data *data, grub_disk_addr_t fsb) ++{ ++ return ((fsb >> data->sblock.log2_agblk) * data->agsize ++ + (fsb & ((1LL << data->sblock.log2_agblk) - 1))); ++} ++ ++static inline grub_uint64_t ++GRUB_XFS_EXTENT_OFFSET (grub_xfs_extent *exts, int ex) ++{ ++ return ((grub_be_to_cpu32 (exts[ex][0]) & ~(1 << 31)) << 23 ++ | grub_be_to_cpu32 (exts[ex][1]) >> 9); ++} ++ ++static inline grub_uint64_t ++GRUB_XFS_EXTENT_BLOCK (grub_xfs_extent *exts, int ex) ++{ ++ return ((grub_uint64_t) (grub_be_to_cpu32 (exts[ex][1]) ++ & (0x1ff)) << 43 ++ | (grub_uint64_t) grub_be_to_cpu32 (exts[ex][2]) << 11 ++ | grub_be_to_cpu32 (exts[ex][3]) >> 21); ++} ++ ++static inline grub_uint64_t ++GRUB_XFS_EXTENT_SIZE (grub_xfs_extent *exts, int ex) ++{ ++ return (grub_be_to_cpu32 (exts[ex][3]) & ((1 << 20) - 1)); ++} ++ ++static inline int ++GRUB_XFS_ROUND_TO_DIRENT (int pos) ++{ ++ return ((((pos) + 8 - 1) / 8) * 8); ++} ++ ++static inline int ++GRUB_XFS_NEXT_DIRENT (int pos, int len) ++{ ++ return (pos) + GRUB_XFS_ROUND_TO_DIRENT (8 + 1 + len + 2); ++} ++ + + static inline grub_uint64_t + grub_xfs_inode_block (struct grub_xfs_data *data, +@@ -241,13 +277,23 @@ + if (node->inode.format == XFS_INODE_FORMAT_BTREE) + { + grub_uint64_t *keys; ++ int recoffset; + +- leaf = grub_malloc (node->data->sblock.bsize); ++ leaf = grub_malloc (node->data->bsize); + if (leaf == 0) + return 0; + + nrec = grub_be_to_cpu16 (node->inode.data.btree.numrecs); + keys = &node->inode.data.btree.keys[0]; ++ if (node->inode.fork_offset) ++ recoffset = (node->inode.fork_offset ++ - ((char *) &node->inode.data.btree.keys - (char *) &node->inode)) ++ / (2 * sizeof (grub_uint64_t)); ++ else ++ recoffset = ((1 << node->data->sblock.log2_inode) ++ - ((char *) &node->inode.data.btree.keys ++ - (char *) &node->inode)) ++ / (2 * sizeof (grub_uint64_t)); + do + { + int i; +@@ -264,12 +310,9 @@ + grub_free (leaf); + return 0; + } +- + if (grub_disk_read (node->data->disk, +- grub_be_to_cpu64 (keys[i - 1 + nrec]) +- << (node->data->sblock.log2_bsize +- - GRUB_DISK_SECTOR_BITS), +- 0, node->data->sblock.bsize, leaf)) ++ GRUB_XFS_FSB_TO_BLOCK (node->data, grub_be_to_cpu64 (keys[i - 1 + recoffset])) << (node->data->sblock.log2_bsize - GRUB_DISK_SECTOR_BITS), ++ 0, node->data->bsize, leaf)) + return 0; + + if (grub_strncmp ((char *) leaf->magic, "BMAP", 4)) +@@ -281,7 +324,11 @@ + + nrec = grub_be_to_cpu16 (leaf->numrecs); + keys = &leaf->keys[0]; +- } while (leaf->level); ++ recoffset = ((node->data->bsize - ((char *) &leaf->keys ++ - (char *) leaf)) ++ / (2 * sizeof (grub_uint64_t))); ++ } ++ while (leaf->level); + exts = (grub_xfs_extent *) keys; + } + else if (node->inode.format == XFS_INODE_FORMAT_EXT) +@@ -328,7 +375,7 @@ + grub_xfs_read_file (grub_fshelp_node_t node, + void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, + unsigned offset, unsigned length), +- int pos, grub_size_t len, char *buf) ++ grub_off_t pos, grub_size_t len, char *buf) + { + return grub_fshelp_read_file (node->data->disk, node, read_hook, + pos, len, buf, grub_xfs_read_block, diff --git a/master/debian/zfs_packed_la_array.patch b/master/debian/zfs_packed_la_array.patch new file mode 100644 index 0000000..e31778b --- /dev/null +++ b/master/debian/zfs_packed_la_array.patch @@ -0,0 +1,17 @@ +2011-08-03 Robert Millan <rmh@gnu.org> + + * include/grub/zfs/zap_leaf.h (typedef union zap_leaf_chunk): Mark + la_array as packed. + Reported by: Zachary Bedell + +--- a/include/grub/zfs/zap_leaf.h ++++ b/include/grub/zfs/zap_leaf.h +@@ -90,7 +90,7 @@ + { + grub_uint8_t la_array[ZAP_LEAF_ARRAY_BYTES]; + grub_uint64_t la_array64; +- }; ++ } __attribute__ ((packed)); + grub_uint16_t la_next; /* next blk or CHAIN_END */ + } l_array; + struct zap_leaf_free { diff --git a/master/debian/zfs_update.patch b/master/debian/zfs_update.patch new file mode 100644 index 0000000..12e4599 --- /dev/null +++ b/master/debian/zfs_update.patch @@ -0,0 +1,2415 @@ + +Revisions: + +3340: ZFS zlib support +3474: Fix 2G limit on ZFS +3486: ZFS fixes +3488: ZFS multi-device and version 33 support +3494: Fix memory leak +3518: Rewrite RAIDZ part based on reverse engineering +3519: Fix RAIDZ(2) for >= 5 devices +3520: Add ability to sustain a single drive failure on both raidz and raidz2 +3521: Support raidz3 +3533: Support second redundancy strip on raidz(2,3) +3534: Support case-insensitive ZFS subvolumes +3535: Support third redundancy strip on raidz3 + +--- a/grub-core/fs/zfs/zfs.c ++++ b/grub-core/fs/zfs/zfs.c +@@ -51,6 +51,7 @@ + #include <grub/zfs/sa_impl.h> + #include <grub/zfs/dsl_dir.h> + #include <grub/zfs/dsl_dataset.h> ++#include <grub/deflate.h> + + GRUB_MOD_LICENSE ("GPLv3+"); + +@@ -139,6 +140,27 @@ + grub_zfs_endian_t endian; + } dnode_end_t; + ++struct grub_zfs_device_desc ++{ ++ enum { DEVICE_LEAF, DEVICE_MIRROR, DEVICE_RAIDZ } type; ++ grub_uint64_t id; ++ grub_uint64_t guid; ++ ++ /* Valid only for non-leafs. */ ++ unsigned n_children; ++ struct grub_zfs_device_desc *children; ++ ++ /* Valid only for RAIDZ. */ ++ unsigned nparity; ++ unsigned ashift; ++ ++ /* Valid only for leaf devices. */ ++ grub_device_t dev; ++ grub_disk_addr_t vdev_phys_sector; ++ uberblock_t current_uberblock; ++ int original; ++}; ++ + struct grub_zfs_data + { + /* cache for a file block of the currently zfs_open()-ed file */ +@@ -153,23 +175,45 @@ + grub_uint64_t dnode_end; + grub_zfs_endian_t dnode_endian; + +- uberblock_t current_uberblock; +- grub_disk_t disk; +- + dnode_end_t mos; + dnode_end_t mdn; + dnode_end_t dnode; + +- grub_disk_addr_t vdev_phys_sector; ++ struct grub_zfs_device_desc *devices_attached; ++ unsigned n_devices_attached; ++ unsigned n_devices_allocated; ++ struct grub_zfs_device_desc *device_original; ++ ++ uberblock_t current_uberblock; ++ ++ int mounted; ++ grub_uint64_t guid; + }; + ++static grub_err_t ++zlib_decompress (void *s, void *d, ++ grub_size_t slen, grub_size_t dlen) ++{ ++ if (grub_zlib_decompress (s, slen, 0, d, dlen) < 0) ++ return grub_errno; ++ return GRUB_ERR_NONE; ++} ++ + static decomp_entry_t decomp_table[ZIO_COMPRESS_FUNCTIONS] = { + {"inherit", NULL}, /* ZIO_COMPRESS_INHERIT */ + {"on", lzjb_decompress}, /* ZIO_COMPRESS_ON */ + {"off", NULL}, /* ZIO_COMPRESS_OFF */ + {"lzjb", lzjb_decompress}, /* ZIO_COMPRESS_LZJB */ + {"empty", NULL}, /* ZIO_COMPRESS_EMPTY */ +- {"gzip", NULL}, /* ZIO_COMPRESS_GZIP */ ++ {"gzip-1", zlib_decompress}, /* ZIO_COMPRESS_GZIP1 */ ++ {"gzip-2", zlib_decompress}, /* ZIO_COMPRESS_GZIP2 */ ++ {"gzip-3", zlib_decompress}, /* ZIO_COMPRESS_GZIP3 */ ++ {"gzip-4", zlib_decompress}, /* ZIO_COMPRESS_GZIP4 */ ++ {"gzip-5", zlib_decompress}, /* ZIO_COMPRESS_GZIP5 */ ++ {"gzip-6", zlib_decompress}, /* ZIO_COMPRESS_GZIP6 */ ++ {"gzip-7", zlib_decompress}, /* ZIO_COMPRESS_GZIP7 */ ++ {"gzip-8", zlib_decompress}, /* ZIO_COMPRESS_GZIP8 */ ++ {"gzip-9", zlib_decompress}, /* ZIO_COMPRESS_GZIP9 */ + }; + + static grub_err_t zio_read_data (blkptr_t * bp, grub_zfs_endian_t endian, +@@ -224,7 +268,7 @@ + */ + static grub_err_t + zio_checksum_verify (zio_cksum_t zc, grub_uint32_t checksum, +- grub_zfs_endian_t endian, char *buf, int size) ++ grub_zfs_endian_t endian, char *buf, grub_size_t size) + { + zio_eck_t *zec = (zio_eck_t *) (buf + size) - 1; + zio_checksum_info_t *ci = &zio_checksum_table[checksum]; +@@ -253,13 +297,13 @@ + || (actual_cksum.zc_word[2] != zc.zc_word[2]) + || (actual_cksum.zc_word[3] != zc.zc_word[3])) + { +- grub_dprintf ("zfs", "checksum %d verification failed\n", checksum); +- grub_dprintf ("zfs", "actual checksum %16llx %16llx %16llx %16llx\n", ++ grub_dprintf ("zfs", "checksum %s verification failed\n", ci->ci_name); ++ grub_dprintf ("zfs", "actual checksum %016llx %016llx %016llx %016llx\n", + (unsigned long long) actual_cksum.zc_word[0], + (unsigned long long) actual_cksum.zc_word[1], + (unsigned long long) actual_cksum.zc_word[2], + (unsigned long long) actual_cksum.zc_word[3]); +- grub_dprintf ("zfs", "expected checksum %16llx %16llx %16llx %16llx\n", ++ grub_dprintf ("zfs", "expected checksum %016llx %016llx %016llx %016llx\n", + (unsigned long long) zc.zc_word[0], + (unsigned long long) zc.zc_word[1], + (unsigned long long) zc.zc_word[2], +@@ -319,7 +363,7 @@ + * + */ + static grub_err_t +-uberblock_verify (uberblock_phys_t * ub, int offset) ++uberblock_verify (uberblock_phys_t * ub, grub_uint64_t offset) + { + uberblock_t *uber = &ub->ubp_uberblock; + grub_err_t err; +@@ -392,7 +436,7 @@ + } + + static grub_uint64_t +-dva_get_offset (dva_t * dva, grub_zfs_endian_t endian) ++dva_get_offset (const dva_t *dva, grub_zfs_endian_t endian) + { + grub_dprintf ("zfs", "dva=%llx, %llx\n", + (unsigned long long) dva->dva_word[0], +@@ -401,6 +445,842 @@ + endian) << SPA_MINBLOCKSHIFT; + } + ++static grub_err_t ++zfs_fetch_nvlist (struct grub_zfs_device_desc *diskdesc, char **nvlist) ++{ ++ grub_err_t err; ++ ++ *nvlist = grub_malloc (VDEV_PHYS_SIZE); ++ if (!diskdesc->dev) ++ return grub_error (GRUB_ERR_BAD_FS, "member drive unknown"); ++ ++ /* Read in the vdev name-value pair list (112K). */ ++ err = grub_disk_read (diskdesc->dev->disk, diskdesc->vdev_phys_sector, 0, ++ VDEV_PHYS_SIZE, *nvlist); ++ if (err) ++ { ++ grub_free (*nvlist); ++ *nvlist = 0; ++ return err; ++ } ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++fill_vdev_info_real (struct grub_zfs_data *data, ++ const char *nvlist, ++ struct grub_zfs_device_desc *fill, ++ struct grub_zfs_device_desc *insert) ++{ ++ char *type; ++ ++ type = grub_zfs_nvlist_lookup_string (nvlist, ZPOOL_CONFIG_TYPE); ++ ++ if (!type) ++ return grub_errno; ++ ++ if (!grub_zfs_nvlist_lookup_uint64 (nvlist, "id", &(fill->id))) ++ return grub_error (GRUB_ERR_BAD_FS, "couldn't find vdev id"); ++ ++ if (!grub_zfs_nvlist_lookup_uint64 (nvlist, "guid", &(fill->guid))) ++ return grub_error (GRUB_ERR_BAD_FS, "couldn't find vdev id"); ++ ++ if (grub_strcmp (type, VDEV_TYPE_DISK) == 0 ++ || grub_strcmp (type, VDEV_TYPE_FILE) == 0) ++ { ++ fill->type = DEVICE_LEAF; ++ ++ if (!fill->dev && fill->guid == insert->guid) ++ { ++ fill->dev = insert->dev; ++ fill->vdev_phys_sector = insert->vdev_phys_sector; ++ fill->current_uberblock = insert->current_uberblock; ++ fill->original = insert->original; ++ if (!data->device_original) ++ data->device_original = fill; ++ } ++ ++ return GRUB_ERR_NONE; ++ } ++ ++ if (grub_strcmp (type, VDEV_TYPE_MIRROR) == 0 ++ || grub_strcmp (type, VDEV_TYPE_RAIDZ) == 0) ++ { ++ int nelm, i; ++ ++ if (grub_strcmp (type, VDEV_TYPE_MIRROR) == 0) ++ fill->type = DEVICE_MIRROR; ++ else ++ { ++ grub_uint64_t par; ++ fill->type = DEVICE_RAIDZ; ++ if (!grub_zfs_nvlist_lookup_uint64 (nvlist, "nparity", &par)) ++ return grub_error (GRUB_ERR_BAD_FS, "couldn't find raidz parity"); ++ fill->nparity = par; ++ if (!grub_zfs_nvlist_lookup_uint64 (nvlist, "ashift", &par)) ++ return grub_error (GRUB_ERR_BAD_FS, "couldn't find raidz ashift"); ++ fill->ashift = par; ++ } ++ ++ nelm = grub_zfs_nvlist_lookup_nvlist_array_get_nelm (nvlist, ZPOOL_CONFIG_CHILDREN); ++ ++ if (nelm <= 0) ++ return grub_error (GRUB_ERR_BAD_FS, "incorrect mirror VDEV"); ++ ++ if (!fill->children) ++ { ++ fill->n_children = nelm; ++ ++ fill->children = grub_zalloc (fill->n_children ++ * sizeof (fill->children[0])); ++ } ++ ++ for (i = 0; i < nelm; i++) ++ { ++ char *child; ++ grub_err_t err; ++ ++ child = grub_zfs_nvlist_lookup_nvlist_array ++ (nvlist, ZPOOL_CONFIG_CHILDREN, i); ++ ++ err = fill_vdev_info_real (data, child, &fill->children[i], insert); ++ ++ grub_free (child); ++ ++ if (err) ++ return err; ++ } ++ return GRUB_ERR_NONE; ++ } ++ ++ return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "vdev %s isn't supported", ++ type); ++} ++ ++static grub_err_t ++fill_vdev_info (struct grub_zfs_data *data, ++ char *nvlist, struct grub_zfs_device_desc *diskdesc) ++{ ++ grub_uint64_t id; ++ unsigned i; ++ ++ if (!grub_zfs_nvlist_lookup_uint64 (nvlist, "id", &id)) ++ return grub_error (GRUB_ERR_BAD_FS, "couldn't find vdev id"); ++ ++ for (i = 0; i < data->n_devices_attached; i++) ++ if (data->devices_attached[i].id == id) ++ return fill_vdev_info_real (data, nvlist, &data->devices_attached[i], ++ diskdesc); ++ ++ data->n_devices_attached++; ++ if (data->n_devices_attached > data->n_devices_allocated) ++ { ++ void *tmp; ++ data->n_devices_allocated = 2 * data->n_devices_attached + 1; ++ data->devices_attached ++ = grub_realloc (tmp = data->devices_attached, ++ data->n_devices_allocated ++ * sizeof (data->devices_attached[0])); ++ if (!data->devices_attached) ++ { ++ data->devices_attached = tmp; ++ return grub_errno; ++ } ++ } ++ ++ grub_memset (&data->devices_attached[data->n_devices_attached - 1], ++ 0, sizeof (data->devices_attached[data->n_devices_attached - 1])); ++ ++ return fill_vdev_info_real (data, nvlist, ++ &data->devices_attached[data->n_devices_attached - 1], ++ diskdesc); ++} ++ ++/* ++ * Check the disk label information and retrieve needed vdev name-value pairs. ++ * ++ */ ++static grub_err_t ++check_pool_label (struct grub_zfs_data *data, ++ struct grub_zfs_device_desc *diskdesc) ++{ ++ grub_uint64_t pool_state, txg = 0; ++ char *nvlist; ++#if 0 ++ char *nv; ++#endif ++ grub_uint64_t poolguid; ++ grub_uint64_t version; ++ int found; ++ grub_err_t err; ++ ++ err = zfs_fetch_nvlist (diskdesc, &nvlist); ++ if (err) ++ return err; ++ ++ grub_dprintf ("zfs", "check 2 passed\n"); ++ ++ found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_STATE, ++ &pool_state); ++ if (! found) ++ { ++ grub_free (nvlist); ++ if (! grub_errno) ++ grub_error (GRUB_ERR_BAD_FS, ZPOOL_CONFIG_POOL_STATE " not found"); ++ return grub_errno; ++ } ++ grub_dprintf ("zfs", "check 3 passed\n"); ++ ++ if (pool_state == POOL_STATE_DESTROYED) ++ { ++ grub_free (nvlist); ++ return grub_error (GRUB_ERR_BAD_FS, "zpool is marked as destroyed"); ++ } ++ grub_dprintf ("zfs", "check 4 passed\n"); ++ ++ found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_TXG, &txg); ++ if (!found) ++ { ++ grub_free (nvlist); ++ if (! grub_errno) ++ grub_error (GRUB_ERR_BAD_FS, ZPOOL_CONFIG_POOL_TXG " not found"); ++ return grub_errno; ++ } ++ grub_dprintf ("zfs", "check 6 passed\n"); ++ ++ /* not an active device */ ++ if (txg == 0) ++ { ++ grub_free (nvlist); ++ return grub_error (GRUB_ERR_BAD_FS, "zpool isn't active"); ++ } ++ grub_dprintf ("zfs", "check 7 passed\n"); ++ ++ found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_VERSION, ++ &version); ++ if (! found) ++ { ++ grub_free (nvlist); ++ if (! grub_errno) ++ grub_error (GRUB_ERR_BAD_FS, ZPOOL_CONFIG_VERSION " not found"); ++ return grub_errno; ++ } ++ grub_dprintf ("zfs", "check 8 passed\n"); ++ ++ if (version > SPA_VERSION) ++ { ++ grub_free (nvlist); ++ return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, ++ "too new version %llu > %llu", ++ (unsigned long long) version, ++ (unsigned long long) SPA_VERSION); ++ } ++ grub_dprintf ("zfs", "check 9 passed\n"); ++ ++ found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_GUID, ++ &(diskdesc->guid)); ++ if (! found) ++ { ++ grub_free (nvlist); ++ if (! grub_errno) ++ grub_error (GRUB_ERR_BAD_FS, ZPOOL_CONFIG_GUID " not found"); ++ return grub_errno; ++ } ++ ++ found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_GUID, ++ &poolguid); ++ if (! found) ++ { ++ grub_free (nvlist); ++ if (! grub_errno) ++ grub_error (GRUB_ERR_BAD_FS, ZPOOL_CONFIG_POOL_GUID " not found"); ++ return grub_errno; ++ } ++ ++ grub_dprintf ("zfs", "check 11 passed\n"); ++ ++ if (data->mounted && data->guid != poolguid) ++ return grub_error (GRUB_ERR_BAD_FS, "another zpool"); ++ else ++ data->guid = poolguid; ++ ++ { ++ char *nv; ++ nv = grub_zfs_nvlist_lookup_nvlist (nvlist, ZPOOL_CONFIG_VDEV_TREE); ++ ++ if (!nv) ++ { ++ grub_free (nvlist); ++ return grub_error (GRUB_ERR_BAD_FS, "couldn't find vdev tree"); ++ } ++ err = fill_vdev_info (data, nv, diskdesc); ++ if (err) ++ { ++ grub_free (nvlist); ++ return err; ++ } ++ } ++ grub_dprintf ("zfs", "check 10 passed\n"); ++ ++ grub_free (nvlist); ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_err_t ++scan_disk (grub_device_t dev, struct grub_zfs_data *data, ++ int original) ++{ ++ int label = 0; ++ uberblock_phys_t *ub_array, *ubbest = NULL; ++ vdev_boot_header_t *bh; ++ grub_err_t err; ++ int vdevnum; ++ struct grub_zfs_device_desc desc; ++ ++ ub_array = grub_malloc (VDEV_UBERBLOCK_RING); ++ if (!ub_array) ++ return grub_errno; ++ ++ bh = grub_malloc (VDEV_BOOT_HEADER_SIZE); ++ if (!bh) ++ { ++ grub_free (ub_array); ++ return grub_errno; ++ } ++ ++ vdevnum = VDEV_LABELS; ++ ++ desc.dev = dev; ++ desc.original = original; ++ ++ /* Don't check back labels on CDROM. */ ++ if (grub_disk_get_size (dev->disk) == GRUB_DISK_SIZE_UNKNOWN) ++ vdevnum = VDEV_LABELS / 2; ++ ++ for (label = 0; ubbest == NULL && label < vdevnum; label++) ++ { ++ desc.vdev_phys_sector ++ = label * (sizeof (vdev_label_t) >> SPA_MINBLOCKSHIFT) ++ + ((VDEV_SKIP_SIZE + VDEV_BOOT_HEADER_SIZE) >> SPA_MINBLOCKSHIFT) ++ + (label < VDEV_LABELS / 2 ? 0 : grub_disk_get_size (dev->disk) ++ - VDEV_LABELS * (sizeof (vdev_label_t) >> SPA_MINBLOCKSHIFT)); ++ ++ /* Read in the uberblock ring (128K). */ ++ err = grub_disk_read (dev->disk, desc.vdev_phys_sector ++ + (VDEV_PHYS_SIZE >> SPA_MINBLOCKSHIFT), ++ 0, VDEV_UBERBLOCK_RING, (char *) ub_array); ++ if (err) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ continue; ++ } ++ grub_dprintf ("zfs", "label ok %d\n", label); ++ ++ ubbest = find_bestub (ub_array, desc.vdev_phys_sector); ++ if (!ubbest) ++ { ++ grub_dprintf ("zfs", "No uberblock found\n"); ++ grub_errno = GRUB_ERR_NONE; ++ continue; ++ } ++ ++ grub_memmove (&(desc.current_uberblock), ++ &ubbest->ubp_uberblock, sizeof (uberblock_t)); ++ if (original) ++ grub_memmove (&(data->current_uberblock), ++ &ubbest->ubp_uberblock, sizeof (uberblock_t)); ++ ++ err = check_pool_label (data, &desc); ++ if (err) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ continue; ++ } ++#if 0 ++ if (find_best_root && ++ vdev_uberblock_compare (&ubbest->ubp_uberblock, ++ &(current_uberblock)) <= 0) ++ continue; ++#endif ++ grub_free (ub_array); ++ grub_free (bh); ++ return GRUB_ERR_NONE; ++ } ++ ++ grub_free (ub_array); ++ grub_free (bh); ++ ++ return grub_error (GRUB_ERR_BAD_FS, "couldn't find a valid label"); ++} ++ ++static grub_err_t ++scan_devices (struct grub_zfs_data *data) ++{ ++ auto int hook (const char *name); ++ int hook (const char *name) ++ { ++ grub_device_t dev; ++ grub_err_t err; ++ dev = grub_device_open (name); ++ if (!dev) ++ return 0; ++ if (!dev->disk) ++ { ++ grub_device_close (dev); ++ return 0; ++ } ++ err = scan_disk (dev, data, 0); ++ if (err == GRUB_ERR_BAD_FS) ++ { ++ grub_device_close (dev); ++ grub_errno = GRUB_ERR_NONE; ++ return 0; ++ } ++ if (err) ++ { ++ grub_device_close (dev); ++ grub_print_error (); ++ return 0; ++ } ++ ++ return 0; ++ } ++ grub_device_iterate (hook); ++ return GRUB_ERR_NONE; ++} ++ ++static inline void ++xor (grub_uint64_t *a, const grub_uint64_t *b, grub_size_t s) ++{ ++ s /= sizeof (grub_uint64_t); ++ while (s--) ++ *a++ ^= *b++; ++} ++ ++/* x**y. */ ++static grub_uint8_t powx[255 * 2]; ++/* Such an s that x**s = y */ ++static int powx_inv[256]; ++static const grub_uint8_t poly = 0x1d; ++ ++/* perform the operation a ^= b * (x ** (known_idx * recovery_pow) ) */ ++static inline void ++xor_out (void *a_in, const void *b_in, grub_size_t s, ++ int known_idx, int recovery_pow) ++{ ++ int add; ++ grub_uint8_t *a = a_in; ++ const grub_uint8_t *b = b_in; ++ ++ /* Simple xor. */ ++ if (known_idx == 0 || recovery_pow == 0) ++ { ++ xor (a_in, b_in, s); ++ return; ++ } ++ add = (known_idx * recovery_pow) % 255; ++ for (;s--; b++, a++) ++ if (*b) ++ *a ^= powx[powx_inv[*b] + add]; ++} ++ ++static inline grub_uint8_t ++gf_mul (grub_uint8_t a, grub_uint8_t b) ++{ ++ if (a == 0 || b == 0) ++ return 0; ++ return powx[powx_inv[a] + powx_inv[b]]; ++} ++ ++static inline grub_err_t ++recovery (grub_uint8_t *bufs[4], grub_size_t s, const int nbufs, ++ const unsigned *powers, ++ const int *idx) ++{ ++ grub_dprintf ("zfs", "recovering %u bufers\n", nbufs); ++ /* Now we have */ ++ /* b_i = sum (r_j* (x ** (powers[i] * idx[j])))*/ ++ /* Let's invert the matrix in question. */ ++ switch (nbufs) ++ { ++ /* Easy: r_0 = bufs[0] / (x << (powers[i] * idx[j])). */ ++ case 1: ++ { ++ int add; ++ grub_uint8_t *a; ++ if (powers[0] == 0 || idx[0] == 0) ++ return GRUB_ERR_NONE; ++ add = 255 - ((powers[0] * idx[0]) % 255); ++ for (a = bufs[0]; s--; a++) ++ if (*a) ++ *a = powx[powx_inv[*a] + add]; ++ return GRUB_ERR_NONE; ++ } ++ /* Case 2x2: Let's use the determinant formula. */ ++ case 2: ++ { ++ grub_uint8_t det, det_inv; ++ grub_uint8_t matrixinv[2][2]; ++ unsigned i; ++ /* The determinant is: */ ++ det = (powx[(powers[0] * idx[0] + powers[1] * idx[1]) % 255] ++ ^ powx[(powers[0] * idx[1] + powers[1] * idx[0]) % 255]); ++ if (det == 0) ++ return grub_error (GRUB_ERR_BAD_FS, "singular recovery matrix"); ++ det_inv = powx[255 - powx_inv[det]]; ++ matrixinv[0][0] = gf_mul (powx[(powers[1] * idx[1]) % 255], det_inv); ++ matrixinv[1][1] = gf_mul (powx[(powers[0] * idx[0]) % 255], det_inv); ++ matrixinv[0][1] = gf_mul (powx[(powers[0] * idx[1]) % 255], det_inv); ++ matrixinv[1][0] = gf_mul (powx[(powers[1] * idx[0]) % 255], det_inv); ++ for (i = 0; i < s; i++) ++ { ++ grub_uint8_t b0, b1; ++ b0 = bufs[0][i]; ++ b1 = bufs[1][i]; ++ ++ bufs[0][i] = (gf_mul (b0, matrixinv[0][0]) ++ ^ gf_mul (b1, matrixinv[0][1])); ++ bufs[1][i] = (gf_mul (b0, matrixinv[1][0]) ++ ^ gf_mul (b1, matrixinv[1][1])); ++ } ++ return GRUB_ERR_NONE; ++ } ++ /* Otherwise use Gauss. */ ++ default: ++ { ++ grub_uint8_t matrix1[nbufs][nbufs], matrix2[nbufs][nbufs]; ++ int i, j, k; ++ ++ for (i = 0; i < nbufs; i++) ++ for (j = 0; j < nbufs; j++) ++ matrix1[i][j] = powx[(powers[i] * idx[j]) % 255]; ++ for (i = 0; i < nbufs; i++) ++ for (j = 0; j < nbufs; j++) ++ matrix2[i][j] = 0; ++ for (i = 0; i < nbufs; i++) ++ matrix2[i][i] = 1; ++ ++ for (i = 0; i < nbufs; i++) ++ { ++ grub_uint8_t mul; ++ for (j = i; j < nbufs; j++) ++ if (matrix1[i][j]) ++ break; ++ if (j == nbufs) ++ return grub_error (GRUB_ERR_BAD_FS, "singular recovery matrix"); ++ if (j != i) ++ { ++ int xchng; ++ xchng = j; ++ for (j = 0; j < nbufs; j++) ++ { ++ grub_uint8_t t; ++ t = matrix1[xchng][j]; ++ matrix1[xchng][j] = matrix1[i][j]; ++ matrix1[i][j] = t; ++ } ++ for (j = 0; j < nbufs; j++) ++ { ++ grub_uint8_t t; ++ t = matrix2[xchng][j]; ++ matrix2[xchng][j] = matrix2[i][j]; ++ matrix2[i][j] = t; ++ } ++ } ++ mul = powx[255 - powx_inv[matrix1[i][i]]]; ++ for (j = 0; j < nbufs; j++) ++ matrix1[i][j] = gf_mul (matrix1[i][j], mul); ++ for (j = 0; j < nbufs; j++) ++ matrix2[i][j] = gf_mul (matrix2[i][j], mul); ++ for (j = i + 1; j < nbufs; j++) ++ { ++ mul = matrix1[j][i]; ++ for (k = 0; k < nbufs; k++) ++ matrix1[j][k] ^= gf_mul (matrix1[i][k], mul); ++ for (k = 0; k < nbufs; k++) ++ matrix2[j][k] ^= gf_mul (matrix2[i][k], mul); ++ } ++ } ++ for (i = nbufs - 1; i >= 0; i--) ++ { ++ for (j = 0; j < i; j++) ++ { ++ grub_uint8_t mul; ++ mul = matrix1[j][i]; ++ for (k = 0; k < nbufs; k++) ++ matrix1[j][k] ^= gf_mul (matrix1[i][k], mul); ++ for (k = 0; k < nbufs; k++) ++ matrix2[j][k] ^= gf_mul (matrix2[i][k], mul); ++ } ++ } ++ ++ for (i = 0; i < (int) s; i++) ++ { ++ grub_uint8_t b[nbufs]; ++ for (j = 0; j < nbufs; j++) ++ b[j] = bufs[j][i]; ++ for (j = 0; j < nbufs; j++) ++ { ++ bufs[j][i] = 0; ++ for (k = 0; k < nbufs; k++) ++ bufs[j][i] ^= gf_mul (matrix2[j][k], b[k]); ++ } ++ } ++ return GRUB_ERR_NONE; ++ } ++ } ++} ++ ++static grub_err_t ++read_device (grub_uint64_t offset, struct grub_zfs_device_desc *desc, ++ grub_size_t len, void *buf) ++{ ++ switch (desc->type) ++ { ++ case DEVICE_LEAF: ++ { ++ grub_uint64_t sector; ++ sector = DVA_OFFSET_TO_PHYS_SECTOR (offset); ++ if (!desc->dev) ++ { ++ return grub_error (GRUB_ERR_BAD_FS, "member drive unknown"); ++ } ++ /* read in a data block */ ++ return grub_disk_read (desc->dev->disk, sector, 0, len, buf); ++ } ++ case DEVICE_MIRROR: ++ { ++ grub_err_t err = GRUB_ERR_NONE; ++ unsigned i; ++ if (desc->n_children <= 0) ++ return grub_error (GRUB_ERR_BAD_FS, ++ "non-positive number of mirror children"); ++ for (i = 0; i < desc->n_children; i++) ++ { ++ err = read_device (offset, &desc->children[i], ++ len, buf); ++ if (!err) ++ break; ++ grub_errno = GRUB_ERR_NONE; ++ } ++ return (grub_errno = err); ++ } ++ case DEVICE_RAIDZ: ++ { ++ unsigned c = 0; ++ grub_uint64_t high; ++ grub_uint64_t devn; ++ grub_uint64_t m; ++ grub_uint32_t s, orig_s; ++ void *orig_buf = buf; ++ grub_size_t orig_len = len; ++ grub_uint8_t *recovery_buf[4]; ++ grub_size_t recovery_len[4]; ++ int recovery_idx[4]; ++ unsigned failed_devices = 0; ++ int idx, orig_idx; ++ ++ if (desc->nparity < 1 || desc->nparity > 3) ++ return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, ++ "raidz%d is not supported", desc->nparity); ++ ++ orig_s = (((len + (1 << desc->ashift) - 1) >> desc->ashift) ++ + (desc->n_children - desc->nparity) - 1); ++ s = orig_s; ++ ++ high = grub_divmod64_full ((offset >> desc->ashift), ++ desc->n_children, &m); ++ if (desc->nparity == 2) ++ c = 2; ++ if (desc->nparity == 3) ++ c = 3; ++ if (((len + (1 << desc->ashift) - 1) >> desc->ashift) ++ >= (desc->n_children - desc->nparity)) ++ idx = (desc->n_children - desc->nparity - 1); ++ else ++ idx = ((len + (1 << desc->ashift) - 1) >> desc->ashift) - 1; ++ orig_idx = idx; ++ while (len > 0) ++ { ++ grub_size_t csize; ++ grub_uint32_t bsize; ++ grub_err_t err; ++ bsize = s / (desc->n_children - desc->nparity); ++ ++ if (desc->nparity == 1 ++ && ((offset >> (desc->ashift + 11)) & 1) == c) ++ c++; ++ ++ high = grub_divmod64_full ((offset >> desc->ashift) + c, ++ desc->n_children, &devn); ++ csize = bsize << desc->ashift; ++ if (csize > len) ++ csize = len; ++ ++ grub_dprintf ("zfs", "RAIDZ mapping 0x%" PRIxGRUB_UINT64_T ++ "+%u (%" PRIxGRUB_SIZE ", %" PRIxGRUB_UINT32_T ++ ") -> (0x%" PRIxGRUB_UINT64_T ", 0x%" ++ PRIxGRUB_UINT64_T ")\n", ++ offset >> desc->ashift, c, len, bsize, high, ++ devn); ++ err = read_device ((high << desc->ashift) ++ | (offset & ((1 << desc->ashift) - 1)), ++ &desc->children[devn], ++ csize, buf); ++ if (err && failed_devices < desc->nparity) ++ { ++ recovery_buf[failed_devices] = buf; ++ recovery_len[failed_devices] = csize; ++ recovery_idx[failed_devices] = idx; ++ failed_devices++; ++ grub_errno = err = 0; ++ } ++ if (err) ++ return err; ++ ++ c++; ++ idx--; ++ s--; ++ buf = (char *) buf + csize; ++ len -= csize; ++ } ++ if (failed_devices) ++ { ++ unsigned redundancy_pow[4]; ++ unsigned cur_redundancy_pow = 0; ++ unsigned n_redundancy = 0; ++ unsigned i, j; ++ grub_err_t err; ++ ++ /* Compute mul. x**s has a period of 255. */ ++ if (powx[0] == 0) ++ { ++ grub_uint8_t cur = 1; ++ for (i = 0; i < 255; i++) ++ { ++ powx[i] = cur; ++ powx[i + 255] = cur; ++ powx_inv[cur] = i; ++ if (cur & 0x80) ++ cur = (cur << 1) ^ poly; ++ else ++ cur <<= 1; ++ } ++ } ++ ++ /* Read redundancy data. */ ++ for (n_redundancy = 0, cur_redundancy_pow = 0; ++ n_redundancy < failed_devices; ++ cur_redundancy_pow++) ++ { ++ high = grub_divmod64_full ((offset >> desc->ashift) ++ + cur_redundancy_pow ++ + ((desc->nparity == 1) ++ && ((offset >> (desc->ashift + 11)) ++ & 1)), ++ desc->n_children, &devn); ++ err = read_device ((high << desc->ashift) ++ | (offset & ((1 << desc->ashift) - 1)), ++ &desc->children[devn], ++ recovery_len[n_redundancy], ++ recovery_buf[n_redundancy]); ++ /* Ignore error if we may still have enough devices. */ ++ if (err && n_redundancy + desc->nparity - cur_redundancy_pow - 1 ++ >= failed_devices) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ continue; ++ } ++ if (err) ++ return err; ++ redundancy_pow[n_redundancy] = cur_redundancy_pow; ++ n_redundancy++; ++ } ++ /* Now xor-our the parts we already know. */ ++ buf = orig_buf; ++ len = orig_len; ++ s = orig_s; ++ idx = orig_idx; ++ ++ while (len > 0) ++ { ++ grub_size_t csize; ++ csize = ((s / (desc->n_children - desc->nparity)) ++ << desc->ashift); ++ if (csize > len) ++ csize = len; ++ ++ for (j = 0; j < failed_devices; j++) ++ if (buf == recovery_buf[j]) ++ break; ++ ++ if (j == failed_devices) ++ for (j = 0; j < failed_devices; j++) ++ xor_out (recovery_buf[j], buf, ++ csize < recovery_len[j] ? csize : recovery_len[j], ++ idx, redundancy_pow[j]); ++ ++ s--; ++ buf = (char *) buf + csize; ++ len -= csize; ++ idx--; ++ } ++ for (i = 0; i < failed_devices ++ && recovery_len[i] == recovery_len[0]; ++ i++); ++ /* Since the chunks have variable length handle the last block ++ separately. */ ++ if (i != failed_devices) ++ { ++ grub_uint8_t *tmp_recovery_buf[4]; ++ for (j = 0; j < i; j++) ++ tmp_recovery_buf[j] = recovery_buf[j] + recovery_len[j] - 1; ++ err = recovery (tmp_recovery_buf, 1, i, redundancy_pow, ++ recovery_idx); ++ if (err) ++ return err; ++ } ++ err = recovery (recovery_buf, recovery_len[failed_devices - 1], ++ failed_devices, redundancy_pow, recovery_idx); ++ if (err) ++ return err; ++ } ++ return GRUB_ERR_NONE; ++ } ++ } ++ return grub_error (GRUB_ERR_BAD_FS, "unsupported device type"); ++} ++ ++static grub_err_t ++read_dva (const dva_t *dva, ++ grub_zfs_endian_t endian, struct grub_zfs_data *data, ++ void *buf, grub_size_t len) ++{ ++ grub_uint64_t offset; ++ unsigned i; ++ grub_err_t err; ++ int try = 0; ++ offset = dva_get_offset (dva, endian); ++ ++ for (try = 0; try < 2; try++) ++ { ++ for (i = 0; i < data->n_devices_attached; i++) ++ if (data->devices_attached[i].id == DVA_GET_VDEV (dva)) ++ { ++ err = read_device (offset, &data->devices_attached[i], len, buf); ++ if (!err) ++ return GRUB_ERR_NONE; ++ break; ++ } ++ if (try == 1) ++ break; ++ err = scan_devices (data); ++ if (err) ++ return err; ++ } ++ return err; ++} + + /* + * Read a block of data based on the gang block address dva, +@@ -412,7 +1292,6 @@ + struct grub_zfs_data *data) + { + zio_gbh_phys_t *zio_gb; +- grub_uint64_t offset, sector; + unsigned i; + grub_err_t err; + zio_cksum_t zc; +@@ -424,13 +1303,8 @@ + return grub_errno; + grub_dprintf ("zfs", endian == LITTLE_ENDIAN ? "little-endian gang\n" + :"big-endian gang\n"); +- offset = dva_get_offset (dva, endian); +- sector = DVA_OFFSET_TO_PHYS_SECTOR (offset); +- grub_dprintf ("zfs", "offset=%llx\n", (unsigned long long) offset); + +- /* read in the gang block header */ +- err = grub_disk_read (data->disk, sector, 0, SPA_GANGBLOCKSIZE, +- (char *) zio_gb); ++ err = read_dva (dva, endian, data, zio_gb, SPA_GANGBLOCKSIZE); + if (err) + { + grub_free (zio_gb); +@@ -483,20 +1357,13 @@ + /* pick a good dva from the block pointer */ + for (i = 0; i < SPA_DVAS_PER_BP; i++) + { +- grub_uint64_t offset, sector; +- + if (bp->blk_dva[i].dva_word[0] == 0 && bp->blk_dva[i].dva_word[1] == 0) + continue; + + if ((grub_zfs_to_cpu64 (bp->blk_dva[i].dva_word[1], endian)>>63) & 1) + err = zio_read_gang (bp, endian, &bp->blk_dva[i], buf, data); + else +- { +- /* read in a data block */ +- offset = dva_get_offset (&bp->blk_dva[i], endian); +- sector = DVA_OFFSET_TO_PHYS_SECTOR (offset); +- err = grub_disk_read (data->disk, sector, 0, psize, buf); +- } ++ err = read_dva (&bp->blk_dva[i], endian, data, buf, psize); + if (!err) + return GRUB_ERR_NONE; + grub_errno = GRUB_ERR_NONE; +@@ -527,7 +1394,7 @@ + *buf = NULL; + + checksum = (grub_zfs_to_cpu64((bp)->blk_prop, endian) >> 40) & 0xff; +- comp = (grub_zfs_to_cpu64((bp)->blk_prop, endian)>>32) & 0x7; ++ comp = (grub_zfs_to_cpu64((bp)->blk_prop, endian)>>32) & 0xff; + lsize = (BP_IS_HOLE(bp) ? 0 : + (((grub_zfs_to_cpu64 ((bp)->blk_prop, endian) & 0xffff) + 1) + << SPA_MINBLOCKSHIFT)); +@@ -602,7 +1469,8 @@ + dmu_read (dnode_end_t * dn, grub_uint64_t blkid, void **buf, + grub_zfs_endian_t *endian_out, struct grub_zfs_data *data) + { +- int idx, level; ++ int level; ++ grub_off_t idx; + blkptr_t *bp_array = dn->dn.dn_blkptr; + int epbs = dn->dn.dn_indblkshift - SPA_BLKPTRSHIFT; + blkptr_t *bp; +@@ -670,7 +1538,8 @@ + */ + static grub_err_t + mzap_lookup (mzap_phys_t * zapobj, grub_zfs_endian_t endian, +- int objsize, char *name, grub_uint64_t * value) ++ int objsize, char *name, grub_uint64_t * value, ++ int case_insensitive) + { + int i, chunks; + mzap_ent_phys_t *mzap_ent = zapobj->mz_chunk; +@@ -678,7 +1547,8 @@ + chunks = objsize / MZAP_ENT_LEN - 1; + for (i = 0; i < chunks; i++) + { +- if (grub_strcmp (mzap_ent[i].mze_name, name) == 0) ++ if (case_insensitive ? (grub_strcasecmp (mzap_ent[i].mze_name, name) == 0) ++ : (grub_strcmp (mzap_ent[i].mze_name, name) == 0)) + { + *value = grub_zfs_to_cpu64 (mzap_ent[i].mze_value, endian); + return GRUB_ERR_NONE; +@@ -711,7 +1581,8 @@ + } + + static grub_uint64_t +-zap_hash (grub_uint64_t salt, const char *name) ++zap_hash (grub_uint64_t salt, const char *name, ++ int case_insensitive) + { + static grub_uint64_t table[256]; + const grub_uint8_t *cp; +@@ -729,8 +1600,12 @@ + } + } + +- for (cp = (const grub_uint8_t *) name; (c = *cp) != '\0'; cp++) +- crc = (crc >> 8) ^ table[(crc ^ c) & 0xFF]; ++ if (case_insensitive) ++ for (cp = (const grub_uint8_t *) name; (c = *cp) != '\0'; cp++) ++ crc = (crc >> 8) ^ table[(crc ^ grub_toupper (c)) & 0xFF]; ++ else ++ for (cp = (const grub_uint8_t *) name; (c = *cp) != '\0'; cp++) ++ crc = (crc >> 8) ^ table[(crc ^ c) & 0xFF]; + + /* + * Only use 28 bits, since we need 4 bits in the cookie for the +@@ -748,10 +1623,34 @@ + * array_len is actual len in bytes (not encoded le_value_length). + * buf is null-terminated. + */ ++ ++static inline int ++name_cmp (const char *s1, const char *s2, grub_size_t n, ++ int case_insensitive) ++{ ++ const char *t1 = (const char *) s1; ++ const char *t2 = (const char *) s2; ++ ++ if (!case_insensitive) ++ return grub_memcmp (t1, t2, n); ++ ++ while (n--) ++ { ++ if (grub_toupper (*t1) != grub_toupper (*t2)) ++ return (int) grub_toupper (*t1) - (int) grub_toupper (*t2); ++ ++ t1++; ++ t2++; ++ } ++ ++ return 0; ++} ++ + /* XXX */ + static int + zap_leaf_array_equal (zap_leaf_phys_t * l, grub_zfs_endian_t endian, +- int blksft, int chunk, int array_len, const char *buf) ++ int blksft, int chunk, int array_len, const char *buf, ++ int case_insensitive) + { + int bseen = 0; + +@@ -763,7 +1662,8 @@ + if (chunk >= ZAP_LEAF_NUMCHUNKS (blksft)) + return (0); + +- if (grub_memcmp (la->la_array, buf + bseen, toread) != 0) ++ if (name_cmp ((char *) la->la_array, buf + bseen, toread, ++ case_insensitive) != 0) + break; + chunk = grub_zfs_to_cpu16 (la->la_next, endian); + bseen += toread; +@@ -804,7 +1704,8 @@ + static grub_err_t + zap_leaf_lookup (zap_leaf_phys_t * l, grub_zfs_endian_t endian, + int blksft, grub_uint64_t h, +- const char *name, grub_uint64_t * value) ++ const char *name, grub_uint64_t * value, ++ int case_insensitive) + { + grub_uint16_t chunk; + struct zap_leaf_entry *le; +@@ -816,7 +1717,7 @@ + return grub_error (GRUB_ERR_BAD_FS, "invalid leaf magic"); + + for (chunk = grub_zfs_to_cpu16 (l->l_hash[LEAF_HASH (blksft, h)], endian); +- chunk != CHAIN_END; chunk = le->le_next) ++ chunk != CHAIN_END; chunk = grub_zfs_to_cpu16 (le->le_next, endian)) + { + + if (chunk >= ZAP_LEAF_NUMCHUNKS (blksft)) +@@ -836,11 +1737,12 @@ + if (zap_leaf_array_equal (l, endian, blksft, + grub_zfs_to_cpu16 (le->le_name_chunk,endian), + grub_zfs_to_cpu16 (le->le_name_length, endian), +- name)) ++ name, case_insensitive)) + { + struct zap_leaf_array *la; + +- if (le->le_int_size != 8 || le->le_value_length != 1) ++ if (le->le_int_size != 8 || grub_zfs_to_cpu16 (le->le_value_length, ++ endian) != 1) + return grub_error (GRUB_ERR_BAD_FS, "invalid leaf chunk entry"); + + /* get the uint64_t property value */ +@@ -858,9 +1760,9 @@ + + /* Verify if this is a fat zap header block */ + static grub_err_t +-zap_verify (zap_phys_t *zap) ++zap_verify (zap_phys_t *zap, grub_zfs_endian_t endian) + { +- if (zap->zap_magic != (grub_uint64_t) ZAP_MAGIC) ++ if (grub_zfs_to_cpu64 (zap->zap_magic, endian) != (grub_uint64_t) ZAP_MAGIC) + return grub_error (GRUB_ERR_BAD_FS, "bad ZAP magic"); + + if (zap->zap_flags != 0) +@@ -879,7 +1781,8 @@ + /* XXX */ + static grub_err_t + fzap_lookup (dnode_end_t * zap_dnode, zap_phys_t * zap, +- char *name, grub_uint64_t * value, struct grub_zfs_data *data) ++ char *name, grub_uint64_t * value, struct grub_zfs_data *data, ++ int case_insensitive) + { + void *l; + grub_uint64_t hash, idx, blkid; +@@ -888,18 +1791,18 @@ + grub_err_t err; + grub_zfs_endian_t leafendian; + +- err = zap_verify (zap); ++ err = zap_verify (zap, zap_dnode->endian); + if (err) + return err; + +- hash = zap_hash (zap->zap_salt, name); ++ hash = zap_hash (zap->zap_salt, name, case_insensitive); + + /* get block id from index */ + if (zap->zap_ptrtbl.zt_numblks != 0) + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "external pointer tables not supported"); + idx = ZAP_HASH_IDX (hash, zap->zap_ptrtbl.zt_shift); +- blkid = ((grub_uint64_t *) zap)[idx + (1 << (blksft - 3 - 1))]; ++ blkid = grub_zfs_to_cpu64 (((grub_uint64_t *) zap)[idx + (1 << (blksft - 3 - 1))], zap_dnode->endian); + + /* Get the leaf block */ + if ((1U << blksft) < sizeof (zap_leaf_phys_t)) +@@ -908,7 +1811,8 @@ + if (err) + return err; + +- err = zap_leaf_lookup (l, leafendian, blksft, hash, name, value); ++ err = zap_leaf_lookup (l, leafendian, blksft, hash, name, value, ++ case_insensitive); + grub_free (l); + return err; + } +@@ -922,14 +1826,14 @@ + { + zap_leaf_phys_t *l; + void *l_in; +- grub_uint64_t idx, blkid; ++ grub_uint64_t idx, idx2, blkid; + grub_uint16_t chunk; + int blksft = zfs_log2 (grub_zfs_to_cpu16 (zap_dnode->dn.dn_datablkszsec, + zap_dnode->endian) << DNODE_SHIFT); + grub_err_t err; + grub_zfs_endian_t endian; + +- if (zap_verify (zap)) ++ if (zap_verify (zap, zap_dnode->endian)) + return 0; + + /* get block id from index */ +@@ -945,9 +1849,17 @@ + grub_error (GRUB_ERR_BAD_FS, "ZAP leaf is too small"); + return 0; + } +- for (idx = 0; idx < zap->zap_ptrtbl.zt_numblks; idx++) ++ for (idx = 0; idx < (1ULL << zap->zap_ptrtbl.zt_shift); idx++) + { +- blkid = ((grub_uint64_t *) zap)[idx + (1 << (blksft - 3 - 1))]; ++ blkid = grub_zfs_to_cpu64 (((grub_uint64_t *) zap)[idx + (1 << (blksft - 3 - 1))], ++ zap_dnode->endian); ++ ++ for (idx2 = 0; idx2 < idx; idx2++) ++ if (blkid == grub_zfs_to_cpu64 (((grub_uint64_t *) zap)[idx2 + (1 << (blksft - 3 - 1))], ++ zap_dnode->endian)) ++ break; ++ if (idx2 != idx) ++ continue; + + err = dmu_read (zap_dnode, blkid, &l_in, &endian, data); + l = l_in; +@@ -983,8 +1895,11 @@ + + buf = grub_malloc (grub_zfs_to_cpu16 (le->le_name_length, endian) + + 1); +- if (zap_leaf_array_get (l, endian, blksft, le->le_name_chunk, +- le->le_name_length, buf)) ++ if (zap_leaf_array_get (l, endian, blksft, ++ grub_zfs_to_cpu16 (le->le_name_chunk, ++ endian), ++ grub_zfs_to_cpu16 (le->le_name_length, ++ endian), buf)) + { + grub_free (buf); + continue; +@@ -996,7 +1911,9 @@ + continue; + + /* get the uint64_t property value */ +- la = &ZAP_LEAF_CHUNK (l, blksft, le->le_value_chunk).l_array; ++ la = &ZAP_LEAF_CHUNK (l, blksft, ++ grub_zfs_to_cpu16 (le->le_value_chunk, ++ endian)).l_array; + val = grub_be_to_cpu64 (la->la_array64); + if (hook (buf, val)) + return 1; +@@ -1014,7 +1931,7 @@ + */ + static grub_err_t + zap_lookup (dnode_end_t * zap_dnode, char *name, grub_uint64_t * val, +- struct grub_zfs_data *data) ++ struct grub_zfs_data *data, int case_insensitive) + { + grub_uint64_t block_type; + int size; +@@ -1037,7 +1954,8 @@ + if (block_type == ZBT_MICRO) + { + grub_dprintf ("zfs", "micro zap\n"); +- err = (mzap_lookup (zapbuf, endian, size, name, val)); ++ err = mzap_lookup (zapbuf, endian, size, name, val, ++ case_insensitive); + grub_dprintf ("zfs", "returned %d\n", err); + grub_free (zapbuf); + return err; +@@ -1046,7 +1964,8 @@ + { + grub_dprintf ("zfs", "fat zap\n"); + /* this is a fat zap */ +- err = (fzap_lookup (zap_dnode, zapbuf, name, val, data)); ++ err = fzap_lookup (zap_dnode, zapbuf, name, val, data, ++ case_insensitive); + grub_dprintf ("zfs", "returned %d\n", err); + grub_free (zapbuf); + return err; +@@ -1074,7 +1993,7 @@ + return 0; + block_type = grub_zfs_to_cpu64 (*((grub_uint64_t *) zapbuf), endian); + +- grub_dprintf ("zfs", "zap read\n"); ++ grub_dprintf ("zfs", "zap iterate\n"); + + if (block_type == ZBT_MICRO) + { +@@ -1172,9 +2091,9 @@ + */ + static grub_err_t + dnode_get_path (dnode_end_t * mdn, const char *path_in, dnode_end_t * dn, +- struct grub_zfs_data *data) ++ struct grub_zfs_data *data, int *case_insensitive) + { +- grub_uint64_t objnum, version; ++ grub_uint64_t objnum, version, insensitivity; + char *cname, ch; + grub_err_t err = GRUB_ERR_NONE; + char *path, *path_buf; +@@ -1199,19 +2118,31 @@ + return err; + } + +- err = zap_lookup (&(dnode_path->dn), ZPL_VERSION_STR, &version, data); ++ err = zap_lookup (&(dnode_path->dn), ZPL_VERSION_STR, &version, ++ data, 0); + if (err) + { + grub_free (dn_new); + return err; + } ++ + if (version > ZPL_VERSION) + { + grub_free (dn_new); + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "too new ZPL version"); + } +- +- err = zap_lookup (&(dnode_path->dn), ZFS_ROOT_OBJ, &objnum, data); ++ ++ err = zap_lookup (&(dnode_path->dn), "casesensitivity", &insensitivity, ++ data, 0); ++ if (err == GRUB_ERR_FILE_NOT_FOUND) ++ { ++ grub_errno = GRUB_ERR_NONE; ++ insensitivity = 0; ++ } ++ if (case_insensitive) ++ *case_insensitive = insensitivity; ++ ++ err = zap_lookup (&(dnode_path->dn), ZFS_ROOT_OBJ, &objnum, data, 0); + if (err) + { + grub_free (dn_new); +@@ -1272,7 +2203,7 @@ + grub_free (path_buf); + return grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory"); + } +- err = zap_lookup (&(dnode_path->dn), cname, &objnum, data); ++ err = zap_lookup (&(dnode_path->dn), cname, &objnum, data, insensitivity); + if (err) + break; + +@@ -1291,22 +2222,54 @@ + break; + + *path = ch; +-#if 0 +- if (((grub_zfs_to_cpu64(((znode_phys_t *) DN_BONUS (&dnode_path->dn.dn))->zp_mode, dnode_path->dn.endian) >> 12) & 0xf) == 0xa && ch) ++ if (dnode_path->dn.dn.dn_bonustype == DMU_OT_ZNODE ++ && ((grub_zfs_to_cpu64(((znode_phys_t *) DN_BONUS (&dnode_path->dn.dn))->zp_mode, dnode_path->dn.endian) >> 12) & 0xf) == 0xa) + { ++ char *sym_value; ++ grub_size_t sym_sz; ++ int free_symval = 0; + char *oldpath = path, *oldpathbuf = path_buf; +- path = path_buf +- = grub_malloc (sizeof (dnode_path->dn.dn.dn_bonus) +- - sizeof (znode_phys_t) + grub_strlen (oldpath) + 1); ++ sym_value = ((char *) DN_BONUS (&dnode_path->dn.dn) + sizeof (struct znode_phys)); ++ ++ sym_sz = grub_zfs_to_cpu64 (((znode_phys_t *) DN_BONUS (&dnode_path->dn.dn))->zp_size, dnode_path->dn.endian); ++ ++ if (dnode_path->dn.dn.dn_flags & 1) ++ { ++ grub_size_t block; ++ grub_size_t blksz; ++ blksz = (grub_zfs_to_cpu16 (dnode_path->dn.dn.dn_datablkszsec, ++ dnode_path->dn.endian) ++ << SPA_MINBLOCKSHIFT); ++ ++ sym_value = grub_malloc (sym_sz); ++ if (!sym_value) ++ return grub_errno; ++ for (block = 0; block < (sym_sz + blksz - 1) / blksz; block++) ++ { ++ void *t; ++ grub_size_t movesize; ++ ++ err = dmu_read (&(dnode_path->dn), block, &t, 0, data); ++ if (err) ++ return err; ++ ++ movesize = MIN (sym_sz - block * blksz, blksz); ++ ++ grub_memcpy (sym_value + block * blksz, t, movesize); ++ grub_free (t); ++ } ++ free_symval = 1; ++ } ++ path = path_buf = grub_malloc (sym_sz + grub_strlen (oldpath) + 1); + if (!path_buf) + { + grub_free (oldpathbuf); + return grub_errno; + } +- grub_memcpy (path, +- (char *) DN_BONUS(&dnode_path->dn.dn) + sizeof (znode_phys_t), +- sizeof (dnode_path->dn.dn.dn_bonus) - sizeof (znode_phys_t)); +- path [sizeof (dnode_path->dn.dn.dn_bonus) - sizeof (znode_phys_t)] = 0; ++ grub_memcpy (path, sym_value, sym_sz); ++ if (free_symval) ++ grub_free (sym_value); ++ path [sym_sz] = 0; + grub_memcpy (path + grub_strlen (path), oldpath, + grub_strlen (oldpath) + 1); + +@@ -1324,7 +2287,62 @@ + grub_free (dn_new); + } + } +-#endif ++ if (dnode_path->dn.dn.dn_bonustype == DMU_OT_SA) ++ { ++ void *sahdrp; ++ int hdrsize; ++ ++ if (dnode_path->dn.dn.dn_bonuslen != 0) ++ { ++ sahdrp = DN_BONUS (&dnode_path->dn.dn); ++ } ++ else if (dnode_path->dn.dn.dn_flags & DNODE_FLAG_SPILL_BLKPTR) ++ { ++ blkptr_t *bp = &dnode_path->dn.dn.dn_spill; ++ ++ err = zio_read (bp, dnode_path->dn.endian, &sahdrp, NULL, data); ++ if (err) ++ return err; ++ } ++ else ++ { ++ return grub_error (GRUB_ERR_BAD_FS, "filesystem is corrupt"); ++ } ++ ++ hdrsize = SA_HDR_SIZE (((sa_hdr_phys_t *) sahdrp)); ++ ++ if (((grub_zfs_to_cpu64 (*(grub_uint64_t *) ((char *) sahdrp + hdrsize + SA_TYPE_OFFSET), dnode_path->dn.endian) >> 12) & 0xf) == 0xa) ++ { ++ char *sym_value = (char *) sahdrp + hdrsize + SA_SYMLINK_OFFSET; ++ grub_size_t sym_sz = ++ grub_zfs_to_cpu64 (*(grub_uint64_t *) ((char *) sahdrp + hdrsize + SA_SIZE_OFFSET), dnode_path->dn.endian); ++ char *oldpath = path, *oldpathbuf = path_buf; ++ path = path_buf = grub_malloc (sym_sz + grub_strlen (oldpath) + 1); ++ if (!path_buf) ++ { ++ grub_free (oldpathbuf); ++ return grub_errno; ++ } ++ grub_memcpy (path, sym_value, sym_sz); ++ path [sym_sz] = 0; ++ grub_memcpy (path + grub_strlen (path), oldpath, ++ grub_strlen (oldpath) + 1); ++ ++ grub_free (oldpathbuf); ++ if (path[0] != '/') ++ { ++ dn_new = dnode_path; ++ dnode_path = dn_new->next; ++ grub_free (dn_new); ++ } ++ else while (dnode_path != root) ++ { ++ dn_new = dnode_path; ++ dnode_path = dn_new->next; ++ grub_free (dn_new); ++ } ++ } ++ } + } + + if (!err) +@@ -1417,7 +2435,7 @@ + + grub_dprintf ("zfs", "alive\n"); + +- err = zap_lookup (mdn, DMU_POOL_ROOT_DATASET, &objnum, data); ++ err = zap_lookup (mdn, DMU_POOL_ROOT_DATASET, &objnum, data, 0); + if (err) + return err; + +@@ -1452,7 +2470,7 @@ + if (err) + return err; + +- err = zap_lookup (mdn, cname, &objnum, data); ++ err = zap_lookup (mdn, cname, &objnum, data, 0); + if (err) + return err; + +@@ -1495,7 +2513,7 @@ + static grub_err_t + dnode_get_fullpath (const char *fullpath, dnode_end_t * mdn, + grub_uint64_t *mdnobj, dnode_end_t * dn, int *isfs, +- struct grub_zfs_data *data) ++ struct grub_zfs_data *data, int *case_insensitive) + { + char *fsname, *snapname; + const char *ptr_at, *filename; +@@ -1573,7 +2591,7 @@ + err = dnode_get (&(data->mos), snapobj, + DMU_OT_DSL_DS_SNAP_MAP, mdn, data); + if (!err) +- err = zap_lookup (mdn, snapname, &headobj, data); ++ err = zap_lookup (mdn, snapname, &headobj, data, 0); + if (!err) + err = dnode_get (&(data->mos), headobj, DMU_OT_DSL_DATASET, mdn, data); + if (err) +@@ -1597,7 +2615,7 @@ + grub_free (snapname); + return GRUB_ERR_NONE; + } +- err = dnode_get_path (mdn, filename, dn, data); ++ err = dnode_get_path (mdn, filename, dn, data, case_insensitive); + grub_free (fsname); + grub_free (snapname); + return err; +@@ -1625,11 +2643,12 @@ + */ + + static int +-nvlist_find_value (char *nvlist, char *name, int valtype, char **val, ++nvlist_find_value (const char *nvlist, const char *name, ++ int valtype, char **val, + grub_size_t *size_out, grub_size_t *nelm_out) + { + int name_len, type, encode_size; +- char *nvpair, *nvp_name; ++ const char *nvpair, *nvp_name; + + /* Verify if the 1st and 2nd byte in the nvlist are valid. */ + /* NOTE: independently of what endianness header announces all +@@ -1671,7 +2690,7 @@ + + if ((grub_strncmp (nvp_name, name, name_len) == 0) && type == valtype) + { +- *val = nvpair; ++ *val = (char *) nvpair; + *size_out = encode_size; + if (nelm_out) + *nelm_out = nelm; +@@ -1684,7 +2703,8 @@ + } + + int +-grub_zfs_nvlist_lookup_uint64 (char *nvlist, char *name, grub_uint64_t * out) ++grub_zfs_nvlist_lookup_uint64 (const char *nvlist, const char *name, ++ grub_uint64_t * out) + { + char *nvpair; + grub_size_t size; +@@ -1704,7 +2724,7 @@ + } + + char * +-grub_zfs_nvlist_lookup_string (char *nvlist, char *name) ++grub_zfs_nvlist_lookup_string (const char *nvlist, const char *name) + { + char *nvpair; + char *ret; +@@ -1732,7 +2752,7 @@ + } + + char * +-grub_zfs_nvlist_lookup_nvlist (char *nvlist, char *name) ++grub_zfs_nvlist_lookup_nvlist (const char *nvlist, const char *name) + { + char *nvpair; + char *ret; +@@ -1753,199 +2773,114 @@ + } + + int +-grub_zfs_nvlist_lookup_nvlist_array_get_nelm (char *nvlist, char *name) +-{ +- char *nvpair; +- grub_size_t nelm, size; +- int found; +- +- found = nvlist_find_value (nvlist, name, DATA_TYPE_NVLIST, &nvpair, +- &size, &nelm); +- if (! found) +- return -1; +- return nelm; +-} +- +-char * +-grub_zfs_nvlist_lookup_nvlist_array (char *nvlist, char *name, +- grub_size_t index) +-{ +- char *nvpair, *nvpairptr; +- int found; +- char *ret; +- grub_size_t size; +- unsigned i; +- grub_size_t nelm; +- +- found = nvlist_find_value (nvlist, name, DATA_TYPE_NVLIST, &nvpair, +- &size, &nelm); +- if (!found) +- return 0; +- if (index >= nelm) +- { +- grub_error (GRUB_ERR_OUT_OF_RANGE, "trying to lookup past nvlist array"); +- return 0; +- } +- +- nvpairptr = nvpair; +- +- for (i = 0; i < index; i++) +- { +- grub_uint32_t encode_size; +- +- /* skip the header, nvl_version, and nvl_nvflag */ +- nvpairptr = nvpairptr + 4 * 2; +- +- while (nvpairptr < nvpair + size +- && (encode_size = grub_be_to_cpu32 (*(grub_uint32_t *) nvpairptr))) +- nvlist += encode_size; /* goto the next nvpair */ +- +- nvlist = nvlist + 4 * 2; /* skip the ending 2 zeros - 8 bytes */ +- } +- +- if (nvpairptr >= nvpair + size +- || nvpairptr + grub_be_to_cpu32 (*(grub_uint32_t *) (nvpairptr + 4 * 2)) +- >= nvpair + size) +- { +- grub_error (GRUB_ERR_BAD_FS, "incorrect nvlist array"); +- return 0; +- } +- +- ret = grub_zalloc (grub_be_to_cpu32 (*(grub_uint32_t *) (nvpairptr + 4 * 2)) +- + 3 * sizeof (grub_uint32_t)); +- if (!ret) +- return 0; +- grub_memcpy (ret, nvlist, sizeof (grub_uint32_t)); +- +- grub_memcpy (ret + sizeof (grub_uint32_t), nvpairptr, size); +- return ret; +-} +- +-static grub_err_t +-zfs_fetch_nvlist (struct grub_zfs_data * data, char **nvlist) +-{ +- grub_err_t err; +- +- *nvlist = grub_malloc (VDEV_PHYS_SIZE); +- /* Read in the vdev name-value pair list (112K). */ +- err = grub_disk_read (data->disk, data->vdev_phys_sector, 0, +- VDEV_PHYS_SIZE, *nvlist); +- if (err) +- { +- grub_free (*nvlist); +- *nvlist = 0; +- return err; +- } +- return GRUB_ERR_NONE; +-} +- +-/* +- * Check the disk label information and retrieve needed vdev name-value pairs. +- * +- */ +-static grub_err_t +-check_pool_label (struct grub_zfs_data *data) ++grub_zfs_nvlist_lookup_nvlist_array_get_nelm (const char *nvlist, ++ const char *name) + { +- grub_uint64_t pool_state, txg = 0; +- char *nvlist; +-#if 0 +- char *nv; +-#endif +- grub_uint64_t diskguid; +- grub_uint64_t version; ++ char *nvpair; ++ grub_size_t nelm, size; + int found; +- grub_err_t err; + +- err = zfs_fetch_nvlist (data, &nvlist); +- if (err) +- return err; ++ found = nvlist_find_value (nvlist, name, DATA_TYPE_NVLIST_ARRAY, &nvpair, ++ &size, &nelm); ++ if (! found) ++ return -1; ++ return nelm; ++} + +- grub_dprintf ("zfs", "check 2 passed\n"); ++static int ++get_nvlist_size (const char *beg, const char *limit) ++{ ++ const char *ptr; ++ grub_uint32_t encode_size; ++ ++ ptr = beg + 8; + +- found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_STATE, +- &pool_state); +- if (! found) +- { +- grub_free (nvlist); +- if (! grub_errno) +- grub_error (GRUB_ERR_BAD_FS, ZPOOL_CONFIG_POOL_STATE " not found"); +- return grub_errno; +- } +- grub_dprintf ("zfs", "check 3 passed\n"); ++ while (ptr < limit ++ && (encode_size = grub_be_to_cpu32 (*(grub_uint32_t *) ptr))) ++ ptr += encode_size; /* goto the next nvpair */ ++ ptr += 8; ++ return (ptr > limit) ? -1 : (ptr - beg); ++} + +- if (pool_state == POOL_STATE_DESTROYED) +- { +- grub_free (nvlist); +- return grub_error (GRUB_ERR_BAD_FS, "zpool is marked as destroyed"); +- } +- grub_dprintf ("zfs", "check 4 passed\n"); ++char * ++grub_zfs_nvlist_lookup_nvlist_array (const char *nvlist, const char *name, ++ grub_size_t index) ++{ ++ char *nvpair, *nvpairptr; ++ int found; ++ char *ret; ++ grub_size_t size; ++ unsigned i; ++ grub_size_t nelm; ++ int elemsize = 0; + +- found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_TXG, &txg); ++ found = nvlist_find_value (nvlist, name, DATA_TYPE_NVLIST_ARRAY, &nvpair, ++ &size, &nelm); + if (!found) ++ return 0; ++ if (index >= nelm) + { +- grub_free (nvlist); +- if (! grub_errno) +- grub_error (GRUB_ERR_BAD_FS, ZPOOL_CONFIG_POOL_TXG " not found"); +- return grub_errno; ++ grub_error (GRUB_ERR_OUT_OF_RANGE, "trying to lookup past nvlist array"); ++ return 0; + } +- grub_dprintf ("zfs", "check 6 passed\n"); + +- /* not an active device */ +- if (txg == 0) +- { +- grub_free (nvlist); +- return grub_error (GRUB_ERR_BAD_FS, "zpool isn't active"); +- } +- grub_dprintf ("zfs", "check 7 passed\n"); ++ nvpairptr = nvpair; + +- found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_VERSION, +- &version); +- if (! found) ++ for (i = 0; i < index; i++) + { +- grub_free (nvlist); +- if (! grub_errno) +- grub_error (GRUB_ERR_BAD_FS, ZPOOL_CONFIG_VERSION " not found"); +- return grub_errno; +- } +- grub_dprintf ("zfs", "check 8 passed\n"); ++ int r; ++ r = get_nvlist_size (nvpairptr, nvpair + size); + +- if (version > SPA_VERSION) +- { +- grub_free (nvlist); +- return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, +- "too new version %llu > %llu", +- (unsigned long long) version, +- (unsigned long long) SPA_VERSION); +- } +- grub_dprintf ("zfs", "check 9 passed\n"); +-#if 0 +- if (nvlist_lookup_value (nvlist, ZPOOL_CONFIG_VDEV_TREE, &nv, +- DATA_TYPE_NVLIST, NULL)) +- { +- grub_free (vdev); +- return (GRUB_ERR_BAD_FS); ++ if (r < 0) ++ { ++ grub_error (GRUB_ERR_BAD_FS, "incorrect nvlist array"); ++ return NULL; ++ } ++ nvpairptr += r; + } +- grub_dprintf ("zfs", "check 10 passed\n"); +-#endif + +- found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_GUID, &diskguid); +- if (! found) ++ elemsize = get_nvlist_size (nvpairptr, nvpair + size); ++ ++ if (elemsize < 0) + { +- grub_free (nvlist); +- if (! grub_errno) +- grub_error (GRUB_ERR_BAD_FS, ZPOOL_CONFIG_GUID " not found"); +- return grub_errno; ++ grub_error (GRUB_ERR_BAD_FS, "incorrect nvlist array"); ++ return 0; + } +- grub_dprintf ("zfs", "check 11 passed\n"); + +- grub_free (nvlist); ++ ret = grub_zalloc (elemsize + sizeof (grub_uint32_t)); ++ if (!ret) ++ return 0; ++ grub_memcpy (ret, nvlist, sizeof (grub_uint32_t)); + +- return GRUB_ERR_NONE; ++ grub_memcpy (ret + sizeof (grub_uint32_t), nvpairptr, elemsize); ++ return ret; ++} ++ ++static void ++unmount_device (struct grub_zfs_device_desc *desc) ++{ ++ unsigned i; ++ switch (desc->type) ++ { ++ case DEVICE_LEAF: ++ if (!desc->original && desc->dev) ++ grub_device_close (desc->dev); ++ return; ++ case DEVICE_RAIDZ: ++ case DEVICE_MIRROR: ++ for (i = 0; i < desc->n_children; i++) ++ unmount_device (&desc->children[i]); ++ return; ++ } + } + + static void + zfs_unmount (struct grub_zfs_data *data) + { ++ unsigned i; ++ for (i = 0; i < data->n_devices_attached; i++) ++ unmount_device (&data->devices_attached[i]); ++ grub_free (data->devices_attached); + grub_free (data->dnode_buf); + grub_free (data->dnode_mdn); + grub_free (data->file_buf); +@@ -1961,13 +2896,11 @@ + zfs_mount (grub_device_t dev) + { + struct grub_zfs_data *data = 0; +- int label = 0; +- uberblock_phys_t *ub_array, *ubbest = NULL; +- vdev_boot_header_t *bh; +- void *osp = 0; +- grub_size_t ospsize; + grub_err_t err; +- int vdevnum; ++ objset_phys_t *osp = 0; ++ grub_size_t ospsize; ++ grub_zfs_endian_t ub_endian = UNKNOWN_ENDIAN; ++ uberblock_t *ub; + + if (! dev->disk) + { +@@ -1975,119 +2908,56 @@ + return 0; + } + +- data = grub_malloc (sizeof (*data)); ++ data = grub_zalloc (sizeof (*data)); + if (!data) + return 0; +- grub_memset (data, 0, sizeof (*data)); + #if 0 + /* if it's our first time here, zero the best uberblock out */ + if (data->best_drive == 0 && data->best_part == 0 && find_best_root) + grub_memset (¤t_uberblock, 0, sizeof (uberblock_t)); + #endif + +- data->disk = dev->disk; +- +- ub_array = grub_malloc (VDEV_UBERBLOCK_RING); +- if (!ub_array) ++ data->n_devices_allocated = 16; ++ data->devices_attached = grub_malloc (sizeof (data->devices_attached[0]) ++ * data->n_devices_allocated); ++ data->n_devices_attached = 0; ++ err = scan_disk (dev, data, 1); ++ if (err) + { + zfs_unmount (data); +- return 0; ++ return NULL; + } + +- bh = grub_malloc (VDEV_BOOT_HEADER_SIZE); +- if (!bh) ++ ub = &(data->current_uberblock); ++ ub_endian = (grub_zfs_to_cpu64 (ub->ub_magic, ++ LITTLE_ENDIAN) == UBERBLOCK_MAGIC ++ ? LITTLE_ENDIAN : BIG_ENDIAN); ++ ++ err = zio_read (&ub->ub_rootbp, ub_endian, ++ (void **) &osp, &ospsize, data); ++ if (err) + { + zfs_unmount (data); +- grub_free (ub_array); +- return 0; ++ return NULL; + } + +- vdevnum = VDEV_LABELS; +- +- /* Don't check back labels on CDROM. */ +- if (grub_disk_get_size (dev->disk) == GRUB_DISK_SIZE_UNKNOWN) +- vdevnum = VDEV_LABELS / 2; +- +- for (label = 0; ubbest == NULL && label < vdevnum; label++) ++ if (ospsize < OBJSET_PHYS_SIZE_V14) + { +- grub_zfs_endian_t ub_endian = UNKNOWN_ENDIAN; +- grub_dprintf ("zfs", "label %d\n", label); +- +- data->vdev_phys_sector +- = label * (sizeof (vdev_label_t) >> SPA_MINBLOCKSHIFT) +- + ((VDEV_SKIP_SIZE + VDEV_BOOT_HEADER_SIZE) >> SPA_MINBLOCKSHIFT) +- + (label < VDEV_LABELS / 2 ? 0 : grub_disk_get_size (dev->disk) +- - VDEV_LABELS * (sizeof (vdev_label_t) >> SPA_MINBLOCKSHIFT)); +- +- /* Read in the uberblock ring (128K). */ +- err = grub_disk_read (data->disk, data->vdev_phys_sector +- + (VDEV_PHYS_SIZE >> SPA_MINBLOCKSHIFT), +- 0, VDEV_UBERBLOCK_RING, (char *) ub_array); +- if (err) +- { +- grub_errno = GRUB_ERR_NONE; +- continue; +- } +- grub_dprintf ("zfs", "label ok %d\n", label); +- +- ubbest = find_bestub (ub_array, data->vdev_phys_sector); +- if (!ubbest) +- { +- grub_dprintf ("zfs", "No uberblock found\n"); +- grub_errno = GRUB_ERR_NONE; +- continue; +- } +- ub_endian = (grub_zfs_to_cpu64 (ubbest->ubp_uberblock.ub_magic, +- LITTLE_ENDIAN) == UBERBLOCK_MAGIC +- ? LITTLE_ENDIAN : BIG_ENDIAN); +- err = zio_read (&ubbest->ubp_uberblock.ub_rootbp, +- ub_endian, +- &osp, &ospsize, data); +- if (err) +- { +- grub_dprintf ("zfs", "couldn't zio_read\n"); +- grub_errno = GRUB_ERR_NONE; +- continue; +- } +- +- if (ospsize < OBJSET_PHYS_SIZE_V14) +- { +- grub_dprintf ("zfs", "osp too small\n"); +- grub_free (osp); +- continue; +- } +- grub_dprintf ("zfs", "ubbest %p\n", ubbest); +- +- err = check_pool_label (data); +- if (err) +- { +- grub_errno = GRUB_ERR_NONE; +- continue; +- } +-#if 0 +- if (find_best_root && +- vdev_uberblock_compare (&ubbest->ubp_uberblock, +- &(current_uberblock)) <= 0) +- continue; +-#endif +- /* Got the MOS. Save it at the memory addr MOS. */ +- grub_memmove (&(data->mos.dn), &((objset_phys_t *) osp)->os_meta_dnode, +- DNODE_SIZE); +- data->mos.endian = (grub_zfs_to_cpu64 (ubbest->ubp_uberblock.ub_rootbp.blk_prop, ub_endian) >> 63) & 1; +- grub_memmove (&(data->current_uberblock), +- &ubbest->ubp_uberblock, sizeof (uberblock_t)); +- grub_free (ub_array); +- grub_free (bh); ++ grub_error (GRUB_ERR_BAD_FS, "OSP too small"); + grub_free (osp); +- return data; ++ zfs_unmount (data); ++ return NULL; + } +- grub_error (GRUB_ERR_BAD_FS, "couldn't find a valid label"); +- zfs_unmount (data); +- grub_free (ub_array); +- grub_free (bh); ++ ++ /* Got the MOS. Save it at the memory addr MOS. */ ++ grub_memmove (&(data->mos.dn), &osp->os_meta_dnode, DNODE_SIZE); ++ data->mos.endian = (grub_zfs_to_cpu64 (ub->ub_rootbp.blk_prop, ++ ub_endian) >> 63) & 1; + grub_free (osp); + +- return 0; ++ data->mounted = 1; ++ ++ return data; + } + + grub_err_t +@@ -2099,7 +2969,7 @@ + zfs = zfs_mount (dev); + if (!zfs) + return grub_errno; +- err = zfs_fetch_nvlist (zfs, nvlist); ++ err = zfs_fetch_nvlist (zfs->device_original, nvlist); + zfs_unmount (zfs); + return err; + } +@@ -2115,7 +2985,7 @@ + if (! data) + return grub_errno; + +- err = zfs_fetch_nvlist (data, &nvlist); ++ err = zfs_fetch_nvlist (data->device_original, &nvlist); + if (err) + { + zfs_unmount (data); +@@ -2131,11 +3001,7 @@ + static grub_err_t + zfs_uuid (grub_device_t device, char **uuid) + { +- char *nvlist; +- int found; + struct grub_zfs_data *data; +- grub_uint64_t guid; +- grub_err_t err; + + *uuid = 0; + +@@ -2143,24 +3009,36 @@ + if (! data) + return grub_errno; + +- err = zfs_fetch_nvlist (data, &nvlist); +- if (err) +- { +- zfs_unmount (data); +- return err; +- } +- +- found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_GUID, &guid); +- if (! found) +- return grub_errno; +- grub_free (nvlist); +- *uuid = grub_xasprintf ("%016llx", (long long unsigned) guid); ++ *uuid = grub_xasprintf ("%016llx", (long long unsigned) data->guid); + zfs_unmount (data); + if (! *uuid) + return grub_errno; + return GRUB_ERR_NONE; + } + ++static grub_err_t ++zfs_mtime (grub_device_t device, grub_int32_t *mt) ++{ ++ struct grub_zfs_data *data; ++ grub_zfs_endian_t ub_endian = UNKNOWN_ENDIAN; ++ uberblock_t *ub; ++ ++ *mt = 0; ++ ++ data = zfs_mount (device); ++ if (! data) ++ return grub_errno; ++ ++ ub = &(data->current_uberblock); ++ ub_endian = (grub_zfs_to_cpu64 (ub->ub_magic, ++ LITTLE_ENDIAN) == UBERBLOCK_MAGIC ++ ? LITTLE_ENDIAN : BIG_ENDIAN); ++ ++ *mt = grub_zfs_to_cpu64 (ub->ub_timestamp, ub_endian); ++ zfs_unmount (data); ++ return GRUB_ERR_NONE; ++} ++ + /* + * zfs_open() locates a file in the rootpool by following the + * MOS and places the dnode of the file in the memory address DNODE. +@@ -2177,7 +3055,7 @@ + return grub_errno; + + err = dnode_get_fullpath (fsfilename, &(data->mdn), 0, +- &(data->dnode), &isfs, data); ++ &(data->dnode), &isfs, data, NULL); + if (err) + { + zfs_unmount (data); +@@ -2227,12 +3105,14 @@ + } + + hdrsize = SA_HDR_SIZE (((sa_hdr_phys_t *) sahdrp)); +- file->size = *(grub_uint64_t *) ((char *) sahdrp + hdrsize + SA_SIZE_OFFSET); ++ file->size = grub_zfs_to_cpu64 (*(grub_uint64_t *) ((char *) sahdrp + hdrsize + SA_SIZE_OFFSET), data->dnode.endian); + } +- else ++ else if (data->dnode.dn.dn_bonustype == DMU_OT_ZNODE) + { + file->size = grub_zfs_to_cpu64 (((znode_phys_t *) DN_BONUS (&data->dnode.dn))->zp_size, data->dnode.endian); + } ++ else ++ return grub_error (GRUB_ERR_BAD_FS, "bad bonus type"); + + file->data = data; + file->offset = 0; +@@ -2248,7 +3128,7 @@ + grub_zfs_read (grub_file_t file, char *buf, grub_size_t len) + { + struct grub_zfs_data *data = (struct grub_zfs_data *) file->data; +- int blksz, movesize; ++ grub_size_t blksz, movesize; + grub_size_t length; + grub_size_t read; + grub_err_t err; +@@ -2302,7 +3182,7 @@ + data->file_start = blkid * blksz; + data->file_end = data->file_start + blksz; + +- movesize = MIN (length, data->file_end - (int) file->offset - read); ++ movesize = MIN (length, data->file_end - file->offset - read); + + grub_memmove (buf, data->file_buf + file->offset + read + - data->file_start, movesize); +@@ -2339,7 +3219,7 @@ + return grub_errno; + + err = dnode_get_fullpath (fsfilename, &(data->mdn), mdnobj, +- &(data->dnode), &isfs, data); ++ &(data->dnode), &isfs, data, NULL); + zfs_unmount (data); + return err; + } +@@ -2377,7 +3257,7 @@ + return; + } + +- err = zap_lookup (&dn, ZFS_ROOT_OBJ, &objnum, data); ++ err = zap_lookup (&dn, ZFS_ROOT_OBJ, &objnum, data, 0); + if (err) + { + grub_dprintf ("zfs", "failed here\n"); +@@ -2391,8 +3271,39 @@ + return; + } + +- info->mtimeset = 1; +- info->mtime = grub_zfs_to_cpu64 (((znode_phys_t *) DN_BONUS (&dn.dn))->zp_mtime[0], dn.endian); ++ if (dn.dn.dn_bonustype == DMU_OT_SA) ++ { ++ void *sahdrp; ++ int hdrsize; ++ ++ if (dn.dn.dn_bonuslen != 0) ++ { ++ sahdrp = (sa_hdr_phys_t *) DN_BONUS (&dn.dn); ++ } ++ else if (dn.dn.dn_flags & DNODE_FLAG_SPILL_BLKPTR) ++ { ++ blkptr_t *bp = &dn.dn.dn_spill; ++ ++ err = zio_read (bp, dn.endian, &sahdrp, NULL, data); ++ if (err) ++ return; ++ } ++ else ++ { ++ grub_error (GRUB_ERR_BAD_FS, "filesystem is corrupt"); ++ return; ++ } ++ ++ hdrsize = SA_HDR_SIZE (((sa_hdr_phys_t *) sahdrp)); ++ info->mtimeset = 1; ++ info->mtime = grub_zfs_to_cpu64 (*(grub_uint64_t *) ((char *) sahdrp + hdrsize + SA_MTIME_OFFSET), dn.endian); ++ } ++ ++ if (dn.dn.dn_bonustype == DMU_OT_ZNODE) ++ { ++ info->mtimeset = 1; ++ info->mtime = grub_zfs_to_cpu64 (((znode_phys_t *) DN_BONUS (&dn.dn))->zp_mtime[0], dn.endian); ++ } + return; + } + +@@ -2403,6 +3314,7 @@ + struct grub_zfs_data *data; + grub_err_t err; + int isfs; ++ int case_insensitive = 0; + auto int NESTED_FUNC_ATTR iterate_zap (const char *name, grub_uint64_t val); + auto int NESTED_FUNC_ATTR iterate_zap_fs (const char *name, + grub_uint64_t val); +@@ -2416,10 +3328,48 @@ + grub_memset (&info, 0, sizeof (info)); + + dnode_get (&(data->mdn), val, 0, &dn, data); +- info.mtimeset = 1; +- info.mtime = grub_zfs_to_cpu64 (((znode_phys_t *) DN_BONUS (&dn.dn))->zp_mtime[0], dn.endian); +- info.dir = (dn.dn.dn_type == DMU_OT_DIRECTORY_CONTENTS); +- grub_dprintf ("zfs", "type=%d, name=%s\n", ++ ++ if (dn.dn.dn_bonustype == DMU_OT_SA) ++ { ++ void *sahdrp; ++ int hdrsize; ++ ++ if (dn.dn.dn_bonuslen != 0) ++ { ++ sahdrp = (sa_hdr_phys_t *) DN_BONUS (&data->dnode.dn); ++ } ++ else if (dn.dn.dn_flags & DNODE_FLAG_SPILL_BLKPTR) ++ { ++ blkptr_t *bp = &dn.dn.dn_spill; ++ ++ err = zio_read (bp, dn.endian, &sahdrp, NULL, data); ++ if (err) ++ { ++ grub_print_error (); ++ return 0; ++ } ++ } ++ else ++ { ++ grub_error (GRUB_ERR_BAD_FS, "filesystem is corrupt"); ++ grub_print_error (); ++ return 0; ++ } ++ ++ hdrsize = SA_HDR_SIZE (((sa_hdr_phys_t *) sahdrp)); ++ info.mtimeset = 1; ++ info.mtime = grub_zfs_to_cpu64 (*(grub_uint64_t *) ((char *) sahdrp + hdrsize + SA_MTIME_OFFSET), dn.endian); ++ info.case_insensitive = case_insensitive; ++ } ++ ++ if (dn.dn.dn_bonustype == DMU_OT_ZNODE) ++ { ++ info.mtimeset = 1; ++ info.mtime = grub_zfs_to_cpu64 (((znode_phys_t *) DN_BONUS (&dn.dn))->zp_mtime[0], ++ dn.endian); ++ } ++ info.dir = (dn.dn.dn_type == DMU_OT_DIRECTORY_CONTENTS); ++ grub_dprintf ("zfs", "type=%d, name=%s\n", + (int)dn.dn.dn_type, (char *)name); + return hook (name, &info); + } +@@ -2464,7 +3414,8 @@ + data = zfs_mount (device); + if (! data) + return grub_errno; +- err = dnode_get_fullpath (path, &(data->mdn), 0, &(data->dnode), &isfs, data); ++ err = dnode_get_fullpath (path, &(data->mdn), 0, &(data->dnode), &isfs, data, ++ &case_insensitive); + if (err) + { + zfs_unmount (data); +@@ -2532,12 +3483,13 @@ + .close = grub_zfs_close, + .label = zfs_label, + .uuid = zfs_uuid, +- .mtime = 0, ++ .mtime = zfs_mtime, + .next = 0 + }; + + GRUB_MOD_INIT (zfs) + { ++ COMPILE_TIME_ASSERT (sizeof (zap_leaf_chunk_t) == ZAP_LEAF_CHUNKSIZE); + grub_fs_register (&grub_zfs_fs); + #ifndef GRUB_UTIL + my_mod = mod; +--- a/include/grub/zfs/zio.h ++++ b/include/grub/zfs/zio.h +@@ -77,7 +77,15 @@ + ZIO_COMPRESS_OFF, + ZIO_COMPRESS_LZJB, + ZIO_COMPRESS_EMPTY, +- ZIO_COMPRESS_GZIP, ++ ZIO_COMPRESS_GZIP1, ++ ZIO_COMPRESS_GZIP2, ++ ZIO_COMPRESS_GZIP3, ++ ZIO_COMPRESS_GZIP4, ++ ZIO_COMPRESS_GZIP5, ++ ZIO_COMPRESS_GZIP6, ++ ZIO_COMPRESS_GZIP7, ++ ZIO_COMPRESS_GZIP8, ++ ZIO_COMPRESS_GZIP9, + ZIO_COMPRESS_FUNCTIONS + }; + +--- a/grub-core/fs/zfs/zfsinfo.c ++++ b/grub-core/fs/zfs/zfsinfo.c +@@ -141,7 +141,6 @@ + } + grub_printf ("Mirror VDEV with %d children\n", nelm); + print_state (nvlist, tab); +- + for (i = 0; i < nelm; i++) + { + char *child; +@@ -161,6 +160,7 @@ + + grub_free (child); + } ++ return GRUB_ERR_NONE; + } + + print_tabs (tab); +--- a/include/grub/zfs/sa_impl.h ++++ b/include/grub/zfs/sa_impl.h +@@ -29,6 +29,9 @@ + } sa_hdr_phys_t; + + #define SA_HDR_SIZE(hdr) BF32_GET_SB(hdr->sa_layout_info, 10, 16, 3, 0) ++#define SA_TYPE_OFFSET 0x0 + #define SA_SIZE_OFFSET 0x8 ++#define SA_MTIME_OFFSET 0x38 ++#define SA_SYMLINK_OFFSET 0xa0 + + #endif /* _SYS_SA_IMPL_H */ +--- a/include/grub/zfs/zfs.h ++++ b/include/grub/zfs/zfs.h +@@ -28,7 +28,7 @@ + /* + * On-disk version number. + */ +-#define SPA_VERSION 28ULL ++#define SPA_VERSION 33ULL + + /* + * The following are configuration names used in the nvlist describing a pool's +@@ -112,12 +112,14 @@ + grub_err_t grub_zfs_getmdnobj (grub_device_t dev, const char *fsfilename, + grub_uint64_t *mdnobj); + +-char *grub_zfs_nvlist_lookup_string (char *nvlist, char *name); +-char *grub_zfs_nvlist_lookup_nvlist (char *nvlist, char *name); +-int grub_zfs_nvlist_lookup_uint64 (char *nvlist, char *name, ++char *grub_zfs_nvlist_lookup_string (const char *nvlist, const char *name); ++char *grub_zfs_nvlist_lookup_nvlist (const char *nvlist, const char *name); ++int grub_zfs_nvlist_lookup_uint64 (const char *nvlist, const char *name, + grub_uint64_t *out); +-char *grub_zfs_nvlist_lookup_nvlist_array (char *nvlist, char *name, ++char *grub_zfs_nvlist_lookup_nvlist_array (const char *nvlist, ++ const char *name, + grub_size_t index); +-int grub_zfs_nvlist_lookup_nvlist_array_get_nelm (char *nvlist, char *name); ++int grub_zfs_nvlist_lookup_nvlist_array_get_nelm (const char *nvlist, ++ const char *name); + + #endif /* ! GRUB_ZFS_HEADER */ |