source: rtems/cpukit/libfs/src/dosfs/fat_file.h @ f91bbe64

4.104.114.84.95
Last change on this file since f91bbe64 was f91bbe64, checked in by Ralf Corsepius <ralf.corsepius@…>, on Mar 22, 2004 at 5:10:43 PM

2004-03-22 Ralf Corsepius <ralf_corsepius@…>

  • libfs/src/dosfs/fat.c, libfs/src/dosfs/fat.h, libfs/src/dosfs/fat_fat_operations.c, libfs/src/dosfs/fat_fat_operations.h, libfs/src/dosfs/fat_file.c, libfs/src/dosfs/fat_file.h, libfs/src/dosfs/msdos.h, libfs/src/dosfs/msdos_create.c, libfs/src/dosfs/msdos_dir.c, libfs/src/dosfs/msdos_file.c, libfs/src/dosfs/msdos_initsupp.c, libfs/src/dosfs/msdos_misc.c, libfs/src/imfs/deviceio.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_directory.c, libfs/src/imfs/imfs_fchmod.c, libfs/src/imfs/linearfile.c, libfs/src/imfs/memfile.c: Convert to using c99 fixed-size types.
  • 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.rtems.com/license/LICENSE.
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    uint32_t   file_cln;
50    uint32_t   disk_cln;
51    uint32_t   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    uint32_t        links_num;     /*
66                                    * the number of fat_file_open call on
67                                    * this fat-file
68                                    */
69    uint32_t        ino;           /* inode, file serial number :)))) */                               
70    fat_file_type_t fat_file_type;
71    uint32_t        size_limit;
72    uint32_t        fat_file_size; /* length  */
73    uint32_t        info_cln;
74    uint32_t        cln;
75    uint16_t        info_ofs;     
76    unsigned char   first_char;
77    uint8_t         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 uint32_t   
123fat_construct_key(
124    rtems_filesystem_mount_table_entry_t *mt_entry,
125    uint32_t                              cl, 
126    uint32_t                              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              uint32_t                               cln, 
137              uint32_t                               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              uint32_t                              start,
151              uint32_t                              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               uint32_t                              start,
158               uint32_t                              count,
159               const char                            *buf);
160
161int
162fat_file_extend(rtems_filesystem_mount_table_entry_t *mt_entry,
163                fat_file_fd_t                        *fat_fd,
164                uint32_t                              new_length,
165                uint32_t                             *a_length);
166
167int
168fat_file_truncate(rtems_filesystem_mount_table_entry_t *mt_entry,
169                  fat_file_fd_t                        *fat_fd,
170                  uint32_t                              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.