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

4.115
Last change on this file since f6c7bcfe was f6c7bcfe, checked in by Mathew Kallada <matkallada@…>, on 12/21/12 at 17:42:39

libblock: Doxygen Enhancement Task #1

  • Property mode set to 100644
File size: 2.1 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
29rtems_status_code rtems_disk_init_phys(
30  rtems_disk_device *dd,
31  uint32_t block_size,
32  rtems_blkdev_bnum block_count,
33  rtems_block_device_ioctl handler,
34  void *driver_data
35)
36{
37  rtems_status_code sc;
38
39  dd = memset(dd, 0, sizeof(*dd));
40
41  dd->phys_dev = dd;
42  dd->size = block_count;
43  dd->media_block_size = block_size;
44  dd->ioctl = handler;
45  dd->driver_data = driver_data;
46  dd->read_ahead.trigger = RTEMS_DISK_READ_AHEAD_NO_TRIGGER;
47
48  if (block_count > 0) {
49    if ((*handler)(dd, RTEMS_BLKIO_CAPABILITIES, &dd->capabilities) != 0) {
50      dd->capabilities = 0;
51    }
52
53    sc = rtems_bdbuf_set_block_size(dd, block_size, false);
54  } else {
55    sc = RTEMS_INVALID_NUMBER;
56  }
57
58  return sc;
59}
60
61rtems_status_code rtems_disk_init_log(
62  rtems_disk_device *dd,
63  rtems_disk_device *phys_dd,
64  rtems_blkdev_bnum block_begin,
65  rtems_blkdev_bnum block_count
66)
67{
68  rtems_status_code sc;
69
70  dd = memset(dd, 0, sizeof(*dd));
71
72  dd->phys_dev = phys_dd;
73  dd->start = block_begin;
74  dd->size = block_count;
75  dd->media_block_size = phys_dd->media_block_size;
76  dd->ioctl = phys_dd->ioctl;
77  dd->driver_data = phys_dd->driver_data;
78  dd->read_ahead.trigger = RTEMS_DISK_READ_AHEAD_NO_TRIGGER;
79
80  if (phys_dd->phys_dev == phys_dd) {
81    rtems_blkdev_bnum phys_block_count = phys_dd->size;
82
83    if (
84      block_begin < phys_block_count
85        && block_count > 0
86        && block_count <= phys_block_count - block_begin
87    ) {
88      sc = rtems_bdbuf_set_block_size(dd, phys_dd->media_block_size, false);
89    } else {
90      sc = RTEMS_INVALID_NUMBER;
91    }
92  } else {
93    sc = RTEMS_INVALID_ID;
94  }
95
96  return sc;
97}
Note: See TracBrowser for help on using the repository browser.