Skip to content

Commit fe17a57

Browse files
author
zgl
committed
chore: add cloop test script
1 parent 4e8d1cc commit fe17a57

4 files changed

Lines changed: 57 additions & 1166 deletions

File tree

drivers/block/cloop/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/make
22

33
MACHINE=$(shell uname -m)
4+
5+
KERNEL_DIR:=../../../../hyperblock_loop/
46
ifndef KERNEL_DIR
57
KERNEL_DIR:=/lib/modules/`uname -r`/build
68
endif

drivers/block/cloop/cloop.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@
4444
#include <asm/div64.h> /* do_div() for 64bit division */
4545
#include <asm/uaccess.h>
4646
#include <asm/byteorder.h>
47+
#include <linux/vfs.h> /* for vfs_read*/
48+
#include <linux/types.h>
49+
#include <linux/string.h>
50+
#include <linux/export.h>
51+
#include <linux/mm.h>
52+
#include <linux/uaccess.h>
53+
#include <linux/version.h>
54+
55+
56+
4757
/* Check for ZLIB, LZO1X, LZ4 decompression algorithms in kernel. */
4858
#if (defined(CONFIG_ZLIB_INFLATE) || defined(CONFIG_ZLIB_INFLATE_MODULE))
4959
#include <linux/zutil.h>
@@ -303,11 +313,14 @@ static ssize_t cloop_read_from_file(struct cloop_device *clo, struct file *f, ch
303313
size_t size = buf_len - buf_done, size_read;
304314
/* kernel_read() only supports 32 bit offsets, so we use vfs_read() instead. */
305315
/* int size_read = kernel_read(f, pos, buf + buf_done, size); */
316+
#if LINUX_VERSION_CODE <= KERNEL_VERSION(4,14,14)
306317
mm_segment_t old_fs = get_fs();
307318
set_fs(get_ds());
308319
size_read = vfs_read(f, (void __user *)(buf + buf_done), size, &pos);
309320
set_fs(old_fs);
310-
321+
#else
322+
size_read = kernel_read(f, (void __user *)(buf + buf_done), size, &pos);
323+
#endif
311324
if(size_read <= 0)
312325
{
313326
printk(KERN_ERR "%s: Read error %d at pos %llu in file %s, "

drivers/block/cloop/test.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#/bin/sh -e
2+
3+
INPUTDEVICE="/tmp/file.fs"
4+
OUTPUTFILE="/tmp/filefs.cloop.img"
5+
BLOCKSIZE="1048576"
6+
#NUMBLOCKS="2000"
7+
NUMBLOCKS="200"
8+
COMPRESSIONLEVEL="9"
9+
#COMPRESSIONLEVEL="-1" # for 7zip compression (untested)
10+
CLOOPLOGFILE="/tmp/cloop-creation.log"
11+
CLOOPBLOCKSIZE="64K"
12+
13+
14+
echo "-----------------> Clearing envs <..."
15+
if [ -d /mnt/cloop ]; then
16+
umount /mnt/cloop/
17+
rmmod cloop
18+
fi
19+
20+
echo "------------------> Making file fs <..."
21+
dd if=/dev/zero of="$INPUTDEVICE" bs="$BLOCKSIZE" count="$NUMBLOCKS" | pv -s "$((NUMBLOCKS * BLOCKSIZE))" -Wpetr
22+
mkfs.ext4 $INPUTDEVICE
23+
24+
if [ ! -d /mnt/tmp ]; then
25+
mkdir /mnt/tmp
26+
fi
27+
mount $INPUTDEVICE /mnt/tmp
28+
touch /mnt/tmp/testfile
29+
sleep .5
30+
umount /mnt/tmp
31+
echo "-------------------> Making compressed image <..."
32+
33+
dd if="$INPUTDEVICE" bs="$BLOCKSIZE" count="$NUMBLOCKS" | pv -s "$((NUMBLOCKS * BLOCKSIZE))" -Wpetr | create_compressed_fs -L "$COMPRESSIONLEVEL" -B "$CLOOPBLOCKSIZE" -s "$NUMBLOCKS"M - "$OUTPUTFILE" > "$CLOOPLOGFILE" 2>&1
34+
35+
#insmod /lib/modules/`uname -r`/cloop.ko file="$OUTPUTFILE"
36+
insmod ../../../../hyperblock_loop/drivers/block/cloop/cloop.ko file="$OUTPUTFILE"
37+
38+
mkdir -p /mnt/cloop
39+
mount -o ro /dev/cloop0 /mnt/cloop
40+
ls /mnt/cloop
41+

0 commit comments

Comments
 (0)