From 004d1cb7ba8d393fdd6fe80e2781a78c739ec478 Mon Sep 17 00:00:00 2001 From: Phil Date: Mon, 24 Mar 2008 20:08:16 +0000 Subject: [PATCH] disk_protect - show queue protection state * disk protection needs a kernel patch and is useful in combination with hdaps git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1045 7f574dfc-610e-0410-a909-a81674777703 --- doc/conky.1 | 4 ++++ doc/variables.xml | 11 +++++++++++ src/conky.c | 13 +++++++++++++ src/conky.h | 1 + src/linux.c | 18 ++++++++++++++++++ 5 files changed, 47 insertions(+) diff --git a/doc/conky.1 b/doc/conky.1 index c392759b..a4725766 100644 --- a/doc/conky.1 +++ b/doc/conky.1 @@ -643,6 +643,10 @@ Displays current disk IO for writes. Device as in diskio. \fB\*(T<\fBdiskiograph_write\fR\*(T>\fR \*(T<\fB(device) (height),(width) (gradient colour 1) (gradient colour 2) (scale)\fR\*(T> Disk IO graph for writes, colours defined in hex, minus the #. If scale is non-zero, it becomes the scale for the graph. Device as in diskio. +.TP +\fB\*(T<\fBdisk_protect\fR\*(T>\fR \*(T<\fBdevice\fR\*(T> +Disk protection status, if supported (needs kernel-patch). Prints either "frozen" or "free " (note the padding). + .TP \fB\*(T<\fBdownspeed\fR\*(T>\fR \*(T<\fBnet\fR\*(T> Download speed in kilobytes diff --git a/doc/variables.xml b/doc/variables.xml index 7499ccf8..74674665 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -572,6 +572,17 @@ + + + + + Disk protection status, if supported (needs kernel-patch). Prints either "frozen" or "free " (note the padding). + + + + + + diff --git a/src/conky.c b/src/conky.c index d31ab44c..65eccab3 100644 --- a/src/conky.c +++ b/src/conky.c @@ -1128,6 +1128,7 @@ enum text_object_type { OBJ_platform, OBJ_hwmon, #if defined(__linux__) + OBJ_disk_protect, OBJ_i8k_version, OBJ_i8k_bios, OBJ_i8k_serial, @@ -2049,6 +2050,9 @@ static void free_text_objects(unsigned int count, struct text_object *objs) break; #endif #ifdef __LINUX__ + case OBJ_disk_protect: + free(objs[i].data.s); + break; case OBJ_if_up: free(objs[i].data.ifblock.s); free(objs[i].data.ifblock.str); @@ -2443,6 +2447,11 @@ static struct text_object *construct_text_object(const char *s, #endif /* !__OpenBSD__ */ #if defined(__linux__) + END OBJ(disk_protect, 0) + if (arg) + obj->data.s = strdup(arg); + else + CRIT_ERR("disk_protect needs an argument"); END OBJ(i8k_version, INFO_I8K) END OBJ(i8k_bios, INFO_I8K) END OBJ(i8k_serial, INFO_I8K) @@ -4342,6 +4351,10 @@ static void generate_text_internal(char *p, int p_max_size, snprintf(p, p_max_size, "%s", BUILD_ARCH); } #if defined(__linux__) + OBJ(disk_protect) { + snprintf(p, p_max_size, "%s", + get_disk_protect_queue(obj->data.s)); + } OBJ(i8k_version) { snprintf(p, p_max_size, "%s", i8k.version); } diff --git a/src/conky.h b/src/conky.h index 08b0bbad..6ccae9e6 100644 --- a/src/conky.h +++ b/src/conky.h @@ -584,6 +584,7 @@ void get_ibm_acpi_fan(char *buf, size_t client_buffer_size); void get_ibm_acpi_temps(void); void get_ibm_acpi_volume(char *buf, size_t client_buffer_size); void get_ibm_acpi_brightness(char *buf, size_t client_buffer_size); +char *get_disk_protect_queue(char *disk); void get_cpu_count(); struct ibm_acpi_struct { diff --git a/src/linux.c b/src/linux.c index d4a5860d..d1bd1ba6 100644 --- a/src/linux.c +++ b/src/linux.c @@ -2416,3 +2416,21 @@ void update_entropy(void) info.mask |= (1 << INFO_ENTROPY); } + +char *get_disk_protect_queue(char *disk) +{ + FILE *fp; + char path[128]; + int state; + + snprintf(path, 127, "/sys/block/%s/queue/protect", disk); + if ((fp = fopen(path, "r")) == NULL) + return "n/a "; + if (fscanf(fp, "%d\n", &state) != 1) { + fclose(fp); + return "failed"; + } + fclose(fp); + return state ? "frozen" : "free "; +} +