source: rtems/cpukit/libblock/src/ramdisk-driver.c @ e41369ef

4.104.115
Last change on this file since e41369ef was e41369ef, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 10/20/09 at 07:53:19
  • libblock/include/rtems/diskdevs.h: Documentation. Added field to rtems_disk_device.
  • libblock/include/rtems/blkdev.h: New request code RTEMS_BLKIO_DELETED.
  • libblock/src/diskdevs.c: Major rewrite. Changed the way disks are deleted. Disks will be now deleted if they are not in use or upon last release. The IO control handler will be invoked if a physical disk is deleted with the RTEMS_BLKIO_DELETED request code. Logical disks increase now the usage count of the associated physical disk.
  • libblock/include/rtems/ramdisk.h: Documentation.
  • libblock/src/ramdisk-driver.c: Compile trace support conditionally.
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_ramdisk
5 *
6 * @brief RAM disk block device implementation.
7 */
8
9/*
10 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
11 * Author: Victor V. Vengerov <vvv@oktet.ru>
12 *
13 * @(#) $Id$
14 */
15
16/* FIXME: How to set this define? */
17#if !defined(RTEMS_RAMDISK_TRACE)
18    #define RTEMS_RAMDISK_TRACE 0
19#endif
20
21#include <stdlib.h>
22#include <errno.h>
23#include <string.h>
24
25#if RTEMS_RAMDISK_TRACE
26    #include <stdio.h>
27#endif
28
29#include <rtems.h>
30#include <rtems/ramdisk.h>
31
32#if RTEMS_RAMDISK_TRACE
33    static void
34    rtems_ramdisk_printf (const ramdisk *rd, const char *format, ...)
35    {
36        if (rd->trace)
37        {
38            va_list args;
39            va_start (args, format);
40            printf ("ramdisk:");
41            vprintf (format, args);
42            printf ("\n");
43        }
44    }
45#endif
46
47static int
48ramdisk_read(struct ramdisk *rd, rtems_blkdev_request *req)
49{
50    uint8_t *from = rd->area;
51    uint32_t   i;
52    rtems_blkdev_sg_buffer *sg;
53
54#if RTEMS_RAMDISK_TRACE
55    rtems_ramdisk_printf (rd, "ramdisk read: start=%d, blocks=%d",
56                          req->bufs[0].block, req->bufnum);
57#endif
58
59    for (i = 0, sg = req->bufs; i < req->bufnum; i++, sg++)
60    {
61#if RTEMS_RAMDISK_TRACE
62        rtems_ramdisk_printf (rd, "ramdisk read: buf=%d block=%d length=%d off=%d addr=%p",
63                              i, sg->block, sg->length, sg->block * rd->block_size,
64                              from + (sg->block * rd->block_size));
65#endif
66        memcpy(sg->buffer, from + (sg->block * rd->block_size), sg->length);
67    }
68    req->req_done(req->done_arg, RTEMS_SUCCESSFUL, 0);
69    return 0;
70}
71
72static int
73ramdisk_write(struct ramdisk *rd, rtems_blkdev_request *req)
74{
75    uint8_t *to = rd->area;
76    uint32_t   i;
77    rtems_blkdev_sg_buffer *sg;
78
79#if RTEMS_RAMDISK_TRACE
80    rtems_ramdisk_printf (rd, "ramdisk write: start=%d, blocks=%d",
81                          req->bufs[0].block, req->bufnum);
82#endif
83    for (i = 0, sg = req->bufs; i < req->bufnum; i++, sg++)
84    {
85#if RTEMS_RAMDISK_TRACE
86        rtems_ramdisk_printf (rd, "ramdisk write: buf=%d block=%d length=%d off=%d addr=%p",
87                              i, sg->block, sg->length, sg->block * rd->block_size,
88                              to + (sg->block * rd->block_size));
89#endif
90        memcpy(to + (sg->block * rd->block_size), sg->buffer, sg->length);
91    }
92    req->req_done(req->done_arg, RTEMS_SUCCESSFUL, 0);
93    return 0;
94}
95
96int
97ramdisk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
98{
99    switch (req)
100    {
101        case RTEMS_BLKIO_REQUEST:
102        {
103            rtems_blkdev_request *r = argp;
104            struct ramdisk *rd = rtems_disk_driver_data(dd);
105
106            switch (r->req)
107            {
108                case RTEMS_BLKDEV_REQ_READ:
109                    return ramdisk_read(rd, r);
110
111                case RTEMS_BLKDEV_REQ_WRITE:
112                    return ramdisk_write(rd, r);
113
114                default:
115                    errno = EINVAL;
116                    return -1;
117            }
118            break;
119        }
120 
121        default:
122            return rtems_blkdev_ioctl (dd, req, argp);
123            break;
124    }
125
126    errno = EINVAL;
127    return -1;
128}
Note: See TracBrowser for help on using the repository browser.