Whamcloud - gitweb
Prevent i_dtime from being mistaken for an inode number post-2038 wraparound
[tools/e2fsprogs.git] / tests / f_pre_1970_date_encoding / script
1 if ! test -x $DEBUGFS_EXE; then
2         echo "$test_name: $test_description: skipped (no debugfs)"
3         return 0
4 fi
5
6 OUT=$test_name.log
7 TIMESTAMPS=$test_name.timestamps.log
8 EXP=$test_dir/expect
9 FSCK_OPT=-yf
10
11 create_file_with_xtime_and_extra() {
12         name=$1
13         time=$2
14         extra=$3
15         {
16                 echo "write /dev/null $name"
17                 for xtime in atime ctime mtime crtime; do
18                         echo "set_inode_field $name $xtime @$time"
19                         echo "set_inode_field $name ${xtime}_extra $extra"
20                 done
21         } | $DEBUGFS -w $TMPFILE >> $OUT 2>&1
22 }
23
24 get_file_xtime_and_extra() {
25         name=$1
26         echo "times for $name =" >> $TIMESTAMPS
27         $DEBUGFS -R "stat $name" $TMPFILE 2>&1 | egrep '^( a| c| m|cr)time:' |
28                 sed 's/ --.*//' >> $TIMESTAMPS
29 }
30
31 rm -f $OUT $TIMESTAMPS
32
33 # create an empty ext4 filesystem with 256-byte inodes for testing
34 > $TMPFILE
35 echo mkfs.ext4 -b 1024 -q -I 256 $TMPFILE 5000 >> $OUT
36 $MKE2FS -t ext4 -b 1024 -q -I 256 -F $TMPFILE 5000 >> $OUT 2>&1
37
38 # this is a pre-1970 file encoded with the old encoding.
39 # fsck should repair this
40 create_file_with_xtime_and_extra year-1909 -1907928000 3
41
42 # these are all already encoded correctly
43 create_file_with_xtime_and_extra year-1979   299592000 0
44 create_file_with_xtime_and_extra year-2039  2191752000 1
45 create_file_with_xtime_and_extra year-2139  5345352000 1
46
47 # confirm that the xtime is wrong on the pre-1970 file
48 get_file_xtime_and_extra year-1909
49
50 # and confirm that it is right on the remaining files
51 get_file_xtime_and_extra year-1979
52 get_file_xtime_and_extra year-2039
53 get_file_xtime_and_extra year-2139
54
55 # before we repair the filesystem, save off a copy so that
56 # we can use it later
57
58 cp -a $TMPFILE $TMPFILE.sav
59
60 # repair the filesystem
61 E2FSCK_TIME=1386393539 $FSCK $FSCK_OPT $TMPFILE >> $OUT 2>&1
62
63 # check that the dates and xtime_extra on the file is now correct
64 get_file_xtime_and_extra year-1909
65
66 # check that the remaining dates have not been altered
67 get_file_xtime_and_extra year-1979
68 get_file_xtime_and_extra year-2039
69 get_file_xtime_and_extra year-2139
70
71 if test $SIZEOF_TIME_T -gt 4
72 then
73   # now we need to check that after the year 2242, e2fsck does not
74   # modify dates with extra_xtime=3
75
76   # restore the unrepaired filesystem
77   mv $TMPFILE.sav $TMPFILE
78
79   #retry the repair
80   E2FSCK_TIME=9270393539 $FSCK $FSCK_OPT $TMPFILE >> $OUT 2>&1
81
82   # check that the 1909 file is unaltered (i.e. it has a post-2378 date)
83   get_file_xtime_and_extra year-1909
84 else
85   rm -f TMPFILE.sav
86 cat << EOF >> $TIMESTAMPS
87 times for year-1909 =
88  ctime: 0x8e475440:00000003
89  atime: 0x8e475440:00000003
90  mtime: 0x8e475440:00000003
91 crtime: 0x8e475440:00000003
92 EOF
93 fi
94
95 cmp -s $TIMESTAMPS $EXP
96 status=$?
97
98 if [ "$status" = 0 ]; then
99         echo "$test_name: $test_description: ok"
100         touch $test_name.ok
101 else
102         echo "$test_name: $test_description: failed"
103         diff $DIFF_OPTS $EXP $TIMESTAMPS > $test_name.failed
104 fi
105
106 unset OUT TIMESTAMPS EXP FSCK_OPT