#! /bin/sh

# Peter T. Breuer 2000 (ptb@it.uc3m.es)

# This script makes /dev/nd{abcd}X - the first four nbd devices.

# It'll also make exactly one of /dev/nd[a-h]* if you give it one
# of /dev/nd[a-h] as an argument

# That's not the limit. In the default compilation configuration
# you can have up to 16 devices. If you want more, you will have
# to recompile and reduce the MAXCON parameter in the driver to 
# 8 or 4 from the default value of 16.

major=43
MAXCON=16

makedev() {
  local dev="$1"
  case $dev in
  *a) minor="$[ 0 * $MAXCON ]";;
  *b) minor="$[ 1 * $MAXCON ]";;
  *c) minor="$[ 2 * $MAXCON ]";;
  *d) minor="$[ 3 * $MAXCON ]";;
  *e) minor="$[ 4 * $MAXCON ]";;
  *f) minor="$[ 5 * $MAXCON ]";;
  *g) minor="$[ 6 * $MAXCON ]";;
  *h) minor="$[ 7 * $MAXCON ]";;
  *) minor=err-$dev ;;
  esac

  [ -b $dev ] || mknod $dev b $major $minor

  local j=0
  local k
  while [ $j -lt $[ $MAXCON - 1 ] ]; do
    j=$[ $j + 1 ]
    [ -b $dev$j ] && continue
    k=$[ $j + $minor ]
    mknod $dev$j b $major $k
  done
}

if [ -z "$*" ]; then
  for i in /dev/nda /dev/ndb /dev/ndc /dev/ndd; do
    makedev $i
  done
else
  for i; do
    makedev $i
  done
fi
true


