]> git.ipfire.org Git - thirdparty/util-linux.git/blob - libblkid/src/superblocks/superblocks.c
987a647d56dad8bb49586f1f75af9b4931920461
[thirdparty/util-linux.git] / libblkid / src / superblocks / superblocks.c
1 /*
2 * superblocks.c - reads information from filesystem and raid superblocks
3 *
4 * Copyright (C) 2008-2009 Karel Zak <kzak@redhat.com>
5 *
6 * This file may be redistributed under the terms of the
7 * GNU Lesser General Public License.
8 */
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <ctype.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <errno.h>
19 #include <stdint.h>
20 #include <stdarg.h>
21
22 #include "superblocks.h"
23
24 /**
25 * SECTION:superblocks
26 * @title: Superblocks probing
27 * @short_description: filesystems and raids superblocks probing.
28 *
29 * The library API has been originally designed for superblocks probing only.
30 * This is reason why some *deprecated* superblock specific functions don't use
31 * '_superblocks_' namespace in the function name. Please, don't use these
32 * functions in new code.
33 *
34 * The 'superblocks' probers support NAME=value (tags) interface only. The
35 * superblocks probing is enabled by default (and controlled by
36 * blkid_probe_enable_superblocks()).
37 *
38 * Currently supported tags:
39 *
40 * @TYPE: filesystem type
41 *
42 * @SEC_TYPE: secondary filesystem type
43 *
44 * @LABEL: filesystem label
45 *
46 * @LABEL_RAW: raw label from FS superblock
47 *
48 * @UUID: filesystem UUID (lower case)
49 *
50 * @UUID_SUB: subvolume uuid (e.g. btrfs)
51 *
52 * @LOGUUID: external log UUID (e.g. xfs)
53 *
54 * @UUID_RAW: raw UUID from FS superblock
55 *
56 * @EXT_JOURNAL: external journal UUID
57 *
58 * @USAGE: usage string: "raid", "filesystem", ...
59 *
60 * @VERSION: filesystem version
61 *
62 * @MOUNT: cluster mount name (?) -- ocfs only
63 *
64 * @SBMAGIC: super block magic string
65 *
66 * @SBMAGIC_OFFSET: offset of SBMAGIC
67 *
68 * @FSSIZE: size of filessystem [not-implemented yet]
69 *
70 * @SYSTEM_ID: ISO9660 system identifier
71 *
72 * @PUBLISHER_ID: ISO9660 publisher identifier
73 *
74 * @APPLICATION_ID: ISO9660 application identifier
75 *
76 * @BOOT_SYSTEM_ID: ISO9660 boot system identifier
77 */
78
79 static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn);
80 static int superblocks_safeprobe(blkid_probe pr, struct blkid_chain *chn);
81
82 static int blkid_probe_set_usage(blkid_probe pr, int usage);
83
84
85 /*
86 * Superblocks chains probing functions
87 */
88 static const struct blkid_idinfo *idinfos[] =
89 {
90 /* RAIDs */
91 &linuxraid_idinfo,
92 &ddfraid_idinfo,
93 &iswraid_idinfo,
94 &lsiraid_idinfo,
95 &viaraid_idinfo,
96 &silraid_idinfo,
97 &nvraid_idinfo,
98 &pdcraid_idinfo,
99 &highpoint45x_idinfo,
100 &highpoint37x_idinfo,
101 &adraid_idinfo,
102 &jmraid_idinfo,
103
104 &bcache_idinfo,
105 &drbd_idinfo,
106 &drbdmanage_idinfo,
107 &drbdproxy_datalog_idinfo,
108 &lvm2_idinfo,
109 &lvm1_idinfo,
110 &snapcow_idinfo,
111 &verity_hash_idinfo,
112 &luks_idinfo,
113 &vmfs_volume_idinfo,
114
115 /* Filesystems */
116 &vfat_idinfo,
117 &swsuspend_idinfo,
118 &swap_idinfo,
119 &xfs_idinfo,
120 &xfs_log_idinfo,
121 &ext4dev_idinfo,
122 &ext4_idinfo,
123 &ext3_idinfo,
124 &ext2_idinfo,
125 &jbd_idinfo,
126 &reiser_idinfo,
127 &reiser4_idinfo,
128 &jfs_idinfo,
129 &udf_idinfo,
130 &iso9660_idinfo,
131 &zfs_idinfo,
132 &hfsplus_idinfo,
133 &hfs_idinfo,
134 &ufs_idinfo,
135 &hpfs_idinfo,
136 &sysv_idinfo,
137 &xenix_idinfo,
138 &ntfs_idinfo,
139 &refs_idinfo,
140 &cramfs_idinfo,
141 &romfs_idinfo,
142 &minix_idinfo,
143 &gfs_idinfo,
144 &gfs2_idinfo,
145 &ocfs_idinfo,
146 &ocfs2_idinfo,
147 &oracleasm_idinfo,
148 &vxfs_idinfo,
149 &squashfs_idinfo,
150 &squashfs3_idinfo,
151 &netware_idinfo,
152 &btrfs_idinfo,
153 &ubifs_idinfo,
154 &bfs_idinfo,
155 &vmfs_fs_idinfo,
156 &befs_idinfo,
157 &nilfs2_idinfo,
158 &exfat_idinfo,
159 &f2fs_idinfo
160 };
161
162 /*
163 * Driver definition
164 */
165 const struct blkid_chaindrv superblocks_drv = {
166 .id = BLKID_CHAIN_SUBLKS,
167 .name = "superblocks",
168 .dflt_enabled = TRUE,
169 .dflt_flags = BLKID_SUBLKS_DEFAULT,
170 .idinfos = idinfos,
171 .nidinfos = ARRAY_SIZE(idinfos),
172 .has_fltr = TRUE,
173 .probe = superblocks_probe,
174 .safeprobe = superblocks_safeprobe,
175 };
176
177 /**
178 * blkid_probe_enable_superblocks:
179 * @pr: probe
180 * @enable: TRUE/FALSE
181 *
182 * Enables/disables the superblocks probing for non-binary interface.
183 *
184 * Returns: 0 on success, or -1 in case of error.
185 */
186 int blkid_probe_enable_superblocks(blkid_probe pr, int enable)
187 {
188 if (!pr)
189 return -1;
190 pr->chains[BLKID_CHAIN_SUBLKS].enabled = enable;
191 return 0;
192 }
193
194 /**
195 * blkid_probe_set_superblocks_flags:
196 * @pr: prober
197 * @flags: BLKID_SUBLKS_* flags
198 *
199 * Sets probing flags to the superblocks prober. This function is optional, the
200 * default are BLKID_SUBLKS_DEFAULTS flags.
201 *
202 * Returns: 0 on success, or -1 in case of error.
203 */
204 int blkid_probe_set_superblocks_flags(blkid_probe pr, int flags)
205 {
206 if (!pr)
207 return -1;
208
209 pr->chains[BLKID_CHAIN_SUBLKS].flags = flags;
210 return 0;
211 }
212
213 /**
214 * blkid_probe_reset_superblocks_filter:
215 * @pr: prober
216 *
217 * Resets superblocks probing filter
218 *
219 * Returns: 0 on success, or -1 in case of error.
220 */
221 int blkid_probe_reset_superblocks_filter(blkid_probe pr)
222 {
223 return __blkid_probe_reset_filter(pr, BLKID_CHAIN_SUBLKS);
224 }
225
226 /**
227 * blkid_probe_invert_superblocks_filter:
228 * @pr: prober
229 *
230 * Inverts superblocks probing filter
231 *
232 * Returns: 0 on success, or -1 in case of error.
233 */
234 int blkid_probe_invert_superblocks_filter(blkid_probe pr)
235 {
236 return __blkid_probe_invert_filter(pr, BLKID_CHAIN_SUBLKS);
237 }
238
239 /**
240 * blkid_probe_filter_superblocks_type:
241 * @pr: prober
242 * @flag: filter BLKID_FLTR_{NOTIN,ONLYIN} flag
243 * @names: NULL terminated array of probing function names (e.g. "vfat").
244 *
245 * %BLKID_FLTR_NOTIN - probe for all items which are NOT IN @names;
246 *
247 * %BLKID_FLTR_ONLYIN - probe for items which are IN @names
248 *
249 * Returns: 0 on success, or -1 in case of error.
250 */
251 int blkid_probe_filter_superblocks_type(blkid_probe pr, int flag, char *names[])
252 {
253 return __blkid_probe_filter_types(pr, BLKID_CHAIN_SUBLKS, flag, names);
254 }
255
256 /**
257 * blkid_probe_filter_superblocks_usage:
258 * @pr: prober
259 * @flag: filter BLKID_FLTR_{NOTIN,ONLYIN} flag
260 * @usage: BLKID_USAGE_* flags
261 *
262 * %BLKID_FLTR_NOTIN - probe for all items which are NOT IN @usage;
263 *
264 * %BLKID_FLTR_ONLYIN - probe for items which are IN @usage
265 *
266 * Returns: 0 on success, or -1 in case of error.
267 */
268 int blkid_probe_filter_superblocks_usage(blkid_probe pr, int flag, int usage)
269 {
270 unsigned long *fltr;
271 struct blkid_chain *chn;
272 size_t i;
273
274 fltr = blkid_probe_get_filter(pr, BLKID_CHAIN_SUBLKS, TRUE);
275 if (!fltr)
276 return -1;
277
278 chn = &pr->chains[BLKID_CHAIN_SUBLKS];
279
280 for (i = 0; i < chn->driver->nidinfos; i++) {
281 const struct blkid_idinfo *id = chn->driver->idinfos[i];
282
283 if (id->usage & usage) {
284 if (flag & BLKID_FLTR_NOTIN)
285 blkid_bmp_set_item(chn->fltr, i);
286 } else if (flag & BLKID_FLTR_ONLYIN)
287 blkid_bmp_set_item(chn->fltr, i);
288 }
289 DBG(LOWPROBE, ul_debug("a new probing usage-filter initialized"));
290 return 0;
291 }
292
293 /**
294 * blkid_known_fstype:
295 * @fstype: filesystem name
296 *
297 * Returns: 1 for known filesytems, or 0 for unknown filesystem.
298 */
299 int blkid_known_fstype(const char *fstype)
300 {
301 size_t i;
302
303 if (!fstype)
304 return 0;
305
306 for (i = 0; i < ARRAY_SIZE(idinfos); i++) {
307 const struct blkid_idinfo *id = idinfos[i];
308 if (strcmp(id->name, fstype) == 0)
309 return 1;
310 }
311 return 0;
312 }
313
314 /**
315 * blkid_superblocks_get_name:
316 * @idx: number >= 0
317 * @name: returns name of supported filesystem/raid (optional)
318 * @usage: returns BLKID_USAGE_* flags, (optional)
319 *
320 * Returns: -1 if @idx is out of range, or 0 on success.
321 */
322 int blkid_superblocks_get_name(size_t idx, const char **name, int *usage)
323 {
324 if (idx < ARRAY_SIZE(idinfos)) {
325 if (name)
326 *name = idinfos[idx]->name;
327 if (usage)
328 *usage = idinfos[idx]->usage;
329 return 0;
330 }
331 return -1;
332 }
333
334 /*
335 * The blkid_do_probe() backend.
336 */
337 static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
338 {
339 size_t i;
340 int rc = BLKID_PROBE_NONE;
341
342 if (!pr || chn->idx < -1)
343 return -EINVAL;
344
345 blkid_probe_chain_reset_values(pr, chn);
346
347 if (pr->flags & BLKID_FL_NOSCAN_DEV)
348 return BLKID_PROBE_NONE;
349
350 if (pr->size <= 0 || (pr->size <= 1024 && !S_ISCHR(pr->mode)))
351 /* Ignore very very small block devices or regular files (e.g.
352 * extended partitions). Note that size of the UBI char devices
353 * is 1 byte */
354 return BLKID_PROBE_NONE;
355
356 DBG(LOWPROBE, ul_debug("--> starting probing loop [SUBLKS idx=%d]",
357 chn->idx));
358
359 i = chn->idx < 0 ? 0 : chn->idx + 1U;
360
361 for ( ; i < ARRAY_SIZE(idinfos); i++) {
362 const struct blkid_idinfo *id;
363 const struct blkid_idmag *mag = NULL;
364 uint64_t off = 0;
365
366 chn->idx = i;
367 id = idinfos[i];
368
369 if (chn->fltr && blkid_bmp_get_item(chn->fltr, i)) {
370 DBG(LOWPROBE, ul_debug("filter out: %s", id->name));
371 rc = BLKID_PROBE_NONE;
372 continue;
373 }
374
375 if (id->minsz && (unsigned)id->minsz > pr->size) {
376 rc = BLKID_PROBE_NONE;
377 continue; /* the device is too small */
378 }
379
380 /* don't probe for RAIDs, swap or journal on CD/DVDs */
381 if ((id->usage & (BLKID_USAGE_RAID | BLKID_USAGE_OTHER)) &&
382 blkid_probe_is_cdrom(pr)) {
383 rc = BLKID_PROBE_NONE;
384 continue;
385 }
386
387 /* don't probe for RAIDs on floppies */
388 if ((id->usage & BLKID_USAGE_RAID) && blkid_probe_is_tiny(pr)) {
389 rc = BLKID_PROBE_NONE;
390 continue;
391 }
392
393 DBG(LOWPROBE, ul_debug("[%zd] %s:", i, id->name));
394
395 rc = blkid_probe_get_idmag(pr, id, &off, &mag);
396 if (rc < 0)
397 break;
398 if (rc != BLKID_PROBE_OK)
399 continue;
400
401 /* final check by probing function */
402 if (id->probefunc) {
403 DBG(LOWPROBE, ul_debug("\tcall probefunc()"));
404 rc = id->probefunc(pr, mag);
405 if (rc != BLKID_PROBE_OK) {
406 blkid_probe_chain_reset_values(pr, chn);
407 if (rc < 0)
408 break;
409 continue;
410 }
411 }
412
413 /* all cheks passed */
414 if (chn->flags & BLKID_SUBLKS_TYPE)
415 rc = blkid_probe_set_value(pr, "TYPE",
416 (unsigned char *) id->name,
417 strlen(id->name) + 1);
418
419 if (!rc)
420 rc = blkid_probe_set_usage(pr, id->usage);
421
422 if (!rc && mag)
423 rc = blkid_probe_set_magic(pr, off, mag->len,
424 (unsigned char *) mag->magic);
425 if (rc) {
426 blkid_probe_chain_reset_values(pr, chn);
427 DBG(LOWPROBE, ul_debug("failed to set result -- ignore"));
428 continue;
429 }
430
431 DBG(LOWPROBE, ul_debug("<-- leaving probing loop (type=%s) [SUBLKS idx=%d]",
432 id->name, chn->idx));
433 return BLKID_PROBE_OK;
434 }
435
436 DBG(LOWPROBE, ul_debug("<-- leaving probing loop (failed=%d) [SUBLKS idx=%d]",
437 rc, chn->idx));
438 return rc;
439 }
440
441 /*
442 * This is the same function as blkid_do_probe(), but returns only one result
443 * (cannot be used in while()) and checks for ambivalen results (more
444 * filesystems on the device) -- in such case returns -2.
445 *
446 * The function does not check for filesystems when a RAID or crypto signature
447 * is detected. The function also does not check for collision between RAIDs
448 * and crypto devices. The first detected RAID or crypto device is returned.
449 *
450 * The function does not probe for ambivalent results on very small devices
451 * (e.g. floppies), on small devices the first detected filesystem is returned.
452 */
453 static int superblocks_safeprobe(blkid_probe pr, struct blkid_chain *chn)
454 {
455 struct list_head vals;
456 int idx = -1;
457 int count = 0;
458 int intol = 0;
459 int rc;
460
461 INIT_LIST_HEAD(&vals);
462
463 if (pr->flags & BLKID_FL_NOSCAN_DEV)
464 return BLKID_PROBE_NONE;
465
466 while ((rc = superblocks_probe(pr, chn)) == 0) {
467
468 if (blkid_probe_is_tiny(pr) && !count)
469 return BLKID_PROBE_OK; /* floppy or so -- returns the first result. */
470
471 count++;
472
473 if (chn->idx >= 0 &&
474 idinfos[chn->idx]->usage & (BLKID_USAGE_RAID | BLKID_USAGE_CRYPTO))
475 break;
476
477 if (chn->idx >= 0 &&
478 !(idinfos[chn->idx]->flags & BLKID_IDINFO_TOLERANT))
479 intol++;
480
481 if (count == 1) {
482 /* save the first result */
483 blkid_probe_chain_save_values(pr, chn, &vals);
484 idx = chn->idx;
485 }
486 }
487
488 if (rc < 0)
489 goto done; /* error */
490
491 if (count > 1 && intol) {
492 DBG(LOWPROBE, ul_debug("ERROR: superblocks chain: "
493 "ambivalent result detected (%d filesystems)!",
494 count));
495 rc = -2; /* error, ambivalent result (more FS) */
496 goto done;
497 }
498 if (!count) {
499 rc = BLKID_PROBE_NONE;
500 goto done;
501 }
502
503 if (idx != -1) {
504 /* restore the first result */
505 blkid_probe_chain_reset_values(pr, chn);
506 blkid_probe_append_values_list(pr, &vals);
507 chn->idx = idx;
508 }
509
510 /*
511 * The RAID device could be partitioned. The problem are RAID1 devices
512 * where the partition table is visible from underlaying devices. We
513 * have to ignore such partition tables.
514 */
515 if (chn->idx >= 0 && idinfos[chn->idx]->usage & BLKID_USAGE_RAID)
516 pr->prob_flags |= BLKID_PROBE_FL_IGNORE_PT;
517
518 rc = BLKID_PROBE_OK;
519 done:
520 blkid_probe_free_values_list(&vals);
521 return rc;
522 }
523
524 int blkid_probe_set_version(blkid_probe pr, const char *version)
525 {
526 struct blkid_chain *chn = blkid_probe_get_chain(pr);
527
528 if (chn->flags & BLKID_SUBLKS_VERSION)
529 return blkid_probe_set_value(pr, "VERSION",
530 (unsigned char *) version, strlen(version) + 1);
531 return 0;
532 }
533
534
535 int blkid_probe_sprintf_version(blkid_probe pr, const char *fmt, ...)
536 {
537 struct blkid_chain *chn = blkid_probe_get_chain(pr);
538 int rc = 0;
539
540 if (chn->flags & BLKID_SUBLKS_VERSION) {
541 va_list ap;
542
543 va_start(ap, fmt);
544 rc = blkid_probe_vsprintf_value(pr, "VERSION", fmt, ap);
545 va_end(ap);
546 }
547 return rc;
548 }
549
550 static int blkid_probe_set_usage(blkid_probe pr, int usage)
551 {
552 struct blkid_chain *chn = blkid_probe_get_chain(pr);
553 char *u = NULL;
554
555 if (!(chn->flags & BLKID_SUBLKS_USAGE))
556 return 0;
557
558 if (usage & BLKID_USAGE_FILESYSTEM)
559 u = "filesystem";
560 else if (usage & BLKID_USAGE_RAID)
561 u = "raid";
562 else if (usage & BLKID_USAGE_CRYPTO)
563 u = "crypto";
564 else if (usage & BLKID_USAGE_OTHER)
565 u = "other";
566 else
567 u = "unknown";
568
569 return blkid_probe_set_value(pr, "USAGE", (unsigned char *) u, strlen(u) + 1);
570 }
571
572 int blkid_probe_set_id_label(blkid_probe pr, const char *name,
573 unsigned char *data, size_t len)
574 {
575 struct blkid_chain *chn = blkid_probe_get_chain(pr);
576 struct blkid_prval *v;
577 int rc = 0;
578
579 if (!(chn->flags & BLKID_SUBLKS_LABEL))
580 return 0;
581
582 v = blkid_probe_assign_value(pr, name);
583 if (!v)
584 return -ENOMEM;
585
586 rc = blkid_probe_value_set_data(v, data, len);
587 if (!rc) {
588 /* remove white spaces */
589 v->len = blkid_rtrim_whitespace(v->data) + 1;
590 if (v->len > 1)
591 v->len = blkid_ltrim_whitespace(v->data) + 1;
592 if (v->len > 1)
593 return 0;
594 }
595
596 blkid_probe_free_value(v);
597 return rc;
598
599 }
600
601 int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name,
602 unsigned char *data, size_t len, int enc)
603 {
604 struct blkid_chain *chn = blkid_probe_get_chain(pr);
605 struct blkid_prval *v;
606 int rc = 0;
607
608 if (!(chn->flags & BLKID_SUBLKS_LABEL))
609 return 0;
610
611 v = blkid_probe_assign_value(pr, name);
612 if (!v)
613 return -ENOMEM;
614
615 v->data = blkid_encode_alloc(len, &v->len);
616 if (!v->data)
617 rc = -ENOMEM;
618
619 if (!rc) {
620 blkid_encode_to_utf8(enc, v->data, v->len, data, len);
621 v->len = blkid_rtrim_whitespace(v->data) + 1;
622 if (v->len > 1)
623 v->len = blkid_ltrim_whitespace(v->data) + 1;
624 if (v->len > 1)
625 return 0;
626 }
627
628 blkid_probe_free_value(v);
629 return rc;
630 }
631
632 int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len)
633 {
634 struct blkid_chain *chn = blkid_probe_get_chain(pr);
635 struct blkid_prval *v;
636 int rc = 0;
637
638 if ((chn->flags & BLKID_SUBLKS_LABELRAW) &&
639 (rc = blkid_probe_set_value(pr, "LABEL_RAW", label, len)) < 0)
640 return rc;
641
642 if (!(chn->flags & BLKID_SUBLKS_LABEL))
643 return 0;
644
645 v = blkid_probe_assign_value(pr, "LABEL");
646 if (!v)
647 return -ENOMEM;
648
649 rc = blkid_probe_value_set_data(v, label, len);
650 if (!rc) {
651 v->len = blkid_rtrim_whitespace(v->data) + 1;
652 if (v->len > 1)
653 return 0;
654 }
655
656 blkid_probe_free_value(v);
657 return rc;
658 }
659
660 int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
661 size_t len, int enc)
662 {
663 struct blkid_chain *chn = blkid_probe_get_chain(pr);
664 struct blkid_prval *v;
665 int rc = 0;
666
667 if ((chn->flags & BLKID_SUBLKS_LABELRAW) &&
668 (rc = blkid_probe_set_value(pr, "LABEL_RAW", label, len)) < 0)
669 return rc;
670
671 if (!(chn->flags & BLKID_SUBLKS_LABEL))
672 return 0;
673
674 v = blkid_probe_assign_value(pr, "LABEL");
675 if (!v)
676 return -ENOMEM;
677
678 v->data = blkid_encode_alloc(len, &v->len);
679 if (!v->data)
680 rc = -ENOMEM;
681 if (!rc) {
682 blkid_encode_to_utf8(enc, v->data, v->len, label, len);
683 v->len = blkid_rtrim_whitespace(v->data) + 1;
684 if (v->len > 1)
685 return 0;
686 }
687
688 blkid_probe_free_value(v);
689 return rc;
690 }
691
692 int blkid_probe_sprintf_uuid(blkid_probe pr, unsigned char *uuid,
693 size_t len, const char *fmt, ...)
694 {
695 struct blkid_chain *chn = blkid_probe_get_chain(pr);
696 va_list ap;
697 int rc = 0;
698
699 if (blkid_uuid_is_empty(uuid, len))
700 return 0;
701
702 if ((chn->flags & BLKID_SUBLKS_UUIDRAW) &&
703 (rc = blkid_probe_set_value(pr, "UUID_RAW", uuid, len)) < 0)
704 return rc;
705
706 if (!(chn->flags & BLKID_SUBLKS_UUID))
707 return 0;
708
709 va_start(ap, fmt);
710 rc = blkid_probe_vsprintf_value(pr, "UUID", fmt, ap);
711 va_end(ap);
712
713 return rc;
714 }
715
716 /* function to set UUIDs that are in suberblocks stored as strings */
717 int blkid_probe_strncpy_uuid(blkid_probe pr, unsigned char *str, size_t len)
718 {
719 struct blkid_chain *chn = blkid_probe_get_chain(pr);
720 struct blkid_prval *v;
721 int rc = 0;
722
723 if (str == NULL || *str == '\0')
724 return -EINVAL;
725
726 if (!len)
727 len = strlen((char *) str);
728
729 if ((chn->flags & BLKID_SUBLKS_UUIDRAW) &&
730 (rc = blkid_probe_set_value(pr, "UUID_RAW", str, len)) < 0)
731 return rc;
732
733 if (!(chn->flags & BLKID_SUBLKS_UUID))
734 return 0;
735
736 v = blkid_probe_assign_value(pr, "UUID");
737 if (!v)
738 rc= -ENOMEM;
739 if (!rc)
740 rc = blkid_probe_value_set_data(v, str, len);
741 if (!rc) {
742 v->len = blkid_rtrim_whitespace(v->data) + 1;
743 if (v->len > 1)
744 return 0;
745 }
746
747 blkid_probe_free_value(v);
748 return rc;
749 }
750
751 /* default _set_uuid function to set DCE UUIDs */
752 int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *name)
753 {
754 struct blkid_chain *chn = blkid_probe_get_chain(pr);
755 struct blkid_prval *v;
756 int rc = 0;
757
758 if (blkid_uuid_is_empty(uuid, 16))
759 return 0;
760
761 if (!name) {
762 if ((chn->flags & BLKID_SUBLKS_UUIDRAW) &&
763 (rc = blkid_probe_set_value(pr, "UUID_RAW", uuid, 16)) < 0)
764 return rc;
765
766 if (!(chn->flags & BLKID_SUBLKS_UUID))
767 return 0;
768
769 v = blkid_probe_assign_value(pr, "UUID");
770 } else
771 v = blkid_probe_assign_value(pr, name);
772
773 if (!v)
774 return -ENOMEM;
775
776 v->len = 37;
777 v->data = calloc(1, v->len);
778 if (!v->data)
779 rc = -ENOMEM;
780
781 if (!rc) {
782 blkid_unparse_uuid(uuid, (char *) v->data, v->len);
783 return 0;
784 }
785
786 blkid_probe_free_value(v);
787 return rc;
788 }
789
790 int blkid_probe_set_uuid(blkid_probe pr, unsigned char *uuid)
791 {
792 return blkid_probe_set_uuid_as(pr, uuid, NULL);
793 }
794
795 /**
796 * blkid_probe_set_request:
797 * @pr: probe
798 * @flags: BLKID_PROBREQ_* (deprecated) or BLKID_SUBLKS_* flags
799 *
800 * Returns: 0 on success, or -1 in case of error.
801 *
802 * Deprecated: Use blkid_probe_set_superblocks_flags().
803 */
804 int blkid_probe_set_request(blkid_probe pr, int flags)
805 {
806 return blkid_probe_set_superblocks_flags(pr, flags);
807 }
808
809 /**
810 * blkid_probe_reset_filter:
811 * @pr: prober
812 *
813 * Returns: 0 on success, or -1 in case of error.
814 *
815 * Deprecated: Use blkid_probe_reset_superblocks_filter().
816 */
817 int blkid_probe_reset_filter(blkid_probe pr)
818 {
819 return __blkid_probe_reset_filter(pr, BLKID_CHAIN_SUBLKS);
820 }
821
822 /**
823 * blkid_probe_invert_filter:
824 * @pr: prober
825 *
826 * Returns: 0 on success, or -1 in case of error.
827 *
828 * Deprecated: Use blkid_probe_invert_superblocks_filter().
829 */
830 int blkid_probe_invert_filter(blkid_probe pr)
831 {
832 return __blkid_probe_invert_filter(pr, BLKID_CHAIN_SUBLKS);
833 }
834
835 /**
836 * blkid_probe_filter_types
837 * @pr: prober
838 * @flag: filter BLKID_FLTR_{NOTIN,ONLYIN} flag
839 * @names: NULL terminated array of probing function names (e.g. "vfat").
840 *
841 * Returns: 0 on success, or -1 in case of error.
842 *
843 * Deprecated: Use blkid_probe_filter_superblocks_types().
844 */
845 int blkid_probe_filter_types(blkid_probe pr, int flag, char *names[])
846 {
847 return __blkid_probe_filter_types(pr, BLKID_CHAIN_SUBLKS, flag, names);
848 }
849
850 /**
851 * blkid_probe_filter_usage
852 * @pr: prober
853 * @flag: filter BLKID_FLTR_{NOTIN,ONLYIN} flag
854 * @usage: BLKID_USAGE_* flags
855 *
856 * Returns: 0 on success, or -1 in case of error.
857 *
858 * Deprecated: Use blkid_probe_filter_superblocks_usage().
859 */
860 int blkid_probe_filter_usage(blkid_probe pr, int flag, int usage)
861 {
862 return blkid_probe_filter_superblocks_usage(pr, flag, usage);
863 }
864
865