diff options
| author | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
| commit | 4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b (patch) | |
| tree | 868c52e06f207b5ec8a3cc141f4b8b2bdfcc165c /devices/block.h | |
| parent | eae0bd57f0a26314a94785061888d193d186944a (diff) | |
| download | progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.gz progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.bz2 progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.zip | |
reorganize file structure to match the upstream requirements
Diffstat (limited to 'devices/block.h')
| -rw-r--r-- | devices/block.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/devices/block.h b/devices/block.h new file mode 100644 index 0000000..21732d6 --- /dev/null +++ b/devices/block.h | |||
| @@ -0,0 +1,74 @@ | |||
| 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. */ | ||
| 15 | typedef uint32_t block_sector_t; | ||
| 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. */ | ||
| 26 | enum block_type | ||
| 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. */ | ||
| 33 | BLOCK_ROLE_CNT, | ||
| 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. */ | ||
| 53 | block_sector_t block_size (struct block *); | ||
| 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 | |||
| 64 | struct block_operations | ||
| 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 */ | ||
