]> Zhao Yanbai Git Server - minix.git/commitdiff
Switch part/autopart to new mbr bootblock
authorAntoine Leca <Antoine.Leca.1@gmail.com>
Thu, 12 Jan 2012 17:14:44 +0000 (18:14 +0100)
committerBen Gras <ben@minix3.org>
Thu, 9 Feb 2012 17:54:46 +0000 (18:54 +0100)
commands/atnormalize/atnormalize.c
commands/autopart/autopart.c
commands/part/part.c

index 707b3272f80202f292ac08e06d5566d6282c5216..a1e66fe1d7ac0ab376b364858700601bf8f802f3 100644 (file)
@@ -12,7 +12,6 @@
 #include <time.h>
 #include <dirent.h>
 #include <limits.h>
-#include <a.out.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <sys/ioctl.h>
index 6d1ebaf6881f17402a4e8ed5f8d81e3889945dde..8e08fda08c8866963eb32cf99246d5a4efd71271 100644 (file)
@@ -21,7 +21,6 @@
 #include <time.h>
 #include <dirent.h>
 #include <limits.h>
-#include <a.out.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <sys/ioctl.h>
@@ -41,7 +40,7 @@ void printstep(int step, char *message);
 #define ext_part(s)    ((s) == 0x05 || (s) == 0x0F)
 
 /* Minix master bootstrap code. */
-char MASTERBOOT[] = "/usr/mdec/masterboot";
+char MASTERBOOT[] = "/usr/mdec/mbr";
 
 /* Template:
                       ----first----  --geom/last--  ------sectors-----
@@ -354,38 +353,6 @@ void getdevices(void)
        (void) closedir(d);
 }
 
-/* One featureful master bootstrap. */
-unsigned char bootstrap[] = {
-0353,0001,0000,0061,0300,0216,0330,0216,0300,0372,0216,0320,0274,0000,0174,0373,
-0275,0276,0007,0211,0346,0126,0277,0000,0006,0271,0000,0001,0374,0363,0245,0352,
-0044,0006,0000,0000,0264,0002,0315,0026,0250,0010,0164,0033,0350,0071,0001,0174,
-0007,0060,0344,0315,0026,0242,0205,0007,0054,0060,0074,0012,0163,0363,0120,0350,
-0046,0001,0205,0007,0130,0353,0012,0240,0002,0006,0204,0300,0165,0003,0351,0147,
-0000,0230,0262,0005,0366,0362,0262,0200,0000,0302,0210,0340,0120,0350,0234,0000,
-0163,0003,0351,0147,0000,0130,0054,0001,0175,0003,0351,0141,0000,0276,0276,0175,
-0211,0357,0271,0040,0000,0363,0245,0200,0301,0004,0211,0356,0215,0174,0020,0070,
-0154,0004,0164,0016,0213,0135,0010,0053,0134,0010,0213,0135,0012,0033,0134,0012,
-0163,0014,0212,0044,0206,0144,0020,0210,0044,0106,0071,0376,0162,0364,0211,0376,
-0201,0376,0356,0007,0162,0326,0342,0322,0211,0356,0264,0020,0366,0344,0001,0306,
-0200,0174,0004,0001,0162,0026,0353,0021,0204,0322,0175,0041,0211,0356,0200,0174,
-0004,0000,0164,0013,0366,0004,0200,0164,0006,0350,0070,0000,0162,0053,0303,0203,
-0306,0020,0201,0376,0376,0007,0162,0346,0350,0215,0000,0211,0007,0376,0302,0204,
-0322,0174,0023,0315,0021,0321,0340,0321,0340,0200,0344,0003,0070,0342,0167,0355,
-0350,0011,0000,0162,0350,0303,0350,0003,0000,0162,0146,0303,0211,0356,0214,0134,
-0010,0214,0134,0012,0277,0003,0000,0122,0006,0127,0264,0010,0315,0023,0137,0007,
-0200,0341,0077,0376,0306,0210,0310,0366,0346,0211,0303,0213,0104,0010,0213,0124,
-0012,0367,0363,0222,0210,0325,0366,0361,0060,0322,0321,0352,0321,0352,0010,0342,
-0210,0321,0376,0301,0132,0210,0306,0273,0000,0174,0270,0001,0002,0315,0023,0163,
-0020,0200,0374,0200,0164,0011,0117,0174,0006,0060,0344,0315,0023,0163,0270,0371,
-0303,0201,0076,0376,0175,0125,0252,0165,0001,0303,0350,0013,0000,0243,0007,0353,
-0005,0350,0004,0000,0227,0007,0353,0376,0136,0255,0126,0211,0306,0254,0204,0300,
-0164,0011,0264,0016,0273,0001,0000,0315,0020,0353,0362,0303,0057,0144,0145,0166,
-0057,0150,0144,0077,0010,0000,0015,0012,0000,0116,0157,0156,0145,0040,0141,0143,
-0164,0151,0166,0145,0015,0012,0000,0122,0145,0141,0144,0040,0145,0162,0162,0157,
-0162,0040,0000,0116,0157,0164,0040,0142,0157,0157,0164,0141,0142,0154,0145,0040,
-0000,0000,
-};
-
 int dirty= 0;
 unsigned char bootblock[SECTOR_SIZE];
 struct part_entry table[1 + NR_PARTITIONS];
@@ -1378,7 +1345,7 @@ void installboot(unsigned char *bootblock, char *masterboot)
 /* Install code from a master bootstrap into a boot block. */
 {
        FILE *mfp;
-       struct exec hdr;
+       unsigned char buf[SECTOR_SIZE];
        int n;
        char *err;
 
@@ -1387,32 +1354,39 @@ void installboot(unsigned char *bootblock, char *masterboot)
                goto m_err;
        }
 
-       n= fread(&hdr, sizeof(char), A_MINHDR, mfp);
+       n= fread(buf, sizeof(char), SECTOR_SIZE, mfp);
        if (ferror(mfp)) {
                err= strerror(errno);
                fclose(mfp);
                goto m_err;
        }
-
-       if (n < A_MINHDR || BADMAG(hdr) || hdr.a_cpu != A_I8086) {
-               err= "Not an 8086 executable";
+       else if (n < 256) {
+               err= "Is probably not a boot sector, too small";
                fclose(mfp);
                goto m_err;
        }
-
-       if (hdr.a_text + hdr.a_data > PART_TABLE_OFF) {
+       else if (n < SECTOR_SIZE && n > PART_TABLE_OFF) {
+               /* if only code, it cannot override partition table */
                err= "Does not fit in a boot sector";
                fclose(mfp);
                goto m_err;
        }
+       else if (n == SECTOR_SIZE) {
+               if (buf[510] != 0x55 || buf[511] != 0xaa) {
+                       err= "Is not a boot sector (bad magic)";
+                       fclose(mfp);
+                       goto m_err;
+               }
+               n = PART_TABLE_OFF;
+       }
 
-       fseek(mfp, hdr.a_hdrlen, 0);
-       fread(bootblock, sizeof(char), (size_t) (hdr.a_text + hdr.a_data), mfp);
-       if (ferror(mfp)) {
-               err= strerror(errno);
+       if (n > PART_TABLE_OFF) {
+               err= "Does not fit in a boot sector";
                fclose(mfp);
                goto m_err;
        }
+
+       memcpy(bootblock, buf, n);
        fclose(mfp);
 
        /* Bootstrap installed. */
index 9646899bb8abf9422c901a80345e8c4dcddb729f..c31f3d5833f3d358cb5429e4c66f3da4644083b4 100644 (file)
@@ -16,7 +16,6 @@
 #include <time.h>
 #include <dirent.h>
 #include <limits.h>
-#include <a.out.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <sys/ioctl.h>
@@ -31,7 +30,7 @@
 #define ext_part(s)    ((s) == 0x05 || (s) == 0x0F)
 
 /* Minix master bootstrap code. */
-static char MASTERBOOT[] = "/usr/mdec/masterboot";
+static char MASTERBOOT[] = "/usr/mdec/mbr";
 
 /* Template:
                       ----first----  --geom/last--  ------sectors-----
@@ -305,38 +304,6 @@ void getdevices(void)
        (void) closedir(d);
 }
 
-/* One featureful master bootstrap. */
-unsigned char bootstrap[] = {
-0353,0001,0000,0061,0300,0216,0330,0216,0300,0372,0216,0320,0274,0000,0174,0373,
-0275,0276,0007,0211,0346,0126,0277,0000,0006,0271,0000,0001,0374,0363,0245,0352,
-0044,0006,0000,0000,0264,0002,0315,0026,0250,0010,0164,0033,0350,0071,0001,0174,
-0007,0060,0344,0315,0026,0242,0205,0007,0054,0060,0074,0012,0163,0363,0120,0350,
-0046,0001,0205,0007,0130,0353,0012,0240,0002,0006,0204,0300,0165,0003,0351,0147,
-0000,0230,0262,0005,0366,0362,0262,0200,0000,0302,0210,0340,0120,0350,0234,0000,
-0163,0003,0351,0147,0000,0130,0054,0001,0175,0003,0351,0141,0000,0276,0276,0175,
-0211,0357,0271,0040,0000,0363,0245,0200,0301,0004,0211,0356,0215,0174,0020,0070,
-0154,0004,0164,0016,0213,0135,0010,0053,0134,0010,0213,0135,0012,0033,0134,0012,
-0163,0014,0212,0044,0206,0144,0020,0210,0044,0106,0071,0376,0162,0364,0211,0376,
-0201,0376,0356,0007,0162,0326,0342,0322,0211,0356,0264,0020,0366,0344,0001,0306,
-0200,0174,0004,0001,0162,0026,0353,0021,0204,0322,0175,0041,0211,0356,0200,0174,
-0004,0000,0164,0013,0366,0004,0200,0164,0006,0350,0070,0000,0162,0053,0303,0203,
-0306,0020,0201,0376,0376,0007,0162,0346,0350,0215,0000,0211,0007,0376,0302,0204,
-0322,0174,0023,0315,0021,0321,0340,0321,0340,0200,0344,0003,0070,0342,0167,0355,
-0350,0011,0000,0162,0350,0303,0350,0003,0000,0162,0146,0303,0211,0356,0214,0134,
-0010,0214,0134,0012,0277,0003,0000,0122,0006,0127,0264,0010,0315,0023,0137,0007,
-0200,0341,0077,0376,0306,0210,0310,0366,0346,0211,0303,0213,0104,0010,0213,0124,
-0012,0367,0363,0222,0210,0325,0366,0361,0060,0322,0321,0352,0321,0352,0010,0342,
-0210,0321,0376,0301,0132,0210,0306,0273,0000,0174,0270,0001,0002,0315,0023,0163,
-0020,0200,0374,0200,0164,0011,0117,0174,0006,0060,0344,0315,0023,0163,0270,0371,
-0303,0201,0076,0376,0175,0125,0252,0165,0001,0303,0350,0013,0000,0243,0007,0353,
-0005,0350,0004,0000,0227,0007,0353,0376,0136,0255,0126,0211,0306,0254,0204,0300,
-0164,0011,0264,0016,0273,0001,0000,0315,0020,0353,0362,0303,0057,0144,0145,0166,
-0057,0150,0144,0077,0010,0000,0015,0012,0000,0116,0157,0156,0145,0040,0141,0143,
-0164,0151,0166,0145,0015,0012,0000,0122,0145,0141,0144,0040,0145,0162,0162,0157,
-0162,0040,0000,0116,0157,0164,0040,0142,0157,0157,0164,0141,0142,0154,0145,0040,
-0000,0000,
-};
-
 int dirty= 0;
 unsigned char bootblock[SECTOR_SIZE];
 struct part_entry table[1 + NR_PARTITIONS];
@@ -1558,7 +1525,7 @@ void installboot(unsigned char *bootblock, char *masterboot)
 /* Install code from a master bootstrap into a boot block. */
 {
        FILE *mfp;
-       struct exec hdr;
+       unsigned char buf[SECTOR_SIZE];
        int n;
        char *err;
 
@@ -1567,32 +1534,39 @@ void installboot(unsigned char *bootblock, char *masterboot)
                goto m_err;
        }
 
-       n= fread(&hdr, sizeof(char), A_MINHDR, mfp);
+       n= fread(buf, sizeof(char), SECTOR_SIZE, mfp);
        if (ferror(mfp)) {
                err= strerror(errno);
                fclose(mfp);
                goto m_err;
        }
-
-       if (n < A_MINHDR || BADMAG(hdr) || hdr.a_cpu != A_I8086) {
-               err= "Not an 8086 executable";
+       else if (n < 256) {
+               err= "Is probably not a boot sector, too small";
                fclose(mfp);
                goto m_err;
        }
-
-       if (hdr.a_text + hdr.a_data > PART_TABLE_OFF) {
+       else if (n < SECTOR_SIZE && n > PART_TABLE_OFF) {
+               /* if only code, it cannot override partition table */
                err= "Does not fit in a boot sector";
                fclose(mfp);
                goto m_err;
        }
+       else if (n == SECTOR_SIZE) {
+               if (buf[510] != 0x55 || buf[511] != 0xaa) {
+                       err= "Is not a boot sector (bad magic)";
+                       fclose(mfp);
+                       goto m_err;
+               }
+               n = PART_TABLE_OFF;
+       }
 
-       fseek(mfp, hdr.a_hdrlen, 0);
-       fread(bootblock, sizeof(char), (size_t) (hdr.a_text + hdr.a_data), mfp);
-       if (ferror(mfp)) {
-               err= strerror(errno);
+       if (n > PART_TABLE_OFF) {
+               err= "Does not fit in a boot sector";
                fclose(mfp);
                goto m_err;
        }
+
+       memcpy(bootblock, buf, n);
        fclose(mfp);
 
        /* Bootstrap installed. */