Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Support functions for mounting devices by label/uuid |
| 4 | * |
| 5 | * Copyright (C) 2006 by Jason Schoon <floydpink@gmail.com> |
| 6 | * Some portions cribbed from e2fsprogs, util-linux, dosfstools |
| 7 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 9 | */ |
Sven-Göran Bergh | 3b45801 | 2013-07-31 15:45:20 +0200 | [diff] [blame] | 10 | |
| 11 | //kbuild:lib-$(CONFIG_BLKID) += get_devname.o |
| 12 | //kbuild:lib-$(CONFIG_FINDFS) += get_devname.o |
| 13 | //kbuild:lib-$(CONFIG_FEATURE_MOUNT_LABEL) += get_devname.o |
Denys Vlasenko | 8cae43c | 2017-07-27 10:58:08 +0200 | [diff] [blame] | 14 | //kbuild:lib-$(CONFIG_FEATURE_SWAPONOFF_LABEL) += get_devname.o |
Sven-Göran Bergh | 3b45801 | 2013-07-31 15:45:20 +0200 | [diff] [blame] | 15 | |
Denys Vlasenko | da49f58 | 2009-07-08 02:58:38 +0200 | [diff] [blame] | 16 | #include <sys/mount.h> /* BLKGETSIZE64 */ |
| 17 | #if !defined(BLKGETSIZE64) |
| 18 | # define BLKGETSIZE64 _IOR(0x12,114,size_t) |
| 19 | #endif |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 20 | #include "volume_id_internal.h" |
| 21 | |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 22 | static struct uuidCache_s { |
| 23 | struct uuidCache_s *next; |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 24 | // int major, minor; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 25 | char *device; |
| 26 | char *label; |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 27 | char *uc_uuid; /* prefix makes it easier to grep for */ |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 28 | IF_FEATURE_BLKID_TYPE(const char *type;) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 29 | } *uuidCache; |
| 30 | |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 31 | #if !ENABLE_FEATURE_BLKID_TYPE |
| 32 | #define get_label_uuid(fd, label, uuid, type) \ |
| 33 | get_label_uuid(fd, label, uuid) |
| 34 | #define uuidcache_addentry(device, label, uuid, type) \ |
| 35 | uuidcache_addentry(device, label, uuid) |
| 36 | #endif |
| 37 | |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 38 | /* Returns !0 on error. |
| 39 | * Otherwise, returns malloc'ed strings for label and uuid |
Denis Vlasenko | 582dff0 | 2008-10-19 19:36:30 +0000 | [diff] [blame] | 40 | * (and they can't be NULL, although they can be ""). |
| 41 | * NB: closes fd. */ |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 42 | static int |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 43 | get_label_uuid(int fd, char **label, char **uuid, const char **type) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 44 | { |
| 45 | int rv = 1; |
| 46 | uint64_t size; |
| 47 | struct volume_id *vid; |
| 48 | |
Denis Vlasenko | 582dff0 | 2008-10-19 19:36:30 +0000 | [diff] [blame] | 49 | /* fd is owned by vid now */ |
| 50 | vid = volume_id_open_node(fd); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 51 | |
Denis Vlasenko | 582dff0 | 2008-10-19 19:36:30 +0000 | [diff] [blame] | 52 | if (ioctl(/*vid->*/fd, BLKGETSIZE64, &size) != 0) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 53 | size = 0; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 54 | |
Denis Vlasenko | 28ea429 | 2009-02-15 05:51:19 +0000 | [diff] [blame] | 55 | if (volume_id_probe_all(vid, /*0,*/ size) != 0) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 56 | goto ret; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 57 | |
S-G Bergh | d2d5049 | 2012-11-05 13:16:07 +0100 | [diff] [blame] | 58 | if (vid->label[0] != '\0' || vid->uuid[0] != '\0' |
| 59 | #if ENABLE_FEATURE_BLKID_TYPE |
| 60 | || vid->type != NULL |
| 61 | #endif |
| 62 | ) { |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 63 | *label = xstrndup(vid->label, sizeof(vid->label)); |
| 64 | *uuid = xstrndup(vid->uuid, sizeof(vid->uuid)); |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 65 | #if ENABLE_FEATURE_BLKID_TYPE |
| 66 | *type = vid->type; |
| 67 | dbg("found label '%s', uuid '%s', type '%s'", *label, *uuid, *type); |
| 68 | #else |
Vladimir Dronnikov | 662e8b7 | 2009-11-01 23:05:09 +0100 | [diff] [blame] | 69 | dbg("found label '%s', uuid '%s'", *label, *uuid); |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 70 | #endif |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 71 | rv = 0; |
| 72 | } |
| 73 | ret: |
Denis Vlasenko | 582dff0 | 2008-10-19 19:36:30 +0000 | [diff] [blame] | 74 | free_volume_id(vid); /* also closes fd */ |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 75 | return rv; |
| 76 | } |
| 77 | |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 78 | /* NB: we take ownership of (malloc'ed) label and uuid */ |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 79 | static void |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 80 | uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid, const char *type) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 81 | { |
| 82 | struct uuidCache_s *last; |
Denis Vlasenko | 42cc304 | 2008-03-24 02:05:58 +0000 | [diff] [blame] | 83 | |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 84 | if (!uuidCache) { |
| 85 | last = uuidCache = xzalloc(sizeof(*uuidCache)); |
| 86 | } else { |
| 87 | for (last = uuidCache; last->next; last = last->next) |
| 88 | continue; |
| 89 | last->next = xzalloc(sizeof(*uuidCache)); |
| 90 | last = last->next; |
| 91 | } |
| 92 | /*last->next = NULL; - xzalloc did it*/ |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 93 | // last->major = major; |
| 94 | // last->minor = minor; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 95 | last->device = device; |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 96 | last->label = label; |
| 97 | last->uc_uuid = uuid; |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 98 | IF_FEATURE_BLKID_TYPE(last->type = type;) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 101 | /* If get_label_uuid() on device_name returns success, |
| 102 | * add a cache entry for this device. |
| 103 | * If device node does not exist, it will be temporarily created. */ |
Denis Vlasenko | 582dff0 | 2008-10-19 19:36:30 +0000 | [diff] [blame] | 104 | static int FAST_FUNC |
| 105 | uuidcache_check_device(const char *device, |
| 106 | struct stat *statbuf, |
| 107 | void *userData UNUSED_PARAM, |
| 108 | int depth UNUSED_PARAM) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 109 | { |
Denys Vlasenko | 4fc5ec5 | 2009-06-27 21:58:25 +0200 | [diff] [blame] | 110 | /* note: this check rejects links to devices, among other nodes */ |
Serj Kalichev | d42cdc2 | 2016-08-29 18:28:34 +0300 | [diff] [blame] | 111 | if (!S_ISBLK(statbuf->st_mode) |
| 112 | #if ENABLE_FEATURE_VOLUMEID_UBIFS |
| 113 | && !(S_ISCHR(statbuf->st_mode) && strncmp(bb_basename(device), "ubi", 3) == 0) |
| 114 | #endif |
| 115 | ) |
Denis Vlasenko | 582dff0 | 2008-10-19 19:36:30 +0000 | [diff] [blame] | 116 | return TRUE; |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 117 | |
Denys Vlasenko | 4fc5ec5 | 2009-06-27 21:58:25 +0200 | [diff] [blame] | 118 | /* Users report that mucking with floppies (especially non-present |
| 119 | * ones) is significant PITA. This is a horribly dirty hack, |
Denys Vlasenko | 1881ba4 | 2009-06-27 22:09:28 +0200 | [diff] [blame] | 120 | * but it is very useful in real world. |
| 121 | * If this will ever need to be enabled, consider using O_NONBLOCK. |
| 122 | */ |
Denys Vlasenko | 4fc5ec5 | 2009-06-27 21:58:25 +0200 | [diff] [blame] | 123 | if (major(statbuf->st_rdev) == 2) |
| 124 | return TRUE; |
| 125 | |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 126 | add_to_uuid_cache(device); |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 127 | |
Denis Vlasenko | 582dff0 | 2008-10-19 19:36:30 +0000 | [diff] [blame] | 128 | return TRUE; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Denys Vlasenko | c3375f0 | 2011-12-06 15:06:59 +0100 | [diff] [blame] | 131 | static struct uuidCache_s* |
Denys Vlasenko | e8cfc3f | 2012-03-03 15:09:07 +0100 | [diff] [blame] | 132 | uuidcache_init(int scan_devices) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 133 | { |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 134 | dbg("DBG: uuidCache=%x, uuidCache"); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 135 | if (uuidCache) |
Denys Vlasenko | c3375f0 | 2011-12-06 15:06:59 +0100 | [diff] [blame] | 136 | return uuidCache; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 137 | |
Denis Vlasenko | 802a7be | 2008-10-19 19:54:49 +0000 | [diff] [blame] | 138 | /* We were scanning /proc/partitions |
| 139 | * and /proc/sys/dev/cdrom/info here. |
| 140 | * Missed volume managers. I see that "standard" blkid uses these: |
| 141 | * /dev/mapper/control |
| 142 | * /proc/devices |
| 143 | * /proc/evms/volumes |
| 144 | * /proc/lvm/VGs |
| 145 | * This is unacceptably complex. Let's just scan /dev. |
| 146 | * (Maybe add scanning of /sys/block/XXX/dev for devices |
| 147 | * somehow not having their /dev/XXX entries created?) */ |
Denys Vlasenko | e8cfc3f | 2012-03-03 15:09:07 +0100 | [diff] [blame] | 148 | if (scan_devices) |
| 149 | recursive_action("/dev", ACTION_RECURSE, |
| 150 | uuidcache_check_device, /* file_action */ |
| 151 | NULL, /* dir_action */ |
| 152 | NULL, /* userData */ |
| 153 | 0 /* depth */); |
Denys Vlasenko | c3375f0 | 2011-12-06 15:06:59 +0100 | [diff] [blame] | 154 | |
| 155 | return uuidCache; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | #define UUID 1 |
| 159 | #define VOL 2 |
| 160 | |
| 161 | #ifdef UNUSED |
| 162 | static char * |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 163 | get_spec_by_x(int n, const char *t, int *majorPtr, int *minorPtr) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 164 | { |
| 165 | struct uuidCache_s *uc; |
| 166 | |
Denys Vlasenko | e8cfc3f | 2012-03-03 15:09:07 +0100 | [diff] [blame] | 167 | uc = uuidcache_init(/*scan_devices:*/ 1); |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 168 | while (uc) { |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 169 | switch (n) { |
| 170 | case UUID: |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 171 | if (strcmp(t, uc->uc_uuid) == 0) { |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 172 | *majorPtr = uc->major; |
| 173 | *minorPtr = uc->minor; |
| 174 | return uc->device; |
| 175 | } |
| 176 | break; |
| 177 | case VOL: |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 178 | if (strcmp(t, uc->label) == 0) { |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 179 | *majorPtr = uc->major; |
| 180 | *minorPtr = uc->minor; |
| 181 | return uc->device; |
| 182 | } |
| 183 | break; |
| 184 | } |
| 185 | uc = uc->next; |
| 186 | } |
| 187 | return NULL; |
| 188 | } |
| 189 | |
| 190 | static unsigned char |
| 191 | fromhex(char c) |
| 192 | { |
| 193 | if (isdigit(c)) |
| 194 | return (c - '0'); |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 195 | return ((c|0x20) - 'a' + 10); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static char * |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 199 | get_spec_by_uuid(const char *s, int *major, int *minor) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 200 | { |
| 201 | unsigned char uuid[16]; |
| 202 | int i; |
| 203 | |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 204 | if (strlen(s) != 36 || s[8] != '-' || s[13] != '-' |
| 205 | || s[18] != '-' || s[23] != '-' |
| 206 | ) { |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 207 | goto bad_uuid; |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 208 | } |
| 209 | for (i = 0; i < 16; i++) { |
| 210 | if (*s == '-') |
| 211 | s++; |
| 212 | if (!isxdigit(s[0]) || !isxdigit(s[1])) |
| 213 | goto bad_uuid; |
| 214 | uuid[i] = ((fromhex(s[0]) << 4) | fromhex(s[1])); |
| 215 | s += 2; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 216 | } |
| 217 | return get_spec_by_x(UUID, (char *)uuid, major, minor); |
| 218 | |
| 219 | bad_uuid: |
| 220 | fprintf(stderr, _("mount: bad UUID")); |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | static char * |
| 225 | get_spec_by_volume_label(const char *s, int *major, int *minor) |
| 226 | { |
| 227 | return get_spec_by_x(VOL, s, major, minor); |
| 228 | } |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 229 | #endif // UNUSED |
| 230 | |
Denis Vlasenko | 1e19afd | 2008-10-12 11:20:08 +0000 | [diff] [blame] | 231 | /* Used by blkid */ |
Denys Vlasenko | e8cfc3f | 2012-03-03 15:09:07 +0100 | [diff] [blame] | 232 | void display_uuid_cache(int scan_devices) |
Denis Vlasenko | 1e19afd | 2008-10-12 11:20:08 +0000 | [diff] [blame] | 233 | { |
Denys Vlasenko | c3375f0 | 2011-12-06 15:06:59 +0100 | [diff] [blame] | 234 | struct uuidCache_s *uc; |
Denis Vlasenko | 1e19afd | 2008-10-12 11:20:08 +0000 | [diff] [blame] | 235 | |
Denys Vlasenko | e8cfc3f | 2012-03-03 15:09:07 +0100 | [diff] [blame] | 236 | uc = uuidcache_init(scan_devices); |
Denys Vlasenko | c3375f0 | 2011-12-06 15:06:59 +0100 | [diff] [blame] | 237 | while (uc) { |
| 238 | printf("%s:", uc->device); |
| 239 | if (uc->label[0]) |
| 240 | printf(" LABEL=\"%s\"", uc->label); |
| 241 | if (uc->uc_uuid[0]) |
| 242 | printf(" UUID=\"%s\"", uc->uc_uuid); |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 243 | #if ENABLE_FEATURE_BLKID_TYPE |
Denys Vlasenko | c3375f0 | 2011-12-06 15:06:59 +0100 | [diff] [blame] | 244 | if (uc->type) |
| 245 | printf(" TYPE=\"%s\"", uc->type); |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 246 | #endif |
Denis Vlasenko | 1e19afd | 2008-10-12 11:20:08 +0000 | [diff] [blame] | 247 | bb_putchar('\n'); |
Denys Vlasenko | c3375f0 | 2011-12-06 15:06:59 +0100 | [diff] [blame] | 248 | uc = uc->next; |
Denis Vlasenko | 1e19afd | 2008-10-12 11:20:08 +0000 | [diff] [blame] | 249 | } |
| 250 | } |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 251 | |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 252 | int add_to_uuid_cache(const char *device) |
| 253 | { |
| 254 | char *uuid = uuid; /* for compiler */ |
| 255 | char *label = label; |
| 256 | #if ENABLE_FEATURE_BLKID_TYPE |
| 257 | const char *type = type; |
| 258 | #endif |
| 259 | int fd; |
| 260 | |
| 261 | fd = open(device, O_RDONLY); |
| 262 | if (fd < 0) |
| 263 | return 0; |
| 264 | |
| 265 | /* get_label_uuid() closes fd in all cases (success & failure) */ |
| 266 | if (get_label_uuid(fd, &label, &uuid, &type) == 0) { |
| 267 | /* uuidcache_addentry() takes ownership of all four params */ |
| 268 | uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid, type); |
| 269 | return 1; |
| 270 | } |
| 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 275 | /* Used by mount and findfs */ |
| 276 | |
| 277 | char *get_devname_from_label(const char *spec) |
| 278 | { |
| 279 | struct uuidCache_s *uc; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 280 | |
Denys Vlasenko | e8cfc3f | 2012-03-03 15:09:07 +0100 | [diff] [blame] | 281 | uc = uuidcache_init(/*scan_devices:*/ 1); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 282 | while (uc) { |
Denis Vlasenko | 9983d80 | 2009-03-31 19:47:34 +0000 | [diff] [blame] | 283 | if (uc->label[0] && strcmp(spec, uc->label) == 0) { |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 284 | return xstrdup(uc->device); |
| 285 | } |
| 286 | uc = uc->next; |
| 287 | } |
| 288 | return NULL; |
| 289 | } |
| 290 | |
| 291 | char *get_devname_from_uuid(const char *spec) |
| 292 | { |
| 293 | struct uuidCache_s *uc; |
| 294 | |
Denys Vlasenko | e8cfc3f | 2012-03-03 15:09:07 +0100 | [diff] [blame] | 295 | uc = uuidcache_init(/*scan_devices:*/ 1); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 296 | while (uc) { |
Denis Vlasenko | d25c33f | 2008-03-17 09:25:05 +0000 | [diff] [blame] | 297 | /* case of hex numbers doesn't matter */ |
| 298 | if (strcasecmp(spec, uc->uc_uuid) == 0) { |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 299 | return xstrdup(uc->device); |
| 300 | } |
| 301 | uc = uc->next; |
| 302 | } |
| 303 | return NULL; |
| 304 | } |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 305 | |
| 306 | int resolve_mount_spec(char **fsname) |
| 307 | { |
| 308 | char *tmp = *fsname; |
| 309 | |
Denys Vlasenko | 8dff01d | 2015-03-12 17:48:34 +0100 | [diff] [blame] | 310 | if (is_prefixed_with(*fsname, "UUID=")) |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 311 | tmp = get_devname_from_uuid(*fsname + 5); |
Alfonso Ranieri | a90490f | 2015-04-14 14:32:39 +0200 | [diff] [blame] | 312 | else if (is_prefixed_with(*fsname, "LABEL=")) |
Natanael Copa | 9aff299 | 2009-09-20 04:28:22 +0200 | [diff] [blame] | 313 | tmp = get_devname_from_label(*fsname + 6); |
| 314 | |
| 315 | if (tmp == *fsname) |
| 316 | return 0; /* no UUID= or LABEL= prefix found */ |
| 317 | |
| 318 | if (tmp) |
| 319 | *fsname = tmp; |
| 320 | return 1; |
| 321 | } |