--- ./advancecomp-1.9_create_compressed_fs/advfs.cc.orig 2004-04-18 20:33:29.000000000 +0000 +++ ./advancecomp-1.9_create_compressed_fs/advfs.cc 2004-09-30 03:08:17.000000000 +0000 @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,6 @@ #include "utility.h" #include "compress.h" #include "siglock.h" -#include #include "lib/mng.h" #include "lib/endianrw.h" --- ./Makefile.orig 2004-05-14 19:17:51.000000000 +0000 +++ ./Makefile 2004-09-30 21:37:58.000000000 +0000 @@ -1,15 +1,17 @@ #!/usr/bin/make +# note: if this is wrong, specifying in the commandline `make KERNEL_DIR=/usr/src/linux-2.6.7' will override it KERNEL_DIR=/usr/src/linux ifdef APPSONLY CFLAGS:=-Wall -Wstrict-prototypes -Wno-trigraphs -O2 -s -I. -fno-strict-aliasing -fno-common -fomit-frame-pointer else include $(KERNEL_DIR)/.config -include $(KERNEL_DIR)/conf.vars +# conf.vars doesn't appear to be in source tarballs from kernel.org, so don't make it mandatory +-include $(KERNEL_DIR)/conf.vars endif -CKERNOPS:=-D__KERNEL__ -DMODULE -fno-builtin -nostdlib -DKBUILD_MODNAME="cloop" -DKBUILD_BASENAME="cloop" +CKERNOPS:=-O2 -D__KERNEL__ -DMODULE -fno-builtin -nostdlib -DKBUILD_MODNAME="cloop" -DKBUILD_BASENAME="cloop" ifdef CONFIG_MODVERSIONS MODVERSIONS:= -DMODVERSIONS -include $(KERNEL_DIR)/include/linux/modversions.h @@ -27,6 +29,10 @@ KERNOBJ:=compressed_loop.o # Name of module +# note -- maybe if conf.vars wasn't found, PATCHLEVEL will be undefined? So let's assume 6 for a 2.6 kernel +ifndef PATCHLEVEL +PATCHLEVEL = 6 +endif ifeq ($(PATCHLEVEL),6) MODULE:=cloop.ko else --- ./compressed_loop.c.orig 2004-07-27 22:44:11.000000000 +0000 +++ ./compressed_loop.c 2004-10-01 04:48:31.000000000 +0000 @@ -133,6 +133,7 @@ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) struct gendisk *disk; request_queue_t *clo_queue; + int native_byte_order; #endif }; @@ -249,6 +250,13 @@ return buf_done; } +unsigned long reorder_offset(struct cloop_device *clo, unsigned long offset) +{ + if (clo->native_byte_order) return offset; + /* Is there a ntohl for 64-bit values? Maybe, but only on 64-bit OSes */ + else return be64_to_cpu(offset); +} + /* This looks more complicated than it is */ static int load_buffer(struct cloop_device *clo, int blocknum) { @@ -267,12 +275,11 @@ if (blocknum == clo->buffered_blocknum) return 1; - /* Is there a ntohl for 64-bit values? */ - buf_length = be64_to_cpu(clo->offsets[blocknum+1]) - be64_to_cpu(clo->offsets[blocknum]); + buf_length = reorder_offset(clo, clo->offsets[blocknum+1]) - reorder_offset(clo, clo->offsets[blocknum]); /* Load one compressed block from the file. */ clo_read_from_file(clo, clo->backing_file, (char *)clo->compressed_buffer, - be64_to_cpu(clo->offsets[blocknum]), buf_length); + reorder_offset(clo, clo->offsets[blocknum]), buf_length); /* Do decompression into real buffer. */ buflen = ntohl(clo->head.block_size); @@ -286,7 +293,7 @@ printk(KERN_ERR "%s: error %i uncompressing block %u %u/%lu/%u/%u " "%Lu-%Lu\n", cloop_name, ret, blocknum, ntohl(clo->head.block_size), buflen, buf_length, buf_done, - be64_to_cpu(clo->offsets[blocknum]), be64_to_cpu(clo->offsets[blocknum+1])); + reorder_offset(clo, clo->offsets[blocknum]), reorder_offset(clo, clo->offsets[blocknum+1])); clo->buffered_blocknum = -1; return 0; } @@ -513,11 +520,9 @@ if (clo->head.preamble[0x0C]<'2') { - printk(KERN_ERR "%s: Cannot read old architecture-dependent " - "(format <= 1.0) images, please use an older " - "version of %s for this file.\n", - cloop_name, cloop_name); - error=-EBADF; goto error_release; + clo->native_byte_order = 1; + } else { + clo->native_byte_order = 0; } total_offsets=ntohl(clo->head.num_blocks)+1; @@ -549,7 +554,7 @@ int i; for(i=0;ioffsets[i+1]) - be64_to_cpu(clo->offsets[i]); + loff_t d=reorder_offset(clo, clo->offsets[i+1]) - reorder_offset(clo, clo->offsets[i]); largest_block=MAX(largest_block,d); } printk("%s: %s: %u blocks, %u bytes/block, largest block is %lu bytes.\n", @@ -584,11 +589,11 @@ zlib_inflateInit(&clo->zstream); if(!isblkdev && - be64_to_cpu(clo->offsets[ntohl(clo->head.num_blocks)]) != inode->i_size) + reorder_offset(clo, clo->offsets[ntohl(clo->head.num_blocks)]) != inode->i_size) { printk(KERN_ERR "%s: final offset wrong (%Lu not %Lu)\n", cloop_name, - be64_to_cpu(clo->offsets[ntohl(clo->head.num_blocks)]), + reorder_offset(clo, clo->offsets[ntohl(clo->head.num_blocks)]), inode->i_size); vfree(clo->zstream.workspace); clo->zstream.workspace=NULL; goto error_release_free_all; @@ -774,14 +779,14 @@ init_MUTEX(&cloop_dev[i].clo_lock); } -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) - if(devfs_register_blkdev(MAJOR_NR, cloop_name, &clo_fops)) -#else if(register_blkdev(MAJOR_NR, cloop_name)) -#endif { printk(KERN_WARNING "%s: Unable to get major %d for cloop\n", cloop_name, MAJOR_NR); + /* FIXME: under some circumstances, failure down the road + will leave MAJOR_NR registered, foiling any further attempt + to install module + */ return -EINVAL; } @@ -830,9 +835,9 @@ printk(KERN_ERR "%s: Unable to get file %s for cloop device\n", cloop_name, file); - return -EINVAL; + error = -EINVAL; } - error=clo_set_file(0,initial_file,file); + if (!error) error=clo_set_file(0,initial_file,file); if(error) { i=max_cloop; goto out_mem; } } @@ -857,11 +862,10 @@ int i; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) devfs_unregister(devfs_handle); - if(devfs_unregister_blkdev(MAJOR_NR, cloop_name) != 0) #else devfs_remove(cloop_name); - if(unregister_blkdev(MAJOR_NR, cloop_name) != 0) #endif + if(unregister_blkdev(MAJOR_NR, cloop_name) != 0) printk(KERN_WARNING "%s: cannot unregister block device\n", cloop_name); for(i=0;i