diff options
author | Richard Yao <ryao@gentoo.org> | 2013-02-03 22:25:47 +0000 |
---|---|---|
committer | Richard Yao <ryao@gentoo.org> | 2013-02-03 22:25:47 +0000 |
commit | 2f6ed3bf18e6b3c19765d75305d99806870ed199 (patch) | |
tree | b199467384058c29d930915ff263b95ae39a3840 /sys-boot | |
parent | add hashcat to license_groups (diff) | |
download | historical-2f6ed3bf18e6b3c19765d75305d99806870ed199.tar.gz historical-2f6ed3bf18e6b3c19765d75305d99806870ed199.tar.bz2 historical-2f6ed3bf18e6b3c19765d75305d99806870ed199.zip |
Add ZFS support for Feature Flags and LZ4 Compression from Illumos GRUB; A big thanks goes to Massimo Maggi for 99.9% of the porting work.
Package-Manager: portage-2.1.11.31/cvs/Linux x86_64
Diffstat (limited to 'sys-boot')
-rw-r--r-- | sys-boot/grub/ChangeLog | 9 | ||||
-rw-r--r-- | sys-boot/grub/Manifest | 24 | ||||
-rw-r--r-- | sys-boot/grub/files/grub-2.00-zfs-feature-flag-support.patch | 1017 | ||||
-rw-r--r-- | sys-boot/grub/grub-2.00-r2.ebuild | 349 |
4 files changed, 1377 insertions, 22 deletions
diff --git a/sys-boot/grub/ChangeLog b/sys-boot/grub/ChangeLog index 947b8f218a25..ef8c70d494df 100644 --- a/sys-boot/grub/ChangeLog +++ b/sys-boot/grub/ChangeLog @@ -1,6 +1,13 @@ # ChangeLog for sys-boot/grub # Copyright 1999-2013 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/sys-boot/grub/ChangeLog,v 1.248 2013/01/19 03:05:28 mattst88 Exp $ +# $Header: /var/cvsroot/gentoo-x86/sys-boot/grub/ChangeLog,v 1.249 2013/02/03 22:25:45 ryao Exp $ + +*grub-2.00-r2 (03 Feb 2013) + + 03 Feb 2013; Richard Yao <ryao@gentoo.org> + +files/grub-2.00-zfs-feature-flag-support.patch, +grub-2.00-r2.ebuild: + Add ZFS support for Feature Flags and LZ4 Compression from Illumos GRUB; A big + thanks goes to Massimo Maggi for 99.9% of the porting work. 19 Jan 2013; Matt Turner <mattst88@gentoo.org> grub-2.00-r1.ebuild: Add yeeloong? ( truetype ) to REQUIRED_USE, bug 452894. diff --git a/sys-boot/grub/Manifest b/sys-boot/grub/Manifest index 09f587ec2687..b504843cc442 100644 --- a/sys-boot/grub/Manifest +++ b/sys-boot/grub/Manifest @@ -1,6 +1,3 @@ ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA256 - AUX 1.99-call_proper_grub_probe.patch 536 SHA256 0e27b4ba6a0deedef2f65822e3b76aea4a817cb7219b01c29c8f682c450bd5e8 SHA512 db4188ed7e5ed3a736580cb17b3a41b984e81d65036254e699a3cba409cfdcbe342341a467c2e01d351800f70ec1b4c61c0fd23c2c4c5fbdf9949a16b43c4d4b WHIRLPOOL eda7dece32b1c3f74227b4f0e53e8846e30f0d56239c512ae17d852fa36825294b314d2c1af8d10807cf345201e31e37762fd556f2c2390ae9de9327129a8df0 AUX 1.99-do_not_stat_so_often.patch 1731 SHA256 a33fdbcab7fa4ad66b26598d9a6f1703f419229058c1e9c9c14edb6272783727 SHA512 66c0e7ea45228b1b58fd842316c35ce708a4fc3170f255165dc90073ea109a7e7f34a0673bca3f8228c392fbd9470cf36984e9e3d9de59c4cd6974ddf05da1b5 WHIRLPOOL bb8e382e4822a03028340092e67ccfc84f5608a4600b329b85c1b325b01d6c0476223e0e102b0948e4ea4cf7cbf310c56468f3c703a72edb5383b8eda30f7f8d AUX 1.99-improve_devmapper.patch 7134 SHA256 b12624944d129820966146d55693b325d48d5d56901727142e386be082661778 SHA512 21d73e2d7f6e065f254a1cc55675e45fe5d1e345f44d8de648395bcd41750324641e84c807839aa06261095ec229a8928290f609d0558d7c897764881305de46 WHIRLPOOL 5e168f740d81e20122acbe1cbfb37cbcb09ba27d1ed2edc537825664107aa416aae5d87ffb96207768a186ba2309e64925a9b9d0f67163fcee7568408e4bac59 @@ -14,6 +11,7 @@ AUX grub-2.00-hardcoded-awk.patch 599 SHA256 438c7357a632c7c9efe406b1d7cbb252469 AUX grub-2.00-no-gets.patch 805 SHA256 054d85619905055a0ea0e5f9d27eb8c8596959598ac9a5bae7e82543c19adeaf SHA512 8b89fa40efe232474e7bb03d12542030d40fea1fe0839a9493f6704fbe6de77516b5976841bf652c7236104513f427750efc668248c71ba0ea7f676557e8c9e3 WHIRLPOOL 796a7bc4583829abd1a552f7d16d6cc4f2999707af1ae0b5231fa53e87ce22a265a35a3d0f486fcac2e74dbed5fd54e3a572186cc2ba1a849433adc021a0a65b AUX grub-2.00-parallel-make.patch 1907 SHA256 7d8eda92eeeeb87001bc44dd1390b96c927c45542af2984c5d80f9ca3a552362 SHA512 cc2c47858ca2fa76b081ca78b6090fe61f0b41d6aad21f07e269dd9f98355b7c148f62659418257c24aa370634060ead2c3a612aae07c6f53e9ba13a25a1d7fc WHIRLPOOL 9b5aad7db3ec5c60151984861690b64e90d6adbeb1dec4257d33873156ae6ce6ded432377520cfb9cbbbbf2f30e69e134d6dbc0007355cfa74521042500d844e AUX grub-2.00-tftp-endian.patch 728 SHA256 4806fb14471fe6547cb69e6fab97e66c8245654acbc4738071cf2717368de458 SHA512 8fee95b06b50f8721d7013ecf8fb954e9b1ba83f99790e165ec334dfcd41fe7655f37868069a315acd4af97d3c4466aa36e0ab5a8b767faf862f1d71f88b3252 WHIRLPOOL 53779e4952049f069824eefcaaaa0e46fc9a7036ed0f9b67008e523f618105d760300ffcd315f861de786c63de02b2753d3ed14637b39fd7af47aadd02355695 +AUX grub-2.00-zfs-feature-flag-support.patch 31186 SHA256 596d509a22d1f3c2bf27864ff285d7ae8e39b3912347163a14afb36812de8605 SHA512 e262f33de0e3ef97c9bcfc294ba40638dd66b369a4a72bcee42c2d5aafa223eec96b1ed841b97c09b40db798dec38504397ad6000eb3b98eb8b29457e0dfefa3 WHIRLPOOL 70314defe1fc0704a2e3ff2579916a8a206b9437517096b3b1129991dd3364a994991f6bed0d5ace51b78c9ba469afeb4de88d445600783c91456a1278c9ac23 AUX grub.conf.gentoo 627 SHA256 914b15af252210a32776196437cd8013e10e57d5780e66877ef3fe9a2b4b9776 SHA512 5ee586c151b025a153867d2854b73e2e18a6af38e9d65069b7114a55af776803ba947b4901b0806e79fa8f36aeac90daad608b9ec2a4a8526301d1beb36e4ef3 WHIRLPOOL fcaef85cd7c2c446c882874cf4ec8a2241d1fc97720973a0a0cd1add259da599d4dae4d0b429ba2dff0307ed2d4598d5939cbc1b11127a0dedb3a54249ec9f81 AUX grub.default 1254 SHA256 181bdb7433ebcbde635e7058a1febaf0100e4e9c83ea4fd222d7010c375882d8 SHA512 1cdce5d9c606a2cba29ec859df96de9e8c292301ee3f26dff848816cda950088c0660dbd3401eec97b15841a2544116664eeda6cb0be753f6d160a7e62578dbc WHIRLPOOL 03514e95078f4f4d176e85ba3a739105a7cbf58a6c3e2ba4a2c660c48329dcc78b968391ecb2d9821084ba4ddddbe03e41d9d6c36685f1db1d4a1f00a1e5d393 AUX grub.default-2 1470 SHA256 fcef668c1316a38f6a1c784c489c2052b23b8e2b79dc1a940b5bda831947af74 SHA512 5c331323ef17683fdfc59b0057a6e89a451039febc4ff6242c17cd3aeda0ef60930a79dc52e180bf534f94867a8b4545655808ae5a7362643542fea42b6a0d91 WHIRLPOOL 5f8a1192763ee9089e48a7eff13ef75947e7f4db20ff873ae86fd99920b107de827588558bdc26d2bf5ee3da4f51a44d53470aa65bf73ab565cf23e84097de5c @@ -58,24 +56,8 @@ EBUILD grub-0.97-r9.ebuild 9053 SHA256 b6411eb5c379cc6b9120f1f727733d9724c425740 EBUILD grub-0.97.ebuild 4238 SHA256 d93dd5dca80c822e0659007b827966fb69c7f702b13ba672b4c3f486af54cee1 SHA512 46d72cfaa5735d0b3d2d89a8e6ce83745e4645370cdbbfcffc37d1413ffeb2b1caafac8c7cc712925ffc09411870b06467eb50bc475997508e7beea8fa5172d7 WHIRLPOOL 4b6fe9a7300baf6364555858a49ae2775ea0da27291d5d48fa634097531ae3b6da445ee2f959ef584bf4c913aad5e689b77e7326af257549ef107704dc0d202e EBUILD grub-1.99-r2.ebuild 8413 SHA256 13a1281843b801804a5f2dc491cd21d6ac4d068c59e739015dc949a51011f585 SHA512 520bd623cfaf70451b4331f2dc464982f4de1b0c070ee8c0b336c9d16589aaa96924ea923f4c47ccb07d3c8f6da987a89ed285f1f4fa8f922465ab912e8940bd WHIRLPOOL 5abb91bf54a5024b225e7c3891b884827b31e6e8e380db9aa37fd520c55cd2e94ce1e7545271d52a58baab63446906cb69440177a4678000ac519088b9ae6966 EBUILD grub-2.00-r1.ebuild 8862 SHA256 c88e12c0de910726920616a0fb9fecd1dab504532287d9742015faab713268ab SHA512 2589fb92dee5d6a25af6a9584ccb45c6b019d219fde0c3dbde1e35abc8a82e7ce8793375e694c30372ea98da9e7383db98b6639c8ee93d23dfb0b9cb6f0cc838 WHIRLPOOL 06f3d43667856a0d6c2fe6ebf3b89930171f047e66ed9df5d766b8851b9bb5ae0db7f72a6d319d16db18a1968b6a4d6c4bcf1b8532df168141bb9c9f0733d24a +EBUILD grub-2.00-r2.ebuild 8660 SHA256 57a179459aa89ac6696254e684ce172fe096e2591be2350d9a582610a3aab0e8 SHA512 7cb7fe40fc1645fbae7f752df93cf8e22bad5c3e354133b5e868b6ee614f66463a0d9cf415779cda58161f4323c0f76fd1d1058e58d9368d376c82839a4b66c9 WHIRLPOOL 48ec38fb5e39b0f6366c452e2000695d0e7fa911c088a03a2723d187f30d373fba14e717e106a51ff1772c6f11fecca8c484e2137b116396d6f79dd4923589fe EBUILD grub-2.00_beta6.ebuild 7140 SHA256 8026d9d32d21863e5427cac5b641fbc5f799662437bd9a40daa3f9a377a0de68 SHA512 35b5a7aa5224ba1f0d3dabaeb03d915b86a3c16419f6ef012c8092b198e8bbc054f22e4658930f704402066622b98c67c869f0c9cf5d74637c34ae786b0861fa WHIRLPOOL 54839cae4be956d12f8c62524923e9087f76c5e2c3c7db7cca074084deba71cd870238e514227a73a1131748fac501566afe29866231b68e4bbddbf2b465a71b EBUILD grub-9999.ebuild 8605 SHA256 506e79cb8de178641162809a15b2656d771af197cb8bc4dbe83754ac99234cdb SHA512 3dcda4d909ab6f37e9e9db5951d4bad076b42e6a38a5e28431b7e5cd801c2c3e569966a5a16ce6031acec03a05005ac8dee1c5a12305fac88e38c3554afa68b8 WHIRLPOOL da73ca55e91e5e303e5f0254197722a0ff05ef223d5fc70305d6d215ef36879232350734b7c92851608989ae97d4e3c71bedb6e64557f2b93b98ac47655483f2 -MISC ChangeLog 47994 SHA256 5fb06c22be33a848e45486ebc76bc721408d0c579ab79be25bb2d34cbb85db30 SHA512 422357ed4c73f7694894f3a8957cc389272ce9347eef073412dad21a2ceab5f0873552cda929097cbf82060a8521d15d16f6f16bf647a6109e14f61121d7cfee WHIRLPOOL f82f27ad6587a2e18b6855182d79044a6c3c1f5f3a15cd305283327ec58f811f7d7ce85fdcb03debdb96e8b7e0bd07447fc411658bcac6deda69896c42727ed3 +MISC ChangeLog 48281 SHA256 b05c7349902d788e5a1bbaf9f535796318c34ead476448451a86e243d435d39c SHA512 7f5b9c34eb35b6e0f07dec2c21d7bbe9b026c23d97741d68d7da0253d08139f9ada9a9f6e4ddc2634982f842a22d85195ea6ebfcda130121b7be56d69affe7e8 WHIRLPOOL 19e5b2c2324c8fcf19cbd025cc5dc5563d25cd127d80d53b27a5349759898c6e04a0186d6e3e7d75d6e2a860c754119581cd73197b7eca1488fce9ad34fdb369 MISC metadata.xml 673 SHA256 e14e5e46b726a3645b85217a2afbd5b04adb54990c7db837e01a50a8322d81b9 SHA512 9df3d519f0aa3e53304c956638acb927224f3ca83ba1959f089852ee7c822ca3cae99d3da0efcbfeedd99dbe630aa0b39d6f9b61d0cad8e72c155f7253c7d8cc WHIRLPOOL ed7bc1f5c8f84ef6fb18143163f239d9f47e8fd88c3fd521f625b2191349d7520bf4c6a7e6c7e3eef73a0af43faa6814e591c983cc29298bf88e7c42df3c69d2 ------BEGIN PGP SIGNATURE----- -Version: GnuPG v2.0.19 (GNU/Linux) - -iQIcBAEBCAAGBQJQ+g4mAAoJEA/daC2XTKcqKp4P/jmm8IBlfA29qXOtcDZbZ0dw -zp18UVEzhb1P3vFrZN5WF9+EEF9HZwdGfp1P/0nw6Q3JF35t2QXgHcSror/oeYlw -H0kvZK29BJzB6N/8tsuiYUjqf6R1gaZCYOt2rPJWMudrvVpdsLGp4146DPONrhTx -Bhrxjhm+j2Yvw/brenZzHqidAwh/05oPCvqiXmmqa4Gxx/NARz49iszH07pRWc13 -RjQXvazj/u/Y5WgP+neiw7Pq7IPsyXHT0ezJGu22yNCfWjHzkHJAQ4b6Z7ejeZOC -TrEN/3FT3nBIrGEu/cY7lkXjTmgUNgn0XWZV49gxcmTfQhInduwne3nzwiqHBXX1 -qgnahkEwjLmhotgDB7OffdpCvR5OMlRAQvOE/BSxZS4ognBlL4C510oAM6vyFFWI -IUE0i9/a51xRBOZp2gYAkXs0lX6sLt6bhKuHP+Igs/tzuPb9k6d5wVJcJZEEI4lG -IGTg/7ZgN4u8FDc2/gLfJ/dYIdAzkvtTFJViCAgkDG+qQJ4iUtrEqe5dwakfqP1b -16cR/Bj0Xt5VSSzkqDDjSNrydrNurOrkLKE3aCl2C+7mNMy+ktwLhPzjr8w1DHrr -pL9jkZcrBTktr6aL9A+dIiagt23/OLuRz5EWlnAfONiGUPXCAayr7INp17wNFPzu -TRwq8UxegEn8YrRkZ43e -=WAKM ------END PGP SIGNATURE----- diff --git a/sys-boot/grub/files/grub-2.00-zfs-feature-flag-support.patch b/sys-boot/grub/files/grub-2.00-zfs-feature-flag-support.patch new file mode 100644 index 000000000000..998dc0733683 --- /dev/null +++ b/sys-boot/grub/files/grub-2.00-zfs-feature-flag-support.patch @@ -0,0 +1,1017 @@ +ZFS Feature Flag Support + +This is a monolithic version of the following commits: + +https://github.com/maxximino/grub2/commit/31a32560fd7948ae5ff5c63105d7c068de7890c8 +https://github.com/maxximino/grub2/commit/595d76e8ca0690a963f5533689de8db54ef07e75 +https://github.com/maxximino/grub2/commit/58344034e40218b20500fa2936eb4d7d019e1e88 +https://github.com/maxximino/grub2/commit/f98cb078abab2c14bb0766b5a0ceb055683dab81 +https://github.com/maxximino/grub2/commit/f12806f43a969a654dee7bb89b2e8fd5c42f0e2e + +A minor change was made to account for d8a0feb6 from upstream. This change +prevents a compile time failure that is caused by a change in the callback +interface used by mzap_interate(). + +The initial feature flag support patches were written by Delphix while the LZ4 +support was written by Saso Kiselkov. The work porting this to GRUB2 was done +by Massimo Maggi, while the adaption to Gentoo's GRUB2 package was done by +Richard Yao. + +diff --git a/Makefile.util.def b/Makefile.util.def +index b80187c..1bf3038 100644 +--- a/Makefile.util.def ++++ b/Makefile.util.def +@@ -95,6 +95,7 @@ library = { + common = grub-core/fs/zfs/zfs.c; + common = grub-core/fs/zfs/zfsinfo.c; + common = grub-core/fs/zfs/zfs_lzjb.c; ++ common = grub-core/fs/zfs/zfs_lz4.c; + common = grub-core/fs/zfs/zfs_sha256.c; + common = grub-core/fs/zfs/zfs_fletcher.c; + common = grub-core/lib/envblk.c; +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 39e77a4..1550b90 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1186,6 +1186,7 @@ module = { + name = zfs; + common = fs/zfs/zfs.c; + common = fs/zfs/zfs_lzjb.c; ++ common = fs/zfs/zfs_lz4.c; + common = fs/zfs/zfs_sha256.c; + common = fs/zfs/zfs_fletcher.c; + }; +diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c +index ba0554a..de31e6c 100644 +--- a/grub-core/fs/zfs/zfs.c ++++ b/grub-core/fs/zfs/zfs.c +@@ -2,6 +2,7 @@ + * GRUB -- GRand Unified Bootloader + * Copyright (C) 1999,2000,2001,2002,2003,2004,2009,2010,2011 Free Software Foundation, Inc. + * Copyright 2010 Sun Microsystems, Inc. ++ * Copyright (c) 2012 by Delphix. All rights reserved. + * + * GRUB is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by +@@ -153,11 +154,13 @@ ZAP_LEAF_ENTRY(zap_leaf_phys_t *l, int bs, int idx) + + + /* +- * Decompression Entry - lzjb ++ * Decompression Entry - lzjb & lz4 + */ + + extern grub_err_t lzjb_decompress (void *, void *, grub_size_t, grub_size_t); + ++extern grub_err_t lz4_decompress (void *, void *, grub_size_t, grub_size_t); ++ + typedef grub_err_t zfs_decomp_func_t (void *s_start, void *d_start, + grub_size_t s_len, grub_size_t d_len); + typedef struct decomp_entry +@@ -263,6 +266,19 @@ grub_crypto_cipher_handle_t (*grub_zfs_load_key) (const struct grub_zfs_key *key + grub_size_t keysize, + grub_uint64_t salt, + grub_uint64_t algo) = NULL; ++/* ++ * List of pool features that the grub implementation of ZFS supports for ++ * read. Note that features that are only required for write do not need ++ * to be listed here since grub opens pools in read-only mode. ++ */ ++static const char *spa_feature_names[] = { ++ "org.illumos:lz4_compress",NULL ++}; ++ ++static int ++check_feature(const char *name, grub_uint64_t val); ++static int ++check_mos_features(dnode_phys_t *mosmdn_phys,grub_zfs_endian_t endian,struct grub_zfs_data* data ); + + static grub_err_t + zlib_decompress (void *s, void *d, +@@ -322,6 +338,7 @@ static decomp_entry_t decomp_table[ZIO_COMPRESS_FUNCTIONS] = { + {"gzip-8", zlib_decompress}, /* ZIO_COMPRESS_GZIP8 */ + {"gzip-9", zlib_decompress}, /* ZIO_COMPRESS_GZIP9 */ + {"zle", zle_decompress}, /* ZIO_COMPRESS_ZLE */ ++ {"lz4", lz4_decompress}, /* ZIO_COMPRESS_LZ4 */ + }; + + static grub_err_t zio_read_data (blkptr_t * bp, grub_zfs_endian_t endian, +@@ -482,15 +499,11 @@ uberblock_verify (uberblock_phys_t * ub, grub_uint64_t offset, + + if (grub_zfs_to_cpu64 (uber->ub_magic, GRUB_ZFS_LITTLE_ENDIAN) + == UBERBLOCK_MAGIC +- && grub_zfs_to_cpu64 (uber->ub_version, GRUB_ZFS_LITTLE_ENDIAN) > 0 +- && grub_zfs_to_cpu64 (uber->ub_version, GRUB_ZFS_LITTLE_ENDIAN) +- <= SPA_VERSION) +- endian = GRUB_ZFS_LITTLE_ENDIAN; ++ && SPA_VERSION_IS_SUPPORTED(grub_zfs_to_cpu64 (uber->ub_version, GRUB_ZFS_LITTLE_ENDIAN))) ++ endian = GRUB_ZFS_LITTLE_ENDIAN; + + if (grub_zfs_to_cpu64 (uber->ub_magic, GRUB_ZFS_BIG_ENDIAN) == UBERBLOCK_MAGIC +- && grub_zfs_to_cpu64 (uber->ub_version, GRUB_ZFS_BIG_ENDIAN) > 0 +- && grub_zfs_to_cpu64 (uber->ub_version, GRUB_ZFS_BIG_ENDIAN) +- <= SPA_VERSION) ++ && SPA_VERSION_IS_SUPPORTED(grub_zfs_to_cpu64 (uber->ub_version, GRUB_ZFS_BIG_ENDIAN))) + endian = GRUB_ZFS_BIG_ENDIAN; + + if (endian == GRUB_ZFS_UNKNOWN_ENDIAN) +@@ -764,6 +777,155 @@ fill_vdev_info (struct grub_zfs_data *data, + } + + /* ++ * For a given XDR packed nvlist, verify the first 4 bytes and move on. ++ * ++ * An XDR packed nvlist is encoded as (comments from nvs_xdr_create) : ++ * ++ * encoding method/host endian (4 bytes) ++ * nvl_version (4 bytes) ++ * nvl_nvflag (4 bytes) ++ * encoded nvpairs: ++ * encoded size of the nvpair (4 bytes) ++ * decoded size of the nvpair (4 bytes) ++ * name string size (4 bytes) ++ * name string data (sizeof(NV_ALIGN4(string)) ++ * data type (4 bytes) ++ * # of elements in the nvpair (4 bytes) ++ * data ++ * 2 zero's for the last nvpair ++ * (end of the entire list) (8 bytes) ++ * ++ */ ++ ++/* ++ * The nvlist_next_nvpair() function returns a handle to the next nvpair in the ++ * list following nvpair. If nvpair is NULL, the first pair is returned. If ++ * nvpair is the last pair in the nvlist, NULL is returned. ++ */ ++static const char * ++nvlist_next_nvpair(const char *nvl, const char *nvpair) ++{ ++ const char *nvp; ++ int encode_size; ++ int name_len; ++ if (nvl == NULL) ++ return (NULL); ++ ++ if (nvpair == NULL) { ++ /* skip over header, nvl_version and nvl_nvflag */ ++ nvpair = nvl + 4 * 3; ++ } else { ++ /* skip to the next nvpair */ ++ encode_size = grub_be_to_cpu32 (grub_get_unaligned32(nvpair)); ++ nvpair += encode_size; ++ } ++ /* 8 bytes of 0 marks the end of the list */ ++ if (*(grub_uint64_t*)nvpair == 0) ++ return (NULL); ++ /*consistency checks*/ ++ if (nvpair + 4 * 3 >= nvl + VDEV_PHYS_SIZE) ++ { ++ grub_dprintf ("zfs", "nvlist overflow\n"); ++ grub_error (GRUB_ERR_BAD_FS, "incorrect nvlist"); ++ return (NULL); ++ } ++ encode_size = grub_be_to_cpu32 (grub_get_unaligned32(nvpair)); ++ ++ nvp = nvpair + 4*2; ++ name_len = grub_be_to_cpu32 (grub_get_unaligned32 (nvp)); ++ nvp += 4; ++ ++ nvp = nvp + ((name_len + 3) & ~3); // align ++ if (nvp + 4 >= nvl + VDEV_PHYS_SIZE ++ || encode_size < 0 ++ || nvp + 4 + encode_size > nvl + VDEV_PHYS_SIZE) ++ { ++ grub_dprintf ("zfs", "nvlist overflow\n"); ++ grub_error (GRUB_ERR_BAD_FS, "incorrect nvlist"); ++ return (NULL); ++ } ++ /* end consistency checks */ ++ ++ return (nvpair); ++} ++/* ++ * This function returns 0 on success and 1 on failure. On success, a string ++ * containing the name of nvpair is saved in buf. ++ */ ++static int ++nvpair_name(const char *nvp, char **buf, int* buflen) ++{ ++ int len; ++ ++ /* skip over encode/decode size */ ++ nvp += 4 * 2; ++ ++ len = grub_be_to_cpu32 (grub_get_unaligned32 (nvp)); ++ nvp=nvp+4; ++ ++ *buf=(char*)nvp; ++ *buflen=len; ++ ++ return (0); ++} ++/* ++ * This function retrieves the value of the nvpair in the form of enumerated ++ * type data_type_t. ++ */ ++static int ++nvpair_type(const char *nvp) ++{ ++ int name_len, type; ++ ++ /* skip over encode/decode size */ ++ nvp += 4 * 2; ++ ++ /* skip over name_len */ ++ name_len = grub_be_to_cpu32 (grub_get_unaligned32 (nvp)); ++ nvp += 4; ++ ++ /* skip over name */ ++ nvp = nvp + ((name_len + 3) & ~3); /* align */ ++ ++ type = grub_be_to_cpu32 (grub_get_unaligned32 (nvp)); ++ ++ return (type); ++} ++static int ++nvpair_value(const char *nvp,char **val, ++ grub_size_t *size_out, grub_size_t *nelm_out) ++{ ++ int name_len,nelm,encode_size; ++ ++ /* skip over encode/decode size */ ++ encode_size = grub_be_to_cpu32 (grub_get_unaligned32(nvp)); ++ nvp += 8; ++ ++ /* skip over name_len */ ++ name_len = grub_be_to_cpu32 (grub_get_unaligned32 (nvp)); ++ nvp += 4; ++ ++ /* skip over name */ ++ nvp = nvp + ((name_len + 3) & ~3); /* align */ ++ ++ /* skip over type */ ++ nvp += 4; ++ nelm = grub_be_to_cpu32 (grub_get_unaligned32 (nvp)); ++ nvp +=4; ++ if (nelm < 1) ++ { ++ grub_error (GRUB_ERR_BAD_FS, "empty nvpair"); ++ return 0; ++ } ++ *val = (char *) nvp; ++ *size_out = encode_size; ++ if (nelm_out) ++ *nelm_out = nelm; ++ ++ return 1; ++} ++ ++/* + * Check the disk label information and retrieve needed vdev name-value pairs. + * + */ +@@ -773,7 +935,7 @@ check_pool_label (struct grub_zfs_data *data, + int *inserted) + { + grub_uint64_t pool_state, txg = 0; +- char *nvlist; ++ char *nvlist,*features; + #if 0 + char *nv; + #endif +@@ -837,13 +999,13 @@ check_pool_label (struct grub_zfs_data *data, + } + grub_dprintf ("zfs", "check 8 passed\n"); + +- if (version > SPA_VERSION) ++ if (!SPA_VERSION_IS_SUPPORTED(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); ++ (unsigned long long) SPA_VERSION_BEFORE_FEATURES); + } + grub_dprintf ("zfs", "check 9 passed\n"); + +@@ -893,7 +1055,30 @@ check_pool_label (struct grub_zfs_data *data, + grub_free (nv); + } + grub_dprintf ("zfs", "check 10 passed\n"); +- ++ if ((features=grub_zfs_nvlist_lookup_nvlist(nvlist, ZPOOL_CONFIG_FEATURES_FOR_READ))) ++ { ++ const char *nvp=NULL; ++ char *name = grub_zalloc(51); ++ char *nameptr; ++ int namelen; ++ while ((nvp = nvlist_next_nvpair(features, nvp)) != NULL) ++ { ++ nvpair_name(nvp, &nameptr,&namelen); ++ if(namelen > 50){namelen=50;} ++ grub_strncpy(name,nameptr,namelen); ++ name[namelen]=0; ++ grub_dprintf("zfs","namelen=%u str=%s\n",namelen,name); ++ if (check_feature(name,1) != 0) ++ { ++ grub_dprintf("zfs","feature missing in check_pool_label:%s\n",name); ++ err= grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET," check_pool_label missing feature '%s' for read",name); ++ grub_free(name); ++ return err; ++ } ++ } ++ grub_free(name); ++ } ++ grub_dprintf ("zfs", "check 12 passed (feature flags)\n"); + grub_free (nvlist); + + return GRUB_ERR_NONE; +@@ -3034,34 +3219,14 @@ dnode_get_fullpath (const char *fullpath, struct subvolume *subvol, + return err; + } + +-/* +- * For a given XDR packed nvlist, verify the first 4 bytes and move on. +- * +- * An XDR packed nvlist is encoded as (comments from nvs_xdr_create) : +- * +- * encoding method/host endian (4 bytes) +- * nvl_version (4 bytes) +- * nvl_nvflag (4 bytes) +- * encoded nvpairs: +- * encoded size of the nvpair (4 bytes) +- * decoded size of the nvpair (4 bytes) +- * name string size (4 bytes) +- * name string data (sizeof(NV_ALIGN4(string)) +- * data type (4 bytes) +- * # of elements in the nvpair (4 bytes) +- * data +- * 2 zero's for the last nvpair +- * (end of the entire list) (8 bytes) +- * +- */ +- + static int + nvlist_find_value (const char *nvlist_in, const char *name, + int valtype, char **val, + grub_size_t *size_out, grub_size_t *nelm_out) + { +- int name_len, type, encode_size; +- const char *nvpair, *nvp_name, *nvlist = nvlist_in; ++ int name_len, type ; ++ const char *nvpair=NULL,*nvlist=nvlist_in; ++ char *nvp_name; + + /* Verify if the 1st and 2nd byte in the nvlist are valid. */ + /* NOTE: independently of what endianness header announces all +@@ -3074,62 +3239,18 @@ nvlist_find_value (const char *nvlist_in, const char *name, + return 0; + } + +- /* skip the header, nvl_version, and nvl_nvflag */ +- nvlist = nvlist + 4 * 3; + /* + * Loop thru the nvpair list + * The XDR representation of an integer is in big-endian byte order. + */ +- while ((encode_size = grub_be_to_cpu32 (grub_get_unaligned32 (nvlist)))) ++ while ((nvpair=nvlist_next_nvpair(nvlist,nvpair))) + { +- int nelm; +- +- if (nvlist + 4 * 4 >= nvlist_in + VDEV_PHYS_SIZE) +- { +- grub_dprintf ("zfs", "nvlist overflow\n"); +- grub_error (GRUB_ERR_BAD_FS, "incorrect nvlist"); +- return 0; +- } +- +- nvpair = nvlist + 4 * 2; /* skip the encode/decode size */ +- +- name_len = grub_be_to_cpu32 (grub_get_unaligned32 (nvpair)); +- nvpair += 4; +- +- nvp_name = nvpair; +- nvpair = nvpair + ((name_len + 3) & ~3); /* align */ +- +- if (nvpair + 8 >= nvlist_in + VDEV_PHYS_SIZE +- || encode_size < 0 +- || nvpair + 8 + encode_size > nvlist_in + VDEV_PHYS_SIZE) ++ nvpair_name(nvpair,&nvp_name,&name_len); ++ type = nvpair_type(nvpair); ++ if ((grub_strncmp (nvp_name, name, grub_strlen(name)) == 0) && type == valtype) + { +- grub_dprintf ("zfs", "nvlist overflow\n"); +- grub_error (GRUB_ERR_BAD_FS, "incorrect nvlist"); +- return 0; ++ return nvpair_value(nvpair,val,size_out,nelm_out); + } +- +- type = grub_be_to_cpu32 (grub_get_unaligned32 (nvpair)); +- nvpair += 4; +- +- nelm = grub_be_to_cpu32 (grub_get_unaligned32 (nvpair)); +- if (nelm < 1) +- { +- grub_error (GRUB_ERR_BAD_FS, "empty nvpair"); +- return 0; +- } +- +- nvpair += 4; +- +- if ((grub_strncmp (nvp_name, name, name_len) == 0) && type == valtype) +- { +- *val = (char *) nvpair; +- *size_out = encode_size; +- if (nelm_out) +- *nelm_out = nelm; +- return 1; +- } +- +- nvlist += encode_size; /* goto the next nvpair */ + } + return 0; + } +@@ -3386,6 +3507,10 @@ zfs_mount (grub_device_t dev) + return NULL; + } + ++ if (ub->ub_version >= SPA_VERSION_FEATURES && ++ check_mos_features(&((objset_phys_t *) osp)->os_meta_dnode,ub_endian, data) != 0) ++ return NULL; ++ + /* Got the MOS. Save it at the memory addr MOS. */ + grub_memmove (&(data->mos.dn), &((objset_phys_t *) osp)->os_meta_dnode, + DNODE_SIZE); +@@ -3910,6 +4035,64 @@ grub_zfs_dir (grub_device_t device, const char *path, + return grub_errno; + } + ++static int ++check_feature(const char *name, grub_uint64_t val) ++{ ++ int i; ++ if(val ==0) return 0; ++ if(*name==0) return 0; ++ for (i = 0; spa_feature_names[i] != NULL; i++) ++ { ++ if (grub_strcmp(name, spa_feature_names[i]) == 0) ++ return 0; ++ } ++ grub_printf("missing feature for read '%s'\n",name); ++ return 1; ++} ++ ++/* ++ * Checks whether the MOS features that are active are supported by this ++ * (GRUB's) implementation of ZFS. ++ * ++ * Return: ++ * 0: Success. ++ * errnum: Failure. ++ */ ++ ++static int ++check_mos_features(dnode_phys_t *mosmdn_phys,grub_zfs_endian_t endian,struct grub_zfs_data* data ) ++{ ++ grub_uint64_t objnum; ++ grub_uint8_t errnum = 0; ++ dnode_end_t dn,mosmdn; ++ mzap_phys_t* mzp; ++ grub_zfs_endian_t endianzap; ++ int size; ++ grub_memmove(&(mosmdn.dn),mosmdn_phys,sizeof(dnode_phys_t)); ++ mosmdn.endian=endian; ++ if ((errnum = dnode_get(&mosmdn, DMU_POOL_DIRECTORY_OBJECT, ++ DMU_OT_OBJECT_DIRECTORY, &dn,data)) != 0) ++ return (errnum); ++ ++ /* ++ * Find the object number for 'features_for_read' and retrieve its ++ * corresponding dnode. Note that we don't check features_for_write ++ * because GRUB is not opening the pool for write. ++ */ ++ if ((errnum = zap_lookup(&dn, DMU_POOL_FEATURES_FOR_READ, &objnum, data,0)) != 0) ++ return (errnum); ++ ++ if ((errnum = dnode_get(&mosmdn, objnum, DMU_OTN_ZAP_METADATA, &dn, data)) != 0) ++ return (errnum); ++ ++ if ((errnum = dmu_read(&dn, 0, (void**)&mzp, &endianzap,data)) != 0) ++ return (errnum); ++ ++ size = grub_zfs_to_cpu16 (dn.dn.dn_datablkszsec, dn.endian) << SPA_MINBLOCKSHIFT; ++ return (mzap_iterate(mzp,endianzap, size, check_feature)); ++} ++ ++ + #ifdef GRUB_UTIL + static grub_err_t + grub_zfs_embed (grub_device_t device __attribute__ ((unused)), +diff --git a/grub-core/fs/zfs/zfs_lz4.c b/grub-core/fs/zfs/zfs_lz4.c +new file mode 100644 +index 0000000..f199434 +--- /dev/null ++++ b/grub-core/fs/zfs/zfs_lz4.c +@@ -0,0 +1,321 @@ ++/* ++ * LZ4 - Fast LZ compression algorithm ++ * Header File ++ * Copyright (C) 2011-2013, Yann Collet. ++ * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) ++ * ++ * Redistribution and use in source and binary forms, with or without ++ * modification, are permitted provided that the following conditions are ++ * met: ++ * ++ * * Redistributions of source code must retain the above copyright ++ * notice, this list of conditions and the following disclaimer. ++ * * Redistributions in binary form must reproduce the above ++ * copyright notice, this list of conditions and the following disclaimer ++ * in the documentation and/or other materials provided with the ++ * distribution. ++ * ++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ++ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ++ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ++ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ++ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ++ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ++ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ++ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ++ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ++ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ++ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ++ * ++ * You can contact the author at : ++ * - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html ++ * - LZ4 source repository : http://code.google.com/p/lz4/ ++ */ ++ ++#include <grub/err.h> ++#include <grub/mm.h> ++#include <grub/misc.h> ++#include <grub/types.h> ++ ++static int LZ4_uncompress_unknownOutputSize(const char *source, char *dest, ++ int isize, int maxOutputSize); ++ ++/* ++ * CPU Feature Detection ++ */ ++ ++/* 32 or 64 bits ? */ ++#if (defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || \ ++ defined(__amd64) || defined(__ppc64__) || defined(_WIN64) || \ ++ defined(__LP64__) || defined(_LP64)) ++#define LZ4_ARCH64 1 ++#else ++#define LZ4_ARCH64 0 ++#endif ++ ++/* ++ * Little Endian or Big Endian? ++ * Note: overwrite the below #define if you know your architecture endianess. ++ */ ++#if (defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN) || \ ++ defined(_BIG_ENDIAN) || defined(_ARCH_PPC) || defined(__PPC__) || \ ++ defined(__PPC) || defined(PPC) || defined(__powerpc__) || \ ++ defined(__powerpc) || defined(powerpc) || \ ++ ((defined(__BYTE_ORDER__)&&(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)))) ++#define LZ4_BIG_ENDIAN 1 ++#else ++ /* ++ * Little Endian assumed. PDP Endian and other very rare endian format ++ * are unsupported. ++ */ ++#endif ++ ++/* ++ * Compiler Options ++ */ ++ ++#if __STDC_VERSION__ >= 199901L /* C99 */ ++/* "restrict" is a known keyword */ ++#else ++/* Disable restrict */ ++#ifndef restrict ++#define restrict /* Only if somebody already didn't take care of that.*/ ++#endif ++#endif ++ ++#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) ++ ++#define lz4_bswap16(x) ((unsigned short int) ((((x) >> 8) & 0xffu) \ ++ | (((x) & 0xffu) << 8))) ++ ++#if (GCC_VERSION >= 302) || (__INTEL_COMPILER >= 800) || defined(__clang__) ++#define expect(expr, value) (__builtin_expect((expr), (value))) ++#else ++#define expect(expr, value) (expr) ++#endif ++ ++#define likely(expr) expect((expr) != 0, 1) ++#define unlikely(expr) expect((expr) != 0, 0) ++ ++/* Basic types */ ++#define BYTE grub_uint8_t ++#define U16 grub_uint16_t ++#define U32 grub_uint32_t ++#define S32 grub_int32_t ++#define U64 grub_uint64_t ++typedef grub_size_t size_t; ++ ++typedef struct _U16_S { ++ U16 v; ++} U16_S; ++typedef struct _U32_S { ++ U32 v; ++} U32_S; ++typedef struct _U64_S { ++ U64 v; ++} U64_S; ++ ++#define A64(x) (((U64_S *)(x))->v) ++#define A32(x) (((U32_S *)(x))->v) ++#define A16(x) (((U16_S *)(x))->v) ++ ++/* ++ * Constants ++ */ ++#define MINMATCH 4 ++ ++#define COPYLENGTH 8 ++#define LASTLITERALS 5 ++ ++#define ML_BITS 4 ++#define ML_MASK ((1U<<ML_BITS)-1) ++#define RUN_BITS (8-ML_BITS) ++#define RUN_MASK ((1U<<RUN_BITS)-1) ++ ++/* ++ * Architecture-specific macros ++ */ ++#if LZ4_ARCH64 ++#define STEPSIZE 8 ++#define UARCH U64 ++#define AARCH A64 ++#define LZ4_COPYSTEP(s, d) A64(d) = A64(s); d += 8; s += 8; ++#define LZ4_COPYPACKET(s, d) LZ4_COPYSTEP(s, d) ++#define LZ4_SECURECOPY(s, d, e) if (d < e) LZ4_WILDCOPY(s, d, e) ++#define HTYPE U32 ++#define INITBASE(base) const BYTE* const base = ip ++#else ++#define STEPSIZE 4 ++#define UARCH U32 ++#define AARCH A32 ++#define LZ4_COPYSTEP(s, d) A32(d) = A32(s); d += 4; s += 4; ++#define LZ4_COPYPACKET(s, d) LZ4_COPYSTEP(s, d); LZ4_COPYSTEP(s, d); ++#define LZ4_SECURECOPY LZ4_WILDCOPY ++#define HTYPE const BYTE* ++#define INITBASE(base) const int base = 0 ++#endif ++ ++#if (defined(LZ4_BIG_ENDIAN) && !defined(BIG_ENDIAN_NATIVE_BUT_INCOMPATIBLE)) ++#define LZ4_READ_LITTLEENDIAN_16(d, s, p) \ ++ { U16 v = A16(p); v = lz4_bswap16(v); d = (s) - v; } ++#define LZ4_WRITE_LITTLEENDIAN_16(p, i) \ ++ { U16 v = (U16)(i); v = lz4_bswap16(v); A16(p) = v; p += 2; } ++#else ++#define LZ4_READ_LITTLEENDIAN_16(d, s, p) { d = (s) - A16(p); } ++#define LZ4_WRITE_LITTLEENDIAN_16(p, v) { A16(p) = v; p += 2; } ++#endif ++ ++/* Macros */ ++#define LZ4_WILDCOPY(s, d, e) do { LZ4_COPYPACKET(s, d) } while (d < e); ++ ++/* Decompression functions */ ++grub_err_t ++lz4_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len); ++ ++grub_err_t ++lz4_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len) ++{ ++ const BYTE *src = s_start; ++ U32 bufsiz = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | ++ src[3]; ++ ++ /* invalid compressed buffer size encoded at start */ ++ if (bufsiz + 4 > s_len) ++ return grub_error(GRUB_ERR_BAD_FS,"lz4 decompression failed."); ++ ++ /* ++ * Returns 0 on success (decompression function returned non-negative) ++ * and appropriate error on failure (decompression function returned negative). ++ */ ++ return (LZ4_uncompress_unknownOutputSize((char*)s_start + 4, d_start, bufsiz, ++ d_len) < 0)?grub_error(GRUB_ERR_BAD_FS,"lz4 decompression failed."):0; ++} ++ ++static int ++LZ4_uncompress_unknownOutputSize(const char *source, ++ char *dest, int isize, int maxOutputSize) ++{ ++ /* Local Variables */ ++ const BYTE *restrict ip = (const BYTE *) source; ++ const BYTE *const iend = ip + isize; ++ const BYTE *restrict ref; ++ ++ BYTE *restrict op = (BYTE *) dest; ++ BYTE *const oend = op + maxOutputSize; ++ BYTE *cpy; ++ ++ size_t dec[] = { 0, 3, 2, 3, 0, 0, 0, 0 }; ++ ++ /* Main Loop */ ++ while (ip < iend) { ++ BYTE token; ++ int length; ++ ++ /* get runlength */ ++ token = *ip++; ++ if ((length = (token >> ML_BITS)) == RUN_MASK) { ++ int s = 255; ++ while ((ip < iend) && (s == 255)) { ++ s = *ip++; ++ length += s; ++ } ++ } ++ /* copy literals */ ++ cpy = op + length; ++ if ((cpy > oend - COPYLENGTH) || ++ (ip + length > iend - COPYLENGTH)) { ++ if (cpy > oend) ++ /* ++ * Error: request to write beyond destination ++ * buffer. ++ */ ++ goto _output_error; ++ if (ip + length > iend) ++ /* ++ * Error : request to read beyond source ++ * buffer. ++ */ ++ goto _output_error; ++ grub_memcpy(op, ip, length); ++ op += length; ++ ip += length; ++ if (ip < iend) ++ /* Error : LZ4 format violation */ ++ goto _output_error; ++ /* Necessarily EOF, due to parsing restrictions. */ ++ break; ++ } ++ LZ4_WILDCOPY(ip, op, cpy); ++ ip -= (op - cpy); ++ op = cpy; ++ ++ /* get offset */ ++ LZ4_READ_LITTLEENDIAN_16(ref, cpy, ip); ++ ip += 2; ++ if (ref < (BYTE * const) dest) ++ /* ++ * Error: offset creates reference outside of ++ * destination buffer. ++ */ ++ goto _output_error; ++ ++ /* get matchlength */ ++ if ((length = (token & ML_MASK)) == ML_MASK) { ++ while (ip < iend) { ++ int s = *ip++; ++ length += s; ++ if (s == 255) ++ continue; ++ break; ++ } ++ } ++ /* copy repeated sequence */ ++ if unlikely(op - ref < STEPSIZE) { ++#if LZ4_ARCH64 ++ size_t dec2table[] = { 0, 0, 0, -1, 0, 1, 2, 3 }; ++ size_t dec2 = dec2table[op - ref]; ++#else ++ const int dec2 = 0; ++#endif ++ *op++ = *ref++; ++ *op++ = *ref++; ++ *op++ = *ref++; ++ *op++ = *ref++; ++ ref -= dec[op - ref]; ++ A32(op) = A32(ref); ++ op += STEPSIZE - 4; ++ ref -= dec2; ++ } else { ++ LZ4_COPYSTEP(ref, op); ++ } ++ cpy = op + length - (STEPSIZE - 4); ++ if (cpy > oend - COPYLENGTH) { ++ if (cpy > oend) ++ /* ++ * Error: request to write outside of ++ * destination buffer. ++ */ ++ goto _output_error; ++ LZ4_SECURECOPY(ref, op, (oend - COPYLENGTH)); ++ while (op < cpy) ++ *op++ = *ref++; ++ op = cpy; ++ if (op == oend) ++ /* ++ * Check EOF (should never happen, since last ++ * 5 bytes are supposed to be literals). ++ */ ++ break; ++ continue; ++ } ++ LZ4_SECURECOPY(ref, op, cpy); ++ op = cpy; /* correction */ ++ } ++ ++ /* end of decoding */ ++ return (int)(((char *)op) - dest); ++ ++ /* write overflow error detected */ ++ _output_error: ++ return (int)(-(((char *)ip) - source)); ++} +diff --git a/grub-core/fs/zfs/zfsinfo.c b/grub-core/fs/zfs/zfsinfo.c +index fdb587a..c96bf21 100644 +--- a/grub-core/fs/zfs/zfsinfo.c ++++ b/grub-core/fs/zfs/zfsinfo.c +@@ -132,21 +132,31 @@ print_vdev_info (char *nvlist, int tab) + grub_free (path); + return GRUB_ERR_NONE; + } ++ char is_mirror=(grub_strcmp(type,VDEV_TYPE_MIRROR) == 0); ++ char is_raidz=(grub_strcmp(type,VDEV_TYPE_RAIDZ) == 0); + +- if (grub_strcmp (type, VDEV_TYPE_MIRROR) == 0) ++ if (is_mirror || is_raidz) + { + int nelm, i; + + nelm = grub_zfs_nvlist_lookup_nvlist_array_get_nelm + (nvlist, ZPOOL_CONFIG_CHILDREN); + ++ if(is_mirror){ ++ grub_puts_ (N_("This VDEV is a mirror")); ++ } ++ else if(is_raidz){ ++ grub_uint64_t parity; ++ grub_zfs_nvlist_lookup_uint64(nvlist,"nparity",&parity); ++ grub_printf_ (N_("This VDEV is a RAIDZ%llu\n"),(unsigned long long)parity); ++ } + print_tabs (tab); + if (nelm <= 0) + { +- grub_puts_ (N_("Incorrect mirror")); ++ grub_puts_ (N_("Incorrect VDEV")); + return GRUB_ERR_NONE; + } +- grub_printf_ (N_("Mirror with %d children\n"), nelm); ++ grub_printf_ (N_("VDEV with %d children\n"), nelm); + print_state (nvlist, tab); + for (i = 0; i < nelm; i++) + { +@@ -162,14 +172,14 @@ print_vdev_info (char *nvlist, int tab) + total element number. And the number itself is fine, + only the element isn't. + */ +- grub_printf_ (N_("Mirror element number %d isn't correct\n"), i); ++ grub_printf_ (N_("VDEV element number %d isn't correct\n"), i); + continue; + } + + /* TRANSLATORS: it's the element carying the number %d, not + total element number. This is used in enumeration + "Element number 1", "Element number 2", ... */ +- grub_printf_ (N_("Mirror element number %d:\n"), i); ++ grub_printf_ (N_("VDEV element number %d:\n"), i); + print_vdev_info (child, tab + 1); + + grub_free (child); +diff --git a/include/grub/zfs/dmu.h b/include/grub/zfs/dmu.h +index 8fc6dc5..4ad616c 100644 +--- a/include/grub/zfs/dmu.h ++++ b/include/grub/zfs/dmu.h +@@ -22,6 +22,39 @@ + + #ifndef _SYS_DMU_H + #define _SYS_DMU_H ++#define B_FALSE 0 ++#define B_TRUE 1 ++ ++#define DMU_OT_NEWTYPE 0x80 ++#define DMU_OT_METADATA 0x40 ++#define DMU_OT_BYTESWAP_MASK 0x3f ++ ++#define DMU_OT(byteswap, metadata) \ ++ (DMU_OT_NEWTYPE | \ ++ ((metadata) ? DMU_OT_METADATA : 0) | \ ++ ((byteswap) & DMU_OT_BYTESWAP_MASK)) ++ ++#define DMU_OT_IS_VALID(ot) (((ot) & DMU_OT_NEWTYPE) ? \ ++ ((ot) & DMU_OT_BYTESWAP_MASK) < DMU_BSWAP_NUMFUNCS : \ ++ (ot) < DMU_OT_NUMTYPES) ++ ++#define DMU_OT_IS_METADATA(ot) (((ot) & DMU_OT_NEWTYPE) ? \ ++ ((ot) & DMU_OT_METADATA) : \ ++ dmu_ot[(ot)].ot_metadata) ++ ++typedef enum dmu_object_byteswap { ++ DMU_BSWAP_UINT8, ++ DMU_BSWAP_UINT16, ++ DMU_BSWAP_UINT32, ++ DMU_BSWAP_UINT64, ++ DMU_BSWAP_ZAP, ++ DMU_BSWAP_DNODE, ++ DMU_BSWAP_OBJSET, ++ DMU_BSWAP_ZNODE, ++ DMU_BSWAP_OLDACL, ++ DMU_BSWAP_ACL, ++ DMU_BSWAP_NUMFUNCS ++} dmu_object_byteswap_t; + + /* + * This file describes the interface that the DMU provides for its +@@ -89,7 +122,17 @@ typedef enum dmu_object_type { + DMU_OT_SA_ATTR_REGISTRATION, /* ZAP */ + DMU_OT_SA_ATTR_LAYOUTS, /* ZAP */ + DMU_OT_DSL_KEYCHAIN = 54, +- DMU_OT_NUMTYPES ++ DMU_OT_NUMTYPES, ++ DMU_OTN_UINT8_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE), ++ DMU_OTN_UINT8_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE), ++ DMU_OTN_UINT16_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE), ++ DMU_OTN_UINT16_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE), ++ DMU_OTN_UINT32_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE), ++ DMU_OTN_UINT32_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE), ++ DMU_OTN_UINT64_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE), ++ DMU_OTN_UINT64_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE), ++ DMU_OTN_ZAP_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE), ++ DMU_OTN_ZAP_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE), + } dmu_object_type_t; + + typedef enum dmu_objset_type { +@@ -116,5 +159,6 @@ typedef enum dmu_objset_type { + #define DMU_POOL_HISTORY "history" + #define DMU_POOL_PROPS "pool_props" + #define DMU_POOL_L2CACHE "l2cache" ++#define DMU_POOL_FEATURES_FOR_READ "features_for_read" + + #endif /* _SYS_DMU_H */ +diff --git a/include/grub/zfs/zfs.h b/include/grub/zfs/zfs.h +index e326c8b..761ade7 100644 +--- a/include/grub/zfs/zfs.h ++++ b/include/grub/zfs/zfs.h +@@ -36,8 +36,13 @@ typedef enum grub_zfs_endian + /* + * On-disk version number. + */ +-#define SPA_VERSION 33ULL +- ++#define SPA_VERSION_INITIAL 1ULL ++#define SPA_VERSION_BEFORE_FEATURES 33ULL ++#define SPA_VERSION 5000ULL ++#define SPA_VERSION_FEATURES 5000ULL ++#define SPA_VERSION_IS_SUPPORTED(v) \ ++ (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \ ++ ((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION)) + /* + * The following are configuration names used in the nvlist describing a pool's + * configuration. +@@ -76,6 +81,7 @@ typedef enum grub_zfs_endian + #define ZPOOL_CONFIG_DDT_HISTOGRAM "ddt_histogram" + #define ZPOOL_CONFIG_DDT_OBJ_STATS "ddt_object_stats" + #define ZPOOL_CONFIG_DDT_STATS "ddt_stats" ++#define ZPOOL_CONFIG_FEATURES_FOR_READ "features_for_read" + /* + * The persistent vdev state is stored as separate values rather than a single + * 'vdev_state' entry. This is because a device can be in multiple states, such +diff --git a/include/grub/zfs/zio.h b/include/grub/zfs/zio.h +index b1c46da..8fad2cc 100644 +--- a/include/grub/zfs/zio.h ++++ b/include/grub/zfs/zio.h +@@ -88,6 +88,7 @@ enum zio_compress { + ZIO_COMPRESS_GZIP8, + ZIO_COMPRESS_GZIP9, + ZIO_COMPRESS_ZLE, ++ ZIO_COMPRESS_LZ4, + ZIO_COMPRESS_FUNCTIONS + }; + +diff --git a/po/POTFILES.in b/po/POTFILES.in +index 987b37a..c55d9e3 100644 +--- a/po/POTFILES.in ++++ b/po/POTFILES.in +@@ -173,6 +173,7 @@ + ./grub-core/fs/zfs/zfs_fletcher.c + ./grub-core/fs/zfs/zfsinfo.c + ./grub-core/fs/zfs/zfs_lzjb.c ++./grub-core/fs/zfs/zfs_lz4.c + ./grub-core/fs/zfs/zfs_sha256.c + ./grub-core/gdb/cstub.c + ./grub-core/gdb/gdb.c diff --git a/sys-boot/grub/grub-2.00-r2.ebuild b/sys-boot/grub/grub-2.00-r2.ebuild new file mode 100644 index 000000000000..47b1ee8a5dbf --- /dev/null +++ b/sys-boot/grub/grub-2.00-r2.ebuild @@ -0,0 +1,349 @@ +# Copyright 1999-2013 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/sys-boot/grub/grub-2.00-r2.ebuild,v 1.1 2013/02/03 22:25:45 ryao Exp $ + +EAPI=4 + +if [[ ${PV} == "9999" ]] ; then + EBZR_REPO_URI="http://bzr.savannah.gnu.org/r/grub/trunk/grub/" + LIVE_ECLASS="bzr" + SRC_URI="" + DO_AUTORECONF="true" +else + MY_P=${P/_/\~} + if [[ ${PV} == *_alpha* || ${PV} == *_beta* || ${PV} == *_rc* ]]; then + SRC_URI="mirror://gnu-alpha/${PN}/${MY_P}.tar.xz" + else + SRC_URI="mirror://gnu/${PN}/${MY_P}.tar.xz + mirror://gentoo/${MY_P}.tar.xz" + fi + KEYWORDS="" + S=${WORKDIR}/${MY_P} + DO_AUTORECONF="true" +fi + +inherit eutils flag-o-matic multiprocessing pax-utils toolchain-funcs ${DO_AUTORECONF:+autotools} ${LIVE_ECLASS} +unset LIVE_ECLASS + +DESCRIPTION="GNU GRUB boot loader" +HOMEPAGE="http://www.gnu.org/software/grub/" + +LICENSE="GPL-3" +SLOT="2" +IUSE="custom-cflags debug device-mapper doc efiemu mount nls static sdl truetype libzfs" + +GRUB_PLATFORMS=( + # everywhere: + emu + # mips only: + qemu-mips yeeloong + # amd64, x86, ppc, ppc64: + ieee1275 + # amd64, x86: + coreboot multiboot efi-32 pc qemu + # amd64, ia64: + efi-64 +) +IUSE+=" ${GRUB_PLATFORMS[@]/#/grub_platforms_}" + +REQUIRED_USE="grub_platforms_qemu? ( truetype )" + +# os-prober: Used on runtime to detect other OSes +# xorriso (dev-libs/libisoburn): Used on runtime for mkrescue +RDEPEND=" + app-arch/xz-utils + >=sys-libs/ncurses-5.2-r5 + debug? ( + sdl? ( media-libs/libsdl ) + ) + device-mapper? ( >=sys-fs/lvm2-2.02.45 ) + libzfs? ( sys-fs/zfs ) + mount? ( sys-fs/fuse ) + truetype? ( + media-libs/freetype + media-fonts/dejavu + >=media-fonts/unifont-5 + ) + ppc? ( sys-apps/ibm-powerpc-utils sys-apps/powerpc-utils ) + ppc64? ( sys-apps/ibm-powerpc-utils sys-apps/powerpc-utils ) +" +DEPEND="${RDEPEND} + >=dev-lang/python-2.5.2 + sys-devel/flex + sys-devel/bison + sys-apps/help2man + sys-apps/texinfo + static? ( + truetype? ( + app-arch/bzip2[static-libs(+)] + media-libs/freetype[static-libs(+)] + sys-libs/zlib[static-libs(+)] + ) + ) +" +RDEPEND+=" + grub_platforms_efi-32? ( sys-boot/efibootmgr ) + grub_platforms_efi-64? ( sys-boot/efibootmgr ) +" +if [[ -n ${DO_AUTORECONF} ]] ; then + DEPEND+=" >=sys-devel/autogen-5.10" +else + DEPEND+=" app-arch/xz-utils" +fi + +export STRIP_MASK="*/grub/*/*.{mod,img}" + +QA_EXECSTACK=" + usr/bin/grub* + usr/sbin/grub* + usr/lib*/grub/*/*.mod + usr/lib*/grub/*/kernel.exec + usr/lib*/grub/*/kernel.img + usr/lib*/grub/*/setjmp.module +" + +QA_WX_LOAD=" + usr/lib*/grub/*/kernel.exec + usr/lib*/grub/*/kernel.img + usr/lib*/grub/*/*.image +" + +QA_PRESTRIPPED=" + usr/lib.*/grub/.*/kernel.img +" + +grub_run_phase() { + local phase=$1 + local platform=$2 + [[ -z ${phase} || -z ${platform} ]] && die "${FUNCNAME} [phase] [platform]" + + [[ -d "${WORKDIR}/build-${platform}" ]] || \ + { mkdir "${WORKDIR}/build-${platform}" || die ; } + pushd "${WORKDIR}/build-${platform}" > /dev/null || die + + echo ">>> Running ${phase} for platform \"${platform}\"" + echo ">>> Working in: \"${WORKDIR}/build-${platform}\"" + + grub_${phase} ${platform} + + popd > /dev/null || die +} + +grub_src_configure() { + local platform=$1 + local with_platform= + local enable_efiemu="--disable-efiemu" + + [[ -z ${platform} ]] && die "${FUNCNAME} [platform]" + + # Used below for efi cross-building + tc-export CC NM OBJCOPY STRIP + + estack_push CTARGET "${CTARGET}" + estack_push TARGET_CC "${TARGET_CC}" + estack_push TARGET_CFLAGS "${TARGET_CFLAGS}" + estack_push TARGET_CPPFLAGS "${TARGET_CPPFLAGS}" + + case ${platform} in + efi-32) + if [[ ${CHOST} == x86_64* ]]; then + CTARGET="${CTARGET:-i386}" + TARGET_CC="${TARGET_CC:-${CC}}" + export TARGET_CC + fi + with_platform="--with-platform=efi" + ;; + efi-64) + if [[ ${CHOST} == i?86* ]]; then + CTARGET="${CTARGET:-x86_64}" + TARGET_CC="${TARGET_CC:-${CC}}" + TARGET_CFLAGS="-Os -march=x86-64 ${TARGET_CFLAGS}" + TARGET_CPPFLAGS="-march=x86-64 ${TARGET_CPPFLAGS}" + export TARGET_CC TARGET_CFLAGS TARGET_CPPFLAGS + fi + with_platform="--with-platform=efi" + ;; + guessed) ;; + *) + with_platform="--with-platform=${platform}" + case ${CTARGET:-${CHOST}} in + i?86*|x86_64*) + enable_efiemu=$(use_enable efiemu) + ;; + esac + ;; + esac + + ECONF_SOURCE="${S}" \ + econf \ + --libdir=/usr/lib \ + --htmldir="${EPREFIX}/usr/share/doc/${PF}/html" \ + --disable-werror \ + --program-prefix= \ + --program-transform-name="s,grub,grub2," \ + --with-grubdir=grub2 \ + ${with_platform} \ + $(use_enable debug mm-debug) \ + $(use_enable debug grub-emu-usb) \ + $(use_enable device-mapper) \ + ${enable_efiemu} \ + $(use_enable mount grub-mount) \ + $(use_enable nls) \ + $(use_enable truetype grub-mkfont) \ + $(use_enable libzfs) \ + $(use sdl && use_enable debug grub-emu-sdl) + + estack_pop CTARGET CTARGET || die + estack_pop TARGET_CC TARGET_CC || die + estack_pop TARGET_CFLAGS TARGET_CFLAGS || die + estack_pop TARGET_CPPFLAGS TARGET_CPPFLAGS || die +} + +grub_src_compile() { + default_src_compile + pax-mark -mpes "${grub_binaries[@]}" +} + +grub_build_docs() { + emake -C docs html +} + +grub_src_install() { + default_src_install +} + +grub_install_docs() { + emake -C docs DESTDIR="${D}" install-html +} + +pkg_pretend() { + if [[ ${MERGE_TYPE} != binary ]]; then + # Bug 439082 + if $(tc-getLD) --version | grep -q "GNU gold"; then + eerror "GRUB does not function correctly when built with the gold linker." + eerror "Please select the bfd linker with binutils-config." + die "GNU gold detected" + fi + fi +} + +src_prepare() { + if [[ ${PV} != 9999 ]]; then + epatch "${FILESDIR}/${P}-parallel-make.patch" #424231 + epatch "${FILESDIR}/${P}-no-gets.patch" #424703 + epatch "${FILESDIR}/${P}-config-quoting.patch" #426364 + epatch "${FILESDIR}/${P}-tftp-endian.patch" # 438612 + epatch "${FILESDIR}/${P}-hardcoded-awk.patch" #424137 + epatch "${FILESDIR}/${P}-zfs-feature-flag-support.patch" #455358 + fi + + # fix texinfo file name, bug 416035 + sed -i \ + -e 's/^\* GRUB:/* GRUB2:/' \ + -e 's/(grub)/(grub2)/' -- \ + "${S}"/docs/grub.texi + + epatch_user + + # autogen.sh does more than just run autotools + if [[ -n ${DO_AUTORECONF} ]] ; then + sed -i -e '/^autoreconf/s:^:set +e; e:' autogen.sh || die + ( + autopoint() { :; } + . ./autogen.sh + ) || die + fi + + # install into the right dir for eselect #372735 + sed -i \ + -e '/^bashcompletiondir =/s:=.*:= $(datarootdir)/bash-completion:' \ + util/bash-completion.d/Makefile.in || die + + # get enabled platforms + GRUB_ENABLED_PLATFORMS="" + local i + for i in ${GRUB_PLATFORMS[@]}; do + use grub_platforms_${i} && GRUB_ENABLED_PLATFORMS+=" ${i}" + done + [[ -z ${GRUB_ENABLED_PLATFORMS} ]] && GRUB_ENABLED_PLATFORMS="guessed" + einfo "Going to build following platforms: ${GRUB_ENABLED_PLATFORMS}" +} + +src_configure() { + local i + + use custom-cflags || unset CCASFLAGS CFLAGS CPPFLAGS LDFLAGS + use static && append-ldflags -static + + # Sandbox bug 404013. + use libzfs && addpredict /etc/dfs:/dev/zfs + + multijob_init + for i in ${GRUB_ENABLED_PLATFORMS}; do + multijob_child_init grub_run_phase ${FUNCNAME} ${i} + done + multijob_finish || die +} + +src_compile() { + # Used for pax marking in grub_src_compile + local grub_binaries=( + grub-editenv + grub-fstest + grub-menulst2cfg + grub-mkimage + grub-mklayout + grub-mkpasswd-pbkdf2 + grub-mkrelpath + grub-script-check + grub-bios-setup + grub-ofpathname + grub-probe + grub-sparc64-setup + ) + use mount && grub_binaries+=( grub-mount ) + use truetype && grub_binaries+=( grub-mkfont ) + + local i + + for i in ${GRUB_ENABLED_PLATFORMS}; do + grub_run_phase ${FUNCNAME} ${i} + done + + # Just build docs once + use doc && grub_run_phase build_docs ${i} +} + +src_install() { + local i + + for i in ${GRUB_ENABLED_PLATFORMS}; do + grub_run_phase ${FUNCNAME} ${i} + done + + use doc && grub_run_phase install_docs ${i} + + mv "${ED}"usr/share/info/grub{,2}.info || die + + # can't be in docs array as we use default_src_install in different builddir + dodoc AUTHORS ChangeLog NEWS README THANKS TODO + insinto /etc/default + newins "${FILESDIR}"/grub.default-2 grub +} + +pkg_postinst() { + # display the link to guide + elog "For information on how to configure grub-2 please refer to the guide:" + elog " http://wiki.gentoo.org/wiki/GRUB2_Quick_Start" + if ! has_version sys-boot/os-prober; then + elog "Install sys-boot/os-prober to enable detection of other operating systems using grub2-mkconfig." + fi + if ! has_version dev-libs/libisoburn; then + elog "Install dev-libs/libisoburn to enable creation of rescue media using grub2-mkrescue." + fi + if has_version sys-boot/grub:0; then + ewarn "If you want to keep GRUB Legacy (grub-0.97) installed, please run" + ewarn "the following to add sys-boot/grub:0 to your world file." + ewarn "emerge --noreplace sys-boot/grub:0" + fi +} |