1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/*
* FILE: dev_byte.h
* DESCR: device management: block-oriented devices
*/
#pragma once
#include "types.h"
#include "drivers/dev.h"
#include "util/list.h"
#include "mm/mobj.h"
#include "mm/page.h"
#define BLOCK_SIZE PAGE_SIZE
struct blockdev_ops;
/*
* Represents a Weenix block device.
*/
typedef struct blockdev
{
/* Fields that should be initialized by drivers: */
devid_t bd_id;
struct blockdev_ops *bd_ops;
#ifdef NO
/* Fields that should be ignored by drivers: */
mobj_t bd_mobj;
#endif
/* Link on the list of block-oriented devices */
list_link_t bd_link;
} blockdev_t;
typedef struct blockdev_ops
{
/**
* Reads a block from the block device. This call will block.
*
* @param bdev the block device
* @param buf the memory into which to read the block (must be
* page-aligned)
* @param loc the number of the block to start reading from
* @param count the number of blocks to read
* @return 0 on success, -errno on failure
*/
long (*read_block)(blockdev_t *bdev, char *buf, blocknum_t loc,
size_t block_count);
/**
* Writes a block to the block device. This call will block.
*
* @param bdev the block device
* @param buf the memory from which to write the block (must be
* page-aligned)
* @param loc the number of the block to start writing at
* @param count the number of blocks to write
* @return 0 on success, -errno on failure
*/
long (*write_block)(blockdev_t *bdev, const char *buf, blocknum_t loc,
size_t block_count);
} blockdev_ops_t;
/**
* Initializes the block device subsystem.
*/
void blockdev_init(void);
/**
* Registers a given block device.
*
* @param dev the block device to register
*/
long blockdev_register(blockdev_t *dev);
/**
* Finds a block device with a given device id.
*
* @param id the device id of the block device to find
* @return the block device with the given id if it exists, or NULL if
* it cannot be found
*/
blockdev_t *blockdev_lookup(devid_t id);
/**
* Cleans and frees all resident pages belonging to a given block
* device.
*
* @param dev the block device to flush
*/
void blockdev_flush_all(blockdev_t *dev);
// restructure, perhaps, so that these don't have to be exported
long blockdev_fill_pframe(mobj_t *mobj, pframe_t *pf);
long blockdev_flush_pframe(mobj_t *mobj, pframe_t *pf);
|