OSDN Git Service

dos: add a partition flag for diagnostics / recovery partitions
[android-x86/external-parted.git] / libparted / filesys.c
index 38d1f75..7c214c0 100644 (file)
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1999-2001, 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
@@ -41,6 +41,7 @@
 #define BUFFER_SIZE    4096            /* in sectors */
 
 static PedFileSystemType*      fs_types = NULL;
+static PedFileSystemAlias*     fs_aliases = NULL;
 
 void
 ped_file_system_type_register (PedFileSystemType* fs_type)
@@ -48,7 +49,7 @@ ped_file_system_type_register (PedFileSystemType* fs_type)
        PED_ASSERT (fs_type != NULL, return);
        PED_ASSERT (fs_type->ops != NULL, return);
        PED_ASSERT (fs_type->name != NULL, return);
-       
+
         fs_type->next = fs_types;
         fs_types = fs_type;
 }
@@ -69,7 +70,51 @@ ped_file_system_type_unregister (PedFileSystemType* fs_type)
        if (last)
                ((struct _PedFileSystemType*) last)->next = fs_type->next;
        else
-               fs_types = fs_type->next;       
+               fs_types = fs_type->next;
+}
+
+void
+ped_file_system_alias_register (PedFileSystemType* fs_type, const char* alias,
+                               int deprecated)
+{
+       PedFileSystemAlias*     fs_alias;
+
+       PED_ASSERT (fs_type != NULL, return);
+       PED_ASSERT (alias != NULL, return);
+
+       fs_alias = ped_malloc (sizeof *fs_alias);
+       if (!fs_alias)
+               return;
+
+       fs_alias->next = fs_aliases;
+       fs_alias->fs_type = fs_type;
+       fs_alias->alias = alias;
+       fs_alias->deprecated = deprecated;
+       fs_aliases = fs_alias;
+}
+
+void
+ped_file_system_alias_unregister (PedFileSystemType* fs_type,
+                                 const char* alias)
+{
+       PedFileSystemAlias*     walk;
+       PedFileSystemAlias*     last = NULL;
+
+       PED_ASSERT (fs_aliases != NULL, return);
+       PED_ASSERT (fs_type != NULL, return);
+       PED_ASSERT (alias != NULL, return);
+
+       for (walk = fs_aliases; walk; last = walk, walk = walk->next) {
+               if (walk->fs_type == fs_type && !strcmp (walk->alias, alias))
+                       break;
+       }
+
+       PED_ASSERT (walk != NULL, return);
+       if (last)
+               last->next = walk->next;
+       else
+               fs_aliases = walk->next;
+       free (walk);
 }
 
 /**
@@ -81,6 +126,7 @@ PedFileSystemType*
 ped_file_system_type_get (const char* name)
 {
        PedFileSystemType*      walk;
+       PedFileSystemAlias*     alias_walk;
 
        PED_ASSERT (name != NULL, return NULL);
 
@@ -88,7 +134,22 @@ ped_file_system_type_get (const char* name)
                if (!strcasecmp (walk->name, name))
                        break;
        }
-       return walk;
+       if (walk != NULL)
+               return walk;
+
+       for (alias_walk = fs_aliases; alias_walk != NULL;
+            alias_walk = alias_walk->next) {
+               if (!strcasecmp (alias_walk->alias, name))
+                       break;
+       }
+       if (alias_walk != NULL) {
+               if (alias_walk->deprecated)
+                       PED_DEBUG (0, "File system alias %s is deprecated",
+                                  name);
+               return alias_walk->fs_type;
+       }
+
+       return NULL;
 }
 
 /**
@@ -106,6 +167,20 @@ ped_file_system_type_get_next (const PedFileSystemType* fs_type)
 }
 
 /**
+ * Get the next PedFileSystemAlias after @p fs_alias.
+ *
+ * @return @c NULL if @p fs_alias is the last item in the list.
+ */
+PedFileSystemAlias*
+ped_file_system_alias_get_next (const PedFileSystemAlias* fs_alias)
+{
+       if (fs_alias)
+               return fs_alias->next;
+       else
+               return fs_aliases;
+}
+
+/**
  * Attempt to find a file system and return the region it occupies.
  *
  * @param fs_type The file system type to probe for.
@@ -123,6 +198,11 @@ ped_file_system_probe_specific (
        PED_ASSERT (fs_type->ops->probe != NULL, return NULL);
        PED_ASSERT (geom != NULL, return NULL);
 
+        /* Fail all fs-specific probe-related tests when sector size
+           is not the default.  */
+       if (geom->dev->sector_size != PED_SECTOR_SIZE_DEFAULT)
+               return 0;
+
        if (!ped_device_open (geom->dev))
                return 0;
        result = fs_type->ops->probe (geom);
@@ -184,7 +264,7 @@ _probe_with_open (PedGeometry* geom, int detected_count,
                } else {
                        open_detected = detected [i];
                }
-       }       
+       }
 
        ped_device_close (geom->dev);
        return open_detected;
@@ -231,7 +311,7 @@ _best_match (const PedGeometry* geom, PedFileSystemType* detected [],
 
 
 /**
- * Attempt to detect a file system in region \p geom. 
+ * Attempt to detect a file system in region \p geom.
  * This function tries to be clever at dealing with ambiguous
  * situations, such as when one file system was not completely erased before a
  * new file system was created on top of it.
@@ -284,7 +364,7 @@ ped_file_system_probe (PedGeometry* geom)
  * After this operation ped_file_system_probe() won't detect any file system.
  *
  * \note ped_file_system_create() calls this before creating a new file system.
- * 
+ *
  * \return \c 1 on success, \c 0 on failure
  */
 int
@@ -359,7 +439,7 @@ ped_file_system_clobber_exclude (PedGeometry* geom,
  *
  * \throws PED_EXCEPTION_ERROR if file system could not be detected
  * \throws PED_EXCEPTION_ERROR if the file system is bigger than its volume
- * \throws PED_EXCEPTION_NO_FEATURE if opening of a file system stored on 
+ * \throws PED_EXCEPTION_NO_FEATURE if opening of a file system stored on
  *     \p geom is not implemented
  *
  * \return a PedFileSystem on success, \c NULL on failure.
@@ -419,11 +499,11 @@ error:
 }
 
 /**
- * This function initializes a new file system of type \p type on 
- * a region described by \p geom, writing out appropriate metadata and 
+ * This function initializes a new file system of type \p type on
+ * a region described by \p geom, writing out appropriate metadata and
  * signatures.  If \p timer is non-NULL, it is used as the progress meter.
  *
- * \throws PED_EXCEPTION_NO_FEATURE if creating file system type \p type 
+ * \throws PED_EXCEPTION_NO_FEATURE if creating file system type \p type
  *     is not implemented yet
  *
  * \return a PedFileSystem on success, \c NULL on failure
@@ -487,7 +567,7 @@ error_close_dev:
 /**
  * Check \p fs file system for errors.
  *
- * \throws PED_EXCEPTION_NO_FEATURE if checking file system \p fs is 
+ * \throws PED_EXCEPTION_NO_FEATURE if checking file system \p fs is
  *     not implemented yet
  *
  * \return \c 0 on failure (i.e. unfixed errors)
@@ -545,7 +625,7 @@ _raw_copy (const PedGeometry* src, PedGeometry* dest, PedTimer* timer)
 
        ped_device_close (src->dev);
        ped_device_close (dest->dev);
-       ped_free (buf);
+       free (buf);
        return 1;
 
 error_close_dest:
@@ -553,7 +633,7 @@ error_close_dest:
 error_close_src:
        ped_device_close (src->dev);
 error_free_buf:
-       ped_free (buf);
+       free (buf);
 error:
        return 0;
 }
@@ -594,11 +674,11 @@ error:
 
 /**
  * Create a new file system (of the same type) on \p geom, and
- * copy the contents of \p fs into the new filesystem.  
+ * copy the contents of \p fs into the new filesystem.
  * If \p timer is non-NULL, it is used as the progress meter.
  *
  * \throws PED_EXCEPTION_ERROR when trying to copy onto an overlapping partition
- * \throws PED_EXCEPTION_NO_FEATURE if copying of file system \p fs 
+ * \throws PED_EXCEPTION_NO_FEATURE if copying of file system \p fs
  *     is not implemented yet
  *
  * \return a new PedFileSystem on success, \c NULL on failure
@@ -635,7 +715,7 @@ ped_file_system_copy (PedFileSystem* fs, PedGeometry* geom, PedTimer* timer)
                                return _raw_copy_and_resize (
                                                fs, (PedGeometry*) geom,
                                                timer);
-                               
+
                        ped_exception_throw (
                                PED_EXCEPTION_NO_FEATURE,
                                PED_EXCEPTION_CANCEL,
@@ -677,10 +757,10 @@ error:
  * (This isn't asserted, so it's not a bug not to... just it's likely
  * to fail ;)  If \p timer is non-NULL, it is used as the progress meter.
  *
- * \throws PED_EXCEPTION_NO_FEATURE if resizing of file system \p fs 
+ * \throws PED_EXCEPTION_NO_FEATURE if resizing of file system \p fs
  *     is not implemented yet
- * 
- * \return \c 0 on failure 
+ *
+ * \return \c 0 on failure
  */
 int
 ped_file_system_resize (PedFileSystem* fs, PedGeometry* geom, PedTimer* timer)
@@ -708,7 +788,7 @@ ped_file_system_resize (PedFileSystem* fs, PedGeometry* geom, PedTimer* timer)
 
 /**
  * This function returns a constraint on the region that all file systems
- * of a particular type \p fs_type created on device \p dev with 
+ * of a particular type \p fs_type created on device \p dev with
  * ped_file_system_create() must satisfy. For example, FAT16 file systems must
  * be at least 32 megabytes.
  *
@@ -727,7 +807,7 @@ ped_file_system_get_create_constraint (const PedFileSystemType* fs_type,
 }
 /**
  * Return a constraint, that represents all of the possible ways the
- * file system \p fs can be resized with ped_file_system_resize().  
+ * file system \p fs can be resized with ped_file_system_resize().
  * This takes into account the amount of used space on
  * the filesystem \p fs and the capabilities of the resize algorithm.
  * Hints:
@@ -735,7 +815,7 @@ ped_file_system_get_create_constraint (const PedFileSystemType* fs_type,
  *    constraint->start_geom->length == 1, then the start can not be moved
  * -# constraint->min_size is the minimum size you can resize the partition
  *    to.  You might want to tell the user this ;-).
- *    
+ *
  * \return a PedConstraint on success, \c NULL on failure
  */
 PedConstraint*
@@ -753,7 +833,7 @@ ped_file_system_get_resize_constraint (const PedFileSystem* fs)
  * to somewhere on \p dev.
  *
  * \return a PedConstraint on success, \c NULL on failure
- */ 
+ */
 PedConstraint*
 ped_file_system_get_copy_constraint (const PedFileSystem* fs,
                                     const PedDevice* dev)