summaryrefslogtreecommitdiff
path: root/sbin/fdisk/misc.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2015-03-30 17:11:50 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2015-03-30 17:11:50 +0000
commit541f3b912c47a0fb6b5fb9f1b1e2f5748dddee53 (patch)
tree9f96081a94ff25d4e3946f5ef536a3de2a6ddcad /sbin/fdisk/misc.c
parent686342425694c618617627d676c3bc27a01f6c98 (diff)
Even better -- readsector() and writesector() become DISK_readsector() and
DISK_writesector() and live in disk.[ch].
Diffstat (limited to 'sbin/fdisk/misc.c')
-rw-r--r--sbin/fdisk/misc.c64
1 files changed, 1 insertions, 63 deletions
diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c
index cc851825768..4b32da58391 100644
--- a/sbin/fdisk/misc.c
+++ b/sbin/fdisk/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.50 2015/03/29 21:16:39 krw Exp $ */
+/* $OpenBSD: misc.c,v 1.51 2015/03/30 17:11:49 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -22,7 +22,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <err.h>
#include <errno.h>
@@ -365,64 +364,3 @@ crc32(const u_char *buf, const u_int32_t size)
return ~crc;
}
-
-/*
- * Read the sector at 'where' from the file descriptor 'fd' into newly
- * calloc'd memory. Return a pointer to the memory if it contains the
- * requested data, or NULL if it does not.
- *
- * The caller must free() the memory it gets.
- */
-char *
-readsector(int fd, off_t where)
-{
- const int secsize = unit_types[SECTORS].conversion;
- char *secbuf;
- ssize_t len;
- off_t off;
-
- where *= secsize;
- off = lseek(fd, where, SEEK_SET);
- if (off != where)
- return (NULL);
-
- secbuf = calloc(1, secsize);
- if (secbuf == NULL)
- return (NULL);
-
- len = read(fd, secbuf, secsize);
- if (len == -1 || len != secsize) {
- free(secbuf);
- return (NULL);
- }
-
- return (secbuf);
-}
-
-/*
- * Write the sector-sized 'secbuf' to the sector 'where' on the file
- * descriptor 'fd'. Return 0 if the write works. Return -1 and set
- * errno if the write fails.
- */
-int
-writesector(int fd, char *secbuf, off_t where)
-{
- const int secsize = unit_types[SECTORS].conversion;
- ssize_t len;
- off_t off;
-
- len = -1;
-
- where *= secsize;
- off = lseek(fd, where, SEEK_SET);
- if (off == where)
- len = write(fd, secbuf, secsize);
-
- if (len == -1 || len != secsize) {
- /* short read or write */
- errno = EIO;
- return (-1);
- }
-
- return (0);
-}