source: rtems/cpukit/include/rtems/sparse-disk.h @ 7e86e00

5
Last change on this file since 7e86e00 was 868ca746, checked in by Sebastian Huber <sebastian.huber@…>, on 01/02/18 at 15:40:21

libblock: Use self-contained mutex for sparse disk

Update #2843.

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