From eccc022091778197769e4e2b57b66049f10577aa Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Sat, 21 Mar 2026 16:03:51 +0100 Subject: [PATCH] sdutil cleanup start_part_dos (), write_iso.sh only work with block devs --- aux/write_iso.sh | 13 ++++++++++++- sdutil/sdutil.c | 36 ++++++++++-------------------------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/aux/write_iso.sh b/aux/write_iso.sh index 89ca690..e4b16f1 100755 --- a/aux/write_iso.sh +++ b/aux/write_iso.sh @@ -3,6 +3,17 @@ # Requires sudo # USAGE: ./aux/write_iso.sh /dev/sda +TARGET="$1" + +if [ -z "$TARGET" ]; then + exit 1 +fi + +if [ ! -b "$TARGET" ]; then + echo "Not a block device" + exit 1 +fi + set -x -dd if=./mop3.iso of="$1" bs=4M status=progress oflag=direct conv=notrunc,sync && sync +dd if=./mop3.iso of="$TARGET" bs=4M status=progress oflag=direct conv=notrunc,sync && sync diff --git a/sdutil/sdutil.c b/sdutil/sdutil.c index b2045d3..5b31a65 100644 --- a/sdutil/sdutil.c +++ b/sdutil/sdutil.c @@ -59,39 +59,23 @@ static void start_part_dos (void) { in_stream_read_line ("Device name: ", dev_name, sizeof (dev_name)); -#define prompt_partition(N) \ +#define prompt_and_setup_partition(N) \ char p##N##_start_lba_str[12], p##N##_sector_cout_str[12]; \ uint32_t p##N##_start_lba, p##N##_sector_count; \ mprintf ("\nConfigure parition %d:\n", N); \ in_stream_read_line ("Start LBA: ", p##N##_start_lba_str, sizeof (p##N##_start_lba_str)); \ in_stream_read_line ("Sector count: ", p##N##_sector_cout_str, sizeof (p##N##_sector_cout_str)); \ p##N##_start_lba = str_to_uint32 (p##N##_start_lba_str); \ - p##N##_sector_count = str_to_uint32 (p##N##_sector_cout_str); + p##N##_sector_count = str_to_uint32 (p##N##_sector_cout_str); \ + mbr.ptes[N].start_lba = p##N##_start_lba; \ + mbr.ptes[N].sector_count = p##N##_sector_count; \ + lba_to_chs (p##N##_start_lba, mbr.ptes[N].chs_start_addr); \ + lba_to_chs (p##N##_start_lba + p##N##_sector_count - 1, mbr.ptes[N].chs_last_sect_addr); - prompt_partition (0); - prompt_partition (1); - prompt_partition (2); - prompt_partition (3); - - mbr.ptes[0].start_lba = p0_start_lba; - mbr.ptes[0].sector_count = p0_sector_count; - lba_to_chs (p0_start_lba, mbr.ptes[0].chs_start_addr); - lba_to_chs (p0_start_lba + p0_sector_count - 1, mbr.ptes[0].chs_last_sect_addr); - - mbr.ptes[1].start_lba = p1_start_lba; - mbr.ptes[1].sector_count = p1_sector_count; - lba_to_chs (p1_start_lba, mbr.ptes[1].chs_start_addr); - lba_to_chs (p1_start_lba + p1_sector_count - 1, mbr.ptes[1].chs_last_sect_addr); - - mbr.ptes[2].start_lba = p2_start_lba; - mbr.ptes[2].sector_count = p2_sector_count; - lba_to_chs (p2_start_lba, mbr.ptes[2].chs_start_addr); - lba_to_chs (p2_start_lba + p2_sector_count - 1, mbr.ptes[2].chs_last_sect_addr); - - mbr.ptes[3].start_lba = p3_start_lba; - mbr.ptes[3].sector_count = p3_sector_count; - lba_to_chs (p3_start_lba, mbr.ptes[3].chs_start_addr); - lba_to_chs (p3_start_lba + p3_sector_count - 1, mbr.ptes[3].chs_last_sect_addr); + prompt_and_setup_partition (0); + prompt_and_setup_partition (1); + prompt_and_setup_partition (2); + prompt_and_setup_partition (3); mbr.valid_sign[0] = 0x55; mbr.valid_sign[1] = 0xAA;