To: [email protected]
Subject: Patch 5.6a.021
Fcc: outbox
From: Bram Moolenaar <[email protected]>
------------

I only solved half the problem...

Patch 5.6a.021
Problem:    Recovering still may not work when the block size of the device
           where the swap file is located is larger than 4096.
Solution:   Read block 0 with the minimal block size.
Files:      src/memfile.c, src/memline.c, src/vim.h


*** ../vim-5.6a.20/src/memfile.c        Mon Jan 10 21:28:45 2000
--- src/memfile.c       Tue Jan 11 16:19:43 2000
***************
*** 170,183 ****
     /*
      * Try to set the page size equal to the block size of the device.
      * Speeds up I/O a lot.
!      * NOTE: minimal block size depends on size of block 0 data! It's not done
!      * with a sizeof(), because block 0 is defined in memline.c (Sorry).
!      * The maximal block size is arbitrary.
      */
     if (mfp->mf_fd >= 0
           && fstatfs(mfp->mf_fd, &stf, sizeof(struct statfs), 0) == 0
!           && stf.F_BSIZE >= 1048
!           && stf.F_BSIZE <= 50000)
       mfp->mf_page_size = stf.F_BSIZE;
 #endif

--- 170,183 ----
     /*
      * Try to set the page size equal to the block size of the device.
      * Speeds up I/O a lot.
!      * When recovering, the actual block size will be retrieved from block 0
!      * in ml_recover().  The size used here may be wrong, therefore
!      * mf_blocknr_max must be rounded up.
      */
     if (mfp->mf_fd >= 0
           && fstatfs(mfp->mf_fd, &stf, sizeof(struct statfs), 0) == 0
!           && stf.F_BSIZE >= MIN_SWAP_PAGE_SIZE
!           && stf.F_BSIZE <= MAX_SWAP_PAGE_SIZE)
       mfp->mf_page_size = stf.F_BSIZE;
 #endif

*** ../vim-5.6a.20/src/memline.c        Mon Dec 20 09:59:15 1999
--- src/memline.c       Tue Jan 11 16:15:36 2000
***************
*** 143,150 ****
  * NOTE: DEFINITION OF BLOCK 0 SHOULD NOT CHANGE! It would make all existing
  * swap files unusable!
  *
!  * If size of block0 changes anyway, adjust minimal block size
!  * in mf_open()!!
  *
  * This block is built up of single bytes, to make it portable accros
  * different machines. b0_magic_* is used to check the byte order and size of
--- 143,149 ----
  * NOTE: DEFINITION OF BLOCK 0 SHOULD NOT CHANGE! It would make all existing
  * swap files unusable!
  *
!  * If size of block0 changes anyway, adjust MIN_SWAP_PAGE_SIZE in vim.h!!
  *
  * This block is built up of single bytes, to make it portable accros
  * different machines. b0_magic_* is used to check the byte order and size of
***************
*** 801,806 ****
--- 800,813 ----
     }
     vim_free(p);
     buf->b_ml.ml_mfp = mfp;
+
+     /*
+      * The page size set in mf_open() might be different from the page size
+      * used in the swap file, we must get it from block 0.  But to read block
+      * 0 we need a page size.  Use the minimal size for block 0 here, it will
+      * be set to the real value below.
+      */
+     mfp->mf_page_size = MIN_SWAP_PAGE_SIZE;

 /*
  * try to read block 0
*** ../vim-5.6a.20/src/vim.h    Mon Dec 20 09:59:07 1999
--- src/vim.h   Tue Jan 11 16:20:58 2000
***************
*** 576,581 ****
--- 576,590 ----
 #define SEA_RECOVER   3       /* recover the file */

 /*
+  * Minimal size for block 0 of a swap file.
+  * NOTE: This depends on size of struct block0! It's not done with a sizeof(),
+  * because struct block0 is defined in memline.c (Sorry).
+  * The maximal block size is arbitrary.
+  */
+ #define MIN_SWAP_PAGE_SIZE 1048
+ #define MAX_SWAP_PAGE_SIZE 50000
+
+ /*
  * Events for autocommands.
  */
 enum auto_event
*** ../vim-5.6a.20/src/version.c        Tue Jan 11 16:54:05 2000
--- src/version.c       Tue Jan 11 16:54:36 2000
***************
*** 420,421 ****
--- 420,423 ----
 {   /* Add new patch number below this line */
+ /**/
+     21,
 /**/

--
hundred-and-one symptoms of being an internet addict:
106. When told to "go to your room" you inform your parents that you
    can't...because you were kicked out and banned.

--/-/---- Bram Moolenaar ---- [email protected] ---- [email protected] ---\-\--
 \ \    www.vim.org/iccf      www.moolenaar.net       www.vim.org    / /