diff -Nur linux-2.5.1-orig/drivers/block/loop.c linux-2.5.1/drivers/block/loop.c
--- linux-2.5.1-orig/drivers/block/loop.c       Fri Nov 30 17:33:50 2001
+++ linux-2.5.1/drivers/block/loop.c    Sun Dec 30 14:41:18 2001
@@ -85,7 +85,7 @@
 * Transfer functions
 */
static int transfer_none(struct loop_device *lo, int cmd, char *raw_buf,
-                        char *loop_buf, int size, int real_block)
+                        char *loop_buf, int size, loop_iv_t IV)
{
       if (raw_buf != loop_buf) {
               if (cmd == READ)
@@ -98,7 +98,7 @@
}

static int transfer_xor(struct loop_device *lo, int cmd, char *raw_buf,
-                       char *loop_buf, int size, int real_block)
+                       char *loop_buf, int size, loop_iv_t IV)
{
       char    *in, *out, *key;
       int     i, keysize;
@@ -185,7 +185,7 @@
       len = bio->bi_size;
       data = bio_data(bio);
       while (len > 0) {
-               int IV = index * (PAGE_CACHE_SIZE/bsize) + offset/bsize;
+               const loop_iv_t IV = (index << (PAGE_CACHE_SHIFT - LOOP_IV_SECTOR_BITS)) + (offset >> LOOP_IV_SECTOR_BITS);
               int transfer_result;

               size = PAGE_CACHE_SIZE - offset;
@@ -243,7 +243,7 @@
       unsigned long count = desc->count;
       struct lo_read_data *p = (struct lo_read_data*)desc->buf;
       struct loop_device *lo = p->lo;
-       int IV = page->index * (PAGE_CACHE_SIZE/p->bsize) + offset/p->bsize;
+       const loop_iv_t IV = (page->index << (PAGE_CACHE_SHIFT - LOOP_IV_SECTOR_BITS)) + (offset >> LOOP_IV_SECTOR_BITS);

       if (size > count)
               size = count;
@@ -294,20 +294,6 @@
       return bs;
}

-static inline unsigned long loop_get_iv(struct loop_device *lo,
-                                       unsigned long sector)
-{
-       int bs = loop_get_bs(lo);
-       unsigned long offset, IV;
-
-       IV = sector / (bs >> 9) + lo->lo_offset / bs;
-       offset = ((sector % (bs >> 9)) << 9) + lo->lo_offset % bs;
-       if (offset >= bs)
-               IV++;
-
-       return IV;
-}
-
static int do_bio_filebacked(struct loop_device *lo, struct bio *bio)
{
       loff_t pos;
@@ -433,7 +419,7 @@
{
       struct bio *bh = NULL;
       struct loop_device *lo;
-       unsigned long IV;
+       loop_iv_t IV;
       int rw = bio_rw(rbh);

       if (MINOR(rbh->bi_dev) >= max_loop)
@@ -470,7 +456,7 @@
        * piggy old buffer on original, and submit for I/O
        */
       bh = loop_get_buffer(lo, rbh);
-       IV = loop_get_iv(lo, rbh->bi_sector);
+       IV = rbh->bi_sector + (lo->lo_offset >> LOOP_IV_SECTOR_BITS);
       if (rw == WRITE) {
               if (lo_do_transfer(lo, WRITE, bio_data(bh), bio_data(rbh),
                                  bh->bi_size, IV))
@@ -495,7 +481,7 @@
static int do_bio_blockbacked(struct loop_device *lo, struct bio *bio,
                             struct bio *rbh)
{
-       unsigned long IV = loop_get_iv(lo, rbh->bi_sector);
+       const loop_iv_t IV = rbh->bi_sector + (lo->lo_offset >> LOOP_IV_SECTOR_BITS);
       struct bio_vec *to;
       char *vto, *vfrom;
       int ret = 0, i;
diff -Nur linux-2.5.1-orig/include/linux/loop.h linux-2.5.1/include/linux/loop.h
--- linux-2.5.1-orig/include/linux/loop.h       Tue Nov 27 18:23:27 2001
+++ linux-2.5.1/include/linux/loop.h    Sun Dec 30 14:35:53 2001
@@ -17,6 +17,12 @@

#ifdef __KERNEL__

+/* definitions for IV metric */
+#define LOOP_IV_SECTOR_BITS 9
+#define LOOP_IV_SECTOR_SIZE (1 << LOOP_IV_SECTOR_BITS)
+
+typedef int loop_iv_t;
+
/* Possible states of device */
enum {
       Lo_unbound,
@@ -24,6 +30,12 @@
       Lo_rundown,
};

+struct loop_device;
+
+typedef        int (* transfer_proc_t)(struct loop_device *, int cmd,
+                               char *raw_buf, char *loop_buf, int size,
+                               loop_iv_t IV);
+
struct loop_device {
       int             lo_number;
       int             lo_refcnt;
@@ -32,9 +44,7 @@
       int             lo_encrypt_type;
       int             lo_encrypt_key_size;
       int             lo_flags;
-       int             (*transfer)(struct loop_device *, int cmd,
-                                   char *raw_buf, char *loop_buf, int size,
-                                   int real_block);
+       transfer_proc_t transfer;
       char            lo_name[LO_NAME_SIZE];
       char            lo_encrypt_key[LO_KEY_SIZE];
       __u32           lo_init[2];
@@ -58,17 +68,13 @@
       atomic_t                lo_pending;
};

-typedef        int (* transfer_proc_t)(struct loop_device *, int cmd,
-                               char *raw_buf, char *loop_buf, int size,
-                               int real_block);
-
static inline int lo_do_transfer(struct loop_device *lo, int cmd, char *rbuf,
-                                char *lbuf, int size, int rblock)
+                                char *lbuf, int size, loop_iv_t IV)
{
       if (!lo->transfer)
               return 0;

-       return lo->transfer(lo, cmd, rbuf, lbuf, size, rblock);
+       return lo->transfer(lo, cmd, rbuf, lbuf, size, IV);
}
#endif /* __KERNEL__ */

@@ -122,6 +128,8 @@
#define LO_CRYPT_IDEA     6
#define LO_CRYPT_DUMMY    9
#define LO_CRYPT_SKIPJACK 10
+#define LO_CRYPT_AES      16   /* loop-AES */
+#define LO_CRYPT_CRYPTOAPI 18  /* international crypto patch */
#define MAX_LO_CRYPT   20

#ifdef __KERNEL__
@@ -129,7 +137,7 @@
struct loop_func_table {
       int number;     /* filter type */
       int (*transfer)(struct loop_device *lo, int cmd, char *raw_buf,
-                       char *loop_buf, int size, int real_block);
+                       char *loop_buf, int size, loop_iv_t IV);
       int (*init)(struct loop_device *, struct loop_info *);
       /* release is called from loop_unregister_transfer or clr_fd */
       int (*release)(struct loop_device *);