~ubuntu-branches/ubuntu/lucid/loop-aes-utils/lucid-security

« back to all changes in this revision

Viewing changes to mount/fsprobe_blkid.c

  • Committer: Bazaar Package Importer
  • Author(s): Max Vozeler
  • Date: 2008-08-22 11:57:17 UTC
  • mfrom: (8.1.3 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080822115717-v8wfa8pxwlfvyje0
Tags: 2.13.1-4
* patches/losetup_add_option_f.dpatch: 
  - Added to support "find next free loop" in losetup.
    (closes: #495682)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <blkid/blkid.h>
 
3
#include "fsprobe.h"
 
4
 
 
5
#define BLKID_EMPTY_CACHE       "/dev/null"
 
6
static blkid_cache blkid;
 
7
 
 
8
void
 
9
fsprobe_init(void)
 
10
{
 
11
        blkid = NULL;
 
12
}
 
13
 
 
14
void
 
15
fsprobe_exit(void)
 
16
{
 
17
        if (blkid)
 
18
                blkid_put_cache(blkid);
 
19
}
 
20
 
 
21
const char *
 
22
fsprobe_get_label_by_devname(const char *devname)
 
23
{
 
24
        if (!blkid)
 
25
                blkid_get_cache(&blkid, NULL);
 
26
 
 
27
        return blkid_get_tag_value(blkid, "LABEL", devname);
 
28
}
 
29
 
 
30
const char *
 
31
fsprobe_get_uuid_by_devname(const char *devname)
 
32
{
 
33
        if (!blkid)
 
34
                blkid_get_cache(&blkid, NULL);
 
35
 
 
36
        return blkid_get_tag_value(blkid, "UUID", devname);
 
37
}
 
38
 
 
39
const char *
 
40
fsprobe_get_devname_by_uuid(const char *uuid)
 
41
{
 
42
        if (!blkid)
 
43
                blkid_get_cache(&blkid, NULL);
 
44
 
 
45
        return blkid_get_devname(blkid, "UUID", uuid);
 
46
}
 
47
 
 
48
const char *
 
49
fsprobe_get_devname_by_label(const char *label)
 
50
{
 
51
        if (!blkid)
 
52
                blkid_get_cache(&blkid, NULL);
 
53
 
 
54
        return blkid_get_devname(blkid, "LABEL", label);
 
55
}
 
56
 
 
57
int
 
58
fsprobe_known_fstype(const char *fstype)
 
59
{
 
60
        return blkid_known_fstype(fstype);
 
61
}
 
62
 
 
63
const char *
 
64
fsprobe_get_fstype_by_devname(const char *devname)
 
65
{
 
66
        blkid_cache c;
 
67
        const char *tp;
 
68
 
 
69
        if (blkid)
 
70
                return blkid_get_tag_value(blkid, "TYPE", devname);
 
71
 
 
72
        /* The cache is not initialized yet. Use empty cache rather than waste
 
73
         * time with /etc/blkid.tab. It seems that probe FS is faster than
 
74
         * parse the cache file.  -- kzak (17-May-2007)
 
75
         */
 
76
        blkid_get_cache(&c, BLKID_EMPTY_CACHE);
 
77
        tp = blkid_get_tag_value(c, "TYPE", devname);
 
78
        blkid_put_cache(c);
 
79
 
 
80
        return tp;
 
81
}
 
82