Skip to content

Commit

Permalink
Merge pull request #121 from Konamiman/support-extended-partition-lba
Browse files Browse the repository at this point in the history
  • Loading branch information
Konamiman committed Nov 30, 2023
2 parents a8aebf1 + a7e89f3 commit 7e8d5f8
Show file tree
Hide file tree
Showing 10 changed files with 450 additions and 78 deletions.
5 changes: 4 additions & 1 deletion docs/Nextor 2.1 Programmers Reference.md
Expand Up @@ -501,11 +501,14 @@ The partition type code returns information about the filesystem that the partit
0: None (the partition with the specified number does not exist)
1: FAT12
4: FAT16, smaller than 32MB (obsolete)
5: Extended (see below)
5: Extended (CHS) (see below)
6: FAT16 (CHS)
14: FAT16 (LBA)
15: Extended (LBA)
```

**Note:** Prior to version 2.1.2, Nextor would only recognize a partition as extended if it had the partition type code 5 (extended CHS), and FDISK would use this code when creating extended partitions. Starting with Nextor 2.1.2, FDISK will use partition type code 15 (extended LBA) when creating extended partitions, and both 5 and 15 will be recognized as valid extended partition type codes when scanning existing partitions with `_GPART`. In the description below, "Extended" means "Either extended CHS or extended LBA".

There are many more partition type codes defined, but they refer to filesystems that can't be handled by Nextor so they are not listed here.

A device can have up to four primary partitions, numbered 1 to 4. In order to accommodate more than four partitions, partition number 2 may be of a special type named "Extended". An extended partition is actually a container for more partitions; there is no limit in the number of extra partitions that a partition of type "Extended" can contain. Primary partitions 3 and 4 do not exist when partition 2 is extended.
Expand Down
12 changes: 0 additions & 12 deletions source/kernel/bank2/val.mac
Expand Up @@ -8,20 +8,8 @@
INCLUDE ../const.inc
RAMMOD

MBR_PSTART equ 01BEh ;Start of partition table in MBR
MBR_PSIZE equ 16 ;Size of partition table entry
POFF_TYPE equ 4 ;Offset of partition type in p. table entry
POFF_PSTART equ 8 ;Offset of partition start in p. table entry
POFF_PSIZE equ 12 ;Offset of partition size in p. table entry
PT_FAT12 equ 1 ;Partition type code for FAT12
PT_FAT16_S equ 4 ;Partition type code for FAT16 (< 32M)
PT_EXT equ 5 ;Partition type code for extended partition
PT_FAT16 equ 6 ;Partition type code for FAT16
PT_FAT16_L equ 14 ;Partition type code for FAT16 (LBA)
MBR_SIG equ 512-2 ;MBR signature offset in MBR (55h, AAh)
MAXCLUS_FAT12 equ 4084
MAXCLUS_12BITS equ 4095

;
;-----------------------------------------------------------------------------
;
Expand Down
24 changes: 18 additions & 6 deletions source/kernel/bank4/partit.mac
Expand Up @@ -23,7 +23,8 @@ POFF_PSTART equ 8 ;Offset of partition start in p. table entry
POFF_PSIZE equ 12 ;Offset of partition size in p. table entry
PT_FAT12 equ 1 ;Partition type code for FAT12
PT_FAT16_S equ 4 ;Partition type code for FAT16 (< 32M)
PT_EXT equ 5 ;Partition type code for extended partition
PT_EXT equ 5 ;Partition type code for extended partition (CHS)
PT_EXT_LBA equ 15 ;Partition type code for extended partition (LBA)
PT_FAT16 equ 6 ;Partition type code for FAT16
PT_FAT16_L equ 14 ;Partition type code for FAT16 (LBA)

Expand Down Expand Up @@ -205,7 +206,7 @@ DO_EXTPAR:
;--- If extended partition requested, first check that partition is actually extended

ld a,(ix+POFF_TYPE)
cp PT_EXT
call IS_EXT_PART
jp nz,UNEX_PART

ld a,(ix+POFF_PSTART) ;Save the start sector number of the outer extended partition
Expand Down Expand Up @@ -285,7 +286,7 @@ EXTP_NEXT:
pop bc

ld a,(ix+POFF_TYPE)
cp PT_EXT
call IS_EXT_PART
jr nz,TPIY_UNEX_PART

jr EXTP_LOOP
Expand Down Expand Up @@ -1232,7 +1233,7 @@ AA_PX_DOEMU:

AA_PX_NOEMU:
ld a,b ;Partition type
cp PT_EXT
call IS_EXT_PART
jr nz,AA_PX_NOEX
ld a,(ix+AAD_CURR_PART_INDEX)
or 80h
Expand Down Expand Up @@ -4505,7 +4506,7 @@ MAPDRV_NOP0:
ld c,_GPART##
call BASIC_DOS
ld a,b
cp 5 ;Extended partition?
call IS_EXT_PART ;Extended partition?

pop bc
ld a,b
Expand Down Expand Up @@ -4540,7 +4541,7 @@ MAPDRV_GOTPAR:
ld a,b
or a
jp z,BASIC_ERR
cp 5
call IS_EXT_PART
jp z,BASIC_ERR ;"Invalid partition" error if non existing or extended partition
ld e,c

Expand Down Expand Up @@ -6278,5 +6279,16 @@ STRCOMP:
inc de
jr STRCOMP


; Check if the partition type passed in A
; corresponds to a recognized extended partition type,
; return Z if so or NZ otherwise

IS_EXT_PART:
cp PT_EXT
ret z
cp PT_EXT_LBA
ret

finish <PARTIT>
end
2 changes: 1 addition & 1 deletion source/kernel/bank5/fdisk.c
Expand Up @@ -841,7 +841,7 @@ byte GetDiskPartitionsInfo()
DosCallFromRom(_GPART, REGS_ALL);
error = regs.Bytes.A;
if(error == 0) {
if(regs.Bytes.B == PARTYPE_EXTENDED) {
if(regs.Bytes.B == PARTYPE_EXTENDED || regs.Bytes.B == PARTYPE_EXTENDED_LBA) {
extendedIndex = 1;
} else {
currentPartition->primaryIndex = primaryIndex;
Expand Down
4 changes: 2 additions & 2 deletions source/kernel/bank5/fdisk2.c
Expand Up @@ -415,7 +415,7 @@ int CalculateFatFileSystemParametersFat16(ulong fileSystemSizeInK, dosFilesystem
clusterCount = dataSectorsCount >> sectorsPerClusterPower;
sectorsPerFat = (clusterCount + 2) >> 8;

if(((clusterCount + 2) & 0x3FF) != 0) {
if(((clusterCount + 2) & 0xFF) != 0) {
sectorsPerFat++;
}

Expand Down Expand Up @@ -515,7 +515,7 @@ int CreatePartition(int index)

if(index != (partitionsCount - 1)) {
tableEntry++;
tableEntry->partitionType = PARTYPE_EXTENDED;
tableEntry->partitionType = PARTYPE_EXTENDED_LBA;
tableEntry->firstAbsoluteSector = nextDeviceSector;
if(index == 0) {
mainExtendedPartitionFirstSector = nextDeviceSector;
Expand Down
54 changes: 0 additions & 54 deletions source/kernel/bank6/partit.h

This file was deleted.

2 changes: 1 addition & 1 deletion source/tools/C/Makefile
Expand Up @@ -11,7 +11,7 @@ define copy_to_bin
cp $(1) ../../../bin/tools/$(2)
endef

COMS := emufile.com fsize.com nexboot.com vsft.com
COMS := emufile.com fsize.com nexboot.com vsft.com eptcft.com

c-tools: $(COMS)

Expand Down

0 comments on commit 7e8d5f8

Please sign in to comment.