From 8683dd4263f7890067452ccc3f1c91588f7ad0ac Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Mon, 1 Nov 2010 13:28:12 -0400 Subject: [PATCH] Properly sort according to CTDS So it looks like e.g. this $ udisks status CTDS MODEL REVISION SERIAL BLOCK -------------------------------------------------------------------------------- 0:0:0:0 SEAGATE ST3300657SS 0006 3SJ1S7K600009051M0CE - 0:0:1:0 SEAGATE ST3300657SS 0006 3SJ1S4MH00009052RG6Z - 0:0:2:0 SEAGATE ST3300657SS 0006 3SJ1RFP900009051HZ5S - 0:0:3:0 SEAGATE ST3300657SS 0006 3SJ1S66L00009052QGZA - 0:0:4:0 SEAGATE ST3300657SS 0006 3SJ1RPFJ00009052BZ10 - 0:0:5:0 SEAGATE ST3300657SS 0006 3SJ1RWZ100009101T12H - 0:0:6:0 SEAGATE ST3300657SS 0006 3SJ1S7C500009052RKPP - 0:0:7:0 SEAGATE ST3300657SS 0006 3SJ1S40K00009101T1XU - 0:0:8:0 SEAGATE ST3300657SS 0006 3SJ1RJS700009050VYEA - 0:0:9:0 SEAGATE ST3300657SS 0006 3SJ1RSJC00009052MWTB - 0:0:10:0 SEAGATE ST3300657SS 0006 3SJ1QNMQ00009052NECM - 0:0:11:0 SEAGATE ST3300657SS 0006 3SJ1S3NE00009101TB5Y - 0:0:13:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30012560 - 0:0:14:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30064749 - 0:0:15:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30039741 - 0:0:16:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30064055 - 0:0:17:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30030732 - 0:0:18:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30010853 - 0:0:19:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30024753 - 0:0:20:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30065104 - 0:0:21:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30031826 - 0:0:22:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30025874 - 0:0:23:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30063724 - 0:0:24:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30064486 - 0:0:25:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30032003 - 0:0:26:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30021345 - 0:0:27:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30067287 - 0:0:28:0 WDC WD1002FAEX-00Y9A0 01.01V10 WD-WCAW30014347 - 0:0:30:0 SEAGATE ST3300657SS 0006 3SJ1S7K600009051M0CE - 0:0:31:0 SEAGATE ST3300657SS 0006 3SJ1S4MH00009052RG6Z - 0:0:32:0 SEAGATE ST3300657SS 0006 3SJ1RFP900009051HZ5S - 0:0:33:0 SEAGATE ST3300657SS 0006 3SJ1S66L00009052QGZA - 0:0:34:0 SEAGATE ST3300657SS 0006 3SJ1RPFJ00009052BZ10 - 0:0:35:0 SEAGATE ST3300657SS 0006 3SJ1RWZ100009101T12H - 0:0:36:0 SEAGATE ST3300657SS 0006 3SJ1S7C500009052RKPP - 0:0:37:0 SEAGATE ST3300657SS 0006 3SJ1S40K00009101T1XU - 0:0:38:0 SEAGATE ST3300657SS 0006 3SJ1RJS700009050VYEA - 0:0:39:0 SEAGATE ST3300657SS 0006 3SJ1RSJC00009052MWTB - 0:0:40:0 SEAGATE ST3300657SS 0006 3SJ1QNMQ00009052NECM - 0:0:41:0 SEAGATE ST3300657SS 0006 3SJ1S3NE00009101TB5Y - 1:0:0:0 HP LOGICAL VOLUME 3.00 5001438008F61790 - Signed-off-by: David Zeuthen --- tools/udisks.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/tools/udisks.c b/tools/udisks.c index 3c4d6ac..1569d6a 100644 --- a/tools/udisks.c +++ b/tools/udisks.c @@ -1347,6 +1347,23 @@ handle_command_monitor (gint *argc, /* ---------------------------------------------------------------------------------------------------- */ +static void +parse_ctds (const gchar *ctds, + guint *c, + guint *d, + guint *t, + guint *s) +{ + if (sscanf (ctds, "%d:%d:%d:%d", c, d, t, s) != 4) + { + g_warning ("Error parsing `%s'", ctds); + *c = 0; + *d = 0; + *t = 0; + *s = 0; + } +} + static gint obj_proxy_cmp_ctds (GDBusObjectProxy *a, GDBusObjectProxy *b) @@ -1358,7 +1375,35 @@ obj_proxy_cmp_ctds (GDBusObjectProxy *a, db = UDISKS_PEEK_DRIVE (b); if (da != NULL && db != NULL) - return g_strcmp0 (udisks_drive_get_ctds (da), udisks_drive_get_ctds (db)); + { + guint c_a, t_a, d_a, s_a; + guint c_b, t_b, d_b, s_b; + + parse_ctds (udisks_drive_get_ctds (da), &c_a, &t_a, &d_a, &s_a); + parse_ctds (udisks_drive_get_ctds (db), &c_b, &t_b, &d_b, &s_b); + + if (c_a > c_b) + return 1; + else if (c_a < c_b) + return -1; + + if (t_a > t_b) + return 1; + else if (t_a < t_b) + return -1; + + if (d_a > d_b) + return 1; + else if (d_a < d_b) + return -1; + + if (s_a > s_b) + return 1; + else if (s_a < s_b) + return -1; + + return 0; + } else return obj_proxy_cmp (a, b); } -- 2.7.4