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

Last change on this file since f381e9b was f381e9b, checked in by Joel Sherrill <joel@…>, on 02/17/22 at 15:47:33

cpukit/libblock: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup rtems_disk Block Device Disk Management
7 *
8 * @brief Block Device Disk Management Initialize
9 */
10
11/*
12 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
13 *
14 *  embedded brains GmbH
15 *  Obere Lagerstr. 30
16 *  82178 Puchheim
17 *  Germany
18 *  <rtems@embedded-brains.de>
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 * 1. Redistributions of source code must retain the above copyright
24 *    notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 *    notice, this list of conditions and the following disclaimer in the
27 *    documentation and/or other materials provided with the distribution.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 */
41
42#ifdef HAVE_CONFIG_H
43#include "config.h"
44#endif
45
46#include <rtems/blkdev.h>
47#include <rtems/bdbuf.h>
48
49#include <string.h>
50
51rtems_status_code rtems_disk_init_phys(
52  rtems_disk_device *dd,
53  uint32_t block_size,
54  rtems_blkdev_bnum block_count,
55  rtems_block_device_ioctl handler,
56  void *driver_data
57)
58{
59  rtems_status_code sc;
60
61  dd = memset(dd, 0, sizeof(*dd));
62
63  dd->phys_dev = dd;
64  dd->size = block_count;
65  dd->media_block_size = block_size;
66  dd->ioctl = handler;
67  dd->driver_data = driver_data;
68  dd->read_ahead.trigger = RTEMS_DISK_READ_AHEAD_NO_TRIGGER;
69
70  if (block_count > 0) {
71    if ((*handler)(dd, RTEMS_BLKIO_CAPABILITIES, &dd->capabilities) != 0) {
72      dd->capabilities = 0;
73    }
74
75    sc = rtems_bdbuf_set_block_size(dd, block_size, false);
76  } else {
77    sc = RTEMS_INVALID_NUMBER;
78  }
79
80  return sc;
81}
82
83rtems_status_code rtems_disk_init_log(
84  rtems_disk_device *dd,
85  rtems_disk_device *phys_dd,
86  rtems_blkdev_bnum block_begin,
87  rtems_blkdev_bnum block_count
88)
89{
90  rtems_status_code sc;
91
92  dd = memset(dd, 0, sizeof(*dd));
93
94  dd->phys_dev = phys_dd;
95  dd->start = block_begin;
96  dd->size = block_count;
97  dd->media_block_size = phys_dd->media_block_size;
98  dd->ioctl = phys_dd->ioctl;
99  dd->driver_data = phys_dd->driver_data;
100  dd->read_ahead.trigger = RTEMS_DISK_READ_AHEAD_NO_TRIGGER;
101
102  if (phys_dd->phys_dev == phys_dd) {
103    rtems_blkdev_bnum phys_block_count = phys_dd->size;
104
105    if (
106      block_begin < phys_block_count
107        && block_count > 0
108        && block_count <= phys_block_count - block_begin
109    ) {
110      sc = rtems_bdbuf_set_block_size(dd, phys_dd->media_block_size, false);
111    } else {
112      sc = RTEMS_INVALID_NUMBER;
113    }
114  } else {
115    sc = RTEMS_INVALID_ID;
116  }
117
118  return sc;
119}
Note: See TracBrowser for help on using the repository browser.