Corrected the "-dump" report of fragment start position.
[rrq/fusefile.git] / fusedisk
1 #!/bin/sh
2 #
3 # Set up a fusefile as a disk device using device mapper.
4 # Note that this requires root access.
5
6 if [ $(id -u) != 0 ] ; then
7     echo "block device set up requires root." >&2
8     exit 1
9 fi
10
11 # fuse blkdev mounting needs to sniff an existing but unmounted block
12 # device node for setup. However the device mapping has an empty table
13 # and the content is only accessible via the fuse mount that links it
14 # to the fusefile process. The device node (major:minor) are still
15 # considered in use by the kernel and, and the device node is "open"
16 # while mounted.
17
18 [ -e /dev/mapper/control ] || modprobe dm_mod || exit 1
19
20 # Create up to N fusedisk named as fusedisk0..fusediskN, the device
21 # mapper also creates its dm-X device nodes and we also force
22 # /dev/mapper/$NAME nodes for them.
23 N=15
24 DEV=
25 for I in $(seq 0 $N) ; do
26     NAME=fusedisk$I
27     C="$(dmsetup info --noheadings -c -o open $NAME 2>/dev/null)"
28     if [ "$C" != "1" ] ; then
29         if [ -z "$C" ] ; then
30             dmsetup create $NAME --notable || exit 1
31             dmsetup mknodes $NAME || exit 1
32         fi
33         DEV=/dev/mapper/$NAME
34         break
35     fi
36 done
37 if [ -z "$DEV" ] ; then
38     echo "** No more fusedisk devices" >&2
39     exit 1
40 fi
41 echo "using $DEV for $*" | logger -t fusedisk
42 exec fusefile -oblkdev,fsname=$DEV -oallow_other $*