RTEMS 7.0-rc1
Loading...
Searching...
No Matches
fat_file.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-with-RTEMS-exception */
2
11/*
12 *
13 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
14 * Author: Eugeny S. Mints <Eugeny.Mints@oktet.ru>
15 *
16 * The license and distribution terms for this file may be
17 * found in the file LICENSE in this distribution or at
18 * http://www.rtems.org/license/LICENSE.
19 */
20
21#ifndef __DOSFS_FAT_FILE_H__
22#define __DOSFS_FAT_FILE_H__
23
24#include <rtems.h>
25#include <rtems/libio_.h>
26
27#include <time.h>
28
29#include "fat.h"
30
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42typedef enum {
43 FAT_DIRECTORY = 0,
44 FAT_HARD_LINK = 2, /* pseudo type */
45 FAT_FILE = 4
46} fat_file_type_t;
47
63typedef struct fat_file_map_s
64{
65 uint32_t file_cln;
66 uint32_t disk_cln;
67 uint32_t last_cln;
69
75typedef struct fat_file_fd_s
76{
77 rtems_chain_node link; /*
78 * fat-file descriptors organized into hash;
79 * collision lists are handled via link
80 * field
81 */
82 uint32_t links_num; /*
83 * the number of fat_file_open call on
84 * this fat-file
85 */
86 uint32_t ino; /* inode, file serial number :)))) */
87 fat_file_type_t fat_file_type;
88 uint32_t size_limit;
89 uint32_t fat_file_size; /* length */
90 uint32_t cln;
91 fat_dir_pos_t dir_pos;
92 uint8_t flags;
94 time_t ctime;
95 time_t mtime;
96
98
99#define FAT_FILE_REMOVED 0x01
100
101#define FAT_FILE_META_DATA_CHANGED 0x02
102
103static inline bool FAT_FILE_IS_REMOVED(const fat_file_fd_t *fat_fd)
104{
105 return (fat_fd->flags & FAT_FILE_REMOVED) != 0;
106}
107
108static inline bool FAT_FILE_HAS_META_DATA_CHANGED(const fat_file_fd_t *fat_fd)
109{
110 return (fat_fd->flags & FAT_FILE_META_DATA_CHANGED) != 0;
111}
112
113/* ioctl macros */
114#define F_CLU_NUM 0x01
115
116/*
117 * Each file and directory on a MSDOS volume is unique identified by it
118 * location, i.e. location of it 32 Bytes Directory Entry Structure. We can
119 * distinguish them by cluster number it locates on and offset inside this
120 * cluster. But root directory on any volumes (FAT12/16/32) has no 32 Bytes
121 * Directory Entry Structure corresponded to it. So we assume 32 Bytes
122 * Directory Entry Structure of root directory locates at cluster 1 (invalid
123 * cluaster number) and offset 0
124 */
125#define FAT_ROOTDIR_CLUSTER_NUM 0x01
126
127#define FAT_FD_OF_ROOT_DIR(fat_fd) \
128 ((fat_fd->dir_pos.sname.cln == FAT_ROOTDIR_CLUSTER_NUM) && \
129 (fat_fd->dir_pos.sname.ofs == 0))
130
131#define FAT_EOF 0x00
132
133/* @brief Construct key for hash access.
134 *
135 * Construct key for hash access: convert (cluster num, offset) to
136 * (sector512 num, new offset) and than construct key as
137 * key = (sector512 num) << 4 | (new offset)
138 *
139 * @param[in] cl - cluster number
140 * @param[in] ofs - offset inside cluster 'cl'
141 * @param[in] fs_info - FS info
142 *
143 * @retval constructed key
144 */
145static inline uint32_t
146fat_construct_key(
147 const fat_fs_info_t *fs_info,
148 fat_pos_t *pos)
149{
150 return ( ((fat_cluster_num_to_sector512_num(fs_info, pos->cln) +
151 (pos->ofs >> FAT_SECTOR512_BITS)) << 4) +
152 ((pos->ofs >> 5) & (FAT_DIRENTRIES_PER_SEC512 - 1)) );
153}
154
155static inline void
156fat_file_set_first_cluster_num(fat_file_fd_t *fat_fd, uint32_t cln)
157{
158 fat_fd->cln = cln;
159 fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
160}
161
162static inline void fat_file_set_file_size(fat_file_fd_t *fat_fd, uint32_t s)
163{
164 fat_fd->fat_file_size = s;
165 fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
166}
167
168static inline void fat_file_set_ctime(fat_file_fd_t *fat_fd, time_t t)
169{
170 fat_fd->ctime = t;
171 fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
172}
173
174static inline void fat_file_set_mtime(fat_file_fd_t *fat_fd, time_t t)
175{
176 fat_fd->mtime = t;
177 fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
178}
179
180static inline void fat_file_set_ctime_mtime(fat_file_fd_t *fat_fd, time_t t)
181{
182 fat_fd->ctime = t;
183 fat_fd->mtime = t;
184 fat_fd->flags |= FAT_FILE_META_DATA_CHANGED;
185}
186
187/* Prototypes for "fat-file" operations */
188int
189fat_file_open(fat_fs_info_t *fs_info,
190 fat_dir_pos_t *dir_pos,
191 fat_file_fd_t **fat_fd);
192
193int
194fat_file_reopen(fat_file_fd_t *fat_fd);
195
196int
197fat_file_close(fat_fs_info_t *fs_info,
198 fat_file_fd_t *fat_fd);
199
200ssize_t
201fat_file_read(fat_fs_info_t *fs_info,
202 fat_file_fd_t *fat_fd,
203 uint32_t start,
204 uint32_t count,
205 uint8_t *buf);
206
207ssize_t
208fat_file_write(fat_fs_info_t *fs_info,
209 fat_file_fd_t *fat_fd,
210 uint32_t start,
211 uint32_t count,
212 const uint8_t *buf);
213
214int
215fat_file_extend(fat_fs_info_t *fs_info,
216 fat_file_fd_t *fat_fd,
217 bool zero_fill,
218 uint32_t new_length,
219 uint32_t *a_length);
220
221int
222fat_file_truncate(fat_fs_info_t *fs_info,
223 fat_file_fd_t *fat_fd,
224 uint32_t new_length);
225
226int
227fat_file_ioctl(fat_fs_info_t *fs_info,
228 fat_file_fd_t *fat_fd,
229 int cmd,
230 ...);
231
232int
233fat_file_size(fat_fs_info_t *fs_info,
234 fat_file_fd_t *fat_fd);
235
236void
237fat_file_mark_removed(fat_fs_info_t *fs_info,
238 fat_file_fd_t *fat_fd);
239
240int
241fat_file_size(fat_fs_info_t *fs_info,
242 fat_file_fd_t *fat_fd);
243
244int
245fat_file_write_first_cluster_num(fat_fs_info_t *fs_info,
246 fat_file_fd_t *fat_fd);
247
248int
249fat_file_write_file_size(fat_fs_info_t *fs_info,
250 fat_file_fd_t *fat_fd);
251
252int
253fat_file_write_time_and_date(fat_fs_info_t *fs_info,
254 fat_file_fd_t *fat_fd);
255
256int
257fat_file_update(fat_fs_info_t *fs_info,
258 fat_file_fd_t *fat_fd);
259
260int
261fat_file_get_new_inode_for(fat_fs_info_t *fs_info,
262 fat_dir_pos_t *new_dir_pos,
263 fat_file_fd_t *fat_fd);
264
265#ifdef __cplusplus
266}
267#endif
269#endif /* __DOSFS_FAT_FILE_H__ */
Constants/Data Structures/Prototypes on a Volume with FAT Filesystem.
struct fat_file_fd_s fat_file_fd_t
Descriptor of a fat-file.
struct fat_file_map_s fat_file_map_t
The "fat-file" representation.
LibIO Internal Interface.
This header file defines the RTEMS Classic API.
This structure represents a chain node.
Definition: chain.h:78
Definition: mm.c:62
Definition: fat.h:383
Descriptor of a fat-file.
Definition: fat_file.h:76
The "fat-file" representation.
Definition: fat_file.h:64
Definition: fat.h:354
Definition: fat.h:371