-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextents-list
executable file
·50 lines (45 loc) · 1.26 KB
/
extents-list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# SPDX-FileCopyrightText: 2016-2020 Graham R. Cobb
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Copyright (C) 2016 Graham R. Cobb
# Released under GPL V3.0 -- see LICENSE
#
# extents-list [-s] <find-options>...
#
# Where <find-options> are options which will be passed to the find
# command to result in a list of files to be considered.
#
# Examples:
#
# extents-list some-directory/some-file
# extents-list some-directory
# extents-list subvolume-directory -mount
#
# Make sure errors are passed back
set -o pipefail
if [ "$1" = "-s" ]
then
shift
$0 "$@" | extents-size
exit $?
fi
if [ $# -eq 0 ]
then
echo "$0: No file specified" >&2
echo "Usage: $0 <find-options>..." >&2
exit 1
fi
# find all the files
find "$@" -type f -print0 |
# list each file's extents
xargs -0 filefrag -vs |
# Get just the extent starts and ends
awk -e '
/^[[:space:]]*[[:digit:]]+:[[:space:]]*[[:digit:]]+..[[:space:]]*[[:digit:]]+:[[:space:]]*([[:digit:]]+)..[[:space:]]*([[:digit:]]+):/ {
if ( (! match($0,/inline/)) &&
match($0, /^[[:space:]]*[[:digit:]]+:[[:space:]]*[[:digit:]]+..[[:space:]]*[[:digit:]]+:[[:space:]]*([[:digit:]]+)..[[:space:]]*([[:digit:]]+):/, a) > 0)
print a[1], a[2]
}
' |
extents-merge