2 * Low-level libblkid probing API
4 * Copyright (C) 2008-2009 Karel Zak <kzak@redhat.com>
6 * This file may be redistributed under the terms of the
7 * GNU Lesser General Public License.
12 * @title: Low-level probing
13 * @short_description: low-level prober initialization
15 * The low-level probing routines always and directly read information from
16 * the selected (see blkid_probe_set_device()) device.
18 * The probing routines are grouped together into separate chains. Currently,
19 * the librray provides superblocks, partitions and topology chains.
21 * The probing routines is possible to filter (enable/disable) by type (e.g.
22 * fstype "vfat" or partype "gpt") or by usage flags (e.g. BLKID_USAGE_RAID).
23 * These filters are per-chain. Note that always when you touch the chain
24 * filter the current probing position is reseted and probing starts from
25 * scratch. It means that the chain filter should not be modified during
26 * probing, for example in loop where you call blkid_do_probe().
28 * For more details see the chain specific documentation.
30 * The low-level API provides two ways how access to probing results.
32 * 1. The NAME=value (tag) interface. This interface is older and returns all data
33 * as strings. This interface is generic for all chains.
35 * 2. The binary interfaces. These interfaces return data in the native formats.
36 * The interface is always specific to the probing chain.
41 * SECTION: lowprobe-tags
42 * @title: Low-level tags
43 * @short_description: generic NAME=value interface.
45 * The probing routines inside the chain are mutually exclusive by default --
46 * only few probing routines are marked as "tolerant". The "tolerant" probing
47 * routines are used for filesystem which can share the same device with any
48 * other filesystem. The blkid_do_safeprobe() checks for the "tolerant" flag.
50 * The SUPERBLOCKS chain is enabled by default. The all others chains is
51 * necessary to enable by blkid_probe_enable_'CHAINNAME'(). See chains specific
54 * The blkid_do_probe() function returns a result from only one probing
55 * routine, and the next call from the next probing routine. It means you need
56 * to call the function in loop, for example:
60 * while((blkid_do_probe(pr) == 0)
65 * The blkid_do_safeprobe() is the same as blkid_do_probe(), but returns only
66 * first probing result for every enabled chain. This function checks for
67 * ambivalent results (e.g. more "intolerant" filesystems superblocks on the
70 * The probing result is set of NAME=value pairs (the NAME is always unique).
79 #include <sys/types.h>
80 #ifdef HAVE_SYS_STAT_H
83 #ifdef HAVE_SYS_MKDEV_H
84 #include <sys/mkdev.h>
93 # ifdef HAVE_UUID_UUID_H
94 # include <uuid/uuid.h>
104 extern const struct blkid_chaindrv superblocks_drv
;
105 extern const struct blkid_chaindrv topology_drv
;
106 extern const struct blkid_chaindrv partitions_drv
;
109 * All supported chains
111 static const struct blkid_chaindrv
*chains_drvs
[] = {
112 [BLKID_CHAIN_SUBLKS
] = &superblocks_drv
,
113 [BLKID_CHAIN_TOPLGY
] = &topology_drv
,
114 [BLKID_CHAIN_PARTS
] = &partitions_drv
117 static void blkid_probe_reset_vals(blkid_probe pr
);
118 static void blkid_probe_reset_buffer(blkid_probe pr
);
123 * Returns: a pointer to the newly allocated probe struct.
125 blkid_probe
blkid_new_probe(void)
131 pr
= calloc(1, sizeof(struct blkid_struct_probe
));
135 /* initialize chains */
136 for (i
= 0; i
< BLKID_NCHAINS
; i
++) {
137 pr
->chains
[i
].driver
= chains_drvs
[i
];
138 pr
->chains
[i
].flags
= chains_drvs
[i
]->dflt_flags
;
139 pr
->chains
[i
].enabled
= chains_drvs
[i
]->dflt_enabled
;
141 INIT_LIST_HEAD(&pr
->buffers
);
146 * blkid_new_probe_from_filename:
147 * @filename: device or regular file
149 * This function is same as call open(filename), blkid_new_probe() and
150 * blkid_probe_set_device(pr, fd, 0, 0).
152 * The @filename is closed by blkid_free_probe() or by the
153 * blkid_probe_set_device() call.
155 * Returns: a pointer to the newly allocated probe struct or NULL in case of
158 blkid_probe
blkid_new_probe_from_filename(const char *filename
)
161 blkid_probe pr
= NULL
;
166 fd
= open(filename
, O_RDONLY
);
170 pr
= blkid_new_probe();
174 if (blkid_probe_set_device(pr
, fd
, 0, 0))
177 pr
->flags
|= BLKID_PRIVATE_FD
;
182 blkid_free_probe(pr
);
190 * Deallocates the probe struct, buffers and all allocated
191 * data that are associated with this probing control struct.
193 void blkid_free_probe(blkid_probe pr
)
200 for (i
= 0; i
< BLKID_NCHAINS
; i
++) {
201 struct blkid_chain
*ch
= &pr
->chains
[i
];
203 if (ch
->driver
->free_data
)
204 ch
->driver
->free_data(pr
, ch
->data
);
208 if ((pr
->flags
& BLKID_PRIVATE_FD
) && pr
->fd
>= 0)
210 blkid_probe_reset_buffer(pr
);
216 * Removes chain values from probing result.
218 void blkid_probe_chain_reset_vals(blkid_probe pr
, struct blkid_chain
*chn
)
220 int nvals
= pr
->nvals
;
223 for (x
= 0, i
= 0; i
< pr
->nvals
; i
++) {
224 struct blkid_prval
*v
= &pr
->vals
[i
];
226 if (v
->chain
!= chn
&& x
== i
) {
230 if (v
->chain
== chn
) {
234 memcpy(&pr
->vals
[x
++], v
, sizeof(struct blkid_prval
));
239 static void blkid_probe_chain_reset_position(struct blkid_chain
*chn
)
246 * Copies chain values from probing result to @vals, the max size of @vals is
247 * @nvals and returns real number of values.
249 int blkid_probe_chain_copy_vals(blkid_probe pr
, struct blkid_chain
*chn
,
250 struct blkid_prval
*vals
, int nvals
)
254 for (x
= 0, i
= 0; i
< pr
->nvals
&& x
< nvals
; i
++) {
255 struct blkid_prval
*v
= &pr
->vals
[i
];
259 memcpy(&vals
[x
++], v
, sizeof(struct blkid_prval
));
265 * Appends values from @vals to the probing result
267 void blkid_probe_append_vals(blkid_probe pr
, struct blkid_prval
*vals
, int nvals
)
271 while (i
< nvals
&& pr
->nvals
< BLKID_NVALS
) {
272 memcpy(&pr
->vals
[pr
->nvals
++], &vals
[i
++],
273 sizeof(struct blkid_prval
));
277 static void blkid_probe_reset_vals(blkid_probe pr
)
279 memset(pr
->vals
, 0, sizeof(pr
->vals
));
283 struct blkid_chain
*blkid_probe_get_chain(blkid_probe pr
)
285 return pr
->cur_chain
;
288 void *blkid_probe_get_binary_data(blkid_probe pr
, struct blkid_chain
*chn
)
297 blkid_probe_chain_reset_position(chn
);
299 rc
= chn
->driver
->probe(pr
, chn
);
302 pr
->cur_chain
= NULL
;
303 blkid_probe_chain_reset_position(chn
);
309 printf("returning %s binary data\n", chn
->driver
->name
));
318 * Zeroize probing results and resets the current probing (this has impact to
319 * blkid_do_probe() only). This function does not touch probing filters and
320 * keeps assigned device.
322 void blkid_reset_probe(blkid_probe pr
)
329 blkid_probe_reset_buffer(pr
);
330 blkid_probe_reset_vals(pr
);
332 pr
->cur_chain
= NULL
;
334 for (i
= 0; i
< BLKID_NCHAINS
; i
++)
335 blkid_probe_chain_reset_position(&pr
->chains
[i
]);
339 static int blkid_probe_dump_filter(blkid_probe pr, int chain)
341 struct blkid_chain *chn;
344 if (!pr || chain < 0 || chain >= BLKID_NCHAINS)
347 chn = &pr->chains[chain];
352 for (i = 0; i < chn->driver->nidinfos; i++) {
353 const struct blkid_idinfo *id = chn->driver->idinfos[i];
355 DBG(DEBUG_LOWPROBE, printf("%d: %s: %s\n",
358 blkid_bmp_get_item(chn->fltr, i)
359 ? "disabled" : "enabled <--"));
366 * Returns properly initialized chain filter
368 unsigned long *blkid_probe_get_filter(blkid_probe pr
, int chain
, int create
)
370 struct blkid_chain
*chn
;
372 if (!pr
|| chain
< 0 || chain
>= BLKID_NCHAINS
)
375 chn
= &pr
->chains
[chain
];
377 /* always when you touch the chain filter all indexes are reseted and
378 * probing starts from scratch
380 blkid_probe_chain_reset_position(chn
);
381 pr
->cur_chain
= NULL
;
383 if (!chn
->driver
->has_fltr
|| (!chn
->fltr
&& !create
))
387 chn
->fltr
= calloc(1, blkid_bmp_nbytes(chn
->driver
->nidinfos
));
389 memset(chn
->fltr
, 0, blkid_bmp_nbytes(chn
->driver
->nidinfos
));
391 /* blkid_probe_dump_filter(pr, chain); */
396 * Generic private functions for filter setting
398 int __blkid_probe_invert_filter(blkid_probe pr
, int chain
)
401 struct blkid_chain
*chn
;
404 fltr
= blkid_probe_get_filter(pr
, chain
, FALSE
);
408 chn
= &pr
->chains
[chain
];
410 for (i
= 0; i
< blkid_bmp_nwords(chn
->driver
->nidinfos
); i
++)
413 DBG(DEBUG_LOWPROBE
, printf("probing filter inverted\n"));
414 /* blkid_probe_dump_filter(pr, chain); */
418 int __blkid_probe_reset_filter(blkid_probe pr
, int chain
)
420 return blkid_probe_get_filter(pr
, chain
, FALSE
) ? 0 : -1;
423 int __blkid_probe_filter_types(blkid_probe pr
, int chain
, int flag
, char *names
[])
426 struct blkid_chain
*chn
;
429 fltr
= blkid_probe_get_filter(pr
, chain
, TRUE
);
433 chn
= &pr
->chains
[chain
];
435 for (i
= 0; i
< chn
->driver
->nidinfos
; i
++) {
437 const struct blkid_idinfo
*id
= chn
->driver
->idinfos
[i
];
440 for (n
= names
; *n
; n
++) {
441 if (!strcmp(id
->name
, *n
)) {
446 if (flag
& BLKID_FLTR_ONLYIN
) {
448 blkid_bmp_set_item(fltr
, i
);
449 } else if (flag
& BLKID_FLTR_NOTIN
) {
451 blkid_bmp_set_item(fltr
, i
);
456 printf("%s: a new probing type-filter initialized\n",
458 /* blkid_probe_dump_filter(pr, chain); */
462 unsigned char *blkid_probe_get_buffer(blkid_probe pr
,
463 blkid_loff_t off
, blkid_loff_t len
)
466 struct blkid_bufinfo
*bf
= NULL
;
471 list_for_each(p
, &pr
->buffers
) {
472 struct blkid_bufinfo
*x
=
473 list_entry(p
, struct blkid_bufinfo
, bufs
);
475 if (x
->off
<= off
&& off
+ len
<= x
->off
+ x
->len
) {
477 printf("\treuse buffer: off=%jd len=%jd\n",
486 if (blkid_llseek(pr
->fd
, pr
->off
+ off
, SEEK_SET
) < 0)
489 /* allocate info and space for data by why call */
490 bf
= calloc(1, sizeof(struct blkid_bufinfo
) + len
);
494 bf
->data
= ((unsigned char *) bf
) + sizeof(struct blkid_bufinfo
);
497 INIT_LIST_HEAD(&bf
->bufs
);
500 printf("\tbuffer read: off=%jd len=%jd\n", off
, len
));
502 ret
= read(pr
->fd
, bf
->data
, len
);
503 if (ret
!= (ssize_t
) len
) {
507 list_add_tail(&bf
->bufs
, &pr
->buffers
);
510 return off
? bf
->data
+ (off
- bf
->off
) : bf
->data
;
514 static void blkid_probe_reset_buffer(blkid_probe pr
)
516 ssize_t read_ct
= 0, len_ct
= 0;
518 if (!pr
|| list_empty(&pr
->buffers
))
521 DBG(DEBUG_LOWPROBE
, printf("reseting probing buffers\n"));
523 while (!list_empty(&pr
->buffers
)) {
524 struct blkid_bufinfo
*bf
= list_entry(pr
->buffers
.next
,
525 struct blkid_bufinfo
, bufs
);
534 printf("buffers summary: %jd bytes by %jd read() call(s)\n",
537 INIT_LIST_HEAD(&pr
->buffers
);
541 * Small devices need a special care.
543 int blkid_probe_is_tiny(blkid_probe pr
)
545 return pr
&& (pr
->flags
& BLKID_TINY_DEV
);
549 * blkid_probe_set_device:
551 * @fd: device file descriptor
552 * @off: begin of probing area
553 * @size: size of probing area (zero means whole device/file)
555 * Assigns the device to probe control struct, resets internal buffers and
556 * resets the current probing.
558 * Returns: -1 in case of failure, or 0 on success.
560 int blkid_probe_set_device(blkid_probe pr
, int fd
,
561 blkid_loff_t off
, blkid_loff_t size
)
566 blkid_reset_probe(pr
);
568 if ((pr
->flags
& BLKID_PRIVATE_FD
) && pr
->fd
>= 0)
571 pr
->flags
&= ~BLKID_PRIVATE_FD
;
572 pr
->flags
&= ~BLKID_TINY_DEV
;
580 #if defined(POSIX_FADV_RANDOM) && defined(HAVE_POSIX_FADVISE)
581 /* Disable read-ahead */
582 posix_fadvise(fd
, 0, 0, POSIX_FADV_RANDOM
);
592 pr
->mode
= sb
.st_mode
;
594 if (S_ISBLK(sb
.st_mode
)) {
595 if (blkdev_get_size(fd
, (unsigned long long *) &pr
->size
)) {
596 DBG(DEBUG_LOWPROBE
, printf(
597 "failed to get device size\n"));
600 } else if (S_ISCHR(sb
.st_mode
))
601 pr
->size
= 1; /* UBI devices are char... */
602 else if (S_ISREG(sb
.st_mode
))
603 pr
->size
= sb
.st_size
; /* regular file */
605 if (S_ISBLK(sb
.st_mode
) || S_ISCHR(sb
.st_mode
))
606 pr
->devno
= sb
.st_rdev
;
608 if (pr
->off
> pr
->size
)
611 /* The probing area cannot be larger than whole device, pr->off
612 * is offset within the device */
616 DBG(DEBUG_LOWPROBE
, printf("ready for low-probing, offset=%jd, size=%jd\n",
619 if (pr
->size
<= 1440 * 1024 && !S_ISCHR(pr
->mode
))
620 pr
->flags
|= BLKID_TINY_DEV
;
625 printf("failed to prepare a device for low-probing\n"));
630 int blkid_probe_get_dimension(blkid_probe pr
,
631 blkid_loff_t
*off
, blkid_loff_t
*size
)
641 int blkid_probe_set_dimension(blkid_probe pr
,
642 blkid_loff_t off
, blkid_loff_t size
)
647 DBG(DEBUG_LOWPROBE
, printf(
648 "changing probing area: size=%llu, off=%llu "
649 "-to-> size=%llu, off=%llu\n",
650 (unsigned long long) pr
->size
,
651 (unsigned long long) pr
->off
,
652 (unsigned long long) size
,
653 (unsigned long long) off
));
657 pr
->flags
&= ~BLKID_TINY_DEV
;
659 if (pr
->size
<= 1440 * 1024 && !S_ISCHR(pr
->mode
))
660 pr
->flags
|= BLKID_TINY_DEV
;
662 blkid_probe_reset_buffer(pr
);
671 * Calls probing functions in all enabled chains. The superblocks chain is
672 * enabled by default. The blkid_do_probe() stores result from only one
673 * probing function. It's necessary to call this routine in a loop to get
674 * results from all probing functions in all chains. The probing is reseted
675 * by blkid_reset_probe() or by filter functions.
677 * This is string-based NAME=value interface only.
680 * <title>basic case - use the first result only</title>
683 * if (blkid_do_probe(pr) == 0) {
684 * int nvals = blkid_probe_numof_values(pr);
685 * for (n = 0; n < nvals; n++) {
686 * if (blkid_probe_get_value(pr, n, &name, &data, &len) == 0)
687 * printf("%s = %s\n", name, data);
694 * <title>advanced case - probe for all signatures</title>
697 * while (blkid_do_probe(pr) == 0) {
698 * int nvals = blkid_probe_numof_values(pr);
704 * See also blkid_reset_probe().
706 * Returns: 0 on success, 1 when probing is done and -1 in case of error.
708 int blkid_do_probe(blkid_probe pr
)
716 struct blkid_chain
*chn
= pr
->cur_chain
;
719 chn
= pr
->cur_chain
= &pr
->chains
[0];
721 /* we go to the next chain only when the previous probing
722 * result was nothing (rc == 1) and when the current chain is
723 * disabled or we are at end of the current chain (chain->idx +
726 else if (rc
== 1 && (chn
->enabled
== FALSE
||
727 chn
->idx
+ 1 == chn
->driver
->nidinfos
)) {
729 int idx
= chn
->driver
->id
+ 1;
731 if (idx
< BLKID_NCHAINS
)
732 chn
= pr
->cur_chain
= &pr
->chains
[idx
];
734 return 1; /* all chains already probed */
737 chn
->binary
= FALSE
; /* for sure... */
739 DBG(DEBUG_LOWPROBE
, printf("chain probe %s %s (idx=%d)\n",
741 chn
->enabled
? "ENABLED" : "DISABLED",
747 /* rc: -1 = error, 0 = success, 1 = no result */
748 rc
= chn
->driver
->probe(pr
, chn
);
756 * blkid_do_safeprobe:
759 * This function gathers probing results from all enabled chains and checks
760 * for ambivalent results (e.g. more filesystems on the device).
762 * This is string-based NAME=value interface only.
764 * Note about suberblocks chain -- the function does not check for filesystems
765 * when a RAID signature is detected. The function also does not check for
766 * collision between RAIDs. The first detected RAID is returned.
768 * Returns: 0 on success, 1 if nothing is detected, -2 if ambivalen result is
769 * detected and -1 on case of error.
771 int blkid_do_safeprobe(blkid_probe pr
)
773 int i
, count
= 0, rc
= 0;
778 for (i
= 0; i
< BLKID_NCHAINS
; i
++) {
779 struct blkid_chain
*chn
;
781 chn
= pr
->cur_chain
= &pr
->chains
[i
];
782 chn
->binary
= FALSE
; /* for sure... */
784 DBG(DEBUG_LOWPROBE
, printf("chain safeprobe %s %s\n",
786 chn
->enabled
? "ENABLED" : "DISABLED"));
791 blkid_probe_chain_reset_position(chn
);
793 rc
= chn
->driver
->safeprobe(pr
, chn
);
795 blkid_probe_chain_reset_position(chn
);
797 /* rc: -2 ambivalent, -1 = error, 0 = success, 1 = no result */
799 goto done
; /* error */
801 count
++; /* success */
805 pr
->cur_chain
= NULL
;
808 return count
? 0 : 1;
812 * blkid_do_fullprobe:
815 * This function gathers probing results from all enabled chains. Same as
816 * blkid_so_safeprobe() but does not check for collision between probing
819 * This is string-based NAME=value interface only.
821 * Returns: 0 on success, 1 if nothing is detected or -1 on case of error.
823 int blkid_do_fullprobe(blkid_probe pr
)
825 int i
, count
= 0, rc
= 0;
830 for (i
= 0; i
< BLKID_NCHAINS
; i
++) {
832 struct blkid_chain
*chn
;
834 chn
= pr
->cur_chain
= &pr
->chains
[i
];
835 chn
->binary
= FALSE
; /* for sure... */
837 DBG(DEBUG_LOWPROBE
, printf("chain fullprobe %s: %s\n",
839 chn
->enabled
? "ENABLED" : "DISABLED"));
844 blkid_probe_chain_reset_position(chn
);
846 rc
= chn
->driver
->probe(pr
, chn
);
848 blkid_probe_chain_reset_position(chn
);
850 /* rc: -1 = error, 0 = success, 1 = no result */
852 goto done
; /* error */
854 count
++; /* success */
858 pr
->cur_chain
= NULL
;
861 return count
? 0 : 1;
864 /* same sa blkid_probe_get_buffer() but works with 512-sectors */
865 unsigned char *blkid_probe_get_sector(blkid_probe pr
, unsigned int sector
)
867 return pr
? blkid_probe_get_buffer(pr
,
868 ((blkid_loff_t
) sector
) << 9, 0x200) : NULL
;
871 struct blkid_prval
*blkid_probe_assign_value(
872 blkid_probe pr
, const char *name
)
874 struct blkid_prval
*v
;
878 if (pr
->nvals
>= BLKID_NVALS
)
881 v
= &pr
->vals
[pr
->nvals
];
883 v
->chain
= pr
->cur_chain
;
887 printf("assigning %s [%s]\n", name
, v
->chain
->driver
->name
));
891 int blkid_probe_reset_last_value(blkid_probe pr
)
893 struct blkid_prval
*v
;
895 if (pr
== NULL
|| pr
->nvals
== 0)
898 v
= &pr
->vals
[pr
->nvals
- 1];
901 printf("un-assigning %s [%s]\n", v
->name
, v
->chain
->driver
->name
));
903 memset(v
, 0, sizeof(struct blkid_prval
));
910 int blkid_probe_set_value(blkid_probe pr
, const char *name
,
911 unsigned char *data
, size_t len
)
913 struct blkid_prval
*v
;
915 if (len
> BLKID_PROBVAL_BUFSIZ
)
916 len
= BLKID_PROBVAL_BUFSIZ
;
918 v
= blkid_probe_assign_value(pr
, name
);
922 memcpy(v
->data
, data
, len
);
927 int blkid_probe_vsprintf_value(blkid_probe pr
, const char *name
,
928 const char *fmt
, va_list ap
)
930 struct blkid_prval
*v
;
933 v
= blkid_probe_assign_value(pr
, name
);
937 len
= vsnprintf((char *) v
->data
, sizeof(v
->data
), fmt
, ap
);
940 blkid_probe_reset_last_value(pr
);
947 int blkid_probe_sprintf_value(blkid_probe pr
, const char *name
,
948 const char *fmt
, ...)
954 rc
= blkid_probe_vsprintf_value(pr
, name
, fmt
, ap
);
961 * blkid_probe_get_devno:
964 * Returns: block device number, or 0 for regilar files.
966 dev_t
blkid_probe_get_devno(blkid_probe pr
)
971 if (fstat(pr
->fd
, &sb
) == 0 &&
972 (S_ISBLK(sb
.st_mode
) || S_ISCHR(sb
.st_mode
)))
973 pr
->devno
= sb
.st_rdev
;
979 * blkid_probe_get_size:
982 * This function returns size of probing area as defined by blkid_probe_set_device().
983 * If the size of the probing area is unrestricted then this function returns
984 * the real size of device. See also blkid_get_dev_size().
986 * Returns: size in bytes or -1 in case of error.
988 blkid_loff_t
blkid_probe_get_size(blkid_probe pr
)
990 return pr
? pr
->size
: -1;
994 * blkid_probe_get_sectorsize:
997 * Returns: block device logical sector size (BLKSSZGET ioctl, default 512).
999 unsigned int blkid_probe_get_sectorsize(blkid_probe pr
)
1002 return DEFAULT_SECTOR_SIZE
; /*... and good luck! */
1008 if (fstat(pr
->fd
, &st
))
1010 pr
->mode
= st
.st_mode
;
1012 if (S_ISBLK(pr
->mode
)) {
1013 if (blkdev_get_sector_size(pr
->fd
, (int *) &pr
->blkssz
))
1020 pr
->blkssz
= DEFAULT_SECTOR_SIZE
;
1025 * blkid_probe_numof_values:
1028 * Returns: number of values in probing result or -1 in case of error.
1030 int blkid_probe_numof_values(blkid_probe pr
)
1038 * blkid_probe_get_value:
1040 * @num: wanted value in range 0..N, where N is blkid_probe_numof_values() - 1
1041 * @name: pointer to return value name or NULL
1042 * @data: pointer to return value data or NULL
1043 * @len: pointer to return value length or NULL
1045 * Note, the @len returns length of the @data, including the terminating
1048 * Returns: 0 on success, or -1 in case of error.
1050 int blkid_probe_get_value(blkid_probe pr
, int num
, const char **name
,
1051 const char **data
, size_t *len
)
1053 struct blkid_prval
*v
= __blkid_probe_get_value(pr
, num
);
1060 *data
= (char *) v
->data
;
1064 DBG(DEBUG_LOWPROBE
, printf("returning %s value\n", v
->name
));
1069 * blkid_probe_lookup_value:
1071 * @name: name of value
1072 * @data: pointer to return value data or NULL
1073 * @len: pointer to return value length or NULL
1075 * Note, the @len returns length of the @data, including the terminating
1078 * Returns: 0 on success, or -1 in case of error.
1080 int blkid_probe_lookup_value(blkid_probe pr
, const char *name
,
1081 const char **data
, size_t *len
)
1083 struct blkid_prval
*v
= __blkid_probe_lookup_value(pr
, name
);
1088 *data
= (char *) v
->data
;
1095 * blkid_probe_has_value:
1097 * @name: name of value
1099 * Returns: 1 if value exist in probing result, otherwise 0.
1101 int blkid_probe_has_value(blkid_probe pr
, const char *name
)
1103 if (blkid_probe_lookup_value(pr
, name
, NULL
, NULL
) == 0)
1108 struct blkid_prval
*__blkid_probe_get_value(blkid_probe pr
, int num
)
1110 if (pr
== NULL
|| num
< 0 || num
>= pr
->nvals
)
1113 return &pr
->vals
[num
];
1116 struct blkid_prval
*__blkid_probe_lookup_value(blkid_probe pr
, const char *name
)
1120 if (pr
== NULL
|| pr
->nvals
== 0 || name
== NULL
)
1123 for (i
= 0; i
< pr
->nvals
; i
++) {
1124 struct blkid_prval
*v
= &pr
->vals
[i
];
1126 if (v
->name
&& strcmp(name
, v
->name
) == 0) {
1127 DBG(DEBUG_LOWPROBE
, printf("returning %s value\n", v
->name
));
1135 /* converts DCE UUID (uuid[16]) to human readable string
1136 * - the @len should be always 37 */
1137 void blkid_unparse_uuid(const unsigned char *uuid
, char *str
, size_t len
)
1140 uuid_unparse(uuid
, str
);
1143 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1144 uuid
[0], uuid
[1], uuid
[2], uuid
[3],
1148 uuid
[10], uuid
[11], uuid
[12], uuid
[13], uuid
[14],uuid
[15]);
1153 /* Removes whitespace from the right-hand side of a string (trailing
1156 * Returns size of the new string (without \0).
1158 size_t blkid_rtrim_whitespace(unsigned char *str
)
1160 size_t i
= strlen((char *) str
);
1163 if (!isspace(str
[i
]))