- test blkid within udev rules
- - add command line interface for blkid_probe_filter_usage():
-
- # blkid -p -o udev --filter-usage filesystems
-
- # blkid -p -o udev --filter-usage noraid
-
- and blkid_probe_filter_types():
+ - add command line interface for blkid_probe_filter_types():
# 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
for non-root users and the library is linked with suid programs
.IR size ]
.RB [ \-o
.IR format ]
+.RB [ \-u
+.IR list ]
.I device
[\fIdevice\fR ...]
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.
.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 "
Look up one device that uses the uuid. For more details see the \fB-L\fR option.
.TP
with no other options.
.TP
.BI \-S " bytes"
-Ooverwrite device/file size (only useful with \fB-p\fR).
+Overwrite device/file size (only useful with \fB-p\fR).
.TP
.BI \-t " NAME" = "value"
Search for block devices with tokens named
"Low-level probing options:\n"
" -p switch to low-level mode (bypass cache)\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);
exit(error);
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)
{
blkid_cache cache = NULL;
char *search_type = NULL, *search_value = NULL;
char *read = NULL;
char *write = NULL;
+ int fltr_usage = 0;
+ int fltr_flag = BLKID_FLTR_ONLYIN;
unsigned int numdev = 0, numtag = 0;
int version = 0;
int err = 4;
int c;
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) {
case 'c':
if (optarg && !*optarg)
search_value = strdup(optarg);
search_type = strdup("LABEL");
break;
+ case 'u':
+ fltr_usage = list_to_usage(optarg, &fltr_flag);
+ break;
case 'U':
eval++;
search_value = strdup(optarg);
BLKID_PROBREQ_LABEL | BLKID_PROBREQ_UUID |
BLKID_PROBREQ_TYPE | BLKID_PROBREQ_SECTYPE |
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++)
err += lowprobe_device(pr, devices[i],