My Kernel v0.1.0
block.h
1#ifndef KERNEL_DEVICES_BLOCK_H
2#define KERNEL_DEVICES_BLOCK_H
3
4#include <kernel/device.h>
5#include <kernel/spinlock.h>
6
7#include <libalgo/queue.h>
8#include <utils/container_of.h>
9
10#include <sys/types.h>
11
12struct block_device {
13 struct device dev;
14 blksize_t block_size;
15 blkcnt_t block_count;
16 const struct block_device_ops *ops;
17};
18
19static inline struct block_device *to_blkdev(struct device *dev)
20{
21 return container_of(dev, struct block_device, dev);
22}
23
24enum block_io_request_type {
25 BLOCK_IO_REQUEST_READ,
26 BLOCK_IO_REQUEST_WRITE,
27};
28
29struct block_io_request {
30 enum block_io_request_type type;
31 off_t offset; /* Offset into the block device. */
32 blkcnt_t count; /* Number of blocks to read/write. */
33 void *buf;
34};
35
36struct block_device_ops {
37 error_t (*request)(struct block_device *, struct block_io_request *);
38};
39
40error_t block_device_register(struct block_device *);
41
42static inline size_t block_device_size(struct block_device *blkdev)
43{
44 return blkdev->block_count * blkdev->block_size;
45}
46
55void *block_read(struct block_device *, blkcnt_t block_index);
56
58void block_free(struct block_device *blkdev, void *block);
59
60#endif /* KERNEL_DEVICES_BLOCK_H */
#define container_of(_ptr, _struct, _field)
Cast a member of a structure out to the containing structure.
Definition: container_of.h:12
Represents a device inside the kernel.
Definition: device.h:78