Hello, OKUJI!

>   I don't want to reject your patch again and again, but I don't like
> the second solution, because the name "blocklist_func" does not
> repesent what it really does. I think that if it's enough to set a
> variable only once, it should be set only once. Thus, I don't like the
> part "if (!stage2_sect) stage2_sect =..." especially. Let's implement
> the first solution.

Well, I've rewritten it.
Also Stage1 will be written after Stage2, so that unsuccessful patching
of Stage2 will prevent modifying the MBR or another important place where
Stage1 may be installed.

ChangeLog:
        * stage2/builtins.c (debug_fs_savesect_func): new function.
        Save the sector to stage2_sect
        (install_func): use debug_fs_savesect_func to calculate the
        first sector of Stage2. Write Stage1 after patching Stage2

Pavel Roskin
Index: stage2/builtins.c
===================================================================
RCS file: /usr/local/cvs/grub/stage2/builtins.c,v
retrieving revision 1.1.1.1
retrieving revision 1.3
diff -u -r1.1.1.1 -r1.3
--- stage2/builtins.c   1999/09/22 20:22:27     1.1.1.1
+++ stage2/builtins.c   1999/09/22 20:28:35     1.3
@@ -727,10 +727,18 @@
   int write_stage2_sect = 0;
   int stage2_sect;
   char *ptr;
-  int installaddr, installlist, installsect;
+  int installaddr, installlist;
 
-  /* Write SECTOR to INSTALLLIST, and update INSTALLADDR and
-     INSTALLSECT.  */
+  /* Save the first sector of Stage2 in stage2_sect */
+  static void debug_fs_savesect_func (int sector)
+    {
+      if (debug)
+       printf("[%d]", sector);
+
+      stage2_sect = sector;
+    }
+
+  /* Write SECTOR to INSTALLLIST and update INSTALLADDR */
   static void debug_fs_blocklist_func (int sector)
     {
       if (debug)
@@ -752,7 +760,6 @@
        }
 
       *((unsigned short *) installlist) += 1;
-      installsect = sector;
       installaddr += 512;
     }
 
@@ -895,8 +902,12 @@
   installlist = BOOTSEC_LOCATION + STAGE1_FIRSTLIST + 4;
 
   /* Read the first sector of Stage 2.  */
+  debug_fs = debug_fs_savesect_func;
   if (! grub_read ((char *) SCRATCHADDR, SECTOR_SIZE) == SECTOR_SIZE)
-    return 1;
+    {
+      debug_fs = 0;
+      return 1;
+    }
 
   /* Check for the version of Stage 2.  */
   if (*((short *) (SCRATCHADDR + STAGE2_VER_MAJ_OFFS)) != COMPAT_VERSION)
@@ -921,8 +932,6 @@
   *((unsigned short *) (BOOTSEC_LOCATION + STAGE1_INSTALLADDR))
     = installaddr;
   
-  stage2_sect = installsect;
-
   if (*ptr == 'p')
     {
       write_stage2_sect = 1;
@@ -955,13 +964,13 @@
   /* Clear the cache.  */
   buf_track = -1;
 
-  if (biosdisk (BIOSDISK_WRITE,
-               dest_drive, &dest_geom,
-               dest_sector, 1, (BOOTSEC_LOCATION >> 4))
-      || (write_stage2_sect
-         && biosdisk (BIOSDISK_WRITE,
-                      current_drive, &buf_geom,
-                      stage2_sect, 1, SCRATCHSEG)))
+  if ((write_stage2_sect
+       && biosdisk (BIOSDISK_WRITE,
+                   current_drive, &buf_geom,
+                   stage2_sect, 1, SCRATCHSEG))
+      || biosdisk (BIOSDISK_WRITE,
+                  dest_drive, &dest_geom,
+                  dest_sector, 1, (BOOTSEC_LOCATION >> 4)))
     {
       errnum = ERR_WRITE;
       debug_fs = 0;

Reply via email to