/** * mnt_resolve_path: * @path: "native" path * @cache: cache for results or NULL * * Converts path: * - to the absolute path * - /dev/dm-N to /dev/mapper/name * * Returns: absolute path or NULL in case of error. The result has to be * deallocated by free() if @cache is NULL. */ char *mnt_resolve_path(const char *path, struct libmnt_cache *cache) { char *p = NULL; /*DBG(CACHE, ul_debugobj(cache, "resolving path %s", path));*/ if (!path) return NULL; if (cache) p = (char *) cache_find_path(cache, path); if (!p) p = canonicalize_path_and_cache(path, cache); return p; }
/** * mnt_resolve_target: * @path: "native" path, a potential mount point * @cache: cache for results or NULL. * * Like mnt_resolve_path(), unless @cache is not NULL and * mnt_cache_set_targets(cache, mtab) was called: if @path is found in the * cached @mtab and the matching entry was provided by the kernel, assume that * @path is already canonicalized. By avoiding a call to realpath(2) on * known mount points, there is a lower risk of stepping on a stale mount * point, which can result in an application freeze. This is also faster in * general, as stat(2) on a mount point is slower than on a regular file. * * Returns: absolute path or NULL in case of error. The result has to be * deallocated by free() if @cache is NULL. */ char *mnt_resolve_target(const char *path, struct libmnt_cache *cache) { char *p = NULL; /*DBG(CACHE, ul_debugobj(cache, "resolving target %s", path));*/ if (!cache || !cache->mtab) return mnt_resolve_path(path, cache); p = (char *) cache_find_path(cache, path); if (p) return p; else { struct libmnt_iter itr; struct libmnt_fs *fs = NULL; mnt_reset_iter(&itr, MNT_ITER_BACKWARD); while (mnt_table_next_fs(cache->mtab, &itr, &fs) == 0) { if (!mnt_fs_is_kernel(fs) || mnt_fs_is_swaparea(fs) || !mnt_fs_streq_target(fs, path)) continue; p = strdup(path); if (!p) return NULL; /* ENOMEM */ if (cache_add_entry(cache, p, p, MNT_CACHE_ISPATH)) { free(p); return NULL; /* ENOMEM */ } break; } } if (!p) p = canonicalize_path_and_cache(path, cache); return p; }
/** * mnt_resolve_path: * @path: "native" path * @cache: cache for results or NULL * * Converts path: * - to the absolute path * - /dev/dm-N to /dev/mapper/name * * Returns: absolute path or NULL in case of error. The result has to be * deallocated by free() if @cache is NULL. */ char *mnt_resolve_path(const char *path, struct libmnt_cache *cache) { char *p = NULL; char *key = NULL; char *value = NULL; /*DBG(CACHE, mnt_debug_h(cache, "resolving path %s", path));*/ if (!path) return NULL; if (cache) p = (char *) cache_find_path(cache, path); if (!p) { p = canonicalize_path(path); if (p && cache) { value = p; key = strcmp(path, p) == 0 ? value : strdup(path); if (!key || !value) goto error; if (cache_add_entry(cache, key, value, MNT_CACHE_ISPATH)) goto error; } } return p; error: if (value != key) free(value); free(key); return NULL; }