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.am26
-rw-r--r--misc-utils/blkid.84
-rw-r--r--misc-utils/blkid.c2
-rw-r--r--misc-utils/cal.14
-rw-r--r--misc-utils/cal.c23
-rw-r--r--misc-utils/ddate.14
-rw-r--r--misc-utils/findfs.86
-rw-r--r--misc-utils/findmnt.84
-rw-r--r--misc-utils/findmnt.c65
-rw-r--r--misc-utils/kill.14
-rw-r--r--misc-utils/logger.14
-rw-r--r--misc-utils/look.14
-rw-r--r--misc-utils/lsblk.869
-rw-r--r--misc-utils/lsblk.c1026
-rw-r--r--misc-utils/mcookie.14
-rw-r--r--misc-utils/namei.14
-rw-r--r--misc-utils/namei.c39
-rw-r--r--misc-utils/rename.14
-rw-r--r--misc-utils/reset.14
-rw-r--r--misc-utils/script.14
-rw-r--r--misc-utils/scriptreplay.14
-rw-r--r--misc-utils/setterm.14
-rw-r--r--misc-utils/uuidd.84
-rw-r--r--misc-utils/uuidgen.14
-rw-r--r--misc-utils/whereis.14
-rw-r--r--misc-utils/wipefs.84
-rw-r--r--misc-utils/wipefs.c11
-rw-r--r--misc-utils/write.14
-rw-r--r--misc-utils/write.c2
30 files changed, 1186 insertions, 160 deletions
diff --git a/misc-utils/.gitignore b/misc-utils/.gitignore
index a39caaf3..d13bdf53 100644
--- a/misc-utils/.gitignore
+++ b/misc-utils/.gitignore
@@ -18,3 +18,4 @@ findfs
blkid
wipefs
findmnt
+lsblk
diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am
index 6a16f999..8b1dbbe2 100644
--- a/misc-utils/Makefile.am
+++ b/misc-utils/Makefile.am
@@ -18,7 +18,9 @@ usrbin_exec_SCRIPTS = chkdupexe
CLEANFILES = chkdupexe
dist_man_MANS = cal.1 chkdupexe.1 ddate.1 logger.1 look.1 mcookie.1 \
- namei.1 script.1 whereis.1 scriptreplay.1
+ namei.1 script.1 whereis.1 scriptreplay.1
+
+namei_SOURCES = namei.c $(top_srcdir)/lib/strutils.c
if BUILD_LIBUUID
usrbin_exec_PROGRAMS += uuidgen
@@ -37,14 +39,26 @@ 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 \
- $(top_srcdir)/lib/strtosize.c
+ $(top_srcdir)/lib/strutils.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 $(top_srcdir)/lib/strtosize.c
+
+wipefs_SOURCES = wipefs.c $(top_srcdir)/lib/strutils.c
wipefs_LDADD = $(ul_libblkid_la)
wipefs_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
+
+bin_PROGRAMS += lsblk
+dist_man_MANS += lsblk.8
+lsblk_SOURCES = lsblk.c \
+ $(top_srcdir)/lib/canonicalize.c \
+ $(top_srcdir)/lib/ismounted.c \
+ $(top_srcdir)/lib/tt.c \
+ $(top_srcdir)/lib/strutils.c
+lsblk_LDADD = $(ul_libblkid_la)
+lsblk_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
if HAVE_STATIC_BLKID
sbin_PROGRAMS += blkid.static
blkid_static_SOURCES = $(blkid_SOURCES)
@@ -60,9 +74,15 @@ 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
+if !HAVE_LANGINFO
+findmnt_SOURCES += $(top_srcdir)/lib/langinfo.c
+endif
endif
cal_SOURCES = cal.c $(top_srcdir)/lib/mbsalign.c
+if !HAVE_LANGINFO
+cal_SOURCES += $(top_srcdir)/lib/langinfo.c
+endif
if HAVE_TINFO
cal_LDADD = -ltinfo @NCURSES_LIBS@
else
diff --git a/misc-utils/blkid.8 b/misc-utils/blkid.8
index 8968bb29..ac72bf69 100644
--- a/misc-utils/blkid.8
+++ b/misc-utils/blkid.8
@@ -253,8 +253,8 @@ For usage or other errors, an exit code of 4 is returned.
was written by Andreas Dilger for libblkid and improved by Theodore Ts'o
and Karel Zak.
.SH AVAILABILITY
-The blkid command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The blkid command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
.SH "SEE ALSO"
.BR libblkid (3)
.BR findfs (8)
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index f94df06a..2f7860fd 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -41,7 +41,7 @@ extern int optind;
#include <blkid.h>
#include "ismounted.h"
-#include "strtosize.h"
+#include "strutils.h"
const char *progname = "blkid";
diff --git a/misc-utils/cal.1 b/misc-utils/cal.1
index 6edb7052..38084feb 100644
--- a/misc-utils/cal.1
+++ b/misc-utils/cal.1
@@ -93,5 +93,5 @@ A
.Nm
command appeared in Version 6 AT&T UNIX.
.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/.
+The cal command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 4d46c1b1..896c4533 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -141,10 +141,6 @@ const char *Senter="", *Sexit="";/* enter and exit standout mode */
int Slen; /* strlen of Senter+Sexit */
char *Hrow; /* pointer to highlighted row in month */
-#ifdef HAVE_LANGINFO_H
-# include <langinfo.h>
-#endif
-
#include "widechar.h"
/* allow compile-time define to over-ride default */
@@ -409,12 +405,6 @@ void headers_init(void)
strcpy(day_headings,"");
strcpy(j_day_headings,"");
-#ifdef HAVE_LANGINFO_H
-# define weekday(wd) nl_langinfo(ABDAY_1+wd)
-#else
-# define weekday(wd) _time_info->abbrev_wkday[wd]
-#endif
-
for(i = 0 ; i < 7 ; i++ ) {
ssize_t space_left;
wd = (i + weekstart) % 7;
@@ -424,25 +414,18 @@ void headers_init(void)
space_left = sizeof(day_headings) - (cur_dh - day_headings);
if(space_left <= 2)
break;
- cur_dh += center_str(weekday(wd), cur_dh, space_left, 2);
+ cur_dh += center_str(nl_langinfo(ABDAY_1+wd), cur_dh, space_left, 2);
if (i)
strcat(cur_j_dh++, " ");
space_left = sizeof(j_day_headings) - (cur_j_dh - j_day_headings);
if(space_left <= 3)
break;
- cur_j_dh += center_str(weekday(wd), cur_j_dh, space_left, 3);
+ cur_j_dh += center_str(nl_langinfo(ABDAY_1+wd), cur_j_dh, space_left, 3);
}
-#undef weekday
-
- for (i = 0; i < 12; i++) {
-#ifdef HAVE_LANGINFO_H
+ for (i = 0; i < 12; i++)
full_month[i] = nl_langinfo(MON_1+i);
-#else
- full_month[i] = _time_info->full_month[i];
-#endif
- }
}
void
diff --git a/misc-utils/ddate.1 b/misc-utils/ddate.1
index 67b2057e..b14e6b34 100644
--- a/misc-utils/ddate.1
+++ b/misc-utils/ddate.1
@@ -110,5 +110,5 @@ Malaclypse the Younger,
.I "Principia Discordia, Or How I Found Goddess And What I Did To Her When I Found Her"
.SH AVAILABILITY
-The ddate command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The ddate command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/findfs.8 b/misc-utils/findfs.8
index 14fcf6fa..107b85b7 100644
--- a/misc-utils/findfs.8
+++ b/misc-utils/findfs.8
@@ -24,10 +24,10 @@ be printed on stdout.
.SH AUTHOR
.B findfs
was originally written by Theodore Ts'o (tytso@mit.edu) and re-written for
-util-linux-ng package by Karel Zak (kzak@redhat.com).
+util-linux package by Karel Zak (kzak@redhat.com).
.SH AVAILABILITY
-The findfs command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The findfs command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
.SH SEE ALSO
.BR blkid (8)
.BR fsck (8)
diff --git a/misc-utils/findmnt.8 b/misc-utils/findmnt.8
index e1cb8ff2..c7a15357 100644
--- a/misc-utils/findmnt.8
+++ b/misc-utils/findmnt.8
@@ -146,5 +146,5 @@ Karel Zak <kzak@redhat.com>
.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/.
+The findmnt command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index b1fb90a4..2b3a50b3 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -26,9 +26,6 @@
#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
@@ -193,46 +190,6 @@ static int column_name_to_id(const char *name, size_t namesz)
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)
{
@@ -447,8 +404,10 @@ again:
return fs;
}
-static int __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(FILE *out)
{
+ int i;
+
fprintf(out, _(
"\nUsage:\n"
" %1$s [options]\n"
@@ -481,12 +440,23 @@ static int __attribute__((__noreturn__)) usage(FILE *out)
" -S, --source <string> device, LABEL= or UUID=device\n"
" -T, --target <string> mountpoint\n\n"));
+
+ fprintf(out, _("\nAvailable columns:\n"));
+
+ for (i = 0; i < __NCOLUMNS; i++) {
+
+ fprintf(out, " %-12s", infos[i].name);
+ if (i && !((i+1) % 3))
+ fputc('\n', out);
+ }
+ fputc('\n', out);
+
fprintf(out, _("\nFor more information see findmnt(1).\n"));
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-static int __attribute__((__noreturn__))
+static void __attribute__((__noreturn__))
errx_mutually_exclusive(const char *opts)
{
errx(EXIT_FAILURE, "%s %s", opts, _("options are mutually exclusive"));
@@ -580,7 +550,8 @@ int main(int argc, char *argv[])
set_all_columns_truncate(FALSE);
break;
case 'o':
- if (set_columns(optarg))
+ if (tt_parse_columns_list(optarg, columns, &ncolumns,
+ column_name_to_id))
exit(EXIT_FAILURE);
break;
case 'O':
@@ -698,7 +669,7 @@ int main(int argc, char *argv[])
}
for (i = 0; i < ncolumns; i++) {
- int fl = get_column_truncate(i) ? TT_FL_TRUNCATE : 0;
+ int fl = get_column_truncate(i) ? TT_FL_TRUNC : 0;
if (get_column_id(i) == COL_TARGET && (tt_flags & TT_FL_TREE))
fl |= TT_FL_TREE;
diff --git a/misc-utils/kill.1 b/misc-utils/kill.1
index 657852ab..4591f440 100644
--- a/misc-utils/kill.1
+++ b/misc-utils/kill.1
@@ -94,5 +94,5 @@ of the named processes, and not send any signals.
Taken from BSD 4.4. The ability to translate process names to process
ids was added by Salvatore Valente <svalente@mit.edu>.
.SH AVAILABILITY
-The kill command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The kill command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/logger.1 b/misc-utils/logger.1
index 1119f62d..df02f1e7 100644
--- a/misc-utils/logger.1
+++ b/misc-utils/logger.1
@@ -125,5 +125,5 @@ command is expected to be
.St -p1003.2
compatible.
.Sh AVAILABILITY
-The logger command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The logger command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/look.1 b/misc-utils/look.1
index a9a7c4b3..e4dbb940 100644
--- a/misc-utils/look.1
+++ b/misc-utils/look.1
@@ -112,5 +112,5 @@ implementation.
.Nm Look
appeared in Version 7 AT&T Unix.
.Sh AVAILABILITY
-The look command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The look command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/lsblk.8 b/misc-utils/lsblk.8
new file mode 100644
index 00000000..2f9c17f7
--- /dev/null
+++ b/misc-utils/lsblk.8
@@ -0,0 +1,69 @@
+.\" -*- nroff -*-
+.TH LSBLK 8 "Apr 2010" "Version 1.0"
+.SH NAME
+lsblk \- list block devices
+.SH SYNOPSIS
+.B lsblk
+.RB [ options ]
+.sp
+.B lsblk
+.RB [ options ]
+.IR device...
+.SH DESCRIPTION
+.B lsblk
+will list information about all or selected block devices. The
+.B lsblk
+command reads
+.I sysfs
+filesystem to gather information.
+.PP
+The command prints all block devices (except RAM disks) in the tree-like format
+by default. See
+.B "lsblk --help"
+to get list of all available columns.
+.SH OPTIONS
+.IP "\fB\-a, \-\-all\fP"
+List all block devices.
+.IP "\fB\-b, \-\-bytes\fP"
+Print the SIZE column in bytes rather than in human readable format.
+.IP "\fB\-d, \-\-nodeps\fP"
+Don't print device holders or slaves. For example "lsblk --nodeps /dev/sda" prints
+information about the sda device only.
+.IP "\fB\-e, \-\-exclude \fIlist\fP
+Exclude devices by comma delimited list of major device numbers. Note that RAM
+disks (major=1) are excluded by default.
+.IP "\fB\-f, \-\-fs\fP
+Output info about filesystems. This option is equivalent to -o NAME,FSTYPE,LABEL,MOUNTPOINT.
+The authoritative information about filesystems and raids are provided by
+.BR blkid (8)
+command.
+.IP "\fB\-h, \-\-help\fP"
+Print help and exit.
+.IP "\fB\-i, \-\-ascii\fP"
+Use ascii characters for tree formatting.
+.IP "\fB\-m, \-\-perms\fP
+Output info about device owner, group and mode. This option is equivalent to -o NAME,SIZE,OWNER,GROUP,MODE.
+.IP "\fB\-l, \-\-list\fP"
+Use the list output format.
+.IP "\fB\-n, \-\-noheadings\fP"
+Do not print a header line.
+.IP "\fB\-o, \-\-output \fIlist\fP"
+Define output columns. Use
+.B "--help"
+to get list of all supported columns.
+.IP "\fB\-r, \-\-raw\fP"
+Use raw output format.
+.IP "\fB\-t, \-\-topology\fP"
+Output info about block device topology. This option is equivalent to -o NAME,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED.
+.SH AUTHORS
+.nf
+Milan Broz <mbroz@redhat.com>
+Karel Zak <kzak@redhat.com>
+.fi
+.SH SEE ALSO
+.BR findmnt (8),
+.BR blkid (8),
+.BR ls (1)
+.SH AVAILABILITY
+The lsblk command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
new file mode 100644
index 00000000..9d0f0160
--- /dev/null
+++ b/misc-utils/lsblk.c
@@ -0,0 +1,1026 @@
+/*
+ * lsblk(8) - list block devices
+ *
+ * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ * Written by Milan Broz <mbroz@redhat.com>
+ * 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 <errno.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <string.h>
+#include <err.h>
+#include <sys/ioctl.h>
+#include <inttypes.h>
+#include <stdarg.h>
+#include <locale.h>
+#include <pwd.h>
+#include <grp.h>
+
+#include <blkid.h>
+
+#include <assert.h>
+
+#include "pathnames.h"
+#include "blkdev.h"
+#include "canonicalize.h"
+#include "ismounted.h"
+#include "nls.h"
+#include "tt.h"
+#include "xalloc.h"
+#include "strutils.h"
+
+/* column IDs */
+enum {
+ COL_NAME = 0,
+ COL_KNAME,
+ COL_MAJMIN,
+ COL_FSTYPE,
+ COL_TARGET,
+ COL_LABEL,
+ COL_UUID,
+ COL_RO,
+ COL_RE,
+ COL_MODEL,
+ COL_SIZE,
+ COL_OWNER,
+ COL_GROUP,
+ COL_MODE,
+ COL_ALIOFF,
+ COL_MINIO,
+ COL_OPTIO,
+ COL_PHYSEC,
+ COL_LOGSEC,
+ COL_ROTA,
+ COL_SCHED,
+
+ __NCOLUMNS
+};
+
+/* column names */
+struct colinfo {
+ const char *name; /* header */
+ double whint; /* width hint (N < 1 is in percent of termwidth) */
+ int flags; /* TT_FL_* */
+ const char *help;
+};
+
+/* columns descriptions */
+static struct colinfo infos[__NCOLUMNS] = {
+ [COL_NAME] = { "NAME", 0.25, TT_FL_TREE, N_("device name") },
+ [COL_KNAME] = { "KNAME", 0.3, 0, N_("internel kernel device name") },
+ [COL_MAJMIN] = { "MAJ:MIN", 6, 0, N_("major:minor device number") },
+ [COL_FSTYPE] = { "FSTYPE", 0.1, TT_FL_TRUNC, N_("filesystem type") },
+ [COL_TARGET] = { "MOUNTPOINT", 0.10, TT_FL_TRUNC, N_("where the device is mounted") },
+ [COL_LABEL] = { "LABEL", 0.1, 0, N_("filesystem LABEL") },
+ [COL_UUID] = { "UUID", 36, 0, N_("filesystem UUID") },
+ [COL_RO] = { "RO", 1, TT_FL_RIGHT, N_("read-only device") },
+ [COL_RE] = { "RE", 1, TT_FL_RIGHT, N_("removable device") },
+ [COL_ROTA] = { "ROTA", 1, TT_FL_RIGHT, N_("rotational device") },
+ [COL_MODEL] = { "MODEL", 0.1, TT_FL_TRUNC, N_("device identifier") },
+ [COL_SIZE] = { "SIZE", 6, TT_FL_RIGHT, N_("size of the device") },
+ [COL_OWNER] = { "OWNER", 0.1, TT_FL_TRUNC, N_("user name"), },
+ [COL_GROUP] = { "GROUP", 0.1, TT_FL_TRUNC, N_("group name") },
+ [COL_MODE] = { "MODE", 10, 0, N_("device node permissions") },
+ [COL_ALIOFF] = { "ALIGNMENT", 6, TT_FL_RIGHT, N_("alignment offset") },
+ [COL_MINIO] = { "MIN-IO", 6, TT_FL_RIGHT, N_("minimum I/O size") },
+ [COL_OPTIO] = { "OPT-IO", 6, TT_FL_RIGHT, N_("optimal I/O size") },
+ [COL_PHYSEC] = { "PHY-SEC", 7, TT_FL_RIGHT, N_("physical sector size") },
+ [COL_LOGSEC] = { "LOG-SEC", 7, TT_FL_RIGHT, N_("logical sector size") },
+ [COL_SCHED] = { "SCHED", 0.1, 0, N_("I/O scheduler name") }
+
+};
+
+struct lsblk {
+ struct tt *tt; /* output table */
+ int all_devices:1; /* print all devices */
+ int bytes:1; /* print SIZE in bytes */
+ int nodeps:1; /* don't print slaves/holders */
+};
+
+struct lsblk *lsblk; /* global handler */
+int columns[__NCOLUMNS];/* enabled columns */
+int ncolumns; /* number of enabled columns */
+
+unsigned int excludes[256];
+int nexcludes;
+
+struct blkdev_cxt {
+ struct blkdev_cxt *parent;
+
+ struct tt_line *tt_line;
+ struct stat st;
+
+ char *name; /* kernel name in /sys/block */
+ char *dm_name; /* DM name (dm/block) */
+
+ char *filename; /* path to device node */
+ int sysfs_fd; /* O_RDONLY file desciptor to /sys/block/<dev> */
+
+ int partition; /* is partition? TRUE/FALSE */
+
+ int probed; /* already probed */
+ char *fstype; /* detected fs, NULL or "?" if cannot detect */
+ char *uuid; /* UUID of device / filesystem */
+ char *label; /* FS label */
+
+ int nholders; /* # of devices mapped directly to this device
+ * /sys/block/.../holders + number of partition */
+ int nslaves; /* # of devices this device maps to */
+ int maj, min; /* devno */
+
+ uint64_t size; /* device size */
+};
+
+static int is_maj_excluded(int maj)
+{
+ int i;
+
+ assert(ARRAY_SIZE(excludes) > nexcludes);
+
+ for (i = 0; i < nexcludes; i++)
+ if (excludes[i] == maj)
+ return 1;
+ return 0;
+}
+
+
+/* array with IDs of enabled columns */
+static int get_column_id(int num)
+{
+ assert(ARRAY_SIZE(columns) == __NCOLUMNS);
+ 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 int column_name_to_id(const char *name, size_t namesz)
+{
+ int i;
+
+ for (i = 0; i < __NCOLUMNS; i++) {
+ const char *cn = infos[i].name;
+
+ if (!strncasecmp(name, cn, namesz) && !*(cn + namesz))
+ return i;
+ }
+ warnx(_("unknown column: %s"), name);
+ return -1;
+}
+
+static void reset_blkdev_cxt(struct blkdev_cxt *cxt)
+{
+ if (!cxt)
+ return;
+ free(cxt->name);
+ free(cxt->dm_name);
+ free(cxt->filename);
+ free(cxt->fstype);
+ free(cxt->uuid);
+ free(cxt->label);
+
+ if (cxt->sysfs_fd >= 0)
+ close(cxt->sysfs_fd);
+
+ memset(cxt, 0, sizeof(*cxt));
+}
+
+static int is_dm(const char *name)
+{
+ return strncmp(name, "dm-", 3) ? 0 : 1;
+}
+
+static struct dirent *xreaddir(DIR *dp)
+{
+ struct dirent *d;
+
+ assert(dp);
+
+ while ((d = readdir(dp))) {
+ if (!strcmp(d->d_name, ".") ||
+ !strcmp(d->d_name, ".."))
+ continue;
+
+ /* blacklist here? */
+ break;
+ }
+ return d;
+}
+
+
+static int is_partition_dirent(DIR *dir, struct dirent *d, const char *parent_name)
+{
+ char path[256];
+
+ assert(dir);
+ assert(d);
+
+#ifdef _DIRENT_HAVE_D_TYPE
+ if (d->d_type != DT_DIR)
+ return 0;
+#endif
+ if (strncmp(parent_name, d->d_name, strlen(parent_name)))
+ return 0;
+
+ /* Cannot use /partition file, not supported on old sysfs */
+ snprintf(path, sizeof(path), "%s/start", d->d_name);
+
+ return faccessat(dirfd(dir), path, R_OK, 0) == 0;
+}
+
+static char *get_device_path(struct blkdev_cxt *cxt)
+{
+ char path[PATH_MAX];
+
+ assert(cxt);
+ assert(cxt->name);
+
+ if (is_dm(cxt->name))
+ return canonicalize_dm_name(cxt->name);
+
+ snprintf(path, sizeof(path), "/dev/%s", cxt->name);
+ return xstrdup(path);
+}
+
+static char *get_sysfs_path(struct blkdev_cxt *cxt)
+{
+ char path[PATH_MAX];
+
+ assert(cxt);
+ assert(cxt->name);
+
+ if (cxt->partition && cxt->parent)
+ snprintf(path, sizeof(path), _PATH_SYS_BLOCK "/%s/%s",
+ cxt->parent->name, cxt->name);
+ else
+ snprintf(path, sizeof(path), _PATH_SYS_BLOCK "/%s", cxt->name);
+
+ return xstrdup(path);
+}
+
+static int sysfs_open(struct blkdev_cxt *cxt, const char *attr)
+{
+ int fd;
+
+ assert(cxt);
+ assert(cxt->sysfs_fd >= 0);
+
+ fd = openat(cxt->sysfs_fd, attr, O_RDONLY);
+ if (fd == -1 && errno == ENOENT && !strncmp(attr, "queue/", 6) && cxt->parent) {
+ fd = openat(cxt->parent->sysfs_fd, attr, O_RDONLY);
+ }
+ return fd;
+}
+
+static FILE *sysfs_fopen(struct blkdev_cxt *cxt, const char *attr)
+{
+ int fd = sysfs_open(cxt, attr);
+
+ return fd < 0 ? NULL : fdopen(fd, "r");
+}
+
+static DIR *sysfs_opendir(struct blkdev_cxt *cxt, const char *attr)
+{
+ DIR *dir;
+ int fd;
+
+ if (attr)
+ fd = sysfs_open(cxt, attr);
+ else {
+ /* request to open root of device in sysfs (/sys/block/<dev>)
+ * -- we cannot use cxt->sysfs_fd directly, because closedir()
+ * will close this our persistent file descriptor.
+ */
+ assert(cxt);
+ assert(cxt->sysfs_fd >= 0);
+
+ fd = dup(cxt->sysfs_fd);
+ }
+
+ if (fd < 0)
+ return NULL;
+ dir = fdopendir(fd);
+ if (!dir) {
+ close(fd);
+ return NULL;
+ }
+ if (!attr)
+ rewinddir(dir);
+ return dir;
+}
+
+static __attribute__ ((format (scanf, 3, 4)))
+int sysfs_scanf(struct blkdev_cxt *cxt, const char *attr, const char *fmt, ...)
+{
+ FILE *f = sysfs_fopen(cxt, attr);
+ va_list ap;
+ int rc;
+
+ if (!f)
+ return -EINVAL;
+ va_start(ap, fmt);
+ rc = vfscanf(f, fmt, ap);
+ va_end(ap);
+
+ fclose(f);
+ return rc;
+}
+
+static uint64_t sysfs_read_u64(struct blkdev_cxt *cxt, const char *attr)
+{
+ uint64_t x;
+ return sysfs_scanf(cxt, attr, "%"SCNu64, &x) == 1 ? x : 0;
+}
+
+static char *sysfs_strdup(struct blkdev_cxt *cxt, const char *attr)
+{
+ char buf[1024];
+ return sysfs_scanf(cxt, attr, "%1024[^\n]", buf) == 1 ?
+ xstrdup(buf) : NULL;
+}
+
+static int sysfs_count_dirents(struct blkdev_cxt *cxt, const char *attr)
+{
+ DIR *dir;
+ int r = 0;
+
+ if (!(dir = sysfs_opendir(cxt, attr)))
+ return 0;
+
+ while (xreaddir(dir)) r++;
+
+ closedir(dir);
+ return r;
+}
+
+static int sysfs_count_partitions(struct blkdev_cxt *cxt)
+{
+ DIR *dir;
+ struct dirent *d;
+ int r = 0;
+
+ if (!(dir = sysfs_opendir(cxt, NULL)))
+ return 0;
+
+ while ((d = xreaddir(dir))) {
+ if (is_partition_dirent(dir, d, cxt->name))
+ r++;
+ }
+
+ closedir(dir);
+ return r;
+}
+
+static char *get_device_mountpoint(struct blkdev_cxt *cxt)
+{
+ int fl = 0;
+ char mnt[PATH_MAX];
+
+ *mnt = '\0';
+
+ /*
+ * TODO: use libmount and parse /proc/mountinfo only once
+ */
+ if (check_mount_point(cxt->filename, &fl, mnt, sizeof(mnt)) == 0 &&
+ (fl & MF_MOUNTED)) {
+ if (fl & MF_SWAP)
+ strcpy(mnt, "[SWAP]");
+ }
+ return strlen(mnt) ? xstrdup(mnt) : NULL;
+}
+
+/* TODO: read info from udev db (if possible) for non-root users
+ */
+static void probe_device(struct blkdev_cxt *cxt)
+{
+ char *path = NULL;
+ blkid_probe pr = NULL;
+
+ if (cxt->probed)
+ return;
+ cxt->probed = 1;
+
+ if (!cxt->size)
+ return;
+
+ pr = blkid_new_probe_from_filename(cxt->filename);
+ if (!pr)
+ return;
+
+ /* TODO: we have to enable partitions probing to avoid conflicts
+ * between raids and PT -- see blkid(8) code for more details
+ */
+ blkid_probe_enable_superblocks(pr, 1);
+ blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_LABEL |
+ BLKID_SUBLKS_UUID |
+ BLKID_SUBLKS_TYPE);
+ if (!blkid_do_safeprobe(pr)) {
+ const char *data = NULL;
+
+ if (!blkid_probe_lookup_value(pr, "TYPE", &data, NULL))
+ cxt->fstype = xstrdup(data);
+ if (!blkid_probe_lookup_value(pr, "UUID", &data, NULL))
+ cxt->uuid = xstrdup(data);
+ if (!blkid_probe_lookup_value(pr, "LABEL", &data, NULL))
+ cxt->label = xstrdup(data);
+ }
+
+ free(path);
+ blkid_free_probe(pr);
+ return;
+}
+
+static int is_readonly_device(struct blkdev_cxt *cxt)
+{
+ int fd, ro = 0;
+
+ if (sysfs_scanf(cxt, "ro", "%d", &ro) == 0)
+ return ro;
+
+ /* fallback if "ro" attribute does not exist */
+ fd = open(cxt->filename, O_RDONLY);
+ if (fd != -1) {
+ ioctl(fd, BLKROGET, &ro);
+ close(fd);
+ }
+ return ro;
+}
+
+static char *get_scheduler(struct blkdev_cxt *cxt)
+{
+ char *str = sysfs_strdup(cxt, "queue/scheduler");
+ char *p, *res = NULL;
+
+ if (!str)
+ return NULL;
+ p = strchr(str, '[');
+ if (p) {
+ res = p + 1;
+ p = strchr(res, ']');
+ if (p) {
+ *p = '\0';
+ res = xstrdup(res);
+ } else
+ res = NULL;
+ }
+ free(str);
+ return res;
+}
+
+static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line *ln)
+{
+ char buf[1024];
+ char *p;
+
+ if (!cxt->st.st_rdev && (id == COL_OWNER || id == COL_GROUP ||
+ id == COL_MODE))
+ stat(cxt->filename, &cxt->st);
+
+ switch(id) {
+ case COL_NAME:
+ if (cxt->dm_name) {
+ snprintf(buf, sizeof(buf), "%s (%s)",
+ cxt->dm_name, cxt->name);
+ tt_line_set_data(ln, col, xstrdup(buf));
+ break;
+ }
+ case COL_KNAME:
+ tt_line_set_data(ln, col, xstrdup(cxt->name));
+ break;
+ case COL_OWNER:
+ {
+ struct passwd *pw = getpwuid(cxt->st.st_uid);
+ if (pw)
+ tt_line_set_data(ln, col, xstrdup(pw->pw_name));
+ break;
+ }
+ case COL_GROUP:
+ {
+ struct group *gr = getgrgid(cxt->st.st_gid);
+ if (gr)
+ tt_line_set_data(ln, col, xstrdup(gr->gr_name));
+ break;
+ }
+ case COL_MODE:
+ {
+ char md[11];
+ strmode(cxt->st.st_mode, md);
+ tt_line_set_data(ln, col, xstrdup(md));
+ break;
+ }
+ case COL_MAJMIN:
+ if (lsblk->tt->flags & TT_FL_RAW)
+ snprintf(buf, sizeof(buf), "%u:%u", cxt->maj, cxt->min);
+ else
+ snprintf(buf, sizeof(buf), "%3u:%-3u", cxt->maj, cxt->min);
+ tt_line_set_data(ln, col, xstrdup(buf));
+ break;
+ case COL_FSTYPE:
+ probe_device(cxt);
+ if (cxt->fstype)
+ tt_line_set_data(ln, col, xstrdup(cxt->fstype));
+ break;
+ case COL_TARGET:
+ if (!cxt->nholders) {
+ p = get_device_mountpoint(cxt);
+ if (p)
+ tt_line_set_data(ln, col, p);
+ }
+ break;
+ case COL_LABEL:
+ probe_device(cxt);
+ if (cxt->label)
+ tt_line_set_data(ln, col, xstrdup(cxt->label));
+ break;
+ case COL_UUID:
+ probe_device(cxt);
+ if (cxt->uuid)
+ tt_line_set_data(ln, col, xstrdup(cxt->uuid));
+ break;
+ case COL_RO:
+ tt_line_set_data(ln, col, is_readonly_device(cxt) ?
+ xstrdup("1") : xstrdup("0"));
+ break;
+ case COL_RE:
+ p = sysfs_strdup(cxt, "removable");
+ if (!p && cxt->parent)
+ p = sysfs_strdup(cxt->parent, "removable");
+ if (p)
+ tt_line_set_data(ln, col, p);
+ break;
+ case COL_ROTA:
+ p = sysfs_strdup(cxt, "queue/rotational");
+ if (p)
+ tt_line_set_data(ln, col, p);
+ break;
+ case COL_MODEL:
+ if (!cxt->partition && cxt->nslaves == 0) {
+ p = sysfs_strdup(cxt, "device/model");
+ if (p)
+ tt_line_set_data(ln, col, p);
+ }
+ break;
+ case COL_SIZE:
+ if (cxt->size) {
+ if (lsblk->bytes) {
+ if (asprintf(&p, "%jd", cxt->size) < 0)
+ p = NULL;
+ } else
+ p = size_to_human_string(cxt->size);
+ if (p)
+ tt_line_set_data(ln, col, p);
+ }
+ break;
+ case COL_ALIOFF:
+ p = sysfs_strdup(cxt, "alignment_offset");
+ if (p)
+ tt_line_set_data(ln, col, p);
+ break;
+ case COL_MINIO:
+ p = sysfs_strdup(cxt, "queue/minimum_io_size");
+ if (p)
+ tt_line_set_data(ln, col, p);
+ break;
+ case COL_OPTIO:
+ p = sysfs_strdup(cxt, "queue/optimal_io_size");
+ if (p)
+ tt_line_set_data(ln, col, p);
+ break;
+ case COL_PHYSEC:
+ p = sysfs_strdup(cxt, "queue/physical_block_size");
+ if (p)
+ tt_line_set_data(ln, col, p);
+ break;
+ case COL_LOGSEC:
+ p = sysfs_strdup(cxt, "queue/logical_block_size");
+ if (p)
+ tt_line_set_data(ln, col, p);
+ break;
+ case COL_SCHED:
+ p = get_scheduler(cxt);
+ if (p)
+ tt_line_set_data(ln, col, p);
+ break;
+ };
+}
+
+static void print_device(struct blkdev_cxt *cxt, struct tt_line *tt_parent)
+{
+ int i;
+
+ cxt->tt_line = tt_add_line(lsblk->tt, tt_parent);
+
+ for (i = 0; i < ncolumns; i++)
+ set_tt_data(cxt, i, get_column_id(i), cxt->tt_line);
+}
+
+static int set_cxt(struct blkdev_cxt *cxt,
+ struct blkdev_cxt *parent,
+ const char *name,
+ int partition)
+{
+ char *p;
+
+ cxt->parent = parent;
+ cxt->name = xstrdup(name);
+ cxt->partition = partition;
+
+ cxt->filename = get_device_path(cxt);
+
+ /* open /sys/block/<name> */
+ p = get_sysfs_path(cxt);
+ cxt->sysfs_fd = open(p, O_RDONLY);
+ if (cxt->sysfs_fd < 0)
+ err(EXIT_FAILURE, _("%s: open failed"), p);
+ free(p);
+
+ if (sysfs_scanf(cxt, "dev", "%u:%u", &cxt->maj, &cxt->min) != 2)
+ return -1;
+
+ cxt->size = sysfs_read_u64(cxt, "size") << 9;
+
+ /* Ignore devices of zero size */
+ if (!lsblk->all_devices && cxt->size == 0)
+ return -1;
+
+ if (is_dm(name))
+ cxt->dm_name = sysfs_strdup(cxt, "dm/name");
+
+ cxt->nholders = sysfs_count_dirents(cxt, "holders") +
+ sysfs_count_partitions(cxt);
+ cxt->nslaves = sysfs_count_dirents(cxt, "slaves");
+
+ return 0;
+}
+
+/*
+ * List devices (holders) mapped to device
+ */
+static int list_holders(struct blkdev_cxt *cxt)
+{
+ DIR *dir;
+ struct dirent *d;
+ struct blkdev_cxt holder = {};
+
+ assert(cxt);
+ assert(cxt->sysfs_fd >= 0);
+
+ if (lsblk->nodeps)
+ return 0;
+
+ if (!cxt->nholders)
+ return 0;
+
+ /* Partitions */
+ dir = sysfs_opendir(cxt, NULL);
+ if (!dir)
+ err(EXIT_FAILURE, _("failed to open device directory in sysfs"));
+
+ while ((d = xreaddir(dir))) {
+ if (!is_partition_dirent(dir, d, cxt->name))
+ continue;
+
+ set_cxt(&holder, cxt, d->d_name, 1);
+ print_device(&holder, cxt->tt_line);
+ list_holders(&holder);
+ reset_blkdev_cxt(&holder);
+ }
+ closedir(dir);
+
+ /* Holders */
+ dir = sysfs_opendir(cxt, "holders");
+ if (!dir)
+ return 0;
+
+ while ((d = xreaddir(dir))) {
+ set_cxt(&holder, cxt, d->d_name, 0);
+ print_device(&holder, cxt->tt_line);
+ list_holders(&holder);
+ reset_blkdev_cxt(&holder);
+ }
+ closedir(dir);
+
+ return 0;
+}
+
+/* Iterate top-level devices in sysfs */
+static int iterate_block_devices(void)
+{
+ DIR *dir;
+ struct dirent *d;
+ struct blkdev_cxt cxt = {};
+
+ if (!(dir = opendir(_PATH_SYS_BLOCK)))
+ return EXIT_FAILURE;
+
+ while ((d = xreaddir(dir))) {
+
+ if (set_cxt(&cxt, NULL, d->d_name, 0))
+ goto next;
+
+ /* Skip devices in the middle of dependence tree */
+ if (cxt.nslaves > 0)
+ goto next;
+
+ if (!lsblk->all_devices && is_maj_excluded(cxt.maj))
+ goto next;
+
+ print_device(&cxt, NULL);
+ list_holders(&cxt);
+ next:
+ reset_blkdev_cxt(&cxt);
+ }
+
+ closedir(dir);
+
+ return EXIT_SUCCESS;
+}
+
+static int process_one_device(char *devname)
+{
+ struct blkdev_cxt parent = {}, cxt = {};
+ struct stat st;
+ char buf[PATH_MAX];
+ dev_t disk = 0;
+
+ if (stat(devname, &st) || !S_ISBLK(st.st_mode)) {
+ warnx(_("%s: not a block device"), devname);
+ return EXIT_FAILURE;
+ }
+ if (blkid_devno_to_wholedisk(st.st_rdev, buf, sizeof(buf), &disk)) {
+ warn(_("%s: failed to get whole-list devno"), devname);
+ return EXIT_FAILURE;
+ }
+ if (st.st_rdev == disk)
+ /*
+ * unpartitioned device
+ */
+ set_cxt(&cxt, NULL, buf, 0);
+ else {
+ /*
+ * Parititioned, read sysfs name of the device
+ */
+ size_t len;
+ char path[PATH_MAX], *diskname, *name;
+
+ snprintf(path, sizeof(path), "/sys/dev/block/%d:%d",
+ major(st.st_rdev), minor(st.st_rdev));
+ diskname = xstrdup(buf);
+
+ len = readlink(path, buf, sizeof(buf));
+ if (len < 0) {
+ warn(_("%s: failed to read link"), path);
+ return EXIT_FAILURE;
+ }
+ buf[len] = '\0';
+
+ /* sysfs device name */
+ name = strrchr(buf, '/') + 1;
+
+ set_cxt(&parent, NULL, diskname, 0);
+ set_cxt(&cxt, &parent, name, 1);
+
+ free(diskname);
+ }
+
+ print_device(&cxt, NULL);
+ list_holders(&cxt);
+ reset_blkdev_cxt(&cxt);
+
+ if (st.st_rdev != disk)
+ reset_blkdev_cxt(&parent);
+
+ return EXIT_SUCCESS;
+}
+
+static void parse_excludes(const char *str)
+{
+ nexcludes = 0;
+
+ while (str && *str) {
+ char *end = NULL;
+ unsigned int n;
+
+ errno = 0;
+ n = strtoul(str, &end, 10);
+
+ if (end == str || (errno != 0 && (n == ULONG_MAX || n == 0)))
+ err(EXIT_FAILURE, _("failed to parse list '%s'"), str);
+ excludes[nexcludes++] = n;
+
+ if (nexcludes == ARRAY_SIZE(excludes))
+ errx(EXIT_FAILURE, _("the list of excluded devices is "
+ "too large (limit is %d devices)"),
+ (int)ARRAY_SIZE(excludes));
+ str = end && *end ? end + 1 : NULL;
+ }
+}
+
+static void __attribute__((__noreturn__)) help(FILE *out)
+{
+ int i;
+
+ fprintf(out, _(
+ "\nUsage:\n"
+ " %s [options] [<device> ...]\n"), program_invocation_short_name);
+
+ fprintf(out, _(
+ "\nOptions:\n"
+ " -a, --all print all devices\n"
+ " -b, --bytes print SIZE in bytes rather than in human readable format\n"
+ " -d, --nodeps don't print slaves or holders\n"
+ " -e, --exclude <list> exclude devices by major number (default: RAM disks)\n"
+ " -f, --fs output info about filesystems\n"
+ " -h, --help usage information (this)\n"
+ " -i, --ascii use ascii characters only\n"
+ " -m, --perms output info about permissions\n"
+ " -l, --list use list format ouput\n"
+ " -n, --noheadings don't print headings\n"
+ " -o, --output <list> output columns\n"
+ " -r, --raw use raw format output\n"
+ " -t, --topology output info about topology\n"));
+
+ fprintf(out, _("\nAvailable columns:\n"));
+
+ for (i = 0; i < __NCOLUMNS; i++)
+ fprintf(out, " %10s %s\n", infos[i].name, gettext(infos[i].help));
+
+ fprintf(out, _("\nFor more information see lsblk(8).\n"));
+
+ exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+static void __attribute__((__noreturn__))
+errx_mutually_exclusive(const char *opts)
+{
+ errx(EXIT_FAILURE, "%s %s", opts, _("options are mutually exclusive"));
+}
+
+int main(int argc, char *argv[])
+{
+ struct lsblk _ls;
+ int tt_flags = TT_FL_TREE;
+ int i, c, status = EXIT_FAILURE;
+
+ struct option longopts[] = {
+ { "all", 0, 0, 'a' },
+ { "bytes", 0, 0, 'b' },
+ { "nodeps", 0, 0, 'd' },
+ { "help", 0, 0, 'h' },
+ { "output", 1, 0, 'o' },
+ { "perms", 0, 0, 'm' },
+ { "noheadings", 0, 0, 'n' },
+ { "list", 0, 0, 'l' },
+ { "ascii", 0, 0, 'i' },
+ { "raw", 0, 0, 'r' },
+ { "fs", 0, 0, 'f' },
+ { "exclude", 1, 0, 'e' },
+ { "topology", 0, 0, 't' },
+ { NULL, 0, 0, 0 },
+ };
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+
+ lsblk = &_ls;
+ memset(lsblk, 0, sizeof(*lsblk));
+
+ while((c = getopt_long(argc, argv, "abde:fhlnmo:irt", longopts, NULL)) != -1) {
+ switch(c) {
+ case 'a':
+ lsblk->all_devices = 1;
+ break;
+ case 'b':
+ lsblk->bytes = 1;
+ break;
+ case 'd':
+ lsblk->nodeps = 1;
+ break;
+ case 'e':
+ parse_excludes(optarg);
+ break;
+ case 'h':
+ help(stdout);
+ 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 'o':
+ if (tt_parse_columns_list(optarg, columns, &ncolumns,
+ column_name_to_id))
+ return EXIT_FAILURE;
+ break;
+ case 'i':
+ tt_flags = TT_FL_ASCII;
+ break;
+ case 'r':
+ tt_flags &= ~TT_FL_TREE; /* disable the default */
+ tt_flags |= TT_FL_RAW; /* enable raw */
+ break;
+ case 'f':
+ columns[ncolumns++] = COL_NAME;
+ columns[ncolumns++] = COL_FSTYPE;
+ columns[ncolumns++] = COL_LABEL;
+ columns[ncolumns++] = COL_TARGET;
+ break;
+ case 'm':
+ columns[ncolumns++] = COL_NAME;
+ columns[ncolumns++] = COL_SIZE;
+ columns[ncolumns++] = COL_OWNER;
+ columns[ncolumns++] = COL_GROUP;
+ columns[ncolumns++] = COL_MODE;
+ break;
+ case 't':
+ columns[ncolumns++] = COL_NAME;
+ columns[ncolumns++] = COL_ALIOFF;
+ columns[ncolumns++] = COL_MINIO;
+ columns[ncolumns++] = COL_OPTIO;
+ columns[ncolumns++] = COL_PHYSEC;
+ columns[ncolumns++] = COL_LOGSEC;
+ columns[ncolumns++] = COL_ROTA;
+ columns[ncolumns++] = COL_SCHED;
+ break;
+ default:
+ help(stderr);
+ }
+ }
+
+ if (!ncolumns) {
+ columns[ncolumns++] = COL_NAME;
+ columns[ncolumns++] = COL_MAJMIN;
+ columns[ncolumns++] = COL_RE;
+ columns[ncolumns++] = COL_SIZE;
+ columns[ncolumns++] = COL_RO;
+ columns[ncolumns++] = COL_TARGET;
+ }
+
+ if (nexcludes && lsblk->all_devices)
+ errx_mutually_exclusive("--{all,exclude}");
+ else if (!nexcludes)
+ excludes[nexcludes++] = 1; /* default: ignore RAM disks */
+ /*
+ * initialize output columns
+ */
+ if (!(lsblk->tt = tt_new_table(tt_flags)))
+ errx(EXIT_FAILURE, _("failed to initialize output table"));
+
+ for (i = 0; i < ncolumns; i++) {
+ struct colinfo *ci = get_column_info(i);
+ int fl = ci->flags;
+
+ if (!(tt_flags & TT_FL_TREE) && get_column_id(i) == COL_NAME)
+ fl &= ~TT_FL_TREE;
+
+ if (!tt_define_column(lsblk->tt, ci->name, ci->whint, fl)) {
+ warn(_("failed to initialize output column"));
+ goto leave;
+ }
+ }
+
+ if (optind == argc)
+ status = iterate_block_devices();
+ else while (optind < argc)
+ status = process_one_device(argv[optind++]);
+
+ tt_print_table(lsblk->tt);
+
+leave:
+ tt_free_table(lsblk->tt);
+ return status;
+}
diff --git a/misc-utils/mcookie.1 b/misc-utils/mcookie.1
index 0396d9a1..641a7c55 100644
--- a/misc-utils/mcookie.1
+++ b/misc-utils/mcookie.1
@@ -50,5 +50,5 @@ It is assumed that none of the devices opened will block.
.BR xauth (1),
.BR md5sum (1)
.SH AVAILABILITY
-The mcookie command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The mcookie command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/namei.1 b/misc-utils/namei.1
index fc10781b..82f5d784 100644
--- a/misc-utils/namei.1
+++ b/misc-utils/namei.1
@@ -66,5 +66,5 @@ To be discovered.
.BR ls (1),
.BR stat (1)
.SH AVAILABILITY
-The namei command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The namei command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/namei.c b/misc-utils/namei.c
index 0342a08c..1c20b377 100644
--- a/misc-utils/namei.c
+++ b/misc-utils/namei.c
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2008 Karel Zak <kzak@redhat.com>
*
- * This file is part of util-linux-ng.
+ * This file is part of util-linux.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -38,6 +38,7 @@
#include "xalloc.h"
#include "nls.h"
#include "widechar.h"
+#include "strutils.h"
#ifndef MAXSYMLINKS
#define MAXSYMLINKS 256
@@ -362,42 +363,6 @@ follow_symlinks(struct namei *nm)
return 0;
}
-static void
-strmode(mode_t mode, char *str)
-{
- if (S_ISDIR(mode))
- str[0] = 'd';
- else if (S_ISLNK(mode))
- str[0] = 'l';
- else if (S_ISCHR(mode))
- str[0] = 'c';
- else if (S_ISBLK(mode))
- str[0] = 'b';
- else if (S_ISSOCK(mode))
- str[0] = 's';
- else if (S_ISFIFO(mode))
- str[0] = 'p';
- else if (S_ISREG(mode))
- str[0] = '-';
-
- str[1] = mode & S_IRUSR ? 'r' : '-';
- str[2] = mode & S_IWUSR ? 'w' : '-';
- str[3] = (mode & S_ISUID
- ? (mode & S_IXUSR ? 's' : 'S')
- : (mode & S_IXUSR ? 'x' : '-'));
- str[4] = mode & S_IRGRP ? 'r' : '-';
- str[5] = mode & S_IWGRP ? 'w' : '-';
- str[6] = (mode & S_ISGID
- ? (mode & S_IXGRP ? 's' : 'S')
- : (mode & S_IXGRP ? 'x' : '-'));
- str[7] = mode & S_IROTH ? 'r' : '-';
- str[8] = mode & S_IWOTH ? 'w' : '-';
- str[9] = (mode & S_ISVTX
- ? (mode & S_IXOTH ? 't' : 'T')
- : (mode & S_IXOTH ? 'x' : '-'));
- str[10] = '\0';
-}
-
static int
print_namei(struct namei *nm, char *path)
{
diff --git a/misc-utils/rename.1 b/misc-utils/rename.1
index 255832fe..30b0699c 100644
--- a/misc-utils/rename.1
+++ b/misc-utils/rename.1
@@ -48,5 +48,5 @@ will fix the extension of your html files.
.BR mmv (1),
.BR mv (1)
.SH AVAILABILITY
-The rename command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The rename command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/reset.1 b/misc-utils/reset.1
index 99150b64..1e2f0f30 100644
--- a/misc-utils/reset.1
+++ b/misc-utils/reset.1
@@ -41,5 +41,5 @@ argument in an attempt to get cooked mode back.
.SH AUTHOR
Rik Faith (faith@cs.unc.edu)
.SH AVAILABILITY
-The reset command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The reset command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/script.1 b/misc-utils/script.1
index 24c6b572..7a7760e3 100644
--- a/misc-utils/script.1
+++ b/misc-utils/script.1
@@ -147,5 +147,5 @@ places
in the log file, including linefeeds and backspaces.
This is not what the naive user expects.
.Sh AVAILABILITY
-The script command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The script command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/scriptreplay.1 b/misc-utils/scriptreplay.1
index 3aa7b6be..d102f060 100644
--- a/misc-utils/scriptreplay.1
+++ b/misc-utils/scriptreplay.1
@@ -214,5 +214,5 @@ The program was re-written in C by James Youngman <jay@gnu.org> and Karel Zak <k
.SH AVAILABILITY
The
.B scriptreplay
-command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/setterm.1 b/misc-utils/setterm.1
index 217e18a5..ceff57ff 100644
--- a/misc-utils/setterm.1
+++ b/misc-utils/setterm.1
@@ -203,5 +203,5 @@ Sets the bell frequency in Hz. Without an argument, defaults to 0.
.SH BUGS
Differences between the Minix and Linux versions are not documented.
.SH AVAILABILITY
-The setterm command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The setterm command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/uuidd.8 b/misc-utils/uuidd.8
index adb8028f..6880efa1 100644
--- a/misc-utils/uuidd.8
+++ b/misc-utils/uuidd.8
@@ -73,8 +73,8 @@ The
.B uuidd
daemon was written by Theodore Ts'o <tytso@mit.edu>.
.SH AVAILABILITY
-uuidd is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+uuidd is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
.SH "SEE ALSO"
.BR libuuid (3),
.BR uuidgen (1)
diff --git a/misc-utils/uuidgen.1 b/misc-utils/uuidgen.1
index 32c98f1d..453a7f58 100644
--- a/misc-utils/uuidgen.1
+++ b/misc-utils/uuidgen.1
@@ -52,7 +52,7 @@ OSF DCE 1.1
.B uuidgen
was written by Andreas Dilger for libuuid.
.SH AVAILABILITY
-The uuidgen command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The uuidgen command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
.SH "SEE ALSO"
.BR libuuid (3)
diff --git a/misc-utils/whereis.1 b/misc-utils/whereis.1
index b13491b6..57bfb0bc 100644
--- a/misc-utils/whereis.1
+++ b/misc-utils/whereis.1
@@ -146,5 +146,5 @@ must be full; that is, they must begin with a
has a hard-coded path, so may not always find what
you're looking for.
.SH AVAILABILITY
-The whereis command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The whereis command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/wipefs.8 b/misc-utils/wipefs.8
index 973f2ef2..6867dfc2 100644
--- a/misc-utils/wipefs.8
+++ b/misc-utils/wipefs.8
@@ -41,8 +41,8 @@ characters of a string to the corresponding hex value prefixed by '\\x'.
.SH AUTHOR
Karel Zak <kzak@redhat.com>.
.SH AVAILABILITY
-The wipefs command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The wipefs command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
.SH SEE ALSO
.BR blkid (8)
.BR findfs (8)
diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c
index dbfabc4a..d3033446 100644
--- a/misc-utils/wipefs.c
+++ b/misc-utils/wipefs.c
@@ -35,7 +35,7 @@
#include "nls.h"
#include "xalloc.h"
-#include "strtosize.h"
+#include "strutils.h"
struct wipe_desc {
loff_t offset; /* magic string offset */
@@ -136,15 +136,6 @@ add_offset(struct wipe_desc *wp0, loff_t offset, int zap)
return wp;
}
-static inline char *
-xstrdup(const char *s)
-{
- char *x = strdup(s);
- if (!x)
- err(EXIT_FAILURE, _("strdup failed"));
- return x;
-}
-
static struct wipe_desc *
get_offset_from_probe(struct wipe_desc *wp, blkid_probe pr, int zap)
{
diff --git a/misc-utils/write.1 b/misc-utils/write.1
index 4d627071..1c15f50c 100644
--- a/misc-utils/write.1
+++ b/misc-utils/write.1
@@ -98,5 +98,5 @@ A
.B write
command appeared in Version 6 AT&T UNIX.
.SH AVAILABILITY
-The write command is part of the util-linux-ng package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+The write command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/misc-utils/write.c b/misc-utils/write.c
index 8ed77634..c4f4ecc4 100644
--- a/misc-utils/write.c
+++ b/misc-utils/write.c
@@ -331,7 +331,7 @@ void do_write(char *tty, char *mytty, uid_t myuid) {
static void
done(int dummy) {
(void)printf("EOF\r\n");
- exit(0);
+ _exit(0);
}
/*