source: rtems/cpukit/libblock/src/diskdevs-init.c @ 66c0078

4.115
Last change on this file since 66c0078 was 7660e8b3, checked in by Sebastian Huber <sebastian.huber@…>, on 07/23/13 at 11:32:58

Include missing <string.h>

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