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

Last change on this file was bcef89f2, checked in by Sebastian Huber <sebastian.huber@…>, on 05/19/23 at 06:18:25

Update company name

The embedded brains GmbH & Co. KG is the legal successor of embedded
brains GmbH.

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