Skip to content

Commit

Permalink
Filter prohibited characters of ISO label for FAT32 partition label
Browse files Browse the repository at this point in the history
Fixes #34
  • Loading branch information
ValdikSS committed Dec 6, 2022
1 parent 1de6055 commit 6249a7f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion windows2usb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dirpath="$(dirname "$scriptpath")"


function check_requirements() {
local reqs=(awk lsblk 7z mkfs.vfat mkfs.ntfs sfdisk ms-sys mktemp wimsplit)
local reqs=(awk lsblk 7z mkfs.vfat mkfs.ntfs sfdisk ms-sys mktemp wimsplit tr)

for req in ${reqs[*]}; do
if ! command -v "$req" > /dev/null;
Expand Down Expand Up @@ -76,6 +76,12 @@ function get_iso_name() {
7z l "$1" | awk '/Comment = / {print $3; exit 0}'
}

function sanitize_iso_name() {
# FAT32 does not allow certain characters in names, see
# https://github.com/dosfstools/dosfstools/blob/1da41f0e70dcbfb874e8191c639b91fa58205ea4/src/fatlabel.c#L96
echo "$1" | tr -d '*?.,;:/\\|+=<>[]"'
}

function check_installwim_gt4gib() {
7z l "$1" | awk 'BEGIN {doend=1} ($6 ~ /install.wim/) {if ($4 > 4294967296) {doend=0; exit 0}; doend=0; exit 1} END {if (doend) {exit 1}}'
}
Expand Down Expand Up @@ -257,6 +263,8 @@ then
# MBR FAT32
if [[ "$labeltype" == "mbr" ]];
then
isolabel="$(sanitize_iso_name "$isolabel")"

echo "${bold} == Creating new MBR-formatted partition table ==${normal}"
format_drive "dos" "$dev"

Expand All @@ -274,6 +282,8 @@ then
# GPT FAT32
elif [[ "$labeltype" == "gpt" ]];
then
isolabel="$(sanitize_iso_name "$isolabel")"

echo "${bold} == Creating new GPT-formatted partition table ==${normal}"
format_drive "gpt" "$dev"

Expand Down

0 comments on commit 6249a7f

Please sign in to comment.