xfs: test what happens when we reset the root dir and it has xattrs
[xfstests-dev.git] / tests / xfs / 151
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 151
6 #
7 # Make sure the xfs_db ls command works the way the author thinks it does.
8 # This means that we can list the current directory, list an arbitrary path,
9 # and we can't list things that aren't directories.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1    # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # real QA test starts here
31 _supported_fs xfs
32 _require_xfs_db_command "path"
33 _require_xfs_db_command "ls"
34 _require_scratch
35
36 echo "Format filesystem and populate"
37 _scratch_mkfs > $seqres.full
38 _scratch_mount >> $seqres.full
39
40 $XFS_INFO_PROG $SCRATCH_MNT | grep -q ftype=1 || \
41         _notrun "filesystem does not support ftype"
42
43 filter_ls() {
44         awk '
45 BEGIN { cookie = 0; }
46 {
47         if (cookie == 0)
48                 cookie = $1;
49         printf("+%d %s %s %s %s %s\n", $1 - cookie, $2, $3, $4, $5, $6);
50         cookie = $1;
51 }' | \
52         sed     -e "s/ $root_ino directory / root directory /g" \
53                 -e "s/ $a_ino directory / a_ino directory /g" \
54                 -e "s/ $b_ino directory / b_ino directory /g" \
55                 -e "s/ $c_ino regular / c_ino regular /g" \
56                 -e "s/ $d_ino symlink / d_ino symlink /g" \
57                 -e "s/ $e_ino blkdev / e_ino blkdev /g" \
58                 -e "s/ $f_ino chardev / f_ino chardev /g" \
59                 -e "s/ $g_ino fifo / g_ino fifo /g" \
60                 -e "s/ $big0_ino regular / big0_ino regular /g" \
61                 -e "s/ $big1_ino regular / big1_ino regular /g" \
62                 -e "s/ $h_ino regular / g_ino regular /g"
63 }
64
65 mkdir $SCRATCH_MNT/a
66 mkdir $SCRATCH_MNT/a/b
67 $XFS_IO_PROG -f -c 'pwrite 0 61' $SCRATCH_MNT/a/c >> $seqres.full
68 ln -s -f b $SCRATCH_MNT/a/d
69 mknod $SCRATCH_MNT/a/e b 0 0
70 mknod $SCRATCH_MNT/a/f c 0 0
71 mknod $SCRATCH_MNT/a/g p
72 touch $SCRATCH_MNT/a/averylongnameforadirectorysothatwecanpushthecookieforward
73 touch $SCRATCH_MNT/a/andmakethefirstcolumnlookmoreinterestingtopeoplelolwtfbbq
74 touch $SCRATCH_MNT/a/h
75
76 root_ino=$(stat -c '%i' $SCRATCH_MNT)
77 a_ino=$(stat -c '%i' $SCRATCH_MNT/a)
78 b_ino=$(stat -c '%i' $SCRATCH_MNT/a/b)
79 c_ino=$(stat -c '%i' $SCRATCH_MNT/a/c)
80 d_ino=$(stat -c '%i' $SCRATCH_MNT/a/d)
81 e_ino=$(stat -c '%i' $SCRATCH_MNT/a/e)
82 f_ino=$(stat -c '%i' $SCRATCH_MNT/a/f)
83 g_ino=$(stat -c '%i' $SCRATCH_MNT/a/g)
84 big0_ino=$(stat -c '%i' $SCRATCH_MNT/a/avery*)
85 big1_ino=$(stat -c '%i' $SCRATCH_MNT/a/andma*)
86 h_ino=$(stat -c '%i' $SCRATCH_MNT/a/h)
87
88 _scratch_unmount
89
90 echo "Manually navigate to root dir then list"
91 _scratch_xfs_db -c 'sb 0' -c 'addr rootino' -c ls | filter_ls
92
93 echo "Use path to navigate to root dir then list"
94 _scratch_xfs_db -c 'path /' -c ls | filter_ls
95
96 echo "Use path to navigate to /a then list"
97 _scratch_xfs_db -c 'path /a' -c ls | filter_ls
98
99 echo "Use path to navigate to /a/b then list"
100 _scratch_xfs_db -c 'path /a/b' -c ls | filter_ls
101
102 echo "Use path to navigate to /a/c (non-dir) then list"
103 _scratch_xfs_db -c 'path /a/c' -c ls
104
105 # success, all done
106 status=0
107 exit