Advertisement
Guest User

hdd_create_region.sh

a guest
Jul 23rd, 2011
1,271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2011 glevand (geoffrey.levand@mail.ru)
  4. # All rights reserved.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; version 2 of the License.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. #
  19.  
  20. PS3HVC_DEV=/dev/ps3hvc
  21. PS3HVC_HVCALL=ps3hvc_hvcall
  22.  
  23. PS3STORMGR_DEV=/dev/ps3stormgr
  24. PS3STOR_REGION=ps3stor_region
  25.  
  26. LPAR_ID=1
  27. LAID=0x1070000002000001
  28.  
  29. RNV_BUS4=0x0000000062757304
  30. RNV_NUM_DEV=0x6e756d5f64657600
  31. RNV_DEV=0x6465760000000000
  32. RNV_ID=0x6964000000000000
  33. RNV_TYPE=0x7479706500000000
  34. RNV_DEV_TYPE_DISK=0x0000000000000000
  35. RNV_N_BLOCKS=0x6e5f626c6f636b73
  36. RNV_N_REGS=0x6e5f726567730000
  37. RNV_REGION=0x726567696f6e0000
  38. RNV_START=0x7374617274000000
  39. RNV_SIZE=0x73697a6500000000
  40.  
  41. # get number of storage devices
  42.  
  43. num_dev=`$PS3HVC_HVCALL $PS3HVC_DEV get_repo_node_val $LPAR_ID $RNV_BUS4 $RNV_NUM_DEV 0 0 |
  44. awk '{ printf $1 }'`
  45. num_dev=`printf "%d" $num_dev`
  46.  
  47. echo "number of storage devices $num_dev"
  48.  
  49. # get index of disk storage device
  50.  
  51. echo "searching for disk storage device ..."
  52.  
  53. dev_idx=0
  54. found=0
  55. while [ $dev_idx -lt $num_dev -a $found -eq 0 ]; do
  56. rnv_dev="`expr substr $RNV_DEV 1 17`${dev_idx}"
  57.  
  58. type=`$PS3HVC_HVCALL $PS3HVC_DEV get_repo_node_val $LPAR_ID $RNV_BUS4 $rnv_dev $RNV_TYPE 0 |
  59. awk '{ printf $1 }'`
  60. if [ "$type" = "$RNV_DEV_TYPE_DISK" ]; then
  61. found=1
  62. else
  63. dev_idx=`expr $dev_idx + 1`
  64. fi
  65. done
  66.  
  67. if [ $found -eq 0 ]; then
  68. echo "disk storage device was not found"
  69. exit 1
  70. fi
  71.  
  72. echo "found disk storage device"
  73. echo "device index $dev_idx"
  74.  
  75. # get id of disk storage device
  76.  
  77. dev_id=`$PS3HVC_HVCALL $PS3HVC_DEV get_repo_node_val $LPAR_ID $RNV_BUS4 $rnv_dev $RNV_ID 0 |
  78. awk '{ printf $1 }'`
  79.  
  80. echo "device id $dev_id"
  81.  
  82. # get number of regions on disk storage device
  83.  
  84. n_regs=`$PS3HVC_HVCALL $PS3HVC_DEV get_repo_node_val $LPAR_ID $RNV_BUS4 $rnv_dev $RNV_N_REGS 0 |
  85. awk '{ printf $1 }'`
  86. n_regs=`printf "%d" $n_regs`
  87.  
  88. echo "number of regions $n_regs"
  89.  
  90. # get total size of disk storage device
  91.  
  92. n_blocks=`$PS3HVC_HVCALL $PS3HVC_DEV get_repo_node_val $LPAR_ID $RNV_BUS4 $rnv_dev $RNV_N_BLOCKS 0 |
  93. awk '{ printf $1 }'`
  94. n_blocks=`printf "%d" $n_blocks`
  95.  
  96. echo "total number of blocks $n_blocks"
  97.  
  98. # calculate start sector and sector count for new region on disk storage device
  99.  
  100. last_reg_idx=`expr $n_regs - 1`
  101. rnv_reg="`expr substr $RNV_REGION 1 17`${last_reg_idx}"
  102.  
  103. last_reg_start_sector=`$PS3HVC_HVCALL $PS3HVC_DEV get_repo_node_val $LPAR_ID $RNV_BUS4 $rnv_dev \
  104. $rnv_reg $RNV_START | awk '{ printf $1 }'`
  105. last_reg_start_sector=`printf "%d" $last_reg_start_sector`
  106.  
  107. echo "last region start sector $last_reg_start_sector"
  108.  
  109. last_reg_sector_count=`$PS3HVC_HVCALL $PS3HVC_DEV get_repo_node_val $LPAR_ID $RNV_BUS4 $rnv_dev \
  110. $rnv_reg $RNV_SIZE | awk '{ printf $1 }'`
  111. last_reg_sector_count=`printf "%d" $last_reg_sector_count`
  112.  
  113. echo "last region sector count $last_reg_sector_count"
  114.  
  115. new_reg_start_sector=`expr $last_reg_start_sector + $last_reg_sector_count`
  116. free_sector_count=`expr $n_blocks - $new_reg_start_sector`
  117. new_reg_sector_count=`expr $free_sector_count - 8`
  118.  
  119. echo "number of free sectors $free_sector_count"
  120.  
  121. # create new region on disk storage device
  122.  
  123. echo "creating new storage region ($new_reg_start_sector, $new_reg_sector_count) ..."
  124.  
  125. new_reg_id=`$PS3STOR_REGION $PS3STORMGR_DEV create $dev_id $new_reg_start_sector $new_reg_sector_count $LAID`
  126.  
  127. echo "new storage region id $new_reg_id"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement