diff options
author | Luigi Rizzo <luigi@FreeBSD.org> | 2008-11-26 21:05:03 +0000 |
---|---|---|
committer | Luigi Rizzo <luigi@FreeBSD.org> | 2008-11-26 21:05:03 +0000 |
commit | 045651ec1e591dcc3b9d26325bd8dea9063cfefa (patch) | |
tree | 93a18bce159d37ac4ff0982b0a3ad96f4bf66a53 /sbin/newfs_msdos | |
parent | 0206cdb8461ff06a42eafe71aa9163523ca3940e (diff) | |
download | src-045651ec1e591dcc3b9d26325bd8dea9063cfefa.tar.gz src-045651ec1e591dcc3b9d26325bd8dea9063cfefa.zip |
Create a fake geometry (16 heads, 64 sectors) when dealing with
a plain file and a geometry is not explicitly supplied through
command line or disktab entry.
This way you can a FAT image on a file as simply as this:
newfs_msdos ./some/file
(right now you need a much longer command
newfs_msdos -h 32 -u 64 -S 512 -s $total_blocks -o 0 ./some/file
Will be merged after 7.1 and 6.4 are released.
See also the related PR which suggests a similar change.
PR: bin/121182
MFC after: 4 weeks
Notes
Notes:
svn path=/head/; revision=185345
Diffstat (limited to 'sbin/newfs_msdos')
-rw-r--r-- | sbin/newfs_msdos/newfs_msdos.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/sbin/newfs_msdos/newfs_msdos.c b/sbin/newfs_msdos/newfs_msdos.c index 1c23b241e638..a29448c3a699 100644 --- a/sbin/newfs_msdos/newfs_msdos.c +++ b/sbin/newfs_msdos/newfs_msdos.c @@ -725,9 +725,20 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, /* Maybe it's a floppy drive */ if (lp == NULL) { - if (ioctl(fd, DIOCGMEDIASIZE, &ms) == -1) - errx(1, "Cannot get disk size, %s", strerror(errno)); - if (ioctl(fd, FD_GTYPE, &type) != -1) { + if (ioctl(fd, DIOCGMEDIASIZE, &ms) == -1) { + struct stat st; + + bzero(&st, sizeof(st)); + if (fstat(fd, &st)) + err(1, "Cannot get disk size"); + /* create a fake geometry for a file image */ + ms = st.st_size; + dlp.d_secsize = 512; + dlp.d_nsectors = 64; + dlp.d_ntracks = 32; + dlp.d_secperunit = ms / dlp.d_secsize; + lp = &dlp; + } else if (ioctl(fd, FD_GTYPE, &type) != -1) { dlp.d_secsize = 128 << type.secsize; dlp.d_nsectors = type.sectrac; dlp.d_ntracks = type.heads; |