source: rtems/cpukit/libfs/src/dosfs/msdos.h @ 4ea97d24

4.115
Last change on this file since 4ea97d24 was d2e0bb3, checked in by Ralf Kirchner <ralf.kirchner@…>, on 05/22/13 at 10:16:18

dosfs: UTF-8 Support: UI, backwards compatibility

User interface and backwards compatibility for UTF-8 support in the FAT
file system. Purpose of UTF-8 support is to permit file names and
directory names with characters from all kinds of languages (Czech,
Chinese, Arabian, Hebrew, Korean, ...). This commit does not yet
support multibyte characters. It only contains the user interface and
the backwards compatibility.

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