[PATCH] device mapper clean-up

Jim Meyering meyering at redhat.com
Fri Jun 6 08:10:02 UTC 2008


* libparted/arch/linux.c: Remove some #ifdef ENABLE_DEVICE_MAPPER
directives.
* include/parted/device.h (struct _PedDevice) [dmtype]: Likewise.
* libparted/arch/linux.c (linux_new): Plug a leak.
---
 include/parted/device.h |    4 +---
 libparted/arch/linux.c  |   26 +++++++++++++-------------
 2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/include/parted/device.h b/include/parted/device.h
index 64b4a0a..42d2593 100644
--- a/include/parted/device.h
+++ b/include/parted/device.h
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 1998 - 2001, 2005, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1998 - 2001, 2005, 2007-2008 Free Software Foundation, I=
nc.

     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
@@ -72,9 +72,7 @@ struct _PedDevice {

         PedDeviceType   type;           /**< SCSI, IDE, etc.
                                              \deprecated \sa PedDeviceType=
 */
-#ifdef ENABLE_DEVICE_MAPPER
         char*		dmtype;         /**< device map target type */
-#endif
         long long       sector_size;            /**< logical sector size */
         long long       phys_sector_size;       /**< physical sector size =
*/
         PedSector       length;                 /**< device length (LBA) */
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 04107d8..57af6c7 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -1,5 +1,4 @@
-/*
-    libparted - a library for manipulating disk partitions
+/* libparted - a library for manipulating disk partitions
     Copyright (C) 1999 - 2005, 2007, 2008 Free Software Foundation, Inc.

     This program is free software; you can redistribute it and/or modify
@@ -31,6 +30,7 @@
 #include <stdio.h>
 #include <syscall.h>
 #include <unistd.h>
+#include <stdbool.h>
 #include <dirent.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
@@ -1150,7 +1150,6 @@ static PedDevice*
 linux_new (const char* path)
 {
         PedDevice*      dev;
-        char* type;

         PED_ASSERT (path !=3D NULL, return NULL);

@@ -1233,14 +1232,19 @@ linux_new (const char* path)
                         goto error_free_arch_specific;
                 break;

-#ifdef ENABLE_DEVICE_MAPPER
         case PED_DEVICE_DM:
-                if (asprintf(&type, _("Linux device-mapper (%s)"), dev->dm=
type) =3D=3D -1)
-                        goto error_free_arch_specific;
-                if (!init_generic (dev, type))
+                {
+                  char* type;
+                  if (dev->dmtype =3D=3D NULL
+                      || asprintf(&type, _("Linux device-mapper (%s)"),
+                                  dev->dmtype) =3D=3D -1)
                         goto error_free_arch_specific;
-                break;
-#endif
+                  bool ok =3D init_generic (dev, type);
+                  free (type);
+                  if (!ok)
+                    goto error_free_arch_specific;
+                  break;
+                }

         case PED_DEVICE_XVD:
                 if (!init_generic (dev, _("Xen Virtual Block Device")))
@@ -1276,9 +1280,7 @@ linux_destroy (PedDevice* dev)
         free (dev->arch_specific);
         free (dev->path);
         free (dev->model);
-#ifdef ENABLE_DEVICE_MAPPER
         free (dev->dmtype);
-#endif
         free (dev);
 }

@@ -2024,9 +2026,7 @@ _device_get_part_path (PedDevice* dev, int num)
         } else if (dev->type =3D=3D PED_DEVICE_DAC960
                         || dev->type =3D=3D PED_DEVICE_CPQARRAY
                         || dev->type =3D=3D PED_DEVICE_ATARAID
-#ifdef ENABLE_DEVICE_MAPPER
                         || dev->type =3D=3D PED_DEVICE_DM
-#endif
                         || isdigit (dev->path[path_len - 1]))
                 snprintf (result, result_len, "%sp%d", dev->path, num);
         else
--=20
1.5.6.rc0.30.g7c3f3




More information about the parted-devel mailing list