1/*
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.org> 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 * ----------------------------------------------------------------------------
8 */
9
10#include <sys/cdefs.h>
11__FBSDID("$FreeBSD$");
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
16#include <fcntl.h>
17#include <string.h>
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <sys/ioctl.h>
21#include <sys/disklabel.h>
22#include <paths.h>
23#include "libdisk.h"
24
25void
26Fill_Disklabel(struct disklabel *dl, const struct disk *new,
27    const struct chunk *c1)
28{
29	struct chunk *c2;
30	int j;
31
32	memset(dl, 0, sizeof *dl);
33
34	for (c2 = c1->part; c2; c2 = c2->next) {
35		if (c2->type == unused)
36			continue;
37		if (!strcmp(c2->name, "X"))
38			continue;
39		j = c2->name[strlen(c2->name) - 1] - 'a';
40		if (j < 0 || j >= MAXPARTITIONS || j == RAW_PART)
41			continue;
42		dl->d_partitions[j].p_size = c2->size;
43		dl->d_partitions[j].p_offset = c2->offset;
44		dl->d_partitions[j].p_fstype = c2->subtype;
45	}
46
47	dl->d_bbsize = BBSIZE;
48	/*
49	 * Add in defaults for superblock size, interleave, and rpms
50	 */
51	dl->d_sbsize = 0;
52
53	strcpy(dl->d_typename, c1->name);
54
55	dl->d_secsize = 512;
56	dl->d_secperunit = new->chunks->size;
57#ifndef __ia64__
58	dl->d_ncylinders = new->bios_cyl;
59	dl->d_ntracks = new->bios_hd;
60	dl->d_nsectors = new->bios_sect;
61#endif
62	dl->d_secpercyl = dl->d_ntracks * dl->d_nsectors;
63
64	dl->d_npartitions = MAXPARTITIONS;
65
66	dl->d_type = new->name[0] == 's' || new->name[0] == 'd' ||
67	    new->name[0] == 'o' ? DTYPE_SCSI : DTYPE_ESDI;
68	dl->d_partitions[RAW_PART].p_size = c1->size;
69	dl->d_partitions[RAW_PART].p_offset = c1->offset;
70	dl->d_rpm = 3600;
71	dl->d_interleave = 1;
72
73	dl->d_magic = DISKMAGIC;
74	dl->d_magic2 = DISKMAGIC;
75	dl->d_checksum = dkcksum(dl);
76}
77