Initial release for Tizen
[platform/upstream/ecryptfs-utils.git] / tests / kernel / link.sh
1 #!/bin/bash
2 #
3 # link.sh : Simple hard link sanity check
4 #
5 # Author: Colin Ian King <colin.king@canonical.com>
6 #
7 # Copyright (C) 2013 Canonical Ltd.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation version 2
12 # of the License.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
23 test_script_dir=$(dirname $0)
24 rc=1
25 test_dir=0
26
27 . ${test_script_dir}/../lib/etl_funcs.sh
28
29 test_cleanup()
30 {
31         etl_remove_test_dir $test_dir
32         etl_umount
33         etl_lumount
34         etl_unlink_keys
35         exit $rc
36 }
37 trap test_cleanup 0 1 2 3 15
38
39 # TEST
40 etl_add_keys || exit
41 etl_lmount || exit
42 etl_mount_i || exit
43 test_dir=$(etl_create_test_dir) || exit
44 test_file1="${test_dir}/test1"
45 test_file2="${test_dir}/test2"
46
47 echo "Testing 1 2 3" > $test_file1
48
49 ln $test_file1 $test_file2
50
51 rc=0
52 #
53 #  Contents should be the same
54 #
55 diff $test_file1 $test_file2 > /dev/null 2>&1
56 if [ $? -ne 0 ]; then
57         rc=1
58 fi
59
60 #
61 #  Size should be the same
62 #
63 test_file1_size=$(stat -c%s $test_file1)
64 test_file2_size=$(stat -c%s $test_file2)
65 if [ $test_file1_size -ne $test_file2_size ]; then
66         rc=1
67 fi
68         
69 #
70 #  Link count should be 2 for both
71 #
72 test_file1_links=$(stat -c%h $test_file1)
73 test_file2_links=$(stat -c%h $test_file2)
74 if [ $test_file1_links -ne 2 -a $test_file2_links -ne 2 ]; then
75         rc=1
76 fi
77
78 rm -f $test_file1 $test_file2
79
80 etl_umount || exit
81 etl_mount_i || exit
82
83 exit