summaryrefslogtreecommitdiff
path: root/sbin/pdisk
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2016-01-16 22:28:15 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2016-01-16 22:28:15 +0000
commit82186622f65282032afd6cf0043d7f0fefdb4aa4 (patch)
treed63bd24b97078bf3a5f18126a96c83d02326d92b /sbin/pdisk
parent9830745e804317dfc2dd046483d4909e1230789e (diff)
Move last field (size_in_bytes) in struct media to struct file_media
and replace MEDIA with FILE_MEDIA everywhere. media.h becomes unused.
Diffstat (limited to 'sbin/pdisk')
-rw-r--r--sbin/pdisk/dump.c4
-rw-r--r--sbin/pdisk/file_media.c39
-rw-r--r--sbin/pdisk/file_media.h21
-rw-r--r--sbin/pdisk/partition_map.c8
-rw-r--r--sbin/pdisk/partition_map.h6
-rw-r--r--sbin/pdisk/pdisk.c4
-rw-r--r--sbin/pdisk/validate.c4
7 files changed, 38 insertions, 48 deletions
diff --git a/sbin/pdisk/dump.c b/sbin/pdisk/dump.c
index dede246cffc..17ca149c9de 100644
--- a/sbin/pdisk/dump.c
+++ b/sbin/pdisk/dump.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dump.c,v 1.19 2016/01/16 20:00:50 krw Exp $ */
+/* $OpenBSD: dump.c,v 1.20 2016/01/16 22:28:14 krw Exp $ */
//
// dump.c - dumping partition maps
@@ -650,7 +650,7 @@ void
display_patches(partition_map *entry)
{
long long offset;
- MEDIA m;
+ FILE_MEDIA m;
static unsigned char *patch_block;
PatchListPtr p;
PatchDescriptorPtr q;
diff --git a/sbin/pdisk/file_media.c b/sbin/pdisk/file_media.c
index 9f44487bd1c..ad8717090b6 100644
--- a/sbin/pdisk/file_media.c
+++ b/sbin/pdisk/file_media.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file_media.c,v 1.25 2016/01/16 22:04:20 krw Exp $ */
+/* $OpenBSD: file_media.c,v 1.26 2016/01/16 22:28:14 krw Exp $ */
/*
* file_media.c -
@@ -55,13 +55,6 @@
/*
* Types
*/
-typedef struct file_media *FILE_MEDIA;
-
-struct file_media {
- struct media m;
- int fd;
- int regular_file;
-};
/*
@@ -111,7 +104,7 @@ compute_block_size(int fd, char *name)
}
-MEDIA
+FILE_MEDIA
open_file_as_media(char *file, int oflag)
{
FILE_MEDIA a;
@@ -131,7 +124,7 @@ open_file_as_media(char *file, int oflag)
compute_block_size(fd, file);
off = lseek(fd, 0, SEEK_END); /* seek to end of media */
//printf("file size = %Ld\n", off);
- a->m.size_in_bytes = (long long) off;
+ a->size_in_bytes = (long long) off;
a->fd = fd;
a->regular_file = 0;
if (fstat(fd, &info) < 0) {
@@ -143,19 +136,18 @@ open_file_as_media(char *file, int oflag)
close(fd);
}
}
- return (MEDIA) a;
+ return (FILE_MEDIA) a;
}
long
-read_file_media(MEDIA m, long long offset, unsigned long count, void *address)
+read_file_media(FILE_MEDIA a, long long offset, unsigned long count,
+ void *address)
{
- FILE_MEDIA a;
long rtn_value;
off_t off;
int t;
- a = (FILE_MEDIA) m;
rtn_value = 0;
if (a == 0) {
/* no media */
@@ -166,7 +158,7 @@ read_file_media(MEDIA m, long long offset, unsigned long count, void *address)
} else if (offset < 0 || offset % DEV_BSIZE != 0) {
/* can't handle offset */
fprintf(stderr,"bad offset\n");
- } else if (offset + count > a->m.size_in_bytes && a->m.size_in_bytes != (long long) 0) {
+ } else if (offset + count > a->size_in_bytes && a->size_in_bytes != (long long) 0) {
/* check for offset (and offset+count) too large */
fprintf(stderr,"offset+count too large\n");
} else if (count > LLONG_MAX - offset) {
@@ -190,14 +182,12 @@ read_file_media(MEDIA m, long long offset, unsigned long count, void *address)
long
-write_file_media(MEDIA m, long long offset, unsigned long count, void *address)
+write_file_media(FILE_MEDIA a, long long offset, unsigned long count, void *address)
{
- FILE_MEDIA a;
long rtn_value;
off_t off;
int t;
- a = (FILE_MEDIA) m;
rtn_value = 0;
if (a == 0) {
/* no media */
@@ -212,8 +202,8 @@ write_file_media(MEDIA m, long long offset, unsigned long count, void *address)
off = offset;
if ((off = lseek(a->fd, off, SEEK_SET)) >= 0) {
if ((t = write(a->fd, address, count)) == count) {
- if (off + count > a->m.size_in_bytes) {
- a->m.size_in_bytes = off + count;
+ if (off + count > a->size_in_bytes) {
+ a->size_in_bytes = off + count;
}
rtn_value = 1;
}
@@ -224,11 +214,8 @@ write_file_media(MEDIA m, long long offset, unsigned long count, void *address)
long
-close_file_media(MEDIA m)
+close_file_media(FILE_MEDIA a)
{
- FILE_MEDIA a;
-
- a = (FILE_MEDIA) m;
if (a == 0) {
return 0;
}
@@ -239,12 +226,10 @@ close_file_media(MEDIA m)
long
-os_reload_file_media(MEDIA m)
+os_reload_file_media(FILE_MEDIA a)
{
- FILE_MEDIA a;
long rtn_value;
- a = (FILE_MEDIA) m;
rtn_value = 0;
if (a == 0) {
/* no media */
diff --git a/sbin/pdisk/file_media.h b/sbin/pdisk/file_media.h
index c301b40f079..4105a9ff855 100644
--- a/sbin/pdisk/file_media.h
+++ b/sbin/pdisk/file_media.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: file_media.h,v 1.6 2016/01/16 20:00:50 krw Exp $ */
+/* $OpenBSD: file_media.h,v 1.7 2016/01/16 22:28:14 krw Exp $ */
/*
* file_media.h -
@@ -30,8 +30,6 @@
#ifndef __file_media__
#define __file_media__
-#include "media.h"
-
/*
* Defines
@@ -41,6 +39,13 @@
/*
* Types
*/
+typedef struct file_media *FILE_MEDIA;
+
+struct file_media {
+ long long size_in_bytes; /* offset granularity */
+ int fd;
+ int regular_file;
+};
/*
@@ -56,10 +61,10 @@
/*
* Forward declarations
*/
-MEDIA open_file_as_media(char *file, int oflag);
-long read_file_media(MEDIA m, long long offset, unsigned long count, void *address);
-long write_file_media(MEDIA m, long long offset, unsigned long count, void *address);
-long close_file_media(MEDIA m);
-long os_reload_file_media(MEDIA m);
+FILE_MEDIA open_file_as_media(char *file, int oflag);
+long read_file_media(FILE_MEDIA m, long long offset, unsigned long count, void *address);
+long write_file_media(FILE_MEDIA m, long long offset, unsigned long count, void *address);
+long close_file_media(FILE_MEDIA m);
+long os_reload_file_media(FILE_MEDIA m);
#endif /* __file_media__ */
diff --git a/sbin/pdisk/partition_map.c b/sbin/pdisk/partition_map.c
index fa7800c306f..ec0b6200e86 100644
--- a/sbin/pdisk/partition_map.c
+++ b/sbin/pdisk/partition_map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: partition_map.c,v 1.23 2016/01/16 21:41:41 krw Exp $ */
+/* $OpenBSD: partition_map.c,v 1.24 2016/01/16 22:28:14 krw Exp $ */
//
// partition_map.c - partition map routines
@@ -115,7 +115,7 @@ int write_block(partition_map_header *map, unsigned long num, char *buf);
partition_map_header *
open_partition_map(char *name, int *valid_file)
{
- MEDIA m;
+ FILE_MEDIA m;
partition_map_header * map;
int writable;
@@ -298,7 +298,7 @@ read_partition_map(partition_map_header *map)
void
write_partition_map(partition_map_header *map)
{
- MEDIA m;
+ FILE_MEDIA m;
char *block;
partition_map * entry;
int i = 0;
@@ -394,7 +394,7 @@ init_partition_map(char *name, partition_map_header* oldmap)
partition_map_header *
create_partition_map(char *name, partition_map_header *oldmap)
{
- MEDIA m;
+ FILE_MEDIA m;
partition_map_header * map;
DPME *data;
unsigned long number;
diff --git a/sbin/pdisk/partition_map.h b/sbin/pdisk/partition_map.h
index 7f2b385f8a5..a734d22119f 100644
--- a/sbin/pdisk/partition_map.h
+++ b/sbin/pdisk/partition_map.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: partition_map.h,v 1.7 2016/01/15 23:05:00 krw Exp $ */
+/* $OpenBSD: partition_map.h,v 1.8 2016/01/16 22:28:14 krw Exp $ */
//
// partition_map.h - partition map routines
@@ -31,7 +31,7 @@
#define __partition_map__
#include "dpme.h"
-#include "media.h"
+#include "file_media.h"
//
@@ -43,7 +43,7 @@
// Types
//
struct partition_map_header {
- MEDIA m;
+ FILE_MEDIA m;
char *name;
struct partition_map * disk_order;
struct partition_map * base_order;
diff --git a/sbin/pdisk/pdisk.c b/sbin/pdisk/pdisk.c
index e3ef66d8d83..41c927dcaab 100644
--- a/sbin/pdisk/pdisk.c
+++ b/sbin/pdisk/pdisk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pdisk.c,v 1.35 2016/01/16 21:41:41 krw Exp $ */
+/* $OpenBSD: pdisk.c,v 1.36 2016/01/16 22:28:14 krw Exp $ */
//
// pdisk - an editor for Apple format partition tables
@@ -701,7 +701,7 @@ do_change_map_size(partition_map_header *map)
void
do_display_block(partition_map_header *map, char *alt_name)
{
- MEDIA m;
+ FILE_MEDIA m;
long number;
char *name;
static unsigned char *display_block;
diff --git a/sbin/pdisk/validate.c b/sbin/pdisk/validate.c
index a02b8036a81..1b37428a5b2 100644
--- a/sbin/pdisk/validate.c
+++ b/sbin/pdisk/validate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: validate.c,v 1.14 2016/01/16 21:41:41 krw Exp $ */
+/* $OpenBSD: validate.c,v 1.15 2016/01/16 22:28:14 krw Exp $ */
//
// validate.c -
@@ -84,7 +84,7 @@ static char *buffer;
static Block0 *b0;
static DPME *mb;
static partition_map_header *the_map;
-static MEDIA the_media;
+static FILE_MEDIA the_media;
static int g;