Merge branch 'master' of git://www.denx.de/git/u-boot-sh
[u-boot-openmoko.git] / fs / fdos / dos.h
blob7b27b01e02fe89f2590e3ffffd8a5cd24f6f3951
1 /*
2 * (C) Copyright 2002
3 * Stäubli Faverges - <www.staubli.com>
4 * Pierre AUBERT p.aubert@staubli.com
6 * See file CREDITS for list of people who contributed to this
7 * project.
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.
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.
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
25 #ifndef _DOS_H_
26 #define _DOS_H_
28 /* Definitions for Dos diskettes */
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 */
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)
45 /* Boot size is 256 bytes, but we need to read almost a sector, then
46 assume bootsize is 512 */
47 #define BOOTSIZE 512
49 /* Fat definitions for 12 bits fat */
50 #define FAT12_MAX_NB 4086
51 #define FAT12_LAST 0x0ff6
52 #define FAT12_END 0x0fff
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
63 /* Name format */
64 #define EXTCASE 0x10
65 #define BASECASE 0x8
67 /* Definition of the boot sector */
68 #define BANNER_LG 8
69 #define LABEL_LG 11
71 typedef struct bootsector
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;
108 /* Structure d'une entree de repertoire */
109 typedef 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;
122 #define MAX_VFAT_SUBENTRIES 20
123 #define VSE_NAMELEN 13
125 #define VSE1SIZE 5
126 #define VSE2SIZE 6
127 #define VSE3SIZE 2
129 #define VBUFSIZE ((MAX_VFAT_SUBENTRIES * VSE_NAMELEN) + 1)
131 #define MAX_VNAMELEN (255)
133 #define VSE_PRESENT 0x01
134 #define VSE_LAST 0x40
135 #define VSE_MASK 0x1f
137 /* Flag used by vfat_lookup */
138 #define DO_OPEN 1
139 #define ACCEPT_PLAIN 0x20
140 #define ACCEPT_DIR 0x10
141 #define ACCEPT_LABEL 0x08
142 #define SINGLE 2
143 #define MATCH_ANY 0x40
145 struct vfat_subentry {
146 unsigned char id; /* VSE_LAST pour la fin, VSE_MASK */
147 /* pour un VSE */
148 char text1 [VSE1SIZE * 2]; /* Caracteres encodes sur 16 bits */
149 unsigned char attribute; /* 0x0f pour les VFAT */
150 unsigned char hash1; /* toujours 0 */
151 unsigned char sum; /* Checksum du nom court */
152 char text2 [VSE2SIZE * 2]; /* Caracteres encodes sur 16 bits */
153 unsigned char sector_l; /* 0 pour les VFAT */
154 unsigned char sector_u; /* 0 pour les VFAT */
155 char text3 [VSE3SIZE * 2]; /* Caracteres encodes sur 16 bits */
156 } __attribute__ ((packed)) ;
158 struct vfat_state {
159 char name [VBUFSIZE];
160 int status; /* is now a bit map of 32 bits */
161 int subentries;
162 unsigned char sum; /* no need to remember the sum for each */
163 /* entry, it is the same anyways */
164 } __attribute__ ((packed)) ;
166 /* Conversion macros */
167 #define DOS_YEAR(dir) (((dir)->date[1] >> 1) + 1980)
168 #define DOS_MONTH(dir) (((((dir)->date[1]&0x1) << 3) + ((dir)->date[0] >> 5)))
169 #define DOS_DAY(dir) ((dir)->date[0] & 0x1f)
170 #define DOS_HOUR(dir) ((dir)->time[1] >> 3)
171 #define DOS_MINUTE(dir) (((((dir)->time[1]&0x7) << 3) + ((dir)->time[0] >> 5)))
172 #define DOS_SEC(dir) (((dir)->time[0] & 0x1f) * 2)
175 #endif