1 | /* |
---|
2 | * msdos.h |
---|
3 | * |
---|
4 | * The MSDOS filesystem constants/data structures/prototypes |
---|
5 | * |
---|
6 | * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia |
---|
7 | * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru> |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.rtems.com/license/LICENSE. |
---|
12 | */ |
---|
13 | #ifndef __DOSFS_MSDOS_H__ |
---|
14 | #define __DOSFS_MSDOS_H__ |
---|
15 | |
---|
16 | #include <rtems.h> |
---|
17 | #include <rtems/libio_.h> |
---|
18 | |
---|
19 | #include "fat.h" |
---|
20 | #include "fat_file.h" |
---|
21 | |
---|
22 | /** |
---|
23 | * @defgroup libfs_msdos MSDOS FileSystem |
---|
24 | * |
---|
25 | * @ingroup libfs |
---|
26 | */ |
---|
27 | /**@{*/ |
---|
28 | #ifdef __cplusplus |
---|
29 | extern "C" { |
---|
30 | #endif |
---|
31 | |
---|
32 | #define MSDOS_NAME_NOT_FOUND_ERR 0x7D01 |
---|
33 | |
---|
34 | /* |
---|
35 | * This structure identifies the instance of the filesystem on the MSDOS |
---|
36 | * level. |
---|
37 | */ |
---|
38 | typedef struct msdos_fs_info_s |
---|
39 | { |
---|
40 | fat_fs_info_t fat; /* |
---|
41 | * volume |
---|
42 | * description |
---|
43 | */ |
---|
44 | const rtems_filesystem_file_handlers_r *directory_handlers; /* |
---|
45 | * a set of routines |
---|
46 | * that handles the |
---|
47 | * nodes of directory |
---|
48 | * type |
---|
49 | */ |
---|
50 | const rtems_filesystem_file_handlers_r *file_handlers; /* |
---|
51 | * a set of routines |
---|
52 | * that handles the |
---|
53 | * nodes of file |
---|
54 | * type |
---|
55 | */ |
---|
56 | rtems_id vol_sema; /* |
---|
57 | * semaphore |
---|
58 | * associated with |
---|
59 | * the volume |
---|
60 | */ |
---|
61 | uint8_t *cl_buf; /* |
---|
62 | * just placeholder |
---|
63 | * for anything |
---|
64 | */ |
---|
65 | } msdos_fs_info_t; |
---|
66 | |
---|
67 | /* a set of routines that handle the nodes which are directories */ |
---|
68 | extern const rtems_filesystem_file_handlers_r msdos_dir_handlers; |
---|
69 | |
---|
70 | /* a set of routines that handle the nodes which are files */ |
---|
71 | extern const rtems_filesystem_file_handlers_r msdos_file_handlers; |
---|
72 | |
---|
73 | /* Volume semaphore timeout value. This value can be changed to a number |
---|
74 | * of ticks to help debugging or if you need such a */ |
---|
75 | #define MSDOS_VOLUME_SEMAPHORE_TIMEOUT RTEMS_NO_TIMEOUT |
---|
76 | |
---|
77 | /* Node types */ |
---|
78 | #define MSDOS_DIRECTORY RTEMS_FILESYSTEM_DIRECTORY |
---|
79 | #define MSDOS_REGULAR_FILE RTEMS_FILESYSTEM_MEMORY_FILE |
---|
80 | #define MSDOS_HARD_LINK RTEMS_FILESYSTEM_HARD_LINK /* pseudo type */ |
---|
81 | |
---|
82 | /** |
---|
83 | * @brief Type of Node that Loc Refers To |
---|
84 | * |
---|
85 | * The following returns the type of node that the loc refers to. |
---|
86 | * |
---|
87 | */ |
---|
88 | typedef rtems_filesystem_node_types_t msdos_node_type_t; |
---|
89 | |
---|
90 | /* |
---|
91 | * Macros for fetching fields from 32 bytes long FAT Directory Entry |
---|
92 | * Structure |
---|
93 | */ |
---|
94 | #define MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE 32 /* 32 bytes */ |
---|
95 | |
---|
96 | #define MSDOS_DIR_NAME(x) (char *)((x) + 0) |
---|
97 | #define MSDOS_DIR_ENTRY_TYPE(x) (uint8_t *)((x) + 0) |
---|
98 | #define MSDOS_DIR_ATTR(x) (uint8_t *)((x) + 11) |
---|
99 | #define MSDOS_DIR_NT_RES(x) (uint8_t *)((x) + 12) |
---|
100 | #define MSDOS_DIR_LFN_CHECKSUM(x) (uint8_t *)((x) + 13) |
---|
101 | #define MSDOS_DIR_CRT_TIME_TENTH(x) (uint8_t *)((x) + 13) |
---|
102 | #define MSDOS_DIR_CRT_TIME(x) (uint16_t *)((x) + 14) |
---|
103 | #define MSDOS_DIR_CRT_DATE(x) (uint16_t *)((x) + 16) |
---|
104 | #define MSDOS_DIR_LAST_ACCESS_DATE(x) (uint16_t *)((x) + 18) |
---|
105 | #define MSDOS_DIR_FIRST_CLUSTER_HI(x) (uint16_t *)((x) + 20) |
---|
106 | #define MSDOS_DIR_WRITE_TIME(x) (uint16_t *)((x) + 22) |
---|
107 | #define MSDOS_DIR_WRITE_DATE(x) (uint16_t *)((x) + 24) |
---|
108 | #define MSDOS_DIR_FIRST_CLUSTER_LOW(x) (uint16_t *)((x) + 26) |
---|
109 | #define MSDOS_DIR_FILE_SIZE(x) (uint32_t *)((x) + 28) |
---|
110 | |
---|
111 | #define MSDOS_EXTRACT_CLUSTER_NUM(p) \ |
---|
112 | (uint32_t)( (CF_LE_W(*MSDOS_DIR_FIRST_CLUSTER_LOW(p))) | \ |
---|
113 | ((uint32_t)(CF_LE_W((*MSDOS_DIR_FIRST_CLUSTER_HI(p))))<<16) ) |
---|
114 | |
---|
115 | /* |
---|
116 | * Fields offset in 32 bytes long FAT Directory Entry |
---|
117 | * Structure |
---|
118 | */ |
---|
119 | #define MSDOS_FILE_SIZE_OFFSET 28 |
---|
120 | #define MSDOS_FILE_NAME_OFFSET 0 |
---|
121 | #define MSDOS_FIRST_CLUSTER_HI_OFFSET 20 |
---|
122 | #define MSDOS_FIRST_CLUSTER_LOW_OFFSET 26 |
---|
123 | #define MSDOS_FILE_WDATE_OFFSET 24 |
---|
124 | #define MSDOS_FILE_WTIME_OFFSET 22 |
---|
125 | #define MSDOS_FILE_ADATE_OFFSET 18 |
---|
126 | |
---|
127 | /* |
---|
128 | * Possible values of DIR_Attr field of 32 bytes long FAT Directory Entry |
---|
129 | * Structure |
---|
130 | */ |
---|
131 | #define MSDOS_ATTR_READ_ONLY 0x01 |
---|
132 | #define MSDOS_ATTR_HIDDEN 0x02 |
---|
133 | #define MSDOS_ATTR_SYSTEM 0x04 |
---|
134 | #define MSDOS_ATTR_VOLUME_ID 0x08 |
---|
135 | #define MSDOS_ATTR_DIRECTORY 0x10 |
---|
136 | #define MSDOS_ATTR_ARCHIVE 0x20 |
---|
137 | #define MSDOS_ATTR_LFN (MSDOS_ATTR_READ_ONLY | \ |
---|
138 | MSDOS_ATTR_HIDDEN | \ |
---|
139 | MSDOS_ATTR_SYSTEM | \ |
---|
140 | MSDOS_ATTR_VOLUME_ID) |
---|
141 | #define MSDOS_ATTR_LFN_MASK (MSDOS_ATTR_READ_ONLY | \ |
---|
142 | MSDOS_ATTR_HIDDEN | \ |
---|
143 | MSDOS_ATTR_SYSTEM | \ |
---|
144 | MSDOS_ATTR_VOLUME_ID | \ |
---|
145 | MSDOS_ATTR_DIRECTORY | \ |
---|
146 | MSDOS_ATTR_ARCHIVE) |
---|
147 | |
---|
148 | #define MSDOS_LAST_LONG_ENTRY 0x40 |
---|
149 | #define MSDOS_LAST_LONG_ENTRY_MASK 0x3F |
---|
150 | |
---|
151 | #define MSDOS_DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */ |
---|
152 | #define MSDOS_DT_2SECONDS_SHIFT 0 |
---|
153 | #define MSDOS_DT_MINUTES_MASK 0x7E0 /* minutes */ |
---|
154 | #define MSDOS_DT_MINUTES_SHIFT 5 |
---|
155 | #define MSDOS_DT_HOURS_MASK 0xF800 /* hours */ |
---|
156 | #define MSDOS_DT_HOURS_SHIFT 11 |
---|
157 | |
---|
158 | #define MSDOS_DD_DAY_MASK 0x1F /* day of month */ |
---|
159 | #define MSDOS_DD_DAY_SHIFT 0 |
---|
160 | #define MSDOS_DD_MONTH_MASK 0x1E0 /* month */ |
---|
161 | #define MSDOS_DD_MONTH_SHIFT 5 |
---|
162 | #define MSDOS_DD_YEAR_MASK 0xFE00 /* year - 1980 */ |
---|
163 | #define MSDOS_DD_YEAR_SHIFT 9 |
---|
164 | |
---|
165 | |
---|
166 | /* |
---|
167 | * Possible values of DIR_Name[0] field of 32 bytes long FAT Directory Entry |
---|
168 | * Structure |
---|
169 | */ |
---|
170 | #define MSDOS_THIS_DIR_ENTRY_EMPTY 0xE5 |
---|
171 | #define MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY 0x00 |
---|
172 | |
---|
173 | /* |
---|
174 | * Number of characters per directory entry for a long filename. |
---|
175 | */ |
---|
176 | #define MSDOS_LFN_LEN_PER_ENTRY (13) |
---|
177 | |
---|
178 | /* |
---|
179 | * Macros for names parsing and formatting |
---|
180 | */ |
---|
181 | |
---|
182 | #define MSDOS_SHORT_BASE_LEN 8 /* 8 characters */ |
---|
183 | #define MSDOS_SHORT_EXT_LEN 3 /* 3 characters */ |
---|
184 | #define MSDOS_SHORT_NAME_LEN (MSDOS_SHORT_BASE_LEN+\ |
---|
185 | MSDOS_SHORT_EXT_LEN) /* 11 chars */ |
---|
186 | #define MSDOS_NAME_MAX_LNF_LEN (255) |
---|
187 | #define MSDOS_NAME_MAX MSDOS_SHORT_NAME_LEN |
---|
188 | #define MSDOS_NAME_MAX_WITH_DOT (MSDOS_NAME_MAX + 1) |
---|
189 | #define MSDOS_NAME_MAX_LFN_WITH_DOT (260) |
---|
190 | |
---|
191 | |
---|
192 | extern const char *const MSDOS_DOT_NAME; /* ".", padded to MSDOS_NAME chars */ |
---|
193 | extern const char *const MSDOS_DOTDOT_NAME; /* ".", padded to MSDOS_NAME chars */ |
---|
194 | |
---|
195 | typedef enum msdos_name_types_e |
---|
196 | { |
---|
197 | MSDOS_NAME_INVALID = 0, /* Unknown name type. Has invalid characters. */ |
---|
198 | MSDOS_NAME_SHORT, /* Name can be short. */ |
---|
199 | MSDOS_NAME_LONG /* Name is long; cannot be short. */ |
---|
200 | } msdos_name_type_t; |
---|
201 | |
---|
202 | typedef enum msdos_token_types_e |
---|
203 | { |
---|
204 | MSDOS_NO_MORE_PATH, |
---|
205 | MSDOS_CURRENT_DIR, |
---|
206 | MSDOS_UP_DIR, |
---|
207 | MSDOS_NAME, |
---|
208 | MSDOS_INVALID_TOKEN |
---|
209 | } msdos_token_types_t; |
---|
210 | |
---|
211 | /* Others macros */ |
---|
212 | #define MSDOS_RES_NT_VALUE 0x00 |
---|
213 | #define MSDOS_INIT_DIR_SIZE 0x00 |
---|
214 | |
---|
215 | /* "dot" entry offset in a directory */ |
---|
216 | #define MSDOS_DOT_DIR_ENTRY_OFFSET 0x00 /* first entry in directory */ |
---|
217 | |
---|
218 | /* "dotdot" entry offset in a directory */ |
---|
219 | #define MSDOS_DOTDOT_DIR_ENTRY_OFFSET 0x20 /* second entry in directory */ |
---|
220 | |
---|
221 | /* 'p' should be char* */ |
---|
222 | #define DOT_NODE_P(p) ((char *)(p)) |
---|
223 | #define DOTDOT_NODE_P(p) ((char *)((p) + MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)) |
---|
224 | |
---|
225 | /* Size limits for files and directories */ |
---|
226 | #define MSDOS_MAX_DIR_LENGHT 0x200000 /* 2,097,152 bytes */ |
---|
227 | #define MSDOS_MAX_FILE_SIZE 0xFFFFFFFF /* 4 Gb */ |
---|
228 | |
---|
229 | /* |
---|
230 | * The number of 32 bytes long FAT Directory Entry |
---|
231 | * Structures per 512 bytes sector |
---|
232 | */ |
---|
233 | #define MSDOS_DPS512_NUM 16 |
---|
234 | |
---|
235 | /** |
---|
236 | * @brief Shut Down MSDOS FileSystem |
---|
237 | * |
---|
238 | * MSDOS shut down handler implementation |
---|
239 | */ |
---|
240 | void msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry); |
---|
241 | |
---|
242 | void msdos_eval_path(rtems_filesystem_eval_path_context_t *ctx); |
---|
243 | |
---|
244 | /** |
---|
245 | * @brief Call Fat-File Close Routine |
---|
246 | * |
---|
247 | * Free node handler implementation for the filesystem operations table. |
---|
248 | */ |
---|
249 | void msdos_free_node_info(const rtems_filesystem_location_info_t *pathloc); |
---|
250 | |
---|
251 | rtems_filesystem_node_types_t msdos_node_type( |
---|
252 | const rtems_filesystem_location_info_t *loc |
---|
253 | ); |
---|
254 | |
---|
255 | int msdos_mknod( |
---|
256 | const rtems_filesystem_location_info_t *loc, |
---|
257 | const char *name, |
---|
258 | size_t namelen, |
---|
259 | mode_t mode, |
---|
260 | dev_t dev |
---|
261 | ); |
---|
262 | |
---|
263 | /** |
---|
264 | * @brief Remove Node from MSDOS Directory |
---|
265 | * |
---|
266 | * MSDOS Directory Handlers Implementation |
---|
267 | */ |
---|
268 | int msdos_rmnod( |
---|
269 | const rtems_filesystem_location_info_t *parentloc, |
---|
270 | const rtems_filesystem_location_info_t *loc |
---|
271 | ); |
---|
272 | |
---|
273 | /** |
---|
274 | * @brief Rename a MSDOS FileSystem Node |
---|
275 | * |
---|
276 | * Routine to rename a MSDOS filesystem node |
---|
277 | */ |
---|
278 | int msdos_rename( |
---|
279 | const rtems_filesystem_location_info_t *old_parent_loc, |
---|
280 | const rtems_filesystem_location_info_t *old_loc, |
---|
281 | const rtems_filesystem_location_info_t *new_parent_loc, |
---|
282 | const char *new_name, |
---|
283 | size_t new_namelen |
---|
284 | ); |
---|
285 | |
---|
286 | void msdos_lock(const rtems_filesystem_mount_table_entry_t *mt_entry); |
---|
287 | |
---|
288 | void msdos_unlock(const rtems_filesystem_mount_table_entry_t *mt_entry); |
---|
289 | |
---|
290 | /** |
---|
291 | * @brief MSDOS Filesystem Initialization |
---|
292 | * |
---|
293 | * MSDOS Initialization support routine implementation |
---|
294 | */ |
---|
295 | int msdos_initialize_support( |
---|
296 | rtems_filesystem_mount_table_entry_t *temp_mt_entry, |
---|
297 | const rtems_filesystem_operations_table *op_table, |
---|
298 | const rtems_filesystem_file_handlers_r *file_handlers, |
---|
299 | const rtems_filesystem_file_handlers_r *directory_handlers |
---|
300 | ); |
---|
301 | |
---|
302 | int msdos_file_close(rtems_libio_t *iop /* IN */); |
---|
303 | |
---|
304 | ssize_t msdos_file_read( |
---|
305 | rtems_libio_t *iop, /* IN */ |
---|
306 | void *buffer, /* IN */ |
---|
307 | size_t count /* IN */ |
---|
308 | ); |
---|
309 | |
---|
310 | ssize_t msdos_file_write( |
---|
311 | rtems_libio_t *iop, /* IN */ |
---|
312 | const void *buffer, /* IN */ |
---|
313 | size_t count /* IN */ |
---|
314 | ); |
---|
315 | |
---|
316 | int msdos_file_stat( |
---|
317 | const rtems_filesystem_location_info_t *loc, |
---|
318 | struct stat *buf |
---|
319 | ); |
---|
320 | |
---|
321 | int |
---|
322 | msdos_file_ftruncate( |
---|
323 | rtems_libio_t *iop, /* IN */ |
---|
324 | off_t length /* IN */ |
---|
325 | ); |
---|
326 | |
---|
327 | int msdos_file_sync(rtems_libio_t *iop); |
---|
328 | |
---|
329 | int msdos_file_datasync(rtems_libio_t *iop); |
---|
330 | |
---|
331 | ssize_t msdos_dir_read( |
---|
332 | rtems_libio_t *iop, /* IN */ |
---|
333 | void *buffer, /* IN */ |
---|
334 | size_t count /* IN */ |
---|
335 | ); |
---|
336 | |
---|
337 | int msdos_dir_sync(rtems_libio_t *iop); |
---|
338 | |
---|
339 | int msdos_dir_stat( |
---|
340 | const rtems_filesystem_location_info_t *loc, |
---|
341 | struct stat *buf |
---|
342 | ); |
---|
343 | |
---|
344 | /** |
---|
345 | * @brief Implements wake up version of the "signal" operation |
---|
346 | * |
---|
347 | * Routine to create a new MSDOS filesystem node |
---|
348 | * |
---|
349 | */ |
---|
350 | int msdos_creat_node(const rtems_filesystem_location_info_t *parent_loc, |
---|
351 | msdos_node_type_t type, |
---|
352 | const char *name, |
---|
353 | int name_len, |
---|
354 | mode_t mode, |
---|
355 | const fat_file_fd_t *link_fd); |
---|
356 | |
---|
357 | /* Misc prototypes */ |
---|
358 | |
---|
359 | int msdos_find_name( |
---|
360 | rtems_filesystem_location_info_t *parent_loc, |
---|
361 | const char *name, |
---|
362 | int name_len |
---|
363 | ); |
---|
364 | |
---|
365 | int msdos_get_name_node( |
---|
366 | const rtems_filesystem_location_info_t *parent_loc, |
---|
367 | bool create_node, |
---|
368 | const char *name, |
---|
369 | int name_len, |
---|
370 | msdos_name_type_t name_type, |
---|
371 | fat_dir_pos_t *dir_pos, |
---|
372 | char *name_dir_entry |
---|
373 | ); |
---|
374 | |
---|
375 | int msdos_dir_info_remove(rtems_filesystem_location_info_t *pathloc); |
---|
376 | |
---|
377 | msdos_name_type_t msdos_long_to_short(const char *lfn, int lfn_len, |
---|
378 | char* sfn, int sfn_len); |
---|
379 | |
---|
380 | int msdos_filename_unix2dos(const char *un, int unlen, char *dn); |
---|
381 | |
---|
382 | void msdos_date_unix2dos( |
---|
383 | unsigned int tsp, uint16_t *ddp, |
---|
384 | uint16_t *dtp); |
---|
385 | |
---|
386 | unsigned int msdos_date_dos2unix(unsigned int dd, unsigned int dt); |
---|
387 | |
---|
388 | int msdos_set_first_cluster_num( |
---|
389 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
390 | fat_file_fd_t *fat_fd |
---|
391 | ); |
---|
392 | |
---|
393 | int msdos_set_file_size( |
---|
394 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
395 | fat_file_fd_t *fat_fd |
---|
396 | ); |
---|
397 | |
---|
398 | int msdos_set_first_char4file_name( |
---|
399 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
400 | fat_dir_pos_t *dir_pos, |
---|
401 | unsigned char first_char |
---|
402 | ); |
---|
403 | |
---|
404 | int msdos_set_dir_wrt_time_and_date( |
---|
405 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
406 | fat_file_fd_t *fat_fd |
---|
407 | ); |
---|
408 | |
---|
409 | |
---|
410 | int msdos_dir_is_empty( |
---|
411 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
412 | fat_file_fd_t *fat_fd, |
---|
413 | bool *ret_val |
---|
414 | ); |
---|
415 | |
---|
416 | int msdos_find_name_in_fat_file( |
---|
417 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
418 | fat_file_fd_t *fat_fd, |
---|
419 | bool create_node, |
---|
420 | const char *name, |
---|
421 | int name_len, |
---|
422 | msdos_name_type_t name_type, |
---|
423 | fat_dir_pos_t *dir_pos, |
---|
424 | char *name_dir_entry |
---|
425 | ); |
---|
426 | |
---|
427 | int msdos_find_node_by_cluster_num_in_fat_file( |
---|
428 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
429 | fat_file_fd_t *fat_fd, |
---|
430 | uint32_t cl4find, |
---|
431 | fat_dir_pos_t *dir_pos, |
---|
432 | char *dir_entry |
---|
433 | ); |
---|
434 | |
---|
435 | int msdos_get_dotdot_dir_info_cluster_num_and_offset( |
---|
436 | rtems_filesystem_mount_table_entry_t *mt_entry, |
---|
437 | uint32_t cln, |
---|
438 | fat_dir_pos_t *dir_pos, |
---|
439 | char *dir_entry |
---|
440 | ); |
---|
441 | |
---|
442 | int msdos_sync(rtems_libio_t *iop); |
---|
443 | |
---|
444 | #ifdef __cplusplus |
---|
445 | } |
---|
446 | #endif |
---|
447 | /**@}*/ |
---|
448 | #endif /* __DOSFS_MSDOS_H__ */ |
---|