Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 20th, 2012  |  syntax: None  |  size: 0.86 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2.  
  3. # This program has two feature.
  4. #
  5. # 1. Create a disk image on RAM.
  6. # 2. Mount that disk image.
  7. #
  8. # Usage:
  9. #   $0 <dir> <size>
  10. #
  11. #   size:
  12. #     The `size' is a size of disk image (MB).
  13. #
  14. #   dir:
  15. #     The `dir' is a directory, the dir is used to mount the disk image.
  16. #
  17. # See also:
  18. #   - hdid(8)
  19. #
  20.  
  21. mount_point=${1}
  22. size=${2:-64}
  23.  
  24. mkdir -p $mount_point
  25. if [ $? -ne 0 ]; then
  26.     echo "The mount point didn't available." >&2
  27.     exit $?
  28. fi
  29.  
  30. sector=$(expr $size \* 1024 \* 1024 / 512)
  31. device_name=$(hdid -nomount "ram://${sector}" | awk '{print $1}')
  32. if [ $? -ne 0 ]; then
  33.     echo "Could not create disk image." >&2
  34.     exit $?
  35. fi
  36.  
  37. newfs_hfs $device_name > /dev/null
  38. if [ $? -ne 0 ]; then
  39.     echo "Could not format disk image." >&2
  40.     exit $?
  41. fi
  42.  
  43. mount -t hfs $device_name $mount_point
  44. if [ $? -ne 0 ]; then
  45.     echo "Could not mount disk image." >&2
  46.     exit $?
  47. fi