source: rtems/cpukit/include/rtems/sparse-disk.h @ 255fe43

Last change on this file since 255fe43 was 255fe43, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 20:40:44

cpukit/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_sparse_disk
5 *
6 * @brief Sparse disk block device API.
7 */
8
9/*
10 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
11 *
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#ifndef SPARSE_DISK_H
18#define SPARSE_DISK_H
19
20#include <stddef.h>
21#include <stdint.h>
22#include <rtems.h>
23#include <rtems/diskdevs.h>
24#include <rtems/thread.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif /* __cplusplus */
29
30/**
31 * @defgroup rtems_sparse_disk Sparse Disk Device
32 *
33 * @ingroup rtems_blkdev
34 *
35 */
36/**@{**/
37
38typedef struct {
39  rtems_blkdev_bnum  block;
40  void              *data;
41} rtems_sparse_disk_key;
42
43typedef struct rtems_sparse_disk rtems_sparse_disk;
44
45typedef void (*rtems_sparse_disk_delete_handler)(rtems_sparse_disk *sparse_disk);
46
47struct rtems_sparse_disk {
48  rtems_mutex                      mutex;
49  rtems_blkdev_bnum                blocks_with_buffer;
50  size_t                           used_count;
51  uint32_t                         media_block_size;
52  rtems_sparse_disk_delete_handler delete_handler;
53  uint8_t                          fill_pattern;
54  rtems_sparse_disk_key           *key_table;
55};
56
57/**
58 * @brief Creates and registers a sparse disk.
59 *
60 * @param[in] device_file_name The device file name path.
61 * @param[in] media_block_size The media block size in bytes.
62 * @param[in] blocks_with_buffer Blocks of the device with a buffer.  Other
63 * blocks can store only fill pattern value bytes.
64 * @param[in] block_count The media block count of the device.  It is the sum
65 * of blocks with buffer and blocks that contain only fill pattern value bytes.
66 * @param[in] fill_pattern The fill pattern specifies the byte value of blocks
67 * without a buffer.  It is also the initial value for blocks with a buffer.
68 *
69 * @retval RTEMS_SUCCESSFUL Successful operation.
70 * @retval RTEMS_INVALID_NUMBER Media block size or media block count is not
71 * positive.  The blocks with buffer count is greater than the media block count.
72 * @retval RTEMS_NO_MEMORY Not enough memory.
73 * @retval RTEMS_TOO_MANY Cannot create semaphore.
74 * @retval RTEMS_UNSATISFIED Cannot create generic device node.
75 *
76 * @see rtems_sparse_disk_register().
77 */
78rtems_status_code rtems_sparse_disk_create_and_register(
79  const char        *device_file_name,
80  uint32_t           media_block_size,
81  rtems_blkdev_bnum  blocks_with_buffer,
82  rtems_blkdev_bnum  media_block_count,
83  uint8_t            fill_pattern
84);
85
86/**
87 * @brief Frees a sparse disk.
88 *
89 * Calls free() on the sparse disk pointer.
90 */
91void rtems_sparse_disk_free( rtems_sparse_disk *sparse_disk );
92
93/**
94 * @brief Initializes and registers a sparse disk.
95 *
96 * This will create one semaphore for mutual exclusion.
97 *
98 * @param[in] device_file_name The device file name path.
99 * @param[in, out] sparse_disk The sparse disk.
100 * @param[in] media_block_size The media block size in bytes.
101 * @param[in] blocks_with_buffer Blocks of the device with a buffer.  Other
102 * blocks can store only fill pattern value bytes.
103 * @param[in] block_count The media block count of the device.  It is the sum
104 * of blocks with buffer and blocks that contain only fill pattern value bytes.
105 * @param[in] fill_pattern The fill pattern specifies the byte value of blocks
106 * without a buffer.  It is also the initial value for blocks with a buffer.
107 * @param[in] sparse_disk_delete The sparse disk delete handler.
108 *
109 * @retval RTEMS_SUCCESSFUL Successful operation.
110 * @retval RTEMS_INVALID_NUMBER Media block size or media block count is not
111 * positive.  The blocks with buffer count is greater than the media block count.
112 * @retval RTEMS_INVALID_ADDRESS Invalid sparse disk address.
113 * @retval RTEMS_TOO_MANY Cannot create semaphore.
114 * @retval RTEMS_UNSATISFIED Cannot create generic device node.
115 */
116rtems_status_code rtems_sparse_disk_register(
117  const char                       *device_file_name,
118  rtems_sparse_disk                *sparse_disk,
119  uint32_t                          media_block_size,
120  rtems_blkdev_bnum                 blocks_with_buffer,
121  rtems_blkdev_bnum                 media_block_count,
122  uint8_t                           fill_pattern,
123  rtems_sparse_disk_delete_handler  sparse_disk_delete
124);
125
126/** @} */
127
128#ifdef __cplusplus
129}
130#endif /* __cplusplus */
131
132#endif /* SPARSE_DISK_H */
Note: See TracBrowser for help on using the repository browser.