Debian Codegraph @

monero/tests/create_test_disks.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 set -e
4
5 LOOP_DEVICE_MAJOR=7
6 LOOP_DEVICE_MIN_ID=100
7
8 echo_errscip-shell shell feather-wallet 2.8.1+dfsg-6 echo_err().() {
9 echoscip-shell system . . echo. "$@" >&2
10 }
11
12 root_execscip-shell shell feather-wallet 2.8.1+dfsg-6 root_exec().() {
13 if [[ $EUID -ne 0 ]]; then
14 ${ROOT_EXEC_CMD:-sudo} "$@"
15 else
16 "$@"
17 fi
18 }
19
20 create_device_nodescip-shell shell feather-wallet 2.8.1+dfsg-6 create_device_node().() {
21 local -r last_id=$(findscip-shell system . . find. /dev/scip-shell filesystem . . `/dev/`. -name 'loop[0-9]*' -printf '%f\n' | sedscip-shell system . . sed. 's/^loop//' | sortscip-shell system . . sort. -r -n | headscip-shell system . . head. -1)
22 local id=$((last_id + 1))
23 if [[ "$id" -lt "$LOOP_DEVICE_MIN_ID" ]]; then
24 id="$LOOP_DEVICE_MIN_ID"
25 fi
26 local path
27 for (( i=0; i<10; i++ )); do
28 path="/dev/loop$id"
29 if [[ ! -e "$path" ]] && root_exec mknod "$path" b "$LOOP_DEVICE_MAJOR" "$id"; then
30 echo "$path"
31 return 0
32 fi
33 $((id++))
34 done
35 return 1
36 }
37
38 device_mountpointscip-shell shell feather-wallet 2.8.1+dfsg-6 device_mountpoint().() {
39 local -r datadir="$1"
40 local -r dev="$2"
41 if [[ -z "$datadir" || -z "$dev" ]]; then
42 echo_errscip-shell shell feather-wallet 2.8.1+dfsg-6 echo_err(). "Usage: device_mountpoint <data dir> <device>"
43 return 1
44 fi
45 echoscip-shell system . . echo. "$datadir/mnt-$(basenamescip-shell system . . basename. "$dev")"
46 }
47
48 create_devicescip-shell shell feather-wallet 2.8.1+dfsg-6 create_device().() {
49 local -r datadir="$1"
50 if [[ -z "$datadir" ]]; then
51 echo_errscip-shell shell feather-wallet 2.8.1+dfsg-6 echo_err(). "Usage: create_device <data dir>"
52 return 1
53 fi
54 local -r dev=$(create_device_nodescip-shell shell feather-wallet 2.8.1+dfsg-6 create_device_node().)
55 local -r fs="$datadir/$(basenamescip-shell system . . basename. "$dev").vhd"
56 local -r mountpoint=$(device_mountpointscip-shell shell feather-wallet 2.8.1+dfsg-6 device_mountpoint(). "$datadir" "$dev")
57 echo_errscip-shell shell feather-wallet 2.8.1+dfsg-6 echo_err().
58 echo_errscip-shell shell feather-wallet 2.8.1+dfsg-6 echo_err(). "# Device $dev"
59 ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of="$fs" bs=64K count=128 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
60 root_execscip-shell shell feather-wallet 2.8.1+dfsg-6 root_exec(). losetup "$dev" "$fs"
61 root_execscip-shell shell feather-wallet 2.8.1+dfsg-6 root_exec(). mkfs.ext4 "$dev" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
62 mkdirscip-shell system . . mkdir. "$mountpoint"
63 root_execscip-shell shell feather-wallet 2.8.1+dfsg-6 root_exec(). mount "$dev" "$mountpoint"
64 echoscip-shell system . . echo. "$dev"
65 }
66
67 # Unused by default, but helpful for local development
68 destroy_devicescip-shell shell feather-wallet 2.8.1+dfsg-6 destroy_device().() {
69 local -r datadir="$1"
70 local -r dev="$2"
71 if [[ -z "$datadir" || -z "$dev" ]]; then
72 echo_errscip-shell shell feather-wallet 2.8.1+dfsg-6 echo_err(). "Usage: destroy_device <data dir> <device>"
73 return 1
74 fi
75 echo_errscip-shell shell feather-wallet 2.8.1+dfsg-6 echo_err(). "Destroying device $dev"
76 root_execscip-shell shell feather-wallet 2.8.1+dfsg-6 root_exec(). umount $(device_mountpointscip-shell shell feather-wallet 2.8.1+dfsg-6 device_mountpoint(). "$datadir" "$dev")
77 root_execscip-shell shell feather-wallet 2.8.1+dfsg-6 root_exec(). losetup -d "$dev"
78 root_execscip-shell shell feather-wallet 2.8.1+dfsg-6 root_exec(). rm "$dev"
79 }
80
81 block_device_pathscip-shell shell feather-wallet 2.8.1+dfsg-6 block_device_path().() {
82 device_name=$(basenamescip-shell system . . basename. "$1")
83 device_minor=${device_name/#loop}
84 echoscip-shell system . . echo. "/sys/dev/block/$LOOP_DEVICE_MAJOR:$device_minor"
85 }
86
87 tmpdir=$(mktempscip-shell system . . mktemp. --tmpdir -d monerotest.XXXXXXXX)
88 echo_errscip-shell shell feather-wallet 2.8.1+dfsg-6 echo_err(). "Creating devices using temporary directory: $tmpdir"
89
90 dev_rot=$(create_devicescip-shell shell feather-wallet 2.8.1+dfsg-6 create_device(). "$tmpdir")
91 bdev_rot=$(block_device_pathscip-shell shell feather-wallet 2.8.1+dfsg-6 block_device_path(). "$dev_rot")
92 echoscip-shell system . . echo. 1 | root_execscip-shell shell feather-wallet 2.8.1+dfsg-6 root_exec(). tee "$bdev_rot/queue/rotational" >/dev/nullscip-shell filesystem . . `/dev/null`.
93 echoscip-shell system . . echo. MONERO_TEST_DEVICE_HDD=$(device_mountpointscip-shell shell feather-wallet 2.8.1+dfsg-6 device_mountpoint(). "$tmpdir" "$dev_rot")
94
95 dev_ssd=$(create_devicescip-shell shell feather-wallet 2.8.1+dfsg-6 create_device(). "$tmpdir")
96 bdev_ssd=$(block_device_pathscip-shell shell feather-wallet 2.8.1+dfsg-6 block_device_path(). "$dev_ssd")
97 echoscip-shell system . . echo. 0 | root_execscip-shell shell feather-wallet 2.8.1+dfsg-6 root_exec(). tee "$bdev_ssd/queue/rotational" >/dev/nullscip-shell filesystem . . `/dev/null`.
98 echoscip-shell system . . echo. MONERO_TEST_DEVICE_SSD=$(device_mountpointscip-shell shell feather-wallet 2.8.1+dfsg-6 device_mountpoint(). "$tmpdir" "$dev_ssd")