Deleted Added
full compact
gpt.c (263465) gpt.c (263466)
1/*-
2 * Copyright (c) 2014 Juniper Networks, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2014 Juniper Networks, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: user/marcel/mkimg/gpt.c 263465 2014-03-21 04:52:46Z marcel $");
28__FBSDID("$FreeBSD: user/marcel/mkimg/gpt.c 263466 2014-03-21 05:30:27Z marcel $");
29
30#include <sys/types.h>
31#include <sys/diskmbr.h>
32#include <sys/endian.h>
33#include <sys/errno.h>
34#include <sys/gpt.h>
35#include <stddef.h>
36#include <stdint.h>

--- 131 unchanged lines hidden (view full) ---

168
169static struct gpt_ent *
170gpt_mktbl(u_int tblsz, u_int secsz)
171{
172 uuid_t uuid;
173 struct gpt_ent *tbl, *ent;
174 struct part *part;
175 uint64_t limit;
29
30#include <sys/types.h>
31#include <sys/diskmbr.h>
32#include <sys/endian.h>
33#include <sys/errno.h>
34#include <sys/gpt.h>
35#include <stddef.h>
36#include <stdint.h>

--- 131 unchanged lines hidden (view full) ---

168
169static struct gpt_ent *
170gpt_mktbl(u_int tblsz, u_int secsz)
171{
172 uuid_t uuid;
173 struct gpt_ent *tbl, *ent;
174 struct part *part;
175 uint64_t limit;
176 int c, idx;
176
177 tbl = calloc(tblsz, secsz);
178 if (tbl == NULL)
179 return (NULL);
180
181 STAILQ_FOREACH(part, &partlist, link) {
182 ent = tbl + part->index;
183 uuid_enc_le(&ent->ent_type, ALIAS_TYPE2PTR(part->type));
184 uuidgen(&uuid, 1);
185 uuid_enc_le(&ent->ent_uuid, &uuid);
186 le64enc(&ent->ent_lba_start, part->offset / secsz);
187 limit = (part->offset + part->size) / secsz;
188 le64enc(&ent->ent_lba_end, limit - 1);
177
178 tbl = calloc(tblsz, secsz);
179 if (tbl == NULL)
180 return (NULL);
181
182 STAILQ_FOREACH(part, &partlist, link) {
183 ent = tbl + part->index;
184 uuid_enc_le(&ent->ent_type, ALIAS_TYPE2PTR(part->type));
185 uuidgen(&uuid, 1);
186 uuid_enc_le(&ent->ent_uuid, &uuid);
187 le64enc(&ent->ent_lba_start, part->offset / secsz);
188 limit = (part->offset + part->size) / secsz;
189 le64enc(&ent->ent_lba_end, limit - 1);
189 /* TODO add support for labels */
190 if (part->label != NULL) {
191 idx = 0;
192 while ((c = part->label[idx]) != '\0') {
193 le16enc(ent->ent_name + idx, c);
194 idx++;
195 }
196 }
190 }
191 return (tbl);
192}
193
194static int
195gpt_write_hdr(int fd, struct gpt_hdr *hdr, uint64_t self, uint64_t alt,
196 uint64_t tbl, u_int secsz)
197{

--- 69 unchanged lines hidden (view full) ---

267}
268
269static struct mkimg_scheme gpt_scheme = {
270 .name = "gpt",
271 .description = "GUID Partition Table",
272 .aliases = gpt_aliases,
273 .metadata = gpt_metadata,
274 .write = gpt_write,
197 }
198 return (tbl);
199}
200
201static int
202gpt_write_hdr(int fd, struct gpt_hdr *hdr, uint64_t self, uint64_t alt,
203 uint64_t tbl, u_int secsz)
204{

--- 69 unchanged lines hidden (view full) ---

274}
275
276static struct mkimg_scheme gpt_scheme = {
277 .name = "gpt",
278 .description = "GUID Partition Table",
279 .aliases = gpt_aliases,
280 .metadata = gpt_metadata,
281 .write = gpt_write,
275 .nparts = 4096
282 .nparts = 4096,
283 .labellen = 36
276};
277
278SCHEME_DEFINE(gpt_scheme);
284};
285
286SCHEME_DEFINE(gpt_scheme);