Skip to content

Commit

Permalink
implement different drive letter assignment methods
Browse files Browse the repository at this point in the history
  • Loading branch information
boeckmann committed Aug 4, 2024
1 parent 2fd5905 commit 1c9271f
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 16 deletions.
11 changes: 11 additions & 0 deletions bin/fdisk.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
; CHECKEXTRA={TRUE | FALSE}
; COLORS={0<=N<=127}
; DEL_ND_LOG={ON | OFF}
; DLA={0 | 1 | 2}
; DRIVE=#-####-###-##
; FLAG_SECTOR={0 | 2<=N<=64 | 256}
; LBA_MARKER={ON | OFF}
Expand Down Expand Up @@ -64,6 +65,16 @@
; TRUE
; * FALSE
;
; DLA Drive letter assignment method.
; * 0 auto dectect by operating system
; 1 FreeDOS / Microsoft driver letter assignment
; one primary per disk (active first), then
; all extended sorted by disk and partition table,
; then all remaining primaries by disk and partition table
; 2 DR-DOS drive letter assignment
; all primaries first sorted by disk and partition table,
; then all logicals by disk and partition table
;
; FLAG_SECTOR Sector number where the flags will be located. The
; default is 2.
; 0 Disables sector flagging function.
Expand Down
6 changes: 4 additions & 2 deletions source/fdisk/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ TOOL_CC = wcc386

CC = wcc
CFLAGS = -q -0 -bt=dos -wx -we
!ifdef __LINUX__
!ifdef __UNIX__
CFLAGS += -i=$(%WATCOM)/h
!endif

AS = nasm
ASFLAGS = -t -f obj
LD = wlink
LDFLAGS =
!ifdef __LINUX__
!ifdef __UNIX__
SEP=/
CP = cp
MV = mv
Expand Down Expand Up @@ -76,6 +76,8 @@ CFLAGS += -DSMART_MBR=1
objs += smartmbr.obj
!endif

.erase

all : fdisk.exe
dist : ../../fdisk.zip
dist-svardos: ../../fdisk.svp
Expand Down
3 changes: 3 additions & 0 deletions source/fdisk/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ void Display_Information( void )
con_print( "FAT32" );
}

con_set_cursor_xy( 68, 1 );
con_printf("DLA%u", flags.dla );

if ( flags.use_ambr == TRUE ) {
con_set_cursor_xy( 73, 1 );
con_print( "AMBR" );
Expand Down
13 changes: 13 additions & 0 deletions source/fdisk/fdiskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,19 @@ void Process_Fdiskini_File( void )
command_ok = TRUE;
}

/* Check for the COLORS statement */
if ( 0 == stricmp( command_buffer, "DLA" ) ) {
number = atoi( setting_buffer );

if ( ( number >= 0 ) && ( number <= 2 ) ) {
flags.dla = number;
}
else {
goto parse_error;
}
command_ok = TRUE;
}

/* Check for the DEL_ND_LOG statement */
if ( 0 == stricmp( command_buffer, "DEL_ND_LOG" ) ) {
if ( !bool_string_to_int( &flags.del_non_dos_log_drives,
Expand Down
20 changes: 20 additions & 0 deletions source/fdisk/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ static int Get_Environment_Settings( char *environment[] )
bool_string_to_int( &flags.del_non_dos_log_drives, setting_buffer );
}

/* Check for drive letter ordering */
if ( 0 == strcmp( command_buffer, "FFD_DLA" ) ) {
number = atoi( setting_buffer );

if ( ( number >= 0 ) && ( number <= 2 ) ) {
flags.dla = number;
}
}

/* Check for the FLAG_SECTOR statement */
if ( 0 == strcmp( command_buffer, "FFD_FLAG_SECTOR" ) ) {
number = atoi( setting_buffer );
Expand Down Expand Up @@ -247,6 +256,7 @@ static void InitOptions( char *environment[] )

/* initialize flags, the ones not set here default to FALSE */
flags.display_name_description_copyright = TRUE;
flags.dla = 0; /* drive letter assignment based on OS */
flags.drive_number = 128;
flags.flag_sector = 2;
flags.lba_marker = TRUE;
Expand Down Expand Up @@ -287,8 +297,18 @@ static void InitOptions( char *environment[] )
if ( flags.version >= COMP_W95B ) {
flags.fat32 = TRUE;
}

if ( flags.dla == DLA_AUTO ) {
if ( os_oem == OEM_DRDOS ) {
flags.dla = DLA_DRDOS;
}
else {
flags.dla = DLA_MSDOS;
}
}
}


static void InitDisks( void )
{
/* Check for interrupt 0x13 extensions (If the proper version is set.) */
Expand Down
1 change: 1 addition & 0 deletions source/fdisk/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ typedef struct flags_structure {
int using_default_drive_number;
int check_for_extra_cylinder;
int do_not_pause_help_information;
int dla;
int drive_number;
int esc;
int extended_options_flag;
Expand Down
117 changes: 103 additions & 14 deletions source/fdisk/pdiskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ extern void Pause( void );

int os_version = 0;
int os_version_minor = 0;
int os_oem = 0;
int os_gui_running = 0;

void Determine_DOS_Version( void )
Expand All @@ -75,9 +76,24 @@ void Determine_DOS_Version( void )
/* check for DOS <5 */
r.w.ax = 0x3000;
intr( 0x21, &r );
if ( r.h.al < 5 ) {
os_version = r.h.al;
os_version_minor = r.h.ah;
os_version = r.h.al;
os_version_minor = r.h.ah;
os_oem = r.h.bh;

if ( os_oem == OEM_IBM ) {
/* Is it DR-DOS pretending to be PC-DOS? */
r.w.ax = 0x4452;
intr( 0x21, &r );
if ( !( r.w.flags & INTR_CF ) ) {
os_oem = OEM_DRDOS;
}
}
if ( os_oem == OEM_NOVELL ) {
/* treat Novell DR-DOS as all other DR-DOS versions */
os_oem = OEM_DRDOS;
}

if ( os_version < 5 ) {
return;
}

Expand Down Expand Up @@ -262,25 +278,45 @@ int Num_Ext_Part( Partition_Table *pDrive )
return num_ext;
}

void dla_msdos( int *cl );
void dla_drdos( int *cl );
void dla_nondos( void );

/* Determine drive letters */
int Determine_Drive_Letters( void )
/* Returns last used drive letter as ASCII number. */
{
// int active_found=FALSE;
int current_letter = 'C';
// int drive_found=FALSE;
int index = 0;
int non_dos_partition;
int non_dos_partition_counter;
int sub_index = 0;

int active_part_found[MAX_DISKS];

Load_Brief_Partition_Table();

/* Clear drive_lettering_buffer[8] [27] */
memset( drive_lettering_buffer, 0, sizeof( drive_lettering_buffer ) );

if ( flags.dla == DLA_MSDOS ) {
dla_msdos( &current_letter );
}
else {
/* DR-DOS drive letter assignment puts all primaries of all drives
first, in order of partition table, then all logicals, drive by
drive. */
dla_drdos( &current_letter );
}

/* assign numbers to non-DOS partitions */
dla_nondos();

return current_letter - 1;
}


void dla_msdos( int *cl )
{
int current_letter = *cl;
int index = 0;
int sub_index = 0;
int active_part_found[MAX_DISKS];

/* Set all active_part_found[] values to 0. */
memset( active_part_found, 0, sizeof( active_part_found ) );

Expand Down Expand Up @@ -352,6 +388,60 @@ int Determine_Drive_Letters( void )
}
}
}
*cl = current_letter;
}


void dla_drdos( int *cl )
{
int current_letter = *cl;
int index = 0;
int sub_index = 0;

/* assign up to one drive letter to an active or non-active partition
per disk */
for ( index = 0; index < MAX_DISKS; index++ ) {
Partition_Table *pDrive = &part_table[index];
if ( !pDrive->usable ) {
continue;
}

/* find active partition for drive */
for ( sub_index = 0; sub_index < 4; sub_index++ ) {
if ( ( IsRecognizedFatPartition(
brief_partition_table[index][sub_index] ) ) ) {
drive_lettering_buffer[index][sub_index] = current_letter;
current_letter++;
}
}
}

/* Next assign drive letters to applicable extended partitions... */
for ( index = 0; index < MAX_DISKS; index++ ) {
Partition_Table *pDrive = &part_table[index];
if ( !pDrive->usable ) {
continue;
}

for ( sub_index = 4; sub_index < 27; sub_index++ ) {
if ( IsRecognizedFatPartition(
brief_partition_table[index][sub_index] ) ) {
drive_lettering_buffer[index][sub_index] = current_letter;
current_letter++;
}
}
}

*cl = current_letter;
}


void dla_nondos( void )
{
int index = 0;
int sub_index = 0;
int non_dos_partition;
int non_dos_partition_counter;

/* Find the Non-DOS Logical Drives in the Extended Partition Table */
for ( index = 0; index < MAX_DISKS; index++ ) {
Expand Down Expand Up @@ -381,11 +471,10 @@ int Determine_Drive_Letters( void )
}
}
}
}

return ( current_letter - 1 );
}
}


void Clear_Partition( Partition *p )
{
memset( p, 0, sizeof( Partition ) );
Expand Down
11 changes: 11 additions & 0 deletions source/fdisk/pdiskio.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@
#define OS_WIN_ME 8
#define OS_WIN_NT 32

#define OEM_IBM 0x00
#define OEM_DRDOS 0xee
#define OEM_NOVELL 0xef
#define OEM_FRERDOS 0xfd

This comment has been minimized.

Copy link
@andrewbird

andrewbird Aug 4, 2024

Contributor

FRERDOS, typo or something else?

This comment has been minimized.

Copy link
@boeckmann

boeckmann Aug 4, 2024

Author Contributor

Oh, thanks. Should have been OEM_FREEDOS :)


#define DLA_AUTO 0
#define DLA_MSDOS 1
#define DLA_DRDOS 2 /* all primary partitions first, then logicals */

extern int os_version;
extern int os_version_minor;
extern int os_oem;

extern int os_gui_running;

/* Buffers */
Expand Down

0 comments on commit 1c9271f

Please sign in to comment.