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
Line 
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
11 *  http://www.rtems.com/license/LICENSE.
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"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#define MSDOS_NAME_NOT_FOUND_ERR  0x7D01
27
28/*
29 * This structure identifies the instance of the filesystem on the MSDOS
30 * level.
31 */
32typedef struct msdos_fs_info_s
33{
34    fat_fs_info_t                     fat;                /*
35                                                           * volume
36                                                           * description
37                                                           */
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                                                            */
50    rtems_id                          vol_sema;           /*
51                                                           * semaphore
52                                                           * associated with
53                                                           * the volume
54                                                           */
55    uint8_t                          *cl_buf;              /*
56                                                            * just placeholder
57                                                            * for anything
58                                                            */
59} msdos_fs_info_t;
60
61/* a set of routines that handle the nodes which are directories */
62extern const rtems_filesystem_file_handlers_r  msdos_dir_handlers;
63
64/* a set of routines that handle the nodes which are files */
65extern const rtems_filesystem_file_handlers_r  msdos_file_handlers;
66
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
70
71/* Node types */
72#define MSDOS_DIRECTORY     RTEMS_FILESYSTEM_DIRECTORY
73#define MSDOS_REGULAR_FILE  RTEMS_FILESYSTEM_MEMORY_FILE
74#define MSDOS_HARD_LINK     RTEMS_FILESYSTEM_HARD_LINK /* pseudo type */
75
76typedef rtems_filesystem_node_types_t msdos_node_type_t;
77
78/*
79 * Macros for fetching fields from 32 bytes long FAT Directory Entry
80 * Structure
81 */
82#define MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE    32 /* 32 bytes */
83
84#define MSDOS_DIR_NAME(x)                 (char     *)((x) + 0)
85#define MSDOS_DIR_ENTRY_TYPE(x)           (uint8_t  *)((x) + 0)
86#define MSDOS_DIR_ATTR(x)                 (uint8_t  *)((x) + 11)
87#define MSDOS_DIR_NT_RES(x)               (uint8_t  *)((x) + 12)
88#define MSDOS_DIR_LFN_CHECKSUM(x)         (uint8_t  *)((x) + 13)
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)
98
99#define MSDOS_EXTRACT_CLUSTER_NUM(p)                                         \
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) )
102
103/*
104 * Fields offset in 32 bytes long FAT Directory Entry
105 * Structure
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
113#define MSDOS_FILE_ADATE_OFFSET           18
114
115/*
116 * Possible values of DIR_Attr field of 32 bytes long FAT Directory Entry
117 * Structure
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
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
138
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
154/*
155 * Possible values of DIR_Name[0] field of 32 bytes long FAT Directory Entry
156 * Structure
157 */
158#define MSDOS_THIS_DIR_ENTRY_EMPTY             0xE5
159#define MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY    0x00
160
161/*
162 * Number of characters per directory entry for a long filename.
163 */
164#define MSDOS_LFN_LEN_PER_ENTRY (13)
165
166/*
167 *  Macros for names parsing and formatting
168 */
169
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 */
174#define MSDOS_NAME_MAX_LNF_LEN           (255)
175#define MSDOS_NAME_MAX                   MSDOS_SHORT_NAME_LEN
176#define MSDOS_NAME_MAX_WITH_DOT          (MSDOS_NAME_MAX + 1)
177#define MSDOS_NAME_MAX_LFN_WITH_DOT      (260)
178
179
180extern const char *const MSDOS_DOT_NAME;    /* ".", padded to MSDOS_NAME chars */
181extern const char *const MSDOS_DOTDOT_NAME; /* ".", padded to MSDOS_NAME chars */
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;
189
190typedef enum msdos_token_types_e
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
213/* Size limits for files and directories */
214#define MSDOS_MAX_DIR_LENGHT               0x200000   /* 2,097,152 bytes */
215#define MSDOS_MAX_FILE_SIZE                0xFFFFFFFF /* 4 Gb */
216
217/*
218 * The number of 32 bytes long FAT Directory Entry
219 * Structures per 512 bytes sector
220 */
221#define MSDOS_DPS512_NUM    16
222
223/* Prototypes */
224void msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry);
225
226void msdos_eval_path(rtems_filesystem_eval_path_context_t *ctx);
227
228void msdos_free_node_info(const rtems_filesystem_location_info_t *pathloc);
229
230rtems_filesystem_node_types_t msdos_node_type(
231  const rtems_filesystem_location_info_t *loc
232);
233
234int msdos_mknod(
235  const rtems_filesystem_location_info_t *loc,
236  const char *name,
237  size_t namelen,
238  mode_t mode,
239  dev_t dev
240);
241
242int msdos_rmnod(
243  const rtems_filesystem_location_info_t *parentloc,
244  const rtems_filesystem_location_info_t *loc
245);
246
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
255void msdos_lock(const rtems_filesystem_mount_table_entry_t *mt_entry);
256
257void msdos_unlock(const rtems_filesystem_mount_table_entry_t *mt_entry);
258
259int msdos_initialize_support(
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
264);
265
266int msdos_file_close(rtems_libio_t *iop /* IN  */);
267
268ssize_t msdos_file_read(
269  rtems_libio_t *iop,              /* IN  */
270  void          *buffer,           /* IN  */
271  size_t         count             /* IN  */
272);
273
274ssize_t msdos_file_write(
275  rtems_libio_t *iop,             /* IN  */
276  const void    *buffer,          /* IN  */
277  size_t         count            /* IN  */
278);
279
280int msdos_file_stat(
281  const rtems_filesystem_location_info_t *loc,
282  struct stat *buf
283);
284
285int
286msdos_file_ftruncate(
287  rtems_libio_t *iop,               /* IN  */
288  off_t          length            /* IN  */
289);
290
291int msdos_file_sync(rtems_libio_t *iop);
292
293int msdos_file_datasync(rtems_libio_t *iop);
294
295ssize_t msdos_dir_read(
296  rtems_libio_t *iop,              /* IN  */
297  void          *buffer,           /* IN  */
298  size_t         count             /* IN  */
299);
300
301int msdos_dir_sync(rtems_libio_t *iop);
302
303int msdos_dir_stat(
304  const rtems_filesystem_location_info_t *loc,
305  struct stat *buf
306);
307
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);
314
315/* Misc prototypes */
316
317int msdos_find_name(
318  rtems_filesystem_location_info_t *parent_loc,
319  const char                       *name,
320  int                               name_len
321);
322
323int msdos_get_name_node(
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
331);
332
333int msdos_dir_info_remove(rtems_filesystem_location_info_t *pathloc);
334
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);
339
340void msdos_date_unix2dos(
341  unsigned int tsp, uint16_t *ddp,
342  uint16_t *dtp);
343
344unsigned int msdos_date_dos2unix(unsigned int dd, unsigned int dt);
345
346int msdos_set_first_cluster_num(
347  rtems_filesystem_mount_table_entry_t *mt_entry,
348  fat_file_fd_t                        *fat_fd
349);
350
351int msdos_set_file_size(
352  rtems_filesystem_mount_table_entry_t *mt_entry,
353  fat_file_fd_t                        *fat_fd
354);
355
356int msdos_set_first_char4file_name(
357  rtems_filesystem_mount_table_entry_t *mt_entry,
358  fat_dir_pos_t                        *dir_pos,
359  unsigned char                         first_char
360);
361
362int msdos_set_dir_wrt_time_and_date(
363    rtems_filesystem_mount_table_entry_t *mt_entry,
364    fat_file_fd_t                        *fat_fd
365);
366
367
368int msdos_dir_is_empty(
369  rtems_filesystem_mount_table_entry_t *mt_entry,
370  fat_file_fd_t                        *fat_fd,
371  bool                                 *ret_val
372);
373
374int msdos_find_name_in_fat_file(
375    rtems_filesystem_mount_table_entry_t *mt_entry,
376    fat_file_fd_t                        *fat_fd,
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,
382    char                                 *name_dir_entry
383);
384
385int msdos_find_node_by_cluster_num_in_fat_file(
386    rtems_filesystem_mount_table_entry_t *mt_entry,
387    fat_file_fd_t                        *fat_fd,
388    uint32_t                              cl4find,
389    fat_dir_pos_t                        *dir_pos,
390    char                                 *dir_entry
391);
392
393int msdos_get_dotdot_dir_info_cluster_num_and_offset(
394    rtems_filesystem_mount_table_entry_t *mt_entry,
395    uint32_t                              cln,
396    fat_dir_pos_t                        *dir_pos,
397    char                                 *dir_entry
398);
399
400int msdos_sync_unprotected(msdos_fs_info_t *fs_info);
401
402int msdos_sync(rtems_libio_t *iop);
403
404#ifdef __cplusplus
405}
406#endif
407
408#endif /* __DOSFS_MSDOS_H__ */
Note: See TracBrowser for help on using the repository browser.