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