-/* $OpenBSD: cmd.c,v 1.4 1997/04/07 01:26:00 weingart Exp $ */
+/* $OpenBSD: cmd.c,v 1.5 1997/04/08 22:48:29 mickey Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff
strncpy (cmd->path, cmd->argv[1],
sizeof(cmd->path));
else
- sprintf(cmd->path, "%s%s/.",
+ sprintf(cmd->path, "%s:%s/.",
cmd->bootdev, cmd->cwd);
if (stat(cmd->path, &sb) < 0) {
break;
}
- sprintf(cmd->path, "%s%s%s",
+ sprintf(cmd->path, "%s:%s%s",
cmd->bootdev, cmd->cwd, cmd->argv[1]);
if (stat(cmd->path, &sb) < 0) {
printf("stat(%s): %d\n", cmd->argv[1], errno);
if (cmd->argc > 1)
strncpy(cmd->path, cmd->argv[1], sizeof(cmd->path));
else
- sprintf(cmd->path, "%s%s%s", cmd->bootdev,
+ sprintf(cmd->path, "%s:%s%s", cmd->bootdev,
cmd->cwd, cmd->image);
cmd->rc = 1;
break;
-/* $OpenBSD: biosdev.c,v 1.3 1997/03/31 23:06:26 mickey Exp $ */
+/* $OpenBSD: biosdev.c,v 1.4 1997/04/08 22:48:27 mickey Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
biosopen(struct open_file *f, ...)
{
va_list ap;
- register char *p, *cp, *fname, **file;
- char devname[sizeof(bdevs[0])];
+ register char *cp, **file;
dev_t maj, unit, part;
register struct biosdisk *bd;
daddr_t off = LABELSECTOR;
u_int8_t *buf;
int i;
- size_t rsize;
va_start(ap, f);
- cp = fname = *(file = va_arg(ap, char **));
+ cp = *(file = va_arg(ap, char **));
va_end(ap);
#ifdef BIOS_DEBUG
f->f_devdata = NULL;
/* search for device specification */
- for ( p = devname; *cp != 0 && *cp != '(';)
- *p++ = *cp++;
- *p = '\0';
- if (*cp != 0) {
- if (*cp++ == '(') {
- for (maj = 0; maj < NENTS(bdevs) &&
- strncmp(devname, bdevs[maj], sizeof(devname));
- maj++);
- if (maj >= NENTS(bdevs)) {
- printf("Unknown device: %s\n", devname);
- return ENXIO;
- }
- } else {
- printf("Syntax error\n");
- return EINVAL;
- }
+ cp += 2;
+ if (cp[2] != ':') {
+ if (cp[3] != ':')
+ return ENOENT;
+ else
+ cp++;
+ }
- /* get unit */
- if ('0' <= *cp && *cp <= '9')
- unit = *cp++ - '0';
- else {
- printf("Bad unit number\n");
- return ENXIO;
- }
- cp++; /* skip ',' */
- /* get partition */
- if ('a' <= *cp && *cp <= 'p')
- part = *cp++ - 'a';
- else {
- printf("Bad partition id\n");
- return ENXIO;
- }
- cp++; /* skip ')' */
- if (*cp != 0)
- *file = cp;
-
- bd = alloc(sizeof(*bd));
- bzero(bd, sizeof(bd));
-
- switch (maj) {
- case 0: /* wd */
- case 4: /* sd */
- bd->biosdev = (u_int8_t)(unit | 0x80);
- break;
- case 2: /* fd */
- bd->biosdev = (u_int8_t)unit;
- break;
- case 3: /* wt */
+ for (maj = 0; maj < NENTS(bdevs) &&
+ strncmp(*file, bdevs[maj], cp - *file); maj++);
+ if (maj >= NENTS(bdevs)) {
+ printf("Unknown device: ");
+ for (cp = *file; *cp != ':'; cp++)
+ putchar(*cp);
+ putchar('\n');
+ return ENXIO;
+ }
+
+ /* get unit */
+ if ('0' <= *cp && *cp <= '9')
+ unit = *cp++ - '0';
+ else {
+ printf("Bad unit number\n");
+ return ENXIO;
+ }
+ /* get partition */
+ if ('a' <= *cp && *cp <= 'p')
+ part = *cp++ - 'a';
+ else {
+ printf("Bad partition id\n");
+ return ENXIO;
+ }
+
+ cp++; /* skip ':' */
+ if (*cp != 0)
+ *file = cp;
+ else
+ f->f_flags |= F_RAW;
+
+ bd = alloc(sizeof(*bd));
+ bzero(bd, sizeof(bd));
+ bd->bsddev = MAKEBOOTDEV(maj, 0, 0, unit, part);
+
+ switch (maj) {
+ case 0: /* wd */
+ case 4: /* sd */
+ bd->biosdev = (u_int8_t)(unit | 0x80);
+ break;
+ case 2: /* fd */
+ bd->biosdev = (u_int8_t)unit;
+ break;
+ case 3: /* wt */
#ifdef DEBUG
- if (debug)
- printf("Wangtek is unsupported\n");
+ if (debug)
+ printf("Wangtek is unsupported\n");
#endif
- default:
- free(bd, 0);
- return ENXIO;
- }
-
- bd->bsddev = MAKEBOOTDEV(maj, 0, 0, unit, part);
- bd->dinfo = biosdinfo((dev_t)bd->biosdev);
+ default:
+ free(bd, 0);
+ return ENXIO;
+ }
- } else
- return ENOENT;
+ bd->dinfo = biosdinfo((dev_t)bd->biosdev);
#ifdef BIOS_DEBUG
if (debug) {
if (maj == 0 || maj == 4) { /* wd, sd */
if ((errno = biosstrategy(bd, F_READ, DOSBBSECTOR,
- DEV_BSIZE, &bd->mbr, &rsize)) != 0) {
+ DEV_BSIZE, &bd->mbr, NULL)) != 0) {
#ifdef DEBUG
if (debug)
printf("cannot read MBR\n");
return EINVAL;
}
- for (off = 0, i = 0; i < NDOSPART; i++)
- if (bd->mbr.dparts[i].dp_typ == DOSPTYP_OPENBSD) {
+ for (off = 0, i = 0; off == 0 && i < NDOSPART; i++)
+ if (bd->mbr.dparts[i].dp_typ == DOSPTYP_OPENBSD)
off = bd->mbr.dparts[i].dp_start + LABELSECTOR;
- break;
- }
if (off == 0) {
#ifdef DEBUG
#endif
/* read disklabel */
if ((errno = biosstrategy(bd, F_READ, off,
- DEV_BSIZE, buf, &rsize)) != 0) {
+ DEV_BSIZE, buf, NULL)) != 0) {
#ifdef DEBUG
if (debug)
printf("failed to read disklabel\n");
return errno;
}
- if ((p = getdisklabel(buf, &bd->disklabel)) != NULL) {
+ if ((cp = getdisklabel(buf, &bd->disklabel)) != NULL) {
#ifdef DEBUG
if (debug)
- printf("%s\n", p);
+ printf("%s\n", cp);
#endif
free(buf, 0);
free(bd, 0);
register const struct bd_error *p = bd_errors;
nsect = (size + DEV_BSIZE-1) / DEV_BSIZE;
- blk += bd->disklabel.d_partitions[B_PARTITION(bd->bsddev)].p_offset;
+ if (rsize != NULL)
+ blk += bd->disklabel.
+ d_partitions[B_PARTITION(bd->bsddev)].p_offset;
#ifdef BIOS_DEBUG
if (debug)
for (i = 0; error == 0 && i < nsect;
i += n, blk += n, buf += n * DEV_BSIZE) {
register int cyl, hd, sect;
-#if 0
- /* fight seg boundary error XXX */
- static u_int8_t bbuf[DEV_BSIZE];
-#endif
btochs(blk, cyl, hd, sect,
BIOSNHEADS(bd->dinfo), BIOSNSECTS(bd->dinfo));
if (debug)
printf(" (%d,%d,%d,%d)@%p", cyl, hd, sect, n, buf);
#endif
- if (rw == F_READ) {
+ if (rw == F_READ)
error = biosread (bd->biosdev, cyl, hd, sect, n, buf);
- /* bcopy(bbuf, buf, sizeof(bbuf)); */
- } else {
- /* bcopy(buf, bbuf, sizeof(bbuf)); */
+ else
error = bioswrite(bd->biosdev, cyl, hd, sect, n, buf);
- }
+
if (error != 0) {
for (p = bd_errors; p < &bd_errors[bd_nents] &&
p->bd_id != error; p++);
}
#endif
- *rsize = i * DEV_BSIZE;
+ if (rsize != NULL)
+ *rsize = i * DEV_BSIZE;
return p->unix_id;
}
-/* $OpenBSD: cmd.c,v 1.4 1997/04/07 01:26:00 weingart Exp $ */
+/* $OpenBSD: cmd.c,v 1.5 1997/04/08 22:48:29 mickey Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff
strncpy (cmd->path, cmd->argv[1],
sizeof(cmd->path));
else
- sprintf(cmd->path, "%s%s/.",
+ sprintf(cmd->path, "%s:%s/.",
cmd->bootdev, cmd->cwd);
if (stat(cmd->path, &sb) < 0) {
break;
}
- sprintf(cmd->path, "%s%s%s",
+ sprintf(cmd->path, "%s:%s%s",
cmd->bootdev, cmd->cwd, cmd->argv[1]);
if (stat(cmd->path, &sb) < 0) {
printf("stat(%s): %d\n", cmd->argv[1], errno);
if (cmd->argc > 1)
strncpy(cmd->path, cmd->argv[1], sizeof(cmd->path));
else
- sprintf(cmd->path, "%s%s%s", cmd->bootdev,
+ sprintf(cmd->path, "%s:%s%s", cmd->bootdev,
cmd->cwd, cmd->image);
cmd->rc = 1;
break;