diff options
author | 2016-01-22 12:31:04 +0000 | |
---|---|---|
committer | 2016-01-22 12:31:04 +0000 | |
commit | 6a5c25959591cb7b80e5b4304a2fc15fdb9cd38e (patch) | |
tree | 6db73539880f704d283d09eecf8053b168184a0c | |
parent | Drop packets whose VNI flag is not set and VNI is not zero (diff) | |
download | wireguard-openbsd-6a5c25959591cb7b80e5b4304a2fc15fdb9cd38e.tar.xz wireguard-openbsd-6a5c25959591cb7b80e5b4304a2fc15fdb9cd38e.zip |
Merge read_block() and read_file_media() into read_block(). Ditto
write_block() and write_file_media(). One layer of read/write
wrappers for pread/pwrite should be enough for anyone.
-rw-r--r-- | sbin/pdisk/file_media.c | 21 | ||||
-rw-r--r-- | sbin/pdisk/file_media.h | 6 | ||||
-rw-r--r-- | sbin/pdisk/partition_map.c | 39 | ||||
-rw-r--r-- | sbin/pdisk/validate.c | 7 |
4 files changed, 25 insertions, 48 deletions
diff --git a/sbin/pdisk/file_media.c b/sbin/pdisk/file_media.c index e1a1960e5ea..c51c234a2a6 100644 --- a/sbin/pdisk/file_media.c +++ b/sbin/pdisk/file_media.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file_media.c,v 1.37 2016/01/21 15:33:21 krw Exp $ */ +/* $OpenBSD: file_media.c,v 1.38 2016/01/22 12:31:04 krw Exp $ */ /* * file_media.c - @@ -35,14 +35,13 @@ #include "file_media.h" -long -read_file_media(int fd, long long offset, unsigned long count, - void *address) +int +read_block(int fd, off_t offset, void *address) { ssize_t off; - off = pread(fd, address, count, offset); - if (off == count) + off = pread(fd, address, DEV_BSIZE, offset); + if (off == DEV_BSIZE) return (1); if (off == 0) @@ -55,15 +54,13 @@ read_file_media(int fd, long long offset, unsigned long count, return (0); } - -long -write_file_media(int fd, long long offset, unsigned long count, - void *address) +int +write_block(int fd, off_t offset, void *address) { ssize_t off; - off = pwrite(fd, address, count, offset); - if (off == count) + off = pwrite(fd, address, DEV_BSIZE, offset); + if (off == DEV_BSIZE) return (1); warn("writing to file failed"); diff --git a/sbin/pdisk/file_media.h b/sbin/pdisk/file_media.h index fdb8f602952..a85466dbb97 100644 --- a/sbin/pdisk/file_media.h +++ b/sbin/pdisk/file_media.h @@ -1,4 +1,4 @@ -/* $OpenBSD: file_media.h,v 1.14 2016/01/21 15:33:21 krw Exp $ */ +/* $OpenBSD: file_media.h,v 1.15 2016/01/22 12:31:04 krw Exp $ */ /* * file_media.h - @@ -30,7 +30,7 @@ #ifndef __file_media__ #define __file_media__ -long read_file_media(int, long long, unsigned long, void *); -long write_file_media(int, long long, unsigned long, void *); +int read_block(int, off_t, void *); +int write_block(int, off_t, void *); #endif /* __file_media__ */ diff --git a/sbin/pdisk/partition_map.c b/sbin/pdisk/partition_map.c index 181ace6a1d3..6674d91b2c2 100644 --- a/sbin/pdisk/partition_map.c +++ b/sbin/pdisk/partition_map.c @@ -1,4 +1,4 @@ -/* $OpenBSD: partition_map.c,v 1.46 2016/01/22 04:16:25 krw Exp $ */ +/* $OpenBSD: partition_map.c,v 1.47 2016/01/22 12:31:04 krw Exp $ */ /* * partition_map.c - partition map routines @@ -66,14 +66,10 @@ struct dpme *create_data(const char *, const char *, uint32_t, uint32_t); void delete_entry(struct partition_map *); void insert_in_base_order(struct partition_map *); void insert_in_disk_order(struct partition_map *); -int read_block(struct partition_map_header *, unsigned long, - char *); int read_partition_map(struct partition_map_header *); void remove_driver(struct partition_map *); void remove_from_disk_order(struct partition_map *); void renumber_disk_addresses(struct partition_map_header *); -int write_block(struct partition_map_header *, unsigned long, - char *); struct partition_map_header * open_partition_map(int fd, char *name, uint64_t mediasz) @@ -103,9 +99,9 @@ open_partition_map(int fd, char *name, uint64_t mediasz) free(map); return NULL; } - if (read_file_media(map->fd, 0, DEV_BSIZE, (char *) map->misc) == 0 || - convert_block0(map->misc, 1) || - coerce_block0(map)) { + if (read_block(map->fd, 0, map->misc) == 0 || + convert_block0(map->misc, 1) || + coerce_block0(map)) { warnx("Can't read block 0 from '%s'", name); free_partition_map(map); return NULL; @@ -159,7 +155,7 @@ read_partition_map(struct partition_map_header * map) warn("can't allocate memory for disk buffers"); return -1; } - if (read_block(map, 1, (char *) data) == 0) { + if (read_block(map->fd, DEV_BSIZE, data) == 0) { warnx("Can't read block 1 from '%s'", map->name); free(data); return -1; @@ -168,7 +164,7 @@ read_partition_map(struct partition_map_header * map) old_logical = map->logical_block; map->logical_block = 512; while (map->logical_block <= map->physical_block) { - if (read_block(map, 1, (char *) data) == 0) { + if (read_block(map->fd, DEV_BSIZE, data) == 0) { warnx("Can't read block 1 from '%s'", map->name); free(data); @@ -206,7 +202,7 @@ read_partition_map(struct partition_map_header * map) warn("can't allocate memory for disk buffers"); return -1; } - if (read_block(map, ix, (char *) data) == 0) { + if (read_block(map->fd, ix * DEV_BSIZE, data) == 0) { warnx("Can't read block %u from '%s'", ix, map->name); free(data); return -1; @@ -231,12 +227,12 @@ write_partition_map(struct partition_map_header * map) if (map->misc != NULL) { convert_block0(map->misc, 0); - result = write_block(map, 0, (char *) map->misc); + result = write_block(map->fd, 0, map->misc); convert_block0(map->misc, 1); } else { block = calloc(1, DEV_BSIZE); if (block != NULL) { - result = write_block(map, 0, block); + result = write_block(map->fd, 0, block); free(block); } } @@ -246,8 +242,7 @@ write_partition_map(struct partition_map_header * map) for (entry = map->disk_order; entry != NULL; entry = entry->next_on_disk) { convert_dpme(entry->data, 0); - result = write_block(map, entry->disk_address, - (char *)entry->data); + result = write_block(map->fd, entry->disk_address, entry->data); convert_dpme(entry->data, 1); i = entry->disk_address; if (result == 0) { @@ -1056,17 +1051,3 @@ remove_driver(struct partition_map * entry) } } -int -read_block(struct partition_map_header * map, unsigned long num, char *buf) -{ - return read_file_media(map->fd, ((long long) num) * map->logical_block, - DEV_BSIZE, (void *) buf); -} - - -int -write_block(struct partition_map_header * map, unsigned long num, char *buf) -{ - return write_file_media(map->fd, ((long long) num) * map->logical_block, - DEV_BSIZE, (void *) buf); -} diff --git a/sbin/pdisk/validate.c b/sbin/pdisk/validate.c index 64312d5bd1b..2a6d3a0c50f 100644 --- a/sbin/pdisk/validate.c +++ b/sbin/pdisk/validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: validate.c,v 1.29 2016/01/21 15:33:21 krw Exp $ */ +/* $OpenBSD: validate.c,v 1.30 2016/01/22 12:31:04 krw Exp $ */ /* * validate.c - @@ -77,8 +77,7 @@ get_block_zero(void) b0 = the_map->misc; rtn_value = 1; } else { - if (read_file_media(the_fd, (long long) 0, DEV_BSIZE, - buffer) == 0) { + if (read_block(the_fd, 0, buffer) == 0) { rtn_value = 0; } else { b0 = (struct block0 *) buffer; @@ -105,7 +104,7 @@ get_block_n(int n) rtn_value = 0; } } else { - if (read_file_media(the_fd, ((long long) n) * g, DEV_BSIZE, (void *) buffer) == 0) { + if (read_block(the_fd, n * DEV_BSIZE, buffer) == 0) { rtn_value = 0; } else { mb = (struct dpme *) buffer; |