CS318 - Pintos
Pintos source browser for JHU CS318 course
block.h
Go to the documentation of this file.
1 #ifndef DEVICES_BLOCK_H
2 #define DEVICES_BLOCK_H
3 
4 #include <stddef.h>
5 #include <inttypes.h>
6 
7 /** Size of a block device sector in bytes.
8  All IDE disks use this sector size, as do most USB and SCSI
9  disks. It's not worth it to try to cater to other sector
10  sizes in Pintos (yet). */
11 #define BLOCK_SECTOR_SIZE 512
12 
13 /** Index of a block device sector.
14  Good enough for devices up to 2 TB. */
16 
17 /** Format specifier for printf(), e.g.:
18  printf ("sector=%"PRDSNu"\n", sector); */
19 #define PRDSNu PRIu32
20 
21 /** Higher-level interface for file systems, etc. */
22 
23 struct block;
24 
25 /** Type of a block device. */
27  {
28  /* Block device types that play a role in Pintos. */
29  BLOCK_KERNEL, /**< Pintos OS kernel. */
30  BLOCK_FILESYS, /**< File system. */
31  BLOCK_SCRATCH, /**< Scratch. */
32  BLOCK_SWAP, /**< Swap. */
34 
35  /* Other kinds of block devices that Pintos may see but does
36  not interact with. */
37  BLOCK_RAW = BLOCK_ROLE_CNT, /**< "Raw" device with unidentified contents. */
38  BLOCK_FOREIGN, /**< Owned by non-Pintos operating system. */
39  BLOCK_CNT /**< Number of Pintos block types. */
40  };
41 
42 const char *block_type_name (enum block_type);
43 
44 /** Finding block devices. */
45 struct block *block_get_role (enum block_type);
46 void block_set_role (enum block_type, struct block *);
47 struct block *block_get_by_name (const char *name);
48 
49 struct block *block_first (void);
50 struct block *block_next (struct block *);
51 
52 /** Block device operations. */
54 void block_read (struct block *, block_sector_t, void *);
55 void block_write (struct block *, block_sector_t, const void *);
56 const char *block_name (struct block *);
57 enum block_type block_type (struct block *);
58 
59 /** Statistics. */
60 void block_print_stats (void);
61 
62 /** Lower-level interface to block device drivers. */
63 
65  {
66  void (*read) (void *aux, block_sector_t, void *buffer);
67  void (*write) (void *aux, block_sector_t, const void *buffer);
68  };
69 
70 struct block *block_register (const char *name, enum block_type,
71  const char *extra_info, block_sector_t size,
72  const struct block_operations *, void *aux);
73 
74 #endif /**< devices/block.h */
name
char * name[]
Definition: insult.c:47
BLOCK_SWAP
Swap.
Definition: block.h:32
block_write
void block_write(struct block *, block_sector_t, const void *)
Write sector SECTOR to BLOCK from BUFFER, which must contain BLOCK_SECTOR_SIZE bytes.
Definition: block.c:134
BLOCK_FOREIGN
Owned by non-Pintos operating system.
Definition: block.h:38
block_print_stats
void block_print_stats(void)
Statistics.
Definition: block.c:165
block_operations
Lower-level interface to block device drivers.
Definition: block.h:64
block_operations::read
void(* read)(void *aux, block_sector_t, void *buffer)
Definition: block.h:66
BLOCK_CNT
Number of Pintos block types.
Definition: block.h:39
block::size
block_sector_t size
Size in sectors.
Definition: block.c:15
block_sector_t
uint32_t block_sector_t
Index of a block device sector.
Definition: block.h:15
BLOCK_RAW
"Raw" device with unidentified contents.
Definition: block.h:37
uint32_t
unsigned int uint32_t
Definition: stdint.h:26
buffer
static struct intq buffer
Stores keys from the keyboard and serial port.
Definition: input.c:7
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 regis...
Definition: block.c:71
block_set_role
void block_set_role(enum block_type, struct block *)
Assigns BLOCK the given ROLE.
Definition: block.c:62
block_type_name
const char * block_type_name(enum block_type)
Returns a human-readable name for the given block device TYPE.
Definition: block.c:35
BLOCK_ROLE_CNT
Definition: block.h:33
BLOCK_SCRATCH
Scratch.
Definition: block.h:31
block_name
const char * block_name(struct block *)
Returns BLOCK's name (e.g.
Definition: block.c:151
block
A block device.
Definition: block.c:9
BLOCK_KERNEL
Pintos OS kernel.
Definition: block.h:29
block_operations::write
void(* write)(void *aux, block_sector_t, const void *buffer)
Definition: block.h:67
block_type
block_type
Type of a block device.
Definition: block.h:26
block_register
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
Definition: block.c:187
block::aux
void * aux
Extra data owned by driver.
Definition: block.c:18
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: block.c:87
block_get_role
struct block * block_get_role(enum block_type)
Finding block devices.
Definition: block.c:54
BLOCK_FILESYS
File system.
Definition: block.h:30
block_read
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.
Definition: block.c:121
inttypes.h
stddef.h
block_size
block_sector_t block_size(struct block *)
Block device operations.
Definition: block.c:144
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 las...
Definition: block.c:79