RTEMS: cpukit/include/rtems/blkdev.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
blkdev.h
Go to the documentation of this file.
1
9/*
10 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
11 * Author: Victor V. Vengerov <vvv@oktet.ru>
12 */
13
14#ifndef _RTEMS_BLKDEV_H
15#define _RTEMS_BLKDEV_H
16
17#include <rtems.h>
18#include <rtems/diskdevs.h>
19#include <rtems/print.h>
20#include <sys/ioccom.h>
21#include <stdio.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
49 typedef enum rtems_blkdev_request_op {
50 RTEMS_BLKDEV_REQ_READ,
51 RTEMS_BLKDEV_REQ_WRITE,
52 RTEMS_BLKDEV_REQ_SYNC
53} rtems_blkdev_request_op;
54
55struct rtems_blkdev_request;
56
60 typedef void (*rtems_blkdev_request_cb)(
61 struct rtems_blkdev_request *req,
62 rtems_status_code status
63);
64
68 typedef struct rtems_blkdev_sg_buffer {
72 rtems_blkdev_bnum block;
73
77 uint32_t length;
78
82 void *buffer;
83
87 void *user;
88} rtems_blkdev_sg_buffer;
89
102 typedef struct rtems_blkdev_request {
106 rtems_blkdev_request_op req;
107
111 rtems_blkdev_request_cb done;
112
116 void *done_arg;
117
121 rtems_status_code status;
122
126 uint32_t bufnum;
127
131 rtems_id io_task;
132
133 /*
134 * TODO: The use of these req blocks is not a great design. The req is a
135 * struct with a single 'bufs' declared in the req struct and the
136 * others are added in the outer level struct. This relies on the
137 * structs joining as a single array and that assumes the compiler
138 * packs the structs. Why not just place on a list ? The BD has a
139 * node that can be used.
140 */
141
145 rtems_blkdev_sg_buffer bufs[RTEMS_ZERO_LENGTH_ARRAY];
146} rtems_blkdev_request;
147
159static inline void rtems_blkdev_request_done(
160 rtems_blkdev_request *req,
161 rtems_status_code status
162)
163{
164 (*req->done)(req, status);
165}
166
173#define RTEMS_BLKDEV_START_BLOCK(req) (req->bufs[0].block)
174
180#define RTEMS_BLKIO_REQUEST _IOWR('B', 1, rtems_blkdev_request)
181#define RTEMS_BLKIO_GETMEDIABLKSIZE _IOR('B', 2, uint32_t)
182#define RTEMS_BLKIO_GETBLKSIZE _IOR('B', 3, uint32_t)
183#define RTEMS_BLKIO_SETBLKSIZE _IOW('B', 4, uint32_t)
184#define RTEMS_BLKIO_GETSIZE _IOR('B', 5, rtems_blkdev_bnum)
185#define RTEMS_BLKIO_SYNCDEV _IO('B', 6)
186#define RTEMS_BLKIO_DELETED _IO('B', 7)
187#define RTEMS_BLKIO_CAPABILITIES _IO('B', 8)
188#define RTEMS_BLKIO_GETDISKDEV _IOR('B', 9, rtems_disk_device *)
189#define RTEMS_BLKIO_PURGEDEV _IO('B', 10)
190#define RTEMS_BLKIO_GETDEVSTATS _IOR('B', 11, rtems_blkdev_stats *)
191#define RTEMS_BLKIO_RESETDEVSTATS _IO('B', 12)
192
195static inline int rtems_disk_fd_get_media_block_size(
196 int fd,
197 uint32_t *media_block_size
198)
199{
200 return ioctl(fd, RTEMS_BLKIO_GETMEDIABLKSIZE, media_block_size);
201}
202
203static inline int rtems_disk_fd_get_block_size(int fd, uint32_t *block_size)
204{
205 return ioctl(fd, RTEMS_BLKIO_GETBLKSIZE, block_size);
206}
207
208static inline int rtems_disk_fd_set_block_size(int fd, uint32_t block_size)
209{
210 return ioctl(fd, RTEMS_BLKIO_SETBLKSIZE, &block_size);
211}
212
213static inline int rtems_disk_fd_get_block_count(
214 int fd,
215 rtems_blkdev_bnum *block_count
216)
217{
218 return ioctl(fd, RTEMS_BLKIO_GETSIZE, block_count);
219}
220
221static inline int rtems_disk_fd_get_disk_device(
222 int fd,
223 rtems_disk_device **dd_ptr
224)
225{
226 return ioctl(fd, RTEMS_BLKIO_GETDISKDEV, dd_ptr);
227}
228
229static inline int rtems_disk_fd_sync(int fd)
230{
231 return ioctl(fd, RTEMS_BLKIO_SYNCDEV);
232}
233
234static inline int rtems_disk_fd_purge(int fd)
235{
236 return ioctl(fd, RTEMS_BLKIO_PURGEDEV);
237}
238
239static inline int rtems_disk_fd_get_device_stats(
240 int fd,
241 rtems_blkdev_stats *stats
242)
243{
244 return ioctl(fd, RTEMS_BLKIO_GETDEVSTATS, stats);
245}
246
247static inline int rtems_disk_fd_reset_device_stats(int fd)
248{
249 return ioctl(fd, RTEMS_BLKIO_RESETDEVSTATS);
250}
251
264#define RTEMS_BLKDEV_CAP_MULTISECTOR_CONT (1 << 0)
265
271#define RTEMS_BLKDEV_CAP_SYNC (1 << 1)
272
281int
282 rtems_blkdev_ioctl(rtems_disk_device *dd, uint32_t req, void *argp);
283
304 rtems_status_code rtems_blkdev_create(
305 const char *device,
306 uint32_t media_block_size,
307 rtems_blkdev_bnum media_block_count,
308 rtems_block_device_ioctl handler,
309 void *driver_data
310);
311
337 rtems_status_code rtems_blkdev_create_partition(
338 const char *partition,
339 const char *parent_block_device,
340 rtems_blkdev_bnum media_block_begin,
341 rtems_blkdev_bnum media_block_count
342);
343
347void rtems_blkdev_print_stats(
348 const rtems_blkdev_stats *stats,
349 uint32_t media_block_size,
350 uint32_t media_block_count,
351 uint32_t block_size,
352 const rtems_printer* printer
353);
354
358void rtems_blkstats(
359 const rtems_printer *printer,
360 const char *device,
361 bool reset
362);
363
383#define RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES \
384 rtems_blkdev_generic_open, \
385 rtems_blkdev_generic_close, \
386 rtems_blkdev_generic_read, \
387 rtems_blkdev_generic_write, \
388 rtems_blkdev_generic_ioctl
389
390/* Use rtems_blkdev_create() instead */
391RTEMS_DEPRECATED rtems_device_driver
392rtems_blkdev_generic_read(
393 rtems_device_major_number major,
394 rtems_device_minor_number minor,
395 void * arg
396);
397
398/* Use rtems_blkdev_create() instead */
399RTEMS_DEPRECATED rtems_device_driver
400rtems_blkdev_generic_write(
401 rtems_device_major_number major,
402 rtems_device_minor_number minor,
403 void * arg
404);
405
406/* Use rtems_blkdev_create() instead */
407RTEMS_DEPRECATED rtems_device_driver
408rtems_blkdev_generic_open(
409 rtems_device_major_number major,
410 rtems_device_minor_number minor,
411 void * arg
412);
413
414/* Use rtems_blkdev_create() instead */
415RTEMS_DEPRECATED rtems_device_driver
416rtems_blkdev_generic_close(
417 rtems_device_major_number major,
418 rtems_device_minor_number minor,
419 void * arg
420);
421
422/* Use rtems_blkdev_create() instead */
423RTEMS_DEPRECATED rtems_device_driver
424rtems_blkdev_generic_ioctl(
425 rtems_device_major_number major,
426 rtems_device_minor_number minor,
427 void * arg
428);
429
430/* Use rtems_blkdev_create() instead */
431RTEMS_DEPRECATED extern const rtems_driver_address_table rtems_blkdev_generic_ops;
432
435#ifdef __cplusplus
436}
437#endif
438
439#endif
diskdevs.h
Block Device Disk Management API.
rtems_status_code
rtems_status_code
Classic API Status.
Definition: status.h:43
rtems_id
Objects_Id rtems_id
Used to manage and manipulate RTEMS object identifiers.
Definition: types.h:83
rtems_blkdev_request_op
rtems_blkdev_request_op
Block device request type.
Definition: blkdev.h:49
rtems_blkdev_request_cb
void(* rtems_blkdev_request_cb)(struct rtems_blkdev_request *req, rtems_status_code status)
Block device request done callback function type.
Definition: blkdev.h:60
rtems_blkdev_create_partition
rtems_status_code rtems_blkdev_create_partition(const char *partition, const char *parent_block_device, rtems_blkdev_bnum media_block_begin, rtems_blkdev_bnum media_block_count)
Creates a partition within a parent block device.
Definition: blkdev-imfs.c:330
rtems_blkdev_print_stats
void rtems_blkdev_print_stats(const rtems_blkdev_stats *stats, uint32_t media_block_size, uint32_t media_block_count, uint32_t block_size, const rtems_printer *printer)
Prints the block device statistics.
Definition: blkdev-print-stats.c:31
rtems_blkdev_ioctl
int rtems_blkdev_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
Common IO control primitive.
Definition: blkdev-ioctl.c:24
rtems_blkstats
void rtems_blkstats(const rtems_printer *printer, const char *device, bool reset)
Block device statistics command.
Definition: blkdev-blkstats.c:35
rtems_blkdev_create
rtems_status_code rtems_blkdev_create(const char *device, uint32_t media_block_size, rtems_blkdev_bnum media_block_count, rtems_block_device_ioctl handler, void *driver_data)
Creates a block device.
Definition: blkdev-imfs.c:280
RTEMS_BLKDEV_REQ_READ
@ RTEMS_BLKDEV_REQ_READ
Definition: blkdev.h:50
RTEMS_BLKDEV_REQ_SYNC
@ RTEMS_BLKDEV_REQ_SYNC
Definition: blkdev.h:52
RTEMS_BLKDEV_REQ_WRITE
@ RTEMS_BLKDEV_REQ_WRITE
Definition: blkdev.h:51
rtems_blkdev_bnum
uint32_t rtems_blkdev_bnum
Block device block index type.
Definition: diskdevs.h:45
rtems_block_device_ioctl
int(* rtems_block_device_ioctl)(rtems_disk_device *dd, uint32_t req, void *argp)
Block device IO control handler type.
Definition: diskdevs.h:50
print.h
User print interface to the bspIO print plug in.
rtems.h
device
Definition: rtemscompat1.h:15
partition
Definition: media.c:43
rtems_blkdev_request
The block device transfer request is used to read or write a number of blocks from or to the device.
Definition: blkdev.h:102
rtems_blkdev_request::io_task
rtems_id io_task
Definition: blkdev.h:131
rtems_blkdev_request::done_arg
void * done_arg
Definition: blkdev.h:116
rtems_blkdev_request::status
rtems_status_code status
Definition: blkdev.h:121
rtems_blkdev_request::req
rtems_blkdev_request_op req
Definition: blkdev.h:106
rtems_blkdev_request::bufs
rtems_blkdev_sg_buffer bufs[RTEMS_ZERO_LENGTH_ARRAY]
Definition: blkdev.h:145
rtems_blkdev_request::done
rtems_blkdev_request_cb done
Definition: blkdev.h:111
rtems_blkdev_request::bufnum
uint32_t bufnum
Definition: blkdev.h:126
rtems_blkdev_sg_buffer
Block device scatter or gather buffer structure.
Definition: blkdev.h:68
rtems_blkdev_sg_buffer::block
rtems_blkdev_bnum block
Definition: blkdev.h:72
rtems_blkdev_sg_buffer::buffer
void * buffer
Definition: blkdev.h:82
rtems_blkdev_sg_buffer::length
uint32_t length
Definition: blkdev.h:77
rtems_blkdev_sg_buffer::user
void * user
Definition: blkdev.h:87
rtems_blkdev_stats
Block device statistics.
Definition: diskdevs.h:92
rtems_disk_device
Description of a disk device (logical and physical disks).
Definition: diskdevs.h:157
rtems_driver_address_table
Definition: io.h:48
rtems_printer
Definition: printer.h:55