1

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!

guns
  • 10,550
  • 3
  • 39
  • 36
  • Wouldn't the list of legal characters be shorter? – DJ. Mar 16 '09 at 18:53
  • If you want to sanitize filenames, you may want to remove a number of otherwise legal characters from filenames, such as control characters (unless part of an international filename). – Eddie Mar 17 '09 at 00:48

2 Answers2

4

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."

derobert
  • 49,731
  • 15
  • 94
  • 124
  • So then disallowing the star character "*" is up to the operating system, then? – guns Mar 16 '09 at 19:30
  • The star character (0x2a) is allowed. Running this should make one; note the backslash to escape from the shell: touch foo\* – derobert Mar 16 '09 at 19:42
0

According to Wikipedia, any character except NUL is legal in an XFS filesystem file name. Of course, POSIX typically doesn't allow the forward slash '/' in a filename. Other than this, anything should be good, including international characters.

Eddie
  • 53,828
  • 22
  • 125
  • 145