fat: reading directories (with long names) and files works now (tested with FAT12)
[meinos.git] / apps / fat / dirent.h
blob2698587512ab4f94532f2b1e95911fcd53cb9d71
1 /*
2 * fat - A FAT* CDI driver
4 * Copyright (C) 2008 Janosch Gräf
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 3 of the License, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef _DIRENT_H_
21 #define _DIRENT_H_
23 #include <stdint.h>
25 #define fat32_first_cluster(de) ((((uint32_t)(de)->first_cluster_high)<<16)|(de)->first_cluster)
27 struct fat_dirent {
28 /// Filename
29 uint8_t filename[8];
31 /// Filename extension
32 uint8_t filename_ext[3];
34 /// File attributes
35 struct {
36 /// Read only
37 unsigned readonly:1;
39 /// File is hidden
40 unsigned hidden:1;
42 /// System file
43 unsigned system:1;
45 /// Volume label
46 unsigned volume:1;
48 /// Directory
49 unsigned dir:1;
51 /// Archiv
52 unsigned archiv:1;
54 unsigned :2;
55 } __attribute__ ((packed)) attr;
57 /// Reserved
58 uint8_t res0;
60 /// Creation date
61 struct {
62 /// Decisecond
63 uint8_t deci_second;
65 /// Hour
66 unsigned hour:5;
68 /// Minute
69 unsigned minute:6;
71 /// 2 Seconds
72 unsigned two_secs:5;
74 /// Year (since 1980)
75 unsigned year:7;
77 /// Month
78 unsigned month:4;
80 /// Day of month
81 unsigned day:5;
82 } __attribute__ ((packed)) create_date;
84 /// Last access date
85 struct {
86 /// Year (since 1980)
87 unsigned year:7;
89 /// Month
90 unsigned month:4;
92 /// Day of month
93 unsigned day:5;
94 } __attribute__ ((packed)) access_date;
96 /// Higher 16 bits of first cluster (for FAT32)
97 uint16_t first_cluster_high;
99 /// Last write date
100 struct {
101 /// Hour
102 unsigned hour:5;
104 /// Minute
105 unsigned minute:6;
107 /// 2 Seconds
108 unsigned two_secs:5;
110 /// Year (since 1980)
111 unsigned year:7;
113 /// Month
114 unsigned month:4;
116 /// Day of month
117 unsigned day:5;
118 } __attribute__ ((packed)) write_date;
120 /// First cluster
121 uint16_t first_cluster;
123 /// File size
124 uint32_t file_size;
125 } __attribute__ ((packed));
127 struct fat_dirent_long {
128 /// Order
129 uint8_t order;
131 /// Name (part 1)
132 uint16_t name1[5];
134 /// File attributes
135 struct {
136 /// Read only
137 unsigned readonly:1;
139 /// File is hidden
140 unsigned hidden:1;
142 /// System file
143 unsigned system:1;
145 /// Volume label
146 unsigned volume:1;
148 /// Directory
149 unsigned dir:1;
151 /// Archiv
152 unsigned archiv:1;
154 unsigned :2;
155 } __attribute__ ((packed)) attr;
157 /// Type of log directory entry (should be 0)
158 uint8_t type;
160 /// Checksum of name
161 uint8_t checksum;
163 /// Name (part 2)
164 uint16_t name2[6];
166 /// Zero
167 uint16_t zero;
169 /// Name (part 3)
170 uint16_t name3[2];
171 } __attribute__ ((packed));
173 #endif