source: rtems/cpukit/libblock/include/rtems/bdbuf.h @ ce92867b

4.104.114.84.95
Last change on this file since ce92867b was ce92867b, checked in by Joel Sherrill <joel.sherrill@…>, on 02/02/05 at 00:06:18

2005-02-01 Joel Sherrill <joel@…>

  • libblock/include/rtems/bdbuf.h, libblock/include/rtems/ide_part_table.h, libblock/src/blkdev.c, libcsupport/include/rtems/termiostypes.h, libcsupport/src/termios.c, posix/macros/rtems/posix/cond.inl, posix/macros/rtems/posix/mutex.inl : Remove warnings.
  • Property mode set to 100644
File size: 9.9 KB
Line 
1/**
2 * @file rtems/bdbuf.h
3 *
4 * block device buffer management
5 */
6 
7/*
8 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
9 * Author: Victor V. Vengerov <vvv@oktet.ru>
10 *
11 * @(#) $Id$
12 */
13
14#ifndef _RTEMS_BDBUF_H
15#define _RTEMS_BDBUF_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#include <rtems.h>
22#include <rtems/libio.h>
23#include <rtems/chain.h>
24
25#include "rtems/blkdev.h"
26#include "rtems/diskdevs.h"
27
28
29/*
30 * To manage buffers we using Buffer Descriptors.
31 * To speed-up buffer lookup descriptors are organized in AVL-Tree.
32 * The fields 'dev' and 'block' are search key.
33 */
34
35/* Buffer descriptors
36 * Descriptors organized in AVL-tree to speedup buffer lookup.
37 * dev and block fields are search key in AVL-tree.
38 * Modified buffers, free buffers and used buffers linked in 'mod', 'free' and
39 * 'lru' chains appropriately.
40 */
41
42typedef struct bdbuf_buffer {
43    Chain_Node link; /* Link in the lru, mod or free chains */
44
45    struct bdbuf_avl_node {
46        signed char cache;           /* Cache */
47
48            struct bdbuf_buffer* left;  /* Left Child */
49            struct bdbuf_buffer* right; /* Right Child */
50
51        signed char bal;             /* The balance of the sub-tree */
52    } avl;
53
54    dev_t       dev;     /* device number */
55    blkdev_bnum block;   /* block number on the device */
56
57    unsigned char    *buffer;  /* Pointer to the buffer memory area */
58    rtems_status_code status; /* Last I/O operation completion status */
59    int         error;   /* If status != RTEMS_SUCCESSFUL, this field contains
60                            errno value which can be used by user later */
61    boolean     modified:1;    /* =1 if buffer was modified */
62    boolean     in_progress:1; /* =1 if exchange with disk is in progress;
63                                  need to wait on semaphore */
64    boolean     actual:1;      /* Buffer contains actual data */
65    int         use_count; /* Usage counter; incremented when somebody use
66                              this buffer; decremented when buffer released
67                              without modification or when buffer is flushed
68                              by swapout task */
69
70    rtems_bdpool_id pool;  /* Identifier of buffer pool to which this buffer
71                              belongs */
72    CORE_mutex_Control transfer_sema;
73                           /* Transfer operation semaphore */
74} bdbuf_buffer;
75
76
77
78/* bdbuf_config structure describes block configuration (size,
79 * amount, memory location) for buffering layer
80 */
81typedef struct rtems_bdbuf_config {
82    int      size;      /* Size of block */
83    int      num;       /* Number of blocks of appropriate size */
84    unsigned char  *mem_area;
85                        /* Pointer to the blocks location or NULL, in this
86                           case memory for blocks will be allocated by
87                           Buffering Layer with the help of RTEMS partition
88                           manager */
89} rtems_bdbuf_config;
90
91extern rtems_bdbuf_config rtems_bdbuf_configuration[];
92extern int rtems_bdbuf_configuration_size;
93
94/* rtems_bdbuf_init --
95 *     Prepare buffering layer to work - initialize buffer descritors
96 *     and (if it is neccessary) buffers. Buffers will be allocated accoriding
97 *     to the configuration table, each entry describes kind of block and
98 *     amount requested. After initialization all blocks is placed into
99 *     free elements lists.
100 *
101 * PARAMETERS:
102 *     conf_table - pointer to the buffers configuration table
103 *     size       - number of entries in configuration table
104 *
105 * RETURNS:
106 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
107 *     or error code if error is occured)
108 */
109rtems_status_code
110rtems_bdbuf_init(rtems_bdbuf_config *conf_table, int size);
111
112
113/* rtems_bdbuf_get --
114 *     Obtain block buffer. If specified block already cached (i.e. there's
115 *     block in the _modified_, or _recently_used_), return address
116 *     of appropriate buffer descriptor and increment reference counter to 1.
117 *     If block is not cached, allocate new buffer and return it. Data
118 *     shouldn't be read to the buffer from media; buffer may contains
119 *     arbitrary data. This primitive may be blocked if there are no free
120 *     buffer descriptors available and there are no unused non-modified
121 *     (or synchronized with media) buffers available.
122 *
123 * PARAMETERS:
124 *     device - device number (constructed of major and minor device number)
125 *     block  - linear media block number
126 *     bd     - address of variable to store pointer to the buffer descriptor
127 *
128 * RETURNS:
129 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
130 *     or error code if error is occured)
131 *
132 * SIDE EFFECTS:
133 *     bufget_sema semaphore obtained by this primitive.
134 */
135rtems_status_code
136rtems_bdbuf_get(dev_t device, blkdev_bnum block, bdbuf_buffer **bdb_ptr);
137
138/* rtems_bdbuf_read --
139 *     (Similar to the rtems_bdbuf_get, except reading data from media)
140 *     Obtain block buffer. If specified block already cached, return address
141 *     of appropriate buffer and increment reference counter to 1. If block is
142 *     not cached, allocate new buffer and read data to it from the media.
143 *     This primitive may be blocked on waiting until data to be read from
144 *     media, if there are no free buffer descriptors available and there are
145 *     no unused non-modified (or synchronized with media) buffers available.
146 *
147 * PARAMETERS:
148 *     device - device number (consists of major and minor device number)
149 *     block  - linear media block number
150 *     bd     - address of variable to store pointer to the buffer descriptor
151 *
152 * RETURNS:
153 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
154 *     or error code if error is occured)
155 *
156 * SIDE EFFECTS:
157 *     bufget_sema and transfer_sema semaphores obtained by this primitive.
158 */
159rtems_status_code
160rtems_bdbuf_read(dev_t device, blkdev_bnum block, bdbuf_buffer **bdb_ptr);
161
162/* rtems_bdbuf_release --
163 *     Release buffer allocated before. This primitive decrease the
164 *     usage counter. If it is zero, further destiny of buffer depends on
165 *     'modified' status. If buffer was modified, it is placed to the end of
166 *     mod list and flush task waken up. If buffer was not modified,
167 *     it is placed to the end of lru list, and bufget_sema released, allowing
168 *     to reuse this buffer.
169 *
170 * PARAMETERS:
171 *     bd_buf - pointer to the bdbuf_buffer structure previously obtained using
172 *              get/read primitive.
173 *
174 * RETURNS:
175 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
176 *     or error code if error is occured)
177 *
178 * SIDE EFFECTS:
179 *     flush_sema and bufget_sema semaphores may be released by this primitive.
180 */
181rtems_status_code
182rtems_bdbuf_release(bdbuf_buffer *bd_buf);
183
184/* rtems_bdbuf_release_modified --
185 *     Release buffer allocated before, assuming that it is _modified_ by
186 *     it's owner. This primitive decrease usage counter for buffer, mark
187 *     buffer descriptor as modified. If usage counter is 0, insert it at
188 *     end of mod chain and release flush_sema semaphore to activate the
189 *     flush task.
190 *
191 * PARAMETERS:
192 *     bd_buf - pointer to the bdbuf_buffer structure previously obtained using
193 *              get/read primitive.
194 *
195 * RETURNS:
196 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
197 *     or error code if error is occured)
198 *
199 * SIDE EFFECTS:
200 *     flush_sema semaphore may be released by this primitive.
201 */
202rtems_status_code
203rtems_bdbuf_release_modified(bdbuf_buffer *bd_buf);
204
205/* rtems_bdbuf_sync --
206 *     Wait until specified buffer synchronized with disk. Invoked on exchanges
207 *     critical for data consistency on the media. This primitive mark owned
208 *     block as modified, decrease usage counter. If usage counter is 0,
209 *     block inserted to the mod chain and flush_sema semaphore released.
210 *     Finally, primitives blocked on transfer_sema semaphore.
211 *
212 * PARAMETERS:
213 *     bd_buf - pointer to the bdbuf_buffer structure previously obtained using
214 *              get/read primitive.
215 *
216 * RETURNS:
217 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
218 *     or error code if error is occured)
219 *
220 * SIDE EFFECTS:
221 *     Primitive may be blocked on transfer_sema semaphore.
222 */
223rtems_status_code
224rtems_bdbuf_sync(bdbuf_buffer *bd_buf);
225
226/* rtems_bdbuf_syncdev --
227 *     Synchronize with disk all buffers containing the blocks belonging to
228 *     specified device.
229 *
230 * PARAMETERS:
231 *     dev - block device number
232 *
233 * RETURNS:
234 *     RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully
235 *     or error code if error is occured)
236 */
237rtems_status_code
238rtems_bdbuf_syncdev(dev_t dev);
239
240/* rtems_bdbuf_find_pool --
241 *     Find first appropriate buffer pool. This primitive returns the index
242 *     of first buffer pool which block size is greater than or equal to
243 *     specified size.
244 *
245 * PARAMETERS:
246 *     block_size - requested block size
247 *     pool       - placeholder for result
248 *
249 * RETURNS:
250 *     RTEMS status code: RTEMS_SUCCESSFUL if operation completed successfully,
251 *     RTEMS_INVALID_SIZE if specified block size is invalid (not a power
252 *     of 2), RTEMS_NOT_DEFINED if buffer pool for this or greater block size
253 *     is not configured.
254 */
255rtems_status_code
256rtems_bdbuf_find_pool(int block_size, rtems_bdpool_id *pool);
257
258/* rtems_bdbuf_get_pool_info --
259 *     Obtain characteristics of buffer pool with specified number.
260 *
261 * PARAMETERS:
262 *     pool       - buffer pool number
263 *     block_size - block size for which buffer pool is configured returned
264 *                  there
265 *     blocks     - number of buffers in buffer pool returned there
266 *
267 * RETURNS:
268 *     RTEMS status code: RTEMS_SUCCESSFUL if operation completed successfully,
269 *     RTEMS_INVALID_NUMBER if appropriate buffer pool is not configured.
270 *
271 * NOTE:
272 *     Buffer pools enumerated contiguously starting from 0.
273 */
274rtems_status_code
275rtems_bdbuf_get_pool_info(rtems_bdpool_id pool, int *block_size, int *blocks);
276
277#ifdef __cplusplus
278}
279#endif
280
281#endif
Note: See TracBrowser for help on using the repository browser.