toolbox: newfs_msdos: Exit on write failure, and handle bogus geometry from the kernel

Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
San Mehat 2010-01-10 11:10:21 -08:00
parent 1851d80959
commit eab453c612
1 changed files with 13 additions and 1 deletions

View File

@ -745,8 +745,10 @@ newfs_msdos_main(int argc, char *argv[])
}
if ((n = write(fd, img, bpb.bps)) == -1)
err(1, "%s", fname);
if ((unsigned)n != bpb.bps)
if ((unsigned)n != bpb.bps) {
errx(1, "%s: can't write sector %u", fname, lsn);
exit(1);
}
}
}
return 0;
@ -828,6 +830,16 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag,
geom.sectors = 63;
}
if (!geom.heads) {
printf("Bogus heads from kernel - setting sane value\n");
geom.heads = 64;
}
if (!geom.sectors) {
printf("Bogus sectors from kernel - setting sane value\n");
geom.sectors = 63;
}
bpb->spt = geom.sectors;
ckgeom(fname, bpb->spt, "sectors/track");