/*
 * This file forms part of PFS (Professional File System)
 * Copyright 1993-1995 Michiel Pelt and distributed by
 * Fourth Level Developments.
 *
 * PFS header file
 *
 */

#ifndef _PFS_H
#define _PFS_H 1

struct bootblock
{
    LONG disktype;          /* PFS\1                            */
    UBYTE reserved[508];
};

typedef struct rootblock
{
    LONG disktype;
    ULONG options;          /* bit 0 is harddisk mode           */
    ULONG reserved_1;
    UWORD creationday;      /* days since Jan. 1, 1978 (like ADOS; WORD instead of LONG) */
    UWORD creationminute;   /* minutes past modnight            */
    UWORD creationtick;     /* ticks past minute                */
    UWORD protection;       /* protection bits (ala ADOS)       */
    UBYTE diskname[32];     /* disk label (pascal string)       */
    ULONG lastreserved;     /* reserved area. blocknumbers      */
    ULONG firstreserved;
    ULONG reserved_free;    /* number of reserved blocks (blksize blocks) free  */
    UWORD blksize;          /* size of reserved blocks in bytes */
    UWORD rblkcluster;      /* number of blocks in rootblock, including bitmap  */
    ULONG blocksfree;       /* blocks free                      */
    ULONG alwaysfree;       /* minimum number of blocks free    */
    ULONG roving_ptr;       /* current LONG bitmapfield nr for allocation       */
    ULONG reserved_3[4];
    ULONG bitmapindex[5];   /* 5 bitmap indexblocks             */
    ULONG indexblocks[99];  /* 99 indexblocks                   */
} rootblock_t;


/* structure for both normal as reserved bitmap
 * normal: normal clustersize
 * reserved: directly behind rootblock. As long as necessary
 */
typedef struct bitmapblock
{
    UWORD id;               /* BM (bitmap block)                */
    UWORD reserved_1;
    ULONG reserved;
    ULONG seqnr;
    ULONG bitmap[253];      /* the bitmap.                      */
} bitmapblock_t;

typedef struct indexblock
{
    UWORD id;               /* AI or BI (anode- bitmap index)   */
    UWORD reserved[3];
    ULONG seqnr;
    LONG index[253];        /* the indices                      */
} indexblock_t;

typedef struct anode
{
    ULONG clustersize;
    ULONG blocknr;
    ULONG next;
} anode_t;

typedef struct anodeblock
{
    UWORD id;               /* AB                               */
    UWORD reserved_1[3];
    ULONG seqnr;
    ULONG reserved_2;
    struct anode nodes[84];
} anodeblock_t;

struct dirblock 
{
    UWORD id;               /* 'DB'                             */
    UWORD reserved[5];
    ULONG anodenr;          /* anodenr belonging to this directory (points to FIRST block of dir) */
    ULONG parent;           /* parent                           */
    UBYTE entries[0];       /* entries                          */
};

struct direntry
{
    UBYTE next;             /* sizeof direntry                  */
    BYTE  type;             /* dir, file, link etc              */
    ULONG anode;            /* anode nummer                     */
    ULONG size;             /* sizeof file                      */
    UWORD creationday;      /* days since Jan. 1, 1978 (like ADOS; WORD instead of LONG) */
    UWORD creationminute;   /* minutes past modnight            */
    UWORD creationtick;     /* ticks past minute                */
    UBYTE protection;       /* protection bits (like DOS)       */
    UBYTE nlength;          /* lenght of filename               */
    UBYTE startofname;      /* filename, followed by filenote length & filenote */
    UBYTE pad;              /* make size even                   */
};


/* max length of filename, diskname and comment */
#define FNSIZE 108
#define DNSIZE 32
#define CMSIZE 80

/* disk id 'PFS\1'  */
#define ID_PFS_DISK     (0x50465301L)

/* block id's		*/
#define DBLKID 0x4442
#define ABLKID 0x4142
#define IBLKID 0x4942
#define BMBLKID 0x424D
#define BMIBLKID 0x4D49
#define SIZEOF_RESBLOCK 1024

/* predefined anodes */
#define ANODE_EOF           0
#define ANODE_BADBLOCKS     4
#define ANODE_ROOTDIR       5
#define ANODE_USERFIRST     6

/* get filenote from directory entry */
#define FILENOTE(de) ((UBYTE*)(&((de)->startofname) + (de)->nlength))

/* get next directory entry */
#define NEXTENTRY(de) ((struct direntry*)((UBYTE*)(de) + (de)->next))

#endif
