Date: Wed, 26 Nov 2008 21:05:04 +0000 (UTC) From: Luigi Rizzo <luigi@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r185345 - head/sbin/newfs_msdos Message-ID: <200811262105.mAQL54ko066233@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: luigi Date: Wed Nov 26 21:05:03 2008 New Revision: 185345 URL: http://svn.freebsd.org/changeset/base/185345 Log: 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 Modified: head/sbin/newfs_msdos/newfs_msdos.c Modified: head/sbin/newfs_msdos/newfs_msdos.c ============================================================================== --- head/sbin/newfs_msdos/newfs_msdos.c Wed Nov 26 20:52:26 2008 (r185344) +++ head/sbin/newfs_msdos/newfs_msdos.c Wed Nov 26 21:05:03 2008 (r185345) @@ -725,9 +725,20 @@ getdiskinfo(int fd, const char *fname, c /* 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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200811262105.mAQL54ko066233>