aboutsummaryrefslogtreecommitdiff
path: root/sbin/newfs_msdos
diff options
context:
space:
mode:
authorAndriy Gapon <avg@FreeBSD.org>2009-02-27 17:29:48 +0000
committerAndriy Gapon <avg@FreeBSD.org>2009-02-27 17:29:48 +0000
commitd461b46dd54504dcbdae5bf710751d9ab27d9e42 (patch)
tree7a16239f0b41d3a83d772474e59ce1e018eae7cc /sbin/newfs_msdos
parentb2c91b67b6d78e9d468ef4b72b67be68a6222755 (diff)
downloadsrc-d461b46dd54504dcbdae5bf710751d9ab27d9e42.tar.gz
src-d461b46dd54504dcbdae5bf710751d9ab27d9e42.zip
newfs_msdos: allow to work with media that doesn't have any CHS params
Either use parameters provided by user or make them up. The code for faking CHS params is borrowed from disklabel code. The logic for using user-provided and auto-guessed parameters is not perfect, so to speak. PR: bin/121182 Approved by: jhb (mentor)
Notes
Notes: svn path=/head/; revision=189112
Diffstat (limited to 'sbin/newfs_msdos')
-rw-r--r--sbin/newfs_msdos/newfs_msdos.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/sbin/newfs_msdos/newfs_msdos.c b/sbin/newfs_msdos/newfs_msdos.c
index 9c021c028381..1a8b81f23eda 100644
--- a/sbin/newfs_msdos/newfs_msdos.c
+++ b/sbin/newfs_msdos/newfs_msdos.c
@@ -793,13 +793,25 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag,
/* Maybe it's a fixed drive */
if (lp == NULL) {
if (ioctl(fd, DIOCGDINFO, &dlp) == -1) {
- if (ioctl(fd, DIOCGSECTORSIZE, &dlp.d_secsize) == -1)
+ if (bpb->bps == 0 && ioctl(fd, DIOCGSECTORSIZE, &dlp.d_secsize) == -1)
errx(1, "Cannot get sector size, %s", strerror(errno));
- if (ioctl(fd, DIOCGFWSECTORS, &dlp.d_nsectors) == -1)
- errx(1, "Cannot get number of sectors, %s", strerror(errno));
- if (ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks)== -1)
- errx(1, "Cannot get number of heads, %s", strerror(errno));
+
+ /* XXX Should we use bpb->bps if it's set? */
dlp.d_secperunit = ms / dlp.d_secsize;
+
+ if (bpb->spt == 0 && ioctl(fd, DIOCGFWSECTORS, &dlp.d_nsectors) == -1) {
+ warnx("Cannot get number of sectors per track, %s", strerror(errno));
+ dlp.d_nsectors = 63;
+ }
+ if (bpb->hds == 0 && ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks) == -1) {
+ warnx("Cannot get number of heads, %s", strerror(errno));
+ if (dlp.d_secperunit <= 63*1*1024)
+ dlp.d_ntracks = 1;
+ else if (dlp.d_secperunit <= 63*16*1024)
+ dlp.d_ntracks = 16;
+ else
+ dlp.d_ntracks = 255;
+ }
}
hs = (ms / dlp.d_secsize) - dlp.d_secperunit;