/*
* Copyright (c) 1996 Leo Weppelman, Waldi Ravens.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by
* Leo Weppelman and Waldi Ravens.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This code implements a simple editor for partition id's on disks containing
* AHDI partition info.
*
* Credits for the code handling disklabels goes to Waldi Ravens.
*
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/disklabel.h>
void ahdi_cksum(void *);
u_int ahdi_getparts(int, ptable_t *, u_int, u_int);
int bsd_label(int, u_int);
int dkcksum(struct disklabel *);
int edit_parts(int, ptable_t *);
void *disk_read(int, u_int, u_int);
void disk_write(int, u_int, u_int, void *);
char *get_id(void);
int lex(int *);
int show_parts(ptable_t *, int);
void update_disk(ptable_t *, int, int);
int
main(int argc, char *argv[])
{
int fd;
ptable_t ptable;
int rv;
struct stat st;
if (argc != 2) {
char *prog = strrchr(argv[0], '/');
if (prog == NULL)
prog = argv[0];
else prog++;
fprintf(stderr, "Usage: %s <raw_disk_device>", prog);
exit(1);
}
if ((fd = open(argv[1], O_RDWR)) < 0)
err(1, "Cannot open '%s'.", argv[1]);
if (fstat(fd, &st) < 0)
err(1, "Cannot stat '%s'.", argv[1]);
if (!S_ISCHR(st.st_mode))
errx(1, "'%s' must be a character special device.", argv[1]);
if ((rv = bsd_label(fd, LABELSECTOR)) < 0)
errx(1, "I/O error");
if (rv == 0) {
warnx("Disk has no ahdi partitions");
return (2);
}
if (rsec == AHDI_BBLOCK)
end = &root->ar_parts[AHDI_MAXRPD];
else end = &root->ar_parts[AHDI_MAXARPD];
for (part = root->ar_parts; part < end; ++part) {
u_int id;
/*
* Look for additional mods on the same sector
*/
for (i = 0; i < ptable->nparts; i++) {
lpart = &ptable->parts[i];
if (lpart->mod && (lpart->rsec == rsec)) {
apart = &root->ar_parts[lpart->rent];