Advertisement
devinteske

zfsboot.patch

Oct 27th, 2018
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.80 KB | None | 0 0
  1. Index: zfsboot
  2. ===================================================================
  3. --- zfsboot (revision 339885)
  4. +++ zfsboot (working copy)
  5. @@ -238,16 +238,23 @@ ZPOOL_SET='zpool set %s "%s"'
  6.  hline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER"
  7.  hline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER"
  8.  hline_arrows_tab_enter="Press arrows, TAB or ENTER"
  9. +msg_add="Add"
  10.  msg_an_unknown_error_occurred="An unknown error occurred"
  11.  msg_back="Back"
  12.  msg_cancel="Cancel"
  13.  msg_change_selection="Change Selection"
  14.  msg_configure_options="Configure Options:"
  15. +msg_dataset_plural="datasets"
  16. +msg_dataset_singular="dataset"
  17. +msg_datasets="Datasets"
  18.  msg_detailed_disk_info="gpart(8) show %s:\n%s\n\ncamcontrol(8) inquiry %s:\n%s\n\n\ncamcontrol(8) identify %s:\n%s\n"
  19.  msg_disk_info="Disk Info"
  20.  msg_disk_info_help="Get detailed information on disk device(s)"
  21.  msg_disk_plural="disks"
  22.  msg_disk_singular="disk"
  23. +msg_edit="Edit"
  24. +msg_edit_datasets_help="Edit ZFS datasets and their options"
  25. +msg_edit_zfs_datasets="Edit ZFS datasets:"
  26.  msg_encrypt_disks="Encrypt Disks?"
  27.  msg_encrypt_disks_help="Use geli(8) to encrypt all data partitions"
  28.  msg_error="Error"
  29. @@ -279,6 +286,7 @@ msg_null_index_argument="NULL index argument"
  30.  msg_null_poolname="NULL poolname"
  31.  msg_odd_disk_selected="An even number of disks must be selected to create a RAID 1+0. (%u selected)"
  32.  msg_ok="OK"
  33. +msg_options="Options"
  34.  msg_partition_scheme="Partition Scheme"
  35.  msg_partition_scheme_help="Select partitioning scheme. GPT is recommended."
  36.  msg_please_enter_a_name_for_your_zpool="Please enter a name for your zpool:"
  37. @@ -289,6 +297,7 @@ msg_pool_name_cannot_be_empty="Pool name cannot be
  38.  msg_pool_name_help="Customize the name of the zpool to be created (Required)"
  39.  msg_pool_type_disks="Pool Type/Disks:"
  40.  msg_pool_type_disks_help="Choose type of ZFS Virtual Device and disks to use (Required)"
  41. +msg_previous_menu="Previous menu"
  42.  msg_processing_selection="Processing selection..."
  43.  msg_raid10_desc="RAID 1+0 - n x 2-Way Mirrors"
  44.  msg_raid10_help="[4+ Disks] Striped Mirrors provides the best performance, but the least storage"
  45. @@ -298,8 +307,10 @@ msg_raidz2_desc="RAID-Z2 - Double Redundant RAID"
  46.  msg_raidz2_help="[4+ Disks] Withstand failure of 2 disks. Recommended for: 4, 6 or 10 disks"
  47.  msg_raidz3_desc="RAID-Z3 - Triple Redundant RAID"
  48.  msg_raidz3_help="[5+ Disks] Withstand failure of 3 disks. Recommended for: 5, 7 or 11 disks"
  49. +msg_remove="Remove"
  50.  msg_rescan_devices="Rescan Devices"
  51.  msg_rescan_devices_help="Scan for device changes"
  52. +msg_reset_defaults="Reset Defaults"
  53.  msg_select="Select"
  54.  msg_select_a_disk_device="Select a disk device"
  55.  msg_select_virtual_device_type="Select Virtual Device type:"
  56. @@ -339,15 +350,27 @@ dialog_menu_main()
  57.     [ "$ZFSBOOT_GELI_ENCRYPTION" ] && usegeli="$msg_yes"
  58.     [ "$ZFSBOOT_SWAP_ENCRYPTION" ] && swapgeli="$msg_yes"
  59.     [ "$ZFSBOOT_SWAP_MIRROR" ] && swapmirror="$msg_yes"
  60. -   local disks n disks_grammar
  61. -   f_count n $ZFSBOOT_DISKS
  62. -   { [ $n -eq 1 ] && disks_grammar=$msg_disk_singular; } ||
  63. +   local disks ndisks disks_grammar
  64. +   f_count ndisks $ZFSBOOT_DISKS
  65. +   { [ $ndisks -eq 1 ] && disks_grammar=$msg_disk_singular; } ||
  66.         disks_grammar=$msg_disk_plural # grammar
  67. +   local ndatasets dataset_grammar
  68. +   ndatasets=$( echo "$ZFSBOOT_DATASETS" | {
  69. +       n=0
  70. +       while read dataset options; do
  71. +           # Skip blank lines and comments
  72. +           case "$dataset" in "#"*|"") continue; esac
  73. +           n=$(( $n + 1 ))
  74. +       done
  75. +       echo $n
  76. +   } )
  77. +   { [ $ndatasets -eq 1 ] && dataset_grammar=$msg_dataset_singular; } ||
  78. +       dataset_grammar=$msg_dataset_plural # grammar
  79.     local menu_list="
  80.         '>>> $msg_install'      '$msg_install_desc'
  81.                                 '$msg_install_help'
  82.         'T $msg_pool_type_disks'
  83. -                      '$ZFSBOOT_VDEV_TYPE: $n $disks_grammar'
  84. +                      '$ZFSBOOT_VDEV_TYPE: $ndisks $disks_grammar'
  85.                        '$msg_pool_type_disks_help'
  86.         '- $msg_rescan_devices' '*'
  87.                                 '$msg_rescan_devices_help'
  88. @@ -369,6 +392,8 @@ dialog_menu_main()
  89.                                 '$msg_swap_mirror_help'
  90.         'W $msg_swap_encrypt'   '$swapgeli'
  91.                                 '$msg_swap_encrypt_help'
  92. +       'D $msg_datasets'       '$msg_edit $ndatasets $dataset_grammar'
  93. +                               '$msg_edit_datasets_help'
  94.     " # END-QUOTE
  95.     local defaultitem= # Calculated below
  96.     local hline="$hline_alnum_arrows_punc_tab_enter"
  97. @@ -1554,6 +1579,120 @@ dialog_menu_diskinfo()
  98.     return $SUCCESS
  99.  }
  100.  
  101. +# dialog_menu_datasets
  102. +#
  103. +# Present a menu allowing the user to view, add, remove, and modify datasets.
  104. +#
  105. +dialog_menu_datasets()
  106. +{
  107. +   local funcname=dialog_menu_datasets
  108. +   local title="$DIALOG_TITLE"
  109. +   local btitle="$DIALOG_BACKTITLE"
  110. +   local prompt="$msg_edit_zfs_datasets"
  111. +   local menu_list
  112. +   local defaultitem= # Calculated below
  113. +   local hline="$hline_alnum_arrows_punc_tab_enter"
  114. +
  115. +   menu_list="
  116. +       '<<< $msg_back'         '$msg_previous_menu'
  117. +       '> $msg_add'            '$msg_datasets/$msg_options'
  118. +       '> $msg_remove'         '$msg_datasets/$msg_options'
  119. +       '! $msg_reset_defaults' '*'
  120. +       '---'                   '---'
  121. +       $( echo "$ZFSBOOT_DATASETS" | while read dataset options; do
  122. +           # Skip blank lines and comments
  123. +           [ "$dataset" ] || continue
  124. +           [ "$dataset" = "${dataset#\#}" ] || continue
  125. +           printf "dataset=%s\n" "$dataset"
  126. +           printf "\t%s\n" "$options"
  127. +           printf "\n"
  128. +       done | awk '
  129. +       BEGIN {
  130. +           ndatasets = 0
  131. +           delete dataset
  132. +           delete dataset_opt
  133. +       }
  134. +       function mprint(tag, item) {
  135. +           gsub(/'\''/, "&\\\\&&", tag)
  136. +           gsub(/'\''/, "&\\\\&&", item)
  137. +           printf "'\''%s'\'' '\''%s'\''\n", tag, item
  138. +       }
  139. +       function _asorti(src, dest)
  140. +       {
  141. +           k = nitems = 0
  142. +           for (i in src) dest[++nitems] = i
  143. +           for (i = 1; i <= nitems; k = i++) {
  144. +               idx = dest[i]
  145. +               while ((k > 0) && (dest[k] > idx)) {
  146. +                   dest[k+1] = dest[k]; k--
  147. +               }
  148. +               dest[k+1] = idx
  149. +           }
  150. +           return nitems
  151. +       }
  152. +       sub(/^dataset=/, "") {
  153. +           dataset[d = $0]
  154. +           getline options
  155. +           # Remove leading whitespace
  156. +           sub(/^[[:space:]]*/, "", options)
  157. +           # Remove potential inline comments
  158. +           sub(/#.*/, "", options)
  159. +           # Reduce contiguous whitespace to one single space
  160. +           gsub(/[[:space:]]+/, " ", options)
  161. +           dataset_opt[d] = options
  162. +       }
  163. +       END {
  164. +           ndatasets = _asorti(dataset, dataset_list)
  165. +           delete klist
  166. +           for (n = 1; n <= ndatasets; n++) {
  167. +               d = k = dataset_list[n]
  168. +               if (d ~ "^/ROOT(/.*)?$") {
  169. +                   k = "/"
  170. +               } else {
  171. +                   sub("^/*", "", k)
  172. +                   k = toupper(substr(k, 1, 1))
  173. +               }
  174. +               klist[k d]
  175. +           }
  176. +           delete kseen
  177. +           delete sorted_klist
  178. +           ndatasets = _asorti(klist, sorted_klist)
  179. +           for (n = 1; n <= ndatasets; n++) {
  180. +               k = substr(sorted_klist[n], 1, 1)
  181. +               d = substr(sorted_klist[n], 2)
  182. +               if (k in kseen) {
  183. +                   k = "-"
  184. +               } else {
  185. +                   kseen[k]
  186. +               }
  187. +               mprint(sprintf("%c %s", k, d), dataset_opt[d])
  188. +           }
  189. +       }
  190. +   ' 2>&3 )"
  191. +
  192. +   local height width rows
  193. +   eval f_dialog_menu_size height width rows \
  194. +       \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $menu_list
  195. +
  196. +   local menu_choice
  197. +   menu_choice=$( eval $DIALOG \
  198. +       --title \"\$title\"              \
  199. +       --backtitle \"\$btitle\"         \
  200. +       --hline \"\$hline\"              \
  201. +       --ok-label \"\$msg_select\"      \
  202. +       --cancel-label \"\$msg_cancel\"  \
  203. +       --default-item \"\$defaultitem\" \
  204. +       --menu \"\$prompt\"              \
  205. +       $height $width $rows             \
  206. +       $menu_list                       \
  207. +       2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
  208. +   )
  209. +   local retval=$?
  210. +   f_dialog_data_sanitize menu_choice
  211. +
  212. +   return $retval
  213. +}
  214. +
  215.  ############################################################ MAIN
  216.  
  217.  #
  218. @@ -1792,6 +1931,9 @@ while :; do
  219.             ZFSBOOT_SWAP_ENCRYPTION=1
  220.         fi
  221.         ;;
  222. +   ?" $msg_datasets")
  223. +       # Present a menu to edit datasets and their options
  224. +       dialog_menu_datasets
  225.     esac
  226.  done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement