3 ################################################################################
5 ## Copyright (c) 2009 FUJITSU LIMITED ##
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. ##
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. ##
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
21 ## Author: Li Zefan <lizf@cn.fujitsu.com> ##
22 ## Miao Xie <miaox@cn.fujitsu.com> ##
24 ################################################################################
26 cd $LTPROOT/testcases
/bin
30 export TCID
="ext4-nsec-timestamps"
39 # Test that file timestamps is second with 128 inode size
40 ext4_test_sec_timestamps
()
42 tst_resm TINFO
"Test timestamps with 128 inode size"
44 mkfs.ext4
-I 128 $EXT4_DEV > /dev
/null
46 tst_resm TFAIL
"failed to create ext4 filesystem"
50 tune2fs
-E test_fs
-O extents
$EXT4_DEV
52 mount
-t ext4
$EXT4_DEV mnt_point
54 tst_resm TFAIL
"failed to mount ext4 filesystem"
58 touch mnt_point
/tmp_file
60 atime
=`./ext4_file_time mnt_point/tmp_file atime nsec`
61 mtime
=`./ext4_file_time mnt_point/tmp_file mtime nsec`
62 ctime
=`./ext4_file_time mnt_point/tmp_file ctime nsec`
64 if [ $atime -ne 0 -o $mtime -ne 0 -o $ctime -ne 0 ]; then
65 tst_resm TFAIL
"Timestamp is not second(atime: $atime, mtime: \
66 $mtime, ctime: $ctime)"
73 tst_resm TFAIL
"failed to umount ext4 filesystem"
77 tst_resm TPASS
"Ext4 nanosecond timestamps test with 128 inode size pass"
80 # Test file timestamps is nanosecond with 256 inode size
81 ext4_test_nsec_timestamps
()
83 tst_resm TINFO
"Test timestamps with 256 inode size"
85 mkfs.ext3
-I 256 $EXT4_DEV > /dev
/null
87 tst_resm TFAIL
"failed to create ext4 filesystem"
91 tune2fs
-E test_fs
$EXT4_DEV
93 mount
-t ext4
$EXT4_DEV mnt_point
95 tst_resm TFAIL
"failed to mount ext4 filesystem"
100 touch mnt_point
/tmp_file
103 # Change atime, ctime and mtime of the file
104 touch mnt_point
/tmp_file
106 cur_time
=`date '+%s %N'`
107 sec
=`echo $cur_time | awk {'print $1'}`
108 nsec
=`echo $cur_time | awk {'print $2'}`
110 sec_atime
=`./ext4_file_time mnt_point/tmp_file atime sec`
111 sec_mtime
=`./ext4_file_time mnt_point/tmp_file mtime sec`
112 sec_ctime
=`./ext4_file_time mnt_point/tmp_file ctime sec`
113 nsec_atime
=`./ext4_file_time mnt_point/tmp_file atime nsec`
114 nsec_mtime
=`./ext4_file_time mnt_point/tmp_file mtime nsec`
115 nsec_ctime
=`./ext4_file_time mnt_point/tmp_file ctime nsec`
118 if [ $nsec_atime -eq 0 -a $nsec_mtime -eq 0 -a $nsec_ctime -eq 0 ]
120 tst_resm TFAIL
"The timestamp is not nanosecond(nsec_atime: $nsec_atime, nsec_mtime: $nsec_mtime, nsec_ctime: $nsec_ctime)"
125 diff1
=$
(( $sec_atime - $sec ))
126 diff2
=$
(( $sec_mtime - $sec ))
127 diff3=$
(( $sec_ctime - $sec ))
129 # Test difference between file time and current time
130 if [ $diff1 -gt 1 -o $diff2 -gt 1 -o $diff2 -gt 1 ]; then
131 tst_resm TFAIL
"The timestamp is wrong, it must be earlier \
132 than the current time we got.(sec_atime: $sec_atime, \
133 sec_mtime: $sec_mtime, sec_ctime: $sec_ctime, \
140 if [ $?
-ne 0 ]; then
141 tst_resm TFAIL
"failed to umount ext4 filesystem"
145 # Test mount to ext3 and then mount back to ext4
146 mount
-t ext3
$EXT4_DEV mnt_point
147 if [ $?
-ne 0 ]; then
148 tst_resm TFAIL
"failed to mount to ext3"
153 mount
-t ext4
$EXT4_DEV mnt_point
154 if [ $?
-ne 0 ]; then
155 tst_resm TFAIL
"failed to mount back to ext4"
159 nsec_atime2
=`./ext4_file_time mnt_point/tmp_file atime nsec`
160 nsec_mtime2
=`./ext4_file_time mnt_point/tmp_file mtime nsec`
161 nsec_ctime2
=`./ext4_file_time mnt_point/tmp_file mtime nsec`
163 if [ $nsec_atime -ne $nsec_atime2 -o $nsec_ctime -ne $nsec_ctime2 -o \
164 $nsec_mtime -ne $nsec_mtime2 ]; then
165 tst_resm TFAIL
"File nanosecond timestamp has changed \
166 unexpected. Before[atime mtime ctime]: $nsec_atime \
167 $nsec_mtime $nsec_ctime, After[atime mtime ctime]: \
168 $nsec_atime2 $nsec_mtime2 $nsec_ctime2)"
174 tst_resm TPASS
"Ext4 nanosecond timestamps test with 256 inode size pass"
182 ext4_test_sec_timestamps
188 ext4_test_nsec_timestamps