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

4.115
Last change on this file since 7666afc was 7666afc, checked in by Sebastian Huber <sebastian.huber@…>, on 05/14/12 at 14:53:49

Filesystem: Add const qualifier to lock/unlock

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