This file is indexed.

/usr/bin/drivemap is in bilibop-common 0.4.20.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/sh

# /usr/bin/drivemap
# Show block devices in a tree of dependencies.

# Works fine with:
#!/bin/bash
#!/bin/dash
#!/bin/busybox sh
#!/usr/lib/klibc/bin/sh.shared
# So, /bin/sh can be a link to /bin/bash, /bin/dash, /bin/busybox or even
# /usr/lib/klibc/bin/sh.shared

PATH="/bin:/usr/bin"
PROG="${0##*/}"

DEBUG="false"

_drive_="false"
_backing_file_="false"
_info_="false"
_mark_="false"
_dm_name_="false"
_mountpoint_="false"
_set_x_="false"
_width_="70"

[ -z "${COLUMNS}" ] &&
	COLUMNS="$(stty size | sed 's,.*\s\([[:digit:]]\+\)$,\1,')" &&
	export COLUMNS

FILE=""

ALREADY_DONE=""
_opts_=""

. /lib/bilibop/drivemap.sh
_drivemap_initial_indent

short_usage() {
	cat <<EOF
usage:
  ${PROG} -h|--help
  ${PROG} [--debug] [-i|--info [-wN|--width=N]] [-d|--drive] [FILE]
  ${PROG} [--debug] [-i|--info [-wN|--width=N]] [-f|--backing-file] [-n|--dm-name] [-m|--mark] [FILE]
EOF
}

usage() {
	cat <<EOF
${PROG}: show block devices in a tree of dependencies
usage:
  ${PROG} [OPTIONS] -- [FILE]
options:
  --debug		Output debug informations on stderr.
  -d, --drive		Display only physical disk names.
  -f, --backing-file	Replace each loop device by its backing file.
  -h, --help		Print this message on stdout and exit.
  -i, --info		Give more informations about devices.
  -m, --mark		Mark the device hosting the FILE given as argument.
  -n, --dm-name		Replace each device-mapper node by its name.
  -p, --mountpoint	Show the mountpoints or swap devices in use.
  -w N, --width=N	Set the width of the output (default is 70).
  -x, --set-x		Set shell option -x.

FILE can be either a regular file, a directory or a block device. If FILE
is not specified, then ${PROG} will display informations about all disks.
EOF
}


# Parse options with getopt.
ARGS="$(getopt -o dfhimnpw:x --long backing-file,debug,dm-name,drive,help,info,mark,mountpoint,set-x,width: -n "${PROG}" -- "${@}")"
if	[ "${?}" = "0" ]
then	eval set -- "$ARGS"
else	short_usage >&2
	exit 1
fi

# Now we can analyse the result. Some options will be stored into the '_opts_'
# variable, for the case we have to run this script from inside itself (this
# will be the case if the -a or --all option is invoked; see below).
while	true
do
	case "${1}" in
		--debug)
			DEBUG="true"
			_opts_="${_opts_:+${_opts_} }${1}"
			shift
			;;
		-d|--drive)
			_drive_="true"
			_opts_="${_opts_:+${_opts_} }${1}"
			shift
			;;
		-f|--backing-file)
			_backing_file_="true"
			_opts_="${_opts_:+${_opts_} }${1}"
			shift
			;;
		-h|--help)
			usage
			exit 0
			;;
		-i|--info)
			_info_="true"
			_opts_="${_opts_:+${_opts_} }${1}"
			shift
			;;
		-m|--mark)
			_mark_="true"
			_opts_="${_opts_:+${_opts_} }${1}"
			shift
			;;
		-n|--dm-name)
			_dm_name_="true"
			_opts_="${_opts_:+${_opts_} }${1}"
			shift
			;;
		-p|--mountpoint)
			_mountpoint_="true"
			_opts_="${_opts_:+${_opts_} }${1}"
			shift
			;;
		-w|--width)
			echo "${2}" | grep -q '^[1-9][0-9]\+$' &&
			_width_="${2}" ||
			_width_="${COLUMNS}"
			[ ${_width_} -gt ${COLUMNS} ] &&
			_width_="${COLUMNS}"
			_opts_="${_opts_:+${_opts_} }-w${_width_}"
			shift 2
			;;
		-x|--set-x)
			_set_x_="true"
			_opts_="${_opts_:+${_opts_} }${1}"
			shift
			;;
		--)
			shift
			break
			;;
		*)
			unknown_argument "${1}" >&2
			short_usage >&2
			exit 1
			;;
	esac
done

${DEBUG} && echo "${ARGS}" >&2
${_set_x_} && set -x

# Now we can analyse argument(s) that are not options (not beginning with a
# dash '-').
for	arg
do
	if	[ -e "${arg}" ]
	then	FILE="${arg}"
		[ -b "${DEVICE}" ] && break
		if	[ -b "${FILE}" ]
		then	DEVICE="$(readlink -f ${FILE})"
		else	DEVICE="$(underlying_device_from_file ${FILE})"
		fi
		# We use the first existing argument. All others (previous
		# bad arguments and next arguments) are silently discarded
		break
	fi
done

# Now, if there was at least one argument but all were rejected as non
# existing, display an error message about each bad argument and exit.
if	[ ! -e "${FILE}" -a -n "$*" ]
then
	for	arg
	do
		unknown_argument "${arg}" >&2
	done
	echo "Nothing to do. Exit." >&2
	exit 1
fi

# If the --mark option is invoked but no FILE is given as argument, mark
# the device of the current working directory:
if	[ "${_mark_}" = "true" ]
then
	[ -e "${FILE}" ] ||
	export DEVICE="$(underlying_device_from_file ${PWD})"
fi

# If the --mountpoint option is invoked, we need to know the length of
# the longest mountpoint string; the shortest being / with length = 1.
if	[ "${_mountpoint_}" = "true" -a -z "${length}" ]
then
	export length="$(_drivemap_max_mp_length)"
fi

# If no DEVICE, DIR or FILE has been given as argument, process on all known
# disks:
if	[ ! -e "${FILE}" ]
then
	for	dev in /sys/block/*
	do
		node="${dev##*/}"
		case "${node}" in
			loop*|dm-*|ram*)
				# Avoid duplicates: all associated loop devices
				# and each dm device are underlyed by a disk
				# node in last instance.
				continue
				;;
		esac

		# For each whole disk, run the same command with the same
		# options.
		${0} ${_opts_} "${udev_root}/${node}"
		[ "${_drive_}" = "true" ] || echo
	done
	exit $?
fi

# Begin by finding the base device, i.e the disk hosting the file (or '/' if
# $file is empty).
readonly DRIVE="$(physical_hard_disk ${FILE})"
[ -b "${DRIVE}" ] || exit 127

# Output the name of the disk hosting the file given as argument, and
# optionally some extra information (disk identifier and size) on the
# same line:
_drivemap_whole_disk "${DRIVE}"

# Otherwise, for the case there is a CD into the CD drive, and for the
# case the whole disk is used as container for a filesystem, RAID array,
# PhysicalVolume, etc.
[ -n "${ID_FS_USAGE}" ] &&
_drivemap_whole_disk_fs "${DRIVE}"

# If we have not explicitly asked to show how the disk is divided, nothing
# else to do.
[ "${_drive_}" = "true" ] && exit 0

# If the disk is associated to a loop device:
_drivemap_loopback_device "${DRIVE##*/}"

# Otherwise, verify if the whole disk is not a LUKS, RAID or LVM
# container:
_drivemap_dmdevice_holder "${DRIVE##*/}"

# If the disk is not partitioned (this is the case for optical media, and
# sometimes for USB sticks), nothing else to do:
[ "$(echo ${DRIVE}?*)" != "${DRIVE}?*" ] || exit 0

# Now we can process with the primary partitions. If we encounter logical
# partitions, they will be treated as subdevices of the extended one, and
# so they can appear differently from their numerical order. This can give:
# part1, part2(part5, part6, part7), part3...
_drivemap_primary_partitions "${DRIVE}"

# That's all