Low-level tags

Low-level tags — generic NAME=value interface.

Functions

Description

The probing routines inside the chain are mutually exclusive by default -- only few probing routines are marked as "tolerant". The "tolerant" probing routines are used for filesystem which can share the same device with any other filesystem. The blkid_do_safeprobe() checks for the "tolerant" flag.

The SUPERBLOCKS chain is enabled by default. The all others chains is necessary to enable by blkid_probe_enable_'CHAINNAME'(). See chains specific documentation.

The blkid_do_probe() function returns a result from only one probing routine, and the next call from the next probing routine. It means you need to call the function in loop, for example:

1
2
while((blkid_do_probe(pr) == 0)
    ... use result ...

The blkid_do_safeprobe() is the same as blkid_do_probe(), but returns only first probing result for every enabled chain. This function checks for ambivalent results (e.g. more "intolerant" filesystems superblocks on the device).

The probing result is set of NAME=value pairs (the NAME is always unique).

Functions

blkid_do_fullprobe ()

int
blkid_do_fullprobe (blkid_probe pr);

This function gathers probing results from all enabled chains. Same as blkid_do_safeprobe() but does not check for collision between probing result.

This is string-based NAME=value interface only.

Parameters

pr

prober

 

Returns

0 on success, 1 if nothing is detected or -1 on case of error.


blkid_do_wipe ()

int
blkid_do_wipe (blkid_probe pr,
               int dryrun);

This function erases the current signature detected by pr . The pr has to be open in O_RDWR mode, BLKID_SUBLKS_MAGIC or/and BLKID_PARTS_MAGIC flags has to be enabled (if you want to erase also superblock with broken check sums then use BLKID_SUBLKS_BADCSUM too).

After successful signature removing the pr prober will be moved one step back and the next blkid_do_probe() call will again call previously called probing function. All in-memory cached data from the device are always reseted.

Example 2. wipe all filesystems or raids from the device

1
2
3
4
5
6
7
8
fd = open(devname, O_RDWR|O_CLOEXEC);
blkid_probe_set_device(pr, fd, 0, 0);

blkid_probe_enable_superblocks(pr, 1);
blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC);

while (blkid_do_probe(pr) == 0)
    blkid_do_wipe(pr, FALSE);

See also blkid_probe_step_back() if you cannot use this build-in wipe function, but you want to use libblkid probing as a source for wiping.

Parameters

pr

prober

 

dryrun

if TRUE then don't touch the device.

 

Returns

0 on success, and -1 in case of error.


blkid_do_probe ()

int
blkid_do_probe (blkid_probe pr);

Calls probing functions in all enabled chains. The superblocks chain is enabled by default. The blkid_do_probe() stores result from only one probing function. It's necessary to call this routine in a loop to get results from all probing functions in all chains. The probing is reset by blkid_reset_probe() or by filter functions.

This is string-based NAME=value interface only.

Example 3. basic case - use the first result only

1
2
3
4
5
6
7
if (blkid_do_probe(pr) == 0) {
    int nvals = blkid_probe_numof_values(pr);
    for (n = 0; n < nvals; n++) {
        if (blkid_probe_get_value(pr, n, &name, &data, &len) == 0)
            printf("%s = %s\n", name, data);
    }
}

Example 4. advanced case - probe for all signatures

1
2
3
4
while (blkid_do_probe(pr) == 0) {
    int nvals = blkid_probe_numof_values(pr);
    ...
}

See also blkid_reset_probe().

Parameters

pr

prober

 

Returns

0 on success, 1 when probing is done and -1 in case of error.


blkid_do_safeprobe ()

int
blkid_do_safeprobe (blkid_probe pr);

This function gathers probing results from all enabled chains and checks for ambivalent results (e.g. more filesystems on the device).

This is string-based NAME=value interface only.

Note about superblocks chain -- the function does not check for filesystems when a RAID signature is detected. The function also does not check for collision between RAIDs. The first detected RAID is returned. The function checks for collision between partition table and RAID signature -- it's recommended to enable partitions chain together with superblocks chain.

Parameters

pr

prober

 

Returns

0 on success, 1 if nothing is detected, -2 if ambivalent result is detected and -1 on case of error.


blkid_probe_get_value ()

int
blkid_probe_get_value (blkid_probe pr,
                       int num,
                       const char **name,
                       const char **data,
                       size_t *len);

Note, the len returns length of the data , including the terminating '\0' character.

Parameters

pr

probe

 

num

wanted value in range 0..N, where N is blkid_probe_numof_values() - 1

 

name

pointer to return value name or NULL

 

data

pointer to return value data or NULL

 

len

pointer to return value length or NULL

 

Returns

0 on success, or -1 in case of error.


blkid_probe_has_value ()

int
blkid_probe_has_value (blkid_probe pr,
                       const char *name);

Parameters

pr

probe

 

name

name of value

 

Returns

1 if value exist in probing result, otherwise 0.


blkid_probe_lookup_value ()

int
blkid_probe_lookup_value (blkid_probe pr,
                          const char *name,
                          const char **data,
                          size_t *len);

Note, the len returns length of the data , including the terminating '\0' character.

Parameters

pr

probe

 

name

name of value

 

data

pointer to return value data or NULL

 

len

pointer to return value length or NULL

 

Returns

0 on success, or -1 in case of error.


blkid_probe_numof_values ()

int
blkid_probe_numof_values (blkid_probe pr);

Parameters

pr

probe

 

Returns

number of values in probing result or -1 in case of error.

Types and Values