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

4.115
Last change on this file since c625a641 was c625a641, checked in by Sebastian Huber <sebastian.huber@…>, on 12/21/14 at 19:12:28

Filesystem: Delete node type operation

Use the fstat handler instead.

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