2 # exercise du's --inodes option
4 # Copyright (C) 2010-2024 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
22 # An empty directory uses only 1 inode.
23 mkdir d || framework_failure_
24 printf '1\td\n' > exp || framework_failure_
26 du
--inodes d
> out
2>err || fail
=1
27 compare exp out || fail
=1
28 compare
/dev
/null err || fail
=1
30 # Add a regular file: 2 inodes used.
31 touch d
/f || framework_failure_
32 printf '2\td\n' > exp || framework_failure_
34 du
--inodes d
> out
2>err || fail
=1
35 compare exp out || fail
=1
36 compare
/dev
/null err || fail
=1
38 # Add a hardlink to the file: still only 2 inodes used.
39 ln -v d
/f d
/h || framework_failure_
40 du
--inodes d
> out
2>err || fail
=1
41 compare exp out || fail
=1
42 compare
/dev
/null err || fail
=1
44 # Now count also hardlinks (-l,--count-links): 3 inodes.
45 printf '3\td\n' > exp || framework_failure_
46 du
--inodes -l d
> out
2>err || fail
=1
47 compare exp out || fail
=1
48 compare
/dev
/null err || fail
=1
50 # Create a directory and summarize: 3 inodes.
51 mkdir d
/d || framework_failure_
52 du
--inodes -s d
> out
2>err || fail
=1
53 compare exp out || fail
=1
54 compare
/dev
/null err || fail
=1
56 # Count inodes separated: 1-2.
57 printf '1\td/d\n2\td\n' > exp || framework_failure_
58 du
--inodes -S d
> out
2>err || fail
=1
59 compare exp out || fail
=1
60 compare
/dev
/null err || fail
=1
62 # Count inodes cumulative (default): 1-3.
63 printf '1\td/d\n3\td\n' > exp || framework_failure_
64 du
--inodes d
> out
2>err || fail
=1
65 compare exp out || fail
=1
66 compare
/dev
/null err || fail
=1
68 # Count all items: 1-1-3.
69 # Sort output because the directory entry order is not defined.
70 # Also replace the hardlink with the original file name because
71 # the system may either return 'd/f' or 'd/h' first, and du(1)
72 # will ignore the other one.
73 printf '1\td/d\n1\td/f\n3\td\n' |
sort > exp || framework_failure_
74 du
--inodes -a d
> out.tmp
2>err || fail
=1
75 sed 's/h$/f/' out.tmp |
sort >out || framework_failure_
76 compare exp out || fail
=1
77 compare
/dev
/null err || fail
=1
79 # Count all items and hardlinks again: 1-1-1-4
80 # Sort output because the directory entry order is not defined.
81 printf '1\td/d\n1\td/h\n1\td/f\n4\td\n' |
sort > exp || framework_failure_
82 du
--inodes -al d
> out.tmp
2>err || fail
=1
83 sort <out.tmp
>out || framework_failure_
84 compare exp out || fail
=1
85 compare
/dev
/null err || fail
=1
87 # Run with total (-c) line: 1-3-3
88 printf '1\td/d\n3\td\n3\ttotal\n' > exp || framework_failure_
89 du
--inodes -c d
> out
2>err || fail
=1
90 compare exp out || fail
=1
91 compare
/dev
/null err || fail
=1
93 # Create another file in the subdirectory: 2-4
94 touch d
/d
/f || framework_failure_
95 printf '2\td/d\n4\td\n' > exp || framework_failure_
96 du
--inodes d
> out
2>err || fail
=1
97 compare exp out || fail
=1
98 compare
/dev
/null err || fail
=1
100 # Ensure human output (-h, --si) works.
101 rm -rf d || framework_failure_
102 mkdir d || framework_failure_
103 seq --format="d/file%g" 1023 |
xargs touch || framework_failure_
104 printf '1.0K\td\n' > exp || framework_failure_
105 du
--inodes -h d
> out
2>err || fail
=1
106 compare exp out || fail
=1
107 compare
/dev
/null err || fail
=1
109 printf '1.1k\td\n' > exp || framework_failure_
110 du
--inodes --si d
> out
2>err || fail
=1
111 compare exp out || fail
=1
112 compare
/dev
/null err || fail
=1
114 # Verify --inodes ignores -B.
115 printf '1024\td\n' > exp || framework_failure_
116 du
--inodes -B10 d
> out
2>err || fail
=1
117 compare exp out || fail
=1
118 compare
/dev
/null err || fail
=1
120 # Verify --inodes works with --threshold.
121 printf '1024\td\n' > exp || framework_failure_
122 du
--inodes --threshold=1000 d
> out
2>err || fail
=1
123 compare exp out || fail
=1
124 compare
/dev
/null err || fail
=1
126 du
--inodes --threshold=-1000 d
> out
2>err || fail
=1
127 compare
/dev
/null out || fail
=1
128 compare
/dev
/null err || fail
=1
130 # Verify --inodes raises a warning for --apparent-size and -b.
131 du
--inodes -b d
> out
2>err || fail
=1
132 grep ' ineffective ' err
>/dev
/null ||
{ fail
=1; cat out err
; }
134 du
--inodes --apparent-size d
> out
2>err || fail
=1
135 grep ' ineffective ' err
>/dev
/null ||
{ fail
=1; cat out err
; }
137 # Ensure that --inodes is mentioned in the usage.
138 du
--help > out || fail
=1
139 grep ' --inodes ' out
>/dev
/null ||
{ fail
=1; cat out
; }