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

4.104.11
Last change on this file since 0d15414e was 0d15414e, checked in by Chris Johns <chrisj@…>, on Aug 5, 2009 at 12:00:54 AM

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
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_blkdev
5 *
6 * Block device management.
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#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <string.h>
21
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;
41    char         *buf;
42    unsigned int count;
43    unsigned int block;
44    unsigned int blkofs;
45    dev_t dev;
46    rtems_disk_device *dd;
47
48    dev = rtems_filesystem_make_dev_t(major, minor);
49    dd = rtems_disk_obtain(dev);
50    if (dd == NULL)
51        return RTEMS_INVALID_NUMBER;
52
53    block_size = dd->block_size;
54
55    buf = args->buffer;
56    count = args->count;
57    args->bytes_moved = 0;
58
59    block = args->offset / block_size;
60    blkofs = args->offset % block_size;
61
62    while (count > 0)
63    {
64        rtems_bdbuf_buffer *diskbuf;
65        uint32_t            copy;
66        rtems_status_code   rc;
67
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
89 *     buffer management primitives.
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;
98    uint32_t      block_size;
99    char         *buf;
100    uint32_t      count;
101    uint32_t      block;
102    uint32_t      blkofs;
103    dev_t dev;
104    rtems_status_code rc;
105    rtems_disk_device *dd;
106
107    dev = rtems_filesystem_make_dev_t(major, minor);
108    dd = rtems_disk_obtain(dev);
109    if (dd == NULL)
110        return RTEMS_INVALID_NUMBER;
111
112    block_size = dd->block_size;
113
114    buf = args->buffer;
115    count = args->count;
116    args->bytes_moved = 0;
117
118    block = args->offset / block_size;
119    blkofs = args->offset % block_size;
120
121    while (count > 0)
122    {
123        rtems_bdbuf_buffer *diskbuf;
124        uint32_t            copy;
125
126        if ((blkofs == 0) && (count >= block_size))
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;
132
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;
138
139        rc = rtems_bdbuf_release_modified(diskbuf);
140        if (rc != RTEMS_SUCCESSFUL)
141            return rc;
142
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,
158    void                    * arg __attribute__((unused)))
159{
160    dev_t dev;
161    rtems_disk_device *dd;
162
163    dev = rtems_filesystem_make_dev_t(major, minor);
164    dd = rtems_disk_obtain(dev);
165    if (dd == NULL)
166        return RTEMS_INVALID_NUMBER;
167
168    dd->uses++;
169
170    rtems_disk_release(dd);
171
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,
183    void                    * arg __attribute__((unused)))
184{
185    dev_t dev;
186    rtems_disk_device *dd;
187
188    dev = rtems_filesystem_make_dev_t(major, minor);
189    dd = rtems_disk_obtain(dev);
190    if (dd == NULL)
191        return RTEMS_INVALID_NUMBER;
192
193    dd->uses--;
194
195    rtems_disk_release(dd);
196
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;
211    rtems_disk_device *dd;
212    int rc;
213
214    dev = rtems_filesystem_make_dev_t(major, minor);
215    dd = rtems_disk_obtain(dev);
216    if (dd == NULL)
217        return RTEMS_INVALID_NUMBER;
218
219    switch (args->command)
220    {
221        case RTEMS_BLKIO_GETBLKSIZE:
222            args->ioctl_return = dd->block_size;
223            break;
224
225        case RTEMS_BLKIO_GETSIZE:
226            args->ioctl_return = dd->size;
227            break;
228
229        case RTEMS_BLKIO_SYNCDEV:
230            rc = rtems_bdbuf_syncdev(dd->dev);
231            args->ioctl_return = (rc == RTEMS_SUCCESSFUL ? 0 : -1);
232            break;
233
234        case RTEMS_BLKIO_REQUEST:
235        {
236            rtems_blkdev_request *req = args->buffer;
237            args->ioctl_return = dd->ioctl(dd->phys_dev->dev, args->command,
238                                           req);
239            break;
240        }
241
242        default:
243            args->ioctl_return = dd->ioctl(dd->phys_dev->dev, args->command,
244                                           args->buffer);
245            break;
246    }
247    rtems_disk_release(dd);
248
249    return RTEMS_SUCCESSFUL;
250}
Note: See TracBrowser for help on using the repository browser.