OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libfs/] [src/] [dosfs/] [fat_file.h] - Blame information for rev 1026

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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
 *  @(#) fat_file.h,v 1.2 2002/03/28 13:52:49 joel Exp
14
 */
15
#ifndef __DOSFS_FAT_FILE_H__
16
#define __DOSFS_FAT_FILE_H__
17
 
18
#ifdef __cplusplus
19
extern "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
 
42
typedef 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
 
47
typedef 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
 */
58
typedef 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
 */
122
static inline unsigned32
123
fat_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 */
134
int
135
fat_file_open(rtems_filesystem_mount_table_entry_t  *mt_entry,
136
              unsigned32                             cln,
137
              unsigned32                             ofs,
138
              fat_file_fd_t                        **fat_fd);
139
 
140
int
141
fat_file_reopen(fat_file_fd_t *fat_fd);
142
 
143
int
144
fat_file_close(rtems_filesystem_mount_table_entry_t *mt_entry,
145
               fat_file_fd_t                        *fat_fd);
146
 
147
ssize_t
148
fat_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
 
154
ssize_t
155
fat_file_write(rtems_filesystem_mount_table_entry_t *mt_entry,
156
               fat_file_fd_t                        *fat_fd,
157
               unsigned32                            start,
158
               unsigned32                            count,
159
               const char                            *buf);
160
 
161
int
162
fat_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
 
167
int
168
fat_file_truncate(rtems_filesystem_mount_table_entry_t *mt_entry,
169
                  fat_file_fd_t                        *fat_fd,
170
                  unsigned32                            new_length);
171
 
172
int
173
fat_file_datasync(rtems_filesystem_mount_table_entry_t *mt_entry,
174
                  fat_file_fd_t                        *fat_fd);
175
 
176
 
177
int
178
fat_file_ioctl(rtems_filesystem_mount_table_entry_t *mt_entry,
179
               fat_file_fd_t                        *fat_fd,
180
               int                                   cmd,
181
               ...);
182
 
183
int
184
fat_file_size(rtems_filesystem_mount_table_entry_t *mt_entry,
185
              fat_file_fd_t                        *fat_fd);
186
 
187
void
188
fat_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__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.