]> err.no Git - util-linux/commitdiff
blkid: add findfs(8)
authorKarel Zak <kzak@redhat.com>
Sat, 7 Feb 2009 23:23:55 +0000 (00:23 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 11 Feb 2009 22:55:51 +0000 (23:55 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libs/blkid/.gitignore
libs/blkid/bin/Makefile.am
libs/blkid/bin/findfs.8 [new file with mode: 0644]
libs/blkid/bin/findfs.c [new file with mode: 0644]
libs/blkid/bin/findfs.sh.in [new file with mode: 0644]

index a8ec330ae3e7cde390c318eda267337a74a41a16..d6126deabfa1f095b24b643eecce2b2ff0ef04da 100644 (file)
@@ -1,3 +1,4 @@
 *.sh
 bin/blkid
+bin/findfs
 test_*
index cc34c57386afc6da6ccca04c08e88378f514c85d..581adbe75b8bff380f27d7bfbfa1e212d040edd7 100644 (file)
@@ -3,13 +3,14 @@ include $(top_srcdir)/config/include-Makefile.am
 AM_LDFLAGS += -L$(top_builddir)/libs/blkid/src -lblkid
 AM_CPPFLAGS += -I$(top_builddir)/libs/blkid/src/
 
-sbin_PROGRAMS = blkid
-dist_man_MANS = blkid.8
+sbin_PROGRAMS = blkid findfs
+dist_man_MANS = blkid.8 findfs.8
 
-shell_in_files = blkid.sh.in
+shell_in_files = blkid.sh.in findfs.sh
 noinst_SCRIPTS = $(shell_in_files:.sh.in=.sh)
 
 blkid_SOURCES = blkid.c
+findfs_SOURCES = findfs.c
 
 CLEANFILES = $(noinst_SCRIPTS)
 
diff --git a/libs/blkid/bin/findfs.8 b/libs/blkid/bin/findfs.8
new file mode 100644 (file)
index 0000000..e93fe54
--- /dev/null
@@ -0,0 +1,35 @@
+.\" -*- nroff -*-
+.\" Copyright 1993, 1994, 1995 by Theodore Ts'o.  All Rights Reserved.
+.\" This file may be copied under the terms of the GNU Public License.
+.\"
+.TH FINDFS 8 "February 2009" "Linux" "MAINTENANCE COMMANDS"
+.SH NAME
+findfs \- Find a filesystem by label or UUID
+.SH SYNOPSIS
+.B findfs
+.BI LABEL= label
+.sp
+.B findfs
+.BI UUID= uuid
+.SH DESCRIPTION
+.B findfs
+will search the disks in the system looking for a filesystem which has
+a label matching
+.I label
+or a UUID equal to
+.IR uuid .
+If the filesystem is found, the device name for the filesystem will
+be printed on stdout.
+.PP
+.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).
+.SH AVAILABILITY
+.B findfs
+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/.
+.SH SEE ALSO
+.BR blkid (8)
+.BR fsck (8)
+
diff --git a/libs/blkid/bin/findfs.c b/libs/blkid/bin/findfs.c
new file mode 100644 (file)
index 0000000..e316eb2
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
+ *
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <err.h>
+
+#include <blkid.h>
+
+#include "nls.h"
+
+static void __attribute__((__noreturn__)) usage(int rc)
+{
+       const char *p = program_invocation_short_name;
+
+       if (!p)
+               p = "findfs";
+
+       fprintf(stderr, _("Usage: %s LABEL=<label>|UUID=<uuid>\n"), p);
+       exit(rc);
+}
+
+int main(int argc, char **argv)
+{
+       char    *dev, *tk, *vl;
+
+       setlocale(LC_ALL, "");
+       bindtextdomain(PACKAGE, LOCALEDIR);
+       textdomain(PACKAGE);
+
+       if (argc != 2)
+               /* we return '2' for backward compatibility
+                * with version from e2fsprogs */
+               usage(2);
+
+       if (!strncmp(argv[1], "LABEL=", 6)) {
+               tk = "LABEL";
+               vl = argv[1] + 6;
+       } else if (!strncmp(argv[1], "UUID=", 5)) {
+               tk = "UUID";
+               vl = argv[1] + 5;
+       } else if (!strcmp(argv[1], "-h") == 0 ||
+                  !strcmp(argv[1], "--help") == 0) {
+               usage(EXIT_SUCCESS);
+       } else
+               usage(2);
+
+       dev = blkid_evaluate_spec(tk, vl, NULL);
+       if (!dev)
+               errx(EXIT_FAILURE, _("unable to resolve '%s'"), argv[1]);
+
+       puts(dev);
+       exit(EXIT_SUCCESS);
+}
+
diff --git a/libs/blkid/bin/findfs.sh.in b/libs/blkid/bin/findfs.sh.in
new file mode 100644 (file)
index 0000000..37876c7
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# libtool? Don't ask!
+
+BLKIDDIR=@SRCDIR@/libs/blkid
+BINARY=$BLKIDDIR/bin/findfs
+LD_LIBRARY_PATH=$BLKIDDIR/src/
+
+export LD_LIBRARY_PATH
+exec $BINARY $@