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

4.115
Last change on this file since d61b0a5 was d61b0a5, checked in by Sebastian Huber <sebastian.huber@…>, on 05/07/12 at 14:15:57

Filesystem: PR1871: Fix O_APPEND

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