blkid: add cmdline interface for blkid_probe_filter_usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
deedaa3053
commit
0bdd2f97fc
|
@ -13,19 +13,10 @@
|
||||||
- test blkid within udev rules
|
- test blkid within udev rules
|
||||||
|
|
||||||
|
|
||||||
- add command line interface for blkid_probe_filter_usage():
|
- add command line interface for blkid_probe_filter_types():
|
||||||
|
|
||||||
# blkid -p -o udev --filter-usage filesystems
|
|
||||||
|
|
||||||
# blkid -p -o udev --filter-usage noraid
|
|
||||||
|
|
||||||
and blkid_probe_filter_types():
|
|
||||||
|
|
||||||
# blkid -p -o udev --filter-type nofat
|
# blkid -p -o udev --filter-type nofat
|
||||||
|
|
||||||
note that "--filter-usage" is necessary for compatibility with vol_id where
|
|
||||||
we in udev rules use things like "vol_id --skip-raid"
|
|
||||||
|
|
||||||
- (?) we need to ignore cache and config files when the files are writable
|
- (?) we need to ignore cache and config files when the files are writable
|
||||||
for non-root users and the library is linked with suid programs
|
for non-root users and the library is linked with suid programs
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@ blkid \- command\-line utility to locate/print block device attributes
|
||||||
.IR size ]
|
.IR size ]
|
||||||
.RB [ \-o
|
.RB [ \-o
|
||||||
.IR format ]
|
.IR format ]
|
||||||
|
.RB [ \-u
|
||||||
|
.IR list ]
|
||||||
.I device
|
.I device
|
||||||
[\fIdevice\fR ...]
|
[\fIdevice\fR ...]
|
||||||
|
|
||||||
|
@ -93,6 +95,20 @@ udev symlinks (depends on setting in /etc/blkid.conf). Avoid to use the
|
||||||
symlinks directly. It is not reliable to use the symlinks without verification.
|
symlinks directly. It is not reliable to use the symlinks without verification.
|
||||||
The \fB-L\fR option is portable and works on systems with and without udev.
|
The \fB-L\fR option is portable and works on systems with and without udev.
|
||||||
.TP
|
.TP
|
||||||
|
.B \-u " list "
|
||||||
|
Restrict probing functions to defined (comma separated) list of "usage" types.
|
||||||
|
Supported usage types are: filesystem, raid, crypto and other. The list can be
|
||||||
|
prefixed with "no" to specify the usage types which should be ignored. For example:
|
||||||
|
.sp
|
||||||
|
blkid -p -u filesystem,other /dev/sda1
|
||||||
|
.sp
|
||||||
|
probes for all filesystems and others (e.g. swap) formats, and
|
||||||
|
.sp
|
||||||
|
blkid -p -u noraid /dev/sda1
|
||||||
|
.sp
|
||||||
|
probes for all supported formats exclude RAIDs. This option is useful with
|
||||||
|
\fB-p\fR only.
|
||||||
|
.TP
|
||||||
.B \-U " uuid "
|
.B \-U " uuid "
|
||||||
Look up one device that uses the uuid. For more details see the \fB-L\fR option.
|
Look up one device that uses the uuid. For more details see the \fB-L\fR option.
|
||||||
.TP
|
.TP
|
||||||
|
@ -138,7 +154,7 @@ In order to just refresh the cache without showing any tokens, use
|
||||||
with no other options.
|
with no other options.
|
||||||
.TP
|
.TP
|
||||||
.BI \-S " bytes"
|
.BI \-S " bytes"
|
||||||
Ooverwrite device/file size (only useful with \fB-p\fR).
|
Overwrite device/file size (only useful with \fB-p\fR).
|
||||||
.TP
|
.TP
|
||||||
.BI \-t " NAME" = "value"
|
.BI \-t " NAME" = "value"
|
||||||
Search for block devices with tokens named
|
Search for block devices with tokens named
|
||||||
|
|
|
@ -76,7 +76,9 @@ static void usage(int error)
|
||||||
"Low-level probing options:\n"
|
"Low-level probing options:\n"
|
||||||
" -p switch to low-level mode (bypass cache)\n"
|
" -p switch to low-level mode (bypass cache)\n"
|
||||||
" -S <bytes> overwrite device size\n"
|
" -S <bytes> overwrite device size\n"
|
||||||
" -O <bytes> probe at the given offset\n\n",
|
" -O <bytes> probe at the given offset\n"
|
||||||
|
" -u <list> filter by \"usage\" (e.g. -u filesystem,raid)\n"
|
||||||
|
"\n",
|
||||||
progname);
|
progname);
|
||||||
|
|
||||||
exit(error);
|
exit(error);
|
||||||
|
@ -361,6 +363,38 @@ error:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* converts comma separated list to BLKID_USAGE_* mask */
|
||||||
|
static int list_to_usage(const char *list, int *flag)
|
||||||
|
{
|
||||||
|
int mask = 0;
|
||||||
|
const char *word, *p = list;
|
||||||
|
|
||||||
|
if (p && strncmp(p, "no", 2) == 0) {
|
||||||
|
*flag = BLKID_FLTR_NOTIN;
|
||||||
|
p += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (word = p; p && *p; p++) {
|
||||||
|
if (*p == ',' || *(p + 1) == '\0') {
|
||||||
|
if (!strncmp(word, "filesystem", 10))
|
||||||
|
mask |= BLKID_USAGE_FILESYSTEM;
|
||||||
|
else if (!strncmp(word, "raid", 4))
|
||||||
|
mask |= BLKID_USAGE_RAID;
|
||||||
|
else if (!strncmp(word, "crypto", 6))
|
||||||
|
mask |= BLKID_USAGE_CRYPTO;
|
||||||
|
else if (!strncmp(word, "other", 5))
|
||||||
|
mask |= BLKID_USAGE_OTHER;
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "unknown usage keyword '%*s'\n",
|
||||||
|
(int) (p - word), word);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
word = p + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
blkid_cache cache = NULL;
|
blkid_cache cache = NULL;
|
||||||
|
@ -369,6 +403,8 @@ int main(int argc, char **argv)
|
||||||
char *search_type = NULL, *search_value = NULL;
|
char *search_type = NULL, *search_value = NULL;
|
||||||
char *read = NULL;
|
char *read = NULL;
|
||||||
char *write = NULL;
|
char *write = NULL;
|
||||||
|
int fltr_usage = 0;
|
||||||
|
int fltr_flag = BLKID_FLTR_ONLYIN;
|
||||||
unsigned int numdev = 0, numtag = 0;
|
unsigned int numdev = 0, numtag = 0;
|
||||||
int version = 0;
|
int version = 0;
|
||||||
int err = 4;
|
int err = 4;
|
||||||
|
@ -378,7 +414,7 @@ int main(int argc, char **argv)
|
||||||
int c;
|
int c;
|
||||||
blkid_loff_t offset = 0, size = 0;
|
blkid_loff_t offset = 0, size = 0;
|
||||||
|
|
||||||
while ((c = getopt (argc, argv, "c:f:ghlL:o:O:ps:S:t:U:w:v")) != EOF)
|
while ((c = getopt (argc, argv, "c:f:ghlL:o:O:ps:S:t:u:U:w:v")) != EOF)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'c':
|
case 'c':
|
||||||
if (optarg && !*optarg)
|
if (optarg && !*optarg)
|
||||||
|
@ -393,6 +429,9 @@ int main(int argc, char **argv)
|
||||||
search_value = strdup(optarg);
|
search_value = strdup(optarg);
|
||||||
search_type = strdup("LABEL");
|
search_type = strdup("LABEL");
|
||||||
break;
|
break;
|
||||||
|
case 'u':
|
||||||
|
fltr_usage = list_to_usage(optarg, &fltr_flag);
|
||||||
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
eval++;
|
eval++;
|
||||||
search_value = strdup(optarg);
|
search_value = strdup(optarg);
|
||||||
|
@ -509,6 +548,9 @@ int main(int argc, char **argv)
|
||||||
BLKID_PROBREQ_LABEL | BLKID_PROBREQ_UUID |
|
BLKID_PROBREQ_LABEL | BLKID_PROBREQ_UUID |
|
||||||
BLKID_PROBREQ_TYPE | BLKID_PROBREQ_SECTYPE |
|
BLKID_PROBREQ_TYPE | BLKID_PROBREQ_SECTYPE |
|
||||||
BLKID_PROBREQ_USAGE | BLKID_PROBREQ_VERSION);
|
BLKID_PROBREQ_USAGE | BLKID_PROBREQ_VERSION);
|
||||||
|
if (fltr_usage &&
|
||||||
|
blkid_probe_filter_usage(pr, fltr_flag, fltr_usage))
|
||||||
|
goto exit;
|
||||||
|
|
||||||
for (i = 0; i < numdev; i++)
|
for (i = 0; i < numdev; i++)
|
||||||
err += lowprobe_device(pr, devices[i],
|
err += lowprobe_device(pr, devices[i],
|
||||||
|
|
Loading…
Reference in New Issue