2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 * Copyright 2007 Sun Microsystems, Inc.
5 * Copyright (C) 2009 Vladimir Serbinenko <phcoder@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <grub/file.h>
25 #include <grub/misc.h>
26 #include <grub/disk.h>
28 #include <grub/types.h>
29 #include <grub/zfs/zfs.h>
30 #include <grub/zfs/zio.h>
31 #include <grub/zfs/dnode.h>
32 #include <grub/zfs/uberblock_impl.h>
33 #include <grub/zfs/vdev_impl.h>
34 #include <grub/zfs/zio_checksum.h>
35 #include <grub/zfs/zap_impl.h>
36 #include <grub/zfs/zap_leaf.h>
37 #include <grub/zfs/zfs_znode.h>
38 #include <grub/zfs/dmu.h>
39 #include <grub/zfs/dmu_objset.h>
40 #include <grub/zfs/dsl_dir.h>
41 #include <grub/zfs/dsl_dataset.h>
45 #define OFFSET_MASK ((1 << (16 - MATCH_BITS)) - 1)
48 * Decompression Entry - lzjb
55 lzjb_decompress (void *s_start
, void *d_start
, grub_size_t s_len
,
59 lzjb_decompress (void *s_start
, void *d_start
, grub_size_t s_len
,
62 grub_uint8_t
*src
= s_start
;
63 grub_uint8_t
*dst
= d_start
;
64 grub_uint8_t
*d_end
= (grub_uint8_t
*) d_start
+ d_len
;
65 grub_uint8_t
*s_end
= (grub_uint8_t
*) s_start
+ s_len
;
66 grub_uint8_t
*cpy
, copymap
= 0;
67 int copymask
= 1 << (NBBY
- 1);
69 while (dst
< d_end
&& src
< s_end
)
71 if ((copymask
<<= 1) == (1 << NBBY
))
77 return grub_error (GRUB_ERR_BAD_FS
, "lzjb decompression failed");
78 if (copymap
& copymask
)
80 int mlen
= (src
[0] >> (NBBY
- MATCH_BITS
)) + MATCH_MIN
;
81 int offset
= ((src
[0] << NBBY
) | src
[1]) & OFFSET_MASK
;
84 if (src
> s_end
|| cpy
< (grub_uint8_t
*) d_start
)
85 return grub_error (GRUB_ERR_BAD_FS
, "lzjb decompression failed");
86 while (--mlen
>= 0 && dst
< d_end
)
93 return grub_error (GRUB_ERR_BAD_FS
, "lzjb decompression failed");