
#pragma pack(1)			/////// needed for C set //////////

/*--------------------------------------------------------------------*/
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*                                                                    */
/*--------------------------------------------------------------------*/

/* XLATOFF */

typedef ULONG (*PMFSFN)();

/*--------------------------*/
/* Disk Control Block       */
/* format                   */
/*--------------------------*/

typedef struct _DCB  *PDCB;
typedef struct _VOL  *PVOL;


typedef struct _DCB                    /* one per physical fixed disk     */
{
  PDCB          pDCBNext;              /* next DCB in the chain           */
  PVOL          pVolChain;             /* volume control block chain      */

  PVOID         pDDB;                  /* device driver control block     */

  ULONG         Flags;                 /* see DCBF_?? below               */

  ULONG         DevType;               /* see DCB_DEVTYPE_?? below        */
  ULONG         DiskNum;               /* physical media #: 0, 1, etc.    */

  /*-----------------------------------*/
  /* Geometry obtained from OS/2 DD    */
  /*-----------------------------------*/
  ULONG         NumCyl;                /* number of cylinders             */
  ULONG         NumHeads;              /* number of heads                 */
  ULONG         SecPerTrk;             /* sectors per track               */

  ULONG         SecSize;               /* sector size in bytes            */
  ULONG         SecShift;              /* right shift count to convert    */
                                       /* from bytes to sector(s)         */
  PMFSFN        pDriveRead;            /* FS specific read routine        */
  PMFSFN        pDriveWrite;           /* FS specific write routine       */


} DCB;

#define DCBF_PARTITIONED        0x80000000   /* partitionable device      */
#define DCBF_REMOVABLE          0x40000000   /* removable media           */

#define DCB_DEVTYPE_DISK        1            /* fixed disk                */
#define DCB_DEVTYPE_CDROM       2            /* CDROM                     */
#define DCB_DEVTYPE_RWOPT       3            /* read/write optical        */
#define DCB_DEVTYPE_DSKT        4            /* diskette                  */

/*--------------------------*/
/* Boot Record format       */
/*                          */
/*                          */
/*--------------------------*/

typedef struct _MBRENTRY  *PMBRENTRY;

typedef struct _MBRENTRY
{
  UCHAR         BootFlag;              /* 0=non bootable 80h=bootable     */
  UCHAR         StartHead;             /* bit 7-6: high order two bits of */
                                       /*          the 1st cylinder in    */
                                       /*          partition              */
                                       /* bit 5-0: first head in part.    */
  UCHAR         StartSec;              /* 1st sector in partition         */
  UCHAR         StartCyl;              /* low order eight bits of the     */
                                       /* the 1st cylinder in partition   */
  UCHAR         PartType;              /* partition type see below        */
  UCHAR         EndHead;               /* bit 7-6: high order two bits of */
                                       /*          the last cylinder in   */
                                       /*          partition              */
                                       /* bit 5-0: last head in partition */
  UCHAR         EndSec;                /* last sector in partition        */
  UCHAR         EndCyl;                /* low order eight bits of the     */
                                       /* last cylinder in partition      */
  ULONG         RelOffset;             /* # of sectors preceding the      */
                                       /* usable data area in this        */
                                       /* partition                       */
  ULONG         RelSize;               /* total # of sectors in this      */
                                       /* partition                       */
} MBRENTRY;

/*
   Format of Boot Sector is
     (1) boot code                      * begins with a 3 byte JMP instr  *
     (2) partition table - 4 entries    * starts at offset 446 =          *
                                        * 512 - (4 * sizeof MBRENTRY) - 2 *
     (3) signature word                 * 55aah - valid boot record       *
 */
#define MBR_OFFSET              446    /* start of partition table */
#define MAX_MBR_ENTRY           4      /* maximum # of partition tables   */

#define PARTTYPE_FAT12          0x04   /* partition >= 16MB <= 32MB       */
#define PARTTYPE_FAT16          0x06   /* partition > 32MB                */
#define PARTTYPE_OS2IFS         0x07   /* IFS partition                   */
#define PARTTYPE_EXTENDED       0x05   /* link to next partition          */


/*--------------------------*/
/* Volume control block     */
/* format                   */
/*--------------------------*/

typedef struct _VOL                    /* a partition on a disk requires  */
{                                      /* a volume control block          */
  PVOL          pVolNext;              /* next VCB chain                  */
  PDCB          pDCB;                  /* Device Control Block            */

  ULONG         Flags;                 /* see VOLF_?? flags below         */
  ULONG         DriveLetter;           /* drive letter assigned           */

  ULONG         IOBufSize;             /* 4096 bytes (8 sectors)          */
  ULONG         FileBlkSize;           /* sizeof(MFSFILE) +               */
                                       /* sizeof(FATINFO) for FAT FS      */
                                       /*           OR                    */
                                       /* sizeof(HPFSINFO) for HPFS FS    */
  ULONG         MBRPos;                /* start of boot record for the    */
                                       /* current partition see RelOffset */
  ULONG         BootRecPos;            /* offset to the partition tables  */
  ULONG         PartType;              /* partition type see PARTTYPE_??  */

  ULONG         SecSize;               /* # of bytes in a sector          */
  ULONG         SecShift;              /* right shift count to convert    */
                                       /* from bytes to sector(s)         */
  PMFSFN        pFSMount;              /* start of I/O service routines   */

  PMFSFN        pFileOpen;
  PMFSFN        pFileClose;

  PMFSFN        pFileRead;
  PMFSFN        pFileWrite;
  PMFSFN        pFileInfo;             /* end of I/O service routines     */

  ULONG         RootDirLSN;            /* LSN of the root directory       */

  PBYTE         pFSVolInfo;            /* FATVOLINFO, not used for HPFS   */

} VOL;

#define VOLF_PRIMARY            0x80000000
#define VOLF_MOUNT_REQ          0x40000000


/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/
typedef struct _FILE  *PFILE;

#ifdef HFILE
  #undef HFILE
#endif
typedef ULONG   HFILE;

#ifdef PHFILE
  #undef PHFILE
#endif
typedef HFILE  *PHFILE;

typedef struct _FILE
{
  PVOL          pVol;                  /* see volume control block format */

  ULONG         Flags;

  PBYTE         pBuf;
  ULONG         BufPos[2];

  ULONG         FileEOFSec;
  ULONG         FileEOFByte;

  UCHAR         FileName[MAX_FILE_NAME];

  UCHAR         FSInfo[1];

} MFSFILE;

#define FILEF_IOBUF_DIRTY       0x80000000

#define IOTYPE_EXTENT_READ      1
#define IOTYPE_EXTENT_WRITE     2

/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/

typedef struct _HPFSINFO *PHPFSINFO;

typedef struct _HPFSINFO
{
   PBYTE        pFNode;
   PBYTE        pNodeBuf;

} HPFSINFO;

/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/

typedef struct _EXTENT *PEXTENT;

typedef struct _EXTENT                              /* file extent structure */
{
  ULONG         ExtentRBA;     /* file extent LSN from the start of the disk */
  ULONG         ExtentSec;       /* # of consecutive sectors for this extent */

} EXTENT;

typedef struct _MFSFILEINFO *PMFSFILEINFO;

typedef struct _MFSFILEINFO
{
  ULONG         VolRBA;    /* volume offset (LSN) from the start of the disk */

  ULONG         FileSize;                       /* size of the file in bytes */

  ULONG         FSType;               /* FS_TYPE_FAT (6) or FS_TYPE_HPFS (7) */

  ULONG         cMaxExtents;           /* maximum # of elements in Extents[] */
  ULONG         cExtents;                       /* number file extents found */
  EXTENT        Extents[1];                                    /* Extents[0] */

} MFSFILEINFO;


/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/

typedef struct _FATEXTENT *PFATEXTENT;

typedef struct _FATEXTENT
{
  ULONG         ExtentRBA;
  ULONG         ExtentSec;

} FATEXTENT;

typedef struct _FATCLMAP *PFATCLMAP;

#define NUM_FAT_EXTENTS         16

typedef struct _FATCLMAP
{
  USHORT        ExtentCount;
  USHORT        Reserved_1;

  USHORT        StartCluster;
  USHORT        NextCluster;

  ULONG         FileSecPos[2];


  FATEXTENT     FatExtent[NUM_FAT_EXTENTS];

} FATCLMAP;

/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/
typedef struct _FATVOLINFO  *PFATVOLINFO;

typedef struct _FATVOLINFO                /* FAT volume specific information */
{                                         /* obtained from the boot sector   */
  USHORT       FatSecPerCL;               /* # of sectors per cluster        */
  USHORT       FatRootDirEnt;             /* # of dirents in this partition  */
  USHORT       FatBitsPerCL;              /* 12-bit or 16-bit clusters       */
  USHORT       FatEOFCLNum;               /* end of cluster marker           */
  USHORT       FatCLMask;                 /* 12-bit or 16-bit cluster mask   */
  ULONG        FatLSN;                    /* LSN to the 1st FAT table        */
  ULONG        FatClusterLSN;             /* LSN to the 1st cluster          */

} FATVOLINFO;

/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/

typedef struct _FATINFO *PFATINFO;

typedef struct _FATINFO
{
   PBYTE        pFatCLBuf;
   ULONG        FatCLBufAlign;
   USHORT       FatCLNum[2];

   FATCLMAP     FatCLMap;

} FATINFO;

#define NUM_FAT_BUFSEC          2


/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/

typedef struct _FATDIRENT *PFATDIRENT;

#ifdef _PPC
#pragma Push_align_members(1)
#endif

typedef struct _FATDIRENT                 /* FAT directory entry format      */
{
  UCHAR         FileName[11];             /* filename                        */
  UCHAR         FileAttr;                 /* attribute bits see below        */
  UCHAR         Reserved_1[10];           /* reserved                        */
  USHORT        FileChgTime;              /* time written                    */
  USHORT        FileChgDate;              /* date written                    */
  USHORT        FileStartCluster;         /* 1st allocation unit of file     */
  ULONG         FileSize;                 /* file size                       */

} FATDIRENT;

#ifdef _PPC
#pragma Pop_align_members()
#endif


/* FATDIRENT->FileName[0] */
#define FAT_FNTYPE_ERASED               0xE5
#define FAT_FNTYPE_END                  0x00


/* FATDIRENT->FileAttr */
#define FAT_FILEATTR_READONLY           0x01
#define FAT_FILEATTR_HIDDEN             0x02
#define FAT_FILEATTR_SYSTEM             0x04
#define FAT_FILEATTR_LABEL              0x08
#define FAT_FILEATTR_SUBDIR             0x10
#define FAT_FILEATTR_ARCHIVE            0x20


/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/

#ifdef _PPC
#pragma Push_align_members(1)
#endif

typedef struct _FATEXTBPB *PFATEXTBPB;

typedef struct _FATEXTBPB
{

  UCHAR         VolId[8];         /* 0*/
  USHORT        BytesPerSec;      /* 8*/  /* # of bytes in a sector          */
  UCHAR         SecPerCluster;    /*10*/  /* # of sector per allocation unit */
  USHORT        ResSectors;       /*11*/  /* # of reserved sectors           */
  UCHAR         NumFats;          /*13*/  /* # of FAT table(s)               */
  USHORT        RootDirEntries;   /*14*/  /* # of directory entries          */
  USHORT        TotalSec;         /*16*/  /* total # of sectors              */
  UCHAR         MediaInd;         /*18*/  /* media descriptor byte           */
  USHORT        FatSec;           /*19*/  /* # of sectors in a FAT table     */
  USHORT        SecPerTrack;      /*21*/  /* # of sectors per track          */
  USHORT        NumHeads;         /*23*/  /* # of heads                      */
  ULONG         HiddenSec;        /*25*/  /* # of hidden sectors             */
  ULONG         BigTotalSec;      /*29*/  /* total sectors if TotalSec = 0   */

  /*--------------------------------------------------------------*/
  /* The following byte is NOT part of the BPB but is set by SYS  */
  /* and format.  We should NOT change its position.              */
  /*--------------------------------------------------------------*/

  UCHAR         PhysDrive;
  UCHAR         LogDrive;

  UCHAR         Signature;
  ULONG         BootID;
  UCHAR         BootVolLabel[11];
  UCHAR         BootSystemID[8];

} FATEXTBPB;

#ifdef _PPC
#pragma Pop_align_members()
#endif

/* XLATON */

#define BOOT_BPB_BYTES_PER_SEC_OFF  8     /* BytesPerSec offset from BPB     */
#define BOOT_BPB_OFFSET             3     /* skip the 3 byte JMP instruction */
                                          /* from the start of boot record   */
/* XLATOFF */

/*---------------------------------------------------*/
/*                                                   */
/*                                                   */
/*---------------------------------------------------*/

/**
 ** Note: Pad these structures to 8-byte boundaries as required!
 **/


typedef struct _PGHEADER  *PPGHEADER;

typedef struct _BUFHEADER *PBUFHEADER;

typedef struct _BUFHEADER
{

   PBUFHEADER               pNext;
   ULONG                    Size;

} BUFHEADER;

typedef struct _PGHEADER
{

   PPGHEADER                pNext;
   ULONG                    cAllocations;
   ULONG                    PhysAddr;

   ULONG                    MaxSize;
   ULONG                    Reserved;

   PBUFHEADER               pBUFChain;

} PGHEADER;

#define MIN_BUF_SIZE 16
#define PAGESIZE        (4*1024L)

/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/

/* XLATON */

#ifndef _PPC

/* ASM
PVOID struc
dd ?
PVOID ends
*/

#define ES_DI 1
#define ES_BX 2
#define ES_BP 3

struct _reg_byte {
  UCHAR  b_al;
  UCHAR  b_ah;
  USHORT b_pad1;
  UCHAR  b_bl;
  UCHAR  b_bh;
  USHORT b_pad2;
  UCHAR  b_cl;
  UCHAR  b_ch;
  USHORT b_pad3;
  UCHAR  b_dl;
  UCHAR  b_dh;
  USHORT b_pad4;
  PVOID  b_pbuf;
  ULONG  b_pbuf_t;
};

struct _reg_word {
  USHORT w_ax;
  USHORT w_pad1;
  USHORT w_bx;
  USHORT w_pad2;
  USHORT w_cx;
  USHORT w_pad3;
  USHORT w_dx;
  USHORT w_pad4;
  PVOID  w_pbuf;
  ULONG  w_pbuf_t;
};

struct _reg_dword {
  ULONG  d_eax;
  ULONG  d_ebx;
  ULONG  d_ecx;
  ULONG  d_edx;
  PVOID  d_pbuf;
  ULONG  d_pbuf_t;
};

union _reg_u {
   struct _reg_byte  reg_byte;
   struct _reg_word  reg_word;
   struct _reg_dword reg_dword;
};

typedef struct reg_s {
   union _reg_u reg_u;
} REGS;

typedef struct reg_s *PREGS;

#define reg_al     reg_u.reg_byte.b_al
#define reg_ah     reg_u.reg_byte.b_ah
#define reg_ax     reg_u.reg_word.w_ax
#define reg_eax    reg_u.reg_dword.d_eax

#define reg_bl     reg_u.reg_byte.b_bl
#define reg_bh     reg_u.reg_byte.b_bh
#define reg_bx     reg_u.reg_word.w_bx
#define reg_ebx    reg_u.reg_dword.d_ebx

#define reg_cl     reg_u.reg_byte.b_cl
#define reg_ch     reg_u.reg_byte.b_ch
#define reg_cx     reg_u.reg_word.w_cx
#define reg_ecx    reg_u.reg_dword.d_ecx

#define reg_dl     reg_u.reg_byte.b_dl
#define reg_dh     reg_u.reg_byte.b_dh
#define reg_dx     reg_u.reg_word.w_dx
#define reg_edx    reg_u.reg_dword.d_edx

#define reg_pbuf   reg_u.reg_dword.d_pbuf
#define reg_pbuf_t reg_u.reg_dword.d_pbuf_t

#endif

/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/

typedef struct _BOOTSUFFIX *PBOOTSUFFIX;

typedef struct _BOOTSUFFIX
{
  ULONG         BootRecRBA;
  USHORT        BootStrapLen;
  USHORT        BootStrapID;

} BOOTSUFFIX;

/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/

typedef struct _BOOTEXTENTS  *PBOOTEXTENTS;

typedef struct _BOOTEXTENTS
{
  ULONG         ExtentRBA;
  ULONG         ExtentSec;

} BOOTEXTENTS;

/* ASM
BOOTEXTENTS EQU _BOOTEXTENTS
*/

#define MAX_BOOT_EXTENTS ((512-140) / sizeof(BOOTEXTENTS))

/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/

typedef struct _BOOTRECHDR *PBOOTRECHDR;

typedef struct _BOOTRECHDR
{
  UCHAR         BootPath[128];

  ULONG         ImageBaseAddr;
  ULONG         ImageEntry;
  ULONG         ImageChksum;

  ULONG         cExtents;
  BOOTEXTENTS   Extents[MAX_BOOT_EXTENTS];

} BOOTRECHDR;

#pragma pack()

/* XLATOFF */

/*--------------------------*/
/*                          */
/*                          */
/*--------------------------*/

#ifdef _PPC

#define BE_L(w) ( (((PUCHAR) &w)[0] << 24 ) | \
                  (((PUCHAR) &w)[1] << 16 ) | \
                  (((PUCHAR) &w)[2] <<  8 ) | \
                  (((PUCHAR) &w)[3]       )      )

#endif

/* XLATON */
