source: rtems/cpukit/libblock/src/diskdevs-init.c @ 73c09b3b

4.115
Last change on this file since 73c09b3b was 73c09b3b, checked in by Sebastian Huber <sebastian.huber@…>, on 05/30/12 at 11:40:34

libblock: Simplify disk management

Add block_count and media_blocks_per_block to rtems_disk_device. Add
and use rtems_disk_init_phys() and rtems_disk_init_log().

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 */
14
15#if HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems/blkdev.h>
20#include <rtems/bdbuf.h>
21
22rtems_status_code rtems_disk_init_phys(
23  rtems_disk_device *dd,
24  uint32_t block_size,
25  rtems_blkdev_bnum block_count,
26  rtems_block_device_ioctl handler,
27  void *driver_data
28)
29{
30  rtems_status_code sc;
31
32  dd = memset(dd, 0, sizeof(*dd));
33
34  dd->phys_dev = dd;
35  dd->size = block_count;
36  dd->media_block_size = block_size;
37  dd->ioctl = handler;
38  dd->driver_data = driver_data;
39
40  if (block_count > 0) {
41    if ((*handler)(dd, RTEMS_BLKIO_CAPABILITIES, &dd->capabilities) != 0) {
42      dd->capabilities = 0;
43    }
44
45    sc = rtems_bdbuf_set_block_size(dd, block_size);
46  } else {
47    sc = RTEMS_INVALID_NUMBER;
48  }
49
50  return sc;
51}
52
53rtems_status_code rtems_disk_init_log(
54  rtems_disk_device *dd,
55  rtems_disk_device *phys_dd,
56  rtems_blkdev_bnum block_begin,
57  rtems_blkdev_bnum block_count
58)
59{
60  rtems_status_code sc;
61
62  dd = memset(dd, 0, sizeof(*dd));
63
64  dd->phys_dev = phys_dd;
65  dd->start = block_begin;
66  dd->size = block_count;
67  dd->media_block_size = phys_dd->media_block_size;
68  dd->ioctl = phys_dd->ioctl;
69  dd->driver_data = phys_dd->driver_data;
70
71  if (phys_dd->phys_dev == phys_dd) {
72    rtems_blkdev_bnum phys_block_count = phys_dd->size;
73
74    if (
75      block_begin < phys_block_count
76        && block_count > 0
77        && block_count <= phys_block_count - block_begin
78    ) {
79      sc = rtems_bdbuf_set_block_size(dd, phys_dd->media_block_size);
80    } else {
81      sc = RTEMS_INVALID_NUMBER;
82    }
83  } else {
84    sc = RTEMS_INVALID_ID;
85  }
86
87  return sc;
88}
Note: See TracBrowser for help on using the repository browser.