views:

584

answers:

2

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!

A: 

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
... and forward slash (/)
derobert
Hmm... so far it looks like [/*"?]. Those characters are non-NUL ASCII
guns
Yes, I updated my answer. '*' and '?' and '"' should be legal. Just not NUL and '/'.
Eddie
+2  A: 

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
So then disallowing the star character "*" is up to the operating system, then?
guns
The star character (0x2a) is allowed. Running this should make one; note the backslash to escape from the shell: touch foo\*
derobert