13 desc="Configure the LUN for device mode USB mass storage"
14 rcvar="cfumass_enable"
16 start_cmd="${name}_start"
17 stop_cmd="${name}_stop"
19 extra_commands="reload"
20 reload_cmd="${name}_start"
22 : ${cfumass_dir:=/var/cfumass}
23 : ${cfumass_image:=/var/tmp/cfumass.img}
24 : ${cfumass_vendor:="FreeBSD"}
25 : ${cfumass_product:="cfumass(4)"}
31 _luns=`ctladm devlist -b block -v | awk '
37 $1 == "file='"${cfumass_image}"'" {
41 for _lun in ${_luns}; do
42 ctladm remove -b block -l "${_lun}" > /dev/null
48 local err _files _template
50 if [ ! -d "${cfumass_dir}" ]; then
51 warn "${cfumass_dir} does not exist"
55 _files=`find "${cfumass_dir}" -newer "${cfumass_image}" -print 2> /dev/null`
56 if [ ! -e "${cfumass_image}" -o -n "${_files}" ]; then
57 # The image doesn't exist or is out of date.
58 makefs -t cd9660 -o rockridge "${cfumass_image}" "${cfumass_dir}"
60 if [ "${err}" -ne 0 ]; then
61 warn "unable to create ${cfumass_image}"
68 ctladm create -b block -o file="${cfumass_image}" -o readonly=on \
69 -o vendor="${cfumass_vendor}" -o product="${cfumass_product}" \
72 if [ "${err}" -ne 0 ]; then
73 warn "unable to create CTL LUN"
77 load_kld -e cfumass cfumass
79 # If the template is already switched to Mass Storage, then reset
80 # it to -1 to force the host to reenumerate it; otherwise it might
81 # not notice the new LUN.
82 _template=`sysctl -n hw.usb.template`
83 if [ "${_template}" -eq 0 ]; then
84 sysctl hw.usb.template=-1 > /dev/null
86 if [ "${err}" -ne 0 ]; then
87 warn "unable to set hw.usb.template sysctl"
92 _template=`sysctl -n hw.usb.template`
93 if [ "${_template}" -lt 0 ]; then
94 sysctl hw.usb.template=0 > /dev/null
96 if [ "${err}" -ne 0 ]; then
97 warn "unable to set hw.usb.template sysctl"
101 # Otherwise don't touch the sysctl - we could lock the user
102 # out of the machine otherwise.
103 warn "hw.usb.template sysctl set to neither -1 nor 0"
111 _template=`sysctl -n hw.usb.template`
112 if [ "${_template}" -eq 0 ]; then
113 sysctl hw.usb.template=-1 > /dev/null
115 if [ "${err}" -ne 0 ]; then
116 warn "unable to set hw.usb.template sysctl"