#include "ismounted.h"
-#define STRTOXX_EXIT_CODE BLKID_EXIT_OTHER /* strtoxx_or_err() */
#include "strutils.h"
#define OPTUTILS_EXIT_CODE BLKID_EXIT_OTHER /* exclusive_option() */
#include "optutils.h"
#include "nls.h"
#include "ttyutils.h"
+
+#define XALLOC_EXIT_CODE BLKID_EXIT_OTHER /* x.*alloc(), xstrndup() */
#include "xalloc.h"
struct blkid_control {
lowprobe:1,
lowprobe_superblocks:1,
lowprobe_topology:1,
+ no_part_details:1,
raw_chars:1;
};
-static void print_version(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
- fprintf(out, _("%s from %s (libblkid %s, %s)\n"),
- program_invocation_short_name, PACKAGE_STRING,
- LIBBLKID_VERSION, LIBBLKID_DATE);
-}
-
-static void usage(int error)
-{
- FILE *out = error ? stderr : stdout;
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out, _( " %s --label <label> | --uuid <uuid>\n\n"), program_invocation_short_name);
fputs(_( " -O, --offset <offset> probe at the given offset\n"), out);
fputs(_( " -u, --usages <list> filter by \"usage\" (e.g. -u filesystem,raid)\n"), out);
fputs(_( " -n, --match-types <list> filter by filesystem type (e.g. -n vfat,ext3)\n"), out);
+ fputs(_( " -D, --no-part-details don't print info from partition table\n"), out);
fputs(USAGE_SEPARATOR, out);
- fputs(USAGE_HELP, out);
- fputs(USAGE_VERSION, out);
- fprintf(out, USAGE_MAN_TAIL("blkid(8)"));
- exit(error);
+ printf(USAGE_HELP_OPTIONS(28));
+ printf(USAGE_MAN_TAIL("blkid(8)"));
+ exit(EXIT_SUCCESS);
}
/*
mtpt[0] = 0;
retval = check_mount_point(devname, &mount_flags, mtpt, sizeof(mtpt));
if (retval == 0) {
+ const char *msg = NULL;
+
if (mount_flags & MF_MOUNTED) {
if (!mtpt[0])
- strcpy(mtpt, _("(mounted, mtpt unknown)"));
+ msg = _("(mounted, mtpt unknown)");
} else if (mount_flags & MF_BUSY)
- strcpy(mtpt, _("(in use)"));
+ msg = _("(in use)");
else
- strcpy(mtpt, _("(not mounted)"));
+ msg = _("(not mounted)");
+
+ if (msg)
+ xstrncpy(mtpt, msg, sizeof(mtpt));
}
pretty_print_line(devname, fs_type, label, mtpt, uuid);
printf("ID_FS_%s=%s\n", name, enc);
} else if (!strcmp(name, "UUID") ||
- !strcmp(name, "LABEL") ||
+ !strncmp(name, "LABEL", 5) ||
!strcmp(name, "UUID_SUB")) {
blkid_safe_string(value, safe, sizeof(safe));
return rc;
}
-static int lowprobe_superblocks(blkid_probe pr)
+static int lowprobe_superblocks(blkid_probe pr, struct blkid_control *ctl)
{
struct stat st;
int rc, fd = blkid_probe_get_fd(pr);
return 0; /* partition table detected */
}
- blkid_probe_set_partitions_flags(pr, BLKID_PARTS_ENTRY_DETAILS);
+ if (!ctl->no_part_details)
+ blkid_probe_set_partitions_flags(pr, BLKID_PARTS_ENTRY_DETAILS);
blkid_probe_enable_superblocks(pr, 1);
return blkid_do_safeprobe(pr);
int rc = 0;
static int first = 1;
- fd = open(devname, O_RDONLY|O_CLOEXEC);
+ fd = open(devname, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
if (fd < 0) {
warn(_("error: %s"), devname);
return BLKID_EXIT_NOTFOUND;
if (ctl->lowprobe_topology)
rc = lowprobe_topology(pr);
if (rc >= 0 && ctl->lowprobe_superblocks)
- rc = lowprobe_superblocks(pr);
+ rc = lowprobe_superblocks(pr, ctl);
if (rc < 0)
goto done;
continue;
if (ctl->show[0] && !has_item(ctl, name))
continue;
- len = strnlen((char *) data, len);
- print_value(ctl, num++, devname, (char *) data, name, len);
+ len = strnlen(data, len);
+ print_value(ctl, num++, devname, data, name, len);
}
if (first)
static const struct option longopts[] = {
{ "cache-file", required_argument, NULL, 'c' },
{ "no-encoding", no_argument, NULL, 'd' },
+ { "no-part-details", no_argument, NULL, 'D' },
{ "garbage-collect", no_argument, NULL, 'g' },
{ "output", required_argument, NULL, 'o' },
{ "list-filesystems", no_argument, NULL, 'k' },
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- atexit(close_stdout);
+ close_stdout_atexit();
+
+ strutils_set_exitcode(BLKID_EXIT_OTHER);
while ((c = getopt_long (argc, argv,
- "c:dghilL:n:ko:O:ps:S:t:u:U:w:Vv", longopts, NULL)) != -1) {
+ "c:DdghilL:n:ko:O:ps:S:t:u:U:w:Vv", longopts, NULL)) != -1) {
err_exclusive_options(c, NULL, excl, excl_st);
case 'd':
ctl.raw_chars = 1;
break;
+ case 'D':
+ ctl.no_part_details = 1;
+ break;
case 'L':
ctl.eval = 1;
search_value = xstrdup(optarg);
case 's':
if (numtag + 1 >= sizeof(ctl.show) / sizeof(*ctl.show)) {
warnx(_("Too many tags specified"));
- errtryh(err);
+ errtryhelp(err);
}
ctl.show[numtag++] = optarg;
break;
if (search_type) {
warnx(_("Can only search for "
"one NAME=value pair"));
- errtryh(err);
+ errtryhelp(err);
}
if (blkid_parse_tag_string(optarg,
&search_type,
&search_value)) {
warnx(_("-t needs NAME=value pair"));
- errtryh(err);
+ errtryhelp(err);
}
break;
case 'V':
case 'v':
- print_version(stdout);
+ fprintf(stdout, _("%s from %s (libblkid %s, %s)\n"),
+ program_invocation_short_name, PACKAGE_STRING,
+ LIBBLKID_VERSION, LIBBLKID_DATE);
+ err = 0;
goto exit;
case 'w':
/* ignore - backward compatibility */
break;
case 'h':
- usage(0);
+ usage();
break;
default:
- errtryh(EXIT_FAILURE);
+ errtryhelp(EXIT_FAILURE);
}
}