159848Sralph /*-
2*63226Sbostic * Copyright (c) 1993
3*63226Sbostic * The Regents of the University of California. All rights reserved.
459848Sralph *
559848Sralph * This code is derived from software contributed to Berkeley by
659848Sralph * Ralph Campbell.
759848Sralph *
859848Sralph * %sccs.include.redist.c%
959848Sralph *
10*63226Sbostic * @(#)dec_label.c 8.1 (Berkeley) 06/10/93
1159848Sralph */
1259848Sralph
1359848Sralph #include <stdio.h>
1459848Sralph #include <unistd.h>
1559848Sralph #include <sys/param.h>
1659848Sralph #include <sys/fcntl.h>
1759848Sralph #include <sys/ioctl.h>
1859848Sralph #include <sys/disklabel.h>
1959848Sralph
2059848Sralph #include <pmax/stand/dec_boot.h>
2159848Sralph
2259848Sralph struct disklabel label;
2359848Sralph struct Dec_DiskLabel dec_label;
2459848Sralph
2559848Sralph /*
2659848Sralph * This program creates or updates the DEC label after 'disklabel'
2759848Sralph * has initialized the Berkeley disk label.
2859848Sralph * This program may be useful in sharing ULTRIX disks with 4.4 BSD but it
2959848Sralph * hasn't been tested much. Use at your own risk.
3059848Sralph *
3159848Sralph * Usage: dec_label <disk>
3259848Sralph */
3359848Sralph
main(argc,argv)3459848Sralph main(argc, argv)
3559848Sralph int argc;
3659848Sralph char *argv[];
3759848Sralph {
3859848Sralph register int i;
3959848Sralph int fd;
4059848Sralph
4159848Sralph if (argc != 2) {
4259848Sralph fprintf(stderr, "Usage: dec_label <disk>\n");
4359848Sralph exit(1);
4459848Sralph }
4559848Sralph if ((fd = open(argv[1], O_RDWR, 0)) < 0)
4659848Sralph err(1, "%s", argv[1]);
4759848Sralph if (ioctl(fd, DIOCGDINFO, &label) < 0)
4859848Sralph err(1, "ioctl DIOCGDINFO");
4959848Sralph
5059848Sralph /* fill in DEC label */
5159848Sralph dec_label.magic = DEC_LABEL_MAGIC;
5259848Sralph dec_label.isPartitioned = 1;
5359848Sralph for (i = 0; i < DEC_NUM_DISK_PARTS; i++) {
5459848Sralph dec_label.map[i].numBlocks = label.d_partitions[i].p_size;
5559848Sralph dec_label.map[i].startBlock = label.d_partitions[i].p_offset;
5659848Sralph printf("%d: start %d size %d\n", i, dec_label.map[i].startBlock,
5759848Sralph dec_label.map[i].numBlocks);
5859848Sralph }
5959848Sralph if (lseek(fd, (off_t)DEC_LABEL_SECTOR * label.d_secsize, SEEK_SET) == -1)
6059848Sralph err(1, "lseek");
6159848Sralph if (write(fd, &dec_label, sizeof(dec_label)) != sizeof(dec_label))
6259848Sralph err(1, "write label");
6359848Sralph return (0);
6459848Sralph }
65