2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
17 #include <sys/types.h>
18 #include <sys/diskslice.h>
19 #include <sys/disklabel.h>
24 Track_Aligned(struct disk *d, u_long offset)
28 if (offset % d->bios_sect)
34 Prev_Track_Aligned(struct disk *d, u_long offset)
38 return (offset / d->bios_sect) * d->bios_sect;
42 Next_Track_Aligned(struct disk *d, u_long offset)
46 return Prev_Track_Aligned(d,offset + d->bios_sect-1);
50 Cyl_Aligned(struct disk *d, u_long offset)
52 if (!d->bios_sect || !d->bios_hd)
54 if (offset % (d->bios_sect * d->bios_hd))
60 Prev_Cyl_Aligned(struct disk *d, u_long offset)
62 if (!d->bios_sect || !d->bios_hd)
64 return (offset / (d->bios_sect*d->bios_hd)) * d->bios_sect * d->bios_hd;
68 Next_Cyl_Aligned(struct disk *d, u_long offset)
70 if (!d->bios_sect || !d->bios_hd)
72 return Prev_Cyl_Aligned(d,offset + (d->bios_sect * d->bios_hd)-1);
77 * Chunks of type 'whole' can have max NDOSPART children.
78 * Only one of them can have the "active" flag
81 Rule_000(struct disk *d, struct chunk *c, char *msg)
92 for (c1=c->part; c1; c1=c1->next) {
93 if (c1->type != unused) continue;
95 if (c1->flags & CHUNK_ACTIVE)
101 sprintf(msg+strlen(msg),
102 "%d is too many children of the 'whole' chunk. Max is %d\n",
106 sprintf(msg+strlen(msg),
107 "Too many active children of 'whole'");
113 * All children of 'whole' and 'extended' must be track-aligned.
114 * Exception: the end can be unaligned if it matches the end of 'whole'
117 Rule_001(struct disk *d, struct chunk *c, char *msg)
122 if (c->type != whole && c->type != extended)
124 for (i=0, c1=c->part; c1; c1=c1->next) {
125 if (c1->type == unused) continue;
126 c1->flags |= CHUNK_ALIGN;
128 if (!Cyl_Aligned(d,c1->offset))
130 if (!Track_Aligned(d,c1->offset))
132 sprintf(msg+strlen(msg),
134 "chunk '%s' [%ld..%ld] does not start on a cylinder boundary\n",
136 "chunk '%s' [%ld..%ld] does not start on a track boundary\n",
138 c1->name,c1->offset,c1->end);
139 if ((c->type == whole || c->end == c1->end)
140 || Cyl_Aligned(d,c1->end+1))
143 sprintf(msg+strlen(msg),
144 "chunk '%s' [%ld..%ld] does not end on a cylinder boundary\n",
145 c1->name,c1->offset,c1->end);
151 * Max one 'fat' as child of 'whole'
154 Rule_002(struct disk *d, struct chunk *c, char *msg)
160 if (c->type != whole)
162 for (i=0, c1=c->part; c1; c1=c1->next) {
168 sprintf(msg+strlen(msg),
169 "Max one 'fat' allowed as child of 'whole'\n");
176 * Max one extended as child of 'whole'
179 Rule_003(struct disk *d, struct chunk *c, char *msg)
185 if (c->type != whole)
187 for (i=0, c1=c->part; c1; c1=c1->next) {
188 if (c1->type != extended)
193 sprintf(msg+strlen(msg),
194 "Max one 'extended' allowed as child of 'whole'\n");
201 * Max seven 'part' as children of 'freebsd'
202 * Max one CHUNK_IS_ROOT child per 'freebsd'
203 * If Bad144, space for table must exist.
204 * If Bad144 & root, bad144 table must be inside 1024
207 Rule_004(struct disk *d, struct chunk *c, char *msg)
212 if (c->type != freebsd)
215 for (c1=c->part; c1; c1=c1->next) {
216 if (c1->type != part)
218 if (c1->flags & CHUNK_IS_ROOT) {
221 if (c1->flags & CHUNK_PAST_1024)
222 sprintf(msg+strlen(msg),
223 "Root filesystem extends past cylinder 1024, and cannot be booted from\n");
229 sprintf(msg+strlen(msg),
230 "Max seven partitions per freebsd slice\n");
233 sprintf(msg+strlen(msg),
234 "Max one root partition child per freebsd slice\n");
239 Check_Chunk(struct disk *d, struct chunk *c, char *msg)
247 Check_Chunk(d,c->part,msg);
249 Check_Chunk(d,c->next,msg);
252 if (c->end >= 1024*d->bios_hd*d->bios_sect)
253 c->flags |= CHUNK_PAST_1024;
255 c->flags &= ~CHUNK_PAST_1024;
260 CheckRules(struct disk *d)
265 Check_Chunk(d,d->chunks,msg);
272 ChunkCanBeRoot(struct chunk *c)
275 struct disk *d = c->disk;
280 if (c->flags & CHUNK_PAST_1024) {
282 "The root partition must end before cylinder 1024 seen from\n");
284 "the BIOS' point of view, or it cannot be booted from.\n");
288 for (c1=d->chunks->part;;) {
289 for (; c1; c1=c1->next)
290 if (c1->offset <= c->offset && c1->end >= c->end)
294 "Internal trouble, cannot find this chunk in the chunk-tree\n");
297 if (c1->type == freebsd)
303 if (c1->type != freebsd) {
305 "The root partition must be in a FreeBSD slice, otherwise\n");
307 "the kernel cannot be booted from it\n");