aboutsummaryrefslogtreecommitdiff
path: root/utils/uvol/files/uvol
blob: 4ecd2e165a6be2e39bc78e7b01de42b8ea8f7dfb (plain)
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
#!/bin/sh

# uvol prototype
# future development roadmap (aka. to-do):
# * re-implement in C (use libubox, execve lvm/ubi*)
# * hash to validate volume while writing
# * add atomic batch processing for use by container/package manager

if [ -z "$1" ]; then cat <<EOF
uvol storage volume manager

syntax: uvol command ...

commands:
  boot				get active volumes ready (called on boot)
  free				show number of bytes available
  total				show total number of bytes
  align				show sector size in bytes
  list [volname]		list volumes
  create volname size type	create new volume
    size: in bytes
    type: 'ro' or 'rw'
  remove volname		delete volume
  device volname		show block device for mounting
  size volname			show size of volume
  up volname			get volume ready for mounting
  down volname			take volume down after unmounting
  status volname		return status of volume
    return code: 0 - volume is ready for use
                 1 - volume is not ready for use
                 2 - volume doesn'y exist
  write volname size		write to volume from stdin, size in bytes
EOF
	return 22
fi

uvol_backend=
backends_tried=

for backend in /usr/libexec/uvol/*.sh; do
	total=$($backend total)
	backends_tried="$backends_tried $($backend name)"
	[ "$total" ] && uvol_backend=$backend
done

if [ -z "$uvol_backend" ]; then
	echo "No backend available. (tried:$backends_tried)"
	echo "To setup devices with block storage install 'autopart'."
	return 2
fi

flock -x /tmp/run/uvol.lock "$uvol_backend" "$@"