#ifndef __MSDIR__ #define __MSDIR__ /* * MSDIR.H Definitions for MS-DOS directory info * * Copyright (c) 1991 Shal Farley * Cheshire Engineering Corporation * 650 Sierra Madre Villa Avenue, Suite 201 * Pasadena, California 91107 * (818) 351-5493 * (818) 351-8645 FAX * shal@alumni.caltech.edu * * This software may be used and distributed for any purpose without license or * royalty payments so long as the above copyright notice is preserved. If you * have any comments, bug fixes, improvements, or new programs based upon this * software I'd like to hear from you. */ #define SECTOR 512 /* "Always" 512 Bytes per sector (block) */ /* * Seek offsets in the first sector (the boot sector) */ #define MSVH_BS 0x0000L /* Boot Sector */ #define MSVH_SYSID 0x01FEL /* Boot signature = 0xAA55 */ /* * A structure holding information about the MS-DOS device */ typedef struct { long nsTotal; /* 2400 for 1.2 MB diskettes */ FILE *pFILE; /* Pointer to the file containing our info */ UCHAR *pDir; /* Pointer to Root Directory */ UCHAR *pFAT; /* Pointer to File Allocation Table */ int fDir; /* Directory needs to be written */ int fFAT; /* FAT needs to be written */ int fValid; /* Device has valid boot signature */ int fMaybe; /* Device has valid BIOS parameters */ int fRT11; /* Device has RT-11 signature */ int nsBoot; /* Sectors per Boot block, always 1 */ int nFATs; /* Always 2 */ int nsFAT; /* Sectors per FAT */ int nDirEntries; /* Entries in Root Directory (32 bytes ea) */ int nsCluster; /* Sectors per cluster, always a power of 2 */ char sName[MSDEVNAME_MAX]; /* RT-11 "DEV:FILNAM.TYP" of device */ } MSDEV; /* * MS-DOS Disk Structure: * Boot block(s) "Always" just one sector * FAT(s) "Always" two copies, variable sized * Root Directory Variable sized * * After reset the BIOS roms of a PC system will read in the bootstrap sector * (sector 0) and jump to it. The first three bytes contain a jump to some code * later in the sector. For "data" disks this code usually prints an error * message and hangs. For "system" disks this code reads in the operating * system. * * The boot block also contains parameters, including the "BIOS Parameter * Block", which tell the BIOS about the format of the media. The MSBS * structure definition below describes the parameters. * * Note that the parameters in the BS are declared as byte arrays, this is to * ensure size conformance regardless of the host's data sizes. Copy any * useful information to host format in the MSDEV structure. The same is true * of the directory entries, copy any useful info to host format in MSFILE. */ /* * The boot sector starts at byte 0 of block 0 of the disk. * * See p34 of Microsoft MS-DOS Programmer's Reference: Version 5 */ typedef struct { UCHAR Jump[3]; /* 0 Jump to start of boot code */ char OemName[8]; /* 3 Name & Version of DOS */ UCHAR BytesPerSec[2]; /* B Always 512 */ UCHAR SecPerClust; /* D 1 or 2 for diskettes */ UCHAR ResSectors[2]; /* E Reserved for Bootstrap, typically 1 */ UCHAR FATs; /* 10 Typically 2 or larger */ UCHAR RootDirEnts[2]; /* 11 224 for 1.2 MB diskettes */ UCHAR Sectors[2]; /* 13 2400 for 1.2 MB diskettes */ UCHAR Media; /* 15 0xF9 for 1.2 MB diskettes */ UCHAR FATsecs[2]; /* 16 7 for 1.2 MB diskettes */ UCHAR SecPerTrack[2]; /* 18 15 for 1.2 MB diskettes */ UCHAR Heads[2]; /* 1A 2 for 1.2 MB diskettes */ /* * Note: the fields below are new in MS-DOS 5.0 (some were present but * undocumented in prior versions). Test .BootSignature to see if the * extended fields are valid. */ UCHAR HiddenSecs[4]; /* 1C Size of partition table */ UCHAR HugeSectors[4]; /* 20 if (disk > 32 MB) .Sectors = 0 */ UCHAR DriveNumber; /* 24 (1st hard drive)? 0x80 : 0x00 */ UCHAR Reserved1; /* 25 do not use */ UCHAR BootSignature; /* 26 extended boot signature == 0x29 */ UCHAR VolumeID[4]; /* 27 Volume serial number */ char VolumeLabel[11]; /* 2B Volume label */ char FileSysType[8]; /* 36 "FAT12 " or "FAT16 " */ } MSBS; #define MSFN_DMAX 1 /* Maximum device field width */ #define MSFN_FMAX 8 /* Maximum name field width */ #define MSFN_TMAX 3 /* Maximum type field width */ /* * Directory Entry structure * * See p38 of Microsoft MS-DOS Programmer's Reference: Version 5 */ typedef struct { char Name[MSFN_FMAX]; /* File Name, in a subset of ASCII */ char Extension[MSFN_TMAX]; /* File Extension, " */ UCHAR Attributes; /* Entry Status byte */ #define MSS_RONLY (0x01) /* " Read-Only file */ #define MSS_HIDDEN (0x02) /* " Hidden file */ #define MSS_SYSTEM (0x04) /* " System file */ #define MSS_ROOT (0x08) /* " Root directory entry w/ volume label */ #define MSS_DIR (0x10) /* " Entry containing a subdirectory */ #define MSS_DIRTY (0x20) /* " Dirty (aka "archive") */ UCHAR Reserved[10]; /* Reserved */ UCHAR Time[2]; /* File update time (little endian short) */ UCHAR Date[2]; /* File update date ( " ) */ UCHAR StartCluster[2]; /* Starting cluster number ( " ) */ UCHAR FileSize[4]; /* File size (little endian long) */ } MSDE; /* * 12-bit FAT Entry structure */ typedef struct { UCHAR b0; /* bits 0-7 of first entry */ UCHAR b1; /* bits 8-11 of first, 0-3 of second */ UCHAR b2; /* bits 4-11 of second entry */ } MSFE; /* * Prototypes for our non-ANSI functions */ extern MSDEV *msdopen(/* devname */); /* Set up the MS-DOS device info * char *devname; "DEV:xxxxx" or "DEV:FILNAM.TYP:xxxxx" * Returns pointer to malloc'd MSDEV */ extern int msdclose(/* pD */); /* Close the MS-DOS device * MSDEV *pD; * Returns 0 on success, EOF on error */ #endif /*__MSDIR__*/