From 93ca79b44535ee24ece08001e1948070db6ab6ed Mon Sep 17 00:00:00 2001 From: Johan Redestig Date: Wed, 18 Apr 2012 16:41:19 +0200 Subject: [PATCH] Allow more characters in partition name links We have several partitions with underscores in their names which would not be properly linked in: /dev/block/platform/msm_sdcc.1/by-name/ With this change more characters (_-.) are allowed in partition name links. Also, any other character is replaced with '_' so the resulting link names have the same length as the partition name. Change-Id: I746566c03db98b10326c755692362d2c10e528ae --- init/devices.c | 2 ++ init/util.c | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/init/devices.c b/init/devices.c index 69f5fc8ab..41ab85ea7 100644 --- a/init/devices.c +++ b/init/devices.c @@ -451,6 +451,8 @@ static char **parse_platform_block_device(struct uevent *uevent) if (uevent->partition_name) { p = strdup(uevent->partition_name); sanitize(p); + if (strcmp(uevent->partition_name, p)) + NOTICE("Linking partition '%s' as '%s'\n", uevent->partition_name, p); if (asprintf(&links[link_num], "%s/by-name/%s", link_path, p) > 0) link_num++; else diff --git a/init/util.c b/init/util.c index 918bc057e..76af9e575 100755 --- a/init/util.c +++ b/init/util.c @@ -305,14 +305,27 @@ int mkdir_recursive(const char *pathname, mode_t mode) return 0; } +/* + * replaces any unacceptable characters with '_', the + * length of the resulting string is equal to the input string + */ void sanitize(char *s) { + const char* accept = + "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "_-."; + if (!s) return; - while (isalnum(*s)) - s++; - *s = 0; + + for (; *s; s++) { + s += strspn(s, accept); + if (*s) *s = '_'; + } } + void make_link(const char *oldpath, const char *newpath) { int ret;