fstests: move test group info to test files
[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 . ./common/preamble
12 _begin_fstest auto quick db
13
14 # Import common functions.
15 . ./common/filter
16
17 # real QA test starts here
18 _supported_fs xfs
19 _require_xfs_db_command "path"
20 _require_xfs_db_command "ls"
21 _require_scratch
22
23 echo "Format filesystem and populate"
24 _scratch_mkfs > $seqres.full
25 _scratch_mount >> $seqres.full
26
27 $XFS_INFO_PROG $SCRATCH_MNT | grep -q ftype=1 || \
28         _notrun "filesystem does not support ftype"
29
30 filter_ls() {
31         awk '
32 BEGIN { cookie = 0; }
33 {
34         if (cookie == 0)
35                 cookie = $1;
36         printf("+%d %s %s %s %s %s\n", $1 - cookie, $2, $3, $4, $5, $6);
37         cookie = $1;
38 }' | \
39         sed     -e "s/ $root_ino directory / root directory /g" \
40                 -e "s/ $a_ino directory / a_ino directory /g" \
41                 -e "s/ $b_ino directory / b_ino directory /g" \
42                 -e "s/ $c_ino regular / c_ino regular /g" \
43                 -e "s/ $d_ino symlink / d_ino symlink /g" \
44                 -e "s/ $e_ino blkdev / e_ino blkdev /g" \
45                 -e "s/ $f_ino chardev / f_ino chardev /g" \
46                 -e "s/ $g_ino fifo / g_ino fifo /g" \
47                 -e "s/ $big0_ino regular / big0_ino regular /g" \
48                 -e "s/ $big1_ino regular / big1_ino regular /g" \
49                 -e "s/ $h_ino regular / g_ino regular /g"
50 }
51
52 mkdir $SCRATCH_MNT/a
53 mkdir $SCRATCH_MNT/a/b
54 $XFS_IO_PROG -f -c 'pwrite 0 61' $SCRATCH_MNT/a/c >> $seqres.full
55 ln -s -f b $SCRATCH_MNT/a/d
56 mknod $SCRATCH_MNT/a/e b 0 0
57 mknod $SCRATCH_MNT/a/f c 0 0
58 mknod $SCRATCH_MNT/a/g p
59 touch $SCRATCH_MNT/a/averylongnameforadirectorysothatwecanpushthecookieforward
60 touch $SCRATCH_MNT/a/andmakethefirstcolumnlookmoreinterestingtopeoplelolwtfbbq
61 touch $SCRATCH_MNT/a/h
62
63 root_ino=$(stat -c '%i' $SCRATCH_MNT)
64 a_ino=$(stat -c '%i' $SCRATCH_MNT/a)
65 b_ino=$(stat -c '%i' $SCRATCH_MNT/a/b)
66 c_ino=$(stat -c '%i' $SCRATCH_MNT/a/c)
67 d_ino=$(stat -c '%i' $SCRATCH_MNT/a/d)
68 e_ino=$(stat -c '%i' $SCRATCH_MNT/a/e)
69 f_ino=$(stat -c '%i' $SCRATCH_MNT/a/f)
70 g_ino=$(stat -c '%i' $SCRATCH_MNT/a/g)
71 big0_ino=$(stat -c '%i' $SCRATCH_MNT/a/avery*)
72 big1_ino=$(stat -c '%i' $SCRATCH_MNT/a/andma*)
73 h_ino=$(stat -c '%i' $SCRATCH_MNT/a/h)
74
75 _scratch_unmount
76
77 echo "Manually navigate to root dir then list"
78 _scratch_xfs_db -c 'sb 0' -c 'addr rootino' -c ls | filter_ls
79
80 echo "Use path to navigate to root dir then list"
81 _scratch_xfs_db -c 'path /' -c ls | filter_ls
82
83 echo "Use path to navigate to /a then list"
84 _scratch_xfs_db -c 'path /a' -c ls | filter_ls
85
86 echo "Use path to navigate to /a/b then list"
87 _scratch_xfs_db -c 'path /a/b' -c ls | filter_ls
88
89 echo "Use path to navigate to /a/c (non-dir) then list"
90 _scratch_xfs_db -c 'path /a/c' -c ls
91
92 # success, all done
93 status=0
94 exit