@ -31,8 +31,15 @@ getdev() {
local voldir volname devname
local voldir volname devname
for voldir in /sys/devices/virtual/ubi/${ ubidev } /${ ubidev } _*; do
for voldir in /sys/devices/virtual/ubi/${ ubidev } /${ ubidev } _*; do
read volname < " ${ voldir } /name "
read volname < " ${ voldir } /name "
[ " $volname " = " uvol-ro- $1 " ] || [ " $volname " = " uvol-wp- $1 " ] || [ " $volname " = " uvol-rw- $1 " ] || [ " $volname " = " uvol-wo- $1 " ] || continue
basename " $voldir "
case " $volname " in
uvol-[ rw] [ owpd] -$1 )
basename " $voldir "
break
; ;
*)
continue
; ;
esac
done
done
}
}
@ -51,7 +58,9 @@ vol_is_mode() {
getstatus( ) {
getstatus( ) {
local voldev = $( getdev " $@ " )
local voldev = $( getdev " $@ " )
[ " $voldev " ] || return 2
[ " $voldev " ] || return 2
vol_is_mode $voldev wo && return 1
vol_is_mode $voldev wo && return 22
vol_is_mode $voldev wp && return 16
vol_is_mode $voldev wd && return 1
vol_is_mode $voldev ro && [ ! -e " /dev/ubiblock ${ voldev : 3 } " ] && return 1
vol_is_mode $voldev ro && [ ! -e " /dev/ubiblock ${ voldev : 3 } " ] && return 1
return 0
return 0
}
}
@ -73,10 +82,17 @@ getuserdev() {
fi
fi
}
}
mkubifs( ) {
local tmp_mp = $( mktemp -d)
mount -t ubifs $1 $tmp_mp
umount $tmp_mp
rmdir $tmp_mp
}
createvol( ) {
createvol( ) {
local mode ret
local mode ret
local existdev = $( getdev " $@ " )
[ " $existdev " ] && return 17
local vol dev= $( getdev " $@ " )
[ " $vol dev " ] && return 17
case " $3 " in
case " $3 " in
ro| wo)
ro| wo)
mode = wo
mode = wo
@ -91,37 +107,61 @@ createvol() {
ubimkvol /dev/$ubidev -N " uvol- $mode - $1 " -s " $2 "
ubimkvol /dev/$ubidev -N " uvol- $mode - $1 " -s " $2 "
ret = $?
ret = $?
[ $ret -eq 0 ] || return $ret
[ $ret -eq 0 ] || return $ret
ubiupdatevol -t /dev/$( getdev " $@ " )
voldev = $( getdev " $@ " )
ubiupdatevol -t /dev/$voldev
[ " $mode " = "wp" ] || return 0
[ " $mode " = "wp" ] || return 0
local tmp_mp = $( mktemp -d)
mount -t ubifs /dev/$( getdev " $@ " ) $tmp_mp
umount $tmp_mp
rmdir $tmp_mp
mkubifs /dev/$voldev
ubirename /dev/$ubidev uvol-wp-$1 uvol-rw-$1
ubirename /dev/$ubidev uvol-wp-$1 uvol-rw-$1
ubus send block.volume " {\"name\": \" $1 \", \"action\": \"up\", \"mode\": \"rw\", \"fstype\": \"ubifs\", \"device\": \"/dev/ $voldev \"} "
}
}
removevol( ) {
removevol( ) {
local voldev = $( getdev " $@ " )
local voldev = $( getdev " $@ " )
local evdata
[ " $voldev " ] || return 2
[ " $voldev " ] || return 2
local volnum = ${ voldev # ${ ubidev } _ }
local volnum = ${ voldev # ${ ubidev } _ }
ubirmvol /dev/$ubidev -n $volnum
if vol_is_mode $voldev rw ; then
evdata = " {\"name\": \" $1 \", \"action\": \"down\", \"device\": \"/dev/ $voldev \"} "
elif vol_is_mode $voldev ro ; then
evdata = " {\"name\": \" $1 \", \"action\": \"down\", \"device\": \"/dev/ubiblock ${ voldev : 3 } \"} "
fi
ubirmvol /dev/$ubidev -n $volnum || return $?
ubus send block.volume " $evdata "
}
}
activatevol( ) {
activatevol( ) {
local voldev = $( getdev " $@ " )
local voldev = $( getdev " $@ " )
[ " $voldev " ] || return 2
[ " $voldev " ] || return 2
vol_is_mode $voldev wo || return 1
vol_is_mode $voldev ro || return 0
[ -e " /dev/ubiblock ${ voldev : 3 } " ] && return 0
ubiblock --create /dev/$voldev
vol_is_mode $voldev rw && return 0
vol_is_mode $voldev wo && return 22
vol_is_mode $voldev wp && return 16
if vol_is_mode $voldev ro; then
[ -e " /dev/ubiblock ${ voldev : 3 } " ] && return 0
ubiblock --create /dev/$voldev
ubus send block.volume " {\"name\": \" $1 \", \"action\": \"up\", \"mode\": \"ro\", \"device\": \"/dev/ubiblock ${ voldev : 3 } \"} "
return 0
elif vol_is_mode $voldev wd; then
ubirename /dev/$ubidev uvol-wd-$1 uvol-rw-$1
ubus send block.volume " {\"name\": \" $1 \", \"action\": \"up\", \"mode\": \"rw\", \"fstype\": \"ubifs\", \"device\": \"/dev/ $voldev \"} "
return 0
fi
}
}
disactivatevol( ) {
disactivatevol( ) {
local voldev = $( getdev " $@ " )
local voldev = $( getdev " $@ " )
[ " $voldev " ] || return 2
[ " $voldev " ] || return 2
vol_is_mode $voldev ro || return 0
[ -e " /dev/ubiblock ${ voldev : 3 } " ] || return 0
ubiblock --remove /dev/$voldev
vol_is_mode $voldev wo && return 22
vol_is_mode $voldev wp && return 16
if vol_is_mode $voldev ro; then
[ -e " /dev/ubiblock ${ voldev : 3 } " ] || return 0
ubiblock --remove /dev/$voldev || return $?
ubus send block.volume " {\"name\": \" $1 \", \"action\": \"down\", \"mode\": \"ro\", \"device\": \"/dev/ubiblock ${ voldev : 3 } \"} "
return 0
elif vol_is_mode $voldev rw; then
ubirename /dev/$ubidev uvol-rw-$1 uvol-wd-$1 || return $?
ubus send block.volume " {\"name\": \" $1 \", \"action\": \"down\", \"mode\": \"rw\", \"device\": \"/dev/ $voldev \"} "
return 0
fi
}
}
updatevol( ) {
updatevol( ) {
@ -131,6 +171,8 @@ updatevol() {
vol_is_mode $voldev wo || return 22
vol_is_mode $voldev wo || return 22
ubiupdatevol -s $2 /dev/$voldev -
ubiupdatevol -s $2 /dev/$voldev -
ubirename /dev/$ubidev uvol-wo-$1 uvol-ro-$1
ubirename /dev/$ubidev uvol-wo-$1 uvol-ro-$1
ubiblock --create /dev/$voldev
ubus send block.volume " {\"name\": \" $1 \", \"action\": \"up\", \"mode\": \"ro\", \"device\": \"/dev/ubiblock ${ voldev : 3 } \"} "
}
}
listvols( ) {
listvols( ) {
@ -138,7 +180,7 @@ listvols() {
for voldir in /sys/devices/virtual/ubi/${ ubidev } /${ ubidev } _*; do
for voldir in /sys/devices/virtual/ubi/${ ubidev } /${ ubidev } _*; do
read volname < $voldir /name
read volname < $voldir /name
case " $volname " in
case " $volname " in
uvol-r[ wo] *)
uvol-[ rw] [ wod ] *)
read volsize < $voldir /data_bytes
read volsize < $voldir /data_bytes
; ;
; ;
*)
*)
@ -151,6 +193,31 @@ listvols() {
done
done
}
}
bootvols( ) {
local volname volmode volsize voldev fstype
for voldir in /sys/devices/virtual/ubi/${ ubidev } /${ ubidev } _*; do
read volname < $voldir /name
voldev = $( basename $voldir )
fstype =
case " $volname " in
uvol-ro-*)
voldev = " /dev/ubiblock ${ voldev : 3 } "
ubiblock --create /dev/$voldev
; ;
uvol-rw-*)
voldev = " /dev/ $voldev "
fstype = "ubifs"
; ;
*)
continue
; ;
esac
volmode = ${ volname : 5 : 2 }
volname = ${ volname : 8 }
ubus send block.volume " {\"name\": \" $volname \", \"action\": \"up\", \"mode\": \" $volmode \", ${ fstype : + \" fstype \" : \" $fstype \" , } \"device\": \" $voldev \"} "
done
}
case " $cmd " in
case " $cmd " in
align)
align)
echo " $ebsize "
echo " $ebsize "
@ -161,6 +228,9 @@ case "$cmd" in
total)
total)
totalbytes
totalbytes
; ;
; ;
boot)
bootvols
; ;
list)
list)
listvols " $@ "
listvols " $@ "
; ;
; ;