Cache

Cache — paths and tags (UUID/LABEL) caching

Synopsis

struct              libmnt_cache;
struct libmnt_cache * mnt_new_cache                     (void);
void                mnt_free_cache                      (struct libmnt_cache *cache);
int                 mnt_cache_device_has_tag            (struct libmnt_cache *cache,
                                                         const char *devname,
                                                         const char *token,
                                                         const char *value);
char *              mnt_cache_find_tag_value            (struct libmnt_cache *cache,
                                                         const char *devname,
                                                         const char *token);
int                 mnt_cache_read_tags                 (struct libmnt_cache *cache,
                                                         const char *devname);
char *              mnt_get_fstype                      (const char *devname,
                                                         int *ambi,
                                                         struct libmnt_cache *cache);
char *              mnt_pretty_path                     (const char *path,
                                                         struct libmnt_cache *cache);
char *              mnt_resolve_path                    (const char *path,
                                                         struct libmnt_cache *cache);
char *              mnt_resolve_spec                    (const char *spec,
                                                         struct libmnt_cache *cache);
char *              mnt_resolve_tag                     (const char *token,
                                                         const char *value,
                                                         struct libmnt_cache *cache);

Description

The cache is a very simple API for work with tags (LABEL, UUID, ...) and paths. The cache uses libblkid as a backend for TAGs resolution.

All returned paths are always canonicalized.

Details

struct libmnt_cache

struct libmnt_cache;

Stores canonicalized paths and evaluated tags


mnt_new_cache ()

struct libmnt_cache * mnt_new_cache                     (void);

Returns :

new struct libmnt_cache instance or NULL in case of ENOMEM error.

mnt_free_cache ()

void                mnt_free_cache                      (struct libmnt_cache *cache);

Deallocates the cache.

cache :

pointer to struct libmnt_cache instance

mnt_cache_device_has_tag ()

int                 mnt_cache_device_has_tag            (struct libmnt_cache *cache,
                                                         const char *devname,
                                                         const char *token,
                                                         const char *value);

Look up cache to check it tag+value are associated with devname.

cache :

paths cache

devname :

path to the device

token :

tag name (e.g "LABEL")

value :

tag value

Returns :

1 on success or 0.

mnt_cache_find_tag_value ()

char *              mnt_cache_find_tag_value            (struct libmnt_cache *cache,
                                                         const char *devname,
                                                         const char *token);

cache :

cache for results

devname :

device name

token :

tag name ("LABEL" or "UUID")

Returns :

LABEL or UUID for the devname or NULL in case of error.

mnt_cache_read_tags ()

int                 mnt_cache_read_tags                 (struct libmnt_cache *cache,
                                                         const char *devname);

Reads devname LABEL and UUID to the cache.

cache :

pointer to struct libmnt_cache instance

devname :

path device

Returns :

0 if at least one tag was added, 1 if no tag was added or negative number in case of error.

mnt_get_fstype ()

char *              mnt_get_fstype                      (const char *devname,
                                                         int *ambi,
                                                         struct libmnt_cache *cache);

devname :

device name

ambi :

returns TRUE if probing result is ambivalent (optional argument)

cache :

cache for results or NULL

Returns :

filesystem type or NULL in case of error. The result has to be deallocated by free() if cache is NULL.

mnt_pretty_path ()

char *              mnt_pretty_path                     (const char *path,
                                                         struct libmnt_cache *cache);

Converts path:

  • to the absolute path

  • /dev/dm-N to /dev/mapper/name

  • /dev/loopN to the loop backing filename

  • empty path (NULL) to 'none'

path :

any path

cache :

NULL or pointer to the cache

Returns :

new allocated string with path, result has to be always deallocated by free().

mnt_resolve_path ()

char *              mnt_resolve_path                    (const char *path,
                                                         struct libmnt_cache *cache);

Converts path:

  • to the absolute path

  • /dev/dm-N to /dev/mapper/name

path :

"native" path

cache :

cache for results or NULL

Returns :

absolute path or NULL in case of error. The result has to be deallocated by free() if cache is NULL.

mnt_resolve_spec ()

char *              mnt_resolve_spec                    (const char *spec,
                                                         struct libmnt_cache *cache);

spec :

path or tag

cache :

paths cache

Returns :

canonicalized path or NULL. The result has to be deallocated by free() if cache is NULL.

mnt_resolve_tag ()

char *              mnt_resolve_tag                     (const char *token,
                                                         const char *value,
                                                         struct libmnt_cache *cache);

token :

tag name

value :

tag value

cache :

for results or NULL

Returns :

device name or NULL in case of error. The result has to be deallocated by free() if cache is NULL.