OSDN Git Service

the beginnings of library partition-table tools
authorJim Meyering <meyering@redhat.com>
Fri, 11 Jul 2008 14:34:50 +0000 (16:34 +0200)
committerJim Meyering <meyering@redhat.com>
Fri, 24 Jul 2009 13:04:40 +0000 (15:04 +0200)
* libparted/labels/pt-tools.h: New file.
* libparted/labels/pt-tools.c: New file.
* libparted/labels/Makefile.am (liblabels_la_SOURCES): Add them.

libparted/labels/Makefile.am
libparted/labels/pt-tools.c [new file with mode: 0644]
libparted/labels/pt-tools.h [new file with mode: 0644]

index 9140291..ace6030 100644 (file)
@@ -1,5 +1,5 @@
 # This file is part of GNU Parted
-# Copyright (C) 1999, 2000, 2001, 2007, 2009 Free Software Foundation, Inc.
+# Copyright (C) 1999-2001, 2007-2009 Free Software Foundation, Inc.
 #
 # This file may be modified and/or distributed without restriction.
 
@@ -26,6 +26,8 @@ liblabels_la_SOURCES = \
   mac.c                \
   misc.h       \
   pc98.c       \
+  pt-tools.c   \
+  pt-tools.h   \
   rdb.c                \
   sun.c
 
diff --git a/libparted/labels/pt-tools.c b/libparted/labels/pt-tools.c
new file mode 100644 (file)
index 0000000..1ecdee5
--- /dev/null
@@ -0,0 +1,48 @@
+/* partition table tools
+   Copyright (C) 2008 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <parted/parted.h>
+#include <parted/debug.h>
+
+#include "pt-tools.h"
+
+/* 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,
+   zero otherwise.  */
+int
+ptt_write_sector (PedDisk const *disk, void const *buf, size_t buflen)
+{
+  PED_ASSERT (buflen <= disk->dev->sector_size, return 0);
+  /* Allocate a big enough buffer for ped_device_write.  */
+  char *s0 = ped_malloc (disk->dev->sector_size);
+  if (s0 == NULL)
+    return 0;
+  /* Copy boot_code into the first part.  */
+  memcpy (s0, buf, buflen);
+  char *p = s0 + buflen;
+  /* Fill the rest with zeros.  */
+  memset (p, 0, disk->dev->sector_size - buflen);
+  int write_ok = ped_device_write (disk->dev, s0, 0, 1);
+  free (s0);
+
+  return write_ok;
+}
diff --git a/libparted/labels/pt-tools.h b/libparted/labels/pt-tools.h
new file mode 100644 (file)
index 0000000..ec870ec
--- /dev/null
@@ -0,0 +1,20 @@
+/* libparted - a library for manipulating disk partitions
+   Copyright (C) 2008 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stddef.h>
+#include <parted/disk.h>
+
+int ptt_write_sector (PedDisk const *disk, void const *buf, size_t buflen);