CS318 - Pintos
Pintos source browser for JHU CS318 course
Data Structures | Macros | Typedefs | Enumerations | Functions
block.h File Reference
#include <stddef.h>
#include <inttypes.h>
Include dependency graph for block.h:
This graph shows which files directly or indirectly include this file:

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 blockblock_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 blockblock_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 blockblock_first (void)
 Returns the first block device in kernel probe order, or a null pointer if no block devices are registered. More...
 
struct blockblock_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 blockblock_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...
 

Macro Definition Documentation

◆ BLOCK_SECTOR_SIZE

#define BLOCK_SECTOR_SIZE   512

Size of a block device sector in bytes.

All IDE disks use this sector size, as do most USB and SCSI disks. It's not worth it to try to cater to other sector sizes in Pintos (yet).

Definition at line 11 of file block.h.

◆ PRDSNu

#define PRDSNu   PRIu32

Format specifier for printf(), e.g.

: printf ("sector=%"PRDSNu"\n", sector);

Definition at line 19 of file block.h.

Typedef Documentation

◆ block_sector_t

Index of a block device sector.

Good enough for devices up to 2 TB.

Definition at line 15 of file block.h.

Enumeration Type Documentation

◆ block_type

enum block_type

Type of a block device.

Enumerator
BLOCK_KERNEL 

Pintos OS kernel.

BLOCK_FILESYS 

File system.

BLOCK_SCRATCH 

Scratch.

BLOCK_SWAP 

Swap.

BLOCK_ROLE_CNT 
BLOCK_RAW 

"Raw" device with unidentified contents.

BLOCK_FOREIGN 

Owned by non-Pintos operating system.

BLOCK_CNT 

Number of Pintos block types.

Definition at line 26 of file block.h.

Function Documentation

◆ block_first()

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().

Here is the call graph for this function:

◆ block_get_by_name()

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().

Here is the call graph for this function:

◆ block_get_role()

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().

Here is the caller graph for this function:

◆ block_name()

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().

Here is the caller graph for this function:

◆ block_next()

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.

Definition at line 79 of file block.c.

References block::list_elem, list_elem_to_block(), and list_next().

Here is the call graph for this function:

◆ block_print_stats()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_read()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_register()

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 
)

devices/block.h

devices/block.h

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_set_role()

void block_set_role ( enum  block_type,
struct block  
)

Assigns BLOCK the given ROLE.

Definition at line 62 of file block.c.

References ASSERT, block_by_role, and BLOCK_ROLE_CNT.

◆ block_size()

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().

Here is the caller graph for this function:

◆ block_type()

enum block_type block_type ( struct block )

Returns BLOCK's type.

Definition at line 158 of file block.c.

References block::type.

◆ block_type_name()

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().

Here is the caller graph for this function:

◆ block_write()

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().

Here is the call graph for this function:
Here is the caller graph for this function: