source: rtems/cpukit/libfs/src/dosfs/msdos.h @ 3efe749

5
Last change on this file since 3efe749 was 3efe749, checked in by Sebastian Huber <sebastian.huber@…>, on 03/14/17 at 08:36:07

dosfs: Add and use msdos_lfn_checksum()

Update #2929.

  • Property mode set to 100644
File size: 16.7 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.org/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/*
89 * Macros for fetching fields from 32 bytes long FAT Directory Entry
90 * Structure
91 */
92#define MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE    32 /* 32 bytes */
93
94#define MSDOS_DIR_NAME(x)                 (char     *)((x) + 0)
95#define MSDOS_DIR_ENTRY_TYPE(x)           (uint8_t  *)((x) + 0)
96#define MSDOS_DIR_ATTR(x)                 (uint8_t  *)((x) + 11)
97#define MSDOS_DIR_NT_RES(x)               (uint8_t  *)((x) + 12)
98#define MSDOS_DIR_LFN_CHECKSUM(x)         (uint8_t  *)((x) + 13)
99#define MSDOS_DIR_CRT_TIME_TENTH(x)       (uint8_t  *)((x) + 13)
100#define MSDOS_DIR_CRT_TIME(x)             (uint16_t *)((x) + 14)
101#define MSDOS_DIR_CRT_DATE(x)             (uint16_t *)((x) + 16)
102#define MSDOS_DIR_LAST_ACCESS_DATE(x)     (uint16_t *)((x) + 18)
103#define MSDOS_DIR_FIRST_CLUSTER_HI(x)     (uint16_t *)((x) + 20)
104#define MSDOS_DIR_WRITE_TIME(x)           (uint16_t *)((x) + 22)
105#define MSDOS_DIR_WRITE_DATE(x)           (uint16_t *)((x) + 24)
106#define MSDOS_DIR_FIRST_CLUSTER_LOW(x)    (uint16_t *)((x) + 26)
107#define MSDOS_DIR_FILE_SIZE(x)            (uint32_t *)((x) + 28)
108
109#define MSDOS_EXTRACT_CLUSTER_NUM(p)                                         \
110            (uint32_t)( (CF_LE_W(*MSDOS_DIR_FIRST_CLUSTER_LOW(p))) |       \
111                          ((uint32_t)(CF_LE_W((*MSDOS_DIR_FIRST_CLUSTER_HI(p))))<<16) )
112
113/*
114 * Fields offset in 32 bytes long FAT Directory Entry
115 * Structure
116 */
117#define MSDOS_FILE_SIZE_OFFSET            28
118#define MSDOS_FILE_NAME_OFFSET             0
119#define MSDOS_FIRST_CLUSTER_HI_OFFSET     20
120#define MSDOS_FIRST_CLUSTER_LOW_OFFSET    26
121#define MSDOS_FILE_WDATE_OFFSET           24
122#define MSDOS_FILE_WTIME_OFFSET           22
123#define MSDOS_FILE_ADATE_OFFSET           18
124#define MSDOS_FILE_CDATE_OFFSET           16
125#define MSDOS_FILE_CTIME_OFFSET           14
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#define MSDOS_NAME_MAX_UTF8_BYTES_PER_CHAR  4
182#define MSDOS_NAME_MIN_UTF8_BYTES_PER_CHAR  1
183
184#define MSDOS_SHORT_BASE_LEN             8  /* 8 characters */
185#define MSDOS_SHORT_EXT_LEN              3  /* 3 characters */
186#define MSDOS_SHORT_NAME_LEN             (MSDOS_SHORT_BASE_LEN+\
187                                          MSDOS_SHORT_EXT_LEN) /* 11 chars */
188#define MSDOS_NAME_MAX_LNF_LEN           (255)
189#define MSDOS_NAME_MAX                   MSDOS_SHORT_NAME_LEN
190#define MSDOS_NAME_MAX_UTF8_SFN_BYTES    (MSDOS_NAME_MAX *\
191                                         MSDOS_NAME_MAX_UTF8_BYTES_PER_CHAR)
192#define MSDOS_NAME_MAX_WITH_DOT          (MSDOS_NAME_MAX + 1)
193#define MSDOS_SFN_MAX_WITH_DOT_UTF8_BYTES (MSDOS_NAME_MAX_WITH_DOT *\
194                                           MSDOS_NAME_MAX_UTF8_BYTES_PER_CHAR)
195#define MSDOS_NAME_MAX_LFN_WITH_DOT      (260)
196
197#define MSDOS_NAME_LFN_BYTES_PER_CHAR    (2)
198#define MSDOS_NAME_MAX_LFN_BYTES         (MSDOS_NAME_MAX_LFN_WITH_DOT *\
199                                          MSDOS_NAME_LFN_BYTES_PER_CHAR)
200#define MSDOS_NAME_MAX_UTF8_LFN_BYTES    (MSDOS_NAME_MAX_LFN_WITH_DOT *\
201                                          MSDOS_NAME_MAX_UTF8_BYTES_PER_CHAR)
202#define MSDOS_ENTRY_LFN_UTF8_BYTES       (MSDOS_LFN_LEN_PER_ENTRY *\
203                                          MSDOS_NAME_MAX_UTF8_BYTES_PER_CHAR)
204
205extern const char *const MSDOS_DOT_NAME;    /* ".", padded to MSDOS_NAME chars */
206extern const char *const MSDOS_DOTDOT_NAME; /* ".", padded to MSDOS_NAME chars */
207
208typedef enum msdos_name_types_e
209{
210    MSDOS_NAME_INVALID = 0, /* Unknown name type. Has invalid characters. */
211    MSDOS_NAME_SHORT,       /* Name can be short. */
212    MSDOS_NAME_LONG         /* Name is long; cannot be short. */
213} msdos_name_type_t;
214
215typedef enum msdos_token_types_e
216{
217    MSDOS_NO_MORE_PATH,
218    MSDOS_CURRENT_DIR,
219    MSDOS_UP_DIR,
220    MSDOS_NAME,
221    MSDOS_INVALID_TOKEN
222} msdos_token_types_t;
223
224/* Others macros */
225#define MSDOS_RES_NT_VALUE     0x00
226#define MSDOS_INIT_DIR_SIZE    0x00
227
228/* "dot" entry offset in a directory */
229#define MSDOS_DOT_DIR_ENTRY_OFFSET       0x00 /* first entry in directory */
230
231/* "dotdot" entry offset in a directory */
232#define MSDOS_DOTDOT_DIR_ENTRY_OFFSET    0x20 /* second entry in directory */
233
234/* 'p' should be char* */
235#define DOT_NODE_P(p)     ((char *)(p))
236#define DOTDOT_NODE_P(p)  ((char *)((p) + MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE))
237
238/* Size limits for files and directories */
239#define MSDOS_MAX_DIR_LENGTH               0x200000   /* 2,097,152 bytes */
240#define MSDOS_MAX_FILE_SIZE                0xFFFFFFFF /* 4 Gb */
241
242/*
243 * The number of 32 bytes long FAT Directory Entry
244 * Structures per 512 bytes sector
245 */
246#define MSDOS_DPS512_NUM    16
247
248/**
249 *  @brief Shut down the MSDOS filesystem.
250 *
251 *  MSDOS shut down handler implementation
252 */
253void msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry);
254
255void msdos_eval_path(rtems_filesystem_eval_path_context_t *ctx);
256
257/**
258 *  @brief Call the Fat-File close routine.
259 *
260 *  Free node handler implementation for the filesystem operations table.
261 */
262void msdos_free_node_info(const rtems_filesystem_location_info_t *pathloc);
263
264/**
265 * @brief Routine for node creation in a MSDOS filesystem.
266 *
267 * MSDOS Directory Handlers Implementation
268 */
269int msdos_mknod(
270  const rtems_filesystem_location_info_t *loc,
271  const char *name,
272  size_t namelen,
273  mode_t mode,
274  dev_t dev
275);
276
277/**
278 * @brief Remove node from MSDOS directory.
279 *
280 * MSDOS Directory Handlers Implementation
281 */
282int msdos_rmnod(
283  const rtems_filesystem_location_info_t *parentloc,
284  const rtems_filesystem_location_info_t *loc
285);
286
287/**
288 * @brief Rename a MSDOS filesystem node.
289 *
290 * Routine to rename a MSDOS filesystem node
291 */
292int msdos_rename(
293  const rtems_filesystem_location_info_t *old_parent_loc,
294  const rtems_filesystem_location_info_t *old_loc,
295  const rtems_filesystem_location_info_t *new_parent_loc,
296  const char *new_name,
297  size_t new_namelen
298);
299
300int msdos_statvfs(
301  const rtems_filesystem_location_info_t *root_loc,
302  struct statvfs *sb);
303
304void msdos_lock(const rtems_filesystem_mount_table_entry_t *mt_entry);
305
306void msdos_unlock(const rtems_filesystem_mount_table_entry_t *mt_entry);
307
308/**
309 *  @brief MSDOS filesystem initialization routine.
310 *
311 *  MSDOS Initialization support routine implementation
312 */
313int msdos_initialize_support(
314  rtems_filesystem_mount_table_entry_t    *temp_mt_entry,
315  const rtems_filesystem_operations_table *op_table,
316  const rtems_filesystem_file_handlers_r  *file_handlers,
317  const rtems_filesystem_file_handlers_r  *directory_handlers,
318  rtems_dosfs_convert_control             *converter
319);
320
321ssize_t msdos_file_read(
322  rtems_libio_t *iop,              /* IN  */
323  void          *buffer,           /* IN  */
324  size_t         count             /* IN  */
325);
326
327ssize_t msdos_file_write(
328  rtems_libio_t *iop,             /* IN  */
329  const void    *buffer,          /* IN  */
330  size_t         count            /* IN  */
331);
332
333int msdos_file_stat(
334  const rtems_filesystem_location_info_t *loc,
335  struct stat *buf
336);
337
338int
339msdos_file_ftruncate(
340  rtems_libio_t *iop,               /* IN  */
341  off_t          length            /* IN  */
342);
343
344int msdos_file_sync(rtems_libio_t *iop);
345
346ssize_t msdos_dir_read(
347  rtems_libio_t *iop,              /* IN  */
348  void          *buffer,           /* IN  */
349  size_t         count             /* IN  */
350);
351
352int msdos_dir_sync(rtems_libio_t *iop);
353
354int msdos_dir_stat(
355  const rtems_filesystem_location_info_t *loc,
356  struct stat *buf
357);
358
359/**
360 * @brief Implements wake up version of the "signal" operation.
361 *
362 * Routine to create a new MSDOS filesystem node
363 *
364 */
365int msdos_creat_node(const rtems_filesystem_location_info_t *parent_loc,
366                     fat_file_type_t                         type,
367                     const char                             *name,
368                     int                                     name_len,
369                     mode_t                                  mode,
370                     const fat_file_fd_t                    *link_fd);
371
372/* Misc prototypes */
373
374int msdos_find_name(
375  rtems_filesystem_location_info_t *parent_loc,
376  const char                       *name,
377  int                               name_len
378);
379
380int msdos_get_name_node(
381  const rtems_filesystem_location_info_t *parent_loc,
382  bool                                    create_node,
383  const char                             *name,
384  int                                     name_len,
385  msdos_name_type_t                       name_type,
386  fat_dir_pos_t                          *dir_pos,
387  char                                   *name_dir_entry
388);
389
390int msdos_dir_info_remove(rtems_filesystem_location_info_t *pathloc);
391
392ssize_t
393msdos_format_dirent_with_dot(char *dst,const char *src);
394
395msdos_name_type_t msdos_long_to_short(rtems_dosfs_convert_control *converter,
396                                      const char *lfn, int lfn_len,
397                                      char* sfn, int sfn_len);
398
399ssize_t
400msdos_filename_utf8_to_short_name_for_compare (
401    rtems_dosfs_convert_control     *converter,
402    const uint8_t                   *utf8_name,
403    const size_t                     utf8_name_size,
404    void                            *short_name,
405    const size_t                     short_name_size);
406
407ssize_t
408msdos_filename_utf8_to_short_name_for_save (
409    rtems_dosfs_convert_control     *converter,
410    const uint8_t                   *utf8_name,
411    const size_t                     utf8_name_size,
412    void                            *short_name,
413    const size_t                     short_name_size);
414
415ssize_t
416msdos_filename_utf8_to_long_name_for_compare (
417    rtems_dosfs_convert_control     *converter,
418    const uint8_t                   *utf8_name,
419    const size_t                     utf8_name_size,
420    uint8_t                         *long_name,
421    const size_t                     long_name_size);
422
423ssize_t
424msdos_filename_utf8_to_long_name_for_save (
425    rtems_dosfs_convert_control     *converter,
426    const uint8_t                   *utf8_name,
427    const size_t                     utf8_name_size,
428    uint16_t                        *long_name,
429    const size_t                     long_name_size);
430
431ssize_t
432msdos_get_utf16_string_from_long_entry (
433  const char                 *entry,
434  uint16_t                   *entry_string_buf,
435  const size_t                buf_size,
436  bool                        is_first_entry
437);
438
439void msdos_date_unix2dos(
440  unsigned int tsp, uint16_t *ddp,
441  uint16_t *dtp);
442
443unsigned int msdos_date_dos2unix(unsigned int dd, unsigned int dt);
444
445int msdos_set_first_char4file_name(
446  rtems_filesystem_mount_table_entry_t *mt_entry,
447  fat_dir_pos_t                        *dir_pos,
448  unsigned char                         first_char
449);
450
451int msdos_dir_is_empty(
452  rtems_filesystem_mount_table_entry_t *mt_entry,
453  fat_file_fd_t                        *fat_fd,
454  bool                                 *ret_val
455);
456
457int msdos_find_name_in_fat_file(
458    rtems_filesystem_mount_table_entry_t *mt_entry,
459    fat_file_fd_t                        *fat_fd,
460    bool                                  create_node,
461    const uint8_t                        *name_utf8,
462    int                                   name_len,
463    msdos_name_type_t                     name_type,
464    fat_dir_pos_t                        *dir_pos,
465    char                                 *name_dir_entry
466);
467
468int msdos_find_node_by_cluster_num_in_fat_file(
469    rtems_filesystem_mount_table_entry_t *mt_entry,
470    fat_file_fd_t                        *fat_fd,
471    uint32_t                              cl4find,
472    fat_dir_pos_t                        *dir_pos,
473    char                                 *dir_entry
474);
475
476int msdos_get_dotdot_dir_info_cluster_num_and_offset(
477    rtems_filesystem_mount_table_entry_t *mt_entry,
478    uint32_t                              cln,
479    fat_dir_pos_t                        *dir_pos,
480    char                                 *dir_entry
481);
482
483int msdos_sync(rtems_libio_t *iop);
484
485uint8_t msdos_lfn_checksum(const void *entry);
486
487#ifdef __cplusplus
488}
489#endif
490/**@}*/
491#endif /* __DOSFS_MSDOS_H__ */
Note: See TracBrowser for help on using the repository browser.