* mnt_cache_find_tag_value:
* @cache: cache for results
* @devname: device name
- * @token: tag name ("LABEL" or "UUID")
+ * @token: tag name ("LABEL", "UUID", ...)
*
* Returns: LABEL or UUID for the @devname or NULL in case of error.
*/
return NULL;
}
-/**
- * mnt_get_fstype:
- * @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.
- */
-char *mnt_get_fstype(const char *devname, int *ambi, struct libmnt_cache *cache)
+static char *fstype_from_cache(const char *devname, struct libmnt_cache *cache)
+{
+ char *val = NULL;
+
+ assert(cache);
+
+ if (__mnt_cache_find_tag_value(cache, devname, "TYPE", &val) != 0)
+ return NULL;
+ return val;
+}
+
+static char *fstype_from_blkid(const char *devname, int *ambi)
{
blkid_probe pr;
const char *data;
char *type = NULL;
int rc;
- DBG(CACHE, ul_debugobj(cache, "get %s FS type", devname));
-
- if (cache) {
- char *val = NULL;
- rc = __mnt_cache_find_tag_value(cache, devname, "TYPE", &val);
- if (ambi)
- *ambi = rc == -2 ? TRUE : FALSE;
- return rc ? NULL : val;
- }
-
- /*
- * no cache, probe directly
- */
pr = blkid_new_probe_from_filename(devname);
if (!pr)
return NULL;
rc = blkid_do_safeprobe(pr);
- DBG(CACHE, ul_debugobj(cache, "libblkid rc=%d", rc));
-
if (!rc && !blkid_probe_lookup_value(pr, "TYPE", &data, NULL))
type = strdup(data);
-
if (ambi)
*ambi = rc == -2 ? TRUE : FALSE;
return type;
}
+/**
+ * mnt_get_fstype:
+ * @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.
+ */
+char *mnt_get_fstype(const char *devname, int *ambi, struct libmnt_cache *cache)
+{
+ DBG(CACHE, ul_debugobj(cache, "get %s FS type", devname));
+
+ if (cache)
+ return fstype_from_cache(devname, cache);
+
+ return fstype_from_blkid(devname, ambi);
+}
+
static char *canonicalize_path_and_cache(const char *path,
struct libmnt_cache *cache)
{