source: rtems/c/src/exec/libfs/src/dosfs/fat_file.h @ f36a7bfc

4.104.114.84.95
Last change on this file since f36a7bfc was f36a7bfc, checked in by Joel Sherrill <joel.sherrill@…>, on 02/28/02 at 20:43:50

2002-02-28 Victor V. Vengerov <vvv@…>

  • DOS filesystem including FAT12, FAT16, and FAT32 support submitted.
  • src/dosfs, src/dosfs/Makefile.am, src/dosfs/stamp-h2.in, src/dosfs/config.h.in, src/dosfs/dosfs.h, src/dosfs/fat.c, src/dosfs/fat.h, src/dosfs/fat_fat_operations.c, src/dosfs/fat_fat_operations.h, src/dosfs/fat_file.c, src/dosfs/fat_file.h, src/dosfs/msdos.h, src/dosfs/msdos_create.c, src/dosfs/msdos_dir.c, src/dosfs/msdos_eval.c, src/dosfs/msdos_file.c, src/dosfs/msdos_free.c, src/dosfs/msdos_fsunmount.c, src/dosfs/msdos_handlers_dir.c, src/dosfs/msdos_handlers_file.c, src/dosfs/msdos_init.c, src/dosfs/msdos_initsupp.c, src/dosfs/msdos_misc.c, src/dosfs/msdos_mknod.c, src/dosfs/msdos_node_type.c, src/dosfs/.cvsignore: New files.
  • configure.ac, src/Makefile.am, wrapup/Makefile.am: Modified to reflect addition.
  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 *  fat_file.h
3 *
4 *  Constants/data structures/prototypes for operations on "fat-file"
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_FAT_FILE_H__
16#define __DOSFS_FAT_FILE_H__
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#include <rtems.h>
23#include <rtems/libio_.h>
24
25#include <time.h>
26
27/* "fat-file" representation
28 *
29 * the idea is: fat-file is nothing but a cluster chain, any open fat-file is
30 * represented in system by fat-file descriptor and has well-known
31 * file interface:
32 *
33 * fat_file_open()
34 * fat_file_close()
35 * fat_file_read()
36 * fat_file_write()
37 *
38 * Such interface hides the architecture of fat-file and represents it like
39 * linear file
40 */
41 
42typedef rtems_filesystem_node_types_t fat_file_type_t;
43
44#define FAT_DIRECTORY     RTEMS_FILESYSTEM_DIRECTORY
45#define FAT_FILE          RTEMS_FILESYSTEM_MEMORY_FILE
46
47typedef struct fat_file_map_s
48{
49    unsigned32 file_cln;
50    unsigned32 disk_cln;
51    unsigned32 last_cln;
52} fat_file_map_t;
53/*
54 * descriptor of a fat-file
55 *
56 * To each particular clusters chain
57 */
58typedef struct fat_file_fd_s
59{
60    Chain_Node      link;          /* 
61                                    * fat-file descriptors organized into hash;
62                                    * collision lists are handled via link
63                                    * field
64                                    */
65    unsigned32      links_num;     /*
66                                    * the number of fat_file_open call on
67                                    * this fat-file
68                                    */
69    unsigned32      ino;           /* inode, file serial number :)))) */                               
70    fat_file_type_t fat_file_type;
71    unsigned32      size_limit;
72    unsigned32      fat_file_size; /* length  */
73    unsigned32      info_cln;
74    unsigned32      cln;
75    unsigned16      info_ofs;     
76    unsigned char   first_char;
77    unsigned8       flags;
78    fat_file_map_t  map;
79    time_t          mtime;
80   
81} fat_file_fd_t;
82
83
84#define FAT_FILE_REMOVED  0x01
85
86#define FAT_FILE_IS_REMOVED(p)\
87    (((p)->flags & FAT_FILE_REMOVED) ? 1 : 0)
88
89/* ioctl macros */
90#define F_CLU_NUM  0x01
91
92/*
93 * Each file and directory on a MSDOS volume is unique identified by it
94 * location, i.e. location of it 32 Bytes Directory Entry Structure. We can
95 * distinguish them by cluster number it locates on and offset inside this
96 * cluster. But root directory on any volumes (FAT12/16/32) has no 32 Bytes
97 * Directory Entry Structure corresponded to it. So we assume 32 Bytes
98 * Directory Entry Structure of root directory locates at cluster 1 (invalid
99 * cluaster number) and offset 0
100 */
101#define FAT_ROOTDIR_CLUSTER_NUM 0x01
102
103#define FAT_FD_OF_ROOT_DIR(fat_fd)  \
104  ((fat_fd->info_cln == FAT_ROOTDIR_CLUSTER_NUM ) && \
105  (fat_fd->info_ofs == 0))
106
107#define FAT_EOF           0x00
108
109/* fat_construct_key --
110 *     Construct key for hash access: convert (cluster num, offset) to
111 *     (sector512 num, new offset) and than construct key as
112 *     key = (sector512 num) << 4 | (new offset)
113 *
114 * PARAMETERS:
115 *     cl       - cluster number
116 *     ofs      - offset inside cluster 'cl'
117 *     mt_entry - mount table entry
118 *
119 * RETURNS:
120 *     constructed key
121 */
122static inline unsigned32
123fat_construct_key(
124    rtems_filesystem_mount_table_entry_t *mt_entry,
125    unsigned32                            cl,
126    unsigned32                            ofs)
127{
128    return ( ((fat_cluster_num_to_sector512_num(mt_entry, cl) +
129              (ofs >> FAT_SECTOR512_BITS)) << 4)              +
130              ((ofs >> 5) & (FAT_DIRENTRIES_PER_SEC512 - 1)) );
131}
132
133/* Prototypes for "fat-file" operations */
134int
135fat_file_open(rtems_filesystem_mount_table_entry_t  *mt_entry,
136              unsigned32                             cln,
137              unsigned32                             ofs,
138              fat_file_fd_t                        **fat_fd);
139
140int
141fat_file_reopen(fat_file_fd_t *fat_fd);
142
143int
144fat_file_close(rtems_filesystem_mount_table_entry_t *mt_entry,
145               fat_file_fd_t                        *fat_fd);
146
147ssize_t
148fat_file_read(rtems_filesystem_mount_table_entry_t *mt_entry,
149              fat_file_fd_t                        *fat_fd,
150              unsigned32                            start,
151              unsigned32                            count,
152              char                                 *buf);
153
154ssize_t
155fat_file_write(rtems_filesystem_mount_table_entry_t *mt_entry,
156               fat_file_fd_t                        *fat_fd,
157               unsigned32                            start,
158               unsigned32                            count,
159               char                                 *buf);
160
161int
162fat_file_extend(rtems_filesystem_mount_table_entry_t *mt_entry,
163                fat_file_fd_t                        *fat_fd,
164                unsigned32                            new_length,
165                unsigned32                           *a_length);
166
167int
168fat_file_truncate(rtems_filesystem_mount_table_entry_t *mt_entry,
169                  fat_file_fd_t                        *fat_fd,
170                  unsigned32                            new_length);
171                 
172int
173fat_file_datasync(rtems_filesystem_mount_table_entry_t *mt_entry,
174                  fat_file_fd_t                        *fat_fd);
175                 
176
177int
178fat_file_ioctl(rtems_filesystem_mount_table_entry_t *mt_entry,
179               fat_file_fd_t                        *fat_fd,
180               int                                   cmd,
181               ...);
182
183int
184fat_file_size(rtems_filesystem_mount_table_entry_t *mt_entry,
185              fat_file_fd_t                        *fat_fd);
186
187void
188fat_file_mark_removed(rtems_filesystem_mount_table_entry_t *mt_entry,
189                      fat_file_fd_t                        *fat_fd);
190
191#ifdef __cplusplus
192}
193#endif
194
195#endif /* __DOSFS_FAT_FILE_H__ */
Note: See TracBrowser for help on using the repository browser.