37 static const char *block_type_names[
BLOCK_CNT] =
48 return block_type_names[
type];
111 PANIC (
"Access past end of device %s (sector=%"PRDSNu", "
174 printf (
"%s (%s): %llu reads, %llu writes\n",
193 PANIC (
"Failed to allocate memory for block device descriptor");
207 if (extra_info !=
NULL)
208 printf (
", %s", extra_info);
static struct list all_blocks
List of all block devices.
struct block * block_first(void)
Returns the first block device in kernel probe order, or a null pointer if no block devices are regis...
struct block * block_get_by_name(const char *name)
Returns the block device with the given NAME, or a null pointer if no block device has that name.
struct block * block_register(const char *name, enum block_type type, const char *extra_info, block_sector_t size, const struct block_operations *ops, void *aux)
Registers a new block device with the given NAME.
struct block * block_get_role(enum block_type role)
Returns the block device fulfilling the given ROLE, or a null pointer if no block device has been ass...
block_sector_t block_size(struct block *block)
Returns the number of sectors in BLOCK.
const char * block_type_name(enum block_type type)
Returns a human-readable name for the given block device TYPE.
void block_read(struct block *block, block_sector_t sector, void *buffer)
Reads sector SECTOR from BLOCK into BUFFER, which must have room for BLOCK_SECTOR_SIZE bytes.
void block_set_role(enum block_type role, struct block *block)
Assigns BLOCK the given ROLE.
static void check_sector(struct block *block, block_sector_t sector)
Verifies that SECTOR is a valid offset within BLOCK.
static struct block * block_by_role[BLOCK_ROLE_CNT]
The block block assigned to each Pintos role.
static struct block * list_elem_to_block(struct list_elem *)
Returns the block device corresponding to LIST_ELEM, or a null pointer if LIST_ELEM is the list end o...
void block_write(struct block *block, block_sector_t sector, const void *buffer)
Write sector SECTOR to BLOCK from BUFFER, which must contain BLOCK_SECTOR_SIZE bytes.
const char * block_name(struct block *block)
Returns BLOCK's name (e.g.
enum block_type block_type(struct block *block)
Returns BLOCK's type.
struct block * block_next(struct block *block)
Returns the block device following BLOCK in kernel probe order, or a null pointer if BLOCK is the las...
void block_print_stats(void)
Prints statistics for each block device used for a Pintos role.
uint32_t block_sector_t
Index of a block device sector.
#define BLOCK_SECTOR_SIZE
Size of a block device sector in bytes.
#define PRDSNu
Format specifier for printf(), e.g.
block_type
Type of a block device.
@ BLOCK_CNT
Number of Pintos block types.
@ BLOCK_FOREIGN
Owned by non-Pintos operating system.
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
#define PANIC(...)
Halts the OS, printing the source file name, line number, and function name, plus a user-specific mes...
struct list_elem * list_begin(struct list *list)
Returns the beginning of LIST.
struct list_elem * list_end(struct list *list)
Returns LIST's tail.
void list_push_back(struct list *list, struct list_elem *elem)
Inserts ELEM at the end of LIST, so that it becomes the back in LIST.
struct list_elem * list_next(struct list_elem *elem)
Returns the element after ELEM in its list.
void print_human_readable_size(uint64_t size)
Prints SIZE, which represents a number of bytes, in a human-readable format, e.g.
int printf(const char *format,...)
Writes formatted output to the console.
#define LIST_INITIALIZER(NAME)
List initialization.
#define list_entry(LIST_ELEM, STRUCT, MEMBER)
Converts pointer to list element LIST_ELEM into a pointer to the structure that LIST_ELEM is embedded...
void * malloc(size_t size)
Obtains and returns a new block of at least SIZE bytes.
unsigned long long int uint64_t
size_t strlcpy(char *dst, const char *src, size_t size)
Copies string SRC to DST.
int strcmp(const char *a_, const char *b_)
Finds the first differing characters in strings A and B.
Lower-level interface to block device drivers.
void(* write)(void *aux, block_sector_t, const void *buffer)
void(* read)(void *aux, block_sector_t, void *buffer)
unsigned long long write_cnt
Number of sectors written.
const struct block_operations * ops
Driver operations.
char name[16]
Block device name.
struct list_elem list_elem
Element in all_blocks.
enum block_type type
Type of block device.
void * aux
Extra data owned by driver.
block_sector_t size
Size in sectors.
unsigned long long read_cnt
Number of sectors read.