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

4.104.114.84.95
Last change on this file since cd12590b was e197621, checked in by Joel Sherrill <joel.sherrill@…>, on 08/29/06 at 19:38:08

2006-08-29 Joel Sherrill <joel@…>

  • libfs/src/dosfs/fat.h, libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_eval.c, libfs/src/dosfs/msdos_file.c, libfs/src/dosfs/msdos_free.c, libfs/src/dosfs/msdos_fsunmount.c, libfs/src/dosfs/msdos_init.c, libfs/src/dosfs/msdos_misc.c, libfs/src/dosfs/msdos_mknod.c, libfs/src/imfs/imfs_debug.c: Remove warnings.
  • Property mode set to 100644
File size: 13.8 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  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    rtems_filesystem_file_handlers_r *directory_handlers; /*
41                                                           * a set of routines
42                                                           * that handles the
43                                                           * nodes of directory
44                                                           * type
45                                                           */
46    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 rtems_filesystem_file_handlers_r  msdos_dir_handlers;
65
66/* a set of routines that handle the nodes which are files */
67extern 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_ATTR(x)                 (uint8_t   *)((x) + 11)
88#define MSDOS_DIR_NT_RES(x)               (uint8_t   *)((x) + 12)
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
114/*
115 * Possible values of DIR_Attr field of 32 bytes long FAT Directory Entry
116 * Structure
117 */
118#define MSDOS_ATTR_READ_ONLY    0x01
119#define MSDOS_ATTR_HIDDEN       0x02
120#define MSDOS_ATTR_SYSTEM       0x04
121#define MSDOS_ATTR_VOLUME_ID    0x08
122#define MSDOS_ATTR_DIRECTORY    0x10
123#define MSDOS_ATTR_ARCHIVE      0x20
124
125#define MSDOS_DT_2SECONDS_MASK        0x1F    /* seconds divided by 2 */
126#define MSDOS_DT_2SECONDS_SHIFT       0
127#define MSDOS_DT_MINUTES_MASK         0x7E0   /* minutes */
128#define MSDOS_DT_MINUTES_SHIFT        5
129#define MSDOS_DT_HOURS_MASK           0xF800  /* hours */
130#define MSDOS_DT_HOURS_SHIFT          11
131
132#define MSDOS_DD_DAY_MASK             0x1F    /* day of month */
133#define MSDOS_DD_DAY_SHIFT            0
134#define MSDOS_DD_MONTH_MASK           0x1E0   /* month */
135#define MSDOS_DD_MONTH_SHIFT          5
136#define MSDOS_DD_YEAR_MASK            0xFE00  /* year - 1980 */
137#define MSDOS_DD_YEAR_SHIFT           9
138
139
140/*
141 * Possible values of DIR_Name[0] field of 32 bytes long FAT Directory Entry
142 * Structure
143 */
144#define MSDOS_THIS_DIR_ENTRY_EMPTY             0xE5
145#define MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY    0x00
146
147
148/*
149 *  Macros for names parsing and formatting
150 */
151#define msdos_is_valid_name_char(_ch)    (1)
152#define msdos_is_separator(_ch)          rtems_filesystem_is_separator(_ch)
153
154#define MSDOS_SHORT_BASE_LEN             8  /* 8 characters */
155#define MSDOS_SHORT_EXT_LEN              3  /* 3 characters */
156#define MSDOS_SHORT_NAME_LEN             (MSDOS_SHORT_BASE_LEN+\
157                                          MSDOS_SHORT_EXT_LEN) /* 11 chars */
158#define MSDOS_NAME_MAX                   MSDOS_SHORT_NAME_LEN
159#define MSDOS_NAME_MAX_WITH_DOT          (MSDOS_NAME_MAX + 1)
160
161#define MSDOS_DOT_NAME     ".          " /* ".", padded to MSDOS_NAME chars */
162#define MSDOS_DOTDOT_NAME  "..         " /* "..", padded to MSDOS_NAME chars */
163
164typedef enum msdos_token_types_e
165{
166    MSDOS_NO_MORE_PATH,
167    MSDOS_CURRENT_DIR,
168    MSDOS_UP_DIR,
169    MSDOS_NAME,
170    MSDOS_INVALID_TOKEN
171} msdos_token_types_t;
172
173/* Others macros */
174#define MSDOS_RES_NT_VALUE     0x00
175#define MSDOS_INIT_DIR_SIZE    0x00
176
177/* "dot" entry offset in a directory */
178#define MSDOS_DOT_DIR_ENTRY_OFFSET       0x00 /* first entry in directory */
179
180/* "dotdot" entry offset in a directory */
181#define MSDOS_DOTDOT_DIR_ENTRY_OFFSET    0x20 /* second entry in directory */
182
183/* 'p' should be char* */
184#define DOT_NODE_P(p)     ((char *)(p))
185#define DOTDOT_NODE_P(p)  ((char *)((p) + MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE))
186
187/* Size limits for files and directories */
188#define MSDOS_MAX_DIR_LENGHT               0x200000   /* 2,097,152 bytes */
189#define MSDOS_MAX_FILE_SIZE                0xFFFFFFFF /* 4 Gb */
190
191/*
192 * The number of 32 bytes long FAT Directory Entry
193 * Structures per 512 bytes sector
194 */
195#define MSDOS_DPS512_NUM    16
196
197/* Prototypes */
198int msdos_initialize(rtems_filesystem_mount_table_entry_t *temp_mt_entry);
199
200int msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry);
201
202int msdos_eval_path(
203  const char                       *pathname, /* IN */
204  int                               flags,    /* IN */
205  rtems_filesystem_location_info_t *pathloc   /* IN/OUT */
206);
207
208int msdos_eval4make(
209  const char                       *path,     /* IN */
210  rtems_filesystem_location_info_t *pathloc,  /* IN/OUT */
211  const char                       **name     /* OUT    */
212);
213
214int msdos_unlink(rtems_filesystem_location_info_t *pathloc /* IN */);
215
216int msdos_free_node_info(rtems_filesystem_location_info_t *pathloc /* IN */);
217
218int msdos_node_type(rtems_filesystem_location_info_t    *pathloc);
219
220int msdos_mknod(
221  const char                       *path,   /* IN */
222  mode_t                            mode,   /* IN */
223  dev_t                             dev,    /* IN */
224  rtems_filesystem_location_info_t *pathloc /* IN/OUT */
225);
226
227int msdos_utime(
228  rtems_filesystem_location_info_t *pathloc, /* IN */
229  time_t                            actime,  /* IN */
230  time_t                            modtime  /* IN */
231);
232
233int msdos_initialize_support(
234  rtems_filesystem_mount_table_entry_t *temp_mt_entry,
235  rtems_filesystem_operations_table    *op_table,
236  rtems_filesystem_file_handlers_r     *file_handlers,
237  rtems_filesystem_file_handlers_r     *directory_handlers
238);
239
240int msdos_file_open(
241  rtems_libio_t *iop,             /* IN  */
242  const char    *pathname,        /* IN  */
243  uint32_t       flag,            /* IN  */
244  uint32_t       mode             /* IN  */
245);
246
247int msdos_file_close(rtems_libio_t *iop /* IN  */);
248
249ssize_t msdos_file_read(
250  rtems_libio_t *iop,              /* IN  */
251  void          *buffer,           /* IN  */
252  uint32_t       count             /* IN  */
253);
254
255ssize_t msdos_file_write(
256  rtems_libio_t *iop,             /* IN  */
257  const void    *buffer,          /* IN  */
258  uint32_t       count            /* IN  */
259);
260
261int msdos_file_lseek(
262  rtems_libio_t        *iop,              /* IN  */
263  off_t                 offset,           /* IN  */
264  int                   whence            /* IN  */
265);
266
267int msdos_file_stat(
268  rtems_filesystem_location_info_t *loc, /* IN  */
269  struct stat                      *buf  /* OUT */
270);
271
272int
273msdos_file_ftruncate(
274  rtems_libio_t *iop,               /* IN  */
275  off_t          length             /* IN  */
276);
277
278int msdos_file_sync(rtems_libio_t *iop);
279
280int msdos_file_datasync(rtems_libio_t *iop);
281
282int msdos_file_ioctl(
283  rtems_libio_t *iop,             /* IN  */
284  uint32_t       command,         /* IN  */
285  void          *buffer           /* IN  */
286);
287
288int msdos_file_rmnod(rtems_filesystem_location_info_t *pathloc /* IN */);
289
290int msdos_file_link(
291  rtems_filesystem_location_info_t *to_loc,
292  rtems_filesystem_location_info_t *pa_loc,
293  const char                       *token
294);
295
296int msdos_dir_open(
297  rtems_libio_t *iop,             /* IN  */
298  const char    *pathname,        /* IN  */
299  uint32_t       flag,            /* IN  */
300  uint32_t       mode             /* IN  */
301);
302
303int msdos_dir_close(rtems_libio_t *iop /* IN  */);
304
305ssize_t msdos_dir_read(
306  rtems_libio_t *iop,              /* IN  */
307  void          *buffer,           /* IN  */
308  uint32_t       count             /* IN  */
309);
310
311int msdos_dir_lseek(
312  rtems_libio_t        *iop,              /* IN  */
313  off_t                 offset,           /* IN  */
314  int                   whence            /* IN  */
315);
316
317int msdos_dir_rmnod(rtems_filesystem_location_info_t *pathloc /* IN */);
318
319int msdos_dir_sync(rtems_libio_t *iop);
320
321int msdos_dir_stat(
322  rtems_filesystem_location_info_t *loc,         /* IN  */
323  struct stat                      *buf          /* OUT */
324);
325
326int msdos_creat_node(rtems_filesystem_location_info_t  *parent_loc,
327                 msdos_node_type_t                  type,
328                 char                              *name,
329                 mode_t                             mode,
330                 const fat_file_fd_t               *link_fd);
331
332/* Misc prototypes */
333msdos_token_types_t msdos_get_token(const char *path,
334                                    char       *token,
335                                    int        *token_len);
336
337int msdos_find_name(
338  rtems_filesystem_location_info_t *parent_loc,
339  char                             *name
340);
341
342int msdos_get_name_node(
343  rtems_filesystem_location_info_t *parent_loc,
344  char                             *name,
345  fat_auxiliary_t                  *paux,
346  char                             *name_dir_entry
347);
348
349int msdos_dir_info_remove(rtems_filesystem_location_info_t *pathloc);
350
351int msdos_filename_unix2dos(char *un, int unlen, char *dn);
352
353void msdos_date_unix2dos(
354  unsigned int tsp, unsigned short *ddp,
355  unsigned short *dtp);
356
357unsigned int msdos_date_dos2unix(unsigned int dd, unsigned int dt);
358
359int msdos_set_first_cluster_num(
360  rtems_filesystem_mount_table_entry_t *mt_entry,
361  fat_file_fd_t                        *fat_fd
362);
363
364int msdos_set_file_size(
365  rtems_filesystem_mount_table_entry_t *mt_entry,
366  fat_file_fd_t                        *fat_fd
367);
368
369int msdos_set_first_char4file_name(
370  rtems_filesystem_mount_table_entry_t *mt_entry,
371  uint32_t    cl,
372  uint32_t    ofs,
373  unsigned char first_char
374);
375
376int msdos_set_dir_wrt_time_and_date(
377    rtems_filesystem_mount_table_entry_t *mt_entry,
378    fat_file_fd_t                        *fat_fd
379);
380
381
382int msdos_dir_is_empty(
383  rtems_filesystem_mount_table_entry_t *mt_entry,
384  fat_file_fd_t                        *fat_fd,
385  rtems_boolean                        *ret_val
386);
387
388int msdos_find_name_in_fat_file(
389    rtems_filesystem_mount_table_entry_t *mt_entry,
390    fat_file_fd_t                        *fat_fd,
391    char                                 *name,
392    fat_auxiliary_t                      *paux,
393    char                                 *name_dir_entry
394);
395
396int msdos_find_node_by_cluster_num_in_fat_file(
397    rtems_filesystem_mount_table_entry_t *mt_entry,
398    fat_file_fd_t                        *fat_fd,
399    uint32_t                              cl4find,
400    fat_auxiliary_t                      *paux,
401    char                                 *dir_entry
402);
403
404int msdos_get_dotdot_dir_info_cluster_num_and_offset(
405    rtems_filesystem_mount_table_entry_t *mt_entry,
406    uint32_t                              cln,
407    fat_auxiliary_t                      *paux,
408    char                                 *dir_entry
409);
410
411#ifdef __cplusplus
412}
413#endif
414
415#endif /* __DOSFS_MSDOS_H__ */
Note: See TracBrowser for help on using the repository browser.