KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
blockdev.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 kos/blockdev.h
4 Copyright (C) 2012, 2013 Lawrence Sebald
5*/
6
7/** \file kos/blockdev.h
8 \brief Definitions for a simple block device interface.
9 \ingroup vfs_blockdev
10
11 This file contains the definition of a very simple block device that is to
12 be used with filesystems in the kernel. This device interface is designed to
13 abstract away direct hardware access and make it easier to interface the
14 various filesystems that we may add support for to multiple potential
15 devices.
16
17 The most common of these devices that people are probably interested in
18 directly would be the Dreamcast SD card reader, and that was indeed the
19 primary impetus to this device structure. However, it could also be used
20 to support a file-based disk image or any number of other devices.
21
22 \author Lawrence Sebald
23*/
24
25#ifndef __KOS_BLOCKDEV_H
26#define __KOS_BLOCKDEV_H
27
28#include <sys/cdefs.h>
29__BEGIN_DECLS
30
31#include <stdint.h>
32#include <sys/types.h>
33
34/** \defgroup vfs_blockdev Block Devices
35 \brief VFS driver for accessing block devices
36 \ingroup vfs_drivers
37
38 @{
39*/
40
41/** \brief A simple block device.
42
43 This structure represents a single block device. Each block device should be
44 associated with exactly one filesystem and is used to actually read the data
45 from the disk (or other device) where it is stored.
46
47 By using a block device with any new filesystems, we can abstract away a few
48 things so that filesystems can be used with a variety of different
49 "devices", such as the SD card reader for the Dreamcast or a disk image file
50 of some sort.
51
52 \headerfile kos/blockdev.h
53*/
54typedef struct kos_blockdev {
55 void *dev_data; /**< \brief Internal device data. */
56 uint32_t l_block_size; /**< \brief Log base 2 of the bytes per block. */
57
58 /** \brief Initialize the block device.
59
60 This function should do any necessary initialization to use the block
61 device passed in.
62
63 \param d The device to initialize.
64 \retval 0 On success.
65 \retval -1 On failure. Set errno as appropriate.
66 */
67 int (*init)(struct kos_blockdev *d);
68
69 /** \brief Shut down the block device.
70
71 This function should do any teardown work that is needed to clean up
72 the block device.
73
74 \param d The device to shut down.
75 \retval 0 On success.
76 \retval -1 On failure. Set errno as appropriate.
77 */
78 int (*shutdown)(struct kos_blockdev *d);
79
80 /** \brief Read a number of blocks from the device.
81
82 This function should read the specified number of device blocks into
83 the given buffer. The buffer will already be allocated by the caller.
84
85 \param d The device to read from.
86 \param block The first block to read.
87 \param count The number of blocks to read.
88 \param buf The buffer to read into.
89 \retval 0 On success.
90 \retval -1 On failure. Set errno as appropriate.
91 */
92 int (*read_blocks)(struct kos_blockdev *d, uint64_t block, size_t count,
93 void *buf);
94
95 /** \brief Write a number of blocks to the device.
96
97 This function should write the specified number of device blocks onto
98 the device from the given buffer.
99
100 \param d The device to write to.
101 \param block The first block to write.
102 \param count The number of blocks to write.
103 \param buf The buffer to write from.
104 \retval 0 On success.
105 \retval -1 On failure. Set errno as appropriate.
106 */
107 int (*write_blocks)(struct kos_blockdev *d, uint64_t block, size_t count,
108 const void *buf);
109
110 /** \brief Count the number of blocks on the device.
111
112 This function should return the total number of blocks on the device.
113 There is no expectation of the device to keep track of which blocks are
114 in use or anything else of the sort.
115
116 \param d The device to read the block count from.
117 \return The number of blocks that the device has.
118 */
119 uint64_t (*count_blocks)(struct kos_blockdev *d);
120
121 /** \brief Flush the write cache (if any) of the device.
122
123 This function shall signal to the device that any write caches that are
124 present on the device shall be flushed so that all data written to this
125 point shall persist to the underlying storage.
126
127 \param d The device to flush caches on.
128 \retval 0 On success.
129 \retval -1 On failure. Set errno as appropriate.
130 */
131 int (*flush)(struct kos_blockdev *d);
133
134/** @} */
135
136__END_DECLS
137
138#endif /* !__KOS_BLOCKDEV_H */
int shutdown(int socket, int how)
Shutdown socket send and receive operations.
A simple block device.
Definition blockdev.h:54
void * dev_data
Internal device data.
Definition blockdev.h:55
uint32_t l_block_size
Log base 2 of the bytes per block.
Definition blockdev.h:56