From: David Zeuthen Date: Fri, 11 Mar 2011 23:34:21 +0000 (-0500) Subject: Add functions to get human-readable strings for partitions and filesystems X-Git-Tag: upstream/2.1.2~480^2~123 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7d4e08fb8f28cdd3ad6b9c7be9d71e7594a17fa9;p=platform%2Fupstream%2Fudisks2.git Add functions to get human-readable strings for partitions and filesystems Signed-off-by: David Zeuthen --- diff --git a/doc/udisks2-sections.txt b/doc/udisks2-sections.txt index 8600485..a30c93a 100644 --- a/doc/udisks2-sections.txt +++ b/doc/udisks2-sections.txt @@ -2,6 +2,9 @@ udisksutil udisks_util_get_size_for_display udisks_util_get_lun_info +udisks_util_get_part_scheme_for_display +udisks_util_get_part_type_for_display +udisks_util_get_id_for_display
diff --git a/udisks/udisksutil.c b/udisks/udisksutil.c index ca6bc7e..f4e836c 100644 --- a/udisks/udisksutil.c +++ b/udisks/udisksutil.c @@ -24,6 +24,7 @@ //#include #define _(x) x +#define N_(x) x #include "udisksutil.h" @@ -129,7 +130,7 @@ get_pow10_size (guint64 size) * udisks_util_get_size_for_display: * @size: Size in bytes * @use_pow2: Whether power-of-two units should be used instead of power-of-ten units. - * @long_string: Whether to produce a long string + * @long_string: Whether to produce a long string. * * Gets a human-readable string that represents @size. * @@ -686,3 +687,337 @@ udisks_util_get_lun_info (UDisksLun *lun, if (out_media_icon != NULL) *out_media_icon = g_themed_icon_new_with_default_fallbacks (lun_get_media_icon_name (lun)); } + +/* ---------------------------------------------------------------------------------------------------- */ + +const static struct +{ + const gchar *scheme; + const gchar *name; +} part_scheme[] = +{ + {"mbr", N_("Master Boot Record")}, + {"gpt", N_("GUID Partition Table")}, + {"apm", N_("Apple Partition Map")}, + {NULL, NULL} +}; + +/** + * udisks_util_get_part_scheme_for_display: + * @scheme: A partitioning scheme id. + * + * Gets a human readable localized string for @scheme. + * + * Returns: A string that should be freed with g_free(). + */ +gchar * +udisks_util_get_part_scheme_for_display (const gchar *scheme) +{ + guint n; + gchar *ret; + + for (n = 0; part_scheme[n].scheme != NULL; n++) + { + if (g_strcmp0 (part_scheme[n].scheme, scheme) == 0) + { + ret = g_strdup (_(part_scheme[n].name)); + goto out; + } + } + + /* Translators: Shown for unknown partitioning scheme. + * First %s is the partition type scheme. + */ + ret = g_strdup_printf (_("Unknown Scheme (%s)"), scheme); + + out: + return ret; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +const static struct +{ + const gchar *scheme; + const gchar *type; + const gchar *name; +} part_type[] = +{ + /* see http://en.wikipedia.org/wiki/GUID_Partition_Table */ + + /* Linux */ + {"gpt", "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", N_("Linux Basic Data Partition")}, /* Same as MS BDP */ + {"gpt", "A19D880F-05FC-4D3B-A006-743F0F84911E", N_("Linux RAID Partition")}, + {"gpt", "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F", N_("Linux Swap Partition")}, + {"gpt", "E6D6D379-F507-44C2-A23C-238F2A3DF928", N_("Linux LVM Partition")}, + {"gpt", "8DA63339-0007-60C0-C436-083AC8230908", N_("Linux Reserved Partition")}, + /* Not associated with any OS */ + {"gpt", "024DEE41-33E7-11D3-9D69-0008C781F39F", N_("MBR Partition Scheme")}, + {"gpt", "C12A7328-F81F-11D2-BA4B-00A0C93EC93B", N_("EFI System Partition")}, + {"gpt", "21686148-6449-6E6F-744E-656564454649", N_("BIOS Boot Partition")}, + /* Microsoft */ + {"gpt", "E3C9E316-0B5C-4DB8-817D-F92DF00215AE", N_("Microsoft Reserved Partition")}, + {"gpt", "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", N_("Microsoft Basic Data Partition")}, /* Same as Linux BDP */ + {"gpt", "5808C8AA-7E8F-42E0-85D2-E1E90434CFB3", N_("Microsoft LDM Metadata Partition")}, + {"gpt", "AF9B60A0-1431-4F62-BC68-3311714A69AD", N_("Microsoft LDM Data Partition")}, + {"gpt", "DE94BBA4-06D1-4D40-A16A-BFD50179D6AC", N_("Microsoft Windows Recovery Environment")}, + /* HP-UX */ + {"gpt", "75894C1E-3AEB-11D3-B7C1-7B03A0000000", N_("HP-UX Data Partition")}, + {"gpt", "E2A1E728-32E3-11D6-A682-7B03A0000000", N_("HP-UX Service Partition")}, + /* FreeBSD */ + {"gpt", "83BD6B9D-7F41-11DC-BE0B-001560B84F0F", N_("FreeBSD Boot Partition")}, + {"gpt", "516E7CB4-6ECF-11D6-8FF8-00022D09712B", N_("FreeBSD Data Partition")}, + {"gpt", "516E7CB5-6ECF-11D6-8FF8-00022D09712B", N_("FreeBSD Swap Partition")}, + {"gpt", "516E7CB6-6ECF-11D6-8FF8-00022D09712B", N_("FreeBSD UFS Partition")}, + {"gpt", "516E7CB8-6ECF-11D6-8FF8-00022D09712B", N_("FreeBSD Vinum Partition")}, + {"gpt", "516E7CBA-6ECF-11D6-8FF8-00022D09712B", N_("FreeBSD ZFS Partition")}, + /* Solaris */ + {"gpt", "6A82CB45-1DD2-11B2-99A6-080020736631", N_("Solaris Boot Partition")}, + {"gpt", "6A85CF4D-1DD2-11B2-99A6-080020736631", N_("Solaris Root Partition")}, + {"gpt", "6A87C46F-1DD2-11B2-99A6-080020736631", N_("Solaris Swap Partition")}, + {"gpt", "6A8B642B-1DD2-11B2-99A6-080020736631", N_("Solaris Backup Partition")}, + {"gpt", "6A898CC3-1DD2-11B2-99A6-080020736631", N_("Solaris /usr Partition")}, /* Same as Apple ZFS */ + {"gpt", "6A8EF2E9-1DD2-11B2-99A6-080020736631", N_("Solaris /var Partition")}, + {"gpt", "6A90BA39-1DD2-11B2-99A6-080020736631", N_("Solaris /home Partition")}, + {"gpt", "6A9283A5-1DD2-11B2-99A6-080020736631", N_("Solaris Alternate Sector Partition")}, + {"gpt", "6A945A3B-1DD2-11B2-99A6-080020736631", N_("Solaris Reserved Partition")}, + {"gpt", "6A9630D1-1DD2-11B2-99A6-080020736631", N_("Solaris Reserved Partition (2)")}, + {"gpt", "6A980767-1DD2-11B2-99A6-080020736631", N_("Solaris Reserved Partition (3)")}, + {"gpt", "6A96237F-1DD2-11B2-99A6-080020736631", N_("Solaris Reserved Partition (4)")}, + {"gpt", "6A8D2AC7-1DD2-11B2-99A6-080020736631", N_("Solaris Reserved Partition (5)")}, + /* Mac OS X */ + {"gpt", "48465300-0000-11AA-AA11-00306543ECAC", N_("Apple HFS/HFS+ Partition")}, + {"gpt", "55465300-0000-11AA-AA11-00306543ECAC", N_("Apple UFS Partition")}, + {"gpt", "6A898CC3-1DD2-11B2-99A6-080020736631", N_("Apple ZFS Partition")}, /* Same as Solaris /usr */ + {"gpt", "52414944-0000-11AA-AA11-00306543ECAC", N_("Apple RAID Partition")}, + {"gpt", "52414944-5F4F-11AA-AA11-00306543ECAC", N_("Apple RAID Partition (Offline)")}, + {"gpt", "426F6F74-0000-11AA-AA11-00306543ECAC", N_("Apple Boot Partition")}, + {"gpt", "4C616265-6C00-11AA-AA11-00306543ECAC", N_("Apple Label Partition")}, + {"gpt", "5265636F-7665-11AA-AA11-00306543ECAC", N_("Apple TV Recovery Partition")}, + /* NetBSD */ + {"gpt", "49F48D32-B10E-11DC-B99B-0019D1879648", N_("NetBSD Swap Partition")}, + {"gpt", "49F48D5A-B10E-11DC-B99B-0019D1879648", N_("NetBSD FFS Partition")}, + {"gpt", "49F48D82-B10E-11DC-B99B-0019D1879648", N_("NetBSD LFS Partition")}, + {"gpt", "49F48DAA-B10E-11DC-B99B-0019D1879648", N_("NetBSD RAID Partition")}, + {"gpt", "2DB519C4-B10F-11DC-B99B-0019D1879648", N_("NetBSD Concatenated Partition")}, + {"gpt", "2DB519EC-B10F-11DC-B99B-0019D1879648", N_("NetBSD Encrypted Partition")}, + + /* see http://developer.apple.com/documentation/mac/Devices/Devices-126.html + * http://lists.apple.com/archives/Darwin-drivers/2003/May/msg00021.html */ + {"apm", "Apple_Unix_SVR2", N_("Apple UFS Partition")}, + {"apm", "Apple_HFS", N_("Apple HFS/HFS+ Partition")}, + {"apm", "Apple_partition_map", N_("Apple Partition Map")}, + {"apm", "Apple_Free", N_("Unused Partition")}, + {"apm", "Apple_Scratch", N_("Empty Partition")}, + {"apm", "Apple_Driver", N_("Driver Partition")}, + {"apm", "Apple_Driver43", N_("Driver 4.3 Partition")}, + {"apm", "Apple_PRODOS", N_("ProDOS file system")}, + {"apm", "DOS_FAT_12", N_("FAT 12")}, + {"apm", "DOS_FAT_16", N_("FAT 16")}, + {"apm", "DOS_FAT_32", N_("FAT 32")}, + {"apm", "Windows_FAT_16", N_("FAT 16 (Windows)")}, + {"apm", "Windows_FAT_32", N_("FAT 32 (Windows)")}, + + /* see http://www.win.tue.nl/~aeb/partitions/partition_types-1.html */ + {"mbr", "0x00", N_("Empty (0x00)")}, + {"mbr", "0x01", N_("FAT12 (0x01)")}, + {"mbr", "0x04", N_("FAT16 <32M (0x04)")}, + {"mbr", "0x05", N_("Extended (0x05)")}, + {"mbr", "0x06", N_("FAT16 (0x06)")}, + {"mbr", "0x07", N_("HPFS/NTFS (0x07)")}, + {"mbr", "0x0b", N_("W95 FAT32 (0x0b)")}, + {"mbr", "0x0c", N_("W95 FAT32 (LBA) (0x0c)")}, + {"mbr", "0x0e", N_("W95 FAT16 (LBA) (0x0e)")}, + {"mbr", "0x0f", N_("W95 Ext d (LBA) (0x0f)")}, + {"mbr", "0x10", N_("OPUS (0x10)")}, + {"mbr", "0x11", N_("Hidden FAT12 (0x11)")}, + {"mbr", "0x12", N_("Compaq diagnostics (0x12)")}, + {"mbr", "0x14", N_("Hidden FAT16 <32M (0x14)")}, + {"mbr", "0x16", N_("Hidden FAT16 (0x16)")}, + {"mbr", "0x17", N_("Hidden HPFS/NTFS (0x17)")}, + {"mbr", "0x1b", N_("Hidden W95 FAT32 (0x1b)")}, + {"mbr", "0x1c", N_("Hidden W95 FAT32 (LBA) (0x1c)")}, + {"mbr", "0x1e", N_("Hidden W95 FAT16 (LBA) (0x1e)")}, + {"mbr", "0x3c", N_("PartitionMagic (0x3c)")}, + {"mbr", "0x81", N_("Minix (0x81)")}, /* cf. http://en.wikipedia.org/wiki/MINIX_file_system */ + {"mbr", "0x82", N_("Linux swap (0x82)")}, + {"mbr", "0x83", N_("Linux (0x83)")}, + {"mbr", "0x84", N_("Hibernation (0x84)")}, + {"mbr", "0x85", N_("Linux Extended (0x85)")}, + {"mbr", "0x8e", N_("Linux LVM (0x8e)")}, + {"mbr", "0xa0", N_("Hibernation (0xa0)")}, + {"mbr", "0xa5", N_("FreeBSD (0xa5)")}, + {"mbr", "0xa6", N_("OpenBSD (0xa6)")}, + {"mbr", "0xa8", N_("Mac OS X (0xa8)")}, + {"mbr", "0xaf", N_("Mac OS X (0xaf)")}, + {"mbr", "0xbe", N_("Solaris boot (0xbe)")}, + {"mbr", "0xbf", N_("Solaris (0xbf)")}, + {"mbr", "0xeb", N_("BeOS BFS (0xeb)")}, + {"mbr", "0xec", N_("SkyOS SkyFS (0xec)")}, + {"mbr", "0xee", N_("EFI GPT (0xee)")}, + {"mbr", "0xef", N_("EFI (FAT-12/16/32 (0xef)")}, + {"mbr", "0xfd", N_("Linux RAID autodetect (0xfd)")}, + {NULL, NULL, NULL} +}; + +/** + * udisks_util_get_part_type_for_display: + * @scheme: A partitioning scheme id. + * @type: A partition type. + * + * Gets a human readable localized string for @scheme and @type. + * + * Returns: A string that should be freed with g_free(). + */ +gchar * +udisks_util_get_part_type_for_display (const gchar *scheme, + const gchar *type) +{ + guint n; + gchar *ret; + + for (n = 0; part_type[n].name != NULL; n++) + { + if (g_strcmp0 (part_type[n].scheme, scheme) == 0 && + g_strcmp0 (part_type[n].type, type) == 0) + { + ret = g_strdup (_(part_type[n].name)); + goto out; + } + } + + /* Translators: Shown for unknown partition types. + * First %s is the partition type. + */ + ret = g_strdup_printf (_("Unknown Type (%s)"), type); + + out: + return ret; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +const static struct +{ + const gchar *usage; + const gchar *type; + const gchar *version; + const gchar *long_name; + const gchar *short_name; +} id_type[] = +{ + {"filesystem", "vfat", "FAT12", N_("FAT (12-bit version)"), N_("FAT")}, + {"filesystem", "vfat", "FAT16", N_("FAT (16-bit version)"), N_("FAT")}, + {"filesystem", "vfat", "FAT32", N_("FAT (32-bit version)"), N_("FAT")}, + {"filesystem", "ntfs", "*", N_("FAT (version %s)"), N_("FAT")}, + {"filesystem", "vfat", NULL, N_("FAT"), N_("FAT")}, + {"filesystem", "ntfs", "*", N_("NTFS (version %s)"), N_("NTFS")}, + {"filesystem", "ntfs", NULL, N_("NTFS"), N_("NTFS")}, + {"filesystem", "hfs", NULL, N_("HFS"), N_("HFS")}, + {"filesystem", "hfsplus", NULL, N_("HFS+"), N_("HFS+")}, + {"filesystem", "ext2", "*", N_("Ext2 (version %s)"), N_("ext2")}, + {"filesystem", "ext2", NULL, N_("Ext2"), N_("ext2")}, + {"filesystem", "ext3", "*", N_("Ext3 (version %s)"), N_("ext2")}, + {"filesystem", "ext3", NULL, N_("Ext3"), N_("ext2")}, + {"filesystem", "ext4", "*", N_("Ext4 (version %s)"), N_("ext2")}, + {"filesystem", "ext4", NULL, N_("Ext4"), N_("ext2")}, + {"filesystem", "jdb", "*", N_("Journal for Ext (version %s)"), N_("jdb")}, + {"filesystem", "jdb", "*", N_("Journal for Ext"), N_("jdb")}, + {"filesystem", "xfs", "*", N_("XFS (version %s)"), N_("XFS")}, + {"filesystem", "xfs", NULL, N_("XFS"), N_("XFS")}, + {"filesystem", "iso9660", "*", N_("ISO 9660 (version %s)"), N_("iso9660")}, + {"filesystem", "iso9660", NULL, N_("ISO 9660"), N_("iso9660")}, + {"filesystem", "udf", "*", N_("UDF (version %s)"), N_("udf")}, + {"filesystem", "udf", NULL, N_("UDF"), N_("udf")}, + {"other", "swap", "*", N_("Swap (version %s)"), N_("swap")}, + {"other", "swap", NULL, N_("Swap"), N_("swap")}, + {"raid", "LVM2_member", "*", N_("LVM2 Phyiscal Volume (version %s)"), N_("lvm2pv")}, + {"raid", "LVM2_member", NULL, N_("LVM2 Phyiscal Volume"), N_("lvm2pv")}, + {"raid", "linux_raid_member", "*", N_("RAID Component (version %s)"), N_("raid")}, + {"raid", "linux_raid_member", NULL, N_("RAID Component"), N_("raid")}, + {"crypto", "crypto_LUKS", "*", N_("LUKS Encryption (version %s)"), N_("LUKS")}, + {"crypto", "crypto_LUKS", NULL, N_("LUKS Encryption"), N_("LUKS")}, + {NULL, NULL, NULL, NULL} +}; + +/** + * udisks_util_get_id_for_display: + * @usage: Usage id e.g. "filesystem" or "crypto". + * @type: Type e.g. "ext4" or "crypto_LUKS" + * @version: Version. + * @long_string: Whether to produce a long string. + * + * Gets a human readable localized string for @usage, @type and @version. + * + * Returns: A string that should be freed with g_free(). + */ +gchar * +udisks_util_get_id_for_display (const gchar *usage, + const gchar *type, + const gchar *version, + gboolean long_string) +{ + guint n; + gchar *ret; + + ret = NULL; + + for (n = 0; id_type[n].usage != NULL; n++) + { + if (g_strcmp0 (id_type[n].usage, usage) == 0 && + g_strcmp0 (id_type[n].type, type) == 0) + { + if ((id_type[n].version == NULL && strlen (version) == 0)) + { + if (long_string) + ret = g_strdup (_(id_type[n].long_name)); + else + ret = g_strdup (_(id_type[n].short_name)); + goto out; + } + else if ((g_strcmp0 (id_type[n].version, version) == 0 && strlen (version) > 0) || + (g_strcmp0 (id_type[n].version, "*") == 0 && strlen (version) > 0)) + { + if (long_string) + ret = g_strdup_printf (_(id_type[n].long_name), version); + else + ret = g_strdup_printf (_(id_type[n].short_name), version); + goto out; + } + } + } + + if (long_string) + { + if (strlen (version) > 0) + { + /* Translators: Shown for unknown filesystem types. + * First %s is the filesystem type, second %s is version. + */ + ret = g_strdup_printf (_("Unknown (%s %s)"), type, version); + } + else + { + if (strlen (type) > 0) + { + /* Translators: Shown for unknown filesystem types. + * First %s is the filesystem type. + */ + ret = g_strdup_printf (_("Unknown (%s)"), type); + } + else + { + /* Translators: Shown for unknown filesystem types. + */ + ret = g_strdup (_("Unknown")); + } + } + } + else + { + ret = g_strdup (type); + } + + out: + return ret; +} diff --git a/udisks/udisksutil.h b/udisks/udisksutil.h index 6d83a5b..f4aad17 100644 --- a/udisks/udisksutil.h +++ b/udisks/udisksutil.h @@ -34,6 +34,16 @@ gchar *udisks_util_get_size_for_display (guint64 size, gboolean use_pow2, gboolean long_string); +gchar *udisks_util_get_part_scheme_for_display (const gchar *scheme); + +gchar *udisks_util_get_part_type_for_display (const gchar *scheme, + const gchar *type); + +gchar *udisks_util_get_id_for_display (const gchar *usage, + const gchar *id, + const gchar *version, + gboolean long_string); + void udisks_util_get_lun_info (UDisksLun *lun, gchar **out_name, gchar **out_description,