1if ! test -x $DEBUGFS_EXE; then 2 echo "$test_name: $test_description: skipped (no debugfs)" 3 return 0 4fi 5 6OUT=$test_name.log 7TIMESTAMPS=$test_name.timestamps.log 8EXP=$test_dir/expect 9FSCK_OPT=-yf 10 11create_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 -f /dev/stdin $TMPFILE >> $OUT 2>&1 22} 23 24get_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 31rm -f $OUT $TIMESTAMPS 32 33# create an empty ext4 filesystem with 256-byte inodes for testing 34> $TMPFILE 35echo 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 40create_file_with_xtime_and_extra year-1909 -1907928000 3 41 42# these are all already encoded correctly 43create_file_with_xtime_and_extra year-1979 299592000 0 44create_file_with_xtime_and_extra year-2039 2191752000 1 45create_file_with_xtime_and_extra year-2139 5345352000 1 46 47# confirm that the xtime is wrong on the pre-1970 file 48get_file_xtime_and_extra year-1909 49 50# and confirm that it is right on the remaining files 51get_file_xtime_and_extra year-1979 52get_file_xtime_and_extra year-2039 53get_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 58cp -a $TMPFILE $TMPFILE.sav 59 60# repair the filesystem 61E2FSCK_TIME=1386393539 $FSCK $FSCK_OPT $TMPFILE >> $OUT 2>&1 62 63# check that the dates and xtime_extra on the file is now correct 64get_file_xtime_and_extra year-1909 65 66# check that the remaining dates have not been altered 67get_file_xtime_and_extra year-1979 68get_file_xtime_and_extra year-2039 69get_file_xtime_and_extra year-2139 70 71if test $SIZEOF_TIME_T -gt 4 72then 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 84else 85 rm -f TMPFILE.sav 86cat << EOF >> $TIMESTAMPS 87times for year-1909 = 88 ctime: 0x8e475440:00000003 89 atime: 0x8e475440:00000003 90 mtime: 0x8e475440:00000003 91crtime: 0x8e475440:00000003 92EOF 93fi 94 95cmp -s $TIMESTAMPS $EXP 96status=$? 97 98if [ "$status" = 0 ]; then 99 echo "$test_name: $test_description: ok" 100 touch $test_name.ok 101else 102 echo "$test_name: $test_description: failed" 103 diff $DIFF_OPTS $EXP $TIMESTAMPS > $test_name.failed 104fi 105 106unset OUT TIMESTAMPS EXP FSCK_OPT 107