# DOS 6.22 Boot Sequence and UPDATE.BAT Analysis

## Problem Summary

User reports:
1. Manual backup worked: `XCOPY /S C:\*.* T:\TS-4R\BACKUP`
2. UPDATE.BAT failed to:
   - Detect machine name (TS-4R) when run without parameters
   - Recognize T: drive as available (claims "T: not available")

## DOS 6.22 Boot Sequence

### Standard DOS 6.22 Boot Process

```
1. BIOS POST
2. Load DOS kernel (IO.SYS, MSDOS.SYS, COMMAND.COM)
3. Process CONFIG.SYS
   - Load device drivers
   - Set FILES, BUFFERS, etc.
4. Process AUTOEXEC.BAT
   - Set PATH, PROMPT, environment variables
   - Start network client (if configured)
5. User prompt (C:\>)
```

### Network Boot Additions

For DOS network clients (Microsoft Network Client 3.0 or Workgroup Add-On):

```
CONFIG.SYS:
   DEVICE=C:\NET\PROTMAN.DOS /I:C:\NET
   DEVICE=C:\NET\NE2000.DOS
   DEVICE=C:\NET\NETBEUI.DOS

AUTOEXEC.BAT:
   SET PATH=C:\DOS;C:\NET;C:\
   CALL C:\NET\STARTNET.BAT

STARTNET.BAT:
   NET START
   NET USE T: \\D2TESTNAS\test /YES
   NET USE X: \\D2TESTNAS\datasheets /YES
```

### Environment After Boot

After STARTNET.BAT completes:
- **T:** mapped to \\D2TESTNAS\test
- **X:** mapped to \\D2TESTNAS\datasheets
- **Environment variables:**
  - COMPUTERNAME may or may not be set (depends on network client version)
  - PATH includes C:\DOS, C:\NET
  - No USERNAME variable in DOS (Windows 95+ feature)

## Root Cause Analysis

### Issue #1: Machine Name Detection Failure

**Problem:** UPDATE.BAT cannot identify machine name (TS-4R)

**Likely causes:**

1. **COMPUTERNAME variable not set in DOS**
   - DOS 6.22 + MS Network Client 3.0 does NOT set %COMPUTERNAME%
   - This is a Windows 95/NT feature, NOT DOS
   - The batch file is checking for %COMPUTERNAME% which is EMPTY

2. **Machine name stored elsewhere:**
   - PROTOCOL.INI (network config file)
   - SYSTEM.INI (Windows 3.x if installed)
   - Could be hardcoded in STARTNET.BAT

3. **Detection method flawed:**
   - Cannot rely on environment variables in DOS
   - Must use different approach (config file, network query, or manual parameter)

### Issue #2: T: Drive Detection Failure

**Problem:** UPDATE.BAT claims "T: not available" when T: IS accessible

**Likely causes:**

1. **Incorrect drive check method:**
   ```bat
   REM WRONG - This doesn't work reliably in DOS 6.22:
   IF EXIST T:\ GOTO DRIVE_OK

   REM Also wrong - environment variable check:
   IF "%TDRIVE%"=="" ECHO T: not available
   ```

2. **Correct DOS 6.22 drive check:**
   ```bat
   REM Method 1: Check for specific file
   IF EXIST T:\NUL GOTO DRIVE_OK

   REM Method 2: Try to change to drive
   T: 2>NUL
   IF ERRORLEVEL 1 GOTO NO_T_DRIVE

   REM Method 3: Check for known directory
   IF EXIST T:\TS-4R\NUL GOTO DRIVE_OK
   ```

3. **Timing issue:**
   - STARTNET.BAT maps T: drive
   - If UPDATE.BAT runs immediately, network might not be fully ready
   - Need small delay or retry logic

### Issue #3: DOS 6.22 Command Limitations

**Cannot use in DOS 6.22:**
- `IF /I` (case-insensitive comparison) - added in Windows NT/2000
- `%ERRORLEVEL%` variable - must use `IF ERRORLEVEL n` syntax
- `FOR /F` loops - added in Windows 2000
- Long filenames - 8.3 only
- `||` and `&&` operators - cmd.exe features, not COMMAND.COM

**Must use:**
- `IF ERRORLEVEL n` (checks if >= n)
- Case-sensitive string comparison
- `GOTO` labels for flow control
- `CALL` for subroutines
- Simple FOR loops only (FOR %%F IN (*.TXT) DO ...)

## Detection Strategies

### Strategy 1: Parse PROTOCOL.INI for ComputerName

```bat
REM Extract computername from C:\NET\PROTOCOL.INI
REM Line format: computername=TS-4R
FOR %%F IN (C:\NET\PROTOCOL.INI) DO FIND "computername=" %%F > C:\TEMP\COMP.TMP
REM Parse the temp file... (complex in pure DOS batch)
```

**Problems:**
- FIND output includes filename
- No easy way to extract value in pure batch
- Requires external tools (SED, AWK, or custom .EXE)

### Strategy 2: Require Command-Line Parameter

```bat
REM UPDATE.BAT TS-4R
IF "%1"=="" GOTO NO_PARAM
SET MACHINE=%1
GOTO CHECK_DRIVE

:NO_PARAM
ECHO ERROR: Machine name required
ECHO Usage: UPDATE machine-name
ECHO Example: UPDATE TS-4R
GOTO END
```

**Pros:**
- Simple, reliable
- No parsing needed
- User control

**Cons:**
- Not automatic
- User must remember machine name

### Strategy 3: Hardcode or Use Environment File

```bat
REM In AUTOEXEC.BAT:
SET MACHINE=TS-4R

REM In UPDATE.BAT:
IF "%MACHINE%"=="" GOTO NO_MACHINE
```

**Pros:**
- Works automatically
- Set once per machine

**Cons:**
- Must edit AUTOEXEC.BAT per machine
- Requires reboot to change

### Strategy 4: Use WFWG computername

If Windows for Workgroups 3.11 is installed:

```bat
REM Read from SYSTEM.INI [network] section
REM ComputerName=TS-4R
```

Still requires parsing.

### Strategy 5: Check for Marker File

```bat
REM Each machine has C:\MACHINE.ID containing name
IF EXIST C:\MACHINE.ID FOR %%F IN (C:\MACHINE.ID) DO SET MACHINE=%%F
```

**Pros:**
- Simple file read
- Easy to set up

**Cons:**
- Requires creating file on each machine
- FOR loop reads filename, not contents (wrong approach)

## Recommended Solution

**Best approach: Use AUTOEXEC.BAT environment variable**

This is the standard DOS way to set machine-specific configuration.

```bat
REM In AUTOEXEC.BAT (one-time setup per machine):
SET MACHINE=TS-4R

REM In UPDATE.BAT:
IF "%MACHINE%"=="" GOTO NO_MACHINE_VAR
IF "%1"=="" GOTO USE_ENV
SET MACHINE=%1

:USE_ENV
REM Continue with backup using %MACHINE%
```

This supports both:
- Automatic detection via environment variable
- Manual override via command-line parameter

## T: Drive Detection Fix

**Current (broken) method:**
```bat
IF "%T%"=="" ECHO T: not available
```

This checks if environment variable %T% is set, NOT if T: drive exists.

**Correct method:**
```bat
REM Test if T: drive is accessible
T: 2>NUL
IF ERRORLEVEL 1 GOTO NO_T_DRIVE

REM Alternative: Check for NUL device
IF NOT EXIST T:\NUL GOTO NO_T_DRIVE

REM We're on T: drive now, go back to C:
C:
GOTO T_DRIVE_OK

:NO_T_DRIVE
ECHO [ERROR] T: drive not available
ECHO Run STARTNET.BAT to map network drives
GOTO END

:T_DRIVE_OK
REM Continue with backup
```

## Console Output Issues

**Problem:** DOS screen scrolls too fast, errors disappear

**Solutions:**

1. **Remove |MORE from commands** - causes issues in batch files
2. **Use PAUSE strategically:**
   ```bat
   ECHO Starting backup of %MACHINE%...
   REM ... backup commands ...
   IF ERRORLEVEL 1 GOTO ERROR
   ECHO [OK] Backup completed
   GOTO END

   :ERROR
   ECHO [ERROR] Backup failed!
   PAUSE Press any key to continue...
   GOTO END

   :END
   ```

3. **Compact output:**
   ```bat
   ECHO Backup: %MACHINE% to T:\%MACHINE%\BACKUP
   XCOPY /S /Y /Q C:\*.* T:\%MACHINE%\BACKUP
   IF ERRORLEVEL 4 ECHO [ERROR] Insufficient memory
   IF ERRORLEVEL 2 ECHO [ERROR] User terminated
   IF ERRORLEVEL 1 ECHO [ERROR] No files found
   IF NOT ERRORLEVEL 1 ECHO [OK] Complete
   ```

## Summary of Fixes Needed

1. **Machine detection:**
   - Add `SET MACHINE=TS-4R` to AUTOEXEC.BAT
   - UPDATE.BAT checks %MACHINE% first, then %1 parameter

2. **T: drive detection:**
   - Replace variable check with actual drive test: `T: 2>NUL` or `IF EXIST T:\NUL`
   - Add error handling for network not started

3. **Console output:**
   - Remove |MORE pipes
   - Add PAUSE only on errors
   - Use compact single-line status messages

4. **Automatic execution:**
   - Add CALL UPDATE.BAT to end of STARTNET.BAT or AUTOEXEC.BAT
   - Run silently if successful, show errors if failed

Next: Create corrected batch files.
