* [PATCH 2/5] tunelp: remove old, now unneeded header
2012-03-18 3:36 [PATCH 1/5] checkxalloc: nudge regex, fix newfound instances Dave Reisner
@ 2012-03-18 3:36 ` Dave Reisner
2012-03-20 9:53 ` Karel Zak
2012-03-18 3:36 ` [PATCH 3/5] include/ttyutils.h: add include guards Dave Reisner
` (4 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Dave Reisner @ 2012-03-18 3:36 UTC (permalink / raw)
To: util-linux; +Cc: Dave Reisner
malloc and friends are provided by stdlib.h.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
sys-utils/tunelp.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/sys-utils/tunelp.c b/sys-utils/tunelp.c
index 700fe65..98b00f6 100644
--- a/sys-utils/tunelp.c
+++ b/sys-utils/tunelp.c
@@ -52,7 +52,6 @@
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
-#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
--
1.7.9.4
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 3/5] include/ttyutils.h: add include guards
2012-03-18 3:36 [PATCH 1/5] checkxalloc: nudge regex, fix newfound instances Dave Reisner
2012-03-18 3:36 ` [PATCH 2/5] tunelp: remove old, now unneeded header Dave Reisner
@ 2012-03-18 3:36 ` Dave Reisner
2012-03-20 9:53 ` Karel Zak
2012-03-18 3:36 ` [PATCH 4/5] findmnt: add FS size, avail, used, and use% columns Dave Reisner
` (3 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Dave Reisner @ 2012-03-18 3:36 UTC (permalink / raw)
To: util-linux; +Cc: Dave Reisner
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
include/ttyutils.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/ttyutils.h b/include/ttyutils.h
index 949b72a..f638aa0 100644
--- a/include/ttyutils.h
+++ b/include/ttyutils.h
@@ -1,3 +1,5 @@
+#ifndef UTIL_LINUX_TTYUTILS_H
+#define UTIL_LINUX_TTYUTILS_H
#include <termios.h>
@@ -71,3 +73,5 @@ static inline void reset_virtual_console(struct termios *tp, int flags)
tp->c_cc[VLNEXT] = CLNEXT;
tp->c_cc[VEOL2] = _POSIX_VDISABLE;
}
+
+#endif /* UTIL_LINUX_TTYUTILS_H */
--
1.7.9.4
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 4/5] findmnt: add FS size, avail, used, and use% columns
2012-03-18 3:36 [PATCH 1/5] checkxalloc: nudge regex, fix newfound instances Dave Reisner
2012-03-18 3:36 ` [PATCH 2/5] tunelp: remove old, now unneeded header Dave Reisner
2012-03-18 3:36 ` [PATCH 3/5] include/ttyutils.h: add include guards Dave Reisner
@ 2012-03-18 3:36 ` Dave Reisner
2012-03-20 9:54 ` Karel Zak
2012-03-18 3:36 ` [PATCH 5/5] findmnt: add -D, --df option to imitate df(1) Dave Reisner
` (2 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Dave Reisner @ 2012-03-18 3:36 UTC (permalink / raw)
To: util-linux; +Cc: Dave Reisner
Provide display of filesystem attributes from statvfs(3). These are all
displayed in human readable format.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
misc-utils/findmnt.8 | 4 ++++
misc-utils/findmnt.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/misc-utils/findmnt.8 b/misc-utils/findmnt.8
index b6d80f0..c1734ca 100644
--- a/misc-utils/findmnt.8
+++ b/misc-utils/findmnt.8
@@ -103,6 +103,10 @@ Define output columns. Currently supported are
.BR OLD-OPTIONS,
.BR VFS-OPTIONS ,
.BR FS-OPTIONS ,
+.BR SIZE ,
+.BR AVAIL ,
+.BR USED ,
+.BR USE% ,
.BR LABEL
and
.BR UUID .
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index 77897d3..547be66 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -30,6 +30,8 @@
#endif
#include <assert.h>
#include <poll.h>
+#include <sys/statvfs.h>
+#include <sys/types.h>
#include <libmount.h>
@@ -65,6 +67,10 @@ enum {
COL_ACTION,
COL_OLD_TARGET,
COL_OLD_OPTIONS,
+ COL_SIZE,
+ COL_AVAIL,
+ COL_USED,
+ COL_USEPERC,
FINDMNT_NCOLUMNS
};
@@ -98,6 +104,10 @@ static struct colinfo infos[FINDMNT_NCOLUMNS] = {
[COL_ACTION] = { "ACTION", 10, TT_FL_STRICTWIDTH, N_("action detected by --poll") },
[COL_OLD_OPTIONS] = { "OLD-OPTIONS", 0.10, TT_FL_TRUNC, N_("old mount options saved by --poll") },
[COL_OLD_TARGET] = { "OLD-TARGET", 0.30, 0, N_("old mountpoint saved by --poll") },
+ [COL_SIZE] = { "SIZE", 8, TT_FL_RIGHT, N_("filesystem size") },
+ [COL_AVAIL] = { "AVAIL", 8, TT_FL_RIGHT, N_("filesystem size available") },
+ [COL_USED] = { "USED", 8, TT_FL_RIGHT, N_("filesystem size used") },
+ [COL_USEPERC] = { "USE%", 8, TT_FL_RIGHT, N_("filesystem use percentage") },
};
/* global flags */
@@ -280,14 +290,49 @@ static const char *get_tag(struct libmnt_fs *fs, const char *tagname)
return res;
}
+static const char *get_vfs_attr(struct libmnt_fs *fs, int sizetype)
+{
+ struct statvfs buf;
+ uint64_t vfs_attr;
+ char *sizestr;
+
+ if (statvfs(mnt_fs_get_target(fs), &buf) != 0)
+ return NULL;
+
+ switch(sizetype) {
+ case COL_SIZE:
+ vfs_attr = buf.f_frsize * buf.f_blocks;
+ break;
+ case COL_AVAIL:
+ vfs_attr = buf.f_frsize * buf.f_bfree;
+ break;
+ case COL_USED:
+ vfs_attr = buf.f_frsize * (buf.f_blocks - buf.f_bfree);
+ break;
+ case COL_USEPERC:
+ if (buf.f_blocks == 0)
+ return "-";
+
+ if (asprintf(&sizestr, "%.0f%%",
+ (double)(buf.f_blocks - buf.f_bfree) /
+ buf.f_blocks * 100) == -1)
+ err(EXIT_FAILURE, "failed to allocate string");
+ return sizestr;
+ }
+
+ return vfs_attr == 0 ? "0" :
+ size_to_human_string(SIZE_SUFFIX_1LETTER, vfs_attr);
+}
+
/* reads FS data from libmount
* TODO: add function that will deallocate data allocated by get_data()
*/
static const char *get_data(struct libmnt_fs *fs, int num)
{
const char *str = NULL;
+ int col_id = get_column_id(num);
- switch(get_column_id(num)) {
+ switch (col_id) {
case COL_SOURCE:
{
const char *root = mnt_fs_get_root(fs);
@@ -346,7 +391,14 @@ static const char *get_data(struct libmnt_fs *fs, int num)
if (rc)
str = tmp;
}
+ break;
}
+ case COL_SIZE:
+ case COL_AVAIL:
+ case COL_USED:
+ case COL_USEPERC:
+ str = get_vfs_attr(fs, col_id);
+ break;
default:
break;
}
--
1.7.9.4
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 4/5] findmnt: add FS size, avail, used, and use% columns
2012-03-18 3:36 ` [PATCH 4/5] findmnt: add FS size, avail, used, and use% columns Dave Reisner
@ 2012-03-20 9:54 ` Karel Zak
0 siblings, 0 replies; 11+ messages in thread
From: Karel Zak @ 2012-03-20 9:54 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux, Dave Reisner
On Sat, Mar 17, 2012 at 11:36:32PM -0400, Dave Reisner wrote:
> misc-utils/findmnt.8 | 4 ++++
> misc-utils/findmnt.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++-
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 5/5] findmnt: add -D, --df option to imitate df(1)
2012-03-18 3:36 [PATCH 1/5] checkxalloc: nudge regex, fix newfound instances Dave Reisner
` (2 preceding siblings ...)
2012-03-18 3:36 ` [PATCH 4/5] findmnt: add FS size, avail, used, and use% columns Dave Reisner
@ 2012-03-18 3:36 ` Dave Reisner
2012-03-20 10:09 ` Karel Zak
2012-03-18 14:53 ` [PATCH 1/5] checkxalloc: nudge regex, fix newfound instances Davidlohr Bueso
2012-03-20 8:50 ` Karel Zak
5 siblings, 1 reply; 11+ messages in thread
From: Dave Reisner @ 2012-03-18 3:36 UTC (permalink / raw)
To: util-linux; +Cc: Dave Reisner
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
misc-utils/findmnt.8 | 3 +++
misc-utils/findmnt.c | 20 ++++++++++++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/misc-utils/findmnt.8 b/misc-utils/findmnt.8
index c1734ca..8ad4432 100644
--- a/misc-utils/findmnt.8
+++ b/misc-utils/findmnt.8
@@ -49,6 +49,9 @@ Search in
The output is in the tree-like format. This is the default.
.IP "\fB\-c, \-\-canonicalize\fP"
Canonicalize all printed paths.
+.IP "\fB\-D, \-\-df\fP"
+Imitate the output of df(1). This option is equivalent to
+"-o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGET".
.IP "\fB\-d, \-\-direction \fIword\fP"
The search direction -
.IR forward
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index 547be66..84092d2 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -890,6 +890,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fprintf(out, _(
" -a, --ascii use ASCII chars for tree formatting\n"
" -c, --canonicalize canonicalize printed paths\n"
+ " -D, --df imitate the output of df(1)\n"
" -d, --direction <word> direction of search, 'forward' or 'backward'\n"
" -e, --evaluate convert tags (LABEL/UUID) to device names\n"
" -F, --tab-file <path> alternative file for --fstab, --mtab or --kernel options\n"
@@ -936,7 +937,7 @@ int main(int argc, char *argv[])
struct libmnt_table *tb = NULL;
char **tabfiles = NULL;
int direction = MNT_ITER_FORWARD;
- int i, c, rc = -1, timeout = -1;
+ int i, c, rc = -1, timeout = -1, df_output = 0;
int ntabfiles = 0, tabtype = 0;
/* table.h */
@@ -946,6 +947,7 @@ int main(int argc, char *argv[])
{ "ascii", 0, 0, 'a' },
{ "canonicalize", 0, 0, 'c' },
{ "direction", 1, 0, 'd' },
+ { "df", 0, 0, 'D' },
{ "evaluate", 0, 0, 'e' },
{ "first-only", 0, 0, 'f' },
{ "fstab", 0, 0, 's' },
@@ -982,7 +984,7 @@ int main(int argc, char *argv[])
tt_flags |= TT_FL_TREE;
while ((c = getopt_long(argc, argv,
- "acd:ehifF:o:O:p::Pklmnrst:uvRS:T:w:",
+ "acDd:ehifF:o:O:p::Pklmnrst:uvRS:T:w:",
longopts, NULL)) != -1) {
switch(c) {
case 'a':
@@ -991,6 +993,10 @@ int main(int argc, char *argv[])
case 'c':
flags |= FL_CANONICALIZE;
break;
+ case 'D':
+ tt_flags &= ~TT_FL_TREE;
+ df_output = 1;
+ break;
case 'd':
if (!strcmp(optarg, "forward"))
direction = MNT_ITER_FORWARD;
@@ -1100,6 +1106,16 @@ int main(int argc, char *argv[])
}
}
+ if (df_output) {
+ columns[ncolumns++] = COL_SOURCE;
+ columns[ncolumns++] = COL_FSTYPE;
+ columns[ncolumns++] = COL_SIZE;
+ columns[ncolumns++] = COL_USED;
+ columns[ncolumns++] = COL_AVAIL;
+ columns[ncolumns++] = COL_USEPERC;
+ columns[ncolumns++] = COL_TARGET;
+ }
+
/* default columns */
if (!ncolumns) {
if (flags & FL_POLL)
--
1.7.9.4
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 5/5] findmnt: add -D, --df option to imitate df(1)
2012-03-18 3:36 ` [PATCH 5/5] findmnt: add -D, --df option to imitate df(1) Dave Reisner
@ 2012-03-20 10:09 ` Karel Zak
0 siblings, 0 replies; 11+ messages in thread
From: Karel Zak @ 2012-03-20 10:09 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux, Dave Reisner
On Sat, Mar 17, 2012 at 11:36:33PM -0400, Dave Reisner wrote:
> misc-utils/findmnt.8 | 3 +++
> misc-utils/findmnt.c | 20 ++++++++++++++++++--
> 2 files changed, 21 insertions(+), 2 deletions(-)
Applied, thanks.
I have added built-in filter to filter out pseudo filesystems for the
df output and new --all option to disable this filter.
Karel
PS. yes, we have to fix (=de-duplicate) our and df(1) output, this is
still on TODO list.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/5] checkxalloc: nudge regex, fix newfound instances
2012-03-18 3:36 [PATCH 1/5] checkxalloc: nudge regex, fix newfound instances Dave Reisner
` (3 preceding siblings ...)
2012-03-18 3:36 ` [PATCH 5/5] findmnt: add -D, --df option to imitate df(1) Dave Reisner
@ 2012-03-18 14:53 ` Davidlohr Bueso
2012-03-20 8:50 ` Karel Zak
5 siblings, 0 replies; 11+ messages in thread
From: Davidlohr Bueso @ 2012-03-18 14:53 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux, Dave Reisner
On Sat, 2012-03-17 at 23:36 -0400, Dave Reisner wrote:
> Using the -w flag with grep actually fought against us here, and hid
> some instances where xalloc functions weren't used. Discard it in favor
> of an explicit word boundary as a prefix to the function name, and
> extend our requirements on the trailing side of the pattern.
>
> This also fixes the few new instances that were overlooked because of
> the regex's deficiency.
>
> Signed-off-by: Dave Reisner <dreisner@archlinux.org>
> ---
> fdisk/sfdisk.c | 2 +-
> sys-utils/swapon.c | 4 ++--
> tools/checkxalloc.sh | 2 +-
> 3 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c
> index 6267652..e766b04 100644
> --- a/fdisk/sfdisk.c
> +++ b/fdisk/sfdisk.c
> @@ -304,7 +304,7 @@ restore_sectors(char *dev) {
> error(_("partition restore file has wrong size - not restoring\n"));
> goto err;
> }
> - if (!(ss0 = (char *)malloc(statbuf.st_size))) {
> + if (!(ss0 = xmalloc(statbuf.st_size))) {
> error(_("out of memory?\n"));
> goto err;
> }
xmalloc and friends abort the program when allocation fail.
> diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c
> index f17fad6..fe16169 100644
> --- a/sys-utils/swapon.c
> +++ b/sys-utils/swapon.c
> @@ -197,7 +197,7 @@ read_proc_swaps(void) {
> *p = '\0';
> }
>
> - q = realloc(swapFiles, (numSwaps+1) * sizeof(*swapFiles));
> + q = xrealloc(swapFiles, (numSwaps+1) * sizeof(*swapFiles));
> if (q == NULL)
> break;
same here. This would actually break functionality.
> swapFiles = q;
> @@ -640,7 +640,7 @@ swapon_all(void) {
> if (!streq(fstab->mnt_type, MNTTYPE_SWAP))
> continue;
>
> - opts = strdup(fstab->mnt_opts);
> + opts = xstrdup(fstab->mnt_opts);
>
> for (opt = strtok(opts, ","); opt != NULL;
> opt = strtok(NULL, ",")) {
> diff --git a/tools/checkxalloc.sh b/tools/checkxalloc.sh
> index 578340e..6634c82 100755
> --- a/tools/checkxalloc.sh
> +++ b/tools/checkxalloc.sh
> @@ -10,7 +10,7 @@ cd "$(git rev-parse --show-toplevel)" || {
> }
>
> git grep -zl '#include "xalloc.h"' |
> - xargs -0 grep -nwE '[^x](([cm]|re)alloc|strdup)\('
> + xargs -0 grep -nE '\b(([cm]|re)alloc|strdup)[[:space:]]*\([^)]'
>
> result=$?
>
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 1/5] checkxalloc: nudge regex, fix newfound instances
2012-03-18 3:36 [PATCH 1/5] checkxalloc: nudge regex, fix newfound instances Dave Reisner
` (4 preceding siblings ...)
2012-03-18 14:53 ` [PATCH 1/5] checkxalloc: nudge regex, fix newfound instances Davidlohr Bueso
@ 2012-03-20 8:50 ` Karel Zak
5 siblings, 0 replies; 11+ messages in thread
From: Karel Zak @ 2012-03-20 8:50 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux, Dave Reisner
On Sat, Mar 17, 2012 at 11:36:29PM -0400, Dave Reisner wrote:
> fdisk/sfdisk.c | 2 +-
> sys-utils/swapon.c | 4 ++--
> tools/checkxalloc.sh | 2 +-
> 3 files changed, 4 insertions(+), 4 deletions(-)
Applied with some minor changes, thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 11+ messages in thread