source: rtems/cpukit/libblock/src/blkdev.c @ 0d15414e

4.104.115
Last change on this file since 0d15414e was 0d15414e, checked in by Chris Johns <chrisj@…>, on 08/05/09 at 00:00:54

009-08-05 Chris Johns <chrisj@…>

  • libmisc/dummy/dummy-networking.c: New.
  • libmisc/dummy/dummy.c, libmisc/Makefile.am: Move trhe networking configuration into a separate file so configuration varations do not cause conflicts.
  • score/inline/rtems/score/object.inl, score/include/rtems/score/object.h: Remove warnings.
  • score/inline/rtems/score/object.inl: Add _Chain_First, _Chain_Last, _Chain_Mext, and _Chain_Previous.
  • sapi/inline/rtems/chain.inl: Add rtems_chain_first, rtems_chain_last, rtems_chain_mext, and rtems_chain_previous.
  • libblock/include/rtems/diskdevs.h: Remove the bdbuf pool id and block_size_log2. Add media_block_size.
  • libblock/src/diskdevs.c: Remove size restrictions on block size. Add media block size initialisation. Remove comment to clean up the bdbuf cache.
  • libblock/src/blkdev.c: Remove references to block_size_log2. Allow any block size.
  • libblock/include/rtems/bdbuf.h, libblock/src/bdbuf.c: Remove all references to pools and make the cache handle demand driver variable buffer size allocation. Added worker threads support the swapout task.
  • sapi/include/confdefs.h: Updated the bdbuf configutation.
  • Property mode set to 100644
File size: 5.8 KB
RevLine 
[57aa979]1/**
2 * @file
3 *
[4670d91]4 * @ingroup rtems_blkdev
5 *
[57aa979]6 * Block device management.
7 */
8 
[8b96149]9/*
[e51bd96]10 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
11 * Author: Victor V. Vengerov <vvv@oktet.ru>
12 *
13 * @(#) $Id$
14 */
15
[006fa1ef]16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
[228587bb]20#include <string.h>
21
[e51bd96]22#include <rtems.h>
23#include <rtems/libio.h>
24#include <sys/ioctl.h>
25
26#include "rtems/diskdevs.h"
27#include "rtems/bdbuf.h"
28
29/* rtems_blkdev_generic_read --
30 *     Generic block device read primitive. Implemented using block device
31 *     buffer management primitives.
32 */
33rtems_device_driver
34rtems_blkdev_generic_read(
35    rtems_device_major_number major,
36    rtems_device_minor_number minor,
37    void                    * arg)
38{
39    rtems_libio_rw_args_t *args = arg;
40    int block_size;
[b17ff491]41    char         *buf;
[e51bd96]42    unsigned int count;
43    unsigned int block;
44    unsigned int blkofs;
45    dev_t dev;
[3899a537]46    rtems_disk_device *dd;
[048dcd2b]47
[e51bd96]48    dev = rtems_filesystem_make_dev_t(major, minor);
[3899a537]49    dd = rtems_disk_obtain(dev);
[e51bd96]50    if (dd == NULL)
51        return RTEMS_INVALID_NUMBER;
[048dcd2b]52
[e51bd96]53    block_size = dd->block_size;
[048dcd2b]54
[e51bd96]55    buf = args->buffer;
56    count = args->count;
57    args->bytes_moved = 0;
[048dcd2b]58
[0d15414e]59    block = args->offset / block_size;
60    blkofs = args->offset % block_size;
[048dcd2b]61
[e51bd96]62    while (count > 0)
63    {
[3899a537]64        rtems_bdbuf_buffer *diskbuf;
[cec5c069]65        uint32_t            copy;
66        rtems_status_code   rc;
[048dcd2b]67
[e51bd96]68        rc = rtems_bdbuf_read(dev, block, &diskbuf);
69        if (rc != RTEMS_SUCCESSFUL)
70            return rc;
71        copy = block_size - blkofs;
72        if (copy > count)
73            copy = count;
74        memcpy(buf, (char *)diskbuf->buffer + blkofs, copy);
75        rc = rtems_bdbuf_release(diskbuf);
76        args->bytes_moved += copy;
77        if (rc != RTEMS_SUCCESSFUL)
78            return rc;
79        count -= copy;
80        buf += copy;
81        blkofs = 0;
82        block++;
83    }
84    return RTEMS_SUCCESSFUL;
85}
86
87/* rtems_blkdev_generic_write --
88 *     Generic block device write primitive. Implemented using block device
[8b96149]89 *     buffer management primitives.
[e51bd96]90 */
91rtems_device_driver
92rtems_blkdev_generic_write(
93    rtems_device_major_number major,
94    rtems_device_minor_number minor,
95    void                    * arg)
96{
97    rtems_libio_rw_args_t *args = arg;
[cec5c069]98    uint32_t      block_size;
[b17ff491]99    char         *buf;
[cec5c069]100    uint32_t      count;
101    uint32_t      block;
102    uint32_t      blkofs;
[e51bd96]103    dev_t dev;
104    rtems_status_code rc;
[3899a537]105    rtems_disk_device *dd;
[048dcd2b]106
[e51bd96]107    dev = rtems_filesystem_make_dev_t(major, minor);
[3899a537]108    dd = rtems_disk_obtain(dev);
[e51bd96]109    if (dd == NULL)
110        return RTEMS_INVALID_NUMBER;
[048dcd2b]111
[e51bd96]112    block_size = dd->block_size;
[048dcd2b]113
[e51bd96]114    buf = args->buffer;
115    count = args->count;
116    args->bytes_moved = 0;
[048dcd2b]117
[0d15414e]118    block = args->offset / block_size;
119    blkofs = args->offset % block_size;
[048dcd2b]120
[e51bd96]121    while (count > 0)
122    {
[3899a537]123        rtems_bdbuf_buffer *diskbuf;
[cec5c069]124        uint32_t            copy;
[048dcd2b]125
[635652e]126        if ((blkofs == 0) && (count >= block_size))
[e51bd96]127            rc = rtems_bdbuf_get(dev, block, &diskbuf);
128        else
129            rc = rtems_bdbuf_read(dev, block, &diskbuf);
130        if (rc != RTEMS_SUCCESSFUL)
131            return rc;
[048dcd2b]132
[e51bd96]133        copy = block_size - blkofs;
134        if (copy > count)
135            copy = count;
136        memcpy((char *)diskbuf->buffer + blkofs, buf, copy);
137        args->bytes_moved += copy;
[048dcd2b]138
[e51bd96]139        rc = rtems_bdbuf_release_modified(diskbuf);
140        if (rc != RTEMS_SUCCESSFUL)
141            return rc;
[048dcd2b]142
[e51bd96]143        count -= copy;
144        buf += copy;
145        blkofs = 0;
146        block++;
147    }
148    return RTEMS_SUCCESSFUL;
149}
150
151/* blkdev_generic_open --
152 *     Generic block device open primitive.
153 */
154rtems_device_driver
155rtems_blkdev_generic_open(
156    rtems_device_major_number major,
157    rtems_device_minor_number minor,
[31e2698]158    void                    * arg __attribute__((unused)))
[e51bd96]159{
160    dev_t dev;
[3899a537]161    rtems_disk_device *dd;
[048dcd2b]162
[e51bd96]163    dev = rtems_filesystem_make_dev_t(major, minor);
[3899a537]164    dd = rtems_disk_obtain(dev);
[e51bd96]165    if (dd == NULL)
166        return RTEMS_INVALID_NUMBER;
[048dcd2b]167
[e51bd96]168    dd->uses++;
[048dcd2b]169
[e51bd96]170    rtems_disk_release(dd);
[048dcd2b]171
[e51bd96]172    return RTEMS_SUCCESSFUL;
173}
174
175
176/* blkdev_generic_close --
177 *     Generic block device close primitive.
178 */
179rtems_device_driver
180rtems_blkdev_generic_close(
181    rtems_device_major_number major,
182    rtems_device_minor_number minor,
[31e2698]183    void                    * arg __attribute__((unused)))
[e51bd96]184{
185    dev_t dev;
[3899a537]186    rtems_disk_device *dd;
[048dcd2b]187
[e51bd96]188    dev = rtems_filesystem_make_dev_t(major, minor);
[3899a537]189    dd = rtems_disk_obtain(dev);
[e51bd96]190    if (dd == NULL)
191        return RTEMS_INVALID_NUMBER;
[048dcd2b]192
[e51bd96]193    dd->uses--;
[048dcd2b]194
[e51bd96]195    rtems_disk_release(dd);
[048dcd2b]196
[e51bd96]197    return RTEMS_SUCCESSFUL;
198}
199
200/* blkdev_generic_ioctl --
201 *     Generic block device ioctl primitive.
202 */
203rtems_device_driver
204rtems_blkdev_generic_ioctl(
205    rtems_device_major_number major,
206    rtems_device_minor_number minor,
207    void                    * arg)
208{
209    rtems_libio_ioctl_args_t *args = arg;
210    dev_t dev;
[3899a537]211    rtems_disk_device *dd;
[e51bd96]212    int rc;
[048dcd2b]213
[e51bd96]214    dev = rtems_filesystem_make_dev_t(major, minor);
[3899a537]215    dd = rtems_disk_obtain(dev);
[e51bd96]216    if (dd == NULL)
217        return RTEMS_INVALID_NUMBER;
[048dcd2b]218
[e51bd96]219    switch (args->command)
220    {
[3899a537]221        case RTEMS_BLKIO_GETBLKSIZE:
[e51bd96]222            args->ioctl_return = dd->block_size;
223            break;
[048dcd2b]224
[3899a537]225        case RTEMS_BLKIO_GETSIZE:
[e51bd96]226            args->ioctl_return = dd->size;
227            break;
228
[3899a537]229        case RTEMS_BLKIO_SYNCDEV:
[e51bd96]230            rc = rtems_bdbuf_syncdev(dd->dev);
231            args->ioctl_return = (rc == RTEMS_SUCCESSFUL ? 0 : -1);
232            break;
[048dcd2b]233
[3899a537]234        case RTEMS_BLKIO_REQUEST:
[e51bd96]235        {
[3899a537]236            rtems_blkdev_request *req = args->buffer;
[8b96149]237            args->ioctl_return = dd->ioctl(dd->phys_dev->dev, args->command,
[e51bd96]238                                           req);
239            break;
240        }
[048dcd2b]241
[e51bd96]242        default:
[8b96149]243            args->ioctl_return = dd->ioctl(dd->phys_dev->dev, args->command,
[e51bd96]244                                           args->buffer);
245            break;
246    }
247    rtems_disk_release(dd);
[048dcd2b]248
[e51bd96]249    return RTEMS_SUCCESSFUL;
250}
Note: See TracBrowser for help on using the repository browser.