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

4.104.114.84.95
Last change on this file since 1679a7b was 1679a7b, checked in by Chris Johns <chrisj@…>, on 07/14/03 at 23:13:24

MSDOS Volume semaphore timeout is now NO TIMEOUT. MSDOS volume opertations will wait for ever.

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