Deleted Added
sdiff udiff text old ( 254156 ) new ( 263382 )
full compact
1/*-
2 * Copyright (c) 2013 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

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

25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD$");
29
30#include <sys/types.h>
31#include <sys/diskmbr.h>
32#include <sys/diskpc98.h>
33#include <sys/queue.h>
34#include <sys/vtoc.h>
35#include <err.h>
36#include <errno.h>
37#include <stdint.h>
38#include <strings.h>
39#include <unistd.h>
40
41#include "mkimg.h"
42#include "scheme.h"
43
44static struct scheme {
45 const char *lexeme;
46 u_int token;
47} schemes[] = {
48 { .lexeme = "apm", .token = SCHEME_APM },
49 { .lexeme = "bsd", .token = SCHEME_BSD },
50 { .lexeme = "ebr", .token = SCHEME_EBR },
51 { .lexeme = "gpt", .token = SCHEME_GPT },
52 { .lexeme = "mbr", .token = SCHEME_MBR },
53 { .lexeme = "pc98", .token = SCHEME_PC98 },
54 { .lexeme = "vtoc8", .token = SCHEME_VTOC8 },
55 { .lexeme = NULL, .token = SCHEME_UNDEF }
56};
57
58static u_int scheme = SCHEME_UNDEF;
59static u_int secsz = 512;
60
61int
62scheme_select(const char *spec)
63{
64 struct scheme *s;
65
66 s = schemes;
67 while (s->lexeme != NULL) {

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

77u_int
78scheme_selected(void)
79{
80
81 return (scheme);
82}
83
84int
85scheme_check_part(struct part *p __unused)
86{
87
88 warnx("part: index=%u, type=`%s', offset=%ju, size=%ju", p->index,
89 p->type, (uintmax_t)p->offset, (uintmax_t)p->size);
90
91 return (0);
92}
93
94u_int
95scheme_max_parts(void)
96{
97 u_int parts;
98

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

125 return (parts);
126}
127
128off_t
129scheme_first_offset(u_int parts)
130{
131 off_t off;
132
133 switch (scheme) {
134 case SCHEME_APM:
135 off = parts + 1;
136 break;
137 case SCHEME_BSD:
138 off = 16;
139 break;
140 case SCHEME_EBR:
141 off = 1;
142 break;
143 case SCHEME_GPT:
144 off = 2 + (parts + 3) / 4;
145 break;
146 case SCHEME_MBR:
147 off = 1;
148 break;
149 case SCHEME_PC98:
150 off = 2;
151 break;
152 case SCHEME_VTOC8:
153 off = 1;
154 break;
155 default:
156 off = 0;
157 break;
158 }

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

172
173void
174scheme_write(int fd, off_t off)
175{
176 off_t lim;
177
178 switch (scheme) {
179 case SCHEME_GPT:
180 lim = off + secsz * (1 + (nparts + 3) / 4);
181 break;
182 case SCHEME_EBR:
183 off -= secsz;
184 /* FALLTHROUGH */
185 default:
186 lim = off;
187 break;
188 }
189 ftruncate(fd, lim);
190}