summaryrefslogtreecommitdiff
path: root/libparted/filesys.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@ubuntu.com>2009-07-10 12:42:14 +0100
committerJim Meyering <meyering@redhat.com>2009-07-10 23:29:10 +0200
commit2882b5300103238f8d71bdf6d0c1f54c4c59646d (patch)
tree568a51dae3bec0704f69d15a618a4323d429b319 /libparted/filesys.c
parent32dcfa4738ce7a430308615d9e4236e71ba94b66 (diff)
downloadparted-2882b5300103238f8d71bdf6d0c1f54c4c59646d.tar.gz
Rationalise linux-swap fs names, and add a "linux-swap" alias
* libparted/filesys.c (ped_file_system_alias_register, ped_file_system_alias_unregister, ped_file_system_alias_get_next): New functions. (ped_file_system_type_get): Walk aliases as well. * include/parted/filesys.h (struct _PedFileSystemAlias): New structure. (ped_file_system_alias_register, ped_file_system_alias_unregister, ped_file_system_alias_get_next): Add prototypes. * parted/parted.c (_init_messages): Walk file system aliases as well as types. * parted/ui.c (init_fs_type_str): Likewise. * libparted/fs/linux_swap/linux_swap.c (_swap_v1_type, _swap_v1_open, _swap_v1_probe, _swap_v1_clobber, _swap_v1_ops): Rename to _swap_v0_type etc. to match version number used in mkswap. Update all users. (_swap_v2_type, _swap_v2_open, _swap_v2_probe, _swap_v2_clobber, _swap_v2_ops): Rename to _swap_v1_type etc. to match version number used in mkswap. Update all users. (_swap_v0_type): Rename type from "linux-swap(old)" to "linux-swap(v0)". (_swap_v1_type): Rename type from "linux-swap(new)" to "linux-swap(v1)". (ped_file_system_linux_swap_init, ped_file_system_linux_swap_done): Register/unregister a "linux-swap" alias for "linux-swap(v1)", and deprecated aliases "linux-swap(old)" and "linux-swap(new)". * libparted/labels/misc.h (is_linux_swap): Update comment. * tests/t2100-mkswap.sh: Refer to "linux-swap(v1)" rather than "linux-swap(new)". Test creation via the new alias.
Diffstat (limited to 'libparted/filesys.c')
-rw-r--r--libparted/filesys.c78
1 files changed, 76 insertions, 2 deletions
diff --git a/libparted/filesys.c b/libparted/filesys.c
index ba48a79..d57c3cd 100644
--- a/libparted/filesys.c
+++ b/libparted/filesys.c
@@ -1,6 +1,6 @@
/*
libparted - a library for manipulating disk partitions
- Copyright (C) 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2007, 2009 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)
@@ -72,6 +73,49 @@ ped_file_system_type_unregister (PedFileSystemType* fs_type)
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;
+}
+
/**
* Get a PedFileSystemType by its @p name.
*
@@ -81,6 +125,7 @@ PedFileSystemType*
ped_file_system_type_get (const char* name)
{
PedFileSystemType* walk;
+ PedFileSystemAlias* alias_walk;
PED_ASSERT (name != NULL, return NULL);
@@ -88,7 +133,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 +166,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.