00001 #ifndef MTOOLS_MSDOS_H
00002 #define MTOOLS_MSDOS_H
00003
00004
00005
00006
00007
00008 #define MAX_SECTOR 8192
00009 #define MDIR_SIZE 32
00010 #define MAX_CLUSTER 8192
00011 #define MAX_PATH 128
00012 #define MAX_DIR_SECS 64
00013 #define MSECTOR_SIZE msector_size
00014
00015 #define NEW 1
00016 #define OLD 0
00017
00018 #define _WORD(x) ((unsigned char)(x)[0] + (((unsigned char)(x)[1]) << 8))
00019 #define _DWORD(x) (_WORD(x) + (_WORD((x)+2) << 16))
00020
00021 #define DELMARK ((char) 0xe5)
00022
00023 struct directory {
00024 char name[8];
00025 char ext[3];
00026 unsigned char attr;
00027 unsigned char Case;
00028 unsigned char ctime_ms;
00029 unsigned char ctime[2];
00030 unsigned char cdate[2];
00031 unsigned char adate[2];
00032 unsigned char startHi[2];
00033 unsigned char time[2];
00034 unsigned char date[2];
00035 unsigned char start[2];
00036 unsigned char size[4];
00037 };
00038
00039 #define EXTCASE 0x10
00040 #define BASECASE 0x8
00041
00042 #define MAX32 0xffffffff
00043 #define MAX_SIZE 0x7fffffff
00044
00045 #define FILE_SIZE(dir) (_DWORD((dir)->size))
00046 #define START(dir) (_WORD((dir)->start))
00047 #define STARTHI(dir) (_WORD((dir)->startHi))
00048
00049
00050 UNUSED(static inline void set_dword(unsigned char *data, unsigned long value))
00051 {
00052 data[3] = (value >> 24) & 0xff;
00053 data[2] = (value >> 16) & 0xff;
00054 data[1] = (value >> 8) & 0xff;
00055 data[0] = (value >> 0) & 0xff;
00056 }
00057
00058
00059
00060 UNUSED(static inline void set_word(unsigned char *data, unsigned short value))
00061 {
00062 data[1] = (value >> 8) & 0xff;
00063 data[0] = (value >> 0) & 0xff;
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 #define DOS_YEAR(dir) (((dir)->date[1] >> 1) + 1980)
00075 #define DOS_MONTH(dir) (((((dir)->date[1]&0x1) << 3) + ((dir)->date[0] >> 5)))
00076 #define DOS_DAY(dir) ((dir)->date[0] & 0x1f)
00077
00078
00079
00080
00081
00082
00083
00084
00085 #define DOS_HOUR(dir) ((dir)->time[1] >> 3)
00086 #define DOS_MINUTE(dir) (((((dir)->time[1]&0x7) << 3) + ((dir)->time[0] >> 5)))
00087 #define DOS_SEC(dir) (((dir)->time[0] & 0x1f) * 2)
00088
00089
00090 typedef struct InfoSector_t {
00091 unsigned char signature1[4];
00092 unsigned char filler1[0x1e0];
00093 unsigned char signature2[4];
00094 unsigned char count[4];
00095 unsigned char pos[4];
00096 unsigned char filler2[14];
00097 unsigned char signature3[2];
00098 } InfoSector_t;
00099
00100 #define INFOSECT_SIGNATURE1 0x41615252
00101 #define INFOSECT_SIGNATURE2 0x61417272
00102
00103
00104 typedef struct label_blk_t {
00105 unsigned char physdrive;
00106 unsigned char reserved;
00107 unsigned char dos4;
00108 unsigned char serial[4];
00109 char label[11];
00110 char fat_type[8];
00111 } label_blk_t;
00112
00113
00114 typedef struct fat32_t {
00115 unsigned char bigFat[4];
00116 unsigned char extFlags[2];
00117 unsigned char fsVersion[2];
00118 unsigned char rootCluster[4];
00119 unsigned char infoSector[2];
00120 unsigned char backupBoot[2];
00121 unsigned char reserved[6];
00122 unsigned char reserved2[6];
00123 struct label_blk_t labelBlock;
00124 } fat32;
00125
00126 typedef struct oldboot_t {
00127 struct label_blk_t labelBlock;
00128 unsigned char res_2m;
00129 unsigned char CheckSum;
00130 unsigned char fmt_2mf;
00131 unsigned char wt;
00132 unsigned char rate_0;
00133 unsigned char rate_any;
00134 unsigned char BootP[2];
00135 unsigned char Infp0[2];
00136 unsigned char InfpX[2];
00137 unsigned char InfTm[2];
00138 unsigned char DateF[2];
00139 unsigned char TimeF[2];
00140 unsigned char junk[1024 - 80];
00141 } oldboot_t;
00142
00143 struct bootsector {
00144 unsigned char jump[3];
00145 char banner[8] PACKED;
00146 unsigned char secsiz[2] PACKED;
00147 unsigned char clsiz;
00148 unsigned char nrsvsect[2];
00149 unsigned char nfat;
00150 unsigned char dirents[2] PACKED;
00151 unsigned char psect[2] PACKED;
00152 unsigned char descr;
00153 unsigned char fatlen[2];
00154 unsigned char nsect[2];
00155 unsigned char nheads[2];
00156 unsigned char nhs[4];
00157 unsigned char bigsect[4];
00158
00159 union {
00160 struct fat32_t fat32;
00161 struct oldboot_t old;
00162 } ext;
00163 };
00164
00165 #define CHAR(x) (boot->x[0])
00166 #define WORD(x) (_WORD(boot->x))
00167 #define DWORD(x) (_DWORD(boot->x))
00168 #define OFFSET(x) (((char *) (boot->x)) - ((char *)(boot->jump)))
00169
00170
00171 extern struct OldDos_t {
00172 int tracks;
00173 int sectors;
00174 int heads;
00175
00176 int dir_len;
00177 int cluster_size;
00178 int fat_len;
00179
00180 int media;
00181 } old_dos[];
00182
00183 #define FAT12 4085
00184 #define FAT16 65525
00185
00186 #define ATTR_ARCHIVE 0x20
00187 #define ATTR_DIR 0x10
00188 #define ATTR_LABEL 0x8
00189 #define ATTR_SYSTEM 0x4
00190 #define ATTR_HIDDEN 0x2
00191 #define ATTR_READONLY 0x1
00192
00193 #define HAS_BIT(entry,x) ((entry)->dir.attr & (x))
00194
00195 #define IS_ARCHIVE(entry) (HAS_BIT((entry),ATTR_ARCHIVE))
00196 #define IS_DIR(entry) (HAS_BIT((entry),ATTR_DIR))
00197 #define IS_LABEL(entry) (HAS_BIT((entry),ATTR_LABEL))
00198 #define IS_SYSTEM(entry) (HAS_BIT((entry),ATTR_SYSTEM))
00199 #define IS_HIDDEN(entry) (HAS_BIT((entry),ATTR_HIDDEN))
00200 #define IS_READONLY(entry) (HAS_BIT((entry),ATTR_READONLY))
00201
00202
00203 #define MAX_SECT_PER_CLUSTER 64
00204
00205
00206
00207
00208
00209 #define FAT_SIZE(bits, sec_siz, clusters) \
00210 ((((clusters)+2) * ((bits)/4) - 1) / 2 / (sec_siz) + 1)
00211
00212 #define NEEDED_FAT_SIZE(x) FAT_SIZE((x)->fat_bits, (x)->sector_size, \
00213 (x)->num_clus)
00214
00215
00216 #define DISK_SIZE(bits, sec_siz, clusters, n, cluster_size) \
00217 ((n) * FAT_SIZE(bits, sec_siz, clusters) + \
00218 (clusters) * (cluster_size))
00219
00220 #define TOTAL_DISK_SIZE(bits, sec_siz, clusters, n, cluster_size) \
00221 (DISK_SIZE(bits, sec_siz, clusters, n, cluster_size) + 2)
00222
00223
00224 extern const char *mversion;
00225 extern const char *mdate;
00226
00227 extern char *Version;
00228 extern char *Date;
00229
00230
00231 int init(char drive, int mode);
00232
00233 #define MT_READ 1
00234 #define MT_WRITE 2
00235
00236 #endif
00237