summaryrefslogtreecommitdiffstats
path: root/mount/mount_blkid.c
blob: 7abadec290f81cb75eba785f4ca041d2830162d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <stdio.h>
#include "mount_blkid.h"

#ifdef HAVE_BLKID

blkid_cache blkid;

void
mount_blkid_get_cache(void) {
	blkid_get_cache(&blkid, NULL);
}

void
mount_blkid_put_cache(void) {
	blkid_put_cache(blkid);
}

const char *
mount_get_volume_label_by_spec(const char *spec) {
	return blkid_get_tag_value(blkid, "LABEL", spec);
}

const char *
mount_get_devname(const char *spec) {
	return blkid_get_devname(blkid, spec, 0);
}

const char *
mount_get_devname_by_uuid(const char *uuid) {
	return blkid_get_devname(blkid, "UUID", uuid);
}

const char *
mount_get_devname_by_label(const char *label) {
	return blkid_get_devname(blkid, "LABEL", label);
}

/* Also when no UUID= or LABEL= occur? No verbose? No warnings? */
const char *
mount_get_devname_for_mounting(const char *spec) {
	return blkid_get_devname(blkid, spec, 0);
}

#else
#include <string.h>
#include "sundries.h"
#include "mount_by_label.h"
#include "nls.h"

void
mount_blkid_get_cache(void) {
}

void
mount_blkid_put_cache(void) {
}

const char *
mount_get_volume_label_by_spec(const char *spec) {
	return strdup(get_volume_label_by_spec(spec));
}

const char *
mount_get_devname(const char *spec) {
	if (!strncmp(spec, "UUID=", 5))
		return get_spec_by_uuid(spec+5);
	if (!strncmp(spec, "LABEL=", 6))
		return get_spec_by_volume_label(spec+6);
	return spec;
}

const char *
mount_get_devname_by_uuid(const char *uuid) {
	return get_spec_by_uuid(uuid);
}

const char *
mount_get_devname_by_label(const char *volumelabel) {
	const char *spec, *spec2;

	spec = get_spec_by_volume_label(volumelabel);
	spec2 = second_occurrence_of_vol_label(volumelabel);
	if (spec2)
		die (EX_FAIL,
		     _("mount: the label %s occurs on "
		       "both %s and %s - not mounted\n"),
		     volumelabel, spec, spec2);
	return spec;
}

const char *
mount_get_devname_for_mounting(const char *spec) {
	const char *nspec;

	if (!strncmp(spec, "UUID=", 5)) {
		nspec = mount_get_devname_by_uuid(spec+5);
		if (nspec && verbose > 1)
			printf(_("mount: going to mount %s by UUID\n"), spec);
	} else if (!strncmp(spec, "LABEL=", 6)) {
		nspec = mount_get_devname_by_label(spec+6);
		if (nspec && verbose > 1)
			printf(_("mount: going to mount %s by label\n"), spec);
	} else
		nspec = spec;

	return nspec;
}


#endif