6beb01c50d
- update to upstream 3.14.1 - mkfs: - fix TRIM detection - do not zero-out end of device unconditionally - no crash with --features option - fsck: - clear log tree in repair mode - check reloc roots - btrfs - reworked space reporting (bnc#873106) - btrfs fi usage - new command - btrfs dev usage - new command - btrfs fi df - enhanced output with GlobalReserve - Removed patches: * 0001-btrfs-progs-move-arg_strtou64-to-a-separate-file-for.patch - Added patches: * 0001-Btrfs-progs-fix-check-to-test-trim-support.patch * 0002-Btrfs-progs-fsck-fix-double-free-memory-crash.patch * 0003-Btrfs-progs-mkfs-Remove-zero_end-1-since-it-has-been.patch * 0004-btrfs-progs-fix-wrong-max-system-array-size-check-in.patch * 0005-btrfs-progs-move-arg_strtou64-to-a-separate-file-for.patch * 0006-Btrfs-progs-fsck-clear-out-log-tree-in-repair-mode.patch * 0007-Btrfs-progs-fsck-avoid-pinning-same-block-several-ti.patch * 0008-Btrfs-progs-fsck-add-ability-to-check-reloc-roots.patch * 0009-btrfs-progs-prevent-close_root-if-the-root-to-close-.patch * 0010-btrfs-progs-fix-mkfs.btrfs-segfault-with-features-op.patch * 0011-btrfs-progs-Enhance-the-command-btrfs-filesystem-df.patch * 0012-btrfs-progs-Add-helpers-functions-to-handle-the-prin.patch * 0013-btrfs-progs-Add-command-btrfs-filesystem-disk-usage.patch * 0014-btrfs-progs-Add-btrfs-device-disk-usage-command.patch * 0015-btrfs-progs-cleanup-dead-return-after-usage-for-fi-d.patch * 0016-btrfs-progs-Fix-memleak-in-get_raid56_used.patch * 0017-Btrfs-progs-fi-usage-free-memory-if-realloc-fails.patch * 0018-btrfs-progs-read-global-reserve-size-from-space-info.patch * 0019-btrfs-progs-add-original-df-and-rename-disk_usage-to.patch * 0020-btrfs-progs-move-device-usage-to-cmds-device-more-cl.patch * 0021-btrfs-progs-check-if-we-can-t-get-info-from-ioctls-d.patch * 0022-btrfs-progs-zero-out-structures-before-calling-ioctl.patch * 0023-btrfs-progs-print-B-for-bytes.patch * 0024-btrfs-progs-Print-more-info-about-device-sizes.patch * 0025-btrfs-progs-compare-unallocated-space-against-the-co.patch * 0026-btrfs-progs-add-section-of-overall-filesystem-usage.patch * 0027-btrfs-progs-cleanup-filesystem-device-usage-code.patch * 0028-btrfs-progs-extend-pretty-printers-with-unit-mode.patch * 0029-btrfs-progs-replace-df_pretty_sizes-with-pretty_size.patch * 0030-btrfs-progs-clean-up-return-codes-and-paths.patch * 0031-btrfs-progs-move-global-reserve-to-overall-summary.patch OBS-URL: https://build.opensuse.org/request/show/232435 OBS-URL: https://build.opensuse.org/package/show/filesystems/btrfsprogs?expand=0&rev=156
262 lines
6.8 KiB
Diff
262 lines
6.8 KiB
Diff
From a79f61440afaa0b77dc67c896fa3367a171c2306 Mon Sep 17 00:00:00 2001
|
|
From: Goffredo Baroncelli <kreijack@libero.it>
|
|
Date: Thu, 13 Feb 2014 20:19:21 +0100
|
|
Subject: [PATCH 23/42] btrfs-progs: Add helpers functions to handle the
|
|
printing of data in tabular format
|
|
|
|
This patch adds some functions to manage the printing of the data in
|
|
tabular format.
|
|
|
|
The function
|
|
struct string_table *table_create(int columns, int rows)
|
|
creates an (empty) table.
|
|
|
|
The functions
|
|
char *table_printf(struct string_table *tab, int column,
|
|
int row, char *fmt, ...)
|
|
char *table_vprintf(struct string_table *tab, int column,
|
|
int row, char *fmt, va_list ap)
|
|
populate the table with text. To align the text to the left, the text
|
|
shall be prefixed with '<', otherwise the text shall be prefixed by a
|
|
'>'. If the first character is a '=', the the text is replace by a
|
|
sequence of '=' to fill the column width.
|
|
|
|
The function
|
|
void table_free(struct string_table *)
|
|
frees all the data associated to the table.
|
|
|
|
The function
|
|
void table_dump(struct string_table *tab)
|
|
prints the table on stdout.
|
|
|
|
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
|
|
Signed-off-by: David Sterba <dsterba@suse.cz>
|
|
---
|
|
Makefile | 2 +-
|
|
string_table.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
string_table.h | 36 +++++++++++++
|
|
3 files changed, 193 insertions(+), 1 deletion(-)
|
|
create mode 100644 string_table.c
|
|
create mode 100644 string_table.h
|
|
|
|
diff --git a/Makefile b/Makefile
|
|
index 50fb9b0ff2e3..bf6dc1c67d2c 100644
|
|
--- a/Makefile
|
|
+++ b/Makefile
|
|
@@ -10,7 +10,7 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
|
|
root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
|
|
extent-cache.o extent_io.o volumes.o utils.o repair.o \
|
|
qgroup.o raid6.o free-space-cache.o list_sort.o props.o \
|
|
- utils-lib.o
|
|
+ utils-lib.o string_table.o
|
|
cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
|
|
cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
|
|
cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
|
|
diff --git a/string_table.c b/string_table.c
|
|
new file mode 100644
|
|
index 000000000000..016356c50392
|
|
--- /dev/null
|
|
+++ b/string_table.c
|
|
@@ -0,0 +1,156 @@
|
|
+/*
|
|
+ * This program is free software; you can redistribute it and/or
|
|
+ * modify it under the terms of the GNU General Public
|
|
+ * License v2 as published by the Free Software Foundation.
|
|
+ *
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
+ * General Public License for more details.
|
|
+ *
|
|
+ * You should have received a copy of the GNU General Public
|
|
+ * License along with this program; if not, write to the
|
|
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
+ * Boston, MA 021110-1307, USA.
|
|
+ */
|
|
+
|
|
+#include <stdlib.h>
|
|
+#include <string.h>
|
|
+#include <stdio.h>
|
|
+#include <stdarg.h>
|
|
+
|
|
+#include "string_table.h"
|
|
+
|
|
+/*
|
|
+ * This function create an array of char * which will represent a table
|
|
+ */
|
|
+struct string_table *table_create(int columns, int rows)
|
|
+{
|
|
+ struct string_table *p;
|
|
+ int size;
|
|
+
|
|
+ size = sizeof( struct string_table ) +
|
|
+ rows * columns* sizeof(char *);
|
|
+ p = calloc(1, size);
|
|
+
|
|
+ if (!p) return NULL;
|
|
+
|
|
+ p->ncols = columns;
|
|
+ p->nrows = rows;
|
|
+
|
|
+ return p;
|
|
+}
|
|
+
|
|
+/*
|
|
+ * This function is like a vprintf, but store the results in a cell of
|
|
+ * the table.
|
|
+ * If fmt starts with '<', the text is left aligned; if fmt starts with
|
|
+ * '>' the text is right aligned. If fmt is equal to '=' the text will
|
|
+ * be replaced by a '=====' dimensioned on the basis of the column width
|
|
+ */
|
|
+char *table_vprintf(struct string_table *tab, int column, int row,
|
|
+ char *fmt, va_list ap)
|
|
+{
|
|
+ int idx = tab->ncols*row+column;
|
|
+ char *msg = calloc(100, sizeof(char));
|
|
+
|
|
+ if (!msg)
|
|
+ return NULL;
|
|
+
|
|
+ if (tab->cells[idx])
|
|
+ free(tab->cells[idx]);
|
|
+ tab->cells[idx] = msg;
|
|
+ vsnprintf(msg, 99, fmt, ap);
|
|
+
|
|
+ return msg;
|
|
+}
|
|
+
|
|
+
|
|
+/*
|
|
+ * This function is like a printf, but store the results in a cell of
|
|
+ * the table.
|
|
+ */
|
|
+char *table_printf(struct string_table *tab, int column, int row,
|
|
+ char *fmt, ...)
|
|
+{
|
|
+ va_list ap;
|
|
+ char *ret;
|
|
+
|
|
+ va_start(ap, fmt);
|
|
+ ret = table_vprintf(tab, column, row, fmt, ap);
|
|
+ va_end(ap);
|
|
+
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+/*
|
|
+ * This function dumps the table. Every "=" string will be replaced by
|
|
+ * a "=======" length as the column
|
|
+ */
|
|
+void table_dump(struct string_table *tab)
|
|
+{
|
|
+ int sizes[tab->ncols];
|
|
+ int i, j;
|
|
+
|
|
+ for (i = 0 ; i < tab->ncols ; i++) {
|
|
+ sizes[i] = 0;
|
|
+ for (j = 0 ; j < tab->nrows ; j++) {
|
|
+ int idx = i + j*tab->ncols;
|
|
+ int s;
|
|
+
|
|
+ if (!tab->cells[idx])
|
|
+ continue;
|
|
+
|
|
+ s = strlen(tab->cells[idx]) - 1;
|
|
+ if (s < 1 || tab->cells[idx][0] == '=')
|
|
+ continue;
|
|
+
|
|
+ if (s > sizes[i])
|
|
+ sizes[i] = s;
|
|
+ }
|
|
+ }
|
|
+
|
|
+
|
|
+ for (j = 0 ; j < tab->nrows ; j++) {
|
|
+ for (i = 0 ; i < tab->ncols ; i++) {
|
|
+
|
|
+ int idx = i + j*tab->ncols;
|
|
+ char *s = tab->cells[idx];
|
|
+
|
|
+ if (!s|| !strlen(s)) {
|
|
+ printf("%*s", sizes[i], "");
|
|
+ } else if (s && s[0] == '=') {
|
|
+ int k = sizes[i];
|
|
+ while(k--)
|
|
+ putchar('=');
|
|
+ } else {
|
|
+ printf("%*s",
|
|
+ s[0] == '<' ? -sizes[i] : sizes[i],
|
|
+ s+1);
|
|
+ }
|
|
+ if (i != (tab->ncols - 1))
|
|
+ putchar(' ');
|
|
+ }
|
|
+ putchar('\n');
|
|
+ }
|
|
+
|
|
+}
|
|
+
|
|
+/*
|
|
+ * Deallocate a tabular and all its content
|
|
+ */
|
|
+
|
|
+void table_free(struct string_table *tab)
|
|
+{
|
|
+
|
|
+ int i, count;
|
|
+
|
|
+ count = tab->ncols * tab->nrows;
|
|
+
|
|
+ for (i=0 ; i < count ; i++)
|
|
+ if (tab->cells[i])
|
|
+ free(tab->cells[i]);
|
|
+
|
|
+ free(tab);
|
|
+
|
|
+}
|
|
diff --git a/string_table.h b/string_table.h
|
|
new file mode 100644
|
|
index 000000000000..83c4425d5f76
|
|
--- /dev/null
|
|
+++ b/string_table.h
|
|
@@ -0,0 +1,36 @@
|
|
+/*
|
|
+ * This program is free software; you can redistribute it and/or
|
|
+ * modify it under the terms of the GNU General Public
|
|
+ * License v2 as published by the Free Software Foundation.
|
|
+ *
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
+ * General Public License for more details.
|
|
+ *
|
|
+ * You should have received a copy of the GNU General Public
|
|
+ * License along with this program; if not, write to the
|
|
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
+ * Boston, MA 021110-1307, USA.
|
|
+ */
|
|
+
|
|
+#ifndef STRING_TABLE_H
|
|
+#define STRING_TABLE_H
|
|
+
|
|
+struct string_table {
|
|
+
|
|
+ int ncols, nrows;
|
|
+ char *cells[];
|
|
+
|
|
+};
|
|
+
|
|
+
|
|
+struct string_table *table_create(int columns, int rows);
|
|
+char *table_printf(struct string_table *tab, int column, int row,
|
|
+ char *fmt, ...);
|
|
+char *table_vprintf(struct string_table *tab, int column, int row,
|
|
+ char *fmt, va_list ap);
|
|
+void table_dump(struct string_table *tab);
|
|
+void table_free(struct string_table *);
|
|
+
|
|
+#endif
|
|
--
|
|
1.9.0
|
|
|