Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-4]: src/sbin/fdisk Pull up bootselector mods, as approved by re...



details:   https://anonhg.NetBSD.org/src/rev/222cceeadb67
branches:  netbsd-1-4
changeset: 468337:222cceeadb67
user:      fvdl <fvdl%NetBSD.org@localhost>
date:      Sun Apr 18 00:18:49 1999 +0000

description:
Pull up bootselector mods, as approved by releng.

diffstat:

 sbin/fdisk/Makefile                  |    4 +-
 sbin/fdisk/fdisk.8                   |   28 +-
 sbin/fdisk/fdisk.c                   |  393 +++++++++++++++++++++++--
 sbin/fdisk/mbr/Makefile              |    5 +-
 sbin/fdisk/mbr/mbr.8                 |   90 ++++++
 sbin/fdisk/mbr_bootsel/Makefile      |   26 +
 sbin/fdisk/mbr_bootsel/mbr_bootsel.S |  525 +++++++++++++++++++++++++++++++++++
 7 files changed, 1013 insertions(+), 58 deletions(-)

diffs (truncated from 1345 to 300 lines):

diff -r 54de51d81c43 -r 222cceeadb67 sbin/fdisk/Makefile
--- a/sbin/fdisk/Makefile       Sat Apr 17 20:18:09 1999 +0000
+++ b/sbin/fdisk/Makefile       Sun Apr 18 00:18:49 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.10 1998/10/15 15:23:23 ws Exp $
+#      $NetBSD: Makefile,v 1.10.2.1 1999/04/18 00:18:49 fvdl Exp $
 
 
 .if (${MACHINE} == "i386" || ${MACHINE} == "powerpc")
@@ -9,7 +9,7 @@
 .endif
 
 .if ${MACHINE} == "i386"
-SUBDIR=        mbr
+SUBDIR=        mbr mbr_bootsel
 .endif
 
 MAN=   fdisk.8
diff -r 54de51d81c43 -r 222cceeadb67 sbin/fdisk/fdisk.8
--- a/sbin/fdisk/fdisk.8        Sat Apr 17 20:18:09 1999 +0000
+++ b/sbin/fdisk/fdisk.8        Sun Apr 18 00:18:49 1999 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: fdisk.8,v 1.17 1999/03/07 11:02:05 mycroft Exp $
+.\"    $NetBSD: fdisk.8,v 1.17.2.1 1999/04/18 00:18:49 fvdl Exp $
 .\"
 .Dd April 4, 1993
 .Dt FDISK 8
@@ -8,7 +8,7 @@
 .Nd DOS partition maintenance program
 .Sh SYNOPSIS
 .Nm ""
-.Op Fl aiufS
+.Op Fl aiufBS
 .Bk -words
 .Op Fl 0 | 1 | 2 | 3
 .Ek
@@ -51,16 +51,13 @@
 When called with no arguments, it prints the sector 0 partition table.
 An example follows:
 .Bd -literal
-       ******* Working on device /dev/rwd0d *******
-       Warning: BIOS sector numbering starts with sector 1
-       parameters extracted from in-core disklabel are:
-       cylinders=769 heads=15 sectors/track=33 (495 sectors/cylinder)
+       NetBSD disklabel disk geometry:
+       cylinders: 769 heads: 15 sectors/track: 33 (495 sectors/cylinder)
 
-       parameters to be used for BIOS calculations are:
-       cylinders=769 heads=15 sectors/track=33 (495 sectors/cylinder)
-               
-       Information from DOS bootblock is:
-       The data for partition 0 is:
+       BIOS geometry:
+       cylinders: 769 heads: 15 sectors/track: 33 (495 sectors/cylinder)
+
+       Partition table:
        0: sysid 169 (NetBSD)
            start 495, size 380160 (185 MB), flag 0
                beg: cylinder    1, head   0, sector  1
@@ -183,6 +180,11 @@
 if run on an i386, end leave the bootcode empty for other
 machines.
 .Pp
+The
+.Fl B
+flag can be used to install/update the bootselect code on i386
+platforms.
+.Pp
 The flags
 .Fl 0 ,
 .Fl 1 ,
@@ -253,9 +255,11 @@
 You should run this program interactively once or twice to see how it works.
 This is completely safe as long as you answer the last question in the negative.
 .Sh FILES
-.Bl -tag -width /usr/mdec/mbrxx -compact
+.Bl -tag -width /usr/mdec/mbrxxxxxxxx -compact
 .It Pa /usr/mdec/mbr
 Default location of i386 bootcode
+.It Pa /usr/mdec/mbr_bootsel
+Default location of i386 bootselect code
 .El
 .Sh SEE ALSO
 .Xr disklabel 8
diff -r 54de51d81c43 -r 222cceeadb67 sbin/fdisk/fdisk.c
--- a/sbin/fdisk/fdisk.c        Sat Apr 17 20:18:09 1999 +0000
+++ b/sbin/fdisk/fdisk.c        Sun Apr 18 00:18:49 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fdisk.c,v 1.33 1999/02/09 19:11:46 perry Exp $ */
+/*     $NetBSD: fdisk.c,v 1.33.2.1 1999/04/18 00:18:49 fvdl Exp $ */
 
 /*
  * Mach Operating System
@@ -29,7 +29,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: fdisk.c,v 1.33 1999/02/09 19:11:46 perry Exp $");
+__RCSID("$NetBSD: fdisk.c,v 1.33.2.1 1999/04/18 00:18:49 fvdl Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -50,6 +50,12 @@
 #include <unistd.h>
 #include <util.h>
 
+#ifdef __i386__
+#include <ctype.h>
+#include <machine/cpu.h>
+#include <sys/sysctl.h>
+#endif
+
 #define LBUF 100
 static char lbuf[LBUF];
 
@@ -74,7 +80,27 @@
 struct mboot mboot;
 
 #ifdef __i386__
+
+struct mbr_bootsel {
+       u_int8_t defkey;
+       u_int8_t flags;
+       u_int16_t timeo;
+       char nametab[4][9];
+       u_int16_t magic;
+} __attribute__((packed));
+
+#define BFL_SELACTIVE   0x01
+
+#define SCAN_ENTER      0x1c
+#define SCAN_F1         0x3b
+
+#define MBR_BOOTSELOFF (MBR_PARTOFF - sizeof (struct mbr_bootsel))
+
 #define        DEFAULT_BOOTCODE        "/usr/mdec/mbr"
+#define DEFAULT_BOOTSELCODE    "/usr/mdec/mbr_bootsel"
+#define OPTIONS                        "0123BSafius:b:c:"
+#else
+#define OPTIONS                        "0123Safius:b:c:"
 #endif
 
 #define ACTIVE 0x80
@@ -97,9 +123,12 @@
 int f_flag;            /* force --not interactive */
 int s_flag;            /* set id,offset,size */
 int b_flag;            /* Set cyl, heads, secs (as c/h/s) */
+int B_flag;            /* Edit/install bootselect code */
 int b_cyl, b_head, b_sec;  /* b_flag values. */
+int bootsel_modified;
 
 unsigned char bootcode[8192];  /* maximum size of bootcode */
+unsigned char tempcode[8192];
 int bootsize;          /* actual size of bootcode */
 
 
@@ -226,9 +255,11 @@
 void   usage __P((void));
 void   print_s0 __P((int));
 void   print_part __P((int));
-void   read_boot __P((char *));
+int    read_boot __P((char *, char *, size_t));
 void   init_sector0 __P((int, int));
 void   intuit_translated_geometry __P((void));
+void   get_geometry __P((void));
+void   get_diskname __P((char *, char *, size_t));
 int    try_heads __P((quad_t, quad_t, quad_t, quad_t, quad_t, quad_t, quad_t,
                       quad_t));
 int    try_sectors __P((quad_t, quad_t, quad_t, quad_t, quad_t));
@@ -248,6 +279,9 @@
 int    type_match __P((const void *, const void *));
 char   *get_type __P((int));
 int    get_mapping __P((int, int *, int *, int *, long *));
+#ifdef __i386__
+void   configure_bootsel __P((void));
+#endif
 
 static inline unsigned short getshort __P((void *));
 static inline void putshort __P((void *p, unsigned short));
@@ -269,7 +303,7 @@
 
        a_flag = i_flag = u_flag = sh_flag = f_flag = s_flag = b_flag = 0;
        csysid = cstart = csize = 0;
-       while ((ch = getopt(argc, argv, "0123Safius:b:c:")) != -1)
+       while ((ch = getopt(argc, argv, OPTIONS)) != -1)
                switch (ch) {
                case '0':
                        partition = 0;
@@ -283,6 +317,11 @@
                case '3':
                        partition = 3;
                        break;
+#ifdef __i386__
+               case 'B':
+                       B_flag = 1;
+                       break;
+#endif
                case 'S':
                        sh_flag = 1;
                        break;
@@ -321,7 +360,7 @@
                                b_cyl = MAXCYL;
                        break;
                case 'c':
-                       read_boot(optarg);
+                       bootsize = read_boot(optarg, bootcode, sizeof bootcode);
                        break;
                default:
                        usage();
@@ -332,6 +371,9 @@
        if (sh_flag && (a_flag || i_flag || u_flag || f_flag || s_flag))
                usage();
 
+       if (B_flag && (a_flag || i_flag || u_flag || f_flag || s_flag))
+               usage();
+
        if (partition == -1 && s_flag) {
                (void) fprintf (stderr,
                                "-s flag requires a partition selected.\n");
@@ -341,16 +383,17 @@
        if (argc > 0)
                disk = argv[0];
 
-       if (open_disk(a_flag || i_flag || u_flag) < 0)
+       if (open_disk(B_flag || a_flag || i_flag || u_flag) < 0)
                exit(1);
 
        if (read_s0())
                init_sector0(sectors > 63 ? 63 : sectors, 1);
 
+#ifdef __i386__
+       get_geometry();
+#else
        intuit_translated_geometry();
-
-       if (!sh_flag && !f_flag)
-               printf("******* Working on device %s *******\n", disk);
+#endif
 
 
        if ((i_flag || u_flag) && (!f_flag || b_flag))
@@ -359,14 +402,11 @@
        if (i_flag)
                init_sector0(dos_sectors > 63 ? 63 : dos_sectors, 0);
 
-       if (!sh_flag && !f_flag)
-               printf("Warning: BIOS sector numbering starts with sector 1\n");
-
        /* Do the update stuff! */
        if (u_flag) {
                if (!f_flag)
-                       printf("Information from DOS bootblock is:\n");
-               if (partition == -1) 
+                       printf("Partition table:\n");
+               if (partition == -1)
                        for (part = 0; part < NMBRPART; part++)
                                change_part(part,-1, -1, -1);
                else
@@ -378,9 +418,17 @@
        if (a_flag)
                change_active(partition);
 
+#ifdef __i386__
+       if (B_flag) {
+               configure_bootsel();
+               if (B_flag && bootsel_modified)
+                       write_s0();
+       }
+#endif
+
        if (u_flag || a_flag || i_flag) {
                if (!f_flag) {
-                       printf("\nWe haven't changed the partition table "
+                       printf("\nWe haven't written the MBR back to disk "
                               "yet.  This is your last chance.\n");
                        print_s0(-1);
                        if (yesno("Should we write new partition table?"))
@@ -408,7 +456,7 @@
 
        print_params();
        if (!sh_flag)
-               printf("Information from DOS bootblock is:\n");
+               printf("Partition table:\n");
        if (which == -1) {
                for (part = 0; part < NMBRPART; part++) {
                        if (!sh_flag)
@@ -419,8 +467,6 @@
                print_part(which);
 }
 
-static struct mbr_partition mtpart = { 0 };
-
 static inline unsigned short
 getshort(p)
        void *p;
@@ -471,7 +517,7 @@
        int empty;
 
        partp = &mboot.parts[part];
-       empty = !memcmp(partp, &mtpart, sizeof(struct mbr_partition));



Home | Main Index | Thread Index | Old Index