1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
From e18d72f70e30109492e9602ace5560e0c90b4a8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= <noltari@gmail.com>
Date: Sat, 7 Mar 2015 13:23:23 +0100
Subject: [PATCH 11/14] Remove linux/msdos_fs.h includes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
Signed-off-by: Andreas Bombe <aeb@debian.org>
---
src/file.c | 7 +------
src/file.h | 2 ++
src/fsck.fat.h | 8 ++------
src/mkfs.fat.c | 32 +++---------------------------
src/msdos_fs.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 69 insertions(+), 41 deletions(-)
create mode 100644 src/msdos_fs.h
diff --git a/src/file.c b/src/file.c
index 0b53840..9519070 100644
--- a/src/file.c
+++ b/src/file.c
@@ -30,14 +30,9 @@
#include <ctype.h>
#include <unistd.h>
-#define _LINUX_STAT_H /* hack to avoid inclusion of <linux/stat.h> */
-#define _LINUX_STRING_H_ /* hack to avoid inclusion of <linux/string.h> */
-#define _LINUX_FS_H /* hack to avoid inclusion of <linux/fs.h> */
-
-#include <linux/msdos_fs.h>
-
#include "common.h"
#include "file.h"
+#include "msdos_fs.h"
#include "charconv.h"
FDSC *fp_root = NULL;
diff --git a/src/file.h b/src/file.h
index 3adfc96..eaaf356 100644
--- a/src/file.h
+++ b/src/file.h
@@ -23,6 +23,8 @@
#ifndef _FILE_H
#define _FILE_H
+#include "msdos_fs.h"
+
typedef enum { fdt_none, fdt_drop, fdt_undelete } FD_TYPE;
typedef struct _fptr {
diff --git a/src/fsck.fat.h b/src/fsck.fat.h
index 27e9d52..e5f6178 100644
--- a/src/fsck.fat.h
+++ b/src/fsck.fat.h
@@ -28,16 +28,12 @@
#define _DOSFSCK_H
#include <fcntl.h>
-#define _LINUX_STAT_H /* hack to avoid inclusion of <linux/stat.h> */
-#define _LINUX_STRING_H_ /* hack to avoid inclusion of <linux/string.h> */
-#define _LINUX_FS_H /* hack to avoid inclusion of <linux/fs.h> */
-
-#include <linux/msdos_fs.h>
-
#include <stddef.h>
#include <stdint.h>
#include <endian.h>
+#include "msdos_fs.h"
+
#define VFAT_LN_ATTR (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
#define FAT_STATE_DIRTY 0x01
diff --git a/src/mkfs.fat.c b/src/mkfs.fat.c
index 3d1512f..76d40d8 100644
--- a/src/mkfs.fat.c
+++ b/src/mkfs.fat.c
@@ -67,6 +67,8 @@
#include <stdint.h>
#include <endian.h>
+#include "msdos_fs.h"
+
/* In earlier versions, an own llseek() was used, but glibc lseek() is
* sufficient (or even better :) for 64 bit offsets in the meantime */
#define llseek lseek
@@ -99,21 +101,6 @@ static inline int cdiv(int a, int b)
return (a + b - 1) / b;
}
-/* MS-DOS filesystem structures -- I included them here instead of
- including linux/msdos_fs.h since that doesn't include some fields we
- need */
-
-#define ATTR_RO 1 /* read-only */
-#define ATTR_HIDDEN 2 /* hidden */
-#define ATTR_SYS 4 /* system */
-#define ATTR_VOLUME 8 /* volume label */
-#define ATTR_DIR 16 /* directory */
-#define ATTR_ARCH 32 /* archived */
-
-#define ATTR_NONE 0 /* no attribute bits */
-#define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
- /* attribute bits that are copied "as is" */
-
/* FAT values */
#define FAT_EOF (atari_format ? 0x0fffffff : 0x0ffffff8)
#define FAT_BAD 0x0ffffff7
@@ -200,19 +187,6 @@ struct fat32_fsinfo {
uint32_t reserved2[4];
};
-struct msdos_dir_entry {
- char name[8], ext[3]; /* name and extension */
- uint8_t attr; /* attribute bits */
- uint8_t lcase; /* Case for base and extension */
- uint8_t ctime_ms; /* Creation time, milliseconds */
- uint16_t ctime; /* Creation time */
- uint16_t cdate; /* Creation date */
- uint16_t adate; /* Last access date */
- uint16_t starthi; /* high 16 bits of first cl. (FAT32) */
- uint16_t time, date, start; /* time, date and first cluster */
- uint32_t size; /* file size (in bytes) */
-} __attribute__ ((packed));
-
/* The "boot code" we put into the filesystem... it writes a message and
tells the user to try again */
@@ -1244,7 +1218,7 @@ static void setup_tables(void)
htole16((unsigned short)(ctime->tm_mday +
((ctime->tm_mon + 1) << 5) +
((ctime->tm_year - 80) << 9)));
- de->ctime_ms = 0;
+ de->ctime_cs = 0;
de->ctime = de->time;
de->cdate = de->date;
de->adate = de->date;
diff --git a/src/msdos_fs.h b/src/msdos_fs.h
new file mode 100644
index 0000000..54b2a34
--- /dev/null
+++ b/src/msdos_fs.h
@@ -0,0 +1,61 @@
+/* msdos_fs.h - MS-DOS filesystem constants/structures
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ The complete text of the GNU General Public License
+ can be found in /usr/share/common-licenses/GPL-3 file.
+*/
+
+#ifndef _MSDOS_FS_H
+#define _MSDOS_FS_H
+
+#include <stdint.h>
+
+#define SECTOR_SIZE 512 /* sector size (bytes) */
+#define MSDOS_DPS (SECTOR_SIZE / sizeof(struct msdos_dir_entry))
+#define MSDOS_DPS_BITS 4 /* log2(MSDOS_DPS) */
+#define MSDOS_DIR_BITS 5 /* log2(sizeof(struct msdos_dir_entry)) */
+
+#define ATTR_NONE 0 /* no attribute bits */
+#define ATTR_RO 1 /* read-only */
+#define ATTR_HIDDEN 2 /* hidden */
+#define ATTR_SYS 4 /* system */
+#define ATTR_VOLUME 8 /* volume label */
+#define ATTR_DIR 16 /* directory */
+#define ATTR_ARCH 32 /* archived */
+
+/* attribute bits that are copied "as is" */
+#define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
+
+#define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
+#define IS_FREE(n) (!*(n) || *(n) == DELETED_FLAG)
+
+#define MSDOS_NAME 11 /* maximum name length */
+#define MSDOS_DOT ". " /* ".", padded to MSDOS_NAME chars */
+#define MSDOS_DOTDOT ".. " /* "..", padded to MSDOS_NAME chars */
+
+struct msdos_dir_entry {
+ uint8_t name[8], ext[3]; /* name and extension */
+ uint8_t attr; /* attribute bits */
+ uint8_t lcase; /* Case for base and extension */
+ uint8_t ctime_cs; /* Creation time, centiseconds (0-199) */
+ uint16_t ctime; /* Creation time */
+ uint16_t cdate; /* Creation date */
+ uint16_t adate; /* Last access date */
+ uint16_t starthi; /* High 16 bits of cluster in FAT32 */
+ uint16_t time, date, start; /* time, date and first cluster */
+ uint32_t size; /* file size (in bytes) */
+} __attribute__ ((packed));
+
+#endif /* _MSDOS_FS_H */
--
1.9.1
|