Index: etc/defaults/rc.conf =================================================================== --- etc/defaults/rc.conf +++ etc/defaults/rc.conf @@ -592,6 +592,9 @@ cron_program="/usr/sbin/cron" # Which cron executable to run (if enabled). cron_dst="YES" # Handle DST transitions intelligently (YES/NO) cron_flags="" # Which options to pass to the cron daemon. +cfumass_enable="NO" # Create default LUN for cfumass(4). +cfumass_dir="/var/cfumass" # File to LUN's contents. +cfumass_image="/var/cfumass.img"# LUN's backing file path. lpd_enable="NO" # Run the line printer daemon. lpd_program="/usr/sbin/lpd" # path to lpd, if you want a different one. lpd_flags="" # Flags to lpd (if enabled). Index: etc/rc.d/cfumass =================================================================== --- /dev/null +++ etc/rc.d/cfumass @@ -0,0 +1,125 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# PROVIDE: cfumass +# REQUIRE: var +# KEYWORD: nojail + +. /etc/rc.subr + +name="cfumass" +desc="Configure the LUN for device mode USB mass storage" +rcvar="cfumass_enable" + +start_cmd="${name}_start" +stop_cmd="${name}_stop" + +extra_commands="reload" +reload_cmd="${name}_start" + +: ${cfumass_dir:=/var/cfumass} +: ${cfumass_image:=/var/cfumass.img} +: ${cfumass_vendor:="FreeBSD"} +: ${cfumass_product:="cfumass(4)"} + +remove_luns() +{ + local _lun _luns + + _luns=`ctladm devlist -b block -v | awk ' + + $1 ~ /^[0-9]+$/ { + lun = $1 + } + + $1 == "file='"${cfumass_image}"'" { + print lun + }'` + + for _lun in ${_luns}; do + ctladm remove -b block -l "${_lun}" > /dev/null + done +} + +cfumass_start() +{ + local err _files _template + + if [ ! -d "${cfumass_dir}" ]; then + warn "${cfumass_dir} does not exist" + return 1 + fi + + _files=`find "${cfumass_dir}" -newer "${cfumass_image}" -print 2> /dev/null` + if [ ! -e "${cfumass_image}" -o -n "${_files}" ]; then + # The image doesn't exist or is out of date. + makefs -t cd9660 -o rockridge "${cfumass_image}" "${cfumass_dir}" + err=$? + if [ "${err}" -ne 0 ]; then + warn "unable to create ${cfumass_image}" + return "${err}" + fi + fi + + remove_luns + + ctladm create -b block -o file="${cfumass_image}" -o readonly=on \ + -o vendor="${cfumass_vendor}" -o product="${cfumass_product}" \ + -t 5 -S 0 > /dev/null + err=$? + if [ "${err}" -ne 0 ]; then + warn "unable to create CTL LUN" + return "${err}" + fi + + load_kld -e cfumass cfumass + + # If the template is already switched to Mass Storage, then reset + # it to -1 to force the host to reenumerate it; otherwise it might + # not notice the new LUN. + _template=`sysctl -n hw.usb.template` + if [ "${_template}" -eq 0 ]; then + sysctl hw.usb.template=-1 > /dev/null + err=$? + if [ "${err}" -ne 0 ]; then + warn "unable to set hw.usb.template sysctl" + return "${err}" + fi + fi + + _template=`sysctl -n hw.usb.template` + if [ "${_template}" -lt 0 ]; then + sysctl hw.usb.template=0 > /dev/null + err=$? + if [ "${err}" -ne 0 ]; then + warn "unable to set hw.usb.template sysctl" + return "${err}" + fi + else + # Otherwise don't touch the sysctl - we could lock the user + # out of the machine otherwise. + warn "hw.usb.template sysctl set to neither -1 nor 0" + fi +} + +cfumass_stop() +{ + local err _template + + _template=`sysctl -n hw.usb.template` + if [ "${_template}" -eq 0 ]; then + sysctl hw.usb.template=-1 > /dev/null + err=$? + if [ "${err}" -ne 0 ]; then + warn "unable to set hw.usb.template sysctl" + return "${err}" + fi + fi + + remove_luns +} + +load_rc_config $name +run_rc_command "$1" Index: share/man/man4/cfumass.4 =================================================================== --- share/man/man4/cfumass.4 +++ share/man/man4/cfumass.4 @@ -88,6 +88,14 @@ and .Xr ctld 8 for details on configuring the LUN. +See the +.Cm cfumass_enable +and +.Cm cfumass_dir +.Xr rc 8 +variables in +.Xr rc.conf 5 +for an automated way to configure it at boot. .Sh SYSCTL VARIABLES These variables are available as both .Xr sysctl 8 Index: share/man/man5/rc.conf.5 =================================================================== --- share/man/man5/rc.conf.5 +++ share/man/man5/rc.conf.5 @@ -4482,6 +4482,18 @@ which configures sessions based on the .Pa /etc/iscsi.conf configuration file. +.It Va cfumass_enable +.Pq Vt bool +If set to +.Dq Li YES , +create and export an USB LUN using +.Xr cfumass 4 +at boot time. +.It Va cfumass_dir +.Pq Vt str +The directory where the files exported by USB LUN are located. +The default directory is +.Pa /var/cfumass . .El .Sh FILES .Bl -tag -width ".Pa /etc/defaults/rc.conf" -compact