summaryrefslogtreecommitdiff
path: root/misc-utils
diff options
context:
space:
mode:
Diffstat (limited to 'misc-utils')
-rw-r--r--misc-utils/.gitignore1
-rw-r--r--misc-utils/Makefile.am15
-rw-r--r--misc-utils/blkid.84
-rw-r--r--misc-utils/blkid.c5
-rw-r--r--misc-utils/cal.16
-rw-r--r--misc-utils/findmnt.8150
-rw-r--r--misc-utils/findmnt.c740
-rw-r--r--misc-utils/look.c3
-rw-r--r--misc-utils/namei.128
-rw-r--r--misc-utils/namei.c3
-rw-r--r--misc-utils/script.c6
-rw-r--r--misc-utils/uuidd.88
-rw-r--r--misc-utils/uuidd.c12
-rw-r--r--misc-utils/uuidgen.14
-rw-r--r--misc-utils/wipefs.c31
15 files changed, 964 insertions, 52 deletions
diff --git a/misc-utils/.gitignore b/misc-utils/.gitignore
index 5d34a50d..a39caaf3 100644
--- a/misc-utils/.gitignore
+++ b/misc-utils/.gitignore
@@ -17,3 +17,4 @@ uuidd
findfs
blkid
wipefs
+findmnt
diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am
index ca272560..6a16f999 100644
--- a/misc-utils/Makefile.am
+++ b/misc-utils/Makefile.am
@@ -10,7 +10,7 @@ usrbin_exec_PROGRAMS = cal ddate logger look mcookie \
namei script whereis scriptreplay
EXTRA_DIST += README.cal README.ddate README.namei README.namei2
-mcookie_SOURCES = mcookie.c ../lib/md5.c
+mcookie_SOURCES = mcookie.c $(top_srcdir)/lib/md5.c
script_LDADD =
usrbin_exec_SCRIPTS = chkdupexe
@@ -36,12 +36,13 @@ endif
if BUILD_LIBBLKID
sbin_PROGRAMS += blkid findfs wipefs
dist_man_MANS += blkid.8 findfs.8 wipefs.8
-blkid_SOURCES = blkid.c $(top_srcdir)/lib/ismounted.c ../lib/strtosize.c
+blkid_SOURCES = blkid.c $(top_srcdir)/lib/ismounted.c \
+ $(top_srcdir)/lib/strtosize.c
blkid_LDADD = $(ul_libblkid_la)
blkid_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
findfs_LDADD = $(ul_libblkid_la)
findfs_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
-wipefs_SOURCES = wipefs.c ../lib/strtosize.c
+wipefs_SOURCES = wipefs.c $(top_srcdir)/lib/strtosize.c
wipefs_LDADD = $(ul_libblkid_la)
wipefs_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
if HAVE_STATIC_BLKID
@@ -53,6 +54,14 @@ blkid_static_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
endif
endif
+if BUILD_LIBMOUNT
+bin_PROGRAMS += findmnt
+dist_man_MANS += findmnt.8
+findmnt_LDADD = $(ul_libmount_la)
+findmnt_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir)
+findmnt_SOURCES = findmnt.c $(top_srcdir)/lib/tt.c
+endif
+
cal_SOURCES = cal.c $(top_srcdir)/lib/mbsalign.c
if HAVE_TINFO
cal_LDADD = -ltinfo @NCURSES_LIBS@
diff --git a/misc-utils/blkid.8 b/misc-utils/blkid.8
index d42074f0..8968bb29 100644
--- a/misc-utils/blkid.8
+++ b/misc-utils/blkid.8
@@ -33,8 +33,6 @@ blkid \- command\-line utility to locate/print block device attributes
.B blkid
.RB -p
-.RB [ \-s
-.IR tag ]
.RB [ \-O
.IR offset ]
.RB [ \-S
@@ -54,8 +52,6 @@ blkid \- command\-line utility to locate/print block device attributes
.B blkid
.RB -i
-.RB [ \-s
-.IR tag ]
.RB [ \-o
.IR format ]
.RB [ \-s
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index 48af7674..f94df06a 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -268,11 +268,8 @@ static void print_udev_format(const char *name, const char *value, size_t sz)
} else if (!strcmp(name, "PART_ENTRY_NAME") ||
!strcmp(name, "PART_ENTRY_TYPE")) {
- blkid_safe_string(value, safe, sizeof(safe));
- printf("ID_%s=%s\n", name, safe);
-
blkid_encode_string(value, enc, sizeof(enc));
- printf("ID_%s_ENC=%s\n", name, enc);
+ printf("ID_%s=%s\n", name, enc);
} else if (!strncmp(name, "PART_ENTRY_", 11))
printf("ID_%s=%s\n", name, value);
diff --git a/misc-utils/cal.1 b/misc-utils/cal.1
index f11f605a..6edb7052 100644
--- a/misc-utils/cal.1
+++ b/misc-utils/cal.1
@@ -92,12 +92,6 @@ calendar for that month is a bit unusual.
A
.Nm
command appeared in Version 6 AT&T UNIX.
-.Sh OTHER VERSIONS
-Several much more elaborate versions of this program exist,
-with support for colors, holidays, birthdays, reminders and
-appointments, etc. For example, try the cal from
-http://home.sprynet.com/~cbagwell/projects.html
-or GNU gcal.
.Sh AVAILABILITY
The cal command is part of the util-linux-ng package and is available from
ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
diff --git a/misc-utils/findmnt.8 b/misc-utils/findmnt.8
new file mode 100644
index 00000000..e1cb8ff2
--- /dev/null
+++ b/misc-utils/findmnt.8
@@ -0,0 +1,150 @@
+.\" -*- nroff -*-
+.TH FINDMNT 8 "Apr 2010" "Version 1.0"
+.SH NAME
+findmnt \- find a filesystem
+.SH SYNOPSIS
+.B findmnt
+.RB [ options ]
+.sp
+.B findmnt
+.RB [ options ]
+.IR device | mountpoint
+.sp
+.B findmnt
+.RB [ options ]
+.RB [ \--source ]
+.IR device
+.RB [ \--target ]
+.IR mountpoint
+.SH DESCRIPTION
+.B findmnt
+will list all mounted filesytems or search for a filesystem. The
+.B findmnt
+command is able to search in
+.IR /etc/fstab ,
+.IR /etc/mtab
+or
+.IR /proc/self/mountinfo .
+If
+.IR device
+or
+.IR mountpoint
+is not given, all filesystems are shown.
+.PP
+The command prints all mounted filesystems in the tree-like format by default.
+.SH OPTIONS
+.IP "\fB\-h, \-\-help\fP"
+Print help and exit.
+.IP "\fB\-s, \-\-fstab\fP"
+Search in
+.IR /etc/fstab .
+The output is in the list format (see --list).
+.IP "\fB\-m, \-\-mtab\fP"
+Search in
+.IR /etc/mtab .
+The output is in the list format (see --list).
+.IP "\fB\-k, \-\-kernel\fP"
+Search in
+.IR /proc/self/mountinfo .
+The output is in the tree-like format. This is the default.
+.IP "\fB\-c, \-\-canonicalize\fP"
+Canonicalize all printed paths.
+.IP "\fB\-d, \-\-direction \fIword\fP"
+The search direction -
+.IR forward
+or
+.IR backward .
+.IP "\fB\-e, \-\-evaluate\fP"
+Convert all tags (LABEL or UUID) to the device names.
+.IP "\fB\-f, \-\-first-only\fP"
+Print the first matching filesystem only.
+.IP "\fB\-i, \-\-invert\fP"
+Invert the sense of matching.
+.IP "\fB\-l, \-\-list\fP"
+Use the list output format.
+.IP "\fB\-n, \-\-noheadings\fP"
+Do not print a header line.
+.IP "\fB\-u, \-\-notruncate\fP"
+Do not truncate text in columns. The default is to not truncate the
+.BR TARGET ,
+.BR SOURCE ,
+.BR UUID
+and
+.BR LABEL
+columns. This option disables text truncation also in all other columns.
+.IP "\fB\-O, \-\-options \fIlist\fP"
+Used to limit the set of printed filesystems. More than one option
+may be specified in a comma-separated list. The
+.B \-t
+and
+.B \-O
+options are cumulative in effect. It is different from
+.B \-t
+in that each option is matched exactly; a leading
+.I no
+at the beginning
+of one option does not negate the rest. For more details see
+.BR mount (8).
+.IP "\fB\-o, \-\-output \fIlist\fP"
+Define output columns. Currently supported are
+.BR SOURCE ,
+.BR TARGET ,
+.BR FSTYPE ,
+.BR OPTIONS ,
+.BR VFS-OPTIONS ,
+.BR FS-OPTIONS ,
+.BR LABEL
+and
+.BR UUID .
+The
+.BR TARGET
+column contains tree formatting if the
+.B \-\-list
+or
+.B \-\-raw
+options are not specified.
+.IP "\fB\-r, \-\-raw\fP"
+Use raw output format.
+.IP "\fB\-a, \-\-ascii\fP"
+Use ascii characters for tree formatting.
+.IP "\fB\-t, \-\-types \fIlist\fP"
+Used to limit the set of printed filesystems. More than one type may be
+specified in a comma-separated list. The list of filesystem types can be
+prefixed with
+.I no
+to specify the filesystem types on which no action should be taken. For
+more details see
+.BR mount (8).
+.IP "\fB\-S, \-\-source \fIspec\fP"
+Explicitly define the mount source. Supported are device, LABEL= or UUID=.
+.IP "\fB\-T, \-\-target \fIdir\fP"
+Explicitly define the mount target (mountpoint directory).
+.SH EXAMPLES
+.IP "\fBfindmnt \-\-fstab \-t nfs\fP"
+Prints all nfs filesystems defined in
+.IR /etc/fstab .
+.IP "\fBfindmnt \-\-fstab /mnt/foo\fP"
+Prints all
+.IR /etc/fstab
+filesystems where the mountpoint directory is /mnt/foo. It also prints bind mounts where /mnt/foo
+is a source.
+.IP "\fBfindmnt \-\-fstab --target /mnt/foo\fP"
+Prints all
+.IR /etc/fstab
+filesystems where the mountpoint directory is /mnt/foo.
+.IP "\fBfindmnt --fstab --evaluate\fP"
+Prints all
+.IR /etc/fstab
+filesystems and converts LABEL= and UUID= tags to the real device names.
+.IP "\fBfindmnt -n --raw --evaluate --output=target LABEL=/boot
+Prints only the mountpoint where the filesystem with label "/boot" is mounted.
+.SH AUTHORS
+.nf
+Karel Zak <kzak@redhat.com>
+.fi
+.SH SEE ALSO
+.BR mount (8),
+.BR fstab (5)
+.SH AVAILABILITY
+The findmnt command is part of the util-linux-ng package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
new file mode 100644
index 00000000..4138480f
--- /dev/null
+++ b/misc-utils/findmnt.c
@@ -0,0 +1,740 @@
+/*
+ * findmnt(8)
+ *
+ * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ * Written by Karel Zak <kzak@redhat.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would 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 02111-1307 USA
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <err.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <string.h>
+#include <termios.h>
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+#include <assert.h>
+
+#define USE_UNSTABLE_LIBMOUNT_API
+#include <mount.h>
+
+#include "pathnames.h"
+#include "nls.h"
+#include "c.h"
+#include "tt.h"
+
+/* flags */
+enum {
+ FL_EVALUATE = (1 << 1),
+ FL_CANONICALIZE = (1 << 2),
+ FL_FIRSTONLY = (1 << 3),
+ FL_INVERT = (1 << 4),
+ FL_NOSWAPMATCH = (1 << 6),
+};
+
+/* column IDs */
+enum {
+ COL_SOURCE,
+ COL_TARGET,
+ COL_FSTYPE,
+ COL_OPTIONS,
+ COL_VFS_OPTIONS,
+ COL_FS_OPTIONS,
+ COL_LABEL,
+ COL_UUID,
+
+ __NCOLUMNS
+};
+
+/* column names */
+struct colinfo {
+ const char *name; /* header */
+ double whint; /* width hint (N < 1 is in percent of termwidth) */
+ int truncate; /* boolean */
+ const char *match; /* pattern for match_func() */
+};
+
+/* columns descriptions */
+struct colinfo infos[__NCOLUMNS] = {
+ [COL_SOURCE] = { "SOURCE", 0.25, FALSE },
+ [COL_TARGET] = { "TARGET", 0.30, FALSE },
+ [COL_FSTYPE] = { "FSTYPE", 0.10, TRUE },
+ [COL_OPTIONS] = { "OPTIONS", 0.10, TRUE },
+ [COL_VFS_OPTIONS] = { "VFS-OPTIONS", 0.20, TRUE },
+ [COL_FS_OPTIONS] = { "FS-OPTIONS", 0.10, TRUE },
+ [COL_LABEL] = { "LABEL", 0.10, FALSE },
+ [COL_UUID] = { "UUID", 36, FALSE },
+};
+
+/* global flags */
+int flags;
+
+/* array with IDs of enabled columns */
+int columns[__NCOLUMNS];
+int ncolumns;
+
+/* libmount cache */
+mnt_cache *cache;
+
+static int get_column_id(int num)
+{
+ assert(num < ncolumns);
+ assert(columns[num] < __NCOLUMNS);
+ return columns[num];
+}
+
+static struct colinfo *get_column_info(int num)
+{
+ return &infos[ get_column_id(num) ];
+}
+
+static const char *column_id_to_name(int id)
+{
+ assert(id < __NCOLUMNS);
+ return infos[id].name;
+}
+
+static const char *get_column_name(int num)
+{
+ return get_column_info(num)->name;
+}
+
+static float get_column_whint(int num)
+{
+ return get_column_info(num)->whint;
+}
+
+static int get_column_truncate(int num)
+{
+ return get_column_info(num)->truncate;
+}
+
+static const char *get_match(int id)
+{
+ assert(id < __NCOLUMNS);
+ return infos[id].match;
+}
+
+static void set_match(int id, const char *match)
+{
+ assert(id < __NCOLUMNS);
+ infos[id].match = match;
+}
+
+/*
+ * "findmnt" without any filter
+ */
+static int is_listall_mode(void)
+{
+ return (!get_match(COL_SOURCE) &&
+ !get_match(COL_TARGET) &&
+ !get_match(COL_FSTYPE) &&
+ !get_match(COL_OPTIONS));
+}
+
+/*
+ * findmnt --first-only <devname|TAG=|mountpoint>
+ *
+ * ... it works like "mount <devname|TAG=|mountpoint>"
+ */
+static int is_mount_compatible_mode(void)
+{
+ if (!get_match(COL_SOURCE))
+ return 0; /* <devname|TAG=|mountpoint> is required */
+ if (get_match(COL_FSTYPE) || get_match(COL_OPTIONS))
+ return 0; /* cannot be restricted by -t or -O */
+ if (!(flags & FL_FIRSTONLY))
+ return 0; /* we have to return the first entry only */
+
+ return 1; /* ok */
+}
+
+static void set_all_columns_truncate(int set)
+{
+ int i;
+
+ for (i = 0; i < __NCOLUMNS; i++)
+ infos[i].truncate = set;
+}
+
+/*
+ * converts @name to column ID
+ */
+static int column_name_to_id(const char *name, size_t namesz)
+{
+ int i;
+
+ for (i = 0; i < __NCOLUMNS; i++) {
+ const char *cn = column_id_to_name(i);
+
+ if (!strncasecmp(name, cn, namesz) && !*(cn + namesz))
+ return i;
+ }
+ warnx(_("unknown column: %s"), name);
+ return -1;
+}
+
+/*
+ * parses list of columns from @str and add IDs to columns[]
+ */
+static int set_columns(const char *str)
+{
+ const char *begin = NULL, *p;
+
+ ncolumns = 0;
+
+ if (!str || !*str)
+ return -1;
+
+ ncolumns = 0;
+
+ for (p = str; p && *p; p++) {
+ const char *end = NULL;
+ int id;
+
+ if (!begin)
+ begin = p; /* begin of the column name */
+ if (*p == ',')
+ end = p; /* terminate the name */
+ if (*(p + 1) == '\0')
+ end = p + 1; /* end of string */
+ if (!begin || !end)
+ continue;
+ if (end <= begin)
+ return -1;
+
+ id = column_name_to_id(begin, end - begin);
+ if (id == -1)
+ return -1;
+ columns[ ncolumns++ ] = id;
+ begin = NULL;
+ if (end && !*end)
+ break;
+ }
+ return 0;
+}
+
+/* Returns LABEL or UUID */
+static const char *get_tag(mnt_fs *fs, const char *tagname)
+{
+ const char *t, *v, *res;
+
+ if (!mnt_fs_get_tag(fs, &t, &v) && !strcmp(t, tagname))
+ res = v;
+ else {
+ res = mnt_fs_get_source(fs);
+ if (res)
+ res = mnt_resolve_spec(res, cache);
+ if (res)
+ res = mnt_cache_find_tag_value(cache, res, tagname);
+ }
+
+ return res;
+}
+
+/* reads FS data from libmount */
+static const char *get_data(mnt_fs *fs, int num)
+{
+ const char *str = NULL;
+
+ switch(get_column_id(num)) {
+ case COL_SOURCE:
+ /* dir or dev */
+ str = mnt_fs_get_srcpath(fs);
+
+ if (str && (flags & FL_CANONICALIZE))
+ str = mnt_resolve_path(str, cache);
+ if (!str) {
+ str = mnt_fs_get_source(fs);
+
+ if (str && (flags & FL_EVALUATE))
+ str = mnt_resolve_spec(str, cache);
+ }
+ break;
+ case COL_TARGET:
+ str = mnt_fs_get_target(fs);
+ break;
+ case COL_FSTYPE:
+ str = mnt_fs_get_fstype(fs);
+ break;
+ case COL_OPTIONS:
+ str = mnt_fs_get_optstr(fs);
+ break;
+ case COL_VFS_OPTIONS:
+ str = mnt_fs_get_vfs_optstr(fs);
+ break;
+ case COL_FS_OPTIONS:
+ str = mnt_fs_get_fs_optstr(fs);
+ break;
+ case COL_UUID:
+ str = get_tag(fs, "UUID");
+ break;
+ case COL_LABEL:
+ str = get_tag(fs, "LABEL");
+ break;
+ default:
+ break;
+ }
+ return str;
+}
+
+/* adds one line to the output @tab */
+static struct tt_line *add_line(struct tt *tt, mnt_fs *fs,
+ struct tt_line *parent)
+{
+ int i;
+ struct tt_line *line = tt_add_line(tt, parent);
+
+ if (!line) {
+ warn(_("failed to add line to output"));
+ return NULL;
+ }
+ for (i = 0; i < ncolumns; i++)
+ tt_line_set_data(line, i, get_data(fs, i));
+
+ return line;
+}
+
+/* reads filesystems from @tb (libmount) and fillin @tab (output table) */
+static int create_treenode(struct tt *tt, mnt_tab *tb,
+ mnt_fs *fs, struct tt_line *parent_line)
+{
+ mnt_fs *chld = NULL;
+ mnt_iter *itr = NULL;
+ struct tt_line *line;
+ int rc = -1;
+
+ if (!fs) {
+ /* first call, get root FS */
+ if (mnt_tab_get_root_fs(tb, &fs))
+ goto leave;
+ parent_line = NULL;
+ }
+
+ itr = mnt_new_iter(MNT_ITER_FORWARD);
+ if (!itr)
+ goto leave;
+
+ line = add_line(tt, fs, parent_line);
+ if (!line)
+ goto leave;
+
+ /*
+ * add all children to the output table
+ */
+ while(mnt_tab_next_child_fs(tb, itr, fs, &chld) == 0) {
+ if (create_treenode(tt, tb, chld, line))
+ goto leave;
+ }
+ rc = 0;
+leave:
+ mnt_free_iter(itr);
+ return rc;
+}
+
+/* calls libmount fstab/mtab/mountinfo parser */
+static mnt_tab *parse_tabfile(const char *path)
+{
+ mnt_tab *tb = mnt_new_tab(path);
+ if (!tb) {
+ warn(_("failed to initialize libmount tab"));
+ return NULL;
+ }
+ if (mnt_tab_parse_file(tb) != 0) {
+ mnt_free_tab(tb);
+ warn(_("can't read: %s"), path);
+ return NULL;
+ }
+ if (mnt_tab_get_nerrs(tb)) {
+ char buf[BUFSIZ];
+ mnt_tab_strerror(tb, buf, sizeof(buf));
+ warnx(_("%s: parse error: %s"), path, buf);
+ }
+
+ return tb;
+}
+
+/* filter function for libmount (mnt_tab_find_next_fs()) */
+static int match_func(mnt_fs *fs, void *data)
+{
+ int rc = flags & FL_INVERT ? 1 : 0;
+ const char *m;
+
+ m = get_match(COL_TARGET);
+ if (m && !mnt_fs_match_target(fs, m, cache))
+ return rc;
+
+ m = get_match(COL_SOURCE);
+ if (m && !mnt_fs_match_source(fs, m, cache))
+ return rc;
+
+ m = get_match(COL_FSTYPE);
+ if (m && !mnt_fs_match_fstype(fs, m))
+ return rc;
+
+ m = get_match(COL_OPTIONS);
+ if (m && !mnt_fs_match_options(fs, m))
+ return rc;
+
+ return !rc;
+}
+
+/* iterate over filesystems in @tb */
+static mnt_fs *get_next_fs(mnt_tab *tb, mnt_iter *itr)
+{
+ mnt_fs *fs = NULL;
+
+ if (is_listall_mode()) {
+ /*
+ * Print whole file
+ */
+ mnt_tab_next_fs(tb, itr, &fs);
+
+ } else if (is_mount_compatible_mode()) {
+ /*
+ * Look up for FS in the same way how mount(8) searchs in fstab
+ *
+ * findmnt -f <spec>
+ */
+ fs = mnt_tab_find_source(tb, get_match(COL_SOURCE),
+ mnt_iter_get_direction(itr));
+ if (!fs)
+ fs = mnt_tab_find_target(tb, get_match(COL_SOURCE),
+ mnt_iter_get_direction(itr));
+ } else {
+ /*
+ * Look up for all matching entries
+ *
+ * findmnt [-l] <source> <target> [-O <options>] [-t <types>]
+ * findmnt [-l] <spec> [-O <options>] [-t <types>]
+ */
+again:
+ mnt_tab_find_next_fs(tb, itr, match_func, NULL, &fs);
+
+ if (!fs &&
+ !(flags & FL_NOSWAPMATCH) &&
+ !get_match(COL_TARGET) && get_match(COL_SOURCE)) {
+
+ /* swap 'spec' and target. */
+ set_match(COL_TARGET, get_match(COL_SOURCE));
+ set_match(COL_SOURCE, NULL);
+ mnt_reset_iter(itr, -1);
+
+ goto again;
+ }
+ }
+
+ return fs;
+}
+
+static int __attribute__((__noreturn__)) usage(FILE *out)
+{
+ fprintf(out, _(
+ "\nUsage:\n"
+ " %1$s [options]\n"
+ " %1$s [options] <device> | <mountpoint>\n"
+ " %1$s [options] <device> <mountpoint>\n"
+ " %1$s [options] [--source <device>] [--target <mountpoint>]\n"),
+ program_invocation_short_name);
+
+ fprintf(out, _(
+ "\nOptions:\n"
+ " -s, --fstab search in static table of filesystems\n"
+ " -m, --mtab search in table of mounted filesystems\n"
+ " -k, --kernel search in kernel table of mounted \n"
+ " filesystems (default)\n\n"
+
+ " -c, --canonicalize canonicalize printed paths\n"
+ " -d, --direction <word> search direction - 'forward' or 'backward'\n"
+ " -e, --evaluate print all TAGs (LABEL/UUID) evaluated\n"
+ " -f, --first-only print the first found filesystem only\n"
+ " -h, --help print this help\n"
+ " -i, --invert invert sense of matching\n"
+ " -l, --list use list format ouput\n"
+ " -n, --noheadings don't print headings\n"
+ " -u, --notruncate don't truncate text in columns\n"
+ " -O, --options <list> limit the set of filesystems by mount options\n"
+ " -o, --output <list> output columns\n"
+ " -r, --raw use raw format output\n"
+ " -a, --ascii use ascii chars for tree formatting\n"
+ " -t, --types <list> limit the set of filesystem by FS types\n"
+ " -S, --source <string> device, LABEL= or UUID=device\n"
+ " -T, --target <string> mountpoint\n\n"));
+
+ fprintf(out, _("\nFor more information see findmnt(1).\n"));
+
+ exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+static int __attribute__((__noreturn__))
+errx_mutually_exclusive(const char *opts)
+{
+ errx(EXIT_FAILURE, "%s %s", opts, _("options are mutually exclusive"));
+}
+
+int main(int argc, char *argv[])
+{
+ /* libmount */
+ mnt_tab *tb = NULL;
+ mnt_iter *itr = NULL;
+ mnt_fs *fs = NULL;
+ char *tabfile = NULL;
+ int direction = MNT_ITER_FORWARD;
+
+ /* table.h */
+ struct tt *tt = NULL;
+ int tt_flags = 0;
+
+ int i, c, rc = EXIT_FAILURE;
+
+ struct option longopts[] = {
+ { "ascii", 0, 0, 'a' },
+ { "canonicalize", 0, 0, 'c' },
+ { "direction", 1, 0, 'd' },
+ { "evaluate", 0, 0, 'e' },
+ { "first-only", 0, 0, 'f' },
+ { "fstab", 0, 0, 's' },
+ { "help", 0, 0, 'h' },
+ { "invert", 0, 0, 'i' },
+ { "kernel", 0, 0, 'k' },
+ { "list", 0, 0, 'l' },
+ { "mtab", 0, 0, 'm' },
+ { "noheadings", 0, 0, 'n' },
+ { "notruncate", 0, 0, 'u' },
+ { "options", 1, 0, 'O' },
+ { "output", 1, 0, 'o' },
+ { "raw", 0, 0, 'r' },
+ { "types", 1, 0, 't' },
+ { "source", 1, 0, 'S' },
+ { "target", 1, 0, 'T' },
+
+ { NULL, 0, 0, 0 }
+ };
+
+ assert(ARRAY_SIZE(columns) == __NCOLUMNS);
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+
+ /* default enabled columns */
+ columns[ncolumns++] = COL_TARGET;
+ columns[ncolumns++] = COL_SOURCE;
+ columns[ncolumns++] = COL_FSTYPE;
+ columns[ncolumns++] = COL_OPTIONS;
+
+ /* default output format */
+ tt_flags |= TT_FL_TREE;
+
+ while ((c = getopt_long(argc, argv,
+ "cd:ehifo:O:klmnrst:uS:T:", longopts, NULL)) != -1) {
+ switch(c) {
+ case 'a':
+ tt_flags |= TT_FL_ASCII;
+ break;
+ case 'c':
+ flags |= FL_CANONICALIZE;
+ break;
+ case 'd':
+ if (!strcmp(optarg, "forward"))
+ direction = MNT_ITER_FORWARD;
+ else if (!strcmp(optarg, "backward"))
+ direction = MNT_ITER_BACKWARD;
+ else
+ errx(EXIT_FAILURE,
+ _("unknown direction '%s'"), optarg);
+ break;
+ case 'e':
+ flags |= FL_EVALUATE;
+ break;
+ case 'h':
+ usage(stdout);
+ break;
+ case 'i':
+ flags |= FL_INVERT;
+ break;
+ case 'f':
+ flags |= FL_FIRSTONLY;
+ break;
+ case 'u':
+ set_all_columns_truncate(FALSE);
+ break;
+ case 'o':
+ if (set_columns(optarg))
+ exit(EXIT_FAILURE);
+ break;
+ case 'O':
+ set_match(COL_OPTIONS, optarg);
+ break;
+ case 'm': /* mtab */
+ if (tabfile)
+ errx_mutually_exclusive("--{fstab,mtab,kernel}");
+ tabfile = _PATH_MOUNTED;
+ tt_flags &= ~TT_FL_TREE;
+ break;
+ case 's': /* fstab */
+ if (tabfile)
+ errx_mutually_exclusive("--{fstab,mtab,kernel}");
+ tabfile = _PATH_MNTTAB;
+ tt_flags &= ~TT_FL_TREE;
+ break;
+ case 'k': /* kernel (mountinfo) */
+ if (tabfile)
+ errx_mutually_exclusive("--{fstab,mtab,kernel}");
+ tabfile = _PATH_PROC_MOUNTINFO;
+ break;
+ case 't':
+ set_match(COL_FSTYPE, optarg);
+ break;
+ case 'r':
+ tt_flags &= ~TT_FL_TREE; /* disable the default */
+ tt_flags |= TT_FL_RAW; /* enable raw */
+ break;
+ case 'l':
+ if (tt_flags & TT_FL_RAW)
+ errx_mutually_exclusive("--{raw,list}");
+
+ tt_flags &= ~TT_FL_TREE; /* disable the default */
+ break;
+ case 'n':
+ tt_flags |= TT_FL_NOHEADINGS;
+ break;
+ case 'S':
+ set_match(COL_SOURCE, optarg);
+ flags |= FL_NOSWAPMATCH;
+ break;
+ case 'T':
+ set_match(COL_TARGET, optarg);
+ flags |= FL_NOSWAPMATCH;
+ break;
+ default:
+ usage(stderr);
+ break;
+ }
+ }
+
+ if (!tabfile) {
+ tabfile = _PATH_PROC_MOUNTINFO;
+
+ if (access(tabfile, R_OK)) { /* old kernel? */
+ tabfile = _PATH_PROC_MOUNTS;
+ tt_flags &= ~TT_FL_TREE;
+ }
+ }
+ if (optind < argc && (get_match(COL_SOURCE) || get_match(COL_TARGET)))
+ errx(EXIT_FAILURE, _(
+ "options --target and --source can't be used together "
+ "with command line element that is not an option"));
+
+ if (optind < argc)
+ set_match(COL_SOURCE, argv[optind++]); /* dev/tag/mountpoint */
+ if (optind < argc)
+ set_match(COL_TARGET, argv[optind++]); /* mountpoint */
+
+ if (!is_listall_mode() || (flags & FL_FIRSTONLY))
+ tt_flags &= ~TT_FL_TREE;
+
+ if (!(flags & FL_NOSWAPMATCH) &&
+ !get_match(COL_TARGET) && get_match(COL_SOURCE)) {
+ /*
+ * Check if we can swap source and target, it's
+ * not possible if the source is LABEL=/UUID=
+ */
+ const char *x = get_match(COL_SOURCE);
+
+ if (!strncmp(x, "LABEL=", 6) || !strncmp(x, "UUID=", 5))
+ flags |= FL_NOSWAPMATCH;
+ }
+
+ /*
+ * initialize libmount
+ */
+ mnt_init_debug(0);
+
+ tb = parse_tabfile(tabfile);
+ if (!tb)
+ goto leave;
+
+ itr = mnt_new_iter(direction);
+ if (!itr) {
+ warn(_("failed to initialize libmount iterator"));
+ goto leave;
+ }
+
+ cache = mnt_new_cache();
+ if (!cache) {
+ warn(_("failed to initialize libmount cache"));
+ goto leave;
+ }
+ mnt_tab_set_cache(tb, cache);
+
+ /*
+ * initialize output formatting (tt.h)
+ */
+ tt = tt_new_table(tt_flags);
+ if (!tt) {
+ warn(_("failed to initialize output table"));
+ goto leave;
+ }
+
+ for (i = 0; i < ncolumns; i++) {
+ int fl = get_column_truncate(i) ? TT_FL_TRUNCATE : 0;
+
+ if (get_column_id(i) == COL_TARGET && (tt_flags & TT_FL_TREE))
+ fl |= TT_FL_TREE;
+
+ if (!tt_define_column(tt, get_column_name(i),
+ get_column_whint(i), fl)) {
+ warn(_("failed to initialize output column"));
+ goto leave;
+ }
+ }
+
+ /*
+ * Fill in data to the output table
+ */
+ if (tt_flags & TT_FL_TREE) {
+ if (create_treenode(tt, tb, NULL, NULL))
+ goto leave;
+ } else {
+ while((fs = get_next_fs(tb, itr))) {
+ if (!add_line(tt, fs, NULL))
+ goto leave;
+ if (flags & FL_FIRSTONLY)
+ break;
+ }
+ }
+
+ /*
+ * Print the output table
+ */
+ tt_print_table(tt);
+ rc = EXIT_SUCCESS;
+leave:
+ tt_free_table(tt);
+
+ mnt_free_tab(tb);
+ mnt_free_cache(cache);
+ mnt_free_iter(itr);
+
+ return rc;
+}
diff --git a/misc-utils/look.c b/misc-utils/look.c
index 9e255965..54fbb918 100644
--- a/misc-utils/look.c
+++ b/misc-utils/look.c
@@ -186,6 +186,9 @@ look(char *front, char *back)
if (front)
print_from(front, back);
+
+ free(comparbuf);
+
return (front ? 0 : 1);
}
diff --git a/misc-utils/namei.1 b/misc-utils/namei.1
index a54fa8ac..fc10781b 100644
--- a/misc-utils/namei.1
+++ b/misc-utils/namei.1
@@ -9,26 +9,26 @@ namei - follow a pathname until a terminal point is found
.RI [ options ]
.IR pathname ...
.SH DESCRIPTION
-.B Namei
+.B namei
uses its arguments as pathnames to any type
of Unix file (symlinks, files, directories, and so forth).
-.B Namei
-then follows each pathname until a terminal
-point is found (a file, directory, char device, etc).
-If it finds a symbolic link, we show the link, and start
+.B namei
+then follows each pathname until an endpoint
+is found (a file, a directory, a device node, etc).
+If it finds a symbolic link, it shows the link, and starts
following it, indenting the output to show the context.
.PP
-This program is useful for finding a "too many levels of
+This program is useful for finding "too many levels of
symbolic links" problems.
.PP
-For each line output,
+For each line of output,
.B namei
-outputs a the following characters to identify the file types found:
+uses the following characters to identify the file type found:
.LP
.nf
- f: = the pathname we are currently trying to resolve
+ f: = the pathname currently being resolved
d = directory
- l = symbolic link (both the link and it's contents are output)
+ l = symbolic link (both the link and its contents are output)
s = socket
b = block device
c = character device
@@ -37,12 +37,12 @@ outputs a the following characters to identify the file types found:
? = an error of some kind
.fi
.PP
-.B Namei
+.B namei
prints an informative message when
the maximum number of symbolic links this system can have has been exceeded.
.SH OPTIONS
.IP "\fB\-l, \-\-long\fP"
-Use a long listing format (same as -m -o -v).
+Use the long listing format (same as -m -o -v).
.IP "\fB\-m, \-\-modes\fP"
Show the mode bits of each file type in the style of ls(1),
for example 'rwxr-xr-x'.
@@ -51,9 +51,9 @@ Show owner and group name of each file.
.IP "\fB\-n, \-\-nosymlinks\fP"
Don't follow symlinks.
.IP "\fB\-v, \-\-vertical\fP"
-Vertical align of modes and owners.
+Vertically align the modes and owners.
.IP "\fB\-x, \-\-mountpoints\fP"
-Show mount point directories with a 'D', rather than a 'd'.
+Show mountpoint directories with a 'D' rather than a 'd'.
.SH AUTHOR
The original
.B namei
diff --git a/misc-utils/namei.c b/misc-utils/namei.c
index 3c465e43..6853e1ec 100644
--- a/misc-utils/namei.c
+++ b/misc-utils/namei.c
@@ -325,6 +325,9 @@ add_namei(struct namei *parent, const char *orgpath, int start, struct namei **l
if (last)
*last = nm;
+
+ free(path);
+
return first;
}
diff --git a/misc-utils/script.c b/misc-utils/script.c
index 2028db66..9367fafb 100644
--- a/misc-utils/script.c
+++ b/misc-utils/script.c
@@ -59,7 +59,7 @@
#include "nls.h"
-#ifdef HAVE_LIBUTIL
+#if HAVE_LIBUTIL && HAVE_PTY_H
#include <pty.h>
#endif
@@ -91,7 +91,7 @@ struct termios tt;
struct winsize win;
int lb;
int l;
-#ifndef HAVE_LIBUTIL
+#if !HAVE_LIBUTIL || !HAVE_PTY_H
char line[] = "/dev/ptyXX";
#endif
int aflg = 0;
@@ -467,7 +467,7 @@ done() {
void
getmaster() {
-#ifdef HAVE_LIBUTIL
+#if HAVE_LIBUTIL && HAVE_PTY_H
(void) tcgetattr(0, &tt);
(void) ioctl(0, TIOCGWINSZ, (char *)&win);
if (openpty(&master, &slave, NULL, &tt, &win) < 0) {
diff --git a/misc-utils/uuidd.8 b/misc-utils/uuidd.8
index 33e650fe..adb8028f 100644
--- a/misc-utils/uuidd.8
+++ b/misc-utils/uuidd.8
@@ -27,9 +27,9 @@ uuidd \- UUID generation daemon
The
.B uuidd
daemon is used by the UUID library to generate
-universally unique identifiers (UUIDs), especially time-based UUID's
+universally unique identifiers (UUIDs), especially time-based UUIDs,
in a secure and guaranteed-unique fashion, even in the face of large
-numbers of threads trying to grab UUID's running on different CPU's.
+numbers of threads running on different CPUs trying to grab UUIDs.
.SH OPTIONS
.TP
.B \-d
@@ -38,13 +38,13 @@ Run
in debugging mode. This prevents uuidd from running as a daemon.
.TP
.B \-k
-If a currently uuidd daemon is running, kill it.
+If currently a uuidd daemon is running, kill it.
.TP
.BI \-n " number"
When issuing a test request to a running uuidd, request a bulk response
of
.I number
-UUID's.
+UUIDs.
.TP
.BI \-p " pidfile"
Specify the pathname where the pid file should be written. By default,
diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c
index 74bab693..716a5824 100644
--- a/misc-utils/uuidd.c
+++ b/misc-utils/uuidd.c
@@ -241,7 +241,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
fd_pidfile = open(pidfile_path, O_CREAT | O_RDWR, 0664);
if (fd_pidfile < 0) {
if (!quiet)
- fprintf(stderr, "Failed to open/create %s: %s\n",
+ fprintf(stderr, _("Failed to open/create %s: %s\n"),
pidfile_path, strerror(errno));
exit(1);
}
@@ -258,7 +258,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
if ((errno == EAGAIN) || (errno == EINTR))
continue;
if (!quiet)
- fprintf(stderr, "Failed to lock %s: %s\n",
+ fprintf(stderr, _("Failed to lock %s: %s\n"),
pidfile_path, strerror(errno));
exit(1);
}
@@ -359,7 +359,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
printf(_("operation %d, incoming num = %d\n"),
op, num);
} else if (debug)
- printf("operation %d\n", op);
+ printf(_("operation %d\n"), op);
switch(op) {
case UUIDD_OP_GETPID:
@@ -412,7 +412,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path,
uuid__generate_random((unsigned char *) reply_buf +
sizeof(num), &num);
if (debug) {
- printf(_("Generated %d UUID's:\n"), num);
+ printf(_("Generated %d UUIDs:\n"), num);
for (i=0, cp=reply_buf+sizeof(num);
i < num; i++, cp+=16) {
uuid_unparse((unsigned char *)cp, str);
@@ -531,9 +531,9 @@ int main(int argc, char **argv)
uuid_unparse((unsigned char *) buf, str);
- printf(_("%s and subsequent %d UUID's\n"), str, num);
+ printf(_("%s and subsequent %d UUIDs\n"), str, num);
} else {
- printf(_("List of UUID's:\n"));
+ printf(_("List of UUIDs:\n"));
cp = buf + 4;
if (ret != (int) (sizeof(num) + num*sizeof(uu)))
goto unexpected_size;
diff --git a/misc-utils/uuidgen.1 b/misc-utils/uuidgen.1
index 18e33de7..32c98f1d 100644
--- a/misc-utils/uuidgen.1
+++ b/misc-utils/uuidgen.1
@@ -22,9 +22,9 @@ all UUIDs created on the local system,
and among UUIDs created on other systems in the past
and in the future.
.PP
-There are two types of UUID's which
+There are two types of UUIDs which
.B uuidgen
-can generate: time-based UUID's and random-based UUID's. By
+can generate: time-based UUIDs and random-based UUIDs. By
default
.B uuidgen
will generate a random-based UUID if a high-quality random number
diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c
index 4d850501..c0b29f0e 100644
--- a/misc-utils/wipefs.c
+++ b/misc-utils/wipefs.c
@@ -174,7 +174,7 @@ get_offset_from_probe(struct wipe_desc *wp, blkid_probe pr, int zap)
wp->usage = xstrdup(usage);
wp->type = xstrdup(type);
- wp->magic = xmalloc(wp->len);
+ wp->magic = xmalloc(len);
memcpy(wp->magic, mag, len);
wp->len = len;
@@ -256,8 +256,8 @@ do_wipe_offset(int fd, struct wipe_desc *wp, const char *fname, int noact)
size_t len;
if (!wp->type) {
- warnx(_("can't found a magic string at offset "
- "0x%jx - ignore."), wp->offset);
+ warnx(_("no magic string found at offset "
+ "0x%jx -- ignored"), wp->offset);
return 0;
}
@@ -303,13 +303,30 @@ do_wipe(struct wipe_desc *wp, const char *fname, int noact)
return 0;
}
+static void
+free_wipe(struct wipe_desc *wp)
+{
+ while (wp) {
+ struct wipe_desc *next = wp->next;
+
+ free(wp->usage);
+ free(wp->type);
+ free(wp->magic);
+ free(wp->label);
+ free(wp->uuid);
+ free(wp);
+
+ wp = next;
+ }
+}
+
static loff_t
strtoll_offset(const char *str)
{
uintmax_t sz;
if (strtosize(str, &sz))
- errx(EXIT_FAILURE, _("invalid offset '%s' value specified"), str);
+ errx(EXIT_FAILURE, _("invalid offset value '%s' specified"), str);
return sz;
}
@@ -322,8 +339,8 @@ usage(FILE *out)
fprintf(out, _(
" -a, --all wipe all magic strings (BE CAREFUL!)\n"
- " -h, --help this help\n"
- " -n, --no-act everything to be done except for the write() call\n"
+ " -h, --help show this help text\n"
+ " -n, --no-act do everything except the actual write() call\n"
" -o, --offset <num> offset to erase, in bytes\n"
" -p, --parsable print out in parsable instead of printable format\n"));
@@ -391,6 +408,8 @@ main(int argc, char **argv)
do_wipe(wp, fname, noact);
else
print_all(wp, mode);
+
+ free_wipe(wp);
}
return EXIT_SUCCESS;
}