blob: 6bbf020de0d77fab4bdf81ebb90eec45d63f6943 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#!/bin/bash
# This is the script that was used to create the image.gz in this directory.
set -e -u
BLOCKSIZE=4096
do_debugfs() {
umount mnt
debugfs -w "$@" image
mount image mnt
}
do_tune2fs() {
umount mnt
tune2fs $@ image
mount image mnt
}
symlink() {
local len=$1
local src=$2
local target=$(perl -e 'print "A" x '$len)
ln -s $target $src
stat -c %i $src
}
# Overwrite the length in the header of the encrypted symlink target
set_encrypted_symlink_len() {
local ino=$1
local len=$2
echo "zap_block -f <$ino> -p $((len%256)) -o 0 -l 1 0"
echo "zap_block -f <$ino> -p $((len/256)) -o 1 -l 1 0"
}
create_symlinks() {
local dir=$1
local encrypted=${2:-false}
local overhead=0
local ino
if $encrypted; then
overhead=2
fi
mkdir -p $dir
{
ino=$(symlink 1 $dir/empty)
echo "set_inode_field <$ino> i_size 10"
echo "set_inode_field <$ino> block[0] 0"
symlink 1 $dir/fast_min > /dev/null
ino=$(symlink 10 $dir/fast_isize_too_small)
echo "set_inode_field <$ino> i_size 1"
ino=$(symlink 10 $dir/fast_isize_too_large)
echo "set_inode_field <$ino> i_size 20"
symlink $((59 - overhead)) $dir/fast_max > /dev/null
symlink $((60 - overhead)) $dir/slow_min > /dev/null
ino=$(symlink 100 $dir/slow_isize_too_small)
echo "set_inode_field <$ino> i_size 80"
ino=$(symlink 100 $dir/slow_isize_too_large)
echo "set_inode_field <$ino> i_size 120"
symlink $((BLOCKSIZE - 1 - overhead)) $dir/slow_max > /dev/null
ino=$(symlink $((BLOCKSIZE - 1 - overhead)) $dir/one_too_long)
echo "set_inode_field <$ino> i_size $BLOCKSIZE"
echo "zap_block -f <$ino> -p 65 0"
if $encrypted; then
set_encrypted_symlink_len $ino $((BLOCKSIZE - overhead))
fi
ino=$(symlink $((BLOCKSIZE - 1 - overhead)) $dir/too_long)
echo "set_inode_field <$ino> i_size $((BLOCKSIZE + 1000))"
echo "zap_block -f <$ino> -p 65 0"
if $encrypted; then
set_encrypted_symlink_len $ino $((BLOCKSIZE + 1000 - overhead))
fi
} >> debugfs_commands
do_debugfs < debugfs_commands
}
create_encrypted_symlinks() {
local dir=$1 link
mkdir $dir
echo | e4crypt add_key $dir
create_symlinks $dir true
# Move symlinks into an unencrypted directory (leaving their targets
# encrypted). This makes the fsck output consistent.
mv $dir ${dir}~encrypted
mkdir $dir
mv ${dir}~encrypted/* $dir
}
mkdir -p mnt
umount mnt &> /dev/null || true
dd if=/dev/zero of=image bs=1024 count=600
mke2fs -O 'encrypt,^extents,^64bit' -b $BLOCKSIZE -I 256 image
mount image mnt
create_symlinks mnt/default
create_encrypted_symlinks mnt/encrypted
do_tune2fs -O extents
create_symlinks mnt/extents
create_encrypted_symlinks mnt/extents_encrypted
do_debugfs -R 'feature inline_data'
create_symlinks mnt/inline_data
rm -rf debugfs_commands mnt/*~encrypted
umount mnt
rmdir mnt
gzip -9 -f image
|