1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Replace any '\' char with '\\' in table specification on input.

Device-mapper in kernel uses '\' as escape character so it's better
to double it to avoid any confusion when using existing device names
with '\' in the table specification.

For example:

dmsetup create x --table "0 8 linear /dev/mapper/a\x20b 0"

should pass just fine now without a need to explicitly escape the '\' char
like this:

dmsetup create x --table "0 8 linear /dev/mapper/a\\x20b 0"
This commit is contained in:
Peter Rajnoha 2012-02-15 12:17:34 +00:00
parent 4491acea0b
commit 3eb23ab3d2
2 changed files with 23 additions and 3 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.71 - Version 1.02.71 -
==================================== ====================================
Replace any '\' char with '\\' in table specification on input.
Add mangle command to dmsetup to provide renaming to correct mangled form. Add mangle command to dmsetup to provide renaming to correct mangled form.
Add 'mangled_name' and 'unmangled_name' fields to dmsetup info -c -o. Add 'mangled_name' and 'unmangled_name' fields to dmsetup info -c -o.
Add --manglename option to dmsetup to select the name mangling mode. Add --manglename option to dmsetup to select the name mangling mode.

View File

@ -866,7 +866,9 @@ static char *_add_target(struct target *t, char *out, char *end)
char *out_sp = out; char *out_sp = out;
struct dm_target_spec sp; struct dm_target_spec sp;
size_t sp_size = sizeof(struct dm_target_spec); size_t sp_size = sizeof(struct dm_target_spec);
unsigned int backslash_count = 0;
int len; int len;
char *pt;
if (strlen(t->type) >= sizeof(sp.target_type)) { if (strlen(t->type) >= sizeof(sp.target_type)) {
log_error("Target type name %s is too long.", t->type); log_error("Target type name %s is too long.", t->type);
@ -880,15 +882,32 @@ static char *_add_target(struct target *t, char *out, char *end)
sp.target_type[sizeof(sp.target_type) - 1] = '\0'; sp.target_type[sizeof(sp.target_type) - 1] = '\0';
out += sp_size; out += sp_size;
len = strlen(t->params); pt = t->params;
while (*pt)
if (*pt++ == '\\')
backslash_count++;
len = strlen(t->params) + backslash_count;
if ((out >= end) || (out + len + 1) >= end) { if ((out >= end) || (out + len + 1) >= end) {
log_error("Ran out of memory building ioctl parameter"); log_error("Ran out of memory building ioctl parameter");
return NULL; return NULL;
} }
strcpy(out, t->params); if (backslash_count) {
out += len + 1; /* replace "\" with "\\" */
pt = t->params;
do {
if (*pt == '\\')
*out++ = '\\';
*out++ = *pt++;
} while (*pt);
*out++ = '\0';
}
else {
strcpy(out, t->params);
out += len + 1;
}
/* align next block */ /* align next block */
out = _align(out, ALIGNMENT); out = _align(out, ALIGNMENT);