]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - spaceman/xfs_info.sh
xfsprogs: Release v6.7.0
[thirdparty/xfsprogs-dev.git] / spaceman / xfs_info.sh
CommitLineData
2bd0ea18 1#!/bin/sh -f
959ef981 2# SPDX-License-Identifier: GPL-2.0
2bd0ea18 3#
0d3e0b37 4# Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved.
dfc130f3 5#
2bd0ea18
NS
6
7OPTS=""
6750f2b8 8USAGE="Usage: xfs_info [-V] [-t mtab] [mountpoint|device|file]"
2bd0ea18 9
bbb43745
DW
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.
13try_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
9440d84d 18while getopts "t:V" c
2bd0ea18
NS
19do
20 case $c in
21 t) OPTS="-t $OPTARG" ;;
3fda24ed 22 V) xfs_spaceman -p xfs_info -V
138aab65
CH
23 status=$?
24 exit $status
25 ;;
2bd0ea18
NS
26 *) echo $USAGE 1>&2
27 exit 2
28 ;;
29 esac
30done
50b1dd46 31set -- extra "$@"
2bd0ea18
NS
32shift $OPTIND
33case $# in
6750f2b8 34 1)
bbb43745
DW
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.
e0bdad06 43 if mountpt="$(findmnt -t xfs -f -n -o TARGET "${arg}" 2> /dev/null)"; then
bbb43745 44 xfs_spaceman -p xfs_info -c "info" $OPTS "${mountpt}"
6750f2b8
DW
45 status=$?
46 else
bbb43745 47 xfs_db -p xfs_info -c "info" $OPTS "${arg}"
6750f2b8
DW
48 status=$?
49 fi
2bd0ea18
NS
50 ;;
51 *) echo $USAGE 1>&2
52 exit 2
53 ;;
54esac
55exit $status