svn commit: r194924 - head/sys/geom/linux_lvm
Ulf Lilleengen
lulf at FreeBSD.org
Wed Jun 24 22:09:31 UTC 2009
Author: lulf
Date: Wed Jun 24 22:09:30 2009
New Revision: 194924
URL: http://svn.freebsd.org/changeset/base/194924
Log:
- Apply the same naming rules of LVM names as done in the LVM code itself.
PR: kern/135874
Modified:
head/sys/geom/linux_lvm/g_linux_lvm.c
Modified: head/sys/geom/linux_lvm/g_linux_lvm.c
==============================================================================
--- head/sys/geom/linux_lvm/g_linux_lvm.c Wed Jun 24 22:06:56 2009 (r194923)
+++ head/sys/geom/linux_lvm/g_linux_lvm.c Wed Jun 24 22:09:30 2009 (r194924)
@@ -826,14 +826,6 @@ llvm_md_decode(const u_char *data, struc
return (0);
}
-#define GRAB_NAME(tok, name, len) \
- len = 0; \
- while (tok[len] && (isalpha(tok[len]) || isdigit(tok[len])) && \
- len < G_LLVM_NAMELEN - 1) \
- len++; \
- bcopy(tok, name, len); \
- name[len] = '\0';
-
#define GRAB_INT(key, tok1, tok2, v) \
if (tok1 && tok2 && strncmp(tok1, key, sizeof(key)) == 0) { \
v = strtol(tok2, &tok1, 10); \
@@ -864,6 +856,27 @@ llvm_md_decode(const u_char *data, struc
break; \
}
+static size_t
+llvm_grab_name(char *name, const char *tok)
+{
+ size_t len;
+
+ len = 0;
+ if (tok == NULL)
+ return (0);
+ if (tok[0] == '-')
+ return (0);
+ if (strcmp(tok, ".") == 0 || strcmp(tok, "..") == 0)
+ return (0);
+ while (tok[len] && (isalpha(tok[len]) || isdigit(tok[len]) ||
+ tok[len] == '.' || tok[len] == '_' || tok[len] == '-' ||
+ tok[len] == '+') && len < G_LLVM_NAMELEN - 1)
+ len++;
+ bcopy(tok, name, len);
+ name[len] = '\0';
+ return (len);
+}
+
static int
llvm_textconf_decode(u_char *data, int buflen, struct g_llvm_metadata *md)
{
@@ -872,7 +885,7 @@ llvm_textconf_decode(u_char *data, int b
char *tok, *v;
char name[G_LLVM_NAMELEN];
char uuid[G_LLVM_UUIDLEN];
- int len;
+ size_t len;
if (buf == NULL || *buf == '\0')
return (EINVAL);
@@ -880,7 +893,7 @@ llvm_textconf_decode(u_char *data, int b
tok = strsep(&buf, "\n");
if (tok == NULL)
return (EINVAL);
- GRAB_NAME(tok, name, len);
+ len = llvm_grab_name(name, tok);
if (len == 0)
return (EINVAL);
@@ -970,7 +983,7 @@ llvm_textconf_decode_pv(char **buf, char
{
struct g_llvm_pv *pv;
char *v;
- int len;
+ size_t len;
if (*buf == NULL || **buf == '\0')
return (EINVAL);
@@ -983,7 +996,7 @@ llvm_textconf_decode_pv(char **buf, char
len = 0;
if (tok == NULL)
goto bad;
- GRAB_NAME(tok, pv->pv_name, len);
+ len = llvm_grab_name(pv->pv_name, tok);
if (len == 0)
goto bad;
@@ -1024,7 +1037,7 @@ llvm_textconf_decode_lv(char **buf, char
struct g_llvm_lv *lv;
struct g_llvm_segment *sg;
char *v;
- int len;
+ size_t len;
if (*buf == NULL || **buf == '\0')
return (EINVAL);
@@ -1036,10 +1049,9 @@ llvm_textconf_decode_lv(char **buf, char
lv->lv_vg = vg;
LIST_INIT(&lv->lv_segs);
- len = 0;
if (tok == NULL)
goto bad;
- GRAB_NAME(tok, lv->lv_name, len);
+ len = llvm_grab_name(lv->lv_name, tok);
if (len == 0)
goto bad;
@@ -1162,7 +1174,6 @@ bad:
free(sg, M_GLLVM);
return (-1);
}
-#undef GRAB_NAME
#undef GRAB_INT
#undef GRAB_STR
#undef SPLIT
More information about the svn-src-all
mailing list