xref: /original-bsd/sys/pmax/stand/dec_label.c (revision 2f46dd9e)
1 /*-
2  * Copyright (c) 1993 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Ralph Campbell.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)dec_label.c	7.1 (Berkeley) 05/09/93
11  */
12 
13 #include <stdio.h>
14 #include <unistd.h>
15 #include <sys/param.h>
16 #include <sys/fcntl.h>
17 #include <sys/ioctl.h>
18 #include <sys/disklabel.h>
19 
20 #include <pmax/stand/dec_boot.h>
21 
22 struct	disklabel label;
23 struct	Dec_DiskLabel dec_label;
24 
25 /*
26  * This program creates or updates the DEC label after 'disklabel'
27  * has initialized the Berkeley disk label.
28  * This program may be useful in sharing ULTRIX disks with 4.4 BSD but it
29  * hasn't been tested much. Use at your own risk.
30  *
31  * Usage: dec_label <disk>
32  */
33 
34 main(argc, argv)
35 	int argc;
36 	char *argv[];
37 {
38 	register int i;
39 	int fd;
40 
41 	if (argc != 2) {
42 		fprintf(stderr, "Usage: dec_label <disk>\n");
43 		exit(1);
44 	}
45 	if ((fd = open(argv[1], O_RDWR, 0)) < 0)
46 		err(1, "%s", argv[1]);
47 	if (ioctl(fd, DIOCGDINFO, &label) < 0)
48 		err(1, "ioctl DIOCGDINFO");
49 
50 	/* fill in DEC label */
51 	dec_label.magic = DEC_LABEL_MAGIC;
52 	dec_label.isPartitioned = 1;
53 	for (i = 0; i < DEC_NUM_DISK_PARTS; i++) {
54 		dec_label.map[i].numBlocks = label.d_partitions[i].p_size;
55 		dec_label.map[i].startBlock = label.d_partitions[i].p_offset;
56 		printf("%d: start %d size %d\n", i, dec_label.map[i].startBlock,
57 			dec_label.map[i].numBlocks);
58 	}
59 	if (lseek(fd, (off_t)DEC_LABEL_SECTOR * label.d_secsize, SEEK_SET) == -1)
60 		err(1, "lseek");
61 	if (write(fd, &dec_label, sizeof(dec_label)) != sizeof(dec_label))
62 		err(1, "write label");
63 	return (0);
64 }
65