home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / CMDS / mtools_3.6.src.lzh / MTOOLS_3.6 / msdos.h < prev    next >
Text File  |  1997-11-12  |  7KB  |  224 lines

  1. #ifndef MTOOLS_MSDOS_H
  2. #define MTOOLS_MSDOS_H
  3.  
  4. /*
  5.  * msdos common header file
  6.  */
  7.  
  8. #define MAX_SECTOR    8192           /* largest sector size */
  9. #define MDIR_SIZE    32        /* MSDOS directory entry size in bytes*/
  10. #define MAX_CLUSTER    8192        /* largest cluster size */
  11. #define MAX_PATH    128        /* largest MSDOS path length */
  12. #define MAX_DIR_SECS    64        /* largest directory (in sectors) */
  13. #define MSECTOR_SIZE    msector_size
  14.  
  15. #define NEW        1
  16. #define OLD        0
  17.  
  18. #define _WORD(x) ((unsigned char)(x)[0] + (((unsigned char)(x)[1]) << 8))
  19. #define _DWORD(x) (_WORD(x) + (_WORD((x)+2) << 16))
  20.  
  21. #define DELMARK ((char) 0xe5)
  22.  
  23. struct directory {
  24.     char name[8];            /* file name */
  25.     char ext[3];            /* file extension */
  26.     unsigned char attr;        /* attribute byte */
  27.     unsigned char Case;        /* case of short filename */
  28.     unsigned char ctime_ms;        /* creation time, milliseconds (?) */
  29.     unsigned char ctime[2];        /* creation time */
  30.     unsigned char cdate[2];        /* creation date */
  31.     unsigned char adate[2];        /* last access date */
  32.     unsigned char startHi[2];    /* start cluster, Hi */
  33.     unsigned char time[2];        /* time stamp */
  34.     unsigned char date[2];        /* date stamp */
  35.     unsigned char start[2];        /* starting cluster number */
  36.     unsigned char size[4];        /* size of the file */
  37. };
  38.  
  39. #define EXTCASE 0x10
  40. #define BASECASE 0x8
  41.  
  42. #define MAX32 0xffffffff
  43. #define MAX_SIZE 0x7fffffff
  44.  
  45. #define FILE_SIZE(dir)  (_DWORD((dir)->size))
  46. #define START(dir) (_WORD((dir)->start))
  47. #define STARTHI(dir) (_WORD((dir)->startHi))
  48.  
  49. /* ASSUMPTION: long is at least 32 bits */
  50. UNUSED(static inline void set_dword(unsigned char *data, unsigned long value))
  51. {
  52.     data[3] = (value >> 24) & 0xff;
  53.     data[2] = (value >> 16) & 0xff;
  54.     data[1] = (value >>  8) & 0xff;
  55.     data[0] = (value >>  0) & 0xff;
  56. }
  57.  
  58.  
  59. /* ASSUMPTION: short is at least 16 bits */
  60. UNUSED(static inline void set_word(unsigned char *data, unsigned short value))
  61. {
  62.     data[1] = (value >>  8) & 0xff;
  63.     data[0] = (value >>  0) & 0xff;
  64. }
  65.  
  66.  
  67. /*
  68.  *        hi byte     |    low byte
  69.  *    |7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
  70.  *      | | | | | | | | | | | | | | | | |
  71.  *      \   7 bits    /\4 bits/\ 5 bits /
  72.  *         year +80      month     day
  73.  */
  74. #define    DOS_YEAR(dir) (((dir)->date[1] >> 1) + 1980)
  75. #define    DOS_MONTH(dir) (((((dir)->date[1]&0x1) << 3) + ((dir)->date[0] >> 5)))
  76. #define    DOS_DAY(dir) ((dir)->date[0] & 0x1f)
  77.  
  78. /*
  79.  *        hi byte     |    low byte
  80.  *    |7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
  81.  *      | | | | | | | | | | | | | | | | |
  82.  *      \  5 bits /\  6 bits  /\ 5 bits /
  83.  *         hour      minutes     sec*2
  84.  */
  85. #define    DOS_HOUR(dir) ((dir)->time[1] >> 3)
  86. #define    DOS_MINUTE(dir) (((((dir)->time[1]&0x7) << 3) + ((dir)->time[0] >> 5)))
  87. #define    DOS_SEC(dir) (((dir)->time[0] & 0x1f) * 2)
  88.  
  89.  
  90. typedef struct InfoSector_t {
  91.     unsigned char signature[4];
  92.     unsigned char count[4];
  93.     unsigned char pos[4];
  94. } InfoSector_t;
  95.  
  96. #define INFOSECT_SIGNATURE 0x61417272
  97.  
  98.  
  99. /* FAT32 specific info in the bootsector */
  100. typedef struct fat32_t {
  101.     unsigned char bigFat[4];    /* 36 nb of sectors per FAT */
  102.     unsigned char extFlags[2];         /* 40 extension flags */
  103.     unsigned char fsVersion[2];    /* 42 ? */
  104.     unsigned char rootCluster[4];    /* 44 start cluster of root dir */
  105.     unsigned char infoSector[2];    /* 48 changeable global info */
  106.     unsigned char backupBoot[2];    /* 50 back up boot sector */
  107.     unsigned char reserved[6];    /* 52 ? */
  108. } fat32; /* ends at 58 */
  109.  
  110. typedef struct oldboot_t {
  111.     unsigned char physdrive;    /* 36 physical drive ? */
  112.     unsigned char reserved;        /* 37 reserved */
  113.     unsigned char dos4;        /* 38 dos > 4.0 diskette */
  114.     unsigned char serial[4];           /* 39 serial number */
  115.     char label[11];            /* 43 disk label */
  116.     char fat_type[8];        /* 54 FAT type */
  117.             
  118.     unsigned char res_2m;        /* 62 reserved by 2M */
  119.     unsigned char CheckSum;        /* 63 2M checksum (not used) */
  120.     unsigned char fmt_2mf;        /* 64 2MF format version */
  121.     unsigned char wt;        /* 65 1 if write track after format */
  122.     unsigned char rate_0;        /* 66 data transfer rate on track 0 */
  123.     unsigned char rate_any;        /* 67 data transfer rate on track<>0 */
  124.     unsigned char BootP[2];        /* 68 offset to boot program */
  125.     unsigned char Infp0[2];        /* 70 T1: information for track 0 */
  126.     unsigned char InfpX[2];        /* 72 T2: information for track<>0 */
  127.     unsigned char InfTm[2];        /* 74 T3: track sectors size table */
  128.     unsigned char DateF[2];        /* 76 Format date */
  129.     unsigned char TimeF[2];        /* 78 Format time */
  130.     unsigned char junk[512 - 80];    /* 80 remaining data */
  131. } oldboot_t;
  132.  
  133. struct bootsector {
  134.     unsigned char jump[3];        /* 0  Jump to boot code */
  135.     char banner[8] PACKED;               /* 3  OEM name & version */
  136.     unsigned char secsiz[2] PACKED;    /* 11 Bytes per sector hopefully 512 */
  137.     unsigned char clsiz;        /* 13 Cluster size in sectors */
  138.     unsigned char nrsvsect[2];    /* 14 Number of reserved (boot) sectors */
  139.     unsigned char nfat;        /* 16 Number of FAT tables hopefully 2 */
  140.     unsigned char dirents[2] PACKED;/* 17 Number of directory slots */
  141.     unsigned char psect[2] PACKED;     /* 19 Total sectors on disk */
  142.     unsigned char descr;        /* 21 Media descriptor=first byte of FAT */
  143.     unsigned char fatlen[2];    /* 22 Sectors in FAT */
  144.     unsigned char nsect[2];        /* 24 Sectors/track */
  145.     unsigned char nheads[2];    /* 26 Heads */
  146.     unsigned char nhs[4];        /* 28 number of hidden sectors */
  147.     unsigned char bigsect[4];    /* 32 big total sectors */
  148.  
  149.     union {
  150.         struct fat32_t fat32;
  151.         struct oldboot_t old;
  152.     } ext;
  153. };
  154.  
  155. #define CHAR(x) (boot->x[0])
  156. #define WORD(x) (_WORD(boot->x))
  157. #define DWORD(x) (_DWORD(boot->x))
  158. #define OFFSET(x) (((char *) (boot->x)) - ((char *)(boot->jump)))
  159.  
  160.  
  161. extern struct OldDos_t {
  162.     int tracks;
  163.     int sectors;
  164.     int heads;
  165.     
  166.     int dir_len;
  167.     int cluster_size;
  168.     int fat_len;
  169.  
  170.     int media;
  171. } old_dos[];
  172.  
  173. #define FAT12 4085 /* max. number of clusters described by a 12 bit FAT */
  174. #define FAT16 65525
  175.  
  176. #define NEEDED_FAT_SIZE(x) ((((x)->num_clus+2) * ((x)->fat_bits/4) -1 )/ 2 / (x)->sector_size + 1)
  177.  
  178. #define MAX_FAT12_FATLEN(sec_siz) (2*((FAT12+2)*3+(2*sec_siz)-1)/(sec_siz)/2)
  179. #define MAX_FAT16_FATLEN(sec_siz) (2*((FAT16+2)*2+(sec_siz)-1)/(sec_siz))
  180. /* The maximal fat length (both fats) for a given drive is the number
  181.  * of slots times the size of one slot divided by the size of a sector */
  182.  
  183. #define MAX_FAT12_SIZE(sec_siz) (64 * FAT12 + MAX_FAT12_FATLEN(sec_siz) + 2)
  184. #define MAX_FAT16_SIZE(sec_siz) (64 * FAT16 + MAX_FAT16_FATLEN(sec_siz) + 2)
  185. /* the maximal size of a drive for a given fat size is FATn clusters
  186.  * of max 64* sectors each, plus the two fats plus a boot sector and
  187.  * at least one dir sector.  This doesn't give an absolute maximum,
  188.  * but a very close approximation.
  189.  * Experimentally, it turns out that DOS only wants powers of two, and 
  190.  * less than 128 (else it gets a divide overflow) */
  191.  
  192.  
  193. #define MIN_FAT16_SIZE(sec_siz) (FAT12+MAX_FAT12_FATLEN(sec_siz)+2)
  194. /* minimal size for which a 16 bit FAT makes sense.  With less
  195.  * sectors, the drive could be set up as a FAT12 drive with 1 sector
  196.  * clusters. 16 bit would only be a waste of space */
  197.  
  198. extern const char *mversion;
  199. extern const char *mdate;
  200.  
  201. /*
  202.  * Function Prototypes */
  203.  
  204. int ask_confirmation(const char *, const char *, const char *);
  205. char *get_homedir(void);
  206. #define EXPAND_BUF 2048
  207. const char *expand(const char *, char *);
  208. const char *fix_mcwd(char *);
  209. FILE *open_mcwd(const char *mode);
  210.  
  211. char *get_name(const char *, char *, char *mcwd);
  212. char *get_path(const char *, char *, char *mcwd, int mode);
  213. char get_drive(const char *, char);
  214.  
  215. int init(char drive, int mode);
  216.  
  217.  
  218.  
  219. #define MT_READ 1
  220. #define MT_WRITE 2
  221.  
  222. #endif
  223.  
  224.