xfstests: check for ctime updates on link(2)
[xfstests-dev.git] / 236
1 #! /bin/bash
2 # FS QA Test No. 236
3 #
4 # Check ctime updated or not if file linked
5 # See also http://marc.info/?l=linux-btrfs&m=127434439020230&w=2
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2010 FUJITSU LIMITED. All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would 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 the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25 # creator
26 owner=shiwh@cn.fujitsu.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30
31 _cleanup()
32 {
33         if [ -a $TEST_DIR/ouch2 ]; then
34                 rm -f $TEST_DIR/ouch2
35         fi
36         if [ -a $TEST_DIR/ouch ]; then
37                 rm -f $TEST_DIR/ouch
38         fi
39 }
40
41 here=`pwd`
42
43 # get standard environment, filters and checks
44 . ./common.rc
45
46 # real QA test starts here
47 _supported_fs generic
48 # only Linux supports fallocate
49 _supported_os Linux
50
51 # create a file and get its ctime
52 touch $TEST_DIR/ouch
53 ctime=`stat -c %Z $TEST_DIR/ouch`
54 sleep 1
55
56 # create a link to a file and get existing file's ctime
57 link $TEST_DIR/ouch $TEST_DIR/ouch2
58 ctime2=`stat -c %Z $TEST_DIR/ouch`
59
60 # check ctime updated
61 if [ $ctime2 -le $ctime ]; then
62         echo "ctime: $ctime -> $ctime2 "
63         echo "Fatal error: ctime not updated after link"
64         _cleanup
65         exit 1
66 fi
67
68 _cleanup
69
70 echo "Test over."
71 # success, all done
72 status=0
73 exit