diff options
author | Jim Meyering <meyering@redhat.com> | 2009-03-10 22:58:20 +0100 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2009-07-24 15:04:42 +0200 |
commit | 62a958f5269198e2a54e81a76a0844a1f0525330 (patch) | |
tree | 8d1615265eba7fc9316c7a40d88d2800ca01c770 /libparted/labels/pt-tools.c | |
parent | 44e7007f60fc2a92c89a15dd129381e4ff97f03b (diff) | |
download | parted-62a958f5269198e2a54e81a76a0844a1f0525330.tar.gz |
ptt_clear_sectors: new function
* libparted/labels/pt-tools.c (ptt_clear_sectors): New function.
* libparted/labels/pt-tools.h: Declare.
Diffstat (limited to 'libparted/labels/pt-tools.c')
-rw-r--r-- | libparted/labels/pt-tools.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/libparted/labels/pt-tools.c b/libparted/labels/pt-tools.c index 50fa55d..564f611 100644 --- a/libparted/labels/pt-tools.c +++ b/libparted/labels/pt-tools.c @@ -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)); +} |