diff options
-rw-r--r-- | i3status.c | 3 | ||||
-rw-r--r-- | include/i3status.h | 2 | ||||
-rw-r--r-- | src/print_disk_info.c | 28 |
3 files changed, 17 insertions, 16 deletions
@@ -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; } diff --git a/include/i3status.h b/include/i3status.h index ef212c8..6e20af3 100644 --- a/include/i3status.h +++ b/include/i3status.h @@ -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); diff --git a/src/print_disk_info.c b/src/print_disk_info.c index 609f6d3..4ed2f22 100644 --- a/src/print_disk_info.c +++ b/src/print_disk_info.c @@ -108,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; @@ -126,22 +126,22 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch if (statvfs(path, &buf) == -1) return; - FILE *mntentfile = setmntent("/etc/mtab", "r"); - struct mntent *m; - bool found = false; + if (format_not_mounted != NULL) { + FILE *mntentfile = setmntent("/etc/mtab", "r"); + struct mntent *m; + bool found = false; - while (NULL != (m = getmntent(mntentfile))) { - if (strcmp(m->mnt_dir, path) == 0) { - found = true; - break; + while (NULL != (m = getmntent(mntentfile))) { + if (strcmp(m->mnt_dir, path) == 0) { + found = true; + break; + } } - } - endmntent(mntentfile); + endmntent(mntentfile); - if (!found) { - *buffer = '\0'; - OUTPUT_FULL_TEXT(buffer); - return; + if (!found) { + format = format_not_mounted; + } } #endif |