1 |
1026 |
ivang |
/*
|
2 |
|
|
* logdisk.h - Physical and logical block devices (disks) support
|
3 |
|
|
*
|
4 |
|
|
* Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
|
5 |
|
|
* Author: Victor V. Vengerov <vvv@oktet.ru>
|
6 |
|
|
*
|
7 |
|
|
* @(#) diskdevs.h,v 1.1 2002/02/28 20:39:54 joel Exp
|
8 |
|
|
*/
|
9 |
|
|
|
10 |
|
|
#ifndef __RTEMS_LIBBLOCK_LOGDISK_H__
|
11 |
|
|
#define __RTEMS_LIBBLOCK_LOGDISK_H__
|
12 |
|
|
|
13 |
|
|
#ifdef __cplusplus
|
14 |
|
|
extern "C" {
|
15 |
|
|
#endif
|
16 |
|
|
|
17 |
|
|
#include <rtems.h>
|
18 |
|
|
#include <rtems/libio.h>
|
19 |
|
|
#include <stdlib.h>
|
20 |
|
|
|
21 |
|
|
#include "rtems/blkdev.h"
|
22 |
|
|
|
23 |
|
|
/* Buffer pool identifier */
|
24 |
|
|
typedef int rtems_bdpool_id;
|
25 |
|
|
|
26 |
|
|
/* Block device ioctl handler */
|
27 |
|
|
typedef int (* block_device_ioctl) (dev_t dev, int req, void *argp);
|
28 |
|
|
|
29 |
|
|
/* disk_device: Entry of this type created for every disk device (both for
|
30 |
|
|
* logical and physical disks).
|
31 |
|
|
* Array of arrays of pointers to disk_device structures maintained. First
|
32 |
|
|
* table indexed by major number and second table indexed by minor number.
|
33 |
|
|
* Such data organization allow quick lookup using data structure of
|
34 |
|
|
* moderated size.
|
35 |
|
|
*/
|
36 |
|
|
typedef struct disk_device {
|
37 |
|
|
dev_t dev; /* Device ID (major + minor) */
|
38 |
|
|
struct disk_device *phys_dev; /* Physical device ID (the same
|
39 |
|
|
as dev if this entry specifies
|
40 |
|
|
the physical device) */
|
41 |
|
|
char *name; /* Disk device name */
|
42 |
|
|
int uses; /* Use counter. Device couldn't be
|
43 |
|
|
removed if it is in use. */
|
44 |
|
|
int start; /* Starting block number (0 for
|
45 |
|
|
physical devices, block offset
|
46 |
|
|
on the related physical device
|
47 |
|
|
for logical device) */
|
48 |
|
|
int size; /* Size of physical or logical disk
|
49 |
|
|
in disk blocks */
|
50 |
|
|
int block_size; /* Size of device block (minimum
|
51 |
|
|
transfer unit) in bytes
|
52 |
|
|
(must be power of 2) */
|
53 |
|
|
int block_size_log2; /* log2 of block_size */
|
54 |
|
|
rtems_bdpool_id pool; /* Buffer pool assigned to this
|
55 |
|
|
device */
|
56 |
|
|
block_device_ioctl ioctl; /* ioctl handler for this block
|
57 |
|
|
device */
|
58 |
|
|
} disk_device;
|
59 |
|
|
|
60 |
|
|
/* rtems_disk_create_phys --
|
61 |
|
|
* Create physical disk entry. This function usually invoked from
|
62 |
|
|
* block device driver initialization code when physical device
|
63 |
|
|
* detected in the system. Device driver should provide ioctl handler
|
64 |
|
|
* to allow block device access operations. This primitive will register
|
65 |
|
|
* device in rtems (invoke rtems_io_register_name).
|
66 |
|
|
*
|
67 |
|
|
* PARAMETERS:
|
68 |
|
|
* dev - device identifier (major, minor numbers)
|
69 |
|
|
* block_size - size of disk block (minimum data transfer unit); must be
|
70 |
|
|
* power of 2
|
71 |
|
|
* disk_size - number of blocks on device
|
72 |
|
|
* handler - IOCTL handler (function providing basic block input/output
|
73 |
|
|
* request handling BIOREQUEST and other device management
|
74 |
|
|
* operations)
|
75 |
|
|
* name - character name of device (e.g. /dev/hda)
|
76 |
|
|
*
|
77 |
|
|
* RETURNS:
|
78 |
|
|
* RTEMS_SUCCESSFUL if information about new physical disk added, or
|
79 |
|
|
* error code if error occured (device already registered, wrong block
|
80 |
|
|
* size value, no memory available).
|
81 |
|
|
*/
|
82 |
|
|
rtems_status_code
|
83 |
|
|
rtems_disk_create_phys(dev_t dev, int block_size, int disk_size,
|
84 |
|
|
block_device_ioctl handler,
|
85 |
|
|
char *name);
|
86 |
|
|
|
87 |
|
|
/* rtems_disk_create_log --
|
88 |
|
|
* Create logical disk entry. Logical disk is contiguous area on physical
|
89 |
|
|
* disk. Disk may be splitted to several logical disks in several ways:
|
90 |
|
|
* manually or using information stored in blocks on physical disk
|
91 |
|
|
* (DOS-like partition table, BSD disk label, etc). This function usually
|
92 |
|
|
* invoked from application when application-specific splitting are in use,
|
93 |
|
|
* or from generic code which handle different logical disk organizations.
|
94 |
|
|
* This primitive will register device in rtems (invoke
|
95 |
|
|
* rtems_io_register_name).
|
96 |
|
|
*
|
97 |
|
|
* PARAMETERS:
|
98 |
|
|
* dev - logical device identifier (major, minor numbers)
|
99 |
|
|
* phys - physical device (block device which holds this logical disk)
|
100 |
|
|
* identifier
|
101 |
|
|
* start - starting block number on the physical device
|
102 |
|
|
* size - logical disk size in blocks
|
103 |
|
|
* name - logical disk name
|
104 |
|
|
*
|
105 |
|
|
* RETURNS:
|
106 |
|
|
* RTEMS_SUCCESSFUL if logical device successfully added, or error code
|
107 |
|
|
* if error occured (device already registered, no physical device
|
108 |
|
|
* exists, logical disk is out of physical disk boundaries, no memory
|
109 |
|
|
* available).
|
110 |
|
|
*/
|
111 |
|
|
rtems_status_code
|
112 |
|
|
rtems_disk_create_log(dev_t dev, dev_t phys, int start, int size, char *name);
|
113 |
|
|
|
114 |
|
|
/* rtems_disk_delete --
|
115 |
|
|
* Delete physical or logical disk device. Device may be deleted if its
|
116 |
|
|
* use counter (and use counters of all logical devices - if it is
|
117 |
|
|
* physical device) equal to 0. When physical device deleted,
|
118 |
|
|
* all logical devices deleted inherently. Appropriate devices removed
|
119 |
|
|
* from "/dev" filesystem.
|
120 |
|
|
*
|
121 |
|
|
* PARAMETERS:
|
122 |
|
|
* dev - device identifier (major, minor numbers)
|
123 |
|
|
*
|
124 |
|
|
* RETURNS:
|
125 |
|
|
* RTEMS_SUCCESSFUL if block device successfully deleted, or error code
|
126 |
|
|
* if error occured (device is not defined, device is in use).
|
127 |
|
|
*/
|
128 |
|
|
rtems_status_code
|
129 |
|
|
rtems_disk_delete(dev_t dev);
|
130 |
|
|
|
131 |
|
|
/* rtems_disk_lookup --
|
132 |
|
|
* Find block device descriptor by its device identifier. This function
|
133 |
|
|
* increment usage counter to 1. User should release disk_device structure
|
134 |
|
|
* by invoking rtems_disk_release primitive.
|
135 |
|
|
*
|
136 |
|
|
* PARAMETERS:
|
137 |
|
|
* dev - device identifier (major, minor numbers)
|
138 |
|
|
*
|
139 |
|
|
* RETURNS:
|
140 |
|
|
* pointer to the block device descriptor, or NULL if no such device
|
141 |
|
|
* exists.
|
142 |
|
|
*/
|
143 |
|
|
disk_device *
|
144 |
|
|
rtems_disk_lookup(dev_t dev);
|
145 |
|
|
|
146 |
|
|
/* rtems_disk_release --
|
147 |
|
|
* Release disk_device structure (decrement usage counter to 1).
|
148 |
|
|
*
|
149 |
|
|
* PARAMETERS:
|
150 |
|
|
* dd - pointer to disk device structure
|
151 |
|
|
*
|
152 |
|
|
* RETURNS:
|
153 |
|
|
* RTEMS_SUCCESSFUL
|
154 |
|
|
*
|
155 |
|
|
* NOTE:
|
156 |
|
|
* It should be implemented as inline function.
|
157 |
|
|
*/
|
158 |
|
|
rtems_status_code
|
159 |
|
|
rtems_disk_release(disk_device *dd);
|
160 |
|
|
|
161 |
|
|
/* rtems_disk_next --
|
162 |
|
|
* Disk device enumerator. Looking for device having device number larger
|
163 |
|
|
* than dev and return disk device descriptor for it. If there are no
|
164 |
|
|
* such device, NULL value returned.
|
165 |
|
|
*
|
166 |
|
|
* PARAMETERS:
|
167 |
|
|
* dev - device number (use -1 to start search)
|
168 |
|
|
*
|
169 |
|
|
* RETURNS:
|
170 |
|
|
* Pointer to the disk descriptor for next disk device, or NULL if all
|
171 |
|
|
* devices enumerated. */
|
172 |
|
|
disk_device *
|
173 |
|
|
rtems_disk_next(dev_t dev);
|
174 |
|
|
|
175 |
|
|
/* rtems_diskio_initialize --
|
176 |
|
|
* Initialization of disk device library (initialize all data structures,
|
177 |
|
|
* etc.)
|
178 |
|
|
*
|
179 |
|
|
* PARAMETERS:
|
180 |
|
|
* none
|
181 |
|
|
*
|
182 |
|
|
* RETURNS:
|
183 |
|
|
* RTEMS_SUCCESSFUL if library initialized, or error code if error
|
184 |
|
|
* occured.
|
185 |
|
|
*/
|
186 |
|
|
rtems_status_code
|
187 |
|
|
rtems_disk_io_initialize(void);
|
188 |
|
|
|
189 |
|
|
/* rtems_diskio_done --
|
190 |
|
|
* Release all resources allocated for disk device interface.
|
191 |
|
|
*
|
192 |
|
|
* PARAMETERS:
|
193 |
|
|
* none
|
194 |
|
|
*
|
195 |
|
|
* RETURNS:
|
196 |
|
|
* RTEMS_SUCCESSFUL if all resources released, or error code if error
|
197 |
|
|
* occured.
|
198 |
|
|
*/
|
199 |
|
|
rtems_status_code
|
200 |
|
|
rtems_disk_io_done(void);
|
201 |
|
|
|
202 |
|
|
#ifdef __cplusplus
|
203 |
|
|
}
|
204 |
|
|
#endif
|
205 |
|
|
|
206 |
|
|
#endif
|