RTEMS 7.0-rc1
Loading...
Searching...
No Matches
msdos.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-with-RTEMS-exception */
2
11/*
12 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
13 * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
14 *
15 * Modifications to support UTF-8 in the file system are
16 * Copyright (c) 2013 embedded brains GmbH & Co. KG
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#ifndef __DOSFS_MSDOS_H__
24#define __DOSFS_MSDOS_H__
25
26#include <rtems.h>
27#include <rtems/libio_.h>
28#include <rtems/dosfs.h>
29#include <rtems/thread.h>
30
31#include "fat.h"
32#include "fat_file.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
44#define MSDOS_NAME_NOT_FOUND_ERR 0x7D01
45
46/*
47 * This structure identifies the instance of the filesystem on the MSDOS
48 * level.
49 */
50typedef struct msdos_fs_info_s
51{
52 fat_fs_info_t fat; /*
53 * volume
54 * description
55 */
56 const rtems_filesystem_file_handlers_r *directory_handlers; /*
57 * a set of routines
58 * that handles the
59 * nodes of directory
60 * type
61 */
62 const rtems_filesystem_file_handlers_r *file_handlers; /*
63 * a set of routines
64 * that handles the
65 * nodes of file
66 * type
67 */
68 rtems_recursive_mutex vol_mutex;
69 uint8_t *cl_buf; /*
70 * just placeholder
71 * for anything
72 */
73
76
77static inline void msdos_fs_lock(msdos_fs_info_t *fs_info)
78{
79 rtems_recursive_mutex_lock(&fs_info->vol_mutex);
80}
81
82static inline void msdos_fs_unlock(msdos_fs_info_t *fs_info)
83{
84 rtems_recursive_mutex_unlock(&fs_info->vol_mutex);
85}
86
87/* a set of routines that handle the nodes which are directories */
88extern const rtems_filesystem_file_handlers_r msdos_dir_handlers;
89
90/* a set of routines that handle the nodes which are files */
91extern const rtems_filesystem_file_handlers_r msdos_file_handlers;
92
93/*
94 * Macros for fetching fields from 32 bytes long FAT Directory Entry
95 * Structure
96 */
97#define MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE 32 /* 32 bytes */
98
99#define MSDOS_DIR_NAME(x) (char *)((x) + 0)
100#define MSDOS_DIR_ENTRY_TYPE(x) (uint8_t *)((x) + 0)
101#define MSDOS_DIR_ATTR(x) (uint8_t *)((x) + 11)
102#define MSDOS_DIR_NT_RES(x) (uint8_t *)((x) + 12)
103#define MSDOS_DIR_LFN_CHECKSUM(x) (uint8_t *)((x) + 13)
104#define MSDOS_DIR_CRT_TIME_TENTH(x) (uint8_t *)((x) + 13)
105#define MSDOS_DIR_CRT_TIME(x) (uint16_t *)((x) + 14)
106#define MSDOS_DIR_CRT_DATE(x) (uint16_t *)((x) + 16)
107#define MSDOS_DIR_LAST_ACCESS_DATE(x) (uint16_t *)((x) + 18)
108#define MSDOS_DIR_FIRST_CLUSTER_HI(x) (uint16_t *)((x) + 20)
109#define MSDOS_DIR_WRITE_TIME(x) (uint16_t *)((x) + 22)
110#define MSDOS_DIR_WRITE_DATE(x) (uint16_t *)((x) + 24)
111#define MSDOS_DIR_FIRST_CLUSTER_LOW(x) (uint16_t *)((x) + 26)
112#define MSDOS_DIR_FILE_SIZE(x) (uint32_t *)((x) + 28)
113
114#define MSDOS_EXTRACT_CLUSTER_NUM(p) \
115 (uint32_t)( (CF_LE_W(*MSDOS_DIR_FIRST_CLUSTER_LOW(p))) | \
116 ((uint32_t)(CF_LE_W((*MSDOS_DIR_FIRST_CLUSTER_HI(p))))<<16) )
117
118/*
119 * Fields offset in 32 bytes long FAT Directory Entry
120 * Structure
121 */
122#define MSDOS_FILE_SIZE_OFFSET 28
123#define MSDOS_FILE_NAME_OFFSET 0
124#define MSDOS_FIRST_CLUSTER_HI_OFFSET 20
125#define MSDOS_FIRST_CLUSTER_LOW_OFFSET 26
126#define MSDOS_FILE_WDATE_OFFSET 24
127#define MSDOS_FILE_WTIME_OFFSET 22
128#define MSDOS_FILE_ADATE_OFFSET 18
129#define MSDOS_FILE_CDATE_OFFSET 16
130#define MSDOS_FILE_CTIME_OFFSET 14
131
132/*
133 * Possible values of DIR_Attr field of 32 bytes long FAT Directory Entry
134 * Structure
135 */
136#define MSDOS_ATTR_READ_ONLY 0x01
137#define MSDOS_ATTR_HIDDEN 0x02
138#define MSDOS_ATTR_SYSTEM 0x04
139#define MSDOS_ATTR_VOLUME_ID 0x08
140#define MSDOS_ATTR_DIRECTORY 0x10
141#define MSDOS_ATTR_ARCHIVE 0x20
142#define MSDOS_ATTR_LFN (MSDOS_ATTR_READ_ONLY | \
143 MSDOS_ATTR_HIDDEN | \
144 MSDOS_ATTR_SYSTEM | \
145 MSDOS_ATTR_VOLUME_ID)
146#define MSDOS_ATTR_LFN_MASK (MSDOS_ATTR_READ_ONLY | \
147 MSDOS_ATTR_HIDDEN | \
148 MSDOS_ATTR_SYSTEM | \
149 MSDOS_ATTR_VOLUME_ID | \
150 MSDOS_ATTR_DIRECTORY | \
151 MSDOS_ATTR_ARCHIVE)
152
153#define MSDOS_LAST_LONG_ENTRY 0x40
154#define MSDOS_LAST_LONG_ENTRY_MASK 0x3F
155
156#define MSDOS_DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */
157#define MSDOS_DT_2SECONDS_SHIFT 0
158#define MSDOS_DT_MINUTES_MASK 0x7E0 /* minutes */
159#define MSDOS_DT_MINUTES_SHIFT 5
160#define MSDOS_DT_HOURS_MASK 0xF800 /* hours */
161#define MSDOS_DT_HOURS_SHIFT 11
162
163#define MSDOS_DD_DAY_MASK 0x1F /* day of month */
164#define MSDOS_DD_DAY_SHIFT 0
165#define MSDOS_DD_MONTH_MASK 0x1E0 /* month */
166#define MSDOS_DD_MONTH_SHIFT 5
167#define MSDOS_DD_YEAR_MASK 0xFE00 /* year - 1980 */
168#define MSDOS_DD_YEAR_SHIFT 9
169
170
171/*
172 * Possible values of DIR_Name[0] field of 32 bytes long FAT Directory Entry
173 * Structure
174 */
175#define MSDOS_THIS_DIR_ENTRY_EMPTY 0xE5
176#define MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY 0x00
177
178/*
179 * Number of characters per directory entry for a long filename.
180 */
181#define MSDOS_LFN_LEN_PER_ENTRY (13)
182
183/*
184 * Macros for names parsing and formatting
185 */
186#define MSDOS_NAME_MAX_UTF8_BYTES_PER_CHAR 4
187#define MSDOS_NAME_MIN_UTF8_BYTES_PER_CHAR 1
188
189#define MSDOS_SHORT_BASE_LEN 8 /* 8 characters */
190#define MSDOS_SHORT_EXT_LEN 3 /* 3 characters */
191#define MSDOS_SHORT_NAME_LEN (MSDOS_SHORT_BASE_LEN+\
192 MSDOS_SHORT_EXT_LEN) /* 11 chars */
193#define MSDOS_NAME_MAX_LNF_LEN (255)
194#define MSDOS_NAME_MAX MSDOS_SHORT_NAME_LEN
195#define MSDOS_NAME_MAX_UTF8_SFN_BYTES (MSDOS_NAME_MAX *\
196 MSDOS_NAME_MAX_UTF8_BYTES_PER_CHAR)
197#define MSDOS_NAME_MAX_WITH_DOT (MSDOS_NAME_MAX + 1)
198#define MSDOS_SFN_MAX_WITH_DOT_UTF8_BYTES (MSDOS_NAME_MAX_WITH_DOT *\
199 MSDOS_NAME_MAX_UTF8_BYTES_PER_CHAR)
200#define MSDOS_NAME_MAX_LFN_WITH_DOT (260)
201
202#define MSDOS_NAME_LFN_BYTES_PER_CHAR (2)
203#define MSDOS_NAME_MAX_LFN_BYTES (MSDOS_NAME_MAX_LFN_WITH_DOT *\
204 MSDOS_NAME_LFN_BYTES_PER_CHAR)
205#define MSDOS_NAME_MAX_UTF8_LFN_BYTES (MSDOS_NAME_MAX_LFN_WITH_DOT *\
206 MSDOS_NAME_MAX_UTF8_BYTES_PER_CHAR)
207#define MSDOS_ENTRY_LFN_UTF8_BYTES (MSDOS_LFN_LEN_PER_ENTRY *\
208 MSDOS_NAME_MAX_UTF8_BYTES_PER_CHAR)
209
210extern const char *const MSDOS_DOT_NAME; /* ".", padded to MSDOS_NAME chars */
211extern const char *const MSDOS_DOTDOT_NAME; /* ".", padded to MSDOS_NAME chars */
212
213typedef enum msdos_name_types_e
214{
215 MSDOS_NAME_INVALID = 0, /* Unknown name type. Has invalid characters. */
216 MSDOS_NAME_SHORT, /* Name can be short. */
217 MSDOS_NAME_LONG /* Name is long; cannot be short. */
218} msdos_name_type_t;
219
220typedef enum msdos_token_types_e
221{
222 MSDOS_NO_MORE_PATH,
223 MSDOS_CURRENT_DIR,
224 MSDOS_UP_DIR,
225 MSDOS_NAME,
226 MSDOS_INVALID_TOKEN
227} msdos_token_types_t;
228
229/* Others macros */
230#define MSDOS_RES_NT_VALUE 0x00
231#define MSDOS_INIT_DIR_SIZE 0x00
232
233/* "dot" entry offset in a directory */
234#define MSDOS_DOT_DIR_ENTRY_OFFSET 0x00 /* first entry in directory */
235
236/* "dotdot" entry offset in a directory */
237#define MSDOS_DOTDOT_DIR_ENTRY_OFFSET 0x20 /* second entry in directory */
238
239/* 'p' should be char* */
240#define DOT_NODE_P(p) ((char *)(p))
241#define DOTDOT_NODE_P(p) ((char *)((p) + MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE))
242
243/* Size limits for files and directories */
244#define MSDOS_MAX_DIR_LENGTH 0x200000 /* 2,097,152 bytes */
245#define MSDOS_MAX_FILE_SIZE 0xFFFFFFFF /* 4 Gb */
246
247/*
248 * The number of 32 bytes long FAT Directory Entry
249 * Structures per 512 bytes sector
250 */
251#define MSDOS_DPS512_NUM 16
252
259
260void msdos_eval_path(rtems_filesystem_eval_path_context_t *ctx);
261
268
274int msdos_mknod(
276 const char *name,
277 size_t namelen,
278 mode_t mode,
279 dev_t dev
280);
281
287int msdos_rmnod(
288 const rtems_filesystem_location_info_t *parentloc,
290);
291
297int msdos_rename(
298 const rtems_filesystem_location_info_t *old_parent_loc,
300 const rtems_filesystem_location_info_t *new_parent_loc,
301 const char *new_name,
302 size_t new_namelen
303);
304
305int msdos_statvfs(
306 const rtems_filesystem_location_info_t *root_loc,
307 struct statvfs *sb);
308
309void msdos_lock(const rtems_filesystem_mount_table_entry_t *mt_entry);
310
311void msdos_unlock(const rtems_filesystem_mount_table_entry_t *mt_entry);
312
320 const rtems_filesystem_operations_table *op_table,
321 const rtems_filesystem_file_handlers_r *file_handlers,
322 const rtems_filesystem_file_handlers_r *directory_handlers,
324);
325
326ssize_t msdos_file_read(
327 rtems_libio_t *iop, /* IN */
328 void *buffer, /* IN */
329 size_t count /* IN */
330);
331
332ssize_t msdos_file_write(
333 rtems_libio_t *iop, /* IN */
334 const void *buffer, /* IN */
335 size_t count /* IN */
336);
337
338int msdos_file_stat(
340 struct stat *buf
341);
342
343int
344msdos_file_ftruncate(
345 rtems_libio_t *iop, /* IN */
346 off_t length /* IN */
347);
348
349int msdos_file_sync(rtems_libio_t *iop);
350
351ssize_t msdos_dir_read(
352 rtems_libio_t *iop, /* IN */
353 void *buffer, /* IN */
354 size_t count /* IN */
355);
356
357int msdos_dir_sync(rtems_libio_t *iop);
358
359int msdos_dir_stat(
361 struct stat *buf
362);
363
371 fat_file_type_t type,
372 const char *name,
373 int name_len,
374 mode_t mode,
375 fat_file_fd_t *link_fd);
376
377/* Misc prototypes */
378
379int msdos_find_name(
381 const char *name,
382 int name_len
383);
384
385int msdos_get_name_node(
386 const rtems_filesystem_location_info_t *parent_loc,
387 bool create_node,
388 const char *name,
389 int name_len,
390 msdos_name_type_t name_type,
391 fat_dir_pos_t *dir_pos,
392 char *name_dir_entry
393);
394
395int msdos_dir_info_remove(rtems_filesystem_location_info_t *pathloc);
396
397ssize_t
398msdos_format_dirent_with_dot(char *dst,const char *src);
399
400msdos_name_type_t msdos_long_to_short(rtems_dosfs_convert_control *converter,
401 const char *lfn, int lfn_len,
402 char* sfn, int sfn_len);
403
404ssize_t
405msdos_filename_utf8_to_short_name_for_compare (
407 const uint8_t *utf8_name,
408 const size_t utf8_name_size,
409 void *short_name,
410 const size_t short_name_size);
411
412ssize_t
413msdos_filename_utf8_to_short_name_for_save (
415 const uint8_t *utf8_name,
416 const size_t utf8_name_size,
417 void *short_name,
418 const size_t short_name_size);
419
420ssize_t
421msdos_filename_utf8_to_long_name_for_compare (
423 const uint8_t *utf8_name,
424 const size_t utf8_name_size,
425 uint8_t *long_name,
426 const size_t long_name_size);
427
428ssize_t
429msdos_filename_utf8_to_long_name_for_save (
431 const uint8_t *utf8_name,
432 const size_t utf8_name_size,
433 uint16_t *long_name,
434 const size_t long_name_size);
435
436ssize_t
437msdos_get_utf16_string_from_long_entry (
438 const char *entry,
439 uint16_t *entry_string_buf,
440 const size_t buf_size,
441 bool is_first_entry
442);
443
444void msdos_date_unix2dos(
445 unsigned int tsp, uint16_t *ddp,
446 uint16_t *dtp);
447
448unsigned int msdos_date_dos2unix(unsigned int dd, unsigned int dt);
449
450int msdos_set_first_char4file_name(
452 fat_dir_pos_t *dir_pos,
453 unsigned char first_char
454);
455
456int msdos_dir_is_empty(
458 fat_file_fd_t *fat_fd,
459 bool *ret_val
460);
461
462int msdos_find_name_in_fat_file(
464 fat_file_fd_t *fat_fd,
465 bool create_node,
466 const uint8_t *name_utf8,
467 int name_len,
468 msdos_name_type_t name_type,
469 fat_dir_pos_t *dir_pos,
470 char *name_dir_entry
471);
472
473int msdos_find_node_by_cluster_num_in_fat_file(
475 fat_file_fd_t *fat_fd,
476 uint32_t cl4find,
477 fat_dir_pos_t *dir_pos,
478 char *dir_entry
479);
480
481int msdos_get_dotdot_dir_info_cluster_num_and_offset(
483 uint32_t cln,
484 fat_dir_pos_t *dir_pos,
485 char *dir_entry
486);
487
488int msdos_sync(rtems_libio_t *iop);
489
490uint8_t msdos_lfn_checksum(const void *entry);
491
494#ifdef __cplusplus
495}
496#endif
497#endif /* __DOSFS_MSDOS_H__ */
Application Interface to FAT Filesystem.
Constants/Data Structures/Prototypes on a Volume with FAT Filesystem.
Constants/Data Structures/Prototypes for Operations on "fat-file".
int msdos_rename(const rtems_filesystem_location_info_t *old_parent_loc, const rtems_filesystem_location_info_t *old_loc, const rtems_filesystem_location_info_t *new_parent_loc, const char *new_name, size_t new_namelen)
Rename a MSDOS filesystem node.
Definition: msdos_rename.c:58
int msdos_initialize_support(rtems_filesystem_mount_table_entry_t *temp_mt_entry, const rtems_filesystem_operations_table *op_table, const rtems_filesystem_file_handlers_r *file_handlers, const rtems_filesystem_file_handlers_r *directory_handlers, rtems_dosfs_convert_control *converter)
MSDOS filesystem initialization routine.
Definition: msdos_initsupp.c:54
void msdos_free_node_info(const rtems_filesystem_location_info_t *pathloc)
Call the Fat-File close routine.
Definition: msdos_free.c:39
int msdos_mknod(const rtems_filesystem_location_info_t *loc, const char *name, size_t namelen, mode_t mode, dev_t dev)
Routine for node creation in a MSDOS filesystem.
Definition: msdos_mknod.c:40
void msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry)
Shut down the MSDOS filesystem.
Definition: msdos_fsunmount.c:49
int msdos_rmnod(const rtems_filesystem_location_info_t *parentloc, const rtems_filesystem_location_info_t *loc)
Remove node from MSDOS directory.
Definition: msdos_rmnod.c:27
int msdos_creat_node(const rtems_filesystem_location_info_t *parent_loc, fat_file_type_t type, const char *name, int name_len, mode_t mode, fat_file_fd_t *link_fd)
Implements wake up version of the "signal" operation.
Definition: msdos_create.c:64
LibIO Internal Interface.
This header file defines the RTEMS Classic API.
File system node operations table.
Definition: libio.h:1008
File system operations table.
Definition: libio.h:475
Definition: mmu-config.c:53
Definition: fat.h:383
Descriptor of a fat-file.
Definition: fat_file.h:76
Definition: fat.h:354
Definition: msdos.h:51
FAT filesystem convert control.
Definition: dosfs.h:201
Path evaluation context.
Definition: libio.h:105
File system location.
Definition: fs.h:72
Mount table entry.
Definition: libio.h:1661
An open file data structure.
Definition: libio.h:1325
Definition: statvfs.h:56
This header file provides the API of Self-Contained Objects.