]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - spaceman/xfs_info.sh
xfsprogs: Release v6.7.0
[thirdparty/xfsprogs-dev.git] / spaceman / xfs_info.sh
1 #!/bin/sh -f
2 # SPDX-License-Identifier: GPL-2.0
3 #
4 # Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
5 #
6
7 OPTS=""
8 USAGE="Usage: xfs_info [-V] [-t mtab] [mountpoint|device|file]"
9
10 # Try to find a loop device associated with a file. We only want to return
11 # one loopdev (multiple loop devices can attach to a single file) so we grab
12 # the last line and return it if it's actually a block device.
13 try_find_loop_dev_for_file() {
14 local x="$(losetup -O NAME -j "$1" 2> /dev/null | tail -n 1)"
15 test -b "$x" && echo "$x"
16 }
17
18 while getopts "t:V" c
19 do
20 case $c in
21 t) OPTS="-t $OPTARG" ;;
22 V) xfs_spaceman -p xfs_info -V
23 status=$?
24 exit $status
25 ;;
26 *) echo $USAGE 1>&2
27 exit 2
28 ;;
29 esac
30 done
31 set -- extra "$@"
32 shift $OPTIND
33 case $# in
34 1)
35 arg="$1"
36
37 # See if we can map the arg to a loop device
38 loopdev="$(try_find_loop_dev_for_file "${arg}")"
39 test -n "${loopdev}" && arg="${loopdev}"
40
41 # If we find a mountpoint for the device, do a live query;
42 # otherwise try reading the fs with xfs_db.
43 if mountpt="$(findmnt -t xfs -f -n -o TARGET "${arg}" 2> /dev/null)"; then
44 xfs_spaceman -p xfs_info -c "info" $OPTS "${mountpt}"
45 status=$?
46 else
47 xfs_db -p xfs_info -c "info" $OPTS "${arg}"
48 status=$?
49 fi
50 ;;
51 *) echo $USAGE 1>&2
52 exit 2
53 ;;
54 esac
55 exit $status