1/* 2 * Copyright (c) 1998 Robert Nordier 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 23 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 25 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#ifndef lint 29static const char rcsid[] = |
30 "$FreeBSD: head/sbin/newfs_msdos/newfs_msdos.c 106372 2002-11-03 08:54:46Z scottl $"; |
31#endif /* not lint */ 32 33#include <sys/param.h> |
34#include <sys/fdcio.h> 35#include <sys/disk.h> |
36#include <sys/disklabel.h> 37#include <sys/mount.h> 38#include <sys/stat.h> 39#include <sys/time.h> 40 41#include <ctype.h> 42#include <err.h> 43#include <errno.h> --- 661 unchanged lines hidden (view full) --- 705 706/* 707 * Get disk slice, partition, and geometry information. 708 */ 709static void 710getdiskinfo(int fd, const char *fname, const char *dtype, int oflag, 711 struct bpb *bpb) 712{ |
713 struct disklabel *lp, dlp; 714 struct fd_type type; 715 off_t ms, hs; |
716 |
717 lp = NULL; 718 719 /* If the user specified a disk type, try to use that */ 720 if (dtype != NULL) { 721 lp = getdiskbyname(dtype); 722 hs = 0; |
723 } |
724 725 /* Maybe it's a floppy drive */ 726 if (lp == NULL) { 727 if (ioctl(fd, DIOCGMEDIASIZE, &ms) == -1) 728 errx(1, "Cannot get disk size, %s\n", strerror(errno)); 729 if (ioctl(fd, FD_GTYPE, &type) != -1) { 730 dlp.d_secsize = 128 << type.secsize; 731 dlp.d_nsectors = type.sectrac; 732 dlp.d_ntracks = type.heads; 733 dlp.d_secperunit = ms / dlp.d_secsize; 734 lp = &dlp; 735 hs = 0; |
736 } |
737 } |
738 739 /* Maybe it's a fixed drive */ 740 if (lp == NULL) { 741 if (ioctl(fd, DIOCGDINFO, &dlp) == -1) { 742 if (ioctl(fd, DIOCGSECTORSIZE, &dlp.d_secsize) == -1) 743 errx(1, "Cannot get sector size, %s\n", strerror(errno)); 744 if (ioctl(fd, DIOCGFWSECTORS, &dlp.d_nsectors) == -1) 745 errx(1, "Cannot get number of sectors, %s\n", strerror(errno)); 746 if (ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks)== -1) 747 errx(1, "Cannot get number of heads, %s\n", strerror(errno)); 748 dlp.d_secperunit = ms / dlp.d_secsize; |
749 } |
750 751 hs = (ms / dlp.d_secsize) - dlp.d_secperunit; 752 lp = &dlp; |
753 } |
754 755 if (bpb->bps == 0) 756 bpb->bps = ckgeom(fname, lp->d_secsize, "bytes/sector"); 757 if (bpb->spt == 0) 758 bpb->spt = ckgeom(fname, lp->d_nsectors, "sectors/track"); 759 if (bpb->hds == 0) 760 bpb->hds = ckgeom(fname, lp->d_ntracks, "drive heads"); 761 if (bpb->bsec == 0) 762 bpb->bsec = lp->d_secperunit; 763 if (bpb->hid == 0) 764 bpb->hid = hs; |
765} 766 767/* 768 * Print out BPB values. 769 */ 770static void 771print_bpb(struct bpb *bpb) 772{ --- 23 unchanged lines hidden (view full) --- 796 * Check a disk geometry value. 797 */ 798static u_int 799ckgeom(const char *fname, u_int val, const char *msg) 800{ 801 if (!val) 802 errx(1, "%s: no default %s", fname, msg); 803 if (val > MAXU16) |
804 errx(1, "%s: illegal %s %d", fname, msg, val); |
805 return val; 806} 807 808/* 809 * Convert and check a numeric option argument. 810 */ 811static u_int 812argtou(const char *arg, u_int lo, u_int hi, const char *msg) --- 84 unchanged lines hidden --- |