home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <stddef.h>
- #include <string.h>
-
- typedef unsigned char byte;
- typedef unsigned int word;
- typedef unsigned long dword;
-
- #pragma pack(1) /* for OS structures, pack on byte boundaries (i.e. not at all)
- */
-
- typedef struct part_rec { /* one partition's data */
- byte boot_ind, /* 0x80 if this is the bootable one, else 0 */
- s_head; /* starting head */
- word s_sec_cyl; /* somewhat screwy combo of sector and cylinder */
- byte sys_ind, /* which OS */
- e_head; /* ending locations */
- word e_sec_cyl;
- dword rel_sect, /* number of sectors BEFORE this partition */
- num_sects; /* number of sectors in this partition */
- } PARTITION;
-
- /* a partition pictorially: 0 begin |boot ind |head | S | CYL |
- * 4 end |syst ind |head | S | CYL |
- * 8 rel sect | low word | high word |
- * C num sect | low word | high word |
- * to quote from the PC-DOS Technical Reference Manual (p. G-2) on the setup
- * of the two byte long combined sector and cylinder number:
- * The 1-byte fields labelled "CYL" contain the low-order 8 bits of
- * the cylinder number -- the high order 2 bits are in the high order
- * 2 bits of the "S" (sector) field. This corresponds with the ROM
- * BIOS Interrupt hex 13 (disk I/O) requirement, to allow for a 10 bit
- * cylinder number.
- * Programmer's note: whoever wrote the BIOS this way is a sick puppy.
- */
-
- /* These macros descramble the above structure. Note that get/put_cyl is only
- * guaranteed to work if the argument is a word (i.e. unsigned int).
- */
-
- #define put_sec_cyl(sec,cyl) ((sec & 0x3f) | (cyl << 8) | ((cyl & 0x300) >> 2))
- #define get_sec(x) (x & 0x3f)
- #define get_cyl(x) ((x >> 8) | ((x<<2) & 0x300))
-
- typedef struct {
- word bytes_per_sec; /* number of bytes per sector */
- byte secs_per_au; /* sectors per allocation unit */
- word res_sectors; /* reserved sectors */
- byte nfats; /* number of FATS */
- word nroot_ents, /* max number of root directory entries */
- nsectors; /* sectors in logical image */
- byte media_des; /* media descriptor */
- word secs_in_fat; /* number of FAT sectors */
- } BPB;
-
- typedef struct {
- char boot_jump[3],
- oem_name[8];
- BPB bpb;
- word secs_per_track, /* sector per track */
- nheads, /* number of heads */
- nhidden; /* number of hidden sectors */
- char boot_code[0x1a0]; /* magic */
- PARTITION ptable[4];
- word signature; /* should = 0xaa55 */
- } BOOT;
-
- typedef struct { /* BIOS-maintained fixed disk parameter table entry.
- * INT 0x41 (or 46 for drive 2) points to a descriptor
- * table for the current fixed drive. See BIOS listing
- */
- word fd_ncyls; /* number of cylinders on drive */
- char fd_heads; /* number of heads on drive */
- word fd_current; /* starting cyl for reduced write current (XT only) */
- word fd_write_precomp; /* starting cylinder for write pre-compensation
- * or -1 if no write precompensation needed.
- */
- byte fd_ecc_burst, /* max ecc data burst length (XT only) */
- fd_control, /* see below */
- fd_std_time, /* standard time out value (XT only) */
- fd_format_time, /* time out for format drive (XT only) */
- fd_check_time; /* time out for check drive (XT only) */
- word fd_lz; /* landing zone */
- char fd_sec_per_track; /* # of sectors per track */
- char fd_reserved; /* reserved for future use */
- } DISK_TABLE;
-
- #pragma pack(2) /* revert back to "normal" int boundary packing */
-
- /* defines for control byte in above fixed disk table structure:
- * note that for AT, 0x80 does the same as 0x40 and only bits 2, 6 and 7
- * are valid.
- */
- #define FD_DISABLE_RETRIES 0x80 /* bit 7: disable disk access retries */
- #define FD_DISABLE_RETRIES2 0x40 /* bit 6: disable ecc retries (XT only) */
- #define FD_MORE_THAN_8_HEADS 0x04
-
- typedef struct { /* decoded partition stuff */
- byte sys_ind;
- word s_cylinder, e_cylinder;
- } PARTDATA;
-
- void pr_head(void),
- pr_part(int, PARTITION *),
- boot_transfer(word, word),
- erase_eol(word),
- erase_eos(word),
- sleep(long),
- message(char *); /* print message and wait a sec */
-
- int get_scr_char(int, char *, char, char);
-
- /* The following are hard-wired by DOS.
- * They are included mostly for ease of reading.
- *
- * IMPORTANT: "SIGNATURE" must NOT be 1 or 4. These are * recognized by PC-DOS as valid DOS partitions and will, therefore,
- * screw up a normal boot.
- */
- #define XENIX_PART 3 /* tells device driver that this is a XENIX partition */
- #define DOS_PART 4 /* tells device driver that this is a DOS partition */
- #define XDOS_PART 5 /* an "extended DOS" partition */
- #define EDOS_PART 6 /* our "special DOS" partition */
-
- #define DISK0 0x80 /* first drive on PC controller */
- #define DISK1 0x81 /* second drive */
-
- #define READ 2
- #define WRITE 3
- extern int get_scr_val(int start,char *m_str,int def_val,int low_lim,int high_lim);
- extern int get_scr_char(int start,char *m_str,char low_lim,char high_lim);
- extern void message(char *str);
- extern void pr_head(void );
- extern void pr_part(int part_no,struct part_rec *part);
- extern void erase_eos(unsigned int from);
- extern void erase_eol(unsigned int from);
- extern void scr_scroll(unsigned, unsigned, unsigned, unsigned, unsigned, unsigned);
- extern void scr_pos(unsigned row, unsigned col),
- scr_sapage(unsigned),
- scr_smode(unsigned);
- extern int scr_rpos(void),
- scr_gapage(void),
- scr_gmode(void);
- extern void init(void);
- extern void clean_quit(void );
- extern int make_fat(int partno,int fat_size,unsigned int secs_in_rdir);
- extern int make_rdir(int partno);
- extern int main(int argc, char **argv);
- extern void add_part(void );
- extern void del_part(void );
- extern void mod_part(void );
- extern void change_parms(void);
-