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

4.115
Last change on this file since c625a641 was c625a641, checked in by Sebastian Huber <sebastian.huber@…>, on Dec 21, 2014 at 7:12:28 PM

Filesystem: Delete node type operation

Use the fstat handler instead.

  • Property mode set to 100644
File size: 7.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Constants/Data Structures/Prototypes for Operations on "fat-file"
5 *
6 * @ingroup libfs_ff
7 */
8
9/*
10 *
11 *  Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
12 *  Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef __DOSFS_FAT_FILE_H__
20#define __DOSFS_FAT_FILE_H__
21
22#include <rtems.h>
23#include <rtems/libio_.h>
24
25#include <time.h>
26
27#include "fat.h"
28
29/**
30 *  @defgroup libfs_ff Fat File
31 *
32 *  @ingroup libfs
33 */
34/**@{*/
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40typedef enum {
41  FAT_DIRECTORY = 0,
42  FAT_FILE = 4
43} fat_file_type_t;
44
45/**
46 * @brief The "fat-file" representation.
47 *
48 * the idea is: fat-file is nothing but a cluster chain, any open fat-file is
49 * represented in system by fat-file descriptor and has well-known
50 * file interface:
51 *
52 * fat_file_open()
53 * fat_file_close()
54 * fat_file_read()
55 * fat_file_write()
56 *
57 * Such interface hides the architecture of fat-file and represents it like
58 * linear file
59 */
60typedef struct fat_file_map_s
61{
62    uint32_t   file_cln;
63    uint32_t   disk_cln;
64    uint32_t   last_cln;
65} fat_file_map_t;
66
67/**
68 * @brief Descriptor of a fat-file.
69 *
70 * To each particular clusters chain
71 */
72typedef struct fat_file_fd_s
73{
74    rtems_chain_node link;          /*
75                                     * fat-file descriptors organized into hash;
76                                     * collision lists are handled via link
77                                     * field
78                                     */
79    uint32_t         links_num;     /*
80                                     * the number of fat_file_open call on
81                                     * this fat-file
82                                     */
83    uint32_t         ino;           /* inode, file serial number :)))) */
84    fat_file_type_t  fat_file_type;
85    uint32_t         size_limit;
86    uint32_t         fat_file_size; /* length  */
87    uint32_t         cln;
88    fat_dir_pos_t    dir_pos;
89    uint8_t          flags;
90    fat_file_map_t   map;
91    time_t           ctime;
92    time_t           mtime;
93
94} fat_file_fd_t;
95
96#define FAT_FILE_REMOVED 0x01
97
98#define FAT_FILE_META_DATA_CHANGED 0x02
99
100static inline bool FAT_FILE_IS_REMOVED(const fat_file_fd_t *fat_fd)
101{
102     return (fat_fd->flags & FAT_FILE_REMOVED) != 0;
103}
104
105static inline bool FAT_FILE_HAS_META_DATA_CHANGED(const fat_file_fd_t *fat_fd)
106{
107     return (fat_fd->flags & FAT_FILE_META_DATA_CHANGED) != 0;
108}
109
110/* ioctl macros */
111#define F_CLU_NUM  0x01
112
113/*
114 * Each file and directory on a MSDOS volume is unique identified by it
115 * location, i.e. location of it 32 Bytes Directory Entry Structure. We can
116 * distinguish them by cluster number it locates on and offset inside this
117 * cluster. But root directory on any volumes (FAT12/16/32) has no 32 Bytes
118 * Directory Entry Structure corresponded to it. So we assume 32 Bytes
119 * Directory Entry Structure of root directory locates at cluster 1 (invalid
120 * cluaster number) and offset 0
121 */
122#define FAT_ROOTDIR_CLUSTER_NUM 0x01
123
124#define FAT_FD_OF_ROOT_DIR(fat_fd)  \
125  ((fat_fd->dir_pos.sname.cln == FAT_ROOTDIR_CLUSTER_NUM) && \
126  (fat_fd->dir_pos.sname.ofs == 0))
127
128#define FAT_EOF           0x00
129
130/* @brief Construct key for hash access.
131 *
132 * Construct key for hash access: convert (cluster num, offset) to
133 * (sector512 num, new offset) and than construct key as
134 * key = (sector512 num) << 4 | (new offset)
135 *
136 * @param[in] cl - cluster number
137 * @param[in] ofs - offset inside cluster 'cl'
138 * @param[in] fs_info - FS info
139 *
140 * @retval constructed key
141 */
142static inline uint32_t
143fat_construct_key(
144    const fat_fs_info_t                  *fs_info,
145    fat_pos_t                            *pos)
146{
147    return ( ((fat_cluster_num_to_sector512_num(fs_info, pos->cln) +
148              (pos->ofs >> FAT_SECTOR512_BITS)) << 4)              +
149              ((pos->ofs >> 5) & (FAT_DIRENTRIES_PER_SEC512 - 1)) );
150}
151
152static inline void
153fat_file_set_first_cluster_num(fat_file_fd_t *fat_fd, uint32_t cln)
154{
155    fat_fd->cln = cln;
156    fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
157}
158
159static inline void fat_file_set_file_size(fat_file_fd_t *fat_fd, uint32_t s)
160{
161    fat_fd->fat_file_size = s;
162    fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
163}
164
165static inline void fat_file_set_ctime(fat_file_fd_t *fat_fd, time_t t)
166{
167    fat_fd->ctime = t;
168    fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
169}
170
171static inline void fat_file_set_mtime(fat_file_fd_t *fat_fd, time_t t)
172{
173    fat_fd->mtime = t;
174    fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
175}
176
177static inline void fat_file_set_ctime_mtime(fat_file_fd_t *fat_fd, time_t t)
178{
179    fat_fd->ctime = t;
180    fat_fd->mtime = t;
181    fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
182}
183
184/* Prototypes for "fat-file" operations */
185int
186fat_file_open(fat_fs_info_t                         *fs_info,
187              fat_dir_pos_t                         *dir_pos,
188              fat_file_fd_t                        **fat_fd);
189
190int
191fat_file_reopen(fat_file_fd_t *fat_fd);
192
193int
194fat_file_close(fat_fs_info_t                        *fs_info,
195               fat_file_fd_t                        *fat_fd);
196
197ssize_t
198fat_file_read(fat_fs_info_t                        *fs_info,
199              fat_file_fd_t                        *fat_fd,
200              uint32_t                              start,
201              uint32_t                              count,
202              uint8_t                              *buf);
203
204ssize_t
205fat_file_write(fat_fs_info_t                        *fs_info,
206               fat_file_fd_t                        *fat_fd,
207               uint32_t                              start,
208               uint32_t                              count,
209               const uint8_t                        *buf);
210
211int
212fat_file_extend(fat_fs_info_t                        *fs_info,
213                fat_file_fd_t                        *fat_fd,
214                bool                                  zero_fill,
215                uint32_t                              new_length,
216                uint32_t                             *a_length);
217
218int
219fat_file_truncate(fat_fs_info_t                        *fs_info,
220                  fat_file_fd_t                        *fat_fd,
221                  uint32_t                              new_length);
222
223int
224fat_file_ioctl(fat_fs_info_t                        *fs_info,
225               fat_file_fd_t                        *fat_fd,
226               int                                   cmd,
227               ...);
228
229int
230fat_file_size(fat_fs_info_t                        *fs_info,
231              fat_file_fd_t                        *fat_fd);
232
233void
234fat_file_mark_removed(fat_fs_info_t                        *fs_info,
235                      fat_file_fd_t                        *fat_fd);
236
237int
238fat_file_size(fat_fs_info_t                        *fs_info,
239              fat_file_fd_t                        *fat_fd);
240
241int
242fat_file_write_first_cluster_num(fat_fs_info_t *fs_info,
243                                 fat_file_fd_t *fat_fd);
244
245int
246fat_file_write_file_size(fat_fs_info_t *fs_info,
247                         fat_file_fd_t *fat_fd);
248
249int
250fat_file_write_time_and_date(fat_fs_info_t *fs_info,
251                             fat_file_fd_t *fat_fd);
252
253int
254fat_file_update(fat_fs_info_t *fs_info,
255                fat_file_fd_t *fat_fd);
256
257#ifdef __cplusplus
258}
259#endif
260/**@}*/
261#endif /* __DOSFS_FAT_FILE_H__ */
Note: See TracBrowser for help on using the repository browser.