1 /* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
\r
3 Copyright (c) 2014-2015 Datalight, Inc.
\r
4 All Rights Reserved Worldwide.
\r
6 This program is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; use version 2 of the License.
\r
10 This program is distributed in the hope that it will be useful,
\r
11 but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
\r
12 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 GNU General Public License for more details.
\r
15 You should have received a copy of the GNU General Public License along
\r
16 with this program; if not, write to the Free Software Foundation, Inc.,
\r
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
19 /* Businesses and individuals that for commercial or other reasons cannot
\r
20 comply with the terms of the GPLv2 license may obtain a commercial license
\r
21 before incorporating Reliance Edge into proprietary software for
\r
22 distribution in any form. Visit http://www.datalight.com/reliance-edge for
\r
26 @brief Implements block device I/O using logical blocks as the units.
\r
28 The OS block device implementations operate on sectors. The core does I/O
\r
29 in terms of logical blocks: this module translates from logical blocks to
\r
33 #include <redcore.h>
\r
36 /** @brief Read a range of logical blocks.
\r
38 @param bVolNum The volume whose block device is being read from.
\r
39 @param ulBlockStart The first block to read.
\r
40 @param ulBlockCount The number of blocks to read.
\r
41 @param pBuffer The buffer to populate with the data read.
\r
43 @return A negated ::REDSTATUS code indicating the operation result.
\r
45 @retval 0 Operation was successful.
\r
46 @retval -RED_EIO A disk I/O error occurred.
\r
47 @retval -RED_EINVAL Invalid parameters.
\r
49 REDSTATUS RedIoRead(
\r
51 uint32_t ulBlockStart,
\r
52 uint32_t ulBlockCount,
\r
57 if( (bVolNum >= REDCONF_VOLUME_COUNT)
\r
58 || (ulBlockStart >= gaRedVolume[bVolNum].ulBlockCount)
\r
59 || ((gaRedVolume[bVolNum].ulBlockCount - ulBlockStart) < ulBlockCount)
\r
60 || (ulBlockCount == 0U)
\r
61 || (pBuffer == NULL))
\r
68 uint8_t bSectorShift = gaRedVolume[bVolNum].bBlockSectorShift;
\r
69 uint64_t ullSectorStart = (uint64_t)ulBlockStart << bSectorShift;
\r
70 uint32_t ulSectorCount = ulBlockCount << bSectorShift;
\r
72 REDASSERT(bSectorShift < 32U);
\r
73 REDASSERT((ulSectorCount >> bSectorShift) == ulBlockCount);
\r
75 ret = RedOsBDevRead(bVolNum, ullSectorStart, ulSectorCount, pBuffer);
\r
78 CRITICAL_ASSERT(ret == 0);
\r
84 #if REDCONF_READ_ONLY == 0
\r
85 /** @brief Write a range of logical blocks.
\r
87 @param bVolNum The volume whose block device is being written to.
\r
88 @param ulBlockStart The first block to write.
\r
89 @param ulBlockCount The number of blocks to write.
\r
90 @param pBuffer The buffer containing the data to write.
\r
92 @return A negated ::REDSTATUS code indicating the operation result.
\r
94 @retval 0 Operation was successful.
\r
95 @retval -RED_EIO A disk I/O error occurred.
\r
96 @retval -RED_EINVAL Invalid parameters.
\r
98 REDSTATUS RedIoWrite(
\r
100 uint32_t ulBlockStart,
\r
101 uint32_t ulBlockCount,
\r
102 const void *pBuffer)
\r
106 if( (bVolNum >= REDCONF_VOLUME_COUNT)
\r
107 || (ulBlockStart >= gaRedVolume[bVolNum].ulBlockCount)
\r
108 || ((gaRedVolume[bVolNum].ulBlockCount - ulBlockStart) < ulBlockCount)
\r
109 || (ulBlockCount == 0U)
\r
110 || (pBuffer == NULL))
\r
117 uint8_t bSectorShift = gaRedVolume[bVolNum].bBlockSectorShift;
\r
118 uint64_t ullSectorStart = (uint64_t)ulBlockStart << bSectorShift;
\r
119 uint32_t ulSectorCount = ulBlockCount << bSectorShift;
\r
121 REDASSERT(bSectorShift < 32U);
\r
122 REDASSERT((ulSectorCount >> bSectorShift) == ulBlockCount);
\r
124 ret = RedOsBDevWrite(bVolNum, ullSectorStart, ulSectorCount, pBuffer);
\r
127 CRITICAL_ASSERT(ret == 0);
\r
133 /** @brief Flush any caches beneath the file system.
\r
135 @param bVolNum The volume number of the volume whose block device is being
\r
138 @return A negated ::REDSTATUS code indicating the operation result.
\r
140 @retval 0 Operation was successful.
\r
141 @retval -RED_EINVAL @p bVolNum is an invalid volume number.
\r
142 @retval -RED_EIO A disk I/O error occurred.
\r
144 REDSTATUS RedIoFlush(
\r
149 if(bVolNum >= REDCONF_VOLUME_COUNT)
\r
156 ret = RedOsBDevFlush(bVolNum);
\r
159 CRITICAL_ASSERT(ret == 0);
\r
163 #endif /* REDCONF_READ_ONLY == 0 */
\r