summaryrefslogtreecommitdiff
path: root/libparted/labels/pt-tools.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2008-07-15 14:47:22 +0200
committerJim Meyering <meyering@redhat.com>2009-07-24 15:04:41 +0200
commit8002e26eff48ce9189c7c61151dee89125d93de5 (patch)
tree157847f547beb3ddbccd9f2eda8f6231d45e2b53 /libparted/labels/pt-tools.c
parentf4af35cec5be4d0e4fe0d6888d35c4ea179d44f9 (diff)
downloadparted-8002e26eff48ce9189c7c61151dee89125d93de5.tar.gz
factor out the read_sector function
* libparted/labels/pt-tools.c (ptt_read_sector): New function. Factored out of... * libparted/labels/aix.c (aix_probe, aix_clobber, read_sector): * libparted/labels/bsd.c (bsd_probe, bsd_clobber, bsd_read) (_probe_and_add_boot_code, read_sector): * libparted/labels/dos.c (_, msdos_probe, msdos_clobber) (read_table, msdos_write, msdos_disk_type, read_sector): * libparted/labels/gpt.c (gpt_probe, gpt_disk_type, read_sector): * libparted/labels/loop.c (loop_probe, loop_read, loop_disk_type) (read_sector): * libparted/labels/mac.c (_, mac_probe, mac_read) (write_block_zero, mac_disk_type, read_sector): * libparted/labels/pt-tools.h: Declare.
Diffstat (limited to 'libparted/labels/pt-tools.c')
-rw-r--r--libparted/labels/pt-tools.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/libparted/labels/pt-tools.c b/libparted/labels/pt-tools.c
index 1ecdee5..50fa55d 100644
--- a/libparted/labels/pt-tools.c
+++ b/libparted/labels/pt-tools.c
@@ -46,3 +46,19 @@ ptt_write_sector (PedDisk const *disk, void const *buf, size_t buflen)
return write_ok;
}
+
+/* Read sector, SECTOR_NUM (which has length DEV->sector_size) into malloc'd
+ storage. If the read fails, free the memory and return zero without
+ modifying *BUF. Otherwise, set *BUF to the new buffer and return 1. */
+int
+ptt_read_sector (PedDevice const *dev, PedSector sector_num, void **buf)
+{
+ char *b = ped_malloc (dev->sector_size);
+ PED_ASSERT (b != NULL, return 0);
+ if (!ped_device_read (dev, b, sector_num, 1)) {
+ free (b);
+ return 0;
+ }
+ *buf = b;
+ return 1;
+}