small newfs_msdos addition

From: Luigi Rizzo <rizzo_at_iet.unipi.it>
Date: Tue, 25 Nov 2008 10:41:25 +0100
If there are no objections I'd like to commit the small patch below
to newfs_msdos.c -- all it does is create a fake geometry if
it cannot get the media size, which is handy when you want to
create a filesystem image on a regular file.

Before the patch you need to do

  newfs_msdos -h 32 -s 64 -o 0 -S 512 -s `du -k /the/file` /the/file

after the patch it becomes

  newfs_msdos /the/file

which is a bit more friendly especially if you have to type it manually.

	cheers
	luigi


> svn diff head/sbin
Index: head/sbin/newfs_msdos/newfs_msdos.c
===================================================================
--- head/sbin/newfs_msdos/newfs_msdos.c (revision 185290)
+++ head/sbin/newfs_msdos/newfs_msdos.c (working copy)
_at__at_ -725,9 +725,20 _at__at_
 
     /* 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;
Received on Tue Nov 25 2008 - 08:36:48 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:38 UTC