1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-10 16:58:47 +03:00

cleanup: use proper const in apply_lvname_restrictions

Better constness used for reserved prefixes and strings.
Also simplify a bit validate_name and use direct char
checks isntead of 2 strcmp() calls.
This commit is contained in:
Zdenek Kabelac 2012-12-14 14:03:58 +01:00
parent 21f6511bc2
commit 575c4ed964

View File

@ -81,7 +81,7 @@ int validate_name(const char *n)
if (*n == '-')
return 0;
if (!strcmp(n, ".") || !strcmp(n, ".."))
if ((*n == '.') && (!n[1] || (n[1] == '.' && !n[2]))) /* ".", ".." */
return 0;
while ((len++, c = *n++))
@ -96,13 +96,13 @@ int validate_name(const char *n)
int apply_lvname_restrictions(const char *name)
{
const char *reserved_prefixes[] = {
static const char * const _reserved_prefixes[] = {
"snapshot",
"pvmove",
NULL
};
const char *reserved_strings[] = {
static const char * const _reserved_strings[] = {
"_mlog",
"_mimage",
"_rimage",
@ -116,7 +116,7 @@ int apply_lvname_restrictions(const char *name)
unsigned i;
const char *s;
for (i = 0; (s = reserved_prefixes[i]); i++) {
for (i = 0; (s = _reserved_prefixes[i]); i++) {
if (!strncmp(name, s, strlen(s))) {
log_error("Names starting \"%s\" are reserved. "
"Please choose a different LV name.", s);
@ -124,7 +124,7 @@ int apply_lvname_restrictions(const char *name)
}
}
for (i = 0; (s = reserved_strings[i]); i++) {
for (i = 0; (s = _reserved_strings[i]); i++) {
if (strstr(name, s)) {
log_error("Names including \"%s\" are reserved. "
"Please choose a different LV name.", s);