]> git.sur5r.net Git - i3/i3status/commitdiff
Merge pull request #3 from chrko/master
authorMichael Stapelberg <stapelberg@users.noreply.github.com>
Sun, 1 Mar 2015 15:42:59 +0000 (07:42 -0800)
committerMichael Stapelberg <stapelberg@users.noreply.github.com>
Sun, 1 Mar 2015 15:42:59 +0000 (07:42 -0800)
Modify print_disk_info. Now there is no output if the path is no mountpoint.

i3status.c
include/i3status.h
man/i3status.man
src/print_disk_info.c

index 7c98d06ede4ebe50d19768b6a475ceeccbd0521d..6491e1c6015371115de7382941fdd96d2820cd89 100644 (file)
@@ -386,6 +386,7 @@ int main(int argc, char *argv[]) {
 
         cfg_opt_t disk_opts[] = {
                 CFG_STR("format", "%free", CFGF_NONE),
+                CFG_STR("format_not_mounted", NULL, CFGF_NONE),
                 CFG_STR("prefix_type", "binary", CFGF_NONE),
                 CFG_STR("threshold_type", "percentage_avail", CFGF_NONE),
                 CFG_FLOAT("low_threshold", 0, CFGF_NONE),
@@ -621,7 +622,7 @@ int main(int argc, char *argv[]) {
 
                         CASE_SEC_TITLE("disk") {
                                 SEC_OPEN_MAP("disk_info");
-                                print_disk_info(json_gen, buffer, title, cfg_getstr(sec, "format"), cfg_getstr(sec, "prefix_type"), cfg_getstr(sec, "threshold_type"), cfg_getfloat(sec, "low_threshold"));
+                                print_disk_info(json_gen, buffer, title, cfg_getstr(sec, "format"), cfg_getstr(sec, "format_not_mounted"), cfg_getstr(sec, "prefix_type"), cfg_getstr(sec, "threshold_type"), cfg_getfloat(sec, "low_threshold"));
                                 SEC_CLOSE_MAP;
                         }
 
index ef212c83fd1a964784d8ea600025b92df9184ae7..6e20af3009ae884cfe32cb0b6ac3df9d81a8a318 100644 (file)
@@ -178,7 +178,7 @@ typedef enum {
 const char *first_eth_interface(const net_type_t type);
 
 void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down);
-void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format, const char *prefix_type, const char *threshold_type, const double low_threshold);
+void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format, const char *format_not_mounted, const char *prefix_type, const char *threshold_type, const double low_threshold);
 void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, const char *status_chr, const char *status_bat, const char *status_full, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds);
 void print_time(yajl_gen json_gen, char *buffer, const char *format, const char *tz, time_t t);
 void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t);
index e11aff508a7f5afe1becbb73c779cf247ea0ef66..a2526e97e8b427b32fc6fccbec99dc18e89fb4a1 100644 (file)
@@ -237,6 +237,11 @@ space is below 2 GiB, it will be colored bad. If not specified, threshold_type
 is assumed to be "percentage_avail" and low_threshold to be set to 0, which
 implies no coloring at all.
 
+You can define a different format with the option "format_not_mounted"
+which is used if the path is not a mount point. So you can just empty
+the output for the given path with adding »format_not_mounted=""«
+to the config section.
+
 *Example order*: +disk /mnt/usbstick+
 
 *Example format*: +%free (%avail)/ %total+
index 167121045cebcced788d7b8d810bccffdc53bf14..e225923a03be01510999f0b48ecb1533766ceb06 100644 (file)
@@ -3,7 +3,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <mntent.h>
 #include <stdint.h>
+#include <sys/stat.h>
 #include <sys/statvfs.h>
 #include <sys/types.h>
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (__OpenBSD__) || defined(__DragonFly__)
@@ -106,7 +108,7 @@ static bool below_threshold(struct statvfs buf, const char *prefix_type, const c
  * human readable manner.
  *
  */
-void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format, const char *prefix_type, const char *threshold_type, const double low_threshold) {
+void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format, const char *format_not_mounted, const char *prefix_type, const char *threshold_type, const double low_threshold) {
         const char *walk;
         char *outwalk = buffer;
         bool colorful_output = false;
@@ -123,6 +125,24 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch
 
         if (statvfs(path, &buf) == -1)
                 return;
+
+        if (format_not_mounted != NULL) {
+                FILE *mntentfile = setmntent("/etc/mtab", "r");
+                struct mntent *m;
+                bool found = false;
+
+                while ((m = getmntent(mntentfile)) != NULL) {
+                        if (strcmp(m->mnt_dir, path) == 0) {
+                                found = true;
+                                break;
+                        }
+                }
+                endmntent(mntentfile);
+
+                if (!found) {
+                        format = format_not_mounted;
+                }
+        }
 #endif
 
         if (low_threshold > 0 && below_threshold(buf, prefix_type, threshold_type, low_threshold)) {