author | Eric Taylor <Eric.Taylor@Sun.COM> |
Wed, 08 Jul 2009 08:44:27 -0600 | |
changeset 10056 | 9f478b0e65da |
parent 8044 | b3af80bbf173 |
child 11670 | 1d964fb5d948 |
permissions | -rw-r--r-- |
3912 | 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 |
/* |
|
10056
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
20 |
* Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
3912 | 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 |
typedef unsigned long long uint64_t; |
|
29 |
typedef unsigned int uint32_t; |
|
30 |
typedef unsigned short uint16_t; |
|
31 |
typedef unsigned char uint8_t; |
|
32 |
typedef unsigned char uchar_t; |
|
33 |
||
34 |
#if defined(_LP64) || defined(_I32LPx) |
|
35 |
typedef unsigned long size_t; |
|
36 |
#else |
|
37 |
typedef unsigned int size_t; |
|
38 |
#endif |
|
39 |
||
40 |
#include <zfs-include/zfs.h> |
|
41 |
#include <zfs-include/dmu.h> |
|
42 |
#include <zfs-include/spa.h> |
|
43 |
#include <zfs-include/zio.h> |
|
44 |
#include <zfs-include/zio_checksum.h> |
|
45 |
#include <zfs-include/vdev_impl.h> |
|
46 |
#include <zfs-include/zap_impl.h> |
|
47 |
#include <zfs-include/zap_leaf.h> |
|
48 |
#include <zfs-include/uberblock_impl.h> |
|
49 |
#include <zfs-include/dnode.h> |
|
50 |
#include <zfs-include/dsl_dir.h> |
|
51 |
#include <zfs-include/zfs_acl.h> |
|
52 |
#include <zfs-include/zfs_znode.h> |
|
53 |
#include <zfs-include/dsl_dataset.h> |
|
54 |
#include <zfs-include/zil.h> |
|
55 |
#include <zfs-include/dmu_objset.h> |
|
56 |
||
57 |
/* |
|
58 |
* Global Memory addresses to store MOS and DNODE data |
|
59 |
*/ |
|
5084 | 60 |
#define MOS ((dnode_phys_t *)\ |
5085
937feae7206d
6584697 Can't boot Xen / Solaris dom0 if root is using ZFS (fix cstyle)
johnlev
parents:
5084
diff
changeset
|
61 |
(RAW_ADDR((mbi.mem_upper << 10) + 0x100000) - ZFS_SCRATCH_SIZE)) |
4725
0452c60b6e69
6541114 GRUB/ZFS fails to load files from a default compressed (lzjb) root
lling
parents:
3912
diff
changeset
|
62 |
#define DNODE (MOS+1) /* move sizeof(dnode_phys_t) bytes */ |
0452c60b6e69
6541114 GRUB/ZFS fails to load files from a default compressed (lzjb) root
lling
parents:
3912
diff
changeset
|
63 |
#define ZFS_SCRATCH ((char *)(DNODE+1)) |
3912 | 64 |
|
65 |
/* |
|
66 |
* Verify dnode type. |
|
67 |
* Can only be used in functions returning non-0 for failure. |
|
68 |
*/ |
|
69 |
#define VERIFY_DN_TYPE(dnp, type) \ |
|
70 |
if (type && (dnp)->dn_type != type) { \ |
|
71 |
return (ERR_FSYS_CORRUPT); \ |
|
72 |
} |
|
73 |
||
74 |
/* |
|
75 |
* Verify object set type. |
|
76 |
* Can only be used in functions returning 0 for failure. |
|
77 |
*/ |
|
78 |
#define VERIFY_OS_TYPE(osp, type) \ |
|
79 |
if (type && (osp)->os_type != type) { \ |
|
80 |
errnum = ERR_FSYS_CORRUPT; \ |
|
81 |
return (0); \ |
|
82 |
} |
|
83 |
||
84 |
#define ZPOOL_PROP_BOOTFS "bootfs" |
|
85 |
||
86 |
/* General macros */ |
|
87 |
#define BSWAP_8(x) ((x) & 0xff) |
|
88 |
#define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8)) |
|
89 |
#define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16)) |
|
90 |
#define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32)) |
|
91 |
#define P2ROUNDUP(x, align) (-(-(x) & -(align))) |
|
92 |
||
93 |
/* |
|
94 |
* XXX Match these macro up with real zfs once we have nvlist support so that we |
|
95 |
* can support large sector disks. |
|
96 |
*/ |
|
97 |
#define UBERBLOCK_SIZE (1ULL << UBERBLOCK_SHIFT) |
|
98 |
#undef offsetof |
|
99 |
#define offsetof(t, m) ((int)&(((t *)0)->m)) |
|
100 |
#define VDEV_UBERBLOCK_SHIFT UBERBLOCK_SHIFT |
|
101 |
#define VDEV_UBERBLOCK_OFFSET(n) \ |
|
102 |
offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT]) |
|
103 |
||
104 |
typedef struct uberblock uberblock_t; |
|
105 |
||
106 |
/* XXX Uberblock_phys_t is no longer in the kernel zfs */ |
|
107 |
typedef struct uberblock_phys { |
|
108 |
uberblock_t ubp_uberblock; |
|
109 |
char ubp_pad[UBERBLOCK_SIZE - sizeof (uberblock_t) - |
|
110 |
sizeof (zio_block_tail_t)]; |
|
111 |
zio_block_tail_t ubp_zbt; |
|
112 |
} uberblock_phys_t; |
|
113 |
||
114 |
/* |
|
115 |
* Macros to get fields in a bp or DVA. |
|
116 |
*/ |
|
117 |
#define P2PHASE(x, align) ((x) & ((align) - 1)) |
|
118 |
#define DVA_OFFSET_TO_PHYS_SECTOR(offset) \ |
|
119 |
((offset + VDEV_LABEL_START_SIZE) >> SPA_MINBLOCKSHIFT) |
|
120 |
||
121 |
/* |
|
10056
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
122 |
* return x rounded down to an align boundary |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
123 |
* eg, P2ALIGN(1200, 1024) == 1024 (1*align) |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
124 |
* eg, P2ALIGN(1024, 1024) == 1024 (1*align) |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
125 |
* eg, P2ALIGN(0x1234, 0x100) == 0x1200 (0x12*align) |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
126 |
* eg, P2ALIGN(0x5600, 0x100) == 0x5600 (0x56*align) |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
127 |
*/ |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
128 |
#define P2ALIGN(x, align) ((x) & -(align)) |
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
129 |
|
9f478b0e65da
6770808 error 37 when encountering multiple pools w/same name but unique bootfs
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8044
diff
changeset
|
130 |
/* |
3912 | 131 |
* For nvlist manipulation. (from nvpair.h) |
132 |
*/ |
|
133 |
#define NV_ENCODE_NATIVE 0 |
|
134 |
#define NV_ENCODE_XDR 1 |
|
135 |
#define HOST_ENDIAN 1 /* for x86 machine */ |
|
136 |
#define DATA_TYPE_UINT64 8 |
|
137 |
#define DATA_TYPE_STRING 9 |
|
6423 | 138 |
#define DATA_TYPE_NVLIST 19 |
139 |
#define DATA_TYPE_NVLIST_ARRAY 20 |
|
3912 | 140 |
|
141 |
/* |
|
142 |
* Decompression Entry - lzjb |
|
143 |
*/ |
|
144 |
#ifndef NBBY |
|
145 |
#define NBBY 8 |
|
146 |
#endif |
|
147 |
||
148 |
typedef int zfs_decomp_func_t(void *s_start, void *d_start, size_t s_len, |
|
149 |
size_t d_len); |
|
150 |
typedef struct decomp_entry { |
|
151 |
char *name; |
|
152 |
zfs_decomp_func_t *decomp_func; |
|
153 |
} decomp_entry_t; |
|
154 |
||
155 |
/* |
|
156 |
* FAT ZAP data structures |
|
157 |
*/ |
|
158 |
#define ZFS_CRC64_POLY 0xC96C5795D7870F42ULL /* ECMA-182, reflected form */ |
|
159 |
#define ZAP_HASH_IDX(hash, n) (((n) == 0) ? 0 : ((hash) >> (64 - (n)))) |
|
160 |
#define CHAIN_END 0xffff /* end of the chunk chain */ |
|
161 |
||
162 |
/* |
|
163 |
* The amount of space within the chunk available for the array is: |
|
164 |
* chunk size - space for type (1) - space for next pointer (2) |
|
165 |
*/ |
|
166 |
#define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3) |
|
167 |
||
168 |
#define ZAP_LEAF_HASH_SHIFT(bs) (bs - 5) |
|
169 |
#define ZAP_LEAF_HASH_NUMENTRIES(bs) (1 << ZAP_LEAF_HASH_SHIFT(bs)) |
|
170 |
#define LEAF_HASH(bs, h) \ |
|
171 |
((ZAP_LEAF_HASH_NUMENTRIES(bs)-1) & \ |
|
172 |
((h) >> (64 - ZAP_LEAF_HASH_SHIFT(bs)-l->l_hdr.lh_prefix_len))) |
|
173 |
||
174 |
/* |
|
175 |
* The amount of space available for chunks is: |
|
176 |
* block size shift - hash entry size (2) * number of hash |
|
177 |
* entries - header space (2*chunksize) |
|
178 |
*/ |
|
179 |
#define ZAP_LEAF_NUMCHUNKS(bs) \ |
|
180 |
(((1<<bs) - 2*ZAP_LEAF_HASH_NUMENTRIES(bs)) / \ |
|
181 |
ZAP_LEAF_CHUNKSIZE - 2) |
|
182 |
||
183 |
/* |
|
184 |
* The chunks start immediately after the hash table. The end of the |
|
185 |
* hash table is at l_hash + HASH_NUMENTRIES, which we simply cast to a |
|
186 |
* chunk_t. |
|
187 |
*/ |
|
188 |
#define ZAP_LEAF_CHUNK(l, bs, idx) \ |
|
189 |
((zap_leaf_chunk_t *)(l->l_hash + ZAP_LEAF_HASH_NUMENTRIES(bs)))[idx] |
|
190 |
#define ZAP_LEAF_ENTRY(l, bs, idx) (&ZAP_LEAF_CHUNK(l, bs, idx).l_entry) |
|
191 |
||
192 |
extern void fletcher_2_native(const void *, uint64_t, zio_cksum_t *); |
|
193 |
extern void fletcher_2_byteswap(const void *, uint64_t, zio_cksum_t *); |
|
194 |
extern void fletcher_4_native(const void *, uint64_t, zio_cksum_t *); |
|
195 |
extern void fletcher_4_byteswap(const void *, uint64_t, zio_cksum_t *); |
|
196 |
extern void zio_checksum_SHA256(const void *, uint64_t, zio_cksum_t *); |
|
197 |
extern int lzjb_decompress(void *, void *, size_t, size_t); |
|
198 |
||
199 |
#endif /* FSYS_ZFS */ |
|
200 |
||
201 |
#endif /* !_FSYS_ZFS_H */ |