Mirror of git://git.busybox.net/busybox with our patches on top
Source
xxxxxxxxxx
/* vi: set sw=4 ts=4: */
/*
* Support functions for mounting devices by label/uuid
*
* Copyright (C) 2006 by Jason Schoon <floydpink@gmail.com>
* Some portions cribbed from e2fsprogs, util-linux, dosfstools
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//kbuild:lib-$(CONFIG_BLKID) += get_devname.o
//kbuild:lib-$(CONFIG_FINDFS) += get_devname.o
//kbuild:lib-$(CONFIG_FEATURE_MOUNT_LABEL) += get_devname.o
/* BLKGETSIZE64 */
static struct uuidCache_s {
struct uuidCache_s *next;
// int major, minor;
char *device;
char *label;
char *uc_uuid; /* prefix makes it easier to grep for */
IF_FEATURE_BLKID_TYPE(const char *type;)
} *uuidCache;
/* Returns !0 on error.
* Otherwise, returns malloc'ed strings for label and uuid
* (and they can't be NULL, although they can be "").
* NB: closes fd. */
static int
get_label_uuid(int fd, char **label, char **uuid, const char **type)
{
int rv = 1;
uint64_t size;
struct volume_id *vid;
/* fd is owned by vid now */
vid = volume_id_open_node(fd);
if (ioctl(/*vid->*/fd, BLKGETSIZE64, &size) != 0)
size = 0;
if (volume_id_probe_all(vid, /*0,*/ size) != 0)
goto ret;
if (vid->label[0] != '\0' || vid->uuid[0] != '\0'
|| vid->type != NULL
) {
*label = xstrndup(vid->label, sizeof(vid->label));
*uuid = xstrndup(vid->uuid, sizeof(vid->uuid));
*type = vid->type;
dbg("found label '%s', uuid '%s', type '%s'", *label, *uuid, *type);
dbg("found label '%s', uuid '%s'", *label, *uuid);
rv = 0;
}
ret:
free_volume_id(vid); /* also closes fd */
return rv;
}
/* NB: we take ownership of (malloc'ed) label and uuid */
static void
uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid, const char *type)
{
struct uuidCache_s *last;
if (!uuidCache) {
last = uuidCache = xzalloc(sizeof(*uuidCache));
} else {
for (last = uuidCache; last->next; last = last->next)
continue;
last->next = xzalloc(sizeof(*uuidCache));
last = last->next;
}
/*last->next = NULL; - xzalloc did it*/
// last->major = major;