Skip to content

Commit

Permalink
blkid: make PART_ENTRY_* tags optional (add --no-part-details)
Browse files Browse the repository at this point in the history
blkid(8) returns information from partition table also for empty
partitions. This is necessary for example for udev, but it could be
confusing if you care about on-device content only.

Default:
 # blkid -p /dev/md0p1; echo $?
 /dev/md0p1: PART_ENTRY_SCHEME="dos" PART_ENTRY_UUID="6d8796b1-01" PART_ENTRY_TYPE="0x83" PART_ENTRY_NUMBER="1" PART_ENTRY_OFFSET="2048" PART_ENTRY_SIZE="204800" PART_ENTRY_DISK="9:0"
 0

With --no-part-details:
 # blkid -p /dev/md0p1 --no-part-details; echo $?
 2

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1653413
Signed-off-by: Karel Zak <[email protected]>
  • Loading branch information
karelzak committed Nov 29, 2018
1 parent 4850e97 commit 5e91d5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion misc-utils/blkid.8
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ blkid \- locate/print block device attributes
.IR list ]
.RB [ \-\-usages
.IR list ]
.RB [ \-\-no\-part\-details ]
.IR device " ..."

.IP \fBblkid\fR
Expand Down Expand Up @@ -114,6 +115,9 @@ Don't encode non-printing characters. The non-printing characters are encoded
by ^ and M- notation by default. Note that the \fB\-\-output udev\fR output format uses
a different encoding which cannot be disabled.
.TP
\fB\-D\fR, \fB\-\-no\-part\-details\fR
Don't print information (PART_ENTRY_* tags) from partition table in low-level probing mode.
.TP
\fB\-g\fR, \fB\-\-garbage\-collect\fR
Perform a garbage collection pass on the blkid cache to remove
devices which no longer exist.
Expand Down Expand Up @@ -224,7 +228,7 @@ Note that low-level probing also returns information about partition table type
(PTTYPE tag) and partitions (PART_ENTRY_* tags). The tag names produced by
low-level probing are based on names used internally by libblkid and it may be
different than when executed without \fB\-\-probe\fR (for example PART_ENTRY_UUID= vs
PARTUUID=).
PARTUUID=). See also \fB\-\-no\-part\-details\fR.
.TP
\fB\-s\fR, \fB\-\-match\-tag\fR \fItag\fR
For each (specified) device, show only the tags that match
Expand Down
15 changes: 11 additions & 4 deletions misc-utils/blkid.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct blkid_control {
lowprobe:1,
lowprobe_superblocks:1,
lowprobe_topology:1,
no_part_details:1,
raw_chars:1;
};

Expand Down Expand Up @@ -101,6 +102,7 @@ static void __attribute__((__noreturn__)) usage(void)
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);
printf(USAGE_HELP_OPTIONS(28));
Expand Down Expand Up @@ -444,7 +446,7 @@ static int print_udev_ambivalent(blkid_probe pr)
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);
Expand All @@ -470,7 +472,8 @@ static int lowprobe_superblocks(blkid_probe 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);
Expand Down Expand Up @@ -509,7 +512,7 @@ static int lowprobe_device(blkid_probe pr, const char *devname,
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;

Expand Down Expand Up @@ -661,6 +664,7 @@ int main(int argc, char **argv)
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' },
Expand Down Expand Up @@ -694,7 +698,7 @@ int main(int argc, char **argv)
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);

Expand All @@ -705,6 +709,9 @@ int main(int argc, char **argv)
case 'd':
ctl.raw_chars = 1;
break;
case 'D':
ctl.no_part_details = 1;
break;
case 'L':
ctl.eval = 1;
search_value = xstrdup(optarg);
Expand Down

0 comments on commit 5e91d5d

Please sign in to comment.