am 5954ecb8: Merge "Allow more characters in partition name links"

* commit '5954ecb87b8c77425d8cc766c0cc798957a07a7d':
  Allow more characters in partition name links
This commit is contained in:
Colin Cross 2013-07-22 15:40:55 -07:00 committed by Android Git Automerger
commit f987398723
2 changed files with 18 additions and 3 deletions

View file

@ -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

View file

@ -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;