diff options
author | nthnluu <nate1299@me.com> | 2024-01-28 21:20:27 -0500 |
---|---|---|
committer | nthnluu <nate1299@me.com> | 2024-01-28 21:20:27 -0500 |
commit | c63f340d90800895f007de64b7d2d14624263331 (patch) | |
tree | 2c0849fa597dd6da831c8707b6f2603403778d7b /kernel/include/drivers/blockdev.h |
Created student weenix repository
Diffstat (limited to 'kernel/include/drivers/blockdev.h')
-rw-r--r-- | kernel/include/drivers/blockdev.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/kernel/include/drivers/blockdev.h b/kernel/include/drivers/blockdev.h new file mode 100644 index 0000000..d1b3062 --- /dev/null +++ b/kernel/include/drivers/blockdev.h @@ -0,0 +1,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);
\ No newline at end of file |