diff options
author | Simon Quigley <tsimonq2@ubuntu.com> | 2017-06-19 14:38:41 -0500 |
---|---|---|
committer | Simon Quigley <tsimonq2@ubuntu.com> | 2017-06-19 14:38:41 -0500 |
commit | 11b8179a57e675c6672cbe649c655230ae3e9744 (patch) | |
tree | 2919c366d51e154e65279156fef5b4f97b8fd2f9 /arch/linux/common/storage.h | |
parent | 720f5023a8f68aaaa54cb6b7bf46efee23b5b4c3 (diff) |
Import Upstream version 0.4.2.1
Diffstat (limited to 'arch/linux/common/storage.h')
-rw-r--r-- | arch/linux/common/storage.h | 133 |
1 files changed, 108 insertions, 25 deletions
diff --git a/arch/linux/common/storage.h b/arch/linux/common/storage.h index 4fb682a9..836ba7ea 100644 --- a/arch/linux/common/storage.h +++ b/arch/linux/common/storage.h @@ -22,8 +22,6 @@ static gboolean remove_scsi_devices(gpointer key, gpointer value, gpointer data) { if (!strncmp((gchar *) key, "SCSI", 4)) { - g_free((gchar *) key); - g_free((GtkTreeIter *) value); return TRUE; } return FALSE; @@ -31,7 +29,7 @@ remove_scsi_devices(gpointer key, gpointer value, gpointer data) /* SCSI support by Pascal F.Martin <pascalmartin@earthlink.net> */ void -scan_scsi(void) +__scan_scsi_devices(void) { FILE *proc_scsi; gchar buffer[256], *buf; @@ -43,7 +41,7 @@ scan_scsi(void) gchar *vendor = NULL, *revision = NULL, *model = NULL; /* remove old devices from global device table */ - g_hash_table_foreach_remove(devices, remove_scsi_devices, NULL); + g_hash_table_foreach_remove(moreinfo, remove_scsi_devices, NULL); if (!g_file_test("/proc/scsi/scsi", G_FILE_TEST_EXISTS)) return; @@ -107,7 +105,7 @@ scan_scsi(void) int i; for (i = 0; type2icon[i].type != NULL; i++) - if (!strcmp(buf + 8, type2icon[i].type)) + if (g_str_equal(buf + 8, type2icon[i].type)) break; type = type2icon[i].label; @@ -120,6 +118,7 @@ scan_scsi(void) gchar *strhash = g_strdup_printf("[Device Information]\n" "Model=%s\n" + "Vendor=%s (%s)\n" "Type=%s\n" "Revision=%s\n" "[SCSI Controller]\n" @@ -127,13 +126,15 @@ scan_scsi(void) "Channel=%d\n" "ID=%d\n" "LUN=%d\n", model, + vendor_get_name(model), + vendor_get_url(model), type, revision, scsi_controller, scsi_channel, scsi_id, scsi_lun); - g_hash_table_insert(devices, devid, strhash); + g_hash_table_insert(moreinfo, devid, strhash); g_free(model); g_free(revision); @@ -147,25 +148,22 @@ static gboolean remove_ide_devices(gpointer key, gpointer value, gpointer data) { if (!strncmp((gchar *) key, "IDE", 3)) { - g_free((gchar *) key); - g_free((gchar *) value); - return TRUE; } return FALSE; } - void -scan_ide(void) +__scan_ide_devices(void) { FILE *proc_ide; gchar *device, iface, *model, *media, *pgeometry = NULL, *lgeometry = NULL; - gint n = 0, i = 0, cache; + gint n = 0, i = 0, cache, nn = 0; + gchar *capab = NULL, *speed = NULL, *driver = NULL; /* remove old devices from global device table */ - g_hash_table_foreach_remove(devices, remove_ide_devices, NULL); + g_hash_table_foreach_remove(moreinfo, remove_ide_devices, NULL); storage_list = g_strdup_printf("%s\n[IDE Disks]\n", storage_list); @@ -173,12 +171,12 @@ scan_ide(void) for (i = 0; i <= 16; i++) { device = g_strdup_printf("/proc/ide/hd%c/model", iface); if (g_file_test(device, G_FILE_TEST_EXISTS)) { - gchar buf[64]; + gchar buf[128]; cache = 0; proc_ide = fopen(device, "r"); - fgets(buf, 64, proc_ide); + fgets(buf, 128, proc_ide); fclose(proc_ide); buf[strlen(buf) - 1] = 0; @@ -189,11 +187,67 @@ scan_ide(void) device = g_strdup_printf("/proc/ide/hd%c/media", iface); proc_ide = fopen(device, "r"); - fgets(buf, 64, proc_ide); + fgets(buf, 128, proc_ide); fclose(proc_ide); buf[strlen(buf) - 1] = 0; media = g_strdup(buf); + if (g_str_equal(media, "cdrom")) { + /* obtain cd-rom drive information from cdrecord */ + GTimer *timer; + gchar *tmp = g_strdup_printf("cdrecord dev=/dev/hd%c -prcap 2>/dev/stdout", iface); + FILE *prcap; + + if ((prcap = popen(tmp, "r"))) { + /* we need a timeout so cdrecord does not try to get information on cd drives + with inserted media, which is not possible currently. half second should be + enough. */ + timer = g_timer_new(); + g_timer_start(timer); + + while (fgets(buf, 128, prcap) && g_timer_elapsed(timer, NULL) < 0.5) { + if (g_str_has_prefix(buf, " Does")) { + if (g_str_has_suffix(buf, "media\n") && !strstr(buf, "speed")) { + gchar *media_type = g_strstrip(strstr(buf, "Does ")); + gchar **ttmp = g_strsplit(media_type, " ", 0); + + capab = g_strdup_printf("%s\nCan %s#%d=%s\n", + capab ? capab : "", + ttmp[1], ++nn, ttmp[2]); + + g_strfreev(ttmp); + } else if (strstr(buf, "Buffer-Underrun-Free")) { + capab = g_strdup_printf("%s\nSupports BurnProof=%s\n", + capab ? capab : "", + strstr(buf, "Does not") ? "No" : "Yes"); + } else if (strstr(buf, "multi-session")) { + capab = g_strdup_printf("%s\nCan read multi-session CDs=%s\n", + capab ? capab : "", + strstr(buf, "Does not") ? "No" : "Yes"); + } else if (strstr(buf, "audio CDs")) { + capab = g_strdup_printf("%s\nCan play audio CDs=%s\n", + capab ? capab : "", + strstr(buf, "Does not") ? "No" : "Yes"); + } else if (strstr(buf, "PREVENT/ALLOW")) { + capab = g_strdup_printf("%s\nCan lock media=%s\n", + capab ? capab : "", + strstr(buf, "Does not") ? "No" : "Yes"); + } + } else if ((strstr(buf, "read") || strstr(buf, "write")) && strstr(buf, "kB/s")) { + speed = g_strconcat(speed ? speed : "", + strreplace(g_strstrip(buf), ":", '='), + "\n", NULL); + } else if (strstr(buf, "Device seems to be")) { + driver = g_strdup_printf("Driver=%s\n", strchr(buf, ':') + 1); + } + } + + pclose(prcap); + g_timer_destroy(timer); + } + + g_free(tmp); + } g_free(device); @@ -242,24 +296,53 @@ scan_ide(void) gchar *strhash = g_strdup_printf("[Device Information]\n" "Model=%s\n" + "Vendor=%s (%s)\n" "Device Name=hd%c\n" - "Media=%s\n" "Cache=%dkb\n", - model, iface, media, cache); - if (pgeometry && lgeometry) + "Media=%s\n" + "Cache=%dkb\n", + model, + vendor_get_name(model), + vendor_get_url(model), + iface, + media, + cache); + if (driver) { + strhash = g_strdup_printf("%s%s\n", strhash, driver); + + g_free(driver); + driver = NULL; + } + + if (pgeometry && lgeometry) { strhash = g_strdup_printf("%s[Geometry]\n" "Physical=%s\n" "Logical=%s\n", strhash, pgeometry, lgeometry); + + g_free(pgeometry); + pgeometry = NULL; + g_free(lgeometry); + lgeometry = NULL; + } + + if (capab) { + strhash = g_strdup_printf("%s[Capabilities]\n%s", strhash, capab); + + g_free(capab); + capab = NULL; + } - g_hash_table_insert(devices, devid, strhash); + if (speed) { + strhash = g_strdup_printf("%s[Speeds]\n%s", strhash, speed); + + g_free(speed); + speed = NULL; + } + + g_hash_table_insert(moreinfo, devid, strhash); g_free(model); model = ""; - - g_free(pgeometry); - pgeometry = NULL; - g_free(lgeometry); - lgeometry = NULL; } else g_free(device); |