home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / RAMDISK / SRDSK141.ZIP / SRDISK.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-06  |  7.2 KB  |  191 lines

  1. /* ReSizeable RAMDisk - srdisk header file
  2. ** Copyright (c) 1992 Marko Kohtala
  3. */
  4.  
  5. #ifndef _SRDISK_H
  6. #define _SRDISK_H
  7.  
  8. /* Byte aligned compilation is a must */
  9. #pragma option -a-
  10. #pragma pack(1)
  11.  
  12. #define VERSION "1.41"
  13.  
  14. #define MAX_CHAINED_DRIVERS 5
  15.  
  16. #include <stdlib.h>
  17. #include <time.h>       /* Only for DOS_time declaration */
  18.  
  19. typedef unsigned char byte;
  20. typedef unsigned short word;
  21. typedef unsigned long dword;
  22.  
  23. #define MULTIPLEXAH 0x72
  24. #define V_FORMAT 0      /* config_s structure format version used here */
  25.  
  26. #define C_APPENDED  1   /* Capable of having appended drivers */
  27. #define C_MULTIPLE  2   /* Capable of driving many disks */
  28. #define C_32BITSEC  4   /* Capable of handling over 32-bit sector addresses */
  29. #define C_NOALLOC   8   /* Incapable of allocating it's owm memory */
  30. #define C_UNKNOWN 0xF0
  31.  
  32. #define READ_ACCESS  1  /* Bit masks for RW_access in IOCTL_msg_s */
  33. #define WRITE_ACCESS 2
  34.  
  35.  
  36. /* Configuration structure internal to device driver (byte aligned) */
  37. struct dev_hdr {
  38.   struct dev_hdr far *next;
  39.   word attr;
  40.   word strategy;
  41.   word commands;
  42.   byte units;
  43.   union {
  44.     char volume[12];            /* Volume label combined of fields below */
  45.     struct {
  46.       char ID[3];               /* Identification string 'SRD' */
  47.       char memory[4];           /* Memory type string */
  48.       char version[4];          /* Device driver version string */
  49.       char null;
  50.     } s;
  51.   } u;
  52.   byte v_format;                /* Config_s format version */
  53.   struct config_s near *conf;   /* Offset to config_s */
  54. };
  55.  
  56. struct config_s {               /* The whole structure */
  57.   byte drive;                   /* Drive letter of this driver */
  58.   byte flags;                   /* Capability flags */
  59.   word (far *disk_IO)(void);    /* Disk I/O routine entry */
  60.   dword (near *malloc_off)(dword _s); /* Memory allocation routine entry offset */
  61.   struct dev_hdr _seg *next;    /* Next chained driver */
  62.   dword maxK;                   /* Maximum memory allowed for disk */
  63.   dword size;                   /* Current size in Kbytes */
  64.   dword sectors;                /* Total sectors in this part of the disk */
  65.  
  66.   word BPB_bps;                 /* BPB - bytes per sector */
  67.   /* The rest is removed from chained drivers, used only in the main driver */
  68.   byte BPB_spc;                 /* BPB - sectors per cluster */
  69.   word BPB_reserved;            /* BPB - reserved sectors in the beginning */
  70.   byte BPB_FATs;                /* BPB - number of FATs on disk */
  71.   word BPB_dir;                 /* BPB - root directory entries */
  72.   word BPB_sectors;             /* BPB - sectors on disk (16-bit) */
  73.   byte BPB_media;               /* BPB - identifies the media (default 0xFA) */
  74.   word BPB_FATsectors;          /* BPB - sectors per FAT */
  75.   word BPB_spt;                 /* BPB - sectors per track (imaginary) */
  76.   word BPB_heads;               /* BPB - heads (imaginary) */
  77.   dword BPB_hidden;             /* BPB - hidden sectors */
  78.   dword BPB_tsectors;           /* BPB - sectors on disk (32-bit) */
  79.  
  80.   dword tsize;                  /* Total size for the disk */
  81.  
  82.   byte RW_access;               /* b0 = enable, b1 = write */
  83.   signed char media_change;     /* -1 if media changed, 1 if not */
  84.   word open_files;              /* Number of open files on disk */
  85.   struct dev_hdr _seg *next_drive;/* Next SRDISK drive */
  86. };
  87.  
  88. extern struct config_s far *mainconf;
  89. extern struct config_s far *conf;
  90.  
  91. #define WRITE_PROTECTION 1
  92. #define DISK_SIZE 2
  93. #define SECTOR_SIZE 4
  94. #define CLUSTER_SIZE 8
  95. #define DIR_ENTRIES 0x10
  96. #define NO_OF_FATS 0x20
  97. #define MAX_PART_SIZES 0x40
  98. #define MEDIA 0x80
  99. #define SEC_PER_TRACK 0x100
  100. #define SIDES 0x200
  101.  
  102. /* format_f tells if a real reformat really needed */
  103. #define format_f (changed_format & ( DISK_SIZE | SECTOR_SIZE \
  104.   | CLUSTER_SIZE | DIR_ENTRIES | NO_OF_FATS | MAX_PART_SIZES | MEDIA \
  105.   | SEC_PER_TRACK | SIDES))
  106.  
  107. struct format_s {                 /* Disk format/configuration description */
  108.   /* User defined parameters */
  109.   byte RW_access;               /* Read/write access flags */
  110.   dword size;                   /* Defined current size */
  111.   int bps;                      /* Bytes per sector */
  112.   int cluster_size;             /* Size of one cluster in bytes */
  113.   int FATs;                     /* Number of FAT copies */
  114.   int dir_entries;              /* Directory entries in the root directory */
  115.   byte media;                   /* Media */
  116.   int sec_per_track;            /* Sectors per track */
  117.   int sides;                    /* Sides on disk */
  118.   struct subconf_s {            /* List of the drivers chained to this disk */
  119.     dword maxK;                 /* The maximum size of this part */
  120.     int userdef:1;              /* True if used defined new max size */
  121.   } subconf[MAX_CHAINED_DRIVERS];
  122.   /* Derived parameters */
  123.   int chain_len;                /* Number of drivers chained to this drive */
  124.   dword max_size;               /* Largest possible disk size (truth may be less) */
  125.   dword current_size;           /* Counted current size from the driver chain */
  126.   int reserved;                 /* Reserved sectors in the beginning (boot) */
  127.   int spFAT;                    /* Sectors per FAT */
  128.   dword sectors;                /* Total sectors on drive */
  129.   int FAT_sectors;              /* Total FAT sectors */
  130.   int dir_sectors;              /* Directory sectors */
  131.   int dir_start;                /* First root directory sector */
  132.   int system_sectors;           /* Boot, FAT and root dir sectors combined */
  133.   long data_sectors;            /* Total number of usable data sectors */
  134.   int spc;                      /* Sectors per cluster */
  135.   dword clusters;               /* Total number of clusters */
  136.   int FAT_type;                 /* Number of bits in one FAT entry (12 or 16) */
  137. };
  138.  
  139. extern struct format_s f, newf;
  140. extern int changed_format;
  141.  
  142. extern int root_files;  /* Number of files in root directory */
  143.  
  144. /* Variables possibly supplied in command line */
  145. extern char drive;          /* Drive letter of drive to format */
  146. extern int force_f;         /* Nonzero if ok to format */
  147. extern int use_old_format_f; /* Take undefined parameters from the old format */
  148. extern int f_set_env;       /* Set environment variables */
  149. extern int verbose;   /* Verbose: 1 banner, */
  150.                       /* 2 + new format, 3 + old format, 4 + long format */
  151.  
  152. /*
  153. **  Declarations
  154. */
  155.  
  156. extern int max_bps;     /* Maximum sector size allowed on system */
  157.  
  158. void parse_cmdline(int, char *[]);
  159. void print_syntax(void);
  160.  
  161. /*  Error handling functions */
  162. void syntax(char *err);
  163. void fatal(char *err);
  164. void error(char *err);
  165. void warning(char *err);
  166.  
  167. /* Utility */
  168. void *xalloc(size_t s);
  169. struct config_s far *conf_ptr(struct dev_hdr _seg *dev);
  170. int getYN(void);
  171. dword DOS_time(time_t);
  172.  
  173. /* Environment */
  174. void set_env(void);
  175.  
  176. /* disk I/O module */
  177. int read_sector(int count, dword start, void *buffer);
  178. int write_sector(int count, dword start, void *buffer);
  179. dword disk_alloc(struct config_s far *conf, dword size);
  180.  
  181. /* Disk Initialization module */
  182. void init_drive(void);
  183.  
  184. /* Format module */
  185. void format_disk(void);
  186. void print_format(struct format_s *);
  187. char *stringisize_flags(int flags);
  188.  
  189. #endif
  190.  
  191.