Project

General

Profile

Bug #2830 ยป 0001-Align-partitions-to-1MiB.patch

pascii, 12/28/2015 05:51 AM

View differences:

sbin/gpt/gpt.8
156 156
You may also specify any symbolic name in the system
157 157
.Xr uuids 5
158 158
files.
159
.Pp
160
.Em NOTE!
161
If you don't specify a beginning sector with
162
.Fl b Ar number
163
, the new partition will be aligned to 1MiB in size and position
164
(in case of 512 byte sector sizes).
159 165
.\" ==== boot ====
160 166
.It Nm Ic boot Ar device ...
161 167
The
sbin/gpt/map.c
34 34

  
35 35
#include "map.h"
36 36

  
37
#define ROUNDTO 2048	// must be a power of two
38
#define ROUNDDOWN(x) ((x-1) & ~(ROUNDTO-1))
39
#define ROUNDUP(x) (ROUNDDOWN(x) + ROUNDTO)
40

  
37 41
int lbawidth;
38 42

  
39 43
static map_t *mediamap;
......
141 145
	off_t delta;
142 146
	map_t *m;
143 147

  
148
	if (start == 0 && size != 0)
149
		size = ROUNDUP(size);
144 150
	for (m = mediamap; m != NULL; m = m->map_next) {
145 151
		if (m->map_type != MAP_TYPE_UNUSED || m->map_start < 2)
146 152
			continue;
147 153
		if (start != 0 && m->map_start > start)
148 154
			return (NULL);
149
		delta = (start != 0) ? start - m->map_start : 0;
155
		delta = (start != 0) ? start - m->map_start : ROUNDUP(m->map_start) - m->map_start;
150 156
		if (size == 0 || m->map_size - delta >= size) {
151 157
			if (m->map_size - delta <= 0)
152 158
				continue;
153
			if (size == 0)
159
			if (size == 0) {
154 160
				size = m->map_size - delta;
161
				if (start == 0)
162
					size = ROUNDDOWN(size);
163
			}
155 164
			return (map_add(m->map_start + delta, size,
156 165
				    MAP_TYPE_GPT_PART, NULL));
157 166
		}
    (1-1/1)