1#!/bin/bash
2
3################################################################################
4##                                                                            ##
5## Copyright (c) 2009 FUJITSU LIMITED                                         ##
6##                                                                            ##
7## This program is free software;  you can redistribute it and#or modify      ##
8## it under the terms of the GNU General Public License as published by       ##
9## the Free Software Foundation; either version 2 of the License, or          ##
10## (at your option) any later version.                                        ##
11##                                                                            ##
12## This program is distributed in the hope that it will be useful, but        ##
13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
14## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
15## for more details.                                                          ##
16##                                                                            ##
17## You should have received a copy of the GNU General Public License          ##
18## along with this program;  if not, write to the Free Software               ##
19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
20##                                                                            ##
21## Author: Li Zefan <lizf@cn.fujitsu.com>                                     ##
22##         Miao Xie <miaox@cn.fujitsu.com>                                    ##
23##                                                                            ##
24################################################################################
25
26export TCID="ext4-inode-version"
27export TST_TOTAL=8
28
29. ext4_funcs.sh
30
31# Test that inode version is not 32 bits with 128 inode size
32ext4_test_128_inode_version()
33{
34	tst_resm TINFO "Test inode version is 32 bits with 128 inode size"
35
36	mkfs.ext4 -I 128 $EXT4_DEV >/dev/null 2>&1
37	if [ $? -ne 0 ]; then
38		tst_resm TFAIL "failed to create ext4 filesystem"
39		return
40	fi
41
42	tune2fs -O extents $EXT4_DEV >/dev/null 2>&1
43
44	mount -t ext4 -o i_version $EXT4_DEV mnt_point
45	if [ $? -ne 0 ]; then
46		tst_resm TFAIL "failed to mount ext4 filesystem"
47		return
48	fi
49
50	# inode version > 0
51	touch mnt_point/tmp_file
52	sync
53	version=`ext4_get_inode_version.sh tmp_file`
54
55	if [ $version -lt 1 ]; then
56		tst_resm TFAIL "inode version is smaller than 1"
57		umount mnt_point
58		return
59	fi
60
61	# inode version is 32 bits: 0x00000000
62	version=`debugfs $EXT4_DEV -R "stat tmp_file" 2> /dev/null | grep 'Version'`
63	version=`echo $version | awk '{ print $NF }'`
64	version=`echo $version | sed 's/^0x//'`
65	len=${#version}
66
67	if [ $len -ne 8 ]; then
68		tst_resm TFAIL "inode version is not 32 bits"
69		umount mnt_point
70		return
71	fi
72
73	umount mnt_point
74	if [ $? -ne 0 ]; then
75		tst_resm TFAIL "failed to umount ext4 filesystem"
76		return
77	fi
78
79	tst_resm TPASS "32 bits inode version with 128 inode size test pass"
80}
81
82# Test file timestamps is nanosecond with 256 inode size
83# $1: file operation
84test_inode_version()
85{
86	mkfs.ext3 -I 256 $EXT4_DEV >/dev/null 2>&1
87	if [ $? -ne 0 ]; then
88		tst_resm TFAIL "failed to create ext4 filesystem"
89		return
90	fi
91
92	mount -t ext4 -o i_version $EXT4_DEV mnt_point
93	if [ $? -ne 0 ]; then
94		tst_resm TFAIL "failed to mount ext4 filesystem"
95		return
96	fi
97
98	# Check the inode version after some file operation
99	old_version=`ext4_test_inode_version $1 mnt_point/tmp_file tmp_file`
100	if [ $? -ne 0 ]; then
101		tst_resm TFAIL "inode version is wrong"
102		umount mnt_point
103		return
104	fi
105
106	umount mnt_point
107	if [ $? -ne 0 ]; then
108		tst_resm TFAIL "failed to umount ext4 filesystem"
109		return
110	fi
111
112	# Test mount to ext3 and then mount back to ext4
113	mount -t ext3 $EXT4_DEV mnt_point
114	if [ $? -ne 0 ]; then
115		tst_resm TFAIL "failed to mount to ext3"
116		return
117	fi
118	umount mnt_point
119
120	mount -t ext4 $EXT4_DEV mnt_point
121	if [ $? -ne 0 ]; then
122		tst_resm TFAIL "failed to mount back to ext4"
123		return
124	fi
125
126	version=`ext4_get_inode_version.sh tmp_file`
127#	echo "remount: old - $old_version"
128#	echo "remount: new - $version"
129	if [ $old_version -ne $version ]; then
130		tst_resm TFAIL "inode version has changed unexpected"
131		umount mnt_point
132		return
133	else
134		tst_resm TPASS "inode version with 256 inode size test pass"
135		umount mnt_point
136	fi
137}
138
139# main
140ext4_setup
141
142ext4_test_128_inode_version
143
144test_inode_version create
145
146test_inode_version chmod
147
148test_inode_version chown
149
150test_inode_version read
151
152test_inode_version write
153
154test_inode_version mmap_read
155
156test_inode_version mmap_write
157
158tst_exit
159