[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-unattended/var/se3/unattended/install/linuxaux/bin/ -> make-blkdev-nodes (source)

   1  #!/bin/bash
   2  
   3  # Create the block device nodes for a mass-storage device and its
   4  # partitions.  The argument to this script is the canonical name of
   5  # the device without the /dev prefix, like "hda" or "i2o/sda".
   6  
   7  die () {
   8      echo "$@"
   9      exit 2
  10  }
  11  
  12  sys_block=/sys/block
  13  
  14  [ -d $sys_block ] \
  15      || die "$sys_block not found!"
  16  
  17  # Argument is a directory like /sys/block/hda, /sys/block/sda/sda1,
  18  # /sys/block/i2o!hda, or /sys/block/i2o!hda/i2o!hda2.
  19  make_block_device () {
  20      local path="$1"
  21  
  22      # Everything after the last /
  23      local name=$path##*/}
  24      local dev_file="/dev/$name"
  25      # Replace ! with /
  26      dev_file=$dev_file//\!/\/}
  27      echo "Making device $dev_file"
  28      [ -f "$path/dev" ] \
  29          || die "$0: Internal error: $path/dev not found"
  30  
  31      # Everything up to the last /
  32      local dev_dir=$dev_file%/*}
  33      mkdir -p "$dev_dir"
  34      [ -d "$dev_dir" ] \
  35          || die "$0: Unable to mkdir $dev_dir"
  36  
  37      local major_minor="`cat $path/dev`"
  38      local temp="$dev_file.$$.tmp"
  39      mknod "$temp" b ${major_minor%:*} ${major_minor#*:} \
  40          || die "mknod failed"
  41      mv -f "$temp" "$dev_file" \
  42          || die "rename $temp to $fullname failed"
  43  }
  44  
  45  # Replace / with !
  46  dev="${1//\//!}"
  47  
  48  [ -n "$dev" ] \
  49      || die "$0: I need an argument"
  50  
  51  # Force "foo*" to expand to nothing if no matches found
  52  shopt -s nullglob
  53  
  54  # Exit silently if device does not exist
  55  [ -d "$sys_block/$dev" ] \
  56      || exit 1
  57  
  58  make_block_device "$sys_block/$dev"
  59  
  60  # Devices like /dev/sda have partition names like /dev/sda1, while
  61  # devices like /dev/rd/c0d0 have partition names like /dev/rd/c0d0p1.
  62  # That is, we must append "pX" if the last character is a digit.  See
  63  # disk_name() in linux/fs/partitions/check.c.
  64  [[ $dev = *[0-9] ]] \
  65      && p=p
  66  
  67  for devX in "$sys_block/$dev/$dev"$p[1-9]* ; do
  68      make_block_device "$devX"
  69  done
  70  
  71  exit 0


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1