wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
Albert ARIBAUD | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 3 | * Stäubli Faverges - <www.staubli.com> |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 4 | * Pierre AUBERT p.aubert@staubli.com |
| 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _DOS_H_ |
| 10 | #define _DOS_H_ |
| 11 | |
| 12 | /* Definitions for Dos diskettes */ |
| 13 | |
| 14 | /* General definitions */ |
| 15 | #define SZ_STD_SECTOR 512 /* Standard sector size */ |
| 16 | #define MDIR_SIZE 32 /* Direntry size */ |
| 17 | #define FAT_BITS 12 /* Diskette use 12 bits fat */ |
| 18 | |
| 19 | #define MAX_PATH 128 /* Max size of the MSDOS PATH */ |
| 20 | #define MAX_DIR_SECS 64 /* Taille max d'un repertoire (en */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 21 | /* secteurs) */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 22 | /* Misc. definitions */ |
| 23 | #define DELMARK '\xe5' |
| 24 | #define EXTENDED_BOOT (0x29) |
| 25 | #define MEDIA_STD (0xf0) |
| 26 | #define JUMP_0_1 (0xe9) |
| 27 | #define JUMP_0_2 (0xeb) |
| 28 | |
| 29 | /* Boot size is 256 bytes, but we need to read almost a sector, then |
| 30 | assume bootsize is 512 */ |
| 31 | #define BOOTSIZE 512 |
| 32 | |
| 33 | /* Fat definitions for 12 bits fat */ |
| 34 | #define FAT12_MAX_NB 4086 |
| 35 | #define FAT12_LAST 0x0ff6 |
| 36 | #define FAT12_END 0x0fff |
| 37 | |
| 38 | /* file attributes */ |
| 39 | #define ATTR_READONLY 0x01 |
| 40 | #define ATTR_HIDDEN 0x02 |
| 41 | #define ATTR_SYSTEM 0x04 |
| 42 | #define ATTR_VOLUME 0x08 |
| 43 | #define ATTR_DIRECTORY 0x10 |
| 44 | #define ATTR_ARCHIVE 0x20 |
| 45 | #define ATTR_VSE 0x0f |
| 46 | |
| 47 | /* Name format */ |
| 48 | #define EXTCASE 0x10 |
| 49 | #define BASECASE 0x8 |
| 50 | |
| 51 | /* Definition of the boot sector */ |
| 52 | #define BANNER_LG 8 |
| 53 | #define LABEL_LG 11 |
| 54 | |
| 55 | typedef struct bootsector |
| 56 | { |
| 57 | unsigned char jump [3]; /* 0 Jump to boot code */ |
| 58 | char banner [BANNER_LG]; /* 3 OEM name & version */ |
| 59 | unsigned short secsiz; /* 11 Bytes per sector hopefully 512 */ |
| 60 | unsigned char clsiz; /* 13 Cluster size in sectors */ |
| 61 | unsigned short nrsvsect; /* 14 Number of reserved (boot) sectors */ |
| 62 | unsigned char nfat; /* 16 Number of FAT tables hopefully 2 */ |
| 63 | unsigned short dirents; /* 17 Number of directory slots */ |
| 64 | unsigned short psect; /* 19 Total sectors on disk */ |
| 65 | unsigned char descr; /* 21 Media descriptor=first byte of FAT */ |
| 66 | unsigned short fatlen; /* 22 Sectors in FAT */ |
| 67 | unsigned short nsect; /* 24 Sectors/track */ |
| 68 | unsigned short nheads; /* 26 Heads */ |
| 69 | unsigned int nhs; /* 28 number of hidden sectors */ |
| 70 | unsigned int bigsect; /* 32 big total sectors */ |
| 71 | unsigned char physdrive; /* 36 physical drive ? */ |
| 72 | unsigned char reserved; /* 37 reserved */ |
| 73 | unsigned char dos4; /* 38 dos > 4.0 diskette */ |
| 74 | unsigned int serial; /* 39 serial number */ |
| 75 | char label [LABEL_LG]; /* 43 disk label */ |
| 76 | char fat_type [8]; /* 54 FAT type */ |
| 77 | unsigned char res_2m; /* 62 reserved by 2M */ |
| 78 | unsigned char CheckSum; /* 63 2M checksum (not used) */ |
| 79 | unsigned char fmt_2mf; /* 64 2MF format version */ |
| 80 | unsigned char wt; /* 65 1 if write track after format */ |
| 81 | unsigned char rate_0; /* 66 data transfer rate on track 0 */ |
| 82 | unsigned char rate_any; /* 67 data transfer rate on track<>0 */ |
| 83 | unsigned short BootP; /* 68 offset to boot program */ |
| 84 | unsigned short Infp0; /* 70 T1: information for track 0 */ |
| 85 | unsigned short InfpX; /* 72 T2: information for track<>0 */ |
| 86 | unsigned short InfTm; /* 74 T3: track sectors size table */ |
| 87 | unsigned short DateF; /* 76 Format date */ |
| 88 | unsigned short TimeF; /* 78 Format time */ |
| 89 | unsigned char junk [BOOTSIZE - 80]; /* 80 remaining data */ |
| 90 | } __attribute__ ((packed)) BootSector_t; |
| 91 | |
| 92 | /* Structure d'une entree de repertoire */ |
| 93 | typedef struct directory { |
| 94 | char name [8]; /* file name */ |
| 95 | char ext [3]; /* file extension */ |
| 96 | unsigned char attr; /* attribute byte */ |
| 97 | unsigned char Case; /* case of short filename */ |
| 98 | unsigned char reserved [9]; /* ?? */ |
| 99 | unsigned char time [2]; /* time stamp */ |
| 100 | unsigned char date [2]; /* date stamp */ |
| 101 | unsigned short start; /* starting cluster number */ |
| 102 | unsigned int size; /* size of the file */ |
| 103 | } __attribute__ ((packed)) Directory_t; |
| 104 | |
| 105 | |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 106 | #define MAX_VFAT_SUBENTRIES 20 |
| 107 | #define VSE_NAMELEN 13 |
| 108 | |
| 109 | #define VSE1SIZE 5 |
| 110 | #define VSE2SIZE 6 |
| 111 | #define VSE3SIZE 2 |
| 112 | |
| 113 | #define VBUFSIZE ((MAX_VFAT_SUBENTRIES * VSE_NAMELEN) + 1) |
| 114 | |
| 115 | #define MAX_VNAMELEN (255) |
| 116 | |
| 117 | #define VSE_PRESENT 0x01 |
| 118 | #define VSE_LAST 0x40 |
| 119 | #define VSE_MASK 0x1f |
| 120 | |
| 121 | /* Flag used by vfat_lookup */ |
| 122 | #define DO_OPEN 1 |
| 123 | #define ACCEPT_PLAIN 0x20 |
| 124 | #define ACCEPT_DIR 0x10 |
| 125 | #define ACCEPT_LABEL 0x08 |
| 126 | #define SINGLE 2 |
| 127 | #define MATCH_ANY 0x40 |
| 128 | |
| 129 | struct vfat_subentry { |
| 130 | unsigned char id; /* VSE_LAST pour la fin, VSE_MASK */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 131 | /* pour un VSE */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 132 | char text1 [VSE1SIZE * 2]; /* Caracteres encodes sur 16 bits */ |
| 133 | unsigned char attribute; /* 0x0f pour les VFAT */ |
| 134 | unsigned char hash1; /* toujours 0 */ |
| 135 | unsigned char sum; /* Checksum du nom court */ |
| 136 | char text2 [VSE2SIZE * 2]; /* Caracteres encodes sur 16 bits */ |
| 137 | unsigned char sector_l; /* 0 pour les VFAT */ |
| 138 | unsigned char sector_u; /* 0 pour les VFAT */ |
| 139 | char text3 [VSE3SIZE * 2]; /* Caracteres encodes sur 16 bits */ |
| 140 | } __attribute__ ((packed)) ; |
| 141 | |
| 142 | struct vfat_state { |
| 143 | char name [VBUFSIZE]; |
| 144 | int status; /* is now a bit map of 32 bits */ |
| 145 | int subentries; |
| 146 | unsigned char sum; /* no need to remember the sum for each */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 147 | /* entry, it is the same anyways */ |
wdenk | 591dda5 | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 148 | } __attribute__ ((packed)) ; |
| 149 | |
| 150 | /* Conversion macros */ |
| 151 | #define DOS_YEAR(dir) (((dir)->date[1] >> 1) + 1980) |
| 152 | #define DOS_MONTH(dir) (((((dir)->date[1]&0x1) << 3) + ((dir)->date[0] >> 5))) |
| 153 | #define DOS_DAY(dir) ((dir)->date[0] & 0x1f) |
| 154 | #define DOS_HOUR(dir) ((dir)->time[1] >> 3) |
| 155 | #define DOS_MINUTE(dir) (((((dir)->time[1]&0x7) << 3) + ((dir)->time[0] >> 5))) |
| 156 | #define DOS_SEC(dir) (((dir)->time[0] & 0x1f) * 2) |
| 157 | |
| 158 | |
| 159 | #endif |