From eab453c612d6d422f863c31da67f00bc4beec914 Mon Sep 17 00:00:00 2001 From: San Mehat Date: Sun, 10 Jan 2010 11:10:21 -0800 Subject: [PATCH] toolbox: newfs_msdos: Exit on write failure, and handle bogus geometry from the kernel Signed-off-by: San Mehat --- toolbox/newfs_msdos.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/toolbox/newfs_msdos.c b/toolbox/newfs_msdos.c index 779150e6c..49042c4a8 100644 --- a/toolbox/newfs_msdos.c +++ b/toolbox/newfs_msdos.c @@ -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");