问题描述
有人可以提供(或指向我列表)XFS文件系统中的所有非法字符吗?我正在编写一个需要清理文件名的应用程序.
好的,因此POSIX文件系统应允许除NUL字符,正斜杠和'.'之外的所有字符.和".."文件名被保留.所有其他例外都是应用程序级别的.谢谢!
POSIX文件系统(包括XFS)允许文件名中的每个字符,但NUL(0x00)和正斜杠(/; 0x2f)除外.>
- NUL标记C字符串的结尾;因此不允许在文件名中使用.
- /是目录分隔符,因此是不允许的.
- 以点(
.
; 0x2e)开头的文件名被视为隐藏文件.这是一个用户区,而不是内核或文件系统约定. - 您可能会遵循一些约定,例如UTF-8文件名,在这种情况下,会有很多很多限制,包括使用哪种规范化形式.
现在,您可能也想禁止其他事情;具有各种奇怪字符的文件名处理起来并不有趣.我强烈建议使用白名单方法.
此外,在处理文件名时,请注意每个目录中的 ..
条目.您不想遍历它并允许任意路径.
来源:单一Unix规范第3版,第3.169节,组成名称的字符可以从除斜杠字符和空字节之外的所有字符值的集合中选择."
Could someone provide (or point me to a list) of all the illegal characters in the XFS filesystem? I'm writing an app that needs to sanitize filenames.
EDIT:
Okay, so POSIX filesystems should allow all characters except the NUL character, forward slash, and the '.' and '..' filenames are reserved. All other exceptions are application-level. Thanks!
POSIX filesystems (including XFS) allow every character in file names, with the exception of NUL (0x00) and forward-slash (/; 0x2f).
- NUL marks the end of a C-string; so it is not allowed in file names.
- / is the directory separator, so it is not allowed.
- File names starting with a dot (
.
; 0x2e) are considered hidden files. This is a userland, not kernel or filesystem convention. - There may be conventions you're following — for example, UTF-8 file names — in which case, there are many, many more restrictions including which normalization form to use.
Now, you probably want to disallow other things too; file name with all kinds of weird characters are no fun to deal with. I strongly suggest the whitelist approach.
Also, when handling file names, beware of the ..
entry in every directory. You don't want to traverse it and allow an arbitrary path.
Source: Single Unix Spec v. 3, §3.169, "the characters composing the name may be selected from the set of all character values excluding the slash character and the null byte."
这篇关于XFS文件系统中所有非法字符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!