OSDN Git Service

ptt_clear_sectors: new function
authorJim Meyering <meyering@redhat.com>
Tue, 10 Mar 2009 21:58:20 +0000 (22:58 +0100)
committerJim Meyering <meyering@redhat.com>
Fri, 24 Jul 2009 13:04:42 +0000 (15:04 +0200)
* libparted/labels/pt-tools.c (ptt_clear_sectors): New function.
* libparted/labels/pt-tools.h: Declare.

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

index 50fa55d..564f611 100644 (file)
@@ -1,5 +1,5 @@
 /* partition table tools
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2009 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -24,6 +24,8 @@
 
 #include "pt-tools.h"
 
+static char zero[16 * 1024];
+
 /* Write a single sector to DISK, filling the first BUFLEN
    bytes of that sector with data from BUF, and NUL-filling
    any remaining bytes.  Return nonzero to indicate success,
@@ -62,3 +64,23 @@ ptt_read_sector (PedDevice const *dev, PedSector sector_num, void **buf)
   *buf = b;
   return 1;
 }
+
+/* Zero N sectors of DEV, starting with START.
+   Return nonzero to indicate success, zero otherwise.  */
+int
+ptt_clear_sectors (PedDevice *dev, PedSector start, PedSector n)
+{
+  PED_ASSERT (dev->sector_size <= sizeof zero, return 0);
+  PedSector n_z_sectors = sizeof zero / dev->sector_size;
+  PedSector n_full = n / n_z_sectors;
+  PedSector i;
+  for (i = 0; i < n_full; i++)
+    {
+      if (!ped_device_write (dev, zero, start + n_z_sectors * i, n_z_sectors))
+        return 0;
+    }
+
+  PedSector rem = n - n_z_sectors * i;
+  return (rem == 0
+          ? 1 : ped_device_write (dev, zero, start + n_z_sectors * i, rem));
+}
index 0af8e73..d36929e 100644 (file)
@@ -1,5 +1,5 @@
 /* libparted - a library for manipulating disk partitions
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2009 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -18,4 +18,5 @@
 #include <parted/disk.h>
 
 int ptt_write_sector (PedDisk const *disk, void const *buf, size_t buflen);
-int ptt_read_sector (const PedDevice *dev, PedSector sector_num, void **buf);
+int ptt_read_sector (PedDevice const *dev, PedSector sector_num, void **buf);
+int ptt_clear_sectors (PedDevice *dev, PedSector start, PedSector count);