1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS File Systems Group Management |
---|
5 | * |
---|
6 | * @ingroup rtems_rfs |
---|
7 | * |
---|
8 | * RTEMS File Systems Group Management. |
---|
9 | * |
---|
10 | * These functions manage the groups used in the file system. |
---|
11 | */ |
---|
12 | |
---|
13 | /* |
---|
14 | * COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org> |
---|
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.com/license/LICENSE. |
---|
19 | */ |
---|
20 | |
---|
21 | |
---|
22 | #if !defined (_RTEMS_RFS_GROUP_H_) |
---|
23 | #define _RTEMS_RFS_GROUP_H_ |
---|
24 | |
---|
25 | /** |
---|
26 | * @ingroup rtems_rfs |
---|
27 | * |
---|
28 | * RTEMS File System Group Management |
---|
29 | */ |
---|
30 | /**@{*/ |
---|
31 | |
---|
32 | #include <rtems/rfs/rtems-rfs-trace.h> |
---|
33 | #include <rtems/rfs/rtems-rfs-bitmaps.h> |
---|
34 | #include <rtems/rfs/rtems-rfs-buffer.h> |
---|
35 | |
---|
36 | /** |
---|
37 | * Block allocations for a group on disk. |
---|
38 | */ |
---|
39 | #define RTEMS_RFS_GROUP_BLOCK_BITMAP_BLOCK (0) |
---|
40 | #define RTEMS_RFS_GROUP_INODE_BITMAP_BLOCK (1) |
---|
41 | #define RTEMS_RFS_GROUP_INODE_BLOCK (2) |
---|
42 | |
---|
43 | /** |
---|
44 | * @brief Creates bit allocator for blocks in the group simpler. |
---|
45 | * |
---|
46 | * A group is a selection of blocks on the disk. Typically the number of blocks |
---|
47 | * in a group is determined by the number of bits a block holds. This makes the |
---|
48 | * bit allocator for blocks in the group simpler plus is allows a simple way to |
---|
49 | * localise access to files and directories. |
---|
50 | */ |
---|
51 | typedef struct _rtems_rfs_group |
---|
52 | { |
---|
53 | /** |
---|
54 | * Base block number. |
---|
55 | */ |
---|
56 | rtems_rfs_buffer_block base; |
---|
57 | |
---|
58 | /** |
---|
59 | * The number of blocks in the group. Groups may be different sizes. |
---|
60 | */ |
---|
61 | size_t size; |
---|
62 | |
---|
63 | /** |
---|
64 | * The block bitmap control. |
---|
65 | */ |
---|
66 | rtems_rfs_bitmap_control block_bitmap; |
---|
67 | |
---|
68 | /** |
---|
69 | * The handle to the block bitmap buffer. |
---|
70 | */ |
---|
71 | rtems_rfs_buffer_handle block_bitmap_buffer; |
---|
72 | |
---|
73 | /** |
---|
74 | * The inode bitmap control. |
---|
75 | */ |
---|
76 | rtems_rfs_bitmap_control inode_bitmap; |
---|
77 | |
---|
78 | /** |
---|
79 | * The handle to the inode bitmap buffer. |
---|
80 | */ |
---|
81 | rtems_rfs_buffer_handle inode_bitmap_buffer; |
---|
82 | |
---|
83 | } rtems_rfs_group; |
---|
84 | |
---|
85 | /** |
---|
86 | * Return the disk's block for a block in a group. |
---|
87 | */ |
---|
88 | #define rtems_rfs_group_block(_g, _b) (((_g)->base) + (_b)) |
---|
89 | |
---|
90 | /** |
---|
91 | * Return the file system inode for a inode in a group. |
---|
92 | */ |
---|
93 | #define rtems_rfs_group_inode(_f, _g, _i) \ |
---|
94 | (((_f)->group_inodes * (_g)) + (_i) + RTEMS_RFS_ROOT_INO) |
---|
95 | |
---|
96 | /** |
---|
97 | * @brief Open a group. |
---|
98 | * |
---|
99 | * Allocate all the resources including the bitmaps. |
---|
100 | * |
---|
101 | * @param fs The file system. |
---|
102 | * @param base The base block number. |
---|
103 | * @param size The number of blocks in the group. |
---|
104 | * @param group Reference to the group to open. |
---|
105 | * @retval int The error number (errno). No error if 0. |
---|
106 | */ |
---|
107 | int rtems_rfs_group_open (rtems_rfs_file_system* fs, |
---|
108 | rtems_rfs_buffer_block base, |
---|
109 | size_t size, |
---|
110 | size_t inodes, |
---|
111 | rtems_rfs_group* group); |
---|
112 | |
---|
113 | /** |
---|
114 | * @brief Close a group. |
---|
115 | * |
---|
116 | * Release all resources the group holds. |
---|
117 | * |
---|
118 | * @param fs The file system. |
---|
119 | * @param group The group to close. |
---|
120 | * @retval int The error number (errno). No error if 0. |
---|
121 | */ |
---|
122 | int rtems_rfs_group_close (rtems_rfs_file_system* fs, |
---|
123 | rtems_rfs_group* group); |
---|
124 | |
---|
125 | /** |
---|
126 | * @brief Allocate an inode or block. |
---|
127 | * |
---|
128 | * The groups are searched to find the next |
---|
129 | * available inode or block. |
---|
130 | * |
---|
131 | * @param fs The file system data. |
---|
132 | * @param goal The goal to seed the bitmap search. |
---|
133 | * @param inode If true allocate an inode else allocate a block. |
---|
134 | * @param result The allocated bit in the bitmap. |
---|
135 | * @retval int The error number (errno). No error if 0. |
---|
136 | */ |
---|
137 | int rtems_rfs_group_bitmap_alloc (rtems_rfs_file_system* fs, |
---|
138 | rtems_rfs_bitmap_bit goal, |
---|
139 | bool inode, |
---|
140 | rtems_rfs_bitmap_bit* result); |
---|
141 | |
---|
142 | /** |
---|
143 | * @brief Free the group allocated bit. |
---|
144 | * |
---|
145 | * @param fs The file system data. |
---|
146 | * @param inode If true the number to free is an inode else it is a block. |
---|
147 | * @param block The inode or block number to free. |
---|
148 | * @retval int The error number (errno). No error if 0. |
---|
149 | */ |
---|
150 | int rtems_rfs_group_bitmap_free (rtems_rfs_file_system* fs, |
---|
151 | bool inode, |
---|
152 | rtems_rfs_bitmap_bit no); |
---|
153 | |
---|
154 | /** |
---|
155 | * @brief Test the group allocated bit. |
---|
156 | * |
---|
157 | * @param fs The file system data. |
---|
158 | * @param inode If true the number to free is an inode else it is a block. |
---|
159 | * @param block The inode or block number to free. |
---|
160 | * @param state Return the state of the bit. |
---|
161 | * @retval int The error number (errno). No error if 0. |
---|
162 | */ |
---|
163 | int rtems_rfs_group_bitmap_test (rtems_rfs_file_system* fs, |
---|
164 | bool inode, |
---|
165 | rtems_rfs_bitmap_bit no, |
---|
166 | bool* state); |
---|
167 | |
---|
168 | /** |
---|
169 | * @brief Determine the number of blocks and inodes used. |
---|
170 | * |
---|
171 | * @param fs The file system data. |
---|
172 | * @param blocks The number of blocks used. |
---|
173 | * @param inodes The number of inodes used. |
---|
174 | * @retval int The error number (errno). No error if 0. |
---|
175 | */ |
---|
176 | int rtems_rfs_group_usage (rtems_rfs_file_system* fs, |
---|
177 | size_t* blocks, |
---|
178 | size_t* inodes); |
---|
179 | |
---|
180 | /** @} */ |
---|
181 | #endif |
---|