Skip to content

Commit

Permalink
Merge pull request #2084 from ghaerr/mbr
Browse files Browse the repository at this point in the history
[boot] Fix bad MBR partition generated by setboot
  • Loading branch information
ghaerr authored Oct 21, 2024
2 parents eddf88b + 4febb81 commit 1bcdc74
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions elks/tools/setboot/setboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,19 @@ static void writePartition(unsigned char *buf)
p->sector = 1; /* next cylinder after MBR, standard*/
p->cyl = 0;
p->start_sect = NumTracks; /* zero-relative start sector here*/
nr_sects -= SecPerTrk;
#else
p->head = 0;
p->sector = 2; /* next sector after MBR, non-standard*/
p->cyl = 0;
p->start_sect = 1; /* zero-relative start sector here*/
nr_sects -= 1;
#endif
StartSector = p->start_sect;
p->sys_ind = 0x80; /* ELKS, Old Minix*/
p->end_head = NumHeads;
p->end_sector = SecPerTrk | ((NumTracks >> 2) & 0xc0);
p->end_cyl = NumTracks & 0xff;
p->end_sector = SecPerTrk | (((NumTracks-1) >> 2) & 0xc0);
p->end_cyl = (NumTracks-1) & 0xff;
p->start_sect_hi = 0;
p->nr_sects = nr_sects & 0xffff;
p->nr_sects_hi = nr_sects >> 16;
Expand Down
8 changes: 4 additions & 4 deletions elkscmd/disk_utils/fdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ void add_part(void)
oset = MBR + PARTITION_START + ((part - 1) * 16);

printf("Total cylinders: %d\n", geometry.cylinders);
for (scyl = geometry.cylinders + 1; scyl < 0 || scyl > geometry.cylinders;) {
printf("First cylinder (%d-%d): ", 0, geometry.cylinders);
for (scyl = geometry.cylinders; scyl < 0 || scyl > geometry.cylinders-1;) {
printf("First cylinder (%d-%d): ", 0, geometry.cylinders-1);
fflush(stdout);
fgets(buf, 31, stdin);
scyl = atoi(buf);
Expand All @@ -185,8 +185,8 @@ void add_part(void)
p.cyl = (scyl & 0xff);
p.sys_ind = PARTITION_TYPE;

for (ecyl = geometry.cylinders + 1; ecyl < scyl || ecyl > geometry.cylinders;) {
printf("Ending cylinder (%d-%d): ", 0, geometry.cylinders);
for (ecyl = geometry.cylinders; ecyl < scyl || ecyl > geometry.cylinders-1;) {
printf("Ending cylinder (%d-%d): ", 0, geometry.cylinders-1);
fflush(stdout);
fgets(buf, 31, stdin);
ecyl = atoi(buf);
Expand Down
4 changes: 2 additions & 2 deletions image/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ hd32-fat:
rm Config

# MBR images
hd32mbr-minix:
hd32mbr-minix: hd32-minix
dd if=/dev/zero bs=512 count=63 | cat - hd32-minix.img > hd32mbr-minix.img
setboot hd32mbr-minix.img -P63,16,63 -Sm $(HD_MBR_BOOT)

hd32mbr-fat:
hd32mbr-fat: hd32-fat
dd if=/dev/zero bs=512 count=63 | cat - hd32-fat.img > hd32mbr-fat.img
setboot hd32mbr-fat.img -P63,16,63 -Sf $(HD_MBR_BOOT)

Expand Down

0 comments on commit 1bcdc74

Please sign in to comment.