summaryrefslogtreecommitdiffstats
path: root/fdisks/utils.c
diff options
context:
space:
mode:
authorKarel Zak2012-12-05 17:08:54 +0100
committerKarel Zak2013-03-11 11:20:41 +0100
commit3eb78aa7453f9466e6050e9ee876c672b5e7d7dd (patch)
tree2badce13e089c38d59a31c7742b519191339de94 /fdisks/utils.c
parentfdisk: remove duplicate code (already in libfdisk) (diff)
downloadkernel-qcow2-util-linux-3eb78aa7453f9466e6050e9ee876c672b5e7d7dd.tar.gz
kernel-qcow2-util-linux-3eb78aa7453f9466e6050e9ee876c672b5e7d7dd.tar.xz
kernel-qcow2-util-linux-3eb78aa7453f9466e6050e9ee876c672b5e7d7dd.zip
libfdisk: add firstsector utils
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks/utils.c')
-rw-r--r--fdisks/utils.c44
1 files changed, 3 insertions, 41 deletions
diff --git a/fdisks/utils.c b/fdisks/utils.c
index 275fee139..24f169efd 100644
--- a/fdisks/utils.c
+++ b/fdisks/utils.c
@@ -69,26 +69,6 @@ static int __probe_labels(struct fdisk_context *cxt)
return 1; /* not found */
}
-static int __init_firstsector_buffer(struct fdisk_context *cxt)
-{
- DBG(TOPOLOGY, dbgprint("initialize first sector buffer"));
-
- cxt->firstsector = calloc(1, MAX_SECTOR_SIZE);
- if (!cxt->firstsector)
- goto fail;
-
- /* read MBR */
- if (512 != read(cxt->dev_fd, cxt->firstsector, 512)) {
- if (errno == 0)
- errno = EINVAL; /* probably too small file/device */
- goto fail;
- }
-
- return 0;
-fail:
- return -errno;
-}
-
static unsigned long __get_sector_size(int fd)
{
int sect_sz;
@@ -236,24 +216,6 @@ static int __discover_topology(struct fdisk_context *cxt)
return 0;
}
-
-/**
- * fdisk_zeroize_firstsector:
- * @cxt: fdisk context
- *
- * Zeros in-memory first sector buffer
- */
-void fdisk_zeroize_firstsector(struct fdisk_context *cxt)
-{
- if (!cxt)
- return;
-
- if (cxt->firstsector) {
- DBG(CONTEXT, dbgprint("zeroize in-memory first sector buffer"));
- memset(cxt->firstsector, 0, MAX_SECTOR_SIZE);
- }
-}
-
/**
* fdisk_dev_sectsz_is_default:
* @cxt: fdisk context
@@ -475,12 +437,12 @@ struct fdisk_context *fdisk_new_context_from_filename(const char *fname, int rea
if (!cxt->dev_path)
goto fail;
- if (__init_firstsector_buffer(cxt) < 0)
- goto fail;
-
__discover_topology(cxt);
__discover_system_geometry(cxt);
+ if (fdisk_read_firstsector(cxt) < 0)
+ goto fail;
+
/* detect labels and apply labes specific stuff (e.g geomery)
* to the context */
__probe_labels(cxt);