summaryrefslogtreecommitdiff
path: root/sbin/pdisk
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2016-01-23 03:46:19 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2016-01-23 03:46:19 +0000
commitc7f4c3f7eedf62e1288b7eed0b5c722ce31c28ee (patch)
treec7f21739e9f1c430658d1675b8c20c4cf34a38ae /sbin/pdisk
parentae30166f3f7b911b7df9f39319ab97b233f66846 (diff)
Flip read_block() and write_block() back to taking sector addresses
instead of off_t values. Do the DEV_BSIZE multiplication in these two functions. Easier to read code and kills two #include <sys/param.h>. Kill unused label.
Diffstat (limited to 'sbin/pdisk')
-rw-r--r--sbin/pdisk/dump.c4
-rw-r--r--sbin/pdisk/file_media.c10
-rw-r--r--sbin/pdisk/file_media.h6
-rw-r--r--sbin/pdisk/partition_map.c11
-rw-r--r--sbin/pdisk/validate.c7
5 files changed, 16 insertions, 22 deletions
diff --git a/sbin/pdisk/dump.c b/sbin/pdisk/dump.c
index b70eb08f2ca..8734f20c5cb 100644
--- a/sbin/pdisk/dump.c
+++ b/sbin/pdisk/dump.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dump.c,v 1.45 2016/01/23 01:43:13 krw Exp $ */
+/* $OpenBSD: dump.c,v 1.46 2016/01/23 03:46:18 krw Exp $ */
/*
* dump.c - dumping partition maps
@@ -27,8 +27,6 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/param.h> /* DEV_BSIZE */
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/sbin/pdisk/file_media.c b/sbin/pdisk/file_media.c
index c51c234a2a6..4fa85ab9e73 100644
--- a/sbin/pdisk/file_media.c
+++ b/sbin/pdisk/file_media.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file_media.c,v 1.38 2016/01/22 12:31:04 krw Exp $ */
+/* $OpenBSD: file_media.c,v 1.39 2016/01/23 03:46:18 krw Exp $ */
/*
* file_media.c -
@@ -36,11 +36,11 @@
#include "file_media.h"
int
-read_block(int fd, off_t offset, void *address)
+read_block(int fd, uint64_t sector, void *address)
{
ssize_t off;
- off = pread(fd, address, DEV_BSIZE, offset);
+ off = pread(fd, address, DEV_BSIZE, sector * DEV_BSIZE);
if (off == DEV_BSIZE)
return (1);
@@ -55,11 +55,11 @@ read_block(int fd, off_t offset, void *address)
}
int
-write_block(int fd, off_t offset, void *address)
+write_block(int fd, uint64_t sector, void *address)
{
ssize_t off;
- off = pwrite(fd, address, DEV_BSIZE, offset);
+ off = pwrite(fd, address, DEV_BSIZE, sector * DEV_BSIZE);
if (off == DEV_BSIZE)
return (1);
diff --git a/sbin/pdisk/file_media.h b/sbin/pdisk/file_media.h
index a85466dbb97..4bee7d37eb0 100644
--- a/sbin/pdisk/file_media.h
+++ b/sbin/pdisk/file_media.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: file_media.h,v 1.15 2016/01/22 12:31:04 krw Exp $ */
+/* $OpenBSD: file_media.h,v 1.16 2016/01/23 03:46:18 krw Exp $ */
/*
* file_media.h -
@@ -30,7 +30,7 @@
#ifndef __file_media__
#define __file_media__
-int read_block(int, off_t, void *);
-int write_block(int, off_t, void *);
+int read_block(int, uint64_t, void *);
+int write_block(int, uint64_t, void *);
#endif /* __file_media__ */
diff --git a/sbin/pdisk/partition_map.c b/sbin/pdisk/partition_map.c
index 73219dedc64..b5f3b7ef8f7 100644
--- a/sbin/pdisk/partition_map.c
+++ b/sbin/pdisk/partition_map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: partition_map.c,v 1.54 2016/01/23 01:43:13 krw Exp $ */
+/* $OpenBSD: partition_map.c,v 1.55 2016/01/23 03:46:18 krw Exp $ */
/*
* partition_map.c - partition map routines
@@ -156,7 +156,7 @@ read_partition_map(struct partition_map_header * map)
warn("can't allocate memory for disk buffers");
return -1;
}
- if (read_block(map->fd, DEV_BSIZE, dpme) == 0) {
+ if (read_block(map->fd, 1, dpme) == 0) {
warnx("Can't read block 1 from '%s'", map->name);
free(dpme);
return -1;
@@ -165,7 +165,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->fd, DEV_BSIZE, dpme) == 0) {
+ if (read_block(map->fd, 1, dpme) == 0) {
warnx("Can't read block 1 from '%s'",
map->name);
free(dpme);
@@ -203,7 +203,7 @@ read_partition_map(struct partition_map_header * map)
warn("can't allocate memory for disk buffers");
return -1;
}
- if (read_block(map->fd, ix * DEV_BSIZE, dpme) == 0) {
+ if (read_block(map->fd, ix, dpme) == 0) {
warnx("Can't read block %u from '%s'", ix, map->name);
free(dpme);
return -1;
@@ -234,8 +234,7 @@ write_partition_map(struct partition_map_header * map)
for (entry = map->disk_order; entry != NULL;
entry = entry->next_on_disk) {
convert_dpme(entry->dpme, 0);
- result = write_block(map->fd, entry->disk_address * DEV_BSIZE,
- entry->dpme);
+ result = write_block(map->fd, entry->disk_address, entry->dpme);
if (result == 0)
warn("Unable to write block %ld", entry->disk_address);
convert_dpme(entry->dpme, 1);
diff --git a/sbin/pdisk/validate.c b/sbin/pdisk/validate.c
index 2c9eae7fad4..d6b594ebd76 100644
--- a/sbin/pdisk/validate.c
+++ b/sbin/pdisk/validate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: validate.c,v 1.33 2016/01/23 01:43:13 krw Exp $ */
+/* $OpenBSD: validate.c,v 1.34 2016/01/23 03:46:18 krw Exp $ */
/*
* validate.c -
@@ -28,8 +28,6 @@
*/
-#include <sys/param.h> /* DEV_BSIZE */
-
#include <stdio.h>
#include <stdlib.h>
@@ -82,7 +80,7 @@ get_block_n(int n)
rtn_value = 0;
}
} else {
- if (read_block(the_fd, n * DEV_BSIZE, buffer) == 0) {
+ if (read_block(the_fd, n, buffer) == 0) {
rtn_value = 0;
} else {
mb = (struct dpme *) buffer;
@@ -294,7 +292,6 @@ validate_map(struct partition_map_header * map)
* args are base & len
*/
-check_map:
/* compute size of map */
if (map != NULL) {
limit = the_map->blocks_in_map;