PKUOS - Pintos
Pintos source browser for PKU Operating System course
|
Go to the source code of this file.
Data Structures | |
struct | block_operations |
Lower-level interface to block device drivers. More... | |
Macros | |
#define | BLOCK_SECTOR_SIZE 512 |
Size of a block device sector in bytes. More... | |
#define | PRDSNu PRIu32 |
Format specifier for printf(), e.g. More... | |
Typedefs | |
typedef uint32_t | block_sector_t |
Index of a block device sector. More... | |
Enumerations | |
enum | block_type { BLOCK_KERNEL , BLOCK_FILESYS , BLOCK_SCRATCH , BLOCK_SWAP , BLOCK_ROLE_CNT , BLOCK_RAW = BLOCK_ROLE_CNT , BLOCK_FOREIGN , BLOCK_CNT } |
Type of a block device. More... | |
Functions | |
const char * | block_type_name (enum block_type) |
Returns a human-readable name for the given block device TYPE. More... | |
struct block * | block_get_role (enum block_type) |
Finding block devices. More... | |
void | block_set_role (enum block_type, struct block *) |
Assigns BLOCK the given ROLE. More... | |
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. More... | |
struct block * | block_first (void) |
Returns the first block device in kernel probe order, or a null pointer if no block devices are registered. More... | |
struct block * | block_next (struct block *) |
Returns the block device following BLOCK in kernel probe order, or a null pointer if BLOCK is the last block device. More... | |
block_sector_t | block_size (struct block *) |
Block device operations. More... | |
void | block_read (struct block *, block_sector_t, void *) |
Reads sector SECTOR from BLOCK into BUFFER, which must have room for BLOCK_SECTOR_SIZE bytes. More... | |
void | block_write (struct block *, block_sector_t, const void *) |
Write sector SECTOR to BLOCK from BUFFER, which must contain BLOCK_SECTOR_SIZE bytes. More... | |
const char * | block_name (struct block *) |
Returns BLOCK's name (e.g. More... | |
enum block_type | block_type (struct block *) |
Returns BLOCK's type. More... | |
void | block_print_stats (void) |
Statistics. More... | |
struct block * | block_register (const char *name, enum block_type, const char *extra_info, block_sector_t size, const struct block_operations *, void *aux) |
devices/block.h More... | |
#define BLOCK_SECTOR_SIZE 512 |
#define PRDSNu PRIu32 |
typedef uint32_t block_sector_t |
enum block_type |
struct block * block_first | ( | void | ) |
Returns the first block device in kernel probe order, or a null pointer if no block devices are registered.
Definition at line 71 of file block.c.
References all_blocks, list_begin(), and list_elem_to_block().
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.
Definition at line 87 of file block.c.
References all_blocks, list_begin(), list_end(), list_entry, list_next(), block::name, name, NULL, and strcmp().
struct block * block_get_role | ( | enum block_type | role | ) |
Finding block devices.
Finding block devices.
Definition at line 54 of file block.c.
References ASSERT, block_by_role, and BLOCK_ROLE_CNT.
Referenced by filesys_init(), fsutil_append(), and fsutil_extract().
const char * block_name | ( | struct block * | block | ) |
Returns BLOCK's name (e.g.
"hda").
Definition at line 151 of file block.c.
References block::name.
Referenced by check_sector(), found_partition(), partition_scan(), and read_partition_table().
Returns the block device following BLOCK in kernel probe order, or a null pointer if BLOCK is the last block device.
Definition at line 79 of file block.c.
References block::list_elem, list_elem_to_block(), and list_next().
void block_print_stats | ( | void | ) |
Statistics.
Statistics.
Definition at line 165 of file block.c.
References block_by_role, BLOCK_ROLE_CNT, block_type_name(), block::name, NULL, printf(), block::read_cnt, block::type, and block::write_cnt.
Referenced by print_stats().
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.
Internally synchronizes accesses to block devices, so external per-block device locking is unneeded.
Definition at line 121 of file block.c.
References block::aux, buffer, check_sector(), block::ops, block_operations::read, and block::read_cnt.
Referenced by fsutil_extract(), inode_open(), inode_read_at(), inode_write_at(), partition_read(), and read_partition_table().
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 | ||
) |
If EXTRA_INFO is non-null, it is printed as part of a user message. The block device's SIZE in sectors and its TYPE must be provided, as well as the it operation functions OPS, which will be passed AUX in each function call.
Definition at line 187 of file block.c.
References all_blocks, block::aux, BLOCK_SECTOR_SIZE, block::list_elem, list_push_back(), malloc(), block::name, name, NULL, block::ops, PANIC, PRDSNu, print_human_readable_size(), printf(), block::read_cnt, block::size, strlcpy(), block::type, and block::write_cnt.
Referenced by found_partition(), and identify_ata_device().
void block_set_role | ( | enum | block_type, |
struct block * | block | ||
) |
Assigns BLOCK the given ROLE.
Definition at line 62 of file block.c.
References ASSERT, block_by_role, and BLOCK_ROLE_CNT.
block_sector_t block_size | ( | struct block * | block | ) |
Block device operations.
Block device operations.
Definition at line 144 of file block.c.
References block::size.
Referenced by bitmap_create_in_buf(), check_file_handle(), found_partition(), free_map_init(), fsutil_append(), read_partition_table(), seq_test(), and write_some_bytes().
enum block_type block_type | ( | struct block * | block | ) |
const char * block_type_name | ( | enum | block_type | ) |
Returns a human-readable name for the given block device TYPE.
Definition at line 35 of file block.c.
References ASSERT, BLOCK_CNT, and block::type.
Referenced by block_print_stats().
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.
Returns after the block device has acknowledged receiving the data. Internally synchronizes accesses to block devices, so external per-block device locking is unneeded.
Definition at line 134 of file block.c.
References ASSERT, block::aux, BLOCK_FOREIGN, buffer, check_sector(), block::ops, block::type, block_operations::write, and block::write_cnt.
Referenced by fsutil_append(), fsutil_extract(), inode_create(), inode_write_at(), and partition_write().