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

4.104.114.84.95
Last change on this file since da6d75f was a72c454, checked in by Ralf Corsepius <ralf.corsepius@…>, on 08/05/05 at 10:38:05

Introduce msdos_status_t.

  • Property mode set to 100644
File size: 14.3 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#ifdef __cplusplus
19extern "C" {
20#endif
21
22#include <rtems.h>
23#include <rtems/libio_.h>
24
25#include "fat.h"
26#include "fat_file.h"
27
28#define MSDOS_NAME_NOT_FOUND_ERR  0xDD000001
29
30typedef uint32_t msdos_status_t;
31
32/*
33 * This structure identifies the instance of the filesystem on the MSDOS
34 * level.
35 */
36typedef struct msdos_fs_info_s
37{
38    fat_fs_info_t                     fat;                /*
39                                                           * volume
40                                                           * description
41                                                           */
42    rtems_filesystem_file_handlers_r *directory_handlers; /*
43                                                           * a set of routines
44                                                           * that handles the
45                                                           * nodes of directory
46                                                           * type
47                                                           */
48    rtems_filesystem_file_handlers_r *file_handlers;      /*
49                                                           * a set of routines
50                                                           * that handles the
51                                                           * nodes of file
52                                                           * type
53                                                           */
54    rtems_id                          vol_sema;           /*
55                                                           * semaphore
56                                                           * associated with
57                                                           * the volume
58                                                           */
59    uint8_t                          *cl_buf;              /*
60                                                            * just placeholder
61                                                            * for anything
62                                                            */
63} msdos_fs_info_t;
64
65/* a set of routines that handle the nodes which are directories */
66extern rtems_filesystem_file_handlers_r  msdos_dir_handlers;
67
68/* a set of routines that handle the nodes which are files */
69extern rtems_filesystem_file_handlers_r  msdos_file_handlers;
70
71/* Volume semaphore timeout value. This value can be changed to a number
72 * of ticks to help debugging or if you need such a  */
73#define MSDOS_VOLUME_SEMAPHORE_TIMEOUT    RTEMS_NO_TIMEOUT
74
75/* Node types */
76#define MSDOS_DIRECTORY     RTEMS_FILESYSTEM_DIRECTORY
77#define MSDOS_REGULAR_FILE  RTEMS_FILESYSTEM_MEMORY_FILE
78#define MSDOS_HARD_LINK     RTEMS_FILESYSTEM_HARD_LINK /* pseudo type */
79
80typedef rtems_filesystem_node_types_t msdos_node_type_t;
81
82/*
83 * Macros for fetching fields from 32 bytes long FAT Directory Entry
84 * Structure
85 */
86#define MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE    32 /* 32 bytes */
87
88#define MSDOS_DIR_NAME(x)                 (char      *)((x) + 0)
89#define MSDOS_DIR_ATTR(x)                 (uint8_t   *)((x) + 11)
90#define MSDOS_DIR_NT_RES(x)               (uint8_t   *)((x) + 12)
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
116/*
117 * Possible values of DIR_Attr field of 32 bytes long FAT Directory Entry
118 * Structure
119 */
120#define MSDOS_ATTR_READ_ONLY    0x01
121#define MSDOS_ATTR_HIDDEN       0x02
122#define MSDOS_ATTR_SYSTEM       0x04
123#define MSDOS_ATTR_VOLUME_ID    0x08
124#define MSDOS_ATTR_DIRECTORY    0x10
125#define MSDOS_ATTR_ARCHIVE      0x20
126
127#define MSDOS_DT_2SECONDS_MASK        0x1F    /* seconds divided by 2 */
128#define MSDOS_DT_2SECONDS_SHIFT       0
129#define MSDOS_DT_MINUTES_MASK         0x7E0   /* minutes */
130#define MSDOS_DT_MINUTES_SHIFT        5
131#define MSDOS_DT_HOURS_MASK           0xF800  /* hours */
132#define MSDOS_DT_HOURS_SHIFT          11
133
134#define MSDOS_DD_DAY_MASK             0x1F    /* day of month */
135#define MSDOS_DD_DAY_SHIFT            0
136#define MSDOS_DD_MONTH_MASK           0x1E0   /* month */
137#define MSDOS_DD_MONTH_SHIFT          5
138#define MSDOS_DD_YEAR_MASK            0xFE00  /* year - 1980 */
139#define MSDOS_DD_YEAR_SHIFT           9
140
141
142/*
143 * Possible values of DIR_Name[0] field of 32 bytes long FAT Directory Entry
144 * Structure
145 */
146#define MSDOS_THIS_DIR_ENTRY_EMPTY             0xE5
147#define MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY    0x00
148
149
150/*
151 *  Macros for names parsing and formatting
152 */
153#define msdos_is_valid_name_char(_ch)    (1)
154#define msdos_is_separator(_ch)          rtems_filesystem_is_separator(_ch)
155
156#define MSDOS_SHORT_BASE_LEN             8  /* 8 characters */
157#define MSDOS_SHORT_EXT_LEN              3  /* 3 characters */
158#define MSDOS_SHORT_NAME_LEN             (MSDOS_SHORT_BASE_LEN+\
159                                          MSDOS_SHORT_EXT_LEN) /* 11 chars */
160#define MSDOS_NAME_MAX                   MSDOS_SHORT_NAME_LEN
161#define MSDOS_NAME_MAX_WITH_DOT          (MSDOS_NAME_MAX + 1)
162
163#define MSDOS_DOT_NAME     ".          " /* ".", padded to MSDOS_NAME chars */
164#define MSDOS_DOTDOT_NAME  "..         " /* "..", padded to MSDOS_NAME chars */
165
166typedef enum msdos_token_types_e
167{
168    MSDOS_NO_MORE_PATH,
169    MSDOS_CURRENT_DIR,
170    MSDOS_UP_DIR,
171    MSDOS_NAME,
172    MSDOS_INVALID_TOKEN
173} msdos_token_types_t;
174
175/* Others macros */
176#define MSDOS_RES_NT_VALUE     0x00
177#define MSDOS_INIT_DIR_SIZE    0x00
178
179/* "dot" entry offset in a directory */
180#define MSDOS_DOT_DIR_ENTRY_OFFSET       0x00 /* first entry in directory */
181
182/* "dotdot" entry offset in a directory */
183#define MSDOS_DOTDOT_DIR_ENTRY_OFFSET    0x20 /* second entry in directory */
184
185/* 'p' should be char* */
186#define DOT_NODE_P(p)     ((char *)(p))
187#define DOTDOT_NODE_P(p)  ((char *)((p) + MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE))
188
189/* Size limits for files and directories */
190#define MSDOS_MAX_DIR_LENGHT               0x200000   /* 2,097,152 bytes */
191#define MSDOS_MAX_FILE_SIZE                0xFFFFFFFF /* 4 Gb */
192
193/*
194 * The number of 32 bytes long FAT Directory Entry
195 * Structures per 512 bytes sector
196 */
197#define MSDOS_DPS512_NUM    16
198
199/* Prototypes */
200msdos_status_t
201msdos_initialize(rtems_filesystem_mount_table_entry_t *temp_mt_entry);
202
203msdos_status_t
204msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry);
205
206msdos_status_t
207msdos_eval_path(const char                       *pathname, /* IN */
208                int                               flags,    /* IN */
209                rtems_filesystem_location_info_t *pathloc   /* IN/OUT */);
210
211msdos_status_t
212msdos_eval4make(const char                       *path,     /* IN */
213                rtems_filesystem_location_info_t *pathloc,  /* IN/OUT */
214                const char                       **name     /* OUT    */);
215
216int
217msdos_unlink(rtems_filesystem_location_info_t *pathloc /* IN */);
218
219msdos_status_t
220msdos_free_node_info(rtems_filesystem_location_info_t *pathloc /* IN */);
221
222rtems_filesystem_node_types_t
223msdos_node_type(rtems_filesystem_location_info_t    *pathloc);
224
225msdos_status_t
226msdos_mknod(const char                       *path,   /* IN */
227            mode_t                            mode,   /* IN */
228            dev_t                             dev,    /* IN */
229            rtems_filesystem_location_info_t *pathloc /* IN/OUT */);
230
231msdos_status_t
232msdos_utime(rtems_filesystem_location_info_t *pathloc, /* IN */
233            time_t                            actime,  /* IN */
234            time_t                            modtime  /* IN */);
235
236int
237msdos_initialize_support(
238  rtems_filesystem_mount_table_entry_t *temp_mt_entry,
239  rtems_filesystem_operations_table    *op_table,
240  rtems_filesystem_file_handlers_r     *file_handlers,
241  rtems_filesystem_file_handlers_r     *directory_handlers
242);
243
244int
245msdos_file_open(
246  rtems_libio_t *iop,             /* IN  */
247  const char    *pathname,        /* IN  */
248  uint32_t       flag,            /* IN  */
249  uint32_t       mode             /* IN  */
250);
251
252int
253msdos_file_close(rtems_libio_t *iop /* IN  */);
254
255ssize_t
256msdos_file_read(
257  rtems_libio_t *iop,              /* IN  */
258  void          *buffer,           /* IN  */
259  uint32_t       count             /* IN  */
260);
261
262ssize_t
263msdos_file_write(
264  rtems_libio_t *iop,             /* IN  */
265  const void    *buffer,          /* IN  */
266  uint32_t       count            /* IN  */
267);
268
269int
270msdos_file_lseek(
271  rtems_libio_t        *iop,              /* IN  */
272  off_t                 offset,           /* IN  */
273  int                   whence            /* IN  */
274);
275
276int
277msdos_file_stat(rtems_filesystem_location_info_t *loc, /* IN  */
278                struct stat                      *buf  /* OUT */);
279
280int
281msdos_file_ftruncate(
282  rtems_libio_t *iop,               /* IN  */
283  off_t          length             /* IN  */
284);
285
286int
287msdos_file_sync(rtems_libio_t *iop);
288
289int
290msdos_file_datasync(rtems_libio_t *iop);
291
292int
293msdos_file_ioctl(
294  rtems_libio_t *iop,             /* IN  */
295  uint32_t       command,         /* IN  */
296  void          *buffer           /* IN  */
297);
298
299msdos_status_t
300msdos_file_rmnod(rtems_filesystem_location_info_t *pathloc /* IN */);
301
302msdos_status_t
303msdos_file_link(rtems_filesystem_location_info_t *to_loc,
304                rtems_filesystem_location_info_t *pa_loc,
305                const char                       *token);
306
307int
308msdos_dir_open(
309  rtems_libio_t *iop,             /* IN  */
310  const char    *pathname,        /* IN  */
311  uint32_t       flag,            /* IN  */
312  uint32_t       mode             /* IN  */
313);
314
315int
316msdos_dir_close(rtems_libio_t *iop /* IN  */);
317
318ssize_t
319msdos_dir_read(
320  rtems_libio_t *iop,              /* IN  */
321  void          *buffer,           /* IN  */
322  uint32_t       count             /* IN  */
323);
324
325int
326msdos_dir_lseek(
327  rtems_libio_t        *iop,              /* IN  */
328  off_t                 offset,           /* IN  */
329  int                   whence            /* IN  */
330);
331
332int
333msdos_dir_rmnod(rtems_filesystem_location_info_t *pathloc /* IN */);
334
335int
336msdos_dir_sync(rtems_libio_t *iop);
337
338int
339msdos_dir_stat(
340  rtems_filesystem_location_info_t *loc,         /* IN  */
341  struct stat                      *buf          /* OUT */
342);
343
344int
345msdos_creat_node(rtems_filesystem_location_info_t  *parent_loc,
346                 msdos_node_type_t                  type,
347                 char                              *name,
348                 mode_t                             mode,
349                 const fat_file_fd_t               *link_fd);
350
351/* Misc prototypes */
352msdos_token_types_t msdos_get_token(const char *path,
353                                    char       *token,
354                                    int        *token_len);
355
356int
357msdos_find_name(rtems_filesystem_location_info_t *parent_loc,
358                char                             *name);
359
360msdos_status_t
361msdos_get_name_node(rtems_filesystem_location_info_t *parent_loc,
362                    char                             *name,
363                    fat_auxiliary_t                  *paux,
364                    char                             *name_dir_entry);
365
366int
367msdos_dir_info_remove(rtems_filesystem_location_info_t *pathloc);
368
369int
370msdos_filename_unix2dos(char *un, int unlen, char *dn);
371
372void
373msdos_date_unix2dos(unsigned int tsp, unsigned short *ddp,
374                    unsigned short *dtp);
375
376unsigned int
377msdos_date_dos2unix(unsigned int dd, unsigned int dt);
378
379int
380msdos_set_first_cluster_num(rtems_filesystem_mount_table_entry_t *mt_entry,
381                            fat_file_fd_t                        *fat_fd);
382
383int
384msdos_set_file_size(rtems_filesystem_mount_table_entry_t *mt_entry,
385                    fat_file_fd_t                        *fat_fd);
386
387int
388msdos_set_first_char4file_name(rtems_filesystem_mount_table_entry_t *mt_entry,
389                               uint32_t    cl,
390                               uint32_t    ofs,
391                               unsigned char first_char);
392
393int
394msdos_set_dir_wrt_time_and_date(
395    rtems_filesystem_mount_table_entry_t *mt_entry,
396    fat_file_fd_t                        *fat_fd
397);
398
399
400int
401msdos_dir_is_empty(rtems_filesystem_mount_table_entry_t *mt_entry,
402                   fat_file_fd_t                        *fat_fd,
403                   rtems_boolean                        *ret_val);
404
405msdos_status_t
406msdos_find_name_in_fat_file(
407    rtems_filesystem_mount_table_entry_t *mt_entry,
408    fat_file_fd_t                        *fat_fd,
409    char                                 *name,
410    fat_auxiliary_t                      *paux,
411    char                                 *name_dir_entry);
412
413msdos_status_t
414msdos_find_node_by_cluster_num_in_fat_file(
415    rtems_filesystem_mount_table_entry_t *mt_entry,
416    fat_file_fd_t                        *fat_fd,
417    uint32_t                              cl4find,
418    fat_auxiliary_t                      *paux,
419    char                                 *dir_entry
420);
421
422int
423msdos_get_dotdot_dir_info_cluster_num_and_offset(
424    rtems_filesystem_mount_table_entry_t *mt_entry,
425    uint32_t                              cln,
426    fat_auxiliary_t                      *paux,
427    char                                 *dir_entry
428);
429
430#ifdef __cplusplus
431}
432#endif
433
434#endif /* __DOSFS_MSDOS_H__ */
Note: See TracBrowser for help on using the repository browser.