Skip to content

Commit

Permalink
Merge pull request #517 from ghaerr/cleanup
Browse files Browse the repository at this point in the history
[mbr] Various standardizations for MBR boot/partitions
  • Loading branch information
ghaerr authored Apr 5, 2020
2 parents da2a49d + 2d36538 commit a1669d5
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 29 deletions.
2 changes: 1 addition & 1 deletion elks/arch/i86/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ CONFIG_FS_DEV=y
# CONFIG_ROOT_READONLY is not set
# CONFIG_FS_RO is not set
CONFIG_FULL_VFS=y
# CONFIG_32BIT_INODES is not set
CONFIG_32BIT_INODES=y
CONFIG_FS_EXTERNAL_BUFFER=y
CONFIG_PIPE=y

Expand Down
25 changes: 15 additions & 10 deletions elks/arch/i86/drivers/block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,29 @@ static void print_minor_name(register struct gendisk *hd,
static void add_partition(struct gendisk *hd, unsigned short int minor,
sector_t start, sector_t size)
{
struct hd_struct *hdp = &hd->part[minor];
#if 0
struct hd_struct *hd0 = &hd->part[0];
struct hd_struct *hdp = &hd->part[minor];

hdp->start_sect = start;
hdp->nr_sects = size;
print_minor_name(hd, minor);

/* additional partition check since no MBR signature*/
if (start > hd0->nr_sects || start+size > hd0->nr_sects) {
printk(":skip%d ", minor);
/*
* Additional partition check since no MBR signature:
* Some BIOS subtract a cylinder, making direct comparison incorrect.
* A CHS cylinder an have 63 max sectors * 255 heads, so adjust for that.
*/
sector_t adj_nr_sects = hd0->nr_sects + 63 * 255;
if (start > adj_nr_sects || start+size > adj_nr_sects) {
printk("skipped ");
hdp->start_sect = -1;
hdp->nr_sects = 0;
return;
}
#endif

/* save boot partition # based on start offset*/
if ((int)start == setupw(0x1e4))
boot_partition = minor;

hdp->start_sect = start;
hdp->nr_sects = size;
print_minor_name(hd, minor);
}

static int is_extended_partition(register struct partition *p)
Expand Down
8 changes: 6 additions & 2 deletions elks/fs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,10 @@ void mount_root(void)
root_mountflags |= MS_RDONLY;
retval = open_filp(0, d_inode, &filp);
}
if (retval) panic("VFS: Unable to open root device %s\n", kdevname(ROOT_DEV));
if (retval) {
printk("VFS: Unable to open root device %s\n", kdevname(ROOT_DEV));
halt();
}

fs_type = &file_systems[0];
do {
Expand Down Expand Up @@ -535,5 +538,6 @@ void mount_root(void)
}
#endif

panic("VFS: Unable to mount root fs on %s\n", kdevname(ROOT_DEV));
printk("VFS: Unable to mount root fs on %s\n", kdevname(ROOT_DEV));
halt();
}
1 change: 1 addition & 0 deletions elks/include/linuxmt/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern int kill_pg(pid_t,sig_t,int);

extern int kill_sl(void);

extern void halt(void);
extern void panic(char *, ...);
extern void printk(char *, ...);
extern void early_printk (char *);
Expand Down
17 changes: 11 additions & 6 deletions elks/kernel/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ void printk(char *fmt, ...)
va_end(p);
}

void halt(void)
{
/* Lock up with infinite loop */
kputs("\nSYSTEM HALTED - Press CTRL-ALT-DEL to reboot:");

while (1)
/* Do nothing */;
}

void panic(char *error, ...)
{
va_list p;
Expand All @@ -219,6 +228,7 @@ void panic(char *error, ...)
va_start(p, error);
vprintk(error, p);
va_end(p);

kputs("\napparent call stack:\n"
"Line: Addr Parameters\n"
"~~~~: ~~~~ ~~~~~~~~~~");
Expand All @@ -232,10 +242,5 @@ void panic(char *error, ...)
} while ((int)(++j) <= 8);
} while (++i < 9);

/* Lock up with infinite loop */

kputs("\n\nSYSTEM LOCKED - Press CTRL-ALT-DEL to reboot:");

while (1)
/* Do nothing */;
halt();
}
9 changes: 8 additions & 1 deletion elks/tools/setboot/setboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,21 @@ static void writePartition(unsigned char *buf)

/* create partition #1 at sector 2 using max CHS as size*/
p->boot_ind = 0x80;
#if 1
p->head = 1;
p->sector = 1; /* next cylinder after MBR, standard*/
p->cyl = 0;
p->start_sect = NumTracks; /* zero-relative start sector here*/
#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*/
#endif
p->sys_ind = 0x80; /* ELKS, Old Minix*/
p->end_head = NumHeads;
p->end_sector = SecPerTrk | ((NumTracks >> 2) & 0xc0);
p->end_cyl = NumTracks & 0xff;
p->start_sect = 1; /* zero-relative start sector here*/
p->start_sect_hi = 0;
p->nr_sects = nr_sects & 0xffff;
p->nr_sects_hi = nr_sects >> 16;
Expand Down
14 changes: 7 additions & 7 deletions elkscmd/disk_utils/fdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ void add_part(void)
return;
}

#if 0
/* skip cylinder 0 head 0 sectors, use head 1 sector 1*/
#if 1
/* skip cylinder 0 head 0 sectors, use head 1 sector 1 (standard)*/
p.head = (scyl == 0) ? 1 : 0;
p.sector = 1 + ((scyl >> 2) & 0xc0);
#else
Expand Down Expand Up @@ -362,8 +362,8 @@ void list_partition(char *devname)
}
} else
memcpy(table,MBR,512);
printf(" START END SECTOR\n");
printf("Device #:ID Head Sect Cyl Head Sect Cyl Start Size\n\n");
printf(" START END SECTOR\n");
printf("Device #:ID Cyl Head Sect Cyl Head Sect Start Size\n\n");
for (i=0; i<4; i++) {
struct partition *p = (struct partition *)&table[PARTITION_START + (i<<4)];
unsigned long start_sect = p->start_sect | ((unsigned long)p->start_sect_hi << 16);
Expand All @@ -376,17 +376,17 @@ void list_partition(char *devname)
*p = 0;
}
//if (p->end_head)
printf("%-15s %c%d:%02x %2d %3d%5d %2d %3d%5d %6lu %6lu\n",
printf("%-15s %c%d:%02x %2d %3d%5d %2d %3d%5d %6lu %6lu\n",
device,
p->boot_ind==0?' ':(p->boot_ind==0x80?'*':'?'),
i+1, /* #*/
p->sys_ind, /* Partition type */
p->cyl | ((p->sector & 0xc0) << 2), /* Start cylinder */
p->head, /* Start head */
p->sector & 0x3f, /* Start sector */
p->cyl | ((p->sector & 0xc0) << 2), /* Start cylinder */
p->end_cyl | ((p->end_sector & 0xc0) << 2), /* End cylinder */
p->end_head, /* End head */
p->end_sector & 0x3f, /* End sector */
p->end_cyl | ((p->end_sector & 0xc0) << 2), /* End cylinder */
start_sect, /* Size*/
nr_sects); /* Sector count */
}
Expand Down
4 changes: 2 additions & 2 deletions image/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ hd32-fat:

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

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

# Clean target
Expand Down

0 comments on commit a1669d5

Please sign in to comment.