OSDN Git Service

libparted: ptt_read_sectors: new function
authorJim Meyering <meyering@redhat.com>
Mon, 7 Dec 2009 19:27:21 +0000 (20:27 +0100)
committerJim Meyering <meyering@redhat.com>
Tue, 8 Dec 2009 19:54:51 +0000 (20:54 +0100)
* libparted/labels/pt-tools.c (ptt_read_sectors): New function.
(ptt_read_sector): Rewrite to use it.
* libparted/labels/pt-tools.h: Declare it.

libparted/labels/pt-tools.c
libparted/labels/pt-tools.h

index 48c9384..8b2ea4a 100644 (file)
@@ -56,15 +56,17 @@ 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.  */
+/* Read N sectors, starting with 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)
+ptt_read_sectors (PedDevice const *dev, PedSector start_sector,
+                 PedSector n_sectors, void **buf)
 {
-  char *b = ped_malloc (dev->sector_size);
+  char *b = ped_malloc (n_sectors * dev->sector_size);
   PED_ASSERT (b != NULL, return 0);
-  if (!ped_device_read (dev, b, sector_num, 1)) {
+  if (!ped_device_read (dev, b, start_sector, n_sectors)) {
     free (b);
     return 0;
   }
@@ -72,6 +74,15 @@ ptt_read_sector (PedDevice const *dev, PedSector sector_num, void **buf)
   return 1;
 }
 
+/* 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)
+{
+  return ptt_read_sectors (dev, sector_num, 1, buf);
+}
+
 /* Zero N sectors of DEV, starting with START.
    Return nonzero to indicate success, zero otherwise.  */
 int
index 2987135..3f275d0 100644 (file)
@@ -19,6 +19,8 @@
 
 int ptt_write_sector (PedDisk const *disk, void const *buf, size_t buflen);
 int ptt_read_sector (PedDevice const *dev, PedSector sector_num, void **buf);
+int ptt_read_sectors (PedDevice const *dev, PedSector start_sector,
+                     PedSector n_sectors, void **buf);
 int ptt_clear_sectors (PedDevice *dev, PedSector start, PedSector count);
 int ptt_partition_max_start_len (char const *label_type,
                 const PedPartition *part);