xref: /illumos-gate/usr/src/grub/grub-0.97/stage2/fsys_zfs.h (revision d0fccfcda73f8b52d101bd2b0f7885a766f7e354)
1 /*
2  *  GRUB  --  GRand Unified Bootloader
3  *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /*
20  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
21  * Use is subject to license terms.
22  */
23 #ifndef _FSYS_ZFS_H
24 #define	_FSYS_ZFS_H
25 
26 #ifdef	FSYS_ZFS
27 
28 #ifndef	FSIMAGE
29 typedef unsigned long long uint64_t;
30 typedef unsigned int uint32_t;
31 typedef unsigned short uint16_t;
32 typedef unsigned char uint8_t;
33 typedef unsigned char uchar_t;
34 
35 #if defined(_LP64) || defined(_I32LPx)
36 typedef	unsigned long size_t;
37 #else
38 typedef	unsigned int size_t;
39 #endif
40 #else
41 #include "fsi_zfs.h"
42 #endif	/* !FSIMAGE */
43 
44 #include <zfs-include/zfs.h>
45 #include <zfs-include/dmu.h>
46 #include <zfs-include/spa.h>
47 #include <zfs-include/zio.h>
48 #include <zfs-include/zio_checksum.h>
49 #include <zfs-include/vdev_impl.h>
50 #include <zfs-include/zap_impl.h>
51 #include <zfs-include/zap_leaf.h>
52 #include <zfs-include/uberblock_impl.h>
53 #include <zfs-include/dnode.h>
54 #include <zfs-include/dsl_dir.h>
55 #include <zfs-include/zfs_acl.h>
56 #include <zfs-include/zfs_znode.h>
57 #include <zfs-include/dsl_dataset.h>
58 #include <zfs-include/zil.h>
59 #include <zfs-include/dmu_objset.h>
60 #include <zfs-include/sa_impl.h>
61 
62 /*
63  * Global Memory addresses to store MOS and DNODE data
64  */
65 #define	MOS		((dnode_phys_t *)\
66 	(RAW_ADDR((mbi.mem_upper << 10) + 0x100000) - ZFS_SCRATCH_SIZE))
67 #define	DNODE		(MOS+1) /* move sizeof(dnode_phys_t) bytes */
68 #define	ZFS_SCRATCH	((char *)(DNODE+1))
69 
70 /*
71  * Verify dnode type.
72  * Can only be used in functions returning non-0 for failure.
73  */
74 #define	VERIFY_DN_TYPE(dnp, type) \
75 	if (type && (dnp)->dn_type != type) { \
76 		return (ERR_FSYS_CORRUPT); \
77 	}
78 
79 /*
80  * Verify object set type.
81  * Can only be used in functions returning 0 for failure.
82  */
83 #define	VERIFY_OS_TYPE(osp, type) \
84 	if (type && (osp)->os_type != type) { \
85 		errnum = ERR_FSYS_CORRUPT; \
86 		return (0); \
87 	}
88 
89 #define	ZPOOL_PROP_BOOTFS		"bootfs"
90 
91 /* General macros */
92 #define	BSWAP_8(x)	((x) & 0xff)
93 #define	BSWAP_16(x)	((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8))
94 #define	BSWAP_32(x)	((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
95 #define	BSWAP_64(x)	((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
96 #define	P2ROUNDUP(x, align)	(-(-(x) & -(align)))
97 
98 typedef struct uberblock uberblock_t;
99 
100 /*
101  * Macros to get fields in a bp or DVA.
102  */
103 #define	P2PHASE(x, align)		((x) & ((align) - 1))
104 #define	DVA_OFFSET_TO_PHYS_SECTOR(offset) \
105 	((offset + VDEV_LABEL_START_SIZE) >> SPA_MINBLOCKSHIFT)
106 
107 /*
108  * return x rounded down to an align boundary
109  * eg, P2ALIGN(1200, 1024) == 1024 (1*align)
110  * eg, P2ALIGN(1024, 1024) == 1024 (1*align)
111  * eg, P2ALIGN(0x1234, 0x100) == 0x1200 (0x12*align)
112  * eg, P2ALIGN(0x5600, 0x100) == 0x5600 (0x56*align)
113  */
114 #define	P2ALIGN(x, align)		((x) & -(align))
115 
116 /*
117  * For nvlist manipulation. (from nvpair.h)
118  */
119 #define	NV_ENCODE_NATIVE	0
120 #define	NV_ENCODE_XDR		1
121 #define	HOST_ENDIAN		1	/* for x86 machine */
122 #define	DATA_TYPE_UINT64	8
123 #define	DATA_TYPE_STRING	9
124 #define	DATA_TYPE_NVLIST	19
125 #define	DATA_TYPE_NVLIST_ARRAY	20
126 
127 /*
128  * Decompression Entry - lzjb
129  */
130 #ifndef	NBBY
131 #define	NBBY	8
132 #endif
133 
134 typedef int zfs_decomp_func_t(void *s_start, void *d_start, size_t s_len,
135 			size_t d_len);
136 typedef struct decomp_entry {
137 	char *name;
138 	zfs_decomp_func_t *decomp_func;
139 } decomp_entry_t;
140 
141 /*
142  * FAT ZAP data structures
143  */
144 #define	ZFS_CRC64_POLY 0xC96C5795D7870F42ULL /* ECMA-182, reflected form */
145 #define	ZAP_HASH_IDX(hash, n)	(((n) == 0) ? 0 : ((hash) >> (64 - (n))))
146 #define	CHAIN_END	0xffff	/* end of the chunk chain */
147 
148 /*
149  * The amount of space within the chunk available for the array is:
150  * chunk size - space for type (1) - space for next pointer (2)
151  */
152 #define	ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
153 
154 #define	ZAP_LEAF_HASH_SHIFT(bs)	(bs - 5)
155 #define	ZAP_LEAF_HASH_NUMENTRIES(bs) (1 << ZAP_LEAF_HASH_SHIFT(bs))
156 #define	LEAF_HASH(bs, h) \
157 	((ZAP_LEAF_HASH_NUMENTRIES(bs)-1) & \
158 	((h) >> (64 - ZAP_LEAF_HASH_SHIFT(bs)-l->l_hdr.lh_prefix_len)))
159 
160 /*
161  * The amount of space available for chunks is:
162  * block size shift - hash entry size (2) * number of hash
163  * entries - header space (2*chunksize)
164  */
165 #define	ZAP_LEAF_NUMCHUNKS(bs) \
166 	(((1<<bs) - 2*ZAP_LEAF_HASH_NUMENTRIES(bs)) / \
167 	ZAP_LEAF_CHUNKSIZE - 2)
168 
169 /*
170  * The chunks start immediately after the hash table.  The end of the
171  * hash table is at l_hash + HASH_NUMENTRIES, which we simply cast to a
172  * chunk_t.
173  */
174 #define	ZAP_LEAF_CHUNK(l, bs, idx) \
175 	((zap_leaf_chunk_t *)(l->l_hash + ZAP_LEAF_HASH_NUMENTRIES(bs)))[idx]
176 #define	ZAP_LEAF_ENTRY(l, bs, idx) (&ZAP_LEAF_CHUNK(l, bs, idx).l_entry)
177 
178 extern void fletcher_2_native(const void *, uint64_t, zio_cksum_t *);
179 extern void fletcher_2_byteswap(const void *, uint64_t, zio_cksum_t *);
180 extern void fletcher_4_native(const void *, uint64_t, zio_cksum_t *);
181 extern void fletcher_4_byteswap(const void *, uint64_t, zio_cksum_t *);
182 extern void zio_checksum_SHA256(const void *, uint64_t, zio_cksum_t *);
183 extern int lzjb_decompress(void *, void *, size_t, size_t);
184 
185 #endif	/* FSYS_ZFS */
186 
187 #endif /* !_FSYS_ZFS_H */
188