msdos.h

Go to the documentation of this file.
00001 #ifndef MTOOLS_MSDOS_H
00002 #define MTOOLS_MSDOS_H
00003 
00004 /*
00005  * msdos common header file
00006  */
00007 
00008 #define MAX_SECTOR      8192            /* largest sector size */
00009 #define MDIR_SIZE       32              /* MSDOS directory entry size in bytes*/
00010 #define MAX_CLUSTER     8192            /* largest cluster size */
00011 #define MAX_PATH        128             /* largest MSDOS path length */
00012 #define MAX_DIR_SECS    64              /* largest directory (in sectors) */
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];                   /*  0 file name */
00025         char ext[3];                    /*  8 file extension */
00026         unsigned char attr;             /* 11 attribute byte */
00027         unsigned char Case;             /* 12 case of short filename */
00028         unsigned char ctime_ms;         /* 13 creation time, milliseconds (?) */
00029         unsigned char ctime[2];         /* 14 creation time */
00030         unsigned char cdate[2];         /* 16 creation date */
00031         unsigned char adate[2];         /* 18 last access date */
00032         unsigned char startHi[2];       /* 20 start cluster, Hi */
00033         unsigned char time[2];          /* 22 time stamp */
00034         unsigned char date[2];          /* 24 date stamp */
00035         unsigned char start[2];         /* 26 starting cluster number */
00036         unsigned char size[4];          /* 28 size of the file */
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 /* ASSUMPTION: long is at least 32 bits */
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 /* ASSUMPTION: short is at least 16 bits */
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  *          hi byte     |    low byte
00069  *      |7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
00070  *  | | | | | | | | | | | | | | | | |
00071  *  \   7 bits    /\4 bits/\ 5 bits /
00072  *     year +80     month     day
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  *          hi byte     |    low byte
00080  *      |7|6|5|4|3|2|1|0|7|6|5|4|3|2|1|0|
00081  *      | | | | | | | | | | | | | | | | |
00082  *      \  5 bits /\  6 bits  /\ 5 bits /
00083  *         hour      minutes     sec*2
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;        /* 36 physical drive ? */
00106         unsigned char reserved;         /* 37 reserved */
00107         unsigned char dos4;             /* 38 dos > 4.0 diskette */
00108         unsigned char serial[4];        /* 39 serial number */
00109         char label[11];                 /* 43 disk label */
00110         char fat_type[8];               /* 54 FAT type */
00111 } label_blk_t;
00112 
00113 /* FAT32 specific info in the bootsector */
00114 typedef struct fat32_t {
00115         unsigned char bigFat[4];        /* 36 nb of sectors per FAT */
00116         unsigned char extFlags[2];      /* 40 extension flags */
00117         unsigned char fsVersion[2];     /* 42 ? */
00118         unsigned char rootCluster[4];   /* 44 start cluster of root dir */
00119         unsigned char infoSector[2];    /* 48 changeable global info */
00120         unsigned char backupBoot[2];    /* 50 back up boot sector */
00121         unsigned char reserved[6];      /* 52 ? */
00122         unsigned char reserved2[6];     /* 52 ? */
00123         struct label_blk_t labelBlock;
00124 } fat32; /* ends at 58 */
00125 
00126 typedef struct oldboot_t {
00127         struct label_blk_t labelBlock;
00128         unsigned char res_2m;           /* 62 reserved by 2M */
00129         unsigned char CheckSum;         /* 63 2M checksum (not used) */
00130         unsigned char fmt_2mf;          /* 64 2MF format version */
00131         unsigned char wt;               /* 65 1 if write track after format */
00132         unsigned char rate_0;           /* 66 data transfer rate on track 0 */
00133         unsigned char rate_any;         /* 67 data transfer rate on track<>0 */
00134         unsigned char BootP[2];         /* 68 offset to boot program */
00135         unsigned char Infp0[2];         /* 70 T1: information for track 0 */
00136         unsigned char InfpX[2];         /* 72 T2: information for track<>0 */
00137         unsigned char InfTm[2];         /* 74 T3: track sectors size table */
00138         unsigned char DateF[2];         /* 76 Format date */
00139         unsigned char TimeF[2];         /* 78 Format time */
00140         unsigned char junk[1024 - 80];  /* 80 remaining data */
00141 } oldboot_t;
00142 
00143 struct bootsector {
00144         unsigned char jump[3];          /* 0  Jump to boot code */
00145         char banner[8] PACKED;          /* 3  OEM name & version */
00146         unsigned char secsiz[2] PACKED; /* 11 Bytes per sector hopefully 512 */
00147         unsigned char clsiz;            /* 13 Cluster size in sectors */
00148         unsigned char nrsvsect[2];      /* 14 Number of reserved (boot) sectors */
00149         unsigned char nfat;             /* 16 Number of FAT tables hopefully 2 */
00150         unsigned char dirents[2] PACKED;/* 17 Number of directory slots */
00151         unsigned char psect[2] PACKED;  /* 19 Total sectors on disk */
00152         unsigned char descr;            /* 21 Media descriptor=first byte of FAT */
00153         unsigned char fatlen[2];        /* 22 Sectors in FAT */
00154         unsigned char nsect[2];         /* 24 Sectors/track */
00155         unsigned char nheads[2];        /* 26 Heads */
00156         unsigned char nhs[4];           /* 28 number of hidden sectors */
00157         unsigned char bigsect[4];       /* 32 big total sectors */
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 /* max. number of clusters described by a 12 bit FAT */
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 /* Experimentally, it turns out that DOS only accepts cluster sizes
00205  * which are powers of two, and less than 128 sectors (else it gets a
00206  * divide overflow) */
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 /* disk size taken by FAT and clusters */
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 /* approx. total disk size: assume 1 boot sector and one directory sector */
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 

Generated on Fri Apr 14 22:56:56 2006 for minix by  doxygen 1.4.6