newfs_msdos.c (104429) | newfs_msdos.c (106372) |
---|---|
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[] = | 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 104429 2002-10-04 00:29:26Z peter $"; | 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> | 31#endif /* not lint */ 32 33#include <sys/param.h> |
34#include <sys/diskslice.h> | 34#include <sys/fdcio.h> 35#include <sys/disk.h> |
35#include <sys/disklabel.h> 36#include <sys/mount.h> 37#include <sys/stat.h> 38#include <sys/time.h> 39 40#include <ctype.h> 41#include <err.h> 42#include <errno.h> --- 661 unchanged lines hidden (view full) --- 704 705/* 706 * Get disk slice, partition, and geometry information. 707 */ 708static void 709getdiskinfo(int fd, const char *fname, const char *dtype, int oflag, 710 struct bpb *bpb) 711{ | 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{ |
712 struct diskslices ds; 713 struct disklabel dl, *lp; 714 const char *s1, *s2; 715 char *s; 716 int slice, part, fd1, i, e; | 713 struct disklabel *lp, dlp; 714 struct fd_type type; 715 off_t ms, hs; |
717 | 716 |
718 slice = part = -1; 719 s1 = fname; 720 if ((s2 = strrchr(s1, '/'))) 721 s1 = s2 + 1; 722 for (s2 = s1; *s2 && !isdigit(*s2); s2++); 723 if (!*s2 || s2 == s1) 724 s2 = NULL; 725 else 726 while (isdigit(*++s2)); 727 s1 = s2; 728 if (s2 && (*s2 == 's' || *s2 == 'p')) { 729 slice = strtol(s2 + 1, &s, 10); 730 if (slice < 1 || slice > MAX_SLICES - BASE_SLICE) 731 s2 = NULL; 732 else { 733 slice = BASE_SLICE + slice - 1; 734 s2 = s; 735 } | 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; |
736 } | 723 } |
737 if (s2 && *s2 >= 'a' && *s2 <= 'a' + MAXPARTITIONS - 1) { 738 if (slice == -1) 739 slice = COMPATIBILITY_SLICE; 740 part = *s2++ - 'a'; 741 } 742 if (!s2 || (*s2 && *s2 != '.')) 743 errx(1, "%s: can't figure out partition info", fname); 744 if (slice != -1 && (!oflag || (!bpb->bsec && part == -1))) { 745 if (ioctl(fd, DIOCGSLICEINFO, &ds) == -1) { 746 warn("ioctl (GSLICEINFO)"); 747 errx(1, "%s: can't get slice info", fname); | 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; |
748 } | 736 } |
749 if (slice >= ds.dss_nslices || !ds.dss_slices[slice].ds_size) 750 errx(1, "%s: slice is unavailable", fname); 751 if (!oflag) 752 bpb->hid = ds.dss_slices[slice].ds_offset; 753 if (!bpb->bsec && part == -1) 754 bpb->bsec = ds.dss_slices[slice].ds_size; | |
755 } | 737 } |
756 if (((slice == -1 || part != -1) && 757 ((!oflag && part != -1) || !bpb->bsec)) || 758 !bpb->bps || !bpb->spt || !bpb->hds) { 759 lp = &dl; 760 i = ioctl(fd, DIOCGDINFO, lp); 761 if (i == -1 && slice != -1 && part == -1) { 762 e = errno; 763 if (!(s = strdup(fname))) 764 err(1, NULL); 765 s[s1 - fname] = 0; 766 if ((fd1 = open(s, O_RDONLY)) != -1) { 767 i = ioctl(fd1, DIOCGDINFO, lp); 768 close(fd1); 769 } 770 free(s); 771 errno = e; | 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; |
772 } | 749 } |
773 if (i == -1) { 774 if (!dtype) { 775 warn("ioctl (GDINFO)"); 776 errx(1, "%s: can't read disk label; " 777 "disk type must be specified", fname); 778 } else if (!(lp = getdiskbyname(dtype))) 779 errx(1, "%s: unknown disk type", dtype); 780 } 781 if (slice == -1 || part != -1) { 782 if (part == -1) 783 part = RAW_PART; 784 if (part >= lp->d_npartitions || 785 !lp->d_partitions[part].p_size) 786 errx(1, "%s: partition is unavailable", fname); 787 if (!oflag && part != -1) 788 bpb->hid += lp->d_partitions[part].p_offset; 789 if (!bpb->bsec) 790 bpb->bsec = lp->d_partitions[part].p_size; 791 } 792 if (!bpb->bps) 793 bpb->bps = ckgeom(fname, lp->d_secsize, "bytes/sector"); 794 if (!bpb->spt) 795 bpb->spt = ckgeom(fname, lp->d_nsectors, "sectors/track"); 796 if (!bpb->hds) 797 bpb->hds = ckgeom(fname, lp->d_ntracks, "drive heads"); | 750 751 hs = (ms / dlp.d_secsize) - dlp.d_secperunit; 752 lp = &dlp; |
798 } | 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; |
|
799} 800 801/* 802 * Print out BPB values. 803 */ 804static void 805print_bpb(struct bpb *bpb) 806{ --- 23 unchanged lines hidden (view full) --- 830 * Check a disk geometry value. 831 */ 832static u_int 833ckgeom(const char *fname, u_int val, const char *msg) 834{ 835 if (!val) 836 errx(1, "%s: no default %s", fname, msg); 837 if (val > MAXU16) | 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) |
838 errx(1, "%s: illegal %s", fname, msg); | 804 errx(1, "%s: illegal %s %d", fname, msg, val); |
839 return val; 840} 841 842/* 843 * Convert and check a numeric option argument. 844 */ 845static u_int 846argtou(const char *arg, u_int lo, u_int hi, const char *msg) --- 84 unchanged lines hidden --- | 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 --- |