/*
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
#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)
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;
}
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);
}
/**
ped_file_system_type_get (const char* name)
{
PedFileSystemType* walk;
+ PedFileSystemAlias* alias_walk;
PED_ASSERT (name != NULL, return NULL);
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;
}
/**
}
/**
+ * 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.
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);
} else {
open_detected = detected [i];
}
- }
+ }
ped_device_close (geom->dev);
return open_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.
* 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
*
* \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.
}
/**
- * 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
/**
* 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)
ped_device_close (src->dev);
ped_device_close (dest->dev);
- ped_free (buf);
+ free (buf);
return 1;
error_close_dest:
error_close_src:
ped_device_close (src->dev);
error_free_buf:
- ped_free (buf);
+ free (buf);
error:
return 0;
}
/**
* 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
return _raw_copy_and_resize (
fs, (PedGeometry*) geom,
timer);
-
+
ped_exception_throw (
PED_EXCEPTION_NO_FEATURE,
PED_EXCEPTION_CANCEL,
* (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)
/**
* 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.
*
}
/**
* 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:
* 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*
* 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)