Here's a slightly different approach to the CRAMFS over RAM disk problem.
This patch (against 2.4) allows the RAM disk block size to be changed
through set_blocksize() without destroying its previous content.  Comments
are welcome.
-- 
Debian GNU/Linux 2.2 is out! ( http://www.debian.org/ )
Email:  Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
diff -u -r1.1.1.5 -r1.5
--- drivers/block/rd.c  2001/02/09 19:30:22     1.1.1.5
+++ drivers/block/rd.c  2001/05/20 01:36:07     1.5
@@ -197,8 +198,11 @@
 static int rd_make_request(request_queue_t * q, int rw, struct buffer_head *sbh)
 {
        unsigned int minor;
-       unsigned long offset, len;
-       struct buffer_head *rbh;
+       unsigned int hardsec;
+       unsigned int len;
+       unsigned int size;
+       unsigned long block;
+       unsigned long offset;
        char *bdata;
 
        
@@ -221,20 +225,32 @@
                goto fail;
        }
 
-       rbh = getblk(sbh->b_rdev, sbh->b_rsector/(sbh->b_size>>9), sbh->b_size);
+       hardsec = (unsigned int) rd_hardsec[minor];
+       block = offset / hardsec;
+       offset %= hardsec;
+       size = len <= hardsec ? len : hardsec;
+
        /* I think that it is safe to assume that rbh is not in HighMem, though
         * sbh might be - NeilBrown
         */
        bdata = bh_kmap(sbh);
-       if (rw == READ) {
-               if (sbh != rbh)
-                       memcpy(bdata, rbh->b_data, rbh->b_size);
-       } else
-               if (sbh != rbh)
-                       memcpy(rbh->b_data, bdata, rbh->b_size);
+       do {
+               struct buffer_head *rbh;
+
+               rbh = getblk(sbh->b_rdev, block, hardsec);
+               if (sbh != rbh) {
+                       if (rw == READ)
+                               memcpy(bdata, rbh->b_data + offset, size);
+                       else
+                               memcpy(rbh->b_data + offset, bdata, size);
+               }
+               mark_buffer_protected(rbh);
+               brelse(rbh);
+               len -= size;
+               bdata += size;
+               block++;
+       } while (len > 0);
        bh_kunmap(sbh);
-       mark_buffer_protected(rbh);
-       brelse(rbh);
 
        sbh->b_end_io(sbh,1);
        return 0;
diff -u -r1.1.1.10 -r1.2
--- fs/buffer.c 2001/04/27 21:23:25     1.1.1.10
+++ fs/buffer.c 2001/05/20 01:36:07     1.2
@@ -711,6 +711,8 @@
                        bh_next = bh->b_next_free;
                        if (bh->b_dev != dev || bh->b_size == size)
                                continue;
+                       if (buffer_protected(bh))
+                               continue;
                        if (buffer_locked(bh)) {
                                atomic_inc(&bh->b_count);
                                spin_unlock(&lru_list_lock);

Reply via email to