OSDN Git Service

maint: don't hard-code bug-reporting address
[android-x86/external-parted.git] / libparted / device.c
index dda8d74..6cbfaaf 100644 (file)
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 1999 - 2001, 2005, 2007-2009 Free Software Foundation, Inc.
+    Copyright (C) 1999 - 2001, 2005, 2007-2010 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
@@ -73,6 +73,16 @@ _device_unregister (PedDevice* dev)
                if (walk == dev) break;
        }
 
+       /* This function may be called twice for the same device if a
+          libparted user explictly removes the device from the cache using
+          ped_device_cache_remove(), we get called and it then becomes the
+          user's responsibility to free the PedDevice by calling
+          ped_device_destroy().
+          ped_device_destroy() will then call us a second time, so if the
+          device is not found in the list do nothing. */
+       if (walk == NULL)
+               return;
+
        if (last)
                last->next = dev->next;
        else
@@ -139,10 +149,12 @@ PedDevice*
 ped_device_get (const char* path)
 {
        PedDevice*      walk;
-       char*           normal_path;
+       char*           normal_path = NULL;
 
        PED_ASSERT (path != NULL, return NULL);
-       normal_path = canonicalize_file_name (path);
+       /* Don't canonicalize /dev/mapper paths, see tests/symlink.c */
+       if (strncmp (path, "/dev/mapper/", 12))
+               normal_path = canonicalize_file_name (path);
        if (!normal_path)
                /* Well, maybe it is just that the file does not exist.
                 * Try it anyway.  */
@@ -401,7 +413,7 @@ ped_device_sync_fast (PedDevice* dev)
  *         constraint.
  */
 PedConstraint*
-ped_device_get_constraint (PedDevice* dev)
+ped_device_get_constraint (const PedDevice* dev)
 {
         PedGeometry *s, *e;
         PedConstraint* c = ped_constraint_new (
@@ -501,10 +513,16 @@ ped_device_get_optimal_aligned_constraint(const PedDevice *dev)
 PedAlignment*
 ped_device_get_minimum_alignment(const PedDevice *dev)
 {
+        PedAlignment *align = NULL;
+
         if (ped_architecture->dev_ops->get_minimum_alignment)
-                return ped_architecture->dev_ops->get_minimum_alignment(dev);
+                align = ped_architecture->dev_ops->get_minimum_alignment(dev);
+
+        if (align == NULL)
+                align = ped_alignment_new(0,
+                                dev->phys_sector_size / dev->sector_size);
 
-        return NULL; /* ped_alignment_none */
+        return align;
 }
 
 /**
@@ -521,10 +539,27 @@ ped_device_get_minimum_alignment(const PedDevice *dev)
 PedAlignment*
 ped_device_get_optimum_alignment(const PedDevice *dev)
 {
+        PedAlignment *align = NULL;
+
         if (ped_architecture->dev_ops->get_optimum_alignment)
-                return ped_architecture->dev_ops->get_optimum_alignment(dev);
+                align = ped_architecture->dev_ops->get_optimum_alignment(dev);
+
+        /* If the arch specific code could not give as an alignment
+           return a default value based on the type of device. */
+        if (align == NULL) {
+                switch (dev->type) {
+                case PED_DEVICE_DASD:
+                        align = ped_device_get_minimum_alignment(dev);
+                        break;
+                default:
+                        /* Align to a grain of 1MiB (like vista / win7) */
+                        align = ped_alignment_new(0,
+                                                  (PED_DEFAULT_ALIGNMENT
+                                                  / dev->sector_size));
+                }
+        }
 
-        return NULL; /* ped_alignment_none */
+        return align;
 }
 
 /** @} */