Skip to content

Commit 12f2f04

Browse files
smfrenchgregkh
authored andcommitted
File names with trailing period or space need special case conversion
commit 45e8a2583d97ca758a55c608f78c4cef562644d1 upstream. POSIX allows files with trailing spaces or a trailing period but SMB3 does not, so convert these using the normal Services For Mac mapping as we do for other reserved characters such as : < > | ? * This is similar to what Macs do for the same problem over SMB3. Signed-off-by: Steve French <steve.french@primarydata.com> Acked-by: Pavel Shilovsky <pshilovsky@samba.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1422b6b commit 12f2f04

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

fs/cifs/cifs_unicode.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ convert_sfm_char(const __u16 src_char, char *target)
101101
case SFM_SLASH:
102102
*target = '\\';
103103
break;
104+
case SFM_SPACE:
105+
*target = ' ';
106+
break;
107+
case SFM_PERIOD:
108+
*target = '.';
109+
break;
104110
default:
105111
return false;
106112
}
@@ -404,7 +410,7 @@ static __le16 convert_to_sfu_char(char src_char)
404410
return dest_char;
405411
}
406412

407-
static __le16 convert_to_sfm_char(char src_char)
413+
static __le16 convert_to_sfm_char(char src_char, bool end_of_string)
408414
{
409415
__le16 dest_char;
410416

@@ -427,6 +433,18 @@ static __le16 convert_to_sfm_char(char src_char)
427433
case '|':
428434
dest_char = cpu_to_le16(SFM_PIPE);
429435
break;
436+
case '.':
437+
if (end_of_string)
438+
dest_char = cpu_to_le16(SFM_PERIOD);
439+
else
440+
dest_char = 0;
441+
break;
442+
case ' ':
443+
if (end_of_string)
444+
dest_char = cpu_to_le16(SFM_SPACE);
445+
else
446+
dest_char = 0;
447+
break;
430448
default:
431449
dest_char = 0;
432450
}
@@ -469,9 +487,16 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
469487
/* see if we must remap this char */
470488
if (map_chars == SFU_MAP_UNI_RSVD)
471489
dst_char = convert_to_sfu_char(src_char);
472-
else if (map_chars == SFM_MAP_UNI_RSVD)
473-
dst_char = convert_to_sfm_char(src_char);
474-
else
490+
else if (map_chars == SFM_MAP_UNI_RSVD) {
491+
bool end_of_string;
492+
493+
if (i == srclen - 1)
494+
end_of_string = true;
495+
else
496+
end_of_string = false;
497+
498+
dst_char = convert_to_sfm_char(src_char, end_of_string);
499+
} else
475500
dst_char = 0;
476501
/*
477502
* FIXME: We can not handle remapping backslash (UNI_SLASH)

fs/cifs/cifs_unicode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
#define SFM_LESSTHAN ((__u16) 0xF023)
6565
#define SFM_PIPE ((__u16) 0xF027)
6666
#define SFM_SLASH ((__u16) 0xF026)
67+
#define SFM_PERIOD ((__u16) 0xF028)
68+
#define SFM_SPACE ((__u16) 0xF029)
6769

6870
/*
6971
* Mapping mechanism to use when one of the seven reserved characters is

0 commit comments

Comments
 (0)